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