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