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