]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
9a5d95eb4c8cdd98699362062a224795913f4e7c
[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 if (event.GetInt() == -1)
1222 {
1223 m_text->AppendText( _T("ListBox has no selections anymore\n") );
1224 return;
1225 }
1226
1227 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
1228 : m_listboxSorted;
1229
1230 m_text->AppendText( _T("ListBox event selection string is: '") );
1231 m_text->AppendText( event.GetString() );
1232 m_text->AppendText( _T("'\n") );
1233
1234 // can't use GetStringSelection() with multiple selections, there could be
1235 // more than one of them
1236 if ( !listbox->HasFlag(wxLB_MULTIPLE) )
1237 {
1238 m_text->AppendText( _T("ListBox control selection string is: '") );
1239 m_text->AppendText( listbox->GetStringSelection() );
1240 m_text->AppendText( _T("'\n") );
1241 }
1242
1243 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1244 m_text->AppendText( _T("ListBox event client data string is: '") );
1245 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
1246 m_text->AppendText( obj->GetData() );
1247 else
1248 m_text->AppendText( wxString(_T("none")) );
1249
1250 m_text->AppendText( _T("'\n") );
1251 m_text->AppendText( _T("ListBox control client data string is: '") );
1252 obj = (wxStringClientData *)listbox->GetClientObject(event.GetInt());
1253 if (obj)
1254 m_text->AppendText( obj->GetData() );
1255 else
1256 m_text->AppendText( wxString(_T("none")) );
1257 m_text->AppendText( _T("'\n") );
1258 }
1259
1260 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
1261 {
1262 m_text->AppendText( _T("ListBox double click string is: ") );
1263 m_text->AppendText( event.GetString() );
1264 m_text->AppendText( _T("\n") );
1265 }
1266
1267 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
1268 {
1269 switch (event.GetId())
1270 {
1271 case ID_LISTBOX_ENABLE:
1272 {
1273 m_text->AppendText(_T("Checkbox clicked.\n"));
1274 #if wxUSE_TOOLTIPS
1275 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
1276 if (event.GetInt())
1277 cb->SetToolTip( _T("Click to enable listbox") );
1278 else
1279 cb->SetToolTip( _T("Click to disable listbox") );
1280 #endif // wxUSE_TOOLTIPS
1281 m_listbox->Enable( event.GetInt() == 0 );
1282 m_lbSelectThis->Enable( event.GetInt() == 0 );
1283 m_lbSelectNum->Enable( event.GetInt() == 0 );
1284 m_listboxSorted->Enable( event.GetInt() == 0 );
1285 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
1286 break;
1287 }
1288 case ID_LISTBOX_SEL_NUM:
1289 {
1290 if (m_listbox->GetCount() > 2)
1291 m_listbox->SetSelection( 2 );
1292 if (m_listboxSorted->GetCount() > 2)
1293 m_listboxSorted->SetSelection( 2 );
1294 m_lbSelectThis->WarpPointer( 40, 14 );
1295 break;
1296 }
1297 case ID_LISTBOX_SEL_STR:
1298 {
1299 if (m_listbox->FindString(_T("This")) != wxNOT_FOUND)
1300 m_listbox->SetStringSelection( _T("This") );
1301 if (m_listboxSorted->FindString(_T("This")) != wxNOT_FOUND)
1302 m_listboxSorted->SetStringSelection( _T("This") );
1303 m_lbSelectNum->WarpPointer( 40, 14 );
1304 break;
1305 }
1306 case ID_LISTBOX_CLEAR:
1307 {
1308 m_listbox->Clear();
1309 m_listboxSorted->Clear();
1310 break;
1311 }
1312 case ID_LISTBOX_APPEND:
1313 {
1314 m_listbox->Append( _T("Hi!") );
1315 m_listboxSorted->Append( _T("Hi!") );
1316 break;
1317 }
1318 case ID_LISTBOX_DELETE:
1319 {
1320 int idx;
1321 idx = m_listbox->GetSelection();
1322 if ( idx != wxNOT_FOUND )
1323 m_listbox->Delete( idx );
1324 idx = m_listboxSorted->GetSelection();
1325 if ( idx != wxNOT_FOUND )
1326 m_listboxSorted->Delete( idx );
1327 break;
1328 }
1329 case ID_LISTBOX_FONT:
1330 {
1331 m_listbox->SetFont( *wxITALIC_FONT );
1332 m_listboxSorted->SetFont( *wxITALIC_FONT );
1333 m_checkbox->SetFont( *wxITALIC_FONT );
1334 break;
1335 }
1336 }
1337 }
1338
1339 #if wxUSE_CHOICE
1340
1341 static const wxChar *GetDataString(wxClientData *data)
1342 {
1343 return data ? wx_static_cast(wxStringClientData *, data)->GetData().c_str()
1344 : _T("none");
1345 }
1346
1347 void MyPanel::OnChoice( wxCommandEvent &event )
1348 {
1349 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
1350 : m_choiceSorted;
1351
1352 const int sel = choice->GetSelection();
1353
1354 wxClientData *dataEvt = event.GetClientObject(),
1355 *dataCtrl = choice->GetClientObject(sel);
1356
1357 wxLogMessage(_T("EVT_CHOICE: item %d/%d (event/control), ")
1358 _T("string \"%s\"/\"%s\", ")
1359 _T("data \"%s\"/\"%s\""),
1360 (int)event.GetInt(),
1361 sel,
1362 event.GetString().c_str(),
1363 choice->GetStringSelection().c_str(),
1364 GetDataString(dataEvt),
1365 GetDataString(dataCtrl));
1366 }
1367
1368 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
1369 {
1370 switch (event.GetId())
1371 {
1372 case ID_CHOICE_ENABLE:
1373 {
1374 m_choice->Enable( event.GetInt() == 0 );
1375 m_choiceSorted->Enable( event.GetInt() == 0 );
1376 break;
1377 }
1378 case ID_CHOICE_SEL_NUM:
1379 {
1380 m_choice->SetSelection( 2 );
1381 m_choiceSorted->SetSelection( 2 );
1382 break;
1383 }
1384 case ID_CHOICE_SEL_STR:
1385 {
1386 m_choice->SetStringSelection( _T("This") );
1387 m_choiceSorted->SetStringSelection( _T("This") );
1388 break;
1389 }
1390 case ID_CHOICE_CLEAR:
1391 {
1392 m_choice->Clear();
1393 m_choiceSorted->Clear();
1394 break;
1395 }
1396 case ID_CHOICE_APPEND:
1397 {
1398 m_choice->Append( _T("Hi!") );
1399 m_choiceSorted->Append( _T("Hi!") );
1400 break;
1401 }
1402 case ID_CHOICE_DELETE:
1403 {
1404 int idx = m_choice->GetSelection();
1405 if ( idx != wxNOT_FOUND )
1406 m_choice->Delete( idx );
1407 idx = m_choiceSorted->GetSelection();
1408 if ( idx != wxNOT_FOUND )
1409 m_choiceSorted->Delete( idx );
1410 break;
1411 }
1412 case ID_CHOICE_FONT:
1413 {
1414 m_choice->SetFont( *wxITALIC_FONT );
1415 m_choiceSorted->SetFont( *wxITALIC_FONT );
1416 break;
1417 }
1418 }
1419 }
1420 #endif // wxUSE_CHOICE
1421
1422 void MyPanel::OnCombo( wxCommandEvent &event )
1423 {
1424 if (!m_combo)
1425 return;
1426
1427 wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string \"%s\"/\"%s\""),
1428 (int)event.GetInt(),
1429 m_combo->GetSelection(),
1430 event.GetString().c_str(),
1431 m_combo->GetStringSelection().c_str());
1432 }
1433
1434 void MyPanel::OnComboTextChanged(wxCommandEvent& event)
1435 {
1436 if (m_combo)
1437 wxLogMessage(wxT("EVT_TEXT for the combobox: \"%s\" (event) or \"%s\" (control)."),
1438 event.GetString().c_str(),
1439 m_combo->GetValue().c_str());
1440 }
1441
1442 void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))
1443 {
1444 if (m_combo)
1445 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1446 m_combo->GetValue().c_str());
1447 }
1448
1449 void MyPanel::OnComboButtons( wxCommandEvent &event )
1450 {
1451 switch (event.GetId())
1452 {
1453 case ID_COMBO_ENABLE:
1454 {
1455 m_combo->Enable( event.GetInt() == 0 );
1456 break;
1457 }
1458 case ID_COMBO_SEL_NUM:
1459 {
1460 m_combo->SetSelection( 2 );
1461 break;
1462 }
1463 case ID_COMBO_SEL_STR:
1464 {
1465 m_combo->SetStringSelection( _T("This") );
1466 break;
1467 }
1468 case ID_COMBO_CLEAR:
1469 {
1470 m_combo->Clear();
1471 break;
1472 }
1473 case ID_COMBO_APPEND:
1474 {
1475 m_combo->Append( _T("Hi!") );
1476 break;
1477 }
1478 case ID_COMBO_DELETE:
1479 {
1480 int idx = m_combo->GetSelection();
1481 m_combo->Delete( idx );
1482 break;
1483 }
1484 case ID_COMBO_FONT:
1485 {
1486 m_combo->SetFont( *wxITALIC_FONT );
1487 break;
1488 }
1489 case ID_COMBO_SET_TEXT:
1490 {
1491 m_combo->SetString( 2, wxT("Hi!") );
1492 break;
1493 }
1494 }
1495 }
1496
1497 void MyPanel::OnRadio( wxCommandEvent &event )
1498 {
1499 m_text->AppendText( _T("RadioBox selection string is: ") );
1500 m_text->AppendText( event.GetString() );
1501 m_text->AppendText( _T("\n") );
1502 }
1503
1504 void MyPanel::OnRadioButton1( wxCommandEvent & WXUNUSED(event) )
1505 {
1506 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1507 }
1508
1509 void MyPanel::OnRadioButton2( wxCommandEvent & WXUNUSED(event) )
1510 {
1511 m_text->AppendText(_T("Second wxRadioButton selected.\n"));
1512 }
1513
1514 void MyPanel::OnRadioButtons( wxCommandEvent &event )
1515 {
1516 switch (event.GetId())
1517 {
1518 case ID_RADIOBOX_ENABLE:
1519 m_radio->Enable( event.GetInt() == 0 );
1520 break;
1521
1522 case ID_RADIOBOX_SEL_NUM:
1523 m_radio->SetSelection( 2 );
1524 break;
1525
1526 case ID_RADIOBOX_SEL_STR:
1527 m_radio->SetStringSelection( _T("This") );
1528 break;
1529
1530 case ID_RADIOBOX_FONT:
1531 m_radio->SetFont( *wxITALIC_FONT );
1532 break;
1533 }
1534 }
1535
1536 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1537 {
1538 m_fontButton->SetFont( *wxITALIC_FONT );
1539 m_text->SetFont( *wxITALIC_FONT );
1540 }
1541
1542 void MyPanel::OnUpdateLabel( wxCommandEvent &event )
1543 {
1544 m_label->SetLabel(event.GetInt() ? _T("Very very very very very long text.")
1545 : _T("Shorter text."));
1546 }
1547
1548 #if wxUSE_SLIDER
1549
1550 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1551 {
1552 #if wxUSE_GAUGE
1553 m_gauge->SetValue( m_slider->GetValue() );
1554 m_gaugeVert->SetValue( m_slider->GetValue() / 2 );
1555 #endif // wxUSE_GAUGE
1556 }
1557
1558 #endif // wxUSE_SLIDER
1559
1560 #if wxUSE_SPINCTRL
1561
1562 void MyPanel::OnSpinCtrlText(wxCommandEvent& event)
1563 {
1564 if ( m_spinctrl )
1565 {
1566 wxString s;
1567 s.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1568 m_spinctrl->GetValue(), event.GetString().c_str() );
1569 m_text->AppendText(s);
1570 }
1571 }
1572
1573 void MyPanel::OnSpinCtrl(wxSpinEvent& event)
1574 {
1575 if ( m_spinctrl )
1576 {
1577 wxString s;
1578 s.Printf( _T("Spin ctrl changed: now %d (from event: %d)\n"),
1579 m_spinctrl->GetValue(), event.GetInt() );
1580 m_text->AppendText(s);
1581 }
1582 }
1583
1584 void MyPanel::OnSpinCtrlUp(wxSpinEvent& event)
1585 {
1586 if ( m_spinctrl )
1587 {
1588 m_text->AppendText( wxString::Format(
1589 _T("Spin up: %d (from event: %d)\n"),
1590 m_spinctrl->GetValue(), event.GetInt() ) );
1591 }
1592 }
1593
1594 void MyPanel::OnSpinCtrlDown(wxSpinEvent& event)
1595 {
1596 if ( m_spinctrl )
1597 {
1598 m_text->AppendText( wxString::Format(
1599 _T("Spin down: %d (from event: %d)\n"),
1600 m_spinctrl->GetValue(), event.GetInt() ) );
1601 }
1602 }
1603
1604 #endif // wxUSE_SPINCTRL
1605
1606 #if wxUSE_SPINBTN
1607 void MyPanel::OnSpinUp( wxSpinEvent &event )
1608 {
1609 wxString value;
1610 value.Printf( _T("Spin control up: current = %d\n"),
1611 m_spinbutton->GetValue());
1612
1613 if ( event.GetPosition() > 17 )
1614 {
1615 value += _T("Preventing the spin button from going above 17.\n");
1616
1617 event.Veto();
1618 }
1619
1620 m_text->AppendText(value);
1621 }
1622
1623 void MyPanel::OnSpinDown( wxSpinEvent &event )
1624 {
1625 wxString value;
1626 value.Printf( _T("Spin control down: current = %d\n"),
1627 m_spinbutton->GetValue());
1628
1629 if ( event.GetPosition() < -17 )
1630 {
1631 value += _T("Preventing the spin button from going below -17.\n");
1632
1633 event.Veto();
1634 }
1635
1636 m_text->AppendText(value);
1637 }
1638
1639 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1640 {
1641 wxString value;
1642 value.Printf( _T("%d"), event.GetPosition() );
1643 m_spintext->SetValue( value );
1644
1645 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1646 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1647 m_spinbutton->GetValue());
1648
1649 m_text->AppendText(value);
1650 }
1651
1652 void MyPanel::OnNewText( wxCommandEvent& /* event */)
1653 {
1654 m_nonWrappingText->SetLabel( wxT("This text is short\nbut still spans\nover three lines.") );
1655 m_wrappingText->SetLabel( wxT("This text is short but will still be wrapped if it is too long.") );
1656 m_wrappingText->GetParent()->Layout();
1657 }
1658
1659 #if wxUSE_PROGRESSDLG
1660
1661 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1662 {
1663 event.Enable( m_spinbutton->GetValue() > 0 );
1664 }
1665
1666 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1667 {
1668 int max = m_spinbutton->GetValue();
1669
1670 if ( max <= 0 )
1671 {
1672 wxLogError(_T("You must set positive range!"));
1673 return;
1674 }
1675
1676 wxProgressDialog dialog(_T("Progress dialog example"),
1677 _T("An informative message"),
1678 max, // range
1679 this, // parent
1680 wxPD_CAN_ABORT |
1681 wxPD_AUTO_HIDE |
1682 wxPD_APP_MODAL |
1683 wxPD_ELAPSED_TIME |
1684 wxPD_ESTIMATED_TIME |
1685 wxPD_REMAINING_TIME);
1686
1687
1688 bool cont = true;
1689 for ( int i = 0; i <= max && cont; i++ )
1690 {
1691 wxSleep(1);
1692 if ( i == max )
1693 {
1694 cont = dialog.Update(i, _T("That's all, folks!"));
1695 }
1696 else if ( i == max / 2 )
1697 {
1698 cont = dialog.Update(i, _T("Only a half left (very long message)!"));
1699 }
1700 else
1701 {
1702 cont = dialog.Update(i);
1703 }
1704 }
1705
1706 if ( !cont )
1707 {
1708 *m_text << _T("Progress dialog aborted!\n");
1709 }
1710 else
1711 {
1712 *m_text << _T("Countdown from ") << max << _T(" finished.\n");
1713 }
1714 }
1715
1716 #endif // wxUSE_PROGRESSDLG
1717 #endif // wxUSE_SPINBTN
1718
1719 #if wxUSE_HYPERLINKCTRL
1720 void MyPanel::OnHyperlink(wxHyperlinkEvent& event)
1721 {
1722 wxLogMessage(wxT("Clicked on hyperlink with url '%s'"), event.GetURL().c_str());
1723 if (!wxLaunchDefaultBrowser(event.GetURL()))
1724 wxMessageBox(_T("Could not launch the default browser!"));
1725 }
1726 #endif //wxUSE_HYPERLINK
1727
1728 void MyPanel::OnSizerCheck( wxCommandEvent &event)
1729 {
1730 switch (event.GetId ()) {
1731 case ID_SIZER_CHECK1:
1732 m_buttonSizer->Show (m_sizerBtn1, event.IsChecked ());
1733 m_buttonSizer->Layout ();
1734 break;
1735 case ID_SIZER_CHECK2:
1736 m_buttonSizer->Show (m_sizerBtn2, event.IsChecked ());
1737 m_buttonSizer->Layout ();
1738 break;
1739 case ID_SIZER_CHECK3:
1740 m_buttonSizer->Show (m_sizerBtn3, event.IsChecked ());
1741 m_buttonSizer->Layout ();
1742 break;
1743 case ID_SIZER_CHECK4:
1744 m_buttonSizer->Show (m_sizerBtn4, event.IsChecked ());
1745 m_buttonSizer->Layout ();
1746 break;
1747 case ID_SIZER_CHECK14:
1748 m_hsizer->Show (m_buttonSizer, event.IsChecked ());
1749 m_hsizer->Layout ();
1750 break;
1751 case ID_SIZER_CHECKBIG:
1752 m_hsizer->Show (m_bigBtn, event.IsChecked ());
1753 m_hsizer->Layout ();
1754 break;
1755 }
1756
1757 }
1758
1759 MyPanel::~MyPanel()
1760 {
1761 //wxLog::RemoveTraceMask(_T("focus"));
1762 delete wxLog::SetActiveTarget(m_logTargetOld);
1763
1764 delete m_book->GetImageList();
1765 }
1766
1767 //----------------------------------------------------------------------
1768 // MyFrame
1769 //----------------------------------------------------------------------
1770
1771 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1772 EVT_MENU(CONTROLS_QUIT, MyFrame::OnQuit)
1773 EVT_MENU(CONTROLS_ABOUT, MyFrame::OnAbout)
1774 EVT_MENU(CONTROLS_CLEAR_LOG, MyFrame::OnClearLog)
1775 #if wxUSE_TOOLTIPS
1776 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1777 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
1778 #endif // wxUSE_TOOLTIPS
1779
1780 EVT_MENU(CONTROLS_ENABLE_ALL, MyFrame::OnEnableAll)
1781 EVT_MENU(CONTROLS_CONTEXT_HELP, MyFrame::OnContextHelp)
1782
1783 EVT_ICONIZE(MyFrame::OnIconized)
1784 EVT_MAXIMIZE(MyFrame::OnMaximized)
1785 EVT_SIZE(MyFrame::OnSize)
1786 EVT_MOVE(MyFrame::OnMove)
1787
1788 EVT_IDLE(MyFrame::OnIdle)
1789 END_EVENT_TABLE()
1790
1791 MyFrame::MyFrame(const wxChar *title, int x, int y)
1792 : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(700, 450))
1793 {
1794 SetHelpText( _T("Controls sample demonstrating various widgets") );
1795
1796 // Give it an icon
1797 // The wxICON() macros loads an icon from a resource under Windows
1798 // and uses an #included XPM image under GTK+ and Motif
1799
1800 #ifdef USE_XPM
1801 SetIcon( wxICON(mondrian) );
1802 #endif
1803
1804 wxMenu *file_menu = new wxMenu;
1805
1806 file_menu->Append(CONTROLS_CLEAR_LOG, _T("&Clear log\tCtrl-L"));
1807 file_menu->AppendSeparator();
1808 file_menu->Append(CONTROLS_ABOUT, _T("&About\tF1"));
1809 file_menu->AppendSeparator();
1810 file_menu->Append(CONTROLS_QUIT, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1811
1812 wxMenuBar *menu_bar = new wxMenuBar;
1813 menu_bar->Append(file_menu, _T("&File"));
1814
1815 #if wxUSE_TOOLTIPS
1816 wxMenu *tooltip_menu = new wxMenu;
1817 tooltip_menu->Append(CONTROLS_SET_TOOLTIP_DELAY, _T("Set &delay\tCtrl-D"));
1818 tooltip_menu->AppendSeparator();
1819 tooltip_menu->Append(CONTROLS_ENABLE_TOOLTIPS, _T("&Toggle tooltips\tCtrl-T"),
1820 _T("enable/disable tooltips"), true);
1821 tooltip_menu->Check(CONTROLS_ENABLE_TOOLTIPS, true);
1822 menu_bar->Append(tooltip_menu, _T("&Tooltips"));
1823 #endif // wxUSE_TOOLTIPS
1824
1825 wxMenu *panel_menu = new wxMenu;
1826 panel_menu->Append(CONTROLS_ENABLE_ALL, _T("&Disable all\tCtrl-E"),
1827 _T("Enable/disable all panel controls"), true);
1828 panel_menu->Append(CONTROLS_CONTEXT_HELP, _T("&Context help...\tCtrl-H"),
1829 _T("Get context help for a control"));
1830 menu_bar->Append(panel_menu, _T("&Panel"));
1831
1832 SetMenuBar(menu_bar);
1833
1834 #if wxUSE_STATUSBAR
1835 CreateStatusBar(2);
1836 #endif // wxUSE_STATUSBAR
1837
1838 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1839 }
1840
1841 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1842 {
1843 Close(true);
1844 }
1845
1846 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1847 {
1848 wxBusyCursor bc;
1849
1850 wxMessageDialog dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK );
1851 dialog.ShowModal();
1852 }
1853
1854 void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
1855 {
1856 m_panel->m_text->Clear();
1857 }
1858
1859 #if wxUSE_TOOLTIPS
1860 void MyFrame::OnSetTooltipDelay(wxCommandEvent& WXUNUSED(event))
1861 {
1862 static long s_delay = 5000;
1863
1864 wxString delay;
1865 delay.Printf( _T("%ld"), s_delay);
1866
1867 delay = wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1868 _T("Set tooltip delay"),
1869 delay,
1870 this);
1871 if ( !delay )
1872 return; // cancelled
1873
1874 wxSscanf(delay, _T("%ld"), &s_delay);
1875
1876 wxToolTip::SetDelay(s_delay);
1877
1878 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1879 }
1880
1881 void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
1882 {
1883 static bool s_enabled = true;
1884
1885 s_enabled = !s_enabled;
1886
1887 wxToolTip::Enable(s_enabled);
1888
1889 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1890 }
1891 #endif // tooltips
1892
1893 void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1894 {
1895 static bool s_enable = true;
1896
1897 s_enable = !s_enable;
1898 m_panel->Enable(s_enable);
1899 }
1900
1901 void MyFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event))
1902 {
1903 // starts a local event loop
1904 wxContextHelp chelp(this);
1905 }
1906
1907 void MyFrame::OnMove( wxMoveEvent& event )
1908 {
1909 #if wxUSE_STATUSBAR
1910 UpdateStatusBar(event.GetPosition(), GetSize());
1911 #endif // wxUSE_STATUSBAR
1912
1913 event.Skip();
1914 }
1915
1916 void MyFrame::OnIconized( wxIconizeEvent& event )
1917 {
1918 wxLogMessage(_T("Frame %s"), event.Iconized() ? _T("iconized")
1919 : _T("restored"));
1920 event.Skip();
1921 }
1922
1923 void MyFrame::OnMaximized( wxMaximizeEvent& WXUNUSED(event) )
1924 {
1925 wxLogMessage(_T("Frame maximized"));
1926 }
1927
1928 void MyFrame::OnSize( wxSizeEvent& event )
1929 {
1930 #if wxUSE_STATUSBAR
1931 UpdateStatusBar(GetPosition(), event.GetSize());
1932 #endif // wxUSE_STATUSBAR
1933
1934 event.Skip();
1935 }
1936
1937 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1938 {
1939 // track the window which has the focus in the status bar
1940 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1941 wxWindow *focus = wxWindow::FindFocus();
1942 if ( focus && (focus != s_windowFocus) )
1943 {
1944 s_windowFocus = focus;
1945
1946 wxString msg;
1947 msg.Printf(
1948 #ifdef __WXMSW__
1949 _T("Focus: %s, HWND = %08x"),
1950 #else
1951 _T("Focus: %s"),
1952 #endif
1953 s_windowFocus->GetClassInfo()->GetClassName()
1954 #ifdef __WXMSW__
1955 , (unsigned int) s_windowFocus->GetHWND()
1956 #endif
1957 );
1958
1959 #if wxUSE_STATUSBAR
1960 SetStatusText(msg);
1961 #endif // wxUSE_STATUSBAR
1962 }
1963 }
1964
1965 void MyComboBox::OnChar(wxKeyEvent& event)
1966 {
1967 wxLogMessage(_T("MyComboBox::OnChar"));
1968
1969 if ( event.GetKeyCode() == 'w' )
1970 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1971 else
1972 event.Skip();
1973 }
1974
1975 void MyComboBox::OnKeyDown(wxKeyEvent& event)
1976 {
1977 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1978
1979 if ( event.GetKeyCode() == 'w' )
1980 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1981 else
1982 event.Skip();
1983 }
1984
1985 void MyComboBox::OnKeyUp(wxKeyEvent& event)
1986 {
1987 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1988
1989 event.Skip();
1990 }
1991
1992 static void SetListboxClientData(const wxChar *name, wxListBox *control)
1993 {
1994 size_t count = control->GetCount();
1995 for ( size_t n = 0; n < count; n++ )
1996 {
1997 wxString s;
1998 s.Printf(wxT("%s client data for '%s'"),
1999 name, control->GetString(n).c_str());
2000
2001 control->SetClientObject(n, new wxStringClientData(s));
2002 }
2003 }
2004
2005 #if wxUSE_CHOICE
2006
2007 static void SetChoiceClientData(const wxChar *name, wxChoice *control)
2008 {
2009 size_t count = control->GetCount();
2010 for ( size_t n = 0; n < count; n++ )
2011 {
2012 wxString s;
2013 s.Printf(wxT("%s client data for '%s'"),
2014 name, control->GetString(n).c_str());
2015
2016 control->SetClientObject(n, new wxStringClientData(s));
2017 }
2018 }
2019
2020 #endif // wxUSE_CHOICE