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(wxSpinEvent
& event
);
109 #endif // wxUSE_SPINCTRL
111 void OnEnableAll(wxCommandEvent
& event
);
112 void OnChangeColour(wxCommandEvent
& event
);
113 void OnTestButton(wxCommandEvent
& event
);
115 wxListBox
*m_listbox
,
123 wxButton
*m_fontButton
;
124 wxButton
*m_lbSelectNum
;
125 wxButton
*m_lbSelectThis
;
127 wxSpinButton
*m_spinbutton
;
128 wxButton
*m_btnProgress
;
129 #endif // wxUSE_SPINBTN
132 wxSpinCtrl
*m_spinctrl
;
133 #endif // wxUSE_SPINCTRL
135 wxTextCtrl
*m_spintext
;
136 wxCheckBox
*m_checkbox
;
139 wxNotebook
*m_notebook
;
141 wxStaticText
*m_label
;
144 wxLog
*m_logTargetOld
;
146 DECLARE_EVENT_TABLE()
149 class MyFrame
: public wxFrame
152 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
154 void OnQuit(wxCommandEvent
& event
);
155 void OnAbout(wxCommandEvent
& event
);
156 void OnClearLog(wxCommandEvent
& event
);
159 void OnSetTooltipDelay(wxCommandEvent
& event
);
160 void OnToggleTooltips(wxCommandEvent
& event
);
161 #endif // wxUSE_TOOLTIPS
163 void OnEnableAll(wxCommandEvent
& event
);
165 void OnIdle( wxIdleEvent
& event
);
166 void OnSize( wxSizeEvent
& event
);
167 void OnMove( wxMoveEvent
& event
);
169 MyPanel
*GetPanel() const { return m_panel
; }
172 void UpdateStatusBar(const wxPoint
& pos
, const wxSize
& size
)
175 msg
.Printf(_("pos=(%d, %d), size=%dx%d"),
176 pos
.x
, pos
.y
, size
.x
, size
.y
);
177 SetStatusText(msg
, 1);
182 DECLARE_EVENT_TABLE()
185 //----------------------------------------------------------------------
187 //----------------------------------------------------------------------
189 static void SetControlClientData(const char *name
,
190 wxControlWithItems
*control
);
194 //----------------------------------------------------------------------
196 //----------------------------------------------------------------------
206 CONTROLS_SET_TOOLTIP_DELAY
= 200,
207 CONTROLS_ENABLE_TOOLTIPS
,
215 // parse the cmd line
220 wxSscanf(argv
[1], "%d", &x
);
221 wxSscanf(argv
[2], "%d", &y
);
224 // Create the main frame window
225 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
226 "Controls wxWindows App",
229 frame
->SetSizeHints( 500, 425 );
232 // The wxICON() macros loads an icon from a resource under Windows
233 // and uses an #included XPM image under GTK+ and Motif
235 frame
->SetIcon( wxICON(mondrian
) );
237 wxMenu
*file_menu
= new wxMenu("", wxMENU_TEAROFF
);
239 file_menu
->Append(CONTROLS_CLEAR_LOG
, "&Clear log\tCtrl-L");
240 file_menu
->AppendSeparator();
241 file_menu
->Append(CONTROLS_ABOUT
, "&About\tF1");
242 file_menu
->AppendSeparator();
243 file_menu
->Append(CONTROLS_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
245 wxMenuBar
*menu_bar
= new wxMenuBar
;
246 menu_bar
->Append(file_menu
, "&File");
249 wxMenu
*tooltip_menu
= new wxMenu
;
250 tooltip_menu
->Append(CONTROLS_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
251 tooltip_menu
->AppendSeparator();
252 tooltip_menu
->Append(CONTROLS_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCtrl-T",
253 "enable/disable tooltips", TRUE
);
254 tooltip_menu
->Check(CONTROLS_ENABLE_TOOLTIPS
, TRUE
);
255 menu_bar
->Append(tooltip_menu
, "&Tooltips");
256 #endif // wxUSE_TOOLTIPS
258 wxMenu
*panel_menu
= new wxMenu
;
259 panel_menu
->Append(CONTROLS_ENABLE_ALL
, "&Disable all\tCtrl-E",
260 "Enable/disable all panel controls", TRUE
);
261 menu_bar
->Append(panel_menu
, "&Panel");
263 frame
->SetMenuBar(menu_bar
);
266 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
268 //frame->GetPanel()->m_notebook->SetSelection(6);
275 //----------------------------------------------------------------------
277 //----------------------------------------------------------------------
279 const int ID_NOTEBOOK
= 1000;
281 const int ID_LISTBOX
= 130;
282 const int ID_LISTBOX_SEL_NUM
= 131;
283 const int ID_LISTBOX_SEL_STR
= 132;
284 const int ID_LISTBOX_CLEAR
= 133;
285 const int ID_LISTBOX_APPEND
= 134;
286 const int ID_LISTBOX_DELETE
= 135;
287 const int ID_LISTBOX_FONT
= 136;
288 const int ID_LISTBOX_ENABLE
= 137;
289 const int ID_LISTBOX_SORTED
= 138;
291 const int ID_CHOICE
= 120;
292 const int ID_CHOICE_SEL_NUM
= 121;
293 const int ID_CHOICE_SEL_STR
= 122;
294 const int ID_CHOICE_CLEAR
= 123;
295 const int ID_CHOICE_APPEND
= 124;
296 const int ID_CHOICE_DELETE
= 125;
297 const int ID_CHOICE_FONT
= 126;
298 const int ID_CHOICE_ENABLE
= 127;
299 const int ID_CHOICE_SORTED
= 128;
301 const int ID_COMBO
= 140;
302 const int ID_COMBO_SEL_NUM
= 141;
303 const int ID_COMBO_SEL_STR
= 142;
304 const int ID_COMBO_CLEAR
= 143;
305 const int ID_COMBO_APPEND
= 144;
306 const int ID_COMBO_DELETE
= 145;
307 const int ID_COMBO_FONT
= 146;
308 const int ID_COMBO_ENABLE
= 147;
310 const int ID_RADIOBOX
= 160;
311 const int ID_RADIOBOX_SEL_NUM
= 161;
312 const int ID_RADIOBOX_SEL_STR
= 162;
313 const int ID_RADIOBOX_FONT
= 163;
314 const int ID_RADIOBOX_ENABLE
= 164;
316 const int ID_RADIOBUTTON_1
= 166;
317 const int ID_RADIOBUTTON_2
= 167;
319 const int ID_SET_FONT
= 170;
321 const int ID_GAUGE
= 180;
322 const int ID_SLIDER
= 181;
324 const int ID_SPIN
= 182;
325 const int ID_BTNPROGRESS
= 183;
326 const int ID_BUTTON_LABEL
= 184;
327 const int ID_SPINCTRL
= 185;
329 const int ID_BUTTON_TEST1
= 190;
330 const int ID_BUTTON_TEST2
= 191;
332 const int ID_CHANGE_COLOUR
= 200;
334 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
335 EVT_SIZE ( MyPanel::OnSize
)
336 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
337 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
338 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
339 EVT_LISTBOX (ID_LISTBOX_SORTED
, MyPanel::OnListBox
)
340 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
341 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
342 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
343 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
344 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
345 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
346 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
347 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
348 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
349 EVT_CHOICE (ID_CHOICE_SORTED
, MyPanel::OnChoice
)
350 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
351 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
352 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
353 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
354 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
355 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
356 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
357 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
358 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
359 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
360 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
361 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
362 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
363 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
364 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
365 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
366 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
367 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
368 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
369 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
370 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
371 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
373 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
374 EVT_SPIN_UP (ID_SPIN
, MyPanel::OnSpinUp
)
375 EVT_SPIN_DOWN (ID_SPIN
, MyPanel::OnSpinDown
)
376 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
377 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
378 #endif // wxUSE_SPINBTN
380 EVT_SPINCTRL (ID_SPINCTRL
, MyPanel::OnSpinCtrl
)
381 #endif // wxUSE_SPINCTRL
382 EVT_BUTTON (ID_BUTTON_LABEL
, MyPanel::OnUpdateLabel
)
383 EVT_CHECKBOX (ID_CHANGE_COLOUR
, MyPanel::OnChangeColour
)
384 EVT_BUTTON (ID_BUTTON_TEST1
, MyPanel::OnTestButton
)
385 EVT_BUTTON (ID_BUTTON_TEST2
, MyPanel::OnTestButton
)
388 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
389 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
390 m_text(NULL
), m_notebook(NULL
)
392 wxLayoutConstraints
*c
;
394 m_text
= new wxTextCtrl(this, -1, "This is the log window.\n",
395 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE
);
396 m_text
->SetBackgroundColour("wheat");
399 wxLog::AddTraceMask(_T("focus"));
400 m_logTargetOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_text
));
402 m_notebook
= new wxNotebook(this, ID_NOTEBOOK
);
417 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
420 // fill the image list
421 wxImageList
*imagelist
= new wxImageList(32, 32);
423 imagelist
-> Add( wxBitmap( list_xpm
));
424 imagelist
-> Add( wxBitmap( choice_xpm
));
425 imagelist
-> Add( wxBitmap( combo_xpm
));
426 imagelist
-> Add( wxBitmap( text_xpm
));
427 imagelist
-> Add( wxBitmap( radio_xpm
));
428 imagelist
-> Add( wxBitmap( gauge_xpm
));
429 m_notebook
->SetImageList(imagelist
);
430 #elif defined(__WXMSW__)
431 // load images from resources
434 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
436 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
438 static const char *s_iconNames
[Image_Max
] =
440 "list", "choice", "combo", "text", "radio", "gauge"
443 for ( size_t n
= 0; n
< Image_Max
; n
++ )
445 wxBitmap
bmp(s_iconNames
[n
]);
446 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
448 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
453 m_notebook
->SetImageList(imagelist
);
457 #define Image_List -1
458 #define Image_Choice -1
459 #define Image_Combo -1
460 #define Image_Text -1
461 #define Image_Radio -1
462 #define Image_Gauge -1
467 wxPanel
*panel
= new wxPanel(m_notebook
);
468 m_listbox
= new wxListBox( panel
, ID_LISTBOX
,
469 wxPoint(10,10), wxSize(120,70),
470 5, choices
, wxLB_ALWAYS_SB
);
471 m_listboxSorted
= new wxListBox( panel
, ID_LISTBOX_SORTED
,
472 wxPoint(10,90), wxSize(120,70),
473 5, choices
, wxLB_SORT
);
475 SetControlClientData("listbox", m_listbox
);
476 SetControlClientData("listbox", m_listboxSorted
);
478 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
480 m_listbox
->SetToolTip( "This is a list box" );
481 #endif // wxUSE_TOOLTIPS
483 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
484 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
485 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
486 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
487 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
488 wxButton
*button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
490 button
->SetDefault();
492 button
->SetForegroundColour(*wxBLUE
);
495 button
->SetToolTip( "Press here to set italic font" );
496 #endif // wxUSE_TOOLTIPS
498 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,170) );
499 m_checkbox
->SetValue(FALSE
);
501 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
502 #endif // wxUSE_TOOLTIPS
503 (void)new wxCheckBox( panel
, ID_CHANGE_COLOUR
, "&Toggle colour",
505 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
507 panel
= new wxPanel(m_notebook
);
508 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
509 m_choiceSorted
= new wxChoice( panel
, ID_CHOICE_SORTED
, wxPoint(10,70), wxSize(120,-1),
510 5, choices
, wxCB_SORT
);
513 SetControlClientData("choice", m_choice
);
514 SetControlClientData("choice", m_choiceSorted
);
517 m_choice
->SetSelection(2);
518 m_choice
->SetBackgroundColour( "red" );
519 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
520 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
521 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
522 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
523 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
524 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
525 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
527 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
529 panel
= new wxPanel(m_notebook
);
530 (void)new wxStaticBox( panel
, -1, "&Box around combobox",
531 wxPoint(5, 5), wxSize(150, 100));
532 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(20,25), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
533 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #&2", wxPoint(180,30), wxSize(140,30) );
534 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
535 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "&Clear", wxPoint(180,80), wxSize(140,30) );
536 (void)new wxButton( panel
, ID_COMBO_APPEND
, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
537 (void)new wxButton( panel
, ID_COMBO_DELETE
, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
538 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
539 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "&Disable", wxPoint(20,130), wxSize(140,30) );
540 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
542 wxString choices2
[] =
546 "Fourth", "Fifth", "Sixth",
547 "Seventh", "Eighth", "Nineth", "Tenth" */
550 panel
= new wxPanel(m_notebook
);
551 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "&That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
552 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "T&his", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
555 m_combo
->SetToolTip("This is a natural\ncombobox - can you believe me?");
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), wxDefaultSize
);
564 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxDefaultSize
, wxRB_GROUP
);
565 rb
->SetValue( FALSE
);
566 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "&Radiobutton2", wxPoint(340,170), wxDefaultSize
);
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 // test for masked bitmap display
638 bitmap
= wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP
);
641 bitmap
.SetMask(new wxMask(bitmap
, *wxBLUE
));
642 (void)new wxStaticBitmap
/* wxBitmapButton */ (panel
, -1, bitmap
, wxPoint(300, 120));
646 wxBitmap
bmp1(wxTheApp
->GetStdIcon(wxICON_INFORMATION
)),
647 bmp2(wxTheApp
->GetStdIcon(wxICON_WARNING
)),
648 bmp3(wxTheApp
->GetStdIcon(wxICON_QUESTION
));
649 wxBitmapButton
*bmpBtn
= new wxBitmapButton
655 bmpBtn
->SetBitmapSelected(bmp2
);
656 bmpBtn
->SetBitmapFocus(bmp3
);
658 (void)new wxButton(panel
, ID_BUTTON_LABEL
, "&Toggle label", wxPoint(250, 20));
659 m_label
= new wxStaticText(panel
, -1, "Label with some long text",
660 wxPoint(250, 60), wxDefaultSize
,
661 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
662 m_label
->SetForegroundColour( *wxBLUE
);
664 m_notebook
->AddPage(panel
, "wxBitmapXXX");
666 // layout constraints
668 panel
= new wxPanel(m_notebook
);
669 panel
->SetAutoLayout( TRUE
);
671 c
= new wxLayoutConstraints
;
672 c
->top
.SameAs( panel
, wxTop
, 10 );
674 c
->left
.SameAs( panel
, wxLeft
, 10 );
675 c
->width
.PercentOf( panel
, wxWidth
, 40 );
677 wxButton
*pMyButton
= new wxButton(panel
, ID_BUTTON_TEST1
, "Test Button &1" );
678 pMyButton
->SetConstraints( c
);
680 c
= new wxLayoutConstraints
;
681 c
->top
.SameAs( panel
, wxTop
, 10 );
682 c
->bottom
.SameAs( panel
, wxBottom
, 10 );
683 c
->right
.SameAs( panel
, wxRight
, 10 );
684 c
->width
.PercentOf( panel
, wxWidth
, 40 );
686 wxButton
*pMyButton2
= new wxButton(panel
, ID_BUTTON_TEST2
, "Test Button &2" );
687 pMyButton2
->SetConstraints( c
);
689 m_notebook
->AddPage(panel
, "wxLayoutConstraint");
693 panel
= new wxPanel(m_notebook
);
694 panel
->SetAutoLayout( TRUE
);
696 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
698 sizer
->Add( new wxButton(panel
, -1, "Test Button &1" ), 3, wxALL
, 10 );
699 sizer
->Add( 20,20, 1 );
700 sizer
->Add( new wxButton(panel
, -1, "Test Button &2" ), 3, wxGROW
|wxALL
, 10 );
702 panel
->SetSizer( sizer
);
704 m_notebook
->AddPage(panel
, "wxSizer");
707 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
711 GetClientSize( &x
, &y
);
713 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
714 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
717 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
719 int selOld
= event
.GetOldSelection();
722 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
723 "page change from taking place - if you select\n"
724 "[No] the current page will stay the third one\n",
726 wxICON_QUESTION
| wxYES_NO
) != wxYES
)
734 *m_text
<< "Notebook selection is being changed from " << selOld
<< "\n";
737 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
739 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
742 void MyPanel::OnTestButton(wxCommandEvent
& event
)
744 wxLogMessage(_T("Button %c clicked."),
745 event
.GetId() == ID_BUTTON_TEST1
? _T('1') : _T('2'));
748 void MyPanel::OnChangeColour(wxCommandEvent
& WXUNUSED(event
))
750 static wxColour s_colOld
;
752 // test panel colour changing and propagation to the subcontrols
755 SetBackgroundColour(s_colOld
);
756 s_colOld
= wxNullColour
;
758 m_lbSelectThis
->SetForegroundColour("red");
759 m_lbSelectThis
->SetBackgroundColour("white");
763 s_colOld
= wxColour("red");
764 SetBackgroundColour("white");
766 m_lbSelectThis
->SetForegroundColour("white");
767 m_lbSelectThis
->SetBackgroundColour("red");
770 m_lbSelectThis
->Refresh();
774 void MyPanel::OnListBox( wxCommandEvent
&event
)
776 // GetParent()->Move(100, 100);
778 if (event
.GetInt() == -1)
780 m_text
->AppendText( "ListBox has no selections anymore\n" );
784 wxListBox
*listbox
= event
.GetId() == ID_LISTBOX
? m_listbox
787 m_text
->AppendText( "ListBox event selection string is: '" );
788 m_text
->AppendText( event
.GetString() );
789 m_text
->AppendText( "'\n" );
790 m_text
->AppendText( "ListBox control selection string is: '" );
791 m_text
->AppendText( listbox
->GetStringSelection() );
792 m_text
->AppendText( "'\n" );
794 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
795 m_text
->AppendText( "ListBox event client data string is: '" );
796 if (obj
) // BC++ doesn't like use of '? .. : .. ' in this context
797 m_text
->AppendText( obj
->GetData() );
799 m_text
->AppendText( wxString("none") );
801 m_text
->AppendText( "'\n" );
802 m_text
->AppendText( "ListBox control client data string is: '" );
803 obj
= (wxStringClientData
*)listbox
->GetClientObject(listbox
->GetSelection());
805 m_text
->AppendText( obj
->GetData() );
807 m_text
->AppendText( wxString("none") );
808 m_text
->AppendText( "'\n" );
811 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
813 m_text
->AppendText( "ListBox double click string is: " );
814 m_text
->AppendText( event
.GetString() );
815 m_text
->AppendText( "\n" );
818 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
820 switch (event
.GetId())
822 case ID_LISTBOX_ENABLE
:
824 m_text
->AppendText("Checkbox clicked.\n");
825 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
828 cb
->SetToolTip( "Click to enable listbox" );
830 cb
->SetToolTip( "Click to disable listbox" );
831 #endif // wxUSE_TOOLTIPS
832 m_listbox
->Enable( event
.GetInt() == 0 );
833 m_lbSelectThis
->Enable( event
.GetInt() == 0 );
834 m_lbSelectNum
->Enable( event
.GetInt() == 0 );
835 m_listboxSorted
->Enable( event
.GetInt() == 0 );
836 FindWindow(ID_CHANGE_COLOUR
)->Enable( event
.GetInt() == 0 );
839 case ID_LISTBOX_SEL_NUM
:
841 m_listbox
->SetSelection( 2 );
842 m_listboxSorted
->SetSelection( 2 );
843 m_lbSelectThis
->WarpPointer( 40, 14 );
846 case ID_LISTBOX_SEL_STR
:
848 m_listbox
->SetStringSelection( "This" );
849 m_listboxSorted
->SetStringSelection( "This" );
850 m_lbSelectNum
->WarpPointer( 40, 14 );
853 case ID_LISTBOX_CLEAR
:
856 m_listboxSorted
->Clear();
859 case ID_LISTBOX_APPEND
:
861 m_listbox
->Append( "Hi!" );
862 m_listboxSorted
->Append( "Hi!" );
865 case ID_LISTBOX_DELETE
:
868 idx
= m_listbox
->GetSelection();
869 m_listbox
->Delete( idx
);
870 idx
= m_listboxSorted
->GetSelection();
871 m_listboxSorted
->Delete( idx
);
874 case ID_LISTBOX_FONT
:
876 m_listbox
->SetFont( *wxITALIC_FONT
);
877 m_listboxSorted
->SetFont( *wxITALIC_FONT
);
878 m_checkbox
->SetFont( *wxITALIC_FONT
);
884 void MyPanel::OnChoice( wxCommandEvent
&event
)
886 wxChoice
*choice
= event
.GetId() == ID_CHOICE
? m_choice
889 m_text
->AppendText( "Choice event selection string is: '" );
890 m_text
->AppendText( event
.GetString() );
891 m_text
->AppendText( "'\n" );
892 m_text
->AppendText( "Choice control selection string is: '" );
893 m_text
->AppendText( choice
->GetStringSelection() );
894 m_text
->AppendText( "'\n" );
896 wxStringClientData
*obj
= ((wxStringClientData
*)event
.GetClientObject());
897 m_text
->AppendText( "Choice event client data string is: '" );
900 m_text
->AppendText( obj
->GetData() );
902 m_text
->AppendText( wxString("none") );
904 m_text
->AppendText( "'\n" );
905 m_text
->AppendText( "Choice control client data string is: '" );
906 obj
= (wxStringClientData
*)choice
->GetClientObject(choice
->GetSelection());
909 m_text
->AppendText( obj
->GetData() );
911 m_text
->AppendText( wxString("none") );
912 m_text
->AppendText( "'\n" );
915 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
917 switch (event
.GetId())
919 case ID_CHOICE_ENABLE
:
921 m_choice
->Enable( event
.GetInt() == 0 );
922 m_choiceSorted
->Enable( event
.GetInt() == 0 );
925 case ID_CHOICE_SEL_NUM
:
927 m_choice
->SetSelection( 2 );
928 m_choiceSorted
->SetSelection( 2 );
931 case ID_CHOICE_SEL_STR
:
933 m_choice
->SetStringSelection( "This" );
934 m_choiceSorted
->SetStringSelection( "This" );
937 case ID_CHOICE_CLEAR
:
940 m_choiceSorted
->Clear();
943 case ID_CHOICE_APPEND
:
945 m_choice
->Append( "Hi!" );
946 m_choiceSorted
->Append( "Hi!" );
949 case ID_CHOICE_DELETE
:
951 int idx
= m_choice
->GetSelection();
952 m_choice
->Delete( idx
);
953 idx
= m_choiceSorted
->GetSelection();
954 m_choiceSorted
->Delete( idx
);
959 m_choice
->SetFont( *wxITALIC_FONT
);
960 m_choiceSorted
->SetFont( *wxITALIC_FONT
);
966 void MyPanel::OnCombo( wxCommandEvent
&event
)
968 m_text
->AppendText( "ComboBox event selection string is: " );
969 m_text
->AppendText( event
.GetString() );
970 m_text
->AppendText( "\n" );
971 m_text
->AppendText( "ComboBox control selection string is: " );
972 m_text
->AppendText( m_combo
->GetStringSelection() );
973 m_text
->AppendText( "\n" );
976 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
978 switch (event
.GetId())
980 case ID_COMBO_ENABLE
:
982 m_combo
->Enable( event
.GetInt() == 0 );
985 case ID_COMBO_SEL_NUM
:
987 m_combo
->SetSelection( 2 );
990 case ID_COMBO_SEL_STR
:
992 m_combo
->SetStringSelection( "This" );
1000 case ID_COMBO_APPEND
:
1002 m_combo
->Append( "Hi!" );
1005 case ID_COMBO_DELETE
:
1007 int idx
= m_combo
->GetSelection();
1008 m_combo
->Delete( idx
);
1013 m_combo
->SetFont( *wxITALIC_FONT
);
1019 void MyPanel::OnRadio( wxCommandEvent
&event
)
1021 m_text
->AppendText( "RadioBox selection string is: " );
1022 m_text
->AppendText( event
.GetString() );
1023 m_text
->AppendText( "\n" );
1026 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1028 switch (event
.GetId())
1030 case ID_RADIOBOX_ENABLE
:
1032 m_radio
->Enable( event
.GetInt() == 0 );
1035 case ID_RADIOBOX_SEL_NUM
:
1037 m_radio
->SetSelection( 2 );
1040 case ID_RADIOBOX_SEL_STR
:
1042 m_radio
->SetStringSelection( "This" );
1045 case ID_RADIOBOX_FONT
:
1047 m_radio
->SetFont( *wxITALIC_FONT
);
1053 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1055 m_fontButton
->SetFont( *wxITALIC_FONT
);
1056 m_text
->SetFont( *wxITALIC_FONT
);
1059 void MyPanel::OnUpdateLabel( wxCommandEvent
&WXUNUSED(event
) )
1061 static bool s_long
= TRUE
;
1064 m_label
->SetLabel(s_long
? "very very very long text" : "shorter text");
1067 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1069 m_gauge
->SetValue( m_slider
->GetValue() );
1074 void MyPanel::OnSpinCtrl(wxSpinEvent
& event
)
1077 s
.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1078 m_spinctrl
->GetValue(), event
.GetInt());
1079 m_text
->AppendText(s
);
1082 #endif // wxUSE_SPINCTRL
1085 void MyPanel::OnSpinUp( wxSpinEvent
&event
)
1088 value
.Printf( _T("Spin control up: current = %d\n"),
1089 m_spinbutton
->GetValue());
1091 if ( m_spinbutton
->GetValue() > 17 )
1093 value
+= _T("Preventing the spin button from going above 17.\n");
1098 m_text
->AppendText(value
);
1101 void MyPanel::OnSpinDown( wxSpinEvent
&event
)
1104 value
.Printf( _T("Spin control down: current = %d\n"),
1105 m_spinbutton
->GetValue());
1107 if ( m_spinbutton
->GetValue() < -17 )
1109 value
+= _T("Preventing the spin button from going below -17.\n");
1114 m_text
->AppendText(value
);
1117 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1120 value
.Printf( _T("%d"), event
.GetPosition() );
1121 m_spintext
->SetValue( value
);
1123 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1124 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1125 m_spinbutton
->GetValue());
1127 m_text
->AppendText(value
);
1130 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1132 event
.Enable( m_spinbutton
->GetValue() > 0 );
1135 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1137 int max
= m_spinbutton
->GetValue();
1138 wxProgressDialog
dialog("Progress dialog example",
1139 "An informative message",
1145 wxPD_ESTIMATED_TIME
|
1146 wxPD_REMAINING_TIME
);
1150 for ( int i
= 0; i
<= max
&& cont
; i
++ )
1155 cont
= dialog
.Update(i
, "That's all, folks!");
1157 else if ( i
== max
/ 2 )
1159 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
1163 cont
= dialog
.Update(i
);
1169 *m_text
<< "Progress dialog aborted!\n";
1173 *m_text
<< "Countdown from " << max
<< " finished.\n";
1177 #endif // wxUSE_SPINBTN
1181 //wxLog::RemoveTraceMask(_T("focus"));
1182 delete wxLog::SetActiveTarget(m_logTargetOld
);
1184 delete m_notebook
->GetImageList();
1187 //----------------------------------------------------------------------
1189 //----------------------------------------------------------------------
1191 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1192 EVT_MENU(CONTROLS_QUIT
, MyFrame::OnQuit
)
1193 EVT_MENU(CONTROLS_ABOUT
, MyFrame::OnAbout
)
1194 EVT_MENU(CONTROLS_CLEAR_LOG
, MyFrame::OnClearLog
)
1196 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1197 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1198 #endif // wxUSE_TOOLTIPS
1200 EVT_MENU(CONTROLS_ENABLE_ALL
, MyFrame::OnEnableAll
)
1202 EVT_SIZE(MyFrame::OnSize
)
1203 EVT_MOVE(MyFrame::OnMove
)
1205 EVT_IDLE(MyFrame::OnIdle
)
1208 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1209 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1213 m_panel
= new MyPanel( this, 10, 10, 300, 100 );
1216 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1221 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1225 #if 0 // VZ: my temp test code, will remove
1226 wxGetTextFromUser("msg", "caption", "val", this);
1230 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1234 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
1236 m_panel
->m_text
->Clear();
1240 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1242 static long s_delay
= 5000;
1245 delay
.Printf( _T("%ld"), s_delay
);
1247 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1248 "Set tooltip delay",
1252 return; // cancelled
1254 wxSscanf(delay
, _T("%ld"), &s_delay
);
1256 wxToolTip::SetDelay(s_delay
);
1258 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1261 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1263 static bool s_enabled
= TRUE
;
1265 s_enabled
= !s_enabled
;
1267 wxToolTip::Enable(s_enabled
);
1269 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1273 void MyFrame::OnEnableAll(wxCommandEvent
& WXUNUSED(event
))
1275 static bool s_enable
= TRUE
;
1277 s_enable
= !s_enable
;
1278 m_panel
->Enable(s_enable
);
1281 void MyFrame::OnMove( wxMoveEvent
& event
)
1283 UpdateStatusBar(event
.GetPosition(), GetSize());
1288 void MyFrame::OnSize( wxSizeEvent
& event
)
1290 UpdateStatusBar(GetPosition(), event
.GetSize());
1295 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1297 // track the window which has the focus in the status bar
1298 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1299 wxWindow
*focus
= wxWindow::FindFocus();
1300 if ( focus
&& (focus
!= s_windowFocus
) )
1302 s_windowFocus
= focus
;
1307 _T("Focus: %s, HWND = %08x"),
1311 s_windowFocus
->GetClassInfo()->GetClassName()
1313 , s_windowFocus
->GetHWND()
1321 static void SetControlClientData(const char *name
,
1322 wxControlWithItems
*control
)
1324 size_t count
= control
->GetCount();
1325 for ( size_t n
= 0; n
< count
; n
++ )
1328 s
.Printf("%s client data for '%s'",
1329 name
, control
->GetString(n
).c_str());
1331 control
->SetClientObject(n
, new wxStringClientData(s
));