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