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 OnSpinUp( wxSpinEvent
&event
);
88 void OnSpinDown( wxSpinEvent
&event
);
89 void OnSpinUpdate( wxSpinEvent
&event
);
90 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
91 void OnShowProgress( wxCommandEvent
&event
);
92 #endif // wxUSE_SPINBUTTON
100 wxButton
*m_fontButton
;
101 wxButton
*m_lbSelectNum
;
102 wxButton
*m_lbSelectThis
;
103 #ifndef wxUSE_SPINBUTTON
104 wxSpinButton
*m_spinbutton
;
105 wxButton
*m_btnProgress
;
107 wxTextCtrl
*m_spintext
;
108 wxCheckBox
*m_checkbox
;
111 wxNotebook
*m_notebook
;
114 DECLARE_EVENT_TABLE()
117 class MyFrame
: public wxFrame
120 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
122 void OnQuit(wxCommandEvent
& event
);
123 void OnAbout(wxCommandEvent
& event
);
125 void OnSetTooltipDelay(wxCommandEvent
& event
);
126 void OnToggleTooltips(wxCommandEvent
& event
);
127 #endif // wxUSE_TOOLTIPS
128 void OnIdle( wxIdleEvent
& event
);
129 void OnSize( wxSizeEvent
& event
);
132 DECLARE_EVENT_TABLE()
135 //----------------------------------------------------------------------
137 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
143 //----------------------------------------------------------------------
152 MINIMAL_SET_TOOLTIP_DELAY
= 200,
153 MINIMAL_ENABLE_TOOLTIPS
158 // Create the main frame window
159 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
160 "Controls wxWindows App",
164 // The wxICON() macros loads an icon from a resource under Windows
165 // and uses an #included XPM image under GTK+ and Motif
167 frame
->SetIcon( wxICON(mondrian
) );
169 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
170 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
171 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
173 wxMenuBar
*menu_bar
= new wxMenuBar
;
174 menu_bar
->Append(file_menu
, "&File");
177 wxMenu
*tooltip_menu
= new wxMenu
;
178 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
179 tooltip_menu
->AppendSeparator();
180 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
181 "enable/disable tooltips", TRUE
);
182 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
183 menu_bar
->Append(tooltip_menu
, "&Tooltips");
184 #endif // wxUSE_TOOLTIPS
186 frame
->SetMenuBar(menu_bar
);
189 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
196 //----------------------------------------------------------------------
198 //----------------------------------------------------------------------
200 const int ID_NOTEBOOK
= 1000;
202 const int ID_LISTBOX
= 130;
203 const int ID_LISTBOX_SEL_NUM
= 131;
204 const int ID_LISTBOX_SEL_STR
= 132;
205 const int ID_LISTBOX_CLEAR
= 133;
206 const int ID_LISTBOX_APPEND
= 134;
207 const int ID_LISTBOX_DELETE
= 135;
208 const int ID_LISTBOX_FONT
= 136;
209 const int ID_LISTBOX_ENABLE
= 137;
211 const int ID_CHOICE
= 120;
212 const int ID_CHOICE_SEL_NUM
= 121;
213 const int ID_CHOICE_SEL_STR
= 122;
214 const int ID_CHOICE_CLEAR
= 123;
215 const int ID_CHOICE_APPEND
= 124;
216 const int ID_CHOICE_DELETE
= 125;
217 const int ID_CHOICE_FONT
= 126;
218 const int ID_CHOICE_ENABLE
= 127;
220 const int ID_COMBO
= 140;
221 const int ID_COMBO_SEL_NUM
= 141;
222 const int ID_COMBO_SEL_STR
= 142;
223 const int ID_COMBO_CLEAR
= 143;
224 const int ID_COMBO_APPEND
= 144;
225 const int ID_COMBO_DELETE
= 145;
226 const int ID_COMBO_FONT
= 146;
227 const int ID_COMBO_ENABLE
= 147;
229 const int ID_RADIOBOX
= 160;
230 const int ID_RADIOBOX_SEL_NUM
= 161;
231 const int ID_RADIOBOX_SEL_STR
= 162;
232 const int ID_RADIOBOX_FONT
= 163;
233 const int ID_RADIOBOX_ENABLE
= 164;
235 const int ID_RADIOBUTTON_1
= 166;
236 const int ID_RADIOBUTTON_2
= 167;
238 const int ID_SET_FONT
= 170;
240 const int ID_GAUGE
= 180;
241 const int ID_SLIDER
= 181;
243 const int ID_SPIN
= 182;
244 const int ID_BTNPROGRESS
= 183;
246 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
247 EVT_SIZE ( MyPanel::OnSize
)
248 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
249 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
250 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
251 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
252 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
253 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
254 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
255 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
256 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
257 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
258 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
259 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
260 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
261 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
262 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
263 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
264 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
265 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
266 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
267 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
268 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
269 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
270 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
271 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
272 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
273 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
274 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
275 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
276 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
277 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
278 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
279 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
280 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
281 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
282 #ifndef wxUSE_SPINBUTTON
283 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
284 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
285 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
286 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
287 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
291 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
292 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
293 m_text(NULL
), m_notebook(NULL
)
295 // SetBackgroundColour("cadet blue");
297 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
298 // m_text->SetBackgroundColour("wheat");
300 delete wxLog::SetActiveTarget(new wxLogStderr
);
302 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
317 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
320 // fill the image list
321 wxImageList
*imagelist
= new wxImageList(32, 32);
323 imagelist
-> Add( wxBitmap( list_xpm
));
324 imagelist
-> Add( wxBitmap( choice_xpm
));
325 imagelist
-> Add( wxBitmap( combo_xpm
));
326 imagelist
-> Add( wxBitmap( text_xpm
));
327 imagelist
-> Add( wxBitmap( radio_xpm
));
328 imagelist
-> Add( wxBitmap( gauge_xpm
));
329 m_notebook
->SetImageList(imagelist
);
330 #elif defined(__WXMSW__)
331 // load images from resources
334 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
336 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
338 static const char *s_iconNames
[Image_Max
] =
340 "list", "choice", "combo", "text", "radio", "gauge"
343 for ( size_t n
= 0; n
< Image_Max
; n
++ )
345 wxBitmap
bmp(s_iconNames
[n
]);
346 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
348 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
353 m_notebook
->SetImageList(imagelist
);
357 #define Image_List -1
358 #define Image_Choice -1
359 #define Image_Combo -1
360 #define Image_Text -1
361 #define Image_Radio -1
362 #define Image_Gauge -1
367 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
368 wxPanel
*panel
= (wxPanel
*) NULL
;
370 panel
= new wxPanel(m_notebook
);
371 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
372 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
374 m_listbox
->SetToolTip( "This is a list box" );
375 #endif // wxUSE_TOOLTIPS
377 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
378 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
379 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
380 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
381 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
382 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
384 button
->SetToolTip( "Press here to set italic font" );
385 #endif // wxUSE_TOOLTIPS
387 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130) );
388 m_checkbox
->SetValue(FALSE
);
390 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
391 #endif // wxUSE_TOOLTIPS
392 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
394 panel
= new wxPanel(m_notebook
);
395 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
396 m_choice
->SetBackgroundColour( "red" );
397 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
398 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
399 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
400 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
401 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
402 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
403 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
405 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
407 panel
= new wxPanel(m_notebook
);
408 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
409 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
410 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
411 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
412 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
413 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
414 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
415 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
416 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
418 wxString choices2
[] =
422 "Fourth", "Fifth", "Sixth",
423 "Seventh", "Eighth", "Nineth", "Tenth" */
426 panel
= new wxPanel(m_notebook
);
427 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
428 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
429 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
430 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
431 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
432 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
433 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
434 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
435 rb
->SetValue( FALSE
);
436 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
437 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
439 panel
= new wxPanel(m_notebook
);
440 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
441 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
442 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
443 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
445 // No wrapping text in wxStaticText yet :-(
446 (void)new wxStaticText( panel
, -1,
452 (void)new wxStaticText( panel
, -1,
453 "In order see the gauge (aka progress bar)\n"
454 "control do something you have to drag the\n"
455 "handle of the slider to the right.\n"
457 "This is also supposed to demonstrate how\n"
458 "to use static controls.\n",
463 int initialSpinValue
= -5;
465 s
<< initialSpinValue
;
466 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
467 #ifndef wxUSE_SPINBUTTON
468 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
469 m_spinbutton
->SetRange(-10,30);
470 m_spinbutton
->SetValue(initialSpinValue
);
472 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
475 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
477 panel
= new wxPanel(m_notebook
);
478 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
479 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
481 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
482 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
484 wxBitmap
bitmap( 100, 100 );
486 dc
.SelectObject( bitmap
);
487 dc
.SetPen(*wxGREEN_PEN
);
488 dc
.DrawEllipse(5, 5, 90, 90);
489 dc
.DrawText("Bitmap", 20, 20);
490 dc
.SelectObject( wxNullBitmap
);
492 wxBitmapButton
*bmpBtn
= new wxBitmapButton
499 bmpBtn
= NULL
; // suppress warning
501 new wxButton(panel
, -1, "Another button", wxPoint(250, 20));
503 m_notebook
->AddPage(panel
, "wxBitmapXXX");
506 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
510 GetClientSize( &x
, &y
);
512 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
513 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
516 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
518 int selOld
= event
.GetOldSelection();
521 if ( wxMessageBox("This demonstrates how a program may prevent the "
522 "page change from taking place - if you select "
523 "[No] the current page will stay the third one",
525 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
533 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
536 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
538 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
541 void MyPanel::OnListBox( wxCommandEvent
&event
)
543 m_text
->AppendText( "ListBox event selection string is: " );
544 m_text
->AppendText( event
.GetString() );
545 m_text
->AppendText( "\n" );
546 m_text
->AppendText( "ListBox control selection string is: " );
547 m_text
->AppendText( m_listbox
->GetStringSelection() );
548 m_text
->AppendText( "\n" );
551 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
553 m_text
->AppendText( "ListBox double click string is: " );
554 m_text
->AppendText( event
.GetString() );
555 m_text
->AppendText( "\n" );
558 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
560 switch (event
.GetId())
562 case ID_LISTBOX_ENABLE
:
564 m_text
->AppendText("Checkbox clicked.\n");
565 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
568 cb
->SetToolTip( "Click to enable listbox" );
570 cb
->SetToolTip( "Click to disable listbox" );
571 #endif // wxUSE_TOOLTIPS
572 m_listbox
->Enable( event
.GetInt() == 0 );
575 case ID_LISTBOX_SEL_NUM
:
577 m_listbox
->SetSelection( 2 );
578 m_lbSelectThis
->WarpPointer( 40, 14 );
581 case ID_LISTBOX_SEL_STR
:
583 m_listbox
->SetStringSelection( "This" );
584 m_lbSelectNum
->WarpPointer( 40, 14 );
587 case ID_LISTBOX_CLEAR
:
592 case ID_LISTBOX_APPEND
:
594 m_listbox
->Append( "Hi!" );
597 case ID_LISTBOX_DELETE
:
599 int idx
= m_listbox
->GetSelection();
600 m_listbox
->Delete( idx
);
603 case ID_LISTBOX_FONT
:
605 m_listbox
->SetFont( *wxITALIC_FONT
);
606 m_checkbox
->SetFont( *wxITALIC_FONT
);
612 void MyPanel::OnChoice( wxCommandEvent
&event
)
614 m_text
->AppendText( "Choice event selection string is: " );
615 m_text
->AppendText( event
.GetString() );
616 m_text
->AppendText( "\n" );
617 m_text
->AppendText( "Choice control selection string is: " );
618 m_text
->AppendText( m_choice
->GetStringSelection() );
619 m_text
->AppendText( "\n" );
622 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
624 switch (event
.GetId())
626 case ID_CHOICE_ENABLE
:
628 m_choice
->Enable( event
.GetInt() == 0 );
631 case ID_CHOICE_SEL_NUM
:
633 m_choice
->SetSelection( 2 );
636 case ID_CHOICE_SEL_STR
:
638 m_choice
->SetStringSelection( "This" );
641 case ID_CHOICE_CLEAR
:
646 case ID_CHOICE_APPEND
:
648 m_choice
->Append( "Hi!" );
651 case ID_CHOICE_DELETE
:
653 int idx
= m_choice
->GetSelection();
654 m_choice
->Delete( idx
);
659 m_choice
->SetFont( *wxITALIC_FONT
);
665 void MyPanel::OnCombo( wxCommandEvent
&event
)
667 m_text
->AppendText( "ComboBox event selection string is: " );
668 m_text
->AppendText( event
.GetString() );
669 m_text
->AppendText( "\n" );
670 m_text
->AppendText( "ComboBox control selection string is: " );
671 m_text
->AppendText( m_combo
->GetStringSelection() );
672 m_text
->AppendText( "\n" );
675 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
677 switch (event
.GetId())
679 case ID_COMBO_ENABLE
:
681 m_combo
->Enable( event
.GetInt() == 0 );
684 case ID_COMBO_SEL_NUM
:
686 m_combo
->SetSelection( 2 );
689 case ID_COMBO_SEL_STR
:
691 m_combo
->SetStringSelection( "This" );
699 case ID_COMBO_APPEND
:
701 m_combo
->Append( "Hi!" );
704 case ID_COMBO_DELETE
:
706 int idx
= m_combo
->GetSelection();
707 m_combo
->Delete( idx
);
712 m_combo
->SetFont( *wxITALIC_FONT
);
718 void MyPanel::OnRadio( wxCommandEvent
&event
)
720 m_text
->AppendText( "RadioBox selection string is: " );
721 m_text
->AppendText( event
.GetString() );
722 m_text
->AppendText( "\n" );
725 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
727 switch (event
.GetId())
729 case ID_RADIOBOX_ENABLE
:
731 m_radio
->Enable( event
.GetInt() == 0 );
734 case ID_RADIOBOX_SEL_NUM
:
736 m_radio
->SetSelection( 2 );
739 case ID_RADIOBOX_SEL_STR
:
741 m_radio
->SetStringSelection( "This" );
744 case ID_RADIOBOX_FONT
:
746 m_radio
->SetFont( *wxITALIC_FONT
);
752 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
754 m_fontButton
->SetFont( *wxITALIC_FONT
);
755 m_text
->SetFont( *wxITALIC_FONT
);
758 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
760 m_gauge
->SetValue( m_slider
->GetValue() );
763 #ifndef wxUSE_SPINBUTTON
764 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
767 value
.Printf( _T("Spin control up: current = %d\n"),
768 m_spinbutton
->GetValue());
770 if ( m_spinbutton
->GetValue() > 17 )
772 value
+= _T("Preventing the spin button from going above 17.\n");
777 m_text
->AppendText(value
);
780 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
783 value
.Printf( _T("Spin control down: current = %d\n"),
784 m_spinbutton
->GetValue());
786 if ( m_spinbutton
->GetValue() < -17 )
788 value
+= _T("Preventing the spin button from going below -17.\n");
793 m_text
->AppendText(value
);
796 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
799 value
.Printf( _T("%d"), event
.GetPosition() );
800 m_spintext
->SetValue( value
);
802 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
803 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
804 m_spinbutton
->GetValue());
806 m_text
->AppendText(value
);
809 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
811 event
.Enable( m_spinbutton
->GetValue() > 0 );
814 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
816 int max
= m_spinbutton
->GetValue();
817 wxProgressDialog
dialog("Progress dialog example",
818 "An informative message",
824 wxPD_ESTIMATED_TIME
|
825 wxPD_REMAINING_TIME
);
829 for ( int i
= 0; i
< max
&& cont
; i
++ )
834 cont
= dialog
.Update(i
, "That's all, folks!");
836 else if ( i
== max
/ 2 )
838 cont
= dialog
.Update(i
, "Only a half left!");
842 cont
= dialog
.Update(i
);
848 *m_text
<< "Progress dialog aborted!\n";
852 *m_text
<< "Countdown from " << max
<< " finished.\n";
856 #endif // wxUSE_SPINBUTTON
860 delete m_notebook
->GetImageList();
863 //----------------------------------------------------------------------
865 //----------------------------------------------------------------------
867 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
868 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
869 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
871 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
872 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
873 #endif // wxUSE_TOOLTIPS
874 EVT_SIZE(MyFrame::OnSize
)
875 EVT_IDLE(MyFrame::OnIdle
)
878 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
879 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
883 (void)new MyPanel( this, 10, 10, 300, 100 );
886 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
891 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
895 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
902 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
904 static long s_delay
= 5000;
907 delay
.Printf( _T("%ld"), s_delay
);
909 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
916 wxSscanf(delay
, _T("%ld"), &s_delay
);
918 wxToolTip::SetDelay(s_delay
);
920 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
923 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
925 static bool s_enabled
= TRUE
;
927 s_enabled
= !s_enabled
;
929 wxToolTip::Enable(s_enabled
);
931 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
935 void MyFrame::OnSize( wxSizeEvent
& event
)
938 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
939 SetStatusText(msg
, 1);
944 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
946 // track the window which has the focus in the status bar
947 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
948 wxWindow
*focus
= wxWindow::FindFocus();
949 if ( focus
&& (focus
!= s_windowFocus
) )
951 s_windowFocus
= focus
;
956 _T("Focus: wxWindow = %p, HWND = %08x"),
958 _T("Focus: wxWindow = %p"),
962 , s_windowFocus
->GetHWND()