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
55 #if !defined(wxUSE_SPINBUTTON)
56 #define wxUSE_SPINBUTTON 1
60 #include "wx/progdlg.h"
62 // VZ: this is a temp. hack, will remove soon
63 #define wxUSE_SPINCTRL 1
66 #include "wx/spinctrl.h"
67 #endif // wxUSE_SPINCTRL
69 //----------------------------------------------------------------------
71 //----------------------------------------------------------------------
73 class MyApp
: public wxApp
79 class MyPanel
: public wxPanel
82 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
85 void OnSize( wxSizeEvent
& event
);
86 void OnListBox( wxCommandEvent
&event
);
87 void OnListBoxDoubleClick( wxCommandEvent
&event
);
88 void OnListBoxButtons( wxCommandEvent
&event
);
89 void OnChoice( wxCommandEvent
&event
);
90 void OnChoiceButtons( wxCommandEvent
&event
);
91 void OnCombo( wxCommandEvent
&event
);
92 void OnComboButtons( wxCommandEvent
&event
);
93 void OnRadio( wxCommandEvent
&event
);
94 void OnRadioButtons( wxCommandEvent
&event
);
95 void OnSetFont( wxCommandEvent
&event
);
96 void OnPageChanged( wxNotebookEvent
&event
);
97 void OnPageChanging( wxNotebookEvent
&event
);
98 void OnSliderUpdate( wxCommandEvent
&event
);
99 void OnUpdateLabel( wxCommandEvent
&event
);
101 void OnSpinUp( wxSpinEvent
&event
);
102 void OnSpinDown( wxSpinEvent
&event
);
103 void OnSpinUpdate( wxSpinEvent
&event
);
104 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
105 void OnShowProgress( wxCommandEvent
&event
);
106 #endif // wxUSE_SPINBUTTON
109 void OnSpinCtrl(wxSpinEvent
& event
);
110 #endif // wxUSE_SPINCTRL
112 wxListBox
*m_listbox
,
120 wxButton
*m_fontButton
;
121 wxButton
*m_lbSelectNum
;
122 wxButton
*m_lbSelectThis
;
124 wxSpinButton
*m_spinbutton
;
125 wxButton
*m_btnProgress
;
126 #endif // wxUSE_SPINBUTTON
129 wxSpinCtrl
*m_spinctrl
;
130 #endif // wxUSE_SPINCTRL
132 wxTextCtrl
*m_spintext
;
133 wxCheckBox
*m_checkbox
;
136 wxNotebook
*m_notebook
;
138 wxStaticText
*m_label
;
141 DECLARE_EVENT_TABLE()
144 class MyFrame
: public wxFrame
147 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
149 void OnQuit(wxCommandEvent
& event
);
150 void OnAbout(wxCommandEvent
& event
);
152 void OnSetTooltipDelay(wxCommandEvent
& event
);
153 void OnToggleTooltips(wxCommandEvent
& event
);
154 #endif // wxUSE_TOOLTIPS
155 void OnIdle( wxIdleEvent
& event
);
156 void OnSize( wxSizeEvent
& event
);
159 DECLARE_EVENT_TABLE()
162 //----------------------------------------------------------------------
164 //----------------------------------------------------------------------
166 static void SetControlClientData(const char *name
,
167 wxControlWithItems
*control
);
171 //----------------------------------------------------------------------
173 //----------------------------------------------------------------------
182 MINIMAL_SET_TOOLTIP_DELAY
= 200,
183 MINIMAL_ENABLE_TOOLTIPS
188 // Create the main frame window
189 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
190 "Controls wxWindows App",
194 // The wxICON() macros loads an icon from a resource under Windows
195 // and uses an #included XPM image under GTK+ and Motif
197 frame
->SetIcon( wxICON(mondrian
) );
199 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
200 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
201 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
203 wxMenuBar
*menu_bar
= new wxMenuBar
;
204 menu_bar
->Append(file_menu
, "&File");
207 wxMenu
*tooltip_menu
= new wxMenu
;
208 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
209 tooltip_menu
->AppendSeparator();
210 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
211 "enable/disable tooltips", TRUE
);
212 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
213 menu_bar
->Append(tooltip_menu
, "&Tooltips");
214 #endif // wxUSE_TOOLTIPS
216 frame
->SetMenuBar(menu_bar
);
219 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
226 //----------------------------------------------------------------------
228 //----------------------------------------------------------------------
230 const int ID_NOTEBOOK
= 1000;
232 const int ID_LISTBOX
= 130;
233 const int ID_LISTBOX_SEL_NUM
= 131;
234 const int ID_LISTBOX_SEL_STR
= 132;
235 const int ID_LISTBOX_CLEAR
= 133;
236 const int ID_LISTBOX_APPEND
= 134;
237 const int ID_LISTBOX_DELETE
= 135;
238 const int ID_LISTBOX_FONT
= 136;
239 const int ID_LISTBOX_ENABLE
= 137;
240 const int ID_LISTBOX_SORTED
= 138;
242 const int ID_CHOICE
= 120;
243 const int ID_CHOICE_SEL_NUM
= 121;
244 const int ID_CHOICE_SEL_STR
= 122;
245 const int ID_CHOICE_CLEAR
= 123;
246 const int ID_CHOICE_APPEND
= 124;
247 const int ID_CHOICE_DELETE
= 125;
248 const int ID_CHOICE_FONT
= 126;
249 const int ID_CHOICE_ENABLE
= 127;
250 const int ID_CHOICE_SORTED
= 128;
252 const int ID_COMBO
= 140;
253 const int ID_COMBO_SEL_NUM
= 141;
254 const int ID_COMBO_SEL_STR
= 142;
255 const int ID_COMBO_CLEAR
= 143;
256 const int ID_COMBO_APPEND
= 144;
257 const int ID_COMBO_DELETE
= 145;
258 const int ID_COMBO_FONT
= 146;
259 const int ID_COMBO_ENABLE
= 147;
261 const int ID_RADIOBOX
= 160;
262 const int ID_RADIOBOX_SEL_NUM
= 161;
263 const int ID_RADIOBOX_SEL_STR
= 162;
264 const int ID_RADIOBOX_FONT
= 163;
265 const int ID_RADIOBOX_ENABLE
= 164;
267 const int ID_RADIOBUTTON_1
= 166;
268 const int ID_RADIOBUTTON_2
= 167;
270 const int ID_SET_FONT
= 170;
272 const int ID_GAUGE
= 180;
273 const int ID_SLIDER
= 181;
275 const int ID_SPIN
= 182;
276 const int ID_BTNPROGRESS
= 183;
277 const int ID_BUTTON_LABEL
= 184;
278 const int ID_SPINCTRL
= 185;
280 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
281 EVT_SIZE ( MyPanel::OnSize
)
282 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
283 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
284 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
285 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
286 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
287 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
288 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
289 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
290 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
291 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
292 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
293 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
294 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
295 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
296 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
297 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
298 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
299 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
300 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
301 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
302 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
303 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
304 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
305 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
306 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
307 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
308 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
309 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
310 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
311 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
312 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
313 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
314 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
315 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
316 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
317 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
319 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
320 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
321 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
322 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
323 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
324 #endif // wxUSE_SPINBUTTON
326 EVT_SPIN (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
327 #endif // wxUSE_SPINCTRL
328 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
331 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
332 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
333 m_text(NULL
), m_notebook(NULL
)
335 // SetBackgroundColour("cadet blue");
337 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
338 // m_text->SetBackgroundColour("wheat");
340 delete wxLog::SetActiveTarget(new wxLogStderr
);
342 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
357 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
360 // fill the image list
361 wxImageList
*imagelist
= new wxImageList(32, 32);
363 imagelist
-> Add( wxBitmap( list_xpm
));
364 imagelist
-> Add( wxBitmap( choice_xpm
));
365 imagelist
-> Add( wxBitmap( combo_xpm
));
366 imagelist
-> Add( wxBitmap( text_xpm
));
367 imagelist
-> Add( wxBitmap( radio_xpm
));
368 imagelist
-> Add( wxBitmap( gauge_xpm
));
369 m_notebook
->SetImageList(imagelist
);
370 #elif defined(__WXMSW__)
371 // load images from resources
374 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
376 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
378 static const char *s_iconNames
[Image_Max
] =
380 "list", "choice", "combo", "text", "radio", "gauge"
383 for ( size_t n
= 0; n
< Image_Max
; n
++ )
385 wxBitmap
bmp(s_iconNames
[n
]);
386 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
388 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
393 m_notebook
->SetImageList(imagelist
);
397 #define Image_List -1
398 #define Image_Choice -1
399 #define Image_Combo -1
400 #define Image_Text -1
401 #define Image_Radio -1
402 #define Image_Gauge -1
407 wxPanel
*panel
= new wxPanel(m_notebook
);
408 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
409 wxPoint(10,10), wxSize(120,70),
410 5, choices
, wxLB_ALWAYS_SB
);
411 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
412 wxPoint(10,90), wxSize(120,70),
413 5, choices
, wxLB_SORT
);
415 SetControlClientData("listbox", m_listbox
);
416 SetControlClientData("listbox", m_listboxSorted
);
418 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
420 m_listbox
->SetToolTip( "This is a list box" );
421 #endif // wxUSE_TOOLTIPS
423 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
424 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
425 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
426 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
427 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
428 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
430 button
->SetToolTip( "Press here to set italic font" );
431 #endif // wxUSE_TOOLTIPS
433 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
434 m_checkbox
->SetValue(FALSE
);
436 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
437 #endif // wxUSE_TOOLTIPS
438 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
440 panel
= new wxPanel(m_notebook
);
441 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
442 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
443 5, choices
, wxCB_SORT
);
445 SetControlClientData("choice", m_choice
);
446 SetControlClientData("choice", m_choiceSorted
);
448 m_choice
->SetSelection(2);
449 m_choice
->SetBackgroundColour( "red" );
450 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
451 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
452 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
453 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
454 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
455 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
456 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
458 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
460 panel
= new wxPanel(m_notebook
);
461 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
462 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
463 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
464 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
465 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
466 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
467 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
468 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
469 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
471 wxString choices2
[] =
475 "Fourth", "Fifth", "Sixth",
476 "Seventh", "Eighth", "Nineth", "Tenth" */
479 panel
= new wxPanel(m_notebook
);
480 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
481 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
482 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
483 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
484 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
485 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
486 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
487 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
488 rb
->SetValue( FALSE
);
489 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
490 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
492 panel
= new wxPanel(m_notebook
);
493 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
494 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
495 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
496 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
498 // No wrapping text in wxStaticText yet :-(
499 (void)new wxStaticText( panel
, -1,
505 (void)new wxStaticText( panel
, -1,
506 "In order see the gauge (aka progress bar)\n"
507 "control do something you have to drag the\n"
508 "handle of the slider to the right.\n"
510 "This is also supposed to demonstrate how\n"
511 "to use static controls.\n",
516 int initialSpinValue
= -5;
518 s
<< initialSpinValue
;
519 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
521 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
522 m_spinbutton
->SetRange(-10,30);
523 m_spinbutton
->SetValue(initialSpinValue
);
525 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
527 #endif // wxUSE_SPINBUTTON
530 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
531 m_spinctrl
->SetRange(10,30);
532 m_spinctrl
->SetValue(15);
533 #endif // wxUSE_SPINCTRL
535 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
537 panel
= new wxPanel(m_notebook
);
539 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
540 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
541 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
543 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
544 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
547 wxBitmap
bitmap( 100, 100 );
549 dc
.SelectObject( bitmap
);
550 dc
.SetPen(*wxGREEN_PEN
);
551 dc
.DrawEllipse(5, 5, 90, 90);
552 dc
.DrawText("Bitmap", 20, 20);
553 dc
.SelectObject( wxNullBitmap
);
555 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(100, 20));
556 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "Toggle label", wxPoint(250, 20));
557 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
558 wxPoint(250, 60), wxDefaultSize
,
559 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
561 m_notebook
->AddPage(panel
, "wxBitmapXXX");
563 // --------------- TEST CODE ----------------------
565 // layout constraints
567 panel
= new wxPanel(m_notebook
);
568 panel
->SetAutoLayout( TRUE
);
570 wxLayoutConstraints
*c
;
571 c
= new wxLayoutConstraints
;
572 c
->top
.SameAs( panel
, wxTop
, 10 );
574 c
->left
.SameAs( panel
, wxLeft
, 10 );
575 c
->width
.PercentOf( panel
, wxWidth
, 40 );
577 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
578 pMyButton
->SetConstraints( c
);
580 c
= new wxLayoutConstraints
;
581 c
->top
.SameAs( panel
, wxTop
, 10 );
582 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
583 c
->right
.SameAs( panel
, wxRight
, 10 );
584 c
->width
.PercentOf( panel
, wxWidth
, 40 );
586 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
587 pMyButton2
->SetConstraints( c
);
589 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
593 panel
= new wxPanel(m_notebook
);
594 panel
->SetAutoLayout( TRUE
);
596 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
598 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
599 sizer
->Add( 20,20, 1 );
600 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
602 panel
->SetSizer( sizer
);
604 m_notebook
->AddPage(panel
, "wxSizer");
606 // --------------- TEST CODE ----------------------
610 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
614 GetClientSize( &x
, &y
);
616 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
617 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
620 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
622 int selOld
= event
.GetOldSelection();
625 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
626 "page change from taking place - if you select\n"
627 "[No] the current page will stay the third one\n",
629 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
637 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
640 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
642 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
645 void MyPanel::OnListBox( wxCommandEvent
&event
)
647 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
650 m_text
->AppendText( "ListBox event selection string is: '" );
651 m_text
->AppendText( event
.GetString() );
652 m_text
->AppendText( "'\n" );
653 m_text
->AppendText( "ListBox control selection string is: '" );
654 m_text
->AppendText( listbox
->GetStringSelection() );
655 m_text
->AppendText( "'\n" );
657 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
658 m_text
->AppendText( "ListBox event client data string is: '" );
659 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
660 m_text
->AppendText( "'\n" );
661 m_text
->AppendText( "ListBox control client data string is: '" );
662 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
663 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
664 m_text
->AppendText( "'\n" );
667 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
669 m_text
->AppendText( "ListBox double click string is: " );
670 m_text
->AppendText( event
.GetString() );
671 m_text
->AppendText( "\n" );
674 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
676 switch (event
.GetId())
678 case ID_LISTBOX_ENABLE
:
680 m_text
->AppendText("Checkbox clicked.\n");
681 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
684 cb
->SetToolTip( "Click to enable listbox" );
686 cb
->SetToolTip( "Click to disable listbox" );
687 #endif // wxUSE_TOOLTIPS
688 m_listbox
->Enable( event
.GetInt() == 0 );
689 m_listboxSorted
->Enable( event
.GetInt() == 0 );
692 case ID_LISTBOX_SEL_NUM
:
694 m_listbox
->SetSelection( 2 );
695 m_listboxSorted
->SetSelection( 2 );
696 m_lbSelectThis
->WarpPointer( 40, 14 );
699 case ID_LISTBOX_SEL_STR
:
701 m_listbox
->SetStringSelection( "This" );
702 m_listboxSorted
->SetStringSelection( "This" );
703 m_lbSelectNum
->WarpPointer( 40, 14 );
706 case ID_LISTBOX_CLEAR
:
709 m_listboxSorted
->Clear();
712 case ID_LISTBOX_APPEND
:
714 m_listbox
->Append( "Hi!" );
715 m_listboxSorted
->Append( "Hi!" );
718 case ID_LISTBOX_DELETE
:
721 idx
= m_listbox
->GetSelection();
722 m_listbox
->Delete( idx
);
723 idx
= m_listboxSorted
->GetSelection();
724 m_listboxSorted
->Delete( idx
);
727 case ID_LISTBOX_FONT
:
729 m_listbox
->SetFont( *wxITALIC_FONT
);
730 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
731 m_checkbox
->SetFont( *wxITALIC_FONT
);
737 void MyPanel::OnChoice( wxCommandEvent
&event
)
739 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
742 m_text
->AppendText( "Choice event selection string is: '" );
743 m_text
->AppendText( event
.GetString() );
744 m_text
->AppendText( "'\n" );
745 m_text
->AppendText( "Choice control selection string is: '" );
746 m_text
->AppendText( choice
->GetStringSelection() );
747 m_text
->AppendText( "'\n" );
749 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
750 m_text
->AppendText( "Choice event client data string is: '" );
751 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
752 m_text
->AppendText( "'\n" );
753 m_text
->AppendText( "Choice control client data string is: '" );
754 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
755 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
756 m_text
->AppendText( "'\n" );
759 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
761 switch (event
.GetId())
763 case ID_CHOICE_ENABLE
:
765 m_choice
->Enable( event
.GetInt() == 0 );
766 m_choiceSorted
->Enable( event
.GetInt() == 0 );
769 case ID_CHOICE_SEL_NUM
:
771 m_choice
->SetSelection( 2 );
772 m_choiceSorted
->SetSelection( 2 );
775 case ID_CHOICE_SEL_STR
:
777 m_choice
->SetStringSelection( "This" );
778 m_choiceSorted
->SetStringSelection( "This" );
781 case ID_CHOICE_CLEAR
:
784 m_choiceSorted
->Clear();
787 case ID_CHOICE_APPEND
:
789 m_choice
->Append( "Hi!" );
790 m_choiceSorted
->Append( "Hi!" );
793 case ID_CHOICE_DELETE
:
795 int idx
= m_choice
->GetSelection();
796 m_choice
->Delete( idx
);
797 idx
= m_choiceSorted
->GetSelection();
798 m_choiceSorted
->Delete( idx
);
803 m_choice
->SetFont( *wxITALIC_FONT
);
804 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
810 void MyPanel::OnCombo( wxCommandEvent
&event
)
812 m_text
->AppendText( "ComboBox event selection string is: " );
813 m_text
->AppendText( event
.GetString() );
814 m_text
->AppendText( "\n" );
815 m_text
->AppendText( "ComboBox control selection string is: " );
816 m_text
->AppendText( m_combo
->GetStringSelection() );
817 m_text
->AppendText( "\n" );
820 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
822 switch (event
.GetId())
824 case ID_COMBO_ENABLE
:
826 m_combo
->Enable( event
.GetInt() == 0 );
829 case ID_COMBO_SEL_NUM
:
831 m_combo
->SetSelection( 2 );
834 case ID_COMBO_SEL_STR
:
836 m_combo
->SetStringSelection( "This" );
844 case ID_COMBO_APPEND
:
846 m_combo
->Append( "Hi!" );
849 case ID_COMBO_DELETE
:
851 int idx
= m_combo
->GetSelection();
852 m_combo
->Delete( idx
);
857 m_combo
->SetFont( *wxITALIC_FONT
);
863 void MyPanel::OnRadio( wxCommandEvent
&event
)
865 m_text
->AppendText( "RadioBox selection string is: " );
866 m_text
->AppendText( event
.GetString() );
867 m_text
->AppendText( "\n" );
870 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
872 switch (event
.GetId())
874 case ID_RADIOBOX_ENABLE
:
876 m_radio
->Enable( event
.GetInt() == 0 );
879 case ID_RADIOBOX_SEL_NUM
:
881 m_radio
->SetSelection( 2 );
884 case ID_RADIOBOX_SEL_STR
:
886 m_radio
->SetStringSelection( "This" );
889 case ID_RADIOBOX_FONT
:
891 m_radio
->SetFont( *wxITALIC_FONT
);
897 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
899 m_fontButton
->SetFont( *wxITALIC_FONT
);
900 m_text
->SetFont( *wxITALIC_FONT
);
903 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
905 static bool s_long
= TRUE
;
908 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
911 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
913 m_gauge
->SetValue( m_slider
->GetValue() );
918 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
921 s
.Printf(_T("Current value of spin ctrl is %d\n"), m_spinctrl
->GetValue());
922 m_text
->AppendText(s
);
925 #endif // wxUSE_SPINCTRL
928 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
931 value
.Printf( _T("Spin control up: current = %d\n"),
932 m_spinbutton
->GetValue());
934 if ( m_spinbutton
->GetValue() > 17 )
936 value
+= _T("Preventing the spin button from going above 17.\n");
941 m_text
->AppendText(value
);
944 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
947 value
.Printf( _T("Spin control down: current = %d\n"),
948 m_spinbutton
->GetValue());
950 if ( m_spinbutton
->GetValue() < -17 )
952 value
+= _T("Preventing the spin button from going below -17.\n");
957 m_text
->AppendText(value
);
960 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
963 value
.Printf( _T("%d"), event
.GetPosition() );
964 m_spintext
->SetValue( value
);
966 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
967 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
968 m_spinbutton
->GetValue());
970 m_text
->AppendText(value
);
973 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
975 event
.Enable( m_spinbutton
->GetValue() > 0 );
978 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
980 int max
= m_spinbutton
->GetValue();
981 wxProgressDialog
dialog("Progress dialog example",
982 "An informative message",
988 wxPD_ESTIMATED_TIME
|
989 wxPD_REMAINING_TIME
);
993 for ( int i
= 0; i
< max
&& cont
; i
++ )
998 cont
= dialog
.Update(i
, "That's all, folks!");
1000 else if ( i
== max
/ 2 )
1002 cont
= dialog
.Update(i
, "Only a half left!");
1006 cont
= dialog
.Update(i
);
1012 *m_text
<< "Progress dialog aborted!\n";
1016 *m_text
<< "Countdown from " << max
<< " finished.\n";
1020 #endif // wxUSE_SPINBUTTON
1024 delete m_notebook
->GetImageList();
1027 //----------------------------------------------------------------------
1029 //----------------------------------------------------------------------
1031 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1032 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1033 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1035 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1036 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1037 #endif // wxUSE_TOOLTIPS
1038 EVT_SIZE(MyFrame::OnSize
)
1039 EVT_IDLE(MyFrame::OnIdle
)
1042 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1043 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1047 (void)new MyPanel( this, 10, 10, 300, 100 );
1050 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1055 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1057 wxBeginBusyCursor();
1059 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1066 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1068 static long s_delay
= 5000;
1071 delay
.Printf( _T("%ld"), s_delay
);
1073 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1074 "Set tooltip delay",
1078 return; // cancelled
1080 wxSscanf(delay
, _T("%ld"), &s_delay
);
1082 wxToolTip::SetDelay(s_delay
);
1084 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1087 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1089 static bool s_enabled
= TRUE
;
1091 s_enabled
= !s_enabled
;
1093 wxToolTip::Enable(s_enabled
);
1095 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1099 void MyFrame::OnSize( wxSizeEvent
& event
)
1102 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
1103 SetStatusText(msg
, 1);
1108 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1110 // track the window which has the focus in the status bar
1111 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1112 wxWindow
*focus
= wxWindow::FindFocus();
1113 if ( focus
&& (focus
!= s_windowFocus
) )
1115 s_windowFocus
= focus
;
1120 _T("Focus: wxWindow = %p, HWND = %08x"),
1122 _T("Focus: wxWindow = %p"),
1126 , s_windowFocus
->GetHWND()
1134 static void SetControlClientData(const char *name
,
1135 wxControlWithItems
*control
)
1137 size_t count
= control
->GetCount();
1138 for ( size_t n
= 0; n
< count
; n
++ )
1141 s
.Printf("%s client data for '%s'",
1142 name
, control
->GetString(n
).c_str());
1144 control
->SetClientObject(n
, new wxStringClientData(s
));