]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/listbox.cpp
fixing infinite recursion for rotated text, introduced in cleanup r57915
[wxWidgets.git] / samples / widgets / listbox.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
be5a51fb 2// Program: wxWidgets Widgets Sample
32b8ec41
VZ
3// Name: listbox.cpp
4// Purpose: Part of the widgets sample showing wxListbox
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
eecdb000
WS
27#if wxUSE_LISTBOX
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/listbox.h"
38 #include "wx/radiobox.h"
39 #include "wx/statbox.h"
40 #include "wx/textctrl.h"
41#endif
42
43#include "wx/sizer.h"
44
45#include "wx/checklst.h"
46
a236aa20 47#include "itemcontainer.h"
32b8ec41 48#include "widgets.h"
eecdb000 49
32b8ec41
VZ
50#include "icons/listbox.xpm"
51
52// ----------------------------------------------------------------------------
53// constants
54// ----------------------------------------------------------------------------
55
56// control ids
57enum
58{
f0fa4312 59 ListboxPage_Reset = wxID_HIGHEST,
32b8ec41
VZ
60 ListboxPage_Add,
61 ListboxPage_AddText,
62 ListboxPage_AddSeveral,
63 ListboxPage_AddMany,
64 ListboxPage_Clear,
65 ListboxPage_Change,
66 ListboxPage_ChangeText,
67 ListboxPage_Delete,
68 ListboxPage_DeleteText,
69 ListboxPage_DeleteSel,
a236aa20 70 ListboxPage_Listbox,
0d29a482
VZ
71 ListboxPage_EnsureVisible,
72 ListboxPage_EnsureVisibleText,
a236aa20 73 ListboxPage_ContainerTests
32b8ec41
VZ
74};
75
76// ----------------------------------------------------------------------------
77// ListboxWidgetsPage
78// ----------------------------------------------------------------------------
79
a236aa20 80class ListboxWidgetsPage : public ItemContainerWidgetsPage
32b8ec41
VZ
81{
82public:
f2fdc4d5 83 ListboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
32b8ec41 84
195df7a7 85 virtual wxControl *GetWidget() const { return m_lbox; }
a236aa20 86 virtual wxItemContainer* GetContainer() const { return m_lbox; }
1301e228 87 virtual void RecreateWidget() { CreateLbox(); }
195df7a7 88
453535a7
WS
89 // lazy creation of the content
90 virtual void CreateContent();
91
32b8ec41
VZ
92protected:
93 // event handlers
94 void OnButtonReset(wxCommandEvent& event);
95 void OnButtonChange(wxCommandEvent& event);
0d29a482 96 void OnButtonEnsureVisible(wxCommandEvent& event);
32b8ec41
VZ
97 void OnButtonDelete(wxCommandEvent& event);
98 void OnButtonDeleteSel(wxCommandEvent& event);
99 void OnButtonClear(wxCommandEvent& event);
100 void OnButtonAdd(wxCommandEvent& event);
101 void OnButtonAddSeveral(wxCommandEvent& event);
102 void OnButtonAddMany(wxCommandEvent& event);
103
104 void OnListbox(wxCommandEvent& event);
105 void OnListboxDClick(wxCommandEvent& event);
106 void OnCheckListbox(wxCommandEvent& event);
107
108 void OnCheckOrRadioBox(wxCommandEvent& event);
109
110 void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
111 void OnUpdateUIClearButton(wxUpdateUIEvent& event);
0d29a482 112 void OnUpdateUIEnsureVisibleButton(wxUpdateUIEvent& event);
32b8ec41
VZ
113 void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
114 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event);
115 void OnUpdateUIResetButton(wxUpdateUIEvent& event);
116
117 // reset the listbox parameters
118 void Reset();
119
120 // (re)create the listbox
121 void CreateLbox();
122
0d29a482
VZ
123 // read the value of a listbox item index from the given control, return
124 // false if it's invalid
125 bool GetValidIndexFromText(const wxTextCtrl *text, int *n = NULL) const;
126
127
32b8ec41
VZ
128 // listbox parameters
129 // ------------------
130
131 // the selection mode
132 enum LboxSelection
133 {
134 LboxSel_Single,
135 LboxSel_Extended,
136 LboxSel_Multiple
137 } m_lboxSelMode;
138
139 // should it be sorted?
140 bool m_sorted;
141
142 // should it have horz scroll/vert scrollbar permanently shown?
143 bool m_horzScroll,
144 m_vertScrollAlways;
145
146 // the controls
147 // ------------
148
149 // the sel mode radiobox
150 wxRadioBox *m_radioSelMode;
151
152 // the checkboxes
822b9009 153 wxCheckBox *m_chkVScroll,
32b8ec41 154 *m_chkHScroll,
822b9009
VZ
155 *m_chkCheck,
156 *m_chkSort,
157 *m_chkOwnerDraw;
32b8ec41
VZ
158
159 // the listbox itself and the sizer it is in
b3c33d35
WS
160#ifdef __WXWINCE__
161 wxListBoxBase
162#else
453535a7 163 wxListBox
b3c33d35
WS
164#endif
165 *m_lbox;
166
32b8ec41
VZ
167 wxSizer *m_sizerLbox;
168
169 // the text entries for "Add/change string" and "Delete" buttons
170 wxTextCtrl *m_textAdd,
171 *m_textChange,
0d29a482 172 *m_textEnsureVisible,
32b8ec41
VZ
173 *m_textDelete;
174
175private:
5e173f35
GD
176 DECLARE_EVENT_TABLE()
177 DECLARE_WIDGETS_PAGE(ListboxWidgetsPage)
32b8ec41
VZ
178};
179
180// ----------------------------------------------------------------------------
181// event tables
182// ----------------------------------------------------------------------------
183
184BEGIN_EVENT_TABLE(ListboxWidgetsPage, WidgetsPage)
185 EVT_BUTTON(ListboxPage_Reset, ListboxWidgetsPage::OnButtonReset)
186 EVT_BUTTON(ListboxPage_Change, ListboxWidgetsPage::OnButtonChange)
187 EVT_BUTTON(ListboxPage_Delete, ListboxWidgetsPage::OnButtonDelete)
188 EVT_BUTTON(ListboxPage_DeleteSel, ListboxWidgetsPage::OnButtonDeleteSel)
0d29a482 189 EVT_BUTTON(ListboxPage_EnsureVisible, ListboxWidgetsPage::OnButtonEnsureVisible)
32b8ec41
VZ
190 EVT_BUTTON(ListboxPage_Clear, ListboxWidgetsPage::OnButtonClear)
191 EVT_BUTTON(ListboxPage_Add, ListboxWidgetsPage::OnButtonAdd)
192 EVT_BUTTON(ListboxPage_AddSeveral, ListboxWidgetsPage::OnButtonAddSeveral)
193 EVT_BUTTON(ListboxPage_AddMany, ListboxWidgetsPage::OnButtonAddMany)
a236aa20 194 EVT_BUTTON(ListboxPage_ContainerTests, ItemContainerWidgetsPage::OnButtonTestItemContainer)
32b8ec41
VZ
195
196 EVT_TEXT_ENTER(ListboxPage_AddText, ListboxWidgetsPage::OnButtonAdd)
197 EVT_TEXT_ENTER(ListboxPage_DeleteText, ListboxWidgetsPage::OnButtonDelete)
0d29a482 198 EVT_TEXT_ENTER(ListboxPage_EnsureVisibleText, ListboxWidgetsPage::OnButtonEnsureVisible)
32b8ec41
VZ
199
200 EVT_UPDATE_UI(ListboxPage_Reset, ListboxWidgetsPage::OnUpdateUIResetButton)
201 EVT_UPDATE_UI(ListboxPage_AddSeveral, ListboxWidgetsPage::OnUpdateUIAddSeveral)
202 EVT_UPDATE_UI(ListboxPage_Clear, ListboxWidgetsPage::OnUpdateUIClearButton)
203 EVT_UPDATE_UI(ListboxPage_DeleteText, ListboxWidgetsPage::OnUpdateUIClearButton)
204 EVT_UPDATE_UI(ListboxPage_Delete, ListboxWidgetsPage::OnUpdateUIDeleteButton)
205 EVT_UPDATE_UI(ListboxPage_Change, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
206 EVT_UPDATE_UI(ListboxPage_ChangeText, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
207 EVT_UPDATE_UI(ListboxPage_DeleteSel, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
0d29a482 208 EVT_UPDATE_UI(ListboxPage_EnsureVisible, ListboxWidgetsPage::OnUpdateUIEnsureVisibleButton)
32b8ec41
VZ
209
210 EVT_LISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnListbox)
211 EVT_LISTBOX_DCLICK(ListboxPage_Listbox, ListboxWidgetsPage::OnListboxDClick)
212 EVT_CHECKLISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnCheckListbox)
213
206d3a16
JS
214 EVT_CHECKBOX(wxID_ANY, ListboxWidgetsPage::OnCheckOrRadioBox)
215 EVT_RADIOBOX(wxID_ANY, ListboxWidgetsPage::OnCheckOrRadioBox)
32b8ec41
VZ
216END_EVENT_TABLE()
217
218// ============================================================================
219// implementation
220// ============================================================================
221
f0fa4312
WS
222#if defined(__WXUNIVERSAL__)
223 #define FAMILY_CTRLS UNIVERSAL_CTRLS
224#else
225 #define FAMILY_CTRLS NATIVE_CTRLS
226#endif
227
f2fdc4d5 228IMPLEMENT_WIDGETS_PAGE(ListboxWidgetsPage, _T("Listbox"),
f0fa4312 229 FAMILY_CTRLS | WITH_ITEMS_CTRLS
f2fdc4d5 230 );
32b8ec41 231
f2fdc4d5 232ListboxWidgetsPage::ListboxWidgetsPage(WidgetsBookCtrl *book,
32b8ec41 233 wxImageList *imaglist)
a236aa20 234 : ItemContainerWidgetsPage(book, imaglist, listbox_xpm)
32b8ec41 235{
32b8ec41
VZ
236 // init everything
237 m_radioSelMode = (wxRadioBox *)NULL;
238
239 m_chkVScroll =
240 m_chkHScroll =
241 m_chkCheck =
822b9009
VZ
242 m_chkSort =
243 m_chkOwnerDraw = (wxCheckBox *)NULL;
32b8ec41 244
b3c33d35 245 m_lbox = NULL;
32b8ec41
VZ
246 m_sizerLbox = (wxSizer *)NULL;
247
453535a7
WS
248}
249
250void ListboxWidgetsPage::CreateContent()
251{
32b8ec41
VZ
252 /*
253 What we create here is a frame having 3 panes: style pane is the
254 leftmost one, in the middle the pane with buttons allowing to perform
255 miscellaneous listbox operations and the pane containing the listbox
256 itself to the right
257 */
258 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
259
260 // left pane
206d3a16
JS
261 wxStaticBox *box = new wxStaticBox(this, wxID_ANY,
262 _T("&Set listbox parameters"));
32b8ec41
VZ
263 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
264
265 static const wxString modes[] =
266 {
267 _T("single"),
268 _T("extended"),
269 _T("multiple"),
270 };
271
206d3a16 272 m_radioSelMode = new wxRadioBox(this, wxID_ANY, _T("Selection &mode:"),
32b8ec41
VZ
273 wxDefaultPosition, wxDefaultSize,
274 WXSIZEOF(modes), modes,
275 1, wxRA_SPECIFY_COLS);
276
277 m_chkVScroll = CreateCheckBoxAndAddToSizer
278 (
279 sizerLeft,
280 _T("Always show &vertical scrollbar")
281 );
282 m_chkHScroll = CreateCheckBoxAndAddToSizer
283 (
284 sizerLeft,
285 _T("Show &horizontal scrollbar")
286 );
287 m_chkCheck = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Check list box"));
288 m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items"));
822b9009 289 m_chkOwnerDraw = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Owner drawn"));
32b8ec41
VZ
290
291 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
292 sizerLeft->Add(m_radioSelMode, 0, wxGROW | wxALL, 5);
293
294 wxButton *btn = new wxButton(this, ListboxPage_Reset, _T("&Reset"));
295 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
296
297 // middle pane
206d3a16
JS
298 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
299 _T("&Change listbox contents"));
32b8ec41
VZ
300 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
301
302 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
303 btn = new wxButton(this, ListboxPage_Add, _T("&Add this string"));
304 m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, _T("test item 0"));
305 sizerRow->Add(btn, 0, wxRIGHT, 5);
306 sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
307 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
308
309 btn = new wxButton(this, ListboxPage_AddSeveral, _T("&Insert a few strings"));
310 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
311
312 btn = new wxButton(this, ListboxPage_AddMany, _T("Add &many strings"));
313 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
314
315 sizerRow = new wxBoxSizer(wxHORIZONTAL);
316 btn = new wxButton(this, ListboxPage_Change, _T("C&hange current"));
206d3a16 317 m_textChange = new wxTextCtrl(this, ListboxPage_ChangeText, wxEmptyString);
32b8ec41
VZ
318 sizerRow->Add(btn, 0, wxRIGHT, 5);
319 sizerRow->Add(m_textChange, 1, wxLEFT, 5);
320 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
321
0d29a482
VZ
322 sizerRow = new wxBoxSizer(wxHORIZONTAL);
323 btn = new wxButton(this, ListboxPage_EnsureVisible, _T("Make item &visible"));
324 m_textEnsureVisible = new wxTextCtrl(this, ListboxPage_EnsureVisibleText, wxEmptyString);
325 sizerRow->Add(btn, 0, wxRIGHT, 5);
326 sizerRow->Add(m_textEnsureVisible, 1, wxLEFT, 5);
327 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
328
32b8ec41
VZ
329 sizerRow = new wxBoxSizer(wxHORIZONTAL);
330 btn = new wxButton(this, ListboxPage_Delete, _T("&Delete this item"));
206d3a16 331 m_textDelete = new wxTextCtrl(this, ListboxPage_DeleteText, wxEmptyString);
32b8ec41
VZ
332 sizerRow->Add(btn, 0, wxRIGHT, 5);
333 sizerRow->Add(m_textDelete, 1, wxLEFT, 5);
334 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
335
336 btn = new wxButton(this, ListboxPage_DeleteSel, _T("Delete &selection"));
337 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
338
339 btn = new wxButton(this, ListboxPage_Clear, _T("&Clear"));
340 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
341
a236aa20
VZ
342 btn = new wxButton(this, ListboxPage_ContainerTests, _T("Run &tests"));
343 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
344
32b8ec41
VZ
345 // right pane
346 wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
347 m_lbox = new wxListBox(this, ListboxPage_Listbox,
348 wxDefaultPosition, wxDefaultSize,
349 0, NULL,
350 wxLB_HSCROLL);
351 sizerRight->Add(m_lbox, 1, wxGROW | wxALL, 5);
7b127900 352 sizerRight->SetMinSize(150, 0);
32b8ec41
VZ
353 m_sizerLbox = sizerRight; // save it to modify it later
354
355 // the 3 panes panes compose the window
356 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
357 sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
358 sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
359
360 // final initializations
361 Reset();
362
32b8ec41 363 SetSizer(sizerTop);
32b8ec41
VZ
364}
365
366// ----------------------------------------------------------------------------
367// operations
368// ----------------------------------------------------------------------------
369
370void ListboxWidgetsPage::Reset()
371{
372 m_radioSelMode->SetSelection(LboxSel_Single);
206d3a16 373 m_chkVScroll->SetValue(false);
822b9009
VZ
374 m_chkHScroll->SetValue(true);
375 m_chkCheck->SetValue(false);
376 m_chkSort->SetValue(false);
377 m_chkOwnerDraw->SetValue(false);
32b8ec41
VZ
378}
379
380void ListboxWidgetsPage::CreateLbox()
381{
1301e228 382 int flags = ms_defaultFlags;
32b8ec41
VZ
383 switch ( m_radioSelMode->GetSelection() )
384 {
385 default:
386 wxFAIL_MSG( _T("unexpected radio box selection") );
387
388 case LboxSel_Single: flags |= wxLB_SINGLE; break;
389 case LboxSel_Extended: flags |= wxLB_EXTENDED; break;
390 case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break;
391 }
392
393 if ( m_chkVScroll->GetValue() )
394 flags |= wxLB_ALWAYS_SB;
395 if ( m_chkHScroll->GetValue() )
396 flags |= wxLB_HSCROLL;
397 if ( m_chkSort->GetValue() )
398 flags |= wxLB_SORT;
822b9009
VZ
399 if ( m_chkOwnerDraw->GetValue() )
400 flags |= wxLB_OWNERDRAW;
32b8ec41
VZ
401
402 wxArrayString items;
403 if ( m_lbox )
404 {
405 int count = m_lbox->GetCount();
406 for ( int n = 0; n < count; n++ )
407 {
408 items.Add(m_lbox->GetString(n));
409 }
410
12a3f227 411 m_sizerLbox->Detach( m_lbox );
32b8ec41
VZ
412 delete m_lbox;
413 }
414
e640f823 415#if wxUSE_CHECKLISTBOX
32b8ec41
VZ
416 if ( m_chkCheck->GetValue() )
417 {
418 m_lbox = new wxCheckListBox(this, ListboxPage_Listbox,
419 wxDefaultPosition, wxDefaultSize,
420 0, NULL,
421 flags);
422 }
423 else // just a listbox
e640f823 424#endif
32b8ec41
VZ
425 {
426 m_lbox = new wxListBox(this, ListboxPage_Listbox,
427 wxDefaultPosition, wxDefaultSize,
428 0, NULL,
429 flags);
430 }
431
432 m_lbox->Set(items);
433 m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
434 m_sizerLbox->Layout();
435}
436
0d29a482
VZ
437// ----------------------------------------------------------------------------
438// miscellaneous helpers
439// ----------------------------------------------------------------------------
440
441bool
442ListboxWidgetsPage::GetValidIndexFromText(const wxTextCtrl *text, int *n) const
443{
444 unsigned long idx;
445 if ( !text->GetValue().ToULong(&idx) || (idx >= m_lbox->GetCount()) )
446 {
447 // don't give the warning if we're just testing but do give it if we
448 // want to retrieve the value as this is only done in answer to a user
449 // action
450 if ( n )
451 wxLogWarning("Invalid index \"%s\"", text->GetValue());
452 return false;
453 }
454
455 if ( n )
456 *n = idx;
457
458 return true;
459}
460
32b8ec41
VZ
461// ----------------------------------------------------------------------------
462// event handlers
463// ----------------------------------------------------------------------------
464
465void ListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
466{
467 Reset();
468
469 CreateLbox();
470}
471
472void ListboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
473{
474 wxArrayInt selections;
475 int count = m_lbox->GetSelections(selections);
476 wxString s = m_textChange->GetValue();
477 for ( int n = 0; n < count; n++ )
478 {
479 m_lbox->SetString(selections[n], s);
480 }
481}
482
0d29a482
VZ
483void ListboxWidgetsPage::OnButtonEnsureVisible(wxCommandEvent& WXUNUSED(event))
484{
485 int n;
486 if ( !GetValidIndexFromText(m_textEnsureVisible, &n) )
487 {
488 return;
489 }
490
491 m_lbox->EnsureVisible(n);
492}
493
32b8ec41
VZ
494void ListboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
495{
0d29a482
VZ
496 int n;
497 if ( !GetValidIndexFromText(m_textDelete, &n) )
32b8ec41
VZ
498 {
499 return;
500 }
501
502 m_lbox->Delete(n);
503}
504
505void ListboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
506{
507 wxArrayInt selections;
508 int n = m_lbox->GetSelections(selections);
509 while ( n > 0 )
510 {
511 m_lbox->Delete(selections[--n]);
512 }
513}
514
c02e5a31 515void ListboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
516{
517 m_lbox->Clear();
518}
519
c02e5a31 520void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
32b8ec41 521{
0c61716c 522 static unsigned int s_item = 0;
32b8ec41
VZ
523
524 wxString s = m_textAdd->GetValue();
525 if ( !m_textAdd->IsModified() )
526 {
527 // update the default string
528 m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item));
529 }
530
531 m_lbox->Append(s);
532}
533
534void ListboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
535{
536 // "many" means 1000 here
0c61716c 537 for ( unsigned int n = 0; n < 1000; n++ )
32b8ec41
VZ
538 {
539 m_lbox->Append(wxString::Format(_T("item #%u"), n));
540 }
541}
542
c02e5a31 543void ListboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
544{
545 wxArrayString items;
546 items.Add(_T("First"));
547 items.Add(_T("another one"));
548 items.Add(_T("and the last (very very very very very very very very very very long) one"));
549 m_lbox->InsertItems(items, 0);
550}
551
552void ListboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
553{
554 event.Enable( (m_radioSelMode->GetSelection() != LboxSel_Single) ||
555 m_chkSort->GetValue() ||
822b9009 556 m_chkOwnerDraw->GetValue() ||
32b8ec41
VZ
557 !m_chkHScroll->GetValue() ||
558 m_chkVScroll->GetValue() );
559}
560
0d29a482
VZ
561void ListboxWidgetsPage::OnUpdateUIEnsureVisibleButton(wxUpdateUIEvent& event)
562{
563 event.Enable(GetValidIndexFromText(m_textEnsureVisible));
564}
565
32b8ec41
VZ
566void ListboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
567{
0d29a482 568 event.Enable(GetValidIndexFromText(m_textDelete));
32b8ec41
VZ
569}
570
571void ListboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
572{
573 wxArrayInt selections;
574 event.Enable(m_lbox->GetSelections(selections) != 0);
575}
576
577void ListboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
578{
579 event.Enable(m_lbox->GetCount() != 0);
580}
581
582void ListboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
583{
584 event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
585}
586
587void ListboxWidgetsPage::OnListbox(wxCommandEvent& event)
588{
a0086878 589 long sel = event.GetSelection();
32b8ec41
VZ
590 m_textDelete->SetValue(wxString::Format(_T("%ld"), sel));
591
a0086878
JS
592 if (event.IsSelection())
593 wxLogMessage(_T("Listbox item %ld selected"), sel);
594 else
595 wxLogMessage(_T("Listbox item %ld deselected"), sel);
32b8ec41
VZ
596}
597
598void ListboxWidgetsPage::OnListboxDClick(wxCommandEvent& event)
599{
33cf9a19 600 wxLogMessage( _T("Listbox item %d double clicked"), event.GetInt() );
32b8ec41
VZ
601}
602
603void ListboxWidgetsPage::OnCheckListbox(wxCommandEvent& event)
604{
33cf9a19 605 wxLogMessage( _T("Listbox item %d toggled"), event.GetInt() );
32b8ec41
VZ
606}
607
c02e5a31 608void ListboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
609{
610 CreateLbox();
611}
612
eecdb000 613#endif // wxUSE_LISTBOX