]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
3 | // Name: combobox.cpp |
4 | // Purpose: Part of the widgets sample showing wxComboBox | |
5 | // Author: Vadim Zeitlin | |
6 | // Created: 27.03.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
526954c5 | 9 | // Licence: wxWindows licence |
32b8ec41 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
3379ed37 VZ |
27 | #if wxUSE_COMBOBOX |
28 | ||
32b8ec41 VZ |
29 | // for all others, include the necessary headers |
30 | #ifndef WX_PRECOMP | |
31 | #include "wx/log.h" | |
32 | ||
3bb70c40 | 33 | #include "wx/bitmap.h" |
32b8ec41 VZ |
34 | #include "wx/button.h" |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/combobox.h" | |
37 | #include "wx/radiobox.h" | |
38 | #include "wx/statbox.h" | |
39 | #include "wx/textctrl.h" | |
40 | #endif | |
41 | ||
42 | #include "wx/sizer.h" | |
43 | ||
a236aa20 | 44 | #include "itemcontainer.h" |
32b8ec41 | 45 | #include "widgets.h" |
32b8ec41 VZ |
46 | #include "icons/combobox.xpm" |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // constants | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // control ids | |
53 | enum | |
54 | { | |
f0fa4312 | 55 | ComboPage_Reset = wxID_HIGHEST, |
d1d1f817 VZ |
56 | ComboPage_Popup, |
57 | ComboPage_Dismiss, | |
90576c50 | 58 | ComboPage_SetCurrent, |
32b8ec41 | 59 | ComboPage_CurText, |
9849a944 | 60 | ComboPage_InsertionPointText, |
243dbf1a VZ |
61 | ComboPage_Insert, |
62 | ComboPage_InsertText, | |
32b8ec41 VZ |
63 | ComboPage_Add, |
64 | ComboPage_AddText, | |
65 | ComboPage_AddSeveral, | |
66 | ComboPage_AddMany, | |
67 | ComboPage_Clear, | |
68 | ComboPage_Change, | |
69 | ComboPage_ChangeText, | |
70 | ComboPage_Delete, | |
71 | ComboPage_DeleteText, | |
72 | ComboPage_DeleteSel, | |
21dd7c5b RR |
73 | ComboPage_SetValue, |
74 | ComboPage_SetValueText, | |
a236aa20 VZ |
75 | ComboPage_Combo, |
76 | ComboPage_ContainerTests | |
32b8ec41 VZ |
77 | }; |
78 | ||
79 | // kinds of comboboxes | |
80 | enum | |
81 | { | |
82 | ComboKind_Default, | |
83 | ComboKind_Simple, | |
84 | ComboKind_DropDown | |
85 | }; | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // ComboboxWidgetsPage | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
a236aa20 | 91 | class ComboboxWidgetsPage : public ItemContainerWidgetsPage |
32b8ec41 VZ |
92 | { |
93 | public: | |
f2fdc4d5 | 94 | ComboboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); |
32b8ec41 | 95 | |
195df7a7 | 96 | virtual wxControl *GetWidget() const { return m_combobox; } |
6a8d7937 | 97 | virtual wxTextEntryBase *GetTextEntry() const { return m_combobox; } |
a236aa20 | 98 | virtual wxItemContainer* GetContainer() const { return m_combobox; } |
1301e228 | 99 | virtual void RecreateWidget() { CreateCombo(); } |
195df7a7 | 100 | |
453535a7 WS |
101 | // lazy creation of the content |
102 | virtual void CreateContent(); | |
103 | ||
32b8ec41 VZ |
104 | protected: |
105 | // event handlers | |
106 | void OnButtonReset(wxCommandEvent& event); | |
d1d1f817 VZ |
107 | void OnButtonPopup(wxCommandEvent&) { m_combobox->Popup(); } |
108 | void OnButtonDismiss(wxCommandEvent&) { m_combobox->Dismiss(); } | |
32b8ec41 VZ |
109 | void OnButtonChange(wxCommandEvent& event); |
110 | void OnButtonDelete(wxCommandEvent& event); | |
111 | void OnButtonDeleteSel(wxCommandEvent& event); | |
112 | void OnButtonClear(wxCommandEvent& event); | |
243dbf1a | 113 | void OnButtonInsert(wxCommandEvent &event); |
32b8ec41 VZ |
114 | void OnButtonAdd(wxCommandEvent& event); |
115 | void OnButtonAddSeveral(wxCommandEvent& event); | |
116 | void OnButtonAddMany(wxCommandEvent& event); | |
21dd7c5b | 117 | void OnButtonSetValue(wxCommandEvent& event); |
90576c50 | 118 | void OnButtonSetCurrent(wxCommandEvent& event); |
32b8ec41 | 119 | |
8933fbc6 VZ |
120 | void OnDropdown(wxCommandEvent& event); |
121 | void OnCloseup(wxCommandEvent& event); | |
32b8ec41 VZ |
122 | void OnComboBox(wxCommandEvent& event); |
123 | void OnComboText(wxCommandEvent& event); | |
124 | ||
125 | void OnCheckOrRadioBox(wxCommandEvent& event); | |
126 | ||
9849a944 | 127 | void OnUpdateUIInsertionPointText(wxUpdateUIEvent& event); |
32b8ec41 | 128 | |
243dbf1a | 129 | void OnUpdateUIInsert(wxUpdateUIEvent& event); |
32b8ec41 VZ |
130 | void OnUpdateUIAddSeveral(wxUpdateUIEvent& event); |
131 | void OnUpdateUIClearButton(wxUpdateUIEvent& event); | |
132 | void OnUpdateUIDeleteButton(wxUpdateUIEvent& event); | |
133 | void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event); | |
134 | void OnUpdateUIResetButton(wxUpdateUIEvent& event); | |
90576c50 | 135 | void OnUpdateUISetCurrent(wxUpdateUIEvent& event); |
32b8ec41 VZ |
136 | |
137 | // reset the combobox parameters | |
138 | void Reset(); | |
139 | ||
140 | // (re)create the combobox | |
141 | void CreateCombo(); | |
142 | ||
143 | // the controls | |
144 | // ------------ | |
145 | ||
146 | // the sel mode radiobox | |
147 | wxRadioBox *m_radioKind; | |
148 | ||
149 | // the checkboxes for styles | |
150 | wxCheckBox *m_chkSort, | |
5f6475c1 VZ |
151 | *m_chkReadonly, |
152 | *m_chkFilename; | |
32b8ec41 VZ |
153 | |
154 | // the combobox itself and the sizer it is in | |
155 | wxComboBox *m_combobox; | |
156 | wxSizer *m_sizerCombo; | |
157 | ||
158 | // the text entries for "Add/change string" and "Delete" buttons | |
243dbf1a VZ |
159 | wxTextCtrl *m_textInsert, |
160 | *m_textAdd, | |
32b8ec41 | 161 | *m_textChange, |
21dd7c5b | 162 | *m_textSetValue, |
90576c50 VZ |
163 | *m_textDelete, |
164 | *m_textCur; | |
32b8ec41 VZ |
165 | |
166 | private: | |
5e173f35 GD |
167 | DECLARE_EVENT_TABLE() |
168 | DECLARE_WIDGETS_PAGE(ComboboxWidgetsPage) | |
32b8ec41 VZ |
169 | }; |
170 | ||
171 | // ---------------------------------------------------------------------------- | |
172 | // event tables | |
173 | // ---------------------------------------------------------------------------- | |
174 | ||
175 | BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage) | |
176 | EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset) | |
d1d1f817 VZ |
177 | EVT_BUTTON(ComboPage_Popup, ComboboxWidgetsPage::OnButtonPopup) |
178 | EVT_BUTTON(ComboPage_Dismiss, ComboboxWidgetsPage::OnButtonDismiss) | |
32b8ec41 VZ |
179 | EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange) |
180 | EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete) | |
181 | EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel) | |
182 | EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear) | |
243dbf1a | 183 | EVT_BUTTON(ComboPage_Insert, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
184 | EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd) |
185 | EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral) | |
186 | EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany) | |
21dd7c5b | 187 | EVT_BUTTON(ComboPage_SetValue, ComboboxWidgetsPage::OnButtonSetValue) |
90576c50 | 188 | EVT_BUTTON(ComboPage_SetCurrent, ComboboxWidgetsPage::OnButtonSetCurrent) |
a236aa20 | 189 | EVT_BUTTON(ComboPage_ContainerTests, ItemContainerWidgetsPage::OnButtonTestItemContainer) |
32b8ec41 | 190 | |
243dbf1a | 191 | EVT_TEXT_ENTER(ComboPage_InsertText, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
192 | EVT_TEXT_ENTER(ComboPage_AddText, ComboboxWidgetsPage::OnButtonAdd) |
193 | EVT_TEXT_ENTER(ComboPage_DeleteText, ComboboxWidgetsPage::OnButtonDelete) | |
194 | ||
9849a944 | 195 | EVT_UPDATE_UI(ComboPage_InsertionPointText, ComboboxWidgetsPage::OnUpdateUIInsertionPointText) |
32b8ec41 VZ |
196 | |
197 | EVT_UPDATE_UI(ComboPage_Reset, ComboboxWidgetsPage::OnUpdateUIResetButton) | |
243dbf1a | 198 | EVT_UPDATE_UI(ComboPage_Insert, ComboboxWidgetsPage::OnUpdateUIInsert) |
32b8ec41 VZ |
199 | EVT_UPDATE_UI(ComboPage_AddSeveral, ComboboxWidgetsPage::OnUpdateUIAddSeveral) |
200 | EVT_UPDATE_UI(ComboPage_Clear, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
201 | EVT_UPDATE_UI(ComboPage_DeleteText, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
202 | EVT_UPDATE_UI(ComboPage_Delete, ComboboxWidgetsPage::OnUpdateUIDeleteButton) | |
203 | EVT_UPDATE_UI(ComboPage_Change, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
204 | EVT_UPDATE_UI(ComboPage_ChangeText, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
205 | EVT_UPDATE_UI(ComboPage_DeleteSel, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
90576c50 | 206 | EVT_UPDATE_UI(ComboPage_SetCurrent, ComboboxWidgetsPage::OnUpdateUISetCurrent) |
32b8ec41 VZ |
207 | |
208 | EVT_COMBOBOX(ComboPage_Combo, ComboboxWidgetsPage::OnComboBox) | |
8933fbc6 VZ |
209 | EVT_COMBOBOX_DROPDOWN(ComboPage_Combo, ComboboxWidgetsPage::OnDropdown) |
210 | EVT_COMBOBOX_CLOSEUP(ComboPage_Combo, ComboboxWidgetsPage::OnCloseup) | |
32b8ec41 | 211 | EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) |
243dbf1a | 212 | EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) |
32b8ec41 | 213 | |
206d3a16 JS |
214 | EVT_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) |
215 | EVT_RADIOBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
216 | END_EVENT_TABLE() |
217 | ||
218 | // ============================================================================ | |
219 | // implementation | |
220 | // ============================================================================ | |
221 | ||
f0fa4312 WS |
222 | #if defined(__WXUNIVERSAL__) |
223 | #define FAMILY_CTRLS UNIVERSAL_CTRLS | |
224 | #else | |
225 | #define FAMILY_CTRLS NATIVE_CTRLS | |
226 | #endif | |
227 | ||
9a83f860 | 228 | IMPLEMENT_WIDGETS_PAGE(ComboboxWidgetsPage, wxT("Combobox"), |
f0fa4312 | 229 | FAMILY_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS |
f2fdc4d5 | 230 | ); |
32b8ec41 | 231 | |
f2fdc4d5 | 232 | ComboboxWidgetsPage::ComboboxWidgetsPage(WidgetsBookCtrl *book, |
61c083e7 | 233 | wxImageList *imaglist) |
a236aa20 | 234 | : ItemContainerWidgetsPage(book, imaglist, combobox_xpm) |
32b8ec41 | 235 | { |
32b8ec41 VZ |
236 | // init everything |
237 | m_chkSort = | |
5f6475c1 VZ |
238 | m_chkReadonly = |
239 | m_chkFilename = (wxCheckBox *)NULL; | |
32b8ec41 VZ |
240 | |
241 | m_combobox = (wxComboBox *)NULL; | |
242 | m_sizerCombo = (wxSizer *)NULL; | |
453535a7 | 243 | } |
32b8ec41 | 244 | |
453535a7 WS |
245 | void ComboboxWidgetsPage::CreateContent() |
246 | { | |
32b8ec41 VZ |
247 | /* |
248 | What we create here is a frame having 3 panes: style pane is the | |
249 | leftmost one, in the middle the pane with buttons allowing to perform | |
250 | miscellaneous combobox operations and the pane containing the combobox | |
251 | itself to the right | |
252 | */ | |
253 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
254 | ||
d1d1f817 | 255 | // upper left pane |
32b8ec41 VZ |
256 | |
257 | // should be in sync with ComboKind_XXX values | |
258 | static const wxString kinds[] = | |
259 | { | |
9a83f860 VZ |
260 | wxT("default"), |
261 | wxT("simple"), | |
262 | wxT("drop down"), | |
32b8ec41 VZ |
263 | }; |
264 | ||
9a83f860 | 265 | m_radioKind = new wxRadioBox(this, wxID_ANY, wxT("Combobox &kind:"), |
32b8ec41 VZ |
266 | wxDefaultPosition, wxDefaultSize, |
267 | WXSIZEOF(kinds), kinds, | |
268 | 1, wxRA_SPECIFY_COLS); | |
269 | ||
d1d1f817 | 270 | wxSizer *sizerLeftTop = new wxStaticBoxSizer(wxVERTICAL, this, "&Set style"); |
32b8ec41 | 271 | |
d1d1f817 VZ |
272 | m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Sort items")); |
273 | m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Read only")); | |
274 | m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&File name")); | |
55b43eaa | 275 | m_chkFilename->Disable(); // not implemented yet |
32b8ec41 | 276 | |
d1d1f817 VZ |
277 | sizerLeftTop->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer |
278 | sizerLeftTop->Add(m_radioKind, 0, wxGROW | wxALL, 5); | |
32b8ec41 | 279 | |
9a83f860 | 280 | wxButton *btn = new wxButton(this, ComboPage_Reset, wxT("&Reset")); |
d1d1f817 VZ |
281 | sizerLeftTop->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); |
282 | ||
283 | // lower left pane | |
284 | wxSizer *sizerLeftBottom = new wxStaticBoxSizer(wxVERTICAL, this, "&Popup"); | |
285 | sizerLeftBottom->Add(new wxButton(this, ComboPage_Popup, "&Show"), | |
286 | wxSizerFlags().Border().Centre()); | |
287 | sizerLeftBottom->Add(new wxButton(this, ComboPage_Dismiss, "&Hide"), | |
288 | wxSizerFlags().Border().Centre()); | |
289 | ||
290 | ||
291 | wxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL); | |
292 | sizerLeft->Add(sizerLeftTop); | |
293 | sizerLeft->AddSpacer(10); | |
294 | sizerLeft->Add(sizerLeftBottom); | |
32b8ec41 VZ |
295 | |
296 | // middle pane | |
206d3a16 | 297 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, |
9a83f860 | 298 | wxT("&Change combobox contents")); |
32b8ec41 VZ |
299 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
300 | ||
301 | wxSizer *sizerRow; | |
302 | ||
90576c50 | 303 | sizerRow = CreateSizerWithTextAndButton(ComboPage_SetCurrent, |
9a83f860 | 304 | wxT("Current &selection"), |
90576c50 VZ |
305 | ComboPage_CurText, |
306 | &m_textCur); | |
32b8ec41 VZ |
307 | |
308 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
309 | ||
90576c50 | 310 | wxTextCtrl *text; |
9a83f860 | 311 | sizerRow = CreateSizerWithTextAndLabel(wxT("Insertion Point"), |
9849a944 VZ |
312 | ComboPage_InsertionPointText, |
313 | &text); | |
314 | text->SetEditable(false); | |
315 | ||
316 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
317 | ||
243dbf1a | 318 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Insert, |
9a83f860 | 319 | wxT("&Insert this string"), |
243dbf1a VZ |
320 | ComboPage_InsertText, |
321 | &m_textInsert); | |
322 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
323 | ||
32b8ec41 | 324 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Add, |
9a83f860 | 325 | wxT("&Add this string"), |
32b8ec41 VZ |
326 | ComboPage_AddText, |
327 | &m_textAdd); | |
328 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
329 | ||
9a83f860 | 330 | btn = new wxButton(this, ComboPage_AddSeveral, wxT("&Append a few strings")); |
32b8ec41 VZ |
331 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
332 | ||
9a83f860 | 333 | btn = new wxButton(this, ComboPage_AddMany, wxT("Append &many strings")); |
32b8ec41 VZ |
334 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
335 | ||
336 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Change, | |
9a83f860 | 337 | wxT("C&hange current"), |
32b8ec41 VZ |
338 | ComboPage_ChangeText, |
339 | &m_textChange); | |
340 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
341 | ||
342 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Delete, | |
9a83f860 | 343 | wxT("&Delete this item"), |
32b8ec41 VZ |
344 | ComboPage_DeleteText, |
345 | &m_textDelete); | |
346 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
347 | ||
9a83f860 | 348 | btn = new wxButton(this, ComboPage_DeleteSel, wxT("Delete &selection")); |
32b8ec41 VZ |
349 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
350 | ||
9a83f860 | 351 | btn = new wxButton(this, ComboPage_Clear, wxT("&Clear")); |
32b8ec41 VZ |
352 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
353 | ||
21dd7c5b | 354 | sizerRow = CreateSizerWithTextAndButton(ComboPage_SetValue, |
9a83f860 | 355 | wxT("SetValue"), |
21dd7c5b RR |
356 | ComboPage_SetValueText, |
357 | &m_textSetValue); | |
358 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
359 | ||
9a83f860 | 360 | btn = new wxButton(this, ComboPage_ContainerTests, wxT("Run &tests")); |
a236aa20 VZ |
361 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
362 | ||
21dd7c5b RR |
363 | |
364 | ||
32b8ec41 VZ |
365 | // right pane |
366 | wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); | |
206d3a16 | 367 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
368 | wxDefaultPosition, wxDefaultSize, |
369 | 0, NULL, | |
370 | 0); | |
6f002df4 | 371 | sizerRight->Add(m_combobox, 0, wxGROW | wxALL, 5); |
7b127900 | 372 | sizerRight->SetMinSize(150, 0); |
32b8ec41 VZ |
373 | m_sizerCombo = sizerRight; // save it to modify it later |
374 | ||
375 | // the 3 panes panes compose the window | |
376 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
377 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
378 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
379 | ||
380 | // final initializations | |
381 | Reset(); | |
382 | ||
32b8ec41 | 383 | SetSizer(sizerTop); |
32b8ec41 VZ |
384 | } |
385 | ||
386 | // ---------------------------------------------------------------------------- | |
387 | // operations | |
388 | // ---------------------------------------------------------------------------- | |
389 | ||
390 | void ComboboxWidgetsPage::Reset() | |
391 | { | |
206d3a16 JS |
392 | m_chkSort->SetValue(false); |
393 | m_chkReadonly->SetValue(false); | |
5f6475c1 | 394 | m_chkFilename->SetValue(false); |
32b8ec41 VZ |
395 | } |
396 | ||
397 | void ComboboxWidgetsPage::CreateCombo() | |
398 | { | |
1301e228 | 399 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
400 | |
401 | if ( m_chkSort->GetValue() ) | |
402 | flags |= wxCB_SORT; | |
403 | if ( m_chkReadonly->GetValue() ) | |
404 | flags |= wxCB_READONLY; | |
405 | ||
406 | switch ( m_radioKind->GetSelection() ) | |
407 | { | |
408 | default: | |
9a83f860 | 409 | wxFAIL_MSG( wxT("unknown combo kind") ); |
32b8ec41 VZ |
410 | // fall through |
411 | ||
412 | case ComboKind_Default: | |
413 | break; | |
414 | ||
415 | case ComboKind_Simple: | |
416 | flags |= wxCB_SIMPLE; | |
417 | break; | |
418 | ||
419 | case ComboKind_DropDown: | |
420 | flags = wxCB_DROPDOWN; | |
421 | break; | |
422 | } | |
423 | ||
424 | wxArrayString items; | |
425 | if ( m_combobox ) | |
426 | { | |
aa61d352 VZ |
427 | unsigned int count = m_combobox->GetCount(); |
428 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
429 | { |
430 | items.Add(m_combobox->GetString(n)); | |
431 | } | |
432 | ||
12a3f227 | 433 | m_sizerCombo->Detach( m_combobox ); |
32b8ec41 VZ |
434 | delete m_combobox; |
435 | } | |
436 | ||
206d3a16 | 437 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
438 | wxDefaultPosition, wxDefaultSize, |
439 | 0, NULL, | |
440 | flags); | |
441 | ||
55b43eaa VZ |
442 | #if 0 |
443 | if ( m_chkFilename->GetValue() ) | |
444 | ; | |
445 | #endif // TODO | |
446 | ||
aa61d352 VZ |
447 | unsigned int count = items.GetCount(); |
448 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
449 | { |
450 | m_combobox->Append(items[n]); | |
451 | } | |
452 | ||
dd740d86 | 453 | m_sizerCombo->Add(m_combobox, 0, wxGROW | wxALL, 5); |
32b8ec41 VZ |
454 | m_sizerCombo->Layout(); |
455 | } | |
456 | ||
457 | // ---------------------------------------------------------------------------- | |
458 | // event handlers | |
459 | // ---------------------------------------------------------------------------- | |
460 | ||
461 | void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
462 | { | |
463 | Reset(); | |
464 | ||
465 | CreateCombo(); | |
466 | } | |
467 | ||
468 | void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) | |
469 | { | |
470 | int sel = m_combobox->GetSelection(); | |
453535a7 | 471 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
472 | { |
473 | #ifndef __WXGTK__ | |
474 | m_combobox->SetString(sel, m_textChange->GetValue()); | |
475 | #else | |
9a83f860 | 476 | wxLogMessage(wxT("Not implemented in wxGTK")); |
32b8ec41 VZ |
477 | #endif |
478 | } | |
479 | } | |
480 | ||
481 | void ComboboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event)) | |
482 | { | |
483 | unsigned long n; | |
484 | if ( !m_textDelete->GetValue().ToULong(&n) || | |
aa61d352 | 485 | (n >= m_combobox->GetCount()) ) |
32b8ec41 VZ |
486 | { |
487 | return; | |
488 | } | |
489 | ||
490 | m_combobox->Delete(n); | |
491 | } | |
492 | ||
493 | void ComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event)) | |
494 | { | |
495 | int sel = m_combobox->GetSelection(); | |
aa61d352 | 496 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
497 | { |
498 | m_combobox->Delete(sel); | |
499 | } | |
500 | } | |
501 | ||
21dd7c5b RR |
502 | void ComboboxWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) |
503 | { | |
504 | wxString value = m_textSetValue->GetValue(); | |
505 | m_combobox->SetValue( value ); | |
506 | } | |
507 | ||
c02e5a31 | 508 | void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
509 | { |
510 | m_combobox->Clear(); | |
511 | } | |
512 | ||
c02e5a31 | 513 | void ComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event)) |
243dbf1a VZ |
514 | { |
515 | static unsigned int s_item = 0; | |
516 | ||
517 | wxString s = m_textInsert->GetValue(); | |
518 | if ( !m_textInsert->IsModified() ) | |
519 | { | |
520 | // update the default string | |
9a83f860 | 521 | m_textInsert->SetValue(wxString::Format(wxT("test item %u"), ++s_item)); |
243dbf1a VZ |
522 | } |
523 | ||
524 | if (m_combobox->GetSelection() >= 0) | |
525 | m_combobox->Insert(s, m_combobox->GetSelection()); | |
526 | } | |
527 | ||
c02e5a31 | 528 | void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 529 | { |
0c61716c | 530 | static unsigned int s_item = 0; |
32b8ec41 VZ |
531 | |
532 | wxString s = m_textAdd->GetValue(); | |
533 | if ( !m_textAdd->IsModified() ) | |
534 | { | |
535 | // update the default string | |
9a83f860 | 536 | m_textAdd->SetValue(wxString::Format(wxT("test item %u"), ++s_item)); |
32b8ec41 VZ |
537 | } |
538 | ||
539 | m_combobox->Append(s); | |
540 | } | |
541 | ||
542 | void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) | |
543 | { | |
544 | // "many" means 1000 here | |
0c61716c | 545 | for ( unsigned int n = 0; n < 1000; n++ ) |
32b8ec41 | 546 | { |
9a83f860 | 547 | m_combobox->Append(wxString::Format(wxT("item #%u"), n)); |
32b8ec41 VZ |
548 | } |
549 | } | |
550 | ||
90576c50 VZ |
551 | void ComboboxWidgetsPage::OnButtonSetCurrent(wxCommandEvent& WXUNUSED(event)) |
552 | { | |
553 | long n; | |
554 | if ( !m_textCur->GetValue().ToLong(&n) ) | |
555 | return; | |
556 | ||
557 | m_combobox->SetSelection(n); | |
558 | } | |
559 | ||
c02e5a31 | 560 | void ComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 561 | { |
9a83f860 VZ |
562 | m_combobox->Append(wxT("First")); |
563 | m_combobox->Append(wxT("another one")); | |
564 | m_combobox->Append(wxT("and the last (very very very very very very very very very very long) one")); | |
32b8ec41 VZ |
565 | } |
566 | ||
9849a944 VZ |
567 | void ComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) |
568 | { | |
569 | if (m_combobox) | |
9a83f860 | 570 | event.SetText( wxString::Format(wxT("%ld"), m_combobox->GetInsertionPoint()) ); |
9849a944 VZ |
571 | } |
572 | ||
32b8ec41 VZ |
573 | void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) |
574 | { | |
5f6475c1 VZ |
575 | event.Enable( m_chkSort->GetValue() || |
576 | m_chkReadonly->GetValue() || | |
577 | m_chkFilename->GetValue() ); | |
32b8ec41 VZ |
578 | } |
579 | ||
243dbf1a VZ |
580 | void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event) |
581 | { | |
582 | if (m_combobox) | |
583 | { | |
584 | bool enable = !(m_combobox->GetWindowStyle() & wxCB_SORT) && | |
585 | (m_combobox->GetSelection() >= 0); | |
586 | ||
587 | event.Enable(enable); | |
588 | } | |
589 | } | |
590 | ||
32b8ec41 VZ |
591 | void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) |
592 | { | |
e640f823 JS |
593 | if (m_combobox) |
594 | { | |
595 | unsigned long n; | |
596 | event.Enable(m_textDelete->GetValue().ToULong(&n) && | |
2f6c54eb | 597 | (n < (unsigned)m_combobox->GetCount())); |
e640f823 | 598 | } |
32b8ec41 VZ |
599 | } |
600 | ||
601 | void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) | |
602 | { | |
e640f823 | 603 | if (m_combobox) |
453535a7 | 604 | event.Enable(m_combobox->GetSelection() != wxNOT_FOUND); |
32b8ec41 VZ |
605 | } |
606 | ||
607 | void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event) | |
608 | { | |
e640f823 JS |
609 | if (m_combobox) |
610 | event.Enable(m_combobox->GetCount() != 0); | |
32b8ec41 VZ |
611 | } |
612 | ||
613 | void ComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event) | |
614 | { | |
e640f823 JS |
615 | if (m_combobox) |
616 | event.Enable(!(m_combobox->GetWindowStyle() & wxCB_SORT)); | |
32b8ec41 VZ |
617 | } |
618 | ||
90576c50 VZ |
619 | void ComboboxWidgetsPage::OnUpdateUISetCurrent(wxUpdateUIEvent& event) |
620 | { | |
621 | long n; | |
622 | event.Enable( m_textCur->GetValue().ToLong(&n) && | |
623 | (n == wxNOT_FOUND || | |
624 | (n >= 0 && (unsigned)n < m_combobox->GetCount())) ); | |
625 | } | |
626 | ||
32b8ec41 VZ |
627 | void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event) |
628 | { | |
e640f823 | 629 | if (!m_combobox) |
2f6c54eb VZ |
630 | return; |
631 | ||
32b8ec41 VZ |
632 | wxString s = event.GetString(); |
633 | ||
634 | wxASSERT_MSG( s == m_combobox->GetValue(), | |
9a83f860 | 635 | wxT("event and combobox values should be the same") ); |
32b8ec41 | 636 | |
243dbf1a | 637 | if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) |
43b2d5e7 | 638 | { |
9a83f860 | 639 | wxLogMessage(wxT("Combobox enter pressed (now '%s')"), s.c_str()); |
43b2d5e7 | 640 | } |
243dbf1a | 641 | else |
43b2d5e7 | 642 | { |
9a83f860 | 643 | wxLogMessage(wxT("Combobox text changed (now '%s')"), s.c_str()); |
43b2d5e7 | 644 | } |
32b8ec41 VZ |
645 | } |
646 | ||
647 | void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event) | |
648 | { | |
aec18ff7 | 649 | long sel = event.GetInt(); |
9a83f860 | 650 | const wxString selstr = wxString::Format(wxT("%ld"), sel); |
90576c50 VZ |
651 | m_textDelete->SetValue(selstr); |
652 | m_textCur->SetValue(selstr); | |
32b8ec41 | 653 | |
9a83f860 | 654 | wxLogMessage(wxT("Combobox item %ld selected"), sel); |
bfd84575 | 655 | |
9a83f860 | 656 | wxLogMessage(wxT("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() ); |
32b8ec41 VZ |
657 | } |
658 | ||
c02e5a31 | 659 | void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
660 | { |
661 | CreateCombo(); | |
662 | } | |
663 | ||
8933fbc6 VZ |
664 | void ComboboxWidgetsPage::OnDropdown(wxCommandEvent& WXUNUSED(event)) |
665 | { | |
9a83f860 | 666 | wxLogMessage(wxT("Combobox dropped down")); |
8933fbc6 VZ |
667 | } |
668 | ||
669 | void ComboboxWidgetsPage::OnCloseup(wxCommandEvent& WXUNUSED(event)) | |
670 | { | |
9a83f860 | 671 | wxLogMessage(wxT("Combobox closed up")); |
8933fbc6 VZ |
672 | } |
673 | ||
d21866cb | 674 | #endif // wxUSE_COMBOBOX |