]> git.saurik.com Git - wxWidgets.git/blame - samples/controls/controls.cpp
corrected (?) wxStringList::Delete()
[wxWidgets.git] / samples / controls / controls.cpp
CommitLineData
1c005ff7 1/////////////////////////////////////////////////////////////////////////////
dfad0599 2// Name: controls.cpp
1c005ff7
RR
3// Purpose: Controls wxWindows sample
4// Author: Robert Roebling
5// Modified by:
6// RCS-ID: $Id$
c67d8618 7// Copyright: (c) Robert Roebling, Julian Smart
1c005ff7
RR
8// Licence: wxWindows license
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
e4a81a2e 12#pragma implementation "controls.h"
1c005ff7
RR
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
4fabb575 26#include "wx/spinbutt.h"
53b28675 27#include "wx/notebook.h"
2cb21a45 28#include "wx/imaglist.h"
b527aac5 29#include "wx/clipbrd.h"
1c005ff7 30
4fabb575
JS
31// XPM doesn't seem to work under Windows at present. Or, wxNotebook images
32// aren't working.
33// Uncomment this line and comment out the next to try it.
34// #if defined(__WXGTK__) || defined(__WXMOTIF__) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
4b5f3fe6 35#if defined(__WXGTK__) || defined(__WXMOTIF__)
4fabb575
JS
36#define USE_XPM
37#endif
38
39#ifdef USE_XPM
47908e25 40#include "mondrian.xpm"
fc54776e
RR
41#include "icons/choice.xpm"
42#include "icons/combo.xpm"
43#include "icons/list.xpm"
44#include "icons/radio.xpm"
45#include "icons/text.xpm"
58614078 46#include "icons/gauge.xpm"
47908e25
RR
47#endif
48
1c005ff7
RR
49//----------------------------------------------------------------------
50// class definitions
51//----------------------------------------------------------------------
52
53class MyApp: public wxApp
54{
55 public:
56 bool OnInit(void);
57};
58
59class MyPanel: public wxPanel
60{
61 public:
62
63 MyPanel(wxFrame *frame, int x, int y, int w, int h);
2cb21a45 64 virtual ~MyPanel();
1c005ff7
RR
65
66 void OnSize( wxSizeEvent& event );
67 void OnListBox( wxCommandEvent &event );
68 void OnListBoxButtons( wxCommandEvent &event );
47908e25
RR
69 void OnChoice( wxCommandEvent &event );
70 void OnChoiceButtons( wxCommandEvent &event );
71 void OnCombo( wxCommandEvent &event );
72 void OnComboButtons( wxCommandEvent &event );
73 void OnRadio( wxCommandEvent &event );
74 void OnRadioButtons( wxCommandEvent &event );
868a2826 75 void OnSetFont( wxCommandEvent &event );
cb43b372 76 void OnPageChanged( wxNotebookEvent &event );
7bce6aec 77 void OnSliderUpdate( wxCommandEvent &event );
e380f72b 78 void OnSpinUpdate( wxSpinEvent &event );
b527aac5
RR
79 void OnPasteFromClipboard( wxCommandEvent &event );
80 void OnCopyToClipboard( wxCommandEvent &event );
81 void OnCutToClipboard( wxCommandEvent &event );
1c005ff7 82
e380f72b
RR
83 wxListBox *m_listbox;
84 wxChoice *m_choice;
85 wxComboBox *m_combo;
86 wxRadioBox *m_radio;
87 wxGauge *m_gauge;
88 wxSlider *m_slider;
89 wxButton *m_fontButton;
90 wxSpinButton *m_spinbutton;
91 wxTextCtrl *m_spintext;
b527aac5 92 wxTextCtrl *m_multitext;
ae0bdb01 93 wxCheckBox *m_checkbox;
1c005ff7 94
e380f72b
RR
95 wxTextCtrl *m_text;
96 wxNotebook *m_notebook;
1c005ff7
RR
97
98 DECLARE_EVENT_TABLE()
99};
100
101class MyFrame: public wxFrame
102{
103 public:
104
105 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
106
107 public:
108
109 void OnQuit(wxCommandEvent& event);
110 void OnAbout(wxCommandEvent& event);
111 bool OnClose(void) { return TRUE; }
112
113 DECLARE_EVENT_TABLE()
114};
115
116//----------------------------------------------------------------------
117// main()
118//----------------------------------------------------------------------
119
120IMPLEMENT_APP (MyApp)
121
122//----------------------------------------------------------------------
123// MyApp
124//----------------------------------------------------------------------
125
c67daf87
UR
126const int MINIMAL_QUIT = 100;
127const int MINIMAL_TEXT = 101;
128const int MINIMAL_ABOUT = 102;
1c005ff7
RR
129
130bool MyApp::OnInit(void)
131{
132 // Create the main frame window
d3904ceb 133 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Controls wxWindows App", 50, 50, 530, 420 );
1c005ff7
RR
134
135 // Give it an icon
e52f60e6
RR
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) );
1c005ff7
RR
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
4fabb575 160const int ID_NOTEBOOK = 1000;
1c005ff7 161
4fabb575
JS
162const int ID_LISTBOX = 130;
163const int ID_LISTBOX_SEL_NUM = 131;
164const int ID_LISTBOX_SEL_STR = 132;
165const int ID_LISTBOX_CLEAR = 133;
166const int ID_LISTBOX_APPEND = 134;
167const int ID_LISTBOX_DELETE = 135;
168const int ID_LISTBOX_FONT = 136;
169const int ID_LISTBOX_ENABLE = 137;
1c005ff7 170
4fabb575
JS
171const int ID_CHOICE = 120;
172const int ID_CHOICE_SEL_NUM = 121;
173const int ID_CHOICE_SEL_STR = 122;
174const int ID_CHOICE_CLEAR = 123;
175const int ID_CHOICE_APPEND = 124;
176const int ID_CHOICE_DELETE = 125;
177const int ID_CHOICE_FONT = 126;
178const int ID_CHOICE_ENABLE = 127;
53010e52 179
4fabb575
JS
180const int ID_COMBO = 140;
181const int ID_COMBO_SEL_NUM = 141;
182const int ID_COMBO_SEL_STR = 142;
183const int ID_COMBO_CLEAR = 143;
184const int ID_COMBO_APPEND = 144;
185const int ID_COMBO_DELETE = 145;
186const int ID_COMBO_FONT = 146;
187const int ID_COMBO_ENABLE = 147;
53010e52 188
4fabb575 189const int ID_TEXT = 150;
b527aac5
RR
190const int ID_PASTE_TEXT = 151;
191const int ID_COPY_TEXT = 152;
192const int ID_CUT_TEXT = 153;
219f895a 193
4fabb575
JS
194const int ID_RADIOBOX = 160;
195const int ID_RADIOBOX_SEL_NUM = 161;
196const int ID_RADIOBOX_SEL_STR = 162;
197const int ID_RADIOBOX_FONT = 163;
198const int ID_RADIOBOX_ENABLE = 164;
868a2826 199
4fabb575 200const int ID_SET_FONT = 170;
47908e25 201
4fabb575
JS
202const int ID_GAUGE = 180;
203const int ID_SLIDER = 181;
58614078 204
4fabb575 205const int ID_SPIN = 182;
e380f72b 206
58614078 207
1c005ff7 208BEGIN_EVENT_TABLE(MyPanel, wxPanel)
cb43b372
RR
209 EVT_SIZE ( MyPanel::OnSize)
210 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
211 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
212 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
213 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
214 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
215 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
216 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
217 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
218 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
219 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
220 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
221 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
222 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
223 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
224 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
225 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
226 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
227 EVT_CHOICE (ID_COMBO, MyPanel::OnCombo)
228 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
229 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
230 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
231 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
232 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
233 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
234 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
235 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
236 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
237 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
238 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
239 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
240 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
7bce6aec 241 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
e380f72b 242 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
b527aac5
RR
243 EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
244 EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
245 EVT_BUTTON (ID_CUT_TEXT, MyPanel::OnCutToClipboard)
1c005ff7
RR
246END_EVENT_TABLE()
247
248MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
249 wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
250{
b527aac5 251// SetBackgroundColour("cadet blue");
a81258be 252
1c005ff7 253 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
b527aac5 254// m_text->SetBackgroundColour("wheat");
1c005ff7 255
53b28675 256 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
1c005ff7 257
53010e52 258 wxString choices[] =
1c005ff7
RR
259 {
260 "This",
c67d8618
RR
261 "is one of my",
262 "really",
e8435fa3 263 "wonderful",
c67d8618 264 "examples.",
1c005ff7
RR
265 };
266
4fabb575 267#ifdef USE_XPM
2cb21a45
VZ
268 // image ids and names
269 enum
270 {
58614078 271 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
2cb21a45
VZ
272 };
273
fc54776e 274 // fill the image list
2cb21a45 275 wxImageList *imagelist = new wxImageList(32, 32);
4fabb575 276
35178437
RR
277 imagelist-> Add( wxBitmap( list_xpm ));
278 imagelist-> Add( wxBitmap( choice_xpm ));
279 imagelist-> Add( wxBitmap( combo_xpm ));
280 imagelist-> Add( wxBitmap( text_xpm ));
281 imagelist-> Add( wxBitmap( radio_xpm ));
282 imagelist-> Add( wxBitmap( gauge_xpm ));
4fabb575
JS
283 m_notebook->SetImageList(imagelist);
284#else
285
286// No images for now
287#define Image_List -1
288#define Image_Choice -1
289#define Image_Combo -1
290#define Image_Text -1
291#define Image_Radio -1
292#define Image_Gauge -1
293#define Image_Max -1
294
fc54776e 295#endif
2cb21a45 296
a81258be
RR
297 wxButton *button = (wxButton*)NULL;
298
b527aac5 299// m_notebook->SetBackgroundColour("cadet blue");
2cb21a45 300
58614078
RR
301 wxPanel *panel = (wxPanel*) NULL;
302 panel = new wxPanel(m_notebook);
b527aac5
RR
303// panel->SetBackgroundColour("cadet blue");
304// panel->SetForegroundColour("blue");
c67d8618 305 m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices );
b527aac5 306// m_listbox->SetBackgroundColour("wheat");
d3904ceb
RR
307 (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
308 (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
f96aa4d9 309 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
d3904ceb 310 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
30f82ea4 311 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
a81258be 312 button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
b527aac5 313// button->SetForegroundColour( "red" );
ae0bdb01 314 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
2cb21a45 315 m_notebook->AddPage(panel, "wxList", FALSE, Image_List);
53010e52 316
4bf58c62 317 panel = new wxPanel(m_notebook);
b527aac5
RR
318// panel->SetBackgroundColour("cadet blue");
319// panel->SetForegroundColour("blue");
c67d8618 320 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
b527aac5 321// m_choice->SetBackgroundColour("wheat");
d3904ceb
RR
322 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
323 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
324 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
325 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
2f6407b9 326 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
d3904ceb
RR
327 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
328 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
2cb21a45 329 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
53010e52 330
4bf58c62 331 panel = new wxPanel(m_notebook);
b527aac5
RR
332// panel->SetBackgroundColour("cadet blue");
333// panel->SetForegroundColour("blue");
c67d8618 334 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices );
b527aac5 335// m_combo->SetBackgroundColour("wheat");
d3904ceb
RR
336 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
337 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
338 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
339 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
2f6407b9 340 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
d3904ceb
RR
341 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
342 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
2cb21a45 343 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
219f895a 344
f96aa4d9 345 panel = new wxPanel(m_notebook);
b527aac5
RR
346// panel->SetBackgroundColour("cadet blue");
347// panel->SetForegroundColour("blue");
348 wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
6ca41e57 349 (*tc) << " More text.";
b527aac5
RR
350// tc->SetBackgroundColour("wheat");
351 m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
352 (*m_multitext) << " More text.";
353// m_multitext->SetBackgroundColour("wheat");
354 (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
3069ac4e 355 (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,70), wxSize(110,30) );
b527aac5 356 (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,110), wxSize(110,30) );
3069ac4e 357 (void)new wxButton( panel, ID_CUT_TEXT, "Cut line 1", wxPoint(370,150), wxSize(110,30) );
f96aa4d9 358 m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
47908e25 359
e5403d7c
RR
360 wxString choices2[] =
361 {
362 "Wonderful",
363 "examples.",
364 };
365
47908e25 366 panel = new wxPanel(m_notebook);
b527aac5
RR
367// panel->SetBackgroundColour("cadet blue");
368// panel->SetForegroundColour("blue");
92976ab6 369 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_VERTICAL );
b527aac5 370// m_radio->SetBackgroundColour("wheat");
92976ab6 371 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_HORIZONTAL );
b527aac5 372// m_radio->SetBackgroundColour("wheat");
d3904ceb
RR
373 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
374 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
b527aac5
RR
375 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
376 m_fontButton->SetForegroundColour("blue");
377 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
e5403d7c 378 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
2cb21a45 379 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
c67d8618
RR
380
381 panel = new wxPanel(m_notebook);
b527aac5
RR
382// panel->SetBackgroundColour("cadet blue");
383// panel->SetForegroundColour("blue");
58614078
RR
384 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
385 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155,-1) );
b527aac5 386// m_gauge->SetBackgroundColour("wheat");
7bce6aec 387 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
b527aac5 388// m_slider->SetBackgroundColour("wheat");
7bce6aec
RR
389 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
390 (void)new wxStaticText( panel, -1,
391 "In order see the gauge (aka progress bar)\n"
392 "control do something you have to drag the\n"
393 "handle of the slider to the right.\n"
394 "\n"
395 "This is also supposed to demonstrate how\n"
396 "to use static controls.\n",
397 wxPoint(208,25) );
e380f72b 398 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
b527aac5 399// m_spintext->SetBackgroundColour("wheat");
e380f72b 400 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
b527aac5 401// m_spinbutton->SetBackgroundColour("wheat");
e380f72b
RR
402 m_spinbutton->SetRange(0,100);
403
58614078 404 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
1c005ff7
RR
405}
406
b527aac5
RR
407void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
408{
409#ifdef __WXGTK__
410
411 if (!wxTheClipboard->IsSupportedFormat( wxDF_TEXT )) return;
412
413 if (!wxTheClipboard->ObtainData( wxDF_TEXT )) return;
414
415 int size = wxTheClipboard->GetDataSize()+1;
416
417 char *data = new char[size];
418
419 data[size-1] = 0;
420
421 wxTheClipboard->GetDataHere( data );
422
423 *m_multitext << data << "\n";
424
425 delete[] data;
426
427#endif
428}
429
430void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
431{
3069ac4e
RR
432#ifdef __WXGTK__
433
434 wxString text( m_multitext->GetLineText(0) );
435
436 if (text.IsEmpty()) return;
437
438 wxTextDataObject *data = new wxTextDataObject( text );
439
440 wxTheClipboard->SetData( data );
441
442#endif
b527aac5
RR
443}
444
445void MyPanel::OnCutToClipboard( wxCommandEvent &WXUNUSED(event) )
446{
447}
448
1c005ff7
RR
449void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
450{
451 int x = 0;
452 int y = 0;
453 GetClientSize( &x, &y );
454
2f6407b9
RR
455 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
456 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1c005ff7
RR
457}
458
cb43b372
RR
459void MyPanel::OnPageChanged( wxNotebookEvent &event )
460{
461 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
462}
463
1c005ff7
RR
464void MyPanel::OnListBox( wxCommandEvent &event )
465{
1c005ff7
RR
466 m_text->WriteText( "ListBox selection string is: " );
467 m_text->WriteText( event.GetString() );
468 m_text->WriteText( "\n" );
469}
470
47908e25
RR
471void MyPanel::OnListBoxButtons( wxCommandEvent &event )
472{
473 switch (event.GetId())
474 {
d3904ceb
RR
475 case ID_LISTBOX_ENABLE:
476 {
477 m_listbox->Enable( !((bool)event.GetInt()) );
478 break;
479 }
47908e25
RR
480 case ID_LISTBOX_SEL_NUM:
481 {
482 m_listbox->SetSelection( 2 );
483 break;
484 }
485 case ID_LISTBOX_SEL_STR:
486 {
487 m_listbox->SetStringSelection( "This" );
488 break;
489 }
490 case ID_LISTBOX_CLEAR:
491 {
492 m_listbox->Clear();
493 break;
494 }
495 case ID_LISTBOX_APPEND:
496 {
497 m_listbox->Append( "Hi!" );
498 break;
499 }
30f82ea4
RR
500 case ID_LISTBOX_DELETE:
501 {
502 int idx = m_listbox->GetSelection();
503 m_listbox->Delete( idx );
504 break;
505 }
868a2826
RR
506 case ID_LISTBOX_FONT:
507 {
508 m_listbox->SetFont( *wxITALIC_FONT );
ae0bdb01 509 m_checkbox->SetFont( *wxITALIC_FONT );
868a2826
RR
510 break;
511 }
47908e25
RR
512 }
513}
514
515void MyPanel::OnChoice( wxCommandEvent &event )
516{
517 m_text->WriteText( "Choice selection string is: " );
518 m_text->WriteText( event.GetString() );
519 m_text->WriteText( "\n" );
520}
521
522void MyPanel::OnChoiceButtons( wxCommandEvent &event )
523{
524 switch (event.GetId())
525 {
d3904ceb
RR
526 case ID_CHOICE_ENABLE:
527 {
528 m_choice->Enable( !((bool)event.GetInt()) );
529 break;
530 }
47908e25
RR
531 case ID_CHOICE_SEL_NUM:
532 {
533 m_choice->SetSelection( 2 );
534 break;
535 }
536 case ID_CHOICE_SEL_STR:
537 {
538 m_choice->SetStringSelection( "This" );
539 break;
540 }
541 case ID_CHOICE_CLEAR:
542 {
543 m_choice->Clear();
544 break;
545 }
546 case ID_CHOICE_APPEND:
547 {
548 m_choice->Append( "Hi!" );
549 break;
550 }
2f6407b9
RR
551 case ID_CHOICE_DELETE:
552 {
553 int idx = m_choice->GetSelection();
554 m_choice->Delete( idx );
555 break;
556 }
868a2826
RR
557 case ID_CHOICE_FONT:
558 {
559 m_choice->SetFont( *wxITALIC_FONT );
560 break;
561 }
47908e25
RR
562 }
563}
564
565void MyPanel::OnCombo( wxCommandEvent &event )
566{
567 m_text->WriteText( "ComboBox selection string is: " );
568 m_text->WriteText( event.GetString() );
569 m_text->WriteText( "\n" );
570}
571
572void MyPanel::OnComboButtons( wxCommandEvent &event )
1c005ff7 573{
47908e25
RR
574 switch (event.GetId())
575 {
d3904ceb
RR
576 case ID_COMBO_ENABLE:
577 {
578 m_combo->Enable( !((bool)event.GetInt()) );
579 break;
580 }
47908e25
RR
581 case ID_COMBO_SEL_NUM:
582 {
583 m_combo->SetSelection( 2 );
584 break;
585 }
586 case ID_COMBO_SEL_STR:
587 {
588 m_combo->SetStringSelection( "This" );
589 break;
590 }
591 case ID_COMBO_CLEAR:
592 {
593 m_combo->Clear();
594 break;
595 }
596 case ID_COMBO_APPEND:
597 {
598 m_combo->Append( "Hi!" );
599 break;
600 }
2f6407b9
RR
601 case ID_COMBO_DELETE:
602 {
603 int idx = m_combo->GetSelection();
604 m_combo->Delete( idx );
605 break;
606 }
868a2826
RR
607 case ID_COMBO_FONT:
608 {
609 m_combo->SetFont( *wxITALIC_FONT );
610 break;
611 }
47908e25
RR
612 }
613}
614
615void MyPanel::OnRadio( wxCommandEvent &event )
616{
617 m_text->WriteText( "RadioBox selection string is: " );
618 m_text->WriteText( event.GetString() );
619 m_text->WriteText( "\n" );
620}
621
622void MyPanel::OnRadioButtons( wxCommandEvent &event )
623{
624 switch (event.GetId())
625 {
d3904ceb
RR
626 case ID_RADIOBOX_ENABLE:
627 {
628 m_radio->Enable( !((bool)event.GetInt()) );
629 break;
630 }
47908e25
RR
631 case ID_RADIOBOX_SEL_NUM:
632 {
633 m_radio->SetSelection( 2 );
634 break;
635 }
636 case ID_RADIOBOX_SEL_STR:
637 {
638 m_radio->SetStringSelection( "This" );
639 break;
640 }
868a2826
RR
641 case ID_RADIOBOX_FONT:
642 {
643 m_radio->SetFont( *wxITALIC_FONT );
644 break;
645 }
47908e25 646 }
1c005ff7
RR
647}
648
868a2826
RR
649void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
650{
651 m_fontButton->SetFont( *wxITALIC_FONT );
652 m_text->SetFont( *wxITALIC_FONT );
653}
654
7bce6aec
RR
655void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
656{
657 m_gauge->SetValue( m_slider->GetValue() );
658}
659
e380f72b
RR
660void MyPanel::OnSpinUpdate( wxSpinEvent &event )
661{
662 wxString value;
663 value.sprintf( "%d", (int)event.GetPosition() );
664 m_spintext->SetValue( value );
665}
666
2cb21a45
VZ
667MyPanel::~MyPanel()
668{
669 delete m_notebook->GetImageList();
670}
671
1c005ff7
RR
672//----------------------------------------------------------------------
673// MyFrame
674//----------------------------------------------------------------------
675
676BEGIN_EVENT_TABLE(MyFrame, wxFrame)
677 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
678 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
679END_EVENT_TABLE()
680
681MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
682 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
683{
654c1d6b 684 (void)new MyPanel( this, 10, 10, 300, 100 );
1c005ff7
RR
685}
686
687void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
688{
689 Close(TRUE);
690}
691
692void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
693{
694 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
695 dialog.ShowModal();
696}