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