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