1 /** \file wxsimagetreeeditordlg.cpp
2 *
3 * This file is part of wxSmith plugin for Code::Blocks Studio
4 * Copyright (C) 2010 Gary Harris
5 *
6 * wxSmith is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * wxSmith is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * This code was taken from the wxSmithImage plug-in, copyright Ron Collins
20 * and released under the GPL.
21 *
22 */
23 
24 #include "wxsimagetreeeditordlg.h"
25 
26 //(*InternalHeaders(wxsImageTreeEditDialog)
27 #include <wx/font.h>
28 #include <wx/intl.h>
29 #include <wx/string.h>
30 //*)
31 
32 #include <wx/msgdlg.h>
33 #include "../properties/wxsimagelisteditordlg.h"
34 
35 
36 //(*IdInit(wxsImageTreeEditorDlg)
37 const long wxsImageTreeEditorDlg::ID_STATICTEXT1 = wxNewId();
38 const long wxsImageTreeEditorDlg::ID_TREECTRL1 = wxNewId();
39 const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON1 = wxNewId();
40 const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON2 = wxNewId();
41 const long wxsImageTreeEditorDlg::ID_STATICTEXT3 = wxNewId();
42 const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON3 = wxNewId();
43 const long wxsImageTreeEditorDlg::ID_STATICTEXT4 = wxNewId();
44 const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON4 = wxNewId();
45 const long wxsImageTreeEditorDlg::ID_STATICTEXT5 = wxNewId();
46 const long wxsImageTreeEditorDlg::ID_BUTTON3 = wxNewId();
47 const long wxsImageTreeEditorDlg::ID_STATICTEXT6 = wxNewId();
48 const long wxsImageTreeEditorDlg::ID_CHECKBOX1 = wxNewId();
49 const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON5 = wxNewId();
50 const long wxsImageTreeEditorDlg::ID_STATICTEXT11 = wxNewId();
51 const long wxsImageTreeEditorDlg::ID_STATICTEXT12 = wxNewId();
52 const long wxsImageTreeEditorDlg::ID_STATICTEXT13 = wxNewId();
53 const long wxsImageTreeEditorDlg::ID_COMBOBOX1 = wxNewId();
54 const long wxsImageTreeEditorDlg::ID_STATICTEXT7 = wxNewId();
55 const long wxsImageTreeEditorDlg::ID_COMBOBOX2 = wxNewId();
56 const long wxsImageTreeEditorDlg::ID_STATICTEXT8 = wxNewId();
57 const long wxsImageTreeEditorDlg::ID_COMBOBOX3 = wxNewId();
58 const long wxsImageTreeEditorDlg::ID_STATICTEXT9 = wxNewId();
59 const long wxsImageTreeEditorDlg::ID_COMBOBOX4 = wxNewId();
60 const long wxsImageTreeEditorDlg::ID_STATICTEXT10 = wxNewId();
61 const long wxsImageTreeEditorDlg::ID_BUTTON1 = wxNewId();
62 const long wxsImageTreeEditorDlg::ID_BUTTON2 = wxNewId();
63 //*)
64 
BEGIN_EVENT_TABLE(wxsImageTreeEditorDlg,wxDialog)65 BEGIN_EVENT_TABLE(wxsImageTreeEditorDlg, wxDialog)
66     //(*EventTable(wxsImageTreeEditorDlg)
67     //*)
68 END_EVENT_TABLE()
69 
70 wxsImageTreeEditorDlg::wxsImageTreeEditorDlg(wxWindow *parent)
71 {
72     //(*Initialize(wxsImageTreeEditorDlg)
73     wxBoxSizer* BoxSizer4;
74     wxBoxSizer* BoxSizer6;
75     wxBoxSizer* BoxSizer5;
76     wxBoxSizer* BoxSizer10;
77     wxBoxSizer* BoxSizer7;
78     wxBoxSizer* BoxSizer8;
79     wxBoxSizer* BoxSizer13;
80     wxBoxSizer* BoxSizer2;
81     wxBoxSizer* BoxSizer11;
82     wxBoxSizer* BoxSizer12;
83     wxGridSizer* GridSizer1;
84     wxBoxSizer* BoxSizer1;
85     wxBoxSizer* BoxSizer9;
86     wxBoxSizer* BoxSizer3;
87 
88     Create(parent, wxID_ANY, _("Tree Item Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
89     wxFont thisFont(8,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Arial"),wxFONTENCODING_DEFAULT);
90     SetFont(thisFont);
91     BoxSizer1 = new wxBoxSizer(wxVERTICAL);
92     BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
93     StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Edit Tree Items"), wxPoint(0,0), wxSize(400,20), wxST_NO_AUTORESIZE|wxALIGN_CENTRE, _T("ID_STATICTEXT1"));
94     wxFont StaticText1Font(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
95     StaticText1->SetFont(StaticText1Font);
96     BoxSizer2->Add(StaticText1, 1, wxEXPAND, 0);
97     BoxSizer1->Add(BoxSizer2, 0, wxEXPAND, 0);
98     BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
99     BoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
100     StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("tree-name"));
101     Tree1 = new wxTreeCtrl(this, ID_TREECTRL1, wxPoint(2,36), wxSize(246,359), wxTR_EDIT_LABELS|wxTR_DEFAULT_STYLE, wxDefaultValidator, _T("ID_TREECTRL1"));
102     StaticBoxSizer1->Add(Tree1, 0, wxALIGN_BOTTOM, 5);
103     BoxSizer5->Add(StaticBoxSizer1, 0, wxALIGN_BOTTOM, 5);
104     BoxSizer3->Add(BoxSizer5, 0, wxALL|wxEXPAND, 0);
105     BoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
106     StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Attributes"));
107     BoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
108     bAddItem = new wxBitmapButton(this, ID_IMAGEBUTTON1, wxNullBitmap, wxPoint(256,36), wxSize(24,23), wxBU_AUTODRAW, wxDefaultValidator, _T("ID_IMAGEBUTTON1"));
109     bAddItem->SetToolTip(_("Add A New Item"));
110     BoxSizer7->Add(bAddItem, 0, wxALIGN_BOTTOM, 5);
111     StaticText2 = new wxStaticText(this, wxID_ANY, _("Add Item"), wxPoint(290,40), wxDefaultSize, 0, _T("wxID_ANY"));
112     BoxSizer7->Add(StaticText2, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
113     StaticBoxSizer2->Add(BoxSizer7, 0, wxEXPAND, 0);
114     BoxSizer8 = new wxBoxSizer(wxHORIZONTAL);
115     bAddSubItem = new wxBitmapButton(this, ID_IMAGEBUTTON2, wxNullBitmap, wxPoint(256,66), wxSize(24,23), wxBU_AUTODRAW, wxDefaultValidator, _T("ID_IMAGEBUTTON2"));
116     bAddSubItem->SetToolTip(_("Add A New Child"));
117     BoxSizer8->Add(bAddSubItem, 0, wxALIGN_BOTTOM, 5);
118     StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Add Sub-Item"), wxPoint(290,70), wxDefaultSize, 0, _T("ID_STATICTEXT3"));
119     BoxSizer8->Add(StaticText3, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
120     StaticBoxSizer2->Add(BoxSizer8, 0, wxTOP|wxEXPAND, 5);
121     BoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
122     bDelItem = new wxBitmapButton(this, ID_IMAGEBUTTON3, wxNullBitmap, wxPoint(256,96), wxSize(24,23), wxBU_AUTODRAW, wxDefaultValidator, _T("ID_IMAGEBUTTON3"));
123     bDelItem->SetToolTip(_("Delete Current Item"));
124     BoxSizer9->Add(bDelItem, 0, wxALIGN_BOTTOM, 5);
125     StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Delete Current Item"), wxPoint(290,100), wxDefaultSize, 0, _T("ID_STATICTEXT4"));
126     BoxSizer9->Add(StaticText4, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
127     StaticBoxSizer2->Add(BoxSizer9, 0, wxTOP|wxEXPAND, 5);
128     BoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
129     bDelAllItems = new wxBitmapButton(this, ID_IMAGEBUTTON4, wxNullBitmap, wxPoint(256,126), wxSize(24,23), wxBU_AUTODRAW, wxDefaultValidator, _T("ID_IMAGEBUTTON4"));
130     bDelAllItems->SetToolTip(_("Delete All Items"));
131     BoxSizer10->Add(bDelAllItems, 0, wxALIGN_BOTTOM, 5);
132     StaticText5 = new wxStaticText(this, ID_STATICTEXT5, _("Delete All Items"), wxPoint(290,130), wxDefaultSize, 0, _T("ID_STATICTEXT5"));
133     BoxSizer10->Add(StaticText5, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
134     StaticBoxSizer2->Add(BoxSizer10, 0, wxTOP|wxEXPAND, 5);
135     BoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
136     bItemColor = new wxButton(this, ID_BUTTON3, _("C"), wxPoint(256,156), wxSize(24,24), 0, wxDefaultValidator, _T("ID_BUTTON3"));
137     wxFont bItemColorFont(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial Black"),wxFONTENCODING_DEFAULT);
138     bItemColor->SetFont(bItemColorFont);
139     bItemColor->SetToolTip(_("Set Item Text Color"));
140     BoxSizer11->Add(bItemColor, 0, wxALIGN_BOTTOM, 5);
141     StaticText6 = new wxStaticText(this, ID_STATICTEXT6, _("Set Item Text Color"), wxPoint(290,160), wxDefaultSize, 0, _T("ID_STATICTEXT6"));
142     BoxSizer11->Add(StaticText6, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
143     StaticBoxSizer2->Add(BoxSizer11, 0, wxTOP|wxEXPAND, 5);
144     BoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
145     cxItemBold = new wxCheckBox(this, ID_CHECKBOX1, _(" Set Item Text Bold"), wxPoint(262,192), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
146     cxItemBold->SetValue(false);
147     cxItemBold->SetToolTip(_("Set Item Text Bold"));
148     BoxSizer12->Add(cxItemBold, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
149     StaticBoxSizer2->Add(BoxSizer12, 0, wxTOP|wxEXPAND, 5);
150     BoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
151     bEditItem = new wxBitmapButton(this, ID_IMAGEBUTTON5, wxNullBitmap, wxPoint(256,216), wxSize(24,23), wxBU_AUTODRAW, wxDefaultValidator, _T("ID_IMAGEBUTTON5"));
152     bEditItem->SetToolTip(_("Start Editor On Current Item"));
153     BoxSizer13->Add(bEditItem, 0, wxALIGN_BOTTOM, 5);
154     StaticText11 = new wxStaticText(this, ID_STATICTEXT11, _("Edit Current Item"), wxPoint(290,220), wxDefaultSize, 0, _T("ID_STATICTEXT11"));
155     BoxSizer13->Add(StaticText11, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
156     StaticBoxSizer2->Add(BoxSizer13, 0, wxTOP|wxEXPAND, 5);
157     GridSizer1 = new wxGridSizer(5, 2, 0, 0);
158     StaticText12 = new wxStaticText(this, ID_STATICTEXT12, _("Image-List"), wxPoint(256,272), wxDefaultSize, 0, _T("ID_STATICTEXT12"));
159     GridSizer1->Add(StaticText12, 0, wxALIGN_CENTER_VERTICAL, 5);
160     StaticText13 = new wxStaticText(this, ID_STATICTEXT13, _("Label"), wxPoint(310,272), wxSize(82,14), wxST_NO_AUTORESIZE, _T("ID_STATICTEXT13"));
161     StaticText13->SetForegroundColour(wxColour(0,0,255));
162     GridSizer1->Add(StaticText13, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
163     cbNormal = new wxBitmapComboBox(this, ID_COMBOBOX1, wxEmptyString, wxPoint(256,296), wxSize(48,22), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T("ID_COMBOBOX1"));
164     GridSizer1->Add(cbNormal, 0, wxTOP|wxEXPAND, 3);
165     StaticText7 = new wxStaticText(this, ID_STATICTEXT7, _("Normal Image"), wxPoint(310,300), wxDefaultSize, 0, _T("ID_STATICTEXT7"));
166     GridSizer1->Add(StaticText7, 0, wxTOP|wxLEFT|wxALIGN_CENTER_VERTICAL, 3);
167     cbSelected = new wxBitmapComboBox(this, ID_COMBOBOX2, wxEmptyString, wxPoint(256,326), wxSize(48,22), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T("ID_COMBOBOX2"));
168     GridSizer1->Add(cbSelected, 0, wxTOP|wxEXPAND, 3);
169     StaticText8 = new wxStaticText(this, ID_STATICTEXT8, _("Selected Image"), wxPoint(310,330), wxDefaultSize, 0, _T("ID_STATICTEXT8"));
170     GridSizer1->Add(StaticText8, 0, wxTOP|wxLEFT|wxALIGN_CENTER_VERTICAL, 3);
171     cbExpanded = new wxBitmapComboBox(this, ID_COMBOBOX3, wxEmptyString, wxPoint(256,356), wxSize(48,22), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T("ID_COMBOBOX3"));
172     GridSizer1->Add(cbExpanded, 0, wxTOP|wxEXPAND, 3);
173     StaticText9 = new wxStaticText(this, ID_STATICTEXT9, _("Expanded Image"), wxPoint(310,360), wxDefaultSize, 0, _T("ID_STATICTEXT9"));
174     GridSizer1->Add(StaticText9, 0, wxTOP|wxLEFT|wxALIGN_CENTER_VERTICAL, 3);
175     cbSelExpanded = new wxBitmapComboBox(this, ID_COMBOBOX4, wxEmptyString, wxPoint(256,386), wxSize(48,22), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T("ID_COMBOBOX4"));
176     GridSizer1->Add(cbSelExpanded, 0, wxTOP|wxEXPAND, 3);
177     StaticText10 = new wxStaticText(this, ID_STATICTEXT10, _("Sel+Exp Image"), wxPoint(310,390), wxDefaultSize, 0, _T("ID_STATICTEXT10"));
178     GridSizer1->Add(StaticText10, 0, wxTOP|wxLEFT|wxALIGN_CENTER_VERTICAL, 3);
179     StaticBoxSizer2->Add(GridSizer1, 0, wxTOP|wxALIGN_LEFT, 5);
180     BoxSizer6->Add(StaticBoxSizer2, 0, wxLEFT|wxEXPAND, 5);
181     BoxSizer3->Add(BoxSizer6, 0, wxALL|wxEXPAND, 0);
182     BoxSizer1->Add(BoxSizer3, 0, wxALL|wxEXPAND, 0);
183     BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
184     bOK = new wxButton(this, ID_BUTTON1, _("OK"), wxPoint(48,440), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
185     bOK->SetDefault();
186     BoxSizer4->Add(bOK, 0, wxALIGN_BOTTOM, 5);
187     BoxSizer4->Add(-1,-1,1, wxLEFT|wxEXPAND, 5);
188     bCancel = new wxButton(this, ID_BUTTON2, _("Cancel"), wxPoint(280,440), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
189     BoxSizer4->Add(bCancel, 0, wxLEFT|wxALIGN_BOTTOM, 5);
190     BoxSizer1->Add(BoxSizer4, 0, wxTOP|wxEXPAND, 0);
191     SetSizer(BoxSizer1);
192     static const char *ImageList1_0_XPM[] = {
193     "16 16 3 1",
194     ". c Black",
195     "X c #00C000",
196     "_ c None",
197     "________......._",
198     "________.XXXXX._",
199     "___..___.XXXXX._",
200     "___..___.XXXXX._",
201     "_......_.XXXXX._",
202     "_......_.XXXXX._",
203     "___..___.XXXXX._",
204     "___..___.XXXXX._",
205     "________.XXXXX._",
206     "________.XXXXX._",
207     "________.XXXXX._",
208     "________.XXXXX._",
209     "________.XX.XX._",
210     "________.X._.X._",
211     "________..___.._",
212     "................"
213     };
214     static const char *ImageList1_1_XPM[] = {
215     "16 16 4 1",
216     "o c Black",
217     ". c #000080",
218     "X c #0000FF",
219     "_ c None",
220     "________......._",
221     "________.XXXXX._",
222     "___oo___.XXXXX._",
223     "___oo___.XXXXX._",
224     "_oooooo_.XXXXX._",
225     "_oooooo_.XXXXX._",
226     "___oo___.XXXXX._",
227     "___oo___.XXXXX._",
228     "________.XXXXX._",
229     "________.XXXXX._",
230     "________.XXXXX._",
231     "________.XXXXX._",
232     "________.XX.XX._",
233     "________.X._.X._",
234     "________..___.._",
235     "oooooooooooooooo"
236     };
237     static const char *ImageList1_2_XPM[] = {
238     "16 16 3 1",
239     ". c Black",
240     "_ c None",
241     "X c #FF4040",
242     "________......._",
243     "________.XXXXX._",
244     "__.___._.XXXXX._",
245     "__.._.._.XXXXX._",
246     "___...__.XXXXX._",
247     "____.___.XXXXX._",
248     "___...__.XXXXX._",
249     "__.._.._.XXXXX._",
250     "__.___._.XXXXX._",
251     "________.XXXXX._",
252     "________.XXXXX._",
253     "________.XXXXX._",
254     "________.XX.XX._",
255     "________.X._.X._",
256     "________..___.._",
257     "................"
258     };
259     static const char *ImageList1_3_XPM[] = {
260     "16 16 22 1",
261     "4 c Black",
262     "3 c #A5AEBD",
263     "= c #5478B4",
264     "1 c #95A3BB",
265     "O c #9AA7BC",
266     ": c #758EB7",
267     "$ c #6986B6",
268     "# c #4971B2",
269     "* c #8A9CBA",
270     "X c #8598B9",
271     "o c #ABB2BE",
272     "; c #7F95B9",
273     "- c #4E74B3",
274     "2 c #A0ABBC",
275     "+ c #6F8AB7",
276     "_ c None",
277     ". c #B5B9BF",
278     "@ c #3E69B1",
279     "< c #90A0BA",
280     "> c #6483B5",
281     ", c #5A7BB4",
282     "& c #5F7FB5",
283     "________________",
284     "____.Xo______OO_",
285     "____+@#.____$@&_",
286     "____*@@X__.=@=o_",
287     "_____-@-_.=@=.__",
288     "_____;@@X=@=.___",
289     "_____.#@@@$.____",
290     "______:@@>______",
291     "_____:@@@+______",
292     "___.,@#&@@._____",
293     "__o=@=oO@@<_____",
294     "_1#@=._.@@-_____",
295     "*@@$____>@@2____",
296     ":#*_____3#,.____",
297     "________________",
298     "4444444444444444"
299     };
300     static const char *ImageList1_4_XPM[] = {
301     "16 16 2 1",
302     ". c Black",
303     "_ c None",
304     "________________",
305     "______..________",
306     "______..._______",
307     "_____...._______",
308     "_____._...______",
309     "____.._...______",
310     "____.___..______",
311     "___..___..._____",
312     "___._____.._____",
313     "___.........____",
314     "__.._____...____",
315     "__._______...___",
316     "_.._______...___",
317     "_....___......._",
318     "________________",
319     "................"
320     };
321     ImageList1 = new wxImageList(16, 16, 6);
322     ImageList1->Add(wxBitmap(ImageList1_0_XPM));
323     ImageList1->Add(wxBitmap(ImageList1_1_XPM));
324     ImageList1->Add(wxBitmap(ImageList1_2_XPM));
325     ImageList1->Add(wxBitmap(ImageList1_3_XPM));
326     ImageList1->Add(wxBitmap(ImageList1_4_XPM));
327     ColourDialog1 = new wxColourDialog(this);
328     BoxSizer1->Fit(this);
329     BoxSizer1->SetSizeHints(this);
330 
331     Connect(ID_TREECTRL1,wxEVT_COMMAND_TREE_SEL_CHANGED,wxTreeEventHandler(wxsImageTreeEditorDlg::OnTreeCtrl1SelectionChanged));
332     // Set the bitmaps for bAddItem.
333     bAddItem->SetBitmapLabel(ImageList1->GetBitmap(0));
334     Connect(ID_IMAGEBUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbAddItemClick));
335     // Set the bitmaps for bAddSubItem.
336     bAddSubItem->SetBitmapLabel(ImageList1->GetBitmap(1));
337     Connect(ID_IMAGEBUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbAddSubItemClick));
338     // Set the bitmaps for bDelItem.
339     bDelItem->SetBitmapLabel(ImageList1->GetBitmap(2));
340     Connect(ID_IMAGEBUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbDelItemClick));
341     // Set the bitmaps for bDelAllItems.
342     bDelAllItems->SetBitmapLabel(ImageList1->GetBitmap(3));
343     Connect(ID_IMAGEBUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbDelAllItemsClick));
344     Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbItemColorClick));
345     Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OncxItemBoldClick));
346     // Set the bitmaps for bEditItem.
347     bEditItem->SetBitmapLabel(ImageList1->GetBitmap(4));
348     Connect(ID_IMAGEBUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbEditItemClick));
349 
350     Connect(ID_COMBOBOX1,wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(wxsImageTreeEditorDlg::OncbNormalSelect));
351 
352     Connect(ID_COMBOBOX2,wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(wxsImageTreeEditorDlg::OncbSelectedSelect));
353 
354     Connect(ID_COMBOBOX3,wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(wxsImageTreeEditorDlg::OncbExpandedSelect));
355 
356     Connect(ID_COMBOBOX4,wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(wxsImageTreeEditorDlg::OncbSelExpandedSelect));
357     Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbOKClick));
358     Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxsImageTreeEditorDlg::OnbCancelClick));
359     //*)
360 }
361 
~wxsImageTreeEditorDlg()362 wxsImageTreeEditorDlg::~wxsImageTreeEditorDlg()
363 {
364     //(*Destroy(wxsImageTreeEditorDlg)
365     //*)
366 }
367 
368     /*! \brief Run the dialogue.
369      *
370      * \param aItems wxArrayString&
371      * \return bool
372      *
373      */
Execute(wxArrayString & aItems)374 bool wxsImageTreeEditorDlg::Execute(wxArrayString &aItems)
375 {
376     int             i, n;
377     int             jv, j1, j2, j3, j4;
378     wxColor         jc;
379     bool            jb;
380     wxString        jt;
381     wxTreeItemId    jp[32];
382 
383     wxString        ss, tt;
384     wxTreeItemId    root;
385     wxTreeItemId    item;
386     wxBitmap        bmp;
387     wxsImageList    *ilist;
388 
389 
390     // get name of combo-box and image-list
391     n = aItems.GetCount();
392     m_sTreeName  = _("<unknown>");
393     m_sImageName = _("<none>");
394     if(n >= 1){
395         m_sTreeName  = aItems.Item(0);
396     }
397     if(n >= 2){
398         m_sImageName = aItems.Item(1);
399     }
400 
401     // show the names
402     ss = _("Tree Control: ") + m_sTreeName;
403     StaticBoxSizer1->GetStaticBox()->SetLabel(ss);
404 
405     ss = m_sImageName;
406     StaticText13->SetLabel(ss);
407 
408     // clear old junk
409     Tree1->DeleteAllItems();
410 
411     // a valid image-list given?
412     m_imageList.RemoveAll();
413     ilist = (wxsImageList *) wxsImageListEditorDlg::FindTool(NULL, m_sImageName);
414     if(ilist != NULL){
415         ilist->GetImageList(m_imageList);
416     }
417     SetImageList(m_imageList);
418 
419     // add all the new items
420     n = aItems.GetCount();
421     for(i = 2; i < n; i++){
422         ss = aItems.Item(i);
423         ParseTreeItem(ss, jv, jc, jb, j1, j2, j3, j4, jt);
424 
425         if(jv == 0){
426             item = Tree1->AddRoot(jt);
427         }
428         else{
429             item = Tree1->AppendItem(jp[jv-1], jt);
430         }
431         jp[jv] = item;
432 
433         if(jc.IsOk()){
434             Tree1->SetItemTextColour(item, jc);
435         }
436         Tree1->SetItemBold(item, jb);
437         Tree1->SetItemImage(item, j1, wxTreeItemIcon_Normal);
438         Tree1->SetItemImage(item, j2, wxTreeItemIcon_Selected);
439         Tree1->SetItemImage(item, j3, wxTreeItemIcon_Expanded);
440         Tree1->SetItemImage(item, j4, wxTreeItemIcon_SelectedExpanded);
441     }
442 
443     Tree1->ExpandAll();
444 
445     // show the dialog and wait for a response
446     n = ShowModal();
447 
448     // save all new stuff?
449     if(n == wxOK){
450         // must save combo-box name and image-list name
451         aItems.Clear();
452         aItems.Add(m_sTreeName);
453         aItems.Add(m_sImageName);
454 
455         // save the root item and all it's children
456         // this effectively saves every item in the tree
457         // I wanted to use a simple loop here, but it works MUCH easier with a recursive function
458         root = Tree1->GetRootItem();
459         if(root.IsOk()){
460             EncodeTreeItems(root, 0, aItems);
461         }
462     }
463 
464     // done
465     return (n == wxOK);
466 }
467 
468 /*! \brief Set the image list.
469  *
470  * \param inImageList wxImageList&
471  * \return void
472  *
473  */
SetImageList(wxImageList & inImageList)474 void    wxsImageTreeEditorDlg::SetImageList(wxImageList &inImageList)
475 {
476     int         i, n;
477     wxString    ss, tt;
478     wxBitmap    bmp;
479 
480     // save the image list in the tree control
481     Tree1->SetImageList(&inImageList);
482 
483     // valid list given?
484     n = inImageList.GetImageCount();
485     if(n <= 0){
486         cbNormal->Enable(false);
487         cbSelected->Enable(false);
488         cbExpanded->Enable(false);
489         cbSelExpanded->Enable(false);
490     }
491     else {
492         cbNormal->Enable(true);
493         cbSelected->Enable(true);
494         cbExpanded->Enable(true);
495         cbSelExpanded->Enable(true);
496     }
497 
498     // set images in the drop-down lists
499     cbNormal->Clear();
500     cbSelected->Clear();
501     cbExpanded->Clear();
502     cbSelExpanded->Clear();
503 
504     ss = _("<none>");
505     cbNormal->Append(ss);
506     cbSelected->Append(ss);
507     cbExpanded->Append(ss);
508     cbSelExpanded->Append(ss);
509 
510     for(i = 0; i < n; i++){
511         ss.Printf(wxT("%d"), i);
512         bmp = inImageList.GetBitmap(i);
513 
514         cbNormal->Append(ss, bmp);
515         cbSelected->Append(ss, bmp);
516         cbExpanded->Append(ss, bmp);
517         cbSelExpanded->Append(ss, bmp);
518     }
519 
520     // default selections
521     cbNormal->SetSelection(0);
522     cbSelected->SetSelection(0);
523     cbExpanded->SetSelection(0);
524     cbSelExpanded->SetSelection(0);
525 }
526 
527 /*! \brief Add a new item as a sibling of the current item.
528  *
529  * \param event wxCommandEvent&
530  * \return void
531  *
532  */
OnbAddItemClick(cb_unused wxCommandEvent & event)533 void wxsImageTreeEditorDlg::OnbAddItemClick(cb_unused wxCommandEvent &event)
534 {
535     int             n;
536     wxTreeItemId    current;
537 
538     // how many items?
539     n = Tree1->GetCount();
540 
541     // and current selection
542     current = Tree1->GetSelection();
543 
544     // add a root item?
545     if(n <= 0){
546         current.Unset();
547         AddItem(current);
548     }
549     // no current item?
550     else if(! current.IsOk()){
551         current = Tree1->GetRootItem();
552         AddItem(current);
553     }
554     // else a sibling
555     else {
556         current = Tree1->GetItemParent(current);
557         AddItem(current);
558     }
559 }
560 
561 /*! \brief Add a new item as a child of the current item.
562  *
563  * \param event wxCommandEvent&
564  * \return void
565  *
566  */
OnbAddSubItemClick(cb_unused wxCommandEvent & event)567 void wxsImageTreeEditorDlg::OnbAddSubItemClick(cb_unused wxCommandEvent &event)
568 {
569     int             n;
570     wxTreeItemId    current;
571 
572     // how many items?
573     n = Tree1->GetCount();
574 
575     // and current selection
576     current = Tree1->GetSelection();
577 
578     // add a root item?
579     if(n <= 0){
580         current.Unset();
581         AddItem(current);
582     }
583     // no current item?
584     else if(! current.IsOk()){
585         current = Tree1->GetRootItem();
586         AddItem(current);
587     }
588     // else a child
589     else {
590         AddItem(current);
591     }
592 
593     // make sure it is expanded
594     Tree1->Expand(current);
595 }
596 
597 /*! \brief Add a new item to the tree.
598  *
599  * \param inParent wxTreeItemId&
600  * \return void
601  *
602  */
AddItem(wxTreeItemId & inParent)603 void wxsImageTreeEditorDlg::AddItem(wxTreeItemId &inParent){
604     int             n;
605     wxString        ss, tt;
606     wxTreeItemId    parent, current;
607     wxColour        cc;
608     bool            b;
609 
610     // how many items?
611     n = Tree1->GetCount();
612 
613     // add a root item?
614     if(n <= 0){
615         ss = _("root");
616         current = Tree1->AddRoot(ss);
617     }
618 
619     // bad parent?
620     else if(! inParent.IsOk()){
621         ss.Printf(_("item %d"), n);
622         parent = Tree1->GetRootItem();
623         current = Tree1->AppendItem(parent, ss);
624     }
625     // else a child of whatever
626     else {
627         ss.Printf(_("item %d"), n);
628         current = Tree1->AppendItem(inParent, ss);
629     }
630 
631     // if it failed, skip the rest of this
632     if(! current.IsOk()){
633         return;
634     }
635 
636     // set text colour
637     cc = bItemColor->GetForegroundColour();
638     Tree1->SetItemTextColour(current, cc);
639 
640     // bold or plain
641     b = cxItemBold->GetValue();
642     Tree1->SetItemBold(current, b);
643 
644     // the images
645     n = cbNormal->GetSelection() - 1;
646     if(n >= 0){
647         Tree1->SetItemImage(current, n, wxTreeItemIcon_Normal);
648     }
649 
650     n = cbSelected->GetSelection() - 1;
651     if(n >= 0){
652         Tree1->SetItemImage(current, n, wxTreeItemIcon_Selected);
653     }
654 
655     n = cbExpanded->GetSelection() - 1;
656     if(n >= 0){
657         Tree1->SetItemImage(current, n, wxTreeItemIcon_Expanded);
658     }
659 
660     n = cbSelExpanded->GetSelection() - 1;
661     if(n >= 0){
662         Tree1->SetItemImage(current, n, wxTreeItemIcon_SelectedExpanded);
663     }
664 
665     // redraw the whole thing
666     Tree1->Refresh();
667 }
668 
669 /*! \brief Delete a tree item.
670  *
671  * \param event wxCommandEvent&
672  * \return void
673  *
674  */
OnbDelItemClick(cb_unused wxCommandEvent & event)675 void wxsImageTreeEditorDlg::OnbDelItemClick(cb_unused wxCommandEvent &event)
676 {
677     wxTreeItemId    current;
678 
679     // current selection
680     current = Tree1->GetSelection();
681 
682     // delete it
683     if(current.IsOk()){
684         Tree1->Delete(current);
685     }
686 }
687 
688 /*! \brief Delete all tree items.
689  *
690  * \param event wxCommandEvent&
691  * \return void
692  *
693  */
OnbDelAllItemsClick(cb_unused wxCommandEvent & event)694 void wxsImageTreeEditorDlg::OnbDelAllItemsClick(cb_unused wxCommandEvent &event)
695 {
696     int         n;
697     wxString    ss;
698 
699     n = wxMessageBox(_("Delete ALL Items In Tree?"), _("Clear"), wxYES_NO);
700     if(n == wxYES){
701         Tree1->DeleteAllItems();
702     }
703 }
704 
705 /*! \brief Select the item's colour.
706  *
707  * \param event wxCommandEvent&
708  * \return void
709  *
710  */
OnbItemColorClick(cb_unused wxCommandEvent & event)711 void wxsImageTreeEditorDlg::OnbItemColorClick(cb_unused wxCommandEvent &event)
712 {
713     int             n;
714     wxColourData    cd;
715     wxColour        cc;
716     wxTreeItemId    current;
717 
718     // ask user for a new color
719     n = ColourDialog1->ShowModal();
720     if(n != wxID_OK){
721         return;
722     }
723 
724     // get the color
725     cd = ColourDialog1->GetColourData();
726     cc = cd.GetColour();
727 
728     // set the button text
729     bItemColor->SetForegroundColour(cc);
730 
731     // and the current item
732     current = Tree1->GetSelection();
733     if(current.IsOk()){
734         Tree1->SetItemTextColour(current, cc);
735     }
736 }
737 
738 /*! \brief Make the item text bold.
739  *
740  * \param event wxCommandEvent&
741  * \return void
742  *
743  */
OncxItemBoldClick(cb_unused wxCommandEvent & event)744 void wxsImageTreeEditorDlg::OncxItemBoldClick(cb_unused wxCommandEvent &event)
745 {
746     bool            b;
747     wxTreeItemId    current;
748 
749     // get checkbox value
750     b = cxItemBold->GetValue();
751 
752     // and set the current item
753     current = Tree1->GetSelection();
754     if(current.IsOk()){
755         Tree1->SetItemBold(current, b);
756     }
757 }
758 
759 /*! \brief Edit an item.
760  *
761  * \param event wxCommandEvent&
762  * \return void
763  *
764  */
OnbEditItemClick(cb_unused wxCommandEvent & event)765 void wxsImageTreeEditorDlg::OnbEditItemClick(cb_unused wxCommandEvent &event)
766 {
767     wxTreeItemId    current;
768 
769     // current selection
770     current = Tree1->GetSelection();
771 
772     // delete it
773     if(current.IsOk()){
774         Tree1->EditLabel(current);
775     }
776 }
777 
778 /*! \brief Select the normal state image.
779  *
780  * \param event wxCommandEvent&
781  * \return void
782  *
783  */
OncbNormalSelect(cb_unused wxCommandEvent & event)784 void wxsImageTreeEditorDlg::OncbNormalSelect(cb_unused wxCommandEvent &event)
785 {
786     int             n;
787     wxTreeItemId    current;
788 
789     n  = cbNormal->GetSelection();
790     n -= 1;
791 
792     current = Tree1->GetSelection();
793     if(current.IsOk()){
794         Tree1->SetItemImage(current, n, wxTreeItemIcon_Normal);
795     }
796 }
797 
798 /*! \brief Select the selected state image.
799  *
800  * \param event wxCommandEvent&
801  * \return void
802  *
803  */
OncbSelectedSelect(cb_unused wxCommandEvent & event)804 void wxsImageTreeEditorDlg::OncbSelectedSelect(cb_unused wxCommandEvent &event)
805 {
806     int             n;
807     wxTreeItemId    current;
808 
809     n  = cbSelected->GetSelection();
810     n -= 1;
811 
812     current = Tree1->GetSelection();
813     if(current.IsOk()){
814         Tree1->SetItemImage(current, n, wxTreeItemIcon_Selected);
815     }
816 }
817 
818 /*! \brief Select the expanded state image.
819  *
820  * \param event wxCommandEvent&
821  * \return void
822  *
823  */
OncbExpandedSelect(cb_unused wxCommandEvent & event)824 void wxsImageTreeEditorDlg::OncbExpandedSelect(cb_unused wxCommandEvent &event)
825 {
826     int             n;
827     wxTreeItemId    current;
828 
829     n  = cbExpanded->GetSelection();
830     n -= 1;
831 
832     current = Tree1->GetSelection();
833     if(current.IsOk()){
834         Tree1->SetItemImage(current, n, wxTreeItemIcon_Expanded);
835     }
836 }
837 
838 /*! \brief Select the selected and expanded state image.
839  *
840  * \param event wxCommandEvent&
841  * \return void
842  *
843  */
OncbSelExpandedSelect(cb_unused wxCommandEvent & event)844 void wxsImageTreeEditorDlg::OncbSelExpandedSelect(cb_unused wxCommandEvent &event)
845 {
846     int             n;
847     wxTreeItemId    current;
848 
849     n  = cbSelExpanded->GetSelection();
850     n -= 1;
851 
852     current = Tree1->GetSelection();
853     if(current.IsOk()){
854         Tree1->SetItemImage(current, n, wxTreeItemIcon_SelectedExpanded);
855     }
856 }
857 
858 /*! \brief The tree item selection was changed.
859  *
860  * \param event wxTreeEvent&
861  * \return void
862  *
863  */
OnTreeCtrl1SelectionChanged(cb_unused wxTreeEvent & event)864 void wxsImageTreeEditorDlg::OnTreeCtrl1SelectionChanged(cb_unused wxTreeEvent &event)
865 {
866     int             n;
867     wxTreeItemId    current;
868     wxColour        cc;
869     bool            b;
870 
871     // get current item
872     current = Tree1->GetSelection();
873     if(! current.IsOk()){
874         return;
875     }
876 
877     // current text colour
878     cc = Tree1->GetItemTextColour(current);
879     bItemColor->SetForegroundColour(cc);
880 
881     // bold or plain
882     b = Tree1->IsBold(current);
883     cxItemBold->SetValue(b);
884 
885     // image indices
886     n = Tree1->GetItemImage(current, wxTreeItemIcon_Normal);
887     n += 1;
888     cbNormal->SetSelection(n);
889 
890     n = Tree1->GetItemImage(current, wxTreeItemIcon_Selected);
891     n += 1;
892     cbSelected->SetSelection(n);
893 
894     n = Tree1->GetItemImage(current, wxTreeItemIcon_Expanded);
895     n += 1;
896     cbExpanded->SetSelection(n);
897 
898     n = Tree1->GetItemImage(current, wxTreeItemIcon_SelectedExpanded);
899     n += 1;
900     cbSelExpanded->SetSelection(n);
901 }
902 
903 /*! \brief Parse tree item text.
904  *
905  * \param aSource wxString
906  * \param outLevel int&
907  * \param outColour wxColour&
908  * \param outBold bool&
909  * \param outImage1 int&
910  * \param outImage2 int&
911  * \param outImage3 int&
912  * \param outImage4 int&
913  * \param outText wxString&
914  * \return void
915  *
916  */
ParseTreeItem(wxString aSource,int & outLevel,wxColour & outColour,bool & outBold,int & outImage1,int & outImage2,int & outImage3,int & outImage4,wxString & outText)917 void wxsImageTreeEditorDlg::ParseTreeItem(wxString aSource, int &outLevel, wxColour &outColour, bool &outBold, int &outImage1, int &outImage2, int &outImage3, int &outImage4, wxString &outText)
918 {
919     int         i, n;
920     long        ll;
921     wxString    ss, tt;
922 
923     // working copy
924     ss = aSource;
925 
926     // the depth level
927     outLevel = 1;
928     i  = ss.Find(wxT(","));
929     if(i != wxNOT_FOUND){
930         tt = ss.Left(i);
931         ss.erase(0, i + 1);
932         if(tt.ToLong(&ll)) outLevel = ll;
933     }
934 
935     // the color
936     outColour.Set(wxT("?"));
937     i  = ss.Find(wxT(","));
938     if(i != wxNOT_FOUND){
939         tt = ss.Left(i);
940         ss.erase(0, i + 1);
941         outColour.Set(tt);
942     }
943 
944     // bold or normal text
945     n = 0;
946     i  = ss.Find(wxT(","));
947     if(i != wxNOT_FOUND){
948         tt = ss.Left(i);
949         ss.erase(0, i + 1);
950         if(tt.ToLong(&ll)){
951             n = ll;
952         }
953     }
954     outBold = (n != 0);
955 
956     // 4 image indices
957     outImage1 = -1;
958     i  = ss.Find(wxT(","));
959     if(i != wxNOT_FOUND){
960         tt = ss.Left(i);
961         ss.erase(0, i + 1);
962         if(tt.ToLong(&ll)){
963             outImage1 = ll;
964         }
965     }
966 
967     outImage2 = -1;
968     i  = ss.Find(wxT(","));
969     if(i != wxNOT_FOUND){
970         tt = ss.Left(i);
971         ss.erase(0, i + 1);
972         if(tt.ToLong(&ll)){
973             outImage2 = ll;
974         }
975     }
976 
977     outImage3 = -1;
978     i  = ss.Find(wxT(","));
979     if(i != wxNOT_FOUND){
980         tt = ss.Left(i);
981         ss.erase(0, i + 1);
982         if(tt.ToLong(&ll)){
983             outImage3 = ll;
984         }
985     }
986 
987     outImage4 = -1;
988     i  = ss.Find(wxT(","));
989     if(i != wxNOT_FOUND){
990         tt = ss.Left(i);
991         ss.erase(0, i + 1);
992         if(tt.ToLong(&ll)){
993             outImage4 = ll;
994         }
995     }
996 
997     // everything else is the text
998     ss.Trim(true);
999     ss.Trim(false);
1000     outText = ss;
1001 }
1002 
1003 /*! \brief Encode tree item text.
1004  *
1005  * \param inParent wxTreeItemId
1006  * \param inLevel int
1007  * \param outList wxArrayString&
1008  * \return void
1009  *
1010  */
EncodeTreeItems(wxTreeItemId inParent,int inLevel,wxArrayString & outList)1011 void wxsImageTreeEditorDlg::EncodeTreeItems(wxTreeItemId inParent, int inLevel, wxArrayString &outList)
1012 {
1013     int                 n;
1014     wxColour            cc;
1015     wxString            ss, tt;
1016     wxTreeItemId        child;
1017     wxTreeItemIdValue   cookie;
1018 
1019     // nothing yet
1020     ss = wxEmptyString;
1021 
1022     // start with this item
1023     tt.Printf(wxT("%d,"), inLevel);
1024     ss += tt;
1025 
1026     cc  = Tree1->GetItemTextColour(inParent);
1027     tt  = cc.GetAsString(wxC2S_HTML_SYNTAX);
1028     tt += wxT(",");
1029     ss += tt;
1030 
1031     if(Tree1->IsBold(inParent)){
1032         tt = wxT("1,");
1033     }
1034     else{
1035         tt = wxT("0,");
1036     }
1037     ss += tt;
1038 
1039     n = Tree1->GetItemImage(inParent, wxTreeItemIcon_Normal);
1040     tt.Printf(wxT("%d,"), n);
1041     ss += tt;
1042 
1043     n = Tree1->GetItemImage(inParent, wxTreeItemIcon_Selected);
1044     tt.Printf(wxT("%d,"), n);
1045     ss += tt;
1046 
1047     n = Tree1->GetItemImage(inParent, wxTreeItemIcon_Expanded);
1048     tt.Printf(wxT("%d,"), n);
1049     ss += tt;
1050 
1051     n = Tree1->GetItemImage(inParent, wxTreeItemIcon_SelectedExpanded);
1052     tt.Printf(wxT("%d,"), n);
1053     ss += tt;
1054 
1055     tt = Tree1->GetItemText(inParent);
1056     ss += tt;
1057 
1058     // save it
1059     outList.Add(ss);
1060 
1061     // and all the children
1062     child = Tree1->GetFirstChild(inParent, cookie);
1063     while(child.IsOk()){
1064         EncodeTreeItems(child, inLevel + 1, outList);
1065         child = Tree1->GetNextChild(inParent, cookie);
1066     }
1067 }
1068 
1069 /*! \brief The OK button was clicked.
1070  *
1071  * \param event wxCommandEvent&
1072  * \return void
1073  *
1074  */
OnbOKClick(cb_unused wxCommandEvent & event)1075 void wxsImageTreeEditorDlg::OnbOKClick(cb_unused wxCommandEvent &event)
1076 {
1077     EndModal(wxOK);
1078 }
1079 
1080 /*! \brief The Cancel button was clicked.
1081  *
1082  * \param event wxCommandEvent&
1083  * \return void
1084  *
1085  */
OnbCancelClick(cb_unused wxCommandEvent & event)1086 void wxsImageTreeEditorDlg::OnbCancelClick(cb_unused wxCommandEvent &event)
1087 {
1088     EndModal(wxCANCEL);
1089 }
1090