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