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