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 DECLARE_EVENT_TABLE()
146 class MyFrame
: public wxFrame
149 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
151 void OnQuit(wxCommandEvent
& event
);
152 void OnAbout(wxCommandEvent
& event
);
155 void OnSetTooltipDelay(wxCommandEvent
& event
);
156 void OnToggleTooltips(wxCommandEvent
& event
);
157 #endif // wxUSE_TOOLTIPS
159 void OnEnableAll(wxCommandEvent
& event
);
161 void OnIdle( wxIdleEvent
& event
);
162 void OnSize( wxSizeEvent
& event
);
163 void OnMove( wxMoveEvent
& event
);
165 MyPanel
*GetPanel() const { return m_panel
; }
168 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
171 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
172 pos
.x
, pos
.y
, size
.x
, size
.y
);
173 SetStatusText(msg
, 1);
178 DECLARE_EVENT_TABLE()
181 //----------------------------------------------------------------------
183 //----------------------------------------------------------------------
185 static void SetControlClientData(const char *name
,
186 wxControlWithItems
*control
);
190 //----------------------------------------------------------------------
192 //----------------------------------------------------------------------
201 MINIMAL_SET_TOOLTIP_DELAY
= 200,
202 MINIMAL_ENABLE_TOOLTIPS
,
210 // parse the cmd line
215 wxSscanf(argv
[1], "%d", &x
);
216 wxSscanf(argv
[2], "%d", &y
);
219 // Create the main frame window
220 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
221 "Controls wxWindows App",
224 frame
->SetSizeHints( 500, 425 );
227 // The wxICON() macros loads an icon from a resource under Windows
228 // and uses an #included XPM image under GTK+ and Motif
230 frame
->SetIcon( wxICON(mondrian
) );
232 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
234 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
235 file_menu
->AppendSeparator();
236 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
238 wxMenuBar
*menu_bar
= new wxMenuBar
;
239 menu_bar
->Append(file_menu
, "&File");
242 wxMenu
*tooltip_menu
= new wxMenu
;
243 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
244 tooltip_menu
->AppendSeparator();
245 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
246 "enable/disable tooltips", TRUE
);
247 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
248 menu_bar
->Append(tooltip_menu
, "&Tooltips");
249 #endif // wxUSE_TOOLTIPS
251 wxMenu
*panel_menu
= new wxMenu
;
252 panel_menu
->Append(MINIMAL_ENABLE_ALL
, "&Disable all\tCtrl-E",
253 "Enable/disable all panel controls", TRUE
);
254 menu_bar
->Append(panel_menu
, "&Panel");
256 frame
->SetMenuBar(menu_bar
);
259 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
261 frame
->GetPanel()->m_notebook
->SetSelection(6);
268 //----------------------------------------------------------------------
270 //----------------------------------------------------------------------
272 const int ID_NOTEBOOK
= 1000;
274 const int ID_LISTBOX
= 130;
275 const int ID_LISTBOX_SEL_NUM
= 131;
276 const int ID_LISTBOX_SEL_STR
= 132;
277 const int ID_LISTBOX_CLEAR
= 133;
278 const int ID_LISTBOX_APPEND
= 134;
279 const int ID_LISTBOX_DELETE
= 135;
280 const int ID_LISTBOX_FONT
= 136;
281 const int ID_LISTBOX_ENABLE
= 137;
282 const int ID_LISTBOX_SORTED
= 138;
284 const int ID_CHOICE
= 120;
285 const int ID_CHOICE_SEL_NUM
= 121;
286 const int ID_CHOICE_SEL_STR
= 122;
287 const int ID_CHOICE_CLEAR
= 123;
288 const int ID_CHOICE_APPEND
= 124;
289 const int ID_CHOICE_DELETE
= 125;
290 const int ID_CHOICE_FONT
= 126;
291 const int ID_CHOICE_ENABLE
= 127;
292 const int ID_CHOICE_SORTED
= 128;
294 const int ID_COMBO
= 140;
295 const int ID_COMBO_SEL_NUM
= 141;
296 const int ID_COMBO_SEL_STR
= 142;
297 const int ID_COMBO_CLEAR
= 143;
298 const int ID_COMBO_APPEND
= 144;
299 const int ID_COMBO_DELETE
= 145;
300 const int ID_COMBO_FONT
= 146;
301 const int ID_COMBO_ENABLE
= 147;
303 const int ID_RADIOBOX
= 160;
304 const int ID_RADIOBOX_SEL_NUM
= 161;
305 const int ID_RADIOBOX_SEL_STR
= 162;
306 const int ID_RADIOBOX_FONT
= 163;
307 const int ID_RADIOBOX_ENABLE
= 164;
309 const int ID_RADIOBUTTON_1
= 166;
310 const int ID_RADIOBUTTON_2
= 167;
312 const int ID_SET_FONT
= 170;
314 const int ID_GAUGE
= 180;
315 const int ID_SLIDER
= 181;
317 const int ID_SPIN
= 182;
318 const int ID_BTNPROGRESS
= 183;
319 const int ID_BUTTON_LABEL
= 184;
320 const int ID_SPINCTRL
= 185;
322 const int ID_CHANGE_COLOUR
= 200;
324 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
325 EVT_SIZE ( MyPanel::OnSize
)
326 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
327 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
328 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
329 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
330 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
331 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
332 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
333 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
334 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
335 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
336 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
337 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
338 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
339 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
340 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
341 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
342 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
343 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
344 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
345 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
346 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
347 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
348 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
349 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
350 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
351 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
352 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
353 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
354 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
355 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
356 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
357 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
358 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
359 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
360 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
361 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
363 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
364 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
365 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
366 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
367 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
368 #endif // wxUSE_SPINBTN
370 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
371 #endif // wxUSE_SPINCTRL
372 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
373 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
376 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
377 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
378 m_text(NULL
), m_notebook(NULL
)
380 wxLayoutConstraints
*c
;
382 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
383 // m_text->SetBackgroundColour("wheat");
385 //delete wxLog::SetActiveTarget(new wxLogStderr);
387 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
402 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
405 // fill the image list
406 wxImageList
*imagelist
= new wxImageList(32, 32);
408 imagelist
-> Add( wxBitmap( list_xpm
));
409 imagelist
-> Add( wxBitmap( choice_xpm
));
410 imagelist
-> Add( wxBitmap( combo_xpm
));
411 imagelist
-> Add( wxBitmap( text_xpm
));
412 imagelist
-> Add( wxBitmap( radio_xpm
));
413 imagelist
-> Add( wxBitmap( gauge_xpm
));
414 m_notebook
->SetImageList(imagelist
);
415 #elif defined(__WXMSW__)
416 // load images from resources
419 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
421 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
423 static const char *s_iconNames
[Image_Max
] =
425 "list", "choice", "combo", "text", "radio", "gauge"
428 for ( size_t n
= 0; n
< Image_Max
; n
++ )
430 wxBitmap
bmp(s_iconNames
[n
]);
431 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
433 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
438 m_notebook
->SetImageList(imagelist
);
442 #define Image_List -1
443 #define Image_Choice -1
444 #define Image_Combo -1
445 #define Image_Text -1
446 #define Image_Radio -1
447 #define Image_Gauge -1
452 wxPanel
*panel
= new wxPanel(m_notebook
);
453 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
454 wxPoint(10,10), wxSize(120,70),
455 5, choices
, wxLB_ALWAYS_SB
);
456 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
457 wxPoint(10,90), wxSize(120,70),
458 5, choices
, wxLB_SORT
);
460 SetControlClientData("listbox", m_listbox
);
461 SetControlClientData("listbox", m_listboxSorted
);
463 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
465 m_listbox
->SetToolTip( "This is a list box" );
466 #endif // wxUSE_TOOLTIPS
468 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
469 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
470 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
471 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
472 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
473 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
475 button
->SetDefault();
477 button
->SetForegroundColour(*wxBLUE
);
480 button
->SetToolTip( "Press here to set italic font" );
481 #endif // wxUSE_TOOLTIPS
483 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
484 m_checkbox
->SetValue(FALSE
);
486 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
487 #endif // wxUSE_TOOLTIPS
488 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
490 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
492 panel
= new wxPanel(m_notebook
);
493 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
494 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
495 5, choices
, wxCB_SORT
);
498 SetControlClientData("choice", m_choice
);
499 SetControlClientData("choice", m_choiceSorted
);
502 m_choice
->SetSelection(2);
503 m_choice
->SetBackgroundColour( "red" );
504 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
505 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
506 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
507 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
508 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
509 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
510 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
512 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
514 panel
= new wxPanel(m_notebook
);
515 (void)new wxStaticBox( panel
, -1, "Box around combobox",
516 wxPoint(5, 5), wxSize(150, 100));
517 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(20,25), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
518 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
519 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
520 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
521 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
522 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
523 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
524 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
525 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
527 wxString choices2
[] =
531 "Fourth", "Fifth", "Sixth",
532 "Seventh", "Eighth", "Nineth", "Tenth" */
535 panel
= new wxPanel(m_notebook
);
536 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
537 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
540 m_radio
->SetToolTip("Ever seen a radiobox?");
541 #endif // wxUSE_TOOLTIPS
543 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
544 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
545 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
546 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
547 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxDefaultSize
);
548 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
549 rb
->SetValue( FALSE
);
550 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxDefaultSize
);
551 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
553 panel
= new wxPanel(m_notebook
);
554 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
555 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
556 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
557 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(220,10), wxSize(270,130) );
559 // No wrapping text in wxStaticText yet :-(
560 (void)new wxStaticText( panel
, -1,
566 (void)new wxStaticText( panel
, -1,
567 "In order see the gauge (aka progress bar)\n"
568 "control do something you have to drag the\n"
569 "handle of the slider to the right.\n"
571 "This is also supposed to demonstrate how\n"
572 "to use static controls.\n",
577 int initialSpinValue
= -5;
579 s
<< initialSpinValue
;
580 m_spintext
= new wxTextCtrl( panel
, -1, s
, wxPoint(20,160), wxSize(80,-1) );
582 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,160), wxSize(80, -1) );
583 m_spinbutton
->SetRange(-10,30);
584 m_spinbutton
->SetValue(initialSpinValue
);
586 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
588 #endif // wxUSE_SPINBTN
591 m_spinctrl
= new wxSpinCtrl( panel
, ID_SPINCTRL
, "", wxPoint(200, 160), wxSize(80, -1) );
592 m_spinctrl
->SetRange(10,30);
593 m_spinctrl
->SetValue(15);
594 #endif // wxUSE_SPINCTRL
596 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
598 panel
= new wxPanel(m_notebook
);
600 #ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
601 wxIcon icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
602 wxStaticBitmap
*bmpStatic
= new wxStaticBitmap(panel
, -1, icon
,
605 bmpStatic
= new wxStaticBitmap(panel
, -1, wxNullIcon
, wxPoint(50, 10));
606 bmpStatic
->SetIcon(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
609 wxBitmap
bitmap( 100, 100 );
611 dc
.SelectObject( bitmap
);
612 dc
.SetPen(*wxGREEN_PEN
);
614 dc
.DrawEllipse(5, 5, 90, 90);
615 dc
.DrawText("Bitmap", 30, 40);
616 dc
.SelectObject( wxNullBitmap
);
618 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(100, 20));
621 bitmap
= wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
623 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
624 (void)new wxBitmapButton(panel
, -1, bitmap
, wxPoint(300, 120));
627 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
628 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
629 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
630 wxBitmapButton
*bmpBtn
= new wxBitmapButton
636 bmpBtn
->SetBitmapSelected(bmp2
);
637 bmpBtn
->SetBitmapFocus(bmp3
);
639 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "Toggle label", wxPoint(250, 20));
640 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
641 wxPoint(250, 60), wxDefaultSize
,
642 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
644 m_notebook
->AddPage(panel
, "wxBitmapXXX");
646 // layout constraints
648 panel
= new wxPanel(m_notebook
);
649 panel
->SetAutoLayout( TRUE
);
651 c
= new wxLayoutConstraints
;
652 c
->top
.SameAs( panel
, wxTop
, 10 );
654 c
->left
.SameAs( panel
, wxLeft
, 10 );
655 c
->width
.PercentOf( panel
, wxWidth
, 40 );
657 wxButton
*pMyButton
= new wxButton(panel
, -1, "Test Button" );
658 pMyButton
->SetConstraints( c
);
660 c
= new wxLayoutConstraints
;
661 c
->top
.SameAs( panel
, wxTop
, 10 );
662 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
663 c
->right
.SameAs( panel
, wxRight
, 10 );
664 c
->width
.PercentOf( panel
, wxWidth
, 40 );
666 wxButton
*pMyButton2
= new wxButton(panel
, -1, "Test Button 2" );
667 pMyButton2
->SetConstraints( c
);
669 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
673 panel
= new wxPanel(m_notebook
);
674 panel
->SetAutoLayout( TRUE
);
676 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
678 sizer
->Add( new wxButton(panel
, -1, "Test Button" ), 3, wxALL
, 10 );
679 sizer
->Add( 20,20, 1 );
680 sizer
->Add( new wxButton(panel
, -1, "Test Button 2" ), 3, wxGROW
|wxALL
, 10 );
682 panel
->SetSizer( sizer
);
684 m_notebook
->AddPage(panel
, "wxSizer");
687 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
691 GetClientSize( &x
, &y
);
693 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
694 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
697 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
699 int selOld
= event
.GetOldSelection();
702 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
703 "page change from taking place - if you select\n"
704 "[No] the current page will stay the third one\n",
706 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
714 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
717 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
719 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
722 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
724 static wxColour s_colOld
;
726 // test panel colour changing and propagation to the subcontrols
729 SetBackgroundColour(s_colOld
);
730 s_colOld
= wxNullColour
;
732 m_lbSelectThis
->SetForegroundColour("yellow");
733 m_lbSelectThis
->SetBackgroundColour("blue");
737 s_colOld
= GetBackgroundColour();
738 SetBackgroundColour("green");
740 m_lbSelectThis
->SetForegroundColour("white");
741 m_lbSelectThis
->SetBackgroundColour("red");
744 m_lbSelectThis
->Refresh();
748 void MyPanel::OnListBox( wxCommandEvent
&event
)
750 // GetParent()->Move(100, 100);
752 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
755 m_text
->AppendText( "ListBox event selection string is: '" );
756 m_text
->AppendText( event
.GetString() );
757 m_text
->AppendText( "'\n" );
758 m_text
->AppendText( "ListBox control selection string is: '" );
759 m_text
->AppendText( listbox
->GetStringSelection() );
760 m_text
->AppendText( "'\n" );
762 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
763 m_text
->AppendText( "ListBox event client data string is: '" );
764 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
765 m_text
->AppendText( obj
->GetData() );
767 m_text
->AppendText( wxString("none") );
769 m_text
->AppendText( "'\n" );
770 m_text
->AppendText( "ListBox control client data string is: '" );
771 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
773 m_text
->AppendText( obj
->GetData() );
775 m_text
->AppendText( wxString("none") );
776 m_text
->AppendText( "'\n" );
779 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
781 m_text
->AppendText( "ListBox double click string is: " );
782 m_text
->AppendText( event
.GetString() );
783 m_text
->AppendText( "\n" );
786 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
788 switch (event
.GetId())
790 case ID_LISTBOX_ENABLE
:
792 m_text
->AppendText("Checkbox clicked.\n");
793 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
796 cb
->SetToolTip( "Click to enable listbox" );
798 cb
->SetToolTip( "Click to disable listbox" );
799 #endif // wxUSE_TOOLTIPS
800 m_listbox
->Enable( event
.GetInt() == 0 );
801 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
802 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
803 m_listboxSorted
->Enable( event
.GetInt() == 0 );
806 case ID_LISTBOX_SEL_NUM
:
808 m_listbox
->SetSelection( 2 );
809 m_listboxSorted
->SetSelection( 2 );
810 m_lbSelectThis
->WarpPointer( 40, 14 );
813 case ID_LISTBOX_SEL_STR
:
815 m_listbox
->SetStringSelection( "This" );
816 m_listboxSorted
->SetStringSelection( "This" );
817 m_lbSelectNum
->WarpPointer( 40, 14 );
820 case ID_LISTBOX_CLEAR
:
823 m_listboxSorted
->Clear();
826 case ID_LISTBOX_APPEND
:
828 m_listbox
->Append( "Hi!" );
829 m_listboxSorted
->Append( "Hi!" );
832 case ID_LISTBOX_DELETE
:
835 idx
= m_listbox
->GetSelection();
836 m_listbox
->Delete( idx
);
837 idx
= m_listboxSorted
->GetSelection();
838 m_listboxSorted
->Delete( idx
);
841 case ID_LISTBOX_FONT
:
843 m_listbox
->SetFont( *wxITALIC_FONT
);
844 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
845 m_checkbox
->SetFont( *wxITALIC_FONT
);
851 void MyPanel::OnChoice( wxCommandEvent
&event
)
853 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
856 m_text
->AppendText( "Choice event selection string is: '" );
857 m_text
->AppendText( event
.GetString() );
858 m_text
->AppendText( "'\n" );
859 m_text
->AppendText( "Choice control selection string is: '" );
860 m_text
->AppendText( choice
->GetStringSelection() );
861 m_text
->AppendText( "'\n" );
863 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
864 m_text
->AppendText( "Choice event client data string is: '" );
867 m_text
->AppendText( obj
->GetData() );
869 m_text
->AppendText( wxString("none") );
871 m_text
->AppendText( "'\n" );
872 m_text
->AppendText( "Choice control client data string is: '" );
873 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
876 m_text
->AppendText( obj
->GetData() );
878 m_text
->AppendText( wxString("none") );
879 m_text
->AppendText( "'\n" );
882 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
884 switch (event
.GetId())
886 case ID_CHOICE_ENABLE
:
888 m_choice
->Enable( event
.GetInt() == 0 );
889 m_choiceSorted
->Enable( event
.GetInt() == 0 );
892 case ID_CHOICE_SEL_NUM
:
894 m_choice
->SetSelection( 2 );
895 m_choiceSorted
->SetSelection( 2 );
898 case ID_CHOICE_SEL_STR
:
900 m_choice
->SetStringSelection( "This" );
901 m_choiceSorted
->SetStringSelection( "This" );
904 case ID_CHOICE_CLEAR
:
907 m_choiceSorted
->Clear();
910 case ID_CHOICE_APPEND
:
912 m_choice
->Append( "Hi!" );
913 m_choiceSorted
->Append( "Hi!" );
916 case ID_CHOICE_DELETE
:
918 int idx
= m_choice
->GetSelection();
919 m_choice
->Delete( idx
);
920 idx
= m_choiceSorted
->GetSelection();
921 m_choiceSorted
->Delete( idx
);
926 m_choice
->SetFont( *wxITALIC_FONT
);
927 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
933 void MyPanel::OnCombo( wxCommandEvent
&event
)
935 m_text
->AppendText( "ComboBox event selection string is: " );
936 m_text
->AppendText( event
.GetString() );
937 m_text
->AppendText( "\n" );
938 m_text
->AppendText( "ComboBox control selection string is: " );
939 m_text
->AppendText( m_combo
->GetStringSelection() );
940 m_text
->AppendText( "\n" );
943 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
945 switch (event
.GetId())
947 case ID_COMBO_ENABLE
:
949 m_combo
->Enable( event
.GetInt() == 0 );
952 case ID_COMBO_SEL_NUM
:
954 m_combo
->SetSelection( 2 );
957 case ID_COMBO_SEL_STR
:
959 m_combo
->SetStringSelection( "This" );
967 case ID_COMBO_APPEND
:
969 m_combo
->Append( "Hi!" );
972 case ID_COMBO_DELETE
:
974 int idx
= m_combo
->GetSelection();
975 m_combo
->Delete( idx
);
980 m_combo
->SetFont( *wxITALIC_FONT
);
986 void MyPanel::OnRadio( wxCommandEvent
&event
)
988 m_text
->AppendText( "RadioBox selection string is: " );
989 m_text
->AppendText( event
.GetString() );
990 m_text
->AppendText( "\n" );
993 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
995 switch (event
.GetId())
997 case ID_RADIOBOX_ENABLE
:
999 m_radio
->Enable( event
.GetInt() == 0 );
1002 case ID_RADIOBOX_SEL_NUM
:
1004 m_radio
->SetSelection( 2 );
1007 case ID_RADIOBOX_SEL_STR
:
1009 m_radio
->SetStringSelection( "This" );
1012 case ID_RADIOBOX_FONT
:
1014 m_radio
->SetFont( *wxITALIC_FONT
);
1020 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1022 m_fontButton
->SetFont( *wxITALIC_FONT
);
1023 m_text
->SetFont( *wxITALIC_FONT
);
1026 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
1028 static bool s_long
= TRUE
;
1031 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
1034 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1036 m_gauge
->SetValue( m_slider
->GetValue() );
1041 void MyPanel::OnSpinCtrl(wxCommandEvent
& event
)
1044 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1045 m_spinctrl
->GetValue(), event
.GetInt());
1046 m_text
->AppendText(s
);
1049 #endif // wxUSE_SPINCTRL
1052 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1055 value
.Printf( _T("Spin control up: current = %d\n"),
1056 m_spinbutton
->GetValue());
1058 if ( m_spinbutton
->GetValue() > 17 )
1060 value
+= _T("Preventing the spin button from going above 17.\n");
1065 m_text
->AppendText(value
);
1068 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1071 value
.Printf( _T("Spin control down: current = %d\n"),
1072 m_spinbutton
->GetValue());
1074 if ( m_spinbutton
->GetValue() < -17 )
1076 value
+= _T("Preventing the spin button from going below -17.\n");
1081 m_text
->AppendText(value
);
1084 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1087 value
.Printf( _T("%d"), event
.GetPosition() );
1088 m_spintext
->SetValue( value
);
1090 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1091 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1092 m_spinbutton
->GetValue());
1094 m_text
->AppendText(value
);
1097 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1099 event
.Enable( m_spinbutton
->GetValue() > 0 );
1102 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1104 int max
= m_spinbutton
->GetValue();
1105 wxProgressDialog
dialog("Progress dialog example",
1106 "An informative message",
1112 wxPD_ESTIMATED_TIME
|
1113 wxPD_REMAINING_TIME
);
1117 for ( int i
= 0; i
< max
&& cont
; i
++ )
1122 cont
= dialog
.Update(i
, "That's all, folks!");
1124 else if ( i
== max
/ 2 )
1126 cont
= dialog
.Update(i
, "Only a half left!");
1130 cont
= dialog
.Update(i
);
1136 *m_text
<< "Progress dialog aborted!\n";
1140 *m_text
<< "Countdown from " << max
<< " finished.\n";
1144 #endif // wxUSE_SPINBTN
1148 delete m_notebook
->GetImageList();
1151 //----------------------------------------------------------------------
1153 //----------------------------------------------------------------------
1155 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1156 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1157 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1159 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1160 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1161 #endif // wxUSE_TOOLTIPS
1163 EVT_MENU(MINIMAL_ENABLE_ALL
, MyFrame::OnEnableAll
)
1165 EVT_SIZE(MyFrame::OnSize
)
1166 EVT_MOVE(MyFrame::OnMove
)
1168 EVT_IDLE(MyFrame::OnIdle
)
1171 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1172 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1176 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1179 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1184 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1186 wxBeginBusyCursor();
1188 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1195 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1197 static long s_delay
= 5000;
1200 delay
.Printf( _T("%ld"), s_delay
);
1202 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1203 "Set tooltip delay",
1207 return; // cancelled
1209 wxSscanf(delay
, _T("%ld"), &s_delay
);
1211 wxToolTip::SetDelay(s_delay
);
1213 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1216 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1218 static bool s_enabled
= TRUE
;
1220 s_enabled
= !s_enabled
;
1222 wxToolTip::Enable(s_enabled
);
1224 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1228 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1230 static bool s_enable
= TRUE
;
1232 s_enable
= !s_enable
;
1233 m_panel
->Enable(s_enable
);
1236 void MyFrame::OnMove( wxMoveEvent
& event
)
1238 UpdateStatusBar(event
.GetPosition(), GetSize());
1243 void MyFrame::OnSize( wxSizeEvent
& event
)
1245 UpdateStatusBar(GetPosition(), event
.GetSize());
1250 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1252 // track the window which has the focus in the status bar
1253 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1254 wxWindow
*focus
= wxWindow::FindFocus();
1255 if ( focus
&& (focus
!= s_windowFocus
) )
1257 s_windowFocus
= focus
;
1262 _T("Focus: wxWindow = %p, HWND = %08x"),
1264 _T("Focus: wxWindow = %p"),
1268 , s_windowFocus
->GetHWND()
1276 static void SetControlClientData(const char *name
,
1277 wxControlWithItems
*control
)
1279 size_t count
= control
->GetCount();
1280 for ( size_t n
= 0; n
< count
; n
++ )
1283 s
.Printf("%s client data for '%s'",
1284 name
, control
->GetString(n
).c_str());
1286 control
->SetClientObject(n
, new wxStringClientData(s
));