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