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