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