]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
a29183cd19397579ba242fd941381acdf15d1d9c
[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 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
27 #include "wx/spinbutt.h"
28 #endif
29 #include "wx/notebook.h"
30 #include "wx/imaglist.h"
31
32 #if wxUSE_TOOLTIPS
33 #include "wx/tooltip.h"
34 #endif
35
36 #if defined(__WXGTK__) || defined(__WXMOTIF__)
37 #define USE_XPM
38 #endif
39
40 #ifdef USE_XPM
41 #include "mondrian.xpm"
42 #include "icons/choice.xpm"
43 #include "icons/combo.xpm"
44 #include "icons/list.xpm"
45 #include "icons/radio.xpm"
46 #include "icons/text.xpm"
47 #include "icons/gauge.xpm"
48 #endif
49
50 #ifdef __WIN16__
51 // Win16 doesn't have them
52 #ifdef wxUSE_SPINBTN
53 #undef wxUSE_SPINBTN
54 #endif
55 #define wxUSE_SPINBTN 0
56 #else
57 #ifndef wxUSE_SPINBTN
58 #define wxUSE_SPINBTN 1
59 #endif
60 #endif // __WIN16__
61
62 #include "wx/progdlg.h"
63
64 #if wxUSE_SPINCTRL
65 #include "wx/spinctrl.h"
66 #endif // wxUSE_SPINCTRL
67
68 #include "wx/generic/calctrl.h"
69
70 //----------------------------------------------------------------------
71 // class definitions
72 //----------------------------------------------------------------------
73
74 class MyApp: public wxApp
75 {
76 public:
77 bool OnInit();
78 };
79
80 class MyPanel: public wxPanel
81 {
82 public:
83 MyPanel(wxFrame *frame, int x, int y, int w, int h);
84 virtual ~MyPanel();
85
86 void OnSize( wxSizeEvent& event );
87 void OnListBox( wxCommandEvent &event );
88 void OnListBoxDoubleClick( wxCommandEvent &event );
89 void OnListBoxButtons( wxCommandEvent &event );
90 void OnChoice( wxCommandEvent &event );
91 void OnChoiceButtons( wxCommandEvent &event );
92 void OnCombo( wxCommandEvent &event );
93 void OnComboButtons( wxCommandEvent &event );
94 void OnRadio( wxCommandEvent &event );
95 void OnRadioButtons( wxCommandEvent &event );
96 void OnSetFont( wxCommandEvent &event );
97 void OnPageChanged( wxNotebookEvent &event );
98 void OnPageChanging( wxNotebookEvent &event );
99 void OnSliderUpdate( wxCommandEvent &event );
100 void OnUpdateLabel( wxCommandEvent &event );
101 #if wxUSE_SPINBTN
102 void OnSpinUp( wxSpinEvent &event );
103 void OnSpinDown( wxSpinEvent &event );
104 void OnSpinUpdate( wxSpinEvent &event );
105 void OnUpdateShowProgress( wxUpdateUIEvent& event );
106 void OnShowProgress( wxCommandEvent &event );
107 #endif // wxUSE_SPINBTN
108
109 #if wxUSE_SPINCTRL
110 void OnSpinCtrl(wxCommandEvent& event);
111 #endif // wxUSE_SPINCTRL
112
113 void OnEnableAll(wxCommandEvent& event);
114 void OnChangeColour(wxCommandEvent& event);
115
116 wxListBox *m_listbox,
117 *m_listboxSorted;
118 wxChoice *m_choice,
119 *m_choiceSorted;
120 wxComboBox *m_combo;
121 wxRadioBox *m_radio;
122 wxGauge *m_gauge;
123 wxSlider *m_slider;
124 wxButton *m_fontButton;
125 wxButton *m_lbSelectNum;
126 wxButton *m_lbSelectThis;
127 #if wxUSE_SPINBTN
128 wxSpinButton *m_spinbutton;
129 wxButton *m_btnProgress;
130 #endif // wxUSE_SPINBTN
131
132 #if wxUSE_SPINCTRL
133 wxSpinCtrl *m_spinctrl;
134 #endif // wxUSE_SPINCTRL
135
136 wxTextCtrl *m_spintext;
137 wxCheckBox *m_checkbox;
138
139 wxTextCtrl *m_text;
140 wxNotebook *m_notebook;
141
142 wxStaticText *m_label;
143
144 private:
145 DECLARE_EVENT_TABLE()
146 };
147
148 class MyFrame: public wxFrame
149 {
150 public:
151 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
152
153 void OnQuit(wxCommandEvent& event);
154 void OnAbout(wxCommandEvent& event);
155
156 #if wxUSE_TOOLTIPS
157 void OnSetTooltipDelay(wxCommandEvent& event);
158 void OnToggleTooltips(wxCommandEvent& event);
159 #endif // wxUSE_TOOLTIPS
160
161 void OnEnableAll(wxCommandEvent& event);
162
163 void OnIdle( wxIdleEvent& event );
164 void OnSize( wxSizeEvent& event );
165 void OnMove( wxMoveEvent& event );
166
167 MyPanel *GetPanel() const { return m_panel; }
168
169 private:
170 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
171 {
172 wxString msg;
173 msg.Printf(_("pos=(%d, %d), size=%dx%d"),
174 pos.x, pos.y, size.x, size.y);
175 SetStatusText(msg, 1);
176 }
177
178 MyPanel *m_panel;
179
180 DECLARE_EVENT_TABLE()
181 };
182
183 //----------------------------------------------------------------------
184 // other
185 //----------------------------------------------------------------------
186
187 static void SetControlClientData(const char *name,
188 wxControlWithItems *control);
189
190 IMPLEMENT_APP(MyApp)
191
192 //----------------------------------------------------------------------
193 // MyApp
194 //----------------------------------------------------------------------
195
196 enum
197 {
198 MINIMAL_QUIT = 100,
199 MINIMAL_TEXT,
200 MINIMAL_ABOUT,
201
202 // tooltip menu
203 MINIMAL_SET_TOOLTIP_DELAY = 200,
204 MINIMAL_ENABLE_TOOLTIPS,
205
206 // panel menu
207 MINIMAL_ENABLE_ALL
208 };
209
210 bool MyApp::OnInit()
211 {
212 // parse the cmd line
213 int x = 50,
214 y = 50;
215 if ( argc == 2 )
216 {
217 wxSscanf(argv[1], "%d", &x);
218 wxSscanf(argv[2], "%d", &y);
219 }
220
221 // Create the main frame window
222 MyFrame *frame = new MyFrame((wxFrame *) NULL,
223 "Controls wxWindows App",
224 x, y, 540, 430);
225
226 frame->SetSizeHints( 500, 425 );
227
228 // Give it an icon
229 // The wxICON() macros loads an icon from a resource under Windows
230 // and uses an #included XPM image under GTK+ and Motif
231
232 frame->SetIcon( wxICON(mondrian) );
233
234 wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF);
235
236 file_menu->Append(MINIMAL_ABOUT, "&About\tF1");
237 file_menu->AppendSeparator();
238 file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample");
239
240 wxMenuBar *menu_bar = new wxMenuBar;
241 menu_bar->Append(file_menu, "&File");
242
243 #if wxUSE_TOOLTIPS
244 wxMenu *tooltip_menu = new wxMenu;
245 tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
246 tooltip_menu->AppendSeparator();
247 tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
248 "enable/disable tooltips", TRUE);
249 tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
250 menu_bar->Append(tooltip_menu, "&Tooltips");
251 #endif // wxUSE_TOOLTIPS
252
253 wxMenu *panel_menu = new wxMenu;
254 panel_menu->Append(MINIMAL_ENABLE_ALL, "&Disable all\tCtrl-E",
255 "Enable/disable all panel controls", TRUE);
256 menu_bar->Append(panel_menu, "&Panel");
257
258 frame->SetMenuBar(menu_bar);
259
260 frame->Show(TRUE);
261 frame->SetCursor(wxCursor(wxCURSOR_HAND));
262
263 frame->GetPanel()->m_notebook->SetSelection(5);
264
265 SetTopWindow(frame);
266
267 return TRUE;
268 }
269
270 //----------------------------------------------------------------------
271 // MyPanel
272 //----------------------------------------------------------------------
273
274 const int ID_NOTEBOOK = 1000;
275
276 const int ID_LISTBOX = 130;
277 const int ID_LISTBOX_SEL_NUM = 131;
278 const int ID_LISTBOX_SEL_STR = 132;
279 const int ID_LISTBOX_CLEAR = 133;
280 const int ID_LISTBOX_APPEND = 134;
281 const int ID_LISTBOX_DELETE = 135;
282 const int ID_LISTBOX_FONT = 136;
283 const int ID_LISTBOX_ENABLE = 137;
284 const int ID_LISTBOX_SORTED = 138;
285
286 const int ID_CHOICE = 120;
287 const int ID_CHOICE_SEL_NUM = 121;
288 const int ID_CHOICE_SEL_STR = 122;
289 const int ID_CHOICE_CLEAR = 123;
290 const int ID_CHOICE_APPEND = 124;
291 const int ID_CHOICE_DELETE = 125;
292 const int ID_CHOICE_FONT = 126;
293 const int ID_CHOICE_ENABLE = 127;
294 const int ID_CHOICE_SORTED = 128;
295
296 const int ID_COMBO = 140;
297 const int ID_COMBO_SEL_NUM = 141;
298 const int ID_COMBO_SEL_STR = 142;
299 const int ID_COMBO_CLEAR = 143;
300 const int ID_COMBO_APPEND = 144;
301 const int ID_COMBO_DELETE = 145;
302 const int ID_COMBO_FONT = 146;
303 const int ID_COMBO_ENABLE = 147;
304
305 const int ID_RADIOBOX = 160;
306 const int ID_RADIOBOX_SEL_NUM = 161;
307 const int ID_RADIOBOX_SEL_STR = 162;
308 const int ID_RADIOBOX_FONT = 163;
309 const int ID_RADIOBOX_ENABLE = 164;
310
311 const int ID_RADIOBUTTON_1 = 166;
312 const int ID_RADIOBUTTON_2 = 167;
313
314 const int ID_SET_FONT = 170;
315
316 const int ID_GAUGE = 180;
317 const int ID_SLIDER = 181;
318
319 const int ID_SPIN = 182;
320 const int ID_BTNPROGRESS = 183;
321 const int ID_BUTTON_LABEL = 184;
322 const int ID_SPINCTRL = 185;
323
324 const int ID_CHANGE_COLOUR = 200;
325
326 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
327 EVT_SIZE ( MyPanel::OnSize)
328 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
329 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
330 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
331 EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
332 EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
333 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
334 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
335 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
336 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
337 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
338 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
339 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
340 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
341 EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
342 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
343 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
344 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
345 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
346 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
347 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
348 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
349 EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
350 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
351 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
352 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
353 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
354 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
355 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
356 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
357 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
358 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
359 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
360 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
361 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
362 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
363 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
364 #if wxUSE_SPINBTN
365 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
366 EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
367 EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
368 EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
369 EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
370 #endif // wxUSE_SPINBTN
371 #if wxUSE_SPINCTRL
372 EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
373 #endif // wxUSE_SPINCTRL
374 EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
375 EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
376 END_EVENT_TABLE()
377
378 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
379 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
380 m_text(NULL), m_notebook(NULL)
381 {
382 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
383 // m_text->SetBackgroundColour("wheat");
384
385 //delete wxLog::SetActiveTarget(new wxLogStderr);
386
387 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
388
389 wxString choices[] =
390 {
391 "This",
392 "is one of my",
393 "really",
394 "wonderful",
395 "examples."
396 };
397
398 #ifdef USE_XPM
399 // image ids
400 enum
401 {
402 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
403 };
404
405 // fill the image list
406 wxImageList *imagelist = new wxImageList(32, 32);
407
408 imagelist-> Add( wxBitmap( list_xpm ));
409 imagelist-> Add( wxBitmap( choice_xpm ));
410 imagelist-> Add( wxBitmap( combo_xpm ));
411 imagelist-> Add( wxBitmap( text_xpm ));
412 imagelist-> Add( wxBitmap( radio_xpm ));
413 imagelist-> Add( wxBitmap( gauge_xpm ));
414 m_notebook->SetImageList(imagelist);
415 #elif defined(__WXMSW__)
416 // load images from resources
417 enum
418 {
419 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
420 };
421 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
422
423 static const char *s_iconNames[Image_Max] =
424 {
425 "list", "choice", "combo", "text", "radio", "gauge"
426 };
427
428 for ( size_t n = 0; n < Image_Max; n++ )
429 {
430 wxBitmap bmp(s_iconNames[n]);
431 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
432 {
433 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
434 s_iconNames[n], n);
435 }
436 }
437
438 m_notebook->SetImageList(imagelist);
439 #else
440
441 // No images for now
442 #define Image_List -1
443 #define Image_Choice -1
444 #define Image_Combo -1
445 #define Image_Text -1
446 #define Image_Radio -1
447 #define Image_Gauge -1
448 #define Image_Max -1
449
450 #endif
451
452 wxPanel *panel = new wxPanel(m_notebook);
453 m_listbox = new wxListBox( panel, ID_LISTBOX,
454 wxPoint(10,10), wxSize(120,70),
455 5, choices, wxLB_ALWAYS_SB );
456 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
457 wxPoint(10,90), wxSize(120,70),
458 5, choices, wxLB_SORT );
459
460 SetControlClientData("listbox", m_listbox);
461 SetControlClientData("listbox", m_listboxSorted);
462
463 m_listbox->SetCursor(*wxCROSS_CURSOR);
464 #if wxUSE_TOOLTIPS
465 m_listbox->SetToolTip( "This is a list box" );
466 #endif // wxUSE_TOOLTIPS
467
468 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
469 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
470 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
471 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
472 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
473 wxButton *button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
474
475 button->SetDefault();
476
477 button->SetForegroundColour(*wxBLUE);
478
479 #if wxUSE_TOOLTIPS
480 button->SetToolTip( "Press here to set italic font" );
481 #endif // wxUSE_TOOLTIPS
482
483 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,170) );
484 m_checkbox->SetValue(FALSE);
485 #if wxUSE_TOOLTIPS
486 m_checkbox->SetToolTip( "Click here to disable the listbox" );
487 #endif // wxUSE_TOOLTIPS
488 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, "&Toggle colour",
489 wxPoint(110,170) );
490 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
491
492 panel = new wxPanel(m_notebook);
493 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
494 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
495 5, choices, wxCB_SORT );
496
497 #ifndef __WXMOTIF__
498 SetControlClientData("choice", m_choice);
499 SetControlClientData("choice", m_choiceSorted);
500 #endif
501
502 m_choice->SetSelection(2);
503 m_choice->SetBackgroundColour( "red" );
504 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
505 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
506 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
507 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
508 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
509 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
510 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
511
512 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
513
514 panel = new wxPanel(m_notebook);
515 (void)new wxStaticBox( panel, -1, "Box around combobox",
516 wxPoint(5, 5), wxSize(150, 100));
517 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(20,20), wxSize(120,-1), 5, choices, wxCB_READONLY );
518 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
519 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
520 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
521 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
522 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
523 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
524 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
525 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
526
527 wxString choices2[] =
528 {
529 "First", "Second",
530 /* "Third",
531 "Fourth", "Fifth", "Sixth",
532 "Seventh", "Eighth", "Nineth", "Tenth" */
533 };
534
535 panel = new wxPanel(m_notebook);
536 (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
537 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
538
539 #if wxUSE_TOOLTIPS
540 m_radio->SetToolTip("Ever seen a radiobox?");
541 #endif // wxUSE_TOOLTIPS
542
543 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
544 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
545 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
546 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
547 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
548 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP );
549 rb->SetValue( FALSE );
550 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
551 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
552
553 panel = new wxPanel(m_notebook);
554 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
555 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
556 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
557 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
558 #ifdef __WXMOTIF__
559 // No wrapping text in wxStaticText yet :-(
560 (void)new wxStaticText( panel, -1,
561 "Drag the slider!",
562 wxPoint(228,30),
563 wxSize(240, -1)
564 );
565 #else
566 (void)new wxStaticText( panel, -1,
567 "In order see the gauge (aka progress bar)\n"
568 "control do something you have to drag the\n"
569 "handle of the slider to the right.\n"
570 "\n"
571 "This is also supposed to demonstrate how\n"
572 "to use static controls.\n",
573 wxPoint(228,25),
574 wxSize(240, 110)
575 );
576 #endif
577 int initialSpinValue = -5;
578 wxString s;
579 s << initialSpinValue;
580 m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) );
581 #if wxUSE_SPINBTN
582 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, -1) );
583 m_spinbutton->SetRange(-10,30);
584 m_spinbutton->SetValue(initialSpinValue);
585
586 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog",
587 wxPoint(300, 160) );
588 #endif // wxUSE_SPINBTN
589
590 #if wxUSE_SPINCTRL
591 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) );
592 m_spinctrl->SetRange(10,30);
593 m_spinctrl->SetValue(15);
594 #endif // wxUSE_SPINCTRL
595
596 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
597
598 panel = new wxPanel(m_notebook);
599
600 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
601 wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
602 wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
603 wxPoint(10, 10));
604
605 bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
606 bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
607 #endif // !Motif
608
609 wxBitmap bitmap( 100, 100 );
610 wxMemoryDC dc;
611 dc.SelectObject( bitmap );
612 dc.SetPen(*wxGREEN_PEN);
613 dc.Clear();
614 dc.DrawEllipse(5, 5, 90, 90);
615 dc.DrawText("Bitmap", 30, 40);
616 dc.SelectObject( wxNullBitmap );
617
618 (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
619
620 #if 0
621 bitmap = wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
622 wxBITMAP_TYPE_BMP);
623 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
624 (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(300, 120));
625 #endif
626
627 wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
628 bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
629 bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
630 wxBitmapButton *bmpBtn = new wxBitmapButton
631 (
632 panel, -1,
633 bmp1,
634 wxPoint(30, 50)
635 );
636 bmpBtn->SetBitmapSelected(bmp2);
637 bmpBtn->SetBitmapFocus(bmp3);
638
639 (void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20));
640 m_label = new wxStaticText(panel, -1, "Label with some long text",
641 wxPoint(250, 60), wxDefaultSize,
642 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
643
644 m_notebook->AddPage(panel, "wxBitmapXXX");
645
646 panel = new wxPanel(m_notebook);
647 (void)new wxCalendarCtrl(panel, -1);
648 m_notebook->AddPage(panel, "wxCalendar");
649
650 // --------------- TEST CODE ----------------------
651
652 // layout constraints
653
654 panel = new wxPanel(m_notebook);
655 panel->SetAutoLayout( TRUE );
656
657 wxLayoutConstraints *c;
658 c = new wxLayoutConstraints;
659 c->top.SameAs( panel, wxTop, 10 );
660 c->height.AsIs( );
661 c->left.SameAs( panel, wxLeft, 10 );
662 c->width.PercentOf( panel, wxWidth, 40 );
663
664 wxButton *pMyButton = new wxButton(panel, -1, "Test Button" );
665 pMyButton->SetConstraints( c );
666
667 c = new wxLayoutConstraints;
668 c->top.SameAs( panel, wxTop, 10 );
669 c->bottom.SameAs( panel, wxBottom, 10 );
670 c->right.SameAs( panel, wxRight, 10 );
671 c->width.PercentOf( panel, wxWidth, 40 );
672
673 wxButton *pMyButton2 = new wxButton(panel, -1, "Test Button 2" );
674 pMyButton2->SetConstraints( c );
675
676 m_notebook->AddPage(panel, "wxLayoutConstraint");
677
678 // sizer
679
680 panel = new wxPanel(m_notebook);
681 panel->SetAutoLayout( TRUE );
682
683 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
684
685 sizer->Add( new wxButton(panel, -1, "Test Button" ), 3, wxALL, 10 );
686 sizer->Add( 20,20, 1 );
687 sizer->Add( new wxButton(panel, -1, "Test Button 2" ), 3, wxGROW|wxALL, 10 );
688
689 panel->SetSizer( sizer );
690
691 m_notebook->AddPage(panel, "wxSizer");
692
693 // --------------- TEST CODE ----------------------
694
695 }
696
697 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
698 {
699 int x = 0;
700 int y = 0;
701 GetClientSize( &x, &y );
702
703 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
704 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
705 }
706
707 void MyPanel::OnPageChanging( wxNotebookEvent &event )
708 {
709 int selOld = event.GetOldSelection();
710 if ( selOld == 2 )
711 {
712 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
713 "page change from taking place - if you select\n"
714 "[No] the current page will stay the third one\n",
715 "Control sample",
716 wxICON_QUESTION | wxYES_NO) != wxYES )
717 {
718 event.Veto();
719
720 return;
721 }
722 }
723
724 *m_text << "Notebook selection is being changed from " << selOld << "\n";
725 }
726
727 void MyPanel::OnPageChanged( wxNotebookEvent &event )
728 {
729 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
730 }
731
732 void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
733 {
734 static wxColour s_colOld;
735
736 // test panel colour changing and propagation to the subcontrols
737 if ( s_colOld.Ok() )
738 {
739 SetBackgroundColour(s_colOld);
740 s_colOld = wxNullColour;
741
742 m_lbSelectThis->SetForegroundColour("yellow");
743 m_lbSelectThis->SetBackgroundColour("blue");
744 }
745 else
746 {
747 s_colOld = GetBackgroundColour();
748 SetBackgroundColour("green");
749
750 m_lbSelectThis->SetForegroundColour("white");
751 m_lbSelectThis->SetBackgroundColour("red");
752 }
753
754 m_lbSelectThis->Refresh();
755 Refresh();
756 }
757
758 void MyPanel::OnListBox( wxCommandEvent &event )
759 {
760 // GetParent()->Move(100, 100);
761
762 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
763 : m_listboxSorted;
764
765 m_text->AppendText( "ListBox event selection string is: '" );
766 m_text->AppendText( event.GetString() );
767 m_text->AppendText( "'\n" );
768 m_text->AppendText( "ListBox control selection string is: '" );
769 m_text->AppendText( listbox->GetStringSelection() );
770 m_text->AppendText( "'\n" );
771
772 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
773 m_text->AppendText( "ListBox event client data string is: '" );
774 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
775 m_text->AppendText( obj->GetData() );
776 else
777 m_text->AppendText( wxString("none") );
778
779 m_text->AppendText( "'\n" );
780 m_text->AppendText( "ListBox control client data string is: '" );
781 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
782 if (obj)
783 m_text->AppendText( obj->GetData() );
784 else
785 m_text->AppendText( wxString("none") );
786 m_text->AppendText( "'\n" );
787 }
788
789 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
790 {
791 m_text->AppendText( "ListBox double click string is: " );
792 m_text->AppendText( event.GetString() );
793 m_text->AppendText( "\n" );
794 }
795
796 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
797 {
798 switch (event.GetId())
799 {
800 case ID_LISTBOX_ENABLE:
801 {
802 m_text->AppendText("Checkbox clicked.\n");
803 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
804 #if wxUSE_TOOLTIPS
805 if (event.GetInt())
806 cb->SetToolTip( "Click to enable listbox" );
807 else
808 cb->SetToolTip( "Click to disable listbox" );
809 #endif // wxUSE_TOOLTIPS
810 m_listbox->Enable( event.GetInt() == 0 );
811 m_lbSelectThis->Enable( event.GetInt() == 0 );
812 m_lbSelectNum->Enable( event.GetInt() == 0 );
813 m_listboxSorted->Enable( event.GetInt() == 0 );
814 break;
815 }
816 case ID_LISTBOX_SEL_NUM:
817 {
818 m_listbox->SetSelection( 2 );
819 m_listboxSorted->SetSelection( 2 );
820 m_lbSelectThis->WarpPointer( 40, 14 );
821 break;
822 }
823 case ID_LISTBOX_SEL_STR:
824 {
825 m_listbox->SetStringSelection( "This" );
826 m_listboxSorted->SetStringSelection( "This" );
827 m_lbSelectNum->WarpPointer( 40, 14 );
828 break;
829 }
830 case ID_LISTBOX_CLEAR:
831 {
832 m_listbox->Clear();
833 m_listboxSorted->Clear();
834 break;
835 }
836 case ID_LISTBOX_APPEND:
837 {
838 m_listbox->Append( "Hi!" );
839 m_listboxSorted->Append( "Hi!" );
840 break;
841 }
842 case ID_LISTBOX_DELETE:
843 {
844 int idx;
845 idx = m_listbox->GetSelection();
846 m_listbox->Delete( idx );
847 idx = m_listboxSorted->GetSelection();
848 m_listboxSorted->Delete( idx );
849 break;
850 }
851 case ID_LISTBOX_FONT:
852 {
853 m_listbox->SetFont( *wxITALIC_FONT );
854 m_listboxSorted->SetFont( *wxITALIC_FONT );
855 m_checkbox->SetFont( *wxITALIC_FONT );
856 break;
857 }
858 }
859 }
860
861 void MyPanel::OnChoice( wxCommandEvent &event )
862 {
863 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
864 : m_choiceSorted;
865
866 m_text->AppendText( "Choice event selection string is: '" );
867 m_text->AppendText( event.GetString() );
868 m_text->AppendText( "'\n" );
869 m_text->AppendText( "Choice control selection string is: '" );
870 m_text->AppendText( choice->GetStringSelection() );
871 m_text->AppendText( "'\n" );
872
873 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
874 m_text->AppendText( "Choice event client data string is: '" );
875
876 if (obj)
877 m_text->AppendText( obj->GetData() );
878 else
879 m_text->AppendText( wxString("none") );
880
881 m_text->AppendText( "'\n" );
882 m_text->AppendText( "Choice control client data string is: '" );
883 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
884
885 if (obj)
886 m_text->AppendText( obj->GetData() );
887 else
888 m_text->AppendText( wxString("none") );
889 m_text->AppendText( "'\n" );
890 }
891
892 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
893 {
894 switch (event.GetId())
895 {
896 case ID_CHOICE_ENABLE:
897 {
898 m_choice->Enable( event.GetInt() == 0 );
899 m_choiceSorted->Enable( event.GetInt() == 0 );
900 break;
901 }
902 case ID_CHOICE_SEL_NUM:
903 {
904 m_choice->SetSelection( 2 );
905 m_choiceSorted->SetSelection( 2 );
906 break;
907 }
908 case ID_CHOICE_SEL_STR:
909 {
910 m_choice->SetStringSelection( "This" );
911 m_choiceSorted->SetStringSelection( "This" );
912 break;
913 }
914 case ID_CHOICE_CLEAR:
915 {
916 m_choice->Clear();
917 m_choiceSorted->Clear();
918 break;
919 }
920 case ID_CHOICE_APPEND:
921 {
922 m_choice->Append( "Hi!" );
923 m_choiceSorted->Append( "Hi!" );
924 break;
925 }
926 case ID_CHOICE_DELETE:
927 {
928 int idx = m_choice->GetSelection();
929 m_choice->Delete( idx );
930 idx = m_choiceSorted->GetSelection();
931 m_choiceSorted->Delete( idx );
932 break;
933 }
934 case ID_CHOICE_FONT:
935 {
936 m_choice->SetFont( *wxITALIC_FONT );
937 m_choiceSorted->SetFont( *wxITALIC_FONT );
938 break;
939 }
940 }
941 }
942
943 void MyPanel::OnCombo( wxCommandEvent &event )
944 {
945 m_text->AppendText( "ComboBox event selection string is: " );
946 m_text->AppendText( event.GetString() );
947 m_text->AppendText( "\n" );
948 m_text->AppendText( "ComboBox control selection string is: " );
949 m_text->AppendText( m_combo->GetStringSelection() );
950 m_text->AppendText( "\n" );
951 }
952
953 void MyPanel::OnComboButtons( wxCommandEvent &event )
954 {
955 switch (event.GetId())
956 {
957 case ID_COMBO_ENABLE:
958 {
959 m_combo->Enable( event.GetInt() == 0 );
960 break;
961 }
962 case ID_COMBO_SEL_NUM:
963 {
964 m_combo->SetSelection( 2 );
965 break;
966 }
967 case ID_COMBO_SEL_STR:
968 {
969 m_combo->SetStringSelection( "This" );
970 break;
971 }
972 case ID_COMBO_CLEAR:
973 {
974 m_combo->Clear();
975 break;
976 }
977 case ID_COMBO_APPEND:
978 {
979 m_combo->Append( "Hi!" );
980 break;
981 }
982 case ID_COMBO_DELETE:
983 {
984 int idx = m_combo->GetSelection();
985 m_combo->Delete( idx );
986 break;
987 }
988 case ID_COMBO_FONT:
989 {
990 m_combo->SetFont( *wxITALIC_FONT );
991 break;
992 }
993 }
994 }
995
996 void MyPanel::OnRadio( wxCommandEvent &event )
997 {
998 m_text->AppendText( "RadioBox selection string is: " );
999 m_text->AppendText( event.GetString() );
1000 m_text->AppendText( "\n" );
1001 }
1002
1003 void MyPanel::OnRadioButtons( wxCommandEvent &event )
1004 {
1005 switch (event.GetId())
1006 {
1007 case ID_RADIOBOX_ENABLE:
1008 {
1009 m_radio->Enable( event.GetInt() == 0 );
1010 break;
1011 }
1012 case ID_RADIOBOX_SEL_NUM:
1013 {
1014 m_radio->SetSelection( 2 );
1015 break;
1016 }
1017 case ID_RADIOBOX_SEL_STR:
1018 {
1019 m_radio->SetStringSelection( "This" );
1020 break;
1021 }
1022 case ID_RADIOBOX_FONT:
1023 {
1024 m_radio->SetFont( *wxITALIC_FONT );
1025 break;
1026 }
1027 }
1028 }
1029
1030 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1031 {
1032 m_fontButton->SetFont( *wxITALIC_FONT );
1033 m_text->SetFont( *wxITALIC_FONT );
1034 }
1035
1036 void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
1037 {
1038 static bool s_long = TRUE;
1039
1040 s_long = !s_long;
1041 m_label->SetLabel(s_long ? "very very very long text" : "shorter text");
1042 }
1043
1044 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1045 {
1046 m_gauge->SetValue( m_slider->GetValue() );
1047 }
1048
1049 #if wxUSE_SPINCTRL
1050
1051 void MyPanel::OnSpinCtrl(wxCommandEvent& event)
1052 {
1053 wxString s;
1054 s.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1055 m_spinctrl->GetValue(), event.GetInt());
1056 m_text->AppendText(s);
1057 }
1058
1059 #endif // wxUSE_SPINCTRL
1060
1061 #if wxUSE_SPINBTN
1062 void MyPanel::OnSpinUp( wxSpinEvent &event )
1063 {
1064 wxString value;
1065 value.Printf( _T("Spin control up: current = %d\n"),
1066 m_spinbutton->GetValue());
1067
1068 if ( m_spinbutton->GetValue() > 17 )
1069 {
1070 value += _T("Preventing the spin button from going above 17.\n");
1071
1072 event.Veto();
1073 }
1074
1075 m_text->AppendText(value);
1076 }
1077
1078 void MyPanel::OnSpinDown( wxSpinEvent &event )
1079 {
1080 wxString value;
1081 value.Printf( _T("Spin control down: current = %d\n"),
1082 m_spinbutton->GetValue());
1083
1084 if ( m_spinbutton->GetValue() < -17 )
1085 {
1086 value += _T("Preventing the spin button from going below -17.\n");
1087
1088 event.Veto();
1089 }
1090
1091 m_text->AppendText(value);
1092 }
1093
1094 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1095 {
1096 wxString value;
1097 value.Printf( _T("%d"), event.GetPosition() );
1098 m_spintext->SetValue( value );
1099
1100 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1101 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1102 m_spinbutton->GetValue());
1103
1104 m_text->AppendText(value);
1105 }
1106
1107 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1108 {
1109 event.Enable( m_spinbutton->GetValue() > 0 );
1110 }
1111
1112 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1113 {
1114 int max = m_spinbutton->GetValue();
1115 wxProgressDialog dialog("Progress dialog example",
1116 "An informative message",
1117 max, // range
1118 this, // parent
1119 wxPD_CAN_ABORT |
1120 wxPD_APP_MODAL |
1121 wxPD_ELAPSED_TIME |
1122 wxPD_ESTIMATED_TIME |
1123 wxPD_REMAINING_TIME);
1124
1125
1126 bool cont = TRUE;
1127 for ( int i = 0; i < max && cont; i++ )
1128 {
1129 wxSleep(1);
1130 if ( i == max - 1 )
1131 {
1132 cont = dialog.Update(i, "That's all, folks!");
1133 }
1134 else if ( i == max / 2 )
1135 {
1136 cont = dialog.Update(i, "Only a half left!");
1137 }
1138 else
1139 {
1140 cont = dialog.Update(i);
1141 }
1142 }
1143
1144 if ( !cont )
1145 {
1146 *m_text << "Progress dialog aborted!\n";
1147 }
1148 else
1149 {
1150 *m_text << "Countdown from " << max << " finished.\n";
1151 }
1152 }
1153
1154 #endif // wxUSE_SPINBTN
1155
1156 MyPanel::~MyPanel()
1157 {
1158 delete m_notebook->GetImageList();
1159 }
1160
1161 //----------------------------------------------------------------------
1162 // MyFrame
1163 //----------------------------------------------------------------------
1164
1165 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1166 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
1167 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
1168 #if wxUSE_TOOLTIPS
1169 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1170 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
1171 #endif // wxUSE_TOOLTIPS
1172
1173 EVT_MENU(MINIMAL_ENABLE_ALL, MyFrame::OnEnableAll)
1174
1175 EVT_SIZE(MyFrame::OnSize)
1176 EVT_MOVE(MyFrame::OnMove)
1177
1178 EVT_IDLE(MyFrame::OnIdle)
1179 END_EVENT_TABLE()
1180
1181 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
1182 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1183 {
1184 CreateStatusBar(2);
1185
1186 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1187 }
1188
1189 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1190 {
1191 Close(TRUE);
1192 }
1193
1194 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1195 {
1196 wxBeginBusyCursor();
1197
1198 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
1199 dialog.ShowModal();
1200
1201 wxEndBusyCursor();
1202 }
1203
1204 #if wxUSE_TOOLTIPS
1205 void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1206 {
1207 static long s_delay = 5000;
1208
1209 wxString delay;
1210 delay.Printf( _T("%ld"), s_delay);
1211
1212 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
1213 "Set tooltip delay",
1214 delay,
1215 this);
1216 if ( !delay )
1217 return; // cancelled
1218
1219 wxSscanf(delay, _T("%ld"), &s_delay);
1220
1221 wxToolTip::SetDelay(s_delay);
1222
1223 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1224 }
1225
1226 void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1227 {
1228 static bool s_enabled = TRUE;
1229
1230 s_enabled = !s_enabled;
1231
1232 wxToolTip::Enable(s_enabled);
1233
1234 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1235 }
1236 #endif // tooltips
1237
1238 void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1239 {
1240 static bool s_enable = TRUE;
1241
1242 s_enable = !s_enable;
1243 m_panel->Enable(s_enable);
1244 }
1245
1246 void MyFrame::OnMove( wxMoveEvent& event )
1247 {
1248 UpdateStatusBar(event.GetPosition(), GetSize());
1249
1250 event.Skip();
1251 }
1252
1253 void MyFrame::OnSize( wxSizeEvent& event )
1254 {
1255 UpdateStatusBar(GetPosition(), event.GetSize());
1256
1257 event.Skip();
1258 }
1259
1260 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1261 {
1262 // track the window which has the focus in the status bar
1263 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1264 wxWindow *focus = wxWindow::FindFocus();
1265 if ( focus && (focus != s_windowFocus) )
1266 {
1267 s_windowFocus = focus;
1268
1269 wxString msg;
1270 msg.Printf(
1271 #ifdef __WXMSW__
1272 _T("Focus: wxWindow = %p, HWND = %08x"),
1273 #else
1274 _T("Focus: wxWindow = %p"),
1275 #endif
1276 s_windowFocus
1277 #ifdef __WXMSW__
1278 , s_windowFocus->GetHWND()
1279 #endif
1280 );
1281
1282 SetStatusText(msg);
1283 }
1284 }
1285
1286 static void SetControlClientData(const char *name,
1287 wxControlWithItems *control)
1288 {
1289 size_t count = control->GetCount();
1290 for ( size_t n = 0; n < count; n++ )
1291 {
1292 wxString s;
1293 s.Printf("%s client data for '%s'",
1294 name, control->GetString(n).c_str());
1295
1296 control->SetClientObject(n, new wxStringClientData(s));
1297 }
1298 }