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