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