]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/configitemselector.cpp
removed SetAutoLayout(true) calls when a corresponding SetSizer() was also called...
[wxWidgets.git] / utils / configtool / src / configitemselector.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configitemselector.cpp
3 // Purpose: Selector for one or more config items
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-04
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "configitemselector.h"
14 #endif
15
16 #include <wx/wx.h>
17 #include <wx/cshelp.h>
18 #include <wx/statline.h>
19 #include <wx/splitter.h>
20 #include <wx/scrolwin.h>
21 #include <wx/spinctrl.h>
22 #include <wx/spinbutt.h>
23 #include <wx/valgen.h>
24
25 #include "configitemselector.h"
26 #include "configtooldoc.h"
27 #include "configtoolview.h"
28 #include "configitem.h"
29 #include "mainframe.h"
30 #include "wxconfigtool.h"
31
32 ////@begin XPM images
33 ////@end XPM images
34
35 /*!
36 * ctConfigItemsSelector type definition
37 */
38
39 IMPLEMENT_CLASS( ctConfigItemsSelector, wxDialog )
40
41 /*!
42 * ctConfigItemsSelector event table definition
43 */
44
45 BEGIN_EVENT_TABLE( ctConfigItemsSelector, wxDialog )
46
47 ////@begin ctConfigItemsSelector event table entries
48 EVT_BUTTON( ID_CONFIG_ADD, ctConfigItemsSelector::OnConfigAdd )
49 EVT_UPDATE_UI( ID_CONFIG_ADD, ctConfigItemsSelector::OnUpdateConfigAdd )
50
51 EVT_BUTTON( ID_CONFIG_REMOVE, ctConfigItemsSelector::OnConfigRemove )
52 EVT_UPDATE_UI( ID_CONFIG_REMOVE, ctConfigItemsSelector::OnUpdateConfigRemove )
53
54 EVT_BUTTON( wxID_OK, ctConfigItemsSelector::OnOk )
55
56 ////@end ctConfigItemsSelector event table entries
57
58 END_EVENT_TABLE()
59
60 /*!
61 * ctConfigItemsSelector constructor
62 */
63
64 ctConfigItemsSelector::ctConfigItemsSelector( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
65 {
66 wxDialog::Create( parent, id, caption, pos, size, style );
67
68 CreateControls();
69 InitSourceConfigList();
70 }
71
72 /*!
73 * Control creation for ctConfigItemsSelector
74 */
75
76 void ctConfigItemsSelector::CreateControls()
77 {
78 ////@begin ctConfigItemsSelector content construction
79
80 ctConfigItemsSelector* item1 = this;
81
82 wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL);
83 item1->SetSizer(item2);
84
85 wxBoxSizer* item3 = new wxBoxSizer(wxVERTICAL);
86 item2->Add(item3, 1, wxGROW|wxALL, 5);
87
88 wxStaticText* item4 = new wxStaticText(item1, wxID_STATIC, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition, wxDefaultSize, 0);
89 item3->Add(item4, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
90
91 wxStaticText* item5 = new wxStaticText(item1, wxID_STATIC, _("&Available items:"), wxDefaultPosition, wxDefaultSize, 0);
92 item3->Add(item5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
93
94 wxString* item6Strings = NULL;
95 wxListBox* item6 = new wxListBox(item1, ID_AVAILABLE_CONFIG_ITEMS, wxDefaultPosition, wxSize(wxDefaultSize.x, 150), 0, item6Strings, wxLB_SINGLE|wxLB_SORT);
96 item3->Add(item6, 1, wxGROW|wxALL, 5);
97
98 wxStaticText* item7 = new wxStaticText(item1, wxID_STATIC, _("&List of configuration items:"), wxDefaultPosition, wxDefaultSize, 0);
99 item3->Add(item7, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
100
101 wxBoxSizer* item8 = new wxBoxSizer(wxHORIZONTAL);
102 item3->Add(item8, 0, wxGROW, 5);
103
104 wxString* item9Strings = NULL;
105 wxListBox* item9 = new wxListBox(item1, ID_CONFIG_ITEMS, wxDefaultPosition, wxSize(wxDefaultSize.x, 100), 0, item9Strings, wxLB_SINGLE);
106 item8->Add(item9, 1, wxGROW|wxALL, 5);
107
108 wxBoxSizer* item10 = new wxBoxSizer(wxVERTICAL);
109 item8->Add(item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
110
111 wxButton* item11 = new wxButton(item1, ID_CONFIG_ADD, _("A&dd"), wxDefaultPosition, wxDefaultSize, 0);
112 item10->Add(item11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
113
114 wxButton* item12 = new wxButton(item1, ID_CONFIG_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0);
115 item10->Add(item12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
116
117 wxBoxSizer* item13 = new wxBoxSizer(wxHORIZONTAL);
118 item3->Add(item13, 0, wxGROW, 5);
119
120 item13->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
121
122 wxButton* item15 = new wxButton(item1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0);
123 item15->SetDefault();
124 item13->Add(item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
125
126 wxButton* item16 = new wxButton(item1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0);
127 item13->Add(item16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
128
129 GetSizer()->Fit(this);
130 GetSizer()->SetSizeHints(this);
131 Centre();
132 ////@end ctConfigItemsSelector content construction
133 }
134
135 /*!
136 * Event handler for ID_CONFIG_ADD
137 */
138
139 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent& WXUNUSED(event) )
140 {
141 wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox);
142 wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox);
143 if (masterList)
144 {
145 if (masterList->GetSelection() > -1)
146 {
147 wxString str = masterList->GetStringSelection();
148 if (m_configItems.Index(str) == wxNOT_FOUND)
149 {
150 listBox->Append(str);
151 m_configItems.Add(str);
152 }
153 }
154 }
155 }
156
157 /*!
158 * Event handler for ID_CONFIG_REMOVE
159 */
160
161 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent& WXUNUSED(event) )
162 {
163 wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox);
164 if (listBox)
165 {
166 if (listBox->GetSelection() > -1)
167 {
168 wxString str = listBox->GetStringSelection();
169 listBox->Delete(listBox->GetSelection());
170 m_configItems.Remove(str);
171 }
172 }
173 }
174
175 /*!
176 * Event handler for wxID_OK
177 */
178
179 void ctConfigItemsSelector::OnOk( wxCommandEvent& event )
180 {
181 // Replace with custom code
182 event.Skip();
183 }
184
185 /*!
186 * Should we show tooltips?
187 */
188
189 bool ctConfigItemsSelector::ShowToolTips()
190 {
191 return true;
192 }
193 /*!
194 * Update event handler for ID_CONFIG_ADD
195 */
196
197 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent& event )
198 {
199 wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox);
200 event.Enable(masterList && masterList->GetSelection() != -1);
201 }
202
203 /*!
204 * Update event handler for ID_CONFIG_REMOVE
205 */
206
207 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent& event )
208 {
209 wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox);
210 event.Enable(listBox && listBox->GetSelection() != -1);
211 }
212
213 /// Initialise the master list
214 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem* item)
215 {
216 wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox);
217 if (!item)
218 item = wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
219
220 if (!item)
221 return;
222
223 bool addIt = false;
224
225 if (item->GetType() == ctTypeGroup)
226 addIt = false;
227 else if (item->GetType() == ctTypeCheckGroup)
228 addIt = true;
229 else if (item->GetType() == ctTypeRadioGroup)
230 addIt = true;
231 else if (item->GetType() == ctTypeString)
232 addIt = true;
233 else if (item->GetType() == ctTypeBoolCheck)
234 addIt = true;
235 else if (item->GetType() == ctTypeBoolRadio)
236 addIt = true;
237 else if (item->GetType() == ctTypeInteger)
238 addIt = true;
239 if (addIt)
240 {
241 masterList->Append(item->GetName());
242 }
243
244 wxNode* node = item->GetChildren().GetFirst();
245 while (node)
246 {
247 ctConfigItem* child = (ctConfigItem*) node->GetData();
248 InitSourceConfigList(child);
249
250 node = node->GetNext();
251 }
252 }
253
254 /// Set the initial list
255 void ctConfigItemsSelector::SetConfigList(const wxArrayString& items)
256 {
257 m_configItems = items;
258 wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox);
259 listBox->Clear();
260
261 size_t i;
262 for (i = 0; i < items.GetCount(); i++)
263 listBox->Append(items[i]);
264 }
265