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