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