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