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 // a choice which handles focus set/kill (for testing)
318 class MyChoice
: public wxChoice
321 MyChoice(wxWindow
*parent
,
323 const wxPoint
& pos
= wxDefaultPosition
,
324 const wxSize
& size
= wxDefaultSize
,
325 int n
= 0, const wxString choices
[] = NULL
,
327 const wxValidator
& validator
= wxDefaultValidator
,
328 const wxString
& name
= wxChoiceNameStr
)
329 : wxChoice(parent
, id
, pos
, size
, n
, choices
,
330 style
, validator
, name
) { }
333 void OnFocusGot(wxFocusEvent
& event
)
335 wxLogMessage(_T("MyChoice::OnFocusGot"));
340 void OnFocusLost(wxFocusEvent
& event
)
342 wxLogMessage(_T("MyChoice::OnFocusLost"));
348 DECLARE_EVENT_TABLE()
353 //----------------------------------------------------------------------
355 //----------------------------------------------------------------------
357 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
360 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
361 #endif // wxUSE_CHOICE
365 //----------------------------------------------------------------------
367 //----------------------------------------------------------------------
371 CONTROLS_QUIT
= wxID_EXIT
,
372 CONTROLS_ABOUT
= wxID_ABOUT
,
377 CONTROLS_SET_TOOLTIP_DELAY
= 200,
378 CONTROLS_ENABLE_TOOLTIPS
,
386 // use standard command line handling:
387 if ( !wxApp::OnInit() )
390 // parse the cmd line
395 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
396 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
399 // Create the main frame window
400 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
406 //----------------------------------------------------------------------
408 //----------------------------------------------------------------------
410 const int ID_BOOK
= 1000;
412 const int ID_LISTBOX
= 130;
413 const int ID_LISTBOX_SEL_NUM
= 131;
414 const int ID_LISTBOX_SEL_STR
= 132;
415 const int ID_LISTBOX_CLEAR
= 133;
416 const int ID_LISTBOX_APPEND
= 134;
417 const int ID_LISTBOX_DELETE
= 135;
418 const int ID_LISTBOX_FONT
= 136;
419 const int ID_LISTBOX_ENABLE
= 137;
420 const int ID_LISTBOX_SORTED
= 138;
422 const int ID_CHOICE
= 120;
423 const int ID_CHOICE_SEL_NUM
= 121;
424 const int ID_CHOICE_SEL_STR
= 122;
425 const int ID_CHOICE_CLEAR
= 123;
426 const int ID_CHOICE_APPEND
= 124;
427 const int ID_CHOICE_DELETE
= 125;
428 const int ID_CHOICE_FONT
= 126;
429 const int ID_CHOICE_ENABLE
= 127;
430 const int ID_CHOICE_SORTED
= 128;
432 const int ID_COMBO
= 140;
433 const int ID_COMBO_SEL_NUM
= 141;
434 const int ID_COMBO_SEL_STR
= 142;
435 const int ID_COMBO_CLEAR
= 143;
436 const int ID_COMBO_APPEND
= 144;
437 const int ID_COMBO_DELETE
= 145;
438 const int ID_COMBO_FONT
= 146;
439 const int ID_COMBO_ENABLE
= 147;
441 const int ID_RADIOBOX
= 160;
442 const int ID_RADIOBOX_SEL_NUM
= 161;
443 const int ID_RADIOBOX_SEL_STR
= 162;
444 const int ID_RADIOBOX_FONT
= 163;
445 const int ID_RADIOBOX_ENABLE
= 164;
447 const int ID_RADIOBUTTON_1
= 166;
448 const int ID_RADIOBUTTON_2
= 167;
450 const int ID_SET_FONT
= 170;
453 const int ID_GAUGE
= 180;
454 #endif // wxUSE_GAUGE
457 const int ID_SLIDER
= 181;
458 #endif // wxUSE_SLIDER
460 const int ID_SPIN
= 182;
461 #if wxUSE_PROGRESSDLG
462 const int ID_BTNPROGRESS
= 183;
463 #endif // wxUSE_PROGRESSDLG
464 const int ID_BUTTON_LABEL
= 184;
465 const int ID_SPINCTRL
= 185;
466 const int ID_BTNNEWTEXT
= 186;
468 const int ID_BUTTON_TEST1
= 190;
469 const int ID_BUTTON_TEST2
= 191;
470 const int ID_BITMAP_BTN
= 192;
471 const int ID_BITMAP_BTN_ENABLE
= 193;
473 const int ID_CHANGE_COLOUR
= 200;
475 const int ID_SIZER_CHECK1
= 201;
476 const int ID_SIZER_CHECK2
= 202;
477 const int ID_SIZER_CHECK3
= 203;
478 const int ID_SIZER_CHECK4
= 204;
479 const int ID_SIZER_CHECK14
= 205;
480 const int ID_SIZER_CHECKBIG
= 206;
482 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
483 EVT_SIZE ( MyPanel::OnSize
)
484 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
485 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
486 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
487 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
488 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
489 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
490 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
491 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
492 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
493 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
494 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
495 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
497 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
498 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
499 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
500 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
501 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
502 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
503 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
504 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
505 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
507 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
508 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
509 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
510 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
511 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
512 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
513 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
514 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
515 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
516 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
517 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
518 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
519 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
520 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
521 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
522 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
523 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
524 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
526 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
527 #endif // wxUSE_SLIDER
529 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
530 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
531 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
532 #if wxUSE_PROGRESSDLG
533 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
534 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
535 #endif // wxUSE_PROGRESSDLG
536 #endif // wxUSE_SPINBTN
538 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
539 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
540 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
541 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
542 #endif // wxUSE_SPINCTRL
543 EVT_BUTTON (ID_BTNNEWTEXT
, MyPanel::OnNewText
)
544 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
545 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
546 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
547 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
548 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
549 EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE
, MyPanel::OnBmpButtonToggle
)
551 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
552 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
553 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
554 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
555 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
556 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
560 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
561 EVT_LEFT_DCLICK(MyButton::OnDClick
)
564 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
565 EVT_CHAR(MyComboBox::OnChar
)
566 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
567 EVT_KEY_UP(MyComboBox::OnKeyUp
)
569 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
572 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
573 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
574 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
577 BEGIN_EVENT_TABLE(MyChoice
, wxChoice
)
578 EVT_SET_FOCUS(MyChoice::OnFocusGot
)
579 EVT_KILL_FOCUS(MyChoice::OnFocusLost
)
582 // ============================================================================
584 // ============================================================================
586 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
587 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
590 m_listboxSorted
= NULL
;
593 m_choiceSorted
= NULL
;
594 #endif // wxUSE_CHOICE
600 #endif // wxUSE_GAUGE
603 #endif // wxUSE_SLIDER
605 m_lbSelectNum
= NULL
;
606 m_lbSelectThis
= NULL
;
609 #if wxUSE_PROGRESSDLG
610 m_btnProgress
= NULL
;
611 #endif // wxUSE_PROGRESSDLG
612 #endif // wxUSE_SPINBTN
615 #endif // wxUSE_SPINCTRL
622 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
623 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
624 m_text
->SetBackgroundColour(wxT("wheat"));
626 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
628 m_book
= new wxBookCtrl(this, ID_BOOK
);
650 #endif // wxUSE_GAUGE
654 // fill the image list
655 wxBitmap
bmp(list_xpm
);
657 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
659 imagelist
-> Add( bmp
);
660 imagelist
-> Add( wxBitmap( choice_xpm
));
661 imagelist
-> Add( wxBitmap( combo_xpm
));
662 imagelist
-> Add( wxBitmap( text_xpm
));
663 imagelist
-> Add( wxBitmap( radio_xpm
));
665 imagelist
-> Add( wxBitmap( gauge_xpm
));
666 #endif // wxUSE_GAUGE
667 m_book
->SetImageList(imagelist
);
668 #elif defined(__WXMSW__)
669 // load images from resources
679 #endif // wxUSE_GAUGE
682 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
684 static const wxChar
*s_iconNames
[Image_Max
] =
693 #endif // wxUSE_GAUGE
696 for ( size_t n
= 0; n
< Image_Max
; n
++ )
698 wxBitmap
bmp(s_iconNames
[n
]);
699 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
701 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
706 m_book
->SetImageList(imagelist
);
710 #define Image_List -1
711 #define Image_Choice -1
712 #define Image_Combo -1
713 #define Image_Text -1
714 #define Image_Radio -1
716 #define Image_Gauge -1
717 #endif // wxUSE_GAUGE
722 wxPanel
*panel
= new wxPanel(m_book
);
723 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
724 wxPoint(10,10), wxSize(120,70),
725 5, choices
, wxLB_MULTIPLE
|wxLB_ALWAYS_SB
);
726 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
727 wxPoint(10,90), wxSize(120,70),
728 5, choices
, wxLB_SORT
);
730 SetListboxClientData(wxT("listbox"), m_listbox
);
731 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
733 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
735 m_listbox
->SetToolTip( _T("This is a list box") );
736 #endif // wxUSE_TOOLTIPS
738 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
739 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
740 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
741 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
742 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
743 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
745 button
->SetDefault();
746 button
->SetForegroundColour(*wxBLUE
);
749 button
->SetToolTip( _T("Press here to set italic font") );
750 #endif // wxUSE_TOOLTIPS
752 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
753 m_checkbox
->SetValue(false);
754 button
->MoveAfterInTabOrder(m_checkbox
);
756 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
757 #endif // wxUSE_TOOLTIPS
758 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
760 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
761 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
764 panel
= new wxPanel(m_book
);
765 m_choice
= new MyChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
766 m_choiceSorted
= new MyChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
767 5, choices
, wxCB_SORT
);
769 SetChoiceClientData(wxT("choice"), m_choice
);
770 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
772 m_choice
->SetSelection(2);
773 m_choice
->SetBackgroundColour( wxT("red") );
774 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
775 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
776 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
777 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
778 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
779 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
780 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
782 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
783 #endif // wxUSE_CHOICE
785 panel
= new wxPanel(m_book
);
786 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
787 wxPoint(5, 5), wxSize(150, 100));
788 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
789 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
791 wxCB_READONLY
| wxPROCESS_ENTER
);
792 m_combo
->SetBackgroundColour(*wxBLUE
);
794 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
795 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
796 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
797 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
798 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
799 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
800 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
801 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
803 wxString choices2
[] =
805 _T("First"), _T("Second"),
807 "Fourth", "Fifth", "Sixth",
808 "Seventh", "Eighth", "Nineth", "Tenth" */
811 panel
= new wxPanel(m_book
);
812 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
813 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
814 m_radio
->SetForegroundColour(*wxRED
);
817 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
818 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
819 #endif // wxUSE_TOOLTIPS
821 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
822 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
823 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
824 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
825 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
826 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
827 rb
->SetValue( false );
828 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
829 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
832 #if wxUSE_SLIDER && wxUSE_GAUGE
833 panel
= new wxPanel(m_book
);
835 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
836 panel
->SetSizer( main_sizer
);
838 wxStaticBoxSizer
*gauge_sizer
= new wxStaticBoxSizer( wxHORIZONTAL
, panel
, _T("&wxGauge and wxSlider") );
839 main_sizer
->Add( gauge_sizer
, 0, wxALL
, 5 );
840 wxBoxSizer
*sz
= new wxBoxSizer( wxVERTICAL
);
841 gauge_sizer
->Add( sz
);
842 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxDefaultPosition
, wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
843 m_gauge
->SetBackgroundColour(*wxGREEN
);
844 m_gauge
->SetForegroundColour(*wxRED
);
845 sz
->Add( m_gauge
, 0, wxALL
, 10 );
846 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200,
847 wxDefaultPosition
, wxSize(155,wxDefaultCoord
),
848 wxSL_AUTOTICKS
| wxSL_LABELS
);
849 m_slider
->SetTickFreq(40, 0);
851 m_slider
->SetToolTip(_T("This is a sliding slider"));
852 #endif // wxUSE_TOOLTIPS
853 sz
->Add( m_slider
, 0, wxALL
, 10 );
855 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
856 wxDefaultPosition
, wxSize(wxDefaultCoord
, 90),
857 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
858 gauge_sizer
->Add( m_gaugeVert
, 0, wxALL
, 10 );
862 wxStaticBox
*sb
= new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
863 wxDefaultPosition
, wxDefaultSize
); //, wxALIGN_CENTER );
864 wxStaticBoxSizer
*wrapping_sizer
= new wxStaticBoxSizer( sb
, wxVERTICAL
);
865 main_sizer
->Add( wrapping_sizer
, 0, wxALL
, 5 );
868 // No wrapping text in wxStaticText yet :-(
869 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
870 _T("Drag the slider!"),
872 wxSize(240, wxDefaultCoord
)
875 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
876 _T("In order see the gauge (aka progress bar) ")
877 _T("control do something you have to drag the ")
878 _T("handle of the slider to the right.")
880 _T("This is also supposed to demonstrate how ")
881 _T("to use static controls with line wrapping."),
886 wrapping_sizer
->Add( m_wrappingText
);
888 wxStaticBoxSizer
*non_wrapping_sizer
= new wxStaticBoxSizer( wxVERTICAL
, panel
, wxT("Non-wrapping") );
889 main_sizer
->Add( non_wrapping_sizer
, 0, wxALL
, 5 );
891 m_nonWrappingText
= new wxStaticText( panel
, wxID_ANY
,
892 _T("This static text has two lines.\nThey do not wrap."),
896 non_wrapping_sizer
->Add( m_nonWrappingText
);
898 (void)new wxButton( panel
, ID_BTNNEWTEXT
, wxT("New text"), wxPoint(450, 160) );
900 int initialSpinValue
= -5;
902 s
<< initialSpinValue
;
903 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
905 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160) );
906 m_spinbutton
->SetRange(-40,30);
907 m_spinbutton
->SetValue(initialSpinValue
);
909 #if wxUSE_PROGRESSDLG
910 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
912 #endif // wxUSE_PROGRESSDLG
913 #endif // wxUSE_SPINBTN
916 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
917 m_spinctrl
->SetRange(10,30);
918 m_spinctrl
->SetValue(15);
919 #endif // wxUSE_SPINCTRL
921 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
922 #endif // wxUSE_SLIDER && wxUSE_GAUGE
925 panel
= new wxPanel(m_book
);
927 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
928 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
929 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
931 // VZ: don't leak memory
932 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
933 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
936 wxBitmap
bitmap( 100, 100 );
938 dc
.SelectObject( bitmap
);
939 dc
.SetPen(*wxGREEN_PEN
);
941 dc
.DrawEllipse(5, 5, 90, 90);
942 dc
.DrawText(_T("Bitmap"), 30, 40);
943 dc
.SelectObject( wxNullBitmap
);
945 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
946 (void)new wxToggleButton(panel
, ID_BITMAP_BTN_ENABLE
,
947 _T("Enable/disable &bitmap"), wxPoint(100, 140));
949 #if defined(__WXMSW__) || defined(__WXMOTIF__)
950 // test for masked bitmap display
951 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
954 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
956 (void)new wxStaticBitmap(panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
960 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
961 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
962 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
963 wxBitmapButton
*bmpBtn
= new wxBitmapButton
970 bmpBtn
->SetBitmapSelected(bmp2
);
971 bmpBtn
->SetBitmapFocus(bmp3
);
973 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
974 _T("&Toggle label"), wxPoint(250, 20));
976 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
977 wxPoint(250, 60), wxDefaultSize
,
978 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
979 m_label
->SetForegroundColour( *wxBLUE
);
981 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
985 panel
= new wxPanel(m_book
);
986 panel
->SetAutoLayout( true );
988 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
990 wxStaticBoxSizer
*csizer
=
991 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
993 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
994 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
995 check1
->SetValue (true);
996 csizer
->Add (check1
);
997 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
998 check2
->SetValue (true);
999 csizer
->Add (check2
);
1000 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
1001 check3
->SetValue (true);
1002 csizer
->Add (check3
);
1003 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
1004 check4
->SetValue (true);
1005 csizer
->Add (check4
);
1006 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
1007 check14
->SetValue (true);
1008 csizer
->Add (check14
);
1009 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
1010 checkBig
->SetValue (true);
1011 csizer
->Add (checkBig
);
1013 sizer
->Add (csizer
);
1015 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
1017 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
1019 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
1020 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
1021 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
1022 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
1023 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
1024 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
1025 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
1026 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
1028 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
1030 m_hsizer
->Add (m_buttonSizer
);
1031 m_hsizer
->Add( 20,20, 1 );
1032 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
1033 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
1035 sizer
->Add (m_hsizer
, 1, wxGROW
);
1037 panel
->SetSizer( sizer
);
1039 m_book
->AddPage(panel
, _T("wxSizer"));
1042 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1046 GetClientSize( &x
, &y
);
1048 if (m_book
) m_book
->SetSize( 2, 2, x
-4, y
*2/3-4 );
1049 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
1052 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
1054 int selOld
= event
.GetOldSelection();
1057 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
1058 _T("page change from taking place - if you select\n")
1059 _T("[No] the current page will stay the third one\n"),
1060 _T("Control sample"),
1061 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
1069 *m_text
<< _T("Book selection is being changed from ") << selOld
1070 << _T(" to ") << event
.GetSelection()
1071 << _T(" (current page from book is ")
1072 << m_book
->GetSelection() << _T(")\n");
1075 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1077 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1078 << _T(" (from book: ") << m_book
->GetSelection()
1082 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1084 wxLogMessage(_T("Button %c clicked."),
1085 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1088 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1090 wxLogMessage(_T("Bitmap button clicked."));
1093 void MyPanel::OnBmpButtonToggle(wxCommandEvent
& event
)
1095 FindWindow(ID_BITMAP_BTN
)->Enable(!event
.IsChecked());
1098 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1100 static wxColour s_colOld
;
1102 SetThemeEnabled(false);
1103 // test panel colour changing and propagation to the subcontrols
1104 if ( s_colOld
.Ok() )
1106 SetBackgroundColour(s_colOld
);
1107 s_colOld
= wxNullColour
;
1109 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1110 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1114 s_colOld
= wxColour(wxT("red"));
1115 SetBackgroundColour(wxT("white"));
1117 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1118 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1121 m_lbSelectThis
->Refresh();
1125 void MyPanel::OnListBox( wxCommandEvent
&event
)
1127 // GetParent()->Move(100, 100);
1129 if (event
.GetInt() == -1)
1131 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1135 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1138 m_text
->AppendText( _T("ListBox event selection string is: '") );
1139 m_text
->AppendText( event
.GetString() );
1140 m_text
->AppendText( _T("'\n") );
1141 m_text
->AppendText( _T("ListBox control selection string is: '") );
1142 m_text
->AppendText( listbox
->GetStringSelection() );
1143 m_text
->AppendText( _T("'\n") );
1145 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1146 m_text
->AppendText( _T("ListBox event client data string is: '") );
1147 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1148 m_text
->AppendText( obj
->GetData() );
1150 m_text
->AppendText( wxString(_T("none")) );
1152 m_text
->AppendText( _T("'\n") );
1153 m_text
->AppendText( _T("ListBox control client data string is: '") );
1154 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1156 m_text
->AppendText( obj
->GetData() );
1158 m_text
->AppendText( wxString(_T("none")) );
1159 m_text
->AppendText( _T("'\n") );
1162 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1164 m_text
->AppendText( _T("ListBox double click string is: ") );
1165 m_text
->AppendText( event
.GetString() );
1166 m_text
->AppendText( _T("\n") );
1169 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1171 switch (event
.GetId())
1173 case ID_LISTBOX_ENABLE
:
1175 m_text
->AppendText(_T("Checkbox clicked.\n"));
1177 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1179 cb
->SetToolTip( _T("Click to enable listbox") );
1181 cb
->SetToolTip( _T("Click to disable listbox") );
1182 #endif // wxUSE_TOOLTIPS
1183 m_listbox
->Enable( event
.GetInt() == 0 );
1184 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1185 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1186 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1187 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1190 case ID_LISTBOX_SEL_NUM
:
1192 if (m_listbox
->GetCount() > 2)
1193 m_listbox
->SetSelection( 2 );
1194 if (m_listboxSorted
->GetCount() > 2)
1195 m_listboxSorted
->SetSelection( 2 );
1196 m_lbSelectThis
->WarpPointer( 40, 14 );
1199 case ID_LISTBOX_SEL_STR
:
1201 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1202 m_listbox
->SetStringSelection( _T("This") );
1203 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1204 m_listboxSorted
->SetStringSelection( _T("This") );
1205 m_lbSelectNum
->WarpPointer( 40, 14 );
1208 case ID_LISTBOX_CLEAR
:
1211 m_listboxSorted
->Clear();
1214 case ID_LISTBOX_APPEND
:
1216 m_listbox
->Append( _T("Hi!") );
1217 m_listboxSorted
->Append( _T("Hi!") );
1220 case ID_LISTBOX_DELETE
:
1223 idx
= m_listbox
->GetSelection();
1224 if ( idx
!= wxNOT_FOUND
)
1225 m_listbox
->Delete( idx
);
1226 idx
= m_listboxSorted
->GetSelection();
1227 if ( idx
!= wxNOT_FOUND
)
1228 m_listboxSorted
->Delete( idx
);
1231 case ID_LISTBOX_FONT
:
1233 m_listbox
->SetFont( *wxITALIC_FONT
);
1234 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1235 m_checkbox
->SetFont( *wxITALIC_FONT
);
1242 void MyPanel::OnChoice( wxCommandEvent
&event
)
1244 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1247 m_text
->AppendText( _T("Choice event selection string is: '") );
1248 m_text
->AppendText( event
.GetString() );
1249 m_text
->AppendText( _T("'\n") );
1250 m_text
->AppendText( _T("Choice control selection string is: '") );
1251 m_text
->AppendText( choice
->GetStringSelection() );
1252 m_text
->AppendText( _T("'\n") );
1254 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1255 m_text
->AppendText( _T("Choice event client data string is: '") );
1258 m_text
->AppendText( obj
->GetData() );
1260 m_text
->AppendText( wxString(_T("none")) );
1262 m_text
->AppendText( _T("'\n") );
1263 m_text
->AppendText( _T("Choice control client data string is: '") );
1264 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1267 m_text
->AppendText( obj
->GetData() );
1269 m_text
->AppendText( wxString(_T("none")) );
1270 m_text
->AppendText( _T("'\n") );
1273 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1275 switch (event
.GetId())
1277 case ID_CHOICE_ENABLE
:
1279 m_choice
->Enable( event
.GetInt() == 0 );
1280 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1283 case ID_CHOICE_SEL_NUM
:
1285 m_choice
->SetSelection( 2 );
1286 m_choiceSorted
->SetSelection( 2 );
1289 case ID_CHOICE_SEL_STR
:
1291 m_choice
->SetStringSelection( _T("This") );
1292 m_choiceSorted
->SetStringSelection( _T("This") );
1295 case ID_CHOICE_CLEAR
:
1298 m_choiceSorted
->Clear();
1301 case ID_CHOICE_APPEND
:
1303 m_choice
->Append( _T("Hi!") );
1304 m_choiceSorted
->Append( _T("Hi!") );
1307 case ID_CHOICE_DELETE
:
1309 int idx
= m_choice
->GetSelection();
1310 if ( idx
!= wxNOT_FOUND
)
1311 m_choice
->Delete( idx
);
1312 idx
= m_choiceSorted
->GetSelection();
1313 if ( idx
!= wxNOT_FOUND
)
1314 m_choiceSorted
->Delete( idx
);
1317 case ID_CHOICE_FONT
:
1319 m_choice
->SetFont( *wxITALIC_FONT
);
1320 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1325 #endif // wxUSE_CHOICE
1327 void MyPanel::OnCombo( wxCommandEvent
&event
)
1329 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1330 m_text
->AppendText( event
.GetString() );
1331 m_text
->AppendText( _T("\n") );
1332 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1333 m_text
->AppendText( m_combo
->GetStringSelection() );
1334 m_text
->AppendText( _T("\n") );
1337 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1340 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1341 event
.GetString().c_str() );
1342 wxLogMessage( str
.c_str() );
1345 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1347 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1348 m_combo
->GetValue().c_str());
1351 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1353 switch (event
.GetId())
1355 case ID_COMBO_ENABLE
:
1357 m_combo
->Enable( event
.GetInt() == 0 );
1360 case ID_COMBO_SEL_NUM
:
1362 m_combo
->SetSelection( 2 );
1365 case ID_COMBO_SEL_STR
:
1367 m_combo
->SetStringSelection( _T("This") );
1370 case ID_COMBO_CLEAR
:
1375 case ID_COMBO_APPEND
:
1377 m_combo
->Append( _T("Hi!") );
1380 case ID_COMBO_DELETE
:
1382 int idx
= m_combo
->GetSelection();
1383 m_combo
->Delete( idx
);
1388 m_combo
->SetFont( *wxITALIC_FONT
);
1394 void MyPanel::OnRadio( wxCommandEvent
&event
)
1396 m_text
->AppendText( _T("RadioBox selection string is: ") );
1397 m_text
->AppendText( event
.GetString() );
1398 m_text
->AppendText( _T("\n") );
1401 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1403 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1406 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1408 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1411 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1413 switch (event
.GetId())
1415 case ID_RADIOBOX_ENABLE
:
1417 m_radio
->Enable( event
.GetInt() == 0 );
1420 case ID_RADIOBOX_SEL_NUM
:
1422 m_radio
->SetSelection( 2 );
1425 case ID_RADIOBOX_SEL_STR
:
1427 m_radio
->SetStringSelection( _T("This") );
1430 case ID_RADIOBOX_FONT
:
1432 m_radio
->SetForegroundColour(*wxGREEN
);
1434 m_radio
->SetFont( *wxITALIC_FONT
);
1440 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1442 m_fontButton
->SetFont( *wxITALIC_FONT
);
1443 m_text
->SetFont( *wxITALIC_FONT
);
1446 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1448 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1449 : _T("Shorter text."));
1454 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1457 m_gauge
->SetValue( m_slider
->GetValue() );
1458 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1459 #endif // wxUSE_GAUGE
1462 #endif // wxUSE_SLIDER
1466 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1471 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1472 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1473 m_text
->AppendText(s
);
1477 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1482 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1483 m_spinctrl
->GetValue(), event
.GetInt() );
1484 m_text
->AppendText(s
);
1488 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1492 m_text
->AppendText( wxString::Format(
1493 _T("Spin up: %d (from event: %ld)\n"),
1494 m_spinctrl
->GetValue(), event
.GetInt() ) );
1498 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1502 m_text
->AppendText( wxString::Format(
1503 _T("Spin down: %d (from event: %ld)\n"),
1504 m_spinctrl
->GetValue(), event
.GetInt() ) );
1508 #endif // wxUSE_SPINCTRL
1511 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1514 value
.Printf( _T("Spin control up: current = %d\n"),
1515 m_spinbutton
->GetValue());
1517 if ( event
.GetPosition() > 17 )
1519 value
+= _T("Preventing the spin button from going above 17.\n");
1524 m_text
->AppendText(value
);
1527 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1530 value
.Printf( _T("Spin control down: current = %d\n"),
1531 m_spinbutton
->GetValue());
1533 if ( event
.GetPosition() < -17 )
1535 value
+= _T("Preventing the spin button from going below -17.\n");
1540 m_text
->AppendText(value
);
1543 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1546 value
.Printf( _T("%d"), event
.GetPosition() );
1547 m_spintext
->SetValue( value
);
1549 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1550 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1551 m_spinbutton
->GetValue());
1553 m_text
->AppendText(value
);
1556 void MyPanel::OnNewText( wxCommandEvent
& /* event */)
1558 m_nonWrappingText
->SetLabel( wxT("This text is short\nbut still spans\nover three lines.") );
1559 m_wrappingText
->SetLabel( wxT("This text is short but will still be wrapped if it is too long.") );
1560 m_wrappingText
->GetParent()->Layout();
1563 #if wxUSE_PROGRESSDLG
1565 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1567 event
.Enable( m_spinbutton
->GetValue() > 0 );
1570 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1572 int max
= m_spinbutton
->GetValue();
1576 wxLogError(_T("You must set positive range!"));
1580 wxProgressDialog
dialog(_T("Progress dialog example"),
1581 _T("An informative message"),
1588 wxPD_ESTIMATED_TIME
|
1589 wxPD_REMAINING_TIME
);
1593 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1598 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1600 else if ( i
== max
/ 2 )
1602 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1606 cont
= dialog
.Update(i
);
1612 *m_text
<< _T("Progress dialog aborted!\n");
1616 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1620 #endif // wxUSE_PROGRESSDLG
1621 #endif // wxUSE_SPINBTN
1623 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1625 switch (event
.GetId ()) {
1626 case ID_SIZER_CHECK1
:
1627 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1628 m_buttonSizer
->Layout ();
1630 case ID_SIZER_CHECK2
:
1631 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1632 m_buttonSizer
->Layout ();
1634 case ID_SIZER_CHECK3
:
1635 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1636 m_buttonSizer
->Layout ();
1638 case ID_SIZER_CHECK4
:
1639 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1640 m_buttonSizer
->Layout ();
1642 case ID_SIZER_CHECK14
:
1643 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1644 m_hsizer
->Layout ();
1646 case ID_SIZER_CHECKBIG
:
1647 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1648 m_hsizer
->Layout ();
1656 //wxLog::RemoveTraceMask(_T("focus"));
1657 delete wxLog::SetActiveTarget(m_logTargetOld
);
1659 delete m_book
->GetImageList();
1662 //----------------------------------------------------------------------
1664 //----------------------------------------------------------------------
1666 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1667 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1668 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1669 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1671 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1672 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1673 #endif // wxUSE_TOOLTIPS
1675 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1677 EVT_ICONIZE(MyFrame::OnIconized
)
1678 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1679 EVT_SIZE(MyFrame::OnSize
)
1680 EVT_MOVE(MyFrame::OnMove
)
1682 EVT_IDLE(MyFrame::OnIdle
)
1685 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1686 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1689 // The wxICON() macros loads an icon from a resource under Windows
1690 // and uses an #included XPM image under GTK+ and Motif
1693 SetIcon( wxICON(mondrian
) );
1696 wxMenu
*file_menu
= new wxMenu
;
1698 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1699 file_menu
->AppendSeparator();
1700 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1701 file_menu
->AppendSeparator();
1702 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1704 wxMenuBar
*menu_bar
= new wxMenuBar
;
1705 menu_bar
->Append(file_menu
, _T("&File"));
1708 wxMenu
*tooltip_menu
= new wxMenu
;
1709 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1710 tooltip_menu
->AppendSeparator();
1711 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1712 _T("enable/disable tooltips"), true);
1713 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1714 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1715 #endif // wxUSE_TOOLTIPS
1717 wxMenu
*panel_menu
= new wxMenu
;
1718 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1719 _T("Enable/disable all panel controls"), true);
1720 menu_bar
->Append(panel_menu
, _T("&Panel"));
1722 SetMenuBar(menu_bar
);
1726 #endif // wxUSE_STATUSBAR
1728 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1730 SetSizeHints( 500, 425 );
1733 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1738 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1742 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1746 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1748 m_panel
->m_text
->Clear();
1752 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1754 static long s_delay
= 5000;
1757 delay
.Printf( _T("%ld"), s_delay
);
1759 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1760 _T("Set tooltip delay"),
1764 return; // cancelled
1766 wxSscanf(delay
, _T("%ld"), &s_delay
);
1768 wxToolTip::SetDelay(s_delay
);
1770 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1773 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1775 static bool s_enabled
= true;
1777 s_enabled
= !s_enabled
;
1779 wxToolTip::Enable(s_enabled
);
1781 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1785 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1787 static bool s_enable
= true;
1789 s_enable
= !s_enable
;
1790 m_panel
->Enable(s_enable
);
1793 void MyFrame::OnMove( wxMoveEvent
& event
)
1796 UpdateStatusBar(event
.GetPosition(), GetSize());
1797 #endif // wxUSE_STATUSBAR
1802 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1804 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1809 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1811 wxLogMessage(_T("Frame maximized"));
1814 void MyFrame::OnSize( wxSizeEvent
& event
)
1817 UpdateStatusBar(GetPosition(), event
.GetSize());
1818 #endif // wxUSE_STATUSBAR
1823 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1825 // track the window which has the focus in the status bar
1826 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1827 wxWindow
*focus
= wxWindow::FindFocus();
1828 if ( focus
&& (focus
!= s_windowFocus
) )
1830 s_windowFocus
= focus
;
1835 _T("Focus: %s, HWND = %08x"),
1839 s_windowFocus
->GetClassInfo()->GetClassName()
1841 , (unsigned int) s_windowFocus
->GetHWND()
1847 #endif // wxUSE_STATUSBAR
1851 void MyComboBox::OnChar(wxKeyEvent
& event
)
1853 wxLogMessage(_T("MyComboBox::OnChar"));
1855 if ( event
.GetKeyCode() == 'w' )
1856 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1861 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1863 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1865 if ( event
.GetKeyCode() == 'w' )
1866 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1871 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1873 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1878 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1880 size_t count
= control
->GetCount();
1881 for ( size_t n
= 0; n
< count
; n
++ )
1884 s
.Printf(wxT("%s client data for '%s'"),
1885 name
, control
->GetString(n
).c_str());
1887 control
->SetClientObject(n
, new wxStringClientData(s
));
1893 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1895 size_t count
= control
->GetCount();
1896 for ( size_t n
= 0; n
< count
; n
++ )
1899 s
.Printf(wxT("%s client data for '%s'"),
1900 name
, control
->GetString(n
).c_str());
1902 control
->SetClientObject(n
, new wxStringClientData(s
));
1906 #endif // wxUSE_CHOICE