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 OnCalendar(wxCalendarEvent
& event
);
117 void OnCalendarWeekDayClick(wxCalendarEvent
& event
);
118 void OnCalendarChange(wxCalendarEvent
& event
);
120 wxListBox
*m_listbox
,
128 wxButton
*m_fontButton
;
129 wxButton
*m_lbSelectNum
;
130 wxButton
*m_lbSelectThis
;
132 wxSpinButton
*m_spinbutton
;
133 wxButton
*m_btnProgress
;
134 #endif // wxUSE_SPINBTN
137 wxSpinCtrl
*m_spinctrl
;
138 #endif // wxUSE_SPINCTRL
140 wxTextCtrl
*m_spintext
;
141 wxCheckBox
*m_checkbox
;
144 wxNotebook
*m_notebook
;
146 wxStaticText
*m_label
;
148 wxCalendarCtrl
*m_calendar
;
149 wxStaticText
*m_date
;
152 DECLARE_EVENT_TABLE()
155 class MyFrame
: public wxFrame
158 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
160 void OnQuit(wxCommandEvent
& event
);
161 void OnAbout(wxCommandEvent
& event
);
164 void OnSetTooltipDelay(wxCommandEvent
& event
);
165 void OnToggleTooltips(wxCommandEvent
& event
);
166 #endif // wxUSE_TOOLTIPS
168 void OnEnableAll(wxCommandEvent
& event
);
170 void OnIdle( wxIdleEvent
& event
);
171 void OnSize( wxSizeEvent
& event
);
172 void OnMove( wxMoveEvent
& event
);
174 MyPanel
*GetPanel() const { return m_panel
; }
177 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
180 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
181 pos
.x
, pos
.y
, size
.x
, size
.y
);
182 SetStatusText(msg
, 1);
187 DECLARE_EVENT_TABLE()
190 //----------------------------------------------------------------------
192 //----------------------------------------------------------------------
194 static void SetControlClientData(const char *name
,
195 wxControlWithItems
*control
);
199 //----------------------------------------------------------------------
201 //----------------------------------------------------------------------
210 MINIMAL_SET_TOOLTIP_DELAY
= 200,
211 MINIMAL_ENABLE_TOOLTIPS
,
219 // parse the cmd line
224 wxSscanf(argv
[1], "%d", &x
);
225 wxSscanf(argv
[2], "%d", &y
);
228 // Create the main frame window
229 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
230 "Controls wxWindows App",
233 frame
->SetSizeHints( 500, 425 );
236 // The wxICON() macros loads an icon from a resource under Windows
237 // and uses an #included XPM image under GTK+ and Motif
239 frame
->SetIcon( wxICON(mondrian
) );
241 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
243 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
244 file_menu
->AppendSeparator();
245 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
247 wxMenuBar
*menu_bar
= new wxMenuBar
;
248 menu_bar
->Append(file_menu
, "&File");
251 wxMenu
*tooltip_menu
= new wxMenu
;
252 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
253 tooltip_menu
->AppendSeparator();
254 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
255 "enable/disable tooltips", TRUE
);
256 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
257 menu_bar
->Append(tooltip_menu
, "&Tooltips");
258 #endif // wxUSE_TOOLTIPS
260 wxMenu
*panel_menu
= new wxMenu
;
261 panel_menu
->Append(MINIMAL_ENABLE_ALL
, "&Disable all\tCtrl-E",
262 "Enable/disable all panel controls", TRUE
);
263 menu_bar
->Append(panel_menu
, "&Panel");
265 frame
->SetMenuBar(menu_bar
);
268 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
270 frame
->GetPanel()->m_notebook
->SetSelection(6);
277 //----------------------------------------------------------------------
279 //----------------------------------------------------------------------
281 const int ID_NOTEBOOK
= 1000;
283 const int ID_LISTBOX
= 130;
284 const int ID_LISTBOX_SEL_NUM
= 131;
285 const int ID_LISTBOX_SEL_STR
= 132;
286 const int ID_LISTBOX_CLEAR
= 133;
287 const int ID_LISTBOX_APPEND
= 134;
288 const int ID_LISTBOX_DELETE
= 135;
289 const int ID_LISTBOX_FONT
= 136;
290 const int ID_LISTBOX_ENABLE
= 137;
291 const int ID_LISTBOX_SORTED
= 138;
293 const int ID_CHOICE
= 120;
294 const int ID_CHOICE_SEL_NUM
= 121;
295 const int ID_CHOICE_SEL_STR
= 122;
296 const int ID_CHOICE_CLEAR
= 123;
297 const int ID_CHOICE_APPEND
= 124;
298 const int ID_CHOICE_DELETE
= 125;
299 const int ID_CHOICE_FONT
= 126;
300 const int ID_CHOICE_ENABLE
= 127;
301 const int ID_CHOICE_SORTED
= 128;
303 const int ID_COMBO
= 140;
304 const int ID_COMBO_SEL_NUM
= 141;
305 const int ID_COMBO_SEL_STR
= 142;
306 const int ID_COMBO_CLEAR
= 143;
307 const int ID_COMBO_APPEND
= 144;
308 const int ID_COMBO_DELETE
= 145;
309 const int ID_COMBO_FONT
= 146;
310 const int ID_COMBO_ENABLE
= 147;
312 const int ID_RADIOBOX
= 160;
313 const int ID_RADIOBOX_SEL_NUM
= 161;
314 const int ID_RADIOBOX_SEL_STR
= 162;
315 const int ID_RADIOBOX_FONT
= 163;
316 const int ID_RADIOBOX_ENABLE
= 164;
318 const int ID_RADIOBUTTON_1
= 166;
319 const int ID_RADIOBUTTON_2
= 167;
321 const int ID_SET_FONT
= 170;
323 const int ID_GAUGE
= 180;
324 const int ID_SLIDER
= 181;
326 const int ID_SPIN
= 182;
327 const int ID_BTNPROGRESS
= 183;
328 const int ID_BUTTON_LABEL
= 184;
329 const int ID_SPINCTRL
= 185;
331 const int ID_CHANGE_COLOUR
= 200;
333 const int ID_CALENDAR
= 210;
335 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
336 EVT_SIZE ( MyPanel::OnSize
)
337 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
338 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
339 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
340 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
341 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
342 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
343 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
344 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
345 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
346 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
347 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
348 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
349 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
350 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
351 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
352 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
353 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
354 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
355 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
356 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
357 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
358 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
359 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
360 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
361 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
362 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
363 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
364 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
365 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
366 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
367 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
368 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
369 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
370 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
371 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
372 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
374 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
375 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
376 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
377 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
378 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
379 #endif // wxUSE_SPINBTN
381 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
382 #endif // wxUSE_SPINCTRL
383 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
384 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
386 EVT_CALENDAR (ID_CALENDAR
, MyPanel::OnCalendar
)
387 EVT_CALENDAR_SEL_CHANGED(ID_CALENDAR
, MyPanel::OnCalendarChange
)
388 EVT_CALENDAR_WEEKDAY_CLICKED(ID_CALENDAR
, MyPanel::OnCalendarWeekDayClick
)
392 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
393 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
394 m_text(NULL
), m_notebook(NULL
)
396 wxLayoutConstraints
*c
;
398 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
399 // m_text->SetBackgroundColour("wheat");
401 //delete wxLog::SetActiveTarget(new wxLogStderr);
403 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
418 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
421 // fill the image list
422 wxImageList
*imagelist
= new wxImageList(32, 32);
424 imagelist
-> Add( wxBitmap( list_xpm
));
425 imagelist
-> Add( wxBitmap( choice_xpm
));
426 imagelist
-> Add( wxBitmap( combo_xpm
));
427 imagelist
-> Add( wxBitmap( text_xpm
));
428 imagelist
-> Add( wxBitmap( radio_xpm
));
429 imagelist
-> Add( wxBitmap( gauge_xpm
));
430 m_notebook
->SetImageList(imagelist
);
431 #elif defined(__WXMSW__)
432 // load images from resources
435 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
437 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
439 static const char *s_iconNames
[Image_Max
] =
441 "list", "choice", "combo", "text", "radio", "gauge"
444 for ( size_t n
= 0; n
< Image_Max
; n
++ )
446 wxBitmap
bmp(s_iconNames
[n
]);
447 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
449 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
454 m_notebook
->SetImageList(imagelist
);
458 #define Image_List -1
459 #define Image_Choice -1
460 #define Image_Combo -1
461 #define Image_Text -1
462 #define Image_Radio -1
463 #define Image_Gauge -1
468 wxPanel
*panel
= new wxPanel(m_notebook
);
469 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
470 wxPoint(10,10), wxSize(120,70),
471 5, choices
, wxLB_ALWAYS_SB
);
472 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
473 wxPoint(10,90), wxSize(120,70),
474 5, choices
, wxLB_SORT
);
476 SetControlClientData("listbox", m_listbox
);
477 SetControlClientData("listbox", m_listboxSorted
);
479 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
481 m_listbox
->SetToolTip( "This is a list box" );
482 #endif // wxUSE_TOOLTIPS
484 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
485 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
486 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
487 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
488 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
489 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
491 button
->SetDefault();
493 button
->SetForegroundColour(*wxBLUE
);
496 button
->SetToolTip( "Press here to set italic font" );
497 #endif // wxUSE_TOOLTIPS
499 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
500 m_checkbox
->SetValue(FALSE
);
502 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
503 #endif // wxUSE_TOOLTIPS
504 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
506 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
508 panel
= new wxPanel(m_notebook
);
509 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
510 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
511 5, choices
, wxCB_SORT
);
514 SetControlClientData("choice", m_choice
);
515 SetControlClientData("choice", m_choiceSorted
);
518 m_choice
->SetSelection(2);
519 m_choice
->SetBackgroundColour( "red" );
520 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
521 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
522 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
523 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
524 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
525 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
526 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
528 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
530 panel
= new wxPanel(m_notebook
);
531 (void)new wxStaticBox( panel
, -1, "Box around combobox",
532 wxPoint(5, 5), wxSize(150, 100));
533 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(20,20), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
534 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
535 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
536 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
537 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
538 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
539 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
540 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
541 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
543 wxString choices2
[] =
547 "Fourth", "Fifth", "Sixth",
548 "Seventh", "Eighth", "Nineth", "Tenth" */
551 panel
= new wxPanel(m_notebook
);
552 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
553 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
556 m_radio
->SetToolTip("Ever seen a radiobox?");
557 #endif // wxUSE_TOOLTIPS
559 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
560 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
561 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
562 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
563 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
564 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP
);
565 rb
->SetValue( FALSE
);
566 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
567 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
569 panel
= new wxPanel(m_notebook
);
570 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
571 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
572 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
573 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
575 // No wrapping text in wxStaticText yet :-(
576 (void)new wxStaticText( panel
, -1,
582 (void)new wxStaticText( panel
, -1,
583 "In order see the gauge (aka progress bar)\n"
584 "control do something you have to drag the\n"
585 "handle of the slider to the right.\n"
587 "This is also supposed to demonstrate how\n"
588 "to use static controls.\n",
593 int initialSpinValue
= -5;
595 s
<< initialSpinValue
;
596 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
598 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
599 m_spinbutton
->SetRange(-10,30);
600 m_spinbutton
->SetValue(initialSpinValue
);
602 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
604 #endif // wxUSE_SPINBTN
607 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
608 m_spinctrl
->SetRange(10,30);
609 m_spinctrl
->SetValue(15);
610 #endif // wxUSE_SPINCTRL
612 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
614 panel
= new wxPanel(m_notebook
);
616 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
617 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
618 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
621 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
622 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
625 wxBitmap
bitmap( 100, 100 );
627 dc
.SelectObject( bitmap
);
628 dc
.SetPen(*wxGREEN_PEN
);
630 dc
.DrawEllipse(5, 5, 90, 90);
631 dc
.DrawText("Bitmap", 30, 40);
632 dc
.SelectObject( wxNullBitmap
);
634 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(100, 20));
637 bitmap
= wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
639 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
640 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(300, 120));
643 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
644 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
645 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
646 wxBitmapButton
*bmpBtn
= new wxBitmapButton
652 bmpBtn
->SetBitmapSelected(bmp2
);
653 bmpBtn
->SetBitmapFocus(bmp3
);
655 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "Toggle label", wxPoint(250, 20));
656 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
657 wxPoint(250, 60), wxDefaultSize
,
658 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
660 m_notebook
->AddPage(panel
, "wxBitmapXXX");
664 panel
= new wxPanel(m_notebook
);
665 panel
->SetAutoLayout( TRUE
);
668 date
.Printf("Selected date: %s",
669 wxDateTime::Today().FormatISODate().c_str());
670 m_date
= new wxStaticText(panel
, -1, date
);
671 m_calendar
= new wxCalendarCtrl(panel
, ID_CALENDAR
);
673 c
= new wxLayoutConstraints
;
674 c
->left
.SameAs( panel
, wxLeft
, 10 );
675 c
->centreY
.SameAs( m_calendar
, wxCentreY
);
679 m_date
->SetConstraints(c
);
681 c
= new wxLayoutConstraints
;
682 c
->left
.SameAs( m_date
, wxRight
, 10 );
683 c
->top
.SameAs( panel
, wxTop
, 10 );
687 m_calendar
->SetConstraints(c
);
689 m_notebook
->AddPage(panel
, "wxCalendar");
691 // layout constraints
693 panel
= new wxPanel(m_notebook
);
694 panel
->SetAutoLayout( TRUE
);
696 c
= new wxLayoutConstraints
;
697 c
->top
.SameAs( panel
, wxTop
, 10 );
699 c
->left
.SameAs( panel
, wxLeft
, 10 );
700 c
->width
.PercentOf( panel
, wxWidth
, 40 );
702 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
703 pMyButton
->SetConstraints( c
);
705 c
= new wxLayoutConstraints
;
706 c
->top
.SameAs( panel
, wxTop
, 10 );
707 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
708 c
->right
.SameAs( panel
, wxRight
, 10 );
709 c
->width
.PercentOf( panel
, wxWidth
, 40 );
711 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
712 pMyButton2
->SetConstraints( c
);
714 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
718 panel
= new wxPanel(m_notebook
);
719 panel
->SetAutoLayout( TRUE
);
721 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
723 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
724 sizer
->Add( 20,20, 1 );
725 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
727 panel
->SetSizer( sizer
);
729 m_notebook
->AddPage(panel
, "wxSizer");
732 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
736 GetClientSize( &x
, &y
);
738 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
739 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
742 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
744 int selOld
= event
.GetOldSelection();
747 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
748 "page change from taking place - if you select\n"
749 "[No] the current page will stay the third one\n",
751 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
759 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
762 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
764 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
767 void MyPanel::OnCalendar(wxCalendarEvent
& event
)
769 *m_text
<< "Selected " << event
.GetDate().FormatISODate() <<
773 void MyPanel::OnCalendarChange(wxCalendarEvent
& event
)
776 s
.Printf("Selected date: %s", event
.GetDate().FormatISODate().c_str());
781 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
783 *m_text
<< "Clicked on "
784 << wxDateTime::GetWeekDayName(event
.GetWeekDay())
788 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
790 static wxColour s_colOld
;
792 // test panel colour changing and propagation to the subcontrols
795 SetBackgroundColour(s_colOld
);
796 s_colOld
= wxNullColour
;
798 m_lbSelectThis
->SetForegroundColour("yellow");
799 m_lbSelectThis
->SetBackgroundColour("blue");
803 s_colOld
= GetBackgroundColour();
804 SetBackgroundColour("green");
806 m_lbSelectThis
->SetForegroundColour("white");
807 m_lbSelectThis
->SetBackgroundColour("red");
810 m_lbSelectThis
->Refresh();
814 void MyPanel::OnListBox( wxCommandEvent
&event
)
816 // GetParent()->Move(100, 100);
818 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
821 m_text
->AppendText( "ListBox event selection string is: '" );
822 m_text
->AppendText( event
.GetString() );
823 m_text
->AppendText( "'\n" );
824 m_text
->AppendText( "ListBox control selection string is: '" );
825 m_text
->AppendText( listbox
->GetStringSelection() );
826 m_text
->AppendText( "'\n" );
828 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
829 m_text
->AppendText( "ListBox event client data string is: '" );
830 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
831 m_text
->AppendText( obj
->GetData() );
833 m_text
->AppendText( wxString("none") );
835 m_text
->AppendText( "'\n" );
836 m_text
->AppendText( "ListBox control client data string is: '" );
837 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
839 m_text
->AppendText( obj
->GetData() );
841 m_text
->AppendText( wxString("none") );
842 m_text
->AppendText( "'\n" );
845 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
847 m_text
->AppendText( "ListBox double click string is: " );
848 m_text
->AppendText( event
.GetString() );
849 m_text
->AppendText( "\n" );
852 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
854 switch (event
.GetId())
856 case ID_LISTBOX_ENABLE
:
858 m_text
->AppendText("Checkbox clicked.\n");
859 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
862 cb
->SetToolTip( "Click to enable listbox" );
864 cb
->SetToolTip( "Click to disable listbox" );
865 #endif // wxUSE_TOOLTIPS
866 m_listbox
->Enable( event
.GetInt() == 0 );
867 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
868 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
869 m_listboxSorted
->Enable( event
.GetInt() == 0 );
872 case ID_LISTBOX_SEL_NUM
:
874 m_listbox
->SetSelection( 2 );
875 m_listboxSorted
->SetSelection( 2 );
876 m_lbSelectThis
->WarpPointer( 40, 14 );
879 case ID_LISTBOX_SEL_STR
:
881 m_listbox
->SetStringSelection( "This" );
882 m_listboxSorted
->SetStringSelection( "This" );
883 m_lbSelectNum
->WarpPointer( 40, 14 );
886 case ID_LISTBOX_CLEAR
:
889 m_listboxSorted
->Clear();
892 case ID_LISTBOX_APPEND
:
894 m_listbox
->Append( "Hi!" );
895 m_listboxSorted
->Append( "Hi!" );
898 case ID_LISTBOX_DELETE
:
901 idx
= m_listbox
->GetSelection();
902 m_listbox
->Delete( idx
);
903 idx
= m_listboxSorted
->GetSelection();
904 m_listboxSorted
->Delete( idx
);
907 case ID_LISTBOX_FONT
:
909 m_listbox
->SetFont( *wxITALIC_FONT
);
910 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
911 m_checkbox
->SetFont( *wxITALIC_FONT
);
917 void MyPanel::OnChoice( wxCommandEvent
&event
)
919 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
922 m_text
->AppendText( "Choice event selection string is: '" );
923 m_text
->AppendText( event
.GetString() );
924 m_text
->AppendText( "'\n" );
925 m_text
->AppendText( "Choice control selection string is: '" );
926 m_text
->AppendText( choice
->GetStringSelection() );
927 m_text
->AppendText( "'\n" );
929 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
930 m_text
->AppendText( "Choice event client data string is: '" );
933 m_text
->AppendText( obj
->GetData() );
935 m_text
->AppendText( wxString("none") );
937 m_text
->AppendText( "'\n" );
938 m_text
->AppendText( "Choice control client data string is: '" );
939 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
942 m_text
->AppendText( obj
->GetData() );
944 m_text
->AppendText( wxString("none") );
945 m_text
->AppendText( "'\n" );
948 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
950 switch (event
.GetId())
952 case ID_CHOICE_ENABLE
:
954 m_choice
->Enable( event
.GetInt() == 0 );
955 m_choiceSorted
->Enable( event
.GetInt() == 0 );
958 case ID_CHOICE_SEL_NUM
:
960 m_choice
->SetSelection( 2 );
961 m_choiceSorted
->SetSelection( 2 );
964 case ID_CHOICE_SEL_STR
:
966 m_choice
->SetStringSelection( "This" );
967 m_choiceSorted
->SetStringSelection( "This" );
970 case ID_CHOICE_CLEAR
:
973 m_choiceSorted
->Clear();
976 case ID_CHOICE_APPEND
:
978 m_choice
->Append( "Hi!" );
979 m_choiceSorted
->Append( "Hi!" );
982 case ID_CHOICE_DELETE
:
984 int idx
= m_choice
->GetSelection();
985 m_choice
->Delete( idx
);
986 idx
= m_choiceSorted
->GetSelection();
987 m_choiceSorted
->Delete( idx
);
992 m_choice
->SetFont( *wxITALIC_FONT
);
993 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
999 void MyPanel::OnCombo( wxCommandEvent
&event
)
1001 m_text
->AppendText( "ComboBox event selection string is: " );
1002 m_text
->AppendText( event
.GetString() );
1003 m_text
->AppendText( "\n" );
1004 m_text
->AppendText( "ComboBox control selection string is: " );
1005 m_text
->AppendText( m_combo
->GetStringSelection() );
1006 m_text
->AppendText( "\n" );
1009 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1011 switch (event
.GetId())
1013 case ID_COMBO_ENABLE
:
1015 m_combo
->Enable( event
.GetInt() == 0 );
1018 case ID_COMBO_SEL_NUM
:
1020 m_combo
->SetSelection( 2 );
1023 case ID_COMBO_SEL_STR
:
1025 m_combo
->SetStringSelection( "This" );
1028 case ID_COMBO_CLEAR
:
1033 case ID_COMBO_APPEND
:
1035 m_combo
->Append( "Hi!" );
1038 case ID_COMBO_DELETE
:
1040 int idx
= m_combo
->GetSelection();
1041 m_combo
->Delete( idx
);
1046 m_combo
->SetFont( *wxITALIC_FONT
);
1052 void MyPanel::OnRadio( wxCommandEvent
&event
)
1054 m_text
->AppendText( "RadioBox selection string is: " );
1055 m_text
->AppendText( event
.GetString() );
1056 m_text
->AppendText( "\n" );
1059 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1061 switch (event
.GetId())
1063 case ID_RADIOBOX_ENABLE
:
1065 m_radio
->Enable( event
.GetInt() == 0 );
1068 case ID_RADIOBOX_SEL_NUM
:
1070 m_radio
->SetSelection( 2 );
1073 case ID_RADIOBOX_SEL_STR
:
1075 m_radio
->SetStringSelection( "This" );
1078 case ID_RADIOBOX_FONT
:
1080 m_radio
->SetFont( *wxITALIC_FONT
);
1086 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1088 m_fontButton
->SetFont( *wxITALIC_FONT
);
1089 m_text
->SetFont( *wxITALIC_FONT
);
1092 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
1094 static bool s_long
= TRUE
;
1097 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
1100 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1102 m_gauge
->SetValue( m_slider
->GetValue() );
1107 void MyPanel::OnSpinCtrl(wxCommandEvent
& event
)
1110 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1111 m_spinctrl
->GetValue(), event
.GetInt());
1112 m_text
->AppendText(s
);
1115 #endif // wxUSE_SPINCTRL
1118 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1121 value
.Printf( _T("Spin control up: current = %d\n"),
1122 m_spinbutton
->GetValue());
1124 if ( m_spinbutton
->GetValue() > 17 )
1126 value
+= _T("Preventing the spin button from going above 17.\n");
1131 m_text
->AppendText(value
);
1134 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1137 value
.Printf( _T("Spin control down: current = %d\n"),
1138 m_spinbutton
->GetValue());
1140 if ( m_spinbutton
->GetValue() < -17 )
1142 value
+= _T("Preventing the spin button from going below -17.\n");
1147 m_text
->AppendText(value
);
1150 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1153 value
.Printf( _T("%d"), event
.GetPosition() );
1154 m_spintext
->SetValue( value
);
1156 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1157 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1158 m_spinbutton
->GetValue());
1160 m_text
->AppendText(value
);
1163 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1165 event
.Enable( m_spinbutton
->GetValue() > 0 );
1168 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1170 int max
= m_spinbutton
->GetValue();
1171 wxProgressDialog
dialog("Progress dialog example",
1172 "An informative message",
1178 wxPD_ESTIMATED_TIME
|
1179 wxPD_REMAINING_TIME
);
1183 for ( int i
= 0; i
< max
&& cont
; i
++ )
1188 cont
= dialog
.Update(i
, "That's all, folks!");
1190 else if ( i
== max
/ 2 )
1192 cont
= dialog
.Update(i
, "Only a half left!");
1196 cont
= dialog
.Update(i
);
1202 *m_text
<< "Progress dialog aborted!\n";
1206 *m_text
<< "Countdown from " << max
<< " finished.\n";
1210 #endif // wxUSE_SPINBTN
1214 delete m_notebook
->GetImageList();
1217 //----------------------------------------------------------------------
1219 //----------------------------------------------------------------------
1221 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1222 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1223 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1225 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1226 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1227 #endif // wxUSE_TOOLTIPS
1229 EVT_MENU(MINIMAL_ENABLE_ALL
, MyFrame::OnEnableAll
)
1231 EVT_SIZE(MyFrame::OnSize
)
1232 EVT_MOVE(MyFrame::OnMove
)
1234 EVT_IDLE(MyFrame::OnIdle
)
1237 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1238 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1242 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1245 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1250 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1252 wxBeginBusyCursor();
1254 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1261 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1263 static long s_delay
= 5000;
1266 delay
.Printf( _T("%ld"), s_delay
);
1268 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1269 "Set tooltip delay",
1273 return; // cancelled
1275 wxSscanf(delay
, _T("%ld"), &s_delay
);
1277 wxToolTip::SetDelay(s_delay
);
1279 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1282 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1284 static bool s_enabled
= TRUE
;
1286 s_enabled
= !s_enabled
;
1288 wxToolTip::Enable(s_enabled
);
1290 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1294 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1296 static bool s_enable
= TRUE
;
1298 s_enable
= !s_enable
;
1299 m_panel
->Enable(s_enable
);
1302 void MyFrame::OnMove( wxMoveEvent
& event
)
1304 UpdateStatusBar(event
.GetPosition(), GetSize());
1309 void MyFrame::OnSize( wxSizeEvent
& event
)
1311 UpdateStatusBar(GetPosition(), event
.GetSize());
1316 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1318 // track the window which has the focus in the status bar
1319 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1320 wxWindow
*focus
= wxWindow::FindFocus();
1321 if ( focus
&& (focus
!= s_windowFocus
) )
1323 s_windowFocus
= focus
;
1328 _T("Focus: wxWindow = %p, HWND = %08x"),
1330 _T("Focus: wxWindow = %p"),
1334 , s_windowFocus
->GetHWND()
1342 static void SetControlClientData(const char *name
,
1343 wxControlWithItems
*control
)
1345 size_t count
= control
->GetCount();
1346 for ( size_t n
= 0; n
< count
; n
++ )
1349 s
.Printf("%s client data for '%s'",
1350 name
, control
->GetString(n
).c_str());
1352 control
->SetClientObject(n
, new wxStringClientData(s
));