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