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