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
55 #define wxUSE_SPINBTN 0
58 #define wxUSE_SPINBTN 1
62 #include "wx/progdlg.h"
65 #include "wx/spinctrl.h"
66 #endif // wxUSE_SPINCTRL
68 #include "wx/calctrl.h"
70 //----------------------------------------------------------------------
72 //----------------------------------------------------------------------
74 class MyApp
: public wxApp
80 class MyPanel
: public wxPanel
83 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
86 void OnSize( wxSizeEvent
& event
);
87 void OnListBox( wxCommandEvent
&event
);
88 void OnListBoxDoubleClick( wxCommandEvent
&event
);
89 void OnListBoxButtons( wxCommandEvent
&event
);
90 void OnChoice( wxCommandEvent
&event
);
91 void OnChoiceButtons( wxCommandEvent
&event
);
92 void OnCombo( wxCommandEvent
&event
);
93 void OnComboButtons( wxCommandEvent
&event
);
94 void OnRadio( wxCommandEvent
&event
);
95 void OnRadioButtons( wxCommandEvent
&event
);
96 void OnSetFont( wxCommandEvent
&event
);
97 void OnPageChanged( wxNotebookEvent
&event
);
98 void OnPageChanging( wxNotebookEvent
&event
);
99 void OnSliderUpdate( wxCommandEvent
&event
);
100 void OnUpdateLabel( wxCommandEvent
&event
);
102 void OnSpinUp( wxSpinEvent
&event
);
103 void OnSpinDown( wxSpinEvent
&event
);
104 void OnSpinUpdate( wxSpinEvent
&event
);
105 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
106 void OnShowProgress( wxCommandEvent
&event
);
107 #endif // wxUSE_SPINBTN
110 void OnSpinCtrl(wxCommandEvent
& event
);
111 #endif // wxUSE_SPINCTRL
113 void OnEnableAll(wxCommandEvent
& event
);
114 void OnChangeColour(wxCommandEvent
& event
);
116 void OnCalendarChange(wxCalendarEvent
& event
);
118 wxListBox
*m_listbox
,
126 wxButton
*m_fontButton
;
127 wxButton
*m_lbSelectNum
;
128 wxButton
*m_lbSelectThis
;
130 wxSpinButton
*m_spinbutton
;
131 wxButton
*m_btnProgress
;
132 #endif // wxUSE_SPINBTN
135 wxSpinCtrl
*m_spinctrl
;
136 #endif // wxUSE_SPINCTRL
138 wxTextCtrl
*m_spintext
;
139 wxCheckBox
*m_checkbox
;
142 wxNotebook
*m_notebook
;
144 wxStaticText
*m_label
;
146 wxCalendarCtrl
*m_calendar
;
147 wxStaticText
*m_date
;
150 DECLARE_EVENT_TABLE()
153 class MyFrame
: public wxFrame
156 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
158 void OnQuit(wxCommandEvent
& event
);
159 void OnAbout(wxCommandEvent
& event
);
162 void OnSetTooltipDelay(wxCommandEvent
& event
);
163 void OnToggleTooltips(wxCommandEvent
& event
);
164 #endif // wxUSE_TOOLTIPS
166 void OnEnableAll(wxCommandEvent
& event
);
168 void OnIdle( wxIdleEvent
& event
);
169 void OnSize( wxSizeEvent
& event
);
170 void OnMove( wxMoveEvent
& event
);
172 MyPanel
*GetPanel() const { return m_panel
; }
175 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
178 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
179 pos
.x
, pos
.y
, size
.x
, size
.y
);
180 SetStatusText(msg
, 1);
185 DECLARE_EVENT_TABLE()
188 //----------------------------------------------------------------------
190 //----------------------------------------------------------------------
192 static void SetControlClientData(const char *name
,
193 wxControlWithItems
*control
);
197 //----------------------------------------------------------------------
199 //----------------------------------------------------------------------
208 MINIMAL_SET_TOOLTIP_DELAY
= 200,
209 MINIMAL_ENABLE_TOOLTIPS
,
217 // parse the cmd line
222 wxSscanf(argv
[1], "%d", &x
);
223 wxSscanf(argv
[2], "%d", &y
);
226 // Create the main frame window
227 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
228 "Controls wxWindows App",
231 frame
->SetSizeHints( 500, 425 );
234 // The wxICON() macros loads an icon from a resource under Windows
235 // and uses an #included XPM image under GTK+ and Motif
237 frame
->SetIcon( wxICON(mondrian
) );
239 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
241 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
242 file_menu
->AppendSeparator();
243 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
245 wxMenuBar
*menu_bar
= new wxMenuBar
;
246 menu_bar
->Append(file_menu
, "&File");
249 wxMenu
*tooltip_menu
= new wxMenu
;
250 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
251 tooltip_menu
->AppendSeparator();
252 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
253 "enable/disable tooltips", TRUE
);
254 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
255 menu_bar
->Append(tooltip_menu
, "&Tooltips");
256 #endif // wxUSE_TOOLTIPS
258 wxMenu
*panel_menu
= new wxMenu
;
259 panel_menu
->Append(MINIMAL_ENABLE_ALL
, "&Disable all\tCtrl-E",
260 "Enable/disable all panel controls", TRUE
);
261 menu_bar
->Append(panel_menu
, "&Panel");
263 frame
->SetMenuBar(menu_bar
);
266 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
268 frame
->GetPanel()->m_notebook
->SetSelection(6);
275 //----------------------------------------------------------------------
277 //----------------------------------------------------------------------
279 const int ID_NOTEBOOK
= 1000;
281 const int ID_LISTBOX
= 130;
282 const int ID_LISTBOX_SEL_NUM
= 131;
283 const int ID_LISTBOX_SEL_STR
= 132;
284 const int ID_LISTBOX_CLEAR
= 133;
285 const int ID_LISTBOX_APPEND
= 134;
286 const int ID_LISTBOX_DELETE
= 135;
287 const int ID_LISTBOX_FONT
= 136;
288 const int ID_LISTBOX_ENABLE
= 137;
289 const int ID_LISTBOX_SORTED
= 138;
291 const int ID_CHOICE
= 120;
292 const int ID_CHOICE_SEL_NUM
= 121;
293 const int ID_CHOICE_SEL_STR
= 122;
294 const int ID_CHOICE_CLEAR
= 123;
295 const int ID_CHOICE_APPEND
= 124;
296 const int ID_CHOICE_DELETE
= 125;
297 const int ID_CHOICE_FONT
= 126;
298 const int ID_CHOICE_ENABLE
= 127;
299 const int ID_CHOICE_SORTED
= 128;
301 const int ID_COMBO
= 140;
302 const int ID_COMBO_SEL_NUM
= 141;
303 const int ID_COMBO_SEL_STR
= 142;
304 const int ID_COMBO_CLEAR
= 143;
305 const int ID_COMBO_APPEND
= 144;
306 const int ID_COMBO_DELETE
= 145;
307 const int ID_COMBO_FONT
= 146;
308 const int ID_COMBO_ENABLE
= 147;
310 const int ID_RADIOBOX
= 160;
311 const int ID_RADIOBOX_SEL_NUM
= 161;
312 const int ID_RADIOBOX_SEL_STR
= 162;
313 const int ID_RADIOBOX_FONT
= 163;
314 const int ID_RADIOBOX_ENABLE
= 164;
316 const int ID_RADIOBUTTON_1
= 166;
317 const int ID_RADIOBUTTON_2
= 167;
319 const int ID_SET_FONT
= 170;
321 const int ID_GAUGE
= 180;
322 const int ID_SLIDER
= 181;
324 const int ID_SPIN
= 182;
325 const int ID_BTNPROGRESS
= 183;
326 const int ID_BUTTON_LABEL
= 184;
327 const int ID_SPINCTRL
= 185;
329 const int ID_CHANGE_COLOUR
= 200;
331 const int ID_CALENDAR
= 210;
333 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
334 EVT_SIZE ( MyPanel::OnSize
)
335 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
336 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
337 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
338 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
339 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
340 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
341 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
342 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
343 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
344 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
345 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
346 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
347 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
348 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
349 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
350 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
351 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
352 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
353 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
354 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
355 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
356 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
357 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
358 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
359 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
360 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
361 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
362 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
363 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
364 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
365 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
366 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
367 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
368 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
369 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
370 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
372 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
373 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
374 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
375 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
376 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
377 #endif // wxUSE_SPINBTN
379 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
380 #endif // wxUSE_SPINCTRL
381 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
382 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
383 EVT_CALENDAR (ID_CALENDAR
, MyPanel::OnCalendarChange
)
386 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
387 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
388 m_text(NULL
), m_notebook(NULL
)
390 wxLayoutConstraints
*c
;
392 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
393 // m_text->SetBackgroundColour("wheat");
395 //delete wxLog::SetActiveTarget(new wxLogStderr);
397 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
412 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
415 // fill the image list
416 wxImageList
*imagelist
= new wxImageList(32, 32);
418 imagelist
-> Add( wxBitmap( list_xpm
));
419 imagelist
-> Add( wxBitmap( choice_xpm
));
420 imagelist
-> Add( wxBitmap( combo_xpm
));
421 imagelist
-> Add( wxBitmap( text_xpm
));
422 imagelist
-> Add( wxBitmap( radio_xpm
));
423 imagelist
-> Add( wxBitmap( gauge_xpm
));
424 m_notebook
->SetImageList(imagelist
);
425 #elif defined(__WXMSW__)
426 // load images from resources
429 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
431 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
433 static const char *s_iconNames
[Image_Max
] =
435 "list", "choice", "combo", "text", "radio", "gauge"
438 for ( size_t n
= 0; n
< Image_Max
; n
++ )
440 wxBitmap
bmp(s_iconNames
[n
]);
441 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
443 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
448 m_notebook
->SetImageList(imagelist
);
452 #define Image_List -1
453 #define Image_Choice -1
454 #define Image_Combo -1
455 #define Image_Text -1
456 #define Image_Radio -1
457 #define Image_Gauge -1
462 wxPanel
*panel
= new wxPanel(m_notebook
);
463 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
464 wxPoint(10,10), wxSize(120,70),
465 5, choices
, wxLB_ALWAYS_SB
);
466 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
467 wxPoint(10,90), wxSize(120,70),
468 5, choices
, wxLB_SORT
);
470 SetControlClientData("listbox", m_listbox
);
471 SetControlClientData("listbox", m_listboxSorted
);
473 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
475 m_listbox
->SetToolTip( "This is a list box" );
476 #endif // wxUSE_TOOLTIPS
478 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
479 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
480 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
481 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
482 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
483 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
485 button
->SetDefault();
487 button
->SetForegroundColour(*wxBLUE
);
490 button
->SetToolTip( "Press here to set italic font" );
491 #endif // wxUSE_TOOLTIPS
493 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
494 m_checkbox
->SetValue(FALSE
);
496 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
497 #endif // wxUSE_TOOLTIPS
498 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
500 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
502 panel
= new wxPanel(m_notebook
);
503 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
504 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
505 5, choices
, wxCB_SORT
);
508 SetControlClientData("choice", m_choice
);
509 SetControlClientData("choice", m_choiceSorted
);
512 m_choice
->SetSelection(2);
513 m_choice
->SetBackgroundColour( "red" );
514 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
515 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
516 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
517 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
518 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
519 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
520 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
522 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
524 panel
= new wxPanel(m_notebook
);
525 (void)new wxStaticBox( panel
, -1, "Box around combobox",
526 wxPoint(5, 5), wxSize(150, 100));
527 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(20,20), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
528 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
529 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
530 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
531 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
532 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
533 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
534 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
535 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
537 wxString choices2
[] =
541 "Fourth", "Fifth", "Sixth",
542 "Seventh", "Eighth", "Nineth", "Tenth" */
545 panel
= new wxPanel(m_notebook
);
546 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
547 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
550 m_radio
->SetToolTip("Ever seen a radiobox?");
551 #endif // wxUSE_TOOLTIPS
553 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
554 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
555 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
556 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
557 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
558 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
559 rb
->SetValue( FALSE
);
560 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
561 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
563 panel
= new wxPanel(m_notebook
);
564 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
565 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
566 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
567 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
569 // No wrapping text in wxStaticText yet :-(
570 (void)new wxStaticText( panel
, -1,
576 (void)new wxStaticText( panel
, -1,
577 "In order see the gauge (aka progress bar)\n"
578 "control do something you have to drag the\n"
579 "handle of the slider to the right.\n"
581 "This is also supposed to demonstrate how\n"
582 "to use static controls.\n",
587 int initialSpinValue
= -5;
589 s
<< initialSpinValue
;
590 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
592 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
593 m_spinbutton
->SetRange(-10,30);
594 m_spinbutton
->SetValue(initialSpinValue
);
596 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
598 #endif // wxUSE_SPINBTN
601 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
602 m_spinctrl
->SetRange(10,30);
603 m_spinctrl
->SetValue(15);
604 #endif // wxUSE_SPINCTRL
606 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
608 panel
= new wxPanel(m_notebook
);
610 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
611 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
612 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
615 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
616 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
619 wxBitmap
bitmap( 100, 100 );
621 dc
.SelectObject( bitmap
);
622 dc
.SetPen(*wxGREEN_PEN
);
624 dc
.DrawEllipse(5, 5, 90, 90);
625 dc
.DrawText("Bitmap", 30, 40);
626 dc
.SelectObject( wxNullBitmap
);
628 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(100, 20));
631 bitmap
= wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
633 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
634 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(300, 120));
637 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
638 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
639 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
640 wxBitmapButton
*bmpBtn
= new wxBitmapButton
646 bmpBtn
->SetBitmapSelected(bmp2
);
647 bmpBtn
->SetBitmapFocus(bmp3
);
649 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "Toggle label", wxPoint(250, 20));
650 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
651 wxPoint(250, 60), wxDefaultSize
,
652 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
654 m_notebook
->AddPage(panel
, "wxBitmapXXX");
658 panel
= new wxPanel(m_notebook
);
659 panel
->SetAutoLayout( TRUE
);
662 date
.Printf("Selected date: %s",
663 wxDateTime::Today().FormatISODate().c_str());
664 m_date
= new wxStaticText(panel
, -1, date
);
665 m_calendar
= new wxCalendarCtrl(panel
, ID_CALENDAR
);
667 c
= new wxLayoutConstraints
;
668 c
->left
.SameAs( panel
, wxLeft
, 10 );
669 c
->centreY
.SameAs( m_calendar
, wxCentreY
);
673 m_date
->SetConstraints(c
);
675 c
= new wxLayoutConstraints
;
676 c
->left
.SameAs( m_date
, wxRight
, 10 );
677 c
->top
.SameAs( panel
, wxTop
, 10 );
681 m_calendar
->SetConstraints(c
);
683 m_notebook
->AddPage(panel
, "wxCalendar");
685 // layout constraints
687 panel
= new wxPanel(m_notebook
);
688 panel
->SetAutoLayout( TRUE
);
690 c
= new wxLayoutConstraints
;
691 c
->top
.SameAs( panel
, wxTop
, 10 );
693 c
->left
.SameAs( panel
, wxLeft
, 10 );
694 c
->width
.PercentOf( panel
, wxWidth
, 40 );
696 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
697 pMyButton
->SetConstraints( c
);
699 c
= new wxLayoutConstraints
;
700 c
->top
.SameAs( panel
, wxTop
, 10 );
701 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
702 c
->right
.SameAs( panel
, wxRight
, 10 );
703 c
->width
.PercentOf( panel
, wxWidth
, 40 );
705 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
706 pMyButton2
->SetConstraints( c
);
708 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
712 panel
= new wxPanel(m_notebook
);
713 panel
->SetAutoLayout( TRUE
);
715 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
717 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
718 sizer
->Add( 20,20, 1 );
719 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
721 panel
->SetSizer( sizer
);
723 m_notebook
->AddPage(panel
, "wxSizer");
726 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
730 GetClientSize( &x
, &y
);
732 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
733 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
736 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
738 int selOld
= event
.GetOldSelection();
741 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
742 "page change from taking place - if you select\n"
743 "[No] the current page will stay the third one\n",
745 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
753 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
756 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
758 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
761 void MyPanel::OnCalendarChange(wxCalendarEvent
& event
)
764 s
.Printf("Selected date: %s", event
.GetDate().FormatISODate().c_str());
769 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
771 static wxColour s_colOld
;
773 // test panel colour changing and propagation to the subcontrols
776 SetBackgroundColour(s_colOld
);
777 s_colOld
= wxNullColour
;
779 m_lbSelectThis
->SetForegroundColour("yellow");
780 m_lbSelectThis
->SetBackgroundColour("blue");
784 s_colOld
= GetBackgroundColour();
785 SetBackgroundColour("green");
787 m_lbSelectThis
->SetForegroundColour("white");
788 m_lbSelectThis
->SetBackgroundColour("red");
791 m_lbSelectThis
->Refresh();
795 void MyPanel::OnListBox( wxCommandEvent
&event
)
797 // GetParent()->Move(100, 100);
799 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
802 m_text
->AppendText( "ListBox event selection string is: '" );
803 m_text
->AppendText( event
.GetString() );
804 m_text
->AppendText( "'\n" );
805 m_text
->AppendText( "ListBox control selection string is: '" );
806 m_text
->AppendText( listbox
->GetStringSelection() );
807 m_text
->AppendText( "'\n" );
809 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
810 m_text
->AppendText( "ListBox event client data string is: '" );
811 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
812 m_text
->AppendText( obj
->GetData() );
814 m_text
->AppendText( wxString("none") );
816 m_text
->AppendText( "'\n" );
817 m_text
->AppendText( "ListBox control client data string is: '" );
818 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
820 m_text
->AppendText( obj
->GetData() );
822 m_text
->AppendText( wxString("none") );
823 m_text
->AppendText( "'\n" );
826 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
828 m_text
->AppendText( "ListBox double click string is: " );
829 m_text
->AppendText( event
.GetString() );
830 m_text
->AppendText( "\n" );
833 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
835 switch (event
.GetId())
837 case ID_LISTBOX_ENABLE
:
839 m_text
->AppendText("Checkbox clicked.\n");
840 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
843 cb
->SetToolTip( "Click to enable listbox" );
845 cb
->SetToolTip( "Click to disable listbox" );
846 #endif // wxUSE_TOOLTIPS
847 m_listbox
->Enable( event
.GetInt() == 0 );
848 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
849 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
850 m_listboxSorted
->Enable( event
.GetInt() == 0 );
853 case ID_LISTBOX_SEL_NUM
:
855 m_listbox
->SetSelection( 2 );
856 m_listboxSorted
->SetSelection( 2 );
857 m_lbSelectThis
->WarpPointer( 40, 14 );
860 case ID_LISTBOX_SEL_STR
:
862 m_listbox
->SetStringSelection( "This" );
863 m_listboxSorted
->SetStringSelection( "This" );
864 m_lbSelectNum
->WarpPointer( 40, 14 );
867 case ID_LISTBOX_CLEAR
:
870 m_listboxSorted
->Clear();
873 case ID_LISTBOX_APPEND
:
875 m_listbox
->Append( "Hi!" );
876 m_listboxSorted
->Append( "Hi!" );
879 case ID_LISTBOX_DELETE
:
882 idx
= m_listbox
->GetSelection();
883 m_listbox
->Delete( idx
);
884 idx
= m_listboxSorted
->GetSelection();
885 m_listboxSorted
->Delete( idx
);
888 case ID_LISTBOX_FONT
:
890 m_listbox
->SetFont( *wxITALIC_FONT
);
891 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
892 m_checkbox
->SetFont( *wxITALIC_FONT
);
898 void MyPanel::OnChoice( wxCommandEvent
&event
)
900 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
903 m_text
->AppendText( "Choice event selection string is: '" );
904 m_text
->AppendText( event
.GetString() );
905 m_text
->AppendText( "'\n" );
906 m_text
->AppendText( "Choice control selection string is: '" );
907 m_text
->AppendText( choice
->GetStringSelection() );
908 m_text
->AppendText( "'\n" );
910 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
911 m_text
->AppendText( "Choice event client data string is: '" );
914 m_text
->AppendText( obj
->GetData() );
916 m_text
->AppendText( wxString("none") );
918 m_text
->AppendText( "'\n" );
919 m_text
->AppendText( "Choice control client data string is: '" );
920 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
923 m_text
->AppendText( obj
->GetData() );
925 m_text
->AppendText( wxString("none") );
926 m_text
->AppendText( "'\n" );
929 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
931 switch (event
.GetId())
933 case ID_CHOICE_ENABLE
:
935 m_choice
->Enable( event
.GetInt() == 0 );
936 m_choiceSorted
->Enable( event
.GetInt() == 0 );
939 case ID_CHOICE_SEL_NUM
:
941 m_choice
->SetSelection( 2 );
942 m_choiceSorted
->SetSelection( 2 );
945 case ID_CHOICE_SEL_STR
:
947 m_choice
->SetStringSelection( "This" );
948 m_choiceSorted
->SetStringSelection( "This" );
951 case ID_CHOICE_CLEAR
:
954 m_choiceSorted
->Clear();
957 case ID_CHOICE_APPEND
:
959 m_choice
->Append( "Hi!" );
960 m_choiceSorted
->Append( "Hi!" );
963 case ID_CHOICE_DELETE
:
965 int idx
= m_choice
->GetSelection();
966 m_choice
->Delete( idx
);
967 idx
= m_choiceSorted
->GetSelection();
968 m_choiceSorted
->Delete( idx
);
973 m_choice
->SetFont( *wxITALIC_FONT
);
974 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
980 void MyPanel::OnCombo( wxCommandEvent
&event
)
982 m_text
->AppendText( "ComboBox event selection string is: " );
983 m_text
->AppendText( event
.GetString() );
984 m_text
->AppendText( "\n" );
985 m_text
->AppendText( "ComboBox control selection string is: " );
986 m_text
->AppendText( m_combo
->GetStringSelection() );
987 m_text
->AppendText( "\n" );
990 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
992 switch (event
.GetId())
994 case ID_COMBO_ENABLE
:
996 m_combo
->Enable( event
.GetInt() == 0 );
999 case ID_COMBO_SEL_NUM
:
1001 m_combo
->SetSelection( 2 );
1004 case ID_COMBO_SEL_STR
:
1006 m_combo
->SetStringSelection( "This" );
1009 case ID_COMBO_CLEAR
:
1014 case ID_COMBO_APPEND
:
1016 m_combo
->Append( "Hi!" );
1019 case ID_COMBO_DELETE
:
1021 int idx
= m_combo
->GetSelection();
1022 m_combo
->Delete( idx
);
1027 m_combo
->SetFont( *wxITALIC_FONT
);
1033 void MyPanel::OnRadio( wxCommandEvent
&event
)
1035 m_text
->AppendText( "RadioBox selection string is: " );
1036 m_text
->AppendText( event
.GetString() );
1037 m_text
->AppendText( "\n" );
1040 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1042 switch (event
.GetId())
1044 case ID_RADIOBOX_ENABLE
:
1046 m_radio
->Enable( event
.GetInt() == 0 );
1049 case ID_RADIOBOX_SEL_NUM
:
1051 m_radio
->SetSelection( 2 );
1054 case ID_RADIOBOX_SEL_STR
:
1056 m_radio
->SetStringSelection( "This" );
1059 case ID_RADIOBOX_FONT
:
1061 m_radio
->SetFont( *wxITALIC_FONT
);
1067 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1069 m_fontButton
->SetFont( *wxITALIC_FONT
);
1070 m_text
->SetFont( *wxITALIC_FONT
);
1073 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
1075 static bool s_long
= TRUE
;
1078 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
1081 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1083 m_gauge
->SetValue( m_slider
->GetValue() );
1088 void MyPanel::OnSpinCtrl(wxCommandEvent
& event
)
1091 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1092 m_spinctrl
->GetValue(), event
.GetInt());
1093 m_text
->AppendText(s
);
1096 #endif // wxUSE_SPINCTRL
1099 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1102 value
.Printf( _T("Spin control up: current = %d\n"),
1103 m_spinbutton
->GetValue());
1105 if ( m_spinbutton
->GetValue() > 17 )
1107 value
+= _T("Preventing the spin button from going above 17.\n");
1112 m_text
->AppendText(value
);
1115 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1118 value
.Printf( _T("Spin control down: current = %d\n"),
1119 m_spinbutton
->GetValue());
1121 if ( m_spinbutton
->GetValue() < -17 )
1123 value
+= _T("Preventing the spin button from going below -17.\n");
1128 m_text
->AppendText(value
);
1131 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1134 value
.Printf( _T("%d"), event
.GetPosition() );
1135 m_spintext
->SetValue( value
);
1137 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1138 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1139 m_spinbutton
->GetValue());
1141 m_text
->AppendText(value
);
1144 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1146 event
.Enable( m_spinbutton
->GetValue() > 0 );
1149 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1151 int max
= m_spinbutton
->GetValue();
1152 wxProgressDialog
dialog("Progress dialog example",
1153 "An informative message",
1159 wxPD_ESTIMATED_TIME
|
1160 wxPD_REMAINING_TIME
);
1164 for ( int i
= 0; i
< max
&& cont
; i
++ )
1169 cont
= dialog
.Update(i
, "That's all, folks!");
1171 else if ( i
== max
/ 2 )
1173 cont
= dialog
.Update(i
, "Only a half left!");
1177 cont
= dialog
.Update(i
);
1183 *m_text
<< "Progress dialog aborted!\n";
1187 *m_text
<< "Countdown from " << max
<< " finished.\n";
1191 #endif // wxUSE_SPINBTN
1195 delete m_notebook
->GetImageList();
1198 //----------------------------------------------------------------------
1200 //----------------------------------------------------------------------
1202 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1203 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1204 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1206 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1207 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1208 #endif // wxUSE_TOOLTIPS
1210 EVT_MENU(MINIMAL_ENABLE_ALL
, MyFrame::OnEnableAll
)
1212 EVT_SIZE(MyFrame::OnSize
)
1213 EVT_MOVE(MyFrame::OnMove
)
1215 EVT_IDLE(MyFrame::OnIdle
)
1218 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1219 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1223 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1226 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1231 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1233 wxBeginBusyCursor();
1235 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1242 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1244 static long s_delay
= 5000;
1247 delay
.Printf( _T("%ld"), s_delay
);
1249 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1250 "Set tooltip delay",
1254 return; // cancelled
1256 wxSscanf(delay
, _T("%ld"), &s_delay
);
1258 wxToolTip::SetDelay(s_delay
);
1260 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1263 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1265 static bool s_enabled
= TRUE
;
1267 s_enabled
= !s_enabled
;
1269 wxToolTip::Enable(s_enabled
);
1271 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1275 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1277 static bool s_enable
= TRUE
;
1279 s_enable
= !s_enable
;
1280 m_panel
->Enable(s_enable
);
1283 void MyFrame::OnMove( wxMoveEvent
& event
)
1285 UpdateStatusBar(event
.GetPosition(), GetSize());
1290 void MyFrame::OnSize( wxSizeEvent
& event
)
1292 UpdateStatusBar(GetPosition(), event
.GetSize());
1297 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1299 // track the window which has the focus in the status bar
1300 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1301 wxWindow
*focus
= wxWindow::FindFocus();
1302 if ( focus
&& (focus
!= s_windowFocus
) )
1304 s_windowFocus
= focus
;
1309 _T("Focus: wxWindow = %p, HWND = %08x"),
1311 _T("Focus: wxWindow = %p"),
1315 , s_windowFocus
->GetHWND()
1323 static void SetControlClientData(const char *name
,
1324 wxControlWithItems
*control
)
1326 size_t count
= control
->GetCount();
1327 for ( size_t n
= 0; n
< count
; n
++ )
1330 s
.Printf("%s client data for '%s'",
1331 name
, control
->GetString(n
).c_str());
1333 control
->SetClientObject(n
, new wxStringClientData(s
));