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