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