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
59 #define wxToggleButton wxCheckBox
60 #define EVT_TOGGLEBUTTON EVT_CHECKBOX
63 //----------------------------------------------------------------------
65 //----------------------------------------------------------------------
67 class MyApp
: public wxApp
73 class MyPanel
: public wxPanel
76 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
79 void OnSize( wxSizeEvent
& event
);
80 void OnListBox( wxCommandEvent
&event
);
81 void OnListBoxDoubleClick( wxCommandEvent
&event
);
82 void OnListBoxButtons( wxCommandEvent
&event
);
84 void OnChoice( wxCommandEvent
&event
);
85 void OnChoiceButtons( wxCommandEvent
&event
);
87 void OnCombo( wxCommandEvent
&event
);
88 void OnComboTextChanged( wxCommandEvent
&event
);
89 void OnComboTextEnter( wxCommandEvent
&event
);
90 void OnComboButtons( wxCommandEvent
&event
);
91 void OnRadio( wxCommandEvent
&event
);
92 void OnRadioButtons( wxCommandEvent
&event
);
93 void OnRadioButton1( wxCommandEvent
&event
);
94 void OnRadioButton2( wxCommandEvent
&event
);
95 void OnSetFont( wxCommandEvent
&event
);
96 void OnPageChanged( wxBookCtrlEvent
&event
);
97 void OnPageChanging( wxBookCtrlEvent
&event
);
98 void OnSliderUpdate( wxCommandEvent
&event
);
99 void OnUpdateLabel( wxCommandEvent
&event
);
101 void OnSpinUp( wxSpinEvent
&event
);
102 void OnSpinDown( wxSpinEvent
&event
);
103 void OnSpinUpdate( wxSpinEvent
&event
);
104 #if wxUSE_PROGRESSDLG
105 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
106 void OnShowProgress( wxCommandEvent
&event
);
107 #endif // wxUSE_PROGRESSDLG
108 #endif // wxUSE_SPINBTN
111 void OnSpinCtrl(wxSpinEvent
& event
);
112 void OnSpinCtrlUp(wxSpinEvent
& event
);
113 void OnSpinCtrlDown(wxSpinEvent
& event
);
114 void OnSpinCtrlText(wxCommandEvent
& event
);
115 #endif // wxUSE_SPINCTRL
117 void OnEnableAll(wxCommandEvent
& event
);
118 void OnChangeColour(wxCommandEvent
& event
);
119 void OnTestButton(wxCommandEvent
& event
);
120 void OnBmpButton(wxCommandEvent
& event
);
121 void OnBmpButtonToggle(wxCommandEvent
& event
);
123 void OnSizerCheck (wxCommandEvent
&event
);
125 wxListBox
*m_listbox
,
130 #endif // wxUSE_CHOICE
137 #endif // wxUSE_GAUGE
140 #endif // wxUSE_SLIDER
141 wxButton
*m_fontButton
;
142 wxButton
*m_lbSelectNum
;
143 wxButton
*m_lbSelectThis
;
145 wxSpinButton
*m_spinbutton
;
146 #if wxUSE_PROGRESSDLG
147 wxButton
*m_btnProgress
;
148 #endif // wxUSE_PROGRESSDLG
149 #endif // wxUSE_SPINBTN
152 wxSpinCtrl
*m_spinctrl
;
153 #endif // wxUSE_SPINCTRL
155 wxTextCtrl
*m_spintext
;
156 wxCheckBox
*m_checkbox
;
161 wxStaticText
*m_label
;
163 wxBoxSizer
*m_buttonSizer
;
164 wxButton
*m_sizerBtn1
;
165 wxButton
*m_sizerBtn2
;
166 wxButton
*m_sizerBtn3
;
167 wxButton
*m_sizerBtn4
;
168 wxBoxSizer
*m_hsizer
;
172 wxLog
*m_logTargetOld
;
174 DECLARE_EVENT_TABLE()
177 class MyFrame
: public wxFrame
180 MyFrame(const wxChar
*title
, int x
, int y
);
182 void OnQuit(wxCommandEvent
& event
);
183 void OnAbout(wxCommandEvent
& event
);
184 void OnClearLog(wxCommandEvent
& event
);
187 void OnSetTooltipDelay(wxCommandEvent
& event
);
188 void OnToggleTooltips(wxCommandEvent
& event
);
189 #endif // wxUSE_TOOLTIPS
191 void OnEnableAll(wxCommandEvent
& event
);
193 void OnIdle( wxIdleEvent
& event
);
194 void OnIconized( wxIconizeEvent
& event
);
195 void OnMaximized( wxMaximizeEvent
& event
);
196 void OnSize( wxSizeEvent
& event
);
197 void OnMove( wxMoveEvent
& event
);
199 MyPanel
*GetPanel() const { return m_panel
; }
203 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
205 if ( m_frameStatusBar
)
208 wxSize sizeAll
= GetSize(),
209 sizeCl
= GetClientSize();
210 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
213 sizeAll
.x
, sizeAll
.y
,
215 SetStatusText(msg
, 1);
218 #endif // wxUSE_STATUSBAR
222 DECLARE_EVENT_TABLE()
225 // a button which intercepts double clicks (for testing...)
226 class MyButton
: public wxButton
229 MyButton(wxWindow
*parent
,
231 const wxString
& label
= wxEmptyString
,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
)
234 : wxButton(parent
, id
, label
, pos
, size
)
238 void OnDClick(wxMouseEvent
& event
)
240 wxLogMessage(_T("MyButton::OnDClick"));
246 DECLARE_EVENT_TABLE()
249 // a combo which intercepts chars (to test Windows behaviour)
250 class MyComboBox
: public wxComboBox
253 MyComboBox(wxWindow
*parent
, wxWindowID id
,
254 const wxString
& value
= wxEmptyString
,
255 const wxPoint
& pos
= wxDefaultPosition
,
256 const wxSize
& size
= wxDefaultSize
,
257 int n
= 0, const wxString choices
[] = NULL
,
259 const wxValidator
& validator
= wxDefaultValidator
,
260 const wxString
& name
= wxComboBoxNameStr
)
261 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
265 void OnChar(wxKeyEvent
& event
);
266 void OnKeyDown(wxKeyEvent
& event
);
267 void OnKeyUp(wxKeyEvent
& event
);
268 void OnFocusGot(wxFocusEvent
& event
)
270 wxLogMessage(_T("MyComboBox::OnFocusGot"));
276 DECLARE_EVENT_TABLE()
279 // a radiobox which handles focus set/kill (for testing)
280 class MyRadioBox
: public wxRadioBox
283 MyRadioBox(wxWindow
*parent
,
285 const wxString
& title
= wxEmptyString
,
286 const wxPoint
& pos
= wxDefaultPosition
,
287 const wxSize
& size
= wxDefaultSize
,
288 int n
= 0, const wxString choices
[] = NULL
,
290 long style
= wxRA_HORIZONTAL
,
291 const wxValidator
& validator
= wxDefaultValidator
,
292 const wxString
& name
= wxRadioBoxNameStr
)
293 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
294 style
, validator
, name
) { SetForegroundColour(*wxRED
); }
297 void OnFocusGot(wxFocusEvent
& event
)
299 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
304 void OnFocusLost(wxFocusEvent
& event
)
306 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
312 DECLARE_EVENT_TABLE()
315 //----------------------------------------------------------------------
317 //----------------------------------------------------------------------
319 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
322 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
323 #endif // wxUSE_CHOICE
327 //----------------------------------------------------------------------
329 //----------------------------------------------------------------------
339 CONTROLS_SET_TOOLTIP_DELAY
= 200,
340 CONTROLS_ENABLE_TOOLTIPS
,
348 // use standard command line handling:
349 if ( !wxApp::OnInit() )
352 // parse the cmd line
357 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
358 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
361 // Create the main frame window
362 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
368 //----------------------------------------------------------------------
370 //----------------------------------------------------------------------
372 const int ID_BOOK
= 1000;
374 const int ID_LISTBOX
= 130;
375 const int ID_LISTBOX_SEL_NUM
= 131;
376 const int ID_LISTBOX_SEL_STR
= 132;
377 const int ID_LISTBOX_CLEAR
= 133;
378 const int ID_LISTBOX_APPEND
= 134;
379 const int ID_LISTBOX_DELETE
= 135;
380 const int ID_LISTBOX_FONT
= 136;
381 const int ID_LISTBOX_ENABLE
= 137;
382 const int ID_LISTBOX_SORTED
= 138;
384 const int ID_CHOICE
= 120;
385 const int ID_CHOICE_SEL_NUM
= 121;
386 const int ID_CHOICE_SEL_STR
= 122;
387 const int ID_CHOICE_CLEAR
= 123;
388 const int ID_CHOICE_APPEND
= 124;
389 const int ID_CHOICE_DELETE
= 125;
390 const int ID_CHOICE_FONT
= 126;
391 const int ID_CHOICE_ENABLE
= 127;
392 const int ID_CHOICE_SORTED
= 128;
394 const int ID_COMBO
= 140;
395 const int ID_COMBO_SEL_NUM
= 141;
396 const int ID_COMBO_SEL_STR
= 142;
397 const int ID_COMBO_CLEAR
= 143;
398 const int ID_COMBO_APPEND
= 144;
399 const int ID_COMBO_DELETE
= 145;
400 const int ID_COMBO_FONT
= 146;
401 const int ID_COMBO_ENABLE
= 147;
403 const int ID_RADIOBOX
= 160;
404 const int ID_RADIOBOX_SEL_NUM
= 161;
405 const int ID_RADIOBOX_SEL_STR
= 162;
406 const int ID_RADIOBOX_FONT
= 163;
407 const int ID_RADIOBOX_ENABLE
= 164;
409 const int ID_RADIOBUTTON_1
= 166;
410 const int ID_RADIOBUTTON_2
= 167;
412 const int ID_SET_FONT
= 170;
415 const int ID_GAUGE
= 180;
416 #endif // wxUSE_GAUGE
419 const int ID_SLIDER
= 181;
420 #endif // wxUSE_SLIDER
422 const int ID_SPIN
= 182;
423 #if wxUSE_PROGRESSDLG
424 const int ID_BTNPROGRESS
= 183;
425 #endif // wxUSE_PROGRESSDLG
426 const int ID_BUTTON_LABEL
= 184;
427 const int ID_SPINCTRL
= 185;
429 const int ID_BUTTON_TEST1
= 190;
430 const int ID_BUTTON_TEST2
= 191;
431 const int ID_BITMAP_BTN
= 192;
432 const int ID_BITMAP_BTN_ENABLE
= 193;
434 const int ID_CHANGE_COLOUR
= 200;
436 const int ID_SIZER_CHECK1
= 201;
437 const int ID_SIZER_CHECK2
= 202;
438 const int ID_SIZER_CHECK3
= 203;
439 const int ID_SIZER_CHECK4
= 204;
440 const int ID_SIZER_CHECK14
= 205;
441 const int ID_SIZER_CHECKBIG
= 206;
443 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
444 EVT_SIZE ( MyPanel::OnSize
)
445 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
446 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
447 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
448 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
449 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
450 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
451 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
452 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
453 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
454 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
455 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
456 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
458 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
459 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
460 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
461 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
462 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
463 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
464 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
465 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
466 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
468 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
469 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
470 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
471 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
472 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
473 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
474 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
475 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
476 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
477 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
478 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
479 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
480 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
481 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
482 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
483 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
484 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
485 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
487 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
488 #endif // wxUSE_SLIDER
490 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
491 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
492 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
493 #if wxUSE_PROGRESSDLG
494 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
495 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
496 #endif // wxUSE_PROGRESSDLG
497 #endif // wxUSE_SPINBTN
499 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
500 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
501 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
502 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
503 #endif // wxUSE_SPINCTRL
504 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
505 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
506 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
507 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
508 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
509 EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE
, MyPanel::OnBmpButtonToggle
)
511 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
512 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
513 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
514 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
515 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
516 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
520 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
521 EVT_LEFT_DCLICK(MyButton::OnDClick
)
524 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
525 EVT_CHAR(MyComboBox::OnChar
)
526 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
527 EVT_KEY_UP(MyComboBox::OnKeyUp
)
529 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
532 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
533 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
534 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
537 // ============================================================================
539 // ============================================================================
541 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
542 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
545 m_listboxSorted
= NULL
;
548 m_choiceSorted
= NULL
;
549 #endif // wxUSE_CHOICE
555 #endif // wxUSE_GAUGE
558 #endif // wxUSE_SLIDER
560 m_lbSelectNum
= NULL
;
561 m_lbSelectThis
= NULL
;
564 #if wxUSE_PROGRESSDLG
565 m_btnProgress
= NULL
;
566 #endif // wxUSE_PROGRESSDLG
567 #endif // wxUSE_SPINBTN
570 #endif // wxUSE_SPINCTRL
577 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
578 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
579 m_text
->SetBackgroundColour(wxT("wheat"));
581 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
583 m_book
= new wxBookCtrl(this, ID_BOOK
);
605 #endif // wxUSE_GAUGE
609 // fill the image list
610 wxBitmap
bmp(list_xpm
);
612 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
614 imagelist
-> Add( bmp
);
615 imagelist
-> Add( wxBitmap( choice_xpm
));
616 imagelist
-> Add( wxBitmap( combo_xpm
));
617 imagelist
-> Add( wxBitmap( text_xpm
));
618 imagelist
-> Add( wxBitmap( radio_xpm
));
620 imagelist
-> Add( wxBitmap( gauge_xpm
));
621 #endif // wxUSE_GAUGE
622 m_book
->SetImageList(imagelist
);
623 #elif defined(__WXMSW__)
624 // load images from resources
634 #endif // wxUSE_GAUGE
637 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
639 static const wxChar
*s_iconNames
[Image_Max
] =
648 #endif // wxUSE_GAUGE
651 for ( size_t n
= 0; n
< Image_Max
; n
++ )
653 wxBitmap
bmp(s_iconNames
[n
]);
654 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
656 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
661 m_book
->SetImageList(imagelist
);
665 #define Image_List -1
666 #define Image_Choice -1
667 #define Image_Combo -1
668 #define Image_Text -1
669 #define Image_Radio -1
671 #define Image_Gauge -1
672 #endif // wxUSE_GAUGE
677 wxPanel
*panel
= new wxPanel(m_book
);
678 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
679 wxPoint(10,10), wxSize(120,70),
680 5, choices
, wxLB_MULTIPLE
|wxLB_ALWAYS_SB
);
681 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
682 wxPoint(10,90), wxSize(120,70),
683 5, choices
, wxLB_SORT
);
685 SetListboxClientData(wxT("listbox"), m_listbox
);
686 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
688 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
690 m_listbox
->SetToolTip( _T("This is a list box") );
691 #endif // wxUSE_TOOLTIPS
693 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
694 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
695 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
696 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
697 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
698 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
700 button
->SetDefault();
701 button
->SetForegroundColour(*wxBLUE
);
704 button
->SetToolTip( _T("Press here to set italic font") );
705 #endif // wxUSE_TOOLTIPS
707 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
708 m_checkbox
->SetValue(false);
709 button
->MoveAfterInTabOrder(m_checkbox
);
711 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
712 #endif // wxUSE_TOOLTIPS
713 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
715 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
716 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
719 panel
= new wxPanel(m_book
);
720 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
721 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
722 5, choices
, wxCB_SORT
);
724 SetChoiceClientData(wxT("choice"), m_choice
);
725 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
727 m_choice
->SetSelection(2);
728 m_choice
->SetBackgroundColour( wxT("red") );
729 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
730 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
731 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
732 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
733 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
734 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
735 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
737 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
738 #endif // wxUSE_CHOICE
740 panel
= new wxPanel(m_book
);
741 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
742 wxPoint(5, 5), wxSize(150, 100));
743 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
744 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
746 wxCB_READONLY
| wxPROCESS_ENTER
);
747 m_combo
->SetBackgroundColour(*wxBLUE
);
749 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
750 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
751 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
752 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
753 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
754 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
755 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
756 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
758 wxString choices2
[] =
760 _T("First"), _T("Second"),
762 "Fourth", "Fifth", "Sixth",
763 "Seventh", "Eighth", "Nineth", "Tenth" */
766 panel
= new wxPanel(m_book
);
767 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
768 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
769 m_radio
->SetForegroundColour(*wxRED
);
772 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
773 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
774 #endif // wxUSE_TOOLTIPS
776 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
777 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
778 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
779 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
780 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
781 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
782 rb
->SetValue( false );
783 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
784 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
786 #if wxUSE_SLIDER && wxUSE_GAUGE
787 panel
= new wxPanel(m_book
);
788 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
789 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
790 m_gauge
->SetBackgroundColour(*wxGREEN
);
791 m_gauge
->SetForegroundColour(*wxRED
);
792 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
793 wxPoint(195,35), wxSize(30, 90),
794 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
795 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200,
796 wxPoint(18,85), wxSize(155,wxDefaultCoord
),
797 wxSL_AUTOTICKS
| wxSL_LABELS
);
798 m_slider
->SetTickFreq(40, 0);
800 m_slider
->SetToolTip(_T("This is a sliding slider"));
801 #endif // wxUSE_TOOLTIPS
803 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
804 wxPoint(230,10), wxSize(270,130),
808 // No wrapping text in wxStaticText yet :-(
809 (void)new wxStaticText( panel
, wxID_ANY
,
810 _T("Drag the slider!"),
812 wxSize(240, wxDefaultCoord
)
815 (void)new wxStaticText( panel
, wxID_ANY
,
816 _T("In order see the gauge (aka progress bar)\n")
817 _T("control do something you have to drag the\n")
818 _T("handle of the slider to the right.\n")
820 _T("This is also supposed to demonstrate how\n")
821 _T("to use static controls.\n"),
826 int initialSpinValue
= -5;
828 s
<< initialSpinValue
;
829 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
831 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, wxDefaultCoord
) );
832 m_spinbutton
->SetRange(-40,30);
833 m_spinbutton
->SetValue(initialSpinValue
);
835 #if wxUSE_PROGRESSDLG
836 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
838 #endif // wxUSE_PROGRESSDLG
839 #endif // wxUSE_SPINBTN
842 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
843 m_spinctrl
->SetRange(10,30);
844 m_spinctrl
->SetValue(15);
845 #endif // wxUSE_SPINCTRL
847 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
848 #endif // wxUSE_SLIDER && wxUSE_GAUGE
850 panel
= new wxPanel(m_book
);
852 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
853 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
854 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
856 // VZ: don't leak memory
857 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
858 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
861 wxBitmap
bitmap( 100, 100 );
863 dc
.SelectObject( bitmap
);
864 dc
.SetPen(*wxGREEN_PEN
);
866 dc
.DrawEllipse(5, 5, 90, 90);
867 dc
.DrawText(_T("Bitmap"), 30, 40);
868 dc
.SelectObject( wxNullBitmap
);
870 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
871 (void)new wxToggleButton(panel
, ID_BITMAP_BTN_ENABLE
,
872 _T("Enable/disable &bitmap"), wxPoint(100, 140));
874 #if defined(__WXMSW__) || defined(__WXMOTIF__)
875 // test for masked bitmap display
876 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
879 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
881 (void)new wxStaticBitmap(panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
885 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
886 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
887 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
888 wxBitmapButton
*bmpBtn
= new wxBitmapButton
895 bmpBtn
->SetBitmapSelected(bmp2
);
896 bmpBtn
->SetBitmapFocus(bmp3
);
898 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
899 _T("&Toggle label"), wxPoint(250, 20));
901 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
902 wxPoint(250, 60), wxDefaultSize
,
903 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
904 m_label
->SetForegroundColour( *wxBLUE
);
906 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
910 panel
= new wxPanel(m_book
);
911 panel
->SetAutoLayout( true );
913 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
915 wxStaticBoxSizer
*csizer
=
916 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
918 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
919 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
920 check1
->SetValue (true);
921 csizer
->Add (check1
);
922 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
923 check2
->SetValue (true);
924 csizer
->Add (check2
);
925 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
926 check3
->SetValue (true);
927 csizer
->Add (check3
);
928 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
929 check4
->SetValue (true);
930 csizer
->Add (check4
);
931 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
932 check14
->SetValue (true);
933 csizer
->Add (check14
);
934 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
935 checkBig
->SetValue (true);
936 csizer
->Add (checkBig
);
940 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
942 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
944 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
945 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
946 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
947 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
948 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
949 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
950 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
951 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
953 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
955 m_hsizer
->Add (m_buttonSizer
);
956 m_hsizer
->Add( 20,20, 1 );
957 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
958 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
960 sizer
->Add (m_hsizer
, 1, wxGROW
);
962 panel
->SetSizer( sizer
);
964 m_book
->AddPage(panel
, _T("wxSizer"));
967 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
971 GetClientSize( &x
, &y
);
973 if (m_book
) m_book
->SetSize( 2, 2, x
-4, y
*2/3-4 );
974 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
977 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
979 int selOld
= event
.GetOldSelection();
982 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
983 _T("page change from taking place - if you select\n")
984 _T("[No] the current page will stay the third one\n"),
985 _T("Control sample"),
986 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
994 *m_text
<< _T("Book selection is being changed from ") << selOld
995 << _T(" to ") << event
.GetSelection()
996 << _T(" (current page from book is ")
997 << m_book
->GetSelection() << _T(")\n");
1000 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1002 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1003 << _T(" (from book: ") << m_book
->GetSelection()
1007 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1009 wxLogMessage(_T("Button %c clicked."),
1010 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1013 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1015 wxLogMessage(_T("Bitmap button clicked."));
1018 void MyPanel::OnBmpButtonToggle(wxCommandEvent
& event
)
1020 FindWindow(ID_BITMAP_BTN
)->Enable(!event
.IsChecked());
1023 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1025 static wxColour s_colOld
;
1027 SetThemeEnabled(false);
1028 // test panel colour changing and propagation to the subcontrols
1029 if ( s_colOld
.Ok() )
1031 SetBackgroundColour(s_colOld
);
1032 s_colOld
= wxNullColour
;
1034 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1035 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1039 s_colOld
= wxColour(wxT("red"));
1040 SetBackgroundColour(wxT("white"));
1042 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1043 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1046 m_lbSelectThis
->Refresh();
1050 void MyPanel::OnListBox( wxCommandEvent
&event
)
1052 // GetParent()->Move(100, 100);
1054 if (event
.GetInt() == -1)
1056 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1060 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1063 m_text
->AppendText( _T("ListBox event selection string is: '") );
1064 m_text
->AppendText( event
.GetString() );
1065 m_text
->AppendText( _T("'\n") );
1066 m_text
->AppendText( _T("ListBox control selection string is: '") );
1067 m_text
->AppendText( listbox
->GetStringSelection() );
1068 m_text
->AppendText( _T("'\n") );
1070 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1071 m_text
->AppendText( _T("ListBox event client data string is: '") );
1072 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1073 m_text
->AppendText( obj
->GetData() );
1075 m_text
->AppendText( wxString(_T("none")) );
1077 m_text
->AppendText( _T("'\n") );
1078 m_text
->AppendText( _T("ListBox control client data string is: '") );
1079 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1081 m_text
->AppendText( obj
->GetData() );
1083 m_text
->AppendText( wxString(_T("none")) );
1084 m_text
->AppendText( _T("'\n") );
1087 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1089 m_text
->AppendText( _T("ListBox double click string is: ") );
1090 m_text
->AppendText( event
.GetString() );
1091 m_text
->AppendText( _T("\n") );
1094 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1096 switch (event
.GetId())
1098 case ID_LISTBOX_ENABLE
:
1100 m_text
->AppendText(_T("Checkbox clicked.\n"));
1102 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1104 cb
->SetToolTip( _T("Click to enable listbox") );
1106 cb
->SetToolTip( _T("Click to disable listbox") );
1107 #endif // wxUSE_TOOLTIPS
1108 m_listbox
->Enable( event
.GetInt() == 0 );
1109 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1110 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1111 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1112 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1115 case ID_LISTBOX_SEL_NUM
:
1117 if (m_listbox
->GetCount() > 2)
1118 m_listbox
->SetSelection( 2 );
1119 if (m_listboxSorted
->GetCount() > 2)
1120 m_listboxSorted
->SetSelection( 2 );
1121 m_lbSelectThis
->WarpPointer( 40, 14 );
1124 case ID_LISTBOX_SEL_STR
:
1126 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1127 m_listbox
->SetStringSelection( _T("This") );
1128 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1129 m_listboxSorted
->SetStringSelection( _T("This") );
1130 m_lbSelectNum
->WarpPointer( 40, 14 );
1133 case ID_LISTBOX_CLEAR
:
1136 m_listboxSorted
->Clear();
1139 case ID_LISTBOX_APPEND
:
1141 m_listbox
->Append( _T("Hi!") );
1142 m_listboxSorted
->Append( _T("Hi!") );
1145 case ID_LISTBOX_DELETE
:
1148 idx
= m_listbox
->GetSelection();
1149 if ( idx
!= wxNOT_FOUND
)
1150 m_listbox
->Delete( idx
);
1151 idx
= m_listboxSorted
->GetSelection();
1152 if ( idx
!= wxNOT_FOUND
)
1153 m_listboxSorted
->Delete( idx
);
1156 case ID_LISTBOX_FONT
:
1158 m_listbox
->SetFont( *wxITALIC_FONT
);
1159 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1160 m_checkbox
->SetFont( *wxITALIC_FONT
);
1167 void MyPanel::OnChoice( wxCommandEvent
&event
)
1169 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1172 m_text
->AppendText( _T("Choice event selection string is: '") );
1173 m_text
->AppendText( event
.GetString() );
1174 m_text
->AppendText( _T("'\n") );
1175 m_text
->AppendText( _T("Choice control selection string is: '") );
1176 m_text
->AppendText( choice
->GetStringSelection() );
1177 m_text
->AppendText( _T("'\n") );
1179 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1180 m_text
->AppendText( _T("Choice event client data string is: '") );
1183 m_text
->AppendText( obj
->GetData() );
1185 m_text
->AppendText( wxString(_T("none")) );
1187 m_text
->AppendText( _T("'\n") );
1188 m_text
->AppendText( _T("Choice control client data string is: '") );
1189 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1192 m_text
->AppendText( obj
->GetData() );
1194 m_text
->AppendText( wxString(_T("none")) );
1195 m_text
->AppendText( _T("'\n") );
1198 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1200 switch (event
.GetId())
1202 case ID_CHOICE_ENABLE
:
1204 m_choice
->Enable( event
.GetInt() == 0 );
1205 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1208 case ID_CHOICE_SEL_NUM
:
1210 m_choice
->SetSelection( 2 );
1211 m_choiceSorted
->SetSelection( 2 );
1214 case ID_CHOICE_SEL_STR
:
1216 m_choice
->SetStringSelection( _T("This") );
1217 m_choiceSorted
->SetStringSelection( _T("This") );
1220 case ID_CHOICE_CLEAR
:
1223 m_choiceSorted
->Clear();
1226 case ID_CHOICE_APPEND
:
1228 m_choice
->Append( _T("Hi!") );
1229 m_choiceSorted
->Append( _T("Hi!") );
1232 case ID_CHOICE_DELETE
:
1234 int idx
= m_choice
->GetSelection();
1235 if ( idx
!= wxNOT_FOUND
)
1236 m_choice
->Delete( idx
);
1237 idx
= m_choiceSorted
->GetSelection();
1238 if ( idx
!= wxNOT_FOUND
)
1239 m_choiceSorted
->Delete( idx
);
1242 case ID_CHOICE_FONT
:
1244 m_choice
->SetFont( *wxITALIC_FONT
);
1245 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1250 #endif // wxUSE_CHOICE
1252 void MyPanel::OnCombo( wxCommandEvent
&event
)
1254 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1255 m_text
->AppendText( event
.GetString() );
1256 m_text
->AppendText( _T("\n") );
1257 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1258 m_text
->AppendText( m_combo
->GetStringSelection() );
1259 m_text
->AppendText( _T("\n") );
1262 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1265 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1266 event
.GetString().c_str() );
1267 wxLogMessage( str
.c_str() );
1270 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1272 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1273 m_combo
->GetValue().c_str());
1276 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1278 switch (event
.GetId())
1280 case ID_COMBO_ENABLE
:
1282 m_combo
->Enable( event
.GetInt() == 0 );
1285 case ID_COMBO_SEL_NUM
:
1287 m_combo
->SetSelection( 2 );
1290 case ID_COMBO_SEL_STR
:
1292 m_combo
->SetStringSelection( _T("This") );
1295 case ID_COMBO_CLEAR
:
1300 case ID_COMBO_APPEND
:
1302 m_combo
->Append( _T("Hi!") );
1305 case ID_COMBO_DELETE
:
1307 int idx
= m_combo
->GetSelection();
1308 m_combo
->Delete( idx
);
1313 m_combo
->SetFont( *wxITALIC_FONT
);
1319 void MyPanel::OnRadio( wxCommandEvent
&event
)
1321 m_text
->AppendText( _T("RadioBox selection string is: ") );
1322 m_text
->AppendText( event
.GetString() );
1323 m_text
->AppendText( _T("\n") );
1326 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1328 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1331 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1333 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1336 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1338 switch (event
.GetId())
1340 case ID_RADIOBOX_ENABLE
:
1342 m_radio
->Enable( event
.GetInt() == 0 );
1345 case ID_RADIOBOX_SEL_NUM
:
1347 m_radio
->SetSelection( 2 );
1350 case ID_RADIOBOX_SEL_STR
:
1352 m_radio
->SetStringSelection( _T("This") );
1355 case ID_RADIOBOX_FONT
:
1357 m_radio
->SetForegroundColour(*wxGREEN
);
1359 m_radio
->SetFont( *wxITALIC_FONT
);
1365 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1367 m_fontButton
->SetFont( *wxITALIC_FONT
);
1368 m_text
->SetFont( *wxITALIC_FONT
);
1371 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1373 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1374 : _T("Shorter text."));
1379 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1382 m_gauge
->SetValue( m_slider
->GetValue() );
1383 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1384 #endif // wxUSE_GAUGE
1387 #endif // wxUSE_SLIDER
1391 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1396 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1397 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1398 m_text
->AppendText(s
);
1402 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1407 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1408 m_spinctrl
->GetValue(), event
.GetInt() );
1409 m_text
->AppendText(s
);
1413 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1417 m_text
->AppendText( wxString::Format(
1418 _T("Spin up: %d (from event: %ld)\n"),
1419 m_spinctrl
->GetValue(), event
.GetInt() ) );
1423 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1427 m_text
->AppendText( wxString::Format(
1428 _T("Spin down: %d (from event: %ld)\n"),
1429 m_spinctrl
->GetValue(), event
.GetInt() ) );
1433 #endif // wxUSE_SPINCTRL
1436 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1439 value
.Printf( _T("Spin control up: current = %d\n"),
1440 m_spinbutton
->GetValue());
1442 if ( event
.GetPosition() > 17 )
1444 value
+= _T("Preventing the spin button from going above 17.\n");
1449 m_text
->AppendText(value
);
1452 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1455 value
.Printf( _T("Spin control down: current = %d\n"),
1456 m_spinbutton
->GetValue());
1458 if ( event
.GetPosition() < -17 )
1460 value
+= _T("Preventing the spin button from going below -17.\n");
1465 m_text
->AppendText(value
);
1468 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1471 value
.Printf( _T("%d"), event
.GetPosition() );
1472 m_spintext
->SetValue( value
);
1474 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1475 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1476 m_spinbutton
->GetValue());
1478 m_text
->AppendText(value
);
1481 #if wxUSE_PROGRESSDLG
1483 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1485 event
.Enable( m_spinbutton
->GetValue() > 0 );
1488 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1490 int max
= m_spinbutton
->GetValue();
1494 wxLogError(_T("You must set positive range!"));
1498 wxProgressDialog
dialog(_T("Progress dialog example"),
1499 _T("An informative message"),
1506 wxPD_ESTIMATED_TIME
|
1507 wxPD_REMAINING_TIME
);
1511 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1516 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1518 else if ( i
== max
/ 2 )
1520 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1524 cont
= dialog
.Update(i
);
1530 *m_text
<< _T("Progress dialog aborted!\n");
1534 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1538 #endif // wxUSE_PROGRESSDLG
1539 #endif // wxUSE_SPINBTN
1541 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1543 switch (event
.GetId ()) {
1544 case ID_SIZER_CHECK1
:
1545 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1546 m_buttonSizer
->Layout ();
1548 case ID_SIZER_CHECK2
:
1549 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1550 m_buttonSizer
->Layout ();
1552 case ID_SIZER_CHECK3
:
1553 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1554 m_buttonSizer
->Layout ();
1556 case ID_SIZER_CHECK4
:
1557 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1558 m_buttonSizer
->Layout ();
1560 case ID_SIZER_CHECK14
:
1561 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1562 m_hsizer
->Layout ();
1564 case ID_SIZER_CHECKBIG
:
1565 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1566 m_hsizer
->Layout ();
1574 //wxLog::RemoveTraceMask(_T("focus"));
1575 delete wxLog::SetActiveTarget(m_logTargetOld
);
1577 delete m_book
->GetImageList();
1580 //----------------------------------------------------------------------
1582 //----------------------------------------------------------------------
1584 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1585 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1586 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1587 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1589 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1590 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1591 #endif // wxUSE_TOOLTIPS
1593 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1595 EVT_ICONIZE(MyFrame::OnIconized
)
1596 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1597 EVT_SIZE(MyFrame::OnSize
)
1598 EVT_MOVE(MyFrame::OnMove
)
1600 EVT_IDLE(MyFrame::OnIdle
)
1603 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1604 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1607 // The wxICON() macros loads an icon from a resource under Windows
1608 // and uses an #included XPM image under GTK+ and Motif
1611 SetIcon( wxICON(mondrian
) );
1614 wxMenu
*file_menu
= new wxMenu
;
1616 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1617 file_menu
->AppendSeparator();
1618 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1619 file_menu
->AppendSeparator();
1620 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1622 wxMenuBar
*menu_bar
= new wxMenuBar
;
1623 menu_bar
->Append(file_menu
, _T("&File"));
1626 wxMenu
*tooltip_menu
= new wxMenu
;
1627 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1628 tooltip_menu
->AppendSeparator();
1629 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1630 _T("enable/disable tooltips"), true);
1631 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1632 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1633 #endif // wxUSE_TOOLTIPS
1635 wxMenu
*panel_menu
= new wxMenu
;
1636 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1637 _T("Enable/disable all panel controls"), true);
1638 menu_bar
->Append(panel_menu
, _T("&Panel"));
1640 SetMenuBar(menu_bar
);
1644 #endif // wxUSE_STATUSBAR
1646 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1648 SetSizeHints( 500, 425 );
1651 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1656 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1660 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1664 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1666 m_panel
->m_text
->Clear();
1670 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1672 static long s_delay
= 5000;
1675 delay
.Printf( _T("%ld"), s_delay
);
1677 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1678 _T("Set tooltip delay"),
1682 return; // cancelled
1684 wxSscanf(delay
, _T("%ld"), &s_delay
);
1686 wxToolTip::SetDelay(s_delay
);
1688 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1691 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1693 static bool s_enabled
= true;
1695 s_enabled
= !s_enabled
;
1697 wxToolTip::Enable(s_enabled
);
1699 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1703 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1705 static bool s_enable
= true;
1707 s_enable
= !s_enable
;
1708 m_panel
->Enable(s_enable
);
1711 void MyFrame::OnMove( wxMoveEvent
& event
)
1714 UpdateStatusBar(event
.GetPosition(), GetSize());
1715 #endif // wxUSE_STATUSBAR
1720 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1722 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1727 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1729 wxLogMessage(_T("Frame maximized"));
1732 void MyFrame::OnSize( wxSizeEvent
& event
)
1735 UpdateStatusBar(GetPosition(), event
.GetSize());
1736 #endif // wxUSE_STATUSBAR
1741 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1743 // track the window which has the focus in the status bar
1744 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1745 wxWindow
*focus
= wxWindow::FindFocus();
1746 if ( focus
&& (focus
!= s_windowFocus
) )
1748 s_windowFocus
= focus
;
1753 _T("Focus: %s, HWND = %08x"),
1757 s_windowFocus
->GetClassInfo()->GetClassName()
1759 , (unsigned int) s_windowFocus
->GetHWND()
1765 #endif // wxUSE_STATUSBAR
1769 void MyComboBox::OnChar(wxKeyEvent
& event
)
1771 wxLogMessage(_T("MyComboBox::OnChar"));
1773 if ( event
.GetKeyCode() == 'w' )
1774 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1779 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1781 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1783 if ( event
.GetKeyCode() == 'w' )
1784 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1789 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1791 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1796 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1798 size_t count
= control
->GetCount();
1799 for ( size_t n
= 0; n
< count
; n
++ )
1802 s
.Printf(wxT("%s client data for '%s'"),
1803 name
, control
->GetString(n
).c_str());
1805 control
->SetClientObject(n
, new wxStringClientData(s
));
1811 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1813 size_t count
= control
->GetCount();
1814 for ( size_t n
= 0; n
< count
; n
++ )
1817 s
.Printf(wxT("%s client data for '%s'"),
1818 name
, control
->GetString(n
).c_str());
1820 control
->SetClientObject(n
, new wxStringClientData(s
));
1824 #endif // wxUSE_CHOICE