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