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
;
113 wxButton
*m_fontButton
;
114 wxButton
*m_lbSelectNum
;
115 wxButton
*m_lbSelectThis
;
117 wxSpinButton
*m_spinbutton
;
118 wxButton
*m_btnProgress
;
119 #endif // wxUSE_SPINBUTTON
122 wxSpinCtrl
*m_spinctrl
;
123 #endif // wxUSE_SPINCTRL
125 wxTextCtrl
*m_spintext
;
126 wxCheckBox
*m_checkbox
;
129 wxNotebook
*m_notebook
;
132 DECLARE_EVENT_TABLE()
135 class MyFrame
: public wxFrame
138 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
140 void OnQuit(wxCommandEvent
& event
);
141 void OnAbout(wxCommandEvent
& event
);
143 void OnSetTooltipDelay(wxCommandEvent
& event
);
144 void OnToggleTooltips(wxCommandEvent
& event
);
145 #endif // wxUSE_TOOLTIPS
146 void OnIdle( wxIdleEvent
& event
);
147 void OnSize( wxSizeEvent
& event
);
150 DECLARE_EVENT_TABLE()
153 //----------------------------------------------------------------------
155 //----------------------------------------------------------------------
159 //----------------------------------------------------------------------
161 //----------------------------------------------------------------------
170 MINIMAL_SET_TOOLTIP_DELAY
= 200,
171 MINIMAL_ENABLE_TOOLTIPS
176 // Create the main frame window
177 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
178 "Controls wxWindows App",
182 // The wxICON() macros loads an icon from a resource under Windows
183 // and uses an #included XPM image under GTK+ and Motif
185 frame
->SetIcon( wxICON(mondrian
) );
187 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
188 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
189 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
191 wxMenuBar
*menu_bar
= new wxMenuBar
;
192 menu_bar
->Append(file_menu
, "&File");
195 wxMenu
*tooltip_menu
= new wxMenu
;
196 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
197 tooltip_menu
->AppendSeparator();
198 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
199 "enable/disable tooltips", TRUE
);
200 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
201 menu_bar
->Append(tooltip_menu
, "&Tooltips");
202 #endif // wxUSE_TOOLTIPS
204 frame
->SetMenuBar(menu_bar
);
207 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
214 //----------------------------------------------------------------------
216 //----------------------------------------------------------------------
218 const int ID_NOTEBOOK
= 1000;
220 const int ID_LISTBOX
= 130;
221 const int ID_LISTBOX_SEL_NUM
= 131;
222 const int ID_LISTBOX_SEL_STR
= 132;
223 const int ID_LISTBOX_CLEAR
= 133;
224 const int ID_LISTBOX_APPEND
= 134;
225 const int ID_LISTBOX_DELETE
= 135;
226 const int ID_LISTBOX_FONT
= 136;
227 const int ID_LISTBOX_ENABLE
= 137;
229 const int ID_CHOICE
= 120;
230 const int ID_CHOICE_SEL_NUM
= 121;
231 const int ID_CHOICE_SEL_STR
= 122;
232 const int ID_CHOICE_CLEAR
= 123;
233 const int ID_CHOICE_APPEND
= 124;
234 const int ID_CHOICE_DELETE
= 125;
235 const int ID_CHOICE_FONT
= 126;
236 const int ID_CHOICE_ENABLE
= 127;
238 const int ID_COMBO
= 140;
239 const int ID_COMBO_SEL_NUM
= 141;
240 const int ID_COMBO_SEL_STR
= 142;
241 const int ID_COMBO_CLEAR
= 143;
242 const int ID_COMBO_APPEND
= 144;
243 const int ID_COMBO_DELETE
= 145;
244 const int ID_COMBO_FONT
= 146;
245 const int ID_COMBO_ENABLE
= 147;
247 const int ID_RADIOBOX
= 160;
248 const int ID_RADIOBOX_SEL_NUM
= 161;
249 const int ID_RADIOBOX_SEL_STR
= 162;
250 const int ID_RADIOBOX_FONT
= 163;
251 const int ID_RADIOBOX_ENABLE
= 164;
253 const int ID_RADIOBUTTON_1
= 166;
254 const int ID_RADIOBUTTON_2
= 167;
256 const int ID_SET_FONT
= 170;
258 const int ID_GAUGE
= 180;
259 const int ID_SLIDER
= 181;
261 const int ID_SPIN
= 182;
262 const int ID_BTNPROGRESS
= 183;
264 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
265 EVT_SIZE ( MyPanel::OnSize
)
266 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
267 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
268 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
269 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
270 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
271 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
272 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
273 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
274 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
275 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
276 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
277 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
278 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
279 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
280 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
281 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
282 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
283 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
284 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
285 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
286 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
287 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
288 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
289 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
290 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
291 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
292 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
293 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
294 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
295 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
296 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
297 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
298 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
299 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
301 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
302 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
303 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
304 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
305 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
309 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
310 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
311 m_text(NULL
), m_notebook(NULL
)
313 // SetBackgroundColour("cadet blue");
315 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
316 // m_text->SetBackgroundColour("wheat");
318 delete wxLog::SetActiveTarget(new wxLogStderr
);
320 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
335 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
338 // fill the image list
339 wxImageList
*imagelist
= new wxImageList(32, 32);
341 imagelist
-> Add( wxBitmap( list_xpm
));
342 imagelist
-> Add( wxBitmap( choice_xpm
));
343 imagelist
-> Add( wxBitmap( combo_xpm
));
344 imagelist
-> Add( wxBitmap( text_xpm
));
345 imagelist
-> Add( wxBitmap( radio_xpm
));
346 imagelist
-> Add( wxBitmap( gauge_xpm
));
347 m_notebook
->SetImageList(imagelist
);
348 #elif defined(__WXMSW__)
349 // load images from resources
352 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
354 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
356 static const char *s_iconNames
[Image_Max
] =
358 "list", "choice", "combo", "text", "radio", "gauge"
361 for ( size_t n
= 0; n
< Image_Max
; n
++ )
363 wxBitmap
bmp(s_iconNames
[n
]);
364 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
366 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
371 m_notebook
->SetImageList(imagelist
);
375 #define Image_List -1
376 #define Image_Choice -1
377 #define Image_Combo -1
378 #define Image_Text -1
379 #define Image_Radio -1
380 #define Image_Gauge -1
385 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
386 wxPanel
*panel
= (wxPanel
*) NULL
;
388 panel
= new wxPanel(m_notebook
);
389 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
390 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
392 m_listbox
->SetToolTip( "This is a list box" );
393 #endif // wxUSE_TOOLTIPS
395 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
396 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
397 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
398 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
399 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
400 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
402 button
->SetToolTip( "Press here to set italic font" );
403 #endif // wxUSE_TOOLTIPS
405 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130) );
406 m_checkbox
->SetValue(FALSE
);
408 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
409 #endif // wxUSE_TOOLTIPS
410 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
412 panel
= new wxPanel(m_notebook
);
413 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
414 m_choice
->SetSelection(2);
415 m_choice
->SetBackgroundColour( "red" );
416 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
417 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
418 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
419 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
420 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
421 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
422 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
424 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
426 panel
= new wxPanel(m_notebook
);
427 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
428 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
429 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
430 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
431 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
432 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
433 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
434 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
435 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
437 wxString choices2
[] =
441 "Fourth", "Fifth", "Sixth",
442 "Seventh", "Eighth", "Nineth", "Tenth" */
445 panel
= new wxPanel(m_notebook
);
446 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
447 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
448 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
449 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
450 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
451 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
452 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
453 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
454 rb
->SetValue( FALSE
);
455 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
456 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
458 panel
= new wxPanel(m_notebook
);
459 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
460 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
461 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
462 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
464 // No wrapping text in wxStaticText yet :-(
465 (void)new wxStaticText( panel
, -1,
471 (void)new wxStaticText( panel
, -1,
472 "In order see the gauge (aka progress bar)\n"
473 "control do something you have to drag the\n"
474 "handle of the slider to the right.\n"
476 "This is also supposed to demonstrate how\n"
477 "to use static controls.\n",
482 int initialSpinValue
= -5;
484 s
<< initialSpinValue
;
485 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
487 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
488 m_spinbutton
->SetRange(-10,30);
489 m_spinbutton
->SetValue(initialSpinValue
);
491 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
493 #endif // wxUSE_SPINBUTTON
496 m_spinctrl
= new wxSpinCtrl( panel
, -1, wxPoint(200, 160), wxSize(80, -1) );
497 m_spinctrl
->SetRange(10,30);
498 m_spinctrl
->SetValue(15);
499 #endif // wxUSE_SPINCTRL
501 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
503 panel
= new wxPanel(m_notebook
);
505 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
506 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
507 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
, wxPoint(10, 10));
509 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
510 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
513 wxBitmap
bitmap( 100, 100 );
515 dc
.SelectObject( bitmap
);
516 dc
.SetPen(*wxGREEN_PEN
);
517 dc
.DrawEllipse(5, 5, 90, 90);
518 dc
.DrawText("Bitmap", 20, 20);
519 dc
.SelectObject( wxNullBitmap
);
521 wxBitmapButton
*bmpBtn
= new wxBitmapButton
528 bmpBtn
= NULL
; // suppress warning
530 new wxButton(panel
, -1, "Another button", wxPoint(250, 20));
532 m_notebook
->AddPage(panel
, "wxBitmapXXX");
534 // --------------- TEST CODE ----------------------
536 panel
= new wxPanel(m_notebook
);
537 panel
->SetAutoLayout( true );
539 wxLayoutConstraints
*c
;
540 c
= new wxLayoutConstraints
;
541 c
->top
.SameAs( panel
, wxTop
, 10 );
543 c
->left
.SameAs( panel
, wxLeft
, 10 );
544 c
->width
.PercentOf( panel
, wxWidth
, 40 );
546 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
547 pMyButton
->SetConstraints( c
);
549 c
= new wxLayoutConstraints
;
550 c
->top
.SameAs( panel
, wxTop
, 10 );
551 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
552 c
->right
.SameAs( panel
, wxRight
, 10 );
553 c
->width
.PercentOf( panel
, wxWidth
, 40 );
555 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
556 pMyButton2
->SetConstraints( c
);
558 m_notebook
->AddPage(panel
, "test layout");
560 // --------------- TEST CODE ----------------------
564 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
568 GetClientSize( &x
, &y
);
570 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
571 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
574 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
576 int selOld
= event
.GetOldSelection();
579 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
580 "page change from taking place - if you select\n"
581 "[No] the current page will stay the third one\n",
583 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
591 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
594 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
596 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
599 void MyPanel::OnListBox( wxCommandEvent
&event
)
601 m_text
->AppendText( "ListBox event selection string is: " );
602 m_text
->AppendText( event
.GetString() );
603 m_text
->AppendText( "\n" );
604 m_text
->AppendText( "ListBox control selection string is: " );
605 m_text
->AppendText( m_listbox
->GetStringSelection() );
606 m_text
->AppendText( "\n" );
609 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
611 m_text
->AppendText( "ListBox double click string is: " );
612 m_text
->AppendText( event
.GetString() );
613 m_text
->AppendText( "\n" );
616 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
618 switch (event
.GetId())
620 case ID_LISTBOX_ENABLE
:
622 m_text
->AppendText("Checkbox clicked.\n");
623 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
626 cb
->SetToolTip( "Click to enable listbox" );
628 cb
->SetToolTip( "Click to disable listbox" );
629 #endif // wxUSE_TOOLTIPS
630 m_listbox
->Enable( event
.GetInt() == 0 );
633 case ID_LISTBOX_SEL_NUM
:
635 m_listbox
->SetSelection( 2 );
636 m_lbSelectThis
->WarpPointer( 40, 14 );
639 case ID_LISTBOX_SEL_STR
:
641 m_listbox
->SetStringSelection( "This" );
642 m_lbSelectNum
->WarpPointer( 40, 14 );
645 case ID_LISTBOX_CLEAR
:
650 case ID_LISTBOX_APPEND
:
652 m_listbox
->Append( "Hi!" );
655 case ID_LISTBOX_DELETE
:
657 int idx
= m_listbox
->GetSelection();
658 m_listbox
->Delete( idx
);
661 case ID_LISTBOX_FONT
:
663 m_listbox
->SetFont( *wxITALIC_FONT
);
664 m_checkbox
->SetFont( *wxITALIC_FONT
);
670 void MyPanel::OnChoice( wxCommandEvent
&event
)
672 m_text
->AppendText( "Choice event selection string is: " );
673 m_text
->AppendText( event
.GetString() );
674 m_text
->AppendText( "\n" );
675 m_text
->AppendText( "Choice control selection string is: " );
676 m_text
->AppendText( m_choice
->GetStringSelection() );
677 m_text
->AppendText( "\n" );
680 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
682 switch (event
.GetId())
684 case ID_CHOICE_ENABLE
:
686 m_choice
->Enable( event
.GetInt() == 0 );
689 case ID_CHOICE_SEL_NUM
:
691 m_choice
->SetSelection( 2 );
694 case ID_CHOICE_SEL_STR
:
696 m_choice
->SetStringSelection( "This" );
699 case ID_CHOICE_CLEAR
:
704 case ID_CHOICE_APPEND
:
706 m_choice
->Append( "Hi!" );
709 case ID_CHOICE_DELETE
:
711 int idx
= m_choice
->GetSelection();
712 m_choice
->Delete( idx
);
717 m_choice
->SetFont( *wxITALIC_FONT
);
723 void MyPanel::OnCombo( wxCommandEvent
&event
)
725 m_text
->AppendText( "ComboBox event selection string is: " );
726 m_text
->AppendText( event
.GetString() );
727 m_text
->AppendText( "\n" );
728 m_text
->AppendText( "ComboBox control selection string is: " );
729 m_text
->AppendText( m_combo
->GetStringSelection() );
730 m_text
->AppendText( "\n" );
733 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
735 switch (event
.GetId())
737 case ID_COMBO_ENABLE
:
739 m_combo
->Enable( event
.GetInt() == 0 );
742 case ID_COMBO_SEL_NUM
:
744 m_combo
->SetSelection( 2 );
747 case ID_COMBO_SEL_STR
:
749 m_combo
->SetStringSelection( "This" );
757 case ID_COMBO_APPEND
:
759 m_combo
->Append( "Hi!" );
762 case ID_COMBO_DELETE
:
764 int idx
= m_combo
->GetSelection();
765 m_combo
->Delete( idx
);
770 m_combo
->SetFont( *wxITALIC_FONT
);
776 void MyPanel::OnRadio( wxCommandEvent
&event
)
778 m_text
->AppendText( "RadioBox selection string is: " );
779 m_text
->AppendText( event
.GetString() );
780 m_text
->AppendText( "\n" );
783 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
785 switch (event
.GetId())
787 case ID_RADIOBOX_ENABLE
:
789 m_radio
->Enable( event
.GetInt() == 0 );
792 case ID_RADIOBOX_SEL_NUM
:
794 m_radio
->SetSelection( 2 );
797 case ID_RADIOBOX_SEL_STR
:
799 m_radio
->SetStringSelection( "This" );
802 case ID_RADIOBOX_FONT
:
804 m_radio
->SetFont( *wxITALIC_FONT
);
810 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
812 m_fontButton
->SetFont( *wxITALIC_FONT
);
813 m_text
->SetFont( *wxITALIC_FONT
);
816 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
818 m_gauge
->SetValue( m_slider
->GetValue() );
822 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
825 value
.Printf( _T("Spin control up: current = %d\n"),
826 m_spinbutton
->GetValue());
828 if ( m_spinbutton
->GetValue() > 17 )
830 value
+= _T("Preventing the spin button from going above 17.\n");
835 m_text
->AppendText(value
);
838 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
841 value
.Printf( _T("Spin control down: current = %d\n"),
842 m_spinbutton
->GetValue());
844 if ( m_spinbutton
->GetValue() < -17 )
846 value
+= _T("Preventing the spin button from going below -17.\n");
851 m_text
->AppendText(value
);
854 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
857 value
.Printf( _T("%d"), event
.GetPosition() );
858 m_spintext
->SetValue( value
);
860 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
861 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
862 m_spinbutton
->GetValue());
864 m_text
->AppendText(value
);
867 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
869 event
.Enable( m_spinbutton
->GetValue() > 0 );
872 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
874 int max
= m_spinbutton
->GetValue();
875 wxProgressDialog
dialog("Progress dialog example",
876 "An informative message",
882 wxPD_ESTIMATED_TIME
|
883 wxPD_REMAINING_TIME
);
887 for ( int i
= 0; i
< max
&& cont
; i
++ )
892 cont
= dialog
.Update(i
, "That's all, folks!");
894 else if ( i
== max
/ 2 )
896 cont
= dialog
.Update(i
, "Only a half left!");
900 cont
= dialog
.Update(i
);
906 *m_text
<< "Progress dialog aborted!\n";
910 *m_text
<< "Countdown from " << max
<< " finished.\n";
914 #endif // wxUSE_SPINBUTTON
918 delete m_notebook
->GetImageList();
921 //----------------------------------------------------------------------
923 //----------------------------------------------------------------------
925 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
926 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
927 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
929 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
930 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
931 #endif // wxUSE_TOOLTIPS
932 EVT_SIZE(MyFrame::OnSize
)
933 EVT_IDLE(MyFrame::OnIdle
)
936 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
937 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
941 (void)new MyPanel( this, 10, 10, 300, 100 );
944 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
949 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
953 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
960 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
962 static long s_delay
= 5000;
965 delay
.Printf( _T("%ld"), s_delay
);
967 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
974 wxSscanf(delay
, _T("%ld"), &s_delay
);
976 wxToolTip::SetDelay(s_delay
);
978 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
981 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
983 static bool s_enabled
= TRUE
;
985 s_enabled
= !s_enabled
;
987 wxToolTip::Enable(s_enabled
);
989 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
993 void MyFrame::OnSize( wxSizeEvent
& event
)
996 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
997 SetStatusText(msg
, 1);
1002 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1004 // track the window which has the focus in the status bar
1005 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1006 wxWindow
*focus
= wxWindow::FindFocus();
1007 if ( focus
&& (focus
!= s_windowFocus
) )
1009 s_windowFocus
= focus
;
1014 _T("Focus: wxWindow = %p, HWND = %08x"),
1016 _T("Focus: wxWindow = %p"),
1020 , s_windowFocus
->GetHWND()