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