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