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