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