]> git.saurik.com Git - wxWidgets.git/blame - samples/listbox/lboxtest.cpp
removed SetAutoLayout(true) calls when a corresponding SetSizer() was also called...
[wxWidgets.git] / samples / listbox / lboxtest.cpp
CommitLineData
4f37a20b
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: lboxtest.cpp
3// Purpose: wxListBox sample
4// Author: Vadim Zeitlin
5// Id: $Id$
6// Copyright: (c) 2000 Vadim Zeitlin
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10/*
11 Current bugs:
12
13 +1. horz scrollbar doesn't appear in listbox
14 +2. truncating text ctrl doesn't update display
15 +3. deleting last listbox item doesn't update display
16 4. text ctrl background corrupted after resize
17 */
18
19// ============================================================================
20// declarations
21// ============================================================================
22
23#ifdef __GNUG__
24 #pragma implementation "lboxtest.cpp"
25 #pragma interface "lboxtest.cpp"
26#endif
27
28// ----------------------------------------------------------------------------
29// headers
30// ----------------------------------------------------------------------------
31
32// for compilers that support precompilation, includes "wx/wx.h".
33#include "wx/wxprec.h"
34
35#ifdef __BORLANDC__
36 #pragma hdrstop
37#endif
38
39// for all others, include the necessary headers
40#ifndef WX_PRECOMP
dacaa6f1 41 #include "wx/wx.h"
4f37a20b
VZ
42 #include "wx/app.h"
43 #include "wx/frame.h"
44 #include "wx/dcclient.h"
45
46 #include "wx/button.h"
47 #include "wx/checkbox.h"
48 #include "wx/checklst.h"
49 #include "wx/listbox.h"
50 #include "wx/radiobox.h"
51 #include "wx/radiobut.h"
52 #include "wx/statbox.h"
53 #include "wx/stattext.h"
54 #include "wx/textctrl.h"
55#endif
56
57#include "wx/sizer.h"
58
59#ifdef __WXUNIVERSAL__
60 #include "wx/univ/theme.h"
61#endif // __WXUNIVERSAL__
62
63// ----------------------------------------------------------------------------
64// constants
65// ----------------------------------------------------------------------------
66
67// control ids
68enum
69{
70 LboxTest_Reset = 100,
71 LboxTest_Create,
72 LboxTest_Add,
73 LboxTest_AddText,
74 LboxTest_AddSeveral,
75 LboxTest_AddMany,
76 LboxTest_Clear,
77 LboxTest_ClearLog,
78 LboxTest_Change,
79 LboxTest_ChangeText,
80 LboxTest_Delete,
81 LboxTest_DeleteText,
82 LboxTest_DeleteSel,
83 LboxTest_Listbox,
84 LboxTest_Quit
85};
86
87// ----------------------------------------------------------------------------
88// our classes
89// ----------------------------------------------------------------------------
90
91// Define a new application type, each program should derive a class from wxApp
92class LboxTestApp : public wxApp
93{
94public:
95 // override base class virtuals
96 // ----------------------------
97
98 // this one is called on application startup and is a good place for the app
99 // initialization (doing it here and not in the ctor allows to have an error
100 // return: if OnInit() returns false, the application terminates)
101 virtual bool OnInit();
102};
103
104// Define a new frame type: this is going to be our main frame
105class LboxTestFrame : public wxFrame
106{
107public:
108 // ctor(s) and dtor
109 LboxTestFrame(const wxString& title);
110 virtual ~LboxTestFrame();
111
112protected:
113 // event handlers
114 void OnButtonReset(wxCommandEvent& event);
115 void OnButtonCreate(wxCommandEvent& event);
116 void OnButtonChange(wxCommandEvent& event);
117 void OnButtonDelete(wxCommandEvent& event);
118 void OnButtonDeleteSel(wxCommandEvent& event);
119 void OnButtonClear(wxCommandEvent& event);
120 void OnButtonClearLog(wxCommandEvent& event);
121 void OnButtonAdd(wxCommandEvent& event);
122 void OnButtonAddSeveral(wxCommandEvent& event);
123 void OnButtonAddMany(wxCommandEvent& event);
124 void OnButtonQuit(wxCommandEvent& event);
125
126 void OnListbox(wxCommandEvent& event);
127 void OnListboxDClick(wxCommandEvent& event);
128
129 void OnCheckOrRadioBox(wxCommandEvent& event);
130
131 void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
132 void OnUpdateUICreateButton(wxUpdateUIEvent& event);
133 void OnUpdateUIClearButton(wxUpdateUIEvent& event);
134 void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
135 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event);
136
137 // reset the listbox parameters
138 void Reset();
139
140 // (re)create the listbox
141 void CreateLbox();
142
143 // listbox parameters
144 // ------------------
145
146 // the selection mode
147 enum LboxSelection
148 {
149 LboxSel_Single,
150 LboxSel_Extended,
151 LboxSel_Multiple
152 } m_lboxSelMode;
153
154 // should it be sorted?
155 bool m_sorted;
156
157 // should it have horz scroll/vert scrollbar permanently shown?
158 bool m_horzScroll,
159 m_vertScrollAlways;
160
161 // should the recreate button be enabled?
162 bool m_dirty;
163
164 // the controls
165 // ------------
166
167 // the sel mode radiobox
168 wxRadioBox *m_radioSelMode;
169
170 // the checkboxes
171 wxCheckBox *m_chkSort,
172 *m_chkHScroll,
173 *m_chkVScroll;
174
175 // the listbox itself and the sizer it is in
176 wxListBox *m_lbox;
177 wxSizer *m_sizerLbox;
178
179 // the listbox for logging messages
180 wxListBox *m_lboxLog;
181
182 // the text entries for "Add/change string" and "Delete" buttons
183 wxTextCtrl *m_textAdd,
184 *m_textChange,
185 *m_textDelete;
186
187private:
188 // the log target we use to redirect messages to the listbox
189 wxLog *m_logTarget;
190
be5a51fb 191 // any class wishing to process wxWidgets events must use this macro
4f37a20b
VZ
192 DECLARE_EVENT_TABLE()
193};
194
195// A log target which just redirects the messages to a listbox
196class LboxLogger : public wxLog
197{
198public:
199 LboxLogger(wxListBox *lbox, wxLog *logOld)
200 {
201 m_lbox = lbox;
202 //m_lbox->Disable(); -- looks ugly under MSW
203 m_logOld = logOld;
204 }
205
206 virtual ~LboxLogger()
207 {
208 wxLog::SetActiveTarget(m_logOld);
209 }
210
211private:
212 // implement sink functions
213 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t)
214 {
215 // don't put trace messages into listbox or we can get into infinite
216 // recursion
217 if ( level == wxLOG_Trace )
218 {
219 if ( m_logOld )
220 {
221 // cast is needed to call protected method
222 ((LboxLogger *)m_logOld)->DoLog(level, szString, t);
223 }
224 }
225 else
226 {
227 wxLog::DoLog(level, szString, t);
228 }
229 }
230
d1f47235 231 virtual void DoLogString(const wxChar *szString, time_t WXUNUSED(t))
4f37a20b
VZ
232 {
233 wxString msg;
234 TimeStamp(&msg);
235 msg += szString;
236 #ifdef __WXUNIVERSAL__
237 m_lbox->AppendAndEnsureVisible(msg);
238 #else // other ports don't have this method yet
239 m_lbox->Append(msg);
240
241 // SetFirstItem() isn't implemented in wxGTK
242 #ifndef __WXGTK__
243 m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
244 #endif
245 #endif
246 }
247
248 // the control we use
249 wxListBox *m_lbox;
250
251 // the old log target
252 wxLog *m_logOld;
253};
254
255// ----------------------------------------------------------------------------
256// misc macros
257// ----------------------------------------------------------------------------
258
259IMPLEMENT_APP(LboxTestApp)
260
4f37a20b
VZ
261// ----------------------------------------------------------------------------
262// event tables
263// ----------------------------------------------------------------------------
264
265BEGIN_EVENT_TABLE(LboxTestFrame, wxFrame)
266 EVT_BUTTON(LboxTest_Reset, LboxTestFrame::OnButtonReset)
267 EVT_BUTTON(LboxTest_Create, LboxTestFrame::OnButtonCreate)
268 EVT_BUTTON(LboxTest_Change, LboxTestFrame::OnButtonChange)
269 EVT_BUTTON(LboxTest_Delete, LboxTestFrame::OnButtonDelete)
270 EVT_BUTTON(LboxTest_DeleteSel, LboxTestFrame::OnButtonDeleteSel)
271 EVT_BUTTON(LboxTest_Clear, LboxTestFrame::OnButtonClear)
272 EVT_BUTTON(LboxTest_ClearLog, LboxTestFrame::OnButtonClearLog)
273 EVT_BUTTON(LboxTest_Add, LboxTestFrame::OnButtonAdd)
274 EVT_BUTTON(LboxTest_AddSeveral, LboxTestFrame::OnButtonAddSeveral)
275 EVT_BUTTON(LboxTest_AddMany, LboxTestFrame::OnButtonAddMany)
276 EVT_BUTTON(LboxTest_Quit, LboxTestFrame::OnButtonQuit)
277
278 EVT_TEXT_ENTER(LboxTest_AddText, LboxTestFrame::OnButtonAdd)
279 EVT_TEXT_ENTER(LboxTest_DeleteText, LboxTestFrame::OnButtonDelete)
280
281 EVT_UPDATE_UI_RANGE(LboxTest_Reset, LboxTest_Create,
282 LboxTestFrame::OnUpdateUICreateButton)
283
284 EVT_UPDATE_UI(LboxTest_AddSeveral, LboxTestFrame::OnUpdateUIAddSeveral)
285 EVT_UPDATE_UI(LboxTest_Clear, LboxTestFrame::OnUpdateUIClearButton)
286 EVT_UPDATE_UI(LboxTest_DeleteText, LboxTestFrame::OnUpdateUIClearButton)
287 EVT_UPDATE_UI(LboxTest_Delete, LboxTestFrame::OnUpdateUIDeleteButton)
288 EVT_UPDATE_UI(LboxTest_Change, LboxTestFrame::OnUpdateUIDeleteSelButton)
289 EVT_UPDATE_UI(LboxTest_ChangeText, LboxTestFrame::OnUpdateUIDeleteSelButton)
290 EVT_UPDATE_UI(LboxTest_DeleteSel, LboxTestFrame::OnUpdateUIDeleteSelButton)
291
292 EVT_LISTBOX(LboxTest_Listbox, LboxTestFrame::OnListbox)
11180f77
WS
293 EVT_LISTBOX_DCLICK(wxID_ANY, LboxTestFrame::OnListboxDClick)
294 EVT_CHECKBOX(wxID_ANY, LboxTestFrame::OnCheckOrRadioBox)
295 EVT_RADIOBOX(wxID_ANY, LboxTestFrame::OnCheckOrRadioBox)
4f37a20b
VZ
296END_EVENT_TABLE()
297
298// ============================================================================
299// implementation
300// ============================================================================
301
302// ----------------------------------------------------------------------------
303// app class
304// ----------------------------------------------------------------------------
305
306bool LboxTestApp::OnInit()
307{
308 wxFrame *frame = new LboxTestFrame(_T("wxListBox sample"));
309 frame->Show();
310
311 //wxLog::AddTraceMask(_T("listbox"));
312 wxLog::AddTraceMask(_T("scrollbar"));
313
11180f77 314 return true;
4f37a20b
VZ
315}
316
317// ----------------------------------------------------------------------------
318// top level frame class
319// ----------------------------------------------------------------------------
320
321LboxTestFrame::LboxTestFrame(const wxString& title)
11180f77 322 : wxFrame(NULL, wxID_ANY, title, wxPoint(100, 100))
4f37a20b
VZ
323{
324 // init everything
11180f77 325 m_dirty = false;
4f37a20b
VZ
326 m_radioSelMode = (wxRadioBox *)NULL;
327
328 m_chkVScroll =
329 m_chkHScroll =
330 m_chkSort = (wxCheckBox *)NULL;
331
332 m_lbox =
333 m_lboxLog = (wxListBox *)NULL;
334 m_sizerLbox = (wxSizer *)NULL;
335
336 m_logTarget = (wxLog *)NULL;
337
11180f77 338 wxPanel *panel = new wxPanel(this, wxID_ANY);
4f37a20b
VZ
339
340 /*
341 What we create here is a frame having 3 panes: the explanatory pane to
342 the left allowing to set the listbox styles and recreate the control,
343 the pane containing the listbox itself and the lower pane containing
344 the buttons which allow to add/change/delete strings to/from it.
345 */
346 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL),
347 *sizerUp = new wxBoxSizer(wxHORIZONTAL),
348 *sizerLeft,
349 *sizerRight = new wxBoxSizer(wxVERTICAL);
350
351 // upper left pane
352 static const wxString modes[] =
353 {
354 _T("single"),
355 _T("extended"),
356 _T("multiple"),
357 };
358
11180f77
WS
359 wxStaticBox *box = new wxStaticBox(panel, wxID_ANY, _T("&Set listbox parameters"));
360 m_radioSelMode = new wxRadioBox(panel, wxID_ANY, _T("Selection &mode:"),
4f37a20b
VZ
361 wxDefaultPosition, wxDefaultSize,
362 WXSIZEOF(modes), modes,
363 1, wxRA_SPECIFY_COLS);
364
11180f77
WS
365 m_chkVScroll = new wxCheckBox(panel, wxID_ANY, _T("Always show &vertical scrollbar"));
366 m_chkHScroll = new wxCheckBox(panel, wxID_ANY, _T("Show &horizontal scrollbar"));
367 m_chkSort = new wxCheckBox(panel, wxID_ANY, _T("&Sort items"));
4f37a20b
VZ
368
369 sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
370
371 sizerLeft->Add(m_chkVScroll, 0, wxLEFT | wxRIGHT, 5);
372 sizerLeft->Add(m_chkHScroll, 0, wxLEFT | wxRIGHT, 5);
373 sizerLeft->Add(m_chkSort, 0, wxLEFT | wxRIGHT, 5);
374 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
375 sizerLeft->Add(m_radioSelMode, 0, wxGROW | wxALL, 5);
376
377 wxSizer *sizerBtn = new wxBoxSizer(wxHORIZONTAL);
378 wxButton *btn = new wxButton(panel, LboxTest_Reset, _T("&Reset"));
379 sizerBtn->Add(btn, 0, wxLEFT | wxRIGHT, 5);
380 btn = new wxButton(panel, LboxTest_Create, _T("&Create"));
381 sizerBtn->Add(btn, 0, wxLEFT | wxRIGHT, 5);
382 sizerLeft->Add(sizerBtn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
383
384 // middle pane
11180f77 385 wxStaticBox *box2 = new wxStaticBox(panel, wxID_ANY, _T("&Change listbox contents"));
4f37a20b
VZ
386 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
387
388 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
389 btn = new wxButton(panel, LboxTest_Add, _T("&Add this string"));
390 m_textAdd = new wxTextCtrl(panel, LboxTest_AddText, _T("test item 0"));
391 sizerRow->Add(btn, 0, wxRIGHT, 5);
392 sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
393 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
394
395 btn = new wxButton(panel, LboxTest_AddSeveral, _T("&Insert a few strings"));
396 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
397
398 btn = new wxButton(panel, LboxTest_AddMany, _T("Add &many strings"));
399 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
400
401 sizerRow = new wxBoxSizer(wxHORIZONTAL);
402 btn = new wxButton(panel, LboxTest_Change, _T("C&hange current"));
dabbc6a5 403 m_textChange = new wxTextCtrl(panel, LboxTest_ChangeText, wxEmptyString);
4f37a20b
VZ
404 sizerRow->Add(btn, 0, wxRIGHT, 5);
405 sizerRow->Add(m_textChange, 1, wxLEFT, 5);
406 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
407
408 sizerRow = new wxBoxSizer(wxHORIZONTAL);
409 btn = new wxButton(panel, LboxTest_Delete, _T("&Delete this item"));
dabbc6a5 410 m_textDelete = new wxTextCtrl(panel, LboxTest_DeleteText, wxEmptyString);
4f37a20b
VZ
411 sizerRow->Add(btn, 0, wxRIGHT, 5);
412 sizerRow->Add(m_textDelete, 1, wxLEFT, 5);
413 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
414
415 btn = new wxButton(panel, LboxTest_DeleteSel, _T("Delete &selection"));
416 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
417
418 btn = new wxButton(panel, LboxTest_Clear, _T("&Clear"));
419 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
420
421 // right pane
422 m_lbox = new wxListBox(panel, LboxTest_Listbox,
423 wxDefaultPosition, wxDefaultSize,
424 0, NULL,
425 wxLB_HSCROLL);
426 sizerRight->Add(m_lbox, 1, wxGROW | wxALL, 5);
427 sizerRight->SetMinSize(250, 0);
428 m_sizerLbox = sizerRight; // save it to modify it later
429
430 // the 3 panes panes compose the upper part of the window
431 sizerUp->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
432 sizerUp->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
433 sizerUp->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
434
435 // the lower one only has the log listbox and a button to clear it
436 wxSizer *sizerDown = new wxStaticBoxSizer
437 (
11180f77 438 new wxStaticBox(panel, wxID_ANY, _T("&Log window")),
4f37a20b
VZ
439 wxVERTICAL
440 );
11180f77 441 m_lboxLog = new wxListBox(panel, wxID_ANY);
4f37a20b
VZ
442 sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
443 wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
444 btn = new wxButton(panel, LboxTest_ClearLog, _T("Clear &log"));
445 sizerBtns->Add(btn);
446 sizerBtns->Add(10, 0); // spacer
447 btn = new wxButton(panel, LboxTest_Quit, _T("E&xit"));
448 sizerBtns->Add(btn);
449 sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
450
451 // put everything together
452 sizerTop->Add(sizerUp, 1, wxGROW | (wxALL & ~wxBOTTOM), 10);
453 sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
454 sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10);
455
456 // final initialization
457 Reset();
11180f77 458 m_dirty = false;
4f37a20b 459
4f37a20b
VZ
460 panel->SetSizer(sizerTop);
461
462 sizerTop->Fit(this);
463 sizerTop->SetSizeHints(this);
464
465 // now that everything is created we can redirect the log messages to the
466 // listbox
467 m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
468 wxLog::SetActiveTarget(m_logTarget);
469}
470
471LboxTestFrame::~LboxTestFrame()
472{
473 delete m_logTarget;
474}
475
476// ----------------------------------------------------------------------------
477// operations
478// ----------------------------------------------------------------------------
479
480void LboxTestFrame::Reset()
481{
482 if ( m_radioSelMode->GetSelection() == LboxSel_Single &&
483 !m_chkSort->GetValue() &&
484 m_chkHScroll->GetValue() &&
485 !m_chkVScroll->GetValue() )
486 {
487 // nothing to do
488 return;
489 }
490
491 m_radioSelMode->SetSelection(LboxSel_Single);
11180f77
WS
492 m_chkSort->SetValue(false);
493 m_chkHScroll->SetValue(true);
494 m_chkVScroll->SetValue(false);
4f37a20b 495
11180f77 496 m_dirty = true;
4f37a20b
VZ
497}
498
499void LboxTestFrame::CreateLbox()
500{
501 int flags = 0;
502 switch ( m_radioSelMode->GetSelection() )
503 {
504 default:
505 wxFAIL_MSG( _T("unexpected radio box selection") );
506
507 case LboxSel_Single: flags |= wxLB_SINGLE; break;
508 case LboxSel_Extended: flags |= wxLB_EXTENDED; break;
509 case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break;
510 }
511
512 if ( m_chkVScroll->GetValue() )
513 flags |= wxLB_ALWAYS_SB;
514 if ( m_chkHScroll->GetValue() )
515 flags |= wxLB_HSCROLL;
516 if ( m_chkSort->GetValue() )
517 flags |= wxLB_SORT;
518
519 wxArrayString items;
520 if ( m_lbox )
521 {
522 int count = m_lbox->GetCount();
523 for ( int n = 0; n < count; n++ )
524 {
525 items.Add(m_lbox->GetString(n));
526 }
527
d1f47235 528 m_sizerLbox->Detach(m_lbox);
4f37a20b
VZ
529 delete m_lbox;
530 }
531
11180f77 532 m_lbox = new wxListBox(this, wxID_ANY,
4f37a20b
VZ
533 wxDefaultPosition, wxDefaultSize,
534 0, NULL,
535 flags);
536 m_lbox->Set(items);
537 m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
538 m_sizerLbox->Layout();
539
11180f77 540 m_dirty = false;
4f37a20b
VZ
541}
542
543// ----------------------------------------------------------------------------
544// event handlers
545// ----------------------------------------------------------------------------
546
547void LboxTestFrame::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
548{
549 Close();
550}
551
552void LboxTestFrame::OnButtonReset(wxCommandEvent& WXUNUSED(event))
553{
554 Reset();
555}
556
557void LboxTestFrame::OnButtonCreate(wxCommandEvent& WXUNUSED(event))
558{
559 CreateLbox();
560}
561
562void LboxTestFrame::OnButtonChange(wxCommandEvent& WXUNUSED(event))
563{
564 wxArrayInt selections;
565 int count = m_lbox->GetSelections(selections);
566 wxString s = m_textChange->GetValue();
567 for ( int n = 0; n < count; n++ )
568 {
569 m_lbox->SetString(selections[n], s);
570 }
571}
572
573void LboxTestFrame::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
574{
575 unsigned long n;
576 if ( !m_textDelete->GetValue().ToULong(&n) ||
577 (n >= (unsigned)m_lbox->GetCount()) )
578 {
579 return;
580 }
581
582 m_lbox->Delete(n);
583}
584
585void LboxTestFrame::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
586{
587 wxArrayInt selections;
588 int n = m_lbox->GetSelections(selections);
589 while ( n > 0 )
590 {
591 m_lbox->Delete(selections[--n]);
592 }
593}
594
87728739 595void LboxTestFrame::OnButtonClear(wxCommandEvent& WXUNUSED(event))
4f37a20b
VZ
596{
597 m_lbox->Clear();
598}
599
87728739 600void LboxTestFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
4f37a20b
VZ
601{
602 m_lboxLog->Clear();
603}
604
87728739 605void LboxTestFrame::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
4f37a20b
VZ
606{
607 static size_t s_item = 0;
608
609 wxString s = m_textAdd->GetValue();
610 if ( !m_textAdd->IsModified() )
611 {
612 // update the default string
613 m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item));
614 }
615
616 m_lbox->Append(s);
617}
618
619void LboxTestFrame::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
620{
621 // "many" means 1000 here
622 for ( size_t n = 0; n < 1000; n++ )
623 {
624 m_lbox->Append(wxString::Format(_T("item #%u"), n));
625 }
626}
627
87728739 628void LboxTestFrame::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event))
4f37a20b
VZ
629{
630 wxArrayString items;
631 items.Add(_T("First"));
632 items.Add(_T("another one"));
633 items.Add(_T("and the last (very very very very very very very very very very long) one"));
634 m_lbox->InsertItems(items, 0);
635}
636
637void LboxTestFrame::OnUpdateUICreateButton(wxUpdateUIEvent& event)
638{
639 event.Enable(m_dirty);
640}
641
642void LboxTestFrame::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
643{
644 unsigned long n;
645 event.Enable(m_textDelete->GetValue().ToULong(&n) &&
646 (n < (unsigned)m_lbox->GetCount()));
647}
648
649void LboxTestFrame::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
650{
651 wxArrayInt selections;
652 event.Enable(m_lbox->GetSelections(selections) != 0);
653}
654
655void LboxTestFrame::OnUpdateUIClearButton(wxUpdateUIEvent& event)
656{
657 event.Enable(m_lbox->GetCount() != 0);
658}
659
660void LboxTestFrame::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
661{
662 event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
663}
664
665void LboxTestFrame::OnListbox(wxCommandEvent& event)
666{
667 int sel = event.GetInt();
dacaa6f1 668 m_textDelete->SetValue(wxString::Format(_T("%d"), sel));
4f37a20b
VZ
669
670 wxLogMessage(_T("Listbox item %d selected"), sel);
671}
672
673void LboxTestFrame::OnListboxDClick(wxCommandEvent& event)
674{
dacaa6f1
JS
675 int sel = event.GetInt();
676 wxLogMessage(_T("Listbox item %d double clicked"), sel);
4f37a20b
VZ
677}
678
87728739 679void LboxTestFrame::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
4f37a20b 680{
11180f77 681 m_dirty = true;
4f37a20b
VZ
682}
683