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