]> git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
wxProgressDialg works again.
[wxWidgets.git] / samples / controls / controls.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: controls.cpp
3 // Purpose: Controls wxWindows sample
4 // Author: Robert Roebling
5 // Modified by:
6 // RCS-ID: $Id$
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "controls.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25
26 #include "wx/spinbutt.h"
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
29
30 #if wxUSE_TOOLTIPS
31 #include "wx/tooltip.h"
32 #endif
33
34 #if defined(__WXGTK__) || defined(__WXMOTIF__)
35 #define USE_XPM
36 #endif
37
38 #ifdef USE_XPM
39 #include "mondrian.xpm"
40 #include "icons/choice.xpm"
41 #include "icons/combo.xpm"
42 #include "icons/list.xpm"
43 #include "icons/radio.xpm"
44 #include "icons/text.xpm"
45 #include "icons/gauge.xpm"
46 #endif
47
48 #ifdef __WIN16__
49 // Win16 doesn't have them
50 #undef wxUSE_SPINBUTTON
51 #define wxUSE_SPINBUTTON 0
52 #endif // __WIN16__
53
54 #include "wx/progdlg.h"
55
56 //----------------------------------------------------------------------
57 // class definitions
58 //----------------------------------------------------------------------
59
60 class MyApp: public wxApp
61 {
62 public:
63 bool OnInit();
64 };
65
66 class MyPanel: public wxPanel
67 {
68 public:
69 MyPanel(wxFrame *frame, int x, int y, int w, int h);
70 virtual ~MyPanel();
71
72 void OnSize( wxSizeEvent& event );
73 void OnListBox( wxCommandEvent &event );
74 void OnListBoxDoubleClick( wxCommandEvent &event );
75 void OnListBoxButtons( wxCommandEvent &event );
76 void OnChoice( wxCommandEvent &event );
77 void OnChoiceButtons( wxCommandEvent &event );
78 void OnCombo( wxCommandEvent &event );
79 void OnComboButtons( wxCommandEvent &event );
80 void OnRadio( wxCommandEvent &event );
81 void OnRadioButtons( wxCommandEvent &event );
82 void OnSetFont( wxCommandEvent &event );
83 void OnPageChanged( wxNotebookEvent &event );
84 void OnPageChanging( wxNotebookEvent &event );
85 void OnSliderUpdate( wxCommandEvent &event );
86 #ifndef wxUSE_SPINBUTTON
87 void OnSpinUpdate( wxSpinEvent &event );
88 void OnUpdateShowProgress( wxUpdateUIEvent& event );
89 void OnShowProgress( wxCommandEvent &event );
90 #endif // wxUSE_SPINBUTTON
91
92 wxListBox *m_listbox;
93 wxChoice *m_choice;
94 wxComboBox *m_combo;
95 wxRadioBox *m_radio;
96 wxGauge *m_gauge;
97 wxSlider *m_slider;
98 wxButton *m_fontButton;
99 wxButton *m_lbSelectNum;
100 wxButton *m_lbSelectThis;
101 #ifndef wxUSE_SPINBUTTON
102 wxSpinButton *m_spinbutton;
103 wxButton *m_btnProgress;
104 #endif
105 wxTextCtrl *m_spintext;
106 wxCheckBox *m_checkbox;
107
108 wxTextCtrl *m_text;
109 wxNotebook *m_notebook;
110
111 private:
112 DECLARE_EVENT_TABLE()
113 };
114
115 class MyFrame: public wxFrame
116 {
117 public:
118 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
119
120 void OnQuit(wxCommandEvent& event);
121 void OnAbout(wxCommandEvent& event);
122 #if wxUSE_TOOLTIPS
123 void OnSetTooltipDelay(wxCommandEvent& event);
124 void OnToggleTooltips(wxCommandEvent& event);
125 #endif // wxUSE_TOOLTIPS
126 void OnIdle( wxIdleEvent& event );
127 void OnSize( wxSizeEvent& event );
128
129 private:
130 DECLARE_EVENT_TABLE()
131 };
132
133 //----------------------------------------------------------------------
134 // main()
135 //----------------------------------------------------------------------
136
137 IMPLEMENT_APP(MyApp)
138
139 //----------------------------------------------------------------------
140 // MyApp
141 //----------------------------------------------------------------------
142
143 enum
144 {
145 MINIMAL_QUIT = 100,
146 MINIMAL_TEXT,
147 MINIMAL_ABOUT,
148
149 // tooltip menu
150 MINIMAL_SET_TOOLTIP_DELAY = 200,
151 MINIMAL_ENABLE_TOOLTIPS
152 };
153
154 bool MyApp::OnInit()
155 {
156 // Create the main frame window
157 MyFrame *frame = new MyFrame((wxFrame *) NULL,
158 "Controls wxWindows App",
159 50, 50, 530, 420);
160
161 // Give it an icon
162 // The wxICON() macros loads an icon from a resource under Windows
163 // and uses an #included XPM image under GTK+ and Motif
164
165 frame->SetIcon( wxICON(mondrian) );
166
167 // submenu
168 wxMenu *sub_menu = new wxMenu( wxMENU_TEAROFF );
169 sub_menu->Append(MINIMAL_ABOUT, "&About", "About this sample");
170 sub_menu->Append(MINIMAL_ABOUT, "&About", "About this sample");
171 sub_menu->Append(MINIMAL_ABOUT, "&About", "About this sample");
172
173 wxMenu *file_menu = new wxMenu;
174 file_menu->Append(MINIMAL_ABOUT, "&About\tF1");
175 file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample");
176 file_menu->Append( 0, "&Submenu", sub_menu );
177
178 wxMenuBar *menu_bar = new wxMenuBar( wxMB_DOCKABLE );
179 menu_bar->Append(file_menu, "&File");
180
181 #if wxUSE_TOOLTIPS
182 wxMenu *tooltip_menu = new wxMenu;
183 tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
184 tooltip_menu->AppendSeparator();
185 tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCrtl-T",
186 "enable/disable tooltips", TRUE);
187 tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
188 menu_bar->Append(tooltip_menu, "&Tooltips");
189 #endif // wxUSE_TOOLTIPS
190
191 frame->SetMenuBar(menu_bar);
192
193 frame->Show(TRUE);
194 frame->SetCursor(wxCursor(wxCURSOR_HAND));
195
196 SetTopWindow(frame);
197
198 return TRUE;
199 }
200
201 //----------------------------------------------------------------------
202 // MyPanel
203 //----------------------------------------------------------------------
204
205 const int ID_NOTEBOOK = 1000;
206
207 const int ID_LISTBOX = 130;
208 const int ID_LISTBOX_SEL_NUM = 131;
209 const int ID_LISTBOX_SEL_STR = 132;
210 const int ID_LISTBOX_CLEAR = 133;
211 const int ID_LISTBOX_APPEND = 134;
212 const int ID_LISTBOX_DELETE = 135;
213 const int ID_LISTBOX_FONT = 136;
214 const int ID_LISTBOX_ENABLE = 137;
215
216 const int ID_CHOICE = 120;
217 const int ID_CHOICE_SEL_NUM = 121;
218 const int ID_CHOICE_SEL_STR = 122;
219 const int ID_CHOICE_CLEAR = 123;
220 const int ID_CHOICE_APPEND = 124;
221 const int ID_CHOICE_DELETE = 125;
222 const int ID_CHOICE_FONT = 126;
223 const int ID_CHOICE_ENABLE = 127;
224
225 const int ID_COMBO = 140;
226 const int ID_COMBO_SEL_NUM = 141;
227 const int ID_COMBO_SEL_STR = 142;
228 const int ID_COMBO_CLEAR = 143;
229 const int ID_COMBO_APPEND = 144;
230 const int ID_COMBO_DELETE = 145;
231 const int ID_COMBO_FONT = 146;
232 const int ID_COMBO_ENABLE = 147;
233
234 const int ID_RADIOBOX = 160;
235 const int ID_RADIOBOX_SEL_NUM = 161;
236 const int ID_RADIOBOX_SEL_STR = 162;
237 const int ID_RADIOBOX_FONT = 163;
238 const int ID_RADIOBOX_ENABLE = 164;
239
240 const int ID_RADIOBUTTON_1 = 166;
241 const int ID_RADIOBUTTON_2 = 167;
242
243 const int ID_SET_FONT = 170;
244
245 const int ID_GAUGE = 180;
246 const int ID_SLIDER = 181;
247
248 const int ID_SPIN = 182;
249 const int ID_BTNPROGRESS = 183;
250
251 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
252 EVT_SIZE ( MyPanel::OnSize)
253 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
254 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
255 EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
256 EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
257 EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
258 EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
259 EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
260 EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
261 EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
262 EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
263 EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
264 EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
265 EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
266 EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
267 EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
268 EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
269 EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
270 EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
271 EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
272 EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
273 EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
274 EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
275 EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
276 EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
277 EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
278 EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
279 EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
280 EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
281 EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
282 EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
283 EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
284 EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
285 EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
286 EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
287 #ifndef wxUSE_SPINBUTTON
288 EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
289 EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
290 EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
291 #endif
292 END_EVENT_TABLE()
293
294 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
295 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
296 m_text(NULL), m_notebook(NULL)
297 {
298 // SetBackgroundColour("cadet blue");
299
300 m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
301 // m_text->SetBackgroundColour("wheat");
302
303 delete wxLog::SetActiveTarget(new wxLogStderr);
304
305 m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) );
306
307 wxString choices[] =
308 {
309 "This",
310 "is one of my",
311 "really",
312 "wonderful",
313 "examples."
314 };
315
316 #ifdef USE_XPM
317 // image ids
318 enum
319 {
320 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
321 };
322
323 // fill the image list
324 wxImageList *imagelist = new wxImageList(32, 32);
325
326 imagelist-> Add( wxBitmap( list_xpm ));
327 imagelist-> Add( wxBitmap( choice_xpm ));
328 imagelist-> Add( wxBitmap( combo_xpm ));
329 imagelist-> Add( wxBitmap( text_xpm ));
330 imagelist-> Add( wxBitmap( radio_xpm ));
331 imagelist-> Add( wxBitmap( gauge_xpm ));
332 m_notebook->SetImageList(imagelist);
333 #elif defined(__WXMSW__)
334 // load images from resources
335 enum
336 {
337 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
338 };
339 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
340
341 static const char *s_iconNames[Image_Max] =
342 {
343 "list", "choice", "combo", "text", "radio", "gauge"
344 };
345
346 for ( size_t n = 0; n < Image_Max; n++ )
347 {
348 wxBitmap bmp(s_iconNames[n]);
349 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
350 {
351 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
352 s_iconNames[n], n);
353 }
354 }
355
356 m_notebook->SetImageList(imagelist);
357 #else
358
359 // No images for now
360 #define Image_List -1
361 #define Image_Choice -1
362 #define Image_Combo -1
363 #define Image_Text -1
364 #define Image_Radio -1
365 #define Image_Gauge -1
366 #define Image_Max -1
367
368 #endif
369
370 wxButton *button = (wxButton*) NULL; /* who did this ? */
371 wxPanel *panel = (wxPanel*) NULL;
372
373 panel = new wxPanel(m_notebook);
374 m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices, wxLB_ALWAYS_SB );
375 m_listbox->SetCursor(*wxCROSS_CURSOR);
376 #if wxUSE_TOOLTIPS
377 m_listbox->SetToolTip( "This is a list box" );
378 #endif // wxUSE_TOOLTIPS
379
380 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
381 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
382 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
383 (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
384 (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
385 button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
386 #if wxUSE_TOOLTIPS
387 button->SetToolTip( "Press here to set italic font" );
388 #endif // wxUSE_TOOLTIPS
389
390 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT );
391 m_checkbox->SetValue(FALSE);
392 #if wxUSE_TOOLTIPS
393 m_checkbox->SetToolTip( "Click here to disable the listbox" );
394 #endif // wxUSE_TOOLTIPS
395 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
396
397 panel = new wxPanel(m_notebook);
398 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
399 m_choice->SetBackgroundColour( "red" );
400 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
401 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
402 (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
403 (void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
404 (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
405 (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
406 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
407 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
408
409 panel = new wxPanel(m_notebook);
410 m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY );
411 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
412 (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
413 (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
414 (void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
415 (void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
416 (void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
417 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
418 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
419
420 wxString choices2[] =
421 {
422 "First", "Second",
423 /* "Third",
424 "Fourth", "Fifth", "Sixth",
425 "Seventh", "Eighth", "Nineth", "Tenth" */
426 };
427
428 panel = new wxPanel(m_notebook);
429 (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
430 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
431 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
432 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
433 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
434 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
435 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) );
436 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
437 rb->SetValue( FALSE );
438 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
439 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
440
441 panel = new wxPanel(m_notebook);
442 (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
443 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) );
444 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
445 (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
446 #ifdef __WXMOTIF__
447 // No wrapping text in wxStaticText yet :-(
448 (void)new wxStaticText( panel, -1,
449 "Drag the slider!",
450 wxPoint(208,30),
451 wxSize(210, -1)
452 );
453 #else
454 (void)new wxStaticText( panel, -1,
455 "In order see the gauge (aka progress bar)\n"
456 "control do something you have to drag the\n"
457 "handle of the slider to the right.\n"
458 "\n"
459 "This is also supposed to demonstrate how\n"
460 "to use static controls.\n",
461 wxPoint(208,25),
462 wxSize(250, 110)
463 );
464 #endif
465 m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
466 #ifndef wxUSE_SPINBUTTON
467 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
468 m_spinbutton->SetRange(-10,30);
469 m_spinbutton->SetValue(-5);
470
471 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog",
472 wxPoint(208, 159) );
473 #endif
474 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
475 }
476
477 void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
478 {
479 int x = 0;
480 int y = 0;
481 GetClientSize( &x, &y );
482
483 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
484 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
485 }
486
487 void MyPanel::OnPageChanging( wxNotebookEvent &event )
488 {
489 int selNew = event.GetSelection(),
490 selOld = event.GetOldSelection();
491 if ( selOld == 2 && selNew == 4 )
492 {
493 wxMessageBox("This demonstrates how a program may prevent the "
494 "page change from taking place - the current page will "
495 "stay the third one", "Conntrol sample",
496 wxICON_INFORMATION | wxOK);
497
498 event.Veto();
499 }
500 else
501 {
502 *m_text << "Notebook selection is being changed from "
503 << selOld << " to " << selNew << "\n";
504 }
505 }
506
507 void MyPanel::OnPageChanged( wxNotebookEvent &event )
508 {
509 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
510 }
511
512 void MyPanel::OnListBox( wxCommandEvent &event )
513 {
514 m_text->AppendText( "ListBox event selection string is: " );
515 m_text->AppendText( event.GetString() );
516 m_text->AppendText( "\n" );
517 m_text->AppendText( "ListBox control selection string is: " );
518 m_text->AppendText( m_listbox->GetStringSelection() );
519 m_text->AppendText( "\n" );
520 }
521
522 void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
523 {
524 m_text->AppendText( "ListBox double click string is: " );
525 m_text->AppendText( event.GetString() );
526 m_text->AppendText( "\n" );
527 }
528
529 void MyPanel::OnListBoxButtons( wxCommandEvent &event )
530 {
531 switch (event.GetId())
532 {
533 case ID_LISTBOX_ENABLE:
534 {
535 m_text->AppendText("Checkbox clicked.\n");
536 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
537 #if wxUSE_TOOLTIPS
538 if (event.GetInt())
539 cb->SetToolTip( "Click to enable listbox" );
540 else
541 cb->SetToolTip( "Click to disable listbox" );
542 #endif // wxUSE_TOOLTIPS
543 m_listbox->Enable( event.GetInt() == 0 );
544 break;
545 }
546 case ID_LISTBOX_SEL_NUM:
547 {
548 m_listbox->SetSelection( 2 );
549 m_lbSelectThis->WarpPointer( 40, 14 );
550 break;
551 }
552 case ID_LISTBOX_SEL_STR:
553 {
554 m_listbox->SetStringSelection( "This" );
555 m_lbSelectNum->WarpPointer( 40, 14 );
556 break;
557 }
558 case ID_LISTBOX_CLEAR:
559 {
560 m_listbox->Clear();
561 break;
562 }
563 case ID_LISTBOX_APPEND:
564 {
565 m_listbox->Append( "Hi!" );
566 break;
567 }
568 case ID_LISTBOX_DELETE:
569 {
570 int idx = m_listbox->GetSelection();
571 m_listbox->Delete( idx );
572 break;
573 }
574 case ID_LISTBOX_FONT:
575 {
576 m_listbox->SetFont( *wxITALIC_FONT );
577 m_checkbox->SetFont( *wxITALIC_FONT );
578 break;
579 }
580 }
581 }
582
583 void MyPanel::OnChoice( wxCommandEvent &event )
584 {
585 m_text->AppendText( "Choice event selection string is: " );
586 m_text->AppendText( event.GetString() );
587 m_text->AppendText( "\n" );
588 m_text->AppendText( "Choice control selection string is: " );
589 m_text->AppendText( m_choice->GetStringSelection() );
590 m_text->AppendText( "\n" );
591 }
592
593 void MyPanel::OnChoiceButtons( wxCommandEvent &event )
594 {
595 switch (event.GetId())
596 {
597 case ID_CHOICE_ENABLE:
598 {
599 m_choice->Enable( event.GetInt() == 0 );
600 break;
601 }
602 case ID_CHOICE_SEL_NUM:
603 {
604 m_choice->SetSelection( 2 );
605 break;
606 }
607 case ID_CHOICE_SEL_STR:
608 {
609 m_choice->SetStringSelection( "This" );
610 break;
611 }
612 case ID_CHOICE_CLEAR:
613 {
614 m_choice->Clear();
615 break;
616 }
617 case ID_CHOICE_APPEND:
618 {
619 m_choice->Append( "Hi!" );
620 break;
621 }
622 case ID_CHOICE_DELETE:
623 {
624 int idx = m_choice->GetSelection();
625 m_choice->Delete( idx );
626 break;
627 }
628 case ID_CHOICE_FONT:
629 {
630 m_choice->SetFont( *wxITALIC_FONT );
631 break;
632 }
633 }
634 }
635
636 void MyPanel::OnCombo( wxCommandEvent &event )
637 {
638 m_text->AppendText( "ComboBox event selection string is: " );
639 m_text->AppendText( event.GetString() );
640 m_text->AppendText( "\n" );
641 m_text->AppendText( "ComboBox control selection string is: " );
642 m_text->AppendText( m_combo->GetStringSelection() );
643 m_text->AppendText( "\n" );
644 }
645
646 void MyPanel::OnComboButtons( wxCommandEvent &event )
647 {
648 switch (event.GetId())
649 {
650 case ID_COMBO_ENABLE:
651 {
652 m_combo->Enable( event.GetInt() == 0 );
653 break;
654 }
655 case ID_COMBO_SEL_NUM:
656 {
657 m_combo->SetSelection( 2 );
658 break;
659 }
660 case ID_COMBO_SEL_STR:
661 {
662 m_combo->SetStringSelection( "This" );
663 break;
664 }
665 case ID_COMBO_CLEAR:
666 {
667 m_combo->Clear();
668 break;
669 }
670 case ID_COMBO_APPEND:
671 {
672 m_combo->Append( "Hi!" );
673 break;
674 }
675 case ID_COMBO_DELETE:
676 {
677 int idx = m_combo->GetSelection();
678 m_combo->Delete( idx );
679 break;
680 }
681 case ID_COMBO_FONT:
682 {
683 m_combo->SetFont( *wxITALIC_FONT );
684 break;
685 }
686 }
687 }
688
689 void MyPanel::OnRadio( wxCommandEvent &event )
690 {
691 m_text->AppendText( "RadioBox selection string is: " );
692 m_text->AppendText( event.GetString() );
693 m_text->AppendText( "\n" );
694 }
695
696 void MyPanel::OnRadioButtons( wxCommandEvent &event )
697 {
698 switch (event.GetId())
699 {
700 case ID_RADIOBOX_ENABLE:
701 {
702 m_radio->Enable( event.GetInt() == 0 );
703 break;
704 }
705 case ID_RADIOBOX_SEL_NUM:
706 {
707 m_radio->SetSelection( 2 );
708 break;
709 }
710 case ID_RADIOBOX_SEL_STR:
711 {
712 m_radio->SetStringSelection( "This" );
713 break;
714 }
715 case ID_RADIOBOX_FONT:
716 {
717 m_radio->SetFont( *wxITALIC_FONT );
718 break;
719 }
720 }
721 }
722
723 void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
724 {
725 m_fontButton->SetFont( *wxITALIC_FONT );
726 m_text->SetFont( *wxITALIC_FONT );
727 }
728
729 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
730 {
731 m_gauge->SetValue( m_slider->GetValue() );
732 }
733
734 #ifndef wxUSE_SPINBUTTON
735 void MyPanel::OnSpinUpdate( wxSpinEvent &event )
736 {
737 wxString value;
738 value.Printf( _T("%d"), event.GetPosition() );
739 m_spintext->SetValue( value );
740
741 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
742 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
743 m_spinbutton->GetValue());
744
745 m_text->AppendText(value);
746 }
747
748 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
749 {
750 event.Enable( m_spinbutton->GetValue() > 0 );
751 }
752
753 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
754 {
755 int max = m_spinbutton->GetValue();
756 wxProgressDialog dialog("Progress dialog example",
757 "An informative message",
758 max, // range
759 this, // parent
760 wxPD_CAN_ABORT | wxPD_APP_MODAL);
761
762
763 bool cont = TRUE;
764 for ( int i = 0; i < max && cont; i++ )
765 {
766 wxSleep(1);
767 if ( i == max - 1 )
768 {
769 cont = dialog.Update(i, "That's all, folks!");
770 }
771 else if ( i == max / 2 )
772 {
773 cont = dialog.Update(i, "Only a half left!");
774 }
775 else
776 {
777 cont = dialog.Update(i);
778 }
779 wxYield();
780 }
781
782 if ( !cont )
783 {
784 *m_text << "Progress dialog aborted!\n";
785 }
786 else
787 {
788 *m_text << "Countdown from " << max << " finished.\n";
789 }
790 }
791
792 #endif // wxUSE_SPINBUTTON
793
794 MyPanel::~MyPanel()
795 {
796 delete m_notebook->GetImageList();
797 }
798
799 //----------------------------------------------------------------------
800 // MyFrame
801 //----------------------------------------------------------------------
802
803 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
804 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
805 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
806 #if wxUSE_TOOLTIPS
807 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
808 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
809 #endif // wxUSE_TOOLTIPS
810 EVT_SIZE(MyFrame::OnSize)
811 EVT_IDLE(MyFrame::OnIdle)
812 END_EVENT_TABLE()
813
814 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
815 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
816 {
817 CreateStatusBar(2);
818
819 (void)new MyPanel( this, 10, 10, 300, 100 );
820 }
821
822 void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
823 {
824 Close(TRUE);
825 }
826
827 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
828 {
829 wxBeginBusyCursor();
830
831 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
832 dialog.ShowModal();
833
834 wxEndBusyCursor();
835 }
836
837 #if wxUSE_TOOLTIPS
838 void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
839 {
840 static long s_delay = 5000;
841
842 wxString delay;
843 delay.Printf( _T("%ld"), s_delay);
844
845 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
846 "Set tooltip delay",
847 delay,
848 this);
849 if ( !delay )
850 return; // cancelled
851
852 wxSscanf(delay, _T("%ld"), &s_delay);
853
854 wxToolTip::SetDelay(s_delay);
855
856 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
857 }
858
859 void MyFrame::OnToggleTooltips(wxCommandEvent& event)
860 {
861 static bool s_enabled = TRUE;
862
863 s_enabled = !s_enabled;
864
865 wxToolTip::Enable(s_enabled);
866
867 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
868 }
869 #endif // tooltips
870
871 void MyFrame::OnSize( wxSizeEvent& event )
872 {
873 wxString msg;
874 msg.Printf( _("%dx%d"), event.GetSize().x, event.GetSize().y);
875 SetStatusText(msg, 1);
876
877 event.Skip();
878 }
879
880 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
881 {
882 // track the window which has the focus in the status bar
883 static wxWindow *s_windowFocus = (wxWindow *)NULL;
884 wxWindow *focus = wxWindow::FindFocus();
885 if ( focus && (focus != s_windowFocus) )
886 {
887 s_windowFocus = focus;
888
889 wxString msg;
890 msg.Printf(
891 #ifdef __WXMSW__
892 _T("Focus: wxWindow = %p, HWND = %08x"),
893 #else
894 _T("Focus: wxWindow = %p"),
895 #endif
896 s_windowFocus
897 #ifdef __WXMSW__
898 , s_windowFocus->GetHWND()
899 #endif
900 );
901
902 SetStatusText(msg);
903 }
904 }