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