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