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