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