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