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
) );
168 wxMenu
*sub_menu
= new wxMenu( wxMENU_TEAROFF
);
169 sub_menu
->Append(MINIMAL_ABOUT
, "&About", "About this sample");
170 sub_menu
->Append(MINIMAL_ABOUT
, "&About", "About this sample");
171 sub_menu
->Append(MINIMAL_ABOUT
, "&About", "About this sample");
173 wxMenu
*file_menu
= new wxMenu
;
174 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
175 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
176 file_menu
->Append( 0, "&Submenu", sub_menu
);
178 wxMenuBar
*menu_bar
= new wxMenuBar( wxMB_DOCKABLE
);
179 menu_bar
->Append(file_menu
, "&File");
182 wxMenu
*tooltip_menu
= new wxMenu
;
183 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
184 tooltip_menu
->AppendSeparator();
185 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
186 "enable/disable tooltips", TRUE
);
187 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
188 menu_bar
->Append(tooltip_menu
, "&Tooltips");
189 #endif // wxUSE_TOOLTIPS
191 frame
->SetMenuBar(menu_bar
);
194 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
201 //----------------------------------------------------------------------
203 //----------------------------------------------------------------------
205 const int ID_NOTEBOOK
= 1000;
207 const int ID_LISTBOX
= 130;
208 const int ID_LISTBOX_SEL_NUM
= 131;
209 const int ID_LISTBOX_SEL_STR
= 132;
210 const int ID_LISTBOX_CLEAR
= 133;
211 const int ID_LISTBOX_APPEND
= 134;
212 const int ID_LISTBOX_DELETE
= 135;
213 const int ID_LISTBOX_FONT
= 136;
214 const int ID_LISTBOX_ENABLE
= 137;
216 const int ID_CHOICE
= 120;
217 const int ID_CHOICE_SEL_NUM
= 121;
218 const int ID_CHOICE_SEL_STR
= 122;
219 const int ID_CHOICE_CLEAR
= 123;
220 const int ID_CHOICE_APPEND
= 124;
221 const int ID_CHOICE_DELETE
= 125;
222 const int ID_CHOICE_FONT
= 126;
223 const int ID_CHOICE_ENABLE
= 127;
225 const int ID_COMBO
= 140;
226 const int ID_COMBO_SEL_NUM
= 141;
227 const int ID_COMBO_SEL_STR
= 142;
228 const int ID_COMBO_CLEAR
= 143;
229 const int ID_COMBO_APPEND
= 144;
230 const int ID_COMBO_DELETE
= 145;
231 const int ID_COMBO_FONT
= 146;
232 const int ID_COMBO_ENABLE
= 147;
234 const int ID_RADIOBOX
= 160;
235 const int ID_RADIOBOX_SEL_NUM
= 161;
236 const int ID_RADIOBOX_SEL_STR
= 162;
237 const int ID_RADIOBOX_FONT
= 163;
238 const int ID_RADIOBOX_ENABLE
= 164;
240 const int ID_RADIOBUTTON_1
= 166;
241 const int ID_RADIOBUTTON_2
= 167;
243 const int ID_SET_FONT
= 170;
245 const int ID_GAUGE
= 180;
246 const int ID_SLIDER
= 181;
248 const int ID_SPIN
= 182;
249 const int ID_BTNPROGRESS
= 183;
251 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
252 EVT_SIZE ( MyPanel::OnSize
)
253 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
254 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
255 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
256 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
257 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
258 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
259 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
260 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
261 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
262 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
263 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
264 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
265 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
266 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
267 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
268 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
269 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
270 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
271 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
272 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
273 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
274 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
275 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
276 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
277 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
278 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
279 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
280 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
281 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
282 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
283 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
284 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
285 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
286 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
287 #ifndef wxUSE_SPINBUTTON
288 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
289 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
290 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
294 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
295 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
296 m_text(NULL
), m_notebook(NULL
)
298 // SetBackgroundColour("cadet blue");
300 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
301 // m_text->SetBackgroundColour("wheat");
303 delete wxLog::SetActiveTarget(new wxLogStderr
);
305 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
320 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
323 // fill the image list
324 wxImageList
*imagelist
= new wxImageList(32, 32);
326 imagelist
-> Add( wxBitmap( list_xpm
));
327 imagelist
-> Add( wxBitmap( choice_xpm
));
328 imagelist
-> Add( wxBitmap( combo_xpm
));
329 imagelist
-> Add( wxBitmap( text_xpm
));
330 imagelist
-> Add( wxBitmap( radio_xpm
));
331 imagelist
-> Add( wxBitmap( gauge_xpm
));
332 m_notebook
->SetImageList(imagelist
);
333 #elif defined(__WXMSW__)
334 // load images from resources
337 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
339 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
341 static const char *s_iconNames
[Image_Max
] =
343 "list", "choice", "combo", "text", "radio", "gauge"
346 for ( size_t n
= 0; n
< Image_Max
; n
++ )
348 wxBitmap
bmp(s_iconNames
[n
]);
349 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
351 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
356 m_notebook
->SetImageList(imagelist
);
360 #define Image_List -1
361 #define Image_Choice -1
362 #define Image_Combo -1
363 #define Image_Text -1
364 #define Image_Radio -1
365 #define Image_Gauge -1
370 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
371 wxPanel
*panel
= (wxPanel
*) NULL
;
373 panel
= new wxPanel(m_notebook
);
374 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
375 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
377 m_listbox
->SetToolTip( "This is a list box" );
378 #endif // wxUSE_TOOLTIPS
380 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
381 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
382 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
383 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
384 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
385 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
387 button
->SetToolTip( "Press here to set italic font" );
388 #endif // wxUSE_TOOLTIPS
390 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT
);
391 m_checkbox
->SetValue(FALSE
);
393 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
394 #endif // wxUSE_TOOLTIPS
395 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
397 panel
= new wxPanel(m_notebook
);
398 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
399 m_choice
->SetBackgroundColour( "red" );
400 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
401 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
402 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
403 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
404 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
405 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
406 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
407 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
409 panel
= new wxPanel(m_notebook
);
410 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
411 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
412 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
413 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
414 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
415 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
416 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
417 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
418 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
420 wxString choices2
[] =
424 "Fourth", "Fifth", "Sixth",
425 "Seventh", "Eighth", "Nineth", "Tenth" */
428 panel
= new wxPanel(m_notebook
);
429 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
430 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
431 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
432 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
433 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
434 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
435 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
436 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
437 rb
->SetValue( FALSE
);
438 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
439 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
441 panel
= new wxPanel(m_notebook
);
442 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
443 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
444 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
445 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
447 // No wrapping text in wxStaticText yet :-(
448 (void)new wxStaticText( panel
, -1,
454 (void)new wxStaticText( panel
, -1,
455 "In order see the gauge (aka progress bar)\n"
456 "control do something you have to drag the\n"
457 "handle of the slider to the right.\n"
459 "This is also supposed to demonstrate how\n"
460 "to use static controls.\n",
465 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
466 #ifndef wxUSE_SPINBUTTON
467 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
468 m_spinbutton
->SetRange(-10,30);
469 m_spinbutton
->SetValue(-5);
471 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
474 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
477 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
481 GetClientSize( &x
, &y
);
483 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
484 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
487 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
489 int selNew
= event
.GetSelection(),
490 selOld
= event
.GetOldSelection();
491 if ( selOld
== 2 && selNew
== 4 )
493 wxMessageBox("This demonstrates how a program may prevent the "
494 "page change from taking place - the current page will "
495 "stay the third one", "Conntrol sample",
496 wxICON_INFORMATION
| wxOK
);
502 *m_text
<< "Notebook selection is being changed from "
503 << selOld
<< " to " << selNew
<< "\n";
507 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
509 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
512 void MyPanel::OnListBox( wxCommandEvent
&event
)
514 m_text
->AppendText( "ListBox event selection string is: " );
515 m_text
->AppendText( event
.GetString() );
516 m_text
->AppendText( "\n" );
517 m_text
->AppendText( "ListBox control selection string is: " );
518 m_text
->AppendText( m_listbox
->GetStringSelection() );
519 m_text
->AppendText( "\n" );
522 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
524 m_text
->AppendText( "ListBox double click string is: " );
525 m_text
->AppendText( event
.GetString() );
526 m_text
->AppendText( "\n" );
529 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
531 switch (event
.GetId())
533 case ID_LISTBOX_ENABLE
:
535 m_text
->AppendText("Checkbox clicked.\n");
536 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
539 cb
->SetToolTip( "Click to enable listbox" );
541 cb
->SetToolTip( "Click to disable listbox" );
542 #endif // wxUSE_TOOLTIPS
543 m_listbox
->Enable( event
.GetInt() == 0 );
546 case ID_LISTBOX_SEL_NUM
:
548 m_listbox
->SetSelection( 2 );
549 m_lbSelectThis
->WarpPointer( 40, 14 );
552 case ID_LISTBOX_SEL_STR
:
554 m_listbox
->SetStringSelection( "This" );
555 m_lbSelectNum
->WarpPointer( 40, 14 );
558 case ID_LISTBOX_CLEAR
:
563 case ID_LISTBOX_APPEND
:
565 m_listbox
->Append( "Hi!" );
568 case ID_LISTBOX_DELETE
:
570 int idx
= m_listbox
->GetSelection();
571 m_listbox
->Delete( idx
);
574 case ID_LISTBOX_FONT
:
576 m_listbox
->SetFont( *wxITALIC_FONT
);
577 m_checkbox
->SetFont( *wxITALIC_FONT
);
583 void MyPanel::OnChoice( wxCommandEvent
&event
)
585 m_text
->AppendText( "Choice event selection string is: " );
586 m_text
->AppendText( event
.GetString() );
587 m_text
->AppendText( "\n" );
588 m_text
->AppendText( "Choice control selection string is: " );
589 m_text
->AppendText( m_choice
->GetStringSelection() );
590 m_text
->AppendText( "\n" );
593 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
595 switch (event
.GetId())
597 case ID_CHOICE_ENABLE
:
599 m_choice
->Enable( event
.GetInt() == 0 );
602 case ID_CHOICE_SEL_NUM
:
604 m_choice
->SetSelection( 2 );
607 case ID_CHOICE_SEL_STR
:
609 m_choice
->SetStringSelection( "This" );
612 case ID_CHOICE_CLEAR
:
617 case ID_CHOICE_APPEND
:
619 m_choice
->Append( "Hi!" );
622 case ID_CHOICE_DELETE
:
624 int idx
= m_choice
->GetSelection();
625 m_choice
->Delete( idx
);
630 m_choice
->SetFont( *wxITALIC_FONT
);
636 void MyPanel::OnCombo( wxCommandEvent
&event
)
638 m_text
->AppendText( "ComboBox event selection string is: " );
639 m_text
->AppendText( event
.GetString() );
640 m_text
->AppendText( "\n" );
641 m_text
->AppendText( "ComboBox control selection string is: " );
642 m_text
->AppendText( m_combo
->GetStringSelection() );
643 m_text
->AppendText( "\n" );
646 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
648 switch (event
.GetId())
650 case ID_COMBO_ENABLE
:
652 m_combo
->Enable( event
.GetInt() == 0 );
655 case ID_COMBO_SEL_NUM
:
657 m_combo
->SetSelection( 2 );
660 case ID_COMBO_SEL_STR
:
662 m_combo
->SetStringSelection( "This" );
670 case ID_COMBO_APPEND
:
672 m_combo
->Append( "Hi!" );
675 case ID_COMBO_DELETE
:
677 int idx
= m_combo
->GetSelection();
678 m_combo
->Delete( idx
);
683 m_combo
->SetFont( *wxITALIC_FONT
);
689 void MyPanel::OnRadio( wxCommandEvent
&event
)
691 m_text
->AppendText( "RadioBox selection string is: " );
692 m_text
->AppendText( event
.GetString() );
693 m_text
->AppendText( "\n" );
696 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
698 switch (event
.GetId())
700 case ID_RADIOBOX_ENABLE
:
702 m_radio
->Enable( event
.GetInt() == 0 );
705 case ID_RADIOBOX_SEL_NUM
:
707 m_radio
->SetSelection( 2 );
710 case ID_RADIOBOX_SEL_STR
:
712 m_radio
->SetStringSelection( "This" );
715 case ID_RADIOBOX_FONT
:
717 m_radio
->SetFont( *wxITALIC_FONT
);
723 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
725 m_fontButton
->SetFont( *wxITALIC_FONT
);
726 m_text
->SetFont( *wxITALIC_FONT
);
729 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
731 m_gauge
->SetValue( m_slider
->GetValue() );
734 #ifndef wxUSE_SPINBUTTON
735 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
738 value
.Printf( _T("%d"), event
.GetPosition() );
739 m_spintext
->SetValue( value
);
741 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
742 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
743 m_spinbutton
->GetValue());
745 m_text
->AppendText(value
);
748 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
750 event
.Enable( m_spinbutton
->GetValue() > 0 );
753 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
755 int max
= m_spinbutton
->GetValue();
756 wxProgressDialog
dialog("Progress dialog example",
757 "An informative message",
760 wxPD_CAN_ABORT
| wxPD_APP_MODAL
);
764 for ( int i
= 0; i
< max
&& cont
; i
++ )
769 cont
= dialog
.Update(i
, "That's all, folks!");
771 else if ( i
== max
/ 2 )
773 cont
= dialog
.Update(i
, "Only a half left!");
777 cont
= dialog
.Update(i
);
783 *m_text
<< "Progress dialog aborted!\n";
787 *m_text
<< "Countdown from " << max
<< " finished.\n";
791 #endif // wxUSE_SPINBUTTON
795 delete m_notebook
->GetImageList();
798 //----------------------------------------------------------------------
800 //----------------------------------------------------------------------
802 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
803 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
804 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
806 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
807 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
808 #endif // wxUSE_TOOLTIPS
809 EVT_SIZE(MyFrame::OnSize
)
810 EVT_IDLE(MyFrame::OnIdle
)
813 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
814 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
818 (void)new MyPanel( this, 10, 10, 300, 100 );
821 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
826 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
830 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
837 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
839 static long s_delay
= 5000;
842 delay
.Printf( _T("%ld"), s_delay
);
844 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
851 wxSscanf(delay
, _T("%ld"), &s_delay
);
853 wxToolTip::SetDelay(s_delay
);
855 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
858 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
860 static bool s_enabled
= TRUE
;
862 s_enabled
= !s_enabled
;
864 wxToolTip::Enable(s_enabled
);
866 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
870 void MyFrame::OnSize( wxSizeEvent
& event
)
873 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
874 SetStatusText(msg
, 1);
879 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
881 // track the window which has the focus in the status bar
882 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
883 wxWindow
*focus
= wxWindow::FindFocus();
884 if ( focus
&& (focus
!= s_windowFocus
) )
886 s_windowFocus
= focus
;
891 _T("Focus: wxWindow = %p, HWND = %08x"),
893 _T("Focus: wxWindow = %p"),
897 , s_windowFocus
->GetHWND()