]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
d0f9bbb2d5b720ed5e3efb1726f14b4bebf0f881
[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 #ifdef __WXGTK__
33 #include "wx/tooltip.h"
34 #endif
35
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 OnListBoxDoubleClick( 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
213 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
214 EVT_SIZE ( MyPanel::OnSize)
215 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
216 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
217 EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
218 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
219 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
220 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
221 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
222 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
223 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
224 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
225 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
226 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
227 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
228 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
229 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
230 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
231 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
232 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
233 EVT_CHOICE (ID_COMBO, MyPanel::OnCombo)
234 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
235 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
236 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
237 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
238 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
239 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
240 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
241 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
242 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
243 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
244 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
245 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
246 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
247 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
248 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
249 EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
250 EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
251 END_EVENT_TABLE()
252
253 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
254 wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
255 {
256 // SetBackgroundColour("cadet blue");
257
258 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
259 // m_text->SetBackgroundColour("wheat");
260
261 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
262
263 wxString choices[] =
264 {
265 "This",
266 "is one of my",
267 "really",
268 "wonderful",
269 "examples."
270 };
271
272 #ifdef USE_XPM
273 // image ids
274 enum
275 {
276 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
277 };
278
279 // fill the image list
280 wxImageList *imagelist = new wxImageList(32, 32);
281
282 imagelist-> Add( wxBitmap( list_xpm ));
283 imagelist-> Add( wxBitmap( choice_xpm ));
284 imagelist-> Add( wxBitmap( combo_xpm ));
285 imagelist-> Add( wxBitmap( text_xpm ));
286 imagelist-> Add( wxBitmap( radio_xpm ));
287 imagelist-> Add( wxBitmap( gauge_xpm ));
288 m_notebook->SetImageList(imagelist);
289 #elif defined(__WXMSW__)
290 // load images from resources
291 enum
292 {
293 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
294 };
295 wxImageList *imagelist = new wxImageList(32, 32, FALSE, Image_Max);
296
297 static const char *s_iconNames[Image_Max] =
298 {
299 "list", "choice", "combo", "text", "radio", "gauge"
300 };
301
302 for ( size_t n = 0; n < Image_Max; n++ )
303 {
304 wxBitmap bmp(s_iconNames[n]);
305 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
306 {
307 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
308 s_iconNames[n], n);
309 }
310 }
311
312 m_notebook->SetImageList(imagelist);
313 #else
314
315 // No images for now
316 #define Image_List -1
317 #define Image_Choice -1
318 #define Image_Combo -1
319 #define Image_Text -1
320 #define Image_Radio -1
321 #define Image_Gauge -1
322 #define Image_Max -1
323
324 #endif
325
326 wxButton *button = (wxButton*)NULL;
327
328 // m_notebook->SetBackgroundColour("cadet blue");
329
330 wxPanel *panel = (wxPanel*) NULL;
331
332 panel = new wxPanel(m_notebook);
333 // panel->SetBackgroundColour("cadet blue");
334 // panel->SetForegroundColour("blue");
335 m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices );
336 // m_listbox->SetBackgroundColour("wheat");
337 (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
338 (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
339 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
340 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
341 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
342 button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
343
344 #ifdef __WXGTK__
345 wxToolTip::Add( button, "Press here to set italic font" );
346 #endif
347 // button->SetForegroundColour( "red" );
348 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
349 m_checkbox->SetValue(FALSE);
350 m_notebook->AddPage(panel, "wxList", TRUE, Image_List);
351
352 panel = new wxPanel(m_notebook);
353 // panel->SetBackgroundColour("cadet blue");
354 // panel->SetForegroundColour("blue");
355 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
356 // m_choice->SetBackgroundColour("wheat");
357 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
358 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
359 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
360 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
361 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
362 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
363 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
364 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
365
366 panel = new wxPanel(m_notebook);
367 // panel->SetBackgroundColour("cadet blue");
368 // panel->SetForegroundColour("blue");
369 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices );
370 // m_combo->SetBackgroundColour("wheat");
371 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
372 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
373 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
374 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
375 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
376 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
377 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
378 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
379
380 panel = new wxPanel(m_notebook);
381 // panel->SetBackgroundColour("cadet blue");
382 // panel->SetForegroundColour("blue");
383 wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
384 (*tc) << " More text.";
385 // tc->SetBackgroundColour("wheat");
386 m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
387 (*m_multitext) << " More text.";
388 m_multitext->SetBackgroundColour("wheat");
389 (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
390 (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
391 (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) );
392 m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
393
394 wxString choices2[] =
395 {
396 "Wonderful",
397 "examples.",
398 };
399
400 panel = new wxPanel(m_notebook);
401 // panel->SetBackgroundColour("cadet blue");
402 // panel->SetForegroundColour("blue");
403 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS );
404 // m_radio->SetBackgroundColour("wheat");
405 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS );
406 // m_radio->SetBackgroundColour("wheat");
407 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
408 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
409 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
410 // m_fontButton->SetForegroundColour("blue");
411 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
412 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
413 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
414 rb->SetValue( FALSE );
415 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
416 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
417
418 panel = new wxPanel(m_notebook);
419 // panel->SetBackgroundColour("cadet blue");
420 // panel->SetForegroundColour("blue");
421 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
422 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
423 // m_gauge->SetBackgroundColour("wheat");
424 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
425 // m_slider->SetBackgroundColour("wheat");
426 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
427 #ifdef __WXMOTIF__
428 // No wrapping text in wxStaticText yet :-(
429 (void)new wxStaticText( panel, -1,
430 "Drag the slider!",
431 wxPoint(208,30),
432 wxSize(210, -1)
433 );
434 #else
435 (void)new wxStaticText( panel, -1,
436 "In order see the gauge (aka progress bar)\n"
437 "control do something you have to drag the\n"
438 "handle of the slider to the right.\n"
439 "\n"
440 "This is also supposed to demonstrate how\n"
441 "to use static controls.\n",
442 wxPoint(208,25),
443 wxSize(210, 110)
444 );
445 #endif
446 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
447 // m_spintext->SetBackgroundColour("wheat");
448 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
449 // m_spinbutton->SetBackgroundColour("wheat");
450 m_spinbutton->SetRange(0,100);
451
452 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
453 }
454
455 void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
456 {
457 #ifdef __WXGTK__
458
459 if (!wxTheClipboard->Open())
460 {
461 *m_text << "Error opening the clipboard." << "\n";
462
463 return;
464 }
465 else
466 {
467 *m_text << "Successfully opened the clipboard." << "\n";
468 }
469
470 wxTextDataObject *data = new wxTextDataObject();
471
472 if (wxTheClipboard->GetData( data ))
473 {
474 *m_text << "Successfully retrieved data from the clipboard." << "\n";
475 *m_multitext << data->GetText() << "\n";
476 }
477 else
478 {
479 *m_text << "Error getting data from the clipboard." << "\n";
480 }
481
482 wxTheClipboard->Close();
483
484 *m_text << "Closed the clipboard." << "\n";
485
486 delete data;
487
488 #endif
489 }
490
491 void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
492 {
493 #ifdef __WXGTK__
494
495 wxString text( m_multitext->GetLineText(0) );
496
497 if (text.IsEmpty()) return;
498
499 if (!wxTheClipboard->Open())
500 {
501 *m_text << "Error opening the clipboard." << "\n";
502
503 return;
504 }
505 else
506 {
507 *m_text << "Successfully opened the clipboard." << "\n";
508 }
509
510 wxTextDataObject *data = new wxTextDataObject( text );
511 wxDataBroker *broker = new wxDataBroker();
512 broker->Add( data );
513
514 if (!wxTheClipboard->SetData( broker ))
515 {
516 *m_text << "Error while copying to the clipboard." << "\n";
517 }
518 else
519 {
520 *m_text << "Successfully copied data to the clipboard." << "\n";
521 }
522
523 wxTheClipboard->Close();
524
525 *m_text << "Closed the clipboard." << "\n";
526
527 #endif
528 }
529
530 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
531 {
532 int x = 0;
533 int y = 0;
534 GetClientSize( &x, &y );
535
536 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
537 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
538 }
539
540 void MyPanel::OnPageChanged( wxNotebookEvent &event )
541 {
542 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
543 }
544
545 void MyPanel::OnListBox( wxCommandEvent &event )
546 {
547 m_text->WriteText( "ListBox selection string is: " );
548 m_text->WriteText( event.GetString() );
549 m_text->WriteText( "\n" );
550 }
551
552 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
553 {
554 m_text->WriteText( "ListBox double click string is: " );
555 m_text->WriteText( event.GetString() );
556 m_text->WriteText( "\n" );
557 }
558
559 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
560 {
561 switch (event.GetId())
562 {
563 case ID_LISTBOX_ENABLE:
564 {
565 m_text->WriteText("Checkbox clicked.\n");
566 m_listbox->Enable( event.GetInt() == 0 );
567 break;
568 }
569 case ID_LISTBOX_SEL_NUM:
570 {
571 m_listbox->SetSelection( 2 );
572 break;
573 }
574 case ID_LISTBOX_SEL_STR:
575 {
576 m_listbox->SetStringSelection( "This" );
577 break;
578 }
579 case ID_LISTBOX_CLEAR:
580 {
581 m_listbox->Clear();
582 break;
583 }
584 case ID_LISTBOX_APPEND:
585 {
586 m_listbox->Append( "Hi!" );
587 break;
588 }
589 case ID_LISTBOX_DELETE:
590 {
591 int idx = m_listbox->GetSelection();
592 m_listbox->Delete( idx );
593 break;
594 }
595 case ID_LISTBOX_FONT:
596 {
597 m_listbox->SetFont( *wxITALIC_FONT );
598 m_checkbox->SetFont( *wxITALIC_FONT );
599 break;
600 }
601 }
602 }
603
604 void MyPanel::OnChoice( wxCommandEvent &event )
605 {
606 m_text->WriteText( "Choice selection string is: " );
607 m_text->WriteText( event.GetString() );
608 m_text->WriteText( "\n" );
609 }
610
611 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
612 {
613 switch (event.GetId())
614 {
615 case ID_CHOICE_ENABLE:
616 {
617 m_choice->Enable( event.GetInt() == 0 );
618 break;
619 }
620 case ID_CHOICE_SEL_NUM:
621 {
622 m_choice->SetSelection( 2 );
623 break;
624 }
625 case ID_CHOICE_SEL_STR:
626 {
627 m_choice->SetStringSelection( "This" );
628 break;
629 }
630 case ID_CHOICE_CLEAR:
631 {
632 m_choice->Clear();
633 break;
634 }
635 case ID_CHOICE_APPEND:
636 {
637 m_choice->Append( "Hi!" );
638 break;
639 }
640 case ID_CHOICE_DELETE:
641 {
642 int idx = m_choice->GetSelection();
643 m_choice->Delete( idx );
644 break;
645 }
646 case ID_CHOICE_FONT:
647 {
648 m_choice->SetFont( *wxITALIC_FONT );
649 break;
650 }
651 }
652 }
653
654 void MyPanel::OnCombo( wxCommandEvent &event )
655 {
656 m_text->WriteText( "ComboBox selection string is: " );
657 m_text->WriteText( event.GetString() );
658 m_text->WriteText( "\n" );
659 }
660
661 void MyPanel::OnComboButtons( wxCommandEvent &event )
662 {
663 switch (event.GetId())
664 {
665 case ID_COMBO_ENABLE:
666 {
667 m_combo->Enable( event.GetInt() == 0 );
668 break;
669 }
670 case ID_COMBO_SEL_NUM:
671 {
672 m_combo->SetSelection( 2 );
673 break;
674 }
675 case ID_COMBO_SEL_STR:
676 {
677 m_combo->SetStringSelection( "This" );
678 break;
679 }
680 case ID_COMBO_CLEAR:
681 {
682 m_combo->Clear();
683 break;
684 }
685 case ID_COMBO_APPEND:
686 {
687 m_combo->Append( "Hi!" );
688 break;
689 }
690 case ID_COMBO_DELETE:
691 {
692 int idx = m_combo->GetSelection();
693 m_combo->Delete( idx );
694 break;
695 }
696 case ID_COMBO_FONT:
697 {
698 m_combo->SetFont( *wxITALIC_FONT );
699 break;
700 }
701 }
702 }
703
704 void MyPanel::OnRadio( wxCommandEvent &event )
705 {
706 m_text->WriteText( "RadioBox selection string is: " );
707 m_text->WriteText( event.GetString() );
708 m_text->WriteText( "\n" );
709 }
710
711 void MyPanel::OnRadioButtons( wxCommandEvent &event )
712 {
713 switch (event.GetId())
714 {
715 case ID_RADIOBOX_ENABLE:
716 {
717 m_radio->Enable( event.GetInt() == 0 );
718 break;
719 }
720 case ID_RADIOBOX_SEL_NUM:
721 {
722 m_radio->SetSelection( 2 );
723 break;
724 }
725 case ID_RADIOBOX_SEL_STR:
726 {
727 m_radio->SetStringSelection( "This" );
728 break;
729 }
730 case ID_RADIOBOX_FONT:
731 {
732 m_radio->SetFont( *wxITALIC_FONT );
733 break;
734 }
735 }
736 }
737
738 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
739 {
740 m_fontButton->SetFont( *wxITALIC_FONT );
741 m_text->SetFont( *wxITALIC_FONT );
742 }
743
744 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
745 {
746 m_gauge->SetValue( m_slider->GetValue() );
747 }
748
749 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
750 {
751 wxString value;
752 value.sprintf( "%d", (int)event.GetPosition() );
753 m_spintext->SetValue( value );
754 }
755
756 MyPanel::~MyPanel()
757 {
758 delete m_notebook->GetImageList();
759 }
760
761 //----------------------------------------------------------------------
762 // MyFrame
763 //----------------------------------------------------------------------
764
765 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
766 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
767 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
768 END_EVENT_TABLE()
769
770 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
771 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
772 {
773 (void)new MyPanel( this, 10, 10, 300, 100 );
774 }
775
776 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
777 {
778 Close(TRUE);
779 }
780
781 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
782 {
783 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
784 dialog.ShowModal();
785 }