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
109 void OnNewText( wxCommandEvent
&event
);
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
150 wxStaticText
*m_wrappingText
;
151 wxStaticText
*m_nonWrappingText
;
154 wxSpinCtrl
*m_spinctrl
;
155 #endif // wxUSE_SPINCTRL
157 wxTextCtrl
*m_spintext
;
158 wxCheckBox
*m_checkbox
;
163 wxStaticText
*m_label
;
165 wxBoxSizer
*m_buttonSizer
;
166 wxButton
*m_sizerBtn1
;
167 wxButton
*m_sizerBtn2
;
168 wxButton
*m_sizerBtn3
;
169 wxButton
*m_sizerBtn4
;
170 wxBoxSizer
*m_hsizer
;
174 wxLog
*m_logTargetOld
;
176 DECLARE_EVENT_TABLE()
179 class MyFrame
: public wxFrame
182 MyFrame(const wxChar
*title
, int x
, int y
);
184 void OnQuit(wxCommandEvent
& event
);
185 void OnAbout(wxCommandEvent
& event
);
186 void OnClearLog(wxCommandEvent
& event
);
189 void OnSetTooltipDelay(wxCommandEvent
& event
);
190 void OnToggleTooltips(wxCommandEvent
& event
);
191 #endif // wxUSE_TOOLTIPS
193 void OnEnableAll(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
) { SetForegroundColour(*wxRED
); }
299 void OnFocusGot(wxFocusEvent
& event
)
301 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
306 void OnFocusLost(wxFocusEvent
& event
)
308 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
314 DECLARE_EVENT_TABLE()
317 //----------------------------------------------------------------------
319 //----------------------------------------------------------------------
321 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
324 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
325 #endif // wxUSE_CHOICE
329 //----------------------------------------------------------------------
331 //----------------------------------------------------------------------
341 CONTROLS_SET_TOOLTIP_DELAY
= 200,
342 CONTROLS_ENABLE_TOOLTIPS
,
350 // use standard command line handling:
351 if ( !wxApp::OnInit() )
354 // parse the cmd line
359 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
360 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
363 // Create the main frame window
364 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
370 //----------------------------------------------------------------------
372 //----------------------------------------------------------------------
374 const int ID_BOOK
= 1000;
376 const int ID_LISTBOX
= 130;
377 const int ID_LISTBOX_SEL_NUM
= 131;
378 const int ID_LISTBOX_SEL_STR
= 132;
379 const int ID_LISTBOX_CLEAR
= 133;
380 const int ID_LISTBOX_APPEND
= 134;
381 const int ID_LISTBOX_DELETE
= 135;
382 const int ID_LISTBOX_FONT
= 136;
383 const int ID_LISTBOX_ENABLE
= 137;
384 const int ID_LISTBOX_SORTED
= 138;
386 const int ID_CHOICE
= 120;
387 const int ID_CHOICE_SEL_NUM
= 121;
388 const int ID_CHOICE_SEL_STR
= 122;
389 const int ID_CHOICE_CLEAR
= 123;
390 const int ID_CHOICE_APPEND
= 124;
391 const int ID_CHOICE_DELETE
= 125;
392 const int ID_CHOICE_FONT
= 126;
393 const int ID_CHOICE_ENABLE
= 127;
394 const int ID_CHOICE_SORTED
= 128;
396 const int ID_COMBO
= 140;
397 const int ID_COMBO_SEL_NUM
= 141;
398 const int ID_COMBO_SEL_STR
= 142;
399 const int ID_COMBO_CLEAR
= 143;
400 const int ID_COMBO_APPEND
= 144;
401 const int ID_COMBO_DELETE
= 145;
402 const int ID_COMBO_FONT
= 146;
403 const int ID_COMBO_ENABLE
= 147;
405 const int ID_RADIOBOX
= 160;
406 const int ID_RADIOBOX_SEL_NUM
= 161;
407 const int ID_RADIOBOX_SEL_STR
= 162;
408 const int ID_RADIOBOX_FONT
= 163;
409 const int ID_RADIOBOX_ENABLE
= 164;
411 const int ID_RADIOBUTTON_1
= 166;
412 const int ID_RADIOBUTTON_2
= 167;
414 const int ID_SET_FONT
= 170;
417 const int ID_GAUGE
= 180;
418 #endif // wxUSE_GAUGE
421 const int ID_SLIDER
= 181;
422 #endif // wxUSE_SLIDER
424 const int ID_SPIN
= 182;
425 #if wxUSE_PROGRESSDLG
426 const int ID_BTNPROGRESS
= 183;
427 #endif // wxUSE_PROGRESSDLG
428 const int ID_BUTTON_LABEL
= 184;
429 const int ID_SPINCTRL
= 185;
430 const int ID_BTNNEWTEXT
= 186;
432 const int ID_BUTTON_TEST1
= 190;
433 const int ID_BUTTON_TEST2
= 191;
434 const int ID_BITMAP_BTN
= 192;
435 const int ID_BITMAP_BTN_ENABLE
= 193;
437 const int ID_CHANGE_COLOUR
= 200;
439 const int ID_SIZER_CHECK1
= 201;
440 const int ID_SIZER_CHECK2
= 202;
441 const int ID_SIZER_CHECK3
= 203;
442 const int ID_SIZER_CHECK4
= 204;
443 const int ID_SIZER_CHECK14
= 205;
444 const int ID_SIZER_CHECKBIG
= 206;
446 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
447 EVT_SIZE ( MyPanel::OnSize
)
448 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
449 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
450 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
451 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
452 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
453 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
454 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
455 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
456 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
457 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
458 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
459 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
461 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
462 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
463 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
464 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
465 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
466 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
467 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
468 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
469 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
471 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
472 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
473 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
474 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
475 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
476 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
477 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
478 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
479 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
480 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
481 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
482 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
483 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
484 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
485 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
486 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
487 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
488 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
490 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
491 #endif // wxUSE_SLIDER
493 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
494 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
495 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
496 #if wxUSE_PROGRESSDLG
497 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
498 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
499 #endif // wxUSE_PROGRESSDLG
500 #endif // wxUSE_SPINBTN
502 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
503 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
504 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
505 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
506 #endif // wxUSE_SPINCTRL
507 EVT_BUTTON (ID_BTNNEWTEXT
, MyPanel::OnNewText
)
508 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
509 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
510 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
511 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
512 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
513 EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE
, MyPanel::OnBmpButtonToggle
)
515 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
516 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
517 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
518 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
519 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
520 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
524 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
525 EVT_LEFT_DCLICK(MyButton::OnDClick
)
528 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
529 EVT_CHAR(MyComboBox::OnChar
)
530 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
531 EVT_KEY_UP(MyComboBox::OnKeyUp
)
533 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
536 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
537 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
538 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
541 // ============================================================================
543 // ============================================================================
545 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
546 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
549 m_listboxSorted
= NULL
;
552 m_choiceSorted
= NULL
;
553 #endif // wxUSE_CHOICE
559 #endif // wxUSE_GAUGE
562 #endif // wxUSE_SLIDER
564 m_lbSelectNum
= NULL
;
565 m_lbSelectThis
= NULL
;
568 #if wxUSE_PROGRESSDLG
569 m_btnProgress
= NULL
;
570 #endif // wxUSE_PROGRESSDLG
571 #endif // wxUSE_SPINBTN
574 #endif // wxUSE_SPINCTRL
581 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
582 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
583 m_text
->SetBackgroundColour(wxT("wheat"));
585 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
587 m_book
= new wxBookCtrl(this, ID_BOOK
);
609 #endif // wxUSE_GAUGE
613 // fill the image list
614 wxBitmap
bmp(list_xpm
);
616 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
618 imagelist
-> Add( bmp
);
619 imagelist
-> Add( wxBitmap( choice_xpm
));
620 imagelist
-> Add( wxBitmap( combo_xpm
));
621 imagelist
-> Add( wxBitmap( text_xpm
));
622 imagelist
-> Add( wxBitmap( radio_xpm
));
624 imagelist
-> Add( wxBitmap( gauge_xpm
));
625 #endif // wxUSE_GAUGE
626 m_book
->SetImageList(imagelist
);
627 #elif defined(__WXMSW__)
628 // load images from resources
638 #endif // wxUSE_GAUGE
641 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
643 static const wxChar
*s_iconNames
[Image_Max
] =
652 #endif // wxUSE_GAUGE
655 for ( size_t n
= 0; n
< Image_Max
; n
++ )
657 wxBitmap
bmp(s_iconNames
[n
]);
658 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
660 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
665 m_book
->SetImageList(imagelist
);
669 #define Image_List -1
670 #define Image_Choice -1
671 #define Image_Combo -1
672 #define Image_Text -1
673 #define Image_Radio -1
675 #define Image_Gauge -1
676 #endif // wxUSE_GAUGE
681 wxPanel
*panel
= new wxPanel(m_book
);
682 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
683 wxPoint(10,10), wxSize(120,70),
684 5, choices
, wxLB_MULTIPLE
|wxLB_ALWAYS_SB
);
685 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
686 wxPoint(10,90), wxSize(120,70),
687 5, choices
, wxLB_SORT
);
689 SetListboxClientData(wxT("listbox"), m_listbox
);
690 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
692 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
694 m_listbox
->SetToolTip( _T("This is a list box") );
695 #endif // wxUSE_TOOLTIPS
697 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
698 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
699 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
700 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
701 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
702 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
704 button
->SetDefault();
705 button
->SetForegroundColour(*wxBLUE
);
708 button
->SetToolTip( _T("Press here to set italic font") );
709 #endif // wxUSE_TOOLTIPS
711 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
712 m_checkbox
->SetValue(false);
713 button
->MoveAfterInTabOrder(m_checkbox
);
715 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
716 #endif // wxUSE_TOOLTIPS
717 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
719 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
720 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
723 panel
= new wxPanel(m_book
);
724 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
725 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
726 5, choices
, wxCB_SORT
);
728 SetChoiceClientData(wxT("choice"), m_choice
);
729 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
731 m_choice
->SetSelection(2);
732 m_choice
->SetBackgroundColour( wxT("red") );
733 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
734 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
735 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
736 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
737 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
738 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
739 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
741 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
742 #endif // wxUSE_CHOICE
744 panel
= new wxPanel(m_book
);
745 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
746 wxPoint(5, 5), wxSize(150, 100));
747 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
748 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
750 wxCB_READONLY
| wxPROCESS_ENTER
);
751 m_combo
->SetBackgroundColour(*wxBLUE
);
753 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
754 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
755 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
756 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
757 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
758 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
759 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
760 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
762 wxString choices2
[] =
764 _T("First"), _T("Second"),
766 "Fourth", "Fifth", "Sixth",
767 "Seventh", "Eighth", "Nineth", "Tenth" */
770 panel
= new wxPanel(m_book
);
771 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
772 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
773 m_radio
->SetForegroundColour(*wxRED
);
776 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
777 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
778 #endif // wxUSE_TOOLTIPS
780 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
781 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
782 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
783 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
784 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
785 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
786 rb
->SetValue( false );
787 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
788 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
791 #if wxUSE_SLIDER && wxUSE_GAUGE
792 panel
= new wxPanel(m_book
);
794 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
795 panel
->SetSizer( main_sizer
);
797 wxStaticBoxSizer
*gauge_sizer
= new wxStaticBoxSizer( wxHORIZONTAL
, panel
, _T("&wxGauge and wxSlider") );
798 main_sizer
->Add( gauge_sizer
, 0, wxALL
, 5 );
799 wxBoxSizer
*sz
= new wxBoxSizer( wxVERTICAL
);
800 gauge_sizer
->Add( sz
);
801 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxDefaultPosition
, wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
802 m_gauge
->SetBackgroundColour(*wxGREEN
);
803 m_gauge
->SetForegroundColour(*wxRED
);
804 sz
->Add( m_gauge
, 0, wxALL
, 10 );
805 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200,
806 wxDefaultPosition
, wxSize(155,wxDefaultCoord
),
807 wxSL_AUTOTICKS
| wxSL_LABELS
);
808 m_slider
->SetTickFreq(40, 0);
810 m_slider
->SetToolTip(_T("This is a sliding slider"));
811 #endif // wxUSE_TOOLTIPS
812 sz
->Add( m_slider
, 0, wxALL
, 10 );
814 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
815 wxDefaultPosition
, wxSize(wxDefaultCoord
, 90),
816 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
817 gauge_sizer
->Add( m_gaugeVert
, 0, wxALL
, 10 );
821 wxStaticBox
*sb
= new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
822 wxDefaultPosition
, wxDefaultSize
); //, wxALIGN_CENTER );
823 wxStaticBoxSizer
*wrapping_sizer
= new wxStaticBoxSizer( sb
, wxVERTICAL
);
824 main_sizer
->Add( wrapping_sizer
, 0, wxALL
, 5 );
827 // No wrapping text in wxStaticText yet :-(
828 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
829 _T("Drag the slider!"),
831 wxSize(240, wxDefaultCoord
)
834 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
835 _T("In order see the gauge (aka progress bar) ")
836 _T("control do something you have to drag the ")
837 _T("handle of the slider to the right.")
839 _T("This is also supposed to demonstrate how ")
840 _T("to use static controls with line wrapping."),
845 wrapping_sizer
->Add( m_wrappingText
);
847 wxStaticBoxSizer
*non_wrapping_sizer
= new wxStaticBoxSizer( wxVERTICAL
, panel
, wxT("Non-wrapping") );
848 main_sizer
->Add( non_wrapping_sizer
, 0, wxALL
, 5 );
850 m_nonWrappingText
= new wxStaticText( panel
, wxID_ANY
,
851 _T("This static text has two lines.\nThey do not wrap."),
855 non_wrapping_sizer
->Add( m_nonWrappingText
);
857 (void)new wxButton( panel
, ID_BTNNEWTEXT
, wxT("New text"), wxPoint(450, 160) );
859 int initialSpinValue
= -5;
861 s
<< initialSpinValue
;
862 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
864 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160) );
865 m_spinbutton
->SetRange(-40,30);
866 m_spinbutton
->SetValue(initialSpinValue
);
868 #if wxUSE_PROGRESSDLG
869 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
871 #endif // wxUSE_PROGRESSDLG
872 #endif // wxUSE_SPINBTN
875 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
876 m_spinctrl
->SetRange(10,30);
877 m_spinctrl
->SetValue(15);
878 #endif // wxUSE_SPINCTRL
880 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
881 #endif // wxUSE_SLIDER && wxUSE_GAUGE
884 panel
= new wxPanel(m_book
);
886 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
887 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
888 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
890 // VZ: don't leak memory
891 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
892 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
895 wxBitmap
bitmap( 100, 100 );
897 dc
.SelectObject( bitmap
);
898 dc
.SetPen(*wxGREEN_PEN
);
900 dc
.DrawEllipse(5, 5, 90, 90);
901 dc
.DrawText(_T("Bitmap"), 30, 40);
902 dc
.SelectObject( wxNullBitmap
);
904 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
905 (void)new wxToggleButton(panel
, ID_BITMAP_BTN_ENABLE
,
906 _T("Enable/disable &bitmap"), wxPoint(100, 140));
908 #if defined(__WXMSW__) || defined(__WXMOTIF__)
909 // test for masked bitmap display
910 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
913 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
915 (void)new wxStaticBitmap(panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
919 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
920 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
921 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
922 wxBitmapButton
*bmpBtn
= new wxBitmapButton
929 bmpBtn
->SetBitmapSelected(bmp2
);
930 bmpBtn
->SetBitmapFocus(bmp3
);
932 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
933 _T("&Toggle label"), wxPoint(250, 20));
935 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
936 wxPoint(250, 60), wxDefaultSize
,
937 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
938 m_label
->SetForegroundColour( *wxBLUE
);
940 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
944 panel
= new wxPanel(m_book
);
945 panel
->SetAutoLayout( true );
947 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
949 wxStaticBoxSizer
*csizer
=
950 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
952 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
953 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
954 check1
->SetValue (true);
955 csizer
->Add (check1
);
956 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
957 check2
->SetValue (true);
958 csizer
->Add (check2
);
959 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
960 check3
->SetValue (true);
961 csizer
->Add (check3
);
962 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
963 check4
->SetValue (true);
964 csizer
->Add (check4
);
965 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
966 check14
->SetValue (true);
967 csizer
->Add (check14
);
968 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
969 checkBig
->SetValue (true);
970 csizer
->Add (checkBig
);
974 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
976 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
978 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
979 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
980 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
981 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
982 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
983 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
984 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
985 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
987 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
989 m_hsizer
->Add (m_buttonSizer
);
990 m_hsizer
->Add( 20,20, 1 );
991 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
992 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
994 sizer
->Add (m_hsizer
, 1, wxGROW
);
996 panel
->SetSizer( sizer
);
998 m_book
->AddPage(panel
, _T("wxSizer"));
1001 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1005 GetClientSize( &x
, &y
);
1007 if (m_book
) m_book
->SetSize( 2, 2, x
-4, y
*2/3-4 );
1008 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
1011 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
1013 int selOld
= event
.GetOldSelection();
1016 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
1017 _T("page change from taking place - if you select\n")
1018 _T("[No] the current page will stay the third one\n"),
1019 _T("Control sample"),
1020 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
1028 *m_text
<< _T("Book selection is being changed from ") << selOld
1029 << _T(" to ") << event
.GetSelection()
1030 << _T(" (current page from book is ")
1031 << m_book
->GetSelection() << _T(")\n");
1034 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1036 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1037 << _T(" (from book: ") << m_book
->GetSelection()
1041 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1043 wxLogMessage(_T("Button %c clicked."),
1044 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1047 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1049 wxLogMessage(_T("Bitmap button clicked."));
1052 void MyPanel::OnBmpButtonToggle(wxCommandEvent
& event
)
1054 FindWindow(ID_BITMAP_BTN
)->Enable(!event
.IsChecked());
1057 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1059 static wxColour s_colOld
;
1061 SetThemeEnabled(false);
1062 // test panel colour changing and propagation to the subcontrols
1063 if ( s_colOld
.Ok() )
1065 SetBackgroundColour(s_colOld
);
1066 s_colOld
= wxNullColour
;
1068 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1069 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1073 s_colOld
= wxColour(wxT("red"));
1074 SetBackgroundColour(wxT("white"));
1076 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1077 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1080 m_lbSelectThis
->Refresh();
1084 void MyPanel::OnListBox( wxCommandEvent
&event
)
1086 // GetParent()->Move(100, 100);
1088 if (event
.GetInt() == -1)
1090 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1094 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1097 m_text
->AppendText( _T("ListBox event selection string is: '") );
1098 m_text
->AppendText( event
.GetString() );
1099 m_text
->AppendText( _T("'\n") );
1100 m_text
->AppendText( _T("ListBox control selection string is: '") );
1101 m_text
->AppendText( listbox
->GetStringSelection() );
1102 m_text
->AppendText( _T("'\n") );
1104 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1105 m_text
->AppendText( _T("ListBox event client data string is: '") );
1106 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1107 m_text
->AppendText( obj
->GetData() );
1109 m_text
->AppendText( wxString(_T("none")) );
1111 m_text
->AppendText( _T("'\n") );
1112 m_text
->AppendText( _T("ListBox control client data string is: '") );
1113 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1115 m_text
->AppendText( obj
->GetData() );
1117 m_text
->AppendText( wxString(_T("none")) );
1118 m_text
->AppendText( _T("'\n") );
1121 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1123 m_text
->AppendText( _T("ListBox double click string is: ") );
1124 m_text
->AppendText( event
.GetString() );
1125 m_text
->AppendText( _T("\n") );
1128 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1130 switch (event
.GetId())
1132 case ID_LISTBOX_ENABLE
:
1134 m_text
->AppendText(_T("Checkbox clicked.\n"));
1136 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1138 cb
->SetToolTip( _T("Click to enable listbox") );
1140 cb
->SetToolTip( _T("Click to disable listbox") );
1141 #endif // wxUSE_TOOLTIPS
1142 m_listbox
->Enable( event
.GetInt() == 0 );
1143 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1144 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1145 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1146 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1149 case ID_LISTBOX_SEL_NUM
:
1151 if (m_listbox
->GetCount() > 2)
1152 m_listbox
->SetSelection( 2 );
1153 if (m_listboxSorted
->GetCount() > 2)
1154 m_listboxSorted
->SetSelection( 2 );
1155 m_lbSelectThis
->WarpPointer( 40, 14 );
1158 case ID_LISTBOX_SEL_STR
:
1160 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1161 m_listbox
->SetStringSelection( _T("This") );
1162 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1163 m_listboxSorted
->SetStringSelection( _T("This") );
1164 m_lbSelectNum
->WarpPointer( 40, 14 );
1167 case ID_LISTBOX_CLEAR
:
1170 m_listboxSorted
->Clear();
1173 case ID_LISTBOX_APPEND
:
1175 m_listbox
->Append( _T("Hi!") );
1176 m_listboxSorted
->Append( _T("Hi!") );
1179 case ID_LISTBOX_DELETE
:
1182 idx
= m_listbox
->GetSelection();
1183 if ( idx
!= wxNOT_FOUND
)
1184 m_listbox
->Delete( idx
);
1185 idx
= m_listboxSorted
->GetSelection();
1186 if ( idx
!= wxNOT_FOUND
)
1187 m_listboxSorted
->Delete( idx
);
1190 case ID_LISTBOX_FONT
:
1192 m_listbox
->SetFont( *wxITALIC_FONT
);
1193 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1194 m_checkbox
->SetFont( *wxITALIC_FONT
);
1201 void MyPanel::OnChoice( wxCommandEvent
&event
)
1203 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1206 m_text
->AppendText( _T("Choice event selection string is: '") );
1207 m_text
->AppendText( event
.GetString() );
1208 m_text
->AppendText( _T("'\n") );
1209 m_text
->AppendText( _T("Choice control selection string is: '") );
1210 m_text
->AppendText( choice
->GetStringSelection() );
1211 m_text
->AppendText( _T("'\n") );
1213 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1214 m_text
->AppendText( _T("Choice event client data string is: '") );
1217 m_text
->AppendText( obj
->GetData() );
1219 m_text
->AppendText( wxString(_T("none")) );
1221 m_text
->AppendText( _T("'\n") );
1222 m_text
->AppendText( _T("Choice control client data string is: '") );
1223 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1226 m_text
->AppendText( obj
->GetData() );
1228 m_text
->AppendText( wxString(_T("none")) );
1229 m_text
->AppendText( _T("'\n") );
1232 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1234 switch (event
.GetId())
1236 case ID_CHOICE_ENABLE
:
1238 m_choice
->Enable( event
.GetInt() == 0 );
1239 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1242 case ID_CHOICE_SEL_NUM
:
1244 m_choice
->SetSelection( 2 );
1245 m_choiceSorted
->SetSelection( 2 );
1248 case ID_CHOICE_SEL_STR
:
1250 m_choice
->SetStringSelection( _T("This") );
1251 m_choiceSorted
->SetStringSelection( _T("This") );
1254 case ID_CHOICE_CLEAR
:
1257 m_choiceSorted
->Clear();
1260 case ID_CHOICE_APPEND
:
1262 m_choice
->Append( _T("Hi!") );
1263 m_choiceSorted
->Append( _T("Hi!") );
1266 case ID_CHOICE_DELETE
:
1268 int idx
= m_choice
->GetSelection();
1269 if ( idx
!= wxNOT_FOUND
)
1270 m_choice
->Delete( idx
);
1271 idx
= m_choiceSorted
->GetSelection();
1272 if ( idx
!= wxNOT_FOUND
)
1273 m_choiceSorted
->Delete( idx
);
1276 case ID_CHOICE_FONT
:
1278 m_choice
->SetFont( *wxITALIC_FONT
);
1279 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1284 #endif // wxUSE_CHOICE
1286 void MyPanel::OnCombo( wxCommandEvent
&event
)
1288 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1289 m_text
->AppendText( event
.GetString() );
1290 m_text
->AppendText( _T("\n") );
1291 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1292 m_text
->AppendText( m_combo
->GetStringSelection() );
1293 m_text
->AppendText( _T("\n") );
1296 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1299 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1300 event
.GetString().c_str() );
1301 wxLogMessage( str
.c_str() );
1304 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1306 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1307 m_combo
->GetValue().c_str());
1310 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1312 switch (event
.GetId())
1314 case ID_COMBO_ENABLE
:
1316 m_combo
->Enable( event
.GetInt() == 0 );
1319 case ID_COMBO_SEL_NUM
:
1321 m_combo
->SetSelection( 2 );
1324 case ID_COMBO_SEL_STR
:
1326 m_combo
->SetStringSelection( _T("This") );
1329 case ID_COMBO_CLEAR
:
1334 case ID_COMBO_APPEND
:
1336 m_combo
->Append( _T("Hi!") );
1339 case ID_COMBO_DELETE
:
1341 int idx
= m_combo
->GetSelection();
1342 m_combo
->Delete( idx
);
1347 m_combo
->SetFont( *wxITALIC_FONT
);
1353 void MyPanel::OnRadio( wxCommandEvent
&event
)
1355 m_text
->AppendText( _T("RadioBox selection string is: ") );
1356 m_text
->AppendText( event
.GetString() );
1357 m_text
->AppendText( _T("\n") );
1360 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1362 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1365 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1367 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1370 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1372 switch (event
.GetId())
1374 case ID_RADIOBOX_ENABLE
:
1376 m_radio
->Enable( event
.GetInt() == 0 );
1379 case ID_RADIOBOX_SEL_NUM
:
1381 m_radio
->SetSelection( 2 );
1384 case ID_RADIOBOX_SEL_STR
:
1386 m_radio
->SetStringSelection( _T("This") );
1389 case ID_RADIOBOX_FONT
:
1391 m_radio
->SetForegroundColour(*wxGREEN
);
1393 m_radio
->SetFont( *wxITALIC_FONT
);
1399 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1401 m_fontButton
->SetFont( *wxITALIC_FONT
);
1402 m_text
->SetFont( *wxITALIC_FONT
);
1405 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1407 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1408 : _T("Shorter text."));
1413 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1416 m_gauge
->SetValue( m_slider
->GetValue() );
1417 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1418 #endif // wxUSE_GAUGE
1421 #endif // wxUSE_SLIDER
1425 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1430 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1431 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1432 m_text
->AppendText(s
);
1436 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1441 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1442 m_spinctrl
->GetValue(), event
.GetInt() );
1443 m_text
->AppendText(s
);
1447 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1451 m_text
->AppendText( wxString::Format(
1452 _T("Spin up: %d (from event: %ld)\n"),
1453 m_spinctrl
->GetValue(), event
.GetInt() ) );
1457 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1461 m_text
->AppendText( wxString::Format(
1462 _T("Spin down: %d (from event: %ld)\n"),
1463 m_spinctrl
->GetValue(), event
.GetInt() ) );
1467 #endif // wxUSE_SPINCTRL
1470 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1473 value
.Printf( _T("Spin control up: current = %d\n"),
1474 m_spinbutton
->GetValue());
1476 if ( event
.GetPosition() > 17 )
1478 value
+= _T("Preventing the spin button from going above 17.\n");
1483 m_text
->AppendText(value
);
1486 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1489 value
.Printf( _T("Spin control down: current = %d\n"),
1490 m_spinbutton
->GetValue());
1492 if ( event
.GetPosition() < -17 )
1494 value
+= _T("Preventing the spin button from going below -17.\n");
1499 m_text
->AppendText(value
);
1502 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1505 value
.Printf( _T("%d"), event
.GetPosition() );
1506 m_spintext
->SetValue( value
);
1508 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1509 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1510 m_spinbutton
->GetValue());
1512 m_text
->AppendText(value
);
1515 void MyPanel::OnNewText( wxCommandEvent
& /* event */)
1517 m_nonWrappingText
->SetLabel( wxT("This text is short\nbut still spans\nover three lines.") );
1518 m_wrappingText
->SetLabel( wxT("This text is short but will still be wrapped if it is too long.") );
1519 m_wrappingText
->GetParent()->Layout();
1522 #if wxUSE_PROGRESSDLG
1524 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1526 event
.Enable( m_spinbutton
->GetValue() > 0 );
1529 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1531 int max
= m_spinbutton
->GetValue();
1535 wxLogError(_T("You must set positive range!"));
1539 wxProgressDialog
dialog(_T("Progress dialog example"),
1540 _T("An informative message"),
1547 wxPD_ESTIMATED_TIME
|
1548 wxPD_REMAINING_TIME
);
1552 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1557 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1559 else if ( i
== max
/ 2 )
1561 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1565 cont
= dialog
.Update(i
);
1571 *m_text
<< _T("Progress dialog aborted!\n");
1575 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1579 #endif // wxUSE_PROGRESSDLG
1580 #endif // wxUSE_SPINBTN
1582 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1584 switch (event
.GetId ()) {
1585 case ID_SIZER_CHECK1
:
1586 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1587 m_buttonSizer
->Layout ();
1589 case ID_SIZER_CHECK2
:
1590 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1591 m_buttonSizer
->Layout ();
1593 case ID_SIZER_CHECK3
:
1594 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1595 m_buttonSizer
->Layout ();
1597 case ID_SIZER_CHECK4
:
1598 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1599 m_buttonSizer
->Layout ();
1601 case ID_SIZER_CHECK14
:
1602 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1603 m_hsizer
->Layout ();
1605 case ID_SIZER_CHECKBIG
:
1606 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1607 m_hsizer
->Layout ();
1615 //wxLog::RemoveTraceMask(_T("focus"));
1616 delete wxLog::SetActiveTarget(m_logTargetOld
);
1618 delete m_book
->GetImageList();
1621 //----------------------------------------------------------------------
1623 //----------------------------------------------------------------------
1625 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1626 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1627 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1628 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1630 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1631 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1632 #endif // wxUSE_TOOLTIPS
1634 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1636 EVT_ICONIZE(MyFrame::OnIconized
)
1637 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1638 EVT_SIZE(MyFrame::OnSize
)
1639 EVT_MOVE(MyFrame::OnMove
)
1641 EVT_IDLE(MyFrame::OnIdle
)
1644 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1645 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1648 // The wxICON() macros loads an icon from a resource under Windows
1649 // and uses an #included XPM image under GTK+ and Motif
1652 SetIcon( wxICON(mondrian
) );
1655 wxMenu
*file_menu
= new wxMenu
;
1657 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1658 file_menu
->AppendSeparator();
1659 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1660 file_menu
->AppendSeparator();
1661 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1663 wxMenuBar
*menu_bar
= new wxMenuBar
;
1664 menu_bar
->Append(file_menu
, _T("&File"));
1667 wxMenu
*tooltip_menu
= new wxMenu
;
1668 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1669 tooltip_menu
->AppendSeparator();
1670 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1671 _T("enable/disable tooltips"), true);
1672 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1673 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1674 #endif // wxUSE_TOOLTIPS
1676 wxMenu
*panel_menu
= new wxMenu
;
1677 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1678 _T("Enable/disable all panel controls"), true);
1679 menu_bar
->Append(panel_menu
, _T("&Panel"));
1681 SetMenuBar(menu_bar
);
1685 #endif // wxUSE_STATUSBAR
1687 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1689 SetSizeHints( 500, 425 );
1692 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1697 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1701 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1705 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1707 m_panel
->m_text
->Clear();
1711 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1713 static long s_delay
= 5000;
1716 delay
.Printf( _T("%ld"), s_delay
);
1718 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1719 _T("Set tooltip delay"),
1723 return; // cancelled
1725 wxSscanf(delay
, _T("%ld"), &s_delay
);
1727 wxToolTip::SetDelay(s_delay
);
1729 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1732 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1734 static bool s_enabled
= true;
1736 s_enabled
= !s_enabled
;
1738 wxToolTip::Enable(s_enabled
);
1740 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1744 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1746 static bool s_enable
= true;
1748 s_enable
= !s_enable
;
1749 m_panel
->Enable(s_enable
);
1752 void MyFrame::OnMove( wxMoveEvent
& event
)
1755 UpdateStatusBar(event
.GetPosition(), GetSize());
1756 #endif // wxUSE_STATUSBAR
1761 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1763 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1768 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1770 wxLogMessage(_T("Frame maximized"));
1773 void MyFrame::OnSize( wxSizeEvent
& event
)
1776 UpdateStatusBar(GetPosition(), event
.GetSize());
1777 #endif // wxUSE_STATUSBAR
1782 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1784 // track the window which has the focus in the status bar
1785 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1786 wxWindow
*focus
= wxWindow::FindFocus();
1787 if ( focus
&& (focus
!= s_windowFocus
) )
1789 s_windowFocus
= focus
;
1794 _T("Focus: %s, HWND = %08x"),
1798 s_windowFocus
->GetClassInfo()->GetClassName()
1800 , (unsigned int) s_windowFocus
->GetHWND()
1806 #endif // wxUSE_STATUSBAR
1810 void MyComboBox::OnChar(wxKeyEvent
& event
)
1812 wxLogMessage(_T("MyComboBox::OnChar"));
1814 if ( event
.GetKeyCode() == 'w' )
1815 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1820 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1822 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1824 if ( event
.GetKeyCode() == 'w' )
1825 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1830 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1832 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1837 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1839 size_t count
= control
->GetCount();
1840 for ( size_t n
= 0; n
< count
; n
++ )
1843 s
.Printf(wxT("%s client data for '%s'"),
1844 name
, control
->GetString(n
).c_str());
1846 control
->SetClientObject(n
, new wxStringClientData(s
));
1852 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1854 size_t count
= control
->GetCount();
1855 for ( size_t n
= 0; n
< count
; n
++ )
1858 s
.Printf(wxT("%s client data for '%s'"),
1859 name
, control
->GetString(n
).c_str());
1861 control
->SetClientObject(n
, new wxStringClientData(s
));
1865 #endif // wxUSE_CHOICE