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