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
;
114 wxButton
*m_fontButton
;
115 wxButton
*m_lbSelectNum
;
116 wxButton
*m_lbSelectThis
;
118 wxSpinButton
*m_spinbutton
;
119 wxButton
*m_btnProgress
;
120 #endif // wxUSE_SPINBUTTON
123 wxSpinCtrl
*m_spinctrl
;
124 #endif // wxUSE_SPINCTRL
126 wxTextCtrl
*m_spintext
;
127 wxCheckBox
*m_checkbox
;
130 wxNotebook
*m_notebook
;
133 DECLARE_EVENT_TABLE()
136 class MyFrame
: public wxFrame
139 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
141 void OnQuit(wxCommandEvent
& event
);
142 void OnAbout(wxCommandEvent
& event
);
144 void OnSetTooltipDelay(wxCommandEvent
& event
);
145 void OnToggleTooltips(wxCommandEvent
& event
);
146 #endif // wxUSE_TOOLTIPS
147 void OnIdle( wxIdleEvent
& event
);
148 void OnSize( wxSizeEvent
& event
);
151 DECLARE_EVENT_TABLE()
154 //----------------------------------------------------------------------
156 //----------------------------------------------------------------------
160 //----------------------------------------------------------------------
162 //----------------------------------------------------------------------
171 MINIMAL_SET_TOOLTIP_DELAY
= 200,
172 MINIMAL_ENABLE_TOOLTIPS
177 // Create the main frame window
178 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
179 "Controls wxWindows App",
183 // The wxICON() macros loads an icon from a resource under Windows
184 // and uses an #included XPM image under GTK+ and Motif
186 frame
->SetIcon( wxICON(mondrian
) );
188 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
189 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
190 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
192 wxMenuBar
*menu_bar
= new wxMenuBar
;
193 menu_bar
->Append(file_menu
, "&File");
196 wxMenu
*tooltip_menu
= new wxMenu
;
197 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
198 tooltip_menu
->AppendSeparator();
199 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
200 "enable/disable tooltips", TRUE
);
201 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
202 menu_bar
->Append(tooltip_menu
, "&Tooltips");
203 #endif // wxUSE_TOOLTIPS
205 frame
->SetMenuBar(menu_bar
);
208 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
215 //----------------------------------------------------------------------
217 //----------------------------------------------------------------------
219 const int ID_NOTEBOOK
= 1000;
221 const int ID_LISTBOX
= 130;
222 const int ID_LISTBOX_SEL_NUM
= 131;
223 const int ID_LISTBOX_SEL_STR
= 132;
224 const int ID_LISTBOX_CLEAR
= 133;
225 const int ID_LISTBOX_APPEND
= 134;
226 const int ID_LISTBOX_DELETE
= 135;
227 const int ID_LISTBOX_FONT
= 136;
228 const int ID_LISTBOX_ENABLE
= 137;
230 const int ID_CHOICE
= 120;
231 const int ID_CHOICE_SEL_NUM
= 121;
232 const int ID_CHOICE_SEL_STR
= 122;
233 const int ID_CHOICE_CLEAR
= 123;
234 const int ID_CHOICE_APPEND
= 124;
235 const int ID_CHOICE_DELETE
= 125;
236 const int ID_CHOICE_FONT
= 126;
237 const int ID_CHOICE_ENABLE
= 127;
238 const int ID_CHOICE_SORTED
= 128;
240 const int ID_COMBO
= 140;
241 const int ID_COMBO_SEL_NUM
= 141;
242 const int ID_COMBO_SEL_STR
= 142;
243 const int ID_COMBO_CLEAR
= 143;
244 const int ID_COMBO_APPEND
= 144;
245 const int ID_COMBO_DELETE
= 145;
246 const int ID_COMBO_FONT
= 146;
247 const int ID_COMBO_ENABLE
= 147;
249 const int ID_RADIOBOX
= 160;
250 const int ID_RADIOBOX_SEL_NUM
= 161;
251 const int ID_RADIOBOX_SEL_STR
= 162;
252 const int ID_RADIOBOX_FONT
= 163;
253 const int ID_RADIOBOX_ENABLE
= 164;
255 const int ID_RADIOBUTTON_1
= 166;
256 const int ID_RADIOBUTTON_2
= 167;
258 const int ID_SET_FONT
= 170;
260 const int ID_GAUGE
= 180;
261 const int ID_SLIDER
= 181;
263 const int ID_SPIN
= 182;
264 const int ID_BTNPROGRESS
= 183;
266 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
267 EVT_SIZE ( MyPanel::OnSize
)
268 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
269 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
270 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
271 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
272 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
273 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
274 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
275 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
276 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
277 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
278 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
279 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
280 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
281 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
282 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
283 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
284 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
285 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
286 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
287 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
288 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
289 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
290 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
291 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
292 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
293 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
294 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
295 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
296 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
297 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
298 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
299 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
300 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
301 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
302 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
304 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
305 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
306 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
307 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
308 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
312 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
313 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
314 m_text(NULL
), m_notebook(NULL
)
316 // SetBackgroundColour("cadet blue");
318 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
319 // m_text->SetBackgroundColour("wheat");
321 delete wxLog::SetActiveTarget(new wxLogStderr
);
323 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
338 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
341 // fill the image list
342 wxImageList
*imagelist
= new wxImageList(32, 32);
344 imagelist
-> Add( wxBitmap( list_xpm
));
345 imagelist
-> Add( wxBitmap( choice_xpm
));
346 imagelist
-> Add( wxBitmap( combo_xpm
));
347 imagelist
-> Add( wxBitmap( text_xpm
));
348 imagelist
-> Add( wxBitmap( radio_xpm
));
349 imagelist
-> Add( wxBitmap( gauge_xpm
));
350 m_notebook
->SetImageList(imagelist
);
351 #elif defined(__WXMSW__)
352 // load images from resources
355 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
357 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
359 static const char *s_iconNames
[Image_Max
] =
361 "list", "choice", "combo", "text", "radio", "gauge"
364 for ( size_t n
= 0; n
< Image_Max
; n
++ )
366 wxBitmap
bmp(s_iconNames
[n
]);
367 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
369 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
374 m_notebook
->SetImageList(imagelist
);
378 #define Image_List -1
379 #define Image_Choice -1
380 #define Image_Combo -1
381 #define Image_Text -1
382 #define Image_Radio -1
383 #define Image_Gauge -1
388 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
389 wxPanel
*panel
= (wxPanel
*) NULL
;
391 panel
= new wxPanel(m_notebook
);
392 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
393 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
395 m_listbox
->SetToolTip( "This is a list box" );
396 #endif // wxUSE_TOOLTIPS
398 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
399 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
400 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
401 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
402 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
403 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
405 button
->SetToolTip( "Press here to set italic font" );
406 #endif // wxUSE_TOOLTIPS
408 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130) );
409 m_checkbox
->SetValue(FALSE
);
411 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
412 #endif // wxUSE_TOOLTIPS
413 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
415 panel
= new wxPanel(m_notebook
);
416 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
417 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
418 5, choices
, wxCB_SORT
);
419 m_choice
->SetSelection(2);
420 m_choice
->SetBackgroundColour( "red" );
421 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
422 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
423 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
424 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
425 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
426 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
427 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
429 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
431 panel
= new wxPanel(m_notebook
);
432 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
433 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
434 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
435 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
436 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
437 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
438 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
439 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
440 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
442 wxString choices2
[] =
446 "Fourth", "Fifth", "Sixth",
447 "Seventh", "Eighth", "Nineth", "Tenth" */
450 panel
= new wxPanel(m_notebook
);
451 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
452 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
453 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
454 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
455 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
456 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
457 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
458 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
459 rb
->SetValue( FALSE
);
460 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
461 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
463 panel
= new wxPanel(m_notebook
);
464 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
465 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
466 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
467 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
469 // No wrapping text in wxStaticText yet :-(
470 (void)new wxStaticText( panel
, -1,
476 (void)new wxStaticText( panel
, -1,
477 "In order see the gauge (aka progress bar)\n"
478 "control do something you have to drag the\n"
479 "handle of the slider to the right.\n"
481 "This is also supposed to demonstrate how\n"
482 "to use static controls.\n",
487 int initialSpinValue
= -5;
489 s
<< initialSpinValue
;
490 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
492 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
493 m_spinbutton
->SetRange(-10,30);
494 m_spinbutton
->SetValue(initialSpinValue
);
496 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
498 #endif // wxUSE_SPINBUTTON
501 m_spinctrl
= new wxSpinCtrl( panel
, -1, wxPoint(200, 160), wxSize(80, -1) );
502 m_spinctrl
->SetRange(10,30);
503 m_spinctrl
->SetValue(15);
504 #endif // wxUSE_SPINCTRL
506 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
508 panel
= new wxPanel(m_notebook
);
510 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
511 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
512 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
514 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
515 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
518 wxBitmap
bitmap( 100, 100 );
520 dc
.SelectObject( bitmap
);
521 dc
.SetPen(*wxGREEN_PEN
);
522 dc
.DrawEllipse(5, 5, 90, 90);
523 dc
.DrawText("Bitmap", 20, 20);
524 dc
.SelectObject( wxNullBitmap
);
526 wxBitmapButton
*bmpBtn
= new wxBitmapButton
533 bmpBtn
= NULL
; // suppress warning
535 new wxButton(panel
, -1, "Another button", wxPoint(250, 20));
537 m_notebook
->AddPage(panel
, "wxBitmapXXX");
539 // --------------- TEST CODE ----------------------
541 panel
= new wxPanel(m_notebook
);
542 panel
->SetAutoLayout( true );
544 wxLayoutConstraints
*c
;
545 c
= new wxLayoutConstraints
;
546 c
->top
.SameAs( panel
, wxTop
, 10 );
548 c
->left
.SameAs( panel
, wxLeft
, 10 );
549 c
->width
.PercentOf( panel
, wxWidth
, 40 );
551 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
552 pMyButton
->SetConstraints( c
);
554 c
= new wxLayoutConstraints
;
555 c
->top
.SameAs( panel
, wxTop
, 10 );
556 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
557 c
->right
.SameAs( panel
, wxRight
, 10 );
558 c
->width
.PercentOf( panel
, wxWidth
, 40 );
560 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
561 pMyButton2
->SetConstraints( c
);
563 m_notebook
->AddPage(panel
, "test layout");
565 // --------------- TEST CODE ----------------------
569 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
573 GetClientSize( &x
, &y
);
575 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
576 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
579 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
581 int selOld
= event
.GetOldSelection();
584 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
585 "page change from taking place - if you select\n"
586 "[No] the current page will stay the third one\n",
588 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
596 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
599 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
601 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
604 void MyPanel::OnListBox( wxCommandEvent
&event
)
606 m_text
->AppendText( "ListBox event selection string is: " );
607 m_text
->AppendText( event
.GetString() );
608 m_text
->AppendText( "\n" );
609 m_text
->AppendText( "ListBox control selection string is: " );
610 m_text
->AppendText( m_listbox
->GetStringSelection() );
611 m_text
->AppendText( "\n" );
614 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
616 m_text
->AppendText( "ListBox double click string is: " );
617 m_text
->AppendText( event
.GetString() );
618 m_text
->AppendText( "\n" );
621 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
623 switch (event
.GetId())
625 case ID_LISTBOX_ENABLE
:
627 m_text
->AppendText("Checkbox clicked.\n");
628 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
631 cb
->SetToolTip( "Click to enable listbox" );
633 cb
->SetToolTip( "Click to disable listbox" );
634 #endif // wxUSE_TOOLTIPS
635 m_listbox
->Enable( event
.GetInt() == 0 );
638 case ID_LISTBOX_SEL_NUM
:
640 m_listbox
->SetSelection( 2 );
641 m_lbSelectThis
->WarpPointer( 40, 14 );
644 case ID_LISTBOX_SEL_STR
:
646 m_listbox
->SetStringSelection( "This" );
647 m_lbSelectNum
->WarpPointer( 40, 14 );
650 case ID_LISTBOX_CLEAR
:
655 case ID_LISTBOX_APPEND
:
657 m_listbox
->Append( "Hi!" );
660 case ID_LISTBOX_DELETE
:
662 int idx
= m_listbox
->GetSelection();
663 m_listbox
->Delete( idx
);
666 case ID_LISTBOX_FONT
:
668 m_listbox
->SetFont( *wxITALIC_FONT
);
669 m_checkbox
->SetFont( *wxITALIC_FONT
);
675 void MyPanel::OnChoice( wxCommandEvent
&event
)
677 m_text
->AppendText( "Choice event selection string is: " );
678 m_text
->AppendText( event
.GetString() );
679 m_text
->AppendText( "\n" );
680 m_text
->AppendText( "Choice control selection string is: '" );
681 m_text
->AppendText( m_choice
->GetStringSelection() );
682 m_text
->AppendText( "' (for unsorted control)\nand '" );
683 m_text
->AppendText( m_choiceSorted
->GetStringSelection() );
684 m_text
->AppendText( "' (for sorted control)\n" );
687 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
689 switch (event
.GetId())
691 case ID_CHOICE_ENABLE
:
693 m_choice
->Enable( event
.GetInt() == 0 );
694 m_choiceSorted
->Enable( event
.GetInt() == 0 );
697 case ID_CHOICE_SEL_NUM
:
699 m_choice
->SetSelection( 2 );
700 m_choiceSorted
->SetSelection( 2 );
703 case ID_CHOICE_SEL_STR
:
705 m_choice
->SetStringSelection( "This" );
706 m_choiceSorted
->SetStringSelection( "This" );
709 case ID_CHOICE_CLEAR
:
712 m_choiceSorted
->Clear();
715 case ID_CHOICE_APPEND
:
717 m_choice
->Append( "Hi!" );
718 m_choiceSorted
->Append( "Hi!" );
721 case ID_CHOICE_DELETE
:
723 int idx
= m_choice
->GetSelection();
724 m_choice
->Delete( idx
);
725 idx
= m_choiceSorted
->GetSelection();
726 m_choiceSorted
->Delete( idx
);
731 m_choice
->SetFont( *wxITALIC_FONT
);
732 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
738 void MyPanel::OnCombo( wxCommandEvent
&event
)
740 m_text
->AppendText( "ComboBox event selection string is: " );
741 m_text
->AppendText( event
.GetString() );
742 m_text
->AppendText( "\n" );
743 m_text
->AppendText( "ComboBox control selection string is: " );
744 m_text
->AppendText( m_combo
->GetStringSelection() );
745 m_text
->AppendText( "\n" );
748 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
750 switch (event
.GetId())
752 case ID_COMBO_ENABLE
:
754 m_combo
->Enable( event
.GetInt() == 0 );
757 case ID_COMBO_SEL_NUM
:
759 m_combo
->SetSelection( 2 );
762 case ID_COMBO_SEL_STR
:
764 m_combo
->SetStringSelection( "This" );
772 case ID_COMBO_APPEND
:
774 m_combo
->Append( "Hi!" );
777 case ID_COMBO_DELETE
:
779 int idx
= m_combo
->GetSelection();
780 m_combo
->Delete( idx
);
785 m_combo
->SetFont( *wxITALIC_FONT
);
791 void MyPanel::OnRadio( wxCommandEvent
&event
)
793 m_text
->AppendText( "RadioBox selection string is: " );
794 m_text
->AppendText( event
.GetString() );
795 m_text
->AppendText( "\n" );
798 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
800 switch (event
.GetId())
802 case ID_RADIOBOX_ENABLE
:
804 m_radio
->Enable( event
.GetInt() == 0 );
807 case ID_RADIOBOX_SEL_NUM
:
809 m_radio
->SetSelection( 2 );
812 case ID_RADIOBOX_SEL_STR
:
814 m_radio
->SetStringSelection( "This" );
817 case ID_RADIOBOX_FONT
:
819 m_radio
->SetFont( *wxITALIC_FONT
);
825 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
827 m_fontButton
->SetFont( *wxITALIC_FONT
);
828 m_text
->SetFont( *wxITALIC_FONT
);
831 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
833 m_gauge
->SetValue( m_slider
->GetValue() );
837 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
840 value
.Printf( _T("Spin control up: current = %d\n"),
841 m_spinbutton
->GetValue());
843 if ( m_spinbutton
->GetValue() > 17 )
845 value
+= _T("Preventing the spin button from going above 17.\n");
850 m_text
->AppendText(value
);
853 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
856 value
.Printf( _T("Spin control down: current = %d\n"),
857 m_spinbutton
->GetValue());
859 if ( m_spinbutton
->GetValue() < -17 )
861 value
+= _T("Preventing the spin button from going below -17.\n");
866 m_text
->AppendText(value
);
869 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
872 value
.Printf( _T("%d"), event
.GetPosition() );
873 m_spintext
->SetValue( value
);
875 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
876 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
877 m_spinbutton
->GetValue());
879 m_text
->AppendText(value
);
882 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
884 event
.Enable( m_spinbutton
->GetValue() > 0 );
887 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
889 int max
= m_spinbutton
->GetValue();
890 wxProgressDialog
dialog("Progress dialog example",
891 "An informative message",
897 wxPD_ESTIMATED_TIME
|
898 wxPD_REMAINING_TIME
);
902 for ( int i
= 0; i
< max
&& cont
; i
++ )
907 cont
= dialog
.Update(i
, "That's all, folks!");
909 else if ( i
== max
/ 2 )
911 cont
= dialog
.Update(i
, "Only a half left!");
915 cont
= dialog
.Update(i
);
921 *m_text
<< "Progress dialog aborted!\n";
925 *m_text
<< "Countdown from " << max
<< " finished.\n";
929 #endif // wxUSE_SPINBUTTON
933 delete m_notebook
->GetImageList();
936 //----------------------------------------------------------------------
938 //----------------------------------------------------------------------
940 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
941 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
942 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
944 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
945 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
946 #endif // wxUSE_TOOLTIPS
947 EVT_SIZE(MyFrame::OnSize
)
948 EVT_IDLE(MyFrame::OnIdle
)
951 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
952 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
956 (void)new MyPanel( this, 10, 10, 300, 100 );
959 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
964 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
968 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
975 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
977 static long s_delay
= 5000;
980 delay
.Printf( _T("%ld"), s_delay
);
982 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
989 wxSscanf(delay
, _T("%ld"), &s_delay
);
991 wxToolTip::SetDelay(s_delay
);
993 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
996 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
998 static bool s_enabled
= TRUE
;
1000 s_enabled
= !s_enabled
;
1002 wxToolTip::Enable(s_enabled
);
1004 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1008 void MyFrame::OnSize( wxSizeEvent
& event
)
1011 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
1012 SetStatusText(msg
, 1);
1017 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1019 // track the window which has the focus in the status bar
1020 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1021 wxWindow
*focus
= wxWindow::FindFocus();
1022 if ( focus
&& (focus
!= s_windowFocus
) )
1024 s_windowFocus
= focus
;
1029 _T("Focus: wxWindow = %p, HWND = %08x"),
1031 _T("Focus: wxWindow = %p"),
1035 , s_windowFocus
->GetHWND()