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 //----------------------------------------------------------------------
70 //----------------------------------------------------------------------
72 class MyApp
: public wxApp
78 class MyPanel
: public wxPanel
81 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
84 void OnSize( wxSizeEvent
& event
);
85 void OnListBox( wxCommandEvent
&event
);
86 void OnListBoxDoubleClick( wxCommandEvent
&event
);
87 void OnListBoxButtons( wxCommandEvent
&event
);
88 void OnChoice( wxCommandEvent
&event
);
89 void OnChoiceButtons( wxCommandEvent
&event
);
90 void OnCombo( wxCommandEvent
&event
);
91 void OnComboButtons( wxCommandEvent
&event
);
92 void OnRadio( wxCommandEvent
&event
);
93 void OnRadioButtons( wxCommandEvent
&event
);
94 void OnSetFont( wxCommandEvent
&event
);
95 void OnPageChanged( wxNotebookEvent
&event
);
96 void OnPageChanging( wxNotebookEvent
&event
);
97 void OnSliderUpdate( wxCommandEvent
&event
);
98 void OnUpdateLabel( 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_SPINBTN
108 void OnSpinCtrl(wxCommandEvent
& event
);
109 #endif // wxUSE_SPINCTRL
111 void OnEnableAll(wxCommandEvent
& event
);
112 void OnChangeColour(wxCommandEvent
& event
);
114 wxListBox
*m_listbox
,
122 wxButton
*m_fontButton
;
123 wxButton
*m_lbSelectNum
;
124 wxButton
*m_lbSelectThis
;
126 wxSpinButton
*m_spinbutton
;
127 wxButton
*m_btnProgress
;
128 #endif // wxUSE_SPINBTN
131 wxSpinCtrl
*m_spinctrl
;
132 #endif // wxUSE_SPINCTRL
134 wxTextCtrl
*m_spintext
;
135 wxCheckBox
*m_checkbox
;
138 wxNotebook
*m_notebook
;
140 wxStaticText
*m_label
;
143 wxLog
*m_logTargetOld
;
145 DECLARE_EVENT_TABLE()
148 class MyFrame
: public wxFrame
151 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
153 void OnQuit(wxCommandEvent
& event
);
154 void OnAbout(wxCommandEvent
& event
);
157 void OnSetTooltipDelay(wxCommandEvent
& event
);
158 void OnToggleTooltips(wxCommandEvent
& event
);
159 #endif // wxUSE_TOOLTIPS
161 void OnEnableAll(wxCommandEvent
& event
);
163 void OnIdle( wxIdleEvent
& event
);
164 void OnSize( wxSizeEvent
& event
);
165 void OnMove( wxMoveEvent
& event
);
167 MyPanel
*GetPanel() const { return m_panel
; }
170 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
173 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
174 pos
.x
, pos
.y
, size
.x
, size
.y
);
175 SetStatusText(msg
, 1);
180 DECLARE_EVENT_TABLE()
183 //----------------------------------------------------------------------
185 //----------------------------------------------------------------------
187 static void SetControlClientData(const char *name
,
188 wxControlWithItems
*control
);
192 //----------------------------------------------------------------------
194 //----------------------------------------------------------------------
203 MINIMAL_SET_TOOLTIP_DELAY
= 200,
204 MINIMAL_ENABLE_TOOLTIPS
,
212 // parse the cmd line
217 wxSscanf(argv
[1], "%d", &x
);
218 wxSscanf(argv
[2], "%d", &y
);
221 // Create the main frame window
222 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
223 "Controls wxWindows App",
226 frame
->SetSizeHints( 500, 425 );
229 // The wxICON() macros loads an icon from a resource under Windows
230 // and uses an #included XPM image under GTK+ and Motif
232 frame
->SetIcon( wxICON(mondrian
) );
234 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
236 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
237 file_menu
->AppendSeparator();
238 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
240 wxMenuBar
*menu_bar
= new wxMenuBar
;
241 menu_bar
->Append(file_menu
, "&File");
244 wxMenu
*tooltip_menu
= new wxMenu
;
245 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
246 tooltip_menu
->AppendSeparator();
247 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
248 "enable/disable tooltips", TRUE
);
249 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
250 menu_bar
->Append(tooltip_menu
, "&Tooltips");
251 #endif // wxUSE_TOOLTIPS
253 wxMenu
*panel_menu
= new wxMenu
;
254 panel_menu
->Append(MINIMAL_ENABLE_ALL
, "&Disable all\tCtrl-E",
255 "Enable/disable all panel controls", TRUE
);
256 menu_bar
->Append(panel_menu
, "&Panel");
258 frame
->SetMenuBar(menu_bar
);
261 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
263 frame
->GetPanel()->m_notebook
->SetSelection(6);
270 //----------------------------------------------------------------------
272 //----------------------------------------------------------------------
274 const int ID_NOTEBOOK
= 1000;
276 const int ID_LISTBOX
= 130;
277 const int ID_LISTBOX_SEL_NUM
= 131;
278 const int ID_LISTBOX_SEL_STR
= 132;
279 const int ID_LISTBOX_CLEAR
= 133;
280 const int ID_LISTBOX_APPEND
= 134;
281 const int ID_LISTBOX_DELETE
= 135;
282 const int ID_LISTBOX_FONT
= 136;
283 const int ID_LISTBOX_ENABLE
= 137;
284 const int ID_LISTBOX_SORTED
= 138;
286 const int ID_CHOICE
= 120;
287 const int ID_CHOICE_SEL_NUM
= 121;
288 const int ID_CHOICE_SEL_STR
= 122;
289 const int ID_CHOICE_CLEAR
= 123;
290 const int ID_CHOICE_APPEND
= 124;
291 const int ID_CHOICE_DELETE
= 125;
292 const int ID_CHOICE_FONT
= 126;
293 const int ID_CHOICE_ENABLE
= 127;
294 const int ID_CHOICE_SORTED
= 128;
296 const int ID_COMBO
= 140;
297 const int ID_COMBO_SEL_NUM
= 141;
298 const int ID_COMBO_SEL_STR
= 142;
299 const int ID_COMBO_CLEAR
= 143;
300 const int ID_COMBO_APPEND
= 144;
301 const int ID_COMBO_DELETE
= 145;
302 const int ID_COMBO_FONT
= 146;
303 const int ID_COMBO_ENABLE
= 147;
305 const int ID_RADIOBOX
= 160;
306 const int ID_RADIOBOX_SEL_NUM
= 161;
307 const int ID_RADIOBOX_SEL_STR
= 162;
308 const int ID_RADIOBOX_FONT
= 163;
309 const int ID_RADIOBOX_ENABLE
= 164;
311 const int ID_RADIOBUTTON_1
= 166;
312 const int ID_RADIOBUTTON_2
= 167;
314 const int ID_SET_FONT
= 170;
316 const int ID_GAUGE
= 180;
317 const int ID_SLIDER
= 181;
319 const int ID_SPIN
= 182;
320 const int ID_BTNPROGRESS
= 183;
321 const int ID_BUTTON_LABEL
= 184;
322 const int ID_SPINCTRL
= 185;
324 const int ID_CHANGE_COLOUR
= 200;
326 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
327 EVT_SIZE ( MyPanel::OnSize
)
328 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
329 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
330 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
331 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
332 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
333 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
334 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
335 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
336 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
337 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
338 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
339 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
340 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
341 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
342 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
343 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
344 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
345 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
346 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
347 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
348 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
349 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
350 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
351 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
352 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
353 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
354 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
355 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
356 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
357 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
358 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
359 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
360 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
361 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
362 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
363 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
365 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
366 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
367 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
368 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
369 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
370 #endif // wxUSE_SPINBTN
372 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
373 #endif // wxUSE_SPINCTRL
374 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
375 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
378 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
379 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
380 m_text(NULL
), m_notebook(NULL
)
382 wxLayoutConstraints
*c
;
384 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
385 // m_text->SetBackgroundColour("wheat");
387 //wxLog::AddTraceMask(_T("focus"));
388 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
390 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
405 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
408 // fill the image list
409 wxImageList
*imagelist
= new wxImageList(32, 32);
411 imagelist
-> Add( wxBitmap( list_xpm
));
412 imagelist
-> Add( wxBitmap( choice_xpm
));
413 imagelist
-> Add( wxBitmap( combo_xpm
));
414 imagelist
-> Add( wxBitmap( text_xpm
));
415 imagelist
-> Add( wxBitmap( radio_xpm
));
416 imagelist
-> Add( wxBitmap( gauge_xpm
));
417 m_notebook
->SetImageList(imagelist
);
418 #elif defined(__WXMSW__)
419 // load images from resources
422 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
424 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
426 static const char *s_iconNames
[Image_Max
] =
428 "list", "choice", "combo", "text", "radio", "gauge"
431 for ( size_t n
= 0; n
< Image_Max
; n
++ )
433 wxBitmap
bmp(s_iconNames
[n
]);
434 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
436 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
441 m_notebook
->SetImageList(imagelist
);
445 #define Image_List -1
446 #define Image_Choice -1
447 #define Image_Combo -1
448 #define Image_Text -1
449 #define Image_Radio -1
450 #define Image_Gauge -1
455 wxPanel
*panel
= new wxPanel(m_notebook
);
456 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
457 wxPoint(10,10), wxSize(120,70),
458 5, choices
, wxLB_ALWAYS_SB
);
459 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
460 wxPoint(10,90), wxSize(120,70),
461 5, choices
, wxLB_SORT
);
463 SetControlClientData("listbox", m_listbox
);
464 SetControlClientData("listbox", m_listboxSorted
);
466 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
468 m_listbox
->SetToolTip( "This is a list box" );
469 #endif // wxUSE_TOOLTIPS
471 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
472 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
473 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
474 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
475 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
476 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
478 button
->SetDefault();
480 button
->SetForegroundColour(*wxBLUE
);
483 button
->SetToolTip( "Press here to set italic font" );
484 #endif // wxUSE_TOOLTIPS
486 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
487 m_checkbox
->SetValue(FALSE
);
489 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
490 #endif // wxUSE_TOOLTIPS
491 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
493 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
495 panel
= new wxPanel(m_notebook
);
496 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
497 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
498 5, choices
, wxCB_SORT
);
501 SetControlClientData("choice", m_choice
);
502 SetControlClientData("choice", m_choiceSorted
);
505 m_choice
->SetSelection(2);
506 m_choice
->SetBackgroundColour( "red" );
507 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
508 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
509 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
510 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
511 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
512 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
513 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
515 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
517 panel
= new wxPanel(m_notebook
);
518 (void)new wxStaticBox( panel
, -1, "Box around combobox",
519 wxPoint(5, 5), wxSize(150, 100));
520 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(20,25), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
521 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
522 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
523 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
524 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
525 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
526 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
527 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
528 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
530 wxString choices2
[] =
534 "Fourth", "Fifth", "Sixth",
535 "Seventh", "Eighth", "Nineth", "Tenth" */
538 panel
= new wxPanel(m_notebook
);
539 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
540 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
543 m_radio
->SetToolTip("Ever seen a radiobox?");
544 #endif // wxUSE_TOOLTIPS
546 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
547 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
548 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
549 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
550 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxDefaultSize
);
551 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
552 rb
->SetValue( FALSE
);
553 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxDefaultSize
);
554 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
556 panel
= new wxPanel(m_notebook
);
557 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
558 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
559 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
560 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
562 // No wrapping text in wxStaticText yet :-(
563 (void)new wxStaticText( panel
, -1,
569 (void)new wxStaticText( panel
, -1,
570 "In order see the gauge (aka progress bar)\n"
571 "control do something you have to drag the\n"
572 "handle of the slider to the right.\n"
574 "This is also supposed to demonstrate how\n"
575 "to use static controls.\n",
580 int initialSpinValue
= -5;
582 s
<< initialSpinValue
;
583 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
585 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
586 m_spinbutton
->SetRange(-10,30);
587 m_spinbutton
->SetValue(initialSpinValue
);
589 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
591 #endif // wxUSE_SPINBTN
594 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
595 m_spinctrl
->SetRange(10,30);
596 m_spinctrl
->SetValue(15);
597 #endif // wxUSE_SPINCTRL
599 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
601 panel
= new wxPanel(m_notebook
);
603 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
604 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
605 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
608 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
609 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
612 wxBitmap
bitmap( 100, 100 );
614 dc
.SelectObject( bitmap
);
615 dc
.SetPen(*wxGREEN_PEN
);
617 dc
.DrawEllipse(5, 5, 90, 90);
618 dc
.DrawText("Bitmap", 30, 40);
619 dc
.SelectObject( wxNullBitmap
);
621 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(100, 20));
624 bitmap
= wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
626 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
627 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(300, 120));
630 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
631 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
632 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
633 wxBitmapButton
*bmpBtn
= new wxBitmapButton
639 bmpBtn
->SetBitmapSelected(bmp2
);
640 bmpBtn
->SetBitmapFocus(bmp3
);
642 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "Toggle label", wxPoint(250, 20));
643 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
644 wxPoint(250, 60), wxDefaultSize
,
645 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
647 m_notebook
->AddPage(panel
, "wxBitmapXXX");
649 // layout constraints
651 panel
= new wxPanel(m_notebook
);
652 panel
->SetAutoLayout( TRUE
);
654 c
= new wxLayoutConstraints
;
655 c
->top
.SameAs( panel
, wxTop
, 10 );
657 c
->left
.SameAs( panel
, wxLeft
, 10 );
658 c
->width
.PercentOf( panel
, wxWidth
, 40 );
660 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
661 pMyButton
->SetConstraints( c
);
663 c
= new wxLayoutConstraints
;
664 c
->top
.SameAs( panel
, wxTop
, 10 );
665 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
666 c
->right
.SameAs( panel
, wxRight
, 10 );
667 c
->width
.PercentOf( panel
, wxWidth
, 40 );
669 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
670 pMyButton2
->SetConstraints( c
);
672 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
676 panel
= new wxPanel(m_notebook
);
677 panel
->SetAutoLayout( TRUE
);
679 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
681 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
682 sizer
->Add( 20,20, 1 );
683 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
685 panel
->SetSizer( sizer
);
687 m_notebook
->AddPage(panel
, "wxSizer");
690 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
694 GetClientSize( &x
, &y
);
696 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
697 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
700 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
702 int selOld
= event
.GetOldSelection();
705 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
706 "page change from taking place - if you select\n"
707 "[No] the current page will stay the third one\n",
709 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
717 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
720 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
722 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
725 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
727 static wxColour s_colOld
;
729 // test panel colour changing and propagation to the subcontrols
732 SetBackgroundColour(s_colOld
);
733 s_colOld
= wxNullColour
;
735 m_lbSelectThis
->SetForegroundColour("yellow");
736 m_lbSelectThis
->SetBackgroundColour("blue");
740 s_colOld
= GetBackgroundColour();
741 SetBackgroundColour("green");
743 m_lbSelectThis
->SetForegroundColour("white");
744 m_lbSelectThis
->SetBackgroundColour("red");
747 m_lbSelectThis
->Refresh();
751 void MyPanel::OnListBox( wxCommandEvent
&event
)
753 // GetParent()->Move(100, 100);
755 if (event
.GetInt() == -1)
757 m_text
->AppendText( "ListBox has no selections anymore\n" );
761 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
764 m_text
->AppendText( "ListBox event selection string is: '" );
765 m_text
->AppendText( event
.GetString() );
766 m_text
->AppendText( "'\n" );
767 m_text
->AppendText( "ListBox control selection string is: '" );
768 m_text
->AppendText( listbox
->GetStringSelection() );
769 m_text
->AppendText( "'\n" );
771 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
772 m_text
->AppendText( "ListBox event client data string is: '" );
773 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
774 m_text
->AppendText( obj
->GetData() );
776 m_text
->AppendText( wxString("none") );
778 m_text
->AppendText( "'\n" );
779 m_text
->AppendText( "ListBox control client data string is: '" );
780 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
782 m_text
->AppendText( obj
->GetData() );
784 m_text
->AppendText( wxString("none") );
785 m_text
->AppendText( "'\n" );
788 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
790 m_text
->AppendText( "ListBox double click string is: " );
791 m_text
->AppendText( event
.GetString() );
792 m_text
->AppendText( "\n" );
795 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
797 switch (event
.GetId())
799 case ID_LISTBOX_ENABLE
:
801 m_text
->AppendText("Checkbox clicked.\n");
802 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
805 cb
->SetToolTip( "Click to enable listbox" );
807 cb
->SetToolTip( "Click to disable listbox" );
808 #endif // wxUSE_TOOLTIPS
809 m_listbox
->Enable( event
.GetInt() == 0 );
810 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
811 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
812 m_listboxSorted
->Enable( event
.GetInt() == 0 );
815 case ID_LISTBOX_SEL_NUM
:
817 m_listbox
->SetSelection( 2 );
818 m_listboxSorted
->SetSelection( 2 );
819 m_lbSelectThis
->WarpPointer( 40, 14 );
822 case ID_LISTBOX_SEL_STR
:
824 m_listbox
->SetStringSelection( "This" );
825 m_listboxSorted
->SetStringSelection( "This" );
826 m_lbSelectNum
->WarpPointer( 40, 14 );
829 case ID_LISTBOX_CLEAR
:
832 m_listboxSorted
->Clear();
835 case ID_LISTBOX_APPEND
:
837 m_listbox
->Append( "Hi!" );
838 m_listboxSorted
->Append( "Hi!" );
841 case ID_LISTBOX_DELETE
:
844 idx
= m_listbox
->GetSelection();
845 m_listbox
->Delete( idx
);
846 idx
= m_listboxSorted
->GetSelection();
847 m_listboxSorted
->Delete( idx
);
850 case ID_LISTBOX_FONT
:
852 m_listbox
->SetFont( *wxITALIC_FONT
);
853 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
854 m_checkbox
->SetFont( *wxITALIC_FONT
);
860 void MyPanel::OnChoice( wxCommandEvent
&event
)
862 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
865 m_text
->AppendText( "Choice event selection string is: '" );
866 m_text
->AppendText( event
.GetString() );
867 m_text
->AppendText( "'\n" );
868 m_text
->AppendText( "Choice control selection string is: '" );
869 m_text
->AppendText( choice
->GetStringSelection() );
870 m_text
->AppendText( "'\n" );
872 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
873 m_text
->AppendText( "Choice event client data string is: '" );
876 m_text
->AppendText( obj
->GetData() );
878 m_text
->AppendText( wxString("none") );
880 m_text
->AppendText( "'\n" );
881 m_text
->AppendText( "Choice control client data string is: '" );
882 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
885 m_text
->AppendText( obj
->GetData() );
887 m_text
->AppendText( wxString("none") );
888 m_text
->AppendText( "'\n" );
891 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
893 switch (event
.GetId())
895 case ID_CHOICE_ENABLE
:
897 m_choice
->Enable( event
.GetInt() == 0 );
898 m_choiceSorted
->Enable( event
.GetInt() == 0 );
901 case ID_CHOICE_SEL_NUM
:
903 m_choice
->SetSelection( 2 );
904 m_choiceSorted
->SetSelection( 2 );
907 case ID_CHOICE_SEL_STR
:
909 m_choice
->SetStringSelection( "This" );
910 m_choiceSorted
->SetStringSelection( "This" );
913 case ID_CHOICE_CLEAR
:
916 m_choiceSorted
->Clear();
919 case ID_CHOICE_APPEND
:
921 m_choice
->Append( "Hi!" );
922 m_choiceSorted
->Append( "Hi!" );
925 case ID_CHOICE_DELETE
:
927 int idx
= m_choice
->GetSelection();
928 m_choice
->Delete( idx
);
929 idx
= m_choiceSorted
->GetSelection();
930 m_choiceSorted
->Delete( idx
);
935 m_choice
->SetFont( *wxITALIC_FONT
);
936 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
942 void MyPanel::OnCombo( wxCommandEvent
&event
)
944 m_text
->AppendText( "ComboBox event selection string is: " );
945 m_text
->AppendText( event
.GetString() );
946 m_text
->AppendText( "\n" );
947 m_text
->AppendText( "ComboBox control selection string is: " );
948 m_text
->AppendText( m_combo
->GetStringSelection() );
949 m_text
->AppendText( "\n" );
952 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
954 switch (event
.GetId())
956 case ID_COMBO_ENABLE
:
958 m_combo
->Enable( event
.GetInt() == 0 );
961 case ID_COMBO_SEL_NUM
:
963 m_combo
->SetSelection( 2 );
966 case ID_COMBO_SEL_STR
:
968 m_combo
->SetStringSelection( "This" );
976 case ID_COMBO_APPEND
:
978 m_combo
->Append( "Hi!" );
981 case ID_COMBO_DELETE
:
983 int idx
= m_combo
->GetSelection();
984 m_combo
->Delete( idx
);
989 m_combo
->SetFont( *wxITALIC_FONT
);
995 void MyPanel::OnRadio( wxCommandEvent
&event
)
997 m_text
->AppendText( "RadioBox selection string is: " );
998 m_text
->AppendText( event
.GetString() );
999 m_text
->AppendText( "\n" );
1002 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1004 switch (event
.GetId())
1006 case ID_RADIOBOX_ENABLE
:
1008 m_radio
->Enable( event
.GetInt() == 0 );
1011 case ID_RADIOBOX_SEL_NUM
:
1013 m_radio
->SetSelection( 2 );
1016 case ID_RADIOBOX_SEL_STR
:
1018 m_radio
->SetStringSelection( "This" );
1021 case ID_RADIOBOX_FONT
:
1023 m_radio
->SetFont( *wxITALIC_FONT
);
1029 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1031 m_fontButton
->SetFont( *wxITALIC_FONT
);
1032 m_text
->SetFont( *wxITALIC_FONT
);
1035 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
1037 static bool s_long
= TRUE
;
1040 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
1043 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1045 m_gauge
->SetValue( m_slider
->GetValue() );
1050 void MyPanel::OnSpinCtrl(wxCommandEvent
& event
)
1053 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1054 m_spinctrl
->GetValue(), event
.GetInt());
1055 m_text
->AppendText(s
);
1058 #endif // wxUSE_SPINCTRL
1061 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1064 value
.Printf( _T("Spin control up: current = %d\n"),
1065 m_spinbutton
->GetValue());
1067 if ( m_spinbutton
->GetValue() > 17 )
1069 value
+= _T("Preventing the spin button from going above 17.\n");
1074 m_text
->AppendText(value
);
1077 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1080 value
.Printf( _T("Spin control down: current = %d\n"),
1081 m_spinbutton
->GetValue());
1083 if ( m_spinbutton
->GetValue() < -17 )
1085 value
+= _T("Preventing the spin button from going below -17.\n");
1090 m_text
->AppendText(value
);
1093 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1096 value
.Printf( _T("%d"), event
.GetPosition() );
1097 m_spintext
->SetValue( value
);
1099 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1100 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1101 m_spinbutton
->GetValue());
1103 m_text
->AppendText(value
);
1106 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1108 event
.Enable( m_spinbutton
->GetValue() > 0 );
1111 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1113 int max
= m_spinbutton
->GetValue();
1114 wxProgressDialog
dialog("Progress dialog example",
1115 "An informative message",
1121 wxPD_ESTIMATED_TIME
|
1122 wxPD_REMAINING_TIME
);
1126 for ( int i
= 0; i
< max
&& cont
; i
++ )
1131 cont
= dialog
.Update(i
, "That's all, folks!");
1133 else if ( i
== max
/ 2 )
1135 cont
= dialog
.Update(i
, "Only a half left!");
1139 cont
= dialog
.Update(i
);
1145 *m_text
<< "Progress dialog aborted!\n";
1149 *m_text
<< "Countdown from " << max
<< " finished.\n";
1153 #endif // wxUSE_SPINBTN
1157 //wxLog::RemoveTraceMask(_T("focus"));
1158 delete wxLog::SetActiveTarget(m_logTargetOld
);
1160 delete m_notebook
->GetImageList();
1163 //----------------------------------------------------------------------
1165 //----------------------------------------------------------------------
1167 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1168 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1169 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1171 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1172 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1173 #endif // wxUSE_TOOLTIPS
1175 EVT_MENU(MINIMAL_ENABLE_ALL
, MyFrame::OnEnableAll
)
1177 EVT_SIZE(MyFrame::OnSize
)
1178 EVT_MOVE(MyFrame::OnMove
)
1180 EVT_IDLE(MyFrame::OnIdle
)
1183 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1184 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1188 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1191 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1196 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1198 wxBeginBusyCursor();
1200 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1207 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1209 static long s_delay
= 5000;
1212 delay
.Printf( _T("%ld"), s_delay
);
1214 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1215 "Set tooltip delay",
1219 return; // cancelled
1221 wxSscanf(delay
, _T("%ld"), &s_delay
);
1223 wxToolTip::SetDelay(s_delay
);
1225 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1228 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1230 static bool s_enabled
= TRUE
;
1232 s_enabled
= !s_enabled
;
1234 wxToolTip::Enable(s_enabled
);
1236 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1240 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1242 static bool s_enable
= TRUE
;
1244 s_enable
= !s_enable
;
1245 m_panel
->Enable(s_enable
);
1248 void MyFrame::OnMove( wxMoveEvent
& event
)
1250 UpdateStatusBar(event
.GetPosition(), GetSize());
1255 void MyFrame::OnSize( wxSizeEvent
& event
)
1257 UpdateStatusBar(GetPosition(), event
.GetSize());
1262 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1264 // track the window which has the focus in the status bar
1265 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1266 wxWindow
*focus
= wxWindow::FindFocus();
1267 if ( focus
&& (focus
!= s_windowFocus
) )
1269 s_windowFocus
= focus
;
1274 _T("Focus: %s, HWND = %08x"),
1278 s_windowFocus
->GetClassInfo()->GetClassName()
1280 , s_windowFocus
->GetHWND()
1288 static void SetControlClientData(const char *name
,
1289 wxControlWithItems
*control
)
1291 size_t count
= control
->GetCount();
1292 for ( size_t n
= 0; n
< count
; n
++ )
1295 s
.Printf("%s client data for '%s'",
1296 name
, control
->GetString(n
).c_str());
1298 control
->SetClientObject(n
, new wxStringClientData(s
));