]> git.saurik.com Git - wxWidgets.git/blame - samples/controls/controls.cpp
More broken code corrections; broken Latex file corrections.
[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");
dcc71398
RD
533
534// --------------- TEST CODE ----------------------
535
536 panel = new wxPanel(m_notebook);
537 panel->SetAutoLayout( true );
538
539 wxLayoutConstraints *c;
540 c = new wxLayoutConstraints;
541 c->top.SameAs( panel, wxTop, 10 );
542 c->height.AsIs( );
543 c->left.SameAs( panel, wxLeft, 10 );
544 c->width.PercentOf( panel, wxWidth, 40 );
545
546 wxButton *pMyButton = new wxButton(panel, -1, "Test Button" );
547 pMyButton->SetConstraints( c );
548
549 c = new wxLayoutConstraints;
550 c->top.SameAs( panel, wxTop, 10 );
551 c->bottom.SameAs( panel, wxBottom, 10 );
552 c->right.SameAs( panel, wxRight, 10 );
553 c->width.PercentOf( panel, wxWidth, 40 );
554
555 wxButton *pMyButton2 = new wxButton(panel, -1, "Test Button 2" );
556 pMyButton2->SetConstraints( c );
557
558 m_notebook->AddPage(panel, "test layout");
559
560// --------------- TEST CODE ----------------------
561
1c005ff7
RR
562}
563
564void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
565{
ec9f7884
VZ
566 int x = 0;
567 int y = 0;
568 GetClientSize( &x, &y );
655822f3 569
ec9f7884
VZ
570 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
571 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1c005ff7
RR
572}
573
4d0f3cd6
VZ
574void MyPanel::OnPageChanging( wxNotebookEvent &event )
575{
45e41c05
VZ
576 int selOld = event.GetOldSelection();
577 if ( selOld == 2 )
4d0f3cd6 578 {
65045edd
RR
579 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
580 "page change from taking place - if you select\n"
581 "[No] the current page will stay the third one\n",
8c3c31d4
VZ
582 "Control sample",
583 wxICON_QUESTION | wxYES_NO) != wxYES )
584 {
585 event.Veto();
45e41c05 586
8c3c31d4
VZ
587 return;
588 }
4d0f3cd6 589 }
45e41c05
VZ
590
591 *m_text << "Notebook selection is being changed from " << selOld << "\n";
4d0f3cd6
VZ
592}
593
cb43b372
RR
594void MyPanel::OnPageChanged( wxNotebookEvent &event )
595{
ec9f7884 596 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
cb43b372
RR
597}
598
1c005ff7
RR
599void MyPanel::OnListBox( wxCommandEvent &event )
600{
19da4326 601 m_text->AppendText( "ListBox event selection string is: " );
ec9f7884
VZ
602 m_text->AppendText( event.GetString() );
603 m_text->AppendText( "\n" );
19da4326
RR
604 m_text->AppendText( "ListBox control selection string is: " );
605 m_text->AppendText( m_listbox->GetStringSelection() );
606 m_text->AppendText( "\n" );
1c005ff7
RR
607}
608
5b077d48
RR
609void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
610{
ec9f7884
VZ
611 m_text->AppendText( "ListBox double click string is: " );
612 m_text->AppendText( event.GetString() );
613 m_text->AppendText( "\n" );
5b077d48
RR
614}
615
47908e25
RR
616void MyPanel::OnListBoxButtons( wxCommandEvent &event )
617{
ec9f7884 618 switch (event.GetId())
d3904ceb 619 {
ec9f7884
VZ
620 case ID_LISTBOX_ENABLE:
621 {
622 m_text->AppendText("Checkbox clicked.\n");
623 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
b8653fbf 624#if wxUSE_TOOLTIPS
ec9f7884
VZ
625 if (event.GetInt())
626 cb->SetToolTip( "Click to enable listbox" );
627 else
628 cb->SetToolTip( "Click to disable listbox" );
16f6dfd8 629#endif // wxUSE_TOOLTIPS
ec9f7884
VZ
630 m_listbox->Enable( event.GetInt() == 0 );
631 break;
632 }
633 case ID_LISTBOX_SEL_NUM:
634 {
635 m_listbox->SetSelection( 2 );
8c3c31d4 636 m_lbSelectThis->WarpPointer( 40, 14 );
ec9f7884
VZ
637 break;
638 }
639 case ID_LISTBOX_SEL_STR:
640 {
641 m_listbox->SetStringSelection( "This" );
8c3c31d4 642 m_lbSelectNum->WarpPointer( 40, 14 );
ec9f7884
VZ
643 break;
644 }
645 case ID_LISTBOX_CLEAR:
646 {
647 m_listbox->Clear();
648 break;
649 }
650 case ID_LISTBOX_APPEND:
651 {
652 m_listbox->Append( "Hi!" );
653 break;
654 }
655 case ID_LISTBOX_DELETE:
656 {
657 int idx = m_listbox->GetSelection();
658 m_listbox->Delete( idx );
659 break;
660 }
661 case ID_LISTBOX_FONT:
662 {
663 m_listbox->SetFont( *wxITALIC_FONT );
664 m_checkbox->SetFont( *wxITALIC_FONT );
665 break;
666 }
868a2826 667 }
47908e25
RR
668}
669
670void MyPanel::OnChoice( wxCommandEvent &event )
671{
19da4326 672 m_text->AppendText( "Choice event selection string is: " );
ec9f7884
VZ
673 m_text->AppendText( event.GetString() );
674 m_text->AppendText( "\n" );
19da4326
RR
675 m_text->AppendText( "Choice control selection string is: " );
676 m_text->AppendText( m_choice->GetStringSelection() );
677 m_text->AppendText( "\n" );
47908e25
RR
678}
679
680void MyPanel::OnChoiceButtons( wxCommandEvent &event )
681{
ec9f7884 682 switch (event.GetId())
47908e25 683 {
ec9f7884
VZ
684 case ID_CHOICE_ENABLE:
685 {
686 m_choice->Enable( event.GetInt() == 0 );
687 break;
688 }
689 case ID_CHOICE_SEL_NUM:
690 {
691 m_choice->SetSelection( 2 );
692 break;
693 }
694 case ID_CHOICE_SEL_STR:
695 {
696 m_choice->SetStringSelection( "This" );
697 break;
698 }
699 case ID_CHOICE_CLEAR:
700 {
701 m_choice->Clear();
702 break;
703 }
704 case ID_CHOICE_APPEND:
705 {
706 m_choice->Append( "Hi!" );
707 break;
708 }
709 case ID_CHOICE_DELETE:
710 {
711 int idx = m_choice->GetSelection();
712 m_choice->Delete( idx );
713 break;
714 }
715 case ID_CHOICE_FONT:
716 {
717 m_choice->SetFont( *wxITALIC_FONT );
718 break;
719 }
868a2826 720 }
47908e25
RR
721}
722
723void MyPanel::OnCombo( wxCommandEvent &event )
724{
19da4326 725 m_text->AppendText( "ComboBox event selection string is: " );
ec9f7884
VZ
726 m_text->AppendText( event.GetString() );
727 m_text->AppendText( "\n" );
19da4326
RR
728 m_text->AppendText( "ComboBox control selection string is: " );
729 m_text->AppendText( m_combo->GetStringSelection() );
730 m_text->AppendText( "\n" );
47908e25
RR
731}
732
733void MyPanel::OnComboButtons( wxCommandEvent &event )
1c005ff7 734{
ec9f7884 735 switch (event.GetId())
2f6407b9 736 {
ec9f7884
VZ
737 case ID_COMBO_ENABLE:
738 {
739 m_combo->Enable( event.GetInt() == 0 );
740 break;
741 }
742 case ID_COMBO_SEL_NUM:
743 {
744 m_combo->SetSelection( 2 );
745 break;
746 }
747 case ID_COMBO_SEL_STR:
748 {
749 m_combo->SetStringSelection( "This" );
750 break;
751 }
752 case ID_COMBO_CLEAR:
753 {
754 m_combo->Clear();
755 break;
756 }
757 case ID_COMBO_APPEND:
758 {
759 m_combo->Append( "Hi!" );
760 break;
761 }
762 case ID_COMBO_DELETE:
763 {
764 int idx = m_combo->GetSelection();
765 m_combo->Delete( idx );
766 break;
767 }
768 case ID_COMBO_FONT:
769 {
770 m_combo->SetFont( *wxITALIC_FONT );
771 break;
772 }
868a2826 773 }
47908e25
RR
774}
775
776void MyPanel::OnRadio( wxCommandEvent &event )
777{
ec9f7884
VZ
778 m_text->AppendText( "RadioBox selection string is: " );
779 m_text->AppendText( event.GetString() );
780 m_text->AppendText( "\n" );
47908e25
RR
781}
782
783void MyPanel::OnRadioButtons( wxCommandEvent &event )
784{
ec9f7884 785 switch (event.GetId())
d3904ceb 786 {
ec9f7884
VZ
787 case ID_RADIOBOX_ENABLE:
788 {
789 m_radio->Enable( event.GetInt() == 0 );
790 break;
791 }
792 case ID_RADIOBOX_SEL_NUM:
793 {
794 m_radio->SetSelection( 2 );
795 break;
796 }
797 case ID_RADIOBOX_SEL_STR:
798 {
799 m_radio->SetStringSelection( "This" );
800 break;
801 }
802 case ID_RADIOBOX_FONT:
803 {
804 m_radio->SetFont( *wxITALIC_FONT );
805 break;
806 }
868a2826 807 }
1c005ff7
RR
808}
809
868a2826
RR
810void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
811{
ec9f7884
VZ
812 m_fontButton->SetFont( *wxITALIC_FONT );
813 m_text->SetFont( *wxITALIC_FONT );
868a2826
RR
814}
815
7bce6aec
RR
816void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
817{
ec9f7884 818 m_gauge->SetValue( m_slider->GetValue() );
7bce6aec
RR
819}
820
b782f2e0 821#if wxUSE_SPINBUTTON
8c3c31d4
VZ
822void MyPanel::OnSpinUp( wxSpinEvent &event )
823{
824 wxString value;
825 value.Printf( _T("Spin control up: current = %d\n"),
826 m_spinbutton->GetValue());
827
828 if ( m_spinbutton->GetValue() > 17 )
829 {
830 value += _T("Preventing the spin button from going above 17.\n");
831
832 event.Veto();
833 }
834
835 m_text->AppendText(value);
836}
837
838void MyPanel::OnSpinDown( wxSpinEvent &event )
839{
840 wxString value;
841 value.Printf( _T("Spin control down: current = %d\n"),
842 m_spinbutton->GetValue());
843
844 if ( m_spinbutton->GetValue() < -17 )
845 {
846 value += _T("Preventing the spin button from going below -17.\n");
847
848 event.Veto();
849 }
850
851 m_text->AppendText(value);
852}
853
e380f72b
RR
854void MyPanel::OnSpinUpdate( wxSpinEvent &event )
855{
ec9f7884 856 wxString value;
f70d5829 857 value.Printf( _T("%d"), event.GetPosition() );
ec9f7884 858 m_spintext->SetValue( value );
6380910c 859
f70d5829 860 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
6380910c
VZ
861 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
862 m_spinbutton->GetValue());
863
864 m_text->AppendText(value);
e380f72b 865}
9726da4f
VZ
866
867void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
868{
869 event.Enable( m_spinbutton->GetValue() > 0 );
870}
871
872void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
873{
874 int max = m_spinbutton->GetValue();
875 wxProgressDialog dialog("Progress dialog example",
876 "An informative message",
877 max, // range
878 this, // parent
8c3c31d4
VZ
879 wxPD_CAN_ABORT |
880 wxPD_APP_MODAL |
881 wxPD_ELAPSED_TIME |
882 wxPD_ESTIMATED_TIME |
883 wxPD_REMAINING_TIME);
2ac1b69a 884
9726da4f
VZ
885
886 bool cont = TRUE;
887 for ( int i = 0; i < max && cont; i++ )
888 {
889 wxSleep(1);
be9abe3f
VZ
890 if ( i == max - 1 )
891 {
892 cont = dialog.Update(i, "That's all, folks!");
893 }
894 else if ( i == max / 2 )
9726da4f
VZ
895 {
896 cont = dialog.Update(i, "Only a half left!");
897 }
898 else
899 {
900 cont = dialog.Update(i);
901 }
902 }
903
904 if ( !cont )
905 {
906 *m_text << "Progress dialog aborted!\n";
907 }
908 else
909 {
910 *m_text << "Countdown from " << max << " finished.\n";
911 }
912}
913
914#endif // wxUSE_SPINBUTTON
e380f72b 915
2cb21a45
VZ
916MyPanel::~MyPanel()
917{
ec9f7884 918 delete m_notebook->GetImageList();
2cb21a45
VZ
919}
920
1c005ff7
RR
921//----------------------------------------------------------------------
922// MyFrame
923//----------------------------------------------------------------------
924
925BEGIN_EVENT_TABLE(MyFrame, wxFrame)
ec9f7884
VZ
926EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
927EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
16f6dfd8 928#if wxUSE_TOOLTIPS
ec9f7884
VZ
929EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
930EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
16f6dfd8 931#endif // wxUSE_TOOLTIPS
ec9f7884
VZ
932EVT_SIZE(MyFrame::OnSize)
933EVT_IDLE(MyFrame::OnIdle)
1c005ff7
RR
934END_EVENT_TABLE()
935
9f3362c4 936MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
ec9f7884 937: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1c005ff7 938{
5fb9fcfc 939 CreateStatusBar(2);
9f3362c4
VZ
940
941 (void)new MyPanel( this, 10, 10, 300, 100 );
1c005ff7
RR
942}
943
944void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
945{
ec9f7884 946 Close(TRUE);
1c005ff7
RR
947}
948
949void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
950{
ec9f7884
VZ
951 wxBeginBusyCursor();
952
953 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
954 dialog.ShowModal();
955
956 wxEndBusyCursor();
1c005ff7 957}
9f3362c4 958
16f6dfd8
VZ
959#if wxUSE_TOOLTIPS
960void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
961{
962 static long s_delay = 5000;
963
964 wxString delay;
f70d5829 965 delay.Printf( _T("%ld"), s_delay);
16f6dfd8
VZ
966
967 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
ec9f7884
VZ
968 "Set tooltip delay",
969 delay,
970 this);
16f6dfd8
VZ
971 if ( !delay )
972 return; // cancelled
973
f70d5829 974 wxSscanf(delay, _T("%ld"), &s_delay);
16f6dfd8
VZ
975
976 wxToolTip::SetDelay(s_delay);
977
f70d5829 978 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
16f6dfd8
VZ
979}
980
981void MyFrame::OnToggleTooltips(wxCommandEvent& event)
982{
983 static bool s_enabled = TRUE;
984
985 s_enabled = !s_enabled;
986
987 wxToolTip::Enable(s_enabled);
988
f70d5829 989 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
16f6dfd8
VZ
990}
991#endif // tooltips
992
5fb9fcfc
VZ
993void MyFrame::OnSize( wxSizeEvent& event )
994{
995 wxString msg;
f70d5829 996 msg.Printf( _("%dx%d"), event.GetSize().x, event.GetSize().y);
5fb9fcfc
VZ
997 SetStatusText(msg, 1);
998
999 event.Skip();
1000}
1001
9f3362c4
VZ
1002void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1003{
1004 // track the window which has the focus in the status bar
1005 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1006 wxWindow *focus = wxWindow::FindFocus();
1007 if ( focus && (focus != s_windowFocus) )
1008 {
1009 s_windowFocus = focus;
1010
1011 wxString msg;
f70d5829 1012 msg.Printf(
9f3362c4 1013#ifdef __WXMSW__
f70d5829
RR
1014 _T("Focus: wxWindow = %p, HWND = %08x"),
1015#else
1016 _T("Focus: wxWindow = %p"),
1017#endif
1018 s_windowFocus
9f3362c4 1019#ifdef __WXMSW__
ec9f7884 1020 , s_windowFocus->GetHWND()
f70d5829 1021#endif
9f3362c4
VZ
1022 );
1023
1024 SetStatusText(msg);
1025 }
341c92a8 1026}