]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
regen bakefiles - get rid of explicit size setting after ctor
[wxWidgets.git] / samples / controls / controls.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: controls.cpp
3 // Purpose: Controls wxWidgets sample
4 // Author: Robert Roebling
5 // Modified by:
6 // RCS-ID: $Id$
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
23 #include "wx/spinbutt.h"
24 #endif
25 #include "wx/tglbtn.h"
26 #include "wx/bookctrl.h"
27 #include "wx/imaglist.h"
28 #include "wx/artprov.h"
29
30 #if wxUSE_TOOLTIPS
31 #include "wx/tooltip.h"
32 #endif
33
34 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
35 #define USE_XPM
36 #endif
37
38 #ifdef USE_XPM
39 #include "mondrian.xpm"
40 #include "icons/choice.xpm"
41 #include "icons/combo.xpm"
42 #include "icons/list.xpm"
43 #include "icons/radio.xpm"
44 #include "icons/text.xpm"
45 #include "icons/gauge.xpm"
46 #endif
47
48 #ifndef wxUSE_SPINBTN
49 #define wxUSE_SPINBTN 1
50 #endif
51
52 #include "wx/progdlg.h"
53
54 #if wxUSE_SPINCTRL
55 #include "wx/spinctrl.h"
56 #endif // wxUSE_SPINCTRL
57
58 //----------------------------------------------------------------------
59 // class definitions
60 //----------------------------------------------------------------------
61
62 class MyApp: public wxApp
63 {
64 public:
65 bool OnInit();
66 };
67
68 class MyPanel: public wxPanel
69 {
70 public:
71 MyPanel(wxFrame *frame, int x, int y, int w, int h);
72 virtual ~MyPanel();
73
74 void OnSize( wxSizeEvent& event );
75 void OnListBox( wxCommandEvent &event );
76 void OnListBoxDoubleClick( wxCommandEvent &event );
77 void OnListBoxButtons( wxCommandEvent &event );
78 #if wxUSE_CHOICE
79 void OnChoice( wxCommandEvent &event );
80 void OnChoiceButtons( wxCommandEvent &event );
81 #endif
82 void OnCombo( wxCommandEvent &event );
83 void OnComboTextChanged( wxCommandEvent &event );
84 void OnComboTextEnter( wxCommandEvent &event );
85 void OnComboButtons( wxCommandEvent &event );
86 void OnRadio( wxCommandEvent &event );
87 void OnRadioButtons( wxCommandEvent &event );
88 void OnRadioButton1( wxCommandEvent &event );
89 void OnRadioButton2( wxCommandEvent &event );
90 void OnSetFont( wxCommandEvent &event );
91 void OnPageChanged( wxBookCtrlEvent &event );
92 void OnPageChanging( wxBookCtrlEvent &event );
93 void OnSliderUpdate( wxCommandEvent &event );
94 void OnUpdateLabel( wxCommandEvent &event );
95 #if wxUSE_SPINBTN
96 void OnSpinUp( wxSpinEvent &event );
97 void OnSpinDown( wxSpinEvent &event );
98 void OnSpinUpdate( wxSpinEvent &event );
99 void OnUpdateShowProgress( wxUpdateUIEvent& event );
100 void OnShowProgress( wxCommandEvent &event );
101 #endif // wxUSE_SPINBTN
102
103 #if wxUSE_SPINCTRL
104 void OnSpinCtrl(wxSpinEvent& event);
105 void OnSpinCtrlUp(wxSpinEvent& event);
106 void OnSpinCtrlDown(wxSpinEvent& event);
107 void OnSpinCtrlText(wxCommandEvent& event);
108 #endif // wxUSE_SPINCTRL
109
110 void OnEnableAll(wxCommandEvent& event);
111 void OnChangeColour(wxCommandEvent& event);
112 void OnTestButton(wxCommandEvent& event);
113 void OnBmpButton(wxCommandEvent& event);
114
115 void OnSizerCheck (wxCommandEvent &event);
116
117 wxListBox *m_listbox,
118 *m_listboxSorted;
119 #if wxUSE_CHOICE
120 wxChoice *m_choice,
121 *m_choiceSorted;
122 #endif // wxUSE_CHOICE
123
124 wxComboBox *m_combo;
125 wxRadioBox *m_radio;
126 wxGauge *m_gauge,
127 *m_gaugeVert;
128 #if wxUSE_SLIDER
129 wxSlider *m_slider;
130 #endif // wxUSE_SLIDER
131 wxButton *m_fontButton;
132 wxButton *m_lbSelectNum;
133 wxButton *m_lbSelectThis;
134 #if wxUSE_SPINBTN
135 wxSpinButton *m_spinbutton;
136 wxButton *m_btnProgress;
137 #endif // wxUSE_SPINBTN
138
139 #if wxUSE_SPINCTRL
140 wxSpinCtrl *m_spinctrl;
141 #endif // wxUSE_SPINCTRL
142
143 wxTextCtrl *m_spintext;
144 wxCheckBox *m_checkbox;
145
146 wxTextCtrl *m_text;
147 wxBookCtrl *m_book;
148
149 wxStaticText *m_label;
150
151 wxBoxSizer *m_buttonSizer;
152 wxButton *m_sizerBtn1;
153 wxButton *m_sizerBtn2;
154 wxButton *m_sizerBtn3;
155 wxButton *m_sizerBtn4;
156 wxBoxSizer *m_hsizer;
157 wxButton *m_bigBtn;
158
159 private:
160 wxLog *m_logTargetOld;
161
162 DECLARE_EVENT_TABLE()
163 };
164
165 class MyFrame: public wxFrame
166 {
167 public:
168 MyFrame(const wxChar *title, int x, int y);
169
170 void OnQuit(wxCommandEvent& event);
171 void OnAbout(wxCommandEvent& event);
172 void OnClearLog(wxCommandEvent& event);
173
174 #if wxUSE_TOOLTIPS
175 void OnSetTooltipDelay(wxCommandEvent& event);
176 void OnToggleTooltips(wxCommandEvent& event);
177 #endif // wxUSE_TOOLTIPS
178
179 void OnEnableAll(wxCommandEvent& event);
180
181 void OnIdle( wxIdleEvent& event );
182 void OnIconized( wxIconizeEvent& event );
183 void OnMaximized( wxMaximizeEvent& event );
184 void OnSize( wxSizeEvent& event );
185 void OnMove( wxMoveEvent& event );
186
187 MyPanel *GetPanel() const { return m_panel; }
188
189 private:
190 #if wxUSE_STATUSBAR
191 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
192 {
193 if ( m_frameStatusBar )
194 {
195 wxString msg;
196 wxSize sizeAll = GetSize(),
197 sizeCl = GetClientSize();
198 msg.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
199 pos.x, pos.y,
200 size.x, size.y,
201 sizeAll.x, sizeAll.y,
202 sizeCl.x, sizeCl.y);
203 SetStatusText(msg, 1);
204 }
205 }
206 #endif // wxUSE_STATUSBAR
207
208 MyPanel *m_panel;
209
210 DECLARE_EVENT_TABLE()
211 };
212
213 // a button which intercepts double clicks (for testing...)
214 class MyButton : public wxButton
215 {
216 public:
217 MyButton(wxWindow *parent,
218 wxWindowID id,
219 const wxString& label = wxEmptyString,
220 const wxPoint& pos = wxDefaultPosition,
221 const wxSize& size = wxDefaultSize)
222 : wxButton(parent, id, label, pos, size)
223 {
224 }
225
226 void OnDClick(wxMouseEvent& event)
227 {
228 wxLogMessage(_T("MyButton::OnDClick"));
229
230 event.Skip();
231 }
232
233 private:
234 DECLARE_EVENT_TABLE()
235 };
236
237 // a combo which intercepts chars (to test Windows behaviour)
238 class MyComboBox : public wxComboBox
239 {
240 public:
241 MyComboBox(wxWindow *parent, wxWindowID id,
242 const wxString& value = wxEmptyString,
243 const wxPoint& pos = wxDefaultPosition,
244 const wxSize& size = wxDefaultSize,
245 int n = 0, const wxString choices[] = NULL,
246 long style = 0,
247 const wxValidator& validator = wxDefaultValidator,
248 const wxString& name = wxComboBoxNameStr)
249 : wxComboBox(parent, id, value, pos, size, n, choices, style,
250 validator, name) { }
251
252 protected:
253 void OnChar(wxKeyEvent& event);
254 void OnKeyDown(wxKeyEvent& event);
255 void OnKeyUp(wxKeyEvent& event);
256 void OnFocusGot(wxFocusEvent& event)
257 {
258 wxLogMessage(_T("MyComboBox::OnFocusGot"));
259
260 event.Skip();
261 }
262
263 private:
264 DECLARE_EVENT_TABLE()
265 };
266
267 // a radiobox which handles focus set/kill (for testing)
268 class MyRadioBox : public wxRadioBox
269 {
270 public:
271 MyRadioBox(wxWindow *parent,
272 wxWindowID id,
273 const wxString& title = wxEmptyString,
274 const wxPoint& pos = wxDefaultPosition,
275 const wxSize& size = wxDefaultSize,
276 int n = 0, const wxString choices[] = NULL,
277 int majorDim = 1,
278 long style = wxRA_HORIZONTAL,
279 const wxValidator& validator = wxDefaultValidator,
280 const wxString& name = wxRadioBoxNameStr)
281 : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
282 style, validator, name) { SetForegroundColour(*wxRED); }
283
284 protected:
285 void OnFocusGot(wxFocusEvent& event)
286 {
287 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
288
289 event.Skip();
290 }
291
292 void OnFocusLost(wxFocusEvent& event)
293 {
294 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
295
296 event.Skip();
297 }
298
299 private:
300 DECLARE_EVENT_TABLE()
301 };
302
303 //----------------------------------------------------------------------
304 // other
305 //----------------------------------------------------------------------
306
307 static void SetListboxClientData(const wxChar *name, wxListBox *control);
308
309 #if wxUSE_CHOICE
310 static void SetChoiceClientData(const wxChar *name, wxChoice *control);
311 #endif // wxUSE_CHOICE
312
313 IMPLEMENT_APP(MyApp)
314
315 //----------------------------------------------------------------------
316 // MyApp
317 //----------------------------------------------------------------------
318
319 enum
320 {
321 CONTROLS_QUIT = 100,
322 CONTROLS_TEXT,
323 CONTROLS_ABOUT,
324 CONTROLS_CLEAR_LOG,
325
326 // tooltip menu
327 CONTROLS_SET_TOOLTIP_DELAY = 200,
328 CONTROLS_ENABLE_TOOLTIPS,
329
330 // panel menu
331 CONTROLS_ENABLE_ALL
332 };
333
334 bool MyApp::OnInit()
335 {
336 // use standard command line handling:
337 if ( !wxApp::OnInit() )
338 return false;
339
340 // parse the cmd line
341 int x = 50,
342 y = 50;
343 if ( argc == 3 )
344 {
345 wxSscanf(wxString(argv[1]), wxT("%d"), &x);
346 wxSscanf(wxString(argv[2]), wxT("%d"), &y);
347 }
348
349 // Create the main frame window
350 MyFrame *frame = new MyFrame(_T("Controls wxWidgets App"), x, y);
351 frame->Show(true);
352
353 return true;
354 }
355
356 //----------------------------------------------------------------------
357 // MyPanel
358 //----------------------------------------------------------------------
359
360 const int ID_BOOK = 1000;
361
362 const int ID_LISTBOX = 130;
363 const int ID_LISTBOX_SEL_NUM = 131;
364 const int ID_LISTBOX_SEL_STR = 132;
365 const int ID_LISTBOX_CLEAR = 133;
366 const int ID_LISTBOX_APPEND = 134;
367 const int ID_LISTBOX_DELETE = 135;
368 const int ID_LISTBOX_FONT = 136;
369 const int ID_LISTBOX_ENABLE = 137;
370 const int ID_LISTBOX_SORTED = 138;
371
372 const int ID_CHOICE = 120;
373 const int ID_CHOICE_SEL_NUM = 121;
374 const int ID_CHOICE_SEL_STR = 122;
375 const int ID_CHOICE_CLEAR = 123;
376 const int ID_CHOICE_APPEND = 124;
377 const int ID_CHOICE_DELETE = 125;
378 const int ID_CHOICE_FONT = 126;
379 const int ID_CHOICE_ENABLE = 127;
380 const int ID_CHOICE_SORTED = 128;
381
382 const int ID_COMBO = 140;
383 const int ID_COMBO_SEL_NUM = 141;
384 const int ID_COMBO_SEL_STR = 142;
385 const int ID_COMBO_CLEAR = 143;
386 const int ID_COMBO_APPEND = 144;
387 const int ID_COMBO_DELETE = 145;
388 const int ID_COMBO_FONT = 146;
389 const int ID_COMBO_ENABLE = 147;
390
391 const int ID_RADIOBOX = 160;
392 const int ID_RADIOBOX_SEL_NUM = 161;
393 const int ID_RADIOBOX_SEL_STR = 162;
394 const int ID_RADIOBOX_FONT = 163;
395 const int ID_RADIOBOX_ENABLE = 164;
396
397 const int ID_RADIOBUTTON_1 = 166;
398 const int ID_RADIOBUTTON_2 = 167;
399
400 const int ID_SET_FONT = 170;
401
402 const int ID_GAUGE = 180;
403 #if wxUSE_SLIDER
404 const int ID_SLIDER = 181;
405 #endif // wxUSE_SLIDER
406
407 const int ID_SPIN = 182;
408 const int ID_BTNPROGRESS = 183;
409 const int ID_BUTTON_LABEL = 184;
410 const int ID_SPINCTRL = 185;
411
412 const int ID_BUTTON_TEST1 = 190;
413 const int ID_BUTTON_TEST2 = 191;
414 const int ID_BITMAP_BTN = 192;
415
416 const int ID_CHANGE_COLOUR = 200;
417
418 const int ID_SIZER_CHECK1 = 201;
419 const int ID_SIZER_CHECK2 = 202;
420 const int ID_SIZER_CHECK3 = 203;
421 const int ID_SIZER_CHECK4 = 204;
422 const int ID_SIZER_CHECK14 = 205;
423 const int ID_SIZER_CHECKBIG = 206;
424
425 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
426 EVT_SIZE ( MyPanel::OnSize)
427 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK, MyPanel::OnPageChanging)
428 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK, MyPanel::OnPageChanged)
429 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
430 EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
431 EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
432 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
433 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
434 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
435 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
436 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
437 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
438 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
439 #if wxUSE_CHOICE
440 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
441 EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
442 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
443 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
444 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
445 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
446 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
447 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
448 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
449 #endif
450 EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
451 EVT_TEXT (ID_COMBO, MyPanel::OnComboTextChanged)
452 EVT_TEXT_ENTER(ID_COMBO, MyPanel::OnComboTextEnter)
453 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
454 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
455 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
456 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
457 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
458 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
459 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
460 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
461 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
462 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
463 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
464 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
465 EVT_RADIOBUTTON(ID_RADIOBUTTON_1, MyPanel::OnRadioButton1)
466 EVT_RADIOBUTTON(ID_RADIOBUTTON_2, MyPanel::OnRadioButton2)
467 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
468 #if wxUSE_SLIDER
469 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
470 #endif // wxUSE_SLIDER
471 #if wxUSE_SPINBTN
472 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
473 EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
474 EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
475 EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
476 EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
477 #endif // wxUSE_SPINBTN
478 #if wxUSE_SPINCTRL
479 EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
480 EVT_SPIN_UP (ID_SPINCTRL, MyPanel::OnSpinCtrlUp)
481 EVT_SPIN_DOWN (ID_SPINCTRL, MyPanel::OnSpinCtrlDown)
482 EVT_TEXT (ID_SPINCTRL, MyPanel::OnSpinCtrlText)
483 #endif // wxUSE_SPINCTRL
484 #if wxUSE_TOGGLEBTN
485 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
486 #else
487 EVT_CHECKBOX(ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
488 #endif // wxUSE_TOGGLEBTN
489 EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
490 EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
491 EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
492 EVT_BUTTON (ID_BITMAP_BTN, MyPanel::OnBmpButton)
493
494 EVT_CHECKBOX (ID_SIZER_CHECK1, MyPanel::OnSizerCheck)
495 EVT_CHECKBOX (ID_SIZER_CHECK2, MyPanel::OnSizerCheck)
496 EVT_CHECKBOX (ID_SIZER_CHECK3, MyPanel::OnSizerCheck)
497 EVT_CHECKBOX (ID_SIZER_CHECK4, MyPanel::OnSizerCheck)
498 EVT_CHECKBOX (ID_SIZER_CHECK14, MyPanel::OnSizerCheck)
499 EVT_CHECKBOX (ID_SIZER_CHECKBIG, MyPanel::OnSizerCheck)
500
501 END_EVENT_TABLE()
502
503 BEGIN_EVENT_TABLE(MyButton, wxButton)
504 EVT_LEFT_DCLICK(MyButton::OnDClick)
505 END_EVENT_TABLE()
506
507 BEGIN_EVENT_TABLE(MyComboBox, wxComboBox)
508 EVT_CHAR(MyComboBox::OnChar)
509 EVT_KEY_DOWN(MyComboBox::OnKeyDown)
510 EVT_KEY_UP(MyComboBox::OnKeyUp)
511
512 EVT_SET_FOCUS(MyComboBox::OnFocusGot)
513 END_EVENT_TABLE()
514
515 BEGIN_EVENT_TABLE(MyRadioBox, wxRadioBox)
516 EVT_SET_FOCUS(MyRadioBox::OnFocusGot)
517 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost)
518 END_EVENT_TABLE()
519
520 // ============================================================================
521 // implementation
522 // ============================================================================
523
524 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
525 : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
526 {
527 m_listbox = NULL;
528 m_listboxSorted = NULL;
529 #if wxUSE_CHOICE
530 m_choice = NULL;
531 m_choiceSorted = NULL;
532 #endif // wxUSE_CHOICE
533 m_combo = NULL;
534 m_radio = NULL;
535 m_gauge = NULL;
536 m_gaugeVert = NULL;
537 #if wxUSE_SLIDER
538 m_slider = NULL;
539 #endif // wxUSE_SLIDER
540 m_fontButton = NULL;
541 m_lbSelectNum = NULL;
542 m_lbSelectThis = NULL;
543 #if wxUSE_SPINBTN
544 m_spinbutton = NULL;
545 m_btnProgress = NULL;
546 #endif // wxUSE_SPINBTN
547 #if wxUSE_SPINCTRL
548 m_spinctrl = NULL;
549 #endif // wxUSE_SPINCTRL
550 m_spintext = NULL;
551 m_checkbox = NULL;
552 m_text = NULL;
553 m_book = NULL;
554 m_label = NULL;
555
556 m_text = new wxTextCtrl(this, wxID_ANY, _T("This is the log window.\n"),
557 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
558 m_text->SetBackgroundColour(wxT("wheat"));
559
560 m_logTargetOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
561
562 m_book = new wxBookCtrl(this, ID_BOOK);
563
564 wxString choices[] =
565 {
566 _T("This"),
567 _T("is one of my"),
568 _T("really"),
569 _T("wonderful"),
570 _T("examples.")
571 };
572
573 #ifdef USE_XPM
574 // image ids
575 enum
576 {
577 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
578 };
579
580 // fill the image list
581 wxBitmap bmp(list_xpm);
582
583 wxImageList *imagelist = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
584
585 imagelist-> Add( bmp );
586 imagelist-> Add( wxBitmap( choice_xpm ));
587 imagelist-> Add( wxBitmap( combo_xpm ));
588 imagelist-> Add( wxBitmap( text_xpm ));
589 imagelist-> Add( wxBitmap( radio_xpm ));
590 imagelist-> Add( wxBitmap( gauge_xpm ));
591 m_book->SetImageList(imagelist);
592 #elif defined(__WXMSW__)
593 // load images from resources
594 enum
595 {
596 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
597 };
598 wxImageList *imagelist = new wxImageList(16, 16, false, Image_Max);
599
600 static const wxChar *s_iconNames[Image_Max] =
601 {
602 _T("list"), _T("choice"), _T("combo"), _T("text"), _T("radio"),
603 _T("gauge")
604 };
605
606 for ( size_t n = 0; n < Image_Max; n++ )
607 {
608 wxBitmap bmp(s_iconNames[n]);
609 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
610 {
611 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
612 s_iconNames[n], n);
613 }
614 }
615
616 m_book->SetImageList(imagelist);
617 #else
618
619 // No images for now
620 #define Image_List -1
621 #define Image_Choice -1
622 #define Image_Combo -1
623 #define Image_Text -1
624 #define Image_Radio -1
625 #define Image_Gauge -1
626 #define Image_Max -1
627
628 #endif
629
630 wxPanel *panel = new wxPanel(m_book);
631 m_listbox = new wxListBox( panel, ID_LISTBOX,
632 wxPoint(10,10), wxSize(120,70),
633 5, choices, wxLB_ALWAYS_SB );
634 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
635 wxPoint(10,90), wxSize(120,70),
636 5, choices, wxLB_SORT );
637
638 SetListboxClientData(wxT("listbox"), m_listbox);
639 SetListboxClientData(wxT("listbox"), m_listboxSorted);
640
641 m_listbox->SetCursor(*wxCROSS_CURSOR);
642 #if wxUSE_TOOLTIPS
643 m_listbox->SetToolTip( _T("This is a list box") );
644 #endif // wxUSE_TOOLTIPS
645
646 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
647 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
648 (void)new wxButton( panel, ID_LISTBOX_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
649 (void)new MyButton( panel, ID_LISTBOX_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
650 (void)new wxButton( panel, ID_LISTBOX_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
651 wxButton *button = new MyButton( panel, ID_LISTBOX_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
652
653 button->SetDefault();
654 button->SetForegroundColour(*wxBLUE);
655
656 #if wxUSE_TOOLTIPS
657 button->SetToolTip( _T("Press here to set italic font") );
658 #endif // wxUSE_TOOLTIPS
659
660 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, _T("&Disable"), wxPoint(20,170) );
661 m_checkbox->SetValue(false);
662 button->MoveAfterInTabOrder(m_checkbox);
663 #if wxUSE_TOOLTIPS
664 m_checkbox->SetToolTip( _T("Click here to disable the listbox") );
665 #endif // wxUSE_TOOLTIPS
666 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, _T("&Toggle colour"),
667 wxPoint(110,170) );
668 panel->SetCursor(wxCursor(wxCURSOR_HAND));
669 m_book->AddPage(panel, _T("wxListBox"), true, Image_List);
670
671 #if wxUSE_CHOICE
672 panel = new wxPanel(m_book);
673 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices );
674 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,wxDefaultCoord),
675 5, choices, wxCB_SORT );
676
677 SetChoiceClientData(wxT("choice"), m_choice);
678 SetChoiceClientData(wxT("choice"), m_choiceSorted);
679
680 m_choice->SetSelection(2);
681 m_choice->SetBackgroundColour( wxT("red") );
682 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
683 (void)new wxButton( panel, ID_CHOICE_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
684 (void)new wxButton( panel, ID_CHOICE_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
685 (void)new wxButton( panel, ID_CHOICE_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
686 (void)new wxButton( panel, ID_CHOICE_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
687 (void)new wxButton( panel, ID_CHOICE_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
688 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
689
690 m_book->AddPage(panel, _T("wxChoice"), false, Image_Choice);
691 #endif // wxUSE_CHOICE
692
693 panel = new wxPanel(m_book);
694 (void)new wxStaticBox( panel, wxID_ANY, _T("&Box around combobox"),
695 wxPoint(5, 5), wxSize(150, 100));
696 m_combo = new MyComboBox( panel, ID_COMBO, _T("This"),
697 wxPoint(20,25), wxSize(120, wxDefaultCoord),
698 5, choices,
699 wxCB_READONLY | wxPROCESS_ENTER);
700 m_combo->SetBackgroundColour(*wxBLUE);
701
702 (void)new wxButton( panel, ID_COMBO_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
703 (void)new wxButton( panel, ID_COMBO_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
704 (void)new wxButton( panel, ID_COMBO_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
705 (void)new wxButton( panel, ID_COMBO_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
706 (void)new wxButton( panel, ID_COMBO_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
707 (void)new wxButton( panel, ID_COMBO_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
708 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
709 m_book->AddPage(panel, _T("wxComboBox"), false, Image_Combo);
710
711 wxString choices2[] =
712 {
713 _T("First"), _T("Second"),
714 /* "Third",
715 "Fourth", "Fifth", "Sixth",
716 "Seventh", "Eighth", "Nineth", "Tenth" */
717 };
718
719 panel = new wxPanel(m_book);
720 (void)new MyRadioBox( panel, ID_RADIOBOX, _T("&That"), wxPoint(10,160), wxDefaultSize, WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
721 m_radio = new wxRadioBox( panel, ID_RADIOBOX, _T("T&his"), wxPoint(10,10), wxDefaultSize, WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
722 m_radio->SetForegroundColour(*wxRED);
723
724 #if wxUSE_TOOLTIPS
725 m_combo->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
726 m_radio->SetToolTip(_T("Ever seen a radiobox?"));
727 #endif // wxUSE_TOOLTIPS
728
729 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
730 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
731 m_fontButton = new wxButton( panel, ID_SET_FONT, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
732 (void)new wxButton( panel, ID_RADIOBOX_FONT, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
733 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, _T("&Disable"), wxPoint(340,130), wxDefaultSize );
734 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize, wxRB_GROUP );
735 rb->SetValue( false );
736 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize );
737 m_book->AddPage(panel, _T("wxRadioBox"), false, Image_Radio);
738
739 #if wxUSE_SLIDER && wxUSE_GAUGE
740 panel = new wxPanel(m_book);
741 (void)new wxStaticBox( panel, wxID_ANY, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
742 m_gauge = new wxGauge( panel, wxID_ANY, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
743 m_gauge->SetBackgroundColour(*wxGREEN);
744 m_gauge->SetForegroundColour(*wxRED);
745 m_gaugeVert = new wxGauge( panel, wxID_ANY, 100,
746 wxPoint(195,35), wxSize(30, 90),
747 wxGA_VERTICAL | wxGA_SMOOTH | wxNO_BORDER );
748 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,wxDefaultCoord),
749 wxSL_AUTOTICKS | wxSL_LABELS );
750 m_slider->SetTickFreq(40, 0);
751 #if wxUSE_TOOLTIPS
752 m_slider->SetToolTip(_T("This is a sliding slider"));
753 #endif // wxUSE_TOOLTIPS
754
755 (void)new wxStaticBox( panel, wxID_ANY, _T("&Explanation"),
756 wxPoint(230,10), wxSize(270,130),
757 wxALIGN_CENTER );
758
759 #ifdef __WXMOTIF__
760 // No wrapping text in wxStaticText yet :-(
761 (void)new wxStaticText( panel, wxID_ANY,
762 _T("Drag the slider!"),
763 wxPoint(250,30),
764 wxSize(240, wxDefaultCoord)
765 );
766 #else
767 (void)new wxStaticText( panel, wxID_ANY,
768 _T("In order see the gauge (aka progress bar)\n")
769 _T("control do something you have to drag the\n")
770 _T("handle of the slider to the right.\n")
771 _T("\n")
772 _T("This is also supposed to demonstrate how\n")
773 _T("to use static controls.\n"),
774 wxPoint(250,25),
775 wxSize(240, 110)
776 );
777 #endif
778 int initialSpinValue = -5;
779 wxString s;
780 s << initialSpinValue;
781 m_spintext = new wxTextCtrl( panel, wxID_ANY, s, wxPoint(20,160), wxSize(80,wxDefaultCoord) );
782 #if wxUSE_SPINBTN
783 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, wxDefaultCoord) );
784 m_spinbutton->SetRange(-40,30);
785 m_spinbutton->SetValue(initialSpinValue);
786
787 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, _T("&Show progress dialog"),
788 wxPoint(300, 160) );
789 #endif // wxUSE_SPINBTN
790
791 #if wxUSE_SPINCTRL
792 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord) );
793 m_spinctrl->SetRange(10,30);
794 m_spinctrl->SetValue(15);
795 #endif // wxUSE_SPINCTRL
796
797 m_book->AddPage(panel, _T("wxGauge"), false, Image_Gauge);
798 #endif // wxUSE_SLIDER && wxUSE_GAUGE
799
800 panel = new wxPanel(m_book);
801
802 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
803 wxIcon icon = wxArtProvider::GetIcon(wxART_INFORMATION);
804 (void) new wxStaticBitmap( panel, wxID_ANY, icon, wxPoint(10, 10) );
805
806 // VZ: don't leak memory
807 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
808 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
809 #endif // !Motif
810
811 wxBitmap bitmap( 100, 100 );
812 wxMemoryDC dc;
813 dc.SelectObject( bitmap );
814 dc.SetPen(*wxGREEN_PEN);
815 dc.Clear();
816 dc.DrawEllipse(5, 5, 90, 90);
817 dc.DrawText(_T("Bitmap"), 30, 40);
818 dc.SelectObject( wxNullBitmap );
819
820 (void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20));
821
822 #if defined(__WXMSW__) || defined(__WXMOTIF__)
823 // test for masked bitmap display
824 bitmap = wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP);
825 if (bitmap.Ok())
826 {
827 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
828
829 (void)new wxStaticBitmap /* wxBitmapButton */ (panel, wxID_ANY, bitmap, wxPoint(300, 120));
830 }
831 #endif
832
833 wxBitmap bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION)),
834 bmp2(wxArtProvider::GetBitmap(wxART_WARNING)),
835 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION));
836 wxBitmapButton *bmpBtn = new wxBitmapButton
837 (
838 panel, wxID_ANY,
839 bmp1,
840 wxPoint(30, 70)
841 );
842
843 bmpBtn->SetBitmapSelected(bmp2);
844 bmpBtn->SetBitmapFocus(bmp3);
845
846 #if wxUSE_TOGGLEBTN
847 (void)new wxToggleButton(panel, ID_BUTTON_LABEL,
848 _T("&Toggle label"), wxPoint(250, 20));
849 #else
850 (void)new wxCheckBox(panel, ID_BUTTON_LABEL,
851 _T("&Toggle label"), wxPoint(250, 20));
852 #endif // wxUSE_TOGGLEBTN
853
854 m_label = new wxStaticText(panel, wxID_ANY, _T("Label with some long text"),
855 wxPoint(250, 60), wxDefaultSize,
856 wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
857 m_label->SetForegroundColour( *wxBLUE );
858
859 m_book->AddPage(panel, _T("wxBitmapXXX"));
860
861 // sizer
862
863 panel = new wxPanel(m_book);
864 panel->SetAutoLayout( true );
865
866 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
867
868 wxStaticBoxSizer *csizer =
869 new wxStaticBoxSizer (new wxStaticBox (panel, wxID_ANY, _T("Show Buttons")), wxHORIZONTAL );
870
871 wxCheckBox *check1, *check2, *check3, *check4, *check14, *checkBig;
872 check1 = new wxCheckBox (panel, ID_SIZER_CHECK1, _T("1"));
873 check1->SetValue (true);
874 csizer->Add (check1);
875 check2 = new wxCheckBox (panel, ID_SIZER_CHECK2, _T("2"));
876 check2->SetValue (true);
877 csizer->Add (check2);
878 check3 = new wxCheckBox (panel, ID_SIZER_CHECK3, _T("3"));
879 check3->SetValue (true);
880 csizer->Add (check3);
881 check4 = new wxCheckBox (panel, ID_SIZER_CHECK4, _T("4"));
882 check4->SetValue (true);
883 csizer->Add (check4);
884 check14 = new wxCheckBox (panel, ID_SIZER_CHECK14, _T("1-4"));
885 check14->SetValue (true);
886 csizer->Add (check14);
887 checkBig = new wxCheckBox (panel, ID_SIZER_CHECKBIG, _T("Big"));
888 checkBig->SetValue (true);
889 csizer->Add (checkBig);
890
891 sizer->Add (csizer);
892
893 m_hsizer = new wxBoxSizer( wxHORIZONTAL );
894
895 m_buttonSizer = new wxBoxSizer (wxVERTICAL);
896
897 m_sizerBtn1 = new wxButton(panel, wxID_ANY, _T("Test Button &1 (tab order 1)") );
898 m_buttonSizer->Add( m_sizerBtn1, 0, wxALL, 10 );
899 m_sizerBtn2 = new wxButton(panel, wxID_ANY, _T("Test Button &2 (tab order 3)") );
900 m_buttonSizer->Add( m_sizerBtn2, 0, wxALL, 10 );
901 m_sizerBtn3 = new wxButton(panel, wxID_ANY, _T("Test Button &3 (tab order 2)") );
902 m_buttonSizer->Add( m_sizerBtn3, 0, wxALL, 10 );
903 m_sizerBtn4 = new wxButton(panel, wxID_ANY, _T("Test Button &4 (tab order 4)") );
904 m_buttonSizer->Add( m_sizerBtn4, 0, wxALL, 10 );
905
906 m_sizerBtn3->MoveBeforeInTabOrder(m_sizerBtn2);
907
908 m_hsizer->Add (m_buttonSizer);
909 m_hsizer->Add( 20,20, 1 );
910 m_bigBtn = new wxButton(panel, wxID_ANY, _T("Multiline\nbutton") );
911 m_hsizer->Add( m_bigBtn , 3, wxGROW|wxALL, 10 );
912
913 sizer->Add (m_hsizer, 1, wxGROW);
914
915 panel->SetSizer( sizer );
916
917 m_book->AddPage(panel, _T("wxSizer"));
918 }
919
920 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
921 {
922 int x = 0;
923 int y = 0;
924 GetClientSize( &x, &y );
925
926 if (m_book) m_book->SetSize( 2, 2, x-4, y*2/3-4 );
927 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
928 }
929
930 void MyPanel::OnPageChanging( wxBookCtrlEvent &event )
931 {
932 int selOld = event.GetOldSelection();
933 if ( selOld == 2 )
934 {
935 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
936 _T("page change from taking place - if you select\n")
937 _T("[No] the current page will stay the third one\n"),
938 _T("Control sample"),
939 wxICON_QUESTION | wxYES_NO, this) != wxYES )
940 {
941 event.Veto();
942
943 return;
944 }
945 }
946
947 *m_text << _T("Book selection is being changed from ") << selOld
948 << _T(" to ") << event.GetSelection()
949 << _T(" (current page from book is ")
950 << m_book->GetSelection() << _T(")\n");
951 }
952
953 void MyPanel::OnPageChanged( wxBookCtrlEvent &event )
954 {
955 *m_text << _T("Book selection is now ") << event.GetSelection()
956 << _T(" (from book: ") << m_book->GetSelection()
957 << _T(")\n");
958 }
959
960 void MyPanel::OnTestButton(wxCommandEvent& event)
961 {
962 wxLogMessage(_T("Button %c clicked."),
963 event.GetId() == ID_BUTTON_TEST1 ? _T('1') : _T('2'));
964 }
965
966 void MyPanel::OnBmpButton(wxCommandEvent& WXUNUSED(event))
967 {
968 wxLogMessage(_T("Bitmap button clicked."));
969 }
970
971 void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
972 {
973 static wxColour s_colOld;
974
975 SetThemeEnabled(false);
976 // test panel colour changing and propagation to the subcontrols
977 if ( s_colOld.Ok() )
978 {
979 SetBackgroundColour(s_colOld);
980 s_colOld = wxNullColour;
981
982 m_lbSelectThis->SetForegroundColour(wxNullColour);
983 m_lbSelectThis->SetBackgroundColour(wxNullColour);
984 }
985 else
986 {
987 s_colOld = wxColour(wxT("red"));
988 SetBackgroundColour(wxT("white"));
989
990 m_lbSelectThis->SetForegroundColour(wxT("white"));
991 m_lbSelectThis->SetBackgroundColour(wxT("red"));
992 }
993
994 m_lbSelectThis->Refresh();
995 Refresh();
996 }
997
998 void MyPanel::OnListBox( wxCommandEvent &event )
999 {
1000 // GetParent()->Move(100, 100);
1001
1002 if (event.GetInt() == -1)
1003 {
1004 m_text->AppendText( _T("ListBox has no selections anymore\n") );
1005 return;
1006 }
1007
1008 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
1009 : m_listboxSorted;
1010
1011 m_text->AppendText( _T("ListBox event selection string is: '") );
1012 m_text->AppendText( event.GetString() );
1013 m_text->AppendText( _T("'\n") );
1014 m_text->AppendText( _T("ListBox control selection string is: '") );
1015 m_text->AppendText( listbox->GetStringSelection() );
1016 m_text->AppendText( _T("'\n") );
1017
1018 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1019 m_text->AppendText( _T("ListBox event client data string is: '") );
1020 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
1021 m_text->AppendText( obj->GetData() );
1022 else
1023 m_text->AppendText( wxString(_T("none")) );
1024
1025 m_text->AppendText( _T("'\n") );
1026 m_text->AppendText( _T("ListBox control client data string is: '") );
1027 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
1028 if (obj)
1029 m_text->AppendText( obj->GetData() );
1030 else
1031 m_text->AppendText( wxString(_T("none")) );
1032 m_text->AppendText( _T("'\n") );
1033 }
1034
1035 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
1036 {
1037 m_text->AppendText( _T("ListBox double click string is: ") );
1038 m_text->AppendText( event.GetString() );
1039 m_text->AppendText( _T("\n") );
1040 }
1041
1042 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
1043 {
1044 switch (event.GetId())
1045 {
1046 case ID_LISTBOX_ENABLE:
1047 {
1048 m_text->AppendText(_T("Checkbox clicked.\n"));
1049 #if wxUSE_TOOLTIPS
1050 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
1051 if (event.GetInt())
1052 cb->SetToolTip( _T("Click to enable listbox") );
1053 else
1054 cb->SetToolTip( _T("Click to disable listbox") );
1055 #endif // wxUSE_TOOLTIPS
1056 m_listbox->Enable( event.GetInt() == 0 );
1057 m_lbSelectThis->Enable( event.GetInt() == 0 );
1058 m_lbSelectNum->Enable( event.GetInt() == 0 );
1059 m_listboxSorted->Enable( event.GetInt() == 0 );
1060 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
1061 break;
1062 }
1063 case ID_LISTBOX_SEL_NUM:
1064 {
1065 if (m_listbox->GetCount() > 2)
1066 m_listbox->SetSelection( 2 );
1067 if (m_listboxSorted->GetCount() > 2)
1068 m_listboxSorted->SetSelection( 2 );
1069 m_lbSelectThis->WarpPointer( 40, 14 );
1070 break;
1071 }
1072 case ID_LISTBOX_SEL_STR:
1073 {
1074 if (m_listbox->FindString(_T("This")) != wxNOT_FOUND)
1075 m_listbox->SetStringSelection( _T("This") );
1076 if (m_listboxSorted->FindString(_T("This")) != wxNOT_FOUND)
1077 m_listboxSorted->SetStringSelection( _T("This") );
1078 m_lbSelectNum->WarpPointer( 40, 14 );
1079 break;
1080 }
1081 case ID_LISTBOX_CLEAR:
1082 {
1083 m_listbox->Clear();
1084 m_listboxSorted->Clear();
1085 break;
1086 }
1087 case ID_LISTBOX_APPEND:
1088 {
1089 m_listbox->Append( _T("Hi!") );
1090 m_listboxSorted->Append( _T("Hi!") );
1091 break;
1092 }
1093 case ID_LISTBOX_DELETE:
1094 {
1095 int idx;
1096 idx = m_listbox->GetSelection();
1097 if ( idx != wxNOT_FOUND )
1098 m_listbox->Delete( idx );
1099 idx = m_listboxSorted->GetSelection();
1100 if ( idx != wxNOT_FOUND )
1101 m_listboxSorted->Delete( idx );
1102 break;
1103 }
1104 case ID_LISTBOX_FONT:
1105 {
1106 m_listbox->SetFont( *wxITALIC_FONT );
1107 m_listboxSorted->SetFont( *wxITALIC_FONT );
1108 m_checkbox->SetFont( *wxITALIC_FONT );
1109 break;
1110 }
1111 }
1112 }
1113
1114 #if wxUSE_CHOICE
1115 void MyPanel::OnChoice( wxCommandEvent &event )
1116 {
1117 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
1118 : m_choiceSorted;
1119
1120 m_text->AppendText( _T("Choice event selection string is: '") );
1121 m_text->AppendText( event.GetString() );
1122 m_text->AppendText( _T("'\n") );
1123 m_text->AppendText( _T("Choice control selection string is: '") );
1124 m_text->AppendText( choice->GetStringSelection() );
1125 m_text->AppendText( _T("'\n") );
1126
1127 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1128 m_text->AppendText( _T("Choice event client data string is: '") );
1129
1130 if (obj)
1131 m_text->AppendText( obj->GetData() );
1132 else
1133 m_text->AppendText( wxString(_T("none")) );
1134
1135 m_text->AppendText( _T("'\n") );
1136 m_text->AppendText( _T("Choice control client data string is: '") );
1137 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
1138
1139 if (obj)
1140 m_text->AppendText( obj->GetData() );
1141 else
1142 m_text->AppendText( wxString(_T("none")) );
1143 m_text->AppendText( _T("'\n") );
1144 }
1145
1146 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
1147 {
1148 switch (event.GetId())
1149 {
1150 case ID_CHOICE_ENABLE:
1151 {
1152 m_choice->Enable( event.GetInt() == 0 );
1153 m_choiceSorted->Enable( event.GetInt() == 0 );
1154 break;
1155 }
1156 case ID_CHOICE_SEL_NUM:
1157 {
1158 m_choice->SetSelection( 2 );
1159 m_choiceSorted->SetSelection( 2 );
1160 break;
1161 }
1162 case ID_CHOICE_SEL_STR:
1163 {
1164 m_choice->SetStringSelection( _T("This") );
1165 m_choiceSorted->SetStringSelection( _T("This") );
1166 break;
1167 }
1168 case ID_CHOICE_CLEAR:
1169 {
1170 m_choice->Clear();
1171 m_choiceSorted->Clear();
1172 break;
1173 }
1174 case ID_CHOICE_APPEND:
1175 {
1176 m_choice->Append( _T("Hi!") );
1177 m_choiceSorted->Append( _T("Hi!") );
1178 break;
1179 }
1180 case ID_CHOICE_DELETE:
1181 {
1182 int idx = m_choice->GetSelection();
1183 if ( idx != wxNOT_FOUND )
1184 m_choice->Delete( idx );
1185 idx = m_choiceSorted->GetSelection();
1186 if ( idx != wxNOT_FOUND )
1187 m_choiceSorted->Delete( idx );
1188 break;
1189 }
1190 case ID_CHOICE_FONT:
1191 {
1192 m_choice->SetFont( *wxITALIC_FONT );
1193 m_choiceSorted->SetFont( *wxITALIC_FONT );
1194 break;
1195 }
1196 }
1197 }
1198 #endif // wxUSE_CHOICE
1199
1200 void MyPanel::OnCombo( wxCommandEvent &event )
1201 {
1202 m_text->AppendText( _T("ComboBox event selection string is: ") );
1203 m_text->AppendText( event.GetString() );
1204 m_text->AppendText( _T("\n") );
1205 m_text->AppendText( _T("ComboBox control selection string is: ") );
1206 m_text->AppendText( m_combo->GetStringSelection() );
1207 m_text->AppendText( _T("\n") );
1208 }
1209
1210 void MyPanel::OnComboTextChanged(wxCommandEvent& event)
1211 {
1212 wxString str;
1213 str.Printf( wxT("Text in the combobox changed: now is '%s'."),
1214 event.GetString().c_str() );
1215 wxLogMessage( str.c_str() );
1216 }
1217
1218 void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))
1219 {
1220 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1221 m_combo->GetValue().c_str());
1222 }
1223
1224 void MyPanel::OnComboButtons( wxCommandEvent &event )
1225 {
1226 switch (event.GetId())
1227 {
1228 case ID_COMBO_ENABLE:
1229 {
1230 m_combo->Enable( event.GetInt() == 0 );
1231 break;
1232 }
1233 case ID_COMBO_SEL_NUM:
1234 {
1235 m_combo->SetSelection( 2 );
1236 break;
1237 }
1238 case ID_COMBO_SEL_STR:
1239 {
1240 m_combo->SetStringSelection( _T("This") );
1241 break;
1242 }
1243 case ID_COMBO_CLEAR:
1244 {
1245 m_combo->Clear();
1246 break;
1247 }
1248 case ID_COMBO_APPEND:
1249 {
1250 m_combo->Append( _T("Hi!") );
1251 break;
1252 }
1253 case ID_COMBO_DELETE:
1254 {
1255 int idx = m_combo->GetSelection();
1256 m_combo->Delete( idx );
1257 break;
1258 }
1259 case ID_COMBO_FONT:
1260 {
1261 m_combo->SetFont( *wxITALIC_FONT );
1262 break;
1263 }
1264 }
1265 }
1266
1267 void MyPanel::OnRadio( wxCommandEvent &event )
1268 {
1269 m_text->AppendText( _T("RadioBox selection string is: ") );
1270 m_text->AppendText( event.GetString() );
1271 m_text->AppendText( _T("\n") );
1272 }
1273
1274 void MyPanel::OnRadioButton1( wxCommandEvent & WXUNUSED(event) )
1275 {
1276 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1277 }
1278
1279 void MyPanel::OnRadioButton2( wxCommandEvent & WXUNUSED(event) )
1280 {
1281 m_text->AppendText(_T("Second wxRadioButton selected.\n"));
1282 }
1283
1284 void MyPanel::OnRadioButtons( wxCommandEvent &event )
1285 {
1286 switch (event.GetId())
1287 {
1288 case ID_RADIOBOX_ENABLE:
1289 {
1290 m_radio->Enable( event.GetInt() == 0 );
1291 break;
1292 }
1293 case ID_RADIOBOX_SEL_NUM:
1294 {
1295 m_radio->SetSelection( 2 );
1296 break;
1297 }
1298 case ID_RADIOBOX_SEL_STR:
1299 {
1300 m_radio->SetStringSelection( _T("This") );
1301 break;
1302 }
1303 case ID_RADIOBOX_FONT:
1304 {
1305 m_radio->SetForegroundColour(*wxGREEN);
1306
1307 m_radio->SetFont( *wxITALIC_FONT );
1308 break;
1309 }
1310 }
1311 }
1312
1313 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1314 {
1315 m_fontButton->SetFont( *wxITALIC_FONT );
1316 m_text->SetFont( *wxITALIC_FONT );
1317 }
1318
1319 void MyPanel::OnUpdateLabel( wxCommandEvent &event )
1320 {
1321 m_label->SetLabel(event.GetInt() ? _T("Very very very very very long text.")
1322 : _T("Shorter text."));
1323 }
1324
1325 #if wxUSE_SLIDER
1326
1327 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1328 {
1329 m_gauge->SetValue( m_slider->GetValue() );
1330 m_gaugeVert->SetValue( m_slider->GetValue() / 2 );
1331 }
1332
1333 #endif // wxUSE_SLIDER
1334
1335 #if wxUSE_SPINCTRL
1336
1337 void MyPanel::OnSpinCtrlText(wxCommandEvent& event)
1338 {
1339 if ( m_spinctrl )
1340 {
1341 wxString s;
1342 s.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1343 m_spinctrl->GetValue(), event.GetString().c_str() );
1344 m_text->AppendText(s);
1345 }
1346 }
1347
1348 void MyPanel::OnSpinCtrl(wxSpinEvent& event)
1349 {
1350 if ( m_spinctrl )
1351 {
1352 wxString s;
1353 s.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1354 m_spinctrl->GetValue(), event.GetInt() );
1355 m_text->AppendText(s);
1356 }
1357 }
1358
1359 void MyPanel::OnSpinCtrlUp(wxSpinEvent& event)
1360 {
1361 if ( m_spinctrl )
1362 {
1363 m_text->AppendText( wxString::Format(
1364 _T("Spin up: %d (from event: %ld)\n"),
1365 m_spinctrl->GetValue(), event.GetInt() ) );
1366 }
1367 }
1368
1369 void MyPanel::OnSpinCtrlDown(wxSpinEvent& event)
1370 {
1371 if ( m_spinctrl )
1372 {
1373 m_text->AppendText( wxString::Format(
1374 _T("Spin down: %d (from event: %ld)\n"),
1375 m_spinctrl->GetValue(), event.GetInt() ) );
1376 }
1377 }
1378
1379 #endif // wxUSE_SPINCTRL
1380
1381 #if wxUSE_SPINBTN
1382 void MyPanel::OnSpinUp( wxSpinEvent &event )
1383 {
1384 wxString value;
1385 value.Printf( _T("Spin control up: current = %d\n"),
1386 m_spinbutton->GetValue());
1387
1388 if ( event.GetPosition() > 17 )
1389 {
1390 value += _T("Preventing the spin button from going above 17.\n");
1391
1392 event.Veto();
1393 }
1394
1395 m_text->AppendText(value);
1396 }
1397
1398 void MyPanel::OnSpinDown( wxSpinEvent &event )
1399 {
1400 wxString value;
1401 value.Printf( _T("Spin control down: current = %d\n"),
1402 m_spinbutton->GetValue());
1403
1404 if ( event.GetPosition() < -17 )
1405 {
1406 value += _T("Preventing the spin button from going below -17.\n");
1407
1408 event.Veto();
1409 }
1410
1411 m_text->AppendText(value);
1412 }
1413
1414 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1415 {
1416 wxString value;
1417 value.Printf( _T("%d"), event.GetPosition() );
1418 m_spintext->SetValue( value );
1419
1420 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1421 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1422 m_spinbutton->GetValue());
1423
1424 m_text->AppendText(value);
1425 }
1426
1427 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1428 {
1429 event.Enable( m_spinbutton->GetValue() > 0 );
1430 }
1431
1432 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1433 {
1434 int max = m_spinbutton->GetValue();
1435
1436 if ( max <= 0 )
1437 {
1438 wxLogError(_T("You must set positive range!"));
1439 return;
1440 }
1441
1442 wxProgressDialog dialog(_T("Progress dialog example"),
1443 _T("An informative message"),
1444 max, // range
1445 this, // parent
1446 wxPD_CAN_ABORT |
1447 wxPD_AUTO_HIDE |
1448 wxPD_APP_MODAL |
1449 wxPD_ELAPSED_TIME |
1450 wxPD_ESTIMATED_TIME |
1451 wxPD_REMAINING_TIME);
1452
1453
1454 bool cont = true;
1455 for ( int i = 0; i <= max && cont; i++ )
1456 {
1457 wxSleep(1);
1458 if ( i == max )
1459 {
1460 cont = dialog.Update(i, _T("That's all, folks!"));
1461 }
1462 else if ( i == max / 2 )
1463 {
1464 cont = dialog.Update(i, _T("Only a half left (very long message)!"));
1465 }
1466 else
1467 {
1468 cont = dialog.Update(i);
1469 }
1470 }
1471
1472 if ( !cont )
1473 {
1474 *m_text << _T("Progress dialog aborted!\n");
1475 }
1476 else
1477 {
1478 *m_text << _T("Countdown from ") << max << _T(" finished.\n");
1479 }
1480 }
1481
1482 #endif // wxUSE_SPINBTN
1483
1484 void MyPanel::OnSizerCheck( wxCommandEvent &event)
1485 {
1486 switch (event.GetId ()) {
1487 case ID_SIZER_CHECK1:
1488 m_buttonSizer->Show (m_sizerBtn1, event.IsChecked ());
1489 m_buttonSizer->Layout ();
1490 break;
1491 case ID_SIZER_CHECK2:
1492 m_buttonSizer->Show (m_sizerBtn2, event.IsChecked ());
1493 m_buttonSizer->Layout ();
1494 break;
1495 case ID_SIZER_CHECK3:
1496 m_buttonSizer->Show (m_sizerBtn3, event.IsChecked ());
1497 m_buttonSizer->Layout ();
1498 break;
1499 case ID_SIZER_CHECK4:
1500 m_buttonSizer->Show (m_sizerBtn4, event.IsChecked ());
1501 m_buttonSizer->Layout ();
1502 break;
1503 case ID_SIZER_CHECK14:
1504 m_hsizer->Show (m_buttonSizer, event.IsChecked ());
1505 m_hsizer->Layout ();
1506 break;
1507 case ID_SIZER_CHECKBIG:
1508 m_hsizer->Show (m_bigBtn, event.IsChecked ());
1509 m_hsizer->Layout ();
1510 break;
1511 }
1512
1513 }
1514
1515 MyPanel::~MyPanel()
1516 {
1517 //wxLog::RemoveTraceMask(_T("focus"));
1518 delete wxLog::SetActiveTarget(m_logTargetOld);
1519
1520 delete m_book->GetImageList();
1521 }
1522
1523 //----------------------------------------------------------------------
1524 // MyFrame
1525 //----------------------------------------------------------------------
1526
1527 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1528 EVT_MENU(CONTROLS_QUIT, MyFrame::OnQuit)
1529 EVT_MENU(CONTROLS_ABOUT, MyFrame::OnAbout)
1530 EVT_MENU(CONTROLS_CLEAR_LOG, MyFrame::OnClearLog)
1531 #if wxUSE_TOOLTIPS
1532 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1533 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
1534 #endif // wxUSE_TOOLTIPS
1535
1536 EVT_MENU(CONTROLS_ENABLE_ALL, MyFrame::OnEnableAll)
1537
1538 EVT_ICONIZE(MyFrame::OnIconized)
1539 EVT_MAXIMIZE(MyFrame::OnMaximized)
1540 EVT_SIZE(MyFrame::OnSize)
1541 EVT_MOVE(MyFrame::OnMove)
1542
1543 EVT_IDLE(MyFrame::OnIdle)
1544 END_EVENT_TABLE()
1545
1546 MyFrame::MyFrame(const wxChar *title, int x, int y)
1547 : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(500, 430))
1548 {
1549 // Give it an icon
1550 // The wxICON() macros loads an icon from a resource under Windows
1551 // and uses an #included XPM image under GTK+ and Motif
1552
1553 #ifdef USE_XPM
1554 SetIcon( wxICON(mondrian) );
1555 #endif
1556
1557 wxMenu *file_menu = new wxMenu;
1558
1559 file_menu->Append(CONTROLS_CLEAR_LOG, _T("&Clear log\tCtrl-L"));
1560 file_menu->AppendSeparator();
1561 file_menu->Append(CONTROLS_ABOUT, _T("&About\tF1"));
1562 file_menu->AppendSeparator();
1563 file_menu->Append(CONTROLS_QUIT, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1564
1565 wxMenuBar *menu_bar = new wxMenuBar;
1566 menu_bar->Append(file_menu, _T("&File"));
1567
1568 #if wxUSE_TOOLTIPS
1569 wxMenu *tooltip_menu = new wxMenu;
1570 tooltip_menu->Append(CONTROLS_SET_TOOLTIP_DELAY, _T("Set &delay\tCtrl-D"));
1571 tooltip_menu->AppendSeparator();
1572 tooltip_menu->Append(CONTROLS_ENABLE_TOOLTIPS, _T("&Toggle tooltips\tCtrl-T"),
1573 _T("enable/disable tooltips"), true);
1574 tooltip_menu->Check(CONTROLS_ENABLE_TOOLTIPS, true);
1575 menu_bar->Append(tooltip_menu, _T("&Tooltips"));
1576 #endif // wxUSE_TOOLTIPS
1577
1578 wxMenu *panel_menu = new wxMenu;
1579 panel_menu->Append(CONTROLS_ENABLE_ALL, _T("&Disable all\tCtrl-E"),
1580 _T("Enable/disable all panel controls"), true);
1581 menu_bar->Append(panel_menu, _T("&Panel"));
1582
1583 SetMenuBar(menu_bar);
1584
1585 #if wxUSE_STATUSBAR
1586 CreateStatusBar(2);
1587 #endif // wxUSE_STATUSBAR
1588
1589 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1590
1591 SetSizeHints( 500, 425 );
1592 }
1593
1594 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1595 {
1596 Close(true);
1597 }
1598
1599 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1600 {
1601 wxBusyCursor bc;
1602
1603 wxMessageDialog dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK );
1604 dialog.ShowModal();
1605 }
1606
1607 void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
1608 {
1609 m_panel->m_text->Clear();
1610 }
1611
1612 #if wxUSE_TOOLTIPS
1613 void MyFrame::OnSetTooltipDelay(wxCommandEvent& WXUNUSED(event))
1614 {
1615 static long s_delay = 5000;
1616
1617 wxString delay;
1618 delay.Printf( _T("%ld"), s_delay);
1619
1620 delay = wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1621 _T("Set tooltip delay"),
1622 delay,
1623 this);
1624 if ( !delay )
1625 return; // cancelled
1626
1627 wxSscanf(delay, _T("%ld"), &s_delay);
1628
1629 wxToolTip::SetDelay(s_delay);
1630
1631 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1632 }
1633
1634 void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
1635 {
1636 static bool s_enabled = true;
1637
1638 s_enabled = !s_enabled;
1639
1640 wxToolTip::Enable(s_enabled);
1641
1642 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1643 }
1644 #endif // tooltips
1645
1646 void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1647 {
1648 static bool s_enable = true;
1649
1650 s_enable = !s_enable;
1651 m_panel->Enable(s_enable);
1652 }
1653
1654 void MyFrame::OnMove( wxMoveEvent& event )
1655 {
1656 #if wxUSE_STATUSBAR
1657 UpdateStatusBar(event.GetPosition(), GetSize());
1658 #endif // wxUSE_STATUSBAR
1659
1660 event.Skip();
1661 }
1662
1663 void MyFrame::OnIconized( wxIconizeEvent& event )
1664 {
1665 wxLogMessage(_T("Frame %s"), event.Iconized() ? _T("iconized")
1666 : _T("restored"));
1667 event.Skip();
1668 }
1669
1670 void MyFrame::OnMaximized( wxMaximizeEvent& WXUNUSED(event) )
1671 {
1672 wxLogMessage(_T("Frame maximized"));
1673 }
1674
1675 void MyFrame::OnSize( wxSizeEvent& event )
1676 {
1677 #if wxUSE_STATUSBAR
1678 UpdateStatusBar(GetPosition(), event.GetSize());
1679 #endif // wxUSE_STATUSBAR
1680
1681 event.Skip();
1682 }
1683
1684 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1685 {
1686 // track the window which has the focus in the status bar
1687 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1688 wxWindow *focus = wxWindow::FindFocus();
1689 if ( focus && (focus != s_windowFocus) )
1690 {
1691 s_windowFocus = focus;
1692
1693 wxString msg;
1694 msg.Printf(
1695 #ifdef __WXMSW__
1696 _T("Focus: %s, HWND = %08x"),
1697 #else
1698 _T("Focus: %s"),
1699 #endif
1700 s_windowFocus->GetClassInfo()->GetClassName()
1701 #ifdef __WXMSW__
1702 , (unsigned int) s_windowFocus->GetHWND()
1703 #endif
1704 );
1705
1706 #if wxUSE_STATUSBAR
1707 SetStatusText(msg);
1708 #endif // wxUSE_STATUSBAR
1709 }
1710 }
1711
1712 void MyComboBox::OnChar(wxKeyEvent& event)
1713 {
1714 wxLogMessage(_T("MyComboBox::OnChar"));
1715
1716 if ( event.GetKeyCode() == 'w' )
1717 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1718 else
1719 event.Skip();
1720 }
1721
1722 void MyComboBox::OnKeyDown(wxKeyEvent& event)
1723 {
1724 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1725
1726 if ( event.GetKeyCode() == 'w' )
1727 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1728 else
1729 event.Skip();
1730 }
1731
1732 void MyComboBox::OnKeyUp(wxKeyEvent& event)
1733 {
1734 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1735
1736 event.Skip();
1737 }
1738
1739 static void SetListboxClientData(const wxChar *name, wxListBox *control)
1740 {
1741 size_t count = control->GetCount();
1742 for ( size_t n = 0; n < count; n++ )
1743 {
1744 wxString s;
1745 s.Printf(wxT("%s client data for '%s'"),
1746 name, control->GetString(n).c_str());
1747
1748 control->SetClientObject(n, new wxStringClientData(s));
1749 }
1750 }
1751
1752 #if wxUSE_CHOICE
1753
1754 static void SetChoiceClientData(const wxChar *name, wxChoice *control)
1755 {
1756 size_t count = control->GetCount();
1757 for ( size_t n = 0; n < count; n++ )
1758 {
1759 wxString s;
1760 s.Printf(wxT("%s client data for '%s'"),
1761 name, control->GetString(n).c_str());
1762
1763 control->SetClientObject(n, new wxStringClientData(s));
1764 }
1765 }
1766
1767 #endif // wxUSE_CHOICE