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