]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/controls/controls.cpp
implemented wxEventLoop for wxMac
[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 OnSize( wxSizeEvent& event );
78 void OnIdle( wxIdleEvent &event );
79 void OnListBox( wxCommandEvent &event );
80 void OnListBoxDoubleClick( wxCommandEvent &event );
81 void OnListBoxButtons( wxCommandEvent &event );
82#if wxUSE_CHOICE
83 void OnChoice( wxCommandEvent &event );
84 void OnChoiceButtons( wxCommandEvent &event );
85#endif
86 void OnCombo( wxCommandEvent &event );
87 void OnComboTextChanged( wxCommandEvent &event );
88 void OnComboTextEnter( wxCommandEvent &event );
89 void OnComboButtons( wxCommandEvent &event );
90 void OnRadio( wxCommandEvent &event );
91 void OnRadioButtons( wxCommandEvent &event );
92 void OnRadioButton1( wxCommandEvent &event );
93 void OnRadioButton2( wxCommandEvent &event );
94 void OnSetFont( wxCommandEvent &event );
95 void OnPageChanged( wxBookCtrlEvent &event );
96 void OnPageChanging( wxBookCtrlEvent &event );
97 void OnSliderUpdate( wxCommandEvent &event );
98 void OnUpdateLabel( wxCommandEvent &event );
99#if wxUSE_SPINBTN
100 void OnSpinUp( wxSpinEvent &event );
101 void OnSpinDown( wxSpinEvent &event );
102 void OnSpinUpdate( wxSpinEvent &event );
103#if wxUSE_PROGRESSDLG
104 void OnUpdateShowProgress( wxUpdateUIEvent& event );
105 void OnShowProgress( wxCommandEvent &event );
106#endif // wxUSE_PROGRESSDLG
107#endif // wxUSE_SPINBTN
108 void OnNewText( wxCommandEvent &event );
109#if wxUSE_SPINCTRL
110 void OnSpinCtrl(wxSpinEvent& event);
111 void OnSpinCtrlUp(wxSpinEvent& event);
112 void OnSpinCtrlDown(wxSpinEvent& event);
113 void OnSpinCtrlText(wxCommandEvent& event);
114#endif // wxUSE_SPINCTRL
115
116 void OnEnableAll(wxCommandEvent& event);
117 void OnChangeColour(wxCommandEvent& event);
118 void OnTestButton(wxCommandEvent& event);
119 void OnBmpButton(wxCommandEvent& event);
120 void OnBmpButtonToggle(wxCommandEvent& event);
121
122 void OnSizerCheck (wxCommandEvent &event);
123
124 wxListBox *m_listbox,
125 *m_listboxSorted;
126#if wxUSE_CHOICE
127 wxChoice *m_choice,
128 *m_choiceSorted;
129#endif // wxUSE_CHOICE
130
131 wxComboBox *m_combo;
132 wxRadioBox *m_radio;
133#if wxUSE_GAUGE
134 wxGauge *m_gauge,
135 *m_gaugeVert;
136#endif // wxUSE_GAUGE
137#if wxUSE_SLIDER
138 wxSlider *m_slider;
139#endif // wxUSE_SLIDER
140 wxButton *m_fontButton;
141 wxButton *m_lbSelectNum;
142 wxButton *m_lbSelectThis;
143#if wxUSE_SPINBTN
144 wxSpinButton *m_spinbutton;
145#if wxUSE_PROGRESSDLG
146 wxButton *m_btnProgress;
147#endif // wxUSE_PROGRESSDLG
148#endif // wxUSE_SPINBTN
149 wxStaticText *m_wrappingText;
150 wxStaticText *m_nonWrappingText;
151
152#if wxUSE_SPINCTRL
153 wxSpinCtrl *m_spinctrl;
154#endif // wxUSE_SPINCTRL
155
156 wxTextCtrl *m_spintext;
157 wxCheckBox *m_checkbox;
158
159 wxTextCtrl *m_text;
160 wxBookCtrl *m_book;
161
162 wxStaticText *m_label;
163
164 wxBoxSizer *m_buttonSizer;
165 wxButton *m_sizerBtn1;
166 wxButton *m_sizerBtn2;
167 wxButton *m_sizerBtn3;
168 wxButton *m_sizerBtn4;
169 wxBoxSizer *m_hsizer;
170 wxButton *m_bigBtn;
171
172private:
173 wxLog *m_logTargetOld;
174
175 DECLARE_EVENT_TABLE()
176};
177
178class MyFrame: public wxFrame
179{
180public:
181 MyFrame(const wxChar *title, int x, int y);
182
183 void OnQuit(wxCommandEvent& event);
184 void OnAbout(wxCommandEvent& event);
185 void OnClearLog(wxCommandEvent& event);
186
187#if wxUSE_TOOLTIPS
188 void OnSetTooltipDelay(wxCommandEvent& event);
189 void OnToggleTooltips(wxCommandEvent& event);
190#endif // wxUSE_TOOLTIPS
191
192 void OnEnableAll(wxCommandEvent& event);
193
194 void OnIdle( wxIdleEvent& event );
195 void OnIconized( wxIconizeEvent& event );
196 void OnMaximized( wxMaximizeEvent& event );
197 void OnSize( wxSizeEvent& event );
198 void OnMove( wxMoveEvent& event );
199
200 MyPanel *GetPanel() const { return m_panel; }
201
202private:
203#if wxUSE_STATUSBAR
204 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
205 {
206 if ( m_frameStatusBar )
207 {
208 wxString msg;
209 wxSize sizeAll = GetSize(),
210 sizeCl = GetClientSize();
211 msg.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
212 pos.x, pos.y,
213 size.x, size.y,
214 sizeAll.x, sizeAll.y,
215 sizeCl.x, sizeCl.y);
216 SetStatusText(msg, 1);
217 }
218 }
219#endif // wxUSE_STATUSBAR
220
221 MyPanel *m_panel;
222
223 DECLARE_EVENT_TABLE()
224};
225
226// a button which intercepts double clicks (for testing...)
227class MyButton : public wxButton
228{
229public:
230 MyButton(wxWindow *parent,
231 wxWindowID id,
232 const wxString& label = wxEmptyString,
233 const wxPoint& pos = wxDefaultPosition,
234 const wxSize& size = wxDefaultSize)
235 : wxButton(parent, id, label, pos, size)
236 {
237 }
238
239 void OnDClick(wxMouseEvent& event)
240 {
241 wxLogMessage(_T("MyButton::OnDClick"));
242
243 event.Skip();
244 }
245
246private:
247 DECLARE_EVENT_TABLE()
248};
249
250// a combo which intercepts chars (to test Windows behaviour)
251class MyComboBox : public wxComboBox
252{
253public:
254 MyComboBox(wxWindow *parent, wxWindowID id,
255 const wxString& value = wxEmptyString,
256 const wxPoint& pos = wxDefaultPosition,
257 const wxSize& size = wxDefaultSize,
258 int n = 0, const wxString choices[] = NULL,
259 long style = 0,
260 const wxValidator& validator = wxDefaultValidator,
261 const wxString& name = wxComboBoxNameStr)
262 : wxComboBox(parent, id, value, pos, size, n, choices, style,
263 validator, name) { }
264
265protected:
266 void OnChar(wxKeyEvent& event);
267 void OnKeyDown(wxKeyEvent& event);
268 void OnKeyUp(wxKeyEvent& event);
269 void OnFocusGot(wxFocusEvent& event)
270 {
271 wxLogMessage(_T("MyComboBox::OnFocusGot"));
272
273 event.Skip();
274 }
275
276private:
277 DECLARE_EVENT_TABLE()
278};
279
280// a radiobox which handles focus set/kill (for testing)
281class MyRadioBox : public wxRadioBox
282{
283public:
284 MyRadioBox(wxWindow *parent,
285 wxWindowID id,
286 const wxString& title = wxEmptyString,
287 const wxPoint& pos = wxDefaultPosition,
288 const wxSize& size = wxDefaultSize,
289 int n = 0, const wxString choices[] = NULL,
290 int majorDim = 1,
291 long style = wxRA_HORIZONTAL,
292 const wxValidator& validator = wxDefaultValidator,
293 const wxString& name = wxRadioBoxNameStr)
294 : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
295 style, validator, name) { SetForegroundColour(*wxRED); }
296
297protected:
298 void OnFocusGot(wxFocusEvent& event)
299 {
300 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
301
302 event.Skip();
303 }
304
305 void OnFocusLost(wxFocusEvent& event)
306 {
307 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
308
309 event.Skip();
310 }
311
312private:
313 DECLARE_EVENT_TABLE()
314};
315
316// a choice which handles focus set/kill (for testing)
317class MyChoice : public wxChoice
318{
319public:
320 MyChoice(wxWindow *parent,
321 wxWindowID id,
322 const wxPoint& pos = wxDefaultPosition,
323 const wxSize& size = wxDefaultSize,
324 int n = 0, const wxString choices[] = NULL,
325 long style = 0,
326 const wxValidator& validator = wxDefaultValidator,
327 const wxString& name = wxChoiceNameStr )
328 : wxChoice(parent, id, pos, size, n, choices,
329 style, validator, name) { }
330
331protected:
332 void OnFocusGot(wxFocusEvent& event)
333 {
334 wxLogMessage(_T("MyChoice::OnFocusGot"));
335
336 event.Skip();
337 }
338
339 void OnFocusLost(wxFocusEvent& event)
340 {
341 wxLogMessage(_T("MyChoice::OnFocusLost"));
342
343 event.Skip();
344 }
345
346private:
347 DECLARE_EVENT_TABLE()
348};
349
350
351
352//----------------------------------------------------------------------
353// other
354//----------------------------------------------------------------------
355
356static void SetListboxClientData(const wxChar *name, wxListBox *control);
357
358#if wxUSE_CHOICE
359static void SetChoiceClientData(const wxChar *name, wxChoice *control);
360#endif // wxUSE_CHOICE
361
362IMPLEMENT_APP(MyApp)
363
364//----------------------------------------------------------------------
365// MyApp
366//----------------------------------------------------------------------
367
368enum
369{
370 CONTROLS_QUIT = wxID_EXIT,
371 CONTROLS_ABOUT = wxID_ABOUT,
372 CONTROLS_TEXT = 100,
373 CONTROLS_CLEAR_LOG,
374
375 // tooltip menu
376 CONTROLS_SET_TOOLTIP_DELAY = 200,
377 CONTROLS_ENABLE_TOOLTIPS,
378
379 // panel menu
380 CONTROLS_ENABLE_ALL
381};
382
383bool MyApp::OnInit()
384{
385 // use standard command line handling:
386 if ( !wxApp::OnInit() )
387 return false;
388
389 // parse the cmd line
390 int x = 50,
391 y = 50;
392 if ( argc == 3 )
393 {
394 wxSscanf(wxString(argv[1]), wxT("%d"), &x);
395 wxSscanf(wxString(argv[2]), wxT("%d"), &y);
396 }
397
398 // Create the main frame window
399 MyFrame *frame = new MyFrame(_T("Controls wxWidgets App"), x, y);
400 frame->Show(true);
401
402 return true;
403}
404
405//----------------------------------------------------------------------
406// MyPanel
407//----------------------------------------------------------------------
408
409const int ID_BOOK = 1000;
410
411const int ID_LISTBOX = 130;
412const int ID_LISTBOX_SEL_NUM = 131;
413const int ID_LISTBOX_SEL_STR = 132;
414const int ID_LISTBOX_CLEAR = 133;
415const int ID_LISTBOX_APPEND = 134;
416const int ID_LISTBOX_DELETE = 135;
417const int ID_LISTBOX_FONT = 136;
418const int ID_LISTBOX_ENABLE = 137;
419const int ID_LISTBOX_SORTED = 138;
420
421const int ID_CHOICE = 120;
422const int ID_CHOICE_SEL_NUM = 121;
423const int ID_CHOICE_SEL_STR = 122;
424const int ID_CHOICE_CLEAR = 123;
425const int ID_CHOICE_APPEND = 124;
426const int ID_CHOICE_DELETE = 125;
427const int ID_CHOICE_FONT = 126;
428const int ID_CHOICE_ENABLE = 127;
429const int ID_CHOICE_SORTED = 128;
430
431const int ID_COMBO = 140;
432const int ID_COMBO_SEL_NUM = 141;
433const int ID_COMBO_SEL_STR = 142;
434const int ID_COMBO_CLEAR = 143;
435const int ID_COMBO_APPEND = 144;
436const int ID_COMBO_DELETE = 145;
437const int ID_COMBO_FONT = 146;
438const int ID_COMBO_ENABLE = 147;
439
440const int ID_RADIOBOX = 160;
441const int ID_RADIOBOX_SEL_NUM = 161;
442const int ID_RADIOBOX_SEL_STR = 162;
443const int ID_RADIOBOX_FONT = 163;
444const int ID_RADIOBOX_ENABLE = 164;
445
446const int ID_RADIOBUTTON_1 = 166;
447const int ID_RADIOBUTTON_2 = 167;
448
449const int ID_SET_FONT = 170;
450
451#if wxUSE_GAUGE
452const int ID_GAUGE = 180;
453#endif // wxUSE_GAUGE
454
455#if wxUSE_SLIDER
456const int ID_SLIDER = 181;
457#endif // wxUSE_SLIDER
458
459const int ID_SPIN = 182;
460#if wxUSE_PROGRESSDLG
461const int ID_BTNPROGRESS = 183;
462#endif // wxUSE_PROGRESSDLG
463const int ID_BUTTON_LABEL = 184;
464const int ID_SPINCTRL = 185;
465const int ID_BTNNEWTEXT = 186;
466
467const int ID_BUTTON_TEST1 = 190;
468const int ID_BUTTON_TEST2 = 191;
469const int ID_BITMAP_BTN = 192;
470const int ID_BITMAP_BTN_ENABLE = 193;
471
472const int ID_CHANGE_COLOUR = 200;
473
474const int ID_SIZER_CHECK1 = 201;
475const int ID_SIZER_CHECK2 = 202;
476const int ID_SIZER_CHECK3 = 203;
477const int ID_SIZER_CHECK4 = 204;
478const int ID_SIZER_CHECK14 = 205;
479const int ID_SIZER_CHECKBIG = 206;
480
481BEGIN_EVENT_TABLE(MyPanel, wxPanel)
482EVT_SIZE ( MyPanel::OnSize)
483EVT_IDLE ( MyPanel::OnIdle)
484EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK, MyPanel::OnPageChanging)
485EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK, MyPanel::OnPageChanged)
486EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
487EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
488EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
489EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
490EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
491EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
492EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
493EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
494EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
495EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
496#if wxUSE_CHOICE
497EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
498EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
499EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
500EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
501EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
502EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
503EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
504EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
505EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
506#endif
507EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
508EVT_TEXT (ID_COMBO, MyPanel::OnComboTextChanged)
509EVT_TEXT_ENTER(ID_COMBO, MyPanel::OnComboTextEnter)
510EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
511EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
512EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
513EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
514EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
515EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
516EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
517EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
518EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
519EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
520EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
521EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
522EVT_RADIOBUTTON(ID_RADIOBUTTON_1, MyPanel::OnRadioButton1)
523EVT_RADIOBUTTON(ID_RADIOBUTTON_2, MyPanel::OnRadioButton2)
524EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
525#if wxUSE_SLIDER
526EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
527#endif // wxUSE_SLIDER
528#if wxUSE_SPINBTN
529EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
530EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
531EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
532#if wxUSE_PROGRESSDLG
533EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
534EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
535#endif // wxUSE_PROGRESSDLG
536#endif // wxUSE_SPINBTN
537#if wxUSE_SPINCTRL
538EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
539EVT_SPIN_UP (ID_SPINCTRL, MyPanel::OnSpinCtrlUp)
540EVT_SPIN_DOWN (ID_SPINCTRL, MyPanel::OnSpinCtrlDown)
541EVT_TEXT (ID_SPINCTRL, MyPanel::OnSpinCtrlText)
542#endif // wxUSE_SPINCTRL
543EVT_BUTTON (ID_BTNNEWTEXT, MyPanel::OnNewText)
544EVT_TOGGLEBUTTON(ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
545EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
546EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
547EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
548EVT_BUTTON (ID_BITMAP_BTN, MyPanel::OnBmpButton)
549EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE, MyPanel::OnBmpButtonToggle)
550
551EVT_CHECKBOX (ID_SIZER_CHECK1, MyPanel::OnSizerCheck)
552EVT_CHECKBOX (ID_SIZER_CHECK2, MyPanel::OnSizerCheck)
553EVT_CHECKBOX (ID_SIZER_CHECK3, MyPanel::OnSizerCheck)
554EVT_CHECKBOX (ID_SIZER_CHECK4, MyPanel::OnSizerCheck)
555EVT_CHECKBOX (ID_SIZER_CHECK14, MyPanel::OnSizerCheck)
556EVT_CHECKBOX (ID_SIZER_CHECKBIG, MyPanel::OnSizerCheck)
557
558END_EVENT_TABLE()
559
560BEGIN_EVENT_TABLE(MyButton, wxButton)
561 EVT_LEFT_DCLICK(MyButton::OnDClick)
562END_EVENT_TABLE()
563
564BEGIN_EVENT_TABLE(MyComboBox, wxComboBox)
565 EVT_CHAR(MyComboBox::OnChar)
566 EVT_KEY_DOWN(MyComboBox::OnKeyDown)
567 EVT_KEY_UP(MyComboBox::OnKeyUp)
568
569 EVT_SET_FOCUS(MyComboBox::OnFocusGot)
570END_EVENT_TABLE()
571
572BEGIN_EVENT_TABLE(MyRadioBox, wxRadioBox)
573 EVT_SET_FOCUS(MyRadioBox::OnFocusGot)
574 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost)
575END_EVENT_TABLE()
576
577BEGIN_EVENT_TABLE(MyChoice, wxChoice)
578 EVT_SET_FOCUS(MyChoice::OnFocusGot)
579 EVT_KILL_FOCUS(MyChoice::OnFocusLost)
580END_EVENT_TABLE()
581
582// ============================================================================
583// implementation
584// ============================================================================
585
586MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
587 : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
588{
589 m_listbox = NULL;
590 m_listboxSorted = NULL;
591#if wxUSE_CHOICE
592 m_choice = NULL;
593 m_choiceSorted = NULL;
594#endif // wxUSE_CHOICE
595 m_combo = NULL;
596 m_radio = NULL;
597#if wxUSE_GAUGE
598 m_gauge = NULL;
599 m_gaugeVert = NULL;
600#endif // wxUSE_GAUGE
601#if wxUSE_SLIDER
602 m_slider = NULL;
603#endif // wxUSE_SLIDER
604 m_fontButton = NULL;
605 m_lbSelectNum = NULL;
606 m_lbSelectThis = NULL;
607#if wxUSE_SPINBTN
608 m_spinbutton = NULL;
609#if wxUSE_PROGRESSDLG
610 m_btnProgress = NULL;
611#endif // wxUSE_PROGRESSDLG
612#endif // wxUSE_SPINBTN
613#if wxUSE_SPINCTRL
614 m_spinctrl = NULL;
615#endif // wxUSE_SPINCTRL
616 m_spintext = NULL;
617 m_checkbox = NULL;
618 m_text = NULL;
619 m_book = NULL;
620 m_label = NULL;
621
622 m_text = new wxTextCtrl(this, wxID_ANY, _T("This is the log window.\n"),
623 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
624 m_text->SetBackgroundColour(wxT("wheat"));
625
626 m_logTargetOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
627
628 m_book = new wxBookCtrl(this, ID_BOOK);
629
630 wxString choices[] =
631 {
632 _T("This"),
633 _T("is one of my"),
634 _T("really"),
635 _T("wonderful"),
636 _T("examples.")
637 };
638
639#ifdef USE_XPM
640 // image ids
641 enum
642 {
643 Image_List,
644 Image_Choice,
645 Image_Combo,
646 Image_Text,
647 Image_Radio,
648#if wxUSE_GAUGE
649 Image_Gauge,
650#endif // wxUSE_GAUGE
651 Image_Max
652 };
653
654 // fill the image list
655 wxBitmap bmp(list_xpm);
656
657 wxImageList *imagelist = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
658
659 imagelist-> Add( bmp );
660 imagelist-> Add( wxBitmap( choice_xpm ));
661 imagelist-> Add( wxBitmap( combo_xpm ));
662 imagelist-> Add( wxBitmap( text_xpm ));
663 imagelist-> Add( wxBitmap( radio_xpm ));
664#if wxUSE_GAUGE
665 imagelist-> Add( wxBitmap( gauge_xpm ));
666#endif // wxUSE_GAUGE
667 m_book->SetImageList(imagelist);
668#elif defined(__WXMSW__)
669 // load images from resources
670 enum
671 {
672 Image_List,
673 Image_Choice,
674 Image_Combo,
675 Image_Text,
676 Image_Radio,
677#if wxUSE_GAUGE
678 Image_Gauge,
679#endif // wxUSE_GAUGE
680 Image_Max
681 };
682 wxImageList *imagelist = new wxImageList(16, 16, false, Image_Max);
683
684 static const wxChar *s_iconNames[Image_Max] =
685 {
686 _T("list")
687 , _T("choice")
688 , _T("combo")
689 , _T("text")
690 , _T("radio")
691#if wxUSE_GAUGE
692 , _T("gauge")
693#endif // wxUSE_GAUGE
694 };
695
696 for ( size_t n = 0; n < Image_Max; n++ )
697 {
698 wxBitmap bmp(s_iconNames[n]);
699 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
700 {
701 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
702 s_iconNames[n], n);
703 }
704 }
705
706 m_book->SetImageList(imagelist);
707#else
708
709 // No images for now
710#define Image_List -1
711#define Image_Choice -1
712#define Image_Combo -1
713#define Image_Text -1
714#define Image_Radio -1
715#if wxUSE_GAUGE
716#define Image_Gauge -1
717#endif // wxUSE_GAUGE
718#define Image_Max -1
719
720#endif
721
722 wxPanel *panel = new wxPanel(m_book);
723 m_listbox = new wxListBox( panel, ID_LISTBOX,
724 wxPoint(10,10), wxSize(120,70),
725 5, choices, wxLB_MULTIPLE |wxLB_ALWAYS_SB );
726 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
727 wxPoint(10,90), wxSize(120,70),
728 5, choices, wxLB_SORT );
729
730 SetListboxClientData(wxT("listbox"), m_listbox);
731 SetListboxClientData(wxT("listbox"), m_listboxSorted);
732
733 m_listbox->SetCursor(*wxCROSS_CURSOR);
734#if wxUSE_TOOLTIPS
735 m_listbox->SetToolTip( _T("This is a list box") );
736#endif // wxUSE_TOOLTIPS
737
738 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
739 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
740 (void)new wxButton( panel, ID_LISTBOX_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
741 (void)new MyButton( panel, ID_LISTBOX_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
742 (void)new wxButton( panel, ID_LISTBOX_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
743 wxButton *button = new MyButton( panel, ID_LISTBOX_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
744
745 button->SetDefault();
746 button->SetForegroundColour(*wxBLUE);
747
748#if wxUSE_TOOLTIPS
749 button->SetToolTip( _T("Press here to set italic font") );
750#endif // wxUSE_TOOLTIPS
751
752 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, _T("&Disable"), wxPoint(20,170) );
753 m_checkbox->SetValue(false);
754 button->MoveAfterInTabOrder(m_checkbox);
755#if wxUSE_TOOLTIPS
756 m_checkbox->SetToolTip( _T("Click here to disable the listbox") );
757#endif // wxUSE_TOOLTIPS
758 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, _T("&Toggle colour"),
759 wxPoint(110,170) );
760 panel->SetCursor(wxCursor(wxCURSOR_HAND));
761 m_book->AddPage(panel, _T("wxListBox"), true, Image_List);
762
763#if wxUSE_CHOICE
764 panel = new wxPanel(m_book);
765 m_choice = new MyChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices );
766 m_choiceSorted = new MyChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,wxDefaultCoord),
767 5, choices, wxCB_SORT );
768
769 SetChoiceClientData(wxT("choice"), m_choice);
770 SetChoiceClientData(wxT("choice"), m_choiceSorted);
771
772 m_choice->SetSelection(2);
773 m_choice->SetBackgroundColour( wxT("red") );
774 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
775 (void)new wxButton( panel, ID_CHOICE_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
776 (void)new wxButton( panel, ID_CHOICE_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
777 (void)new wxButton( panel, ID_CHOICE_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
778 (void)new wxButton( panel, ID_CHOICE_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
779 (void)new wxButton( panel, ID_CHOICE_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
780 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
781
782 m_book->AddPage(panel, _T("wxChoice"), false, Image_Choice);
783#endif // wxUSE_CHOICE
784
785 panel = new wxPanel(m_book);
786 (void)new wxStaticBox( panel, wxID_ANY, _T("&Box around combobox"),
787 wxPoint(5, 5), wxSize(150, 100));
788 m_combo = new MyComboBox( panel, ID_COMBO, _T("This"),
789 wxPoint(20,25), wxSize(120, wxDefaultCoord),
790 5, choices,
791 wxCB_READONLY | wxPROCESS_ENTER);
792 m_combo->SetBackgroundColour(*wxBLUE);
793
794 (void)new wxButton( panel, ID_COMBO_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
795 (void)new wxButton( panel, ID_COMBO_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
796 (void)new wxButton( panel, ID_COMBO_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
797 (void)new wxButton( panel, ID_COMBO_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
798 (void)new wxButton( panel, ID_COMBO_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
799 (void)new wxButton( panel, ID_COMBO_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
800 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
801 m_book->AddPage(panel, _T("wxComboBox"), false, Image_Combo);
802
803 wxString choices2[] =
804 {
805 _T("First"), _T("Second"),
806 /* "Third",
807 "Fourth", "Fifth", "Sixth",
808 "Seventh", "Eighth", "Nineth", "Tenth" */
809 };
810
811 panel = new wxPanel(m_book);
812 (void)new MyRadioBox( panel, ID_RADIOBOX, _T("&That"), wxPoint(10,160), wxDefaultSize, WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
813 m_radio = new wxRadioBox( panel, ID_RADIOBOX, _T("T&his"), wxPoint(10,10), wxDefaultSize, WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
814 m_radio->SetForegroundColour(*wxRED);
815
816#if wxUSE_TOOLTIPS
817 m_combo->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
818 m_radio->SetToolTip(_T("Ever seen a radiobox?"));
819#endif // wxUSE_TOOLTIPS
820
821 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
822 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
823 m_fontButton = new wxButton( panel, ID_SET_FONT, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
824 (void)new wxButton( panel, ID_RADIOBOX_FONT, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
825 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, _T("&Disable"), wxPoint(340,130), wxDefaultSize );
826 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize, wxRB_GROUP );
827 rb->SetValue( false );
828 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize );
829 m_book->AddPage(panel, _T("wxRadioBox"), false, Image_Radio);
830
831
832#if wxUSE_SLIDER && wxUSE_GAUGE
833 panel = new wxPanel(m_book);
834
835 wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL );
836 panel->SetSizer( main_sizer );
837
838 wxStaticBoxSizer *gauge_sizer = new wxStaticBoxSizer( wxHORIZONTAL, panel, _T("&wxGauge and wxSlider") );
839 main_sizer->Add( gauge_sizer, 0, wxALL, 5 );
840 wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL );
841 gauge_sizer->Add( sz );
842 m_gauge = new wxGauge( panel, wxID_ANY, 200, wxDefaultPosition, wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
843 m_gauge->SetBackgroundColour(*wxGREEN);
844 m_gauge->SetForegroundColour(*wxRED);
845 sz->Add( m_gauge, 0, wxALL, 10 );
846 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200,
847 wxDefaultPosition, wxSize(155,wxDefaultCoord),
848 wxSL_AUTOTICKS | wxSL_LABELS);
849 m_slider->SetTickFreq(40, 0);
850#if wxUSE_TOOLTIPS
851 m_slider->SetToolTip(_T("This is a sliding slider"));
852#endif // wxUSE_TOOLTIPS
853 sz->Add( m_slider, 0, wxALL, 10 );
854
855 m_gaugeVert = new wxGauge( panel, wxID_ANY, 100,
856 wxDefaultPosition, wxSize(wxDefaultCoord, 90),
857 wxGA_VERTICAL | wxGA_SMOOTH | wxNO_BORDER );
858 gauge_sizer->Add( m_gaugeVert, 0, wxALL, 10 );
859
860
861
862 wxStaticBox *sb = new wxStaticBox( panel, wxID_ANY, _T("&Explanation"),
863 wxDefaultPosition, wxDefaultSize ); //, wxALIGN_CENTER );
864 wxStaticBoxSizer *wrapping_sizer = new wxStaticBoxSizer( sb, wxVERTICAL );
865 main_sizer->Add( wrapping_sizer, 0, wxALL, 5 );
866
867#ifdef __WXMOTIF__
868 // No wrapping text in wxStaticText yet :-(
869 m_wrappingText = new wxStaticText( panel, wxID_ANY,
870 _T("Drag the slider!"),
871 wxPoint(250,30),
872 wxSize(240, wxDefaultCoord)
873 );
874#else
875 m_wrappingText = new wxStaticText( panel, wxID_ANY,
876 _T("In order see the gauge (aka progress bar) ")
877 _T("control do something you have to drag the ")
878 _T("handle of the slider to the right.")
879 _T("\n\n")
880 _T("This is also supposed to demonstrate how ")
881 _T("to use static controls with line wrapping."),
882 wxDefaultPosition,
883 wxSize(240, wxDefaultCoord)
884 );
885#endif
886 wrapping_sizer->Add( m_wrappingText );
887
888 wxStaticBoxSizer *non_wrapping_sizer = new wxStaticBoxSizer( wxVERTICAL, panel, wxT("Non-wrapping") );
889 main_sizer->Add( non_wrapping_sizer, 0, wxALL, 5 );
890
891 m_nonWrappingText = new wxStaticText( panel, wxID_ANY,
892 _T("This static text has two lines.\nThey do not wrap."),
893 wxDefaultPosition,
894 wxDefaultSize
895 );
896 non_wrapping_sizer->Add( m_nonWrappingText );
897
898 (void)new wxButton( panel, ID_BTNNEWTEXT, wxT("New text"), wxPoint(450, 160) );
899
900 int initialSpinValue = -5;
901 wxString s;
902 s << initialSpinValue;
903 m_spintext = new wxTextCtrl( panel, wxID_ANY, s, wxPoint(20,160), wxSize(80,wxDefaultCoord) );
904#if wxUSE_SPINBTN
905 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160) );
906 m_spinbutton->SetRange(-40,30);
907 m_spinbutton->SetValue(initialSpinValue);
908
909#if wxUSE_PROGRESSDLG
910 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, _T("&Show progress dialog"),
911 wxPoint(300, 160) );
912#endif // wxUSE_PROGRESSDLG
913#endif // wxUSE_SPINBTN
914
915#if wxUSE_SPINCTRL
916 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, wxEmptyString, wxPoint(200, 160), wxSize(80, wxDefaultCoord) );
917 m_spinctrl->SetRange(10,30);
918 m_spinctrl->SetValue(15);
919#endif // wxUSE_SPINCTRL
920
921 m_book->AddPage(panel, _T("wxGauge"), false, Image_Gauge);
922#endif // wxUSE_SLIDER && wxUSE_GAUGE
923
924
925 panel = new wxPanel(m_book);
926
927#if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
928 wxIcon icon = wxArtProvider::GetIcon(wxART_INFORMATION);
929 (void) new wxStaticBitmap( panel, wxID_ANY, icon, wxPoint(10, 10) );
930
931 // VZ: don't leak memory
932 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
933 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
934#endif // !Motif
935
936 wxBitmap bitmap( 100, 100 );
937 wxMemoryDC dc;
938 dc.SelectObject( bitmap );
939 dc.SetPen(*wxGREEN_PEN);
940 dc.Clear();
941 dc.DrawEllipse(5, 5, 90, 90);
942 dc.DrawText(_T("Bitmap"), 30, 40);
943 dc.SelectObject( wxNullBitmap );
944
945 (void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20));
946 (void)new wxToggleButton(panel, ID_BITMAP_BTN_ENABLE,
947 _T("Enable/disable &bitmap"), wxPoint(100, 140));
948
949#if defined(__WXMSW__) || defined(__WXMOTIF__)
950 // test for masked bitmap display
951 bitmap = wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP);
952 if (bitmap.Ok())
953 {
954 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
955
956 (void)new wxStaticBitmap(panel, wxID_ANY, bitmap, wxPoint(300, 120));
957 }
958#endif
959
960 wxBitmap bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION)),
961 bmp2(wxArtProvider::GetBitmap(wxART_WARNING)),
962 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION));
963 wxBitmapButton *bmpBtn = new wxBitmapButton
964 (
965 panel, wxID_ANY,
966 bmp1,
967 wxPoint(30, 70)
968 );
969
970 bmpBtn->SetBitmapSelected(bmp2);
971 bmpBtn->SetBitmapFocus(bmp3);
972
973 (void)new wxToggleButton(panel, ID_BUTTON_LABEL,
974 _T("&Toggle label"), wxPoint(250, 20));
975
976 m_label = new wxStaticText(panel, wxID_ANY, _T("Label with some long text"),
977 wxPoint(250, 60), wxDefaultSize,
978 wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
979 m_label->SetForegroundColour( *wxBLUE );
980
981 m_book->AddPage(panel, _T("wxBitmapXXX"));
982
983 // sizer
984
985 panel = new wxPanel(m_book);
986 panel->SetAutoLayout( true );
987
988 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
989
990 wxStaticBoxSizer *csizer =
991 new wxStaticBoxSizer (new wxStaticBox (panel, wxID_ANY, _T("Show Buttons")), wxHORIZONTAL );
992
993 wxCheckBox *check1, *check2, *check3, *check4, *check14, *checkBig;
994 check1 = new wxCheckBox (panel, ID_SIZER_CHECK1, _T("1"));
995 check1->SetValue (true);
996 csizer->Add (check1);
997 check2 = new wxCheckBox (panel, ID_SIZER_CHECK2, _T("2"));
998 check2->SetValue (true);
999 csizer->Add (check2);
1000 check3 = new wxCheckBox (panel, ID_SIZER_CHECK3, _T("3"));
1001 check3->SetValue (true);
1002 csizer->Add (check3);
1003 check4 = new wxCheckBox (panel, ID_SIZER_CHECK4, _T("4"));
1004 check4->SetValue (true);
1005 csizer->Add (check4);
1006 check14 = new wxCheckBox (panel, ID_SIZER_CHECK14, _T("1-4"));
1007 check14->SetValue (true);
1008 csizer->Add (check14);
1009 checkBig = new wxCheckBox (panel, ID_SIZER_CHECKBIG, _T("Big"));
1010 checkBig->SetValue (true);
1011 csizer->Add (checkBig);
1012
1013 sizer->Add (csizer);
1014
1015 m_hsizer = new wxBoxSizer( wxHORIZONTAL );
1016
1017 m_buttonSizer = new wxBoxSizer (wxVERTICAL);
1018
1019 m_sizerBtn1 = new wxButton(panel, wxID_ANY, _T("Test Button &1 (tab order 1)") );
1020 m_buttonSizer->Add( m_sizerBtn1, 0, wxALL, 10 );
1021 m_sizerBtn2 = new wxButton(panel, wxID_ANY, _T("Test Button &2 (tab order 3)") );
1022 m_buttonSizer->Add( m_sizerBtn2, 0, wxALL, 10 );
1023 m_sizerBtn3 = new wxButton(panel, wxID_ANY, _T("Test Button &3 (tab order 2)") );
1024 m_buttonSizer->Add( m_sizerBtn3, 0, wxALL, 10 );
1025 m_sizerBtn4 = new wxButton(panel, wxID_ANY, _T("Test Button &4 (tab order 4)") );
1026 m_buttonSizer->Add( m_sizerBtn4, 0, wxALL, 10 );
1027
1028 m_sizerBtn3->MoveBeforeInTabOrder(m_sizerBtn2);
1029
1030 m_hsizer->Add (m_buttonSizer);
1031 m_hsizer->Add( 20,20, 1 );
1032 m_bigBtn = new wxButton(panel, wxID_ANY, _T("Multiline\nbutton") );
1033 m_hsizer->Add( m_bigBtn , 3, wxGROW|wxALL, 10 );
1034
1035 sizer->Add (m_hsizer, 1, wxGROW);
1036
1037 panel->SetSizer( sizer );
1038
1039 m_book->AddPage(panel, _T("wxSizer"));
1040}
1041
1042void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
1043{
1044 int x = 0;
1045 int y = 0;
1046 GetClientSize( &x, &y );
1047
1048 if (m_book) m_book->SetSize( 2, 2, x-4, y*2/3-4 );
1049 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1050}
1051
1052void MyPanel::OnIdle(wxIdleEvent& event)
1053{
1054 static const int INVALID_SELECTION = -2;
1055
1056 static int s_selCombo = INVALID_SELECTION;
1057 int sel = m_combo->GetSelection();
1058 if ( sel != s_selCombo )
1059 {
1060 if ( s_selCombo != INVALID_SELECTION )
1061 {
1062 wxLogMessage(_T("EVT_IDLE: combobox selection changed from %d to %d"),
1063 s_selCombo, sel);
1064 }
1065
1066 s_selCombo = sel;
1067 }
1068
1069 static int s_selChoice = INVALID_SELECTION;
1070 sel = m_choice->GetSelection();
1071 if ( sel != s_selChoice )
1072 {
1073 if ( s_selChoice != INVALID_SELECTION )
1074 {
1075 wxLogMessage(_T("EVT_IDLE: choice selection changed from %d to %d"),
1076 s_selChoice, sel);
1077 }
1078
1079 s_selChoice = sel;
1080 }
1081
1082 event.Skip();
1083}
1084
1085void MyPanel::OnPageChanging( wxBookCtrlEvent &event )
1086{
1087 int selOld = event.GetOldSelection();
1088 if ( selOld == 2 )
1089 {
1090 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
1091 _T("page change from taking place - if you select\n")
1092 _T("[No] the current page will stay the third one\n"),
1093 _T("Control sample"),
1094 wxICON_QUESTION | wxYES_NO, this) != wxYES )
1095 {
1096 event.Veto();
1097
1098 return;
1099 }
1100 }
1101
1102 *m_text << _T("Book selection is being changed from ") << selOld
1103 << _T(" to ") << event.GetSelection()
1104 << _T(" (current page from book is ")
1105 << m_book->GetSelection() << _T(")\n");
1106}
1107
1108void MyPanel::OnPageChanged( wxBookCtrlEvent &event )
1109{
1110 *m_text << _T("Book selection is now ") << event.GetSelection()
1111 << _T(" (from book: ") << m_book->GetSelection()
1112 << _T(")\n");
1113}
1114
1115void MyPanel::OnTestButton(wxCommandEvent& event)
1116{
1117 wxLogMessage(_T("Button %c clicked."),
1118 event.GetId() == ID_BUTTON_TEST1 ? _T('1') : _T('2'));
1119}
1120
1121void MyPanel::OnBmpButton(wxCommandEvent& WXUNUSED(event))
1122{
1123 wxLogMessage(_T("Bitmap button clicked."));
1124}
1125
1126void MyPanel::OnBmpButtonToggle(wxCommandEvent& event)
1127{
1128 FindWindow(ID_BITMAP_BTN)->Enable(!event.IsChecked());
1129}
1130
1131void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
1132{
1133 static wxColour s_colOld;
1134
1135 SetThemeEnabled(false);
1136 // test panel colour changing and propagation to the subcontrols
1137 if ( s_colOld.Ok() )
1138 {
1139 SetBackgroundColour(s_colOld);
1140 s_colOld = wxNullColour;
1141
1142 m_lbSelectThis->SetForegroundColour(wxNullColour);
1143 m_lbSelectThis->SetBackgroundColour(wxNullColour);
1144 }
1145 else
1146 {
1147 s_colOld = wxColour(wxT("red"));
1148 SetBackgroundColour(wxT("white"));
1149
1150 m_lbSelectThis->SetForegroundColour(wxT("white"));
1151 m_lbSelectThis->SetBackgroundColour(wxT("red"));
1152 }
1153
1154 m_lbSelectThis->Refresh();
1155 Refresh();
1156}
1157
1158void MyPanel::OnListBox( wxCommandEvent &event )
1159{
1160// GetParent()->Move(100, 100);
1161
1162 if (event.GetInt() == -1)
1163 {
1164 m_text->AppendText( _T("ListBox has no selections anymore\n") );
1165 return;
1166 }
1167
1168 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
1169 : m_listboxSorted;
1170
1171 m_text->AppendText( _T("ListBox event selection string is: '") );
1172 m_text->AppendText( event.GetString() );
1173 m_text->AppendText( _T("'\n") );
1174 m_text->AppendText( _T("ListBox control selection string is: '") );
1175 m_text->AppendText( listbox->GetStringSelection() );
1176 m_text->AppendText( _T("'\n") );
1177
1178 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1179 m_text->AppendText( _T("ListBox event client data string is: '") );
1180 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
1181 m_text->AppendText( obj->GetData() );
1182 else
1183 m_text->AppendText( wxString(_T("none")) );
1184
1185 m_text->AppendText( _T("'\n") );
1186 m_text->AppendText( _T("ListBox control client data string is: '") );
1187 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
1188 if (obj)
1189 m_text->AppendText( obj->GetData() );
1190 else
1191 m_text->AppendText( wxString(_T("none")) );
1192 m_text->AppendText( _T("'\n") );
1193}
1194
1195void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
1196{
1197 m_text->AppendText( _T("ListBox double click string is: ") );
1198 m_text->AppendText( event.GetString() );
1199 m_text->AppendText( _T("\n") );
1200}
1201
1202void MyPanel::OnListBoxButtons( wxCommandEvent &event )
1203{
1204 switch (event.GetId())
1205 {
1206 case ID_LISTBOX_ENABLE:
1207 {
1208 m_text->AppendText(_T("Checkbox clicked.\n"));
1209#if wxUSE_TOOLTIPS
1210 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
1211 if (event.GetInt())
1212 cb->SetToolTip( _T("Click to enable listbox") );
1213 else
1214 cb->SetToolTip( _T("Click to disable listbox") );
1215#endif // wxUSE_TOOLTIPS
1216 m_listbox->Enable( event.GetInt() == 0 );
1217 m_lbSelectThis->Enable( event.GetInt() == 0 );
1218 m_lbSelectNum->Enable( event.GetInt() == 0 );
1219 m_listboxSorted->Enable( event.GetInt() == 0 );
1220 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
1221 break;
1222 }
1223 case ID_LISTBOX_SEL_NUM:
1224 {
1225 if (m_listbox->GetCount() > 2)
1226 m_listbox->SetSelection( 2 );
1227 if (m_listboxSorted->GetCount() > 2)
1228 m_listboxSorted->SetSelection( 2 );
1229 m_lbSelectThis->WarpPointer( 40, 14 );
1230 break;
1231 }
1232 case ID_LISTBOX_SEL_STR:
1233 {
1234 if (m_listbox->FindString(_T("This")) != wxNOT_FOUND)
1235 m_listbox->SetStringSelection( _T("This") );
1236 if (m_listboxSorted->FindString(_T("This")) != wxNOT_FOUND)
1237 m_listboxSorted->SetStringSelection( _T("This") );
1238 m_lbSelectNum->WarpPointer( 40, 14 );
1239 break;
1240 }
1241 case ID_LISTBOX_CLEAR:
1242 {
1243 m_listbox->Clear();
1244 m_listboxSorted->Clear();
1245 break;
1246 }
1247 case ID_LISTBOX_APPEND:
1248 {
1249 m_listbox->Append( _T("Hi!") );
1250 m_listboxSorted->Append( _T("Hi!") );
1251 break;
1252 }
1253 case ID_LISTBOX_DELETE:
1254 {
1255 int idx;
1256 idx = m_listbox->GetSelection();
1257 if ( idx != wxNOT_FOUND )
1258 m_listbox->Delete( idx );
1259 idx = m_listboxSorted->GetSelection();
1260 if ( idx != wxNOT_FOUND )
1261 m_listboxSorted->Delete( idx );
1262 break;
1263 }
1264 case ID_LISTBOX_FONT:
1265 {
1266 m_listbox->SetFont( *wxITALIC_FONT );
1267 m_listboxSorted->SetFont( *wxITALIC_FONT );
1268 m_checkbox->SetFont( *wxITALIC_FONT );
1269 break;
1270 }
1271 }
1272}
1273
1274#if wxUSE_CHOICE
1275void MyPanel::OnChoice( wxCommandEvent &event )
1276{
1277 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
1278 : m_choiceSorted;
1279
1280 m_text->AppendText( _T("Choice event selection string is: '") );
1281 m_text->AppendText( event.GetString() );
1282 m_text->AppendText( _T("'\n") );
1283 m_text->AppendText( _T("Choice control selection string is: '") );
1284 m_text->AppendText( choice->GetStringSelection() );
1285 m_text->AppendText( _T("'\n") );
1286
1287 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1288 m_text->AppendText( _T("Choice event client data string is: '") );
1289
1290 if (obj)
1291 m_text->AppendText( obj->GetData() );
1292 else
1293 m_text->AppendText( wxString(_T("none")) );
1294
1295 m_text->AppendText( _T("'\n") );
1296 m_text->AppendText( _T("Choice control client data string is: '") );
1297 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
1298
1299 if (obj)
1300 m_text->AppendText( obj->GetData() );
1301 else
1302 m_text->AppendText( wxString(_T("none")) );
1303 m_text->AppendText( _T("'\n") );
1304}
1305
1306void MyPanel::OnChoiceButtons( wxCommandEvent &event )
1307{
1308 switch (event.GetId())
1309 {
1310 case ID_CHOICE_ENABLE:
1311 {
1312 m_choice->Enable( event.GetInt() == 0 );
1313 m_choiceSorted->Enable( event.GetInt() == 0 );
1314 break;
1315 }
1316 case ID_CHOICE_SEL_NUM:
1317 {
1318 m_choice->SetSelection( 2 );
1319 m_choiceSorted->SetSelection( 2 );
1320 break;
1321 }
1322 case ID_CHOICE_SEL_STR:
1323 {
1324 m_choice->SetStringSelection( _T("This") );
1325 m_choiceSorted->SetStringSelection( _T("This") );
1326 break;
1327 }
1328 case ID_CHOICE_CLEAR:
1329 {
1330 m_choice->Clear();
1331 m_choiceSorted->Clear();
1332 break;
1333 }
1334 case ID_CHOICE_APPEND:
1335 {
1336 m_choice->Append( _T("Hi!") );
1337 m_choiceSorted->Append( _T("Hi!") );
1338 break;
1339 }
1340 case ID_CHOICE_DELETE:
1341 {
1342 int idx = m_choice->GetSelection();
1343 if ( idx != wxNOT_FOUND )
1344 m_choice->Delete( idx );
1345 idx = m_choiceSorted->GetSelection();
1346 if ( idx != wxNOT_FOUND )
1347 m_choiceSorted->Delete( idx );
1348 break;
1349 }
1350 case ID_CHOICE_FONT:
1351 {
1352 m_choice->SetFont( *wxITALIC_FONT );
1353 m_choiceSorted->SetFont( *wxITALIC_FONT );
1354 break;
1355 }
1356 }
1357}
1358#endif // wxUSE_CHOICE
1359
1360void MyPanel::OnCombo( wxCommandEvent &event )
1361{
1362 wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string \"%s\"/\"%s\""),
1363 (int)event.GetInt(),
1364 m_combo->GetSelection(),
1365 event.GetString().c_str(),
1366 m_combo->GetStringSelection().c_str());
1367}
1368
1369void MyPanel::OnComboTextChanged(wxCommandEvent& event)
1370{
1371 wxLogMessage(wxT("EVT_TEXT for the combobox: \"%s\" (event) or \"%s\" (control)."),
1372 event.GetString().c_str(),
1373 m_combo->GetValue().c_str());
1374}
1375
1376void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))
1377{
1378 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1379 m_combo->GetValue().c_str());
1380}
1381
1382void MyPanel::OnComboButtons( wxCommandEvent &event )
1383{
1384 switch (event.GetId())
1385 {
1386 case ID_COMBO_ENABLE:
1387 {
1388 m_combo->Enable( event.GetInt() == 0 );
1389 break;
1390 }
1391 case ID_COMBO_SEL_NUM:
1392 {
1393 m_combo->SetSelection( 2 );
1394 break;
1395 }
1396 case ID_COMBO_SEL_STR:
1397 {
1398 m_combo->SetStringSelection( _T("This") );
1399 break;
1400 }
1401 case ID_COMBO_CLEAR:
1402 {
1403 m_combo->Clear();
1404 break;
1405 }
1406 case ID_COMBO_APPEND:
1407 {
1408 m_combo->Append( _T("Hi!") );
1409 break;
1410 }
1411 case ID_COMBO_DELETE:
1412 {
1413 int idx = m_combo->GetSelection();
1414 m_combo->Delete( idx );
1415 break;
1416 }
1417 case ID_COMBO_FONT:
1418 {
1419 m_combo->SetFont( *wxITALIC_FONT );
1420 break;
1421 }
1422 }
1423}
1424
1425void MyPanel::OnRadio( wxCommandEvent &event )
1426{
1427 m_text->AppendText( _T("RadioBox selection string is: ") );
1428 m_text->AppendText( event.GetString() );
1429 m_text->AppendText( _T("\n") );
1430}
1431
1432void MyPanel::OnRadioButton1( wxCommandEvent & WXUNUSED(event) )
1433{
1434 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1435}
1436
1437void MyPanel::OnRadioButton2( wxCommandEvent & WXUNUSED(event) )
1438{
1439 m_text->AppendText(_T("Second wxRadioButton selected.\n"));
1440}
1441
1442void MyPanel::OnRadioButtons( wxCommandEvent &event )
1443{
1444 switch (event.GetId())
1445 {
1446 case ID_RADIOBOX_ENABLE:
1447 {
1448 m_radio->Enable( event.GetInt() == 0 );
1449 break;
1450 }
1451 case ID_RADIOBOX_SEL_NUM:
1452 {
1453 m_radio->SetSelection( 2 );
1454 break;
1455 }
1456 case ID_RADIOBOX_SEL_STR:
1457 {
1458 m_radio->SetStringSelection( _T("This") );
1459 break;
1460 }
1461 case ID_RADIOBOX_FONT:
1462 {
1463 m_radio->SetForegroundColour(*wxGREEN);
1464
1465 m_radio->SetFont( *wxITALIC_FONT );
1466 break;
1467 }
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: %ld)\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: %ld)\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: %ld)\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