]> git.saurik.com Git - wxWidgets.git/blob - samples/listbox/lboxtest.cpp
Applied patch [ 846809 ] Cleaning of 11 samples
[wxWidgets.git] / samples / listbox / lboxtest.cpp
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
41 #include "wx/wx.h"
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
68 enum
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
92 class LboxTestApp : public wxApp
93 {
94 public:
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
105 class LboxTestFrame : public wxFrame
106 {
107 public:
108 // ctor(s) and dtor
109 LboxTestFrame(const wxString& title);
110 virtual ~LboxTestFrame();
111
112 protected:
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
187 private:
188 // the log target we use to redirect messages to the listbox
189 wxLog *m_logTarget;
190
191 // any class wishing to process wxWindows events must use this macro
192 DECLARE_EVENT_TABLE()
193 };
194
195 // A log target which just redirects the messages to a listbox
196 class LboxLogger : public wxLog
197 {
198 public:
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
211 private:
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
231 virtual void DoLogString(const wxChar *szString, time_t t)
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
259 IMPLEMENT_APP(LboxTestApp)
260
261 // ----------------------------------------------------------------------------
262 // event tables
263 // ----------------------------------------------------------------------------
264
265 BEGIN_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)
293 EVT_LISTBOX_DCLICK(-1, LboxTestFrame::OnListboxDClick)
294 EVT_CHECKBOX(-1, LboxTestFrame::OnCheckOrRadioBox)
295 EVT_RADIOBOX(-1, LboxTestFrame::OnCheckOrRadioBox)
296 END_EVENT_TABLE()
297
298 // ============================================================================
299 // implementation
300 // ============================================================================
301
302 // ----------------------------------------------------------------------------
303 // app class
304 // ----------------------------------------------------------------------------
305
306 bool 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
314 return TRUE;
315 }
316
317 // ----------------------------------------------------------------------------
318 // top level frame class
319 // ----------------------------------------------------------------------------
320
321 LboxTestFrame::LboxTestFrame(const wxString& title)
322 : wxFrame(NULL, -1, title, wxPoint(100, 100))
323 {
324 // init everything
325 m_dirty = FALSE;
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
338 wxPanel *panel = new wxPanel(this, -1);
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
359 wxStaticBox *box = new wxStaticBox(panel, -1, _T("&Set listbox parameters"));
360 m_radioSelMode = new wxRadioBox(panel, -1, _T("Selection &mode:"),
361 wxDefaultPosition, wxDefaultSize,
362 WXSIZEOF(modes), modes,
363 1, wxRA_SPECIFY_COLS);
364
365 m_chkVScroll = new wxCheckBox(panel, -1, _T("Always show &vertical scrollbar"));
366 m_chkHScroll = new wxCheckBox(panel, -1, _T("Show &horizontal scrollbar"));
367 m_chkSort = new wxCheckBox(panel, -1, _T("&Sort items"));
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
385 wxStaticBox *box2 = new wxStaticBox(panel, -1, _T("&Change listbox contents"));
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"));
403 m_textChange = new wxTextCtrl(panel, LboxTest_ChangeText, _T(""));
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"));
410 m_textDelete = new wxTextCtrl(panel, LboxTest_DeleteText, _T(""));
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 (
438 new wxStaticBox(panel, -1, _T("&Log window")),
439 wxVERTICAL
440 );
441 m_lboxLog = new wxListBox(panel, -1);
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();
458 m_dirty = FALSE;
459
460 panel->SetAutoLayout(TRUE);
461 panel->SetSizer(sizerTop);
462
463 sizerTop->Fit(this);
464 sizerTop->SetSizeHints(this);
465
466 // now that everything is created we can redirect the log messages to the
467 // listbox
468 m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
469 wxLog::SetActiveTarget(m_logTarget);
470 }
471
472 LboxTestFrame::~LboxTestFrame()
473 {
474 delete m_logTarget;
475 }
476
477 // ----------------------------------------------------------------------------
478 // operations
479 // ----------------------------------------------------------------------------
480
481 void LboxTestFrame::Reset()
482 {
483 if ( m_radioSelMode->GetSelection() == LboxSel_Single &&
484 !m_chkSort->GetValue() &&
485 m_chkHScroll->GetValue() &&
486 !m_chkVScroll->GetValue() )
487 {
488 // nothing to do
489 return;
490 }
491
492 m_radioSelMode->SetSelection(LboxSel_Single);
493 m_chkSort->SetValue(FALSE);
494 m_chkHScroll->SetValue(TRUE);
495 m_chkVScroll->SetValue(FALSE);
496
497 m_dirty = TRUE;
498 }
499
500 void LboxTestFrame::CreateLbox()
501 {
502 int flags = 0;
503 switch ( m_radioSelMode->GetSelection() )
504 {
505 default:
506 wxFAIL_MSG( _T("unexpected radio box selection") );
507
508 case LboxSel_Single: flags |= wxLB_SINGLE; break;
509 case LboxSel_Extended: flags |= wxLB_EXTENDED; break;
510 case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break;
511 }
512
513 if ( m_chkVScroll->GetValue() )
514 flags |= wxLB_ALWAYS_SB;
515 if ( m_chkHScroll->GetValue() )
516 flags |= wxLB_HSCROLL;
517 if ( m_chkSort->GetValue() )
518 flags |= wxLB_SORT;
519
520 wxArrayString items;
521 if ( m_lbox )
522 {
523 int count = m_lbox->GetCount();
524 for ( int n = 0; n < count; n++ )
525 {
526 items.Add(m_lbox->GetString(n));
527 }
528
529 m_sizerLbox->Remove(m_lbox);
530 delete m_lbox;
531 }
532
533 m_lbox = new wxListBox(this, -1,
534 wxDefaultPosition, wxDefaultSize,
535 0, NULL,
536 flags);
537 m_lbox->Set(items);
538 m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
539 m_sizerLbox->Layout();
540
541 m_dirty = FALSE;
542 }
543
544 // ----------------------------------------------------------------------------
545 // event handlers
546 // ----------------------------------------------------------------------------
547
548 void LboxTestFrame::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
549 {
550 Close();
551 }
552
553 void LboxTestFrame::OnButtonReset(wxCommandEvent& WXUNUSED(event))
554 {
555 Reset();
556 }
557
558 void LboxTestFrame::OnButtonCreate(wxCommandEvent& WXUNUSED(event))
559 {
560 CreateLbox();
561 }
562
563 void LboxTestFrame::OnButtonChange(wxCommandEvent& WXUNUSED(event))
564 {
565 wxArrayInt selections;
566 int count = m_lbox->GetSelections(selections);
567 wxString s = m_textChange->GetValue();
568 for ( int n = 0; n < count; n++ )
569 {
570 m_lbox->SetString(selections[n], s);
571 }
572 }
573
574 void LboxTestFrame::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
575 {
576 unsigned long n;
577 if ( !m_textDelete->GetValue().ToULong(&n) ||
578 (n >= (unsigned)m_lbox->GetCount()) )
579 {
580 return;
581 }
582
583 m_lbox->Delete(n);
584 }
585
586 void LboxTestFrame::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
587 {
588 wxArrayInt selections;
589 int n = m_lbox->GetSelections(selections);
590 while ( n > 0 )
591 {
592 m_lbox->Delete(selections[--n]);
593 }
594 }
595
596 void LboxTestFrame::OnButtonClear(wxCommandEvent& WXUNUSED(event))
597 {
598 m_lbox->Clear();
599 }
600
601 void LboxTestFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
602 {
603 m_lboxLog->Clear();
604 }
605
606 void LboxTestFrame::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
607 {
608 static size_t s_item = 0;
609
610 wxString s = m_textAdd->GetValue();
611 if ( !m_textAdd->IsModified() )
612 {
613 // update the default string
614 m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item));
615 }
616
617 m_lbox->Append(s);
618 }
619
620 void LboxTestFrame::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
621 {
622 // "many" means 1000 here
623 for ( size_t n = 0; n < 1000; n++ )
624 {
625 m_lbox->Append(wxString::Format(_T("item #%u"), n));
626 }
627 }
628
629 void LboxTestFrame::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event))
630 {
631 wxArrayString items;
632 items.Add(_T("First"));
633 items.Add(_T("another one"));
634 items.Add(_T("and the last (very very very very very very very very very very long) one"));
635 m_lbox->InsertItems(items, 0);
636 }
637
638 void LboxTestFrame::OnUpdateUICreateButton(wxUpdateUIEvent& event)
639 {
640 event.Enable(m_dirty);
641 }
642
643 void LboxTestFrame::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
644 {
645 unsigned long n;
646 event.Enable(m_textDelete->GetValue().ToULong(&n) &&
647 (n < (unsigned)m_lbox->GetCount()));
648 }
649
650 void LboxTestFrame::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
651 {
652 wxArrayInt selections;
653 event.Enable(m_lbox->GetSelections(selections) != 0);
654 }
655
656 void LboxTestFrame::OnUpdateUIClearButton(wxUpdateUIEvent& event)
657 {
658 event.Enable(m_lbox->GetCount() != 0);
659 }
660
661 void LboxTestFrame::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
662 {
663 event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
664 }
665
666 void LboxTestFrame::OnListbox(wxCommandEvent& event)
667 {
668 int sel = event.GetInt();
669 m_textDelete->SetValue(wxString::Format(_T("%d"), sel));
670
671 wxLogMessage(_T("Listbox item %d selected"), sel);
672 }
673
674 void LboxTestFrame::OnListboxDClick(wxCommandEvent& event)
675 {
676 int sel = event.GetInt();
677 wxLogMessage(_T("Listbox item %d double clicked"), sel);
678 }
679
680 void LboxTestFrame::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
681 {
682 m_dirty = TRUE;
683 }
684