1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Controls wxWidgets sample
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
22 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
23 #include "wx/spinbutt.h"
25 #include "wx/tglbtn.h"
26 #include "wx/bookctrl.h"
27 #include "wx/imaglist.h"
28 #include "wx/artprov.h"
31 #include "wx/tooltip.h"
34 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
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"
49 #define wxUSE_SPINBTN 1
52 #include "wx/progdlg.h"
55 #include "wx/spinctrl.h"
56 #endif // wxUSE_SPINCTRL
58 //----------------------------------------------------------------------
60 //----------------------------------------------------------------------
62 class MyApp
: public wxApp
68 class MyPanel
: public wxPanel
71 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
74 void OnSize( wxSizeEvent
& event
);
75 void OnListBox( wxCommandEvent
&event
);
76 void OnListBoxDoubleClick( wxCommandEvent
&event
);
77 void OnListBoxButtons( wxCommandEvent
&event
);
79 void OnChoice( wxCommandEvent
&event
);
80 void OnChoiceButtons( wxCommandEvent
&event
);
82 void OnCombo( wxCommandEvent
&event
);
83 void OnComboTextChanged( wxCommandEvent
&event
);
84 void OnComboTextEnter( wxCommandEvent
&event
);
85 void OnComboButtons( wxCommandEvent
&event
);
86 void OnRadio( wxCommandEvent
&event
);
87 void OnRadioButtons( wxCommandEvent
&event
);
88 void OnRadioButton1( wxCommandEvent
&event
);
89 void OnRadioButton2( wxCommandEvent
&event
);
90 void OnSetFont( wxCommandEvent
&event
);
91 void OnPageChanged( wxBookCtrlEvent
&event
);
92 void OnPageChanging( wxBookCtrlEvent
&event
);
93 void OnSliderUpdate( wxCommandEvent
&event
);
94 void OnUpdateLabel( wxCommandEvent
&event
);
96 void OnSpinUp( wxSpinEvent
&event
);
97 void OnSpinDown( wxSpinEvent
&event
);
98 void OnSpinUpdate( wxSpinEvent
&event
);
100 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
101 void OnShowProgress( wxCommandEvent
&event
);
102 #endif // wxUSE_PROGRESSDLG
103 #endif // wxUSE_SPINBTN
106 void OnSpinCtrl(wxSpinEvent
& event
);
107 void OnSpinCtrlUp(wxSpinEvent
& event
);
108 void OnSpinCtrlDown(wxSpinEvent
& event
);
109 void OnSpinCtrlText(wxCommandEvent
& event
);
110 #endif // wxUSE_SPINCTRL
112 void OnEnableAll(wxCommandEvent
& event
);
113 void OnChangeColour(wxCommandEvent
& event
);
114 void OnTestButton(wxCommandEvent
& event
);
115 void OnBmpButton(wxCommandEvent
& event
);
117 void OnSizerCheck (wxCommandEvent
&event
);
119 wxListBox
*m_listbox
,
124 #endif // wxUSE_CHOICE
131 #endif // wxUSE_GAUGE
134 #endif // wxUSE_SLIDER
135 wxButton
*m_fontButton
;
136 wxButton
*m_lbSelectNum
;
137 wxButton
*m_lbSelectThis
;
139 wxSpinButton
*m_spinbutton
;
140 #if wxUSE_PROGRESSDLG
141 wxButton
*m_btnProgress
;
142 #endif // wxUSE_PROGRESSDLG
143 #endif // wxUSE_SPINBTN
146 wxSpinCtrl
*m_spinctrl
;
147 #endif // wxUSE_SPINCTRL
149 wxTextCtrl
*m_spintext
;
150 wxCheckBox
*m_checkbox
;
155 wxStaticText
*m_label
;
157 wxBoxSizer
*m_buttonSizer
;
158 wxButton
*m_sizerBtn1
;
159 wxButton
*m_sizerBtn2
;
160 wxButton
*m_sizerBtn3
;
161 wxButton
*m_sizerBtn4
;
162 wxBoxSizer
*m_hsizer
;
166 wxLog
*m_logTargetOld
;
168 DECLARE_EVENT_TABLE()
171 class MyFrame
: public wxFrame
174 MyFrame(const wxChar
*title
, int x
, int y
);
176 void OnQuit(wxCommandEvent
& event
);
177 void OnAbout(wxCommandEvent
& event
);
178 void OnClearLog(wxCommandEvent
& event
);
181 void OnSetTooltipDelay(wxCommandEvent
& event
);
182 void OnToggleTooltips(wxCommandEvent
& event
);
183 #endif // wxUSE_TOOLTIPS
185 void OnEnableAll(wxCommandEvent
& event
);
187 void OnIdle( wxIdleEvent
& event
);
188 void OnIconized( wxIconizeEvent
& event
);
189 void OnMaximized( wxMaximizeEvent
& event
);
190 void OnSize( wxSizeEvent
& event
);
191 void OnMove( wxMoveEvent
& event
);
193 MyPanel
*GetPanel() const { return m_panel
; }
197 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
199 if ( m_frameStatusBar
)
202 wxSize sizeAll
= GetSize(),
203 sizeCl
= GetClientSize();
204 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
207 sizeAll
.x
, sizeAll
.y
,
209 SetStatusText(msg
, 1);
212 #endif // wxUSE_STATUSBAR
216 DECLARE_EVENT_TABLE()
219 // a button which intercepts double clicks (for testing...)
220 class MyButton
: public wxButton
223 MyButton(wxWindow
*parent
,
225 const wxString
& label
= wxEmptyString
,
226 const wxPoint
& pos
= wxDefaultPosition
,
227 const wxSize
& size
= wxDefaultSize
)
228 : wxButton(parent
, id
, label
, pos
, size
)
232 void OnDClick(wxMouseEvent
& event
)
234 wxLogMessage(_T("MyButton::OnDClick"));
240 DECLARE_EVENT_TABLE()
243 // a combo which intercepts chars (to test Windows behaviour)
244 class MyComboBox
: public wxComboBox
247 MyComboBox(wxWindow
*parent
, wxWindowID id
,
248 const wxString
& value
= wxEmptyString
,
249 const wxPoint
& pos
= wxDefaultPosition
,
250 const wxSize
& size
= wxDefaultSize
,
251 int n
= 0, const wxString choices
[] = NULL
,
253 const wxValidator
& validator
= wxDefaultValidator
,
254 const wxString
& name
= wxComboBoxNameStr
)
255 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
259 void OnChar(wxKeyEvent
& event
);
260 void OnKeyDown(wxKeyEvent
& event
);
261 void OnKeyUp(wxKeyEvent
& event
);
262 void OnFocusGot(wxFocusEvent
& event
)
264 wxLogMessage(_T("MyComboBox::OnFocusGot"));
270 DECLARE_EVENT_TABLE()
273 // a radiobox which handles focus set/kill (for testing)
274 class MyRadioBox
: public wxRadioBox
277 MyRadioBox(wxWindow
*parent
,
279 const wxString
& title
= wxEmptyString
,
280 const wxPoint
& pos
= wxDefaultPosition
,
281 const wxSize
& size
= wxDefaultSize
,
282 int n
= 0, const wxString choices
[] = NULL
,
284 long style
= wxRA_HORIZONTAL
,
285 const wxValidator
& validator
= wxDefaultValidator
,
286 const wxString
& name
= wxRadioBoxNameStr
)
287 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
288 style
, validator
, name
) { SetForegroundColour(*wxRED
); }
291 void OnFocusGot(wxFocusEvent
& event
)
293 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
298 void OnFocusLost(wxFocusEvent
& event
)
300 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
306 DECLARE_EVENT_TABLE()
309 //----------------------------------------------------------------------
311 //----------------------------------------------------------------------
313 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
316 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
317 #endif // wxUSE_CHOICE
321 //----------------------------------------------------------------------
323 //----------------------------------------------------------------------
333 CONTROLS_SET_TOOLTIP_DELAY
= 200,
334 CONTROLS_ENABLE_TOOLTIPS
,
342 // use standard command line handling:
343 if ( !wxApp::OnInit() )
346 // parse the cmd line
351 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
352 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
355 // Create the main frame window
356 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
362 //----------------------------------------------------------------------
364 //----------------------------------------------------------------------
366 const int ID_BOOK
= 1000;
368 const int ID_LISTBOX
= 130;
369 const int ID_LISTBOX_SEL_NUM
= 131;
370 const int ID_LISTBOX_SEL_STR
= 132;
371 const int ID_LISTBOX_CLEAR
= 133;
372 const int ID_LISTBOX_APPEND
= 134;
373 const int ID_LISTBOX_DELETE
= 135;
374 const int ID_LISTBOX_FONT
= 136;
375 const int ID_LISTBOX_ENABLE
= 137;
376 const int ID_LISTBOX_SORTED
= 138;
378 const int ID_CHOICE
= 120;
379 const int ID_CHOICE_SEL_NUM
= 121;
380 const int ID_CHOICE_SEL_STR
= 122;
381 const int ID_CHOICE_CLEAR
= 123;
382 const int ID_CHOICE_APPEND
= 124;
383 const int ID_CHOICE_DELETE
= 125;
384 const int ID_CHOICE_FONT
= 126;
385 const int ID_CHOICE_ENABLE
= 127;
386 const int ID_CHOICE_SORTED
= 128;
388 const int ID_COMBO
= 140;
389 const int ID_COMBO_SEL_NUM
= 141;
390 const int ID_COMBO_SEL_STR
= 142;
391 const int ID_COMBO_CLEAR
= 143;
392 const int ID_COMBO_APPEND
= 144;
393 const int ID_COMBO_DELETE
= 145;
394 const int ID_COMBO_FONT
= 146;
395 const int ID_COMBO_ENABLE
= 147;
397 const int ID_RADIOBOX
= 160;
398 const int ID_RADIOBOX_SEL_NUM
= 161;
399 const int ID_RADIOBOX_SEL_STR
= 162;
400 const int ID_RADIOBOX_FONT
= 163;
401 const int ID_RADIOBOX_ENABLE
= 164;
403 const int ID_RADIOBUTTON_1
= 166;
404 const int ID_RADIOBUTTON_2
= 167;
406 const int ID_SET_FONT
= 170;
409 const int ID_GAUGE
= 180;
410 #endif // wxUSE_GAUGE
413 const int ID_SLIDER
= 181;
414 #endif // wxUSE_SLIDER
416 const int ID_SPIN
= 182;
417 #if wxUSE_PROGRESSDLG
418 const int ID_BTNPROGRESS
= 183;
419 #endif // wxUSE_PROGRESSDLG
420 const int ID_BUTTON_LABEL
= 184;
421 const int ID_SPINCTRL
= 185;
423 const int ID_BUTTON_TEST1
= 190;
424 const int ID_BUTTON_TEST2
= 191;
425 const int ID_BITMAP_BTN
= 192;
427 const int ID_CHANGE_COLOUR
= 200;
429 const int ID_SIZER_CHECK1
= 201;
430 const int ID_SIZER_CHECK2
= 202;
431 const int ID_SIZER_CHECK3
= 203;
432 const int ID_SIZER_CHECK4
= 204;
433 const int ID_SIZER_CHECK14
= 205;
434 const int ID_SIZER_CHECKBIG
= 206;
436 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
437 EVT_SIZE ( MyPanel::OnSize
)
438 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
439 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
440 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
441 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
442 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
443 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
444 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
445 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
446 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
447 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
448 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
449 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
451 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
452 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
453 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
454 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
455 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
456 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
457 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
458 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
459 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
461 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
462 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
463 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
464 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
465 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
466 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
467 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
468 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
469 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
470 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
471 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
472 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
473 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
474 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
475 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
476 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
477 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
478 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
480 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
481 #endif // wxUSE_SLIDER
483 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
484 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
485 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
486 #if wxUSE_PROGRESSDLG
487 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
488 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
489 #endif // wxUSE_PROGRESSDLG
490 #endif // wxUSE_SPINBTN
492 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
493 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
494 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
495 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
496 #endif // wxUSE_SPINCTRL
498 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
500 EVT_CHECKBOX(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
501 #endif // wxUSE_TOGGLEBTN
502 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
503 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
504 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
505 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
507 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
508 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
509 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
510 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
511 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
512 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
516 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
517 EVT_LEFT_DCLICK(MyButton::OnDClick
)
520 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
521 EVT_CHAR(MyComboBox::OnChar
)
522 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
523 EVT_KEY_UP(MyComboBox::OnKeyUp
)
525 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
528 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
529 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
530 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
533 // ============================================================================
535 // ============================================================================
537 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
538 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
541 m_listboxSorted
= NULL
;
544 m_choiceSorted
= NULL
;
545 #endif // wxUSE_CHOICE
551 #endif // wxUSE_GAUGE
554 #endif // wxUSE_SLIDER
556 m_lbSelectNum
= NULL
;
557 m_lbSelectThis
= NULL
;
560 #if wxUSE_PROGRESSDLG
561 m_btnProgress
= NULL
;
562 #endif // wxUSE_PROGRESSDLG
563 #endif // wxUSE_SPINBTN
566 #endif // wxUSE_SPINCTRL
573 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
574 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
575 m_text
->SetBackgroundColour(wxT("wheat"));
577 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
579 m_book
= new wxBookCtrl(this, ID_BOOK
);
601 #endif // wxUSE_GAUGE
605 // fill the image list
606 wxBitmap
bmp(list_xpm
);
608 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
610 imagelist
-> Add( bmp
);
611 imagelist
-> Add( wxBitmap( choice_xpm
));
612 imagelist
-> Add( wxBitmap( combo_xpm
));
613 imagelist
-> Add( wxBitmap( text_xpm
));
614 imagelist
-> Add( wxBitmap( radio_xpm
));
616 imagelist
-> Add( wxBitmap( gauge_xpm
));
617 #endif // wxUSE_GAUGE
618 m_book
->SetImageList(imagelist
);
619 #elif defined(__WXMSW__)
620 // load images from resources
630 #endif // wxUSE_GAUGE
633 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
635 static const wxChar
*s_iconNames
[Image_Max
] =
644 #endif // wxUSE_GAUGE
647 for ( size_t n
= 0; n
< Image_Max
; n
++ )
649 wxBitmap
bmp(s_iconNames
[n
]);
650 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
652 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
657 m_book
->SetImageList(imagelist
);
661 #define Image_List -1
662 #define Image_Choice -1
663 #define Image_Combo -1
664 #define Image_Text -1
665 #define Image_Radio -1
667 #define Image_Gauge -1
668 #endif // wxUSE_GAUGE
673 wxPanel
*panel
= new wxPanel(m_book
);
674 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
675 wxPoint(10,10), wxSize(120,70),
676 5, choices
, wxLB_ALWAYS_SB
);
677 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
678 wxPoint(10,90), wxSize(120,70),
679 5, choices
, wxLB_SORT
);
681 SetListboxClientData(wxT("listbox"), m_listbox
);
682 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
684 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
686 m_listbox
->SetToolTip( _T("This is a list box") );
687 #endif // wxUSE_TOOLTIPS
689 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
690 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
691 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
692 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
693 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
694 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
696 button
->SetDefault();
697 button
->SetForegroundColour(*wxBLUE
);
700 button
->SetToolTip( _T("Press here to set italic font") );
701 #endif // wxUSE_TOOLTIPS
703 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
704 m_checkbox
->SetValue(false);
705 button
->MoveAfterInTabOrder(m_checkbox
);
707 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
708 #endif // wxUSE_TOOLTIPS
709 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
711 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
712 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
715 panel
= new wxPanel(m_book
);
716 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
717 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
718 5, choices
, wxCB_SORT
);
720 SetChoiceClientData(wxT("choice"), m_choice
);
721 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
723 m_choice
->SetSelection(2);
724 m_choice
->SetBackgroundColour( wxT("red") );
725 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
726 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
727 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
728 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
729 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
730 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
731 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
733 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
734 #endif // wxUSE_CHOICE
736 panel
= new wxPanel(m_book
);
737 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
738 wxPoint(5, 5), wxSize(150, 100));
739 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
740 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
742 wxCB_READONLY
| wxPROCESS_ENTER
);
743 m_combo
->SetBackgroundColour(*wxBLUE
);
745 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
746 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
747 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
748 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
749 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
750 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
751 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
752 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
754 wxString choices2
[] =
756 _T("First"), _T("Second"),
758 "Fourth", "Fifth", "Sixth",
759 "Seventh", "Eighth", "Nineth", "Tenth" */
762 panel
= new wxPanel(m_book
);
763 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
764 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
765 m_radio
->SetForegroundColour(*wxRED
);
768 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
769 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
770 #endif // wxUSE_TOOLTIPS
772 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
773 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
774 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
775 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
776 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
777 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
778 rb
->SetValue( false );
779 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
780 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
782 #if wxUSE_SLIDER && wxUSE_GAUGE
783 panel
= new wxPanel(m_book
);
784 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
785 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
786 m_gauge
->SetBackgroundColour(*wxGREEN
);
787 m_gauge
->SetForegroundColour(*wxRED
);
788 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
789 wxPoint(195,35), wxSize(30, 90),
790 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
791 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,wxDefaultCoord
),
792 wxSL_AUTOTICKS
| wxSL_LABELS
);
793 m_slider
->SetTickFreq(40, 0);
795 m_slider
->SetToolTip(_T("This is a sliding slider"));
796 #endif // wxUSE_TOOLTIPS
798 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
799 wxPoint(230,10), wxSize(270,130),
803 // No wrapping text in wxStaticText yet :-(
804 (void)new wxStaticText( panel
, wxID_ANY
,
805 _T("Drag the slider!"),
807 wxSize(240, wxDefaultCoord
)
810 (void)new wxStaticText( panel
, wxID_ANY
,
811 _T("In order see the gauge (aka progress bar)\n")
812 _T("control do something you have to drag the\n")
813 _T("handle of the slider to the right.\n")
815 _T("This is also supposed to demonstrate how\n")
816 _T("to use static controls.\n"),
821 int initialSpinValue
= -5;
823 s
<< initialSpinValue
;
824 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
826 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, wxDefaultCoord
) );
827 m_spinbutton
->SetRange(-40,30);
828 m_spinbutton
->SetValue(initialSpinValue
);
830 #if wxUSE_PROGRESSDLG
831 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
833 #endif // wxUSE_PROGRESSDLG
834 #endif // wxUSE_SPINBTN
837 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
838 m_spinctrl
->SetRange(10,30);
839 m_spinctrl
->SetValue(15);
840 #endif // wxUSE_SPINCTRL
842 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
843 #endif // wxUSE_SLIDER && wxUSE_GAUGE
845 panel
= new wxPanel(m_book
);
847 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
848 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
849 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
851 // VZ: don't leak memory
852 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
853 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
856 wxBitmap
bitmap( 100, 100 );
858 dc
.SelectObject( bitmap
);
859 dc
.SetPen(*wxGREEN_PEN
);
861 dc
.DrawEllipse(5, 5, 90, 90);
862 dc
.DrawText(_T("Bitmap"), 30, 40);
863 dc
.SelectObject( wxNullBitmap
);
865 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
867 #if defined(__WXMSW__) || defined(__WXMOTIF__)
868 // test for masked bitmap display
869 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
872 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
874 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
878 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
879 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
880 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
881 wxBitmapButton
*bmpBtn
= new wxBitmapButton
888 bmpBtn
->SetBitmapSelected(bmp2
);
889 bmpBtn
->SetBitmapFocus(bmp3
);
892 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
893 _T("&Toggle label"), wxPoint(250, 20));
895 (void)new wxCheckBox(panel
, ID_BUTTON_LABEL
,
896 _T("&Toggle label"), wxPoint(250, 20));
897 #endif // wxUSE_TOGGLEBTN
899 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
900 wxPoint(250, 60), wxDefaultSize
,
901 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
902 m_label
->SetForegroundColour( *wxBLUE
);
904 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
908 panel
= new wxPanel(m_book
);
909 panel
->SetAutoLayout( true );
911 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
913 wxStaticBoxSizer
*csizer
=
914 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
916 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
917 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
918 check1
->SetValue (true);
919 csizer
->Add (check1
);
920 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
921 check2
->SetValue (true);
922 csizer
->Add (check2
);
923 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
924 check3
->SetValue (true);
925 csizer
->Add (check3
);
926 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
927 check4
->SetValue (true);
928 csizer
->Add (check4
);
929 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
930 check14
->SetValue (true);
931 csizer
->Add (check14
);
932 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
933 checkBig
->SetValue (true);
934 csizer
->Add (checkBig
);
938 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
940 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
942 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
943 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
944 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
945 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
946 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
947 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
948 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
949 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
951 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
953 m_hsizer
->Add (m_buttonSizer
);
954 m_hsizer
->Add( 20,20, 1 );
955 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
956 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
958 sizer
->Add (m_hsizer
, 1, wxGROW
);
960 panel
->SetSizer( sizer
);
962 m_book
->AddPage(panel
, _T("wxSizer"));
965 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
969 GetClientSize( &x
, &y
);
971 if (m_book
) m_book
->SetSize( 2, 2, x
-4, y
*2/3-4 );
972 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
975 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
977 int selOld
= event
.GetOldSelection();
980 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
981 _T("page change from taking place - if you select\n")
982 _T("[No] the current page will stay the third one\n"),
983 _T("Control sample"),
984 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
992 *m_text
<< _T("Book selection is being changed from ") << selOld
993 << _T(" to ") << event
.GetSelection()
994 << _T(" (current page from book is ")
995 << m_book
->GetSelection() << _T(")\n");
998 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1000 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1001 << _T(" (from book: ") << m_book
->GetSelection()
1005 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1007 wxLogMessage(_T("Button %c clicked."),
1008 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1011 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1013 wxLogMessage(_T("Bitmap button clicked."));
1016 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1018 static wxColour s_colOld
;
1020 SetThemeEnabled(false);
1021 // test panel colour changing and propagation to the subcontrols
1022 if ( s_colOld
.Ok() )
1024 SetBackgroundColour(s_colOld
);
1025 s_colOld
= wxNullColour
;
1027 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1028 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1032 s_colOld
= wxColour(wxT("red"));
1033 SetBackgroundColour(wxT("white"));
1035 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1036 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1039 m_lbSelectThis
->Refresh();
1043 void MyPanel::OnListBox( wxCommandEvent
&event
)
1045 // GetParent()->Move(100, 100);
1047 if (event
.GetInt() == -1)
1049 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1053 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1056 m_text
->AppendText( _T("ListBox event selection string is: '") );
1057 m_text
->AppendText( event
.GetString() );
1058 m_text
->AppendText( _T("'\n") );
1059 m_text
->AppendText( _T("ListBox control selection string is: '") );
1060 m_text
->AppendText( listbox
->GetStringSelection() );
1061 m_text
->AppendText( _T("'\n") );
1063 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1064 m_text
->AppendText( _T("ListBox event client data string is: '") );
1065 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1066 m_text
->AppendText( obj
->GetData() );
1068 m_text
->AppendText( wxString(_T("none")) );
1070 m_text
->AppendText( _T("'\n") );
1071 m_text
->AppendText( _T("ListBox control client data string is: '") );
1072 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1074 m_text
->AppendText( obj
->GetData() );
1076 m_text
->AppendText( wxString(_T("none")) );
1077 m_text
->AppendText( _T("'\n") );
1080 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1082 m_text
->AppendText( _T("ListBox double click string is: ") );
1083 m_text
->AppendText( event
.GetString() );
1084 m_text
->AppendText( _T("\n") );
1087 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1089 switch (event
.GetId())
1091 case ID_LISTBOX_ENABLE
:
1093 m_text
->AppendText(_T("Checkbox clicked.\n"));
1095 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1097 cb
->SetToolTip( _T("Click to enable listbox") );
1099 cb
->SetToolTip( _T("Click to disable listbox") );
1100 #endif // wxUSE_TOOLTIPS
1101 m_listbox
->Enable( event
.GetInt() == 0 );
1102 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1103 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1104 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1105 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1108 case ID_LISTBOX_SEL_NUM
:
1110 if (m_listbox
->GetCount() > 2)
1111 m_listbox
->SetSelection( 2 );
1112 if (m_listboxSorted
->GetCount() > 2)
1113 m_listboxSorted
->SetSelection( 2 );
1114 m_lbSelectThis
->WarpPointer( 40, 14 );
1117 case ID_LISTBOX_SEL_STR
:
1119 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1120 m_listbox
->SetStringSelection( _T("This") );
1121 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1122 m_listboxSorted
->SetStringSelection( _T("This") );
1123 m_lbSelectNum
->WarpPointer( 40, 14 );
1126 case ID_LISTBOX_CLEAR
:
1129 m_listboxSorted
->Clear();
1132 case ID_LISTBOX_APPEND
:
1134 m_listbox
->Append( _T("Hi!") );
1135 m_listboxSorted
->Append( _T("Hi!") );
1138 case ID_LISTBOX_DELETE
:
1141 idx
= m_listbox
->GetSelection();
1142 if ( idx
!= wxNOT_FOUND
)
1143 m_listbox
->Delete( idx
);
1144 idx
= m_listboxSorted
->GetSelection();
1145 if ( idx
!= wxNOT_FOUND
)
1146 m_listboxSorted
->Delete( idx
);
1149 case ID_LISTBOX_FONT
:
1151 m_listbox
->SetFont( *wxITALIC_FONT
);
1152 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1153 m_checkbox
->SetFont( *wxITALIC_FONT
);
1160 void MyPanel::OnChoice( wxCommandEvent
&event
)
1162 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1165 m_text
->AppendText( _T("Choice event selection string is: '") );
1166 m_text
->AppendText( event
.GetString() );
1167 m_text
->AppendText( _T("'\n") );
1168 m_text
->AppendText( _T("Choice control selection string is: '") );
1169 m_text
->AppendText( choice
->GetStringSelection() );
1170 m_text
->AppendText( _T("'\n") );
1172 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1173 m_text
->AppendText( _T("Choice event client data string is: '") );
1176 m_text
->AppendText( obj
->GetData() );
1178 m_text
->AppendText( wxString(_T("none")) );
1180 m_text
->AppendText( _T("'\n") );
1181 m_text
->AppendText( _T("Choice control client data string is: '") );
1182 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1185 m_text
->AppendText( obj
->GetData() );
1187 m_text
->AppendText( wxString(_T("none")) );
1188 m_text
->AppendText( _T("'\n") );
1191 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1193 switch (event
.GetId())
1195 case ID_CHOICE_ENABLE
:
1197 m_choice
->Enable( event
.GetInt() == 0 );
1198 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1201 case ID_CHOICE_SEL_NUM
:
1203 m_choice
->SetSelection( 2 );
1204 m_choiceSorted
->SetSelection( 2 );
1207 case ID_CHOICE_SEL_STR
:
1209 m_choice
->SetStringSelection( _T("This") );
1210 m_choiceSorted
->SetStringSelection( _T("This") );
1213 case ID_CHOICE_CLEAR
:
1216 m_choiceSorted
->Clear();
1219 case ID_CHOICE_APPEND
:
1221 m_choice
->Append( _T("Hi!") );
1222 m_choiceSorted
->Append( _T("Hi!") );
1225 case ID_CHOICE_DELETE
:
1227 int idx
= m_choice
->GetSelection();
1228 if ( idx
!= wxNOT_FOUND
)
1229 m_choice
->Delete( idx
);
1230 idx
= m_choiceSorted
->GetSelection();
1231 if ( idx
!= wxNOT_FOUND
)
1232 m_choiceSorted
->Delete( idx
);
1235 case ID_CHOICE_FONT
:
1237 m_choice
->SetFont( *wxITALIC_FONT
);
1238 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1243 #endif // wxUSE_CHOICE
1245 void MyPanel::OnCombo( wxCommandEvent
&event
)
1247 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1248 m_text
->AppendText( event
.GetString() );
1249 m_text
->AppendText( _T("\n") );
1250 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1251 m_text
->AppendText( m_combo
->GetStringSelection() );
1252 m_text
->AppendText( _T("\n") );
1255 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1258 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1259 event
.GetString().c_str() );
1260 wxLogMessage( str
.c_str() );
1263 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1265 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1266 m_combo
->GetValue().c_str());
1269 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1271 switch (event
.GetId())
1273 case ID_COMBO_ENABLE
:
1275 m_combo
->Enable( event
.GetInt() == 0 );
1278 case ID_COMBO_SEL_NUM
:
1280 m_combo
->SetSelection( 2 );
1283 case ID_COMBO_SEL_STR
:
1285 m_combo
->SetStringSelection( _T("This") );
1288 case ID_COMBO_CLEAR
:
1293 case ID_COMBO_APPEND
:
1295 m_combo
->Append( _T("Hi!") );
1298 case ID_COMBO_DELETE
:
1300 int idx
= m_combo
->GetSelection();
1301 m_combo
->Delete( idx
);
1306 m_combo
->SetFont( *wxITALIC_FONT
);
1312 void MyPanel::OnRadio( wxCommandEvent
&event
)
1314 m_text
->AppendText( _T("RadioBox selection string is: ") );
1315 m_text
->AppendText( event
.GetString() );
1316 m_text
->AppendText( _T("\n") );
1319 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1321 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1324 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1326 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1329 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1331 switch (event
.GetId())
1333 case ID_RADIOBOX_ENABLE
:
1335 m_radio
->Enable( event
.GetInt() == 0 );
1338 case ID_RADIOBOX_SEL_NUM
:
1340 m_radio
->SetSelection( 2 );
1343 case ID_RADIOBOX_SEL_STR
:
1345 m_radio
->SetStringSelection( _T("This") );
1348 case ID_RADIOBOX_FONT
:
1350 m_radio
->SetForegroundColour(*wxGREEN
);
1352 m_radio
->SetFont( *wxITALIC_FONT
);
1358 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1360 m_fontButton
->SetFont( *wxITALIC_FONT
);
1361 m_text
->SetFont( *wxITALIC_FONT
);
1364 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1366 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1367 : _T("Shorter text."));
1372 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1375 m_gauge
->SetValue( m_slider
->GetValue() );
1376 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1377 #endif // wxUSE_GAUGE
1380 #endif // wxUSE_SLIDER
1384 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1389 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1390 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1391 m_text
->AppendText(s
);
1395 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1400 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1401 m_spinctrl
->GetValue(), event
.GetInt() );
1402 m_text
->AppendText(s
);
1406 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1410 m_text
->AppendText( wxString::Format(
1411 _T("Spin up: %d (from event: %ld)\n"),
1412 m_spinctrl
->GetValue(), event
.GetInt() ) );
1416 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1420 m_text
->AppendText( wxString::Format(
1421 _T("Spin down: %d (from event: %ld)\n"),
1422 m_spinctrl
->GetValue(), event
.GetInt() ) );
1426 #endif // wxUSE_SPINCTRL
1429 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1432 value
.Printf( _T("Spin control up: current = %d\n"),
1433 m_spinbutton
->GetValue());
1435 if ( event
.GetPosition() > 17 )
1437 value
+= _T("Preventing the spin button from going above 17.\n");
1442 m_text
->AppendText(value
);
1445 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1448 value
.Printf( _T("Spin control down: current = %d\n"),
1449 m_spinbutton
->GetValue());
1451 if ( event
.GetPosition() < -17 )
1453 value
+= _T("Preventing the spin button from going below -17.\n");
1458 m_text
->AppendText(value
);
1461 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1464 value
.Printf( _T("%d"), event
.GetPosition() );
1465 m_spintext
->SetValue( value
);
1467 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1468 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1469 m_spinbutton
->GetValue());
1471 m_text
->AppendText(value
);
1474 #if wxUSE_PROGRESSDLG
1476 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1478 event
.Enable( m_spinbutton
->GetValue() > 0 );
1481 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1483 int max
= m_spinbutton
->GetValue();
1487 wxLogError(_T("You must set positive range!"));
1491 wxProgressDialog
dialog(_T("Progress dialog example"),
1492 _T("An informative message"),
1499 wxPD_ESTIMATED_TIME
|
1500 wxPD_REMAINING_TIME
);
1504 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1509 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1511 else if ( i
== max
/ 2 )
1513 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1517 cont
= dialog
.Update(i
);
1523 *m_text
<< _T("Progress dialog aborted!\n");
1527 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1531 #endif // wxUSE_PROGRESSDLG
1532 #endif // wxUSE_SPINBTN
1534 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1536 switch (event
.GetId ()) {
1537 case ID_SIZER_CHECK1
:
1538 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1539 m_buttonSizer
->Layout ();
1541 case ID_SIZER_CHECK2
:
1542 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1543 m_buttonSizer
->Layout ();
1545 case ID_SIZER_CHECK3
:
1546 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1547 m_buttonSizer
->Layout ();
1549 case ID_SIZER_CHECK4
:
1550 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1551 m_buttonSizer
->Layout ();
1553 case ID_SIZER_CHECK14
:
1554 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1555 m_hsizer
->Layout ();
1557 case ID_SIZER_CHECKBIG
:
1558 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1559 m_hsizer
->Layout ();
1567 //wxLog::RemoveTraceMask(_T("focus"));
1568 delete wxLog::SetActiveTarget(m_logTargetOld
);
1570 delete m_book
->GetImageList();
1573 //----------------------------------------------------------------------
1575 //----------------------------------------------------------------------
1577 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1578 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1579 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1580 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1582 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1583 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1584 #endif // wxUSE_TOOLTIPS
1586 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1588 EVT_ICONIZE(MyFrame::OnIconized
)
1589 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1590 EVT_SIZE(MyFrame::OnSize
)
1591 EVT_MOVE(MyFrame::OnMove
)
1593 EVT_IDLE(MyFrame::OnIdle
)
1596 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1597 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1600 // The wxICON() macros loads an icon from a resource under Windows
1601 // and uses an #included XPM image under GTK+ and Motif
1604 SetIcon( wxICON(mondrian
) );
1607 wxMenu
*file_menu
= new wxMenu
;
1609 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1610 file_menu
->AppendSeparator();
1611 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1612 file_menu
->AppendSeparator();
1613 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1615 wxMenuBar
*menu_bar
= new wxMenuBar
;
1616 menu_bar
->Append(file_menu
, _T("&File"));
1619 wxMenu
*tooltip_menu
= new wxMenu
;
1620 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1621 tooltip_menu
->AppendSeparator();
1622 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1623 _T("enable/disable tooltips"), true);
1624 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1625 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1626 #endif // wxUSE_TOOLTIPS
1628 wxMenu
*panel_menu
= new wxMenu
;
1629 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1630 _T("Enable/disable all panel controls"), true);
1631 menu_bar
->Append(panel_menu
, _T("&Panel"));
1633 SetMenuBar(menu_bar
);
1637 #endif // wxUSE_STATUSBAR
1639 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1641 SetSizeHints( 500, 425 );
1644 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1649 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1653 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1657 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1659 m_panel
->m_text
->Clear();
1663 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1665 static long s_delay
= 5000;
1668 delay
.Printf( _T("%ld"), s_delay
);
1670 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1671 _T("Set tooltip delay"),
1675 return; // cancelled
1677 wxSscanf(delay
, _T("%ld"), &s_delay
);
1679 wxToolTip::SetDelay(s_delay
);
1681 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1684 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1686 static bool s_enabled
= true;
1688 s_enabled
= !s_enabled
;
1690 wxToolTip::Enable(s_enabled
);
1692 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1696 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1698 static bool s_enable
= true;
1700 s_enable
= !s_enable
;
1701 m_panel
->Enable(s_enable
);
1704 void MyFrame::OnMove( wxMoveEvent
& event
)
1707 UpdateStatusBar(event
.GetPosition(), GetSize());
1708 #endif // wxUSE_STATUSBAR
1713 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1715 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1720 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1722 wxLogMessage(_T("Frame maximized"));
1725 void MyFrame::OnSize( wxSizeEvent
& event
)
1728 UpdateStatusBar(GetPosition(), event
.GetSize());
1729 #endif // wxUSE_STATUSBAR
1734 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1736 // track the window which has the focus in the status bar
1737 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1738 wxWindow
*focus
= wxWindow::FindFocus();
1739 if ( focus
&& (focus
!= s_windowFocus
) )
1741 s_windowFocus
= focus
;
1746 _T("Focus: %s, HWND = %08x"),
1750 s_windowFocus
->GetClassInfo()->GetClassName()
1752 , (unsigned int) s_windowFocus
->GetHWND()
1758 #endif // wxUSE_STATUSBAR
1762 void MyComboBox::OnChar(wxKeyEvent
& event
)
1764 wxLogMessage(_T("MyComboBox::OnChar"));
1766 if ( event
.GetKeyCode() == 'w' )
1767 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1772 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1774 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1776 if ( event
.GetKeyCode() == 'w' )
1777 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1782 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1784 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1789 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1791 size_t count
= control
->GetCount();
1792 for ( size_t n
= 0; n
< count
; n
++ )
1795 s
.Printf(wxT("%s client data for '%s'"),
1796 name
, control
->GetString(n
).c_str());
1798 control
->SetClientObject(n
, new wxStringClientData(s
));
1804 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1806 size_t count
= control
->GetCount();
1807 for ( size_t n
= 0; n
< count
; n
++ )
1810 s
.Printf(wxT("%s client data for '%s'"),
1811 name
, control
->GetString(n
).c_str());
1813 control
->SetClientObject(n
, new wxStringClientData(s
));
1817 #endif // wxUSE_CHOICE