]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/listbox.cpp
Fix return value of wxGenericTreeCtrl::FindItem().
[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
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
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
9a83f860 228IMPLEMENT_WIDGETS_PAGE(ListboxWidgetsPage, wxT("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 261 wxStaticBox *box = new wxStaticBox(this, wxID_ANY,
9a83f860 262 wxT("&Set listbox parameters"));
32b8ec41
VZ
263 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
264
265 static const wxString modes[] =
266 {
9a83f860
VZ
267 wxT("single"),
268 wxT("extended"),
269 wxT("multiple"),
32b8ec41
VZ
270 };
271
9a83f860 272 m_radioSelMode = new wxRadioBox(this, wxID_ANY, wxT("Selection &mode:"),
32b8ec41
VZ
273 wxDefaultPosition, wxDefaultSize,
274 WXSIZEOF(modes), modes,
275 1, wxRA_SPECIFY_COLS);
276
277 m_chkVScroll = CreateCheckBoxAndAddToSizer
278 (
279 sizerLeft,
9a83f860 280 wxT("Always show &vertical scrollbar")
32b8ec41
VZ
281 );
282 m_chkHScroll = CreateCheckBoxAndAddToSizer
283 (
284 sizerLeft,
9a83f860 285 wxT("Show &horizontal scrollbar")
32b8ec41 286 );
9a83f860
VZ
287 m_chkCheck = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Check list box"));
288 m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Sort items"));
289 m_chkOwnerDraw = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&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
9a83f860 294 wxButton *btn = new wxButton(this, ListboxPage_Reset, wxT("&Reset"));
32b8ec41
VZ
295 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
296
297 // middle pane
206d3a16 298 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
9a83f860 299 wxT("&Change listbox contents"));
32b8ec41
VZ
300 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
301
302 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
9a83f860
VZ
303 btn = new wxButton(this, ListboxPage_Add, wxT("&Add this string"));
304 m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, wxT("test item 0"));
32b8ec41
VZ
305 sizerRow->Add(btn, 0, wxRIGHT, 5);
306 sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
307 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
308
9a83f860 309 btn = new wxButton(this, ListboxPage_AddSeveral, wxT("&Insert a few strings"));
32b8ec41
VZ
310 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
311
9a83f860 312 btn = new wxButton(this, ListboxPage_AddMany, wxT("Add &many strings"));
32b8ec41
VZ
313 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
314
315 sizerRow = new wxBoxSizer(wxHORIZONTAL);
9a83f860 316 btn = new wxButton(this, ListboxPage_Change, wxT("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 322 sizerRow = new wxBoxSizer(wxHORIZONTAL);
9a83f860 323 btn = new wxButton(this, ListboxPage_EnsureVisible, wxT("Make item &visible"));
0d29a482
VZ
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 329 sizerRow = new wxBoxSizer(wxHORIZONTAL);
9a83f860 330 btn = new wxButton(this, ListboxPage_Delete, wxT("&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
9a83f860 336 btn = new wxButton(this, ListboxPage_DeleteSel, wxT("Delete &selection"));
32b8ec41
VZ
337 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
338
9a83f860 339 btn = new wxButton(this, ListboxPage_Clear, wxT("&Clear"));
32b8ec41
VZ
340 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
341
9a83f860 342 btn = new wxButton(this, ListboxPage_ContainerTests, wxT("Run &tests"));
a236aa20
VZ
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:
9a83f860 386 wxFAIL_MSG( wxT("unexpected radio box selection") );
32b8ec41
VZ
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 )
9fceb168 451 {
0d29a482 452 wxLogWarning("Invalid index \"%s\"", text->GetValue());
9fceb168
VZ
453 }
454
0d29a482
VZ
455 return false;
456 }
457
458 if ( n )
459 *n = idx;
460
461 return true;
462}
463
32b8ec41
VZ
464// ----------------------------------------------------------------------------
465// event handlers
466// ----------------------------------------------------------------------------
467
468void ListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
469{
470 Reset();
471
472 CreateLbox();
473}
474
475void ListboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
476{
477 wxArrayInt selections;
478 int count = m_lbox->GetSelections(selections);
479 wxString s = m_textChange->GetValue();
480 for ( int n = 0; n < count; n++ )
481 {
482 m_lbox->SetString(selections[n], s);
483 }
484}
485
0d29a482
VZ
486void ListboxWidgetsPage::OnButtonEnsureVisible(wxCommandEvent& WXUNUSED(event))
487{
488 int n;
489 if ( !GetValidIndexFromText(m_textEnsureVisible, &n) )
490 {
491 return;
492 }
493
494 m_lbox->EnsureVisible(n);
495}
496
32b8ec41
VZ
497void ListboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
498{
0d29a482
VZ
499 int n;
500 if ( !GetValidIndexFromText(m_textDelete, &n) )
32b8ec41
VZ
501 {
502 return;
503 }
504
505 m_lbox->Delete(n);
506}
507
508void ListboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
509{
510 wxArrayInt selections;
511 int n = m_lbox->GetSelections(selections);
512 while ( n > 0 )
513 {
514 m_lbox->Delete(selections[--n]);
515 }
516}
517
c02e5a31 518void ListboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
519{
520 m_lbox->Clear();
521}
522
c02e5a31 523void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
32b8ec41 524{
0c61716c 525 static unsigned int s_item = 0;
32b8ec41
VZ
526
527 wxString s = m_textAdd->GetValue();
528 if ( !m_textAdd->IsModified() )
529 {
530 // update the default string
9a83f860 531 m_textAdd->SetValue(wxString::Format(wxT("test item %u"), ++s_item));
32b8ec41
VZ
532 }
533
534 m_lbox->Append(s);
535}
536
537void ListboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
538{
539 // "many" means 1000 here
0c61716c 540 for ( unsigned int n = 0; n < 1000; n++ )
32b8ec41 541 {
9a83f860 542 m_lbox->Append(wxString::Format(wxT("item #%u"), n));
32b8ec41
VZ
543 }
544}
545
c02e5a31 546void ListboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
547{
548 wxArrayString items;
9a83f860
VZ
549 items.Add(wxT("First"));
550 items.Add(wxT("another one"));
551 items.Add(wxT("and the last (very very very very very very very very very very long) one"));
32b8ec41
VZ
552 m_lbox->InsertItems(items, 0);
553}
554
555void ListboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
556{
557 event.Enable( (m_radioSelMode->GetSelection() != LboxSel_Single) ||
558 m_chkSort->GetValue() ||
822b9009 559 m_chkOwnerDraw->GetValue() ||
32b8ec41
VZ
560 !m_chkHScroll->GetValue() ||
561 m_chkVScroll->GetValue() );
562}
563
0d29a482
VZ
564void ListboxWidgetsPage::OnUpdateUIEnsureVisibleButton(wxUpdateUIEvent& event)
565{
566 event.Enable(GetValidIndexFromText(m_textEnsureVisible));
567}
568
32b8ec41
VZ
569void ListboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
570{
0d29a482 571 event.Enable(GetValidIndexFromText(m_textDelete));
32b8ec41
VZ
572}
573
574void ListboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
575{
576 wxArrayInt selections;
577 event.Enable(m_lbox->GetSelections(selections) != 0);
578}
579
580void ListboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
581{
582 event.Enable(m_lbox->GetCount() != 0);
583}
584
585void ListboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
586{
587 event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
588}
589
590void ListboxWidgetsPage::OnListbox(wxCommandEvent& event)
591{
a0086878 592 long sel = event.GetSelection();
9a83f860 593 m_textDelete->SetValue(wxString::Format(wxT("%ld"), sel));
32b8ec41 594
a0086878 595 if (event.IsSelection())
43b2d5e7 596 {
9a83f860 597 wxLogMessage(wxT("Listbox item %ld selected"), sel);
43b2d5e7 598 }
a0086878 599 else
43b2d5e7 600 {
9a83f860 601 wxLogMessage(wxT("Listbox item %ld deselected"), sel);
43b2d5e7 602 }
32b8ec41
VZ
603}
604
605void ListboxWidgetsPage::OnListboxDClick(wxCommandEvent& event)
606{
9a83f860 607 wxLogMessage( wxT("Listbox item %d double clicked"), event.GetInt() );
32b8ec41
VZ
608}
609
610void ListboxWidgetsPage::OnCheckListbox(wxCommandEvent& event)
611{
9a83f860 612 wxLogMessage( wxT("Listbox item %d toggled"), event.GetInt() );
32b8ec41
VZ
613}
614
c02e5a31 615void ListboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
616{
617 CreateLbox();
618}
619
eecdb000 620#endif // wxUSE_LISTBOX