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