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
);
100 void OnSpinUp( wxSpinEvent
&event
);
101 void OnSpinDown( wxSpinEvent
&event
);
102 void OnSpinUpdate( wxSpinEvent
&event
);
103 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
104 void OnShowProgress( wxCommandEvent
&event
);
105 #endif // wxUSE_SPINBUTTON
107 wxListBox
*m_listbox
,
115 wxButton
*m_fontButton
;
116 wxButton
*m_lbSelectNum
;
117 wxButton
*m_lbSelectThis
;
119 wxSpinButton
*m_spinbutton
;
120 wxButton
*m_btnProgress
;
121 #endif // wxUSE_SPINBUTTON
124 wxSpinCtrl
*m_spinctrl
;
125 #endif // wxUSE_SPINCTRL
127 wxTextCtrl
*m_spintext
;
128 wxCheckBox
*m_checkbox
;
131 wxNotebook
*m_notebook
;
134 DECLARE_EVENT_TABLE()
137 class MyFrame
: public wxFrame
140 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
142 void OnQuit(wxCommandEvent
& event
);
143 void OnAbout(wxCommandEvent
& event
);
145 void OnSetTooltipDelay(wxCommandEvent
& event
);
146 void OnToggleTooltips(wxCommandEvent
& event
);
147 #endif // wxUSE_TOOLTIPS
148 void OnIdle( wxIdleEvent
& event
);
149 void OnSize( wxSizeEvent
& event
);
152 DECLARE_EVENT_TABLE()
155 //----------------------------------------------------------------------
157 //----------------------------------------------------------------------
159 static void SetControlClientData(const char *name
,
160 wxControlWithItems
*control
);
164 //----------------------------------------------------------------------
166 //----------------------------------------------------------------------
175 MINIMAL_SET_TOOLTIP_DELAY
= 200,
176 MINIMAL_ENABLE_TOOLTIPS
181 // Create the main frame window
182 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
183 "Controls wxWindows App",
187 // The wxICON() macros loads an icon from a resource under Windows
188 // and uses an #included XPM image under GTK+ and Motif
190 frame
->SetIcon( wxICON(mondrian
) );
192 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
193 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
194 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
196 wxMenuBar
*menu_bar
= new wxMenuBar
;
197 menu_bar
->Append(file_menu
, "&File");
200 wxMenu
*tooltip_menu
= new wxMenu
;
201 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
202 tooltip_menu
->AppendSeparator();
203 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
204 "enable/disable tooltips", TRUE
);
205 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
206 menu_bar
->Append(tooltip_menu
, "&Tooltips");
207 #endif // wxUSE_TOOLTIPS
209 frame
->SetMenuBar(menu_bar
);
212 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
219 //----------------------------------------------------------------------
221 //----------------------------------------------------------------------
223 const int ID_NOTEBOOK
= 1000;
225 const int ID_LISTBOX
= 130;
226 const int ID_LISTBOX_SEL_NUM
= 131;
227 const int ID_LISTBOX_SEL_STR
= 132;
228 const int ID_LISTBOX_CLEAR
= 133;
229 const int ID_LISTBOX_APPEND
= 134;
230 const int ID_LISTBOX_DELETE
= 135;
231 const int ID_LISTBOX_FONT
= 136;
232 const int ID_LISTBOX_ENABLE
= 137;
233 const int ID_LISTBOX_SORTED
= 138;
235 const int ID_CHOICE
= 120;
236 const int ID_CHOICE_SEL_NUM
= 121;
237 const int ID_CHOICE_SEL_STR
= 122;
238 const int ID_CHOICE_CLEAR
= 123;
239 const int ID_CHOICE_APPEND
= 124;
240 const int ID_CHOICE_DELETE
= 125;
241 const int ID_CHOICE_FONT
= 126;
242 const int ID_CHOICE_ENABLE
= 127;
243 const int ID_CHOICE_SORTED
= 128;
245 const int ID_COMBO
= 140;
246 const int ID_COMBO_SEL_NUM
= 141;
247 const int ID_COMBO_SEL_STR
= 142;
248 const int ID_COMBO_CLEAR
= 143;
249 const int ID_COMBO_APPEND
= 144;
250 const int ID_COMBO_DELETE
= 145;
251 const int ID_COMBO_FONT
= 146;
252 const int ID_COMBO_ENABLE
= 147;
254 const int ID_RADIOBOX
= 160;
255 const int ID_RADIOBOX_SEL_NUM
= 161;
256 const int ID_RADIOBOX_SEL_STR
= 162;
257 const int ID_RADIOBOX_FONT
= 163;
258 const int ID_RADIOBOX_ENABLE
= 164;
260 const int ID_RADIOBUTTON_1
= 166;
261 const int ID_RADIOBUTTON_2
= 167;
263 const int ID_SET_FONT
= 170;
265 const int ID_GAUGE
= 180;
266 const int ID_SLIDER
= 181;
268 const int ID_SPIN
= 182;
269 const int ID_BTNPROGRESS
= 183;
271 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
272 EVT_SIZE ( MyPanel::OnSize
)
273 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
274 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
275 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
276 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
277 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
278 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
279 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
280 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
281 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
282 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
283 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
284 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
285 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
286 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
287 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
288 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
289 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
290 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
291 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
292 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
293 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
294 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
295 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
296 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
297 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
298 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
299 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
300 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
301 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
302 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
303 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
304 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
305 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
306 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
307 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
308 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
310 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
311 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
312 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
313 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
314 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
318 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
319 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
320 m_text(NULL
), m_notebook(NULL
)
322 // SetBackgroundColour("cadet blue");
324 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
325 // m_text->SetBackgroundColour("wheat");
327 delete wxLog::SetActiveTarget(new wxLogStderr
);
329 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
344 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
347 // fill the image list
348 wxImageList
*imagelist
= new wxImageList(32, 32);
350 imagelist
-> Add( wxBitmap( list_xpm
));
351 imagelist
-> Add( wxBitmap( choice_xpm
));
352 imagelist
-> Add( wxBitmap( combo_xpm
));
353 imagelist
-> Add( wxBitmap( text_xpm
));
354 imagelist
-> Add( wxBitmap( radio_xpm
));
355 imagelist
-> Add( wxBitmap( gauge_xpm
));
356 m_notebook
->SetImageList(imagelist
);
357 #elif defined(__WXMSW__)
358 // load images from resources
361 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
363 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
365 static const char *s_iconNames
[Image_Max
] =
367 "list", "choice", "combo", "text", "radio", "gauge"
370 for ( size_t n
= 0; n
< Image_Max
; n
++ )
372 wxBitmap
bmp(s_iconNames
[n
]);
373 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
375 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
380 m_notebook
->SetImageList(imagelist
);
384 #define Image_List -1
385 #define Image_Choice -1
386 #define Image_Combo -1
387 #define Image_Text -1
388 #define Image_Radio -1
389 #define Image_Gauge -1
394 wxPanel
*panel
= new wxPanel(m_notebook
);
395 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
396 wxPoint(10,10), wxSize(120,70),
397 5, choices
, wxLB_ALWAYS_SB
);
398 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
399 wxPoint(10,90), wxSize(120,70),
400 5, choices
, wxLB_SORT
);
402 SetControlClientData("listbox", m_listbox
);
403 SetControlClientData("listbox", m_listboxSorted
);
405 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
407 m_listbox
->SetToolTip( "This is a list box" );
408 #endif // wxUSE_TOOLTIPS
410 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
411 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
412 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
413 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
414 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
415 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
417 button
->SetToolTip( "Press here to set italic font" );
418 #endif // wxUSE_TOOLTIPS
420 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
421 m_checkbox
->SetValue(FALSE
);
423 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
424 #endif // wxUSE_TOOLTIPS
425 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
427 panel
= new wxPanel(m_notebook
);
428 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
429 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
430 5, choices
, wxCB_SORT
);
432 SetControlClientData("choice", m_choice
);
433 SetControlClientData("choice", m_choiceSorted
);
435 m_choice
->SetSelection(2);
436 m_choice
->SetBackgroundColour( "red" );
437 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
438 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
439 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
440 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
441 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
442 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
443 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
445 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
447 panel
= new wxPanel(m_notebook
);
448 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
449 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
450 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
451 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
452 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
453 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
454 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
455 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
456 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
458 wxString choices2
[] =
462 "Fourth", "Fifth", "Sixth",
463 "Seventh", "Eighth", "Nineth", "Tenth" */
466 panel
= new wxPanel(m_notebook
);
467 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
468 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
469 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
470 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
471 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
472 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
473 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
474 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
475 rb
->SetValue( FALSE
);
476 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
477 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
479 panel
= new wxPanel(m_notebook
);
480 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
481 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
482 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
483 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
485 // No wrapping text in wxStaticText yet :-(
486 (void)new wxStaticText( panel
, -1,
492 (void)new wxStaticText( panel
, -1,
493 "In order see the gauge (aka progress bar)\n"
494 "control do something you have to drag the\n"
495 "handle of the slider to the right.\n"
497 "This is also supposed to demonstrate how\n"
498 "to use static controls.\n",
503 int initialSpinValue
= -5;
505 s
<< initialSpinValue
;
506 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
508 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
509 m_spinbutton
->SetRange(-10,30);
510 m_spinbutton
->SetValue(initialSpinValue
);
512 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
514 #endif // wxUSE_SPINBUTTON
517 m_spinctrl
= new wxSpinCtrl( panel
, -1, wxPoint(200, 160), wxSize(80, -1) );
518 m_spinctrl
->SetRange(10,30);
519 m_spinctrl
->SetValue(15);
520 #endif // wxUSE_SPINCTRL
522 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
524 panel
= new wxPanel(m_notebook
);
526 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
527 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
528 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
530 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
531 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
534 wxBitmap
bitmap( 100, 100 );
536 dc
.SelectObject( bitmap
);
537 dc
.SetPen(*wxGREEN_PEN
);
538 dc
.DrawEllipse(5, 5, 90, 90);
539 dc
.DrawText("Bitmap", 20, 20);
540 dc
.SelectObject( wxNullBitmap
);
542 wxBitmapButton
*bmpBtn
= new wxBitmapButton
549 bmpBtn
= NULL
; // suppress warning
551 new wxButton(panel
, -1, "Another button", wxPoint(250, 20));
553 m_notebook
->AddPage(panel
, "wxBitmapXXX");
555 // --------------- TEST CODE ----------------------
557 // layout constraints
559 panel
= new wxPanel(m_notebook
);
560 panel
->SetAutoLayout( true );
562 wxLayoutConstraints
*c
;
563 c
= new wxLayoutConstraints
;
564 c
->top
.SameAs( panel
, wxTop
, 10 );
566 c
->left
.SameAs( panel
, wxLeft
, 10 );
567 c
->width
.PercentOf( panel
, wxWidth
, 40 );
569 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
570 pMyButton
->SetConstraints( c
);
572 c
= new wxLayoutConstraints
;
573 c
->top
.SameAs( panel
, wxTop
, 10 );
574 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
575 c
->right
.SameAs( panel
, wxRight
, 10 );
576 c
->width
.PercentOf( panel
, wxWidth
, 40 );
578 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
579 pMyButton2
->SetConstraints( c
);
581 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
585 panel
= new wxPanel(m_notebook
);
586 panel
->SetAutoLayout( true );
588 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
590 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
591 sizer
->Add( 20,20, 1 );
592 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
594 panel
->SetSizer( sizer
);
596 m_notebook
->AddPage(panel
, "wxSizer");
598 // --------------- TEST CODE ----------------------
602 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
606 GetClientSize( &x
, &y
);
608 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
609 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
612 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
614 int selOld
= event
.GetOldSelection();
617 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
618 "page change from taking place - if you select\n"
619 "[No] the current page will stay the third one\n",
621 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
629 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
632 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
634 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
637 void MyPanel::OnListBox( wxCommandEvent
&event
)
639 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
642 m_text
->AppendText( "ListBox event selection string is: '" );
643 m_text
->AppendText( event
.GetString() );
644 m_text
->AppendText( "'\n" );
645 m_text
->AppendText( "ListBox control selection string is: '" );
646 m_text
->AppendText( listbox
->GetStringSelection() );
647 m_text
->AppendText( "'\n" );
649 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
650 m_text
->AppendText( "ListBox event client data string is: '" );
651 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
652 m_text
->AppendText( "'\n" );
653 m_text
->AppendText( "ListBox control client data string is: '" );
654 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
655 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
656 m_text
->AppendText( "'\n" );
659 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
661 m_text
->AppendText( "ListBox double click string is: " );
662 m_text
->AppendText( event
.GetString() );
663 m_text
->AppendText( "\n" );
666 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
668 switch (event
.GetId())
670 case ID_LISTBOX_ENABLE
:
672 m_text
->AppendText("Checkbox clicked.\n");
673 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
676 cb
->SetToolTip( "Click to enable listbox" );
678 cb
->SetToolTip( "Click to disable listbox" );
679 #endif // wxUSE_TOOLTIPS
680 m_listbox
->Enable( event
.GetInt() == 0 );
681 m_listboxSorted
->Enable( event
.GetInt() == 0 );
684 case ID_LISTBOX_SEL_NUM
:
686 m_listbox
->SetSelection( 2 );
687 m_listboxSorted
->SetSelection( 2 );
688 m_lbSelectThis
->WarpPointer( 40, 14 );
691 case ID_LISTBOX_SEL_STR
:
693 m_listbox
->SetStringSelection( "This" );
694 m_listboxSorted
->SetStringSelection( "This" );
695 m_lbSelectNum
->WarpPointer( 40, 14 );
698 case ID_LISTBOX_CLEAR
:
701 m_listboxSorted
->Clear();
704 case ID_LISTBOX_APPEND
:
706 m_listbox
->Append( "Hi!" );
707 m_listboxSorted
->Append( "Hi!" );
710 case ID_LISTBOX_DELETE
:
713 idx
= m_listbox
->GetSelection();
714 m_listbox
->Delete( idx
);
715 idx
= m_listboxSorted
->GetSelection();
716 m_listboxSorted
->Delete( idx
);
719 case ID_LISTBOX_FONT
:
721 m_listbox
->SetFont( *wxITALIC_FONT
);
722 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
723 m_checkbox
->SetFont( *wxITALIC_FONT
);
729 void MyPanel::OnChoice( wxCommandEvent
&event
)
731 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
734 m_text
->AppendText( "Choice event selection string is: '" );
735 m_text
->AppendText( event
.GetString() );
736 m_text
->AppendText( "'\n" );
737 m_text
->AppendText( "Choice control selection string is: '" );
738 m_text
->AppendText( choice
->GetStringSelection() );
739 m_text
->AppendText( "'\n" );
741 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
742 m_text
->AppendText( "Choice event client data string is: '" );
743 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
744 m_text
->AppendText( "'\n" );
745 m_text
->AppendText( "Choice control client data string is: '" );
746 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
747 m_text
->AppendText( obj
? obj
->GetData() : wxString("none"));
748 m_text
->AppendText( "'\n" );
751 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
753 switch (event
.GetId())
755 case ID_CHOICE_ENABLE
:
757 m_choice
->Enable( event
.GetInt() == 0 );
758 m_choiceSorted
->Enable( event
.GetInt() == 0 );
761 case ID_CHOICE_SEL_NUM
:
763 m_choice
->SetSelection( 2 );
764 m_choiceSorted
->SetSelection( 2 );
767 case ID_CHOICE_SEL_STR
:
769 m_choice
->SetStringSelection( "This" );
770 m_choiceSorted
->SetStringSelection( "This" );
773 case ID_CHOICE_CLEAR
:
776 m_choiceSorted
->Clear();
779 case ID_CHOICE_APPEND
:
781 m_choice
->Append( "Hi!" );
782 m_choiceSorted
->Append( "Hi!" );
785 case ID_CHOICE_DELETE
:
787 int idx
= m_choice
->GetSelection();
788 m_choice
->Delete( idx
);
789 idx
= m_choiceSorted
->GetSelection();
790 m_choiceSorted
->Delete( idx
);
795 m_choice
->SetFont( *wxITALIC_FONT
);
796 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
802 void MyPanel::OnCombo( wxCommandEvent
&event
)
804 m_text
->AppendText( "ComboBox event selection string is: " );
805 m_text
->AppendText( event
.GetString() );
806 m_text
->AppendText( "\n" );
807 m_text
->AppendText( "ComboBox control selection string is: " );
808 m_text
->AppendText( m_combo
->GetStringSelection() );
809 m_text
->AppendText( "\n" );
812 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
814 switch (event
.GetId())
816 case ID_COMBO_ENABLE
:
818 m_combo
->Enable( event
.GetInt() == 0 );
821 case ID_COMBO_SEL_NUM
:
823 m_combo
->SetSelection( 2 );
826 case ID_COMBO_SEL_STR
:
828 m_combo
->SetStringSelection( "This" );
836 case ID_COMBO_APPEND
:
838 m_combo
->Append( "Hi!" );
841 case ID_COMBO_DELETE
:
843 int idx
= m_combo
->GetSelection();
844 m_combo
->Delete( idx
);
849 m_combo
->SetFont( *wxITALIC_FONT
);
855 void MyPanel::OnRadio( wxCommandEvent
&event
)
857 m_text
->AppendText( "RadioBox selection string is: " );
858 m_text
->AppendText( event
.GetString() );
859 m_text
->AppendText( "\n" );
862 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
864 switch (event
.GetId())
866 case ID_RADIOBOX_ENABLE
:
868 m_radio
->Enable( event
.GetInt() == 0 );
871 case ID_RADIOBOX_SEL_NUM
:
873 m_radio
->SetSelection( 2 );
876 case ID_RADIOBOX_SEL_STR
:
878 m_radio
->SetStringSelection( "This" );
881 case ID_RADIOBOX_FONT
:
883 m_radio
->SetFont( *wxITALIC_FONT
);
889 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
891 m_fontButton
->SetFont( *wxITALIC_FONT
);
892 m_text
->SetFont( *wxITALIC_FONT
);
895 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
897 m_gauge
->SetValue( m_slider
->GetValue() );
901 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
904 value
.Printf( _T("Spin control up: current = %d\n"),
905 m_spinbutton
->GetValue());
907 if ( m_spinbutton
->GetValue() > 17 )
909 value
+= _T("Preventing the spin button from going above 17.\n");
914 m_text
->AppendText(value
);
917 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
920 value
.Printf( _T("Spin control down: current = %d\n"),
921 m_spinbutton
->GetValue());
923 if ( m_spinbutton
->GetValue() < -17 )
925 value
+= _T("Preventing the spin button from going below -17.\n");
930 m_text
->AppendText(value
);
933 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
936 value
.Printf( _T("%d"), event
.GetPosition() );
937 m_spintext
->SetValue( value
);
939 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
940 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
941 m_spinbutton
->GetValue());
943 m_text
->AppendText(value
);
946 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
948 event
.Enable( m_spinbutton
->GetValue() > 0 );
951 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
953 int max
= m_spinbutton
->GetValue();
954 wxProgressDialog
dialog("Progress dialog example",
955 "An informative message",
961 wxPD_ESTIMATED_TIME
|
962 wxPD_REMAINING_TIME
);
966 for ( int i
= 0; i
< max
&& cont
; i
++ )
971 cont
= dialog
.Update(i
, "That's all, folks!");
973 else if ( i
== max
/ 2 )
975 cont
= dialog
.Update(i
, "Only a half left!");
979 cont
= dialog
.Update(i
);
985 *m_text
<< "Progress dialog aborted!\n";
989 *m_text
<< "Countdown from " << max
<< " finished.\n";
993 #endif // wxUSE_SPINBUTTON
997 delete m_notebook
->GetImageList();
1000 //----------------------------------------------------------------------
1002 //----------------------------------------------------------------------
1004 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1005 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1006 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1008 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1009 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1010 #endif // wxUSE_TOOLTIPS
1011 EVT_SIZE(MyFrame::OnSize
)
1012 EVT_IDLE(MyFrame::OnIdle
)
1015 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1016 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1020 (void)new MyPanel( this, 10, 10, 300, 100 );
1023 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1028 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1030 wxBeginBusyCursor();
1032 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1039 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1041 static long s_delay
= 5000;
1044 delay
.Printf( _T("%ld"), s_delay
);
1046 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1047 "Set tooltip delay",
1051 return; // cancelled
1053 wxSscanf(delay
, _T("%ld"), &s_delay
);
1055 wxToolTip::SetDelay(s_delay
);
1057 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1060 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1062 static bool s_enabled
= TRUE
;
1064 s_enabled
= !s_enabled
;
1066 wxToolTip::Enable(s_enabled
);
1068 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1072 void MyFrame::OnSize( wxSizeEvent
& event
)
1075 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
1076 SetStatusText(msg
, 1);
1081 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1083 // track the window which has the focus in the status bar
1084 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1085 wxWindow
*focus
= wxWindow::FindFocus();
1086 if ( focus
&& (focus
!= s_windowFocus
) )
1088 s_windowFocus
= focus
;
1093 _T("Focus: wxWindow = %p, HWND = %08x"),
1095 _T("Focus: wxWindow = %p"),
1099 , s_windowFocus
->GetHWND()
1107 static void SetControlClientData(const char *name
,
1108 wxControlWithItems
*control
)
1110 size_t count
= control
->GetCount();
1111 for ( size_t n
= 0; n
< count
; n
++ )
1114 s
.Printf("%s client data for '%s'",
1115 name
, control
->GetString(n
).c_str());
1117 control
->SetClientObject(n
, new wxStringClientData(s
));