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