]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
6bd7b650e7458eff75e6ad5b1112a23e8fde6204
[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 #include "wx/spinbutt.h"
25 #endif
26
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
29
30 #if defined(__WXGTK__) || defined(__WXMOTIF__)
31 #include "mondrian.xpm"
32 #include "icons/choice.xpm"
33 #include "icons/combo.xpm"
34 #include "icons/list.xpm"
35 #include "icons/radio.xpm"
36 #include "icons/text.xpm"
37 #include "icons/gauge.xpm"
38 #endif
39
40 //----------------------------------------------------------------------
41 // class definitions
42 //----------------------------------------------------------------------
43
44 class MyApp: public wxApp
45 {
46 public:
47 bool OnInit(void);
48 };
49
50 class MyPanel: public wxPanel
51 {
52 public:
53
54 MyPanel(wxFrame *frame, int x, int y, int w, int h);
55 virtual ~MyPanel();
56
57 void OnSize( wxSizeEvent& event );
58 void OnListBox( wxCommandEvent &event );
59 void OnListBoxButtons( wxCommandEvent &event );
60 void OnChoice( wxCommandEvent &event );
61 void OnChoiceButtons( wxCommandEvent &event );
62 void OnCombo( wxCommandEvent &event );
63 void OnComboButtons( wxCommandEvent &event );
64 void OnRadio( wxCommandEvent &event );
65 void OnRadioButtons( wxCommandEvent &event );
66 void OnSetFont( wxCommandEvent &event );
67 void OnPageChanged( wxNotebookEvent &event );
68 void OnSliderUpdate( wxCommandEvent &event );
69 void OnSpinUpdate( wxSpinEvent &event );
70
71 wxListBox *m_listbox;
72 wxChoice *m_choice;
73 wxComboBox *m_combo;
74 wxRadioBox *m_radio;
75 wxGauge *m_gauge;
76 wxSlider *m_slider;
77 wxButton *m_fontButton;
78 wxSpinButton *m_spinbutton;
79 wxTextCtrl *m_spintext;
80
81 wxTextCtrl *m_text;
82 wxNotebook *m_notebook;
83
84 DECLARE_EVENT_TABLE()
85 };
86
87 class MyFrame: public wxFrame
88 {
89 public:
90
91 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
92
93 public:
94
95 void OnQuit(wxCommandEvent& event);
96 void OnAbout(wxCommandEvent& event);
97 bool OnClose(void) { return TRUE; }
98
99 DECLARE_EVENT_TABLE()
100 };
101
102 //----------------------------------------------------------------------
103 // main()
104 //----------------------------------------------------------------------
105
106 IMPLEMENT_APP (MyApp)
107
108 //----------------------------------------------------------------------
109 // MyApp
110 //----------------------------------------------------------------------
111
112 const int MINIMAL_QUIT = 100;
113 const int MINIMAL_TEXT = 101;
114 const int MINIMAL_ABOUT = 102;
115
116 bool MyApp::OnInit(void)
117 {
118 // Create the main frame window
119 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Controls wxWindows App", 50, 50, 530, 420 );
120
121 // Give it an icon
122 #ifdef __WXMSW__
123 frame->SetIcon(wxIcon("mondrian"));
124 #else
125 frame->SetIcon(wxIcon( mondrian_xpm ));
126 #endif
127
128 wxMenu *file_menu = new wxMenu;
129
130 file_menu->Append(MINIMAL_ABOUT, "&About");
131 file_menu->Append(MINIMAL_QUIT, "E&xit");
132 wxMenuBar *menu_bar = new wxMenuBar;
133 menu_bar->Append(file_menu, "&File");
134 frame->SetMenuBar(menu_bar);
135
136 frame->Show(TRUE);
137
138 SetTopWindow(frame);
139
140 return TRUE;
141 }
142
143 //----------------------------------------------------------------------
144 // MyPanel
145 //----------------------------------------------------------------------
146
147 const ID_NOTEBOOK = 1000;
148
149 const ID_LISTBOX = 130;
150 const ID_LISTBOX_SEL_NUM = 131;
151 const ID_LISTBOX_SEL_STR = 132;
152 const ID_LISTBOX_CLEAR = 133;
153 const ID_LISTBOX_APPEND = 134;
154 const ID_LISTBOX_DELETE = 135;
155 const ID_LISTBOX_FONT = 136;
156 const ID_LISTBOX_ENABLE = 137;
157
158 const ID_CHOICE = 120;
159 const ID_CHOICE_SEL_NUM = 121;
160 const ID_CHOICE_SEL_STR = 122;
161 const ID_CHOICE_CLEAR = 123;
162 const ID_CHOICE_APPEND = 124;
163 const ID_CHOICE_DELETE = 125;
164 const ID_CHOICE_FONT = 126;
165 const ID_CHOICE_ENABLE = 127;
166
167 const ID_COMBO = 140;
168 const ID_COMBO_SEL_NUM = 141;
169 const ID_COMBO_SEL_STR = 142;
170 const ID_COMBO_CLEAR = 143;
171 const ID_COMBO_APPEND = 144;
172 const ID_COMBO_DELETE = 145;
173 const ID_COMBO_FONT = 146;
174 const ID_COMBO_ENABLE = 147;
175
176 const ID_TEXT = 150;
177
178 const ID_RADIOBOX = 160;
179 const ID_RADIOBOX_SEL_NUM = 161;
180 const ID_RADIOBOX_SEL_STR = 162;
181 const ID_RADIOBOX_FONT = 163;
182 const ID_RADIOBOX_ENABLE = 164;
183
184 const ID_SET_FONT = 170;
185
186 const ID_GAUGE = 180;
187 const ID_SLIDER = 181;
188
189 const ID_SPIN = 182;
190
191
192 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
193 EVT_SIZE ( MyPanel::OnSize)
194 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
195 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
196 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
197 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
198 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
199 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
200 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
201 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
202 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
203 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
204 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
205 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
206 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
207 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
208 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
209 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
210 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
211 EVT_CHOICE (ID_COMBO, MyPanel::OnCombo)
212 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
213 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
214 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
215 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
216 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
217 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
218 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
219 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
220 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
221 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
222 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
223 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
224 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
225 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
226 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
227 END_EVENT_TABLE()
228
229 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
230 wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
231 {
232 SetBackgroundColour("cadet blue");
233
234 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
235 m_text->SetBackgroundColour("wheat");
236
237 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
238
239 wxString choices[] =
240 {
241 "This",
242 "is one of my",
243 "really",
244 "wonderful",
245 "examples.",
246 };
247
248 // image ids and names
249 enum
250 {
251 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
252 };
253
254 // fill the image list
255 #ifdef __WXMSW__
256 const char *aIconNames[] =
257 {
258 "list.xpm", "choice.xpm", "combo.xpm", "text.xpm", "radio.xpm", "gauge.txt"
259 };
260
261 wxASSERT( WXSIZEOF(aIconNames) == Image_Max ); // keep in sync
262
263 wxString strIconDir = "icons/";
264
265 wxImageList *imagelist = new wxImageList(32, 32);
266 for ( size_t n = 0; n < Image_Max; n++ )
267 {
268 imagelist->Add(wxBitmap(strIconDir + aIconNames[n]));
269 }
270 #else
271 wxImageList *imagelist = new wxImageList(32, 32);
272
273 imagelist-> Add( wxBitmap( list_xpm ));
274 imagelist-> Add( wxBitmap( choice_xpm ));
275 imagelist-> Add( wxBitmap( combo_xpm ));
276 imagelist-> Add( wxBitmap( text_xpm ));
277 imagelist-> Add( wxBitmap( radio_xpm ));
278 imagelist-> Add( wxBitmap( gauge_xpm ));
279 #endif
280
281 wxButton *button = (wxButton*)NULL;
282
283 m_notebook->SetImageList(imagelist);
284 m_notebook->SetBackgroundColour("cadet blue");
285
286 wxPanel *panel = (wxPanel*) NULL;
287 panel = new wxPanel(m_notebook);
288 panel->SetBackgroundColour("cadet blue");
289 panel->SetForegroundColour("blue");
290 m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices );
291 m_listbox->SetBackgroundColour("wheat");
292 (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
293 (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
294 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
295 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
296 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
297 button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
298 button->SetForegroundColour( "red" );
299 (void)new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
300 m_notebook->AddPage(panel, "wxList", FALSE, Image_List);
301
302 panel = new wxPanel(m_notebook);
303 panel->SetBackgroundColour("cadet blue");
304 panel->SetForegroundColour("blue");
305 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
306 m_choice->SetBackgroundColour("wheat");
307 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
308 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
309 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
310 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
311 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
312 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
313 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
314 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
315
316 panel = new wxPanel(m_notebook);
317 panel->SetBackgroundColour("cadet blue");
318 panel->SetForegroundColour("blue");
319 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices );
320 m_combo->SetBackgroundColour("wheat");
321 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
322 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
323 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
324 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
325 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
326 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
327 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
328 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
329
330 panel = new wxPanel(m_notebook);
331 panel->SetBackgroundColour("cadet blue");
332 panel->SetForegroundColour("blue");
333 wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(350,28));
334 (*tc) << " More text.";
335 tc->SetBackgroundColour("wheat");
336 tc = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(350,160), wxTE_MULTILINE );
337 (*tc) << " More text.";
338 tc->SetBackgroundColour("wheat");
339 m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
340
341 wxString choices2[] =
342 {
343 "Wonderful",
344 "examples.",
345 };
346
347 panel = new wxPanel(m_notebook);
348 panel->SetBackgroundColour("cadet blue");
349 panel->SetForegroundColour("blue");
350 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_HORIZONTAL );
351 m_radio->SetBackgroundColour("wheat");
352 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_VERTICAL );
353 m_radio->SetBackgroundColour("wheat");
354 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
355 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
356 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(180,130), wxSize(140,30) );
357 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
358 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(160,30) );
359 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
360
361 panel = new wxPanel(m_notebook);
362 panel->SetBackgroundColour("cadet blue");
363 panel->SetForegroundColour("blue");
364 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
365 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155,-1) );
366 m_gauge->SetBackgroundColour("wheat");
367 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
368 m_slider->SetBackgroundColour("wheat");
369 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
370 (void)new wxStaticText( panel, -1,
371 "In order see the gauge (aka progress bar)\n"
372 "control do something you have to drag the\n"
373 "handle of the slider to the right.\n"
374 "\n"
375 "This is also supposed to demonstrate how\n"
376 "to use static controls.\n",
377 wxPoint(208,25) );
378 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
379 m_spintext->SetBackgroundColour("wheat");
380 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
381 m_spinbutton->SetBackgroundColour("wheat");
382 m_spinbutton->SetRange(0,100);
383
384 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
385 }
386
387 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
388 {
389 int x = 0;
390 int y = 0;
391 GetClientSize( &x, &y );
392
393 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
394 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
395 }
396
397 void MyPanel::OnPageChanged( wxNotebookEvent &event )
398 {
399 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
400 }
401
402 void MyPanel::OnListBox( wxCommandEvent &event )
403 {
404 m_text->WriteText( "ListBox selection string is: " );
405 m_text->WriteText( event.GetString() );
406 m_text->WriteText( "\n" );
407 }
408
409 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
410 {
411 switch (event.GetId())
412 {
413 case ID_LISTBOX_ENABLE:
414 {
415 m_listbox->Enable( !((bool)event.GetInt()) );
416 break;
417 }
418 case ID_LISTBOX_SEL_NUM:
419 {
420 m_listbox->SetSelection( 2 );
421 break;
422 }
423 case ID_LISTBOX_SEL_STR:
424 {
425 m_listbox->SetStringSelection( "This" );
426 break;
427 }
428 case ID_LISTBOX_CLEAR:
429 {
430 m_listbox->Clear();
431 break;
432 }
433 case ID_LISTBOX_APPEND:
434 {
435 m_listbox->Append( "Hi!" );
436 break;
437 }
438 case ID_LISTBOX_DELETE:
439 {
440 int idx = m_listbox->GetSelection();
441 m_listbox->Delete( idx );
442 break;
443 }
444 case ID_LISTBOX_FONT:
445 {
446 m_listbox->SetFont( *wxITALIC_FONT );
447 break;
448 }
449 }
450 }
451
452 void MyPanel::OnChoice( wxCommandEvent &event )
453 {
454 m_text->WriteText( "Choice selection string is: " );
455 m_text->WriteText( event.GetString() );
456 m_text->WriteText( "\n" );
457 }
458
459 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
460 {
461 switch (event.GetId())
462 {
463 case ID_CHOICE_ENABLE:
464 {
465 m_choice->Enable( !((bool)event.GetInt()) );
466 break;
467 }
468 case ID_CHOICE_SEL_NUM:
469 {
470 m_choice->SetSelection( 2 );
471 break;
472 }
473 case ID_CHOICE_SEL_STR:
474 {
475 m_choice->SetStringSelection( "This" );
476 break;
477 }
478 case ID_CHOICE_CLEAR:
479 {
480 m_choice->Clear();
481 break;
482 }
483 case ID_CHOICE_APPEND:
484 {
485 m_choice->Append( "Hi!" );
486 break;
487 }
488 case ID_CHOICE_DELETE:
489 {
490 int idx = m_choice->GetSelection();
491 m_choice->Delete( idx );
492 break;
493 }
494 case ID_CHOICE_FONT:
495 {
496 m_choice->SetFont( *wxITALIC_FONT );
497 break;
498 }
499 }
500 }
501
502 void MyPanel::OnCombo( wxCommandEvent &event )
503 {
504 m_text->WriteText( "ComboBox selection string is: " );
505 m_text->WriteText( event.GetString() );
506 m_text->WriteText( "\n" );
507 }
508
509 void MyPanel::OnComboButtons( wxCommandEvent &event )
510 {
511 switch (event.GetId())
512 {
513 case ID_COMBO_ENABLE:
514 {
515 m_combo->Enable( !((bool)event.GetInt()) );
516 break;
517 }
518 case ID_COMBO_SEL_NUM:
519 {
520 m_combo->SetSelection( 2 );
521 break;
522 }
523 case ID_COMBO_SEL_STR:
524 {
525 m_combo->SetStringSelection( "This" );
526 break;
527 }
528 case ID_COMBO_CLEAR:
529 {
530 m_combo->Clear();
531 break;
532 }
533 case ID_COMBO_APPEND:
534 {
535 m_combo->Append( "Hi!" );
536 break;
537 }
538 case ID_COMBO_DELETE:
539 {
540 int idx = m_combo->GetSelection();
541 m_combo->Delete( idx );
542 break;
543 }
544 case ID_COMBO_FONT:
545 {
546 m_combo->SetFont( *wxITALIC_FONT );
547 break;
548 }
549 }
550 }
551
552 void MyPanel::OnRadio( wxCommandEvent &event )
553 {
554 m_text->WriteText( "RadioBox selection string is: " );
555 m_text->WriteText( event.GetString() );
556 m_text->WriteText( "\n" );
557 }
558
559 void MyPanel::OnRadioButtons( wxCommandEvent &event )
560 {
561 switch (event.GetId())
562 {
563 case ID_RADIOBOX_ENABLE:
564 {
565 m_radio->Enable( !((bool)event.GetInt()) );
566 break;
567 }
568 case ID_RADIOBOX_SEL_NUM:
569 {
570 m_radio->SetSelection( 2 );
571 break;
572 }
573 case ID_RADIOBOX_SEL_STR:
574 {
575 m_radio->SetStringSelection( "This" );
576 break;
577 }
578 case ID_RADIOBOX_FONT:
579 {
580 m_radio->SetFont( *wxITALIC_FONT );
581 break;
582 }
583 }
584 }
585
586 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
587 {
588 m_fontButton->SetFont( *wxITALIC_FONT );
589 m_text->SetFont( *wxITALIC_FONT );
590 }
591
592 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
593 {
594 m_gauge->SetValue( m_slider->GetValue() );
595 }
596
597 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
598 {
599 wxString value;
600 value.sprintf( "%d", (int)event.GetPosition() );
601 m_spintext->SetValue( value );
602 }
603
604 MyPanel::~MyPanel()
605 {
606 delete m_notebook->GetImageList();
607 }
608
609 //----------------------------------------------------------------------
610 // MyFrame
611 //----------------------------------------------------------------------
612
613 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
614 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
615 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
616 END_EVENT_TABLE()
617
618 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
619 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
620 {
621 (void)new MyPanel( this, 10, 10, 300, 100 );
622 }
623
624 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
625 {
626 Close(TRUE);
627 }
628
629 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
630 {
631 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
632 dialog.ShowModal();
633 }