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