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