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