1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Controls wxWindows sample
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "controls.h"
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
26 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
27 #include "wx/spinbutt.h"
29 #include "wx/tglbtn.h"
30 #include "wx/notebook.h"
31 #include "wx/imaglist.h"
32 #include "wx/artprov.h"
35 #include "wx/tooltip.h"
38 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
43 #include "mondrian.xpm"
44 #include "icons/choice.xpm"
45 #include "icons/combo.xpm"
46 #include "icons/list.xpm"
47 #include "icons/radio.xpm"
48 #include "icons/text.xpm"
49 #include "icons/gauge.xpm"
53 // Win16 doesn't have them
57 #define wxUSE_SPINBTN 0
60 #define wxUSE_SPINBTN 1
64 #include "wx/progdlg.h"
67 #include "wx/spinctrl.h"
68 #endif // wxUSE_SPINCTRL
70 //----------------------------------------------------------------------
72 //----------------------------------------------------------------------
74 class MyApp
: public wxApp
80 class MyPanel
: public wxPanel
83 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
86 void OnSize( wxSizeEvent
& event
);
87 void OnListBox( wxCommandEvent
&event
);
88 void OnListBoxDoubleClick( wxCommandEvent
&event
);
89 void OnListBoxButtons( wxCommandEvent
&event
);
91 void OnChoice( wxCommandEvent
&event
);
92 void OnChoiceButtons( wxCommandEvent
&event
);
94 void OnCombo( wxCommandEvent
&event
);
95 void OnComboTextChanged( wxCommandEvent
&event
);
96 void OnComboTextEnter( wxCommandEvent
&event
);
97 void OnComboButtons( wxCommandEvent
&event
);
98 void OnRadio( wxCommandEvent
&event
);
99 void OnRadioButtons( wxCommandEvent
&event
);
100 void OnSetFont( wxCommandEvent
&event
);
101 void OnPageChanged( wxNotebookEvent
&event
);
102 void OnPageChanging( wxNotebookEvent
&event
);
103 void OnSliderUpdate( wxCommandEvent
&event
);
104 void OnUpdateLabel( wxCommandEvent
&event
);
106 void OnSpinUp( wxSpinEvent
&event
);
107 void OnSpinDown( wxSpinEvent
&event
);
108 void OnSpinUpdate( wxSpinEvent
&event
);
109 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
110 void OnShowProgress( wxCommandEvent
&event
);
111 #endif // wxUSE_SPINBTN
114 void OnSpinCtrl(wxSpinEvent
& event
);
115 #endif // wxUSE_SPINCTRL
117 void OnEnableAll(wxCommandEvent
& event
);
118 void OnChangeColour(wxCommandEvent
& event
);
119 void OnTestButton(wxCommandEvent
& event
);
120 void OnBmpButton(wxCommandEvent
& event
);
122 wxListBox
*m_listbox
,
133 wxButton
*m_fontButton
;
134 wxButton
*m_lbSelectNum
;
135 wxButton
*m_lbSelectThis
;
137 wxSpinButton
*m_spinbutton
;
138 wxButton
*m_btnProgress
;
139 #endif // wxUSE_SPINBTN
142 wxSpinCtrl
*m_spinctrl
;
143 #endif // wxUSE_SPINCTRL
145 wxTextCtrl
*m_spintext
;
146 wxCheckBox
*m_checkbox
;
149 wxNotebook
*m_notebook
;
151 wxStaticText
*m_label
;
154 wxLog
*m_logTargetOld
;
156 DECLARE_EVENT_TABLE()
159 class MyFrame
: public wxFrame
162 MyFrame(const char *title
, int x
, int y
);
164 void OnQuit(wxCommandEvent
& event
);
165 void OnAbout(wxCommandEvent
& event
);
166 void OnClearLog(wxCommandEvent
& event
);
169 void OnSetTooltipDelay(wxCommandEvent
& event
);
170 void OnToggleTooltips(wxCommandEvent
& event
);
171 #endif // wxUSE_TOOLTIPS
173 void OnEnableAll(wxCommandEvent
& event
);
175 void OnIdle( wxIdleEvent
& event
);
176 void OnSize( wxSizeEvent
& event
);
177 void OnMove( wxMoveEvent
& event
);
179 MyPanel
*GetPanel() const { return m_panel
; }
182 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
184 if ( m_frameStatusBar
)
187 wxSize sizeCl
= GetClientSize();
188 msg
.Printf(_("pos=(%d, %d), size=%dx%d (client=%dx%d)"),
192 SetStatusText(msg
, 1);
198 DECLARE_EVENT_TABLE()
201 // a button which intercepts double clicks (for testing...)
202 class MyButton
: public wxButton
205 MyButton(wxWindow
*parent
,
207 const wxString
& label
= wxEmptyString
,
208 const wxPoint
& pos
= wxDefaultPosition
,
209 const wxSize
& size
= wxDefaultSize
)
210 : wxButton(parent
, id
, label
, pos
, size
)
214 void OnDClick(wxMouseEvent
& event
)
216 wxLogMessage(_T("MyButton::OnDClick"));
222 DECLARE_EVENT_TABLE()
225 // a combo which intercepts chars (to test Windows behaviour)
226 class MyComboBox
: public wxComboBox
229 MyComboBox(wxWindow
*parent
, wxWindowID id
,
230 const wxString
& value
= wxEmptyString
,
231 const wxPoint
& pos
= wxDefaultPosition
,
232 const wxSize
& size
= wxDefaultSize
,
233 int n
= 0, const wxString choices
[] = NULL
,
235 const wxValidator
& validator
= wxDefaultValidator
,
236 const wxString
& name
= wxComboBoxNameStr
)
237 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
241 void OnChar(wxKeyEvent
& event
);
242 void OnKeyDown(wxKeyEvent
& event
);
243 void OnKeyUp(wxKeyEvent
& event
);
244 void OnFocusGot(wxFocusEvent
& event
)
246 wxLogMessage(_T("MyComboBox::OnFocusGot"));
252 DECLARE_EVENT_TABLE()
255 // a radiobox which handles focus set/kill (for testing)
256 class MyRadioBox
: public wxRadioBox
259 MyRadioBox(wxWindow
*parent
,
261 const wxString
& title
= wxEmptyString
,
262 const wxPoint
& pos
= wxDefaultPosition
,
263 const wxSize
& size
= wxDefaultSize
,
264 int n
= 0, const wxString choices
[] = NULL
,
266 long style
= wxRA_HORIZONTAL
,
267 const wxValidator
& validator
= wxDefaultValidator
,
268 const wxString
& name
= wxRadioBoxNameStr
)
269 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
270 style
, validator
, name
) { }
273 void OnFocusGot(wxFocusEvent
& event
)
275 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
280 void OnFocusLost(wxFocusEvent
& event
)
282 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
288 DECLARE_EVENT_TABLE()
291 //----------------------------------------------------------------------
293 //----------------------------------------------------------------------
295 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
);
296 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
);
300 //----------------------------------------------------------------------
302 //----------------------------------------------------------------------
312 CONTROLS_SET_TOOLTIP_DELAY
= 200,
313 CONTROLS_ENABLE_TOOLTIPS
,
321 // use standard command line handling:
322 if ( !wxApp::OnInit() )
325 // parse the cmd line
330 wxSscanf(wxString(argv
[1]), wxT("%d"), &x
);
331 wxSscanf(wxString(argv
[2]), wxT("%d"), &y
);
334 // Create the main frame window
335 MyFrame
*frame
= new MyFrame("Controls wxWindows App", x
, y
);
341 //----------------------------------------------------------------------
343 //----------------------------------------------------------------------
345 const int ID_NOTEBOOK
= 1000;
347 const int ID_LISTBOX
= 130;
348 const int ID_LISTBOX_SEL_NUM
= 131;
349 const int ID_LISTBOX_SEL_STR
= 132;
350 const int ID_LISTBOX_CLEAR
= 133;
351 const int ID_LISTBOX_APPEND
= 134;
352 const int ID_LISTBOX_DELETE
= 135;
353 const int ID_LISTBOX_FONT
= 136;
354 const int ID_LISTBOX_ENABLE
= 137;
355 const int ID_LISTBOX_SORTED
= 138;
357 const int ID_CHOICE
= 120;
358 const int ID_CHOICE_SEL_NUM
= 121;
359 const int ID_CHOICE_SEL_STR
= 122;
360 const int ID_CHOICE_CLEAR
= 123;
361 const int ID_CHOICE_APPEND
= 124;
362 const int ID_CHOICE_DELETE
= 125;
363 const int ID_CHOICE_FONT
= 126;
364 const int ID_CHOICE_ENABLE
= 127;
365 const int ID_CHOICE_SORTED
= 128;
367 const int ID_COMBO
= 140;
368 const int ID_COMBO_SEL_NUM
= 141;
369 const int ID_COMBO_SEL_STR
= 142;
370 const int ID_COMBO_CLEAR
= 143;
371 const int ID_COMBO_APPEND
= 144;
372 const int ID_COMBO_DELETE
= 145;
373 const int ID_COMBO_FONT
= 146;
374 const int ID_COMBO_ENABLE
= 147;
376 const int ID_RADIOBOX
= 160;
377 const int ID_RADIOBOX_SEL_NUM
= 161;
378 const int ID_RADIOBOX_SEL_STR
= 162;
379 const int ID_RADIOBOX_FONT
= 163;
380 const int ID_RADIOBOX_ENABLE
= 164;
382 const int ID_RADIOBUTTON_1
= 166;
383 const int ID_RADIOBUTTON_2
= 167;
385 const int ID_SET_FONT
= 170;
387 const int ID_GAUGE
= 180;
388 const int ID_SLIDER
= 181;
390 const int ID_SPIN
= 182;
391 const int ID_BTNPROGRESS
= 183;
392 const int ID_BUTTON_LABEL
= 184;
393 const int ID_SPINCTRL
= 185;
395 const int ID_BUTTON_TEST1
= 190;
396 const int ID_BUTTON_TEST2
= 191;
397 const int ID_BITMAP_BTN
= 192;
399 const int ID_CHANGE_COLOUR
= 200;
401 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
402 EVT_SIZE ( MyPanel::OnSize
)
403 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
404 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
405 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
406 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
407 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
408 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
409 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
410 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
411 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
412 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
413 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
414 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
416 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
417 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
418 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
419 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
420 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
421 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
422 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
423 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
424 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
426 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
427 EVT_TEXT (ID_COMBO
, MyPanel::OnComboTextChanged
)
428 EVT_TEXT_ENTER(ID_COMBO
, MyPanel::OnComboTextEnter
)
429 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
430 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
431 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
432 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
433 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
434 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
435 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
436 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
437 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
438 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
439 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
440 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
441 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
442 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
444 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
445 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
446 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
447 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
448 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
449 #endif // wxUSE_SPINBTN
451 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
452 #endif // wxUSE_SPINCTRL
454 EVT_TOGGLEBUTTON(ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
455 #endif // wxUSE_TOGGLEBTN
456 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
457 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
458 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
459 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
462 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
463 EVT_LEFT_DCLICK(MyButton::OnDClick
)
466 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
467 EVT_CHAR(MyComboBox::OnChar
)
468 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
469 EVT_KEY_UP(MyComboBox::OnKeyUp
)
471 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
474 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
475 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
476 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
479 // ============================================================================
481 // ============================================================================
483 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
484 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
485 m_text(NULL
), m_notebook(NULL
)
487 m_text
= new wxTextCtrl(this, -1, "This is the log window.\n",
488 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
489 m_text
->SetBackgroundColour(wxT("wheat"));
492 wxLog::AddTraceMask(_T("focus"));
493 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
495 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
510 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
513 // fill the image list
514 wxImageList
*imagelist
= new wxImageList(32, 32);
516 imagelist
-> Add( wxBitmap( list_xpm
));
517 imagelist
-> Add( wxBitmap( choice_xpm
));
518 imagelist
-> Add( wxBitmap( combo_xpm
));
519 imagelist
-> Add( wxBitmap( text_xpm
));
520 imagelist
-> Add( wxBitmap( radio_xpm
));
521 imagelist
-> Add( wxBitmap( gauge_xpm
));
522 m_notebook
->SetImageList(imagelist
);
523 #elif defined(__WXMSW__)
524 // load images from resources
527 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
529 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
531 static const char *s_iconNames
[Image_Max
] =
533 "list", "choice", "combo", "text", "radio", "gauge"
536 for ( size_t n
= 0; n
< Image_Max
; n
++ )
538 wxBitmap
bmp(s_iconNames
[n
]);
539 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
541 wxLogWarning(wxT("Couldn't load the image '%s' for the notebook page %d."),
546 m_notebook
->SetImageList(imagelist
);
550 #define Image_List -1
551 #define Image_Choice -1
552 #define Image_Combo -1
553 #define Image_Text -1
554 #define Image_Radio -1
555 #define Image_Gauge -1
560 wxPanel
*panel
= new wxPanel(m_notebook
);
561 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
562 wxPoint(10,10), wxSize(120,70),
563 5, choices
, wxLB_ALWAYS_SB
);
564 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
565 wxPoint(10,90), wxSize(120,70),
566 5, choices
, wxLB_SORT
);
568 SetListboxClientData(wxT("listbox"), m_listbox
);
569 SetListboxClientData(wxT("listbox"), m_listboxSorted
);
571 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
573 m_listbox
->SetToolTip( "This is a list box" );
574 #endif // wxUSE_TOOLTIPS
576 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
577 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
578 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
579 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
580 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
581 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
583 button
->SetDefault();
585 button
->SetForegroundColour(*wxBLUE
);
588 button
->SetToolTip( "Press here to set italic font" );
589 #endif // wxUSE_TOOLTIPS
591 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
592 m_checkbox
->SetValue(FALSE
);
594 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
595 #endif // wxUSE_TOOLTIPS
596 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
598 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
599 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
602 panel
= new wxPanel(m_notebook
);
603 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
604 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
605 5, choices
, wxCB_SORT
);
607 SetChoiceClientData(wxT("choice"), m_choice
);
608 SetChoiceClientData(wxT("choice"), m_choiceSorted
);
610 m_choice
->SetSelection(2);
611 m_choice
->SetBackgroundColour( wxT("red") );
612 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
613 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
614 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
615 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
616 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
617 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
618 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
620 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
621 #endif // wxUSE_CHOICE
623 panel
= new wxPanel(m_notebook
);
624 (void)new wxStaticBox( panel
, -1, "&Box around combobox",
625 wxPoint(5, 5), wxSize(150, 100));
626 m_combo
= new MyComboBox( panel
, ID_COMBO
, "This",
627 wxPoint(20,25), wxSize(120, -1),
629 /* wxCB_READONLY | */ wxPROCESS_ENTER
);
631 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
632 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
633 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
634 (void)new wxButton( panel
, ID_COMBO_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
635 (void)new wxButton( panel
, ID_COMBO_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
636 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
637 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
638 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
640 wxString choices2
[] =
644 "Fourth", "Fifth", "Sixth",
645 "Seventh", "Eighth", "Nineth", "Tenth" */
648 panel
= new wxPanel(m_notebook
);
649 (void)new MyRadioBox( panel
, ID_RADIOBOX
, "&That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
650 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "T&his", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
653 m_combo
->SetToolTip("This is a natural\ncombobox - can you believe me?");
654 m_radio
->SetToolTip("Ever seen a radiobox?");
655 #endif // wxUSE_TOOLTIPS
657 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
658 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "&Select 'This'", wxPoint(180,80), wxSize(140,30) );
659 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set &more Italic font", wxPoint(340,30), wxSize(140,30) );
660 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set &Italic font", wxPoint(340,80), wxSize(140,30) );
661 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "&Disable", wxPoint(340,130), wxDefaultSize
);
662 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
663 rb
->SetValue( FALSE
);
664 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "&Radiobutton2", wxPoint(340,170), wxDefaultSize
);
665 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
667 panel
= new wxPanel(m_notebook
);
668 (void)new wxStaticBox( panel
, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(222,130) );
669 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
670 m_gauge
->SetBackgroundColour(*wxGREEN
);
671 m_gauge
->SetForegroundColour(*wxRED
);
672 m_gaugeVert
= new wxGauge( panel
, -1, 100,
673 wxPoint(195,35), wxSize(30, 90),
674 wxGA_VERTICAL
| wxGA_SMOOTH
| wxNO_BORDER
);
675 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1),
676 wxSL_AUTOTICKS
| wxSL_LABELS
);
677 m_slider
->SetTickFreq(40, 0);
678 (void)new wxStaticBox( panel
, -1, "&Explanation",
679 wxPoint(230,10), wxSize(270,130),
683 // No wrapping text in wxStaticText yet :-(
684 (void)new wxStaticText( panel
, -1,
690 (void)new wxStaticText( panel
, -1,
691 "In order see the gauge (aka progress bar)\n"
692 "control do something you have to drag the\n"
693 "handle of the slider to the right.\n"
695 "This is also supposed to demonstrate how\n"
696 "to use static controls.\n",
701 int initialSpinValue
= -5;
703 s
<< initialSpinValue
;
704 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
706 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
707 m_spinbutton
->SetRange(-10,30);
708 m_spinbutton
->SetValue(initialSpinValue
);
710 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "&Show progress dialog",
712 #endif // wxUSE_SPINBTN
715 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
716 m_spinctrl
->SetRange(10,30);
717 m_spinctrl
->SetValue(15);
718 #endif // wxUSE_SPINCTRL
720 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
722 panel
= new wxPanel(m_notebook
);
724 #if !defined(__WXMOTIF__) && !defined(__WIN16__) // wxStaticBitmap not working under Motif yet; and icons not allowed under WIN16.
725 wxIcon icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
726 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
729 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
730 bmpStatic
->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION
));
733 wxBitmap
bitmap( 100, 100 );
735 dc
.SelectObject( bitmap
);
736 dc
.SetPen(*wxGREEN_PEN
);
738 dc
.DrawEllipse(5, 5, 90, 90);
739 dc
.DrawText("Bitmap", 30, 40);
740 dc
.SelectObject( wxNullBitmap
);
742 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
745 // test for masked bitmap display
746 bitmap
= wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP
);
749 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
751 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, -1, bitmap
, wxPoint(300, 120));
755 wxBitmap
bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION
)),
756 bmp2(wxArtProvider::GetBitmap(wxART_WARNING
)),
757 bmp3(wxArtProvider::GetBitmap(wxART_QUESTION
));
758 wxBitmapButton
*bmpBtn
= new wxBitmapButton
765 bmpBtn
->SetBitmapSelected(bmp2
);
766 bmpBtn
->SetBitmapFocus(bmp3
);
769 (void)new wxToggleButton(panel
, ID_BUTTON_LABEL
,
770 "&Toggle label", wxPoint(250, 20));
771 #endif // wxUSE_TOGGLEBTN
773 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
774 wxPoint(250, 60), wxDefaultSize
,
775 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
776 m_label
->SetForegroundColour( *wxBLUE
);
778 m_notebook
->AddPage(panel
, "wxBitmapXXX");
780 // layout constraints
781 #if wxUSE_CONSTRAINTS
782 wxLayoutConstraints
*c
;
784 panel
= new wxPanel(m_notebook
);
785 panel
->SetAutoLayout( TRUE
);
787 c
= new wxLayoutConstraints
;
788 c
->top
.SameAs( panel
, wxTop
, 10 );
790 c
->left
.SameAs( panel
, wxLeft
, 10 );
791 c
->width
.PercentOf( panel
, wxWidth
, 40 );
793 wxButton
*pMyButton
= new wxButton(panel
, ID_BUTTON_TEST1
, "Test Button &1" );
794 pMyButton
->SetConstraints( c
);
796 c
= new wxLayoutConstraints
;
797 c
->top
.SameAs( panel
, wxTop
, 10 );
798 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
799 c
->right
.SameAs( panel
, wxRight
, 10 );
800 c
->width
.PercentOf( panel
, wxWidth
, 40 );
802 wxButton
*pMyButton2
= new wxButton(panel
, ID_BUTTON_TEST2
, "Test Button &2" );
803 pMyButton2
->SetConstraints( c
);
805 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
810 panel
= new wxPanel(m_notebook
);
811 panel
->SetAutoLayout( TRUE
);
813 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
815 sizer
->Add( new wxButton(panel
, -1, "Test Button &1" ), 3, wxALL
, 10 );
816 sizer
->Add( 20,20, 1 );
817 sizer
->Add( new wxButton(panel
, -1, "Test Button &2" ), 3, wxGROW
|wxALL
, 10 );
819 panel
->SetSizer( sizer
);
821 m_notebook
->AddPage(panel
, "wxSizer");
824 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
828 GetClientSize( &x
, &y
);
830 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
831 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
834 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
836 int selOld
= event
.GetOldSelection();
839 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
840 "page change from taking place - if you select\n"
841 "[No] the current page will stay the third one\n",
843 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
851 *m_text
<< "Notebook selection is being changed from " << selOld
852 << " to " << event
.GetSelection()
853 << " (current page from notebook is "
854 << m_notebook
->GetSelection() << ")\n";
857 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
859 *m_text
<< "Notebook selection is now " << event
.GetSelection()
860 << " (from notebook: " << m_notebook
->GetSelection() << ")\n";
863 void MyPanel::OnTestButton(wxCommandEvent
& event
)
865 wxLogMessage(_T("Button %c clicked."),
866 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
869 void MyPanel::OnBmpButton(wxCommandEvent
& event
)
871 wxLogMessage(_T("Bitmap button clicked."));
874 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
876 static wxColour s_colOld
;
878 // test panel colour changing and propagation to the subcontrols
881 SetBackgroundColour(s_colOld
);
882 s_colOld
= wxNullColour
;
884 m_lbSelectThis
->SetForegroundColour(wxT("red"));
885 m_lbSelectThis
->SetBackgroundColour(wxT("white"));
889 s_colOld
= wxColour(wxT("red"));
890 SetBackgroundColour(wxT("white"));
892 m_lbSelectThis
->SetForegroundColour(wxT("white"));
893 m_lbSelectThis
->SetBackgroundColour(wxT("red"));
896 m_lbSelectThis
->Refresh();
900 void MyPanel::OnListBox( wxCommandEvent
&event
)
902 // GetParent()->Move(100, 100);
904 if (event
.GetInt() == -1)
906 m_text
->AppendText( "ListBox has no selections anymore\n" );
910 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
913 m_text
->AppendText( "ListBox event selection string is: '" );
914 m_text
->AppendText( event
.GetString() );
915 m_text
->AppendText( "'\n" );
916 m_text
->AppendText( "ListBox control selection string is: '" );
917 m_text
->AppendText( listbox
->GetStringSelection() );
918 m_text
->AppendText( "'\n" );
920 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
921 m_text
->AppendText( "ListBox event client data string is: '" );
922 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
923 m_text
->AppendText( obj
->GetData() );
925 m_text
->AppendText( wxString("none") );
927 m_text
->AppendText( "'\n" );
928 m_text
->AppendText( "ListBox control client data string is: '" );
929 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
931 m_text
->AppendText( obj
->GetData() );
933 m_text
->AppendText( wxString("none") );
934 m_text
->AppendText( "'\n" );
937 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
939 m_text
->AppendText( "ListBox double click string is: " );
940 m_text
->AppendText( event
.GetString() );
941 m_text
->AppendText( "\n" );
944 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
946 switch (event
.GetId())
948 case ID_LISTBOX_ENABLE
:
950 m_text
->AppendText("Checkbox clicked.\n");
952 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
954 cb
->SetToolTip( "Click to enable listbox" );
956 cb
->SetToolTip( "Click to disable listbox" );
957 #endif // wxUSE_TOOLTIPS
958 m_listbox
->Enable( event
.GetInt() == 0 );
959 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
960 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
961 m_listboxSorted
->Enable( event
.GetInt() == 0 );
962 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
965 case ID_LISTBOX_SEL_NUM
:
967 m_listbox
->SetSelection( 2 );
968 m_listboxSorted
->SetSelection( 2 );
969 m_lbSelectThis
->WarpPointer( 40, 14 );
972 case ID_LISTBOX_SEL_STR
:
974 m_listbox
->SetStringSelection( "This" );
975 m_listboxSorted
->SetStringSelection( "This" );
976 m_lbSelectNum
->WarpPointer( 40, 14 );
979 case ID_LISTBOX_CLEAR
:
982 m_listboxSorted
->Clear();
985 case ID_LISTBOX_APPEND
:
987 m_listbox
->Append( "Hi!" );
988 m_listboxSorted
->Append( "Hi!" );
991 case ID_LISTBOX_DELETE
:
994 idx
= m_listbox
->GetSelection();
995 if ( idx
!= wxNOT_FOUND
)
996 m_listbox
->Delete( idx
);
997 idx
= m_listboxSorted
->GetSelection();
998 if ( idx
!= wxNOT_FOUND
)
999 m_listboxSorted
->Delete( idx
);
1002 case ID_LISTBOX_FONT
:
1004 m_listbox
->SetFont( *wxITALIC_FONT
);
1005 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1006 m_checkbox
->SetFont( *wxITALIC_FONT
);
1013 void MyPanel::OnChoice( wxCommandEvent
&event
)
1015 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1018 m_text
->AppendText( "Choice event selection string is: '" );
1019 m_text
->AppendText( event
.GetString() );
1020 m_text
->AppendText( "'\n" );
1021 m_text
->AppendText( "Choice control selection string is: '" );
1022 m_text
->AppendText( choice
->GetStringSelection() );
1023 m_text
->AppendText( "'\n" );
1025 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1026 m_text
->AppendText( "Choice event client data string is: '" );
1029 m_text
->AppendText( obj
->GetData() );
1031 m_text
->AppendText( wxString("none") );
1033 m_text
->AppendText( "'\n" );
1034 m_text
->AppendText( "Choice control client data string is: '" );
1035 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1038 m_text
->AppendText( obj
->GetData() );
1040 m_text
->AppendText( wxString("none") );
1041 m_text
->AppendText( "'\n" );
1044 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1046 switch (event
.GetId())
1048 case ID_CHOICE_ENABLE
:
1050 m_choice
->Enable( event
.GetInt() == 0 );
1051 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1054 case ID_CHOICE_SEL_NUM
:
1056 m_choice
->SetSelection( 2 );
1057 m_choiceSorted
->SetSelection( 2 );
1060 case ID_CHOICE_SEL_STR
:
1062 m_choice
->SetStringSelection( "This" );
1063 m_choiceSorted
->SetStringSelection( "This" );
1066 case ID_CHOICE_CLEAR
:
1069 m_choiceSorted
->Clear();
1072 case ID_CHOICE_APPEND
:
1074 m_choice
->Append( "Hi!" );
1075 m_choiceSorted
->Append( "Hi!" );
1078 case ID_CHOICE_DELETE
:
1080 int idx
= m_choice
->GetSelection();
1081 if ( idx
!= wxNOT_FOUND
)
1082 m_choice
->Delete( idx
);
1083 idx
= m_choiceSorted
->GetSelection();
1084 if ( idx
!= wxNOT_FOUND
)
1085 m_choiceSorted
->Delete( idx
);
1088 case ID_CHOICE_FONT
:
1090 m_choice
->SetFont( *wxITALIC_FONT
);
1091 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
1096 #endif // wxUSE_CHOICE
1098 void MyPanel::OnCombo( wxCommandEvent
&event
)
1100 m_text
->AppendText( "ComboBox event selection string is: " );
1101 m_text
->AppendText( event
.GetString() );
1102 m_text
->AppendText( "\n" );
1103 m_text
->AppendText( "ComboBox control selection string is: " );
1104 m_text
->AppendText( m_combo
->GetStringSelection() );
1105 m_text
->AppendText( "\n" );
1108 void MyPanel::OnComboTextChanged(wxCommandEvent
& WXUNUSED(event
))
1110 wxLogMessage(_T("Text in the combobox changed: now is '%s'."),
1111 m_combo
->GetValue().c_str());
1114 void MyPanel::OnComboTextEnter(wxCommandEvent
& WXUNUSED(event
))
1116 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1117 m_combo
->GetValue().c_str());
1120 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1122 switch (event
.GetId())
1124 case ID_COMBO_ENABLE
:
1126 m_combo
->Enable( event
.GetInt() == 0 );
1129 case ID_COMBO_SEL_NUM
:
1131 m_combo
->SetSelection( 2 );
1134 case ID_COMBO_SEL_STR
:
1136 m_combo
->SetStringSelection( "This" );
1139 case ID_COMBO_CLEAR
:
1144 case ID_COMBO_APPEND
:
1146 m_combo
->Append( "Hi!" );
1149 case ID_COMBO_DELETE
:
1151 int idx
= m_combo
->GetSelection();
1152 m_combo
->Delete( idx
);
1157 m_combo
->SetFont( *wxITALIC_FONT
);
1163 void MyPanel::OnRadio( wxCommandEvent
&event
)
1165 m_text
->AppendText( "RadioBox selection string is: " );
1166 m_text
->AppendText( event
.GetString() );
1167 m_text
->AppendText( "\n" );
1170 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1172 switch (event
.GetId())
1174 case ID_RADIOBOX_ENABLE
:
1176 m_radio
->Enable( event
.GetInt() == 0 );
1179 case ID_RADIOBOX_SEL_NUM
:
1181 m_radio
->SetSelection( 2 );
1184 case ID_RADIOBOX_SEL_STR
:
1186 m_radio
->SetStringSelection( "This" );
1189 case ID_RADIOBOX_FONT
:
1191 m_radio
->SetFont( *wxITALIC_FONT
);
1197 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1199 m_fontButton
->SetFont( *wxITALIC_FONT
);
1200 m_text
->SetFont( *wxITALIC_FONT
);
1203 void MyPanel::OnUpdateLabel( wxCommandEvent
&event
)
1205 m_label
->SetLabel(event
.GetInt() ? "Very very very very very long text."
1209 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1211 m_gauge
->SetValue( m_slider
->GetValue() );
1212 m_gaugeVert
->SetValue( m_slider
->GetValue() / 2 );
1217 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1220 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1221 m_spinctrl
->GetValue(), event
.GetInt());
1222 m_text
->AppendText(s
);
1225 #endif // wxUSE_SPINCTRL
1228 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1231 value
.Printf( _T("Spin control up: current = %d\n"),
1232 m_spinbutton
->GetValue());
1234 if ( m_spinbutton
->GetValue() > 17 )
1236 value
+= _T("Preventing the spin button from going above 17.\n");
1241 m_text
->AppendText(value
);
1244 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1247 value
.Printf( _T("Spin control down: current = %d\n"),
1248 m_spinbutton
->GetValue());
1250 if ( m_spinbutton
->GetValue() < -17 )
1252 value
+= _T("Preventing the spin button from going below -17.\n");
1257 m_text
->AppendText(value
);
1260 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1263 value
.Printf( _T("%d"), event
.GetPosition() );
1264 m_spintext
->SetValue( value
);
1266 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1267 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1268 m_spinbutton
->GetValue());
1270 m_text
->AppendText(value
);
1273 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1275 event
.Enable( m_spinbutton
->GetValue() > 0 );
1278 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1280 int max
= m_spinbutton
->GetValue();
1284 wxLogError(_T("You must set positive range!"));
1288 wxProgressDialog
dialog("Progress dialog example",
1289 "An informative message",
1296 wxPD_ESTIMATED_TIME
|
1297 wxPD_REMAINING_TIME
);
1301 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1306 cont
= dialog
.Update(i
, "That's all, folks!");
1308 else if ( i
== max
/ 2 )
1310 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
1314 cont
= dialog
.Update(i
);
1320 *m_text
<< "Progress dialog aborted!\n";
1324 *m_text
<< "Countdown from " << max
<< " finished.\n";
1328 #endif // wxUSE_SPINBTN
1332 //wxLog::RemoveTraceMask(_T("focus"));
1333 delete wxLog::SetActiveTarget(m_logTargetOld
);
1335 delete m_notebook
->GetImageList();
1338 //----------------------------------------------------------------------
1340 //----------------------------------------------------------------------
1342 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1343 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1344 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1345 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1347 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1348 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1349 #endif // wxUSE_TOOLTIPS
1351 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1353 EVT_SIZE(MyFrame::OnSize
)
1354 EVT_MOVE(MyFrame::OnMove
)
1356 EVT_IDLE(MyFrame::OnIdle
)
1359 MyFrame::MyFrame(const char *title
, int x
, int y
)
1360 : wxFrame(NULL
, -1, title
, wxPoint(x
, y
), wxSize(500, 430))
1363 // The wxICON() macros loads an icon from a resource under Windows
1364 // and uses an #included XPM image under GTK+ and Motif
1366 SetIcon( wxICON(mondrian
) );
1368 wxMenu
*file_menu
= new wxMenu
;
1370 file_menu
->Append(CONTROLS_CLEAR_LOG
, "&Clear log\tCtrl-L");
1371 file_menu
->AppendSeparator();
1372 file_menu
->Append(CONTROLS_ABOUT
, "&About\tF1");
1373 file_menu
->AppendSeparator();
1374 file_menu
->Append(CONTROLS_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
1376 wxMenuBar
*menu_bar
= new wxMenuBar
;
1377 menu_bar
->Append(file_menu
, "&File");
1380 wxMenu
*tooltip_menu
= new wxMenu
;
1381 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
1382 tooltip_menu
->AppendSeparator();
1383 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
1384 "enable/disable tooltips", TRUE
);
1385 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, TRUE
);
1386 menu_bar
->Append(tooltip_menu
, "&Tooltips");
1387 #endif // wxUSE_TOOLTIPS
1389 wxMenu
*panel_menu
= new wxMenu
;
1390 panel_menu
->Append(CONTROLS_ENABLE_ALL
, "&Disable all\tCtrl-E",
1391 "Enable/disable all panel controls", TRUE
);
1392 menu_bar
->Append(panel_menu
, "&Panel");
1394 SetMenuBar(menu_bar
);
1398 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1400 SetSizeHints( 500, 425 );
1403 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1408 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1412 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1416 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1418 m_panel
->m_text
->Clear();
1422 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1424 static long s_delay
= 5000;
1427 delay
.Printf( _T("%ld"), s_delay
);
1429 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1430 "Set tooltip delay",
1434 return; // cancelled
1436 wxSscanf(delay
, _T("%ld"), &s_delay
);
1438 wxToolTip::SetDelay(s_delay
);
1440 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1443 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1445 static bool s_enabled
= TRUE
;
1447 s_enabled
= !s_enabled
;
1449 wxToolTip::Enable(s_enabled
);
1451 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1455 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1457 static bool s_enable
= TRUE
;
1459 s_enable
= !s_enable
;
1460 m_panel
->Enable(s_enable
);
1463 void MyFrame::OnMove( wxMoveEvent
& event
)
1465 UpdateStatusBar(event
.GetPosition(), GetSize());
1470 void MyFrame::OnSize( wxSizeEvent
& event
)
1472 UpdateStatusBar(GetPosition(), event
.GetSize());
1477 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1479 // track the window which has the focus in the status bar
1480 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1481 wxWindow
*focus
= wxWindow::FindFocus();
1482 if ( focus
&& (focus
!= s_windowFocus
) )
1484 s_windowFocus
= focus
;
1489 _T("Focus: %s, HWND = %08x"),
1493 s_windowFocus
->GetClassInfo()->GetClassName()
1495 , s_windowFocus
->GetHWND()
1503 void MyComboBox::OnChar(wxKeyEvent
& event
)
1505 wxLogMessage(_T("MyComboBox::OnChar"));
1507 if ( event
.KeyCode() == 'w' )
1508 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1513 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1515 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1517 if ( event
.KeyCode() == 'w' )
1518 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1523 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1525 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1530 static void SetListboxClientData(const wxChar
*name
, wxListBox
*control
)
1532 size_t count
= control
->GetCount();
1533 for ( size_t n
= 0; n
< count
; n
++ )
1536 s
.Printf(wxT("%s client data for '%s'"),
1537 name
, control
->GetString(n
).c_str());
1539 control
->SetClientObject(n
, new wxStringClientData(s
));
1543 static void SetChoiceClientData(const wxChar
*name
, wxChoice
*control
)
1545 size_t count
= control
->GetCount();
1546 for ( size_t n
= 0; n
< count
; n
++ )
1549 s
.Printf(wxT("%s client data for '%s'"),
1550 name
, control
->GetString(n
).c_str());
1552 control
->SetClientObject(n
, new wxStringClientData(s
));