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