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