wxUSE_GAUGE/PROGRESSDLG condition.
[wxWidgets.git] / samples / controls / controls.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: controls.cpp
3 // Purpose: Controls wxWidgets 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 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
23 #include "wx/spinbutt.h"
24 #endif
25 #include "wx/tglbtn.h"
26 #include "wx/bookctrl.h"
27 #include "wx/imaglist.h"
28 #include "wx/artprov.h"
29
30 #if wxUSE_TOOLTIPS
31 #include "wx/tooltip.h"
32 #endif
33
34 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
35 #define USE_XPM
36 #endif
37
38 #ifdef USE_XPM
39 #include "mondrian.xpm"
40 #include "icons/choice.xpm"
41 #include "icons/combo.xpm"
42 #include "icons/list.xpm"
43 #include "icons/radio.xpm"
44 #include "icons/text.xpm"
45 #include "icons/gauge.xpm"
46 #endif
47
48 #ifndef wxUSE_SPINBTN
49 #define wxUSE_SPINBTN 1
50 #endif
51
52 #include "wx/progdlg.h"
53
54 #if wxUSE_SPINCTRL
55 #include "wx/spinctrl.h"
56 #endif // wxUSE_SPINCTRL
57
58 //----------------------------------------------------------------------
59 // class definitions
60 //----------------------------------------------------------------------
61
62 class MyApp: public wxApp
63 {
64 public:
65 bool OnInit();
66 };
67
68 class MyPanel: public wxPanel
69 {
70 public:
71 MyPanel(wxFrame *frame, int x, int y, int w, int h);
72 virtual ~MyPanel();
73
74 void OnSize( wxSizeEvent& event );
75 void OnListBox( wxCommandEvent &event );
76 void OnListBoxDoubleClick( wxCommandEvent &event );
77 void OnListBoxButtons( wxCommandEvent &event );
78 #if wxUSE_CHOICE
79 void OnChoice( wxCommandEvent &event );
80 void OnChoiceButtons( wxCommandEvent &event );
81 #endif
82 void OnCombo( wxCommandEvent &event );
83 void OnComboTextChanged( wxCommandEvent &event );
84 void OnComboTextEnter( wxCommandEvent &event );
85 void OnComboButtons( wxCommandEvent &event );
86 void OnRadio( wxCommandEvent &event );
87 void OnRadioButtons( wxCommandEvent &event );
88 void OnRadioButton1( wxCommandEvent &event );
89 void OnRadioButton2( wxCommandEvent &event );
90 void OnSetFont( wxCommandEvent &event );
91 void OnPageChanged( wxBookCtrlEvent &event );
92 void OnPageChanging( wxBookCtrlEvent &event );
93 void OnSliderUpdate( wxCommandEvent &event );
94 void OnUpdateLabel( wxCommandEvent &event );
95 #if wxUSE_SPINBTN
96 void OnSpinUp( wxSpinEvent &event );
97 void OnSpinDown( wxSpinEvent &event );
98 void OnSpinUpdate( wxSpinEvent &event );
99 #if wxUSE_PROGRESSDLG
100 void OnUpdateShowProgress( wxUpdateUIEvent& event );
101 void OnShowProgress( wxCommandEvent &event );
102 #endif // wxUSE_PROGRESSDLG
103 #endif // wxUSE_SPINBTN
104
105 #if wxUSE_SPINCTRL
106 void OnSpinCtrl(wxSpinEvent& event);
107 void OnSpinCtrlUp(wxSpinEvent& event);
108 void OnSpinCtrlDown(wxSpinEvent& event);
109 void OnSpinCtrlText(wxCommandEvent& event);
110 #endif // wxUSE_SPINCTRL
111
112 void OnEnableAll(wxCommandEvent& event);
113 void OnChangeColour(wxCommandEvent& event);
114 void OnTestButton(wxCommandEvent& event);
115 void OnBmpButton(wxCommandEvent& event);
116
117 void OnSizerCheck (wxCommandEvent &event);
118
119 wxListBox *m_listbox,
120 *m_listboxSorted;
121 #if wxUSE_CHOICE
122 wxChoice *m_choice,
123 *m_choiceSorted;
124 #endif // wxUSE_CHOICE
125
126 wxComboBox *m_combo;
127 wxRadioBox *m_radio;
128 #if wxUSE_GAUGE
129 wxGauge *m_gauge,
130 *m_gaugeVert;
131 #endif // wxUSE_GAUGE
132 #if wxUSE_SLIDER
133 wxSlider *m_slider;
134 #endif // wxUSE_SLIDER
135 wxButton *m_fontButton;
136 wxButton *m_lbSelectNum;
137 wxButton *m_lbSelectThis;
138 #if wxUSE_SPINBTN
139 wxSpinButton *m_spinbutton;
140 #if wxUSE_PROGRESSDLG
141 wxButton *m_btnProgress;
142 #endif // wxUSE_PROGRESSDLG
143 #endif // wxUSE_SPINBTN
144
145 #if wxUSE_SPINCTRL
146 wxSpinCtrl *m_spinctrl;
147 #endif // wxUSE_SPINCTRL
148
149 wxTextCtrl *m_spintext;
150 wxCheckBox *m_checkbox;
151
152 wxTextCtrl *m_text;
153 wxBookCtrl *m_book;
154
155 wxStaticText *m_label;
156
157 wxBoxSizer *m_buttonSizer;
158 wxButton *m_sizerBtn1;
159 wxButton *m_sizerBtn2;
160 wxButton *m_sizerBtn3;
161 wxButton *m_sizerBtn4;
162 wxBoxSizer *m_hsizer;
163 wxButton *m_bigBtn;
164
165 private:
166 wxLog *m_logTargetOld;
167
168 DECLARE_EVENT_TABLE()
169 };
170
171 class MyFrame: public wxFrame
172 {
173 public:
174 MyFrame(const wxChar *title, int x, int y);
175
176 void OnQuit(wxCommandEvent& event);
177 void OnAbout(wxCommandEvent& event);
178 void OnClearLog(wxCommandEvent& event);
179
180 #if wxUSE_TOOLTIPS
181 void OnSetTooltipDelay(wxCommandEvent& event);
182 void OnToggleTooltips(wxCommandEvent& event);
183 #endif // wxUSE_TOOLTIPS
184
185 void OnEnableAll(wxCommandEvent& event);
186
187 void OnIdle( wxIdleEvent& event );
188 void OnIconized( wxIconizeEvent& event );
189 void OnMaximized( wxMaximizeEvent& event );
190 void OnSize( wxSizeEvent& event );
191 void OnMove( wxMoveEvent& event );
192
193 MyPanel *GetPanel() const { return m_panel; }
194
195 private:
196 #if wxUSE_STATUSBAR
197 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
198 {
199 if ( m_frameStatusBar )
200 {
201 wxString msg;
202 wxSize sizeAll = GetSize(),
203 sizeCl = GetClientSize();
204 msg.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
205 pos.x, pos.y,
206 size.x, size.y,
207 sizeAll.x, sizeAll.y,
208 sizeCl.x, sizeCl.y);
209 SetStatusText(msg, 1);
210 }
211 }
212 #endif // wxUSE_STATUSBAR
213
214 MyPanel *m_panel;
215
216 DECLARE_EVENT_TABLE()
217 };
218
219 // a button which intercepts double clicks (for testing...)
220 class MyButton : public wxButton
221 {
222 public:
223 MyButton(wxWindow *parent,
224 wxWindowID id,
225 const wxString& label = wxEmptyString,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize)
228 : wxButton(parent, id, label, pos, size)
229 {
230 }
231
232 void OnDClick(wxMouseEvent& event)
233 {
234 wxLogMessage(_T("MyButton::OnDClick"));
235
236 event.Skip();
237 }
238
239 private:
240 DECLARE_EVENT_TABLE()
241 };
242
243 // a combo which intercepts chars (to test Windows behaviour)
244 class MyComboBox : public wxComboBox
245 {
246 public:
247 MyComboBox(wxWindow *parent, wxWindowID id,
248 const wxString& value = wxEmptyString,
249 const wxPoint& pos = wxDefaultPosition,
250 const wxSize& size = wxDefaultSize,
251 int n = 0, const wxString choices[] = NULL,
252 long style = 0,
253 const wxValidator& validator = wxDefaultValidator,
254 const wxString& name = wxComboBoxNameStr)
255 : wxComboBox(parent, id, value, pos, size, n, choices, style,
256 validator, name) { }
257
258 protected:
259 void OnChar(wxKeyEvent& event);
260 void OnKeyDown(wxKeyEvent& event);
261 void OnKeyUp(wxKeyEvent& event);
262 void OnFocusGot(wxFocusEvent& event)
263 {
264 wxLogMessage(_T("MyComboBox::OnFocusGot"));
265
266 event.Skip();
267 }
268
269 private:
270 DECLARE_EVENT_TABLE()
271 };
272
273 // a radiobox which handles focus set/kill (for testing)
274 class MyRadioBox : public wxRadioBox
275 {
276 public:
277 MyRadioBox(wxWindow *parent,
278 wxWindowID id,
279 const wxString& title = wxEmptyString,
280 const wxPoint& pos = wxDefaultPosition,
281 const wxSize& size = wxDefaultSize,
282 int n = 0, const wxString choices[] = NULL,
283 int majorDim = 1,
284 long style = wxRA_HORIZONTAL,
285 const wxValidator& validator = wxDefaultValidator,
286 const wxString& name = wxRadioBoxNameStr)
287 : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
288 style, validator, name) { SetForegroundColour(*wxRED); }
289
290 protected:
291 void OnFocusGot(wxFocusEvent& event)
292 {
293 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
294
295 event.Skip();
296 }
297
298 void OnFocusLost(wxFocusEvent& event)
299 {
300 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
301
302 event.Skip();
303 }
304
305 private:
306 DECLARE_EVENT_TABLE()
307 };
308
309 //----------------------------------------------------------------------
310 // other
311 //----------------------------------------------------------------------
312
313 static void SetListboxClientData(const wxChar *name, wxListBox *control);
314
315 #if wxUSE_CHOICE
316 static void SetChoiceClientData(const wxChar *name, wxChoice *control);
317 #endif // wxUSE_CHOICE
318
319 IMPLEMENT_APP(MyApp)
320
321 //----------------------------------------------------------------------
322 // MyApp
323 //----------------------------------------------------------------------
324
325 enum
326 {
327 CONTROLS_QUIT = 100,
328 CONTROLS_TEXT,
329 CONTROLS_ABOUT,
330 CONTROLS_CLEAR_LOG,
331
332 // tooltip menu
333 CONTROLS_SET_TOOLTIP_DELAY = 200,
334 CONTROLS_ENABLE_TOOLTIPS,
335
336 // panel menu
337 CONTROLS_ENABLE_ALL
338 };
339
340 bool MyApp::OnInit()
341 {
342 // use standard command line handling:
343 if ( !wxApp::OnInit() )
344 return false;
345
346 // parse the cmd line
347 int x = 50,
348 y = 50;
349 if ( argc == 3 )
350 {
351 wxSscanf(wxString(argv[1]), wxT("%d"), &x);
352 wxSscanf(wxString(argv[2]), wxT("%d"), &y);
353 }
354
355 // Create the main frame window
356 MyFrame *frame = new MyFrame(_T("Controls wxWidgets App"), x, y);
357 frame->Show(true);
358
359 return true;
360 }
361
362 //----------------------------------------------------------------------
363 // MyPanel
364 //----------------------------------------------------------------------
365
366 const int ID_BOOK = 1000;
367
368 const int ID_LISTBOX = 130;
369 const int ID_LISTBOX_SEL_NUM = 131;
370 const int ID_LISTBOX_SEL_STR = 132;
371 const int ID_LISTBOX_CLEAR = 133;
372 const int ID_LISTBOX_APPEND = 134;
373 const int ID_LISTBOX_DELETE = 135;
374 const int ID_LISTBOX_FONT = 136;
375 const int ID_LISTBOX_ENABLE = 137;
376 const int ID_LISTBOX_SORTED = 138;
377
378 const int ID_CHOICE = 120;
379 const int ID_CHOICE_SEL_NUM = 121;
380 const int ID_CHOICE_SEL_STR = 122;
381 const int ID_CHOICE_CLEAR = 123;
382 const int ID_CHOICE_APPEND = 124;
383 const int ID_CHOICE_DELETE = 125;
384 const int ID_CHOICE_FONT = 126;
385 const int ID_CHOICE_ENABLE = 127;
386 const int ID_CHOICE_SORTED = 128;
387
388 const int ID_COMBO = 140;
389 const int ID_COMBO_SEL_NUM = 141;
390 const int ID_COMBO_SEL_STR = 142;
391 const int ID_COMBO_CLEAR = 143;
392 const int ID_COMBO_APPEND = 144;
393 const int ID_COMBO_DELETE = 145;
394 const int ID_COMBO_FONT = 146;
395 const int ID_COMBO_ENABLE = 147;
396
397 const int ID_RADIOBOX = 160;
398 const int ID_RADIOBOX_SEL_NUM = 161;
399 const int ID_RADIOBOX_SEL_STR = 162;
400 const int ID_RADIOBOX_FONT = 163;
401 const int ID_RADIOBOX_ENABLE = 164;
402
403 const int ID_RADIOBUTTON_1 = 166;
404 const int ID_RADIOBUTTON_2 = 167;
405
406 const int ID_SET_FONT = 170;
407
408 #if wxUSE_GAUGE
409 const int ID_GAUGE = 180;
410 #endif // wxUSE_GAUGE
411
412 #if wxUSE_SLIDER
413 const int ID_SLIDER = 181;
414 #endif // wxUSE_SLIDER
415
416 const int ID_SPIN = 182;
417 #if wxUSE_PROGRESSDLG
418 const int ID_BTNPROGRESS = 183;
419 #endif // wxUSE_PROGRESSDLG
420 const int ID_BUTTON_LABEL = 184;
421 const int ID_SPINCTRL = 185;
422
423 const int ID_BUTTON_TEST1 = 190;
424 const int ID_BUTTON_TEST2 = 191;
425 const int ID_BITMAP_BTN = 192;
426
427 const int ID_CHANGE_COLOUR = 200;
428
429 const int ID_SIZER_CHECK1 = 201;
430 const int ID_SIZER_CHECK2 = 202;
431 const int ID_SIZER_CHECK3 = 203;
432 const int ID_SIZER_CHECK4 = 204;
433 const int ID_SIZER_CHECK14 = 205;
434 const int ID_SIZER_CHECKBIG = 206;
435
436 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
437 EVT_SIZE ( MyPanel::OnSize)
438 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK, MyPanel::OnPageChanging)
439 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK, MyPanel::OnPageChanged)
440 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
441 EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
442 EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
443 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
444 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
445 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
446 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
447 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
448 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
449 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
450 #if wxUSE_CHOICE
451 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
452 EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
453 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
454 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
455 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
456 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
457 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
458 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
459 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
460 #endif
461 EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
462 EVT_TEXT (ID_COMBO, MyPanel::OnComboTextChanged)
463 EVT_TEXT_ENTER(ID_COMBO, MyPanel::OnComboTextEnter)
464 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
465 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
466 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
467 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
468 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
469 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
470 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
471 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
472 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
473 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
474 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
475 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
476 EVT_RADIOBUTTON(ID_RADIOBUTTON_1, MyPanel::OnRadioButton1)
477 EVT_RADIOBUTTON(ID_RADIOBUTTON_2, MyPanel::OnRadioButton2)
478 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
479 #if wxUSE_SLIDER
480 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
481 #endif // wxUSE_SLIDER
482 #if wxUSE_SPINBTN
483 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
484 EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
485 EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
486 #if wxUSE_PROGRESSDLG
487 EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
488 EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
489 #endif // wxUSE_PROGRESSDLG
490 #endif // wxUSE_SPINBTN
491 #if wxUSE_SPINCTRL
492 EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
493 EVT_SPIN_UP (ID_SPINCTRL, MyPanel::OnSpinCtrlUp)
494 EVT_SPIN_DOWN (ID_SPINCTRL, MyPanel::OnSpinCtrlDown)
495 EVT_TEXT (ID_SPINCTRL, MyPanel::OnSpinCtrlText)
496 #endif // wxUSE_SPINCTRL
497 #if wxUSE_TOGGLEBTN
498 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
499 #else
500 EVT_CHECKBOX(ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
501 #endif // wxUSE_TOGGLEBTN
502 EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
503 EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
504 EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
505 EVT_BUTTON (ID_BITMAP_BTN, MyPanel::OnBmpButton)
506
507 EVT_CHECKBOX (ID_SIZER_CHECK1, MyPanel::OnSizerCheck)
508 EVT_CHECKBOX (ID_SIZER_CHECK2, MyPanel::OnSizerCheck)
509 EVT_CHECKBOX (ID_SIZER_CHECK3, MyPanel::OnSizerCheck)
510 EVT_CHECKBOX (ID_SIZER_CHECK4, MyPanel::OnSizerCheck)
511 EVT_CHECKBOX (ID_SIZER_CHECK14, MyPanel::OnSizerCheck)
512 EVT_CHECKBOX (ID_SIZER_CHECKBIG, MyPanel::OnSizerCheck)
513
514 END_EVENT_TABLE()
515
516 BEGIN_EVENT_TABLE(MyButton, wxButton)
517 EVT_LEFT_DCLICK(MyButton::OnDClick)
518 END_EVENT_TABLE()
519
520 BEGIN_EVENT_TABLE(MyComboBox, wxComboBox)
521 EVT_CHAR(MyComboBox::OnChar)
522 EVT_KEY_DOWN(MyComboBox::OnKeyDown)
523 EVT_KEY_UP(MyComboBox::OnKeyUp)
524
525 EVT_SET_FOCUS(MyComboBox::OnFocusGot)
526 END_EVENT_TABLE()
527
528 BEGIN_EVENT_TABLE(MyRadioBox, wxRadioBox)
529 EVT_SET_FOCUS(MyRadioBox::OnFocusGot)
530 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost)
531 END_EVENT_TABLE()
532
533 // ============================================================================
534 // implementation
535 // ============================================================================
536
537 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
538 : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
539 {
540 m_listbox = NULL;
541 m_listboxSorted = NULL;
542 #if wxUSE_CHOICE
543 m_choice = NULL;
544 m_choiceSorted = NULL;
545 #endif // wxUSE_CHOICE
546 m_combo = NULL;
547 m_radio = NULL;
548 #if wxUSE_GAUGE
549 m_gauge = NULL;
550 m_gaugeVert = NULL;
551 #endif // wxUSE_GAUGE
552 #if wxUSE_SLIDER
553 m_slider = NULL;
554 #endif // wxUSE_SLIDER
555 m_fontButton = NULL;
556 m_lbSelectNum = NULL;
557 m_lbSelectThis = NULL;
558 #if wxUSE_SPINBTN
559 m_spinbutton = NULL;
560 #if wxUSE_PROGRESSDLG
561 m_btnProgress = NULL;
562 #endif // wxUSE_PROGRESSDLG
563 #endif // wxUSE_SPINBTN
564 #if wxUSE_SPINCTRL
565 m_spinctrl = NULL;
566 #endif // wxUSE_SPINCTRL
567 m_spintext = NULL;
568 m_checkbox = NULL;
569 m_text = NULL;
570 m_book = NULL;
571 m_label = NULL;
572
573 m_text = new wxTextCtrl(this, wxID_ANY, _T("This is the log window.\n"),
574 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
575 m_text->SetBackgroundColour(wxT("wheat"));
576
577 m_logTargetOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
578
579 m_book = new wxBookCtrl(this, ID_BOOK);
580
581 wxString choices[] =
582 {
583 _T("This"),
584 _T("is one of my"),
585 _T("really"),
586 _T("wonderful"),
587 _T("examples.")
588 };
589
590 #ifdef USE_XPM
591 // image ids
592 enum
593 {
594 Image_List,
595 Image_Choice,
596 Image_Combo,
597 Image_Text,
598 Image_Radio,
599 #if wxUSE_GAUGE
600 Image_Gauge,
601 #endif // wxUSE_GAUGE
602 Image_Max
603 };
604
605 // fill the image list
606 wxBitmap bmp(list_xpm);
607
608 wxImageList *imagelist = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
609
610 imagelist-> Add( bmp );
611 imagelist-> Add( wxBitmap( choice_xpm ));
612 imagelist-> Add( wxBitmap( combo_xpm ));
613 imagelist-> Add( wxBitmap( text_xpm ));
614 imagelist-> Add( wxBitmap( radio_xpm ));
615 #if wxUSE_GAUGE
616 imagelist-> Add( wxBitmap( gauge_xpm ));
617 #endif // wxUSE_GAUGE
618 m_book->SetImageList(imagelist);
619 #elif defined(__WXMSW__)
620 // load images from resources
621 enum
622 {
623 Image_List,
624 Image_Choice,
625 Image_Combo,
626 Image_Text,
627 Image_Radio,
628 #if wxUSE_GAUGE
629 Image_Gauge,
630 #endif // wxUSE_GAUGE
631 Image_Max
632 };
633 wxImageList *imagelist = new wxImageList(16, 16, false, Image_Max);
634
635 static const wxChar *s_iconNames[Image_Max] =
636 {
637 _T("list")
638 , _T("choice")
639 , _T("combo")
640 , _T("text")
641 , _T("radio")
642 #if wxUSE_GAUGE
643 , _T("gauge")
644 #endif // wxUSE_GAUGE
645 };
646
647 for ( size_t n = 0; n < Image_Max; n++ )
648 {
649 wxBitmap bmp(s_iconNames[n]);
650 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
651 {
652 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
653 s_iconNames[n], n);
654 }
655 }
656
657 m_book->SetImageList(imagelist);
658 #else
659
660 // No images for now
661 #define Image_List -1
662 #define Image_Choice -1
663 #define Image_Combo -1
664 #define Image_Text -1
665 #define Image_Radio -1
666 #if wxUSE_GAUGE
667 #define Image_Gauge -1
668 #endif // wxUSE_GAUGE
669 #define Image_Max -1
670
671 #endif
672
673 wxPanel *panel = new wxPanel(m_book);
674 m_listbox = new wxListBox( panel, ID_LISTBOX,
675 wxPoint(10,10), wxSize(120,70),
676 5, choices, wxLB_ALWAYS_SB );
677 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
678 wxPoint(10,90), wxSize(120,70),
679 5, choices, wxLB_SORT );
680
681 SetListboxClientData(wxT("listbox"), m_listbox);
682 SetListboxClientData(wxT("listbox"), m_listboxSorted);
683
684 m_listbox->SetCursor(*wxCROSS_CURSOR);
685 #if wxUSE_TOOLTIPS
686 m_listbox->SetToolTip( _T("This is a list box") );
687 #endif // wxUSE_TOOLTIPS
688
689 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
690 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
691 (void)new wxButton( panel, ID_LISTBOX_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
692 (void)new MyButton( panel, ID_LISTBOX_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
693 (void)new wxButton( panel, ID_LISTBOX_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
694 wxButton *button = new MyButton( panel, ID_LISTBOX_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
695
696 button->SetDefault();
697 button->SetForegroundColour(*wxBLUE);
698
699 #if wxUSE_TOOLTIPS
700 button->SetToolTip( _T("Press here to set italic font") );
701 #endif // wxUSE_TOOLTIPS
702
703 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, _T("&Disable"), wxPoint(20,170) );
704 m_checkbox->SetValue(false);
705 button->MoveAfterInTabOrder(m_checkbox);
706 #if wxUSE_TOOLTIPS
707 m_checkbox->SetToolTip( _T("Click here to disable the listbox") );
708 #endif // wxUSE_TOOLTIPS
709 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, _T("&Toggle colour"),
710 wxPoint(110,170) );
711 panel->SetCursor(wxCursor(wxCURSOR_HAND));
712 m_book->AddPage(panel, _T("wxListBox"), true, Image_List);
713
714 #if wxUSE_CHOICE
715 panel = new wxPanel(m_book);
716 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices );
717 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,wxDefaultCoord),
718 5, choices, wxCB_SORT );
719
720 SetChoiceClientData(wxT("choice"), m_choice);
721 SetChoiceClientData(wxT("choice"), m_choiceSorted);
722
723 m_choice->SetSelection(2);
724 m_choice->SetBackgroundColour( wxT("red") );
725 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
726 (void)new wxButton( panel, ID_CHOICE_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
727 (void)new wxButton( panel, ID_CHOICE_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
728 (void)new wxButton( panel, ID_CHOICE_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
729 (void)new wxButton( panel, ID_CHOICE_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
730 (void)new wxButton( panel, ID_CHOICE_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
731 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
732
733 m_book->AddPage(panel, _T("wxChoice"), false, Image_Choice);
734 #endif // wxUSE_CHOICE
735
736 panel = new wxPanel(m_book);
737 (void)new wxStaticBox( panel, wxID_ANY, _T("&Box around combobox"),
738 wxPoint(5, 5), wxSize(150, 100));
739 m_combo = new MyComboBox( panel, ID_COMBO, _T("This"),
740 wxPoint(20,25), wxSize(120, wxDefaultCoord),
741 5, choices,
742 wxCB_READONLY | wxPROCESS_ENTER);
743 m_combo->SetBackgroundColour(*wxBLUE);
744
745 (void)new wxButton( panel, ID_COMBO_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
746 (void)new wxButton( panel, ID_COMBO_SEL_STR, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
747 (void)new wxButton( panel, ID_COMBO_CLEAR, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
748 (void)new wxButton( panel, ID_COMBO_APPEND, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
749 (void)new wxButton( panel, ID_COMBO_DELETE, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
750 (void)new wxButton( panel, ID_COMBO_FONT, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
751 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
752 m_book->AddPage(panel, _T("wxComboBox"), false, Image_Combo);
753
754 wxString choices2[] =
755 {
756 _T("First"), _T("Second"),
757 /* "Third",
758 "Fourth", "Fifth", "Sixth",
759 "Seventh", "Eighth", "Nineth", "Tenth" */
760 };
761
762 panel = new wxPanel(m_book);
763 (void)new MyRadioBox( panel, ID_RADIOBOX, _T("&That"), wxPoint(10,160), wxDefaultSize, WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
764 m_radio = new wxRadioBox( panel, ID_RADIOBOX, _T("T&his"), wxPoint(10,10), wxDefaultSize, WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
765 m_radio->SetForegroundColour(*wxRED);
766
767 #if wxUSE_TOOLTIPS
768 m_combo->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
769 m_radio->SetToolTip(_T("Ever seen a radiobox?"));
770 #endif // wxUSE_TOOLTIPS
771
772 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
773 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
774 m_fontButton = new wxButton( panel, ID_SET_FONT, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
775 (void)new wxButton( panel, ID_RADIOBOX_FONT, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
776 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, _T("&Disable"), wxPoint(340,130), wxDefaultSize );
777 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize, wxRB_GROUP );
778 rb->SetValue( false );
779 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize );
780 m_book->AddPage(panel, _T("wxRadioBox"), false, Image_Radio);
781
782 #if wxUSE_SLIDER && wxUSE_GAUGE
783 panel = new wxPanel(m_book);
784 (void)new wxStaticBox( panel, wxID_ANY, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
785 m_gauge = new wxGauge( panel, wxID_ANY, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
786 m_gauge->SetBackgroundColour(*wxGREEN);
787 m_gauge->SetForegroundColour(*wxRED);
788 m_gaugeVert = new wxGauge( panel, wxID_ANY, 100,
789 wxPoint(195,35), wxSize(30, 90),
790 wxGA_VERTICAL | wxGA_SMOOTH | wxNO_BORDER );
791 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,wxDefaultCoord),
792 wxSL_AUTOTICKS | wxSL_LABELS );
793 m_slider->SetTickFreq(40, 0);
794 #if wxUSE_TOOLTIPS
795 m_slider->SetToolTip(_T("This is a sliding slider"));
796 #endif // wxUSE_TOOLTIPS
797
798 (void)new wxStaticBox( panel, wxID_ANY, _T("&Explanation"),
799 wxPoint(230,10), wxSize(270,130),
800 wxALIGN_CENTER );
801
802 #ifdef __WXMOTIF__
803 // No wrapping text in wxStaticText yet :-(
804 (void)new wxStaticText( panel, wxID_ANY,
805 _T("Drag the slider!"),
806 wxPoint(250,30),
807 wxSize(240, wxDefaultCoord)
808 );
809 #else
810 (void)new wxStaticText( panel, wxID_ANY,
811 _T("In order see the gauge (aka progress bar)\n")
812 _T("control do something you have to drag the\n")
813 _T("handle of the slider to the right.\n")
814 _T("\n")
815 _T("This is also supposed to demonstrate how\n")
816 _T("to use static controls.\n"),
817 wxPoint(250,25),
818 wxSize(240, 110)
819 );
820 #endif
821 int initialSpinValue = -5;
822 wxString s;
823 s << initialSpinValue;
824 m_spintext = new wxTextCtrl( panel, wxID_ANY, s, wxPoint(20,160), wxSize(80,wxDefaultCoord) );
825 #if wxUSE_SPINBTN
826 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, wxDefaultCoord) );
827 m_spinbutton->SetRange(-40,30);
828 m_spinbutton->SetValue(initialSpinValue);
829
830 #if wxUSE_PROGRESSDLG
831 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, _T("&Show progress dialog"),
832 wxPoint(300, 160) );
833 #endif // wxUSE_PROGRESSDLG
834 #endif // wxUSE_SPINBTN
835
836 #if wxUSE_SPINCTRL
837 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord) );
838 m_spinctrl->SetRange(10,30);
839 m_spinctrl->SetValue(15);
840 #endif // wxUSE_SPINCTRL
841
842 m_book->AddPage(panel, _T("wxGauge"), false, Image_Gauge);
843 #endif // wxUSE_SLIDER && wxUSE_GAUGE
844
845 panel = new wxPanel(m_book);
846
847 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
848 wxIcon icon = wxArtProvider::GetIcon(wxART_INFORMATION);
849 (void) new wxStaticBitmap( panel, wxID_ANY, icon, wxPoint(10, 10) );
850
851 // VZ: don't leak memory
852 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
853 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
854 #endif // !Motif
855
856 wxBitmap bitmap( 100, 100 );
857 wxMemoryDC dc;
858 dc.SelectObject( bitmap );
859 dc.SetPen(*wxGREEN_PEN);
860 dc.Clear();
861 dc.DrawEllipse(5, 5, 90, 90);
862 dc.DrawText(_T("Bitmap"), 30, 40);
863 dc.SelectObject( wxNullBitmap );
864
865 (void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20));
866
867 #if defined(__WXMSW__) || defined(__WXMOTIF__)
868 // test for masked bitmap display
869 bitmap = wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP);
870 if (bitmap.Ok())
871 {
872 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
873
874 (void)new wxStaticBitmap /* wxBitmapButton */ (panel, wxID_ANY, bitmap, wxPoint(300, 120));
875 }
876 #endif
877
878 wxBitmap bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION)),
879 bmp2(wxArtProvider::GetBitmap(wxART_WARNING)),
880 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION));
881 wxBitmapButton *bmpBtn = new wxBitmapButton
882 (
883 panel, wxID_ANY,
884 bmp1,
885 wxPoint(30, 70)
886 );
887
888 bmpBtn->SetBitmapSelected(bmp2);
889 bmpBtn->SetBitmapFocus(bmp3);
890
891 #if wxUSE_TOGGLEBTN
892 (void)new wxToggleButton(panel, ID_BUTTON_LABEL,
893 _T("&Toggle label"), wxPoint(250, 20));
894 #else
895 (void)new wxCheckBox(panel, ID_BUTTON_LABEL,
896 _T("&Toggle label"), wxPoint(250, 20));
897 #endif // wxUSE_TOGGLEBTN
898
899 m_label = new wxStaticText(panel, wxID_ANY, _T("Label with some long text"),
900 wxPoint(250, 60), wxDefaultSize,
901 wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
902 m_label->SetForegroundColour( *wxBLUE );
903
904 m_book->AddPage(panel, _T("wxBitmapXXX"));
905
906 // sizer
907
908 panel = new wxPanel(m_book);
909 panel->SetAutoLayout( true );
910
911 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
912
913 wxStaticBoxSizer *csizer =
914 new wxStaticBoxSizer (new wxStaticBox (panel, wxID_ANY, _T("Show Buttons")), wxHORIZONTAL );
915
916 wxCheckBox *check1, *check2, *check3, *check4, *check14, *checkBig;
917 check1 = new wxCheckBox (panel, ID_SIZER_CHECK1, _T("1"));
918 check1->SetValue (true);
919 csizer->Add (check1);
920 check2 = new wxCheckBox (panel, ID_SIZER_CHECK2, _T("2"));
921 check2->SetValue (true);
922 csizer->Add (check2);
923 check3 = new wxCheckBox (panel, ID_SIZER_CHECK3, _T("3"));
924 check3->SetValue (true);
925 csizer->Add (check3);
926 check4 = new wxCheckBox (panel, ID_SIZER_CHECK4, _T("4"));
927 check4->SetValue (true);
928 csizer->Add (check4);
929 check14 = new wxCheckBox (panel, ID_SIZER_CHECK14, _T("1-4"));
930 check14->SetValue (true);
931 csizer->Add (check14);
932 checkBig = new wxCheckBox (panel, ID_SIZER_CHECKBIG, _T("Big"));
933 checkBig->SetValue (true);
934 csizer->Add (checkBig);
935
936 sizer->Add (csizer);
937
938 m_hsizer = new wxBoxSizer( wxHORIZONTAL );
939
940 m_buttonSizer = new wxBoxSizer (wxVERTICAL);
941
942 m_sizerBtn1 = new wxButton(panel, wxID_ANY, _T("Test Button &1 (tab order 1)") );
943 m_buttonSizer->Add( m_sizerBtn1, 0, wxALL, 10 );
944 m_sizerBtn2 = new wxButton(panel, wxID_ANY, _T("Test Button &2 (tab order 3)") );
945 m_buttonSizer->Add( m_sizerBtn2, 0, wxALL, 10 );
946 m_sizerBtn3 = new wxButton(panel, wxID_ANY, _T("Test Button &3 (tab order 2)") );
947 m_buttonSizer->Add( m_sizerBtn3, 0, wxALL, 10 );
948 m_sizerBtn4 = new wxButton(panel, wxID_ANY, _T("Test Button &4 (tab order 4)") );
949 m_buttonSizer->Add( m_sizerBtn4, 0, wxALL, 10 );
950
951 m_sizerBtn3->MoveBeforeInTabOrder(m_sizerBtn2);
952
953 m_hsizer->Add (m_buttonSizer);
954 m_hsizer->Add( 20,20, 1 );
955 m_bigBtn = new wxButton(panel, wxID_ANY, _T("Multiline\nbutton") );
956 m_hsizer->Add( m_bigBtn , 3, wxGROW|wxALL, 10 );
957
958 sizer->Add (m_hsizer, 1, wxGROW);
959
960 panel->SetSizer( sizer );
961
962 m_book->AddPage(panel, _T("wxSizer"));
963 }
964
965 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
966 {
967 int x = 0;
968 int y = 0;
969 GetClientSize( &x, &y );
970
971 if (m_book) m_book->SetSize( 2, 2, x-4, y*2/3-4 );
972 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
973 }
974
975 void MyPanel::OnPageChanging( wxBookCtrlEvent &event )
976 {
977 int selOld = event.GetOldSelection();
978 if ( selOld == 2 )
979 {
980 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
981 _T("page change from taking place - if you select\n")
982 _T("[No] the current page will stay the third one\n"),
983 _T("Control sample"),
984 wxICON_QUESTION | wxYES_NO, this) != wxYES )
985 {
986 event.Veto();
987
988 return;
989 }
990 }
991
992 *m_text << _T("Book selection is being changed from ") << selOld
993 << _T(" to ") << event.GetSelection()
994 << _T(" (current page from book is ")
995 << m_book->GetSelection() << _T(")\n");
996 }
997
998 void MyPanel::OnPageChanged( wxBookCtrlEvent &event )
999 {
1000 *m_text << _T("Book selection is now ") << event.GetSelection()
1001 << _T(" (from book: ") << m_book->GetSelection()
1002 << _T(")\n");
1003 }
1004
1005 void MyPanel::OnTestButton(wxCommandEvent& event)
1006 {
1007 wxLogMessage(_T("Button %c clicked."),
1008 event.GetId() == ID_BUTTON_TEST1 ? _T('1') : _T('2'));
1009 }
1010
1011 void MyPanel::OnBmpButton(wxCommandEvent& WXUNUSED(event))
1012 {
1013 wxLogMessage(_T("Bitmap button clicked."));
1014 }
1015
1016 void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
1017 {
1018 static wxColour s_colOld;
1019
1020 SetThemeEnabled(false);
1021 // test panel colour changing and propagation to the subcontrols
1022 if ( s_colOld.Ok() )
1023 {
1024 SetBackgroundColour(s_colOld);
1025 s_colOld = wxNullColour;
1026
1027 m_lbSelectThis->SetForegroundColour(wxNullColour);
1028 m_lbSelectThis->SetBackgroundColour(wxNullColour);
1029 }
1030 else
1031 {
1032 s_colOld = wxColour(wxT("red"));
1033 SetBackgroundColour(wxT("white"));
1034
1035 m_lbSelectThis->SetForegroundColour(wxT("white"));
1036 m_lbSelectThis->SetBackgroundColour(wxT("red"));
1037 }
1038
1039 m_lbSelectThis->Refresh();
1040 Refresh();
1041 }
1042
1043 void MyPanel::OnListBox( wxCommandEvent &event )
1044 {
1045 // GetParent()->Move(100, 100);
1046
1047 if (event.GetInt() == -1)
1048 {
1049 m_text->AppendText( _T("ListBox has no selections anymore\n") );
1050 return;
1051 }
1052
1053 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
1054 : m_listboxSorted;
1055
1056 m_text->AppendText( _T("ListBox event selection string is: '") );
1057 m_text->AppendText( event.GetString() );
1058 m_text->AppendText( _T("'\n") );
1059 m_text->AppendText( _T("ListBox control selection string is: '") );
1060 m_text->AppendText( listbox->GetStringSelection() );
1061 m_text->AppendText( _T("'\n") );
1062
1063 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1064 m_text->AppendText( _T("ListBox event client data string is: '") );
1065 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
1066 m_text->AppendText( obj->GetData() );
1067 else
1068 m_text->AppendText( wxString(_T("none")) );
1069
1070 m_text->AppendText( _T("'\n") );
1071 m_text->AppendText( _T("ListBox control client data string is: '") );
1072 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
1073 if (obj)
1074 m_text->AppendText( obj->GetData() );
1075 else
1076 m_text->AppendText( wxString(_T("none")) );
1077 m_text->AppendText( _T("'\n") );
1078 }
1079
1080 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
1081 {
1082 m_text->AppendText( _T("ListBox double click string is: ") );
1083 m_text->AppendText( event.GetString() );
1084 m_text->AppendText( _T("\n") );
1085 }
1086
1087 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
1088 {
1089 switch (event.GetId())
1090 {
1091 case ID_LISTBOX_ENABLE:
1092 {
1093 m_text->AppendText(_T("Checkbox clicked.\n"));
1094 #if wxUSE_TOOLTIPS
1095 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
1096 if (event.GetInt())
1097 cb->SetToolTip( _T("Click to enable listbox") );
1098 else
1099 cb->SetToolTip( _T("Click to disable listbox") );
1100 #endif // wxUSE_TOOLTIPS
1101 m_listbox->Enable( event.GetInt() == 0 );
1102 m_lbSelectThis->Enable( event.GetInt() == 0 );
1103 m_lbSelectNum->Enable( event.GetInt() == 0 );
1104 m_listboxSorted->Enable( event.GetInt() == 0 );
1105 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
1106 break;
1107 }
1108 case ID_LISTBOX_SEL_NUM:
1109 {
1110 if (m_listbox->GetCount() > 2)
1111 m_listbox->SetSelection( 2 );
1112 if (m_listboxSorted->GetCount() > 2)
1113 m_listboxSorted->SetSelection( 2 );
1114 m_lbSelectThis->WarpPointer( 40, 14 );
1115 break;
1116 }
1117 case ID_LISTBOX_SEL_STR:
1118 {
1119 if (m_listbox->FindString(_T("This")) != wxNOT_FOUND)
1120 m_listbox->SetStringSelection( _T("This") );
1121 if (m_listboxSorted->FindString(_T("This")) != wxNOT_FOUND)
1122 m_listboxSorted->SetStringSelection( _T("This") );
1123 m_lbSelectNum->WarpPointer( 40, 14 );
1124 break;
1125 }
1126 case ID_LISTBOX_CLEAR:
1127 {
1128 m_listbox->Clear();
1129 m_listboxSorted->Clear();
1130 break;
1131 }
1132 case ID_LISTBOX_APPEND:
1133 {
1134 m_listbox->Append( _T("Hi!") );
1135 m_listboxSorted->Append( _T("Hi!") );
1136 break;
1137 }
1138 case ID_LISTBOX_DELETE:
1139 {
1140 int idx;
1141 idx = m_listbox->GetSelection();
1142 if ( idx != wxNOT_FOUND )
1143 m_listbox->Delete( idx );
1144 idx = m_listboxSorted->GetSelection();
1145 if ( idx != wxNOT_FOUND )
1146 m_listboxSorted->Delete( idx );
1147 break;
1148 }
1149 case ID_LISTBOX_FONT:
1150 {
1151 m_listbox->SetFont( *wxITALIC_FONT );
1152 m_listboxSorted->SetFont( *wxITALIC_FONT );
1153 m_checkbox->SetFont( *wxITALIC_FONT );
1154 break;
1155 }
1156 }
1157 }
1158
1159 #if wxUSE_CHOICE
1160 void MyPanel::OnChoice( wxCommandEvent &event )
1161 {
1162 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
1163 : m_choiceSorted;
1164
1165 m_text->AppendText( _T("Choice event selection string is: '") );
1166 m_text->AppendText( event.GetString() );
1167 m_text->AppendText( _T("'\n") );
1168 m_text->AppendText( _T("Choice control selection string is: '") );
1169 m_text->AppendText( choice->GetStringSelection() );
1170 m_text->AppendText( _T("'\n") );
1171
1172 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1173 m_text->AppendText( _T("Choice event client data string is: '") );
1174
1175 if (obj)
1176 m_text->AppendText( obj->GetData() );
1177 else
1178 m_text->AppendText( wxString(_T("none")) );
1179
1180 m_text->AppendText( _T("'\n") );
1181 m_text->AppendText( _T("Choice control client data string is: '") );
1182 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
1183
1184 if (obj)
1185 m_text->AppendText( obj->GetData() );
1186 else
1187 m_text->AppendText( wxString(_T("none")) );
1188 m_text->AppendText( _T("'\n") );
1189 }
1190
1191 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
1192 {
1193 switch (event.GetId())
1194 {
1195 case ID_CHOICE_ENABLE:
1196 {
1197 m_choice->Enable( event.GetInt() == 0 );
1198 m_choiceSorted->Enable( event.GetInt() == 0 );
1199 break;
1200 }
1201 case ID_CHOICE_SEL_NUM:
1202 {
1203 m_choice->SetSelection( 2 );
1204 m_choiceSorted->SetSelection( 2 );
1205 break;
1206 }
1207 case ID_CHOICE_SEL_STR:
1208 {
1209 m_choice->SetStringSelection( _T("This") );
1210 m_choiceSorted->SetStringSelection( _T("This") );
1211 break;
1212 }
1213 case ID_CHOICE_CLEAR:
1214 {
1215 m_choice->Clear();
1216 m_choiceSorted->Clear();
1217 break;
1218 }
1219 case ID_CHOICE_APPEND:
1220 {
1221 m_choice->Append( _T("Hi!") );
1222 m_choiceSorted->Append( _T("Hi!") );
1223 break;
1224 }
1225 case ID_CHOICE_DELETE:
1226 {
1227 int idx = m_choice->GetSelection();
1228 if ( idx != wxNOT_FOUND )
1229 m_choice->Delete( idx );
1230 idx = m_choiceSorted->GetSelection();
1231 if ( idx != wxNOT_FOUND )
1232 m_choiceSorted->Delete( idx );
1233 break;
1234 }
1235 case ID_CHOICE_FONT:
1236 {
1237 m_choice->SetFont( *wxITALIC_FONT );
1238 m_choiceSorted->SetFont( *wxITALIC_FONT );
1239 break;
1240 }
1241 }
1242 }
1243 #endif // wxUSE_CHOICE
1244
1245 void MyPanel::OnCombo( wxCommandEvent &event )
1246 {
1247 m_text->AppendText( _T("ComboBox event selection string is: ") );
1248 m_text->AppendText( event.GetString() );
1249 m_text->AppendText( _T("\n") );
1250 m_text->AppendText( _T("ComboBox control selection string is: ") );
1251 m_text->AppendText( m_combo->GetStringSelection() );
1252 m_text->AppendText( _T("\n") );
1253 }
1254
1255 void MyPanel::OnComboTextChanged(wxCommandEvent& event)
1256 {
1257 wxString str;
1258 str.Printf( wxT("Text in the combobox changed: now is '%s'."),
1259 event.GetString().c_str() );
1260 wxLogMessage( str.c_str() );
1261 }
1262
1263 void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))
1264 {
1265 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1266 m_combo->GetValue().c_str());
1267 }
1268
1269 void MyPanel::OnComboButtons( wxCommandEvent &event )
1270 {
1271 switch (event.GetId())
1272 {
1273 case ID_COMBO_ENABLE:
1274 {
1275 m_combo->Enable( event.GetInt() == 0 );
1276 break;
1277 }
1278 case ID_COMBO_SEL_NUM:
1279 {
1280 m_combo->SetSelection( 2 );
1281 break;
1282 }
1283 case ID_COMBO_SEL_STR:
1284 {
1285 m_combo->SetStringSelection( _T("This") );
1286 break;
1287 }
1288 case ID_COMBO_CLEAR:
1289 {
1290 m_combo->Clear();
1291 break;
1292 }
1293 case ID_COMBO_APPEND:
1294 {
1295 m_combo->Append( _T("Hi!") );
1296 break;
1297 }
1298 case ID_COMBO_DELETE:
1299 {
1300 int idx = m_combo->GetSelection();
1301 m_combo->Delete( idx );
1302 break;
1303 }
1304 case ID_COMBO_FONT:
1305 {
1306 m_combo->SetFont( *wxITALIC_FONT );
1307 break;
1308 }
1309 }
1310 }
1311
1312 void MyPanel::OnRadio( wxCommandEvent &event )
1313 {
1314 m_text->AppendText( _T("RadioBox selection string is: ") );
1315 m_text->AppendText( event.GetString() );
1316 m_text->AppendText( _T("\n") );
1317 }
1318
1319 void MyPanel::OnRadioButton1( wxCommandEvent & WXUNUSED(event) )
1320 {
1321 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1322 }
1323
1324 void MyPanel::OnRadioButton2( wxCommandEvent & WXUNUSED(event) )
1325 {
1326 m_text->AppendText(_T("Second wxRadioButton selected.\n"));
1327 }
1328
1329 void MyPanel::OnRadioButtons( wxCommandEvent &event )
1330 {
1331 switch (event.GetId())
1332 {
1333 case ID_RADIOBOX_ENABLE:
1334 {
1335 m_radio->Enable( event.GetInt() == 0 );
1336 break;
1337 }
1338 case ID_RADIOBOX_SEL_NUM:
1339 {
1340 m_radio->SetSelection( 2 );
1341 break;
1342 }
1343 case ID_RADIOBOX_SEL_STR:
1344 {
1345 m_radio->SetStringSelection( _T("This") );
1346 break;
1347 }
1348 case ID_RADIOBOX_FONT:
1349 {
1350 m_radio->SetForegroundColour(*wxGREEN);
1351
1352 m_radio->SetFont( *wxITALIC_FONT );
1353 break;
1354 }
1355 }
1356 }
1357
1358 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1359 {
1360 m_fontButton->SetFont( *wxITALIC_FONT );
1361 m_text->SetFont( *wxITALIC_FONT );
1362 }
1363
1364 void MyPanel::OnUpdateLabel( wxCommandEvent &event )
1365 {
1366 m_label->SetLabel(event.GetInt() ? _T("Very very very very very long text.")
1367 : _T("Shorter text."));
1368 }
1369
1370 #if wxUSE_SLIDER
1371
1372 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1373 {
1374 #if wxUSE_GAUGE
1375 m_gauge->SetValue( m_slider->GetValue() );
1376 m_gaugeVert->SetValue( m_slider->GetValue() / 2 );
1377 #endif // wxUSE_GAUGE
1378 }
1379
1380 #endif // wxUSE_SLIDER
1381
1382 #if wxUSE_SPINCTRL
1383
1384 void MyPanel::OnSpinCtrlText(wxCommandEvent& event)
1385 {
1386 if ( m_spinctrl )
1387 {
1388 wxString s;
1389 s.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1390 m_spinctrl->GetValue(), event.GetString().c_str() );
1391 m_text->AppendText(s);
1392 }
1393 }
1394
1395 void MyPanel::OnSpinCtrl(wxSpinEvent& event)
1396 {
1397 if ( m_spinctrl )
1398 {
1399 wxString s;
1400 s.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1401 m_spinctrl->GetValue(), event.GetInt() );
1402 m_text->AppendText(s);
1403 }
1404 }
1405
1406 void MyPanel::OnSpinCtrlUp(wxSpinEvent& event)
1407 {
1408 if ( m_spinctrl )
1409 {
1410 m_text->AppendText( wxString::Format(
1411 _T("Spin up: %d (from event: %ld)\n"),
1412 m_spinctrl->GetValue(), event.GetInt() ) );
1413 }
1414 }
1415
1416 void MyPanel::OnSpinCtrlDown(wxSpinEvent& event)
1417 {
1418 if ( m_spinctrl )
1419 {
1420 m_text->AppendText( wxString::Format(
1421 _T("Spin down: %d (from event: %ld)\n"),
1422 m_spinctrl->GetValue(), event.GetInt() ) );
1423 }
1424 }
1425
1426 #endif // wxUSE_SPINCTRL
1427
1428 #if wxUSE_SPINBTN
1429 void MyPanel::OnSpinUp( wxSpinEvent &event )
1430 {
1431 wxString value;
1432 value.Printf( _T("Spin control up: current = %d\n"),
1433 m_spinbutton->GetValue());
1434
1435 if ( event.GetPosition() > 17 )
1436 {
1437 value += _T("Preventing the spin button from going above 17.\n");
1438
1439 event.Veto();
1440 }
1441
1442 m_text->AppendText(value);
1443 }
1444
1445 void MyPanel::OnSpinDown( wxSpinEvent &event )
1446 {
1447 wxString value;
1448 value.Printf( _T("Spin control down: current = %d\n"),
1449 m_spinbutton->GetValue());
1450
1451 if ( event.GetPosition() < -17 )
1452 {
1453 value += _T("Preventing the spin button from going below -17.\n");
1454
1455 event.Veto();
1456 }
1457
1458 m_text->AppendText(value);
1459 }
1460
1461 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1462 {
1463 wxString value;
1464 value.Printf( _T("%d"), event.GetPosition() );
1465 m_spintext->SetValue( value );
1466
1467 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1468 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1469 m_spinbutton->GetValue());
1470
1471 m_text->AppendText(value);
1472 }
1473
1474 #if wxUSE_PROGRESSDLG
1475
1476 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1477 {
1478 event.Enable( m_spinbutton->GetValue() > 0 );
1479 }
1480
1481 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1482 {
1483 int max = m_spinbutton->GetValue();
1484
1485 if ( max <= 0 )
1486 {
1487 wxLogError(_T("You must set positive range!"));
1488 return;
1489 }
1490
1491 wxProgressDialog dialog(_T("Progress dialog example"),
1492 _T("An informative message"),
1493 max, // range
1494 this, // parent
1495 wxPD_CAN_ABORT |
1496 wxPD_AUTO_HIDE |
1497 wxPD_APP_MODAL |
1498 wxPD_ELAPSED_TIME |
1499 wxPD_ESTIMATED_TIME |
1500 wxPD_REMAINING_TIME);
1501
1502
1503 bool cont = true;
1504 for ( int i = 0; i <= max && cont; i++ )
1505 {
1506 wxSleep(1);
1507 if ( i == max )
1508 {
1509 cont = dialog.Update(i, _T("That's all, folks!"));
1510 }
1511 else if ( i == max / 2 )
1512 {
1513 cont = dialog.Update(i, _T("Only a half left (very long message)!"));
1514 }
1515 else
1516 {
1517 cont = dialog.Update(i);
1518 }
1519 }
1520
1521 if ( !cont )
1522 {
1523 *m_text << _T("Progress dialog aborted!\n");
1524 }
1525 else
1526 {
1527 *m_text << _T("Countdown from ") << max << _T(" finished.\n");
1528 }
1529 }
1530
1531 #endif // wxUSE_PROGRESSDLG
1532 #endif // wxUSE_SPINBTN
1533
1534 void MyPanel::OnSizerCheck( wxCommandEvent &event)
1535 {
1536 switch (event.GetId ()) {
1537 case ID_SIZER_CHECK1:
1538 m_buttonSizer->Show (m_sizerBtn1, event.IsChecked ());
1539 m_buttonSizer->Layout ();
1540 break;
1541 case ID_SIZER_CHECK2:
1542 m_buttonSizer->Show (m_sizerBtn2, event.IsChecked ());
1543 m_buttonSizer->Layout ();
1544 break;
1545 case ID_SIZER_CHECK3:
1546 m_buttonSizer->Show (m_sizerBtn3, event.IsChecked ());
1547 m_buttonSizer->Layout ();
1548 break;
1549 case ID_SIZER_CHECK4:
1550 m_buttonSizer->Show (m_sizerBtn4, event.IsChecked ());
1551 m_buttonSizer->Layout ();
1552 break;
1553 case ID_SIZER_CHECK14:
1554 m_hsizer->Show (m_buttonSizer, event.IsChecked ());
1555 m_hsizer->Layout ();
1556 break;
1557 case ID_SIZER_CHECKBIG:
1558 m_hsizer->Show (m_bigBtn, event.IsChecked ());
1559 m_hsizer->Layout ();
1560 break;
1561 }
1562
1563 }
1564
1565 MyPanel::~MyPanel()
1566 {
1567 //wxLog::RemoveTraceMask(_T("focus"));
1568 delete wxLog::SetActiveTarget(m_logTargetOld);
1569
1570 delete m_book->GetImageList();
1571 }
1572
1573 //----------------------------------------------------------------------
1574 // MyFrame
1575 //----------------------------------------------------------------------
1576
1577 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1578 EVT_MENU(CONTROLS_QUIT, MyFrame::OnQuit)
1579 EVT_MENU(CONTROLS_ABOUT, MyFrame::OnAbout)
1580 EVT_MENU(CONTROLS_CLEAR_LOG, MyFrame::OnClearLog)
1581 #if wxUSE_TOOLTIPS
1582 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1583 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
1584 #endif // wxUSE_TOOLTIPS
1585
1586 EVT_MENU(CONTROLS_ENABLE_ALL, MyFrame::OnEnableAll)
1587
1588 EVT_ICONIZE(MyFrame::OnIconized)
1589 EVT_MAXIMIZE(MyFrame::OnMaximized)
1590 EVT_SIZE(MyFrame::OnSize)
1591 EVT_MOVE(MyFrame::OnMove)
1592
1593 EVT_IDLE(MyFrame::OnIdle)
1594 END_EVENT_TABLE()
1595
1596 MyFrame::MyFrame(const wxChar *title, int x, int y)
1597 : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(500, 430))
1598 {
1599 // Give it an icon
1600 // The wxICON() macros loads an icon from a resource under Windows
1601 // and uses an #included XPM image under GTK+ and Motif
1602
1603 #ifdef USE_XPM
1604 SetIcon( wxICON(mondrian) );
1605 #endif
1606
1607 wxMenu *file_menu = new wxMenu;
1608
1609 file_menu->Append(CONTROLS_CLEAR_LOG, _T("&Clear log\tCtrl-L"));
1610 file_menu->AppendSeparator();
1611 file_menu->Append(CONTROLS_ABOUT, _T("&About\tF1"));
1612 file_menu->AppendSeparator();
1613 file_menu->Append(CONTROLS_QUIT, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1614
1615 wxMenuBar *menu_bar = new wxMenuBar;
1616 menu_bar->Append(file_menu, _T("&File"));
1617
1618 #if wxUSE_TOOLTIPS
1619 wxMenu *tooltip_menu = new wxMenu;
1620 tooltip_menu->Append(CONTROLS_SET_TOOLTIP_DELAY, _T("Set &delay\tCtrl-D"));
1621 tooltip_menu->AppendSeparator();
1622 tooltip_menu->Append(CONTROLS_ENABLE_TOOLTIPS, _T("&Toggle tooltips\tCtrl-T"),
1623 _T("enable/disable tooltips"), true);
1624 tooltip_menu->Check(CONTROLS_ENABLE_TOOLTIPS, true);
1625 menu_bar->Append(tooltip_menu, _T("&Tooltips"));
1626 #endif // wxUSE_TOOLTIPS
1627
1628 wxMenu *panel_menu = new wxMenu;
1629 panel_menu->Append(CONTROLS_ENABLE_ALL, _T("&Disable all\tCtrl-E"),
1630 _T("Enable/disable all panel controls"), true);
1631 menu_bar->Append(panel_menu, _T("&Panel"));
1632
1633 SetMenuBar(menu_bar);
1634
1635 #if wxUSE_STATUSBAR
1636 CreateStatusBar(2);
1637 #endif // wxUSE_STATUSBAR
1638
1639 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1640
1641 SetSizeHints( 500, 425 );
1642 }
1643
1644 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1645 {
1646 Close(true);
1647 }
1648
1649 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1650 {
1651 wxBusyCursor bc;
1652
1653 wxMessageDialog dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK );
1654 dialog.ShowModal();
1655 }
1656
1657 void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
1658 {
1659 m_panel->m_text->Clear();
1660 }
1661
1662 #if wxUSE_TOOLTIPS
1663 void MyFrame::OnSetTooltipDelay(wxCommandEvent& WXUNUSED(event))
1664 {
1665 static long s_delay = 5000;
1666
1667 wxString delay;
1668 delay.Printf( _T("%ld"), s_delay);
1669
1670 delay = wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1671 _T("Set tooltip delay"),
1672 delay,
1673 this);
1674 if ( !delay )
1675 return; // cancelled
1676
1677 wxSscanf(delay, _T("%ld"), &s_delay);
1678
1679 wxToolTip::SetDelay(s_delay);
1680
1681 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1682 }
1683
1684 void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
1685 {
1686 static bool s_enabled = true;
1687
1688 s_enabled = !s_enabled;
1689
1690 wxToolTip::Enable(s_enabled);
1691
1692 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1693 }
1694 #endif // tooltips
1695
1696 void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1697 {
1698 static bool s_enable = true;
1699
1700 s_enable = !s_enable;
1701 m_panel->Enable(s_enable);
1702 }
1703
1704 void MyFrame::OnMove( wxMoveEvent& event )
1705 {
1706 #if wxUSE_STATUSBAR
1707 UpdateStatusBar(event.GetPosition(), GetSize());
1708 #endif // wxUSE_STATUSBAR
1709
1710 event.Skip();
1711 }
1712
1713 void MyFrame::OnIconized( wxIconizeEvent& event )
1714 {
1715 wxLogMessage(_T("Frame %s"), event.Iconized() ? _T("iconized")
1716 : _T("restored"));
1717 event.Skip();
1718 }
1719
1720 void MyFrame::OnMaximized( wxMaximizeEvent& WXUNUSED(event) )
1721 {
1722 wxLogMessage(_T("Frame maximized"));
1723 }
1724
1725 void MyFrame::OnSize( wxSizeEvent& event )
1726 {
1727 #if wxUSE_STATUSBAR
1728 UpdateStatusBar(GetPosition(), event.GetSize());
1729 #endif // wxUSE_STATUSBAR
1730
1731 event.Skip();
1732 }
1733
1734 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1735 {
1736 // track the window which has the focus in the status bar
1737 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1738 wxWindow *focus = wxWindow::FindFocus();
1739 if ( focus && (focus != s_windowFocus) )
1740 {
1741 s_windowFocus = focus;
1742
1743 wxString msg;
1744 msg.Printf(
1745 #ifdef __WXMSW__
1746 _T("Focus: %s, HWND = %08x"),
1747 #else
1748 _T("Focus: %s"),
1749 #endif
1750 s_windowFocus->GetClassInfo()->GetClassName()
1751 #ifdef __WXMSW__
1752 , (unsigned int) s_windowFocus->GetHWND()
1753 #endif
1754 );
1755
1756 #if wxUSE_STATUSBAR
1757 SetStatusText(msg);
1758 #endif // wxUSE_STATUSBAR
1759 }
1760 }
1761
1762 void MyComboBox::OnChar(wxKeyEvent& event)
1763 {
1764 wxLogMessage(_T("MyComboBox::OnChar"));
1765
1766 if ( event.GetKeyCode() == 'w' )
1767 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1768 else
1769 event.Skip();
1770 }
1771
1772 void MyComboBox::OnKeyDown(wxKeyEvent& event)
1773 {
1774 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1775
1776 if ( event.GetKeyCode() == 'w' )
1777 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1778 else
1779 event.Skip();
1780 }
1781
1782 void MyComboBox::OnKeyUp(wxKeyEvent& event)
1783 {
1784 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1785
1786 event.Skip();
1787 }
1788
1789 static void SetListboxClientData(const wxChar *name, wxListBox *control)
1790 {
1791 size_t count = control->GetCount();
1792 for ( size_t n = 0; n < count; n++ )
1793 {
1794 wxString s;
1795 s.Printf(wxT("%s client data for '%s'"),
1796 name, control->GetString(n).c_str());
1797
1798 control->SetClientObject(n, new wxStringClientData(s));
1799 }
1800 }
1801
1802 #if wxUSE_CHOICE
1803
1804 static void SetChoiceClientData(const wxChar *name, wxChoice *control)
1805 {
1806 size_t count = control->GetCount();
1807 for ( size_t n = 0; n < count; n++ )
1808 {
1809 wxString s;
1810 s.Printf(wxT("%s client data for '%s'"),
1811 name, control->GetString(n).c_str());
1812
1813 control->SetClientObject(n, new wxStringClientData(s));
1814 }
1815 }
1816
1817 #endif // wxUSE_CHOICE