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/notebook.h"
30 #include "wx/imaglist.h"
33 #include "wx/tooltip.h"
36 #if defined(__WXGTK__) || defined(__WXMOTIF__)
41 #include "mondrian.xpm"
42 #include "icons/choice.xpm"
43 #include "icons/combo.xpm"
44 #include "icons/list.xpm"
45 #include "icons/radio.xpm"
46 #include "icons/text.xpm"
47 #include "icons/gauge.xpm"
51 // Win16 doesn't have them
55 #define wxUSE_SPINBTN 0
58 #define wxUSE_SPINBTN 1
62 #include "wx/progdlg.h"
65 #include "wx/spinctrl.h"
66 #endif // wxUSE_SPINCTRL
68 //----------------------------------------------------------------------
70 //----------------------------------------------------------------------
72 class MyApp
: public wxApp
78 class MyPanel
: public wxPanel
81 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
84 void OnSize( wxSizeEvent
& event
);
85 void OnListBox( wxCommandEvent
&event
);
86 void OnListBoxDoubleClick( wxCommandEvent
&event
);
87 void OnListBoxButtons( wxCommandEvent
&event
);
88 void OnChoice( wxCommandEvent
&event
);
89 void OnChoiceButtons( wxCommandEvent
&event
);
90 void OnCombo( wxCommandEvent
&event
);
91 void OnComboTextChanged( wxCommandEvent
&event
);
92 void OnComboTextEnter( wxCommandEvent
&event
);
93 void OnComboButtons( wxCommandEvent
&event
);
94 void OnRadio( wxCommandEvent
&event
);
95 void OnRadioButtons( wxCommandEvent
&event
);
96 void OnSetFont( wxCommandEvent
&event
);
97 void OnPageChanged( wxNotebookEvent
&event
);
98 void OnPageChanging( wxNotebookEvent
&event
);
99 void OnSliderUpdate( wxCommandEvent
&event
);
100 void OnUpdateLabel( wxCommandEvent
&event
);
102 void OnSpinUp( wxSpinEvent
&event
);
103 void OnSpinDown( wxSpinEvent
&event
);
104 void OnSpinUpdate( wxSpinEvent
&event
);
105 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
106 void OnShowProgress( wxCommandEvent
&event
);
107 #endif // wxUSE_SPINBTN
110 void OnSpinCtrl(wxSpinEvent
& event
);
111 #endif // wxUSE_SPINCTRL
113 void OnEnableAll(wxCommandEvent
& event
);
114 void OnChangeColour(wxCommandEvent
& event
);
115 void OnTestButton(wxCommandEvent
& event
);
116 void OnBmpButton(wxCommandEvent
& event
);
118 wxListBox
*m_listbox
,
126 wxButton
*m_fontButton
;
127 wxButton
*m_lbSelectNum
;
128 wxButton
*m_lbSelectThis
;
130 wxSpinButton
*m_spinbutton
;
131 wxButton
*m_btnProgress
;
132 #endif // wxUSE_SPINBTN
135 wxSpinCtrl
*m_spinctrl
;
136 #endif // wxUSE_SPINCTRL
138 wxTextCtrl
*m_spintext
;
139 wxCheckBox
*m_checkbox
;
142 wxNotebook
*m_notebook
;
144 wxStaticText
*m_label
;
147 wxLog
*m_logTargetOld
;
149 DECLARE_EVENT_TABLE()
152 class MyFrame
: public wxFrame
155 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
157 void OnQuit(wxCommandEvent
& event
);
158 void OnAbout(wxCommandEvent
& event
);
159 void OnClearLog(wxCommandEvent
& event
);
162 void OnSetTooltipDelay(wxCommandEvent
& event
);
163 void OnToggleTooltips(wxCommandEvent
& event
);
164 #endif // wxUSE_TOOLTIPS
166 void OnEnableAll(wxCommandEvent
& event
);
168 void OnIdle( wxIdleEvent
& event
);
169 void OnSize( wxSizeEvent
& event
);
170 void OnMove( wxMoveEvent
& event
);
172 MyPanel
*GetPanel() const { return m_panel
; }
175 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
178 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
179 pos
.x
, pos
.y
, size
.x
, size
.y
);
180 SetStatusText(msg
, 1);
185 DECLARE_EVENT_TABLE()
188 // a button which intercepts double clicks (for testing...)
189 class MyButton
: public wxButton
192 MyButton(wxWindow
*parent
,
194 const wxString
& label
= wxEmptyString
,
195 const wxPoint
& pos
= wxDefaultPosition
,
196 const wxSize
& size
= wxDefaultSize
)
197 : wxButton(parent
, id
, label
, pos
, size
)
201 void OnDClick(wxMouseEvent
& event
)
203 wxLogMessage(_T("MyButton::OnDClick"));
209 DECLARE_EVENT_TABLE()
212 // a combo which intercepts chars (to test Windows behaviour)
213 class MyComboBox
: public wxComboBox
216 MyComboBox(wxWindow
*parent
, wxWindowID id
,
217 const wxString
& value
= wxEmptyString
,
218 const wxPoint
& pos
= wxDefaultPosition
,
219 const wxSize
& size
= wxDefaultSize
,
220 int n
= 0, const wxString choices
[] = NULL
,
222 const wxValidator
& validator
= wxDefaultValidator
,
223 const wxString
& name
= wxComboBoxNameStr
)
224 : wxComboBox(parent
, id
, value
, pos
, size
, n
, choices
, style
,
228 void OnChar(wxKeyEvent
& event
);
229 void OnKeyDown(wxKeyEvent
& event
);
230 void OnKeyUp(wxKeyEvent
& event
);
231 void OnFocusGot(wxFocusEvent
& event
)
233 wxLogMessage(_T("MyComboBox::OnFocusGot"));
239 DECLARE_EVENT_TABLE()
242 // a radiobox which handles focus set/kill (for testing)
243 class MyRadioBox
: public wxRadioBox
246 MyRadioBox(wxWindow
*parent
,
248 const wxString
& title
= wxEmptyString
,
249 const wxPoint
& pos
= wxDefaultPosition
,
250 const wxSize
& size
= wxDefaultSize
,
251 int n
= 0, const wxString choices
[] = NULL
,
253 long style
= wxRA_HORIZONTAL
,
254 const wxValidator
& validator
= wxDefaultValidator
,
255 const wxString
& name
= wxComboBoxNameStr
)
256 : wxRadioBox(parent
, id
, title
, pos
, size
, n
, choices
, majorDim
,
257 style
, validator
, name
) { }
260 void OnFocusGot(wxFocusEvent
& event
)
262 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
267 void OnFocusLost(wxFocusEvent
& event
)
269 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
275 DECLARE_EVENT_TABLE()
278 //----------------------------------------------------------------------
280 //----------------------------------------------------------------------
282 static void SetControlClientData(const char *name
,
283 wxControlWithItems
*control
);
287 //----------------------------------------------------------------------
289 //----------------------------------------------------------------------
299 CONTROLS_SET_TOOLTIP_DELAY
= 200,
300 CONTROLS_ENABLE_TOOLTIPS
,
308 // parse the cmd line
313 wxSscanf(argv
[1], "%d", &x
);
314 wxSscanf(argv
[2], "%d", &y
);
317 // Create the main frame window
318 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
319 "Controls wxWindows App",
322 frame
->SetSizeHints( 500, 425 );
325 // The wxICON() macros loads an icon from a resource under Windows
326 // and uses an #included XPM image under GTK+ and Motif
328 frame
->SetIcon( wxICON(mondrian
) );
330 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
332 file_menu
->Append(CONTROLS_CLEAR_LOG
, "&Clear log\tCtrl-L");
333 file_menu
->AppendSeparator();
334 file_menu
->Append(CONTROLS_ABOUT
, "&About\tF1");
335 file_menu
->AppendSeparator();
336 file_menu
->Append(CONTROLS_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
338 wxMenuBar
*menu_bar
= new wxMenuBar
;
339 menu_bar
->Append(file_menu
, "&File");
342 wxMenu
*tooltip_menu
= new wxMenu
;
343 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
344 tooltip_menu
->AppendSeparator();
345 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
346 "enable/disable tooltips", TRUE
);
347 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, TRUE
);
348 menu_bar
->Append(tooltip_menu
, "&Tooltips");
349 #endif // wxUSE_TOOLTIPS
351 wxMenu
*panel_menu
= new wxMenu
;
352 panel_menu
->Append(CONTROLS_ENABLE_ALL
, "&Disable all\tCtrl-E",
353 "Enable/disable all panel controls", TRUE
);
354 menu_bar
->Append(panel_menu
, "&Panel");
356 frame
->SetMenuBar(menu_bar
);
360 //frame->GetPanel()->m_notebook->SetSelection(6);
367 //----------------------------------------------------------------------
369 //----------------------------------------------------------------------
371 const int ID_NOTEBOOK
= 1000;
373 const int ID_LISTBOX
= 130;
374 const int ID_LISTBOX_SEL_NUM
= 131;
375 const int ID_LISTBOX_SEL_STR
= 132;
376 const int ID_LISTBOX_CLEAR
= 133;
377 const int ID_LISTBOX_APPEND
= 134;
378 const int ID_LISTBOX_DELETE
= 135;
379 const int ID_LISTBOX_FONT
= 136;
380 const int ID_LISTBOX_ENABLE
= 137;
381 const int ID_LISTBOX_SORTED
= 138;
383 const int ID_CHOICE
= 120;
384 const int ID_CHOICE_SEL_NUM
= 121;
385 const int ID_CHOICE_SEL_STR
= 122;
386 const int ID_CHOICE_CLEAR
= 123;
387 const int ID_CHOICE_APPEND
= 124;
388 const int ID_CHOICE_DELETE
= 125;
389 const int ID_CHOICE_FONT
= 126;
390 const int ID_CHOICE_ENABLE
= 127;
391 const int ID_CHOICE_SORTED
= 128;
393 const int ID_COMBO
= 140;
394 const int ID_COMBO_SEL_NUM
= 141;
395 const int ID_COMBO_SEL_STR
= 142;
396 const int ID_COMBO_CLEAR
= 143;
397 const int ID_COMBO_APPEND
= 144;
398 const int ID_COMBO_DELETE
= 145;
399 const int ID_COMBO_FONT
= 146;
400 const int ID_COMBO_ENABLE
= 147;
402 const int ID_RADIOBOX
= 160;
403 const int ID_RADIOBOX_SEL_NUM
= 161;
404 const int ID_RADIOBOX_SEL_STR
= 162;
405 const int ID_RADIOBOX_FONT
= 163;
406 const int ID_RADIOBOX_ENABLE
= 164;
408 const int ID_RADIOBUTTON_1
= 166;
409 const int ID_RADIOBUTTON_2
= 167;
411 const int ID_SET_FONT
= 170;
413 const int ID_GAUGE
= 180;
414 const int ID_SLIDER
= 181;
416 const int ID_SPIN
= 182;
417 const int ID_BTNPROGRESS
= 183;
418 const int ID_BUTTON_LABEL
= 184;
419 const int ID_SPINCTRL
= 185;
421 const int ID_BUTTON_TEST1
= 190;
422 const int ID_BUTTON_TEST2
= 191;
423 const int ID_BITMAP_BTN
= 192;
425 const int ID_CHANGE_COLOUR
= 200;
427 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
428 EVT_SIZE ( MyPanel::OnSize
)
429 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
430 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
431 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
432 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
433 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
434 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
435 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
436 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
437 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
438 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
439 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
440 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
441 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
442 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
443 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
444 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
445 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
446 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
447 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
448 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
449 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_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
466 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
468 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
469 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
470 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
471 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
472 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
473 #endif // wxUSE_SPINBTN
475 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
476 #endif // wxUSE_SPINCTRL
477 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
478 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
479 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
480 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
481 EVT_BUTTON (ID_BITMAP_BTN
, MyPanel::OnBmpButton
)
484 BEGIN_EVENT_TABLE(MyButton
, wxButton
)
485 EVT_LEFT_DCLICK(MyButton::OnDClick
)
488 BEGIN_EVENT_TABLE(MyComboBox
, wxComboBox
)
489 EVT_CHAR(MyComboBox::OnChar
)
490 EVT_KEY_DOWN(MyComboBox::OnKeyDown
)
491 EVT_KEY_UP(MyComboBox::OnKeyUp
)
493 EVT_SET_FOCUS(MyComboBox::OnFocusGot
)
496 BEGIN_EVENT_TABLE(MyRadioBox
, wxRadioBox
)
497 EVT_SET_FOCUS(MyRadioBox::OnFocusGot
)
498 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost
)
501 // ============================================================================
503 // ============================================================================
505 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
506 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
507 m_text(NULL
), m_notebook(NULL
)
509 wxLayoutConstraints
*c
;
511 m_text
= new wxTextCtrl(this, -1, "This is the log window.\n",
512 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
513 m_text
->SetBackgroundColour("wheat");
516 wxLog::AddTraceMask(_T("focus"));
517 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
519 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
534 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
537 // fill the image list
538 wxImageList
*imagelist
= new wxImageList(32, 32);
540 imagelist
-> Add( wxBitmap( list_xpm
));
541 imagelist
-> Add( wxBitmap( choice_xpm
));
542 imagelist
-> Add( wxBitmap( combo_xpm
));
543 imagelist
-> Add( wxBitmap( text_xpm
));
544 imagelist
-> Add( wxBitmap( radio_xpm
));
545 imagelist
-> Add( wxBitmap( gauge_xpm
));
546 m_notebook
->SetImageList(imagelist
);
547 #elif defined(__WXMSW__)
548 // load images from resources
551 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
553 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
555 static const char *s_iconNames
[Image_Max
] =
557 "list", "choice", "combo", "text", "radio", "gauge"
560 for ( size_t n
= 0; n
< Image_Max
; n
++ )
562 wxBitmap
bmp(s_iconNames
[n
]);
563 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
565 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
570 m_notebook
->SetImageList(imagelist
);
574 #define Image_List -1
575 #define Image_Choice -1
576 #define Image_Combo -1
577 #define Image_Text -1
578 #define Image_Radio -1
579 #define Image_Gauge -1
584 wxPanel
*panel
= new wxPanel(m_notebook
);
585 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
586 wxPoint(10,10), wxSize(120,70),
587 5, choices
, wxLB_ALWAYS_SB
);
588 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
589 wxPoint(10,90), wxSize(120,70),
590 5, choices
, wxLB_SORT
);
592 SetControlClientData("listbox", m_listbox
);
593 SetControlClientData("listbox", m_listboxSorted
);
595 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
597 m_listbox
->SetToolTip( "This is a list box" );
598 #endif // wxUSE_TOOLTIPS
600 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
601 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
602 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
603 (void)new MyButton( panel
, ID_LISTBOX_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
604 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
605 wxButton
*button
= new MyButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
607 button
->SetDefault();
609 button
->SetForegroundColour(*wxBLUE
);
612 button
->SetToolTip( "Press here to set italic font" );
613 #endif // wxUSE_TOOLTIPS
615 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
616 m_checkbox
->SetValue(FALSE
);
618 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
619 #endif // wxUSE_TOOLTIPS
620 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
622 panel
->SetCursor(wxCursor(wxCURSOR_HAND
));
623 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
625 panel
= new wxPanel(m_notebook
);
626 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
627 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
628 5, choices
, wxCB_SORT
);
630 SetControlClientData("choice", m_choice
);
631 SetControlClientData("choice", m_choiceSorted
);
633 m_choice
->SetSelection(2);
634 m_choice
->SetBackgroundColour( "red" );
635 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
636 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
637 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
638 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
639 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
640 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
641 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
643 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
645 panel
= new wxPanel(m_notebook
);
646 (void)new wxStaticBox( panel
, -1, "&Box around combobox",
647 wxPoint(5, 5), wxSize(150, 100));
648 m_combo
= new MyComboBox( panel
, ID_COMBO
, "This",
649 wxPoint(20,25), wxSize(120, -1),
651 /* wxCB_READONLY | */ wxPROCESS_ENTER
);
653 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
654 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
655 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
656 (void)new wxButton( panel
, ID_COMBO_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
657 (void)new wxButton( panel
, ID_COMBO_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
658 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
659 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
660 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
662 wxString choices2
[] =
666 "Fourth", "Fifth", "Sixth",
667 "Seventh", "Eighth", "Nineth", "Tenth" */
670 panel
= new wxPanel(m_notebook
);
671 (void)new MyRadioBox( panel
, ID_RADIOBOX
, "&That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
672 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "T&his", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
675 m_combo
->SetToolTip("This is a natural\ncombobox - can you believe me?");
676 m_radio
->SetToolTip("Ever seen a radiobox?");
677 #endif // wxUSE_TOOLTIPS
679 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
680 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "&Select 'This'", wxPoint(180,80), wxSize(140,30) );
681 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set &more Italic font", wxPoint(340,30), wxSize(140,30) );
682 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set &Italic font", wxPoint(340,80), wxSize(140,30) );
683 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "&Disable", wxPoint(340,130), wxDefaultSize
);
684 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
685 rb
->SetValue( FALSE
);
686 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "&Radiobutton2", wxPoint(340,170), wxDefaultSize
);
687 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
689 panel
= new wxPanel(m_notebook
);
690 (void)new wxStaticBox( panel
, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
691 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL
|wxNO_BORDER
);
692 m_gauge
->SetBackgroundColour(*wxGREEN
);
693 m_gauge
->SetForegroundColour(*wxRED
);
694 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
695 (void)new wxStaticBox( panel
, -1, "&Explanation", wxPoint(220,10), wxSize(270,130) );
697 // No wrapping text in wxStaticText yet :-(
698 (void)new wxStaticText( panel
, -1,
704 (void)new wxStaticText( panel
, -1,
705 "In order see the gauge (aka progress bar)\n"
706 "control do something you have to drag the\n"
707 "handle of the slider to the right.\n"
709 "This is also supposed to demonstrate how\n"
710 "to use static controls.\n",
715 int initialSpinValue
= -5;
717 s
<< initialSpinValue
;
718 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
720 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
721 m_spinbutton
->SetRange(-10,30);
722 m_spinbutton
->SetValue(initialSpinValue
);
724 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "&Show progress dialog",
726 #endif // wxUSE_SPINBTN
729 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
730 m_spinctrl
->SetRange(10,30);
731 m_spinctrl
->SetValue(15);
732 #endif // wxUSE_SPINCTRL
734 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
736 panel
= new wxPanel(m_notebook
);
738 #if !defined(__WXMOTIF__) && !defined(__WIN16__) // wxStaticBitmap not working under Motif yet; and icons not allowed under WIN16.
739 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
740 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
743 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
744 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
747 wxBitmap
bitmap( 100, 100 );
749 dc
.SelectObject( bitmap
);
750 dc
.SetPen(*wxGREEN_PEN
);
752 dc
.DrawEllipse(5, 5, 90, 90);
753 dc
.DrawText("Bitmap", 30, 40);
754 dc
.SelectObject( wxNullBitmap
);
756 (void)new wxBitmapButton(panel
, ID_BITMAP_BTN
, bitmap
, wxPoint(100, 20));
759 // test for masked bitmap display
760 bitmap
= wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP
);
763 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
765 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, -1, bitmap
, wxPoint(300, 120));
769 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
770 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
771 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
772 wxBitmapButton
*bmpBtn
= new wxBitmapButton
778 bmpBtn
->SetBitmapSelected(bmp2
);
779 bmpBtn
->SetBitmapFocus(bmp3
);
781 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "&Toggle label", wxPoint(250, 20));
782 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
783 wxPoint(250, 60), wxDefaultSize
,
784 wxALIGN_RIGHT
/*| wxST_NO_AUTORESIZE*/);
785 m_label
->SetForegroundColour( *wxBLUE
);
787 m_notebook
->AddPage(panel
, "wxBitmapXXX");
789 // layout constraints
791 panel
= new wxPanel(m_notebook
);
792 panel
->SetAutoLayout( TRUE
);
794 c
= new wxLayoutConstraints
;
795 c
->top
.SameAs( panel
, wxTop
, 10 );
797 c
->left
.SameAs( panel
, wxLeft
, 10 );
798 c
->width
.PercentOf( panel
, wxWidth
, 40 );
800 wxButton
*pMyButton
= new wxButton(panel
, ID_BUTTON_TEST1
, "Test Button &1" );
801 pMyButton
->SetConstraints( c
);
803 c
= new wxLayoutConstraints
;
804 c
->top
.SameAs( panel
, wxTop
, 10 );
805 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
806 c
->right
.SameAs( panel
, wxRight
, 10 );
807 c
->width
.PercentOf( panel
, wxWidth
, 40 );
809 wxButton
*pMyButton2
= new wxButton(panel
, ID_BUTTON_TEST2
, "Test Button &2" );
810 pMyButton2
->SetConstraints( c
);
812 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
816 panel
= new wxPanel(m_notebook
);
817 panel
->SetAutoLayout( TRUE
);
819 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
821 sizer
->Add( new wxButton(panel
, -1, "Test Button &1" ), 3, wxALL
, 10 );
822 sizer
->Add( 20,20, 1 );
823 sizer
->Add( new wxButton(panel
, -1, "Test Button &2" ), 3, wxGROW
|wxALL
, 10 );
825 panel
->SetSizer( sizer
);
827 m_notebook
->AddPage(panel
, "wxSizer");
830 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
834 GetClientSize( &x
, &y
);
836 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
837 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
840 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
842 int selOld
= event
.GetOldSelection();
845 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
846 "page change from taking place - if you select\n"
847 "[No] the current page will stay the third one\n",
849 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
857 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
860 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
862 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
865 void MyPanel::OnTestButton(wxCommandEvent
& event
)
867 wxLogMessage(_T("Button %c clicked."),
868 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
871 void MyPanel::OnBmpButton(wxCommandEvent
& event
)
873 wxLogMessage(_T("Bitmap button clicked."));
876 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
878 static wxColour s_colOld
;
880 // test panel colour changing and propagation to the subcontrols
883 SetBackgroundColour(s_colOld
);
884 s_colOld
= wxNullColour
;
886 m_lbSelectThis
->SetForegroundColour("red");
887 m_lbSelectThis
->SetBackgroundColour("white");
891 s_colOld
= wxColour("red");
892 SetBackgroundColour("white");
894 m_lbSelectThis
->SetForegroundColour("white");
895 m_lbSelectThis
->SetBackgroundColour("red");
898 m_lbSelectThis
->Refresh();
902 void MyPanel::OnListBox( wxCommandEvent
&event
)
904 // GetParent()->Move(100, 100);
906 if (event
.GetInt() == -1)
908 m_text
->AppendText( "ListBox has no selections anymore\n" );
912 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
915 m_text
->AppendText( "ListBox event selection string is: '" );
916 m_text
->AppendText( event
.GetString() );
917 m_text
->AppendText( "'\n" );
918 m_text
->AppendText( "ListBox control selection string is: '" );
919 m_text
->AppendText( listbox
->GetStringSelection() );
920 m_text
->AppendText( "'\n" );
922 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
923 m_text
->AppendText( "ListBox event client data string is: '" );
924 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
925 m_text
->AppendText( obj
->GetData() );
927 m_text
->AppendText( wxString("none") );
929 m_text
->AppendText( "'\n" );
930 m_text
->AppendText( "ListBox control client data string is: '" );
931 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
933 m_text
->AppendText( obj
->GetData() );
935 m_text
->AppendText( wxString("none") );
936 m_text
->AppendText( "'\n" );
939 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
941 m_text
->AppendText( "ListBox double click string is: " );
942 m_text
->AppendText( event
.GetString() );
943 m_text
->AppendText( "\n" );
946 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
948 switch (event
.GetId())
950 case ID_LISTBOX_ENABLE
:
952 m_text
->AppendText("Checkbox clicked.\n");
953 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
956 cb
->SetToolTip( "Click to enable listbox" );
958 cb
->SetToolTip( "Click to disable listbox" );
959 #endif // wxUSE_TOOLTIPS
960 m_listbox
->Enable( event
.GetInt() == 0 );
961 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
962 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
963 m_listboxSorted
->Enable( event
.GetInt() == 0 );
964 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
967 case ID_LISTBOX_SEL_NUM
:
969 m_listbox
->SetSelection( 2 );
970 m_listboxSorted
->SetSelection( 2 );
971 m_lbSelectThis
->WarpPointer( 40, 14 );
974 case ID_LISTBOX_SEL_STR
:
976 m_listbox
->SetStringSelection( "This" );
977 m_listboxSorted
->SetStringSelection( "This" );
978 m_lbSelectNum
->WarpPointer( 40, 14 );
981 case ID_LISTBOX_CLEAR
:
984 m_listboxSorted
->Clear();
987 case ID_LISTBOX_APPEND
:
989 m_listbox
->Append( "Hi!" );
990 m_listboxSorted
->Append( "Hi!" );
993 case ID_LISTBOX_DELETE
:
996 idx
= m_listbox
->GetSelection();
997 if ( idx
!= wxNOT_FOUND
)
998 m_listbox
->Delete( idx
);
999 idx
= m_listboxSorted
->GetSelection();
1000 if ( idx
!= wxNOT_FOUND
)
1001 m_listboxSorted
->Delete( idx
);
1004 case ID_LISTBOX_FONT
:
1006 m_listbox
->SetFont( *wxITALIC_FONT
);
1007 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
1008 m_checkbox
->SetFont( *wxITALIC_FONT
);
1014 void MyPanel::OnChoice( wxCommandEvent
&event
)
1016 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
1019 m_text
->AppendText( "Choice event selection string is: '" );
1020 m_text
->AppendText( event
.GetString() );
1021 m_text
->AppendText( "'\n" );
1022 m_text
->AppendText( "Choice control selection string is: '" );
1023 m_text
->AppendText( choice
->GetStringSelection() );
1024 m_text
->AppendText( "'\n" );
1026 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
1027 m_text
->AppendText( "Choice event client data string is: '" );
1030 m_text
->AppendText( obj
->GetData() );
1032 m_text
->AppendText( wxString("none") );
1034 m_text
->AppendText( "'\n" );
1035 m_text
->AppendText( "Choice control client data string is: '" );
1036 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
1039 m_text
->AppendText( obj
->GetData() );
1041 m_text
->AppendText( wxString("none") );
1042 m_text
->AppendText( "'\n" );
1045 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
1047 switch (event
.GetId())
1049 case ID_CHOICE_ENABLE
:
1051 m_choice
->Enable( event
.GetInt() == 0 );
1052 m_choiceSorted
->Enable( event
.GetInt() == 0 );
1055 case ID_CHOICE_SEL_NUM
:
1057 m_choice
->SetSelection( 2 );
1058 m_choiceSorted
->SetSelection( 2 );
1061 case ID_CHOICE_SEL_STR
:
1063 m_choice
->SetStringSelection( "This" );
1064 m_choiceSorted
->SetStringSelection( "This" );
1067 case ID_CHOICE_CLEAR
:
1070 m_choiceSorted
->Clear();
1073 case ID_CHOICE_APPEND
:
1075 m_choice
->Append( "Hi!" );
1076 m_choiceSorted
->Append( "Hi!" );
1079 case ID_CHOICE_DELETE
:
1081 int idx
= m_choice
->GetSelection();
1082 if ( idx
!= wxNOT_FOUND
)
1083 m_choice
->Delete( idx
);
1084 idx
= m_choiceSorted
->GetSelection();
1085 if ( idx
!= wxNOT_FOUND
)
1086 m_choiceSorted
->Delete( idx
);
1089 case ID_CHOICE_FONT
:
1091 m_choice
->SetFont( *wxITALIC_FONT
);
1092 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
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
&WXUNUSED(event
) )
1205 static bool s_long
= TRUE
;
1208 m_label
->SetLabel(s_long
? "Very very very very very long text." : "Shorter text.");
1211 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1213 m_gauge
->SetValue( m_slider
->GetValue() );
1218 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1221 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1222 m_spinctrl
->GetValue(), event
.GetInt());
1223 m_text
->AppendText(s
);
1226 #endif // wxUSE_SPINCTRL
1229 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1232 value
.Printf( _T("Spin control up: current = %d\n"),
1233 m_spinbutton
->GetValue());
1235 if ( m_spinbutton
->GetValue() > 17 )
1237 value
+= _T("Preventing the spin button from going above 17.\n");
1242 m_text
->AppendText(value
);
1245 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1248 value
.Printf( _T("Spin control down: current = %d\n"),
1249 m_spinbutton
->GetValue());
1251 if ( m_spinbutton
->GetValue() < -17 )
1253 value
+= _T("Preventing the spin button from going below -17.\n");
1258 m_text
->AppendText(value
);
1261 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1264 value
.Printf( _T("%d"), event
.GetPosition() );
1265 m_spintext
->SetValue( value
);
1267 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1268 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1269 m_spinbutton
->GetValue());
1271 m_text
->AppendText(value
);
1274 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1276 event
.Enable( m_spinbutton
->GetValue() > 0 );
1279 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1281 int max
= m_spinbutton
->GetValue();
1282 wxProgressDialog
dialog("Progress dialog example",
1283 "An informative message",
1290 wxPD_ESTIMATED_TIME
|
1291 wxPD_REMAINING_TIME
);
1295 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1300 cont
= dialog
.Update(i
, "That's all, folks!");
1302 else if ( i
== max
/ 2 )
1304 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
1308 cont
= dialog
.Update(i
);
1314 *m_text
<< "Progress dialog aborted!\n";
1318 *m_text
<< "Countdown from " << max
<< " finished.\n";
1322 #endif // wxUSE_SPINBTN
1326 //wxLog::RemoveTraceMask(_T("focus"));
1327 delete wxLog::SetActiveTarget(m_logTargetOld
);
1329 delete m_notebook
->GetImageList();
1332 //----------------------------------------------------------------------
1334 //----------------------------------------------------------------------
1336 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1337 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1338 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1339 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1341 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1342 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1343 #endif // wxUSE_TOOLTIPS
1345 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1347 EVT_SIZE(MyFrame::OnSize
)
1348 EVT_MOVE(MyFrame::OnMove
)
1350 EVT_IDLE(MyFrame::OnIdle
)
1353 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1354 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1358 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1361 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1366 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1370 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1374 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1376 m_panel
->m_text
->Clear();
1380 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1382 static long s_delay
= 5000;
1385 delay
.Printf( _T("%ld"), s_delay
);
1387 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1388 "Set tooltip delay",
1392 return; // cancelled
1394 wxSscanf(delay
, _T("%ld"), &s_delay
);
1396 wxToolTip::SetDelay(s_delay
);
1398 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1401 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1403 static bool s_enabled
= TRUE
;
1405 s_enabled
= !s_enabled
;
1407 wxToolTip::Enable(s_enabled
);
1409 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1413 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1415 static bool s_enable
= TRUE
;
1417 s_enable
= !s_enable
;
1418 m_panel
->Enable(s_enable
);
1421 void MyFrame::OnMove( wxMoveEvent
& event
)
1423 UpdateStatusBar(event
.GetPosition(), GetSize());
1428 void MyFrame::OnSize( wxSizeEvent
& event
)
1430 UpdateStatusBar(GetPosition(), event
.GetSize());
1435 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1437 // track the window which has the focus in the status bar
1438 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1439 wxWindow
*focus
= wxWindow::FindFocus();
1440 if ( focus
&& (focus
!= s_windowFocus
) )
1442 s_windowFocus
= focus
;
1447 _T("Focus: %s, HWND = %08x"),
1451 s_windowFocus
->GetClassInfo()->GetClassName()
1453 , s_windowFocus
->GetHWND()
1461 void MyComboBox::OnChar(wxKeyEvent
& event
)
1463 wxLogMessage(_T("MyComboBox::OnChar"));
1465 if ( event
.KeyCode() == 'w' )
1466 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1471 void MyComboBox::OnKeyDown(wxKeyEvent
& event
)
1473 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1475 if ( event
.KeyCode() == 'w' )
1476 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1481 void MyComboBox::OnKeyUp(wxKeyEvent
& event
)
1483 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1488 static void SetControlClientData(const char *name
,
1489 wxControlWithItems
*control
)
1491 size_t count
= control
->GetCount();
1492 for ( size_t n
= 0; n
< count
; n
++ )
1495 s
.Printf("%s client data for '%s'",
1496 name
, control
->GetString(n
).c_str());
1498 control
->SetClientObject(n
, new wxStringClientData(s
));