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