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
52 #undef wxUSE_SPINBUTTON
53 #define wxUSE_SPINBUTTON 0
56 #include "wx/progdlg.h"
58 //----------------------------------------------------------------------
60 //----------------------------------------------------------------------
62 class MyApp
: public wxApp
68 class MyPanel
: public wxPanel
71 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
74 void OnSize( wxSizeEvent
& event
);
75 void OnListBox( wxCommandEvent
&event
);
76 void OnListBoxDoubleClick( wxCommandEvent
&event
);
77 void OnListBoxButtons( wxCommandEvent
&event
);
78 void OnChoice( wxCommandEvent
&event
);
79 void OnChoiceButtons( wxCommandEvent
&event
);
80 void OnCombo( wxCommandEvent
&event
);
81 void OnComboButtons( wxCommandEvent
&event
);
82 void OnRadio( wxCommandEvent
&event
);
83 void OnRadioButtons( wxCommandEvent
&event
);
84 void OnSetFont( wxCommandEvent
&event
);
85 void OnPageChanged( wxNotebookEvent
&event
);
86 void OnPageChanging( wxNotebookEvent
&event
);
87 void OnSliderUpdate( wxCommandEvent
&event
);
88 #ifndef wxUSE_SPINBUTTON
89 void OnSpinUp( wxSpinEvent
&event
);
90 void OnSpinDown( wxSpinEvent
&event
);
91 void OnSpinUpdate( wxSpinEvent
&event
);
92 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
93 void OnShowProgress( wxCommandEvent
&event
);
94 #endif // wxUSE_SPINBUTTON
102 wxButton
*m_fontButton
;
103 wxButton
*m_lbSelectNum
;
104 wxButton
*m_lbSelectThis
;
105 #ifndef wxUSE_SPINBUTTON
106 wxSpinButton
*m_spinbutton
;
107 wxButton
*m_btnProgress
;
109 wxTextCtrl
*m_spintext
;
110 wxCheckBox
*m_checkbox
;
113 wxNotebook
*m_notebook
;
116 DECLARE_EVENT_TABLE()
119 class MyFrame
: public wxFrame
122 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
124 void OnQuit(wxCommandEvent
& event
);
125 void OnAbout(wxCommandEvent
& event
);
127 void OnSetTooltipDelay(wxCommandEvent
& event
);
128 void OnToggleTooltips(wxCommandEvent
& event
);
129 #endif // wxUSE_TOOLTIPS
130 void OnIdle( wxIdleEvent
& event
);
131 void OnSize( wxSizeEvent
& event
);
134 DECLARE_EVENT_TABLE()
137 //----------------------------------------------------------------------
139 //----------------------------------------------------------------------
143 //----------------------------------------------------------------------
145 //----------------------------------------------------------------------
154 MINIMAL_SET_TOOLTIP_DELAY
= 200,
155 MINIMAL_ENABLE_TOOLTIPS
160 // Create the main frame window
161 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
162 "Controls wxWindows App",
166 // The wxICON() macros loads an icon from a resource under Windows
167 // and uses an #included XPM image under GTK+ and Motif
169 frame
->SetIcon( wxICON(mondrian
) );
171 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
172 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
173 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
175 wxMenuBar
*menu_bar
= new wxMenuBar
;
176 menu_bar
->Append(file_menu
, "&File");
179 wxMenu
*tooltip_menu
= new wxMenu
;
180 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
181 tooltip_menu
->AppendSeparator();
182 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
183 "enable/disable tooltips", TRUE
);
184 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
185 menu_bar
->Append(tooltip_menu
, "&Tooltips");
186 #endif // wxUSE_TOOLTIPS
188 frame
->SetMenuBar(menu_bar
);
191 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
198 //----------------------------------------------------------------------
200 //----------------------------------------------------------------------
202 const int ID_NOTEBOOK
= 1000;
204 const int ID_LISTBOX
= 130;
205 const int ID_LISTBOX_SEL_NUM
= 131;
206 const int ID_LISTBOX_SEL_STR
= 132;
207 const int ID_LISTBOX_CLEAR
= 133;
208 const int ID_LISTBOX_APPEND
= 134;
209 const int ID_LISTBOX_DELETE
= 135;
210 const int ID_LISTBOX_FONT
= 136;
211 const int ID_LISTBOX_ENABLE
= 137;
213 const int ID_CHOICE
= 120;
214 const int ID_CHOICE_SEL_NUM
= 121;
215 const int ID_CHOICE_SEL_STR
= 122;
216 const int ID_CHOICE_CLEAR
= 123;
217 const int ID_CHOICE_APPEND
= 124;
218 const int ID_CHOICE_DELETE
= 125;
219 const int ID_CHOICE_FONT
= 126;
220 const int ID_CHOICE_ENABLE
= 127;
222 const int ID_COMBO
= 140;
223 const int ID_COMBO_SEL_NUM
= 141;
224 const int ID_COMBO_SEL_STR
= 142;
225 const int ID_COMBO_CLEAR
= 143;
226 const int ID_COMBO_APPEND
= 144;
227 const int ID_COMBO_DELETE
= 145;
228 const int ID_COMBO_FONT
= 146;
229 const int ID_COMBO_ENABLE
= 147;
231 const int ID_RADIOBOX
= 160;
232 const int ID_RADIOBOX_SEL_NUM
= 161;
233 const int ID_RADIOBOX_SEL_STR
= 162;
234 const int ID_RADIOBOX_FONT
= 163;
235 const int ID_RADIOBOX_ENABLE
= 164;
237 const int ID_RADIOBUTTON_1
= 166;
238 const int ID_RADIOBUTTON_2
= 167;
240 const int ID_SET_FONT
= 170;
242 const int ID_GAUGE
= 180;
243 const int ID_SLIDER
= 181;
245 const int ID_SPIN
= 182;
246 const int ID_BTNPROGRESS
= 183;
248 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
249 EVT_SIZE ( MyPanel::OnSize
)
250 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
251 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
252 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
253 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
254 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
255 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
256 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
257 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
258 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
259 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
260 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
261 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
262 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
263 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
264 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
265 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
266 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
267 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
268 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
269 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
270 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
271 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
272 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
273 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
274 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
275 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
276 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
277 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
278 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
279 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
280 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
281 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
282 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
283 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
284 #ifndef wxUSE_SPINBUTTON
285 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
286 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
287 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
288 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
289 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
293 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
294 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
295 m_text(NULL
), m_notebook(NULL
)
297 // SetBackgroundColour("cadet blue");
299 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
300 // m_text->SetBackgroundColour("wheat");
302 delete wxLog::SetActiveTarget(new wxLogStderr
);
304 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
319 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
322 // fill the image list
323 wxImageList
*imagelist
= new wxImageList(32, 32);
325 imagelist
-> Add( wxBitmap( list_xpm
));
326 imagelist
-> Add( wxBitmap( choice_xpm
));
327 imagelist
-> Add( wxBitmap( combo_xpm
));
328 imagelist
-> Add( wxBitmap( text_xpm
));
329 imagelist
-> Add( wxBitmap( radio_xpm
));
330 imagelist
-> Add( wxBitmap( gauge_xpm
));
331 m_notebook
->SetImageList(imagelist
);
332 #elif defined(__WXMSW__)
333 // load images from resources
336 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
338 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
340 static const char *s_iconNames
[Image_Max
] =
342 "list", "choice", "combo", "text", "radio", "gauge"
345 for ( size_t n
= 0; n
< Image_Max
; n
++ )
347 wxBitmap
bmp(s_iconNames
[n
]);
348 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
350 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
355 m_notebook
->SetImageList(imagelist
);
359 #define Image_List -1
360 #define Image_Choice -1
361 #define Image_Combo -1
362 #define Image_Text -1
363 #define Image_Radio -1
364 #define Image_Gauge -1
369 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
370 wxPanel
*panel
= (wxPanel
*) NULL
;
372 panel
= new wxPanel(m_notebook
);
373 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
374 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
376 m_listbox
->SetToolTip( "This is a list box" );
377 #endif // wxUSE_TOOLTIPS
379 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
380 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
381 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
382 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
383 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
384 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
386 button
->SetToolTip( "Press here to set italic font" );
387 #endif // wxUSE_TOOLTIPS
389 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130) );
390 m_checkbox
->SetValue(FALSE
);
392 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
393 #endif // wxUSE_TOOLTIPS
394 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
396 panel
= new wxPanel(m_notebook
);
397 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
398 m_choice
->SetBackgroundColour( "red" );
399 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
400 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
401 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
402 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
403 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
404 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
405 (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), wxRB_GROUP
);
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(200,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(220,10), wxSize(270,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 int initialSpinValue
= -5;
467 s
<< initialSpinValue
;
468 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
469 #ifndef wxUSE_SPINBUTTON
470 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
471 m_spinbutton
->SetRange(-10,30);
472 m_spinbutton
->SetValue(initialSpinValue
);
474 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
477 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
479 panel
= new wxPanel(m_notebook
);
481 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
482 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
483 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
485 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
486 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
489 wxBitmap
bitmap( 100, 100 );
491 dc
.SelectObject( bitmap
);
492 dc
.SetPen(*wxGREEN_PEN
);
493 dc
.DrawEllipse(5, 5, 90, 90);
494 dc
.DrawText("Bitmap", 20, 20);
495 dc
.SelectObject( wxNullBitmap
);
497 wxBitmapButton
*bmpBtn
= new wxBitmapButton
504 bmpBtn
= NULL
; // suppress warning
506 new wxButton(panel
, -1, "Another button", wxPoint(250, 20));
508 m_notebook
->AddPage(panel
, "wxBitmapXXX");
511 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
515 GetClientSize( &x
, &y
);
517 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
518 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
521 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
523 int selOld
= event
.GetOldSelection();
526 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
527 "page change from taking place - if you select\n"
528 "[No] the current page will stay the third one\n",
530 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
538 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
541 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
543 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
546 void MyPanel::OnListBox( wxCommandEvent
&event
)
548 m_text
->AppendText( "ListBox event selection string is: " );
549 m_text
->AppendText( event
.GetString() );
550 m_text
->AppendText( "\n" );
551 m_text
->AppendText( "ListBox control selection string is: " );
552 m_text
->AppendText( m_listbox
->GetStringSelection() );
553 m_text
->AppendText( "\n" );
556 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
558 m_text
->AppendText( "ListBox double click string is: " );
559 m_text
->AppendText( event
.GetString() );
560 m_text
->AppendText( "\n" );
563 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
565 switch (event
.GetId())
567 case ID_LISTBOX_ENABLE
:
569 m_text
->AppendText("Checkbox clicked.\n");
570 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
573 cb
->SetToolTip( "Click to enable listbox" );
575 cb
->SetToolTip( "Click to disable listbox" );
576 #endif // wxUSE_TOOLTIPS
577 m_listbox
->Enable( event
.GetInt() == 0 );
580 case ID_LISTBOX_SEL_NUM
:
582 m_listbox
->SetSelection( 2 );
583 m_lbSelectThis
->WarpPointer( 40, 14 );
586 case ID_LISTBOX_SEL_STR
:
588 m_listbox
->SetStringSelection( "This" );
589 m_lbSelectNum
->WarpPointer( 40, 14 );
592 case ID_LISTBOX_CLEAR
:
597 case ID_LISTBOX_APPEND
:
599 m_listbox
->Append( "Hi!" );
602 case ID_LISTBOX_DELETE
:
604 int idx
= m_listbox
->GetSelection();
605 m_listbox
->Delete( idx
);
608 case ID_LISTBOX_FONT
:
610 m_listbox
->SetFont( *wxITALIC_FONT
);
611 m_checkbox
->SetFont( *wxITALIC_FONT
);
617 void MyPanel::OnChoice( wxCommandEvent
&event
)
619 m_text
->AppendText( "Choice event selection string is: " );
620 m_text
->AppendText( event
.GetString() );
621 m_text
->AppendText( "\n" );
622 m_text
->AppendText( "Choice control selection string is: " );
623 m_text
->AppendText( m_choice
->GetStringSelection() );
624 m_text
->AppendText( "\n" );
627 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
629 switch (event
.GetId())
631 case ID_CHOICE_ENABLE
:
633 m_choice
->Enable( event
.GetInt() == 0 );
636 case ID_CHOICE_SEL_NUM
:
638 m_choice
->SetSelection( 2 );
641 case ID_CHOICE_SEL_STR
:
643 m_choice
->SetStringSelection( "This" );
646 case ID_CHOICE_CLEAR
:
651 case ID_CHOICE_APPEND
:
653 m_choice
->Append( "Hi!" );
656 case ID_CHOICE_DELETE
:
658 int idx
= m_choice
->GetSelection();
659 m_choice
->Delete( idx
);
664 m_choice
->SetFont( *wxITALIC_FONT
);
670 void MyPanel::OnCombo( wxCommandEvent
&event
)
672 m_text
->AppendText( "ComboBox event selection string is: " );
673 m_text
->AppendText( event
.GetString() );
674 m_text
->AppendText( "\n" );
675 m_text
->AppendText( "ComboBox control selection string is: " );
676 m_text
->AppendText( m_combo
->GetStringSelection() );
677 m_text
->AppendText( "\n" );
680 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
682 switch (event
.GetId())
684 case ID_COMBO_ENABLE
:
686 m_combo
->Enable( event
.GetInt() == 0 );
689 case ID_COMBO_SEL_NUM
:
691 m_combo
->SetSelection( 2 );
694 case ID_COMBO_SEL_STR
:
696 m_combo
->SetStringSelection( "This" );
704 case ID_COMBO_APPEND
:
706 m_combo
->Append( "Hi!" );
709 case ID_COMBO_DELETE
:
711 int idx
= m_combo
->GetSelection();
712 m_combo
->Delete( idx
);
717 m_combo
->SetFont( *wxITALIC_FONT
);
723 void MyPanel::OnRadio( wxCommandEvent
&event
)
725 m_text
->AppendText( "RadioBox selection string is: " );
726 m_text
->AppendText( event
.GetString() );
727 m_text
->AppendText( "\n" );
730 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
732 switch (event
.GetId())
734 case ID_RADIOBOX_ENABLE
:
736 m_radio
->Enable( event
.GetInt() == 0 );
739 case ID_RADIOBOX_SEL_NUM
:
741 m_radio
->SetSelection( 2 );
744 case ID_RADIOBOX_SEL_STR
:
746 m_radio
->SetStringSelection( "This" );
749 case ID_RADIOBOX_FONT
:
751 m_radio
->SetFont( *wxITALIC_FONT
);
757 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
759 m_fontButton
->SetFont( *wxITALIC_FONT
);
760 m_text
->SetFont( *wxITALIC_FONT
);
763 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
765 m_gauge
->SetValue( m_slider
->GetValue() );
768 #ifndef wxUSE_SPINBUTTON
769 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
772 value
.Printf( _T("Spin control up: current = %d\n"),
773 m_spinbutton
->GetValue());
775 if ( m_spinbutton
->GetValue() > 17 )
777 value
+= _T("Preventing the spin button from going above 17.\n");
782 m_text
->AppendText(value
);
785 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
788 value
.Printf( _T("Spin control down: current = %d\n"),
789 m_spinbutton
->GetValue());
791 if ( m_spinbutton
->GetValue() < -17 )
793 value
+= _T("Preventing the spin button from going below -17.\n");
798 m_text
->AppendText(value
);
801 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
804 value
.Printf( _T("%d"), event
.GetPosition() );
805 m_spintext
->SetValue( value
);
807 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
808 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
809 m_spinbutton
->GetValue());
811 m_text
->AppendText(value
);
814 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
816 event
.Enable( m_spinbutton
->GetValue() > 0 );
819 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
821 int max
= m_spinbutton
->GetValue();
822 wxProgressDialog
dialog("Progress dialog example",
823 "An informative message",
829 wxPD_ESTIMATED_TIME
|
830 wxPD_REMAINING_TIME
);
834 for ( int i
= 0; i
< max
&& cont
; i
++ )
839 cont
= dialog
.Update(i
, "That's all, folks!");
841 else if ( i
== max
/ 2 )
843 cont
= dialog
.Update(i
, "Only a half left!");
847 cont
= dialog
.Update(i
);
853 *m_text
<< "Progress dialog aborted!\n";
857 *m_text
<< "Countdown from " << max
<< " finished.\n";
861 #endif // wxUSE_SPINBUTTON
865 delete m_notebook
->GetImageList();
868 //----------------------------------------------------------------------
870 //----------------------------------------------------------------------
872 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
873 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
874 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
876 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
877 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
878 #endif // wxUSE_TOOLTIPS
879 EVT_SIZE(MyFrame::OnSize
)
880 EVT_IDLE(MyFrame::OnIdle
)
883 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
884 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
888 (void)new MyPanel( this, 10, 10, 300, 100 );
891 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
896 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
900 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
907 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
909 static long s_delay
= 5000;
912 delay
.Printf( _T("%ld"), s_delay
);
914 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
921 wxSscanf(delay
, _T("%ld"), &s_delay
);
923 wxToolTip::SetDelay(s_delay
);
925 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
928 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
930 static bool s_enabled
= TRUE
;
932 s_enabled
= !s_enabled
;
934 wxToolTip::Enable(s_enabled
);
936 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
940 void MyFrame::OnSize( wxSizeEvent
& event
)
943 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
944 SetStatusText(msg
, 1);
949 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
951 // track the window which has the focus in the status bar
952 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
953 wxWindow
*focus
= wxWindow::FindFocus();
954 if ( focus
&& (focus
!= s_windowFocus
) )
956 s_windowFocus
= focus
;
961 _T("Focus: wxWindow = %p, HWND = %08x"),
963 _T("Focus: wxWindow = %p"),
967 , s_windowFocus
->GetHWND()