1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Controls wxWidgets sample
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
22 #include "wx/spinbutt.h"
23 #include "wx/tglbtn.h"
24 #include "wx/bookctrl.h"
25 #include "wx/imaglist.h"
26 #include "wx/artprov.h"
29 #include "wx/tooltip.h"
32 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
37 #include "mondrian.xpm"
38 #include "icons/choice.xpm"
39 #include "icons/combo.xpm"
40 #include "icons/list.xpm"
41 #include "icons/radio.xpm"
42 #include "icons/text.xpm"
43 #include "icons/gauge.xpm"
47 #define wxUSE_SPINBTN 1
50 #include "wx/progdlg.h"
53 #include "wx/spinctrl.h"
54 #endif // wxUSE_SPINCTRL
57 #define wxToggleButton wxCheckBox
58 #define EVT_TOGGLEBUTTON EVT_CHECKBOX
61 //----------------------------------------------------------------------
63 //----------------------------------------------------------------------
65 class MyApp
: public wxApp
71 class MyPanel
: public wxPanel
74 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
77 void OnIdle( wxIdleEvent
&event
);
78 void OnListBox( wxCommandEvent
&event
);
79 void OnListBoxDoubleClick( wxCommandEvent
&event
);
80 void OnListBoxButtons( wxCommandEvent
&event
);
82 void OnChoice( wxCommandEvent
&event
);
83 void OnChoiceButtons( wxCommandEvent
&event
);
85 void OnCombo( wxCommandEvent
&event
);
86 void OnComboTextChanged( wxCommandEvent
&event
);
87 void OnComboTextEnter( wxCommandEvent
&event
);
88 void OnComboButtons( wxCommandEvent
&event
);
89 void OnRadio( wxCommandEvent
&event
);
90 void OnRadioButtons( wxCommandEvent
&event
);
91 void OnRadioButton1( wxCommandEvent
&event
);
92 void OnRadioButton2( wxCommandEvent
&event
);
93 void OnSetFont( wxCommandEvent
&event
);
94 void OnPageChanged( wxBookCtrlEvent
&event
);
95 void OnPageChanging( wxBookCtrlEvent
&event
);
96 void OnSliderUpdate( wxCommandEvent
&event
);
97 void OnUpdateLabel( wxCommandEvent
&event
);
99 void OnSpinUp( wxSpinEvent
&event
);
100 void OnSpinDown( wxSpinEvent
&event
);
101 void OnSpinUpdate( wxSpinEvent
&event
);
102 #if wxUSE_PROGRESSDLG
103 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
104 void OnShowProgress( wxCommandEvent
&event
);
105 #endif // wxUSE_PROGRESSDLG
106 #endif // wxUSE_SPINBTN
107 void OnNewText( wxCommandEvent
&event
);
109 void OnSpinCtrl(wxSpinEvent
& event
);
110 void OnSpinCtrlUp(wxSpinEvent
& event
);
111 void OnSpinCtrlDown(wxSpinEvent
& event
);
112 void OnSpinCtrlText(wxCommandEvent
& event
);
113 #endif // wxUSE_SPINCTRL
115 void OnEnableAll(wxCommandEvent
& event
);
116 void OnChangeColour(wxCommandEvent
& event
);
117 void OnTestButton(wxCommandEvent
& event
);
118 void OnBmpButton(wxCommandEvent
& event
);
119 void OnBmpButtonToggle(wxCommandEvent
& event
);
121 void OnSizerCheck (wxCommandEvent
&event
);
123 wxListBox
*m_listbox
,
128 #endif // wxUSE_CHOICE
135 #endif // wxUSE_GAUGE
138 #endif // wxUSE_SLIDER
139 wxButton
*m_fontButton
;
140 wxButton
*m_lbSelectNum
;
141 wxButton
*m_lbSelectThis
;
143 wxSpinButton
*m_spinbutton
;
144 #if wxUSE_PROGRESSDLG
145 wxButton
*m_btnProgress
;
146 #endif // wxUSE_PROGRESSDLG
147 #endif // wxUSE_SPINBTN
148 wxStaticText
*m_wrappingText
;
149 wxStaticText
*m_nonWrappingText
;
152 wxSpinCtrl
*m_spinctrl
;
153 #endif // wxUSE_SPINCTRL
155 wxTextCtrl
*m_spintext
;
156 wxCheckBox
*m_checkbox
;
161 wxStaticText
*m_label
;
163 wxBoxSizer
*m_buttonSizer
;
164 wxButton
*m_sizerBtn1
;
165 wxButton
*m_sizerBtn2
;
166 wxButton
*m_sizerBtn3
;
167 wxButton
*m_sizerBtn4
;
168 wxBoxSizer
*m_hsizer
;
172 wxLog
*m_logTargetOld
;
174 DECLARE_EVENT_TABLE()
177 class MyFrame
: public wxFrame
180 MyFrame(const wxChar
*title
, int x
, int y
);
182 void OnQuit(wxCommandEvent
& event
);
183 void OnAbout(wxCommandEvent
& event
);
184 void OnClearLog(wxCommandEvent
& event
);
187 void OnSetTooltipDelay(wxCommandEvent
& event
);
188 void OnToggleTooltips(wxCommandEvent
& event
);
189 #endif // wxUSE_TOOLTIPS
191 void OnEnableAll(wxCommandEvent
& event
);
193 void OnIdle( wxIdleEvent
& event
);
194 void OnIconized( wxIconizeEvent
& event
);
195 void OnMaximized( wxMaximizeEvent
& event
);
196 void OnSize( wxSizeEvent
& event
);
197 void OnMove( wxMoveEvent
& event
);
199 MyPanel
*GetPanel() const { return m_panel
; }
203 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
205 if ( m_frameStatusBar
)
208 wxSize sizeAll
= GetSize(),
209 sizeCl
= GetClientSize();
210 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
213 sizeAll
.x
, sizeAll
.y
,
215 SetStatusText(msg
, 1);
218 #endif // wxUSE_STATUSBAR
222 DECLARE_EVENT_TABLE()
225 // a button which intercepts double clicks (for testing...)
226 class MyButton
: public wxButton
229 MyButton(wxWindow
*parent
,
231 const wxString
& label
= wxEmptyString
,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
)
234 : wxButton(parent
, id
, label
, pos
, size
)
238 void OnDClick(wxMouseEvent
& event
)
240 wxLogMessage(_T("MyButton::OnDClick"));
246 DECLARE_EVENT_TABLE()
249 // a combo which intercepts chars (to test Windows behaviour)
250 class MyComboBox
: public wxComboBox
253 MyComboBox(wxWindow
*parent
, wxWindowID id
,
254 const wxString
& value
= wxEmptyString
,
255 const wxPoint
& pos
= wxDefaultPosition
,
256 const wxSize
& size
= wxDefaultSize
,
257 int n
= 0, const wxString choices
[] = NULL
,
259 const wxValidator
& validator
= wxDefaultValidator
,
260 const wxString
& name
= wxComboBoxNameStr
)
261 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
265 void OnChar(wxKeyEvent
& event
);
266 void OnKeyDown(wxKeyEvent
& event
);
267 void OnKeyUp(wxKeyEvent
& event
);
268 void OnFocusGot(wxFocusEvent
& event
)
270 wxLogMessage(_T("MyComboBox::OnFocusGot"));
276 DECLARE_EVENT_TABLE()
279 // a radiobox which handles focus set/kill (for testing)
280 class MyRadioBox
: public wxRadioBox
283 MyRadioBox(wxWindow
*parent
,
285 const wxString
& title
= wxEmptyString
,
286 const wxPoint
& pos
= wxDefaultPosition
,
287 const wxSize
& size
= wxDefaultSize
,
288 int n
= 0, const wxString choices
[] = NULL
,
290 long style
= wxRA_HORIZONTAL
,
291 const wxValidator
& validator
= wxDefaultValidator
,
292 const wxString
& name
= wxRadioBoxNameStr
)
293 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
294 style
, validator
, name
)
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;
440 const int ID_COMBO_SET_TEXT
= 148;
442 const int ID_RADIOBOX
= 160;
443 const int ID_RADIOBOX_SEL_NUM
= 161;
444 const int ID_RADIOBOX_SEL_STR
= 162;
445 const int ID_RADIOBOX_FONT
= 163;
446 const int ID_RADIOBOX_ENABLE
= 164;
448 const int ID_RADIOBUTTON_1
= 166;
449 const int ID_RADIOBUTTON_2
= 167;
451 const int ID_SET_FONT
= 170;
454 const int ID_GAUGE
= 180;
455 #endif // wxUSE_GAUGE
458 const int ID_SLIDER
= 181;
459 #endif // wxUSE_SLIDER
461 const int ID_SPIN
= 182;
462 #if wxUSE_PROGRESSDLG
463 const int ID_BTNPROGRESS
= 183;
464 #endif // wxUSE_PROGRESSDLG
465 const int ID_BUTTON_LABEL
= 184;
466 const int ID_SPINCTRL
= 185;
467 const int ID_BTNNEWTEXT
= 186;
469 const int ID_BUTTON_TEST1
= 190;
470 const int ID_BUTTON_TEST2
= 191;
471 const int ID_BITMAP_BTN
= 192;
472 const int ID_BITMAP_BTN_ENABLE
= 193;
474 const int ID_CHANGE_COLOUR
= 200;
476 const int ID_SIZER_CHECK1
= 201;
477 const int ID_SIZER_CHECK2
= 202;
478 const int ID_SIZER_CHECK3
= 203;
479 const int ID_SIZER_CHECK4
= 204;
480 const int ID_SIZER_CHECK14
= 205;
481 const int ID_SIZER_CHECKBIG
= 206;
483 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
484 EVT_IDLE ( MyPanel::OnIdle
)
485 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
486 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
487 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
488 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
489 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
490 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
491 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
492 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
493 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
494 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
495 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
496 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
498 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
499 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
500 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
501 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
502 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
503 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
504 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
505 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
506 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
508 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
509 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
510 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
511 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
512 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
513 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
514 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
515 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
516 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
517 EVT_BUTTON (ID_COMBO_SET_TEXT
, MyPanel::OnComboButtons
)
518 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
519 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
520 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
521 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
522 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
523 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
524 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
525 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
526 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
528 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
529 #endif // wxUSE_SLIDER
531 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
532 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
533 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
534 #if wxUSE_PROGRESSDLG
535 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
536 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
537 #endif // wxUSE_PROGRESSDLG
538 #endif // wxUSE_SPINBTN
540 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
541 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
542 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
543 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
544 #endif // wxUSE_SPINCTRL
545 EVT_BUTTON (ID_BTNNEWTEXT
, MyPanel::OnNewText
)
546 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
547 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
548 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
549 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
550 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
551 EVT_TOGGLEBUTTON(ID_BITMAP_BTN_ENABLE
, MyPanel::OnBmpButtonToggle
)
553 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
554 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
555 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
556 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
557 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
558 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
562 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
563 EVT_LEFT_DCLICK(MyButton::OnDClick
)
566 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
567 EVT_CHAR(MyComboBox::OnChar
)
568 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
569 EVT_KEY_UP(MyComboBox::OnKeyUp
)
571 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
574 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
575 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
576 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
579 BEGIN_EVENT_TABLE(MyChoice
, wxChoice
)
580 EVT_SET_FOCUS(MyChoice::OnFocusGot
)
581 EVT_KILL_FOCUS(MyChoice::OnFocusLost
)
584 // ============================================================================
586 // ============================================================================
588 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
589 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
592 m_listboxSorted
= NULL
;
595 m_choiceSorted
= NULL
;
596 #endif // wxUSE_CHOICE
602 #endif // wxUSE_GAUGE
605 #endif // wxUSE_SLIDER
607 m_lbSelectNum
= NULL
;
608 m_lbSelectThis
= NULL
;
611 #if wxUSE_PROGRESSDLG
612 m_btnProgress
= NULL
;
613 #endif // wxUSE_PROGRESSDLG
614 #endif // wxUSE_SPINBTN
617 #endif // wxUSE_SPINCTRL
624 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
625 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
627 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
629 m_book
= new wxBookCtrl(this, ID_BOOK
);
651 #endif // wxUSE_GAUGE
655 // fill the image list
656 wxBitmap
bmp(list_xpm
);
658 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
660 imagelist
-> Add( bmp
);
661 imagelist
-> Add( wxBitmap( choice_xpm
));
662 imagelist
-> Add( wxBitmap( combo_xpm
));
663 imagelist
-> Add( wxBitmap( text_xpm
));
664 imagelist
-> Add( wxBitmap( radio_xpm
));
666 imagelist
-> Add( wxBitmap( gauge_xpm
));
667 #endif // wxUSE_GAUGE
668 m_book
->SetImageList(imagelist
);
669 #elif defined(__WXMSW__)
670 // load images from resources
680 #endif // wxUSE_GAUGE
683 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
685 static const wxChar
*s_iconNames
[Image_Max
] =
694 #endif // wxUSE_GAUGE
697 for ( size_t n
= 0; n
< Image_Max
; n
++ )
699 wxBitmap
bmp(s_iconNames
[n
]);
700 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
702 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
707 m_book
->SetImageList(imagelist
);
711 #define Image_List -1
712 #define Image_Choice -1
713 #define Image_Combo -1
714 #define Image_Text -1
715 #define Image_Radio -1
717 #define Image_Gauge -1
718 #endif // wxUSE_GAUGE
723 wxPanel
*panel
= new wxPanel(m_book
);
724 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
725 wxPoint(10,10), wxSize(120,70),
726 5, choices
, wxLB_MULTIPLE
|wxLB_ALWAYS_SB
);
727 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
728 wxPoint(10,90), wxSize(120,70),
729 5, choices
, wxLB_SORT
);
731 SetListboxClientData(wxT("listbox"), m_listbox
);
732 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
734 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
736 m_listbox
->SetToolTip( _T("This is a list box") );
737 #endif // wxUSE_TOOLTIPS
739 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
740 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
741 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
742 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
743 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
744 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
746 button
->SetDefault();
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 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
774 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
775 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
776 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
777 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
778 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
779 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
781 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
782 #endif // wxUSE_CHOICE
784 panel
= new wxPanel(m_book
);
785 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
786 wxPoint(5, 5), wxSize(150, 100));
787 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
788 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
792 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
793 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
794 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
795 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
796 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
797 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
798 (void)new wxButton( panel
, ID_COMBO_SET_TEXT
, _T("Set 'Hi!' at #2"), wxPoint(340,180), wxSize(140,30) );
799 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
800 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
802 wxString choices2
[] =
804 _T("First"), _T("Second"),
806 "Fourth", "Fifth", "Sixth",
807 "Seventh", "Eighth", "Nineth", "Tenth" */
810 panel
= new wxPanel(m_book
);
811 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
812 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
815 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
816 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
817 #endif // wxUSE_TOOLTIPS
819 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
820 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
821 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
822 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
823 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
825 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
826 rb
->SetValue( false );
827 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
828 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
831 #if wxUSE_SLIDER && wxUSE_GAUGE
832 panel
= new wxPanel(m_book
);
834 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
835 panel
->SetSizer( main_sizer
);
837 wxStaticBoxSizer
*gauge_sizer
= new wxStaticBoxSizer( wxHORIZONTAL
, panel
, _T("&wxGauge and wxSlider") );
838 main_sizer
->Add( gauge_sizer
, 0, wxALL
, 5 );
839 wxBoxSizer
*sz
= new wxBoxSizer( wxVERTICAL
);
840 gauge_sizer
->Add( sz
);
841 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxDefaultPosition
, wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
842 sz
->Add( m_gauge
, 0, wxALL
, 10 );
843 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200,
844 wxDefaultPosition
, wxSize(155,wxDefaultCoord
),
845 wxSL_AUTOTICKS
| wxSL_LABELS
);
846 m_slider
->SetTickFreq(40, 0);
848 m_slider
->SetToolTip(_T("This is a sliding slider"));
849 #endif // wxUSE_TOOLTIPS
850 sz
->Add( m_slider
, 0, wxALL
, 10 );
852 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
853 wxDefaultPosition
, wxSize(wxDefaultCoord
, 90),
854 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
855 gauge_sizer
->Add( m_gaugeVert
, 0, wxALL
, 10 );
859 wxStaticBox
*sb
= new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
860 wxDefaultPosition
, wxDefaultSize
); //, wxALIGN_CENTER );
861 wxStaticBoxSizer
*wrapping_sizer
= new wxStaticBoxSizer( sb
, wxVERTICAL
);
862 main_sizer
->Add( wrapping_sizer
, 0, wxALL
, 5 );
865 // No wrapping text in wxStaticText yet :-(
866 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
867 _T("Drag the slider!"),
869 wxSize(240, wxDefaultCoord
)
872 m_wrappingText
= new wxStaticText( panel
, wxID_ANY
,
873 _T("In order see the gauge (aka progress bar) ")
874 _T("control do something you have to drag the ")
875 _T("handle of the slider to the right.")
877 _T("This is also supposed to demonstrate how ")
878 _T("to use static controls with line wrapping."),
880 wxSize(240, wxDefaultCoord
)
883 wrapping_sizer
->Add( m_wrappingText
);
885 wxStaticBoxSizer
*non_wrapping_sizer
= new wxStaticBoxSizer( wxVERTICAL
, panel
, wxT("Non-wrapping") );
886 main_sizer
->Add( non_wrapping_sizer
, 0, wxALL
, 5 );
888 m_nonWrappingText
= new wxStaticText( panel
, wxID_ANY
,
889 _T("This static text has two lines.\nThey do not wrap."),
893 non_wrapping_sizer
->Add( m_nonWrappingText
);
895 (void)new wxButton( panel
, ID_BTNNEWTEXT
, wxT("New text"), wxPoint(450, 160) );
897 int initialSpinValue
= -5;
899 s
<< initialSpinValue
;
900 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
902 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160) );
903 m_spinbutton
->SetRange(-40,30);
904 m_spinbutton
->SetValue(initialSpinValue
);
906 #if wxUSE_PROGRESSDLG
907 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
909 #endif // wxUSE_PROGRESSDLG
910 #endif // wxUSE_SPINBTN
913 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, wxEmptyString
, wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
914 m_spinctrl
->SetRange(10,30);
915 m_spinctrl
->SetValue(15);
916 #endif // wxUSE_SPINCTRL
918 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
919 #endif // wxUSE_SLIDER && wxUSE_GAUGE
922 panel
= new wxPanel(m_book
);
924 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
925 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
926 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
928 // VZ: don't leak memory
929 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
930 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
933 wxBitmap
bitmap( 100, 100 );
935 dc
.SelectObject( bitmap
);
936 dc
.SetPen(*wxGREEN_PEN
);
938 dc
.DrawEllipse(5, 5, 90, 90);
939 dc
.DrawText(_T("Bitmap"), 30, 40);
940 dc
.SelectObject( wxNullBitmap
);
942 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
943 (void)new wxToggleButton(panel
, ID_BITMAP_BTN_ENABLE
,
944 _T("Enable/disable &bitmap"), wxPoint(100, 140));
946 #if defined(__WXMSW__) || defined(__WXMOTIF__)
947 // test for masked bitmap display
948 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
951 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
953 (void)new wxStaticBitmap(panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
957 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
958 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
959 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
960 wxBitmapButton
*bmpBtn
= new wxBitmapButton
967 bmpBtn
->SetBitmapSelected(bmp2
);
968 bmpBtn
->SetBitmapFocus(bmp3
);
970 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
971 _T("&Toggle label"), wxPoint(250, 20));
973 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
974 wxPoint(250, 60), wxDefaultSize
,
975 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
976 m_label
->SetForegroundColour( *wxBLUE
);
978 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
982 panel
= new wxPanel(m_book
);
983 panel
->SetAutoLayout( true );
985 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
987 wxStaticBoxSizer
*csizer
=
988 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
990 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
991 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
992 check1
->SetValue (true);
993 csizer
->Add (check1
);
994 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
995 check2
->SetValue (true);
996 csizer
->Add (check2
);
997 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
998 check3
->SetValue (true);
999 csizer
->Add (check3
);
1000 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
1001 check4
->SetValue (true);
1002 csizer
->Add (check4
);
1003 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
1004 check14
->SetValue (true);
1005 csizer
->Add (check14
);
1006 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
1007 checkBig
->SetValue (true);
1008 csizer
->Add (checkBig
);
1010 sizer
->Add (csizer
);
1012 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
1014 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
1016 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
1017 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
1018 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
1019 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
1020 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
1021 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
1022 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
1023 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
1025 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
1027 m_hsizer
->Add (m_buttonSizer
);
1028 m_hsizer
->Add( 20,20, 1 );
1029 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
1030 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
1032 sizer
->Add (m_hsizer
, 1, wxGROW
);
1034 panel
->SetSizer( sizer
);
1036 m_book
->AddPage(panel
, _T("wxSizer"));
1038 // set the sizer for the panel itself
1039 sizer
= new wxBoxSizer(wxVERTICAL
);
1040 sizer
->Add(m_book
, wxSizerFlags().Border().Expand());
1041 sizer
->Add(m_text
, wxSizerFlags(1).Border().Expand());
1045 void MyPanel::OnIdle(wxIdleEvent
& event
)
1047 static const int INVALID_SELECTION
= -2;
1049 static int s_selCombo
= INVALID_SELECTION
;
1050 int sel
= m_combo
->GetSelection();
1051 if ( sel
!= s_selCombo
)
1053 if ( s_selCombo
!= INVALID_SELECTION
)
1055 wxLogMessage(_T("EVT_IDLE: combobox selection changed from %d to %d"),
1062 static int s_selChoice
= INVALID_SELECTION
;
1063 sel
= m_choice
->GetSelection();
1064 if ( sel
!= s_selChoice
)
1066 if ( s_selChoice
!= INVALID_SELECTION
)
1068 wxLogMessage(_T("EVT_IDLE: choice selection changed from %d to %d"),
1078 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
1080 int selOld
= event
.GetOldSelection();
1083 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
1084 _T("page change from taking place - if you select\n")
1085 _T("[No] the current page will stay the third one\n"),
1086 _T("Control sample"),
1087 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
1095 *m_text
<< _T("Book selection is being changed from ") << selOld
1096 << _T(" to ") << event
.GetSelection()
1097 << _T(" (current page from book is ")
1098 << m_book
->GetSelection() << _T(")\n");
1101 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
1103 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
1104 << _T(" (from book: ") << m_book
->GetSelection()
1108 void MyPanel::OnTestButton(wxCommandEvent
& event
)
1110 wxLogMessage(_T("Button %c clicked."),
1111 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
1114 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
1116 wxLogMessage(_T("Bitmap button clicked."));
1119 void MyPanel::OnBmpButtonToggle(wxCommandEvent
& event
)
1121 FindWindow(ID_BITMAP_BTN
)->Enable(!event
.IsChecked());
1124 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
1126 static wxColour s_colOld
;
1128 SetThemeEnabled(false);
1129 // test panel colour changing and propagation to the subcontrols
1130 if ( s_colOld
.Ok() )
1132 SetBackgroundColour(s_colOld
);
1133 s_colOld
= wxNullColour
;
1135 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
1136 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
1140 s_colOld
= wxColour(wxT("red"));
1141 SetBackgroundColour(wxT("white"));
1143 m_lbSelectThis
->SetForegroundColour(wxT("white"));
1144 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
1147 m_lbSelectThis
->Refresh();
1151 void MyPanel::OnListBox( wxCommandEvent
&event
)
1153 // GetParent()->Move(100, 100);
1155 if (event
.GetInt() == -1)
1157 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1161 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1164 m_text
->AppendText( _T("ListBox event selection string is: '") );
1165 m_text
->AppendText( event
.GetString() );
1166 m_text
->AppendText( _T("'\n") );
1167 m_text
->AppendText( _T("ListBox control selection string is: '") );
1168 m_text
->AppendText( listbox
->GetStringSelection() );
1169 m_text
->AppendText( _T("'\n") );
1171 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1172 m_text
->AppendText( _T("ListBox event client data string is: '") );
1173 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1174 m_text
->AppendText( obj
->GetData() );
1176 m_text
->AppendText( wxString(_T("none")) );
1178 m_text
->AppendText( _T("'\n") );
1179 m_text
->AppendText( _T("ListBox control client data string is: '") );
1180 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1182 m_text
->AppendText( obj
->GetData() );
1184 m_text
->AppendText( wxString(_T("none")) );
1185 m_text
->AppendText( _T("'\n") );
1188 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1190 m_text
->AppendText( _T("ListBox double click string is: ") );
1191 m_text
->AppendText( event
.GetString() );
1192 m_text
->AppendText( _T("\n") );
1195 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1197 switch (event
.GetId())
1199 case ID_LISTBOX_ENABLE
:
1201 m_text
->AppendText(_T("Checkbox clicked.\n"));
1203 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1205 cb
->SetToolTip( _T("Click to enable listbox") );
1207 cb
->SetToolTip( _T("Click to disable listbox") );
1208 #endif // wxUSE_TOOLTIPS
1209 m_listbox
->Enable( event
.GetInt() == 0 );
1210 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1211 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1212 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1213 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1216 case ID_LISTBOX_SEL_NUM
:
1218 if (m_listbox
->GetCount() > 2)
1219 m_listbox
->SetSelection( 2 );
1220 if (m_listboxSorted
->GetCount() > 2)
1221 m_listboxSorted
->SetSelection( 2 );
1222 m_lbSelectThis
->WarpPointer( 40, 14 );
1225 case ID_LISTBOX_SEL_STR
:
1227 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1228 m_listbox
->SetStringSelection( _T("This") );
1229 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1230 m_listboxSorted
->SetStringSelection( _T("This") );
1231 m_lbSelectNum
->WarpPointer( 40, 14 );
1234 case ID_LISTBOX_CLEAR
:
1237 m_listboxSorted
->Clear();
1240 case ID_LISTBOX_APPEND
:
1242 m_listbox
->Append( _T("Hi!") );
1243 m_listboxSorted
->Append( _T("Hi!") );
1246 case ID_LISTBOX_DELETE
:
1249 idx
= m_listbox
->GetSelection();
1250 if ( idx
!= wxNOT_FOUND
)
1251 m_listbox
->Delete( idx
);
1252 idx
= m_listboxSorted
->GetSelection();
1253 if ( idx
!= wxNOT_FOUND
)
1254 m_listboxSorted
->Delete( idx
);
1257 case ID_LISTBOX_FONT
:
1259 m_listbox
->SetFont( *wxITALIC_FONT
);
1260 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1261 m_checkbox
->SetFont( *wxITALIC_FONT
);
1269 static const wxChar
*GetDataString(wxClientData
*data
)
1271 return data
? wx_static_cast(wxStringClientData
*, data
)->GetData().c_str()
1275 void MyPanel::OnChoice( wxCommandEvent
&event
)
1277 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1280 const int sel
= choice
->GetSelection();
1282 wxClientData
*dataEvt
= event
.GetClientObject(),
1283 *dataCtrl
= choice
->GetClientObject(sel
);
1285 wxLogMessage(_T("EVT_CHOICE: item %d/%d (event/control), ")
1286 _T("string \"%s\"/\"%s\", ")
1287 _T("data \"%s\"/\"%s\""),
1288 (int)event
.GetInt(),
1290 event
.GetString().c_str(),
1291 choice
->GetStringSelection().c_str(),
1292 GetDataString(dataEvt
),
1293 GetDataString(dataCtrl
));
1296 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1298 switch (event
.GetId())
1300 case ID_CHOICE_ENABLE
:
1302 m_choice
->Enable( event
.GetInt() == 0 );
1303 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1306 case ID_CHOICE_SEL_NUM
:
1308 m_choice
->SetSelection( 2 );
1309 m_choiceSorted
->SetSelection( 2 );
1312 case ID_CHOICE_SEL_STR
:
1314 m_choice
->SetStringSelection( _T("This") );
1315 m_choiceSorted
->SetStringSelection( _T("This") );
1318 case ID_CHOICE_CLEAR
:
1321 m_choiceSorted
->Clear();
1324 case ID_CHOICE_APPEND
:
1326 m_choice
->Append( _T("Hi!") );
1327 m_choiceSorted
->Append( _T("Hi!") );
1330 case ID_CHOICE_DELETE
:
1332 int idx
= m_choice
->GetSelection();
1333 if ( idx
!= wxNOT_FOUND
)
1334 m_choice
->Delete( idx
);
1335 idx
= m_choiceSorted
->GetSelection();
1336 if ( idx
!= wxNOT_FOUND
)
1337 m_choiceSorted
->Delete( idx
);
1340 case ID_CHOICE_FONT
:
1342 m_choice
->SetFont( *wxITALIC_FONT
);
1343 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1348 #endif // wxUSE_CHOICE
1350 void MyPanel::OnCombo( wxCommandEvent
&event
)
1352 wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string \"%s\"/\"%s\""),
1353 (int)event
.GetInt(),
1354 m_combo
->GetSelection(),
1355 event
.GetString().c_str(),
1356 m_combo
->GetStringSelection().c_str());
1359 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1361 wxLogMessage(wxT("EVT_TEXT for the combobox: \"%s\" (event) or \"%s\" (control)."),
1362 event
.GetString().c_str(),
1363 m_combo
->GetValue().c_str());
1366 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1368 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1369 m_combo
->GetValue().c_str());
1372 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1374 switch (event
.GetId())
1376 case ID_COMBO_ENABLE
:
1378 m_combo
->Enable( event
.GetInt() == 0 );
1381 case ID_COMBO_SEL_NUM
:
1383 m_combo
->SetSelection( 2 );
1386 case ID_COMBO_SEL_STR
:
1388 m_combo
->SetStringSelection( _T("This") );
1391 case ID_COMBO_CLEAR
:
1396 case ID_COMBO_APPEND
:
1398 m_combo
->Append( _T("Hi!") );
1401 case ID_COMBO_DELETE
:
1403 int idx
= m_combo
->GetSelection();
1404 m_combo
->Delete( idx
);
1409 m_combo
->SetFont( *wxITALIC_FONT
);
1412 case ID_COMBO_SET_TEXT
:
1414 m_combo
->SetString( 2, wxT("Hi!") );
1420 void MyPanel::OnRadio( wxCommandEvent
&event
)
1422 m_text
->AppendText( _T("RadioBox selection string is: ") );
1423 m_text
->AppendText( event
.GetString() );
1424 m_text
->AppendText( _T("\n") );
1427 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1429 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1432 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1434 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1437 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1439 switch (event
.GetId())
1441 case ID_RADIOBOX_ENABLE
:
1442 m_radio
->Enable( event
.GetInt() == 0 );
1445 case ID_RADIOBOX_SEL_NUM
:
1446 m_radio
->SetSelection( 2 );
1449 case ID_RADIOBOX_SEL_STR
:
1450 m_radio
->SetStringSelection( _T("This") );
1453 case ID_RADIOBOX_FONT
:
1454 m_radio
->SetFont( *wxITALIC_FONT
);
1459 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1461 m_fontButton
->SetFont( *wxITALIC_FONT
);
1462 m_text
->SetFont( *wxITALIC_FONT
);
1465 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1467 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1468 : _T("Shorter text."));
1473 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1476 m_gauge
->SetValue( m_slider
->GetValue() );
1477 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1478 #endif // wxUSE_GAUGE
1481 #endif // wxUSE_SLIDER
1485 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1490 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1491 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1492 m_text
->AppendText(s
);
1496 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1501 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1502 m_spinctrl
->GetValue(), event
.GetInt() );
1503 m_text
->AppendText(s
);
1507 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1511 m_text
->AppendText( wxString::Format(
1512 _T("Spin up: %d (from event: %ld)\n"),
1513 m_spinctrl
->GetValue(), event
.GetInt() ) );
1517 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1521 m_text
->AppendText( wxString::Format(
1522 _T("Spin down: %d (from event: %ld)\n"),
1523 m_spinctrl
->GetValue(), event
.GetInt() ) );
1527 #endif // wxUSE_SPINCTRL
1530 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1533 value
.Printf( _T("Spin control up: current = %d\n"),
1534 m_spinbutton
->GetValue());
1536 if ( event
.GetPosition() > 17 )
1538 value
+= _T("Preventing the spin button from going above 17.\n");
1543 m_text
->AppendText(value
);
1546 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1549 value
.Printf( _T("Spin control down: current = %d\n"),
1550 m_spinbutton
->GetValue());
1552 if ( event
.GetPosition() < -17 )
1554 value
+= _T("Preventing the spin button from going below -17.\n");
1559 m_text
->AppendText(value
);
1562 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1565 value
.Printf( _T("%d"), event
.GetPosition() );
1566 m_spintext
->SetValue( value
);
1568 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1569 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1570 m_spinbutton
->GetValue());
1572 m_text
->AppendText(value
);
1575 void MyPanel::OnNewText( wxCommandEvent
& /* event */)
1577 m_nonWrappingText
->SetLabel( wxT("This text is short\nbut still spans\nover three lines.") );
1578 m_wrappingText
->SetLabel( wxT("This text is short but will still be wrapped if it is too long.") );
1579 m_wrappingText
->GetParent()->Layout();
1582 #if wxUSE_PROGRESSDLG
1584 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1586 event
.Enable( m_spinbutton
->GetValue() > 0 );
1589 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1591 int max
= m_spinbutton
->GetValue();
1595 wxLogError(_T("You must set positive range!"));
1599 wxProgressDialog
dialog(_T("Progress dialog example"),
1600 _T("An informative message"),
1607 wxPD_ESTIMATED_TIME
|
1608 wxPD_REMAINING_TIME
);
1612 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1617 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1619 else if ( i
== max
/ 2 )
1621 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1625 cont
= dialog
.Update(i
);
1631 *m_text
<< _T("Progress dialog aborted!\n");
1635 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1639 #endif // wxUSE_PROGRESSDLG
1640 #endif // wxUSE_SPINBTN
1642 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1644 switch (event
.GetId ()) {
1645 case ID_SIZER_CHECK1
:
1646 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1647 m_buttonSizer
->Layout ();
1649 case ID_SIZER_CHECK2
:
1650 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1651 m_buttonSizer
->Layout ();
1653 case ID_SIZER_CHECK3
:
1654 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1655 m_buttonSizer
->Layout ();
1657 case ID_SIZER_CHECK4
:
1658 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1659 m_buttonSizer
->Layout ();
1661 case ID_SIZER_CHECK14
:
1662 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1663 m_hsizer
->Layout ();
1665 case ID_SIZER_CHECKBIG
:
1666 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1667 m_hsizer
->Layout ();
1675 //wxLog::RemoveTraceMask(_T("focus"));
1676 delete wxLog::SetActiveTarget(m_logTargetOld
);
1678 delete m_book
->GetImageList();
1681 //----------------------------------------------------------------------
1683 //----------------------------------------------------------------------
1685 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1686 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1687 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1688 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1690 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1691 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1692 #endif // wxUSE_TOOLTIPS
1694 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1696 EVT_ICONIZE(MyFrame::OnIconized
)
1697 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1698 EVT_SIZE(MyFrame::OnSize
)
1699 EVT_MOVE(MyFrame::OnMove
)
1701 EVT_IDLE(MyFrame::OnIdle
)
1704 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1705 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1708 // The wxICON() macros loads an icon from a resource under Windows
1709 // and uses an #included XPM image under GTK+ and Motif
1712 SetIcon( wxICON(mondrian
) );
1715 wxMenu
*file_menu
= new wxMenu
;
1717 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1718 file_menu
->AppendSeparator();
1719 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1720 file_menu
->AppendSeparator();
1721 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1723 wxMenuBar
*menu_bar
= new wxMenuBar
;
1724 menu_bar
->Append(file_menu
, _T("&File"));
1727 wxMenu
*tooltip_menu
= new wxMenu
;
1728 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1729 tooltip_menu
->AppendSeparator();
1730 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1731 _T("enable/disable tooltips"), true);
1732 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1733 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1734 #endif // wxUSE_TOOLTIPS
1736 wxMenu
*panel_menu
= new wxMenu
;
1737 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1738 _T("Enable/disable all panel controls"), true);
1739 menu_bar
->Append(panel_menu
, _T("&Panel"));
1741 SetMenuBar(menu_bar
);
1745 #endif // wxUSE_STATUSBAR
1747 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1749 SetSizeHints( 500, 425 );
1752 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1757 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1761 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1765 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1767 m_panel
->m_text
->Clear();
1771 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1773 static long s_delay
= 5000;
1776 delay
.Printf( _T("%ld"), s_delay
);
1778 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1779 _T("Set tooltip delay"),
1783 return; // cancelled
1785 wxSscanf(delay
, _T("%ld"), &s_delay
);
1787 wxToolTip::SetDelay(s_delay
);
1789 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1792 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1794 static bool s_enabled
= true;
1796 s_enabled
= !s_enabled
;
1798 wxToolTip::Enable(s_enabled
);
1800 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1804 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1806 static bool s_enable
= true;
1808 s_enable
= !s_enable
;
1809 m_panel
->Enable(s_enable
);
1812 void MyFrame::OnMove( wxMoveEvent
& event
)
1815 UpdateStatusBar(event
.GetPosition(), GetSize());
1816 #endif // wxUSE_STATUSBAR
1821 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1823 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1828 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1830 wxLogMessage(_T("Frame maximized"));
1833 void MyFrame::OnSize( wxSizeEvent
& event
)
1836 UpdateStatusBar(GetPosition(), event
.GetSize());
1837 #endif // wxUSE_STATUSBAR
1842 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1844 // track the window which has the focus in the status bar
1845 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1846 wxWindow
*focus
= wxWindow::FindFocus();
1847 if ( focus
&& (focus
!= s_windowFocus
) )
1849 s_windowFocus
= focus
;
1854 _T("Focus: %s, HWND = %08x"),
1858 s_windowFocus
->GetClassInfo()->GetClassName()
1860 , (unsigned int) s_windowFocus
->GetHWND()
1866 #endif // wxUSE_STATUSBAR
1870 void MyComboBox::OnChar(wxKeyEvent
& event
)
1872 wxLogMessage(_T("MyComboBox::OnChar"));
1874 if ( event
.GetKeyCode() == 'w' )
1875 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1880 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1882 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1884 if ( event
.GetKeyCode() == 'w' )
1885 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1890 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1892 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1897 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1899 size_t count
= control
->GetCount();
1900 for ( size_t n
= 0; n
< count
; n
++ )
1903 s
.Printf(wxT("%s client data for '%s'"),
1904 name
, control
->GetString(n
).c_str());
1906 control
->SetClientObject(n
, new wxStringClientData(s
));
1912 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1914 size_t count
= control
->GetCount();
1915 for ( size_t n
= 0; n
< count
; n
++ )
1918 s
.Printf(wxT("%s client data for '%s'"),
1919 name
, control
->GetString(n
).c_str());
1921 control
->SetClientObject(n
, new wxStringClientData(s
));
1925 #endif // wxUSE_CHOICE