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 #include "wx/spinbutt.h"
23 #include "wx/tglbtn.h"
24 #include "wx/bookctrl.h"
25 #include "wx/imaglist.h"
26 #include "wx/artprov.h"
27 #include "wx/cshelp.h"
30 #include "wx/tooltip.h"
33 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
38 #include "mondrian.xpm"
39 #include "icons/choice.xpm"
40 #include "icons/combo.xpm"
41 #include "icons/list.xpm"
42 #include "icons/radio.xpm"
43 #include "icons/text.xpm"
44 #include "icons/gauge.xpm"
48 #define wxUSE_SPINBTN 1
51 #include "wx/progdlg.h"
54 #include "wx/spinctrl.h"
55 #endif // wxUSE_SPINCTRL
58 #define wxToggleButton wxCheckBox
59 #define EVT_TOGGLEBUTTON EVT_CHECKBOX
62 //----------------------------------------------------------------------
64 //----------------------------------------------------------------------
66 class MyApp
: public wxApp
72 class MyPanel
: public wxPanel
75 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
78 void OnIdle( wxIdleEvent
&event
);
79 void OnListBox( wxCommandEvent
&event
);
80 void OnListBoxDoubleClick( wxCommandEvent
&event
);
81 void OnListBoxButtons( wxCommandEvent
&event
);
83 void OnChoice( wxCommandEvent
&event
);
84 void OnChoiceButtons( wxCommandEvent
&event
);
86 void OnCombo( wxCommandEvent
&event
);
87 void OnComboTextChanged( wxCommandEvent
&event
);
88 void OnComboTextEnter( wxCommandEvent
&event
);
89 void OnComboButtons( wxCommandEvent
&event
);
90 void OnRadio( wxCommandEvent
&event
);
91 void OnRadioButtons( wxCommandEvent
&event
);
92 void OnRadioButton1( wxCommandEvent
&event
);
93 void OnRadioButton2( wxCommandEvent
&event
);
94 void OnSetFont( wxCommandEvent
&event
);
95 void OnPageChanged( wxBookCtrlEvent
&event
);
96 void OnPageChanging( wxBookCtrlEvent
&event
);
97 void OnSliderUpdate( wxCommandEvent
&event
);
98 void OnUpdateLabel( wxCommandEvent
&event
);
100 void OnSpinUp( wxSpinEvent
&event
);
101 void OnSpinDown( wxSpinEvent
&event
);
102 void OnSpinUpdate( wxSpinEvent
&event
);
103 #if wxUSE_PROGRESSDLG
104 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
105 void OnShowProgress( wxCommandEvent
&event
);
106 #endif // wxUSE_PROGRESSDLG
107 #endif // wxUSE_SPINBTN
108 void OnNewText( wxCommandEvent
&event
);
110 void OnSpinCtrl(wxSpinEvent
& event
);
111 void OnSpinCtrlUp(wxSpinEvent
& event
);
112 void OnSpinCtrlDown(wxSpinEvent
& event
);
113 void OnSpinCtrlText(wxCommandEvent
& event
);
114 #endif // wxUSE_SPINCTRL
116 void OnEnableAll(wxCommandEvent
& event
);
117 void OnChangeColour(wxCommandEvent
& event
);
118 void OnTestButton(wxCommandEvent
& event
);
119 void OnBmpButton(wxCommandEvent
& event
);
120 void OnBmpButtonToggle(wxCommandEvent
& event
);
122 void OnSizerCheck (wxCommandEvent
&event
);
124 wxListBox
*m_listbox
,
129 #endif // wxUSE_CHOICE
136 #endif // wxUSE_GAUGE
139 #endif // wxUSE_SLIDER
140 wxButton
*m_fontButton
;
141 wxButton
*m_lbSelectNum
;
142 wxButton
*m_lbSelectThis
;
144 wxSpinButton
*m_spinbutton
;
145 #if wxUSE_PROGRESSDLG
146 wxButton
*m_btnProgress
;
147 #endif // wxUSE_PROGRESSDLG
148 #endif // wxUSE_SPINBTN
149 wxStaticText
*m_wrappingText
;
150 wxStaticText
*m_nonWrappingText
;
153 wxSpinCtrl
*m_spinctrl
;
154 #endif // wxUSE_SPINCTRL
156 wxTextCtrl
*m_spintext
;
157 wxCheckBox
*m_checkbox
;
162 wxStaticText
*m_label
;
164 wxBoxSizer
*m_buttonSizer
;
165 wxButton
*m_sizerBtn1
;
166 wxButton
*m_sizerBtn2
;
167 wxButton
*m_sizerBtn3
;
168 wxButton
*m_sizerBtn4
;
169 wxBoxSizer
*m_hsizer
;
173 wxLog
*m_logTargetOld
;
175 DECLARE_EVENT_TABLE()
178 class MyFrame
: public wxFrame
181 MyFrame(const wxChar
*title
, int x
, int y
);
183 void OnQuit(wxCommandEvent
& event
);
184 void OnAbout(wxCommandEvent
& event
);
185 void OnClearLog(wxCommandEvent
& event
);
188 void OnSetTooltipDelay(wxCommandEvent
& event
);
189 void OnToggleTooltips(wxCommandEvent
& event
);
190 #endif // wxUSE_TOOLTIPS
192 void OnEnableAll(wxCommandEvent
& event
);
193 void OnContextHelp(wxCommandEvent
& event
);
195 void OnIdle( wxIdleEvent
& event
);
196 void OnIconized( wxIconizeEvent
& event
);
197 void OnMaximized( wxMaximizeEvent
& event
);
198 void OnSize( wxSizeEvent
& event
);
199 void OnMove( wxMoveEvent
& event
);
201 MyPanel
*GetPanel() const { return m_panel
; }
205 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
207 if ( m_frameStatusBar
)
210 wxSize sizeAll
= GetSize(),
211 sizeCl
= GetClientSize();
212 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
215 sizeAll
.x
, sizeAll
.y
,
217 SetStatusText(msg
, 1);
220 #endif // wxUSE_STATUSBAR
224 DECLARE_EVENT_TABLE()
227 // a button which intercepts double clicks (for testing...)
228 class MyButton
: public wxButton
231 MyButton(wxWindow
*parent
,
233 const wxString
& label
= wxEmptyString
,
234 const wxPoint
& pos
= wxDefaultPosition
,
235 const wxSize
& size
= wxDefaultSize
)
236 : wxButton(parent
, id
, label
, pos
, size
)
240 void OnDClick(wxMouseEvent
& event
)
242 wxLogMessage(_T("MyButton::OnDClick"));
248 DECLARE_EVENT_TABLE()
251 // a combo which intercepts chars (to test Windows behaviour)
252 class MyComboBox
: public wxComboBox
255 MyComboBox(wxWindow
*parent
, wxWindowID id
,
256 const wxString
& value
= wxEmptyString
,
257 const wxPoint
& pos
= wxDefaultPosition
,
258 const wxSize
& size
= wxDefaultSize
,
259 int n
= 0, const wxString choices
[] = NULL
,
261 const wxValidator
& validator
= wxDefaultValidator
,
262 const wxString
& name
= wxComboBoxNameStr
)
263 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
267 void OnChar(wxKeyEvent
& event
);
268 void OnKeyDown(wxKeyEvent
& event
);
269 void OnKeyUp(wxKeyEvent
& event
);
270 void OnFocusGot(wxFocusEvent
& event
)
272 wxLogMessage(_T("MyComboBox::OnFocusGot"));
278 DECLARE_EVENT_TABLE()
281 // a radiobox which handles focus set/kill (for testing)
282 class MyRadioBox
: public wxRadioBox
285 MyRadioBox(wxWindow
*parent
,
287 const wxString
& title
= wxEmptyString
,
288 const wxPoint
& pos
= wxDefaultPosition
,
289 const wxSize
& size
= wxDefaultSize
,
290 int n
= 0, const wxString choices
[] = NULL
,
292 long style
= wxRA_HORIZONTAL
,
293 const wxValidator
& validator
= wxDefaultValidator
,
294 const wxString
& name
= wxRadioBoxNameStr
)
295 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
296 style
, validator
, name
)
301 void OnFocusGot(wxFocusEvent
& event
)
303 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
308 void OnFocusLost(wxFocusEvent
& event
)
310 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
316 DECLARE_EVENT_TABLE()
319 // a choice which handles focus set/kill (for testing)
320 class MyChoice
: public wxChoice
323 MyChoice(wxWindow
*parent
,
325 const wxPoint
& pos
= wxDefaultPosition
,
326 const wxSize
& size
= wxDefaultSize
,
327 int n
= 0, const wxString choices
[] = NULL
,
329 const wxValidator
& validator
= wxDefaultValidator
,
330 const wxString
& name
= wxChoiceNameStr
)
331 : wxChoice(parent
, id
, pos
, size
, n
, choices
,
332 style
, validator
, name
) { }
335 void OnFocusGot(wxFocusEvent
& event
)
337 wxLogMessage(_T("MyChoice::OnFocusGot"));
342 void OnFocusLost(wxFocusEvent
& event
)
344 wxLogMessage(_T("MyChoice::OnFocusLost"));
350 DECLARE_EVENT_TABLE()
355 //----------------------------------------------------------------------
357 //----------------------------------------------------------------------
359 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
362 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
363 #endif // wxUSE_CHOICE
367 //----------------------------------------------------------------------
369 //----------------------------------------------------------------------
373 CONTROLS_QUIT
= wxID_EXIT
,
374 CONTROLS_ABOUT
= wxID_ABOUT
,
379 CONTROLS_SET_TOOLTIP_DELAY
= 200,
380 CONTROLS_ENABLE_TOOLTIPS
,
384 CONTROLS_CONTEXT_HELP
389 // use standard command line handling:
390 if ( !wxApp::OnInit() )
393 // parse the cmd line
398 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
399 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
403 wxHelpProvider::Set( new wxSimpleHelpProvider
);
406 // Create the main frame window
407 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
413 //----------------------------------------------------------------------
415 //----------------------------------------------------------------------
417 const int ID_BOOK
= 1000;
419 const int ID_LISTBOX
= 130;
420 const int ID_LISTBOX_SEL_NUM
= 131;
421 const int ID_LISTBOX_SEL_STR
= 132;
422 const int ID_LISTBOX_CLEAR
= 133;
423 const int ID_LISTBOX_APPEND
= 134;
424 const int ID_LISTBOX_DELETE
= 135;
425 const int ID_LISTBOX_FONT
= 136;
426 const int ID_LISTBOX_ENABLE
= 137;
427 const int ID_LISTBOX_SORTED
= 138;
429 const int ID_CHOICE
= 120;
430 const int ID_CHOICE_SEL_NUM
= 121;
431 const int ID_CHOICE_SEL_STR
= 122;
432 const int ID_CHOICE_CLEAR
= 123;
433 const int ID_CHOICE_APPEND
= 124;
434 const int ID_CHOICE_DELETE
= 125;
435 const int ID_CHOICE_FONT
= 126;
436 const int ID_CHOICE_ENABLE
= 127;
437 const int ID_CHOICE_SORTED
= 128;
439 const int ID_COMBO
= 140;
440 const int ID_COMBO_SEL_NUM
= 141;
441 const int ID_COMBO_SEL_STR
= 142;
442 const int ID_COMBO_CLEAR
= 143;
443 const int ID_COMBO_APPEND
= 144;
444 const int ID_COMBO_DELETE
= 145;
445 const int ID_COMBO_FONT
= 146;
446 const int ID_COMBO_ENABLE
= 147;
447 const int ID_COMBO_SET_TEXT
= 148;
449 const int ID_RADIOBOX
= 160;
450 const int ID_RADIOBOX_SEL_NUM
= 161;
451 const int ID_RADIOBOX_SEL_STR
= 162;
452 const int ID_RADIOBOX_FONT
= 163;
453 const int ID_RADIOBOX_ENABLE
= 164;
455 const int ID_RADIOBUTTON_1
= 166;
456 const int ID_RADIOBUTTON_2
= 167;
458 const int ID_SET_FONT
= 170;
461 const int ID_GAUGE
= 180;
462 #endif // wxUSE_GAUGE
465 const int ID_SLIDER
= 181;
466 #endif // wxUSE_SLIDER
468 const int ID_SPIN
= 182;
469 #if wxUSE_PROGRESSDLG
470 const int ID_BTNPROGRESS
= 183;
471 #endif // wxUSE_PROGRESSDLG
472 const int ID_BUTTON_LABEL
= 184;
473 const int ID_SPINCTRL
= 185;
474 const int ID_BTNNEWTEXT
= 186;
476 const int ID_BUTTON_TEST1
= 190;
477 const int ID_BUTTON_TEST2
= 191;
478 const int ID_BITMAP_BTN
= 192;
479 const int ID_BITMAP_BTN_ENABLE
= 193;
481 const int ID_CHANGE_COLOUR
= 200;
483 const int ID_SIZER_CHECK1
= 201;
484 const int ID_SIZER_CHECK2
= 202;
485 const int ID_SIZER_CHECK3
= 203;
486 const int ID_SIZER_CHECK4
= 204;
487 const int ID_SIZER_CHECK14
= 205;
488 const int ID_SIZER_CHECKBIG
= 206;
490 const int ID_HYPERLINK
= 300;
492 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
493 EVT_IDLE ( MyPanel::OnIdle
)
494 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
495 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
496 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
497 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
498 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
499 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
500 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
501 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
502 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
503 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
504 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
505 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
507 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
508 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
509 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
510 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
511 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
512 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
513 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
514 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
515 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
517 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
518 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
519 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
520 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
521 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
522 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
523 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
524 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
525 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
526 EVT_BUTTON (ID_COMBO_SET_TEXT
, MyPanel::OnComboButtons
)
527 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
528 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
529 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
530 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
531 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
532 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
533 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
534 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
535 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
537 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
538 #endif // wxUSE_SLIDER
540 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
541 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
542 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
543 #if wxUSE_PROGRESSDLG
544 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
545 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
546 #endif // wxUSE_PROGRESSDLG
547 #endif // wxUSE_SPINBTN
549 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
550 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
551 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
552 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
553 #endif // wxUSE_SPINCTRL
554 EVT_BUTTON (ID_BTNNEWTEXT
, MyPanel::OnNewText
)
555 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
556 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
557 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
558 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
559 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
560 EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE
, MyPanel::OnBmpButtonToggle
)
562 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
563 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
564 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
565 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
566 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
567 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
571 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
572 EVT_LEFT_DCLICK(MyButton::OnDClick
)
575 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
576 EVT_CHAR(MyComboBox::OnChar
)
577 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
578 EVT_KEY_UP(MyComboBox::OnKeyUp
)
580 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
583 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
584 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
585 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
588 BEGIN_EVENT_TABLE(MyChoice
, wxChoice
)
589 EVT_SET_FOCUS(MyChoice::OnFocusGot
)
590 EVT_KILL_FOCUS(MyChoice::OnFocusLost
)
593 // ============================================================================
595 // ============================================================================
597 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
598 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
601 m_listboxSorted
= NULL
;
604 m_choiceSorted
= NULL
;
605 #endif // wxUSE_CHOICE
611 #endif // wxUSE_GAUGE
614 #endif // wxUSE_SLIDER
616 m_lbSelectNum
= NULL
;
617 m_lbSelectThis
= NULL
;
620 #if wxUSE_PROGRESSDLG
621 m_btnProgress
= NULL
;
622 #endif // wxUSE_PROGRESSDLG
623 #endif // wxUSE_SPINBTN
626 #endif // wxUSE_SPINCTRL
633 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
634 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
636 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
638 m_book
= new wxBookCtrl(this, ID_BOOK
);
660 #endif // wxUSE_GAUGE
664 // fill the image list
665 wxBitmap
bmp(list_xpm
);
667 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
669 imagelist
-> Add( bmp
);
670 imagelist
-> Add( wxBitmap( choice_xpm
));
671 imagelist
-> Add( wxBitmap( combo_xpm
));
672 imagelist
-> Add( wxBitmap( text_xpm
));
673 imagelist
-> Add( wxBitmap( radio_xpm
));
675 imagelist
-> Add( wxBitmap( gauge_xpm
));
676 #endif // wxUSE_GAUGE
677 m_book
->SetImageList(imagelist
);
678 #elif defined(__WXMSW__)
679 // load images from resources
689 #endif // wxUSE_GAUGE
692 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
694 static const wxChar
*s_iconNames
[Image_Max
] =
703 #endif // wxUSE_GAUGE
706 for ( size_t n
= 0; n
< Image_Max
; n
++ )
708 wxBitmap
bmp(s_iconNames
[n
]);
709 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
711 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
716 m_book
->SetImageList(imagelist
);
720 #define Image_List -1
721 #define Image_Choice -1
722 #define Image_Combo -1
723 #define Image_Text -1
724 #define Image_Radio -1
726 #define Image_Gauge -1
727 #endif // wxUSE_GAUGE
732 wxPanel
*panel
= new wxPanel(m_book
);
733 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
734 wxPoint(10,10), wxSize(120,70),
735 5, choices
, wxLB_MULTIPLE
|wxLB_ALWAYS_SB
);
736 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
737 wxPoint(10,90), wxSize(120,70),
738 5, choices
, wxLB_SORT
);
740 SetListboxClientData(wxT("listbox"), m_listbox
);
741 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
743 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
745 m_listbox
->SetToolTip( _T("This is a list box") );
746 #endif // wxUSE_TOOLTIPS
748 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
749 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
750 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
751 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
752 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
753 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
755 button
->SetDefault();
758 button
->SetToolTip( _T("Press here to set italic font") );
759 #endif // wxUSE_TOOLTIPS
761 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
762 m_checkbox
->SetValue(false);
763 button
->MoveAfterInTabOrder(m_checkbox
);
765 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
766 #endif // wxUSE_TOOLTIPS
767 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
769 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
770 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
773 panel
= new wxPanel(m_book
);
774 m_choice
= new MyChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
775 m_choiceSorted
= new MyChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
776 5, choices
, wxCB_SORT
);
778 SetChoiceClientData(wxT("choice"), m_choice
);
779 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
781 m_choice
->SetSelection(2);
782 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
783 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
784 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
785 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
786 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
787 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
788 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
790 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
791 #endif // wxUSE_CHOICE
793 panel
= new wxPanel(m_book
);
794 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
795 wxPoint(5, 5), wxSize(150, 100));
796 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
797 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
801 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
802 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
803 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
804 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
805 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
806 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
807 (void)new wxButton( panel
, ID_COMBO_SET_TEXT
, _T("Set 'Hi!' at #2"), wxPoint(340,180), wxSize(140,30) );
808 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
809 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
811 wxString choices2
[] =
813 _T("First"), _T("Second"),
815 "Fourth", "Fifth", "Sixth",
816 "Seventh", "Eighth", "Nineth", "Tenth" */
819 panel
= new wxPanel(m_book
);
820 wxRadioBox
*radio2
= new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
821 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
824 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
825 radio2
->SetToolTip(_T("Ever seen a radiobox?"));
827 //m_radio->SetToolTip(_T("Tooltip for the entire radiobox"));
828 for ( unsigned int nb
= 0; nb
< WXSIZEOF(choices
); nb
++ )
830 m_radio
->SetItemToolTip(nb
, _T("tooltip for\n") + choices
[nb
]);
833 // remove the tooltip for one of the items
834 m_radio
->SetItemToolTip(2, _T(""));
835 #endif // wxUSE_TOOLTIPS
838 for( unsigned int item
= 0; item
< WXSIZEOF(choices
); ++item
)
839 m_radio
->SetItemHelpText( item
, wxString::Format( _T("Help text for \"%s\""), choices
[item
].c_str() ) );
841 // erase help text for the second item
842 m_radio
->SetItemHelpText( 1, _T("") );
843 // set default help text for control
844 m_radio
->SetHelpText( _T("Default helptext for wxRadioBox") );
847 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
848 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
849 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
850 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
851 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
853 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
854 rb
->SetValue( false );
855 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
856 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
859 #if wxUSE_SLIDER && wxUSE_GAUGE
860 panel
= new wxPanel(m_book
);
862 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
863 panel
->SetSizer( main_sizer
);
865 wxStaticBoxSizer
*gauge_sizer
= new wxStaticBoxSizer( wxHORIZONTAL
, panel
, _T("&wxGauge and wxSlider") );
866 main_sizer
->Add( gauge_sizer
, 0, wxALL
, 5 );
867 wxBoxSizer
*sz
= new wxBoxSizer( wxVERTICAL
);
868 gauge_sizer
->Add( sz
);
869 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxDefaultPosition
, wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
870 sz
->Add( m_gauge
, 0, wxALL
, 10 );
871 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200,
872 wxDefaultPosition
, wxSize(155,wxDefaultCoord
),
873 wxSL_AUTOTICKS
| wxSL_LABELS
);
874 m_slider
->SetTickFreq(40, 0);
876 m_slider
->SetToolTip(_T("This is a sliding slider"));
877 #endif // wxUSE_TOOLTIPS
878 sz
->Add( m_slider
, 0, wxALL
, 10 );
880 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
881 wxDefaultPosition
, wxSize(wxDefaultCoord
, 90),
882 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
883 gauge_sizer
->Add( m_gaugeVert
, 0, wxALL
, 10 );
887 wxStaticBox
*sb
= new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
888 wxDefaultPosition
, wxDefaultSize
); //, wxALIGN_CENTER );
889 wxStaticBoxSizer
*wrapping_sizer
= new wxStaticBoxSizer( sb
, wxVERTICAL
);
890 main_sizer
->Add( wrapping_sizer
, 0, wxALL
, 5 );
893 // No wrapping text in wxStaticText yet :-(
894 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
895 _T("Drag the slider!"),
897 wxSize(240, wxDefaultCoord
)
900 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
901 _T("In order see the gauge (aka progress bar) ")
902 _T("control do something you have to drag the ")
903 _T("handle of the slider to the right.")
905 _T("This is also supposed to demonstrate how ")
906 _T("to use static controls with line wrapping."),
908 wxSize(240, wxDefaultCoord
)
911 wrapping_sizer
->Add( m_wrappingText
);
913 wxStaticBoxSizer
*non_wrapping_sizer
= new wxStaticBoxSizer( wxVERTICAL
, panel
, wxT("Non-wrapping") );
914 main_sizer
->Add( non_wrapping_sizer
, 0, wxALL
, 5 );
916 m_nonWrappingText
= new wxStaticText( panel
, wxID_ANY
,
917 _T("This static text has two lines.\nThey do not wrap."),
921 non_wrapping_sizer
->Add( m_nonWrappingText
);
923 (void)new wxButton( panel
, ID_BTNNEWTEXT
, wxT("New text"), wxPoint(450, 160) );
925 int initialSpinValue
= -5;
927 s
<< initialSpinValue
;
928 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
930 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160) );
931 m_spinbutton
->SetRange(-40,30);
932 m_spinbutton
->SetValue(initialSpinValue
);
934 #if wxUSE_PROGRESSDLG
935 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
937 #endif // wxUSE_PROGRESSDLG
938 #endif // wxUSE_SPINBTN
941 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, wxEmptyString
, wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
942 //m_spinctrl->SetRange(10,30);
943 m_spinctrl
->SetValue(15);
944 #endif // wxUSE_SPINCTRL
946 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
947 #endif // wxUSE_SLIDER && wxUSE_GAUGE
950 panel
= new wxPanel(m_book
);
952 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
953 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
954 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
956 // VZ: don't leak memory
957 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
958 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
961 wxBitmap
bitmap( 100, 100 );
963 dc
.SelectObject( bitmap
);
964 dc
.SetBackground(*wxGREEN
);
965 dc
.SetPen(*wxRED_PEN
);
967 dc
.DrawEllipse(5, 5, 90, 90);
968 dc
.DrawText(_T("Bitmap"), 30, 40);
969 dc
.SelectObject( wxNullBitmap
);
971 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
972 (void)new wxToggleButton(panel
, ID_BITMAP_BTN_ENABLE
,
973 _T("Enable/disable &bitmap"), wxPoint(100, 140));
975 #if defined(__WXMSW__) || defined(__WXMOTIF__)
976 // test for masked bitmap display
977 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
980 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
982 (void)new wxStaticBitmap(panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
986 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
987 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
988 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
989 wxBitmapButton
*bmpBtn
= new wxBitmapButton
996 bmpBtn
->SetBitmapSelected(bmp2
);
997 bmpBtn
->SetBitmapFocus(bmp3
);
999 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
1000 _T("&Toggle label"), wxPoint(250, 20));
1002 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
1003 wxPoint(250, 60), wxDefaultSize
,
1004 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
1005 m_label
->SetForegroundColour( *wxBLUE
);
1007 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
1010 panel
= new wxPanel(m_book
);
1011 panel
->SetAutoLayout( true );
1013 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
1015 wxStaticBoxSizer
*csizer
=
1016 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
1018 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
1019 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
1020 check1
->SetValue (true);
1021 csizer
->Add (check1
);
1022 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
1023 check2
->SetValue (true);
1024 csizer
->Add (check2
);
1025 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
1026 check3
->SetValue (true);
1027 csizer
->Add (check3
);
1028 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
1029 check4
->SetValue (true);
1030 csizer
->Add (check4
);
1031 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
1032 check14
->SetValue (true);
1033 csizer
->Add (check14
);
1034 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
1035 checkBig
->SetValue (true);
1036 csizer
->Add (checkBig
);
1038 sizer
->Add (csizer
);
1040 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
1042 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
1044 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
1045 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
1046 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
1047 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
1048 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
1049 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
1050 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
1051 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
1053 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
1055 m_hsizer
->Add (m_buttonSizer
);
1056 m_hsizer
->Add( 20,20, 1 );
1057 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
1058 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
1060 sizer
->Add (m_hsizer
, 1, wxGROW
);
1062 panel
->SetSizer( sizer
);
1064 m_book
->AddPage(panel
, _T("wxSizer"));
1066 // set the sizer for the panel itself
1067 sizer
= new wxBoxSizer(wxVERTICAL
);
1068 sizer
->Add(m_book
, wxSizerFlags().Border().Expand());
1069 sizer
->Add(m_text
, wxSizerFlags(1).Border().Expand());
1073 void MyPanel::OnIdle(wxIdleEvent
& event
)
1075 static const int INVALID_SELECTION
= -2;
1077 static int s_selCombo
= INVALID_SELECTION
;
1079 if (!m_combo
|| !m_choice
)
1085 int sel
= m_combo
->GetSelection();
1086 if ( sel
!= s_selCombo
)
1088 if ( s_selCombo
!= INVALID_SELECTION
)
1090 wxLogMessage(_T("EVT_IDLE: combobox selection changed from %d to %d"),
1097 static int s_selChoice
= INVALID_SELECTION
;
1098 sel
= m_choice
->GetSelection();
1099 if ( sel
!= s_selChoice
)
1101 if ( s_selChoice
!= INVALID_SELECTION
)
1103 wxLogMessage(_T("EVT_IDLE: choice selection changed from %d to %d"),
1113 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
1115 int selOld
= event
.GetOldSelection();
1118 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
1119 _T("page change from taking place - if you select\n")
1120 _T("[No] the current page will stay the third one\n"),
1121 _T("Control sample"),
1122 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
1130 *m_text
<< _T("Book selection is being changed from ") << selOld
1131 << _T(" to ") << event
.GetSelection()
1132 << _T(" (current page from book is ")
1133 << m_book
->GetSelection() << _T(")\n");
1136 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1138 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1139 << _T(" (from book: ") << m_book
->GetSelection()
1143 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1145 wxLogMessage(_T("Button %c clicked."),
1146 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1149 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1151 wxLogMessage(_T("Bitmap button clicked."));
1154 void MyPanel::OnBmpButtonToggle(wxCommandEvent
& event
)
1156 FindWindow(ID_BITMAP_BTN
)->Enable(!event
.IsChecked());
1159 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1161 static wxColour s_colOld
;
1163 SetThemeEnabled(false);
1164 // test panel colour changing and propagation to the subcontrols
1165 if ( s_colOld
.Ok() )
1167 SetBackgroundColour(s_colOld
);
1168 s_colOld
= wxNullColour
;
1170 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1171 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1175 s_colOld
= wxColour(wxT("red"));
1176 SetBackgroundColour(wxT("white"));
1178 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1179 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1182 m_lbSelectThis
->Refresh();
1186 void MyPanel::OnListBox( wxCommandEvent
&event
)
1188 if (event
.GetInt() == -1)
1190 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1194 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1197 m_text
->AppendText( _T("ListBox event selection string is: '") );
1198 m_text
->AppendText( event
.GetString() );
1199 m_text
->AppendText( _T("'\n") );
1201 // can't use GetStringSelection() with multiple selections, there could be
1202 // more than one of them
1203 if ( !listbox
->HasFlag(wxLB_MULTIPLE
) )
1205 m_text
->AppendText( _T("ListBox control selection string is: '") );
1206 m_text
->AppendText( listbox
->GetStringSelection() );
1207 m_text
->AppendText( _T("'\n") );
1210 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1211 m_text
->AppendText( _T("ListBox event client data string is: '") );
1212 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1213 m_text
->AppendText( obj
->GetData() );
1215 m_text
->AppendText( wxString(_T("none")) );
1217 m_text
->AppendText( _T("'\n") );
1218 m_text
->AppendText( _T("ListBox control client data string is: '") );
1219 obj
= (wxStringClientData
*)listbox
->GetClientObject(event
.GetInt());
1221 m_text
->AppendText( obj
->GetData() );
1223 m_text
->AppendText( wxString(_T("none")) );
1224 m_text
->AppendText( _T("'\n") );
1227 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1229 m_text
->AppendText( _T("ListBox double click string is: ") );
1230 m_text
->AppendText( event
.GetString() );
1231 m_text
->AppendText( _T("\n") );
1234 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1236 switch (event
.GetId())
1238 case ID_LISTBOX_ENABLE
:
1240 m_text
->AppendText(_T("Checkbox clicked.\n"));
1242 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1244 cb
->SetToolTip( _T("Click to enable listbox") );
1246 cb
->SetToolTip( _T("Click to disable listbox") );
1247 #endif // wxUSE_TOOLTIPS
1248 m_listbox
->Enable( event
.GetInt() == 0 );
1249 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1250 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1251 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1252 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1255 case ID_LISTBOX_SEL_NUM
:
1257 if (m_listbox
->GetCount() > 2)
1258 m_listbox
->SetSelection( 2 );
1259 if (m_listboxSorted
->GetCount() > 2)
1260 m_listboxSorted
->SetSelection( 2 );
1261 m_lbSelectThis
->WarpPointer( 40, 14 );
1264 case ID_LISTBOX_SEL_STR
:
1266 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1267 m_listbox
->SetStringSelection( _T("This") );
1268 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1269 m_listboxSorted
->SetStringSelection( _T("This") );
1270 m_lbSelectNum
->WarpPointer( 40, 14 );
1273 case ID_LISTBOX_CLEAR
:
1276 m_listboxSorted
->Clear();
1279 case ID_LISTBOX_APPEND
:
1281 m_listbox
->Append( _T("Hi!") );
1282 m_listboxSorted
->Append( _T("Hi!") );
1285 case ID_LISTBOX_DELETE
:
1288 idx
= m_listbox
->GetSelection();
1289 if ( idx
!= wxNOT_FOUND
)
1290 m_listbox
->Delete( idx
);
1291 idx
= m_listboxSorted
->GetSelection();
1292 if ( idx
!= wxNOT_FOUND
)
1293 m_listboxSorted
->Delete( idx
);
1296 case ID_LISTBOX_FONT
:
1298 m_listbox
->SetFont( *wxITALIC_FONT
);
1299 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1300 m_checkbox
->SetFont( *wxITALIC_FONT
);
1308 static const wxChar
*GetDataString(wxClientData
*data
)
1310 return data
? wx_static_cast(wxStringClientData
*, data
)->GetData().c_str()
1314 void MyPanel::OnChoice( wxCommandEvent
&event
)
1316 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1319 const int sel
= choice
->GetSelection();
1321 wxClientData
*dataEvt
= event
.GetClientObject(),
1322 *dataCtrl
= choice
->GetClientObject(sel
);
1324 wxLogMessage(_T("EVT_CHOICE: item %d/%d (event/control), ")
1325 _T("string \"%s\"/\"%s\", ")
1326 _T("data \"%s\"/\"%s\""),
1327 (int)event
.GetInt(),
1329 event
.GetString().c_str(),
1330 choice
->GetStringSelection().c_str(),
1331 GetDataString(dataEvt
),
1332 GetDataString(dataCtrl
));
1335 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1337 switch (event
.GetId())
1339 case ID_CHOICE_ENABLE
:
1341 m_choice
->Enable( event
.GetInt() == 0 );
1342 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1345 case ID_CHOICE_SEL_NUM
:
1347 m_choice
->SetSelection( 2 );
1348 m_choiceSorted
->SetSelection( 2 );
1351 case ID_CHOICE_SEL_STR
:
1353 m_choice
->SetStringSelection( _T("This") );
1354 m_choiceSorted
->SetStringSelection( _T("This") );
1357 case ID_CHOICE_CLEAR
:
1360 m_choiceSorted
->Clear();
1363 case ID_CHOICE_APPEND
:
1365 m_choice
->Append( _T("Hi!") );
1366 m_choiceSorted
->Append( _T("Hi!") );
1369 case ID_CHOICE_DELETE
:
1371 int idx
= m_choice
->GetSelection();
1372 if ( idx
!= wxNOT_FOUND
)
1373 m_choice
->Delete( idx
);
1374 idx
= m_choiceSorted
->GetSelection();
1375 if ( idx
!= wxNOT_FOUND
)
1376 m_choiceSorted
->Delete( idx
);
1379 case ID_CHOICE_FONT
:
1381 m_choice
->SetFont( *wxITALIC_FONT
);
1382 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1387 #endif // wxUSE_CHOICE
1389 void MyPanel::OnCombo( wxCommandEvent
&event
)
1394 wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string \"%s\"/\"%s\""),
1395 (int)event
.GetInt(),
1396 m_combo
->GetSelection(),
1397 event
.GetString().c_str(),
1398 m_combo
->GetStringSelection().c_str());
1401 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1404 wxLogMessage(wxT("EVT_TEXT for the combobox: \"%s\" (event) or \"%s\" (control)."),
1405 event
.GetString().c_str(),
1406 m_combo
->GetValue().c_str());
1409 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1412 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1413 m_combo
->GetValue().c_str());
1416 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1418 switch (event
.GetId())
1420 case ID_COMBO_ENABLE
:
1422 m_combo
->Enable( event
.GetInt() == 0 );
1425 case ID_COMBO_SEL_NUM
:
1427 m_combo
->SetSelection( 2 );
1430 case ID_COMBO_SEL_STR
:
1432 m_combo
->SetStringSelection( _T("This") );
1435 case ID_COMBO_CLEAR
:
1440 case ID_COMBO_APPEND
:
1442 m_combo
->Append( _T("Hi!") );
1445 case ID_COMBO_DELETE
:
1447 int idx
= m_combo
->GetSelection();
1448 m_combo
->Delete( idx
);
1453 m_combo
->SetFont( *wxITALIC_FONT
);
1456 case ID_COMBO_SET_TEXT
:
1458 m_combo
->SetString( 2, wxT("Hi!") );
1464 void MyPanel::OnRadio( wxCommandEvent
&event
)
1466 m_text
->AppendText( _T("RadioBox selection string is: ") );
1467 m_text
->AppendText( event
.GetString() );
1468 m_text
->AppendText( _T("\n") );
1471 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1473 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1476 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1478 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1481 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1483 switch (event
.GetId())
1485 case ID_RADIOBOX_ENABLE
:
1486 m_radio
->Enable( event
.GetInt() == 0 );
1489 case ID_RADIOBOX_SEL_NUM
:
1490 m_radio
->SetSelection( 2 );
1493 case ID_RADIOBOX_SEL_STR
:
1494 m_radio
->SetStringSelection( _T("This") );
1497 case ID_RADIOBOX_FONT
:
1498 m_radio
->SetFont( *wxITALIC_FONT
);
1503 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1505 m_fontButton
->SetFont( *wxITALIC_FONT
);
1506 m_text
->SetFont( *wxITALIC_FONT
);
1509 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1511 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1512 : _T("Shorter text."));
1517 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1520 m_gauge
->SetValue( m_slider
->GetValue() );
1521 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1522 #endif // wxUSE_GAUGE
1525 #endif // wxUSE_SLIDER
1529 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1534 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1535 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1536 m_text
->AppendText(s
);
1540 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1545 s
.Printf( _T("Spin ctrl changed: now %d (from event: %d)\n"),
1546 m_spinctrl
->GetValue(), event
.GetInt() );
1547 m_text
->AppendText(s
);
1551 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1555 m_text
->AppendText( wxString::Format(
1556 _T("Spin up: %d (from event: %d)\n"),
1557 m_spinctrl
->GetValue(), event
.GetInt() ) );
1561 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1565 m_text
->AppendText( wxString::Format(
1566 _T("Spin down: %d (from event: %d)\n"),
1567 m_spinctrl
->GetValue(), event
.GetInt() ) );
1571 #endif // wxUSE_SPINCTRL
1574 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1577 value
.Printf( _T("Spin control up: current = %d\n"),
1578 m_spinbutton
->GetValue());
1580 if ( event
.GetPosition() > 17 )
1582 value
+= _T("Preventing the spin button from going above 17.\n");
1587 m_text
->AppendText(value
);
1590 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1593 value
.Printf( _T("Spin control down: current = %d\n"),
1594 m_spinbutton
->GetValue());
1596 if ( event
.GetPosition() < -17 )
1598 value
+= _T("Preventing the spin button from going below -17.\n");
1603 m_text
->AppendText(value
);
1606 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1609 value
.Printf( _T("%d"), event
.GetPosition() );
1610 m_spintext
->SetValue( value
);
1612 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1613 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1614 m_spinbutton
->GetValue());
1616 m_text
->AppendText(value
);
1619 void MyPanel::OnNewText( wxCommandEvent
& /* event */)
1621 m_nonWrappingText
->SetLabel( wxT("This text is short\nbut still spans\nover three lines.") );
1622 m_wrappingText
->SetLabel( wxT("This text is short but will still be wrapped if it is too long.") );
1623 m_wrappingText
->GetParent()->Layout();
1626 #if wxUSE_PROGRESSDLG
1628 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1630 event
.Enable( m_spinbutton
->GetValue() > 0 );
1633 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1635 int max
= m_spinbutton
->GetValue();
1639 wxLogError(_T("You must set positive range!"));
1643 wxProgressDialog
dialog(_T("Progress dialog example"),
1644 _T("An informative message"),
1651 wxPD_ESTIMATED_TIME
|
1652 wxPD_REMAINING_TIME
);
1656 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1661 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1663 else if ( i
== max
/ 2 )
1665 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1669 cont
= dialog
.Update(i
);
1675 *m_text
<< _T("Progress dialog aborted!\n");
1679 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1683 #endif // wxUSE_PROGRESSDLG
1684 #endif // wxUSE_SPINBTN
1686 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1688 switch (event
.GetId ()) {
1689 case ID_SIZER_CHECK1
:
1690 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1691 m_buttonSizer
->Layout ();
1693 case ID_SIZER_CHECK2
:
1694 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1695 m_buttonSizer
->Layout ();
1697 case ID_SIZER_CHECK3
:
1698 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1699 m_buttonSizer
->Layout ();
1701 case ID_SIZER_CHECK4
:
1702 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1703 m_buttonSizer
->Layout ();
1705 case ID_SIZER_CHECK14
:
1706 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1707 m_hsizer
->Layout ();
1709 case ID_SIZER_CHECKBIG
:
1710 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1711 m_hsizer
->Layout ();
1719 //wxLog::RemoveTraceMask(_T("focus"));
1720 delete wxLog::SetActiveTarget(m_logTargetOld
);
1722 delete m_book
->GetImageList();
1725 //----------------------------------------------------------------------
1727 //----------------------------------------------------------------------
1729 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1730 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1731 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1732 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1734 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1735 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1736 #endif // wxUSE_TOOLTIPS
1738 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1739 EVT_MENU(CONTROLS_CONTEXT_HELP
, MyFrame::OnContextHelp
)
1741 EVT_ICONIZE(MyFrame::OnIconized
)
1742 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1743 EVT_SIZE(MyFrame::OnSize
)
1744 EVT_MOVE(MyFrame::OnMove
)
1746 EVT_IDLE(MyFrame::OnIdle
)
1749 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1750 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(700, 450))
1752 SetHelpText( _T("Controls sample demonstrating various widgets") );
1755 // The wxICON() macros loads an icon from a resource under Windows
1756 // and uses an #included XPM image under GTK+ and Motif
1759 SetIcon( wxICON(mondrian
) );
1762 wxMenu
*file_menu
= new wxMenu
;
1764 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1765 file_menu
->AppendSeparator();
1766 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1767 file_menu
->AppendSeparator();
1768 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1770 wxMenuBar
*menu_bar
= new wxMenuBar
;
1771 menu_bar
->Append(file_menu
, _T("&File"));
1774 wxMenu
*tooltip_menu
= new wxMenu
;
1775 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1776 tooltip_menu
->AppendSeparator();
1777 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1778 _T("enable/disable tooltips"), true);
1779 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1780 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1781 #endif // wxUSE_TOOLTIPS
1783 wxMenu
*panel_menu
= new wxMenu
;
1784 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1785 _T("Enable/disable all panel controls"), true);
1786 panel_menu
->Append(CONTROLS_CONTEXT_HELP
, _T("&Context help...\tCtrl-H"),
1787 _T("Get context help for a control"));
1788 menu_bar
->Append(panel_menu
, _T("&Panel"));
1790 SetMenuBar(menu_bar
);
1794 #endif // wxUSE_STATUSBAR
1796 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1799 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1804 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1808 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1812 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1814 m_panel
->m_text
->Clear();
1818 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1820 static long s_delay
= 5000;
1823 delay
.Printf( _T("%ld"), s_delay
);
1825 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1826 _T("Set tooltip delay"),
1830 return; // cancelled
1832 wxSscanf(delay
, _T("%ld"), &s_delay
);
1834 wxToolTip::SetDelay(s_delay
);
1836 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1839 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1841 static bool s_enabled
= true;
1843 s_enabled
= !s_enabled
;
1845 wxToolTip::Enable(s_enabled
);
1847 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1851 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1853 static bool s_enable
= true;
1855 s_enable
= !s_enable
;
1856 m_panel
->Enable(s_enable
);
1859 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
1861 // starts a local event loop
1862 wxContextHelp
chelp(this);
1865 void MyFrame::OnMove( wxMoveEvent
& event
)
1868 UpdateStatusBar(event
.GetPosition(), GetSize());
1869 #endif // wxUSE_STATUSBAR
1874 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1876 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1881 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1883 wxLogMessage(_T("Frame maximized"));
1886 void MyFrame::OnSize( wxSizeEvent
& event
)
1889 UpdateStatusBar(GetPosition(), event
.GetSize());
1890 #endif // wxUSE_STATUSBAR
1895 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1897 // track the window which has the focus in the status bar
1898 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1899 wxWindow
*focus
= wxWindow::FindFocus();
1900 if ( focus
&& (focus
!= s_windowFocus
) )
1902 s_windowFocus
= focus
;
1907 _T("Focus: %s, HWND = %08x"),
1911 s_windowFocus
->GetClassInfo()->GetClassName()
1913 , (unsigned int) s_windowFocus
->GetHWND()
1919 #endif // wxUSE_STATUSBAR
1923 void MyComboBox::OnChar(wxKeyEvent
& event
)
1925 wxLogMessage(_T("MyComboBox::OnChar"));
1927 if ( event
.GetKeyCode() == 'w' )
1928 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1933 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1935 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1937 if ( event
.GetKeyCode() == 'w' )
1938 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1943 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1945 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1950 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1952 size_t count
= control
->GetCount();
1953 for ( size_t n
= 0; n
< count
; n
++ )
1956 s
.Printf(wxT("%s client data for '%s'"),
1957 name
, control
->GetString(n
).c_str());
1959 control
->SetClientObject(n
, new wxStringClientData(s
));
1965 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1967 size_t count
= control
->GetCount();
1968 for ( size_t n
= 0; n
< count
; n
++ )
1971 s
.Printf(wxT("%s client data for '%s'"),
1972 name
, control
->GetString(n
).c_str());
1974 control
->SetClientObject(n
, new wxStringClientData(s
));
1978 #endif // wxUSE_CHOICE