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