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/notebook.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( wxNotebookEvent
&event
);
92 void OnPageChanging( wxNotebookEvent
&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
129 wxButton
*m_fontButton
;
130 wxButton
*m_lbSelectNum
;
131 wxButton
*m_lbSelectThis
;
133 wxSpinButton
*m_spinbutton
;
134 wxButton
*m_btnProgress
;
135 #endif // wxUSE_SPINBTN
138 wxSpinCtrl
*m_spinctrl
;
139 #endif // wxUSE_SPINCTRL
141 wxTextCtrl
*m_spintext
;
142 wxCheckBox
*m_checkbox
;
145 wxNotebook
*m_notebook
;
147 wxStaticText
*m_label
;
149 wxBoxSizer
*m_buttonSizer
;
150 wxButton
*m_sizerBtn1
;
151 wxButton
*m_sizerBtn2
;
152 wxButton
*m_sizerBtn3
;
153 wxButton
*m_sizerBtn4
;
154 wxBoxSizer
*m_hsizer
;
158 wxLog
*m_logTargetOld
;
160 DECLARE_EVENT_TABLE()
163 class MyFrame
: public wxFrame
166 MyFrame(const wxChar
*title
, int x
, int y
);
168 void OnQuit(wxCommandEvent
& event
);
169 void OnAbout(wxCommandEvent
& event
);
170 void OnClearLog(wxCommandEvent
& event
);
173 void OnSetTooltipDelay(wxCommandEvent
& event
);
174 void OnToggleTooltips(wxCommandEvent
& event
);
175 #endif // wxUSE_TOOLTIPS
177 void OnEnableAll(wxCommandEvent
& event
);
179 void OnIdle( wxIdleEvent
& event
);
180 void OnIconized( wxIconizeEvent
& event
);
181 void OnMaximized( wxMaximizeEvent
& event
);
182 void OnSize( wxSizeEvent
& event
);
183 void OnMove( wxMoveEvent
& event
);
185 MyPanel
*GetPanel() const { return m_panel
; }
189 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
191 if ( m_frameStatusBar
)
194 wxSize sizeAll
= GetSize(),
195 sizeCl
= GetClientSize();
196 msg
.Printf(_("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)"),
199 sizeAll
.x
, sizeAll
.y
,
201 SetStatusText(msg
, 1);
204 #endif // wxUSE_STATUSBAR
208 DECLARE_EVENT_TABLE()
211 // a button which intercepts double clicks (for testing...)
212 class MyButton
: public wxButton
215 MyButton(wxWindow
*parent
,
217 const wxString
& label
= wxEmptyString
,
218 const wxPoint
& pos
= wxDefaultPosition
,
219 const wxSize
& size
= wxDefaultSize
)
220 : wxButton(parent
, id
, label
, pos
, size
)
224 void OnDClick(wxMouseEvent
& event
)
226 wxLogMessage(_T("MyButton::OnDClick"));
232 DECLARE_EVENT_TABLE()
235 // a combo which intercepts chars (to test Windows behaviour)
236 class MyComboBox
: public wxComboBox
239 MyComboBox(wxWindow
*parent
, wxWindowID id
,
240 const wxString
& value
= wxEmptyString
,
241 const wxPoint
& pos
= wxDefaultPosition
,
242 const wxSize
& size
= wxDefaultSize
,
243 int n
= 0, const wxString choices
[] = NULL
,
245 const wxValidator
& validator
= wxDefaultValidator
,
246 const wxString
& name
= wxComboBoxNameStr
)
247 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
251 void OnChar(wxKeyEvent
& event
);
252 void OnKeyDown(wxKeyEvent
& event
);
253 void OnKeyUp(wxKeyEvent
& event
);
254 void OnFocusGot(wxFocusEvent
& event
)
256 wxLogMessage(_T("MyComboBox::OnFocusGot"));
262 DECLARE_EVENT_TABLE()
265 // a radiobox which handles focus set/kill (for testing)
266 class MyRadioBox
: public wxRadioBox
269 MyRadioBox(wxWindow
*parent
,
271 const wxString
& title
= wxEmptyString
,
272 const wxPoint
& pos
= wxDefaultPosition
,
273 const wxSize
& size
= wxDefaultSize
,
274 int n
= 0, const wxString choices
[] = NULL
,
276 long style
= wxRA_HORIZONTAL
,
277 const wxValidator
& validator
= wxDefaultValidator
,
278 const wxString
& name
= wxRadioBoxNameStr
)
279 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
280 style
, validator
, name
) { SetForegroundColour(*wxRED
); }
283 void OnFocusGot(wxFocusEvent
& event
)
285 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
290 void OnFocusLost(wxFocusEvent
& event
)
292 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
298 DECLARE_EVENT_TABLE()
301 //----------------------------------------------------------------------
303 //----------------------------------------------------------------------
305 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
308 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
309 #endif // wxUSE_CHOICE
313 //----------------------------------------------------------------------
315 //----------------------------------------------------------------------
325 CONTROLS_SET_TOOLTIP_DELAY
= 200,
326 CONTROLS_ENABLE_TOOLTIPS
,
334 // use standard command line handling:
335 if ( !wxApp::OnInit() )
338 // parse the cmd line
343 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
344 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
347 // Create the main frame window
348 MyFrame
*frame
= new MyFrame(_T("Controls wxWidgets App"), x
, y
);
354 //----------------------------------------------------------------------
356 //----------------------------------------------------------------------
358 const int ID_NOTEBOOK
= 1000;
360 const int ID_LISTBOX
= 130;
361 const int ID_LISTBOX_SEL_NUM
= 131;
362 const int ID_LISTBOX_SEL_STR
= 132;
363 const int ID_LISTBOX_CLEAR
= 133;
364 const int ID_LISTBOX_APPEND
= 134;
365 const int ID_LISTBOX_DELETE
= 135;
366 const int ID_LISTBOX_FONT
= 136;
367 const int ID_LISTBOX_ENABLE
= 137;
368 const int ID_LISTBOX_SORTED
= 138;
370 const int ID_CHOICE
= 120;
371 const int ID_CHOICE_SEL_NUM
= 121;
372 const int ID_CHOICE_SEL_STR
= 122;
373 const int ID_CHOICE_CLEAR
= 123;
374 const int ID_CHOICE_APPEND
= 124;
375 const int ID_CHOICE_DELETE
= 125;
376 const int ID_CHOICE_FONT
= 126;
377 const int ID_CHOICE_ENABLE
= 127;
378 const int ID_CHOICE_SORTED
= 128;
380 const int ID_COMBO
= 140;
381 const int ID_COMBO_SEL_NUM
= 141;
382 const int ID_COMBO_SEL_STR
= 142;
383 const int ID_COMBO_CLEAR
= 143;
384 const int ID_COMBO_APPEND
= 144;
385 const int ID_COMBO_DELETE
= 145;
386 const int ID_COMBO_FONT
= 146;
387 const int ID_COMBO_ENABLE
= 147;
389 const int ID_RADIOBOX
= 160;
390 const int ID_RADIOBOX_SEL_NUM
= 161;
391 const int ID_RADIOBOX_SEL_STR
= 162;
392 const int ID_RADIOBOX_FONT
= 163;
393 const int ID_RADIOBOX_ENABLE
= 164;
395 const int ID_RADIOBUTTON_1
= 166;
396 const int ID_RADIOBUTTON_2
= 167;
398 const int ID_SET_FONT
= 170;
400 const int ID_GAUGE
= 180;
401 const int ID_SLIDER
= 181;
403 const int ID_SPIN
= 182;
404 const int ID_BTNPROGRESS
= 183;
405 const int ID_BUTTON_LABEL
= 184;
406 const int ID_SPINCTRL
= 185;
408 const int ID_BUTTON_TEST1
= 190;
409 const int ID_BUTTON_TEST2
= 191;
410 const int ID_BITMAP_BTN
= 192;
412 const int ID_CHANGE_COLOUR
= 200;
414 const int ID_SIZER_CHECK1
= 201;
415 const int ID_SIZER_CHECK2
= 202;
416 const int ID_SIZER_CHECK3
= 203;
417 const int ID_SIZER_CHECK4
= 204;
418 const int ID_SIZER_CHECK14
= 205;
419 const int ID_SIZER_CHECKBIG
= 206;
421 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
422 EVT_SIZE ( MyPanel::OnSize
)
423 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
424 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
425 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
426 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
427 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
428 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
429 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
430 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
431 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
432 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
433 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
434 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
436 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
437 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
438 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
439 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
440 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
441 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
442 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
443 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
444 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
446 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
447 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
448 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
449 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
450 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
451 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
452 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
453 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
454 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
455 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
456 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
457 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
458 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
459 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
460 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
461 EVT_RADIOBUTTON(ID_RADIOBUTTON_1
, MyPanel::OnRadioButton1
)
462 EVT_RADIOBUTTON(ID_RADIOBUTTON_2
, MyPanel::OnRadioButton2
)
463 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
464 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
466 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
467 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
468 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
469 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
470 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
471 #endif // wxUSE_SPINBTN
473 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
474 EVT_SPIN_UP (ID_SPINCTRL
, MyPanel::OnSpinCtrlUp
)
475 EVT_SPIN_DOWN (ID_SPINCTRL
, MyPanel::OnSpinCtrlDown
)
476 EVT_TEXT (ID_SPINCTRL
, MyPanel::OnSpinCtrlText
)
477 #endif // wxUSE_SPINCTRL
479 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
481 EVT_CHECKBOX(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
482 #endif // wxUSE_TOGGLEBTN
483 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
484 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
485 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
486 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
488 EVT_CHECKBOX (ID_SIZER_CHECK1
, MyPanel::OnSizerCheck
)
489 EVT_CHECKBOX (ID_SIZER_CHECK2
, MyPanel::OnSizerCheck
)
490 EVT_CHECKBOX (ID_SIZER_CHECK3
, MyPanel::OnSizerCheck
)
491 EVT_CHECKBOX (ID_SIZER_CHECK4
, MyPanel::OnSizerCheck
)
492 EVT_CHECKBOX (ID_SIZER_CHECK14
, MyPanel::OnSizerCheck
)
493 EVT_CHECKBOX (ID_SIZER_CHECKBIG
, MyPanel::OnSizerCheck
)
497 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
498 EVT_LEFT_DCLICK(MyButton::OnDClick
)
501 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
502 EVT_CHAR(MyComboBox::OnChar
)
503 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
504 EVT_KEY_UP(MyComboBox::OnKeyUp
)
506 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
509 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
510 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
511 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
514 // ============================================================================
516 // ============================================================================
518 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
519 : wxPanel( frame
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
) )
522 m_listboxSorted
= NULL
;
525 m_choiceSorted
= NULL
;
533 m_lbSelectNum
= NULL
;
534 m_lbSelectThis
= NULL
;
537 m_btnProgress
= NULL
;
538 #endif // wxUSE_SPINBTN
541 #endif // wxUSE_SPINCTRL
548 m_text
= new wxTextCtrl(this, wxID_ANY
, _T("This is the log window.\n"),
549 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
550 m_text
->SetBackgroundColour(wxT("wheat"));
552 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
554 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
569 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
572 // fill the image list
573 wxBitmap
bmp(list_xpm
);
575 wxImageList
*imagelist
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight());
577 imagelist
-> Add( bmp
);
578 imagelist
-> Add( wxBitmap( choice_xpm
));
579 imagelist
-> Add( wxBitmap( combo_xpm
));
580 imagelist
-> Add( wxBitmap( text_xpm
));
581 imagelist
-> Add( wxBitmap( radio_xpm
));
582 imagelist
-> Add( wxBitmap( gauge_xpm
));
583 m_notebook
->SetImageList(imagelist
);
584 #elif defined(__WXMSW__)
585 // load images from resources
588 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
590 wxImageList
*imagelist
= new wxImageList(16, 16, false, Image_Max
);
592 static const wxChar
*s_iconNames
[Image_Max
] =
594 _T("list"), _T("choice"), _T("combo"), _T("text"), _T("radio"),
598 for ( size_t n
= 0; n
< Image_Max
; n
++ )
600 wxBitmap
bmp(s_iconNames
[n
]);
601 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
603 wxLogWarning(wxT("Couldn't load the image '%s' for the notebook page %d."),
608 m_notebook
->SetImageList(imagelist
);
612 #define Image_List -1
613 #define Image_Choice -1
614 #define Image_Combo -1
615 #define Image_Text -1
616 #define Image_Radio -1
617 #define Image_Gauge -1
622 wxPanel
*panel
= new wxPanel(m_notebook
);
623 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
624 wxPoint(10,10), wxSize(120,70),
625 5, choices
, wxLB_ALWAYS_SB
);
626 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
627 wxPoint(10,90), wxSize(120,70),
628 5, choices
, wxLB_SORT
);
630 SetListboxClientData(wxT("listbox"), m_listbox
);
631 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
633 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
635 m_listbox
->SetToolTip( _T("This is a list box") );
636 #endif // wxUSE_TOOLTIPS
638 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
639 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
640 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
641 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
642 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
643 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
645 button
->SetDefault();
646 button
->SetForegroundColour(*wxBLUE
);
649 button
->SetToolTip( _T("Press here to set italic font") );
650 #endif // wxUSE_TOOLTIPS
652 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, _T("&Disable"), wxPoint(20,170) );
653 m_checkbox
->SetValue(false);
654 button
->MoveAfterInTabOrder(m_checkbox
);
656 m_checkbox
->SetToolTip( _T("Click here to disable the listbox") );
657 #endif // wxUSE_TOOLTIPS
658 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, _T("&Toggle colour"),
660 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
661 m_notebook
->AddPage(panel
, _T("wxListBox"), true, Image_List
);
664 panel
= new wxPanel(m_notebook
);
665 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,wxDefaultCoord
), 5, choices
);
666 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,wxDefaultCoord
),
667 5, choices
, wxCB_SORT
);
669 SetChoiceClientData(wxT("choice"), m_choice
);
670 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
672 m_choice
->SetSelection(2);
673 m_choice
->SetBackgroundColour( wxT("red") );
674 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
675 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
676 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
677 (void)new wxButton( panel
, ID_CHOICE_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
678 (void)new wxButton( panel
, ID_CHOICE_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
679 (void)new wxButton( panel
, ID_CHOICE_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
680 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
682 m_notebook
->AddPage(panel
, _T("wxChoice"), false, Image_Choice
);
683 #endif // wxUSE_CHOICE
685 panel
= new wxPanel(m_notebook
);
686 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Box around combobox"),
687 wxPoint(5, 5), wxSize(150, 100));
688 m_combo
= new MyComboBox( panel
, ID_COMBO
, _T("This"),
689 wxPoint(20,25), wxSize(120, wxDefaultCoord
),
691 wxCB_READONLY
| wxPROCESS_ENTER
);
692 m_combo
->SetBackgroundColour(*wxBLUE
);
694 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
695 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, _T("&Select 'This'"), wxPoint(340,30), wxSize(140,30) );
696 (void)new wxButton( panel
, ID_COMBO_CLEAR
, _T("&Clear"), wxPoint(180,80), wxSize(140,30) );
697 (void)new wxButton( panel
, ID_COMBO_APPEND
, _T("&Append 'Hi!'"), wxPoint(340,80), wxSize(140,30) );
698 (void)new wxButton( panel
, ID_COMBO_DELETE
, _T("D&elete selected item"), wxPoint(180,130), wxSize(140,30) );
699 (void)new wxButton( panel
, ID_COMBO_FONT
, _T("Set &Italic font"), wxPoint(340,130), wxSize(140,30) );
700 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, _T("&Disable"), wxPoint(20,130), wxSize(140,30) );
701 m_notebook
->AddPage(panel
, _T("wxComboBox"), false, Image_Combo
);
703 wxString choices2
[] =
705 _T("First"), _T("Second"),
707 "Fourth", "Fifth", "Sixth",
708 "Seventh", "Eighth", "Nineth", "Tenth" */
711 panel
= new wxPanel(m_notebook
);
712 (void)new MyRadioBox( panel
, ID_RADIOBOX
, _T("&That"), wxPoint(10,160), wxDefaultSize
, WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
713 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, _T("T&his"), wxPoint(10,10), wxDefaultSize
, WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
714 m_radio
->SetForegroundColour(*wxRED
);
717 m_combo
->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
718 m_radio
->SetToolTip(_T("Ever seen a radiobox?"));
719 #endif // wxUSE_TOOLTIPS
721 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
722 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, _T("&Select 'This'"), wxPoint(180,80), wxSize(140,30) );
723 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, _T("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) );
724 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, _T("Set &Italic font"), wxPoint(340,80), wxSize(140,30) );
725 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, _T("&Disable"), wxPoint(340,130), wxDefaultSize
);
726 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, _T("Radiobutton1"), wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
727 rb
->SetValue( false );
728 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, _T("&Radiobutton2"), wxPoint(340,170), wxDefaultSize
);
729 m_notebook
->AddPage(panel
, _T("wxRadioBox"), false, Image_Radio
);
731 panel
= new wxPanel(m_notebook
);
732 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&wxGauge and wxSlider"), wxPoint(10,10), wxSize(222,130) );
733 m_gauge
= new wxGauge( panel
, wxID_ANY
, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
734 m_gauge
->SetBackgroundColour(*wxGREEN
);
735 m_gauge
->SetForegroundColour(*wxRED
);
736 m_gaugeVert
= new wxGauge( panel
, wxID_ANY
, 100,
737 wxPoint(195,35), wxSize(30, 90),
738 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
739 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,wxDefaultCoord
),
740 wxSL_AUTOTICKS
| wxSL_LABELS
);
741 m_slider
->SetTickFreq(40, 0);
743 m_slider
->SetToolTip(_T("This is a sliding slider"));
744 #endif // wxUSE_TOOLTIPS
746 (void)new wxStaticBox( panel
, wxID_ANY
, _T("&Explanation"),
747 wxPoint(230,10), wxSize(270,130),
751 // No wrapping text in wxStaticText yet :-(
752 (void)new wxStaticText( panel
, wxID_ANY
,
753 _T("Drag the slider!"),
755 wxSize(240, wxDefaultCoord
)
758 (void)new wxStaticText( panel
, wxID_ANY
,
759 _T("In order see the gauge (aka progress bar)\n")
760 _T("control do something you have to drag the\n")
761 _T("handle of the slider to the right.\n")
763 _T("This is also supposed to demonstrate how\n")
764 _T("to use static controls.\n"),
769 int initialSpinValue
= -5;
771 s
<< initialSpinValue
;
772 m_spintext
= new wxTextCtrl( panel
, wxID_ANY
, s
, wxPoint(20,160), wxSize(80,wxDefaultCoord
) );
774 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, wxDefaultCoord
) );
775 m_spinbutton
->SetRange(-40,30);
776 m_spinbutton
->SetValue(initialSpinValue
);
778 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, _T("&Show progress dialog"),
780 #endif // wxUSE_SPINBTN
783 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord
) );
784 m_spinctrl
->SetRange(10,30);
785 m_spinctrl
->SetValue(15);
786 #endif // wxUSE_SPINCTRL
788 m_notebook
->AddPage(panel
, _T("wxGauge"), false, Image_Gauge
);
790 panel
= new wxPanel(m_notebook
);
792 #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
793 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
794 (void) new wxStaticBitmap( panel
, wxID_ANY
, icon
, wxPoint(10, 10) );
796 // VZ: don't leak memory
797 // bmpStatic = new wxStaticBitmap(panel, wxID_ANY, wxNullIcon, wxPoint(50, 10));
798 // bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
801 wxBitmap
bitmap( 100, 100 );
803 dc
.SelectObject( bitmap
);
804 dc
.SetPen(*wxGREEN_PEN
);
806 dc
.DrawEllipse(5, 5, 90, 90);
807 dc
.DrawText(_T("Bitmap"), 30, 40);
808 dc
.SelectObject( wxNullBitmap
);
810 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
812 #if defined(__WXMSW__) || defined(__WXMOTIF__)
813 // test for masked bitmap display
814 bitmap
= wxBitmap(_T("test2.bmp"), wxBITMAP_TYPE_BMP
);
817 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
819 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, wxID_ANY
, bitmap
, wxPoint(300, 120));
823 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
824 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
825 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
826 wxBitmapButton
*bmpBtn
= new wxBitmapButton
833 bmpBtn
->SetBitmapSelected(bmp2
);
834 bmpBtn
->SetBitmapFocus(bmp3
);
837 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
838 _T("&Toggle label"), wxPoint(250, 20));
840 (void)new wxCheckBox(panel
, ID_BUTTON_LABEL
,
841 _T("&Toggle label"), wxPoint(250, 20));
842 #endif // wxUSE_TOGGLEBTN
844 m_label
= new wxStaticText(panel
, wxID_ANY
, _T("Label with some long text"),
845 wxPoint(250, 60), wxDefaultSize
,
846 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
847 m_label
->SetForegroundColour( *wxBLUE
);
849 m_notebook
->AddPage(panel
, _T("wxBitmapXXX"));
853 panel
= new wxPanel(m_notebook
);
854 panel
->SetAutoLayout( true );
856 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
858 wxStaticBoxSizer
*csizer
=
859 new wxStaticBoxSizer (new wxStaticBox (panel
, wxID_ANY
, _T("Show Buttons")), wxHORIZONTAL
);
861 wxCheckBox
*check1
, *check2
, *check3
, *check4
, *check14
, *checkBig
;
862 check1
= new wxCheckBox (panel
, ID_SIZER_CHECK1
, _T("1"));
863 check1
->SetValue (true);
864 csizer
->Add (check1
);
865 check2
= new wxCheckBox (panel
, ID_SIZER_CHECK2
, _T("2"));
866 check2
->SetValue (true);
867 csizer
->Add (check2
);
868 check3
= new wxCheckBox (panel
, ID_SIZER_CHECK3
, _T("3"));
869 check3
->SetValue (true);
870 csizer
->Add (check3
);
871 check4
= new wxCheckBox (panel
, ID_SIZER_CHECK4
, _T("4"));
872 check4
->SetValue (true);
873 csizer
->Add (check4
);
874 check14
= new wxCheckBox (panel
, ID_SIZER_CHECK14
, _T("1-4"));
875 check14
->SetValue (true);
876 csizer
->Add (check14
);
877 checkBig
= new wxCheckBox (panel
, ID_SIZER_CHECKBIG
, _T("Big"));
878 checkBig
->SetValue (true);
879 csizer
->Add (checkBig
);
883 m_hsizer
= new wxBoxSizer( wxHORIZONTAL
);
885 m_buttonSizer
= new wxBoxSizer (wxVERTICAL
);
887 m_sizerBtn1
= new wxButton(panel
, wxID_ANY
, _T("Test Button &1 (tab order 1)") );
888 m_buttonSizer
->Add( m_sizerBtn1
, 0, wxALL
, 10 );
889 m_sizerBtn2
= new wxButton(panel
, wxID_ANY
, _T("Test Button &2 (tab order 3)") );
890 m_buttonSizer
->Add( m_sizerBtn2
, 0, wxALL
, 10 );
891 m_sizerBtn3
= new wxButton(panel
, wxID_ANY
, _T("Test Button &3 (tab order 2)") );
892 m_buttonSizer
->Add( m_sizerBtn3
, 0, wxALL
, 10 );
893 m_sizerBtn4
= new wxButton(panel
, wxID_ANY
, _T("Test Button &4 (tab order 4)") );
894 m_buttonSizer
->Add( m_sizerBtn4
, 0, wxALL
, 10 );
896 m_sizerBtn3
->MoveBeforeInTabOrder(m_sizerBtn2
);
898 m_hsizer
->Add (m_buttonSizer
);
899 m_hsizer
->Add( 20,20, 1 );
900 m_bigBtn
= new wxButton(panel
, wxID_ANY
, _T("Multiline\nbutton") );
901 m_hsizer
->Add( m_bigBtn
, 3, wxGROW
|wxALL
, 10 );
903 sizer
->Add (m_hsizer
, 1, wxGROW
);
905 panel
->SetSizer( sizer
);
907 m_notebook
->AddPage(panel
, _T("wxSizer"));
910 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
914 GetClientSize( &x
, &y
);
916 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
917 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
920 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
922 int selOld
= event
.GetOldSelection();
925 if ( wxMessageBox(_T("This demonstrates how a program may prevent the\n")
926 _T("page change from taking place - if you select\n")
927 _T("[No] the current page will stay the third one\n"),
928 _T("Control sample"),
929 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
937 *m_text
<< _T("Notebook selection is being changed from ") << selOld
938 << _T(" to ") << event
.GetSelection()
939 << _T(" (current page from notebook is ")
940 << m_notebook
->GetSelection() << _T(")\n");
943 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
945 *m_text
<< _T("Notebook selection is now ") << event
.GetSelection()
946 << _T(" (from notebook: ") << m_notebook
->GetSelection()
950 void MyPanel::OnTestButton(wxCommandEvent
& event
)
952 wxLogMessage(_T("Button %c clicked."),
953 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
956 void MyPanel::OnBmpButton(wxCommandEvent
& WXUNUSED(event
))
958 wxLogMessage(_T("Bitmap button clicked."));
961 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
963 static wxColour s_colOld
;
965 SetThemeEnabled(false);
966 // test panel colour changing and propagation to the subcontrols
969 SetBackgroundColour(s_colOld
);
970 s_colOld
= wxNullColour
;
972 m_lbSelectThis
->SetForegroundColour(wxNullColour
);
973 m_lbSelectThis
->SetBackgroundColour(wxNullColour
);
977 s_colOld
= wxColour(wxT("red"));
978 SetBackgroundColour(wxT("white"));
980 m_lbSelectThis
->SetForegroundColour(wxT("white"));
981 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
984 m_lbSelectThis
->Refresh();
988 void MyPanel::OnListBox( wxCommandEvent
&event
)
990 // GetParent()->Move(100, 100);
992 if (event
.GetInt() == -1)
994 m_text
->AppendText( _T("ListBox has no selections anymore\n") );
998 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
1001 m_text
->AppendText( _T("ListBox event selection string is: '") );
1002 m_text
->AppendText( event
.GetString() );
1003 m_text
->AppendText( _T("'\n") );
1004 m_text
->AppendText( _T("ListBox control selection string is: '") );
1005 m_text
->AppendText( listbox
->GetStringSelection() );
1006 m_text
->AppendText( _T("'\n") );
1008 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1009 m_text
->AppendText( _T("ListBox event client data string is: '") );
1010 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
1011 m_text
->AppendText( obj
->GetData() );
1013 m_text
->AppendText( wxString(_T("none")) );
1015 m_text
->AppendText( _T("'\n") );
1016 m_text
->AppendText( _T("ListBox control client data string is: '") );
1017 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
1019 m_text
->AppendText( obj
->GetData() );
1021 m_text
->AppendText( wxString(_T("none")) );
1022 m_text
->AppendText( _T("'\n") );
1025 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
1027 m_text
->AppendText( _T("ListBox double click string is: ") );
1028 m_text
->AppendText( event
.GetString() );
1029 m_text
->AppendText( _T("\n") );
1032 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
1034 switch (event
.GetId())
1036 case ID_LISTBOX_ENABLE
:
1038 m_text
->AppendText(_T("Checkbox clicked.\n"));
1040 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
1042 cb
->SetToolTip( _T("Click to enable listbox") );
1044 cb
->SetToolTip( _T("Click to disable listbox") );
1045 #endif // wxUSE_TOOLTIPS
1046 m_listbox
->Enable( event
.GetInt() == 0 );
1047 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
1048 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
1049 m_listboxSorted
->Enable( event
.GetInt() == 0 );
1050 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
1053 case ID_LISTBOX_SEL_NUM
:
1055 if (m_listbox
->GetCount() > 2)
1056 m_listbox
->SetSelection( 2 );
1057 if (m_listboxSorted
->GetCount() > 2)
1058 m_listboxSorted
->SetSelection( 2 );
1059 m_lbSelectThis
->WarpPointer( 40, 14 );
1062 case ID_LISTBOX_SEL_STR
:
1064 if (m_listbox
->FindString(_T("This")) != wxNOT_FOUND
)
1065 m_listbox
->SetStringSelection( _T("This") );
1066 if (m_listboxSorted
->FindString(_T("This")) != wxNOT_FOUND
)
1067 m_listboxSorted
->SetStringSelection( _T("This") );
1068 m_lbSelectNum
->WarpPointer( 40, 14 );
1071 case ID_LISTBOX_CLEAR
:
1074 m_listboxSorted
->Clear();
1077 case ID_LISTBOX_APPEND
:
1079 m_listbox
->Append( _T("Hi!") );
1080 m_listboxSorted
->Append( _T("Hi!") );
1083 case ID_LISTBOX_DELETE
:
1086 idx
= m_listbox
->GetSelection();
1087 if ( idx
!= wxNOT_FOUND
)
1088 m_listbox
->Delete( idx
);
1089 idx
= m_listboxSorted
->GetSelection();
1090 if ( idx
!= wxNOT_FOUND
)
1091 m_listboxSorted
->Delete( idx
);
1094 case ID_LISTBOX_FONT
:
1096 m_listbox
->SetFont( *wxITALIC_FONT
);
1097 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1098 m_checkbox
->SetFont( *wxITALIC_FONT
);
1105 void MyPanel::OnChoice( wxCommandEvent
&event
)
1107 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1110 m_text
->AppendText( _T("Choice event selection string is: '") );
1111 m_text
->AppendText( event
.GetString() );
1112 m_text
->AppendText( _T("'\n") );
1113 m_text
->AppendText( _T("Choice control selection string is: '") );
1114 m_text
->AppendText( choice
->GetStringSelection() );
1115 m_text
->AppendText( _T("'\n") );
1117 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1118 m_text
->AppendText( _T("Choice event client data string is: '") );
1121 m_text
->AppendText( obj
->GetData() );
1123 m_text
->AppendText( wxString(_T("none")) );
1125 m_text
->AppendText( _T("'\n") );
1126 m_text
->AppendText( _T("Choice control client data string is: '") );
1127 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1130 m_text
->AppendText( obj
->GetData() );
1132 m_text
->AppendText( wxString(_T("none")) );
1133 m_text
->AppendText( _T("'\n") );
1136 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1138 switch (event
.GetId())
1140 case ID_CHOICE_ENABLE
:
1142 m_choice
->Enable( event
.GetInt() == 0 );
1143 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1146 case ID_CHOICE_SEL_NUM
:
1148 m_choice
->SetSelection( 2 );
1149 m_choiceSorted
->SetSelection( 2 );
1152 case ID_CHOICE_SEL_STR
:
1154 m_choice
->SetStringSelection( _T("This") );
1155 m_choiceSorted
->SetStringSelection( _T("This") );
1158 case ID_CHOICE_CLEAR
:
1161 m_choiceSorted
->Clear();
1164 case ID_CHOICE_APPEND
:
1166 m_choice
->Append( _T("Hi!") );
1167 m_choiceSorted
->Append( _T("Hi!") );
1170 case ID_CHOICE_DELETE
:
1172 int idx
= m_choice
->GetSelection();
1173 if ( idx
!= wxNOT_FOUND
)
1174 m_choice
->Delete( idx
);
1175 idx
= m_choiceSorted
->GetSelection();
1176 if ( idx
!= wxNOT_FOUND
)
1177 m_choiceSorted
->Delete( idx
);
1180 case ID_CHOICE_FONT
:
1182 m_choice
->SetFont( *wxITALIC_FONT
);
1183 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1188 #endif // wxUSE_CHOICE
1190 void MyPanel::OnCombo( wxCommandEvent
&event
)
1192 m_text
->AppendText( _T("ComboBox event selection string is: ") );
1193 m_text
->AppendText( event
.GetString() );
1194 m_text
->AppendText( _T("\n") );
1195 m_text
->AppendText( _T("ComboBox control selection string is: ") );
1196 m_text
->AppendText( m_combo
->GetStringSelection() );
1197 m_text
->AppendText( _T("\n") );
1200 void MyPanel::OnComboTextChanged(wxCommandEvent
& event
)
1203 str
.Printf( wxT("Text in the combobox changed: now is '%s'."),
1204 event
.GetString().c_str() );
1205 wxLogMessage( str
.c_str() );
1208 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1210 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1211 m_combo
->GetValue().c_str());
1214 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1216 switch (event
.GetId())
1218 case ID_COMBO_ENABLE
:
1220 m_combo
->Enable( event
.GetInt() == 0 );
1223 case ID_COMBO_SEL_NUM
:
1225 m_combo
->SetSelection( 2 );
1228 case ID_COMBO_SEL_STR
:
1230 m_combo
->SetStringSelection( _T("This") );
1233 case ID_COMBO_CLEAR
:
1238 case ID_COMBO_APPEND
:
1240 m_combo
->Append( _T("Hi!") );
1243 case ID_COMBO_DELETE
:
1245 int idx
= m_combo
->GetSelection();
1246 m_combo
->Delete( idx
);
1251 m_combo
->SetFont( *wxITALIC_FONT
);
1257 void MyPanel::OnRadio( wxCommandEvent
&event
)
1259 m_text
->AppendText( _T("RadioBox selection string is: ") );
1260 m_text
->AppendText( event
.GetString() );
1261 m_text
->AppendText( _T("\n") );
1264 void MyPanel::OnRadioButton1( wxCommandEvent
& WXUNUSED(event
) )
1266 wxMessageBox(_T("First wxRadioButton selected."), _T("wxControl sample"));
1269 void MyPanel::OnRadioButton2( wxCommandEvent
& WXUNUSED(event
) )
1271 m_text
->AppendText(_T("Second wxRadioButton selected.\n"));
1274 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1276 switch (event
.GetId())
1278 case ID_RADIOBOX_ENABLE
:
1280 m_radio
->Enable( event
.GetInt() == 0 );
1283 case ID_RADIOBOX_SEL_NUM
:
1285 m_radio
->SetSelection( 2 );
1288 case ID_RADIOBOX_SEL_STR
:
1290 m_radio
->SetStringSelection( _T("This") );
1293 case ID_RADIOBOX_FONT
:
1295 m_radio
->SetForegroundColour(*wxGREEN
);
1297 m_radio
->SetFont( *wxITALIC_FONT
);
1303 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1305 m_fontButton
->SetFont( *wxITALIC_FONT
);
1306 m_text
->SetFont( *wxITALIC_FONT
);
1309 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1311 m_label
->SetLabel(event
.GetInt() ? _T("Very very very very very long text.")
1312 : _T("Shorter text."));
1315 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1317 m_gauge
->SetValue( m_slider
->GetValue() );
1318 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1323 void MyPanel::OnSpinCtrlText(wxCommandEvent
& event
)
1328 s
.Printf( _T("Spin ctrl text changed: now %d (from event: %s)\n"),
1329 m_spinctrl
->GetValue(), event
.GetString().c_str() );
1330 m_text
->AppendText(s
);
1334 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1339 s
.Printf( _T("Spin ctrl changed: now %d (from event: %ld)\n"),
1340 m_spinctrl
->GetValue(), event
.GetInt() );
1341 m_text
->AppendText(s
);
1345 void MyPanel::OnSpinCtrlUp(wxSpinEvent
& event
)
1349 m_text
->AppendText( wxString::Format(
1350 _T("Spin up: %d (from event: %ld)\n"),
1351 m_spinctrl
->GetValue(), event
.GetInt() ) );
1355 void MyPanel::OnSpinCtrlDown(wxSpinEvent
& event
)
1359 m_text
->AppendText( wxString::Format(
1360 _T("Spin down: %d (from event: %ld)\n"),
1361 m_spinctrl
->GetValue(), event
.GetInt() ) );
1365 #endif // wxUSE_SPINCTRL
1368 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1371 value
.Printf( _T("Spin control up: current = %d\n"),
1372 m_spinbutton
->GetValue());
1374 if ( event
.GetPosition() > 17 )
1376 value
+= _T("Preventing the spin button from going above 17.\n");
1381 m_text
->AppendText(value
);
1384 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1387 value
.Printf( _T("Spin control down: current = %d\n"),
1388 m_spinbutton
->GetValue());
1390 if ( event
.GetPosition() < -17 )
1392 value
+= _T("Preventing the spin button from going below -17.\n");
1397 m_text
->AppendText(value
);
1400 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1403 value
.Printf( _T("%d"), event
.GetPosition() );
1404 m_spintext
->SetValue( value
);
1406 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1407 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1408 m_spinbutton
->GetValue());
1410 m_text
->AppendText(value
);
1413 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1415 event
.Enable( m_spinbutton
->GetValue() > 0 );
1418 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1420 int max
= m_spinbutton
->GetValue();
1424 wxLogError(_T("You must set positive range!"));
1428 wxProgressDialog
dialog(_T("Progress dialog example"),
1429 _T("An informative message"),
1436 wxPD_ESTIMATED_TIME
|
1437 wxPD_REMAINING_TIME
);
1441 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1446 cont
= dialog
.Update(i
, _T("That's all, folks!"));
1448 else if ( i
== max
/ 2 )
1450 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
1454 cont
= dialog
.Update(i
);
1460 *m_text
<< _T("Progress dialog aborted!\n");
1464 *m_text
<< _T("Countdown from ") << max
<< _T(" finished.\n");
1468 #endif // wxUSE_SPINBTN
1470 void MyPanel::OnSizerCheck( wxCommandEvent
&event
)
1472 switch (event
.GetId ()) {
1473 case ID_SIZER_CHECK1
:
1474 m_buttonSizer
->Show (m_sizerBtn1
, event
.IsChecked ());
1475 m_buttonSizer
->Layout ();
1477 case ID_SIZER_CHECK2
:
1478 m_buttonSizer
->Show (m_sizerBtn2
, event
.IsChecked ());
1479 m_buttonSizer
->Layout ();
1481 case ID_SIZER_CHECK3
:
1482 m_buttonSizer
->Show (m_sizerBtn3
, event
.IsChecked ());
1483 m_buttonSizer
->Layout ();
1485 case ID_SIZER_CHECK4
:
1486 m_buttonSizer
->Show (m_sizerBtn4
, event
.IsChecked ());
1487 m_buttonSizer
->Layout ();
1489 case ID_SIZER_CHECK14
:
1490 m_hsizer
->Show (m_buttonSizer
, event
.IsChecked ());
1491 m_hsizer
->Layout ();
1493 case ID_SIZER_CHECKBIG
:
1494 m_hsizer
->Show (m_bigBtn
, event
.IsChecked ());
1495 m_hsizer
->Layout ();
1503 //wxLog::RemoveTraceMask(_T("focus"));
1504 delete wxLog::SetActiveTarget(m_logTargetOld
);
1506 delete m_notebook
->GetImageList();
1509 //----------------------------------------------------------------------
1511 //----------------------------------------------------------------------
1513 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1514 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1515 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1516 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1518 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1519 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1520 #endif // wxUSE_TOOLTIPS
1522 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1524 EVT_ICONIZE(MyFrame::OnIconized
)
1525 EVT_MAXIMIZE(MyFrame::OnMaximized
)
1526 EVT_SIZE(MyFrame::OnSize
)
1527 EVT_MOVE(MyFrame::OnMove
)
1529 EVT_IDLE(MyFrame::OnIdle
)
1532 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
)
1533 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(500, 430))
1536 // The wxICON() macros loads an icon from a resource under Windows
1537 // and uses an #included XPM image under GTK+ and Motif
1540 SetIcon( wxICON(mondrian
) );
1543 wxMenu
*file_menu
= new wxMenu
;
1545 file_menu
->Append(CONTROLS_CLEAR_LOG
, _T("&Clear log\tCtrl-L"));
1546 file_menu
->AppendSeparator();
1547 file_menu
->Append(CONTROLS_ABOUT
, _T("&About\tF1"));
1548 file_menu
->AppendSeparator();
1549 file_menu
->Append(CONTROLS_QUIT
, _T("E&xit\tAlt-X"), _T("Quit controls sample"));
1551 wxMenuBar
*menu_bar
= new wxMenuBar
;
1552 menu_bar
->Append(file_menu
, _T("&File"));
1555 wxMenu
*tooltip_menu
= new wxMenu
;
1556 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, _T("Set &delay\tCtrl-D"));
1557 tooltip_menu
->AppendSeparator();
1558 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, _T("&Toggle tooltips\tCtrl-T"),
1559 _T("enable/disable tooltips"), true);
1560 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, true);
1561 menu_bar
->Append(tooltip_menu
, _T("&Tooltips"));
1562 #endif // wxUSE_TOOLTIPS
1564 wxMenu
*panel_menu
= new wxMenu
;
1565 panel_menu
->Append(CONTROLS_ENABLE_ALL
, _T("&Disable all\tCtrl-E"),
1566 _T("Enable/disable all panel controls"), true);
1567 menu_bar
->Append(panel_menu
, _T("&Panel"));
1569 SetMenuBar(menu_bar
);
1573 #endif // wxUSE_STATUSBAR
1575 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1577 SetSizeHints( 500, 425 );
1580 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1585 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1589 wxMessageDialog
dialog(this, _T("This is a control sample"), _T("About Controls"), wxOK
);
1593 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1595 m_panel
->m_text
->Clear();
1599 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& WXUNUSED(event
))
1601 static long s_delay
= 5000;
1604 delay
.Printf( _T("%ld"), s_delay
);
1606 delay
= wxGetTextFromUser(_T("Enter delay (in milliseconds)"),
1607 _T("Set tooltip delay"),
1611 return; // cancelled
1613 wxSscanf(delay
, _T("%ld"), &s_delay
);
1615 wxToolTip::SetDelay(s_delay
);
1617 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1620 void MyFrame::OnToggleTooltips(wxCommandEvent
& WXUNUSED(event
))
1622 static bool s_enabled
= true;
1624 s_enabled
= !s_enabled
;
1626 wxToolTip::Enable(s_enabled
);
1628 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1632 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1634 static bool s_enable
= true;
1636 s_enable
= !s_enable
;
1637 m_panel
->Enable(s_enable
);
1640 void MyFrame::OnMove( wxMoveEvent
& event
)
1643 UpdateStatusBar(event
.GetPosition(), GetSize());
1644 #endif // wxUSE_STATUSBAR
1649 void MyFrame::OnIconized( wxIconizeEvent
& event
)
1651 wxLogMessage(_T("Frame %s"), event
.Iconized() ? _T("iconized")
1656 void MyFrame::OnMaximized( wxMaximizeEvent
& WXUNUSED(event
) )
1658 wxLogMessage(_T("Frame maximized"));
1661 void MyFrame::OnSize( wxSizeEvent
& event
)
1664 UpdateStatusBar(GetPosition(), event
.GetSize());
1665 #endif // wxUSE_STATUSBAR
1670 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1672 // track the window which has the focus in the status bar
1673 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1674 wxWindow
*focus
= wxWindow::FindFocus();
1675 if ( focus
&& (focus
!= s_windowFocus
) )
1677 s_windowFocus
= focus
;
1682 _T("Focus: %s, HWND = %08x"),
1686 s_windowFocus
->GetClassInfo()->GetClassName()
1688 , (unsigned int) s_windowFocus
->GetHWND()
1694 #endif // wxUSE_STATUSBAR
1698 void MyComboBox::OnChar(wxKeyEvent
& event
)
1700 wxLogMessage(_T("MyComboBox::OnChar"));
1702 if ( event
.GetKeyCode() == 'w' )
1703 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1708 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1710 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1712 if ( event
.GetKeyCode() == 'w' )
1713 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1718 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1720 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1725 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1727 size_t count
= control
->GetCount();
1728 for ( size_t n
= 0; n
< count
; n
++ )
1731 s
.Printf(wxT("%s client data for '%s'"),
1732 name
, control
->GetString(n
).c_str());
1734 control
->SetClientObject(n
, new wxStringClientData(s
));
1740 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1742 size_t count
= control
->GetCount();
1743 for ( size_t n
= 0; n
< count
; n
++ )
1746 s
.Printf(wxT("%s client data for '%s'"),
1747 name
, control
->GetString(n
).c_str());
1749 control
->SetClientObject(n
, new wxStringClientData(s
));
1753 #endif // wxUSE_CHOICE