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