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