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