]> git.saurik.com Git - wxWidgets.git/blame - samples/controls/controls.cpp
Added rc and def files for new samples
[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
9726da4f
VZ
54#ifdef __WIN16__
55 // Win16 doesn't have them
56 #undef wxUSE_SPINBUTTON
57 #define wxUSE_SPINBUTTON 0
58#endif // __WIN16__
59
60#include "wx/progdlg.h"
61
1c005ff7
RR
62//----------------------------------------------------------------------
63// class definitions
64//----------------------------------------------------------------------
65
66class MyApp: public wxApp
655822f3 67{
b8653fbf
VZ
68public:
69 bool OnInit();
1c005ff7
RR
70};
71
6085b116
VZ
72// a text ctrl which allows to call different wxTextCtrl functions
73// interactively by pressing function keys in it
74class MyTextCtrl : public wxTextCtrl
75{
76public:
77 MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
78 const wxPoint &pos, const wxSize &size, int style = 0)
79 : wxTextCtrl(parent, id, value, pos, size, style) { }
80
5fb9fcfc 81 void OnKeyDown(wxKeyEvent& event);
0a772322 82 void OnKeyUp(wxKeyEvent& event);
14531b30 83 void OnChar(wxKeyEvent& event);
6085b116
VZ
84
85private:
0a772322
VZ
86 static inline char GetChar(bool on, char c) { return on ? c : '-'; }
87 void LogEvent(const char *name, wxKeyEvent& event) const;
88
6085b116
VZ
89 DECLARE_EVENT_TABLE()
90};
91
1c005ff7
RR
92class MyPanel: public wxPanel
93{
b8653fbf 94public:
1c005ff7 95 MyPanel(wxFrame *frame, int x, int y, int w, int h);
2cb21a45 96 virtual ~MyPanel();
16f6dfd8 97
1c005ff7
RR
98 void OnSize( wxSizeEvent& event );
99 void OnListBox( wxCommandEvent &event );
5b077d48 100 void OnListBoxDoubleClick( wxCommandEvent &event );
1c005ff7 101 void OnListBoxButtons( wxCommandEvent &event );
47908e25
RR
102 void OnChoice( wxCommandEvent &event );
103 void OnChoiceButtons( wxCommandEvent &event );
104 void OnCombo( wxCommandEvent &event );
105 void OnComboButtons( wxCommandEvent &event );
106 void OnRadio( wxCommandEvent &event );
107 void OnRadioButtons( wxCommandEvent &event );
868a2826 108 void OnSetFont( wxCommandEvent &event );
cb43b372 109 void OnPageChanged( wxNotebookEvent &event );
4d0f3cd6 110 void OnPageChanging( wxNotebookEvent &event );
7bce6aec 111 void OnSliderUpdate( wxCommandEvent &event );
9726da4f 112#ifndef wxUSE_SPINBUTTON
e380f72b 113 void OnSpinUpdate( wxSpinEvent &event );
9726da4f
VZ
114 void OnUpdateShowProgress( wxUpdateUIEvent& event );
115 void OnShowProgress( wxCommandEvent &event );
116#endif // wxUSE_SPINBUTTON
b527aac5
RR
117 void OnPasteFromClipboard( wxCommandEvent &event );
118 void OnCopyToClipboard( wxCommandEvent &event );
d59051dd
VZ
119 void OnMoveToEndOfText( wxCommandEvent &event );
120 void OnMoveToEndOfEntry( wxCommandEvent &event );
16f6dfd8 121
e380f72b
RR
122 wxListBox *m_listbox;
123 wxChoice *m_choice;
124 wxComboBox *m_combo;
125 wxRadioBox *m_radio;
126 wxGauge *m_gauge;
127 wxSlider *m_slider;
128 wxButton *m_fontButton;
9726da4f 129#ifndef wxUSE_SPINBUTTON
e380f72b 130 wxSpinButton *m_spinbutton;
9726da4f 131 wxButton *m_btnProgress;
2a47d3c1 132#endif
e380f72b 133 wxTextCtrl *m_spintext;
6085b116
VZ
134 MyTextCtrl *m_multitext;
135 MyTextCtrl *m_textentry;
ae0bdb01 136 wxCheckBox *m_checkbox;
16f6dfd8 137
e380f72b 138 wxTextCtrl *m_text;
655822f3
VZ
139 wxNotebook *m_notebook;
140
b8653fbf
VZ
141private:
142 DECLARE_EVENT_TABLE()
1c005ff7
RR
143};
144
145class MyFrame: public wxFrame
146{
b8653fbf 147public:
1c005ff7 148 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
655822f3 149
1c005ff7
RR
150 void OnQuit(wxCommandEvent& event);
151 void OnAbout(wxCommandEvent& event);
16f6dfd8
VZ
152#if wxUSE_TOOLTIPS
153 void OnSetTooltipDelay(wxCommandEvent& event);
154 void OnToggleTooltips(wxCommandEvent& event);
155#endif // wxUSE_TOOLTIPS
9f3362c4 156 void OnIdle( wxIdleEvent& event );
5fb9fcfc 157 void OnSize( wxSizeEvent& event );
655822f3 158
b8653fbf
VZ
159private:
160 DECLARE_EVENT_TABLE()
1c005ff7
RR
161};
162
163//----------------------------------------------------------------------
164// main()
165//----------------------------------------------------------------------
166
d59051dd 167IMPLEMENT_APP(MyApp)
1c005ff7
RR
168
169//----------------------------------------------------------------------
170// MyApp
171//----------------------------------------------------------------------
172
16f6dfd8
VZ
173enum
174{
175 MINIMAL_QUIT = 100,
176 MINIMAL_TEXT,
177 MINIMAL_ABOUT,
178
179 // tooltip menu
180 MINIMAL_SET_TOOLTIP_DELAY = 200,
181 MINIMAL_ENABLE_TOOLTIPS
182};
1c005ff7 183
b8653fbf 184bool MyApp::OnInit()
1c005ff7 185{
ec9f7884
VZ
186 // Create the main frame window
187 MyFrame *frame = new MyFrame((wxFrame *) NULL,
188 "Controls wxWindows App",
189 50, 50, 530, 420);
655822f3 190
ec9f7884
VZ
191 // Give it an icon
192 // The wxICON() macros loads an icon from a resource under Windows
193 // and uses an #included XPM image under GTK+ and Motif
655822f3 194
ec9f7884 195 frame->SetIcon( wxICON(mondrian) );
1c005ff7 196
ec9f7884 197 wxMenu *file_menu = new wxMenu;
6bc8a1c8
RR
198 file_menu->Append(MINIMAL_ABOUT, "&About\tF1");
199 file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample");
16f6dfd8 200
ba0730de 201 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
ec9f7884 202 menu_bar->Append(file_menu, "&File");
16f6dfd8
VZ
203
204#if wxUSE_TOOLTIPS
ec9f7884 205 wxMenu *tooltip_menu = new wxMenu;
6bc8a1c8 206 tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
ec9f7884 207 tooltip_menu->AppendSeparator();
6bc8a1c8 208 tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCrtl-T",
ec9f7884
VZ
209 "enable/disable tooltips", TRUE);
210 tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
211 menu_bar->Append(tooltip_menu, "&Tooltips");
16f6dfd8
VZ
212#endif // wxUSE_TOOLTIPS
213
ec9f7884 214 frame->SetMenuBar(menu_bar);
1c005ff7 215
ec9f7884 216 frame->Show(TRUE);
9018abe3 217 frame->SetCursor(wxCursor(wxCURSOR_HAND));
655822f3 218
ec9f7884 219 SetTopWindow(frame);
1c005ff7 220
ec9f7884 221 return TRUE;
1c005ff7
RR
222}
223
6085b116
VZ
224//----------------------------------------------------------------------
225// MyTextCtrl
226//----------------------------------------------------------------------
227
228BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
14531b30 229 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
0a772322 230 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
14531b30 231 EVT_CHAR(MyTextCtrl::OnChar)
6085b116
VZ
232END_EVENT_TABLE()
233
0a772322 234void MyTextCtrl::LogEvent(const char *name, wxKeyEvent& event) const
14531b30 235{
0a772322
VZ
236 wxString key;
237 long keycode = event.KeyCode();
fac2987b 238 if ( isprint((int)keycode) )
0a772322 239 key.Printf("'%c'", (char)keycode);
14531b30
VZ
240 else
241 {
0a772322
VZ
242 switch ( keycode )
243 {
244 case WXK_BACK: key = "BACK"; break;
245 case WXK_TAB: key = "TAB"; break;
246 case WXK_RETURN: key = "RETURN"; break;
247 case WXK_ESCAPE: key = "ESCAPE"; break;
248 case WXK_SPACE: key = "SPACE"; break;
249 case WXK_DELETE: key = "DELETE"; break;
0a772322
VZ
250 case WXK_START: key = "START"; break;
251 case WXK_LBUTTON: key = "LBUTTON"; break;
252 case WXK_RBUTTON: key = "RBUTTON"; break;
253 case WXK_CANCEL: key = "CANCEL"; break;
254 case WXK_MBUTTON: key = "MBUTTON"; break;
255 case WXK_CLEAR: key = "CLEAR"; break;
256 case WXK_SHIFT: key = "SHIFT"; break;
257 case WXK_CONTROL: key = "CONTROL"; break;
258 case WXK_MENU: key = "MENU"; break;
259 case WXK_PAUSE: key = "PAUSE"; break;
260 case WXK_CAPITAL: key = "CAPITAL"; break;
261 case WXK_PRIOR: key = "PRIOR"; break;
262 case WXK_NEXT: key = "NEXT"; break;
263 case WXK_END: key = "END"; break;
264 case WXK_HOME: key = "HOME"; break;
265 case WXK_LEFT: key = "LEFT"; break;
266 case WXK_UP: key = "UP"; break;
267 case WXK_RIGHT: key = "RIGHT"; break;
268 case WXK_DOWN: key = "DOWN"; break;
269 case WXK_SELECT: key = "SELECT"; break;
270 case WXK_PRINT: key = "PRINT"; break;
271 case WXK_EXECUTE: key = "EXECUTE"; break;
272 case WXK_SNAPSHOT: key = "SNAPSHOT"; break;
273 case WXK_INSERT: key = "INSERT"; break;
274 case WXK_HELP: key = "HELP"; break;
275 case WXK_NUMPAD0: key = "NUMPAD0"; break;
276 case WXK_NUMPAD1: key = "NUMPAD1"; break;
277 case WXK_NUMPAD2: key = "NUMPAD2"; break;
278 case WXK_NUMPAD3: key = "NUMPAD3"; break;
279 case WXK_NUMPAD4: key = "NUMPAD4"; break;
280 case WXK_NUMPAD5: key = "NUMPAD5"; break;
281 case WXK_NUMPAD6: key = "NUMPAD6"; break;
282 case WXK_NUMPAD7: key = "NUMPAD7"; break;
283 case WXK_NUMPAD8: key = "NUMPAD8"; break;
284 case WXK_NUMPAD9: key = "NUMPAD9"; break;
285 case WXK_MULTIPLY: key = "MULTIPLY"; break;
286 case WXK_ADD: key = "ADD"; break;
287 case WXK_SEPARATOR: key = "SEPARATOR"; break;
288 case WXK_SUBTRACT: key = "SUBTRACT"; break;
289 case WXK_DECIMAL: key = "DECIMAL"; break;
290 case WXK_DIVIDE: key = "DIVIDE"; break;
291 case WXK_F1: key = "F1"; break;
292 case WXK_F2: key = "F2"; break;
293 case WXK_F3: key = "F3"; break;
294 case WXK_F4: key = "F4"; break;
295 case WXK_F5: key = "F5"; break;
296 case WXK_F6: key = "F6"; break;
297 case WXK_F7: key = "F7"; break;
298 case WXK_F8: key = "F8"; break;
299 case WXK_F9: key = "F9"; break;
300 case WXK_F10: key = "F10"; break;
301 case WXK_F11: key = "F11"; break;
302 case WXK_F12: key = "F12"; break;
303 case WXK_F13: key = "F13"; break;
304 case WXK_F14: key = "F14"; break;
305 case WXK_F15: key = "F15"; break;
306 case WXK_F16: key = "F16"; break;
307 case WXK_F17: key = "F17"; break;
308 case WXK_F18: key = "F18"; break;
309 case WXK_F19: key = "F19"; break;
310 case WXK_F20: key = "F20"; break;
311 case WXK_F21: key = "F21"; break;
312 case WXK_F22: key = "F22"; break;
313 case WXK_F23: key = "F23"; break;
314 case WXK_F24: key = "F24"; break;
315 case WXK_NUMLOCK: key = "NUMLOCK"; break;
316 case WXK_SCROLL: key = "SCROLL"; break;
317 case WXK_PAGEUP: key = "PAGEUP"; break;
318 case WXK_PAGEDOWN: key = "PAGEDOWN"; break;
319 case WXK_NUMPAD_SPACE: key = "NUMPAD_SPACE"; break;
320 case WXK_NUMPAD_TAB: key = "NUMPAD_TAB"; break;
321 case WXK_NUMPAD_ENTER: key = "NUMPAD_ENTER"; break;
322 case WXK_NUMPAD_F1: key = "NUMPAD_F1"; break;
323 case WXK_NUMPAD_F2: key = "NUMPAD_F2"; break;
324 case WXK_NUMPAD_F3: key = "NUMPAD_F3"; break;
325 case WXK_NUMPAD_F4: key = "NUMPAD_F4"; break;
326 case WXK_NUMPAD_HOME: key = "NUMPAD_HOME"; break;
327 case WXK_NUMPAD_LEFT: key = "NUMPAD_LEFT"; break;
328 case WXK_NUMPAD_UP: key = "NUMPAD_UP"; break;
329 case WXK_NUMPAD_RIGHT: key = "NUMPAD_RIGHT"; break;
330 case WXK_NUMPAD_DOWN: key = "NUMPAD_DOWN"; break;
331 case WXK_NUMPAD_PRIOR: key = "NUMPAD_PRIOR"; break;
332 case WXK_NUMPAD_PAGEUP: key = "NUMPAD_PAGEUP"; break;
333 case WXK_NUMPAD_PAGEDOWN: key = "NUMPAD_PAGEDOWN"; break;
334 case WXK_NUMPAD_END: key = "NUMPAD_END"; break;
335 case WXK_NUMPAD_BEGIN: key = "NUMPAD_BEGIN"; break;
336 case WXK_NUMPAD_INSERT: key = "NUMPAD_INSERT"; break;
337 case WXK_NUMPAD_DELETE: key = "NUMPAD_DELETE"; break;
338 case WXK_NUMPAD_EQUAL: key = "NUMPAD_EQUAL"; break;
339 case WXK_NUMPAD_MULTIPLY: key = "NUMPAD_MULTIPLY"; break;
340 case WXK_NUMPAD_ADD: key = "NUMPAD_ADD"; break;
341 case WXK_NUMPAD_SEPARATOR: key = "NUMPAD_SEPARATOR"; break;
342 case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break;
343 case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break;
344
345 default:
346 key.Printf("unknown (%ld)", keycode);
347 }
14531b30 348 }
0a772322
VZ
349
350 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
351 name,
352 key.c_str(),
353 GetChar(event.ControlDown(), 'C'),
354 GetChar(event.AltDown(), 'A'),
355 GetChar(event.ShiftDown(), 'S'),
356 GetChar(event.MetaDown(), 'M'));
357
358}
359
360void MyTextCtrl::OnChar(wxKeyEvent& event)
361{
362 LogEvent("Char", event);
363
364 event.Skip();
365}
366
367void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
368{
369 LogEvent("Key up", event);
14531b30
VZ
370
371 event.Skip();
372}
373
5fb9fcfc 374void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
6085b116
VZ
375{
376 switch ( event.KeyCode() )
377 {
378 case WXK_F1:
379 // show current position and text length
380 {
381 long line, column, pos = GetInsertionPoint();
382 PositionToXY(pos, &column, &line);
383
f70d5829 384 wxLogMessage( _T("Current position: %ld\n"
ec9f7884
VZ
385 "Current line, column: (%ld, %ld)\n"
386 "Number of lines: %ld\n"
387 "Current line length: %ld\n"
f70d5829 388 "Total text length: %ld"),
ec9f7884
VZ
389 pos,
390 line, column,
391 GetNumberOfLines(),
392 GetLineLength(line),
393 GetLastPosition());
6085b116
VZ
394 }
395 break;
396
397 case WXK_F2:
398 // go to the end
399 SetInsertionPointEnd();
400 break;
401
402 case WXK_F3:
403 // go to position 10
404 SetInsertionPoint(10);
405 break;
6085b116 406 }
0a772322
VZ
407
408 LogEvent("Key down", event);
409
410 event.Skip();
6085b116
VZ
411}
412
1c005ff7
RR
413//----------------------------------------------------------------------
414// MyPanel
415//----------------------------------------------------------------------
416
4fabb575 417const int ID_NOTEBOOK = 1000;
1c005ff7 418
4fabb575
JS
419const int ID_LISTBOX = 130;
420const int ID_LISTBOX_SEL_NUM = 131;
421const int ID_LISTBOX_SEL_STR = 132;
422const int ID_LISTBOX_CLEAR = 133;
423const int ID_LISTBOX_APPEND = 134;
424const int ID_LISTBOX_DELETE = 135;
425const int ID_LISTBOX_FONT = 136;
426const int ID_LISTBOX_ENABLE = 137;
1c005ff7 427
4fabb575
JS
428const int ID_CHOICE = 120;
429const int ID_CHOICE_SEL_NUM = 121;
430const int ID_CHOICE_SEL_STR = 122;
431const int ID_CHOICE_CLEAR = 123;
432const int ID_CHOICE_APPEND = 124;
433const int ID_CHOICE_DELETE = 125;
434const int ID_CHOICE_FONT = 126;
435const int ID_CHOICE_ENABLE = 127;
53010e52 436
4fabb575
JS
437const int ID_COMBO = 140;
438const int ID_COMBO_SEL_NUM = 141;
439const int ID_COMBO_SEL_STR = 142;
440const int ID_COMBO_CLEAR = 143;
441const int ID_COMBO_APPEND = 144;
442const int ID_COMBO_DELETE = 145;
443const int ID_COMBO_FONT = 146;
444const int ID_COMBO_ENABLE = 147;
53010e52 445
4fabb575 446const int ID_TEXT = 150;
b527aac5
RR
447const int ID_PASTE_TEXT = 151;
448const int ID_COPY_TEXT = 152;
d59051dd
VZ
449const int ID_MOVE_END_ENTRY = 153;
450const int ID_MOVE_END_ZONE = 154;
219f895a 451
4fabb575
JS
452const int ID_RADIOBOX = 160;
453const int ID_RADIOBOX_SEL_NUM = 161;
454const int ID_RADIOBOX_SEL_STR = 162;
455const int ID_RADIOBOX_FONT = 163;
456const int ID_RADIOBOX_ENABLE = 164;
868a2826 457
f5d29b39
RR
458const int ID_RADIOBUTTON_1 = 166;
459const int ID_RADIOBUTTON_2 = 167;
460
4fabb575 461const int ID_SET_FONT = 170;
47908e25 462
4fabb575
JS
463const int ID_GAUGE = 180;
464const int ID_SLIDER = 181;
58614078 465
4fabb575 466const int ID_SPIN = 182;
9726da4f 467const int ID_BTNPROGRESS = 183;
e380f72b 468
1c005ff7 469BEGIN_EVENT_TABLE(MyPanel, wxPanel)
ec9f7884 470EVT_SIZE ( MyPanel::OnSize)
4d0f3cd6 471EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
ec9f7884
VZ
472EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
473EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
474EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
475EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
476EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
477EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
478EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
479EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
480EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
481EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
482EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
483EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
484EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
485EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
486EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
487EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
488EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
489EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
490EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
491EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
492EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
493EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
494EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
495EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
496EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
497EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
498EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
499EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
500EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
501EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
502EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
503EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
504EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
9726da4f 505#ifndef wxUSE_SPINBUTTON
ec9f7884 506EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
9726da4f
VZ
507EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
508EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
2a47d3c1 509#endif
ec9f7884
VZ
510EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
511EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
512EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText)
513EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry)
1c005ff7
RR
514END_EVENT_TABLE()
515
5fb9fcfc 516MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
0a772322
VZ
517 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
518 m_text(NULL), m_notebook(NULL)
1c005ff7 519{
ec9f7884 520 // SetBackgroundColour("cadet blue");
a81258be 521
ec9f7884
VZ
522 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
523 // m_text->SetBackgroundColour("wheat");
655822f3 524
4d0f3cd6 525 delete wxLog::SetActiveTarget(new wxLogStderr);
0a772322 526
ec9f7884 527 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
655822f3 528
ec9f7884
VZ
529 wxString choices[] =
530 {
531 "This",
532 "is one of my",
533 "really",
534 "wonderful",
535 "examples."
536 };
655822f3 537
4fabb575 538#ifdef USE_XPM
ec9f7884
VZ
539 // image ids
540 enum
541 {
542 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
543 };
544
545 // fill the image list
546 wxImageList *imagelist = new wxImageList(32, 32);
547
548 imagelist-> Add( wxBitmap( list_xpm ));
549 imagelist-> Add( wxBitmap( choice_xpm ));
550 imagelist-> Add( wxBitmap( combo_xpm ));
551 imagelist-> Add( wxBitmap( text_xpm ));
552 imagelist-> Add( wxBitmap( radio_xpm ));
553 imagelist-> Add( wxBitmap( gauge_xpm ));
554 m_notebook->SetImageList(imagelist);
73c700fd 555#elif defined(__WXMSW__)
ec9f7884
VZ
556 // load images from resources
557 enum
558 {
559 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
560 };
561 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
562
563 static const char *s_iconNames[Image_Max] =
564 {
565 "list", "choice", "combo", "text", "radio", "gauge"
566 };
567
568 for ( size_t n = 0; n < Image_Max; n++ )
569 {
570 wxBitmap bmp(s_iconNames[n]);
571 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
572 {
573 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
574 s_iconNames[n], n);
575 }
576 }
577
578 m_notebook->SetImageList(imagelist);
4fabb575
JS
579#else
580
ec9f7884 581 // No images for now
4fabb575
JS
582#define Image_List -1
583#define Image_Choice -1
584#define Image_Combo -1
585#define Image_Text -1
586#define Image_Radio -1
587#define Image_Gauge -1
588#define Image_Max -1
589
fc54776e 590#endif
2cb21a45 591
ec9f7884
VZ
592 wxButton *button = (wxButton*) NULL; /* who did this ? */
593 wxPanel *panel = (wxPanel*) NULL;
9838df2c 594
ec9f7884 595 panel = new wxPanel(m_notebook);
034be888 596 m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices, wxLB_ALWAYS_SB );
ec9f7884 597 m_listbox->SetCursor(*wxCROSS_CURSOR);
b8653fbf 598#if wxUSE_TOOLTIPS
ec9f7884 599 m_listbox->SetToolTip( "This is a list box" );
16f6dfd8 600#endif // wxUSE_TOOLTIPS
9f3362c4 601
ec9f7884
VZ
602 (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
603 (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
604 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
605 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
606 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
034be888 607 button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
b8653fbf 608#if wxUSE_TOOLTIPS
ec9f7884 609 button->SetToolTip( "Press here to set italic font" );
16f6dfd8 610#endif // wxUSE_TOOLTIPS
b1170810 611
0a772322 612 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT );
ec9f7884 613 m_checkbox->SetValue(FALSE);
b8653fbf 614#if wxUSE_TOOLTIPS
ec9f7884 615 m_checkbox->SetToolTip( "Click here to disable the listbox" );
16f6dfd8 616#endif // wxUSE_TOOLTIPS
ec9f7884
VZ
617 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
618
619 panel = new wxPanel(m_notebook);
620 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
2b07d713 621 m_choice->SetBackgroundColour( "red" );
ec9f7884
VZ
622 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
623 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
624 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
625 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
626 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
627 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
628 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
629 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
630
631 panel = new wxPanel(m_notebook);
a260fe6a 632 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY );
ec9f7884
VZ
633 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
634 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
635 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
636 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
637 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
638 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
639 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
640 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
641
642 panel = new wxPanel(m_notebook);
643 m_textentry = new MyTextCtrl( panel, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0);
644 wxTE_PROCESS_ENTER);
645 (*m_textentry) << " Appended.";
646 m_textentry->SetInsertionPoint(0);
647 m_textentry->WriteText( "Prepended. " );
648
649 m_multitext = new MyTextCtrl( panel, ID_TEXT, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE );
650 (*m_multitext) << " Appended.";
651 m_multitext->SetInsertionPoint(0);
652 m_multitext->WriteText( "Prepended. " );
ab46dc18 653 m_multitext->AppendText( "\nPress function keys for test different tests." );
ec9f7884
VZ
654
655 (*m_multitext) << "\nDoes it have cross cursor?";
656 m_multitext->SetCursor(*wxCROSS_CURSOR);
657
658 new MyTextCtrl( panel, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE | wxTE_PROCESS_TAB);
16f6dfd8 659#if wxUSE_TOOLTIPS
ec9f7884
VZ
660 m_multitext->AppendText( "\nThis ctrl has a tooltip. " );
661 m_multitext->SetToolTip("Press F1 here.");
16f6dfd8 662#endif // wxUSE_TOOLTIPS
9f3362c4 663
ec9f7884
VZ
664 (void)new wxStaticBox( panel, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
665 (void)new wxButton( panel, ID_MOVE_END_ENTRY, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
666 (void)new wxButton( panel, ID_MOVE_END_ZONE, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
667 (void)new wxStaticBox( panel, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) );
668 (void)new wxButton( panel, ID_COPY_TEXT, "C&opy line 1", wxPoint(370,120), wxSize(110,30) );
669 (void)new wxButton( panel, ID_PASTE_TEXT, "&Paste text", wxPoint(370,160), wxSize(110,30) );
670 m_notebook->AddPage( panel, "wxTextCtrl" , FALSE, Image_Text );
671
672 wxString choices2[] =
673 {
17867d61 674 "First", "Second",
0a772322 675 /* "Third",
17867d61
RR
676 "Fourth", "Fifth", "Sixth",
677 "Seventh", "Eighth", "Nineth", "Tenth" */
ec9f7884
VZ
678 };
679
680 panel = new wxPanel(m_notebook);
9018abe3
VZ
681 (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
682 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
ec9f7884
VZ
683 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
684 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
685 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
686 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
687 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
688 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
689 rb->SetValue( FALSE );
690 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
691 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
692
693 panel = new wxPanel(m_notebook);
694 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
695 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
858b5bdd 696 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
ec9f7884 697 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
9838df2c 698#ifdef __WXMOTIF__
ec9f7884
VZ
699 // No wrapping text in wxStaticText yet :-(
700 (void)new wxStaticText( panel, -1,
701 "Drag the slider!",
702 wxPoint(208,30),
703 wxSize(210, -1)
704 );
9838df2c 705#else
ec9f7884
VZ
706 (void)new wxStaticText( panel, -1,
707 "In order see the gauge (aka progress bar)\n"
708 "control do something you have to drag the\n"
709 "handle of the slider to the right.\n"
710 "\n"
711 "This is also supposed to demonstrate how\n"
712 "to use static controls.\n",
713 wxPoint(208,25),
714 wxSize(250, 110)
715 );
9838df2c 716#endif
ec9f7884 717 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
9726da4f 718#ifndef wxUSE_SPINBUTTON
ec9f7884 719 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
6380910c
VZ
720 m_spinbutton->SetRange(-10,30);
721 m_spinbutton->SetValue(-5);
9726da4f
VZ
722
723 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog",
724 wxPoint(208, 159) );
2a47d3c1 725#endif
ec9f7884 726 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
1c005ff7
RR
727}
728
b527aac5
RR
729void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
730{
ec9f7884
VZ
731 // We test for wxUSE_DRAG_AND_DROP also, because data objects
732 // may not be implemented for compilers that can't cope with the OLE
733 // parts in wxUSE_DRAG_AND_DROP.
8e0080ee
JS
734
735#if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
ec9f7884
VZ
736 if (!wxTheClipboard->Open())
737 {
738 *m_text << "Error opening the clipboard.\n";
739
740 return;
741 }
742 else
743 {
744 *m_text << "Successfully opened the clipboard.\n";
745 }
746
747 wxTextDataObject data;
748
749 if (wxTheClipboard->IsSupported( data.GetFormat() ))
750 {
751 *m_text << "Clipboard supports requested format.\n";
752
753 if (wxTheClipboard->GetData( &data ))
754 {
755 *m_text << "Successfully retrieved data from the clipboard.\n";
756 *m_multitext << data.GetText() << "\n";
757 }
758 else
759 {
760 *m_text << "Error getting data from the clipboard.\n";
761 }
762 }
763 else
764 {
765 *m_text << "Clipboard doesn't support requested format.\n";
766 }
767
768 wxTheClipboard->Close();
769
770 *m_text << "Closed the clipboard.\n";
341c92a8 771#else
ec9f7884 772 wxLogError("Your version of wxWindows is compiled without clipboard support.");
b527aac5
RR
773#endif
774}
775
776void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
777{
8e0080ee 778#if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
ec9f7884 779 wxString text( m_multitext->GetLineText(0) );
3069ac4e 780
ec9f7884
VZ
781 if (text.IsEmpty())
782 {
783 *m_text << "No text to copy.\n";
b8653fbf 784
ec9f7884
VZ
785 return;
786 }
655822f3 787
ec9f7884
VZ
788 if (!wxTheClipboard->Open())
789 {
790 *m_text << "Error opening the clipboard.\n";
655822f3 791
ec9f7884
VZ
792 return;
793 }
794 else
795 {
796 *m_text << "Successfully opened the clipboard.\n";
797 }
3069ac4e 798
ec9f7884 799 wxTextDataObject *data = new wxTextDataObject( text );
0d2a2b60 800
ec9f7884
VZ
801 if (!wxTheClipboard->SetData( data ))
802 {
803 *m_text << "Error while copying to the clipboard.\n";
804 }
805 else
806 {
807 *m_text << "Successfully copied data to the clipboard.\n";
808 }
8b53e5a2 809
ec9f7884 810 wxTheClipboard->Close();
655822f3 811
ec9f7884 812 *m_text << "Closed the clipboard.\n";
b8653fbf 813#else
ec9f7884 814 wxLogError("Your version of wxWindows is compiled without clipboard support.");
3069ac4e 815#endif
b527aac5
RR
816}
817
d59051dd
VZ
818void MyPanel::OnMoveToEndOfText( wxCommandEvent &event )
819{
820 m_multitext->SetInsertionPointEnd();
821 m_multitext->SetFocus();
822}
823
824void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event )
825{
826 m_textentry->SetInsertionPointEnd();
827 m_textentry->SetFocus();
828}
829
1c005ff7
RR
830void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
831{
ec9f7884
VZ
832 int x = 0;
833 int y = 0;
834 GetClientSize( &x, &y );
655822f3 835
ec9f7884
VZ
836 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
837 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
1c005ff7
RR
838}
839
4d0f3cd6
VZ
840void MyPanel::OnPageChanging( wxNotebookEvent &event )
841{
842 int selNew = event.GetSelection(),
843 selOld = event.GetOldSelection();
844 if ( selOld == 2 && selNew == 4 )
845 {
846 wxMessageBox("This demonstrates how a program may prevent the "
847 "page change from taking place - the current page will "
848 "stay the third one", "Conntrol sample",
849 wxICON_INFORMATION | wxOK);
850
851 event.Veto();
852 }
853 else
854 {
855 *m_text << "Notebook selection is being changed from "
856 << selOld << " to " << selNew << "\n";
857 }
858}
859
cb43b372
RR
860void MyPanel::OnPageChanged( wxNotebookEvent &event )
861{
ec9f7884 862 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
cb43b372
RR
863}
864
1c005ff7
RR
865void MyPanel::OnListBox( wxCommandEvent &event )
866{
19da4326 867 m_text->AppendText( "ListBox event selection string is: " );
ec9f7884
VZ
868 m_text->AppendText( event.GetString() );
869 m_text->AppendText( "\n" );
19da4326
RR
870 m_text->AppendText( "ListBox control selection string is: " );
871 m_text->AppendText( m_listbox->GetStringSelection() );
872 m_text->AppendText( "\n" );
1c005ff7
RR
873}
874
5b077d48
RR
875void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
876{
ec9f7884
VZ
877 m_text->AppendText( "ListBox double click string is: " );
878 m_text->AppendText( event.GetString() );
879 m_text->AppendText( "\n" );
5b077d48
RR
880}
881
47908e25
RR
882void MyPanel::OnListBoxButtons( wxCommandEvent &event )
883{
ec9f7884 884 switch (event.GetId())
d3904ceb 885 {
ec9f7884
VZ
886 case ID_LISTBOX_ENABLE:
887 {
888 m_text->AppendText("Checkbox clicked.\n");
889 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
b8653fbf 890#if wxUSE_TOOLTIPS
ec9f7884
VZ
891 if (event.GetInt())
892 cb->SetToolTip( "Click to enable listbox" );
893 else
894 cb->SetToolTip( "Click to disable listbox" );
16f6dfd8 895#endif // wxUSE_TOOLTIPS
ec9f7884
VZ
896 m_listbox->Enable( event.GetInt() == 0 );
897 break;
898 }
899 case ID_LISTBOX_SEL_NUM:
900 {
901 m_listbox->SetSelection( 2 );
902 break;
903 }
904 case ID_LISTBOX_SEL_STR:
905 {
906 m_listbox->SetStringSelection( "This" );
907 break;
908 }
909 case ID_LISTBOX_CLEAR:
910 {
911 m_listbox->Clear();
912 break;
913 }
914 case ID_LISTBOX_APPEND:
915 {
916 m_listbox->Append( "Hi!" );
917 break;
918 }
919 case ID_LISTBOX_DELETE:
920 {
921 int idx = m_listbox->GetSelection();
922 m_listbox->Delete( idx );
923 break;
924 }
925 case ID_LISTBOX_FONT:
926 {
927 m_listbox->SetFont( *wxITALIC_FONT );
928 m_checkbox->SetFont( *wxITALIC_FONT );
929 break;
930 }
868a2826 931 }
47908e25
RR
932}
933
934void MyPanel::OnChoice( wxCommandEvent &event )
935{
19da4326 936 m_text->AppendText( "Choice event selection string is: " );
ec9f7884
VZ
937 m_text->AppendText( event.GetString() );
938 m_text->AppendText( "\n" );
19da4326
RR
939 m_text->AppendText( "Choice control selection string is: " );
940 m_text->AppendText( m_choice->GetStringSelection() );
941 m_text->AppendText( "\n" );
47908e25
RR
942}
943
944void MyPanel::OnChoiceButtons( wxCommandEvent &event )
945{
ec9f7884 946 switch (event.GetId())
47908e25 947 {
ec9f7884
VZ
948 case ID_CHOICE_ENABLE:
949 {
950 m_choice->Enable( event.GetInt() == 0 );
951 break;
952 }
953 case ID_CHOICE_SEL_NUM:
954 {
955 m_choice->SetSelection( 2 );
956 break;
957 }
958 case ID_CHOICE_SEL_STR:
959 {
960 m_choice->SetStringSelection( "This" );
961 break;
962 }
963 case ID_CHOICE_CLEAR:
964 {
965 m_choice->Clear();
966 break;
967 }
968 case ID_CHOICE_APPEND:
969 {
970 m_choice->Append( "Hi!" );
971 break;
972 }
973 case ID_CHOICE_DELETE:
974 {
975 int idx = m_choice->GetSelection();
976 m_choice->Delete( idx );
977 break;
978 }
979 case ID_CHOICE_FONT:
980 {
981 m_choice->SetFont( *wxITALIC_FONT );
982 break;
983 }
868a2826 984 }
47908e25
RR
985}
986
987void MyPanel::OnCombo( wxCommandEvent &event )
988{
19da4326 989 m_text->AppendText( "ComboBox event selection string is: " );
ec9f7884
VZ
990 m_text->AppendText( event.GetString() );
991 m_text->AppendText( "\n" );
19da4326
RR
992 m_text->AppendText( "ComboBox control selection string is: " );
993 m_text->AppendText( m_combo->GetStringSelection() );
994 m_text->AppendText( "\n" );
47908e25
RR
995}
996
997void MyPanel::OnComboButtons( wxCommandEvent &event )
1c005ff7 998{
ec9f7884 999 switch (event.GetId())
2f6407b9 1000 {
ec9f7884
VZ
1001 case ID_COMBO_ENABLE:
1002 {
1003 m_combo->Enable( event.GetInt() == 0 );
1004 break;
1005 }
1006 case ID_COMBO_SEL_NUM:
1007 {
1008 m_combo->SetSelection( 2 );
1009 break;
1010 }
1011 case ID_COMBO_SEL_STR:
1012 {
1013 m_combo->SetStringSelection( "This" );
1014 break;
1015 }
1016 case ID_COMBO_CLEAR:
1017 {
1018 m_combo->Clear();
1019 break;
1020 }
1021 case ID_COMBO_APPEND:
1022 {
1023 m_combo->Append( "Hi!" );
1024 break;
1025 }
1026 case ID_COMBO_DELETE:
1027 {
1028 int idx = m_combo->GetSelection();
1029 m_combo->Delete( idx );
1030 break;
1031 }
1032 case ID_COMBO_FONT:
1033 {
1034 m_combo->SetFont( *wxITALIC_FONT );
1035 break;
1036 }
868a2826 1037 }
47908e25
RR
1038}
1039
1040void MyPanel::OnRadio( wxCommandEvent &event )
1041{
ec9f7884
VZ
1042 m_text->AppendText( "RadioBox selection string is: " );
1043 m_text->AppendText( event.GetString() );
1044 m_text->AppendText( "\n" );
47908e25
RR
1045}
1046
1047void MyPanel::OnRadioButtons( wxCommandEvent &event )
1048{
ec9f7884 1049 switch (event.GetId())
d3904ceb 1050 {
ec9f7884
VZ
1051 case ID_RADIOBOX_ENABLE:
1052 {
1053 m_radio->Enable( event.GetInt() == 0 );
1054 break;
1055 }
1056 case ID_RADIOBOX_SEL_NUM:
1057 {
1058 m_radio->SetSelection( 2 );
1059 break;
1060 }
1061 case ID_RADIOBOX_SEL_STR:
1062 {
1063 m_radio->SetStringSelection( "This" );
1064 break;
1065 }
1066 case ID_RADIOBOX_FONT:
1067 {
1068 m_radio->SetFont( *wxITALIC_FONT );
1069 break;
1070 }
868a2826 1071 }
1c005ff7
RR
1072}
1073
868a2826
RR
1074void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1075{
ec9f7884
VZ
1076 m_fontButton->SetFont( *wxITALIC_FONT );
1077 m_text->SetFont( *wxITALIC_FONT );
868a2826
RR
1078}
1079
7bce6aec
RR
1080void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1081{
ec9f7884 1082 m_gauge->SetValue( m_slider->GetValue() );
7bce6aec
RR
1083}
1084
9726da4f 1085#ifndef wxUSE_SPINBUTTON
e380f72b
RR
1086void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1087{
ec9f7884 1088 wxString value;
f70d5829 1089 value.Printf( _T("%d"), event.GetPosition() );
ec9f7884 1090 m_spintext->SetValue( value );
6380910c 1091
f70d5829 1092 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
6380910c
VZ
1093 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1094 m_spinbutton->GetValue());
1095
1096 m_text->AppendText(value);
e380f72b 1097}
9726da4f
VZ
1098
1099void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1100{
1101 event.Enable( m_spinbutton->GetValue() > 0 );
1102}
1103
1104void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1105{
1106 int max = m_spinbutton->GetValue();
1107 wxProgressDialog dialog("Progress dialog example",
1108 "An informative message",
1109 max, // range
1110 this, // parent
be9abe3f
VZ
1111 wxPD_CAN_ABORT | wxPD_APP_MODAL);
1112
9726da4f
VZ
1113
1114 bool cont = TRUE;
1115 for ( int i = 0; i < max && cont; i++ )
1116 {
1117 wxSleep(1);
be9abe3f
VZ
1118 if ( i == max - 1 )
1119 {
1120 cont = dialog.Update(i, "That's all, folks!");
1121 }
1122 else if ( i == max / 2 )
9726da4f
VZ
1123 {
1124 cont = dialog.Update(i, "Only a half left!");
1125 }
1126 else
1127 {
1128 cont = dialog.Update(i);
1129 }
1130 }
1131
1132 if ( !cont )
1133 {
1134 *m_text << "Progress dialog aborted!\n";
1135 }
1136 else
1137 {
1138 *m_text << "Countdown from " << max << " finished.\n";
1139 }
1140}
1141
1142#endif // wxUSE_SPINBUTTON
e380f72b 1143
2cb21a45
VZ
1144MyPanel::~MyPanel()
1145{
ec9f7884 1146 delete m_notebook->GetImageList();
2cb21a45
VZ
1147}
1148
1c005ff7
RR
1149//----------------------------------------------------------------------
1150// MyFrame
1151//----------------------------------------------------------------------
1152
1153BEGIN_EVENT_TABLE(MyFrame, wxFrame)
ec9f7884
VZ
1154EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
1155EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
16f6dfd8 1156#if wxUSE_TOOLTIPS
ec9f7884
VZ
1157EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1158EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
16f6dfd8 1159#endif // wxUSE_TOOLTIPS
ec9f7884
VZ
1160EVT_SIZE(MyFrame::OnSize)
1161EVT_IDLE(MyFrame::OnIdle)
1c005ff7
RR
1162END_EVENT_TABLE()
1163
9f3362c4 1164MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
ec9f7884 1165: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1c005ff7 1166{
5fb9fcfc 1167 CreateStatusBar(2);
9f3362c4
VZ
1168
1169 (void)new MyPanel( this, 10, 10, 300, 100 );
1c005ff7
RR
1170}
1171
1172void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1173{
ec9f7884 1174 Close(TRUE);
1c005ff7
RR
1175}
1176
1177void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1178{
ec9f7884
VZ
1179 wxBeginBusyCursor();
1180
1181 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
1182 dialog.ShowModal();
1183
1184 wxEndBusyCursor();
1c005ff7 1185}
9f3362c4 1186
16f6dfd8
VZ
1187#if wxUSE_TOOLTIPS
1188void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1189{
1190 static long s_delay = 5000;
1191
1192 wxString delay;
f70d5829 1193 delay.Printf( _T("%ld"), s_delay);
16f6dfd8
VZ
1194
1195 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
ec9f7884
VZ
1196 "Set tooltip delay",
1197 delay,
1198 this);
16f6dfd8
VZ
1199 if ( !delay )
1200 return; // cancelled
1201
f70d5829 1202 wxSscanf(delay, _T("%ld"), &s_delay);
16f6dfd8
VZ
1203
1204 wxToolTip::SetDelay(s_delay);
1205
f70d5829 1206 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
16f6dfd8
VZ
1207}
1208
1209void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1210{
1211 static bool s_enabled = TRUE;
1212
1213 s_enabled = !s_enabled;
1214
1215 wxToolTip::Enable(s_enabled);
1216
f70d5829 1217 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
16f6dfd8
VZ
1218}
1219#endif // tooltips
1220
5fb9fcfc
VZ
1221void MyFrame::OnSize( wxSizeEvent& event )
1222{
1223 wxString msg;
f70d5829 1224 msg.Printf( _("%dx%d"), event.GetSize().x, event.GetSize().y);
5fb9fcfc
VZ
1225 SetStatusText(msg, 1);
1226
1227 event.Skip();
1228}
1229
9f3362c4
VZ
1230void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1231{
1232 // track the window which has the focus in the status bar
1233 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1234 wxWindow *focus = wxWindow::FindFocus();
1235 if ( focus && (focus != s_windowFocus) )
1236 {
1237 s_windowFocus = focus;
1238
1239 wxString msg;
f70d5829 1240 msg.Printf(
9f3362c4 1241#ifdef __WXMSW__
f70d5829
RR
1242 _T("Focus: wxWindow = %p, HWND = %08x"),
1243#else
1244 _T("Focus: wxWindow = %p"),
1245#endif
1246 s_windowFocus
9f3362c4 1247#ifdef __WXMSW__
ec9f7884 1248 , s_windowFocus->GetHWND()
f70d5829 1249#endif
9f3362c4
VZ
1250 );
1251
1252 SetStatusText(msg);
1253 }
341c92a8 1254}