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