]> git.saurik.com Git - wxWidgets.git/blame - samples/controls/controls.cpp
moved Destroy() to the beginning
[wxWidgets.git] / samples / controls / controls.cpp
CommitLineData
1c005ff7 1/////////////////////////////////////////////////////////////////////////////
dfad0599 2// Name: controls.cpp
1c005ff7
RR
3// Purpose: Controls wxWindows sample
4// Author: Robert Roebling
5// Modified by:
6// RCS-ID: $Id$
c67d8618 7// Copyright: (c) Robert Roebling, Julian Smart
655822f3 8// Licence: wxWindows license
1c005ff7
RR
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
9f3362c4 12 #pragma implementation "controls.h"
1c005ff7
RR
13#endif
14
15// For compilers that support precompilation, includes "wx/wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
9f3362c4 19 #pragma hdrstop
1c005ff7
RR
20#endif
21
22#ifndef WX_PRECOMP
9f3362c4 23 #include "wx/wx.h"
1c005ff7
RR
24#endif
25
3372145d 26#if !defined( __WXMSW__ ) || defined( __WIN95__ )
4fabb575 27#include "wx/spinbutt.h"
3372145d 28#endif
53b28675 29#include "wx/notebook.h"
2cb21a45 30#include "wx/imaglist.h"
b8653fbf
VZ
31
32#if wxUSE_TOOLTIPS
33 #include "wx/tooltip.h"
34#endif
1c005ff7 35
4b5f3fe6 36#if defined(__WXGTK__) || defined(__WXMOTIF__)
73c700fd 37 #define USE_XPM
4fabb575
JS
38#endif
39
40#ifdef USE_XPM
73c700fd
VZ
41 #include "mondrian.xpm"
42 #include "icons/choice.xpm"
43 #include "icons/combo.xpm"
44 #include "icons/list.xpm"
45 #include "icons/radio.xpm"
46 #include "icons/text.xpm"
47 #include "icons/gauge.xpm"
47908e25
RR
48#endif
49
9726da4f
VZ
50#ifdef __WIN16__
51 // Win16 doesn't have them
ad556aa9 52 #ifdef wxUSE_SPINBTN
0e528b99 53 #undef wxUSE_SPINBTN
ad556aa9 54 #endif
0e528b99 55 #define wxUSE_SPINBTN 0
b782f2e0 56#else
ad556aa9
JS
57 #ifndef wxUSE_SPINBTN
58 #define wxUSE_SPINBTN 1
b782f2e0 59 #endif
9726da4f
VZ
60#endif // __WIN16__
61
62#include "wx/progdlg.h"
63
b782f2e0
VZ
64#if wxUSE_SPINCTRL
65 #include "wx/spinctrl.h"
66#endif // wxUSE_SPINCTRL
67
1c005ff7
RR
68//----------------------------------------------------------------------
69// class definitions
70//----------------------------------------------------------------------
71
72class MyApp: public wxApp
655822f3 73{
b8653fbf
VZ
74public:
75 bool OnInit();
1c005ff7
RR
76};
77
78class MyPanel: public wxPanel
79{
b8653fbf 80public:
1c005ff7 81 MyPanel(wxFrame *frame, int x, int y, int w, int h);
2cb21a45 82 virtual ~MyPanel();
16f6dfd8 83
1c005ff7
RR
84 void OnSize( wxSizeEvent& event );
85 void OnListBox( wxCommandEvent &event );
5b077d48 86 void OnListBoxDoubleClick( wxCommandEvent &event );
1c005ff7 87 void OnListBoxButtons( wxCommandEvent &event );
47908e25
RR
88 void OnChoice( wxCommandEvent &event );
89 void OnChoiceButtons( wxCommandEvent &event );
90 void OnCombo( wxCommandEvent &event );
91 void OnComboButtons( wxCommandEvent &event );
92 void OnRadio( wxCommandEvent &event );
93 void OnRadioButtons( wxCommandEvent &event );
868a2826 94 void OnSetFont( wxCommandEvent &event );
cb43b372 95 void OnPageChanged( wxNotebookEvent &event );
4d0f3cd6 96 void OnPageChanging( wxNotebookEvent &event );
7bce6aec 97 void OnSliderUpdate( wxCommandEvent &event );
185fa6bf 98 void OnUpdateLabel( wxCommandEvent &event );
0e528b99 99#if wxUSE_SPINBTN
8c3c31d4
VZ
100 void OnSpinUp( wxSpinEvent &event );
101 void OnSpinDown( wxSpinEvent &event );
e380f72b 102 void OnSpinUpdate( wxSpinEvent &event );
9726da4f
VZ
103 void OnUpdateShowProgress( wxUpdateUIEvent& event );
104 void OnShowProgress( wxCommandEvent &event );
0e528b99 105#endif // wxUSE_SPINBTN
16f6dfd8 106
baccb514 107#if wxUSE_SPINCTRL
457e6c54 108 void OnSpinCtrl(wxSpinEvent& event);
baccb514
VZ
109#endif // wxUSE_SPINCTRL
110
87a1e308
VZ
111 void OnEnableAll(wxCommandEvent& event);
112 void OnChangeColour(wxCommandEvent& event);
3e2dd3db 113 void OnTestButton(wxCommandEvent& event);
87a1e308 114
6c8a980f
VZ
115 wxListBox *m_listbox,
116 *m_listboxSorted;
b56c2246
VZ
117 wxChoice *m_choice,
118 *m_choiceSorted;
e380f72b
RR
119 wxComboBox *m_combo;
120 wxRadioBox *m_radio;
121 wxGauge *m_gauge;
122 wxSlider *m_slider;
123 wxButton *m_fontButton;
85eb36c2
RR
124 wxButton *m_lbSelectNum;
125 wxButton *m_lbSelectThis;
0e528b99 126#if wxUSE_SPINBTN
e380f72b 127 wxSpinButton *m_spinbutton;
9726da4f 128 wxButton *m_btnProgress;
0e528b99 129#endif // wxUSE_SPINBTN
b782f2e0
VZ
130
131#if wxUSE_SPINCTRL
132 wxSpinCtrl *m_spinctrl;
133#endif // wxUSE_SPINCTRL
134
e380f72b 135 wxTextCtrl *m_spintext;
ae0bdb01 136 wxCheckBox *m_checkbox;
16f6dfd8 137
e380f72b 138 wxTextCtrl *m_text;
655822f3
VZ
139 wxNotebook *m_notebook;
140
185fa6bf
VZ
141 wxStaticText *m_label;
142
b8653fbf 143private:
29e7e51a
VZ
144 wxLog *m_logTargetOld;
145
b8653fbf 146 DECLARE_EVENT_TABLE()
1c005ff7
RR
147};
148
149class MyFrame: public wxFrame
150{
b8653fbf 151public:
1c005ff7 152 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
655822f3 153
1c005ff7
RR
154 void OnQuit(wxCommandEvent& event);
155 void OnAbout(wxCommandEvent& event);
3e2dd3db 156 void OnClearLog(wxCommandEvent& event);
87a1e308 157
16f6dfd8
VZ
158#if wxUSE_TOOLTIPS
159 void OnSetTooltipDelay(wxCommandEvent& event);
160 void OnToggleTooltips(wxCommandEvent& event);
161#endif // wxUSE_TOOLTIPS
87a1e308
VZ
162
163 void OnEnableAll(wxCommandEvent& event);
164
9f3362c4 165 void OnIdle( wxIdleEvent& event );
5fb9fcfc 166 void OnSize( wxSizeEvent& event );
97206645 167 void OnMove( wxMoveEvent& event );
655822f3 168
f048e32f
VZ
169 MyPanel *GetPanel() const { return m_panel; }
170
b8653fbf 171private:
97206645
VZ
172 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
173 {
174 wxString msg;
175 msg.Printf(_("pos=(%d, %d), size=%dx%d"),
176 pos.x, pos.y, size.x, size.y);
177 SetStatusText(msg, 1);
178 }
179
f048e32f 180 MyPanel *m_panel;
87a1e308 181
b8653fbf 182 DECLARE_EVENT_TABLE()
1c005ff7
RR
183};
184
185//----------------------------------------------------------------------
6c8a980f 186// other
1c005ff7
RR
187//----------------------------------------------------------------------
188
6c8a980f
VZ
189static void SetControlClientData(const char *name,
190 wxControlWithItems *control);
191
d59051dd 192IMPLEMENT_APP(MyApp)
1c005ff7
RR
193
194//----------------------------------------------------------------------
195// MyApp
196//----------------------------------------------------------------------
197
16f6dfd8
VZ
198enum
199{
3e2dd3db
VZ
200 CONTROLS_QUIT = 100,
201 CONTROLS_TEXT,
202 CONTROLS_ABOUT,
203 CONTROLS_CLEAR_LOG,
16f6dfd8
VZ
204
205 // tooltip menu
3e2dd3db
VZ
206 CONTROLS_SET_TOOLTIP_DELAY = 200,
207 CONTROLS_ENABLE_TOOLTIPS,
87a1e308
VZ
208
209 // panel menu
3e2dd3db 210 CONTROLS_ENABLE_ALL
16f6dfd8 211};
1c005ff7 212
b8653fbf 213bool MyApp::OnInit()
1c005ff7 214{
e66ad5c6
VZ
215 // parse the cmd line
216 int x = 50,
217 y = 50;
218 if ( argc == 2 )
219 {
220 wxSscanf(argv[1], "%d", &x);
221 wxSscanf(argv[2], "%d", &y);
222 }
223
ec9f7884
VZ
224 // Create the main frame window
225 MyFrame *frame = new MyFrame((wxFrame *) NULL,
226 "Controls wxWindows App",
fb5dc8a2 227 x, y, 540, 430);
29e7e51a 228
fb5dc8a2 229 frame->SetSizeHints( 500, 425 );
655822f3 230
ec9f7884
VZ
231 // Give it an icon
232 // The wxICON() macros loads an icon from a resource under Windows
233 // and uses an #included XPM image under GTK+ and Motif
655822f3 234
ec9f7884 235 frame->SetIcon( wxICON(mondrian) );
1c005ff7 236
6adaedf0
JS
237 wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF);
238
3e2dd3db 239 file_menu->Append(CONTROLS_CLEAR_LOG, "&Clear log\tCtrl-L");
87a1e308 240 file_menu->AppendSeparator();
3e2dd3db
VZ
241 file_menu->Append(CONTROLS_ABOUT, "&About\tF1");
242 file_menu->AppendSeparator();
243 file_menu->Append(CONTROLS_QUIT, "E&xit\tAlt-X", "Quit controls sample");
16f6dfd8 244
33caefb3 245 wxMenuBar *menu_bar = new wxMenuBar;
ec9f7884 246 menu_bar->Append(file_menu, "&File");
16f6dfd8
VZ
247
248#if wxUSE_TOOLTIPS
ec9f7884 249 wxMenu *tooltip_menu = new wxMenu;
3e2dd3db 250 tooltip_menu->Append(CONTROLS_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
ec9f7884 251 tooltip_menu->AppendSeparator();
3e2dd3db 252 tooltip_menu->Append(CONTROLS_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
ec9f7884 253 "enable/disable tooltips", TRUE);
3e2dd3db 254 tooltip_menu->Check(CONTROLS_ENABLE_TOOLTIPS, TRUE);
ec9f7884 255 menu_bar->Append(tooltip_menu, "&Tooltips");
16f6dfd8
VZ
256#endif // wxUSE_TOOLTIPS
257
87a1e308 258 wxMenu *panel_menu = new wxMenu;
3e2dd3db 259 panel_menu->Append(CONTROLS_ENABLE_ALL, "&Disable all\tCtrl-E",
87a1e308
VZ
260 "Enable/disable all panel controls", TRUE);
261 menu_bar->Append(panel_menu, "&Panel");
262
ec9f7884 263 frame->SetMenuBar(menu_bar);
1c005ff7 264
ec9f7884 265 frame->Show(TRUE);
9018abe3 266 frame->SetCursor(wxCursor(wxCURSOR_HAND));
655822f3 267
ee6e1b1d 268 //frame->GetPanel()->m_notebook->SetSelection(6);
f048e32f 269
ec9f7884 270 SetTopWindow(frame);
1c005ff7 271
ec9f7884 272 return TRUE;
1c005ff7
RR
273}
274
275//----------------------------------------------------------------------
276// MyPanel
277//----------------------------------------------------------------------
278
4fabb575 279const int ID_NOTEBOOK = 1000;
1c005ff7 280
4fabb575
JS
281const int ID_LISTBOX = 130;
282const int ID_LISTBOX_SEL_NUM = 131;
283const int ID_LISTBOX_SEL_STR = 132;
284const int ID_LISTBOX_CLEAR = 133;
285const int ID_LISTBOX_APPEND = 134;
286const int ID_LISTBOX_DELETE = 135;
287const int ID_LISTBOX_FONT = 136;
288const int ID_LISTBOX_ENABLE = 137;
6c8a980f 289const int ID_LISTBOX_SORTED = 138;
1c005ff7 290
4fabb575
JS
291const int ID_CHOICE = 120;
292const int ID_CHOICE_SEL_NUM = 121;
293const int ID_CHOICE_SEL_STR = 122;
294const int ID_CHOICE_CLEAR = 123;
295const int ID_CHOICE_APPEND = 124;
296const int ID_CHOICE_DELETE = 125;
297const int ID_CHOICE_FONT = 126;
298const int ID_CHOICE_ENABLE = 127;
b56c2246 299const int ID_CHOICE_SORTED = 128;
53010e52 300
4fabb575
JS
301const int ID_COMBO = 140;
302const int ID_COMBO_SEL_NUM = 141;
303const int ID_COMBO_SEL_STR = 142;
304const int ID_COMBO_CLEAR = 143;
305const int ID_COMBO_APPEND = 144;
306const int ID_COMBO_DELETE = 145;
307const int ID_COMBO_FONT = 146;
308const int ID_COMBO_ENABLE = 147;
53010e52 309
4fabb575
JS
310const int ID_RADIOBOX = 160;
311const int ID_RADIOBOX_SEL_NUM = 161;
312const int ID_RADIOBOX_SEL_STR = 162;
313const int ID_RADIOBOX_FONT = 163;
314const int ID_RADIOBOX_ENABLE = 164;
868a2826 315
f5d29b39
RR
316const int ID_RADIOBUTTON_1 = 166;
317const int ID_RADIOBUTTON_2 = 167;
318
4fabb575 319const int ID_SET_FONT = 170;
47908e25 320
4fabb575
JS
321const int ID_GAUGE = 180;
322const int ID_SLIDER = 181;
58614078 323
4fabb575 324const int ID_SPIN = 182;
9726da4f 325const int ID_BTNPROGRESS = 183;
185fa6bf 326const int ID_BUTTON_LABEL = 184;
baccb514 327const int ID_SPINCTRL = 185;
e380f72b 328
3e2dd3db
VZ
329const int ID_BUTTON_TEST1 = 190;
330const int ID_BUTTON_TEST2 = 191;
331
87a1e308
VZ
332const int ID_CHANGE_COLOUR = 200;
333
1c005ff7 334BEGIN_EVENT_TABLE(MyPanel, wxPanel)
ec9f7884 335EVT_SIZE ( MyPanel::OnSize)
4d0f3cd6 336EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
ec9f7884
VZ
337EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
338EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
6c8a980f 339EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
ec9f7884
VZ
340EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
341EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
342EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
343EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
344EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
345EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
346EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
347EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
348EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
b56c2246 349EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
ec9f7884
VZ
350EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
351EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
352EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
353EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
354EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
355EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
356EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
357EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
358EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
359EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
360EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
361EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
362EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
363EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
364EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
365EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
366EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
367EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
368EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
369EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
370EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
371EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
0e528b99 372#if wxUSE_SPINBTN
ec9f7884 373EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
8c3c31d4
VZ
374EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
375EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
9726da4f
VZ
376EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
377EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
0e528b99 378#endif // wxUSE_SPINBTN
baccb514 379#if wxUSE_SPINCTRL
57160afe 380EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
baccb514 381#endif // wxUSE_SPINCTRL
185fa6bf 382EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
87a1e308 383EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
3e2dd3db
VZ
384EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
385EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
1c005ff7
RR
386END_EVENT_TABLE()
387
5fb9fcfc 388MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
0a772322
VZ
389 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
390 m_text(NULL), m_notebook(NULL)
1c005ff7 391{
9d9b7755
VZ
392 wxLayoutConstraints *c;
393
3e2dd3db
VZ
394 m_text = new wxTextCtrl(this, -1, "This is the log window.\n",
395 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
103aab26 396 m_text->SetBackgroundColour("wheat");
655822f3 397
abceee76
VZ
398 if ( 0 )
399 wxLog::AddTraceMask(_T("focus"));
29e7e51a 400 m_logTargetOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
0a772322 401
3e2dd3db 402 m_notebook = new wxNotebook(this, ID_NOTEBOOK);
655822f3 403
ec9f7884
VZ
404 wxString choices[] =
405 {
406 "This",
407 "is one of my",
408 "really",
409 "wonderful",
410 "examples."
411 };
655822f3 412
4fabb575 413#ifdef USE_XPM
ec9f7884
VZ
414 // image ids
415 enum
416 {
417 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
418 };
419
420 // fill the image list
421 wxImageList *imagelist = new wxImageList(32, 32);
422
423 imagelist-> Add( wxBitmap( list_xpm ));
424 imagelist-> Add( wxBitmap( choice_xpm ));
425 imagelist-> Add( wxBitmap( combo_xpm ));
426 imagelist-> Add( wxBitmap( text_xpm ));
427 imagelist-> Add( wxBitmap( radio_xpm ));
428 imagelist-> Add( wxBitmap( gauge_xpm ));
429 m_notebook->SetImageList(imagelist);
73c700fd 430#elif defined(__WXMSW__)
ec9f7884
VZ
431 // load images from resources
432 enum
433 {
434 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
435 };
436 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
437
438 static const char *s_iconNames[Image_Max] =
439 {
440 "list", "choice", "combo", "text", "radio", "gauge"
441 };
442
443 for ( size_t n = 0; n < Image_Max; n++ )
444 {
445 wxBitmap bmp(s_iconNames[n]);
446 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
447 {
448 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
449 s_iconNames[n], n);
450 }
451 }
452
453 m_notebook->SetImageList(imagelist);
4fabb575
JS
454#else
455
ec9f7884 456 // No images for now
4fabb575
JS
457#define Image_List -1
458#define Image_Choice -1
459#define Image_Combo -1
460#define Image_Text -1
461#define Image_Radio -1
462#define Image_Gauge -1
463#define Image_Max -1
464
fc54776e 465#endif
2cb21a45 466
6c8a980f
VZ
467 wxPanel *panel = new wxPanel(m_notebook);
468 m_listbox = new wxListBox( panel, ID_LISTBOX,
469 wxPoint(10,10), wxSize(120,70),
354aa1e3 470 5, choices, wxLB_ALWAYS_SB );
6c8a980f
VZ
471 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
472 wxPoint(10,90), wxSize(120,70),
354aa1e3 473 5, choices, wxLB_SORT );
6c8a980f
VZ
474
475 SetControlClientData("listbox", m_listbox);
476 SetControlClientData("listbox", m_listboxSorted);
9838df2c 477
ec9f7884 478 m_listbox->SetCursor(*wxCROSS_CURSOR);
b8653fbf 479#if wxUSE_TOOLTIPS
ec9f7884 480 m_listbox->SetToolTip( "This is a list box" );
16f6dfd8 481#endif // wxUSE_TOOLTIPS
9f3362c4 482
3e2dd3db
VZ
483 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
484 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
485 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
486 (void)new wxButton( panel, ID_LISTBOX_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
487 (void)new wxButton( panel, ID_LISTBOX_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
6c8a980f 488 wxButton *button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
57160afe
VZ
489
490 button->SetDefault();
491
492 button->SetForegroundColour(*wxBLUE);
493
b8653fbf 494#if wxUSE_TOOLTIPS
ec9f7884 495 button->SetToolTip( "Press here to set italic font" );
16f6dfd8 496#endif // wxUSE_TOOLTIPS
b1170810 497
6c8a980f 498 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,170) );
ec9f7884 499 m_checkbox->SetValue(FALSE);
b8653fbf 500#if wxUSE_TOOLTIPS
ec9f7884 501 m_checkbox->SetToolTip( "Click here to disable the listbox" );
16f6dfd8 502#endif // wxUSE_TOOLTIPS
87a1e308
VZ
503 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, "&Toggle colour",
504 wxPoint(110,170) );
ec9f7884
VZ
505 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
506
507 panel = new wxPanel(m_notebook);
508 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
b56c2246
VZ
509 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
510 5, choices, wxCB_SORT );
6c8a980f 511
6adaedf0 512#ifndef __WXMOTIF__
6c8a980f
VZ
513 SetControlClientData("choice", m_choice);
514 SetControlClientData("choice", m_choiceSorted);
6adaedf0 515#endif
6c8a980f 516
ddc8c2e3 517 m_choice->SetSelection(2);
2b07d713 518 m_choice->SetBackgroundColour( "red" );
3e2dd3db
VZ
519 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
520 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
521 (void)new wxButton( panel, ID_CHOICE_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
522 (void)new wxButton( panel, ID_CHOICE_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
523 (void)new wxButton( panel, ID_CHOICE_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
524 (void)new wxButton( panel, ID_CHOICE_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
525 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "&Disable", wxPoint(20,130), wxSize(140,30) );
1fad4c3e 526
ec9f7884
VZ
527 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
528
529 panel = new wxPanel(m_notebook);
3e2dd3db 530 (void)new wxStaticBox( panel, -1, "&Box around combobox",
f048e32f 531 wxPoint(5, 5), wxSize(150, 100));
07f5b19a 532 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(20,25), wxSize(120,-1), 5, choices, wxCB_READONLY );
3e2dd3db
VZ
533 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
534 (void)new wxButton( panel, ID_COMBO_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
535 (void)new wxButton( panel, ID_COMBO_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
536 (void)new wxButton( panel, ID_COMBO_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
537 (void)new wxButton( panel, ID_COMBO_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
538 (void)new wxButton( panel, ID_COMBO_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
539 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "&Disable", wxPoint(20,130), wxSize(140,30) );
ec9f7884
VZ
540 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
541
ec9f7884
VZ
542 wxString choices2[] =
543 {
17867d61 544 "First", "Second",
0a772322 545 /* "Third",
17867d61
RR
546 "Fourth", "Fifth", "Sixth",
547 "Seventh", "Eighth", "Nineth", "Tenth" */
ec9f7884
VZ
548 };
549
550 panel = new wxPanel(m_notebook);
3e2dd3db
VZ
551 (void)new wxRadioBox( panel, ID_RADIOBOX, "&That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
552 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "T&his", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
f048e32f
VZ
553
554#if wxUSE_TOOLTIPS
3e2dd3db 555 m_combo->SetToolTip("This is a natural\ncombobox - can you believe me?");
f048e32f
VZ
556 m_radio->SetToolTip("Ever seen a radiobox?");
557#endif // wxUSE_TOOLTIPS
558
3e2dd3db
VZ
559 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
560 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "&Select 'This'", wxPoint(180,80), wxSize(140,30) );
561 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set &more Italic font", wxPoint(340,30), wxSize(140,30) );
562 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set &Italic font", wxPoint(340,80), wxSize(140,30) );
563 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "&Disable", wxPoint(340,130), wxDefaultSize );
7e2b55cd 564 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxDefaultSize, wxRB_GROUP );
ec9f7884 565 rb->SetValue( FALSE );
3e2dd3db 566 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "&Radiobutton2", wxPoint(340,170), wxDefaultSize );
ec9f7884
VZ
567 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
568
569 panel = new wxPanel(m_notebook);
3e2dd3db 570 (void)new wxStaticBox( panel, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
ec9f7884 571 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
858b5bdd 572 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
3e2dd3db 573 (void)new wxStaticBox( panel, -1, "&Explanation", wxPoint(220,10), wxSize(270,130) );
9838df2c 574#ifdef __WXMOTIF__
ec9f7884
VZ
575 // No wrapping text in wxStaticText yet :-(
576 (void)new wxStaticText( panel, -1,
577 "Drag the slider!",
33961d59 578 wxPoint(228,30),
e65cc56a 579 wxSize(240, -1)
ec9f7884 580 );
9838df2c 581#else
ec9f7884
VZ
582 (void)new wxStaticText( panel, -1,
583 "In order see the gauge (aka progress bar)\n"
584 "control do something you have to drag the\n"
585 "handle of the slider to the right.\n"
586 "\n"
587 "This is also supposed to demonstrate how\n"
588 "to use static controls.\n",
8c3c31d4
VZ
589 wxPoint(228,25),
590 wxSize(240, 110)
ec9f7884 591 );
9838df2c 592#endif
8c3c31d4
VZ
593 int initialSpinValue = -5;
594 wxString s;
595 s << initialSpinValue;
596 m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) );
0e528b99 597#if wxUSE_SPINBTN
738f9e5a 598 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, -1) );
6380910c 599 m_spinbutton->SetRange(-10,30);
8c3c31d4 600 m_spinbutton->SetValue(initialSpinValue);
9726da4f 601
3e2dd3db 602 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "&Show progress dialog",
738f9e5a 603 wxPoint(300, 160) );
0e528b99 604#endif // wxUSE_SPINBTN
b782f2e0
VZ
605
606#if wxUSE_SPINCTRL
678cd6de 607 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) );
b782f2e0
VZ
608 m_spinctrl->SetRange(10,30);
609 m_spinctrl->SetValue(15);
610#endif // wxUSE_SPINCTRL
611
ec9f7884 612 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
45e41c05
VZ
613
614 panel = new wxPanel(m_notebook);
b782f2e0 615
556921dc 616#ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
45e41c05 617 wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
f048e32f
VZ
618 wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
619 wxPoint(10, 10));
45e41c05
VZ
620
621 bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
622 bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
b782f2e0
VZ
623#endif // !Motif
624
45e41c05
VZ
625 wxBitmap bitmap( 100, 100 );
626 wxMemoryDC dc;
627 dc.SelectObject( bitmap );
628 dc.SetPen(*wxGREEN_PEN);
f048e32f 629 dc.Clear();
45e41c05 630 dc.DrawEllipse(5, 5, 90, 90);
f048e32f 631 dc.DrawText("Bitmap", 30, 40);
45e41c05
VZ
632 dc.SelectObject( wxNullBitmap );
633
185fa6bf 634 (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
f048e32f 635
80a58c99 636#ifdef __WXMSW__
3e2dd3db
VZ
637 // test for masked bitmap display
638 bitmap = wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP);
9bb3479c
JS
639 if (bitmap.Ok())
640 {
641 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
642 (void)new wxStaticBitmap /* wxBitmapButton */ (panel, -1, bitmap, wxPoint(300, 120));
643 }
57160afe 644#endif
5ef2e633 645
f048e32f
VZ
646 wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
647 bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
648 bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
649 wxBitmapButton *bmpBtn = new wxBitmapButton
650 (
651 panel, -1,
652 bmp1,
653 wxPoint(30, 50)
654 );
655 bmpBtn->SetBitmapSelected(bmp2);
656 bmpBtn->SetBitmapFocus(bmp3);
657
3e2dd3db 658 (void)new wxButton(panel, ID_BUTTON_LABEL, "&Toggle label", wxPoint(250, 20));
185fa6bf
VZ
659 m_label = new wxStaticText(panel, -1, "Label with some long text",
660 wxPoint(250, 60), wxDefaultSize,
661 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
103aab26 662 m_label->SetForegroundColour( *wxBLUE );
2ac1b69a 663
45e41c05 664 m_notebook->AddPage(panel, "wxBitmapXXX");
dcc71398 665
9d9b7755 666 // layout constraints
dcc71398 667
9d9b7755
VZ
668 panel = new wxPanel(m_notebook);
669 panel->SetAutoLayout( TRUE );
d7928388 670
9d9b7755
VZ
671 c = new wxLayoutConstraints;
672 c->top.SameAs( panel, wxTop, 10 );
673 c->height.AsIs( );
674 c->left.SameAs( panel, wxLeft, 10 );
675 c->width.PercentOf( panel, wxWidth, 40 );
d7928388 676
3e2dd3db 677 wxButton *pMyButton = new wxButton(panel, ID_BUTTON_TEST1, "Test Button &1" );
9d9b7755 678 pMyButton->SetConstraints( c );
d7928388 679
9d9b7755
VZ
680 c = new wxLayoutConstraints;
681 c->top.SameAs( panel, wxTop, 10 );
682 c->bottom.SameAs( panel, wxBottom, 10 );
683 c->right.SameAs( panel, wxRight, 10 );
684 c->width.PercentOf( panel, wxWidth, 40 );
185fa6bf 685
3e2dd3db 686 wxButton *pMyButton2 = new wxButton(panel, ID_BUTTON_TEST2, "Test Button &2" );
9d9b7755 687 pMyButton2->SetConstraints( c );
185fa6bf 688
9d9b7755 689 m_notebook->AddPage(panel, "wxLayoutConstraint");
d7928388 690
9d9b7755 691 // sizer
dcc71398 692
9d9b7755
VZ
693 panel = new wxPanel(m_notebook);
694 panel->SetAutoLayout( TRUE );
dcc71398 695
9d9b7755
VZ
696 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
697
3e2dd3db 698 sizer->Add( new wxButton(panel, -1, "Test Button &1" ), 3, wxALL, 10 );
9d9b7755 699 sizer->Add( 20,20, 1 );
3e2dd3db 700 sizer->Add( new wxButton(panel, -1, "Test Button &2" ), 3, wxGROW|wxALL, 10 );
9d9b7755
VZ
701
702 panel->SetSizer( sizer );
703
704 m_notebook->AddPage(panel, "wxSizer");
1c005ff7
RR
705}
706
707void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
708{
ec9f7884
VZ
709 int x = 0;
710 int y = 0;
711 GetClientSize( &x, &y );
655822f3 712
ec9f7884
VZ
713 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
714 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1c005ff7
RR
715}
716
4d0f3cd6
VZ
717void MyPanel::OnPageChanging( wxNotebookEvent &event )
718{
45e41c05
VZ
719 int selOld = event.GetOldSelection();
720 if ( selOld == 2 )
4d0f3cd6 721 {
65045edd
RR
722 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
723 "page change from taking place - if you select\n"
724 "[No] the current page will stay the third one\n",
8c3c31d4
VZ
725 "Control sample",
726 wxICON_QUESTION | wxYES_NO) != wxYES )
727 {
728 event.Veto();
45e41c05 729
8c3c31d4
VZ
730 return;
731 }
4d0f3cd6 732 }
45e41c05
VZ
733
734 *m_text << "Notebook selection is being changed from " << selOld << "\n";
4d0f3cd6
VZ
735}
736
cb43b372
RR
737void MyPanel::OnPageChanged( wxNotebookEvent &event )
738{
ec9f7884 739 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
cb43b372
RR
740}
741
3e2dd3db
VZ
742void MyPanel::OnTestButton(wxCommandEvent& event)
743{
744 wxLogMessage(_T("Button %c clicked."),
745 event.GetId() == ID_BUTTON_TEST1 ? _T('1') : _T('2'));
746}
747
87a1e308
VZ
748void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
749{
750 static wxColour s_colOld;
751
752 // test panel colour changing and propagation to the subcontrols
753 if ( s_colOld.Ok() )
754 {
755 SetBackgroundColour(s_colOld);
756 s_colOld = wxNullColour;
757
103aab26
RR
758 m_lbSelectThis->SetForegroundColour("red");
759 m_lbSelectThis->SetBackgroundColour("white");
87a1e308
VZ
760 }
761 else
762 {
103aab26
RR
763 s_colOld = wxColour("red");
764 SetBackgroundColour("white");
87a1e308 765
57160afe 766 m_lbSelectThis->SetForegroundColour("white");
87a1e308
VZ
767 m_lbSelectThis->SetBackgroundColour("red");
768 }
769
770 m_lbSelectThis->Refresh();
771 Refresh();
772}
773
1c005ff7
RR
774void MyPanel::OnListBox( wxCommandEvent &event )
775{
2e0e025e 776// GetParent()->Move(100, 100);
e66ad5c6 777
846e1424
RR
778 if (event.GetInt() == -1)
779 {
780 m_text->AppendText( "ListBox has no selections anymore\n" );
781 return;
782 }
783
6c8a980f
VZ
784 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
785 : m_listboxSorted;
786
787 m_text->AppendText( "ListBox event selection string is: '" );
ec9f7884 788 m_text->AppendText( event.GetString() );
6c8a980f
VZ
789 m_text->AppendText( "'\n" );
790 m_text->AppendText( "ListBox control selection string is: '" );
791 m_text->AppendText( listbox->GetStringSelection() );
792 m_text->AppendText( "'\n" );
793
794 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
795 m_text->AppendText( "ListBox event client data string is: '" );
6e47faf1 796 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
74a533f7 797 m_text->AppendText( obj->GetData() );
6e47faf1 798 else
74a533f7 799 m_text->AppendText( wxString("none") );
6e47faf1 800
6c8a980f
VZ
801 m_text->AppendText( "'\n" );
802 m_text->AppendText( "ListBox control client data string is: '" );
803 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
6e47faf1 804 if (obj)
74a533f7 805 m_text->AppendText( obj->GetData() );
6e47faf1 806 else
74a533f7 807 m_text->AppendText( wxString("none") );
6c8a980f 808 m_text->AppendText( "'\n" );
1c005ff7
RR
809}
810
5b077d48
RR
811void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
812{
ec9f7884
VZ
813 m_text->AppendText( "ListBox double click string is: " );
814 m_text->AppendText( event.GetString() );
815 m_text->AppendText( "\n" );
5b077d48
RR
816}
817
47908e25
RR
818void MyPanel::OnListBoxButtons( wxCommandEvent &event )
819{
ec9f7884 820 switch (event.GetId())
d3904ceb 821 {
ec9f7884
VZ
822 case ID_LISTBOX_ENABLE:
823 {
824 m_text->AppendText("Checkbox clicked.\n");
825 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
b8653fbf 826#if wxUSE_TOOLTIPS
ec9f7884
VZ
827 if (event.GetInt())
828 cb->SetToolTip( "Click to enable listbox" );
829 else
830 cb->SetToolTip( "Click to disable listbox" );
16f6dfd8 831#endif // wxUSE_TOOLTIPS
ec9f7884 832 m_listbox->Enable( event.GetInt() == 0 );
57160afe
VZ
833 m_lbSelectThis->Enable( event.GetInt() == 0 );
834 m_lbSelectNum->Enable( event.GetInt() == 0 );
6c8a980f 835 m_listboxSorted->Enable( event.GetInt() == 0 );
ee6e1b1d 836 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
ec9f7884
VZ
837 break;
838 }
839 case ID_LISTBOX_SEL_NUM:
840 {
841 m_listbox->SetSelection( 2 );
6c8a980f 842 m_listboxSorted->SetSelection( 2 );
8c3c31d4 843 m_lbSelectThis->WarpPointer( 40, 14 );
ec9f7884
VZ
844 break;
845 }
846 case ID_LISTBOX_SEL_STR:
847 {
848 m_listbox->SetStringSelection( "This" );
6c8a980f 849 m_listboxSorted->SetStringSelection( "This" );
8c3c31d4 850 m_lbSelectNum->WarpPointer( 40, 14 );
ec9f7884
VZ
851 break;
852 }
853 case ID_LISTBOX_CLEAR:
854 {
855 m_listbox->Clear();
6c8a980f 856 m_listboxSorted->Clear();
ec9f7884
VZ
857 break;
858 }
859 case ID_LISTBOX_APPEND:
860 {
861 m_listbox->Append( "Hi!" );
6c8a980f 862 m_listboxSorted->Append( "Hi!" );
ec9f7884
VZ
863 break;
864 }
865 case ID_LISTBOX_DELETE:
866 {
6c8a980f
VZ
867 int idx;
868 idx = m_listbox->GetSelection();
ec9f7884 869 m_listbox->Delete( idx );
6c8a980f
VZ
870 idx = m_listboxSorted->GetSelection();
871 m_listboxSorted->Delete( idx );
ec9f7884
VZ
872 break;
873 }
874 case ID_LISTBOX_FONT:
875 {
876 m_listbox->SetFont( *wxITALIC_FONT );
6c8a980f 877 m_listboxSorted->SetFont( *wxITALIC_FONT );
ec9f7884
VZ
878 m_checkbox->SetFont( *wxITALIC_FONT );
879 break;
880 }
868a2826 881 }
47908e25
RR
882}
883
884void MyPanel::OnChoice( wxCommandEvent &event )
885{
6c8a980f
VZ
886 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
887 : m_choiceSorted;
888
889 m_text->AppendText( "Choice event selection string is: '" );
ec9f7884 890 m_text->AppendText( event.GetString() );
6c8a980f 891 m_text->AppendText( "'\n" );
b56c2246 892 m_text->AppendText( "Choice control selection string is: '" );
6c8a980f
VZ
893 m_text->AppendText( choice->GetStringSelection() );
894 m_text->AppendText( "'\n" );
895
896 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
897 m_text->AppendText( "Choice event client data string is: '" );
6e47faf1
JS
898
899 if (obj)
900 m_text->AppendText( obj->GetData() );
901 else
902 m_text->AppendText( wxString("none") );
903
6c8a980f
VZ
904 m_text->AppendText( "'\n" );
905 m_text->AppendText( "Choice control client data string is: '" );
906 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
6e47faf1
JS
907
908 if (obj)
909 m_text->AppendText( obj->GetData() );
910 else
911 m_text->AppendText( wxString("none") );
6c8a980f 912 m_text->AppendText( "'\n" );
47908e25
RR
913}
914
915void MyPanel::OnChoiceButtons( wxCommandEvent &event )
916{
ec9f7884 917 switch (event.GetId())
47908e25 918 {
ec9f7884
VZ
919 case ID_CHOICE_ENABLE:
920 {
921 m_choice->Enable( event.GetInt() == 0 );
b56c2246 922 m_choiceSorted->Enable( event.GetInt() == 0 );
ec9f7884
VZ
923 break;
924 }
925 case ID_CHOICE_SEL_NUM:
926 {
927 m_choice->SetSelection( 2 );
b56c2246 928 m_choiceSorted->SetSelection( 2 );
ec9f7884
VZ
929 break;
930 }
931 case ID_CHOICE_SEL_STR:
932 {
933 m_choice->SetStringSelection( "This" );
b56c2246 934 m_choiceSorted->SetStringSelection( "This" );
ec9f7884
VZ
935 break;
936 }
937 case ID_CHOICE_CLEAR:
938 {
939 m_choice->Clear();
b56c2246 940 m_choiceSorted->Clear();
ec9f7884
VZ
941 break;
942 }
943 case ID_CHOICE_APPEND:
944 {
945 m_choice->Append( "Hi!" );
b56c2246 946 m_choiceSorted->Append( "Hi!" );
ec9f7884
VZ
947 break;
948 }
949 case ID_CHOICE_DELETE:
950 {
951 int idx = m_choice->GetSelection();
952 m_choice->Delete( idx );
b56c2246
VZ
953 idx = m_choiceSorted->GetSelection();
954 m_choiceSorted->Delete( idx );
ec9f7884
VZ
955 break;
956 }
957 case ID_CHOICE_FONT:
958 {
959 m_choice->SetFont( *wxITALIC_FONT );
b56c2246 960 m_choiceSorted->SetFont( *wxITALIC_FONT );
ec9f7884
VZ
961 break;
962 }
868a2826 963 }
47908e25
RR
964}
965
966void MyPanel::OnCombo( wxCommandEvent &event )
967{
19da4326 968 m_text->AppendText( "ComboBox event selection string is: " );
ec9f7884
VZ
969 m_text->AppendText( event.GetString() );
970 m_text->AppendText( "\n" );
19da4326
RR
971 m_text->AppendText( "ComboBox control selection string is: " );
972 m_text->AppendText( m_combo->GetStringSelection() );
973 m_text->AppendText( "\n" );
47908e25
RR
974}
975
976void MyPanel::OnComboButtons( wxCommandEvent &event )
1c005ff7 977{
ec9f7884 978 switch (event.GetId())
2f6407b9 979 {
ec9f7884
VZ
980 case ID_COMBO_ENABLE:
981 {
982 m_combo->Enable( event.GetInt() == 0 );
983 break;
984 }
985 case ID_COMBO_SEL_NUM:
986 {
987 m_combo->SetSelection( 2 );
988 break;
989 }
990 case ID_COMBO_SEL_STR:
991 {
992 m_combo->SetStringSelection( "This" );
993 break;
994 }
995 case ID_COMBO_CLEAR:
996 {
997 m_combo->Clear();
998 break;
999 }
1000 case ID_COMBO_APPEND:
1001 {
1002 m_combo->Append( "Hi!" );
1003 break;
1004 }
1005 case ID_COMBO_DELETE:
1006 {
1007 int idx = m_combo->GetSelection();
1008 m_combo->Delete( idx );
1009 break;
1010 }
1011 case ID_COMBO_FONT:
1012 {
1013 m_combo->SetFont( *wxITALIC_FONT );
1014 break;
1015 }
868a2826 1016 }
47908e25
RR
1017}
1018
1019void MyPanel::OnRadio( wxCommandEvent &event )
1020{
ec9f7884
VZ
1021 m_text->AppendText( "RadioBox selection string is: " );
1022 m_text->AppendText( event.GetString() );
1023 m_text->AppendText( "\n" );
47908e25
RR
1024}
1025
1026void MyPanel::OnRadioButtons( wxCommandEvent &event )
1027{
ec9f7884 1028 switch (event.GetId())
d3904ceb 1029 {
ec9f7884
VZ
1030 case ID_RADIOBOX_ENABLE:
1031 {
1032 m_radio->Enable( event.GetInt() == 0 );
1033 break;
1034 }
1035 case ID_RADIOBOX_SEL_NUM:
1036 {
1037 m_radio->SetSelection( 2 );
1038 break;
1039 }
1040 case ID_RADIOBOX_SEL_STR:
1041 {
1042 m_radio->SetStringSelection( "This" );
1043 break;
1044 }
1045 case ID_RADIOBOX_FONT:
1046 {
1047 m_radio->SetFont( *wxITALIC_FONT );
1048 break;
1049 }
868a2826 1050 }
1c005ff7
RR
1051}
1052
868a2826
RR
1053void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1054{
ec9f7884
VZ
1055 m_fontButton->SetFont( *wxITALIC_FONT );
1056 m_text->SetFont( *wxITALIC_FONT );
868a2826
RR
1057}
1058
185fa6bf
VZ
1059void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
1060{
1061 static bool s_long = TRUE;
1062
1063 s_long = !s_long;
1064 m_label->SetLabel(s_long ? "very very very long text" : "shorter text");
1065}
1066
7bce6aec
RR
1067void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1068{
ec9f7884 1069 m_gauge->SetValue( m_slider->GetValue() );
7bce6aec
RR
1070}
1071
baccb514
VZ
1072#if wxUSE_SPINCTRL
1073
457e6c54 1074void MyPanel::OnSpinCtrl(wxSpinEvent& event)
baccb514
VZ
1075{
1076 wxString s;
57160afe
VZ
1077 s.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1078 m_spinctrl->GetValue(), event.GetInt());
baccb514
VZ
1079 m_text->AppendText(s);
1080}
1081
1082#endif // wxUSE_SPINCTRL
1083
0e528b99 1084#if wxUSE_SPINBTN
8c3c31d4
VZ
1085void MyPanel::OnSpinUp( wxSpinEvent &event )
1086{
1087 wxString value;
1088 value.Printf( _T("Spin control up: current = %d\n"),
1089 m_spinbutton->GetValue());
1090
1091 if ( m_spinbutton->GetValue() > 17 )
1092 {
1093 value += _T("Preventing the spin button from going above 17.\n");
1094
1095 event.Veto();
1096 }
1097
1098 m_text->AppendText(value);
1099}
1100
1101void MyPanel::OnSpinDown( wxSpinEvent &event )
1102{
1103 wxString value;
1104 value.Printf( _T("Spin control down: current = %d\n"),
1105 m_spinbutton->GetValue());
1106
1107 if ( m_spinbutton->GetValue() < -17 )
1108 {
1109 value += _T("Preventing the spin button from going below -17.\n");
1110
1111 event.Veto();
1112 }
1113
1114 m_text->AppendText(value);
1115}
1116
e380f72b
RR
1117void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1118{
ec9f7884 1119 wxString value;
f70d5829 1120 value.Printf( _T("%d"), event.GetPosition() );
ec9f7884 1121 m_spintext->SetValue( value );
6380910c 1122
f70d5829 1123 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
6380910c
VZ
1124 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1125 m_spinbutton->GetValue());
1126
1127 m_text->AppendText(value);
e380f72b 1128}
9726da4f
VZ
1129
1130void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1131{
1132 event.Enable( m_spinbutton->GetValue() > 0 );
1133}
1134
1135void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1136{
1137 int max = m_spinbutton->GetValue();
1138 wxProgressDialog dialog("Progress dialog example",
1139 "An informative message",
1140 max, // range
1141 this, // parent
8c3c31d4
VZ
1142 wxPD_CAN_ABORT |
1143 wxPD_APP_MODAL |
1144 wxPD_ELAPSED_TIME |
1145 wxPD_ESTIMATED_TIME |
1146 wxPD_REMAINING_TIME);
2ac1b69a 1147
9726da4f
VZ
1148
1149 bool cont = TRUE;
abceee76 1150 for ( int i = 0; i <= max && cont; i++ )
9726da4f
VZ
1151 {
1152 wxSleep(1);
abceee76 1153 if ( i == max )
be9abe3f
VZ
1154 {
1155 cont = dialog.Update(i, "That's all, folks!");
1156 }
1157 else if ( i == max / 2 )
9726da4f 1158 {
abceee76 1159 cont = dialog.Update(i, "Only a half left (very long message)!");
9726da4f
VZ
1160 }
1161 else
1162 {
1163 cont = dialog.Update(i);
1164 }
1165 }
1166
1167 if ( !cont )
1168 {
1169 *m_text << "Progress dialog aborted!\n";
1170 }
1171 else
1172 {
1173 *m_text << "Countdown from " << max << " finished.\n";
1174 }
1175}
1176
0e528b99 1177#endif // wxUSE_SPINBTN
e380f72b 1178
2cb21a45
VZ
1179MyPanel::~MyPanel()
1180{
29e7e51a
VZ
1181 //wxLog::RemoveTraceMask(_T("focus"));
1182 delete wxLog::SetActiveTarget(m_logTargetOld);
1183
ec9f7884 1184 delete m_notebook->GetImageList();
2cb21a45
VZ
1185}
1186
1c005ff7
RR
1187//----------------------------------------------------------------------
1188// MyFrame
1189//----------------------------------------------------------------------
1190
1191BEGIN_EVENT_TABLE(MyFrame, wxFrame)
3e2dd3db
VZ
1192 EVT_MENU(CONTROLS_QUIT, MyFrame::OnQuit)
1193 EVT_MENU(CONTROLS_ABOUT, MyFrame::OnAbout)
1194 EVT_MENU(CONTROLS_CLEAR_LOG, MyFrame::OnClearLog)
16f6dfd8 1195#if wxUSE_TOOLTIPS
3e2dd3db
VZ
1196 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1197 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
16f6dfd8 1198#endif // wxUSE_TOOLTIPS
87a1e308 1199
3e2dd3db 1200 EVT_MENU(CONTROLS_ENABLE_ALL, MyFrame::OnEnableAll)
87a1e308
VZ
1201
1202 EVT_SIZE(MyFrame::OnSize)
97206645
VZ
1203 EVT_MOVE(MyFrame::OnMove)
1204
87a1e308 1205 EVT_IDLE(MyFrame::OnIdle)
1c005ff7
RR
1206END_EVENT_TABLE()
1207
9f3362c4 1208MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
ec9f7884 1209: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1c005ff7 1210{
5fb9fcfc 1211 CreateStatusBar(2);
9f3362c4 1212
87a1e308 1213 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1c005ff7
RR
1214}
1215
1216void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1217{
ec9f7884 1218 Close(TRUE);
1c005ff7
RR
1219}
1220
1221void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1222{
abceee76
VZ
1223 wxBusyCursor bc;
1224
1225#if 0 // VZ: my temp test code, will remove
1226 wxGetTextFromUser("msg", "caption", "val", this);
1227 return;
1228#endif // 0
ec9f7884
VZ
1229
1230 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
1231 dialog.ShowModal();
1c005ff7 1232}
9f3362c4 1233
3e2dd3db
VZ
1234void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
1235{
1236 m_panel->m_text->Clear();
1237}
1238
16f6dfd8
VZ
1239#if wxUSE_TOOLTIPS
1240void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1241{
1242 static long s_delay = 5000;
1243
1244 wxString delay;
f70d5829 1245 delay.Printf( _T("%ld"), s_delay);
16f6dfd8
VZ
1246
1247 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
ec9f7884
VZ
1248 "Set tooltip delay",
1249 delay,
1250 this);
16f6dfd8
VZ
1251 if ( !delay )
1252 return; // cancelled
1253
f70d5829 1254 wxSscanf(delay, _T("%ld"), &s_delay);
16f6dfd8
VZ
1255
1256 wxToolTip::SetDelay(s_delay);
1257
f70d5829 1258 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
16f6dfd8
VZ
1259}
1260
1261void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1262{
1263 static bool s_enabled = TRUE;
1264
1265 s_enabled = !s_enabled;
1266
1267 wxToolTip::Enable(s_enabled);
1268
f70d5829 1269 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
16f6dfd8
VZ
1270}
1271#endif // tooltips
1272
87a1e308
VZ
1273void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1274{
1275 static bool s_enable = TRUE;
1276
1277 s_enable = !s_enable;
1278 m_panel->Enable(s_enable);
1279}
1280
97206645
VZ
1281void MyFrame::OnMove( wxMoveEvent& event )
1282{
1283 UpdateStatusBar(event.GetPosition(), GetSize());
1284
1285 event.Skip();
1286}
1287
5fb9fcfc
VZ
1288void MyFrame::OnSize( wxSizeEvent& event )
1289{
97206645 1290 UpdateStatusBar(GetPosition(), event.GetSize());
5fb9fcfc
VZ
1291
1292 event.Skip();
1293}
1294
9f3362c4
VZ
1295void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1296{
1297 // track the window which has the focus in the status bar
1298 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1299 wxWindow *focus = wxWindow::FindFocus();
1300 if ( focus && (focus != s_windowFocus) )
1301 {
1302 s_windowFocus = focus;
1303
1304 wxString msg;
f70d5829 1305 msg.Printf(
9f3362c4 1306#ifdef __WXMSW__
29e7e51a 1307 _T("Focus: %s, HWND = %08x"),
f70d5829 1308#else
29e7e51a 1309 _T("Focus: %s"),
f70d5829 1310#endif
29e7e51a 1311 s_windowFocus->GetClassInfo()->GetClassName()
9f3362c4 1312#ifdef __WXMSW__
ec9f7884 1313 , s_windowFocus->GetHWND()
f70d5829 1314#endif
9f3362c4
VZ
1315 );
1316
1317 SetStatusText(msg);
1318 }
341c92a8 1319}
6c8a980f
VZ
1320
1321static void SetControlClientData(const char *name,
1322 wxControlWithItems *control)
1323{
1324 size_t count = control->GetCount();
1325 for ( size_t n = 0; n < count; n++ )
1326 {
1327 wxString s;
1328 s.Printf("%s client data for '%s'",
1329 name, control->GetString(n).c_str());
1330
1331 control->SetClientObject(n, new wxStringClientData(s));
1332 }
1333}