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