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