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