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