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