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