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