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