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