]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
04259c3c3d4d2c97d9033c23680931e34f309602
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 #include "wx/spinbutt.h"
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
29 #include "wx/clipbrd.h"
31 // XPM doesn't seem to work under Windows at present. Or, wxNotebook images
33 // Uncomment this line and comment out the next to try it.
34 // #if defined(__WXGTK__) || defined(__WXMOTIF__) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
35 #if defined(__WXGTK__) || defined(__WXMOTIF__)
40 #include "mondrian.xpm"
41 #include "icons/choice.xpm"
42 #include "icons/combo.xpm"
43 #include "icons/list.xpm"
44 #include "icons/radio.xpm"
45 #include "icons/text.xpm"
46 #include "icons/gauge.xpm"
49 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
53 class MyApp
: public wxApp
59 class MyPanel
: public wxPanel
63 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
66 void OnSize( wxSizeEvent
& event
);
67 void OnListBox( wxCommandEvent
&event
);
68 void OnListBoxButtons( wxCommandEvent
&event
);
69 void OnChoice( wxCommandEvent
&event
);
70 void OnChoiceButtons( wxCommandEvent
&event
);
71 void OnCombo( wxCommandEvent
&event
);
72 void OnComboButtons( wxCommandEvent
&event
);
73 void OnRadio( wxCommandEvent
&event
);
74 void OnRadioButtons( wxCommandEvent
&event
);
75 void OnSetFont( wxCommandEvent
&event
);
76 void OnPageChanged( wxNotebookEvent
&event
);
77 void OnSliderUpdate( wxCommandEvent
&event
);
78 void OnSpinUpdate( wxSpinEvent
&event
);
79 void OnPasteFromClipboard( wxCommandEvent
&event
);
80 void OnCopyToClipboard( wxCommandEvent
&event
);
88 wxButton
*m_fontButton
;
89 wxSpinButton
*m_spinbutton
;
90 wxTextCtrl
*m_spintext
;
91 wxTextCtrl
*m_multitext
;
92 wxCheckBox
*m_checkbox
;
95 wxNotebook
*m_notebook
;
100 class MyFrame
: public wxFrame
104 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
108 void OnQuit(wxCommandEvent
& event
);
109 void OnAbout(wxCommandEvent
& event
);
110 bool OnClose(void) { return TRUE
; }
112 DECLARE_EVENT_TABLE()
115 //----------------------------------------------------------------------
117 //----------------------------------------------------------------------
119 IMPLEMENT_APP (MyApp
)
121 //----------------------------------------------------------------------
123 //----------------------------------------------------------------------
125 const int MINIMAL_QUIT
= 100;
126 const int MINIMAL_TEXT
= 101;
127 const int MINIMAL_ABOUT
= 102;
129 bool MyApp::OnInit(void)
131 // Create the main frame window
132 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, (char *) "Controls wxWindows App", 50, 50, 530, 420 );
135 // The wxICON() macros loads an icon from a resource under Windows
136 // and uses an #included XPM image under GTK+ and Motif
138 frame
->SetIcon( wxICON(mondrian
) );
140 wxMenu
*file_menu
= new wxMenu
;
142 file_menu
->Append(MINIMAL_ABOUT
, "&About");
143 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
144 wxMenuBar
*menu_bar
= new wxMenuBar
;
145 menu_bar
->Append(file_menu
, "&File");
146 frame
->SetMenuBar(menu_bar
);
155 //----------------------------------------------------------------------
157 //----------------------------------------------------------------------
159 const int ID_NOTEBOOK
= 1000;
161 const int ID_LISTBOX
= 130;
162 const int ID_LISTBOX_SEL_NUM
= 131;
163 const int ID_LISTBOX_SEL_STR
= 132;
164 const int ID_LISTBOX_CLEAR
= 133;
165 const int ID_LISTBOX_APPEND
= 134;
166 const int ID_LISTBOX_DELETE
= 135;
167 const int ID_LISTBOX_FONT
= 136;
168 const int ID_LISTBOX_ENABLE
= 137;
170 const int ID_CHOICE
= 120;
171 const int ID_CHOICE_SEL_NUM
= 121;
172 const int ID_CHOICE_SEL_STR
= 122;
173 const int ID_CHOICE_CLEAR
= 123;
174 const int ID_CHOICE_APPEND
= 124;
175 const int ID_CHOICE_DELETE
= 125;
176 const int ID_CHOICE_FONT
= 126;
177 const int ID_CHOICE_ENABLE
= 127;
179 const int ID_COMBO
= 140;
180 const int ID_COMBO_SEL_NUM
= 141;
181 const int ID_COMBO_SEL_STR
= 142;
182 const int ID_COMBO_CLEAR
= 143;
183 const int ID_COMBO_APPEND
= 144;
184 const int ID_COMBO_DELETE
= 145;
185 const int ID_COMBO_FONT
= 146;
186 const int ID_COMBO_ENABLE
= 147;
188 const int ID_TEXT
= 150;
189 const int ID_PASTE_TEXT
= 151;
190 const int ID_COPY_TEXT
= 152;
192 const int ID_RADIOBOX
= 160;
193 const int ID_RADIOBOX_SEL_NUM
= 161;
194 const int ID_RADIOBOX_SEL_STR
= 162;
195 const int ID_RADIOBOX_FONT
= 163;
196 const int ID_RADIOBOX_ENABLE
= 164;
198 const int ID_RADIOBUTTON_1
= 166;
199 const int ID_RADIOBUTTON_2
= 167;
201 const int ID_SET_FONT
= 170;
203 const int ID_GAUGE
= 180;
204 const int ID_SLIDER
= 181;
206 const int ID_SPIN
= 182;
209 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
210 EVT_SIZE ( MyPanel::OnSize
)
211 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
212 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
213 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
214 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
215 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
216 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
217 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
218 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
219 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
220 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
221 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
222 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
223 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
224 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
225 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
226 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
227 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
228 EVT_CHOICE (ID_COMBO
, MyPanel::OnCombo
)
229 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
230 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
231 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
232 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
233 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
234 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
235 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
236 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
237 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
238 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
239 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
240 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
241 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
242 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
243 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
244 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
245 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
248 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
249 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
251 // SetBackgroundColour("cadet blue");
253 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
254 // m_text->SetBackgroundColour("wheat");
256 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
268 // image ids and names
271 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
274 // fill the image list
275 wxImageList
*imagelist
= new wxImageList(32, 32);
277 imagelist
-> Add( wxBitmap( list_xpm
));
278 imagelist
-> Add( wxBitmap( choice_xpm
));
279 imagelist
-> Add( wxBitmap( combo_xpm
));
280 imagelist
-> Add( wxBitmap( text_xpm
));
281 imagelist
-> Add( wxBitmap( radio_xpm
));
282 imagelist
-> Add( wxBitmap( gauge_xpm
));
283 m_notebook
->SetImageList(imagelist
);
287 #define Image_List -1
288 #define Image_Choice -1
289 #define Image_Combo -1
290 #define Image_Text -1
291 #define Image_Radio -1
292 #define Image_Gauge -1
297 wxButton
*button
= (wxButton
*)NULL
;
299 // m_notebook->SetBackgroundColour("cadet blue");
301 wxPanel
*panel
= (wxPanel
*) NULL
;
302 panel
= new wxPanel(m_notebook
);
303 // panel->SetBackgroundColour("cadet blue");
304 // panel->SetForegroundColour("blue");
305 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
306 // m_listbox->SetBackgroundColour("wheat");
307 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
308 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
309 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
310 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
311 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
312 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
313 // button->SetForegroundColour( "red" );
314 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
315 m_notebook
->AddPage(panel
, "wxList", FALSE
, Image_List
);
317 panel
= new wxPanel(m_notebook
);
318 // panel->SetBackgroundColour("cadet blue");
319 // panel->SetForegroundColour("blue");
320 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
321 // m_choice->SetBackgroundColour("wheat");
322 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
323 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
324 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
325 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
326 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
327 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
328 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
329 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
331 panel
= new wxPanel(m_notebook
);
332 // panel->SetBackgroundColour("cadet blue");
333 // panel->SetForegroundColour("blue");
334 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
335 // m_combo->SetBackgroundColour("wheat");
336 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
337 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
338 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
339 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
340 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
341 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
342 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
343 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
345 panel
= new wxPanel(m_notebook
);
346 // panel->SetBackgroundColour("cadet blue");
347 // panel->SetForegroundColour("blue");
348 wxTextCtrl
*tc
= new wxTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
349 (*tc
) << " More text.";
350 // tc->SetBackgroundColour("wheat");
351 m_multitext
= new wxTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
352 (*m_multitext
) << " More text.";
353 // m_multitext->SetBackgroundColour("wheat");
354 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
355 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
356 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,140), wxSize(110,30) );
357 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
359 wxString choices2
[] =
365 panel
= new wxPanel(m_notebook
);
366 // panel->SetBackgroundColour("cadet blue");
367 // panel->SetForegroundColour("blue");
368 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_VERTICAL
);
369 // m_radio->SetBackgroundColour("wheat");
370 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_HORIZONTAL
);
371 // m_radio->SetBackgroundColour("wheat");
372 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
373 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
374 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
375 m_fontButton
->SetForegroundColour("blue");
376 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
377 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
378 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
379 rb
->SetValue( FALSE
);
380 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
381 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
383 panel
= new wxPanel(m_notebook
);
384 // panel->SetBackgroundColour("cadet blue");
385 // panel->SetForegroundColour("blue");
386 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
387 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155,-1) );
388 // m_gauge->SetBackgroundColour("wheat");
389 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
390 // m_slider->SetBackgroundColour("wheat");
391 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
392 (void)new wxStaticText( panel
, -1,
393 "In order see the gauge (aka progress bar)\n"
394 "control do something you have to drag the\n"
395 "handle of the slider to the right.\n"
397 "This is also supposed to demonstrate how\n"
398 "to use static controls.\n",
400 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
401 // m_spintext->SetBackgroundColour("wheat");
402 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
403 // m_spinbutton->SetBackgroundColour("wheat");
404 m_spinbutton
->SetRange(0,100);
406 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
409 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
413 if (!wxTheClipboard
->IsSupportedFormat( wxDF_TEXT
))
415 *m_text
<< "The clipboard doesn't contain any data in the requested format." << "\n";
420 if (!wxTheClipboard
->Open())
422 *m_text
<< "Error opening the clipboard." << "\n";
428 *m_text
<< "Successfully opened the clipboard." << "\n";
431 wxTextDataObject
*data
= new wxTextDataObject();
433 if (wxTheClipboard
->GetData( data
))
435 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
436 *m_multitext
<< data
->GetText() << "\n";
440 *m_text
<< "Error getting data from the clipboard." << "\n";
443 wxTheClipboard
->Close();
445 *m_text
<< "Closed the clipboard." << "\n";
452 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
456 wxString
text( m_multitext
->GetLineText(0) );
458 if (text
.IsEmpty()) return;
460 wxTextDataObject
*data
= new wxTextDataObject( text
);
462 if (!wxTheClipboard
->Open())
464 *m_text
<< "Error opening the clipboard." << "\n";
470 *m_text
<< "Successfully opened the clipboard." << "\n";
473 if (!wxTheClipboard
->SetData( data
))
475 *m_text
<< "Error while copying to the clipboard." << "\n";
479 *m_text
<< "Successfully copied data to the clipboard." << "\n";
482 wxTheClipboard
->Close();
484 *m_text
<< "Closed the clipboard." << "\n";
489 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
493 GetClientSize( &x
, &y
);
495 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
496 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
499 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
501 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
504 void MyPanel::OnListBox( wxCommandEvent
&event
)
506 m_text
->WriteText( "ListBox selection string is: " );
507 m_text
->WriteText( event
.GetString() );
508 m_text
->WriteText( "\n" );
511 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
513 switch (event
.GetId())
515 case ID_LISTBOX_ENABLE
:
517 m_listbox
->Enable( !((bool)event
.GetInt()) );
520 case ID_LISTBOX_SEL_NUM
:
522 m_listbox
->SetSelection( 2 );
525 case ID_LISTBOX_SEL_STR
:
527 m_listbox
->SetStringSelection( "This" );
530 case ID_LISTBOX_CLEAR
:
535 case ID_LISTBOX_APPEND
:
537 m_listbox
->Append( "Hi!" );
540 case ID_LISTBOX_DELETE
:
542 int idx
= m_listbox
->GetSelection();
543 m_listbox
->Delete( idx
);
546 case ID_LISTBOX_FONT
:
548 m_listbox
->SetFont( *wxITALIC_FONT
);
549 m_checkbox
->SetFont( *wxITALIC_FONT
);
555 void MyPanel::OnChoice( wxCommandEvent
&event
)
557 m_text
->WriteText( "Choice selection string is: " );
558 m_text
->WriteText( event
.GetString() );
559 m_text
->WriteText( "\n" );
562 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
564 switch (event
.GetId())
566 case ID_CHOICE_ENABLE
:
568 m_choice
->Enable( !((bool)event
.GetInt()) );
571 case ID_CHOICE_SEL_NUM
:
573 m_choice
->SetSelection( 2 );
576 case ID_CHOICE_SEL_STR
:
578 m_choice
->SetStringSelection( "This" );
581 case ID_CHOICE_CLEAR
:
586 case ID_CHOICE_APPEND
:
588 m_choice
->Append( "Hi!" );
591 case ID_CHOICE_DELETE
:
593 int idx
= m_choice
->GetSelection();
594 m_choice
->Delete( idx
);
599 m_choice
->SetFont( *wxITALIC_FONT
);
605 void MyPanel::OnCombo( wxCommandEvent
&event
)
607 m_text
->WriteText( "ComboBox selection string is: " );
608 m_text
->WriteText( event
.GetString() );
609 m_text
->WriteText( "\n" );
612 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
614 switch (event
.GetId())
616 case ID_COMBO_ENABLE
:
618 m_combo
->Enable( !((bool)event
.GetInt()) );
621 case ID_COMBO_SEL_NUM
:
623 m_combo
->SetSelection( 2 );
626 case ID_COMBO_SEL_STR
:
628 m_combo
->SetStringSelection( "This" );
636 case ID_COMBO_APPEND
:
638 m_combo
->Append( "Hi!" );
641 case ID_COMBO_DELETE
:
643 int idx
= m_combo
->GetSelection();
644 m_combo
->Delete( idx
);
649 m_combo
->SetFont( *wxITALIC_FONT
);
655 void MyPanel::OnRadio( wxCommandEvent
&event
)
657 m_text
->WriteText( "RadioBox selection string is: " );
658 m_text
->WriteText( event
.GetString() );
659 m_text
->WriteText( "\n" );
662 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
664 switch (event
.GetId())
666 case ID_RADIOBOX_ENABLE
:
668 m_radio
->Enable( !((bool)event
.GetInt()) );
671 case ID_RADIOBOX_SEL_NUM
:
673 m_radio
->SetSelection( 2 );
676 case ID_RADIOBOX_SEL_STR
:
678 m_radio
->SetStringSelection( "This" );
681 case ID_RADIOBOX_FONT
:
683 m_radio
->SetFont( *wxITALIC_FONT
);
689 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
691 m_fontButton
->SetFont( *wxITALIC_FONT
);
692 m_text
->SetFont( *wxITALIC_FONT
);
695 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
697 m_gauge
->SetValue( m_slider
->GetValue() );
700 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
703 value
.sprintf( "%d", (int)event
.GetPosition() );
704 m_spintext
->SetValue( value
);
709 delete m_notebook
->GetImageList();
712 //----------------------------------------------------------------------
714 //----------------------------------------------------------------------
716 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
717 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
718 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
721 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
722 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
724 (void)new MyPanel( this, 10, 10, 300, 100 );
727 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
732 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
734 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);