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