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