]> git.saurik.com Git - wxWidgets.git/blame - samples/controls/controls.cpp
added wxEncodingConverter - scripts for creating convertion tables
[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
ad556aa9 52 #ifdef wxUSE_SPINBTN
0e528b99 53 #undef wxUSE_SPINBTN
ad556aa9 54 #endif
0e528b99 55 #define wxUSE_SPINBTN 0
b782f2e0 56#else
ad556aa9
JS
57 #ifndef wxUSE_SPINBTN
58 #define wxUSE_SPINBTN 1
b782f2e0 59 #endif
9726da4f
VZ
60#endif // __WIN16__
61
62#include "wx/progdlg.h"
63
b782f2e0
VZ
64#if wxUSE_SPINCTRL
65 #include "wx/spinctrl.h"
66#endif // wxUSE_SPINCTRL
67
9d9b7755 68#include "wx/calctrl.h"
75c74ca0 69
1c005ff7
RR
70//----------------------------------------------------------------------
71// class definitions
72//----------------------------------------------------------------------
73
74class MyApp: public wxApp
655822f3 75{
b8653fbf
VZ
76public:
77 bool OnInit();
1c005ff7
RR
78};
79
80class MyPanel: public wxPanel
81{
b8653fbf 82public:
1c005ff7 83 MyPanel(wxFrame *frame, int x, int y, int w, int h);
2cb21a45 84 virtual ~MyPanel();
16f6dfd8 85
1c005ff7
RR
86 void OnSize( wxSizeEvent& event );
87 void OnListBox( wxCommandEvent &event );
5b077d48 88 void OnListBoxDoubleClick( wxCommandEvent &event );
1c005ff7 89 void OnListBoxButtons( wxCommandEvent &event );
47908e25
RR
90 void OnChoice( wxCommandEvent &event );
91 void OnChoiceButtons( wxCommandEvent &event );
92 void OnCombo( wxCommandEvent &event );
93 void OnComboButtons( wxCommandEvent &event );
94 void OnRadio( wxCommandEvent &event );
95 void OnRadioButtons( wxCommandEvent &event );
868a2826 96 void OnSetFont( wxCommandEvent &event );
cb43b372 97 void OnPageChanged( wxNotebookEvent &event );
4d0f3cd6 98 void OnPageChanging( wxNotebookEvent &event );
7bce6aec 99 void OnSliderUpdate( wxCommandEvent &event );
185fa6bf 100 void OnUpdateLabel( wxCommandEvent &event );
0e528b99 101#if wxUSE_SPINBTN
8c3c31d4
VZ
102 void OnSpinUp( wxSpinEvent &event );
103 void OnSpinDown( wxSpinEvent &event );
e380f72b 104 void OnSpinUpdate( wxSpinEvent &event );
9726da4f
VZ
105 void OnUpdateShowProgress( wxUpdateUIEvent& event );
106 void OnShowProgress( wxCommandEvent &event );
0e528b99 107#endif // wxUSE_SPINBTN
16f6dfd8 108
baccb514 109#if wxUSE_SPINCTRL
57160afe 110 void OnSpinCtrl(wxCommandEvent& event);
baccb514
VZ
111#endif // wxUSE_SPINCTRL
112
87a1e308
VZ
113 void OnEnableAll(wxCommandEvent& event);
114 void OnChangeColour(wxCommandEvent& event);
115
0185cd09
VZ
116 void OnCalendar(wxCalendarEvent& event);
117 void OnCalendarWeekDayClick(wxCalendarEvent& event);
9d9b7755
VZ
118 void OnCalendarChange(wxCalendarEvent& event);
119
6c8a980f
VZ
120 wxListBox *m_listbox,
121 *m_listboxSorted;
b56c2246
VZ
122 wxChoice *m_choice,
123 *m_choiceSorted;
e380f72b
RR
124 wxComboBox *m_combo;
125 wxRadioBox *m_radio;
126 wxGauge *m_gauge;
127 wxSlider *m_slider;
128 wxButton *m_fontButton;
85eb36c2
RR
129 wxButton *m_lbSelectNum;
130 wxButton *m_lbSelectThis;
0e528b99 131#if wxUSE_SPINBTN
e380f72b 132 wxSpinButton *m_spinbutton;
9726da4f 133 wxButton *m_btnProgress;
0e528b99 134#endif // wxUSE_SPINBTN
b782f2e0
VZ
135
136#if wxUSE_SPINCTRL
137 wxSpinCtrl *m_spinctrl;
138#endif // wxUSE_SPINCTRL
139
e380f72b 140 wxTextCtrl *m_spintext;
ae0bdb01 141 wxCheckBox *m_checkbox;
16f6dfd8 142
e380f72b 143 wxTextCtrl *m_text;
655822f3
VZ
144 wxNotebook *m_notebook;
145
185fa6bf
VZ
146 wxStaticText *m_label;
147
9d9b7755
VZ
148 wxCalendarCtrl *m_calendar;
149 wxStaticText *m_date;
150
b8653fbf
VZ
151private:
152 DECLARE_EVENT_TABLE()
1c005ff7
RR
153};
154
155class MyFrame: public wxFrame
156{
b8653fbf 157public:
1c005ff7 158 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
655822f3 159
1c005ff7
RR
160 void OnQuit(wxCommandEvent& event);
161 void OnAbout(wxCommandEvent& event);
87a1e308 162
16f6dfd8
VZ
163#if wxUSE_TOOLTIPS
164 void OnSetTooltipDelay(wxCommandEvent& event);
165 void OnToggleTooltips(wxCommandEvent& event);
166#endif // wxUSE_TOOLTIPS
87a1e308
VZ
167
168 void OnEnableAll(wxCommandEvent& event);
169
9f3362c4 170 void OnIdle( wxIdleEvent& event );
5fb9fcfc 171 void OnSize( wxSizeEvent& event );
97206645 172 void OnMove( wxMoveEvent& event );
655822f3 173
f048e32f
VZ
174 MyPanel *GetPanel() const { return m_panel; }
175
b8653fbf 176private:
97206645
VZ
177 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
178 {
179 wxString msg;
180 msg.Printf(_("pos=(%d, %d), size=%dx%d"),
181 pos.x, pos.y, size.x, size.y);
182 SetStatusText(msg, 1);
183 }
184
f048e32f 185 MyPanel *m_panel;
87a1e308 186
b8653fbf 187 DECLARE_EVENT_TABLE()
1c005ff7
RR
188};
189
190//----------------------------------------------------------------------
6c8a980f 191// other
1c005ff7
RR
192//----------------------------------------------------------------------
193
6c8a980f
VZ
194static void SetControlClientData(const char *name,
195 wxControlWithItems *control);
196
d59051dd 197IMPLEMENT_APP(MyApp)
1c005ff7
RR
198
199//----------------------------------------------------------------------
200// MyApp
201//----------------------------------------------------------------------
202
16f6dfd8
VZ
203enum
204{
205 MINIMAL_QUIT = 100,
206 MINIMAL_TEXT,
207 MINIMAL_ABOUT,
208
209 // tooltip menu
210 MINIMAL_SET_TOOLTIP_DELAY = 200,
87a1e308
VZ
211 MINIMAL_ENABLE_TOOLTIPS,
212
213 // panel menu
214 MINIMAL_ENABLE_ALL
16f6dfd8 215};
1c005ff7 216
b8653fbf 217bool MyApp::OnInit()
1c005ff7 218{
e66ad5c6
VZ
219 // parse the cmd line
220 int x = 50,
221 y = 50;
222 if ( argc == 2 )
223 {
224 wxSscanf(argv[1], "%d", &x);
225 wxSscanf(argv[2], "%d", &y);
226 }
227
ec9f7884
VZ
228 // Create the main frame window
229 MyFrame *frame = new MyFrame((wxFrame *) NULL,
230 "Controls wxWindows App",
fb5dc8a2
RR
231 x, y, 540, 430);
232
233 frame->SetSizeHints( 500, 425 );
655822f3 234
ec9f7884
VZ
235 // Give it an icon
236 // The wxICON() macros loads an icon from a resource under Windows
237 // and uses an #included XPM image under GTK+ and Motif
655822f3 238
ec9f7884 239 frame->SetIcon( wxICON(mondrian) );
1c005ff7 240
6adaedf0
JS
241 wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF);
242
6bc8a1c8 243 file_menu->Append(MINIMAL_ABOUT, "&About\tF1");
87a1e308 244 file_menu->AppendSeparator();
6bc8a1c8 245 file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample");
16f6dfd8 246
33caefb3 247 wxMenuBar *menu_bar = new wxMenuBar;
ec9f7884 248 menu_bar->Append(file_menu, "&File");
16f6dfd8
VZ
249
250#if wxUSE_TOOLTIPS
ec9f7884 251 wxMenu *tooltip_menu = new wxMenu;
6bc8a1c8 252 tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
ec9f7884 253 tooltip_menu->AppendSeparator();
185fa6bf 254 tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
ec9f7884
VZ
255 "enable/disable tooltips", TRUE);
256 tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
257 menu_bar->Append(tooltip_menu, "&Tooltips");
16f6dfd8
VZ
258#endif // wxUSE_TOOLTIPS
259
87a1e308
VZ
260 wxMenu *panel_menu = new wxMenu;
261 panel_menu->Append(MINIMAL_ENABLE_ALL, "&Disable all\tCtrl-E",
262 "Enable/disable all panel controls", TRUE);
263 menu_bar->Append(panel_menu, "&Panel");
264
ec9f7884 265 frame->SetMenuBar(menu_bar);
1c005ff7 266
ec9f7884 267 frame->Show(TRUE);
9018abe3 268 frame->SetCursor(wxCursor(wxCURSOR_HAND));
655822f3 269
9d9b7755 270 frame->GetPanel()->m_notebook->SetSelection(6);
f048e32f 271
ec9f7884 272 SetTopWindow(frame);
1c005ff7 273
ec9f7884 274 return TRUE;
1c005ff7
RR
275}
276
277//----------------------------------------------------------------------
278// MyPanel
279//----------------------------------------------------------------------
280
4fabb575 281const int ID_NOTEBOOK = 1000;
1c005ff7 282
4fabb575
JS
283const int ID_LISTBOX = 130;
284const int ID_LISTBOX_SEL_NUM = 131;
285const int ID_LISTBOX_SEL_STR = 132;
286const int ID_LISTBOX_CLEAR = 133;
287const int ID_LISTBOX_APPEND = 134;
288const int ID_LISTBOX_DELETE = 135;
289const int ID_LISTBOX_FONT = 136;
290const int ID_LISTBOX_ENABLE = 137;
6c8a980f 291const int ID_LISTBOX_SORTED = 138;
1c005ff7 292
4fabb575
JS
293const int ID_CHOICE = 120;
294const int ID_CHOICE_SEL_NUM = 121;
295const int ID_CHOICE_SEL_STR = 122;
296const int ID_CHOICE_CLEAR = 123;
297const int ID_CHOICE_APPEND = 124;
298const int ID_CHOICE_DELETE = 125;
299const int ID_CHOICE_FONT = 126;
300const int ID_CHOICE_ENABLE = 127;
b56c2246 301const int ID_CHOICE_SORTED = 128;
53010e52 302
4fabb575
JS
303const int ID_COMBO = 140;
304const int ID_COMBO_SEL_NUM = 141;
305const int ID_COMBO_SEL_STR = 142;
306const int ID_COMBO_CLEAR = 143;
307const int ID_COMBO_APPEND = 144;
308const int ID_COMBO_DELETE = 145;
309const int ID_COMBO_FONT = 146;
310const int ID_COMBO_ENABLE = 147;
53010e52 311
4fabb575
JS
312const int ID_RADIOBOX = 160;
313const int ID_RADIOBOX_SEL_NUM = 161;
314const int ID_RADIOBOX_SEL_STR = 162;
315const int ID_RADIOBOX_FONT = 163;
316const int ID_RADIOBOX_ENABLE = 164;
868a2826 317
f5d29b39
RR
318const int ID_RADIOBUTTON_1 = 166;
319const int ID_RADIOBUTTON_2 = 167;
320
4fabb575 321const int ID_SET_FONT = 170;
47908e25 322
4fabb575
JS
323const int ID_GAUGE = 180;
324const int ID_SLIDER = 181;
58614078 325
4fabb575 326const int ID_SPIN = 182;
9726da4f 327const int ID_BTNPROGRESS = 183;
185fa6bf 328const int ID_BUTTON_LABEL = 184;
baccb514 329const int ID_SPINCTRL = 185;
e380f72b 330
87a1e308
VZ
331const int ID_CHANGE_COLOUR = 200;
332
9d9b7755
VZ
333const int ID_CALENDAR = 210;
334
1c005ff7 335BEGIN_EVENT_TABLE(MyPanel, wxPanel)
ec9f7884 336EVT_SIZE ( MyPanel::OnSize)
4d0f3cd6 337EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
ec9f7884
VZ
338EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
339EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
6c8a980f 340EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
ec9f7884
VZ
341EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
342EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
343EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
344EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
345EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
346EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
347EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
348EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
349EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
b56c2246 350EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
ec9f7884
VZ
351EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
352EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
353EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
354EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
355EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
356EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
357EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
358EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
359EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
360EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
361EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
362EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
363EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
364EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
365EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
366EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
367EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
368EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
369EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
370EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
371EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
372EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
0e528b99 373#if wxUSE_SPINBTN
ec9f7884 374EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
8c3c31d4
VZ
375EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
376EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
9726da4f
VZ
377EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
378EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
0e528b99 379#endif // wxUSE_SPINBTN
baccb514 380#if wxUSE_SPINCTRL
57160afe 381EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
baccb514 382#endif // wxUSE_SPINCTRL
185fa6bf 383EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
87a1e308 384EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
0185cd09
VZ
385
386EVT_CALENDAR (ID_CALENDAR, MyPanel::OnCalendar)
387EVT_CALENDAR_SEL_CHANGED(ID_CALENDAR, MyPanel::OnCalendarChange)
388EVT_CALENDAR_WEEKDAY_CLICKED(ID_CALENDAR, MyPanel::OnCalendarWeekDayClick)
389
1c005ff7
RR
390END_EVENT_TABLE()
391
5fb9fcfc 392MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
0a772322
VZ
393 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
394 m_text(NULL), m_notebook(NULL)
1c005ff7 395{
9d9b7755
VZ
396 wxLayoutConstraints *c;
397
ec9f7884
VZ
398 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
399 // m_text->SetBackgroundColour("wheat");
655822f3 400
57160afe 401 //delete wxLog::SetActiveTarget(new wxLogStderr);
0a772322 402
ec9f7884 403 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
655822f3 404
ec9f7884
VZ
405 wxString choices[] =
406 {
407 "This",
408 "is one of my",
409 "really",
410 "wonderful",
411 "examples."
412 };
655822f3 413
4fabb575 414#ifdef USE_XPM
ec9f7884
VZ
415 // image ids
416 enum
417 {
418 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
419 };
420
421 // fill the image list
422 wxImageList *imagelist = new wxImageList(32, 32);
423
424 imagelist-> Add( wxBitmap( list_xpm ));
425 imagelist-> Add( wxBitmap( choice_xpm ));
426 imagelist-> Add( wxBitmap( combo_xpm ));
427 imagelist-> Add( wxBitmap( text_xpm ));
428 imagelist-> Add( wxBitmap( radio_xpm ));
429 imagelist-> Add( wxBitmap( gauge_xpm ));
430 m_notebook->SetImageList(imagelist);
73c700fd 431#elif defined(__WXMSW__)
ec9f7884
VZ
432 // load images from resources
433 enum
434 {
435 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
436 };
437 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
438
439 static const char *s_iconNames[Image_Max] =
440 {
441 "list", "choice", "combo", "text", "radio", "gauge"
442 };
443
444 for ( size_t n = 0; n < Image_Max; n++ )
445 {
446 wxBitmap bmp(s_iconNames[n]);
447 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
448 {
449 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
450 s_iconNames[n], n);
451 }
452 }
453
454 m_notebook->SetImageList(imagelist);
4fabb575
JS
455#else
456
ec9f7884 457 // No images for now
4fabb575
JS
458#define Image_List -1
459#define Image_Choice -1
460#define Image_Combo -1
461#define Image_Text -1
462#define Image_Radio -1
463#define Image_Gauge -1
464#define Image_Max -1
465
fc54776e 466#endif
2cb21a45 467
6c8a980f
VZ
468 wxPanel *panel = new wxPanel(m_notebook);
469 m_listbox = new wxListBox( panel, ID_LISTBOX,
470 wxPoint(10,10), wxSize(120,70),
354aa1e3 471 5, choices, wxLB_ALWAYS_SB );
6c8a980f
VZ
472 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
473 wxPoint(10,90), wxSize(120,70),
354aa1e3 474 5, choices, wxLB_SORT );
6c8a980f
VZ
475
476 SetControlClientData("listbox", m_listbox);
477 SetControlClientData("listbox", m_listboxSorted);
9838df2c 478
ec9f7884 479 m_listbox->SetCursor(*wxCROSS_CURSOR);
b8653fbf 480#if wxUSE_TOOLTIPS
ec9f7884 481 m_listbox->SetToolTip( "This is a list box" );
16f6dfd8 482#endif // wxUSE_TOOLTIPS
9f3362c4 483
85eb36c2
RR
484 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
485 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
ec9f7884
VZ
486 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
487 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
488 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
6c8a980f 489 wxButton *button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
57160afe
VZ
490
491 button->SetDefault();
492
493 button->SetForegroundColour(*wxBLUE);
494
b8653fbf 495#if wxUSE_TOOLTIPS
ec9f7884 496 button->SetToolTip( "Press here to set italic font" );
16f6dfd8 497#endif // wxUSE_TOOLTIPS
b1170810 498
6c8a980f 499 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,170) );
ec9f7884 500 m_checkbox->SetValue(FALSE);
b8653fbf 501#if wxUSE_TOOLTIPS
ec9f7884 502 m_checkbox->SetToolTip( "Click here to disable the listbox" );
16f6dfd8 503#endif // wxUSE_TOOLTIPS
87a1e308
VZ
504 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, "&Toggle colour",
505 wxPoint(110,170) );
ec9f7884
VZ
506 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
507
508 panel = new wxPanel(m_notebook);
509 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
b56c2246
VZ
510 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
511 5, choices, wxCB_SORT );
6c8a980f 512
6adaedf0 513#ifndef __WXMOTIF__
6c8a980f
VZ
514 SetControlClientData("choice", m_choice);
515 SetControlClientData("choice", m_choiceSorted);
6adaedf0 516#endif
6c8a980f 517
ddc8c2e3 518 m_choice->SetSelection(2);
2b07d713 519 m_choice->SetBackgroundColour( "red" );
ec9f7884
VZ
520 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
521 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
522 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
523 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
524 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
525 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
526 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
1fad4c3e 527
ec9f7884
VZ
528 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
529
530 panel = new wxPanel(m_notebook);
f048e32f
VZ
531 (void)new wxStaticBox( panel, -1, "Box around combobox",
532 wxPoint(5, 5), wxSize(150, 100));
533 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(20,20), wxSize(120,-1), 5, choices, wxCB_READONLY );
ec9f7884
VZ
534 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
535 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
536 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
537 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
538 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
539 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
540 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
541 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
542
ec9f7884
VZ
543 wxString choices2[] =
544 {
17867d61 545 "First", "Second",
0a772322 546 /* "Third",
17867d61
RR
547 "Fourth", "Fifth", "Sixth",
548 "Seventh", "Eighth", "Nineth", "Tenth" */
ec9f7884
VZ
549 };
550
551 panel = new wxPanel(m_notebook);
9018abe3
VZ
552 (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
553 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
f048e32f
VZ
554
555#if wxUSE_TOOLTIPS
556 m_radio->SetToolTip("Ever seen a radiobox?");
557#endif // wxUSE_TOOLTIPS
558
ec9f7884
VZ
559 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
560 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
561 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
562 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
563 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
0544bc0a 564 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP );
ec9f7884
VZ
565 rb->SetValue( FALSE );
566 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
567 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
568
569 panel = new wxPanel(m_notebook);
33961d59 570 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
ec9f7884 571 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
858b5bdd 572 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
33961d59 573 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
9838df2c 574#ifdef __WXMOTIF__
ec9f7884
VZ
575 // No wrapping text in wxStaticText yet :-(
576 (void)new wxStaticText( panel, -1,
577 "Drag the slider!",
33961d59 578 wxPoint(228,30),
e65cc56a 579 wxSize(240, -1)
ec9f7884 580 );
9838df2c 581#else
ec9f7884
VZ
582 (void)new wxStaticText( panel, -1,
583 "In order see the gauge (aka progress bar)\n"
584 "control do something you have to drag the\n"
585 "handle of the slider to the right.\n"
586 "\n"
587 "This is also supposed to demonstrate how\n"
588 "to use static controls.\n",
8c3c31d4
VZ
589 wxPoint(228,25),
590 wxSize(240, 110)
ec9f7884 591 );
9838df2c 592#endif
8c3c31d4
VZ
593 int initialSpinValue = -5;
594 wxString s;
595 s << initialSpinValue;
596 m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) );
0e528b99 597#if wxUSE_SPINBTN
738f9e5a 598 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, -1) );
6380910c 599 m_spinbutton->SetRange(-10,30);
8c3c31d4 600 m_spinbutton->SetValue(initialSpinValue);
9726da4f
VZ
601
602 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog",
738f9e5a 603 wxPoint(300, 160) );
0e528b99 604#endif // wxUSE_SPINBTN
b782f2e0
VZ
605
606#if wxUSE_SPINCTRL
678cd6de 607 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) );
b782f2e0
VZ
608 m_spinctrl->SetRange(10,30);
609 m_spinctrl->SetValue(15);
610#endif // wxUSE_SPINCTRL
611
ec9f7884 612 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
45e41c05
VZ
613
614 panel = new wxPanel(m_notebook);
b782f2e0 615
556921dc 616#ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
45e41c05 617 wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
f048e32f
VZ
618 wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
619 wxPoint(10, 10));
45e41c05
VZ
620
621 bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
622 bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
b782f2e0
VZ
623#endif // !Motif
624
45e41c05
VZ
625 wxBitmap bitmap( 100, 100 );
626 wxMemoryDC dc;
627 dc.SelectObject( bitmap );
628 dc.SetPen(*wxGREEN_PEN);
f048e32f 629 dc.Clear();
45e41c05 630 dc.DrawEllipse(5, 5, 90, 90);
f048e32f 631 dc.DrawText("Bitmap", 30, 40);
45e41c05
VZ
632 dc.SelectObject( wxNullBitmap );
633
185fa6bf 634 (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
f048e32f 635
57160afe 636#if 0
5ef2e633
VZ
637 bitmap = wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
638 wxBITMAP_TYPE_BMP);
639 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
640 (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(300, 120));
57160afe 641#endif
5ef2e633 642
f048e32f
VZ
643 wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
644 bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
645 bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
646 wxBitmapButton *bmpBtn = new wxBitmapButton
647 (
648 panel, -1,
649 bmp1,
650 wxPoint(30, 50)
651 );
652 bmpBtn->SetBitmapSelected(bmp2);
653 bmpBtn->SetBitmapFocus(bmp3);
654
185fa6bf
VZ
655 (void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20));
656 m_label = new wxStaticText(panel, -1, "Label with some long text",
657 wxPoint(250, 60), wxDefaultSize,
658 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
2ac1b69a 659
45e41c05 660 m_notebook->AddPage(panel, "wxBitmapXXX");
dcc71398 661
9d9b7755
VZ
662 // wxCalendarCtrl
663
75c74ca0 664 panel = new wxPanel(m_notebook);
9d9b7755 665 panel->SetAutoLayout( TRUE );
75c74ca0 666
9d9b7755
VZ
667 wxString date;
668 date.Printf("Selected date: %s",
669 wxDateTime::Today().FormatISODate().c_str());
670 m_date = new wxStaticText(panel, -1, date);
671 m_calendar = new wxCalendarCtrl(panel, ID_CALENDAR);
dcc71398 672
9d9b7755
VZ
673 c = new wxLayoutConstraints;
674 c->left.SameAs( panel, wxLeft, 10 );
675 c->centreY.SameAs( m_calendar, wxCentreY );
676 c->height.AsIs();
677 c->width.AsIs();
d7928388 678
9d9b7755 679 m_date->SetConstraints(c);
dcc71398 680
9d9b7755
VZ
681 c = new wxLayoutConstraints;
682 c->left.SameAs( m_date, wxRight, 10 );
683 c->top.SameAs( panel, wxTop, 10 );
684 c->height.AsIs();
685 c->width.AsIs();
dcc71398 686
9d9b7755 687 m_calendar->SetConstraints(c);
dcc71398 688
9d9b7755 689 m_notebook->AddPage(panel, "wxCalendar");
dcc71398 690
9d9b7755 691 // layout constraints
dcc71398 692
9d9b7755
VZ
693 panel = new wxPanel(m_notebook);
694 panel->SetAutoLayout( TRUE );
d7928388 695
9d9b7755
VZ
696 c = new wxLayoutConstraints;
697 c->top.SameAs( panel, wxTop, 10 );
698 c->height.AsIs( );
699 c->left.SameAs( panel, wxLeft, 10 );
700 c->width.PercentOf( panel, wxWidth, 40 );
d7928388 701
9d9b7755
VZ
702 wxButton *pMyButton = new wxButton(panel, -1, "Test Button" );
703 pMyButton->SetConstraints( c );
d7928388 704
9d9b7755
VZ
705 c = new wxLayoutConstraints;
706 c->top.SameAs( panel, wxTop, 10 );
707 c->bottom.SameAs( panel, wxBottom, 10 );
708 c->right.SameAs( panel, wxRight, 10 );
709 c->width.PercentOf( panel, wxWidth, 40 );
185fa6bf 710
9d9b7755
VZ
711 wxButton *pMyButton2 = new wxButton(panel, -1, "Test Button 2" );
712 pMyButton2->SetConstraints( c );
185fa6bf 713
9d9b7755 714 m_notebook->AddPage(panel, "wxLayoutConstraint");
d7928388 715
9d9b7755 716 // sizer
dcc71398 717
9d9b7755
VZ
718 panel = new wxPanel(m_notebook);
719 panel->SetAutoLayout( TRUE );
dcc71398 720
9d9b7755
VZ
721 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
722
723 sizer->Add( new wxButton(panel, -1, "Test Button" ), 3, wxALL, 10 );
724 sizer->Add( 20,20, 1 );
725 sizer->Add( new wxButton(panel, -1, "Test Button 2" ), 3, wxGROW|wxALL, 10 );
726
727 panel->SetSizer( sizer );
728
729 m_notebook->AddPage(panel, "wxSizer");
1c005ff7
RR
730}
731
732void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
733{
ec9f7884
VZ
734 int x = 0;
735 int y = 0;
736 GetClientSize( &x, &y );
655822f3 737
ec9f7884
VZ
738 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
739 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1c005ff7
RR
740}
741
4d0f3cd6
VZ
742void MyPanel::OnPageChanging( wxNotebookEvent &event )
743{
45e41c05
VZ
744 int selOld = event.GetOldSelection();
745 if ( selOld == 2 )
4d0f3cd6 746 {
65045edd
RR
747 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
748 "page change from taking place - if you select\n"
749 "[No] the current page will stay the third one\n",
8c3c31d4
VZ
750 "Control sample",
751 wxICON_QUESTION | wxYES_NO) != wxYES )
752 {
753 event.Veto();
45e41c05 754
8c3c31d4
VZ
755 return;
756 }
4d0f3cd6 757 }
45e41c05
VZ
758
759 *m_text << "Notebook selection is being changed from " << selOld << "\n";
4d0f3cd6
VZ
760}
761
cb43b372
RR
762void MyPanel::OnPageChanged( wxNotebookEvent &event )
763{
ec9f7884 764 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
cb43b372
RR
765}
766
0185cd09
VZ
767void MyPanel::OnCalendar(wxCalendarEvent& event)
768{
769 *m_text << "Selected " << event.GetDate().FormatISODate() <<
770 " from calendar\n";
771}
772
9d9b7755
VZ
773void MyPanel::OnCalendarChange(wxCalendarEvent& event)
774{
775 wxString s;
776 s.Printf("Selected date: %s", event.GetDate().FormatISODate().c_str());
777
778 m_date->SetLabel(s);
779}
780
0185cd09
VZ
781void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
782{
783 *m_text << "Clicked on "
784 << wxDateTime::GetWeekDayName(event.GetWeekDay())
785 << "\n";
786}
787
87a1e308
VZ
788void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
789{
790 static wxColour s_colOld;
791
792 // test panel colour changing and propagation to the subcontrols
793 if ( s_colOld.Ok() )
794 {
795 SetBackgroundColour(s_colOld);
796 s_colOld = wxNullColour;
797
57160afe 798 m_lbSelectThis->SetForegroundColour("yellow");
87a1e308
VZ
799 m_lbSelectThis->SetBackgroundColour("blue");
800 }
801 else
802 {
803 s_colOld = GetBackgroundColour();
804 SetBackgroundColour("green");
805
57160afe 806 m_lbSelectThis->SetForegroundColour("white");
87a1e308
VZ
807 m_lbSelectThis->SetBackgroundColour("red");
808 }
809
810 m_lbSelectThis->Refresh();
811 Refresh();
812}
813
1c005ff7
RR
814void MyPanel::OnListBox( wxCommandEvent &event )
815{
2e0e025e 816// GetParent()->Move(100, 100);
e66ad5c6 817
6c8a980f
VZ
818 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
819 : m_listboxSorted;
820
821 m_text->AppendText( "ListBox event selection string is: '" );
ec9f7884 822 m_text->AppendText( event.GetString() );
6c8a980f
VZ
823 m_text->AppendText( "'\n" );
824 m_text->AppendText( "ListBox control selection string is: '" );
825 m_text->AppendText( listbox->GetStringSelection() );
826 m_text->AppendText( "'\n" );
827
828 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
829 m_text->AppendText( "ListBox event client data string is: '" );
6e47faf1
JS
830 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
831 m_text->AppendText( obj->GetData() );
832 else
833 m_text->AppendText( wxString("none") );
834
6c8a980f
VZ
835 m_text->AppendText( "'\n" );
836 m_text->AppendText( "ListBox control client data string is: '" );
837 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
6e47faf1
JS
838 if (obj)
839 m_text->AppendText( obj->GetData() );
840 else
841 m_text->AppendText( wxString("none") );
6c8a980f 842 m_text->AppendText( "'\n" );
1c005ff7
RR
843}
844
5b077d48
RR
845void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
846{
ec9f7884
VZ
847 m_text->AppendText( "ListBox double click string is: " );
848 m_text->AppendText( event.GetString() );
849 m_text->AppendText( "\n" );
5b077d48
RR
850}
851
47908e25
RR
852void MyPanel::OnListBoxButtons( wxCommandEvent &event )
853{
ec9f7884 854 switch (event.GetId())
d3904ceb 855 {
ec9f7884
VZ
856 case ID_LISTBOX_ENABLE:
857 {
858 m_text->AppendText("Checkbox clicked.\n");
859 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
b8653fbf 860#if wxUSE_TOOLTIPS
ec9f7884
VZ
861 if (event.GetInt())
862 cb->SetToolTip( "Click to enable listbox" );
863 else
864 cb->SetToolTip( "Click to disable listbox" );
16f6dfd8 865#endif // wxUSE_TOOLTIPS
ec9f7884 866 m_listbox->Enable( event.GetInt() == 0 );
57160afe
VZ
867 m_lbSelectThis->Enable( event.GetInt() == 0 );
868 m_lbSelectNum->Enable( event.GetInt() == 0 );
6c8a980f 869 m_listboxSorted->Enable( event.GetInt() == 0 );
ec9f7884
VZ
870 break;
871 }
872 case ID_LISTBOX_SEL_NUM:
873 {
874 m_listbox->SetSelection( 2 );
6c8a980f 875 m_listboxSorted->SetSelection( 2 );
8c3c31d4 876 m_lbSelectThis->WarpPointer( 40, 14 );
ec9f7884
VZ
877 break;
878 }
879 case ID_LISTBOX_SEL_STR:
880 {
881 m_listbox->SetStringSelection( "This" );
6c8a980f 882 m_listboxSorted->SetStringSelection( "This" );
8c3c31d4 883 m_lbSelectNum->WarpPointer( 40, 14 );
ec9f7884
VZ
884 break;
885 }
886 case ID_LISTBOX_CLEAR:
887 {
888 m_listbox->Clear();
6c8a980f 889 m_listboxSorted->Clear();
ec9f7884
VZ
890 break;
891 }
892 case ID_LISTBOX_APPEND:
893 {
894 m_listbox->Append( "Hi!" );
6c8a980f 895 m_listboxSorted->Append( "Hi!" );
ec9f7884
VZ
896 break;
897 }
898 case ID_LISTBOX_DELETE:
899 {
6c8a980f
VZ
900 int idx;
901 idx = m_listbox->GetSelection();
ec9f7884 902 m_listbox->Delete( idx );
6c8a980f
VZ
903 idx = m_listboxSorted->GetSelection();
904 m_listboxSorted->Delete( idx );
ec9f7884
VZ
905 break;
906 }
907 case ID_LISTBOX_FONT:
908 {
909 m_listbox->SetFont( *wxITALIC_FONT );
6c8a980f 910 m_listboxSorted->SetFont( *wxITALIC_FONT );
ec9f7884
VZ
911 m_checkbox->SetFont( *wxITALIC_FONT );
912 break;
913 }
868a2826 914 }
47908e25
RR
915}
916
917void MyPanel::OnChoice( wxCommandEvent &event )
918{
6c8a980f
VZ
919 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
920 : m_choiceSorted;
921
922 m_text->AppendText( "Choice event selection string is: '" );
ec9f7884 923 m_text->AppendText( event.GetString() );
6c8a980f 924 m_text->AppendText( "'\n" );
b56c2246 925 m_text->AppendText( "Choice control selection string is: '" );
6c8a980f
VZ
926 m_text->AppendText( choice->GetStringSelection() );
927 m_text->AppendText( "'\n" );
928
929 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
930 m_text->AppendText( "Choice event client data string is: '" );
6e47faf1
JS
931
932 if (obj)
933 m_text->AppendText( obj->GetData() );
934 else
935 m_text->AppendText( wxString("none") );
936
6c8a980f
VZ
937 m_text->AppendText( "'\n" );
938 m_text->AppendText( "Choice control client data string is: '" );
939 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
6e47faf1
JS
940
941 if (obj)
942 m_text->AppendText( obj->GetData() );
943 else
944 m_text->AppendText( wxString("none") );
6c8a980f 945 m_text->AppendText( "'\n" );
47908e25
RR
946}
947
948void MyPanel::OnChoiceButtons( wxCommandEvent &event )
949{
ec9f7884 950 switch (event.GetId())
47908e25 951 {
ec9f7884
VZ
952 case ID_CHOICE_ENABLE:
953 {
954 m_choice->Enable( event.GetInt() == 0 );
b56c2246 955 m_choiceSorted->Enable( event.GetInt() == 0 );
ec9f7884
VZ
956 break;
957 }
958 case ID_CHOICE_SEL_NUM:
959 {
960 m_choice->SetSelection( 2 );
b56c2246 961 m_choiceSorted->SetSelection( 2 );
ec9f7884
VZ
962 break;
963 }
964 case ID_CHOICE_SEL_STR:
965 {
966 m_choice->SetStringSelection( "This" );
b56c2246 967 m_choiceSorted->SetStringSelection( "This" );
ec9f7884
VZ
968 break;
969 }
970 case ID_CHOICE_CLEAR:
971 {
972 m_choice->Clear();
b56c2246 973 m_choiceSorted->Clear();
ec9f7884
VZ
974 break;
975 }
976 case ID_CHOICE_APPEND:
977 {
978 m_choice->Append( "Hi!" );
b56c2246 979 m_choiceSorted->Append( "Hi!" );
ec9f7884
VZ
980 break;
981 }
982 case ID_CHOICE_DELETE:
983 {
984 int idx = m_choice->GetSelection();
985 m_choice->Delete( idx );
b56c2246
VZ
986 idx = m_choiceSorted->GetSelection();
987 m_choiceSorted->Delete( idx );
ec9f7884
VZ
988 break;
989 }
990 case ID_CHOICE_FONT:
991 {
992 m_choice->SetFont( *wxITALIC_FONT );
b56c2246 993 m_choiceSorted->SetFont( *wxITALIC_FONT );
ec9f7884
VZ
994 break;
995 }
868a2826 996 }
47908e25
RR
997}
998
999void MyPanel::OnCombo( wxCommandEvent &event )
1000{
19da4326 1001 m_text->AppendText( "ComboBox event selection string is: " );
ec9f7884
VZ
1002 m_text->AppendText( event.GetString() );
1003 m_text->AppendText( "\n" );
19da4326
RR
1004 m_text->AppendText( "ComboBox control selection string is: " );
1005 m_text->AppendText( m_combo->GetStringSelection() );
1006 m_text->AppendText( "\n" );
47908e25
RR
1007}
1008
1009void MyPanel::OnComboButtons( wxCommandEvent &event )
1c005ff7 1010{
ec9f7884 1011 switch (event.GetId())
2f6407b9 1012 {
ec9f7884
VZ
1013 case ID_COMBO_ENABLE:
1014 {
1015 m_combo->Enable( event.GetInt() == 0 );
1016 break;
1017 }
1018 case ID_COMBO_SEL_NUM:
1019 {
1020 m_combo->SetSelection( 2 );
1021 break;
1022 }
1023 case ID_COMBO_SEL_STR:
1024 {
1025 m_combo->SetStringSelection( "This" );
1026 break;
1027 }
1028 case ID_COMBO_CLEAR:
1029 {
1030 m_combo->Clear();
1031 break;
1032 }
1033 case ID_COMBO_APPEND:
1034 {
1035 m_combo->Append( "Hi!" );
1036 break;
1037 }
1038 case ID_COMBO_DELETE:
1039 {
1040 int idx = m_combo->GetSelection();
1041 m_combo->Delete( idx );
1042 break;
1043 }
1044 case ID_COMBO_FONT:
1045 {
1046 m_combo->SetFont( *wxITALIC_FONT );
1047 break;
1048 }
868a2826 1049 }
47908e25
RR
1050}
1051
1052void MyPanel::OnRadio( wxCommandEvent &event )
1053{
ec9f7884
VZ
1054 m_text->AppendText( "RadioBox selection string is: " );
1055 m_text->AppendText( event.GetString() );
1056 m_text->AppendText( "\n" );
47908e25
RR
1057}
1058
1059void MyPanel::OnRadioButtons( wxCommandEvent &event )
1060{
ec9f7884 1061 switch (event.GetId())
d3904ceb 1062 {
ec9f7884
VZ
1063 case ID_RADIOBOX_ENABLE:
1064 {
1065 m_radio->Enable( event.GetInt() == 0 );
1066 break;
1067 }
1068 case ID_RADIOBOX_SEL_NUM:
1069 {
1070 m_radio->SetSelection( 2 );
1071 break;
1072 }
1073 case ID_RADIOBOX_SEL_STR:
1074 {
1075 m_radio->SetStringSelection( "This" );
1076 break;
1077 }
1078 case ID_RADIOBOX_FONT:
1079 {
1080 m_radio->SetFont( *wxITALIC_FONT );
1081 break;
1082 }
868a2826 1083 }
1c005ff7
RR
1084}
1085
868a2826
RR
1086void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1087{
ec9f7884
VZ
1088 m_fontButton->SetFont( *wxITALIC_FONT );
1089 m_text->SetFont( *wxITALIC_FONT );
868a2826
RR
1090}
1091
185fa6bf
VZ
1092void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
1093{
1094 static bool s_long = TRUE;
1095
1096 s_long = !s_long;
1097 m_label->SetLabel(s_long ? "very very very long text" : "shorter text");
1098}
1099
7bce6aec
RR
1100void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1101{
ec9f7884 1102 m_gauge->SetValue( m_slider->GetValue() );
7bce6aec
RR
1103}
1104
baccb514
VZ
1105#if wxUSE_SPINCTRL
1106
57160afe 1107void MyPanel::OnSpinCtrl(wxCommandEvent& event)
baccb514
VZ
1108{
1109 wxString s;
57160afe
VZ
1110 s.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1111 m_spinctrl->GetValue(), event.GetInt());
baccb514
VZ
1112 m_text->AppendText(s);
1113}
1114
1115#endif // wxUSE_SPINCTRL
1116
0e528b99 1117#if wxUSE_SPINBTN
8c3c31d4
VZ
1118void MyPanel::OnSpinUp( wxSpinEvent &event )
1119{
1120 wxString value;
1121 value.Printf( _T("Spin control up: current = %d\n"),
1122 m_spinbutton->GetValue());
1123
1124 if ( m_spinbutton->GetValue() > 17 )
1125 {
1126 value += _T("Preventing the spin button from going above 17.\n");
1127
1128 event.Veto();
1129 }
1130
1131 m_text->AppendText(value);
1132}
1133
1134void MyPanel::OnSpinDown( wxSpinEvent &event )
1135{
1136 wxString value;
1137 value.Printf( _T("Spin control down: current = %d\n"),
1138 m_spinbutton->GetValue());
1139
1140 if ( m_spinbutton->GetValue() < -17 )
1141 {
1142 value += _T("Preventing the spin button from going below -17.\n");
1143
1144 event.Veto();
1145 }
1146
1147 m_text->AppendText(value);
1148}
1149
e380f72b
RR
1150void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1151{
ec9f7884 1152 wxString value;
f70d5829 1153 value.Printf( _T("%d"), event.GetPosition() );
ec9f7884 1154 m_spintext->SetValue( value );
6380910c 1155
f70d5829 1156 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
6380910c
VZ
1157 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1158 m_spinbutton->GetValue());
1159
1160 m_text->AppendText(value);
e380f72b 1161}
9726da4f
VZ
1162
1163void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1164{
1165 event.Enable( m_spinbutton->GetValue() > 0 );
1166}
1167
1168void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1169{
1170 int max = m_spinbutton->GetValue();
1171 wxProgressDialog dialog("Progress dialog example",
1172 "An informative message",
1173 max, // range
1174 this, // parent
8c3c31d4
VZ
1175 wxPD_CAN_ABORT |
1176 wxPD_APP_MODAL |
1177 wxPD_ELAPSED_TIME |
1178 wxPD_ESTIMATED_TIME |
1179 wxPD_REMAINING_TIME);
2ac1b69a 1180
9726da4f
VZ
1181
1182 bool cont = TRUE;
1183 for ( int i = 0; i < max && cont; i++ )
1184 {
1185 wxSleep(1);
be9abe3f
VZ
1186 if ( i == max - 1 )
1187 {
1188 cont = dialog.Update(i, "That's all, folks!");
1189 }
1190 else if ( i == max / 2 )
9726da4f
VZ
1191 {
1192 cont = dialog.Update(i, "Only a half left!");
1193 }
1194 else
1195 {
1196 cont = dialog.Update(i);
1197 }
1198 }
1199
1200 if ( !cont )
1201 {
1202 *m_text << "Progress dialog aborted!\n";
1203 }
1204 else
1205 {
1206 *m_text << "Countdown from " << max << " finished.\n";
1207 }
1208}
1209
0e528b99 1210#endif // wxUSE_SPINBTN
e380f72b 1211
2cb21a45
VZ
1212MyPanel::~MyPanel()
1213{
ec9f7884 1214 delete m_notebook->GetImageList();
2cb21a45
VZ
1215}
1216
1c005ff7
RR
1217//----------------------------------------------------------------------
1218// MyFrame
1219//----------------------------------------------------------------------
1220
1221BEGIN_EVENT_TABLE(MyFrame, wxFrame)
87a1e308
VZ
1222 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
1223 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
16f6dfd8 1224#if wxUSE_TOOLTIPS
87a1e308
VZ
1225 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1226 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
16f6dfd8 1227#endif // wxUSE_TOOLTIPS
87a1e308
VZ
1228
1229 EVT_MENU(MINIMAL_ENABLE_ALL, MyFrame::OnEnableAll)
1230
1231 EVT_SIZE(MyFrame::OnSize)
97206645
VZ
1232 EVT_MOVE(MyFrame::OnMove)
1233
87a1e308 1234 EVT_IDLE(MyFrame::OnIdle)
1c005ff7
RR
1235END_EVENT_TABLE()
1236
9f3362c4 1237MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
ec9f7884 1238: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1c005ff7 1239{
5fb9fcfc 1240 CreateStatusBar(2);
9f3362c4 1241
87a1e308 1242 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1c005ff7
RR
1243}
1244
1245void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1246{
ec9f7884 1247 Close(TRUE);
1c005ff7
RR
1248}
1249
1250void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1251{
ec9f7884
VZ
1252 wxBeginBusyCursor();
1253
1254 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
1255 dialog.ShowModal();
1256
1257 wxEndBusyCursor();
1c005ff7 1258}
9f3362c4 1259
16f6dfd8
VZ
1260#if wxUSE_TOOLTIPS
1261void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1262{
1263 static long s_delay = 5000;
1264
1265 wxString delay;
f70d5829 1266 delay.Printf( _T("%ld"), s_delay);
16f6dfd8
VZ
1267
1268 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
ec9f7884
VZ
1269 "Set tooltip delay",
1270 delay,
1271 this);
16f6dfd8
VZ
1272 if ( !delay )
1273 return; // cancelled
1274
f70d5829 1275 wxSscanf(delay, _T("%ld"), &s_delay);
16f6dfd8
VZ
1276
1277 wxToolTip::SetDelay(s_delay);
1278
f70d5829 1279 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
16f6dfd8
VZ
1280}
1281
1282void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1283{
1284 static bool s_enabled = TRUE;
1285
1286 s_enabled = !s_enabled;
1287
1288 wxToolTip::Enable(s_enabled);
1289
f70d5829 1290 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
16f6dfd8
VZ
1291}
1292#endif // tooltips
1293
87a1e308
VZ
1294void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1295{
1296 static bool s_enable = TRUE;
1297
1298 s_enable = !s_enable;
1299 m_panel->Enable(s_enable);
1300}
1301
97206645
VZ
1302void MyFrame::OnMove( wxMoveEvent& event )
1303{
1304 UpdateStatusBar(event.GetPosition(), GetSize());
1305
1306 event.Skip();
1307}
1308
5fb9fcfc
VZ
1309void MyFrame::OnSize( wxSizeEvent& event )
1310{
97206645 1311 UpdateStatusBar(GetPosition(), event.GetSize());
5fb9fcfc
VZ
1312
1313 event.Skip();
1314}
1315
9f3362c4
VZ
1316void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1317{
1318 // track the window which has the focus in the status bar
1319 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1320 wxWindow *focus = wxWindow::FindFocus();
1321 if ( focus && (focus != s_windowFocus) )
1322 {
1323 s_windowFocus = focus;
1324
1325 wxString msg;
f70d5829 1326 msg.Printf(
9f3362c4 1327#ifdef __WXMSW__
f70d5829
RR
1328 _T("Focus: wxWindow = %p, HWND = %08x"),
1329#else
1330 _T("Focus: wxWindow = %p"),
1331#endif
1332 s_windowFocus
9f3362c4 1333#ifdef __WXMSW__
ec9f7884 1334 , s_windowFocus->GetHWND()
f70d5829 1335#endif
9f3362c4
VZ
1336 );
1337
1338 SetStatusText(msg);
1339 }
341c92a8 1340}
6c8a980f
VZ
1341
1342static void SetControlClientData(const char *name,
1343 wxControlWithItems *control)
1344{
1345 size_t count = control->GetCount();
1346 for ( size_t n = 0; n < count; n++ )
1347 {
1348 wxString s;
1349 s.Printf("%s client data for '%s'",
1350 name, control->GetString(n).c_str());
1351
1352 control->SetClientObject(n, new wxStringClientData(s));
1353 }
1354}