]>
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: | |
5378558e | 88 | ComboboxWidgetsPage(wxBookCtrlBase *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 | ||
195 | IMPLEMENT_WIDGETS_PAGE(ComboboxWidgetsPage, _T("Combobox")); | |
196 | ||
5378558e | 197 | ComboboxWidgetsPage::ComboboxWidgetsPage(wxBookCtrlBase *book, |
61c083e7 WS |
198 | wxImageList *imaglist) |
199 | : WidgetsPage(book) | |
32b8ec41 | 200 | { |
32b8ec41 VZ |
201 | // init everything |
202 | m_chkSort = | |
203 | m_chkReadonly = (wxCheckBox *)NULL; | |
204 | ||
205 | m_combobox = (wxComboBox *)NULL; | |
206 | m_sizerCombo = (wxSizer *)NULL; | |
207 | ||
e640f823 JS |
208 | imaglist->Add(wxBitmap(combobox_xpm)); |
209 | ||
32b8ec41 VZ |
210 | /* |
211 | What we create here is a frame having 3 panes: style pane is the | |
212 | leftmost one, in the middle the pane with buttons allowing to perform | |
213 | miscellaneous combobox operations and the pane containing the combobox | |
214 | itself to the right | |
215 | */ | |
216 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
217 | ||
218 | // left pane | |
206d3a16 | 219 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style")); |
32b8ec41 VZ |
220 | |
221 | // should be in sync with ComboKind_XXX values | |
222 | static const wxString kinds[] = | |
223 | { | |
224 | _T("default"), | |
225 | _T("simple"), | |
226 | _T("drop down"), | |
227 | }; | |
228 | ||
206d3a16 | 229 | m_radioKind = new wxRadioBox(this, wxID_ANY, _T("Combobox &kind:"), |
32b8ec41 VZ |
230 | wxDefaultPosition, wxDefaultSize, |
231 | WXSIZEOF(kinds), kinds, | |
232 | 1, wxRA_SPECIFY_COLS); | |
233 | ||
234 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
235 | ||
236 | m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items")); | |
237 | m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Read only")); | |
238 | ||
239 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
240 | sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5); | |
241 | ||
242 | wxButton *btn = new wxButton(this, ComboPage_Reset, _T("&Reset")); | |
243 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); | |
244 | ||
245 | // middle pane | |
206d3a16 JS |
246 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, |
247 | _T("&Change combobox contents")); | |
32b8ec41 VZ |
248 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
249 | ||
250 | wxSizer *sizerRow; | |
251 | ||
252 | wxTextCtrl *text; | |
253 | sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"), | |
254 | ComboPage_CurText, | |
255 | &text); | |
206d3a16 | 256 | text->SetEditable(false); |
32b8ec41 VZ |
257 | |
258 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
259 | ||
9849a944 VZ |
260 | sizerRow = CreateSizerWithTextAndLabel(_T("Insertion Point"), |
261 | ComboPage_InsertionPointText, | |
262 | &text); | |
263 | text->SetEditable(false); | |
264 | ||
265 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
266 | ||
243dbf1a VZ |
267 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Insert, |
268 | _T("&Insert this string"), | |
269 | ComboPage_InsertText, | |
270 | &m_textInsert); | |
271 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
272 | ||
32b8ec41 VZ |
273 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Add, |
274 | _T("&Add this string"), | |
275 | ComboPage_AddText, | |
276 | &m_textAdd); | |
277 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
278 | ||
243dbf1a | 279 | btn = new wxButton(this, ComboPage_AddSeveral, _T("&Append a few strings")); |
32b8ec41 VZ |
280 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
281 | ||
243dbf1a | 282 | btn = new wxButton(this, ComboPage_AddMany, _T("Append &many strings")); |
32b8ec41 VZ |
283 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
284 | ||
285 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Change, | |
286 | _T("C&hange current"), | |
287 | ComboPage_ChangeText, | |
288 | &m_textChange); | |
289 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
290 | ||
291 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Delete, | |
292 | _T("&Delete this item"), | |
293 | ComboPage_DeleteText, | |
294 | &m_textDelete); | |
295 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
296 | ||
297 | btn = new wxButton(this, ComboPage_DeleteSel, _T("Delete &selection")); | |
298 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
299 | ||
300 | btn = new wxButton(this, ComboPage_Clear, _T("&Clear")); | |
301 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
302 | ||
303 | // right pane | |
304 | wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); | |
206d3a16 | 305 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
306 | wxDefaultPosition, wxDefaultSize, |
307 | 0, NULL, | |
308 | 0); | |
309 | sizerRight->Add(m_combobox, 1, wxGROW | wxALL, 5); | |
7b127900 | 310 | sizerRight->SetMinSize(150, 0); |
32b8ec41 VZ |
311 | m_sizerCombo = sizerRight; // save it to modify it later |
312 | ||
313 | // the 3 panes panes compose the window | |
314 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
315 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
316 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
317 | ||
318 | // final initializations | |
319 | Reset(); | |
320 | ||
32b8ec41 VZ |
321 | SetSizer(sizerTop); |
322 | ||
323 | sizerTop->Fit(this); | |
324 | } | |
325 | ||
326 | // ---------------------------------------------------------------------------- | |
327 | // operations | |
328 | // ---------------------------------------------------------------------------- | |
329 | ||
330 | void ComboboxWidgetsPage::Reset() | |
331 | { | |
206d3a16 JS |
332 | m_chkSort->SetValue(false); |
333 | m_chkReadonly->SetValue(false); | |
32b8ec41 VZ |
334 | } |
335 | ||
336 | void ComboboxWidgetsPage::CreateCombo() | |
337 | { | |
1301e228 | 338 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
339 | |
340 | if ( m_chkSort->GetValue() ) | |
341 | flags |= wxCB_SORT; | |
342 | if ( m_chkReadonly->GetValue() ) | |
343 | flags |= wxCB_READONLY; | |
344 | ||
345 | switch ( m_radioKind->GetSelection() ) | |
346 | { | |
347 | default: | |
348 | wxFAIL_MSG( _T("unknown combo kind") ); | |
349 | // fall through | |
350 | ||
351 | case ComboKind_Default: | |
352 | break; | |
353 | ||
354 | case ComboKind_Simple: | |
355 | flags |= wxCB_SIMPLE; | |
356 | break; | |
357 | ||
358 | case ComboKind_DropDown: | |
359 | flags = wxCB_DROPDOWN; | |
360 | break; | |
361 | } | |
362 | ||
363 | wxArrayString items; | |
364 | if ( m_combobox ) | |
365 | { | |
aa61d352 VZ |
366 | unsigned int count = m_combobox->GetCount(); |
367 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
368 | { |
369 | items.Add(m_combobox->GetString(n)); | |
370 | } | |
371 | ||
12a3f227 | 372 | m_sizerCombo->Detach( m_combobox ); |
32b8ec41 VZ |
373 | delete m_combobox; |
374 | } | |
375 | ||
206d3a16 | 376 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
377 | wxDefaultPosition, wxDefaultSize, |
378 | 0, NULL, | |
379 | flags); | |
380 | ||
aa61d352 VZ |
381 | unsigned int count = items.GetCount(); |
382 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
383 | { |
384 | m_combobox->Append(items[n]); | |
385 | } | |
386 | ||
387 | m_sizerCombo->Add(m_combobox, 1, wxGROW | wxALL, 5); | |
388 | m_sizerCombo->Layout(); | |
389 | } | |
390 | ||
391 | // ---------------------------------------------------------------------------- | |
392 | // event handlers | |
393 | // ---------------------------------------------------------------------------- | |
394 | ||
395 | void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
396 | { | |
397 | Reset(); | |
398 | ||
399 | CreateCombo(); | |
400 | } | |
401 | ||
402 | void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) | |
403 | { | |
404 | int sel = m_combobox->GetSelection(); | |
405 | if ( sel != -1 ) | |
406 | { | |
407 | #ifndef __WXGTK__ | |
408 | m_combobox->SetString(sel, m_textChange->GetValue()); | |
409 | #else | |
410 | wxLogMessage(_T("Not implemented in wxGTK")); | |
411 | #endif | |
412 | } | |
413 | } | |
414 | ||
415 | void ComboboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event)) | |
416 | { | |
417 | unsigned long n; | |
418 | if ( !m_textDelete->GetValue().ToULong(&n) || | |
aa61d352 | 419 | (n >= m_combobox->GetCount()) ) |
32b8ec41 VZ |
420 | { |
421 | return; | |
422 | } | |
423 | ||
424 | m_combobox->Delete(n); | |
425 | } | |
426 | ||
427 | void ComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event)) | |
428 | { | |
429 | int sel = m_combobox->GetSelection(); | |
aa61d352 | 430 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
431 | { |
432 | m_combobox->Delete(sel); | |
433 | } | |
434 | } | |
435 | ||
c02e5a31 | 436 | void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
437 | { |
438 | m_combobox->Clear(); | |
439 | } | |
440 | ||
c02e5a31 | 441 | void ComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event)) |
243dbf1a VZ |
442 | { |
443 | static unsigned int s_item = 0; | |
444 | ||
445 | wxString s = m_textInsert->GetValue(); | |
446 | if ( !m_textInsert->IsModified() ) | |
447 | { | |
448 | // update the default string | |
449 | m_textInsert->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
450 | } | |
451 | ||
452 | if (m_combobox->GetSelection() >= 0) | |
453 | m_combobox->Insert(s, m_combobox->GetSelection()); | |
454 | } | |
455 | ||
c02e5a31 | 456 | void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 457 | { |
0c61716c | 458 | static unsigned int s_item = 0; |
32b8ec41 VZ |
459 | |
460 | wxString s = m_textAdd->GetValue(); | |
461 | if ( !m_textAdd->IsModified() ) | |
462 | { | |
463 | // update the default string | |
464 | m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
465 | } | |
466 | ||
467 | m_combobox->Append(s); | |
468 | } | |
469 | ||
470 | void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) | |
471 | { | |
472 | // "many" means 1000 here | |
0c61716c | 473 | for ( unsigned int n = 0; n < 1000; n++ ) |
32b8ec41 VZ |
474 | { |
475 | m_combobox->Append(wxString::Format(_T("item #%u"), n)); | |
476 | } | |
477 | } | |
478 | ||
c02e5a31 | 479 | void ComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
480 | { |
481 | m_combobox->Append(_T("First")); | |
482 | m_combobox->Append(_T("another one")); | |
483 | m_combobox->Append(_T("and the last (very very very very very very very very very very long) one")); | |
484 | } | |
485 | ||
486 | void ComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent& event) | |
487 | { | |
e640f823 JS |
488 | if (m_combobox) |
489 | event.SetText( wxString::Format(_T("%d"), m_combobox->GetSelection()) ); | |
32b8ec41 VZ |
490 | } |
491 | ||
9849a944 VZ |
492 | void ComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) |
493 | { | |
494 | if (m_combobox) | |
e95c145c | 495 | event.SetText( wxString::Format(_T("%ld"), m_combobox->GetInsertionPoint()) ); |
9849a944 VZ |
496 | } |
497 | ||
32b8ec41 VZ |
498 | void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) |
499 | { | |
e640f823 JS |
500 | if (m_combobox) |
501 | event.Enable( m_chkSort->GetValue() || m_chkReadonly->GetValue() ); | |
32b8ec41 VZ |
502 | } |
503 | ||
243dbf1a VZ |
504 | void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event) |
505 | { | |
506 | if (m_combobox) | |
507 | { | |
508 | bool enable = !(m_combobox->GetWindowStyle() & wxCB_SORT) && | |
509 | (m_combobox->GetSelection() >= 0); | |
510 | ||
511 | event.Enable(enable); | |
512 | } | |
513 | } | |
514 | ||
32b8ec41 VZ |
515 | void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) |
516 | { | |
e640f823 JS |
517 | if (m_combobox) |
518 | { | |
519 | unsigned long n; | |
520 | event.Enable(m_textDelete->GetValue().ToULong(&n) && | |
2f6c54eb | 521 | (n < (unsigned)m_combobox->GetCount())); |
e640f823 | 522 | } |
32b8ec41 VZ |
523 | } |
524 | ||
525 | void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) | |
526 | { | |
e640f823 JS |
527 | if (m_combobox) |
528 | event.Enable(m_combobox->GetSelection() != -1); | |
32b8ec41 VZ |
529 | } |
530 | ||
531 | void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event) | |
532 | { | |
e640f823 JS |
533 | if (m_combobox) |
534 | event.Enable(m_combobox->GetCount() != 0); | |
32b8ec41 VZ |
535 | } |
536 | ||
537 | void ComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event) | |
538 | { | |
e640f823 JS |
539 | if (m_combobox) |
540 | event.Enable(!(m_combobox->GetWindowStyle() & wxCB_SORT)); | |
32b8ec41 VZ |
541 | } |
542 | ||
543 | void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event) | |
544 | { | |
e640f823 | 545 | if (!m_combobox) |
2f6c54eb VZ |
546 | return; |
547 | ||
32b8ec41 VZ |
548 | wxString s = event.GetString(); |
549 | ||
550 | wxASSERT_MSG( s == m_combobox->GetValue(), | |
551 | _T("event and combobox values should be the same") ); | |
552 | ||
243dbf1a VZ |
553 | if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) |
554 | wxLogMessage(_T("Combobox enter pressed (now '%s')"), s.c_str()); | |
555 | else | |
bfd84575 | 556 | wxLogMessage(_T("Combobox text changed (now '%s')"), s.c_str()); |
32b8ec41 VZ |
557 | } |
558 | ||
559 | void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event) | |
560 | { | |
aec18ff7 | 561 | long sel = event.GetInt(); |
32b8ec41 VZ |
562 | m_textDelete->SetValue(wxString::Format(_T("%ld"), sel)); |
563 | ||
aec18ff7 | 564 | wxLogMessage(_T("Combobox item %ld selected"), sel); |
bfd84575 | 565 | |
78b3b018 | 566 | wxLogMessage(_T("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() ); |
32b8ec41 VZ |
567 | } |
568 | ||
c02e5a31 | 569 | void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
570 | { |
571 | CreateCombo(); | |
572 | } | |
573 | ||
3379ed37 VZ |
574 | #endif //wxUSE_COMBOBOX |
575 | ||
7b127900 | 576 | #endif |