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