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 #include "wx/spinbutt.h"
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
31 #include "wx/tooltip.h"
34 #if defined(__WXGTK__) || defined(__WXMOTIF__)
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 // Win16 doesn't have them
50 #undef wxUSE_SPINBUTTON
51 #define wxUSE_SPINBUTTON 0
54 #include "wx/progdlg.h"
56 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
60 class MyApp
: public wxApp
66 class MyPanel
: public wxPanel
69 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
72 void OnSize( wxSizeEvent
& event
);
73 void OnListBox( wxCommandEvent
&event
);
74 void OnListBoxDoubleClick( wxCommandEvent
&event
);
75 void OnListBoxButtons( wxCommandEvent
&event
);
76 void OnChoice( wxCommandEvent
&event
);
77 void OnChoiceButtons( wxCommandEvent
&event
);
78 void OnCombo( wxCommandEvent
&event
);
79 void OnComboButtons( wxCommandEvent
&event
);
80 void OnRadio( wxCommandEvent
&event
);
81 void OnRadioButtons( wxCommandEvent
&event
);
82 void OnSetFont( wxCommandEvent
&event
);
83 void OnPageChanged( wxNotebookEvent
&event
);
84 void OnPageChanging( wxNotebookEvent
&event
);
85 void OnSliderUpdate( wxCommandEvent
&event
);
86 #ifndef wxUSE_SPINBUTTON
87 void OnSpinUpdate( wxSpinEvent
&event
);
88 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
89 void OnShowProgress( wxCommandEvent
&event
);
90 #endif // wxUSE_SPINBUTTON
98 wxButton
*m_fontButton
;
99 wxButton
*m_lbSelectNum
;
100 wxButton
*m_lbSelectThis
;
101 #ifndef wxUSE_SPINBUTTON
102 wxSpinButton
*m_spinbutton
;
103 wxButton
*m_btnProgress
;
105 wxTextCtrl
*m_spintext
;
106 wxCheckBox
*m_checkbox
;
109 wxNotebook
*m_notebook
;
112 DECLARE_EVENT_TABLE()
115 class MyFrame
: public wxFrame
118 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
120 void OnQuit(wxCommandEvent
& event
);
121 void OnAbout(wxCommandEvent
& event
);
123 void OnSetTooltipDelay(wxCommandEvent
& event
);
124 void OnToggleTooltips(wxCommandEvent
& event
);
125 #endif // wxUSE_TOOLTIPS
126 void OnIdle( wxIdleEvent
& event
);
127 void OnSize( wxSizeEvent
& event
);
130 DECLARE_EVENT_TABLE()
133 //----------------------------------------------------------------------
135 //----------------------------------------------------------------------
139 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
150 MINIMAL_SET_TOOLTIP_DELAY
= 200,
151 MINIMAL_ENABLE_TOOLTIPS
156 // Create the main frame window
157 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
158 "Controls wxWindows App",
162 // The wxICON() macros loads an icon from a resource under Windows
163 // and uses an #included XPM image under GTK+ and Motif
165 frame
->SetIcon( wxICON(mondrian
) );
167 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
168 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
169 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
171 wxMenuBar
*menu_bar
= new wxMenuBar
;
172 menu_bar
->Append(file_menu
, "&File");
175 wxMenu
*tooltip_menu
= new wxMenu
;
176 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
177 tooltip_menu
->AppendSeparator();
178 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
179 "enable/disable tooltips", TRUE
);
180 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
181 menu_bar
->Append(tooltip_menu
, "&Tooltips");
182 #endif // wxUSE_TOOLTIPS
184 frame
->SetMenuBar(menu_bar
);
187 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
194 //----------------------------------------------------------------------
196 //----------------------------------------------------------------------
198 const int ID_NOTEBOOK
= 1000;
200 const int ID_LISTBOX
= 130;
201 const int ID_LISTBOX_SEL_NUM
= 131;
202 const int ID_LISTBOX_SEL_STR
= 132;
203 const int ID_LISTBOX_CLEAR
= 133;
204 const int ID_LISTBOX_APPEND
= 134;
205 const int ID_LISTBOX_DELETE
= 135;
206 const int ID_LISTBOX_FONT
= 136;
207 const int ID_LISTBOX_ENABLE
= 137;
209 const int ID_CHOICE
= 120;
210 const int ID_CHOICE_SEL_NUM
= 121;
211 const int ID_CHOICE_SEL_STR
= 122;
212 const int ID_CHOICE_CLEAR
= 123;
213 const int ID_CHOICE_APPEND
= 124;
214 const int ID_CHOICE_DELETE
= 125;
215 const int ID_CHOICE_FONT
= 126;
216 const int ID_CHOICE_ENABLE
= 127;
218 const int ID_COMBO
= 140;
219 const int ID_COMBO_SEL_NUM
= 141;
220 const int ID_COMBO_SEL_STR
= 142;
221 const int ID_COMBO_CLEAR
= 143;
222 const int ID_COMBO_APPEND
= 144;
223 const int ID_COMBO_DELETE
= 145;
224 const int ID_COMBO_FONT
= 146;
225 const int ID_COMBO_ENABLE
= 147;
227 const int ID_RADIOBOX
= 160;
228 const int ID_RADIOBOX_SEL_NUM
= 161;
229 const int ID_RADIOBOX_SEL_STR
= 162;
230 const int ID_RADIOBOX_FONT
= 163;
231 const int ID_RADIOBOX_ENABLE
= 164;
233 const int ID_RADIOBUTTON_1
= 166;
234 const int ID_RADIOBUTTON_2
= 167;
236 const int ID_SET_FONT
= 170;
238 const int ID_GAUGE
= 180;
239 const int ID_SLIDER
= 181;
241 const int ID_SPIN
= 182;
242 const int ID_BTNPROGRESS
= 183;
244 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
245 EVT_SIZE ( MyPanel::OnSize
)
246 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
247 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
248 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
249 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
250 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
251 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
252 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
253 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
254 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
255 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
256 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
257 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
258 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
259 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
260 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
261 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
262 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
263 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
264 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
265 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
266 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
267 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
268 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
269 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
270 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
271 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
272 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
273 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
274 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
275 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
276 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
277 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
278 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
279 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
280 #ifndef wxUSE_SPINBUTTON
281 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
282 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
283 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
287 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
288 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
289 m_text(NULL
), m_notebook(NULL
)
291 // SetBackgroundColour("cadet blue");
293 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
294 // m_text->SetBackgroundColour("wheat");
296 delete wxLog::SetActiveTarget(new wxLogStderr
);
298 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
313 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
316 // fill the image list
317 wxImageList
*imagelist
= new wxImageList(32, 32);
319 imagelist
-> Add( wxBitmap( list_xpm
));
320 imagelist
-> Add( wxBitmap( choice_xpm
));
321 imagelist
-> Add( wxBitmap( combo_xpm
));
322 imagelist
-> Add( wxBitmap( text_xpm
));
323 imagelist
-> Add( wxBitmap( radio_xpm
));
324 imagelist
-> Add( wxBitmap( gauge_xpm
));
325 m_notebook
->SetImageList(imagelist
);
326 #elif defined(__WXMSW__)
327 // load images from resources
330 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
332 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
334 static const char *s_iconNames
[Image_Max
] =
336 "list", "choice", "combo", "text", "radio", "gauge"
339 for ( size_t n
= 0; n
< Image_Max
; n
++ )
341 wxBitmap
bmp(s_iconNames
[n
]);
342 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
344 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
349 m_notebook
->SetImageList(imagelist
);
353 #define Image_List -1
354 #define Image_Choice -1
355 #define Image_Combo -1
356 #define Image_Text -1
357 #define Image_Radio -1
358 #define Image_Gauge -1
363 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
364 wxPanel
*panel
= (wxPanel
*) NULL
;
366 panel
= new wxPanel(m_notebook
);
367 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
368 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
370 m_listbox
->SetToolTip( "This is a list box" );
371 #endif // wxUSE_TOOLTIPS
373 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
374 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
375 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
376 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
377 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
378 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
380 button
->SetToolTip( "Press here to set italic font" );
381 #endif // wxUSE_TOOLTIPS
383 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT
);
384 m_checkbox
->SetValue(FALSE
);
386 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
387 #endif // wxUSE_TOOLTIPS
388 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
390 panel
= new wxPanel(m_notebook
);
391 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
392 m_choice
->SetBackgroundColour( "red" );
393 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
394 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
395 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
396 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
397 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
398 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
399 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
402 wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
403 wxSize sizeIcon = wxSize(icon.GetWidth(), icon.GetHeight());
404 (void)new wxStaticBitmap( panel, -1, icon, wxPoint(50, 60), sizeIcon);
405 wxStaticBitmap *bitmap = new wxStaticBitmap( panel, -1, wxNullBitmap, wxPoint(10, 60), sizeIcon);
406 bitmap->SetBitmap(icon);
408 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
409 (void)new wxStaticBitmap( panel
, -1, icon
, wxPoint(50, 60) );
410 wxStaticBitmap
*bitmap
= new wxStaticBitmap( panel
, -1, wxNullBitmap
, wxPoint(10, 60) );
411 bitmap
->SetBitmap(icon
);
413 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
415 panel
= new wxPanel(m_notebook
);
416 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
417 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
418 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
419 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
420 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
421 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
422 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
423 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
424 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
426 wxString choices2
[] =
430 "Fourth", "Fifth", "Sixth",
431 "Seventh", "Eighth", "Nineth", "Tenth" */
434 panel
= new wxPanel(m_notebook
);
435 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
436 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
437 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
438 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
439 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
440 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
441 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
442 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
443 rb
->SetValue( FALSE
);
444 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
445 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
447 panel
= new wxPanel(m_notebook
);
448 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
449 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
450 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
451 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
453 // No wrapping text in wxStaticText yet :-(
454 (void)new wxStaticText( panel
, -1,
460 (void)new wxStaticText( panel
, -1,
461 "In order see the gauge (aka progress bar)\n"
462 "control do something you have to drag the\n"
463 "handle of the slider to the right.\n"
465 "This is also supposed to demonstrate how\n"
466 "to use static controls.\n",
471 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
472 #ifndef wxUSE_SPINBUTTON
473 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
474 m_spinbutton
->SetRange(-10,30);
475 m_spinbutton
->SetValue(-5);
477 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
480 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
483 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
487 GetClientSize( &x
, &y
);
489 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
490 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
493 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
495 int selNew
= event
.GetSelection(),
496 selOld
= event
.GetOldSelection();
497 if ( selOld
== 2 && selNew
== 4 )
499 wxMessageBox("This demonstrates how a program may prevent the "
500 "page change from taking place - \n the current page will "
501 "stay the third one", "Control sample",
502 wxICON_INFORMATION
| wxOK
);
508 *m_text
<< "Notebook selection is being changed from "
509 << selOld
<< " to " << selNew
<< "\n";
513 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
515 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
518 void MyPanel::OnListBox( wxCommandEvent
&event
)
520 m_text
->AppendText( "ListBox event selection string is: " );
521 m_text
->AppendText( event
.GetString() );
522 m_text
->AppendText( "\n" );
523 m_text
->AppendText( "ListBox control selection string is: " );
524 m_text
->AppendText( m_listbox
->GetStringSelection() );
525 m_text
->AppendText( "\n" );
528 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
530 m_text
->AppendText( "ListBox double click string is: " );
531 m_text
->AppendText( event
.GetString() );
532 m_text
->AppendText( "\n" );
535 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
537 switch (event
.GetId())
539 case ID_LISTBOX_ENABLE
:
541 m_text
->AppendText("Checkbox clicked.\n");
542 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
545 cb
->SetToolTip( "Click to enable listbox" );
547 cb
->SetToolTip( "Click to disable listbox" );
548 #endif // wxUSE_TOOLTIPS
549 m_listbox
->Enable( event
.GetInt() == 0 );
552 case ID_LISTBOX_SEL_NUM
:
554 m_listbox
->SetSelection( 2 );
555 m_lbSelectThis
->WarpPointer( 40, 14 );
558 case ID_LISTBOX_SEL_STR
:
560 m_listbox
->SetStringSelection( "This" );
561 m_lbSelectNum
->WarpPointer( 40, 14 );
564 case ID_LISTBOX_CLEAR
:
569 case ID_LISTBOX_APPEND
:
571 m_listbox
->Append( "Hi!" );
574 case ID_LISTBOX_DELETE
:
576 int idx
= m_listbox
->GetSelection();
577 m_listbox
->Delete( idx
);
580 case ID_LISTBOX_FONT
:
582 m_listbox
->SetFont( *wxITALIC_FONT
);
583 m_checkbox
->SetFont( *wxITALIC_FONT
);
589 void MyPanel::OnChoice( wxCommandEvent
&event
)
591 m_text
->AppendText( "Choice event selection string is: " );
592 m_text
->AppendText( event
.GetString() );
593 m_text
->AppendText( "\n" );
594 m_text
->AppendText( "Choice control selection string is: " );
595 m_text
->AppendText( m_choice
->GetStringSelection() );
596 m_text
->AppendText( "\n" );
599 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
601 switch (event
.GetId())
603 case ID_CHOICE_ENABLE
:
605 m_choice
->Enable( event
.GetInt() == 0 );
608 case ID_CHOICE_SEL_NUM
:
610 m_choice
->SetSelection( 2 );
613 case ID_CHOICE_SEL_STR
:
615 m_choice
->SetStringSelection( "This" );
618 case ID_CHOICE_CLEAR
:
623 case ID_CHOICE_APPEND
:
625 m_choice
->Append( "Hi!" );
628 case ID_CHOICE_DELETE
:
630 int idx
= m_choice
->GetSelection();
631 m_choice
->Delete( idx
);
636 m_choice
->SetFont( *wxITALIC_FONT
);
642 void MyPanel::OnCombo( wxCommandEvent
&event
)
644 m_text
->AppendText( "ComboBox event selection string is: " );
645 m_text
->AppendText( event
.GetString() );
646 m_text
->AppendText( "\n" );
647 m_text
->AppendText( "ComboBox control selection string is: " );
648 m_text
->AppendText( m_combo
->GetStringSelection() );
649 m_text
->AppendText( "\n" );
652 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
654 switch (event
.GetId())
656 case ID_COMBO_ENABLE
:
658 m_combo
->Enable( event
.GetInt() == 0 );
661 case ID_COMBO_SEL_NUM
:
663 m_combo
->SetSelection( 2 );
666 case ID_COMBO_SEL_STR
:
668 m_combo
->SetStringSelection( "This" );
676 case ID_COMBO_APPEND
:
678 m_combo
->Append( "Hi!" );
681 case ID_COMBO_DELETE
:
683 int idx
= m_combo
->GetSelection();
684 m_combo
->Delete( idx
);
689 m_combo
->SetFont( *wxITALIC_FONT
);
695 void MyPanel::OnRadio( wxCommandEvent
&event
)
697 m_text
->AppendText( "RadioBox selection string is: " );
698 m_text
->AppendText( event
.GetString() );
699 m_text
->AppendText( "\n" );
702 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
704 switch (event
.GetId())
706 case ID_RADIOBOX_ENABLE
:
708 m_radio
->Enable( event
.GetInt() == 0 );
711 case ID_RADIOBOX_SEL_NUM
:
713 m_radio
->SetSelection( 2 );
716 case ID_RADIOBOX_SEL_STR
:
718 m_radio
->SetStringSelection( "This" );
721 case ID_RADIOBOX_FONT
:
723 m_radio
->SetFont( *wxITALIC_FONT
);
729 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
731 m_fontButton
->SetFont( *wxITALIC_FONT
);
732 m_text
->SetFont( *wxITALIC_FONT
);
735 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
737 m_gauge
->SetValue( m_slider
->GetValue() );
740 #ifndef wxUSE_SPINBUTTON
741 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
744 value
.Printf( _T("%d"), event
.GetPosition() );
745 m_spintext
->SetValue( value
);
747 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
748 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
749 m_spinbutton
->GetValue());
751 m_text
->AppendText(value
);
754 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
756 event
.Enable( m_spinbutton
->GetValue() > 0 );
759 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
761 int max
= m_spinbutton
->GetValue();
762 wxProgressDialog
dialog("Progress dialog example",
763 "An informative message",
766 wxPD_CAN_ABORT
| wxPD_APP_MODAL
| wxPD_ELAPSED_TIME
| wxPD_ESTIMATED_TIME
| wxPD_REMAINING_TIME
);
770 for ( int i
= 0; i
< max
&& cont
; i
++ )
775 cont
= dialog
.Update(i
, "That's all, folks!");
777 else if ( i
== max
/ 2 )
779 cont
= dialog
.Update(i
, "Only a half left!");
783 cont
= dialog
.Update(i
);
789 *m_text
<< "Progress dialog aborted!\n";
793 *m_text
<< "Countdown from " << max
<< " finished.\n";
797 #endif // wxUSE_SPINBUTTON
801 delete m_notebook
->GetImageList();
804 //----------------------------------------------------------------------
806 //----------------------------------------------------------------------
808 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
809 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
810 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
812 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
813 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
814 #endif // wxUSE_TOOLTIPS
815 EVT_SIZE(MyFrame::OnSize
)
816 EVT_IDLE(MyFrame::OnIdle
)
819 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
820 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
824 (void)new MyPanel( this, 10, 10, 300, 100 );
827 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
832 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
836 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
843 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
845 static long s_delay
= 5000;
848 delay
.Printf( _T("%ld"), s_delay
);
850 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
857 wxSscanf(delay
, _T("%ld"), &s_delay
);
859 wxToolTip::SetDelay(s_delay
);
861 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
864 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
866 static bool s_enabled
= TRUE
;
868 s_enabled
= !s_enabled
;
870 wxToolTip::Enable(s_enabled
);
872 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
876 void MyFrame::OnSize( wxSizeEvent
& event
)
879 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
880 SetStatusText(msg
, 1);
885 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
887 // track the window which has the focus in the status bar
888 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
889 wxWindow
*focus
= wxWindow::FindFocus();
890 if ( focus
&& (focus
!= s_windowFocus
) )
892 s_windowFocus
= focus
;
897 _T("Focus: wxWindow = %p, HWND = %08x"),
899 _T("Focus: wxWindow = %p"),
903 , s_windowFocus
->GetHWND()