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