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
58 //----------------------------------------------------------------------
60 //----------------------------------------------------------------------
62 class MyApp
: public wxApp
68 class MyPanel
: public wxPanel
71 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
74 void OnSize( wxSizeEvent
& event
);
75 void OnListBox( wxCommandEvent
&event
);
76 void OnListBoxDoubleClick( wxCommandEvent
&event
);
77 void OnListBoxButtons( wxCommandEvent
&event
);
79 void OnChoice( wxCommandEvent
&event
);
80 void OnChoiceButtons( wxCommandEvent
&event
);
82 void OnCombo( wxCommandEvent
&event
);
83 void OnComboTextChanged( wxCommandEvent
&event
);
84 void OnComboTextEnter( wxCommandEvent
&event
);
85 void OnComboButtons( wxCommandEvent
&event
);
86 void OnRadio( wxCommandEvent
&event
);
87 void OnRadioButtons( wxCommandEvent
&event
);
88 void OnRadioButton1( wxCommandEvent
&event
);
89 void OnRadioButton2( wxCommandEvent
&event
);
90 void OnSetFont( wxCommandEvent
&event
);
91 void OnPageChanged( wxBookCtrlEvent
&event
);
92 void OnPageChanging( wxBookCtrlEvent
&event
);
93 void OnSliderUpdate( wxCommandEvent
&event
);
94 void OnUpdateLabel( wxCommandEvent
&event
);
96 void OnSpinUp( wxSpinEvent
&event
);
97 void OnSpinDown( wxSpinEvent
&event
);
98 void OnSpinUpdate( wxSpinEvent
&event
);
99 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
100 void OnShowProgress( wxCommandEvent
&event
);
101 #endif // wxUSE_SPINBTN
104 void OnSpinCtrl(wxSpinEvent
& event
);
105 void OnSpinCtrlUp(wxSpinEvent
& event
);
106 void OnSpinCtrlDown(wxSpinEvent
& event
);
107 void OnSpinCtrlText(wxCommandEvent
& event
);
108 #endif // wxUSE_SPINCTRL
110 void OnEnableAll(wxCommandEvent
& event
);
111 void OnChangeColour(wxCommandEvent
& event
);
112 void OnTestButton(wxCommandEvent
& event
);
113 void OnBmpButton(wxCommandEvent
& event
);
115 void OnSizerCheck (wxCommandEvent
&event
);
117 wxListBox
*m_listbox
,
122 #endif // wxUSE_CHOICE
130 #endif // wxUSE_SLIDER
131 wxButton
*m_fontButton
;
132 wxButton
*m_lbSelectNum
;
133 wxButton
*m_lbSelectThis
;
135 wxSpinButton
*m_spinbutton
;
136 wxButton
*m_btnProgress
;
137 #endif // wxUSE_SPINBTN
140 wxSpinCtrl
*m_spinctrl
;
141 #endif // wxUSE_SPINCTRL
143 wxTextCtrl
*m_spintext
;
144 wxCheckBox
*m_checkbox
;
149 wxStaticText
*m_label
;
151 wxBoxSizer
*m_buttonSizer
;
152 wxButton
*m_sizerBtn1
;
153 wxButton
*m_sizerBtn2
;
154 wxButton
*m_sizerBtn3
;
155 wxButton
*m_sizerBtn4
;
156 wxBoxSizer
*m_hsizer
;
160 wxLog
*m_logTargetOld
;
162 DECLARE_EVENT_TABLE()
165 class MyFrame
: public wxFrame
168 MyFrame(const wxChar
*title
, int x
, int y
);
170 void OnQuit(wxCommandEvent
& event
);
171 void OnAbout(wxCommandEvent
& event
);
172 void OnClearLog(wxCommandEvent
& event
);
175 void OnSetTooltipDelay(wxCommandEvent
& event
);
176 void OnToggleTooltips(wxCommandEvent
& event
);
177 #endif // wxUSE_TOOLTIPS
179 void OnEnableAll(wxCommandEvent
& event
);
181 void OnIdle( wxIdleEvent
& event
);
182 void OnIconized( wxIconizeEvent
& event
);
183 void OnMaximized( wxMaximizeEvent
& event
);
184 void OnSize( wxSizeEvent
& event
);
185 void OnMove( wxMoveEvent
& event
);
187 MyPanel
*GetPanel() const { return m_panel
; }
191 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
193 if ( m_frameStatusBar
)
196 wxSize sizeAll
= GetSize(),
197 sizeCl
= GetClientSize();
198 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
201 sizeAll
.x
, sizeAll
.y
,
203 SetStatusText(msg
, 1);
206 #endif // wxUSE_STATUSBAR
210 DECLARE_EVENT_TABLE()
213 // a button which intercepts double clicks (for testing...)
214 class MyButton
: public wxButton
217 MyButton(wxWindow
*parent
,
219 const wxString
& label
= wxEmptyString
,
220 const wxPoint
& pos
= wxDefaultPosition
,
221 const wxSize
& size
= wxDefaultSize
)
222 : wxButton(parent
, id
, label
, pos
, size
)
226 void OnDClick(wxMouseEvent
& event
)
228 wxLogMessage(_T("MyButton::OnDClick"));
234 DECLARE_EVENT_TABLE()
237 // a combo which intercepts chars (to test Windows behaviour)
238 class MyComboBox
: public wxComboBox
241 MyComboBox(wxWindow
*parent
, wxWindowID id
,
242 const wxString
& value
= wxEmptyString
,
243 const wxPoint
& pos
= wxDefaultPosition
,
244 const wxSize
& size
= wxDefaultSize
,
245 int n
= 0, const wxString choices
[] = NULL
,
247 const wxValidator
& validator
= wxDefaultValidator
,
248 const wxString
& name
= wxComboBoxNameStr
)
249 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
253 void OnChar(wxKeyEvent
& event
);
254 void OnKeyDown(wxKeyEvent
& event
);
255 void OnKeyUp(wxKeyEvent
& event
);
256 void OnFocusGot(wxFocusEvent
& event
)
258 wxLogMessage(_T("MyComboBox::OnFocusGot"));
264 DECLARE_EVENT_TABLE()
267 // a radiobox which handles focus set/kill (for testing)
268 class MyRadioBox
: public wxRadioBox
271 MyRadioBox(wxWindow
*parent
,
273 const wxString
& title
= wxEmptyString
,
274 const wxPoint
& pos
= wxDefaultPosition
,
275 const wxSize
& size
= wxDefaultSize
,
276 int n
= 0, const wxString choices
[] = NULL
,
278 long style
= wxRA_HORIZONTAL
,
279 const wxValidator
& validator
= wxDefaultValidator
,
280 const wxString
& name
= wxRadioBoxNameStr
)
281 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
282 style
, validator
, name
) { SetForegroundColour(*wxRED
); }
285 void OnFocusGot(wxFocusEvent
& event
)
287 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
292 void OnFocusLost(wxFocusEvent
& event
)
294 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
300 DECLARE_EVENT_TABLE()
303 //----------------------------------------------------------------------
305 //----------------------------------------------------------------------
307 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
310 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
311 #endif // wxUSE_CHOICE
315 //----------------------------------------------------------------------
317 //----------------------------------------------------------------------
327 CONTROLS_SET_TOOLTIP_DELAY
= 200,
328 CONTROLS_ENABLE_TOOLTIPS
,
336 // use standard command line handling:
337 if ( !wxApp::OnInit() )
340 // parse the cmd line
345 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
346 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
349 // Create the main frame window
350 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
356 //----------------------------------------------------------------------
358 //----------------------------------------------------------------------
360 const int ID_BOOK
= 1000;
362 const int ID_LISTBOX
= 130;
363 const int ID_LISTBOX_SEL_NUM
= 131;
364 const int ID_LISTBOX_SEL_STR
= 132;
365 const int ID_LISTBOX_CLEAR
= 133;
366 const int ID_LISTBOX_APPEND
= 134;
367 const int ID_LISTBOX_DELETE
= 135;
368 const int ID_LISTBOX_FONT
= 136;
369 const int ID_LISTBOX_ENABLE
= 137;
370 const int ID_LISTBOX_SORTED
= 138;
372 const int ID_CHOICE
= 120;
373 const int ID_CHOICE_SEL_NUM
= 121;
374 const int ID_CHOICE_SEL_STR
= 122;
375 const int ID_CHOICE_CLEAR
= 123;
376 const int ID_CHOICE_APPEND
= 124;
377 const int ID_CHOICE_DELETE
= 125;
378 const int ID_CHOICE_FONT
= 126;
379 const int ID_CHOICE_ENABLE
= 127;
380 const int ID_CHOICE_SORTED
= 128;
382 const int ID_COMBO
= 140;
383 const int ID_COMBO_SEL_NUM
= 141;
384 const int ID_COMBO_SEL_STR
= 142;
385 const int ID_COMBO_CLEAR
= 143;
386 const int ID_COMBO_APPEND
= 144;
387 const int ID_COMBO_DELETE
= 145;
388 const int ID_COMBO_FONT
= 146;
389 const int ID_COMBO_ENABLE
= 147;
391 const int ID_RADIOBOX
= 160;
392 const int ID_RADIOBOX_SEL_NUM
= 161;
393 const int ID_RADIOBOX_SEL_STR
= 162;
394 const int ID_RADIOBOX_FONT
= 163;
395 const int ID_RADIOBOX_ENABLE
= 164;
397 const int ID_RADIOBUTTON_1
= 166;
398 const int ID_RADIOBUTTON_2
= 167;
400 const int ID_SET_FONT
= 170;
402 const int ID_GAUGE
= 180;
404 const int ID_SLIDER
= 181;
405 #endif // wxUSE_SLIDER
407 const int ID_SPIN
= 182;
408 const int ID_BTNPROGRESS
= 183;
409 const int ID_BUTTON_LABEL
= 184;
410 const int ID_SPINCTRL
= 185;
412 const int ID_BUTTON_TEST1
= 190;
413 const int ID_BUTTON_TEST2
= 191;
414 const int ID_BITMAP_BTN
= 192;
416 const int ID_CHANGE_COLOUR
= 200;
418 const int ID_SIZER_CHECK1
= 201;
419 const int ID_SIZER_CHECK2
= 202;
420 const int ID_SIZER_CHECK3
= 203;
421 const int ID_SIZER_CHECK4
= 204;
422 const int ID_SIZER_CHECK14
= 205;
423 const int ID_SIZER_CHECKBIG
= 206;
425 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
426 EVT_SIZE ( MyPanel::OnSize
)
427 EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK
, MyPanel::OnPageChanging
)
428 EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK
, MyPanel::OnPageChanged
)
429 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
430 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
431 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
432 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
433 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
434 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
435 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
436 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
437 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
438 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
440 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
441 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
442 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
443 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
444 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
445 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
446 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
447 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
448 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
450 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
451 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
452 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
453 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
454 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
455 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
456 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
457 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
458 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
459 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
460 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
461 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
462 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
463 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
464 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
465 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
466 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
467 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
469 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
470 #endif // wxUSE_SLIDER
472 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
473 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
474 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
475 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
476 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
477 #endif // wxUSE_SPINBTN
479 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
480 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
481 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
482 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
483 #endif // wxUSE_SPINCTRL
485 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
487 EVT_CHECKBOX(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
488 #endif // wxUSE_TOGGLEBTN
489 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
490 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
491 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
492 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
494 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
495 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
496 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
497 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
498 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
499 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
503 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
504 EVT_LEFT_DCLICK(MyButton::OnDClick
)
507 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
508 EVT_CHAR(MyComboBox::OnChar
)
509 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
510 EVT_KEY_UP(MyComboBox::OnKeyUp
)
512 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
515 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
516 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
517 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
520 // ============================================================================
522 // ============================================================================
524 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
525 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
528 m_listboxSorted
= NULL
;
531 m_choiceSorted
= NULL
;
532 #endif // wxUSE_CHOICE
539 #endif // wxUSE_SLIDER
541 m_lbSelectNum
= NULL
;
542 m_lbSelectThis
= NULL
;
545 m_btnProgress
= NULL
;
546 #endif // wxUSE_SPINBTN
549 #endif // wxUSE_SPINCTRL
556 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
557 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
558 m_text
->SetBackgroundColour(wxT("wheat"));
560 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
562 m_book
= new wxBookCtrl(this, ID_BOOK
);
577 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
580 // fill the image list
581 wxBitmap
bmp(list_xpm
);
583 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
585 imagelist
-> Add( bmp
);
586 imagelist
-> Add( wxBitmap( choice_xpm
));
587 imagelist
-> Add( wxBitmap( combo_xpm
));
588 imagelist
-> Add( wxBitmap( text_xpm
));
589 imagelist
-> Add( wxBitmap( radio_xpm
));
590 imagelist
-> Add( wxBitmap( gauge_xpm
));
591 m_book
->SetImageList(imagelist
);
592 #elif defined(__WXMSW__)
593 // load images from resources
596 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
598 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
600 static const wxChar
*s_iconNames
[Image_Max
] =
602 _T("list"), _T("choice"), _T("combo"), _T("text"), _T("radio"),
606 for ( size_t n
= 0; n
< Image_Max
; n
++ )
608 wxBitmap
bmp(s_iconNames
[n
]);
609 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
611 wxLogWarning(wxT("Couldn't load the image '%s' for the book control page %d."),
616 m_book
->SetImageList(imagelist
);
620 #define Image_List -1
621 #define Image_Choice -1
622 #define Image_Combo -1
623 #define Image_Text -1
624 #define Image_Radio -1
625 #define Image_Gauge -1
630 wxPanel
*panel
= new wxPanel(m_book
);
631 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
632 wxPoint(10,10), wxSize(120,70),
633 5, choices
, wxLB_ALWAYS_SB
);
634 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
635 wxPoint(10,90), wxSize(120,70),
636 5, choices
, wxLB_SORT
);
638 SetListboxClientData(wxT("listbox"), m_listbox
);
639 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
641 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
643 m_listbox
->SetToolTip( _T("This is a list box") );
644 #endif // wxUSE_TOOLTIPS
646 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
647 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
648 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
649 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
650 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
651 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
653 button
->SetDefault();
654 button
->SetForegroundColour(*wxBLUE
);
657 button
->SetToolTip( _T("Press here to set italic font") );
658 #endif // wxUSE_TOOLTIPS
660 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
661 m_checkbox
->SetValue(false);
662 button
->MoveAfterInTabOrder(m_checkbox
);
664 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
665 #endif // wxUSE_TOOLTIPS
666 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
668 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
669 m_book
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
672 panel
= new wxPanel(m_book
);
673 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
674 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
675 5, choices
, wxCB_SORT
);
677 SetChoiceClientData(wxT("choice"), m_choice
);
678 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
680 m_choice
->SetSelection(2);
681 m_choice
->SetBackgroundColour( wxT("red") );
682 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
683 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
684 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
685 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
686 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
687 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
688 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
690 m_book
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
691 #endif // wxUSE_CHOICE
693 panel
= new wxPanel(m_book
);
694 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
695 wxPoint(5, 5), wxSize(150, 100));
696 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
697 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
699 wxCB_READONLY
| wxPROCESS_ENTER
);
700 m_combo
->SetBackgroundColour(*wxBLUE
);
702 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
703 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
704 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
705 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
706 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
707 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
708 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
709 m_book
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
711 wxString choices2
[] =
713 _T("First"), _T("Second"),
715 "Fourth", "Fifth", "Sixth",
716 "Seventh", "Eighth", "Nineth", "Tenth" */
719 panel
= new wxPanel(m_book
);
720 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
721 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
722 m_radio
->SetForegroundColour(*wxRED
);
725 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
726 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
727 #endif // wxUSE_TOOLTIPS
729 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
730 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
731 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
732 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
733 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
734 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
735 rb
->SetValue( false );
736 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
737 m_book
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
739 #if wxUSE_SLIDER && wxUSE_GAUGE
740 panel
= new wxPanel(m_book
);
741 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
742 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
743 m_gauge
->SetBackgroundColour(*wxGREEN
);
744 m_gauge
->SetForegroundColour(*wxRED
);
745 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
746 wxPoint(195,35), wxSize(30, 90),
747 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
748 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,wxDefaultCoord
),
749 wxSL_AUTOTICKS
| wxSL_LABELS
);
750 m_slider
->SetTickFreq(40, 0);
752 m_slider
->SetToolTip(_T("This is a sliding slider"));
753 #endif // wxUSE_TOOLTIPS
755 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
756 wxPoint(230,10), wxSize(270,130),
760 // No wrapping text in wxStaticText yet :-(
761 (void)new wxStaticText( panel
, wxID_ANY
,
762 _T("Drag the slider!"),
764 wxSize(240, wxDefaultCoord
)
767 (void)new wxStaticText( panel
, wxID_ANY
,
768 _T("In order see the gauge (aka progress bar)\n")
769 _T("control do something you have to drag the\n")
770 _T("handle of the slider to the right.\n")
772 _T("This is also supposed to demonstrate how\n")
773 _T("to use static controls.\n"),
778 int initialSpinValue
= -5;
780 s
<< initialSpinValue
;
781 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
783 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, wxDefaultCoord
) );
784 m_spinbutton
->SetRange(-40,30);
785 m_spinbutton
->SetValue(initialSpinValue
);
787 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
789 #endif // wxUSE_SPINBTN
792 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
793 m_spinctrl
->SetRange(10,30);
794 m_spinctrl
->SetValue(15);
795 #endif // wxUSE_SPINCTRL
797 m_book
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
798 #endif // wxUSE_SLIDER && wxUSE_GAUGE
800 panel
= new wxPanel(m_book
);
802 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
803 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
804 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
806 // VZ: don't leak memory
807 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
808 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
811 wxBitmap
bitmap( 100, 100 );
813 dc
.SelectObject( bitmap
);
814 dc
.SetPen(*wxGREEN_PEN
);
816 dc
.DrawEllipse(5, 5, 90, 90);
817 dc
.DrawText(_T("Bitmap"), 30, 40);
818 dc
.SelectObject( wxNullBitmap
);
820 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
822 #if defined(__WXMSW__) || defined(__WXMOTIF__)
823 // test for masked bitmap display
824 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
827 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
829 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
833 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
834 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
835 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
836 wxBitmapButton
*bmpBtn
= new wxBitmapButton
843 bmpBtn
->SetBitmapSelected(bmp2
);
844 bmpBtn
->SetBitmapFocus(bmp3
);
847 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
848 _T("&Toggle label"), wxPoint(250, 20));
850 (void)new wxCheckBox(panel
, ID_BUTTON_LABEL
,
851 _T("&Toggle label"), wxPoint(250, 20));
852 #endif // wxUSE_TOGGLEBTN
854 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
855 wxPoint(250, 60), wxDefaultSize
,
856 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
857 m_label
->SetForegroundColour( *wxBLUE
);
859 m_book
->AddPage(panel
, _T("wxBitmapXXX"));
863 panel
= new wxPanel(m_book
);
864 panel
->SetAutoLayout( true );
866 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
868 wxStaticBoxSizer
*csizer
=
869 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
871 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
872 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
873 check1
->SetValue (true);
874 csizer
->Add (check1
);
875 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
876 check2
->SetValue (true);
877 csizer
->Add (check2
);
878 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
879 check3
->SetValue (true);
880 csizer
->Add (check3
);
881 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
882 check4
->SetValue (true);
883 csizer
->Add (check4
);
884 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
885 check14
->SetValue (true);
886 csizer
->Add (check14
);
887 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
888 checkBig
->SetValue (true);
889 csizer
->Add (checkBig
);
893 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
895 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
897 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
898 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
899 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
900 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
901 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
902 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
903 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
904 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
906 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
908 m_hsizer
->Add (m_buttonSizer
);
909 m_hsizer
->Add( 20,20, 1 );
910 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
911 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
913 sizer
->Add (m_hsizer
, 1, wxGROW
);
915 panel
->SetSizer( sizer
);
917 m_book
->AddPage(panel
, _T("wxSizer"));
920 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
924 GetClientSize( &x
, &y
);
926 if (m_book
) m_book
->SetSize( 2, 2, x
-4, y
*2/3-4 );
927 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
930 void MyPanel::OnPageChanging( wxBookCtrlEvent
&event
)
932 int selOld
= event
.GetOldSelection();
935 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
936 _T("page change from taking place - if you select\n")
937 _T("[No] the current page will stay the third one\n"),
938 _T("Control sample"),
939 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
947 *m_text
<< _T("Book selection is being changed from ") << selOld
948 << _T(" to ") << event
.GetSelection()
949 << _T(" (current page from book is ")
950 << m_book
->GetSelection() << _T(")\n");
953 void MyPanel::OnPageChanged( wxBookCtrlEvent
&event
)
955 *m_text
<< _T("Book selection is now ") << event
.GetSelection()
956 << _T(" (from book: ") << m_book
->GetSelection()
960 void MyPanel::OnTestButton(wxCommandEvent
& event
)
962 wxLogMessage(_T("Button %c clicked."),
963 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
966 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
968 wxLogMessage(_T("Bitmap button clicked."));
971 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
973 static wxColour s_colOld
;
975 SetThemeEnabled(false);
976 // test panel colour changing and propagation to the subcontrols
979 SetBackgroundColour(s_colOld
);
980 s_colOld
= wxNullColour
;
982 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
983 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
987 s_colOld
= wxColour(wxT("red"));
988 SetBackgroundColour(wxT("white"));
990 m_lbSelectThis
->SetForegroundColour(wxT("white"));
991 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
994 m_lbSelectThis
->Refresh();
998 void MyPanel::OnListBox( wxCommandEvent
&event
)
1000 // GetParent()->Move(100, 100);
1002 if (event
.GetInt() == -1)
1004 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
1008 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1011 m_text
->AppendText( _T("ListBox event selection string is: '") );
1012 m_text
->AppendText( event
.GetString() );
1013 m_text
->AppendText( _T("'\n") );
1014 m_text
->AppendText( _T("ListBox control selection string is: '") );
1015 m_text
->AppendText( listbox
->GetStringSelection() );
1016 m_text
->AppendText( _T("'\n") );
1018 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1019 m_text
->AppendText( _T("ListBox event client data string is: '") );
1020 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1021 m_text
->AppendText( obj
->GetData() );
1023 m_text
->AppendText( wxString(_T("none")) );
1025 m_text
->AppendText( _T("'\n") );
1026 m_text
->AppendText( _T("ListBox control client data string is: '") );
1027 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1029 m_text
->AppendText( obj
->GetData() );
1031 m_text
->AppendText( wxString(_T("none")) );
1032 m_text
->AppendText( _T("'\n") );
1035 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1037 m_text
->AppendText( _T("ListBox double click string is: ") );
1038 m_text
->AppendText( event
.GetString() );
1039 m_text
->AppendText( _T("\n") );
1042 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1044 switch (event
.GetId())
1046 case ID_LISTBOX_ENABLE
:
1048 m_text
->AppendText(_T("Checkbox clicked.\n"));
1050 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1052 cb
->SetToolTip( _T("Click to enable listbox") );
1054 cb
->SetToolTip( _T("Click to disable listbox") );
1055 #endif // wxUSE_TOOLTIPS
1056 m_listbox
->Enable( event
.GetInt() == 0 );
1057 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1058 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1059 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1060 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1063 case ID_LISTBOX_SEL_NUM
:
1065 if (m_listbox
->GetCount() > 2)
1066 m_listbox
->SetSelection( 2 );
1067 if (m_listboxSorted
->GetCount() > 2)
1068 m_listboxSorted
->SetSelection( 2 );
1069 m_lbSelectThis
->WarpPointer( 40, 14 );
1072 case ID_LISTBOX_SEL_STR
:
1074 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1075 m_listbox
->SetStringSelection( _T("This") );
1076 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1077 m_listboxSorted
->SetStringSelection( _T("This") );
1078 m_lbSelectNum
->WarpPointer( 40, 14 );
1081 case ID_LISTBOX_CLEAR
:
1084 m_listboxSorted
->Clear();
1087 case ID_LISTBOX_APPEND
:
1089 m_listbox
->Append( _T("Hi!") );
1090 m_listboxSorted
->Append( _T("Hi!") );
1093 case ID_LISTBOX_DELETE
:
1096 idx
= m_listbox
->GetSelection();
1097 if ( idx
!= wxNOT_FOUND
)
1098 m_listbox
->Delete( idx
);
1099 idx
= m_listboxSorted
->GetSelection();
1100 if ( idx
!= wxNOT_FOUND
)
1101 m_listboxSorted
->Delete( idx
);
1104 case ID_LISTBOX_FONT
:
1106 m_listbox
->SetFont( *wxITALIC_FONT
);
1107 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1108 m_checkbox
->SetFont( *wxITALIC_FONT
);
1115 void MyPanel::OnChoice( wxCommandEvent
&event
)
1117 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1120 m_text
->AppendText( _T("Choice event selection string is: '") );
1121 m_text
->AppendText( event
.GetString() );
1122 m_text
->AppendText( _T("'\n") );
1123 m_text
->AppendText( _T("Choice control selection string is: '") );
1124 m_text
->AppendText( choice
->GetStringSelection() );
1125 m_text
->AppendText( _T("'\n") );
1127 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1128 m_text
->AppendText( _T("Choice event client data string is: '") );
1131 m_text
->AppendText( obj
->GetData() );
1133 m_text
->AppendText( wxString(_T("none")) );
1135 m_text
->AppendText( _T("'\n") );
1136 m_text
->AppendText( _T("Choice control client data string is: '") );
1137 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1140 m_text
->AppendText( obj
->GetData() );
1142 m_text
->AppendText( wxString(_T("none")) );
1143 m_text
->AppendText( _T("'\n") );
1146 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1148 switch (event
.GetId())
1150 case ID_CHOICE_ENABLE
:
1152 m_choice
->Enable( event
.GetInt() == 0 );
1153 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1156 case ID_CHOICE_SEL_NUM
:
1158 m_choice
->SetSelection( 2 );
1159 m_choiceSorted
->SetSelection( 2 );
1162 case ID_CHOICE_SEL_STR
:
1164 m_choice
->SetStringSelection( _T("This") );
1165 m_choiceSorted
->SetStringSelection( _T("This") );
1168 case ID_CHOICE_CLEAR
:
1171 m_choiceSorted
->Clear();
1174 case ID_CHOICE_APPEND
:
1176 m_choice
->Append( _T("Hi!") );
1177 m_choiceSorted
->Append( _T("Hi!") );
1180 case ID_CHOICE_DELETE
:
1182 int idx
= m_choice
->GetSelection();
1183 if ( idx
!= wxNOT_FOUND
)
1184 m_choice
->Delete( idx
);
1185 idx
= m_choiceSorted
->GetSelection();
1186 if ( idx
!= wxNOT_FOUND
)
1187 m_choiceSorted
->Delete( idx
);
1190 case ID_CHOICE_FONT
:
1192 m_choice
->SetFont( *wxITALIC_FONT
);
1193 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1198 #endif // wxUSE_CHOICE
1200 void MyPanel::OnCombo( wxCommandEvent
&event
)
1202 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1203 m_text
->AppendText( event
.GetString() );
1204 m_text
->AppendText( _T("\n") );
1205 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1206 m_text
->AppendText( m_combo
->GetStringSelection() );
1207 m_text
->AppendText( _T("\n") );
1210 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1213 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1214 event
.GetString().c_str() );
1215 wxLogMessage( str
.c_str() );
1218 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1220 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1221 m_combo
->GetValue().c_str());
1224 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1226 switch (event
.GetId())
1228 case ID_COMBO_ENABLE
:
1230 m_combo
->Enable( event
.GetInt() == 0 );
1233 case ID_COMBO_SEL_NUM
:
1235 m_combo
->SetSelection( 2 );
1238 case ID_COMBO_SEL_STR
:
1240 m_combo
->SetStringSelection( _T("This") );
1243 case ID_COMBO_CLEAR
:
1248 case ID_COMBO_APPEND
:
1250 m_combo
->Append( _T("Hi!") );
1253 case ID_COMBO_DELETE
:
1255 int idx
= m_combo
->GetSelection();
1256 m_combo
->Delete( idx
);
1261 m_combo
->SetFont( *wxITALIC_FONT
);
1267 void MyPanel::OnRadio( wxCommandEvent
&event
)
1269 m_text
->AppendText( _T("RadioBox selection string is: ") );
1270 m_text
->AppendText( event
.GetString() );
1271 m_text
->AppendText( _T("\n") );
1274 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1276 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1279 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1281 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1284 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1286 switch (event
.GetId())
1288 case ID_RADIOBOX_ENABLE
:
1290 m_radio
->Enable( event
.GetInt() == 0 );
1293 case ID_RADIOBOX_SEL_NUM
:
1295 m_radio
->SetSelection( 2 );
1298 case ID_RADIOBOX_SEL_STR
:
1300 m_radio
->SetStringSelection( _T("This") );
1303 case ID_RADIOBOX_FONT
:
1305 m_radio
->SetForegroundColour(*wxGREEN
);
1307 m_radio
->SetFont( *wxITALIC_FONT
);
1313 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1315 m_fontButton
->SetFont( *wxITALIC_FONT
);
1316 m_text
->SetFont( *wxITALIC_FONT
);
1319 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1321 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1322 : _T("Shorter text."));
1327 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1329 m_gauge
->SetValue( m_slider
->GetValue() );
1330 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1333 #endif // wxUSE_SLIDER
1337 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1342 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1343 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1344 m_text
->AppendText(s
);
1348 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1353 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1354 m_spinctrl
->GetValue(), event
.GetInt() );
1355 m_text
->AppendText(s
);
1359 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1363 m_text
->AppendText( wxString::Format(
1364 _T("Spin up: %d (from event: %ld)\n"),
1365 m_spinctrl
->GetValue(), event
.GetInt() ) );
1369 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1373 m_text
->AppendText( wxString::Format(
1374 _T("Spin down: %d (from event: %ld)\n"),
1375 m_spinctrl
->GetValue(), event
.GetInt() ) );
1379 #endif // wxUSE_SPINCTRL
1382 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1385 value
.Printf( _T("Spin control up: current = %d\n"),
1386 m_spinbutton
->GetValue());
1388 if ( event
.GetPosition() > 17 )
1390 value
+= _T("Preventing the spin button from going above 17.\n");
1395 m_text
->AppendText(value
);
1398 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1401 value
.Printf( _T("Spin control down: current = %d\n"),
1402 m_spinbutton
->GetValue());
1404 if ( event
.GetPosition() < -17 )
1406 value
+= _T("Preventing the spin button from going below -17.\n");
1411 m_text
->AppendText(value
);
1414 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1417 value
.Printf( _T("%d"), event
.GetPosition() );
1418 m_spintext
->SetValue( value
);
1420 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1421 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1422 m_spinbutton
->GetValue());
1424 m_text
->AppendText(value
);
1427 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1429 event
.Enable( m_spinbutton
->GetValue() > 0 );
1432 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1434 int max
= m_spinbutton
->GetValue();
1438 wxLogError(_T("You must set positive range!"));
1442 wxProgressDialog
dialog(_T("Progress dialog example"),
1443 _T("An informative message"),
1450 wxPD_ESTIMATED_TIME
|
1451 wxPD_REMAINING_TIME
);
1455 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1460 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1462 else if ( i
== max
/ 2 )
1464 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1468 cont
= dialog
.Update(i
);
1474 *m_text
<< _T("Progress dialog aborted!\n");
1478 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1482 #endif // wxUSE_SPINBTN
1484 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1486 switch (event
.GetId ()) {
1487 case ID_SIZER_CHECK1
:
1488 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1489 m_buttonSizer
->Layout ();
1491 case ID_SIZER_CHECK2
:
1492 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1493 m_buttonSizer
->Layout ();
1495 case ID_SIZER_CHECK3
:
1496 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1497 m_buttonSizer
->Layout ();
1499 case ID_SIZER_CHECK4
:
1500 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1501 m_buttonSizer
->Layout ();
1503 case ID_SIZER_CHECK14
:
1504 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1505 m_hsizer
->Layout ();
1507 case ID_SIZER_CHECKBIG
:
1508 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1509 m_hsizer
->Layout ();
1517 //wxLog::RemoveTraceMask(_T("focus"));
1518 delete wxLog::SetActiveTarget(m_logTargetOld
);
1520 delete m_book
->GetImageList();
1523 //----------------------------------------------------------------------
1525 //----------------------------------------------------------------------
1527 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1528 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1529 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1530 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1532 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1533 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1534 #endif // wxUSE_TOOLTIPS
1536 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1538 EVT_ICONIZE(MyFrame::OnIconized
)
1539 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1540 EVT_SIZE(MyFrame::OnSize
)
1541 EVT_MOVE(MyFrame::OnMove
)
1543 EVT_IDLE(MyFrame::OnIdle
)
1546 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1547 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1550 // The wxICON() macros loads an icon from a resource under Windows
1551 // and uses an #included XPM image under GTK+ and Motif
1554 SetIcon( wxICON(mondrian
) );
1557 wxMenu
*file_menu
= new wxMenu
;
1559 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1560 file_menu
->AppendSeparator();
1561 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1562 file_menu
->AppendSeparator();
1563 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1565 wxMenuBar
*menu_bar
= new wxMenuBar
;
1566 menu_bar
->Append(file_menu
, _T("&File"));
1569 wxMenu
*tooltip_menu
= new wxMenu
;
1570 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1571 tooltip_menu
->AppendSeparator();
1572 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1573 _T("enable/disable tooltips"), true);
1574 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1575 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1576 #endif // wxUSE_TOOLTIPS
1578 wxMenu
*panel_menu
= new wxMenu
;
1579 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1580 _T("Enable/disable all panel controls"), true);
1581 menu_bar
->Append(panel_menu
, _T("&Panel"));
1583 SetMenuBar(menu_bar
);
1587 #endif // wxUSE_STATUSBAR
1589 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1591 SetSizeHints( 500, 425 );
1594 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1599 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1603 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1607 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1609 m_panel
->m_text
->Clear();
1613 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1615 static long s_delay
= 5000;
1618 delay
.Printf( _T("%ld"), s_delay
);
1620 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1621 _T("Set tooltip delay"),
1625 return; // cancelled
1627 wxSscanf(delay
, _T("%ld"), &s_delay
);
1629 wxToolTip::SetDelay(s_delay
);
1631 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1634 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1636 static bool s_enabled
= true;
1638 s_enabled
= !s_enabled
;
1640 wxToolTip::Enable(s_enabled
);
1642 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1646 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1648 static bool s_enable
= true;
1650 s_enable
= !s_enable
;
1651 m_panel
->Enable(s_enable
);
1654 void MyFrame::OnMove( wxMoveEvent
& event
)
1657 UpdateStatusBar(event
.GetPosition(), GetSize());
1658 #endif // wxUSE_STATUSBAR
1663 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1665 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1670 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1672 wxLogMessage(_T("Frame maximized"));
1675 void MyFrame::OnSize( wxSizeEvent
& event
)
1678 UpdateStatusBar(GetPosition(), event
.GetSize());
1679 #endif // wxUSE_STATUSBAR
1684 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1686 // track the window which has the focus in the status bar
1687 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1688 wxWindow
*focus
= wxWindow::FindFocus();
1689 if ( focus
&& (focus
!= s_windowFocus
) )
1691 s_windowFocus
= focus
;
1696 _T("Focus: %s, HWND = %08x"),
1700 s_windowFocus
->GetClassInfo()->GetClassName()
1702 , (unsigned int) s_windowFocus
->GetHWND()
1708 #endif // wxUSE_STATUSBAR
1712 void MyComboBox::OnChar(wxKeyEvent
& event
)
1714 wxLogMessage(_T("MyComboBox::OnChar"));
1716 if ( event
.GetKeyCode() == 'w' )
1717 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1722 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1724 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1726 if ( event
.GetKeyCode() == 'w' )
1727 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1732 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1734 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1739 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1741 size_t count
= control
->GetCount();
1742 for ( size_t n
= 0; n
< count
; n
++ )
1745 s
.Printf(wxT("%s client data for '%s'"),
1746 name
, control
->GetString(n
).c_str());
1748 control
->SetClientObject(n
, new wxStringClientData(s
));
1754 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1756 size_t count
= control
->GetCount();
1757 for ( size_t n
= 0; n
< count
; n
++ )
1760 s
.Printf(wxT("%s client data for '%s'"),
1761 name
, control
->GetString(n
).c_str());
1763 control
->SetClientObject(n
, new wxStringClientData(s
));
1767 #endif // wxUSE_CHOICE