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