]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
fe99c4266e87f4f6d77aa5b9fb930c73d4760211
[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_COMBOBOX (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 #ifdef __WXGTK__
337 m_listbox->SetToolTip( "This is a list box" );
338 #endif
339 // m_listbox->SetBackgroundColour("wheat");
340 (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
341 (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
342 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
343 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
344 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
345 button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
346 #ifdef __WXGTK__
347 button->SetToolTip( "Press here to set italic font" );
348 #endif
349
350 // button->SetForegroundColour( "red" );
351 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
352 m_checkbox->SetValue(FALSE);
353 #ifdef __WXGTK__
354 m_checkbox->SetToolTip( "Click here to disable the listbox" );
355 #endif
356 m_notebook->AddPage(panel, "wxList", TRUE, Image_List);
357
358 panel = new wxPanel(m_notebook);
359 // panel->SetBackgroundColour("cadet blue");
360 // panel->SetForegroundColour("blue");
361 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
362 // m_choice->SetBackgroundColour("wheat");
363 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
364 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
365 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
366 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
367 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
368 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
369 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
370 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
371
372 panel = new wxPanel(m_notebook);
373 // panel->SetBackgroundColour("cadet blue");
374 // panel->SetForegroundColour("blue");
375 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices );
376 // m_combo->SetBackgroundColour("wheat");
377 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
378 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
379 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
380 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
381 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
382 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
383 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
384 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
385
386 panel = new wxPanel(m_notebook);
387 // panel->SetBackgroundColour("cadet blue");
388 // panel->SetForegroundColour("blue");
389 wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
390 (*tc) << " More text.";
391 // tc->SetBackgroundColour("wheat");
392 m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
393 (*m_multitext) << " More text.";
394 // m_multitext->SetBackgroundColour("wheat");
395 (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
396 (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
397 (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) );
398 m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
399
400 wxString choices2[] =
401 {
402 "Wonderful",
403 "examples.",
404 };
405
406 panel = new wxPanel(m_notebook);
407 // panel->SetBackgroundColour("cadet blue");
408 // panel->SetForegroundColour("blue");
409 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS );
410 // m_radio->SetBackgroundColour("wheat");
411 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS );
412 // m_radio->SetBackgroundColour("wheat");
413 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
414 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
415 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
416 // m_fontButton->SetForegroundColour("blue");
417 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
418 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
419 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
420 rb->SetValue( FALSE );
421 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
422 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
423
424 panel = new wxPanel(m_notebook);
425 // panel->SetBackgroundColour("cadet blue");
426 // panel->SetForegroundColour("blue");
427 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
428 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
429 // m_gauge->SetBackgroundColour("wheat");
430 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
431 // m_slider->SetBackgroundColour("wheat");
432 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
433 #ifdef __WXMOTIF__
434 // No wrapping text in wxStaticText yet :-(
435 (void)new wxStaticText( panel, -1,
436 "Drag the slider!",
437 wxPoint(208,30),
438 wxSize(210, -1)
439 );
440 #else
441 (void)new wxStaticText( panel, -1,
442 "In order see the gauge (aka progress bar)\n"
443 "control do something you have to drag the\n"
444 "handle of the slider to the right.\n"
445 "\n"
446 "This is also supposed to demonstrate how\n"
447 "to use static controls.\n",
448 wxPoint(208,25),
449 wxSize(210, 110)
450 );
451 #endif
452 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
453 // m_spintext->SetBackgroundColour("wheat");
454 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
455 // m_spinbutton->SetBackgroundColour("wheat");
456 m_spinbutton->SetRange(0,100);
457
458 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
459 }
460
461 void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
462 {
463 #ifdef __WXGTK__
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 wxTextDataObject *data = new wxTextDataObject();
477
478 if (wxTheClipboard->GetData( data ))
479 {
480 *m_text << "Successfully retrieved data from the clipboard." << "\n";
481 *m_multitext << data->GetText() << "\n";
482 }
483 else
484 {
485 *m_text << "Error getting data from the clipboard." << "\n";
486 }
487
488 wxTheClipboard->Close();
489
490 *m_text << "Closed the clipboard." << "\n";
491
492 delete data;
493
494 #endif
495 }
496
497 void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
498 {
499 #ifdef __WXGTK__
500
501 wxString text( m_multitext->GetLineText(0) );
502
503 if (text.IsEmpty()) return;
504
505 if (!wxTheClipboard->Open())
506 {
507 *m_text << "Error opening the clipboard." << "\n";
508
509 return;
510 }
511 else
512 {
513 *m_text << "Successfully opened the clipboard." << "\n";
514 }
515
516 wxTextDataObject *data = new wxTextDataObject( text );
517 wxDataBroker *broker = new wxDataBroker();
518 broker->Add( data );
519
520 if (!wxTheClipboard->SetData( broker ))
521 {
522 *m_text << "Error while copying to the clipboard." << "\n";
523 }
524 else
525 {
526 *m_text << "Successfully copied data to the clipboard." << "\n";
527 }
528
529 wxTheClipboard->Close();
530
531 *m_text << "Closed the clipboard." << "\n";
532
533 #endif
534 }
535
536 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
537 {
538 int x = 0;
539 int y = 0;
540 GetClientSize( &x, &y );
541
542 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
543 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
544 }
545
546 void MyPanel::OnPageChanged( wxNotebookEvent &event )
547 {
548 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
549 }
550
551 void MyPanel::OnListBox( wxCommandEvent &event )
552 {
553 m_text->WriteText( "ListBox selection string is: " );
554 m_text->WriteText( event.GetString() );
555 m_text->WriteText( "\n" );
556 }
557
558 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
559 {
560 m_text->WriteText( "ListBox double click string is: " );
561 m_text->WriteText( event.GetString() );
562 m_text->WriteText( "\n" );
563 }
564
565 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
566 {
567 switch (event.GetId())
568 {
569 case ID_LISTBOX_ENABLE:
570 {
571 m_text->WriteText("Checkbox clicked.\n");
572 m_listbox->Enable( event.GetInt() == 0 );
573 break;
574 }
575 case ID_LISTBOX_SEL_NUM:
576 {
577 m_listbox->SetSelection( 2 );
578 break;
579 }
580 case ID_LISTBOX_SEL_STR:
581 {
582 m_listbox->SetStringSelection( "This" );
583 break;
584 }
585 case ID_LISTBOX_CLEAR:
586 {
587 m_listbox->Clear();
588 break;
589 }
590 case ID_LISTBOX_APPEND:
591 {
592 m_listbox->Append( "Hi!" );
593 break;
594 }
595 case ID_LISTBOX_DELETE:
596 {
597 int idx = m_listbox->GetSelection();
598 m_listbox->Delete( idx );
599 break;
600 }
601 case ID_LISTBOX_FONT:
602 {
603 m_listbox->SetFont( *wxITALIC_FONT );
604 m_checkbox->SetFont( *wxITALIC_FONT );
605 break;
606 }
607 }
608 }
609
610 void MyPanel::OnChoice( wxCommandEvent &event )
611 {
612 m_text->WriteText( "Choice selection string is: " );
613 m_text->WriteText( event.GetString() );
614 m_text->WriteText( "\n" );
615 }
616
617 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
618 {
619 switch (event.GetId())
620 {
621 case ID_CHOICE_ENABLE:
622 {
623 m_choice->Enable( event.GetInt() == 0 );
624 break;
625 }
626 case ID_CHOICE_SEL_NUM:
627 {
628 m_choice->SetSelection( 2 );
629 break;
630 }
631 case ID_CHOICE_SEL_STR:
632 {
633 m_choice->SetStringSelection( "This" );
634 break;
635 }
636 case ID_CHOICE_CLEAR:
637 {
638 m_choice->Clear();
639 break;
640 }
641 case ID_CHOICE_APPEND:
642 {
643 m_choice->Append( "Hi!" );
644 break;
645 }
646 case ID_CHOICE_DELETE:
647 {
648 int idx = m_choice->GetSelection();
649 m_choice->Delete( idx );
650 break;
651 }
652 case ID_CHOICE_FONT:
653 {
654 m_choice->SetFont( *wxITALIC_FONT );
655 break;
656 }
657 }
658 }
659
660 void MyPanel::OnCombo( wxCommandEvent &event )
661 {
662 m_text->WriteText( "ComboBox selection string is: " );
663 m_text->WriteText( event.GetString() );
664 m_text->WriteText( "\n" );
665 }
666
667 void MyPanel::OnComboButtons( wxCommandEvent &event )
668 {
669 switch (event.GetId())
670 {
671 case ID_COMBO_ENABLE:
672 {
673 m_combo->Enable( event.GetInt() == 0 );
674 break;
675 }
676 case ID_COMBO_SEL_NUM:
677 {
678 m_combo->SetSelection( 2 );
679 break;
680 }
681 case ID_COMBO_SEL_STR:
682 {
683 m_combo->SetStringSelection( "This" );
684 break;
685 }
686 case ID_COMBO_CLEAR:
687 {
688 m_combo->Clear();
689 break;
690 }
691 case ID_COMBO_APPEND:
692 {
693 m_combo->Append( "Hi!" );
694 break;
695 }
696 case ID_COMBO_DELETE:
697 {
698 int idx = m_combo->GetSelection();
699 m_combo->Delete( idx );
700 break;
701 }
702 case ID_COMBO_FONT:
703 {
704 m_combo->SetFont( *wxITALIC_FONT );
705 break;
706 }
707 }
708 }
709
710 void MyPanel::OnRadio( wxCommandEvent &event )
711 {
712 m_text->WriteText( "RadioBox selection string is: " );
713 m_text->WriteText( event.GetString() );
714 m_text->WriteText( "\n" );
715 }
716
717 void MyPanel::OnRadioButtons( wxCommandEvent &event )
718 {
719 switch (event.GetId())
720 {
721 case ID_RADIOBOX_ENABLE:
722 {
723 m_radio->Enable( event.GetInt() == 0 );
724 break;
725 }
726 case ID_RADIOBOX_SEL_NUM:
727 {
728 m_radio->SetSelection( 2 );
729 break;
730 }
731 case ID_RADIOBOX_SEL_STR:
732 {
733 m_radio->SetStringSelection( "This" );
734 break;
735 }
736 case ID_RADIOBOX_FONT:
737 {
738 m_radio->SetFont( *wxITALIC_FONT );
739 break;
740 }
741 }
742 }
743
744 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
745 {
746 m_fontButton->SetFont( *wxITALIC_FONT );
747 m_text->SetFont( *wxITALIC_FONT );
748 }
749
750 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
751 {
752 m_gauge->SetValue( m_slider->GetValue() );
753 }
754
755 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
756 {
757 wxString value;
758 value.sprintf( "%d", (int)event.GetPosition() );
759 m_spintext->SetValue( value );
760 }
761
762 MyPanel::~MyPanel()
763 {
764 delete m_notebook->GetImageList();
765 }
766
767 //----------------------------------------------------------------------
768 // MyFrame
769 //----------------------------------------------------------------------
770
771 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
772 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
773 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
774 END_EVENT_TABLE()
775
776 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
777 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
778 {
779 (void)new MyPanel( this, 10, 10, 300, 100 );
780 }
781
782 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
783 {
784 Close(TRUE);
785 }
786
787 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
788 {
789 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
790 dialog.ShowModal();
791 }