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