]>
Commit | Line | Data |
---|---|---|
d7463f75 JS |
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 | ||
71ada1a5 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
f8105809 | 13 | #pragma implementation "configitemselector.h" |
d7463f75 JS |
14 | #endif |
15 | ||
d9ab621e | 16 | // For compilers that support precompilation, includes "wx/wx.h". |
696e113b WS |
17 | #include "wx/wxprec.h" |
18 | ||
19 | #ifdef __BORLANDC__ | |
d9ab621e | 20 | #pragma hdrstop |
696e113b WS |
21 | #endif |
22 | ||
23 | #ifndef WX_PRECOMP | |
696e113b | 24 | |
d9ab621e WS |
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 | |
d7463f75 | 32 | |
d9ab621e WS |
33 | #include "wx/cshelp.h" |
34 | #include "wx/notebook.h" | |
35 | #include "wx/valgen.h" | |
d7463f75 JS |
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 | ||
d9ab621e | 75 | ctConfigItemsSelector::ctConfigItemsSelector( wxWindow* parent, wxWindowID id, const wxString& caption) |
d7463f75 | 76 | { |
d9ab621e | 77 | wxDialog::Create( parent, id, caption); |
d7463f75 JS |
78 | |
79 | CreateControls(); | |
80 | InitSourceConfigList(); | |
81 | } | |
82 | ||
83 | /*! | |
84 | * Control creation for ctConfigItemsSelector | |
85 | */ | |
86 | ||
87 | void ctConfigItemsSelector::CreateControls() | |
dabbc6a5 | 88 | { |
d7463f75 JS |
89 | ////@begin ctConfigItemsSelector content construction |
90 | ||
91 | ctConfigItemsSelector* item1 = this; | |
92 | ||
93 | wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL); | |
94 | item1->SetSizer(item2); | |
d7463f75 JS |
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; | |
422d0ff0 | 106 | wxListBox* item6 = new wxListBox(item1, ID_AVAILABLE_CONFIG_ITEMS, wxDefaultPosition, wxSize(wxDefaultCoord, 150), 0, item6Strings, wxLB_SINGLE|wxLB_SORT); |
d7463f75 JS |
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; | |
422d0ff0 | 116 | wxListBox* item9 = new wxListBox(item1, ID_CONFIG_ITEMS, wxDefaultPosition, wxSize(wxDefaultCoord, 100), 0, item9Strings, wxLB_SINGLE); |
d7463f75 JS |
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 | ||
677ded95 | 133 | wxButton* item15 = new wxButton(item1, wxID_OK); |
d7463f75 JS |
134 | item15->SetDefault(); |
135 | item13->Add(item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
136 | ||
677ded95 | 137 | wxButton* item16 = new wxButton(item1, wxID_CANCEL); |
d7463f75 JS |
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 | ||
69da0d99 | 150 | void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent& WXUNUSED(event) ) |
d7463f75 JS |
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 | ||
69da0d99 | 172 | void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent& WXUNUSED(event) ) |
d7463f75 JS |
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 | { | |
4fe30bce | 202 | return true; |
d7463f75 JS |
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 | ||
4fe30bce | 234 | bool addIt = false; |
d7463f75 JS |
235 | |
236 | if (item->GetType() == ctTypeGroup) | |
4fe30bce | 237 | addIt = false; |
d7463f75 | 238 | else if (item->GetType() == ctTypeCheckGroup) |
4fe30bce | 239 | addIt = true; |
d7463f75 | 240 | else if (item->GetType() == ctTypeRadioGroup) |
4fe30bce | 241 | addIt = true; |
d7463f75 | 242 | else if (item->GetType() == ctTypeString) |
4fe30bce | 243 | addIt = true; |
d7463f75 | 244 | else if (item->GetType() == ctTypeBoolCheck) |
4fe30bce | 245 | addIt = true; |
d7463f75 | 246 | else if (item->GetType() == ctTypeBoolRadio) |
4fe30bce | 247 | addIt = true; |
d7463f75 | 248 | else if (item->GetType() == ctTypeInteger) |
4fe30bce | 249 | addIt = true; |
d7463f75 JS |
250 | if (addIt) |
251 | { | |
252 | masterList->Append(item->GetName()); | |
253 | } | |
254 | ||
d9ab621e | 255 | wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); |
d7463f75 JS |
256 | while (node) |
257 | { | |
258 | ctConfigItem* child = (ctConfigItem*) node->GetData(); | |
259 | InitSourceConfigList(child); | |
260 | ||
ddc4f3b5 | 261 | node = node->GetNext(); |
d7463f75 JS |
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 |