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