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