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