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