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