]>
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 | |
9 | // License: wxWindows license | |
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 | ||
44 | #include "widgets.h" | |
7b127900 | 45 | #if 1 |
32b8ec41 VZ |
46 | #include "icons/combobox.xpm" |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // constants | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // control ids | |
53 | enum | |
54 | { | |
55 | ComboPage_Reset = 100, | |
56 | ComboPage_CurText, | |
9849a944 | 57 | ComboPage_InsertionPointText, |
243dbf1a VZ |
58 | ComboPage_Insert, |
59 | ComboPage_InsertText, | |
32b8ec41 VZ |
60 | ComboPage_Add, |
61 | ComboPage_AddText, | |
62 | ComboPage_AddSeveral, | |
63 | ComboPage_AddMany, | |
64 | ComboPage_Clear, | |
65 | ComboPage_Change, | |
66 | ComboPage_ChangeText, | |
67 | ComboPage_Delete, | |
68 | ComboPage_DeleteText, | |
69 | ComboPage_DeleteSel, | |
70 | ComboPage_Combo | |
71 | }; | |
72 | ||
73 | // kinds of comboboxes | |
74 | enum | |
75 | { | |
76 | ComboKind_Default, | |
77 | ComboKind_Simple, | |
78 | ComboKind_DropDown | |
79 | }; | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // ComboboxWidgetsPage | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | class ComboboxWidgetsPage : public WidgetsPage | |
86 | { | |
87 | public: | |
f2fdc4d5 | 88 | ComboboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); |
32b8ec41 | 89 | |
195df7a7 | 90 | virtual wxControl *GetWidget() const { return m_combobox; } |
1301e228 | 91 | virtual void RecreateWidget() { CreateCombo(); } |
195df7a7 | 92 | |
32b8ec41 VZ |
93 | protected: |
94 | // event handlers | |
95 | void OnButtonReset(wxCommandEvent& event); | |
96 | void OnButtonChange(wxCommandEvent& event); | |
97 | void OnButtonDelete(wxCommandEvent& event); | |
98 | void OnButtonDeleteSel(wxCommandEvent& event); | |
99 | void OnButtonClear(wxCommandEvent& event); | |
243dbf1a | 100 | void OnButtonInsert(wxCommandEvent &event); |
32b8ec41 VZ |
101 | void OnButtonAdd(wxCommandEvent& event); |
102 | void OnButtonAddSeveral(wxCommandEvent& event); | |
103 | void OnButtonAddMany(wxCommandEvent& event); | |
104 | ||
105 | void OnComboBox(wxCommandEvent& event); | |
106 | void OnComboText(wxCommandEvent& event); | |
107 | ||
108 | void OnCheckOrRadioBox(wxCommandEvent& event); | |
109 | ||
110 | void OnUpdateUICurText(wxUpdateUIEvent& event); | |
9849a944 | 111 | void OnUpdateUIInsertionPointText(wxUpdateUIEvent& event); |
32b8ec41 | 112 | |
243dbf1a | 113 | void OnUpdateUIInsert(wxUpdateUIEvent& event); |
32b8ec41 VZ |
114 | void OnUpdateUIAddSeveral(wxUpdateUIEvent& event); |
115 | void OnUpdateUIClearButton(wxUpdateUIEvent& event); | |
116 | void OnUpdateUIDeleteButton(wxUpdateUIEvent& event); | |
117 | void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event); | |
118 | void OnUpdateUIResetButton(wxUpdateUIEvent& event); | |
119 | ||
120 | // reset the combobox parameters | |
121 | void Reset(); | |
122 | ||
123 | // (re)create the combobox | |
124 | void CreateCombo(); | |
125 | ||
126 | // the controls | |
127 | // ------------ | |
128 | ||
129 | // the sel mode radiobox | |
130 | wxRadioBox *m_radioKind; | |
131 | ||
132 | // the checkboxes for styles | |
133 | wxCheckBox *m_chkSort, | |
134 | *m_chkReadonly; | |
135 | ||
136 | // the combobox itself and the sizer it is in | |
137 | wxComboBox *m_combobox; | |
138 | wxSizer *m_sizerCombo; | |
139 | ||
140 | // the text entries for "Add/change string" and "Delete" buttons | |
243dbf1a VZ |
141 | wxTextCtrl *m_textInsert, |
142 | *m_textAdd, | |
32b8ec41 VZ |
143 | *m_textChange, |
144 | *m_textDelete; | |
145 | ||
146 | private: | |
5e173f35 GD |
147 | DECLARE_EVENT_TABLE() |
148 | DECLARE_WIDGETS_PAGE(ComboboxWidgetsPage) | |
32b8ec41 VZ |
149 | }; |
150 | ||
151 | // ---------------------------------------------------------------------------- | |
152 | // event tables | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage) | |
156 | EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset) | |
157 | EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange) | |
158 | EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete) | |
159 | EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel) | |
160 | EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear) | |
243dbf1a | 161 | EVT_BUTTON(ComboPage_Insert, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
162 | EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd) |
163 | EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral) | |
164 | EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany) | |
165 | ||
243dbf1a | 166 | EVT_TEXT_ENTER(ComboPage_InsertText, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
167 | EVT_TEXT_ENTER(ComboPage_AddText, ComboboxWidgetsPage::OnButtonAdd) |
168 | EVT_TEXT_ENTER(ComboPage_DeleteText, ComboboxWidgetsPage::OnButtonDelete) | |
169 | ||
170 | EVT_UPDATE_UI(ComboPage_CurText, ComboboxWidgetsPage::OnUpdateUICurText) | |
9849a944 | 171 | EVT_UPDATE_UI(ComboPage_InsertionPointText, ComboboxWidgetsPage::OnUpdateUIInsertionPointText) |
32b8ec41 VZ |
172 | |
173 | EVT_UPDATE_UI(ComboPage_Reset, ComboboxWidgetsPage::OnUpdateUIResetButton) | |
243dbf1a | 174 | EVT_UPDATE_UI(ComboPage_Insert, ComboboxWidgetsPage::OnUpdateUIInsert) |
32b8ec41 VZ |
175 | EVT_UPDATE_UI(ComboPage_AddSeveral, ComboboxWidgetsPage::OnUpdateUIAddSeveral) |
176 | EVT_UPDATE_UI(ComboPage_Clear, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
177 | EVT_UPDATE_UI(ComboPage_DeleteText, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
178 | EVT_UPDATE_UI(ComboPage_Delete, ComboboxWidgetsPage::OnUpdateUIDeleteButton) | |
179 | EVT_UPDATE_UI(ComboPage_Change, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
180 | EVT_UPDATE_UI(ComboPage_ChangeText, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
181 | EVT_UPDATE_UI(ComboPage_DeleteSel, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
182 | ||
183 | EVT_COMBOBOX(ComboPage_Combo, ComboboxWidgetsPage::OnComboBox) | |
184 | EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) | |
243dbf1a | 185 | EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) |
32b8ec41 | 186 | |
206d3a16 JS |
187 | EVT_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) |
188 | EVT_RADIOBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
189 | END_EVENT_TABLE() |
190 | ||
191 | // ============================================================================ | |
192 | // implementation | |
193 | // ============================================================================ | |
194 | ||
f2fdc4d5 WS |
195 | IMPLEMENT_WIDGETS_PAGE(ComboboxWidgetsPage, _T("Combobox"), |
196 | (int)wxPlatform(GENERIC_CTRLS).If(wxMSW,NATIVE_CTRLS) | |
197 | | WITH_ITEMS_CTRLS | COMBO_CTRLS | |
198 | ); | |
32b8ec41 | 199 | |
f2fdc4d5 | 200 | ComboboxWidgetsPage::ComboboxWidgetsPage(WidgetsBookCtrl *book, |
61c083e7 WS |
201 | wxImageList *imaglist) |
202 | : WidgetsPage(book) | |
32b8ec41 | 203 | { |
32b8ec41 VZ |
204 | // init everything |
205 | m_chkSort = | |
206 | m_chkReadonly = (wxCheckBox *)NULL; | |
207 | ||
208 | m_combobox = (wxComboBox *)NULL; | |
209 | m_sizerCombo = (wxSizer *)NULL; | |
210 | ||
e640f823 JS |
211 | imaglist->Add(wxBitmap(combobox_xpm)); |
212 | ||
32b8ec41 VZ |
213 | /* |
214 | What we create here is a frame having 3 panes: style pane is the | |
215 | leftmost one, in the middle the pane with buttons allowing to perform | |
216 | miscellaneous combobox operations and the pane containing the combobox | |
217 | itself to the right | |
218 | */ | |
219 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
220 | ||
221 | // left pane | |
206d3a16 | 222 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style")); |
32b8ec41 VZ |
223 | |
224 | // should be in sync with ComboKind_XXX values | |
225 | static const wxString kinds[] = | |
226 | { | |
227 | _T("default"), | |
228 | _T("simple"), | |
229 | _T("drop down"), | |
230 | }; | |
231 | ||
206d3a16 | 232 | m_radioKind = new wxRadioBox(this, wxID_ANY, _T("Combobox &kind:"), |
32b8ec41 VZ |
233 | wxDefaultPosition, wxDefaultSize, |
234 | WXSIZEOF(kinds), kinds, | |
235 | 1, wxRA_SPECIFY_COLS); | |
236 | ||
237 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
238 | ||
239 | m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items")); | |
240 | m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Read only")); | |
241 | ||
242 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
243 | sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5); | |
244 | ||
245 | wxButton *btn = new wxButton(this, ComboPage_Reset, _T("&Reset")); | |
246 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); | |
247 | ||
248 | // middle pane | |
206d3a16 JS |
249 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, |
250 | _T("&Change combobox contents")); | |
32b8ec41 VZ |
251 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
252 | ||
253 | wxSizer *sizerRow; | |
254 | ||
255 | wxTextCtrl *text; | |
256 | sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"), | |
257 | ComboPage_CurText, | |
258 | &text); | |
206d3a16 | 259 | text->SetEditable(false); |
32b8ec41 VZ |
260 | |
261 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
262 | ||
9849a944 VZ |
263 | sizerRow = CreateSizerWithTextAndLabel(_T("Insertion Point"), |
264 | ComboPage_InsertionPointText, | |
265 | &text); | |
266 | text->SetEditable(false); | |
267 | ||
268 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
269 | ||
243dbf1a VZ |
270 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Insert, |
271 | _T("&Insert this string"), | |
272 | ComboPage_InsertText, | |
273 | &m_textInsert); | |
274 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
275 | ||
32b8ec41 VZ |
276 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Add, |
277 | _T("&Add this string"), | |
278 | ComboPage_AddText, | |
279 | &m_textAdd); | |
280 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
281 | ||
243dbf1a | 282 | btn = new wxButton(this, ComboPage_AddSeveral, _T("&Append a few strings")); |
32b8ec41 VZ |
283 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
284 | ||
243dbf1a | 285 | btn = new wxButton(this, ComboPage_AddMany, _T("Append &many strings")); |
32b8ec41 VZ |
286 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
287 | ||
288 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Change, | |
289 | _T("C&hange current"), | |
290 | ComboPage_ChangeText, | |
291 | &m_textChange); | |
292 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
293 | ||
294 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Delete, | |
295 | _T("&Delete this item"), | |
296 | ComboPage_DeleteText, | |
297 | &m_textDelete); | |
298 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
299 | ||
300 | btn = new wxButton(this, ComboPage_DeleteSel, _T("Delete &selection")); | |
301 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
302 | ||
303 | btn = new wxButton(this, ComboPage_Clear, _T("&Clear")); | |
304 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
305 | ||
306 | // right pane | |
307 | wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); | |
206d3a16 | 308 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
309 | wxDefaultPosition, wxDefaultSize, |
310 | 0, NULL, | |
311 | 0); | |
312 | sizerRight->Add(m_combobox, 1, wxGROW | wxALL, 5); | |
7b127900 | 313 | sizerRight->SetMinSize(150, 0); |
32b8ec41 VZ |
314 | m_sizerCombo = sizerRight; // save it to modify it later |
315 | ||
316 | // the 3 panes panes compose the window | |
317 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
318 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
319 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
320 | ||
321 | // final initializations | |
322 | Reset(); | |
323 | ||
32b8ec41 VZ |
324 | SetSizer(sizerTop); |
325 | ||
326 | sizerTop->Fit(this); | |
327 | } | |
328 | ||
329 | // ---------------------------------------------------------------------------- | |
330 | // operations | |
331 | // ---------------------------------------------------------------------------- | |
332 | ||
333 | void ComboboxWidgetsPage::Reset() | |
334 | { | |
206d3a16 JS |
335 | m_chkSort->SetValue(false); |
336 | m_chkReadonly->SetValue(false); | |
32b8ec41 VZ |
337 | } |
338 | ||
339 | void ComboboxWidgetsPage::CreateCombo() | |
340 | { | |
1301e228 | 341 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
342 | |
343 | if ( m_chkSort->GetValue() ) | |
344 | flags |= wxCB_SORT; | |
345 | if ( m_chkReadonly->GetValue() ) | |
346 | flags |= wxCB_READONLY; | |
347 | ||
348 | switch ( m_radioKind->GetSelection() ) | |
349 | { | |
350 | default: | |
351 | wxFAIL_MSG( _T("unknown combo kind") ); | |
352 | // fall through | |
353 | ||
354 | case ComboKind_Default: | |
355 | break; | |
356 | ||
357 | case ComboKind_Simple: | |
358 | flags |= wxCB_SIMPLE; | |
359 | break; | |
360 | ||
361 | case ComboKind_DropDown: | |
362 | flags = wxCB_DROPDOWN; | |
363 | break; | |
364 | } | |
365 | ||
366 | wxArrayString items; | |
367 | if ( m_combobox ) | |
368 | { | |
aa61d352 VZ |
369 | unsigned int count = m_combobox->GetCount(); |
370 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
371 | { |
372 | items.Add(m_combobox->GetString(n)); | |
373 | } | |
374 | ||
12a3f227 | 375 | m_sizerCombo->Detach( m_combobox ); |
32b8ec41 VZ |
376 | delete m_combobox; |
377 | } | |
378 | ||
206d3a16 | 379 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
380 | wxDefaultPosition, wxDefaultSize, |
381 | 0, NULL, | |
382 | flags); | |
383 | ||
aa61d352 VZ |
384 | unsigned int count = items.GetCount(); |
385 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
386 | { |
387 | m_combobox->Append(items[n]); | |
388 | } | |
389 | ||
390 | m_sizerCombo->Add(m_combobox, 1, wxGROW | wxALL, 5); | |
391 | m_sizerCombo->Layout(); | |
392 | } | |
393 | ||
394 | // ---------------------------------------------------------------------------- | |
395 | // event handlers | |
396 | // ---------------------------------------------------------------------------- | |
397 | ||
398 | void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
399 | { | |
400 | Reset(); | |
401 | ||
402 | CreateCombo(); | |
403 | } | |
404 | ||
405 | void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) | |
406 | { | |
407 | int sel = m_combobox->GetSelection(); | |
408 | if ( sel != -1 ) | |
409 | { | |
410 | #ifndef __WXGTK__ | |
411 | m_combobox->SetString(sel, m_textChange->GetValue()); | |
412 | #else | |
413 | wxLogMessage(_T("Not implemented in wxGTK")); | |
414 | #endif | |
415 | } | |
416 | } | |
417 | ||
418 | void ComboboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event)) | |
419 | { | |
420 | unsigned long n; | |
421 | if ( !m_textDelete->GetValue().ToULong(&n) || | |
aa61d352 | 422 | (n >= m_combobox->GetCount()) ) |
32b8ec41 VZ |
423 | { |
424 | return; | |
425 | } | |
426 | ||
427 | m_combobox->Delete(n); | |
428 | } | |
429 | ||
430 | void ComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event)) | |
431 | { | |
432 | int sel = m_combobox->GetSelection(); | |
aa61d352 | 433 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
434 | { |
435 | m_combobox->Delete(sel); | |
436 | } | |
437 | } | |
438 | ||
c02e5a31 | 439 | void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
440 | { |
441 | m_combobox->Clear(); | |
442 | } | |
443 | ||
c02e5a31 | 444 | void ComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event)) |
243dbf1a VZ |
445 | { |
446 | static unsigned int s_item = 0; | |
447 | ||
448 | wxString s = m_textInsert->GetValue(); | |
449 | if ( !m_textInsert->IsModified() ) | |
450 | { | |
451 | // update the default string | |
452 | m_textInsert->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
453 | } | |
454 | ||
455 | if (m_combobox->GetSelection() >= 0) | |
456 | m_combobox->Insert(s, m_combobox->GetSelection()); | |
457 | } | |
458 | ||
c02e5a31 | 459 | void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 460 | { |
0c61716c | 461 | static unsigned int s_item = 0; |
32b8ec41 VZ |
462 | |
463 | wxString s = m_textAdd->GetValue(); | |
464 | if ( !m_textAdd->IsModified() ) | |
465 | { | |
466 | // update the default string | |
467 | m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
468 | } | |
469 | ||
470 | m_combobox->Append(s); | |
471 | } | |
472 | ||
473 | void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) | |
474 | { | |
475 | // "many" means 1000 here | |
0c61716c | 476 | for ( unsigned int n = 0; n < 1000; n++ ) |
32b8ec41 VZ |
477 | { |
478 | m_combobox->Append(wxString::Format(_T("item #%u"), n)); | |
479 | } | |
480 | } | |
481 | ||
c02e5a31 | 482 | void ComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
483 | { |
484 | m_combobox->Append(_T("First")); | |
485 | m_combobox->Append(_T("another one")); | |
486 | m_combobox->Append(_T("and the last (very very very very very very very very very very long) one")); | |
487 | } | |
488 | ||
489 | void ComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent& event) | |
490 | { | |
e640f823 JS |
491 | if (m_combobox) |
492 | event.SetText( wxString::Format(_T("%d"), m_combobox->GetSelection()) ); | |
32b8ec41 VZ |
493 | } |
494 | ||
9849a944 VZ |
495 | void ComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) |
496 | { | |
497 | if (m_combobox) | |
e95c145c | 498 | event.SetText( wxString::Format(_T("%ld"), m_combobox->GetInsertionPoint()) ); |
9849a944 VZ |
499 | } |
500 | ||
32b8ec41 VZ |
501 | void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) |
502 | { | |
e640f823 JS |
503 | if (m_combobox) |
504 | event.Enable( m_chkSort->GetValue() || m_chkReadonly->GetValue() ); | |
32b8ec41 VZ |
505 | } |
506 | ||
243dbf1a VZ |
507 | void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event) |
508 | { | |
509 | if (m_combobox) | |
510 | { | |
511 | bool enable = !(m_combobox->GetWindowStyle() & wxCB_SORT) && | |
512 | (m_combobox->GetSelection() >= 0); | |
513 | ||
514 | event.Enable(enable); | |
515 | } | |
516 | } | |
517 | ||
32b8ec41 VZ |
518 | void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) |
519 | { | |
e640f823 JS |
520 | if (m_combobox) |
521 | { | |
522 | unsigned long n; | |
523 | event.Enable(m_textDelete->GetValue().ToULong(&n) && | |
2f6c54eb | 524 | (n < (unsigned)m_combobox->GetCount())); |
e640f823 | 525 | } |
32b8ec41 VZ |
526 | } |
527 | ||
528 | void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) | |
529 | { | |
e640f823 JS |
530 | if (m_combobox) |
531 | event.Enable(m_combobox->GetSelection() != -1); | |
32b8ec41 VZ |
532 | } |
533 | ||
534 | void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event) | |
535 | { | |
e640f823 JS |
536 | if (m_combobox) |
537 | event.Enable(m_combobox->GetCount() != 0); | |
32b8ec41 VZ |
538 | } |
539 | ||
540 | void ComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event) | |
541 | { | |
e640f823 JS |
542 | if (m_combobox) |
543 | event.Enable(!(m_combobox->GetWindowStyle() & wxCB_SORT)); | |
32b8ec41 VZ |
544 | } |
545 | ||
546 | void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event) | |
547 | { | |
e640f823 | 548 | if (!m_combobox) |
2f6c54eb VZ |
549 | return; |
550 | ||
32b8ec41 VZ |
551 | wxString s = event.GetString(); |
552 | ||
553 | wxASSERT_MSG( s == m_combobox->GetValue(), | |
554 | _T("event and combobox values should be the same") ); | |
555 | ||
243dbf1a VZ |
556 | if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) |
557 | wxLogMessage(_T("Combobox enter pressed (now '%s')"), s.c_str()); | |
558 | else | |
bfd84575 | 559 | wxLogMessage(_T("Combobox text changed (now '%s')"), s.c_str()); |
32b8ec41 VZ |
560 | } |
561 | ||
562 | void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event) | |
563 | { | |
aec18ff7 | 564 | long sel = event.GetInt(); |
32b8ec41 VZ |
565 | m_textDelete->SetValue(wxString::Format(_T("%ld"), sel)); |
566 | ||
aec18ff7 | 567 | wxLogMessage(_T("Combobox item %ld selected"), sel); |
bfd84575 | 568 | |
78b3b018 | 569 | wxLogMessage(_T("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() ); |
32b8ec41 VZ |
570 | } |
571 | ||
c02e5a31 | 572 | void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
573 | { |
574 | CreateCombo(); | |
575 | } | |
576 | ||
3379ed37 VZ |
577 | #endif //wxUSE_COMBOBOX |
578 | ||
7b127900 | 579 | #endif |