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