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