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