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