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