]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
1053d0653c173bf489bc14fb99072299e22bd0af
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/spinbutt.h"
30 #include "wx/clipbrd.h"
32 #if defined(__WXGTK__) || defined(__WXMOTIF__)
37 #include "mondrian.xpm"
38 #include "icons/choice.xpm"
39 #include "icons/combo.xpm"
40 #include "icons/list.xpm"
41 #include "icons/radio.xpm"
42 #include "icons/text.xpm"
43 #include "icons/gauge.xpm"
46 //----------------------------------------------------------------------
48 //----------------------------------------------------------------------
50 class MyApp
: public wxApp
56 class MyPanel
: public wxPanel
60 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
63 void OnSize( wxSizeEvent
& event
);
64 void OnListBox( wxCommandEvent
&event
);
65 void OnListBoxDoubleClick( wxCommandEvent
&event
);
66 void OnListBoxButtons( wxCommandEvent
&event
);
67 void OnChoice( wxCommandEvent
&event
);
68 void OnChoiceButtons( wxCommandEvent
&event
);
69 void OnCombo( wxCommandEvent
&event
);
70 void OnComboButtons( wxCommandEvent
&event
);
71 void OnRadio( wxCommandEvent
&event
);
72 void OnRadioButtons( wxCommandEvent
&event
);
73 void OnSetFont( wxCommandEvent
&event
);
74 void OnPageChanged( wxNotebookEvent
&event
);
75 void OnSliderUpdate( wxCommandEvent
&event
);
76 void OnSpinUpdate( wxSpinEvent
&event
);
77 void OnPasteFromClipboard( wxCommandEvent
&event
);
78 void OnCopyToClipboard( wxCommandEvent
&event
);
86 wxButton
*m_fontButton
;
87 wxSpinButton
*m_spinbutton
;
88 wxTextCtrl
*m_spintext
;
89 wxTextCtrl
*m_multitext
;
90 wxCheckBox
*m_checkbox
;
93 wxNotebook
*m_notebook
;
98 class MyFrame
: public wxFrame
102 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
106 void OnQuit(wxCommandEvent
& event
);
107 void OnAbout(wxCommandEvent
& event
);
108 bool OnClose(void) { return TRUE
; }
110 DECLARE_EVENT_TABLE()
113 //----------------------------------------------------------------------
115 //----------------------------------------------------------------------
117 IMPLEMENT_APP (MyApp
)
119 //----------------------------------------------------------------------
121 //----------------------------------------------------------------------
123 const int MINIMAL_QUIT
= 100;
124 const int MINIMAL_TEXT
= 101;
125 const int MINIMAL_ABOUT
= 102;
127 bool MyApp::OnInit(void)
129 // Create the main frame window
130 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
131 "Controls wxWindows App",
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_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
214 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
215 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
216 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
217 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
218 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
219 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
220 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
221 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
222 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
223 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
224 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
225 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
226 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
227 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
228 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
229 EVT_CHOICE (ID_COMBO
, MyPanel::OnCombo
)
230 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
231 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
232 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
233 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
234 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
235 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
236 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
237 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
238 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
239 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
240 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
241 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
242 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
243 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
244 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
245 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
246 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
249 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
250 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
252 // SetBackgroundColour("cadet blue");
254 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
255 // m_text->SetBackgroundColour("wheat");
257 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
272 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
275 // fill the image list
276 wxImageList
*imagelist
= new wxImageList(32, 32);
278 imagelist
-> Add( wxBitmap( list_xpm
));
279 imagelist
-> Add( wxBitmap( choice_xpm
));
280 imagelist
-> Add( wxBitmap( combo_xpm
));
281 imagelist
-> Add( wxBitmap( text_xpm
));
282 imagelist
-> Add( wxBitmap( radio_xpm
));
283 imagelist
-> Add( wxBitmap( gauge_xpm
));
284 m_notebook
->SetImageList(imagelist
);
285 #elif defined(__WXMSW__)
286 // load images from resources
289 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
291 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
293 static const char *s_iconNames
[Image_Max
] =
295 "list", "choice", "combo", "text", "radio", "gauge"
298 for ( size_t n
= 0; n
< Image_Max
; n
++ )
300 wxBitmap
bmp(s_iconNames
[n
]);
301 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
303 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
308 m_notebook
->SetImageList(imagelist
);
312 #define Image_List -1
313 #define Image_Choice -1
314 #define Image_Combo -1
315 #define Image_Text -1
316 #define Image_Radio -1
317 #define Image_Gauge -1
322 wxButton
*button
= (wxButton
*)NULL
;
324 // m_notebook->SetBackgroundColour("cadet blue");
326 wxPanel
*panel
= (wxPanel
*) NULL
;
327 panel
= new wxPanel(m_notebook
);
328 // panel->SetBackgroundColour("cadet blue");
329 // panel->SetForegroundColour("blue");
330 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
331 // m_listbox->SetBackgroundColour("wheat");
332 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
333 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
334 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
335 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
336 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
337 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
338 // button->SetForegroundColour( "red" );
339 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
340 m_checkbox
->SetValue(FALSE
);
341 m_notebook
->AddPage(panel
, "wxList", FALSE
, Image_List
);
343 panel
= new wxPanel(m_notebook
);
344 // panel->SetBackgroundColour("cadet blue");
345 // panel->SetForegroundColour("blue");
346 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
347 // m_choice->SetBackgroundColour("wheat");
348 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
349 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
350 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
351 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
352 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
353 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
354 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
355 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
357 panel
= new wxPanel(m_notebook
);
358 // panel->SetBackgroundColour("cadet blue");
359 // panel->SetForegroundColour("blue");
360 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
361 // m_combo->SetBackgroundColour("wheat");
362 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
363 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
364 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
365 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
366 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
367 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
368 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
369 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
371 panel
= new wxPanel(m_notebook
);
372 // panel->SetBackgroundColour("cadet blue");
373 // panel->SetForegroundColour("blue");
374 wxTextCtrl
*tc
= new wxTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
375 (*tc
) << " More text.";
376 // tc->SetBackgroundColour("wheat");
377 m_multitext
= new wxTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
378 (*m_multitext
) << " More text.";
379 m_multitext
->SetBackgroundColour("wheat");
380 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
381 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
382 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,140), wxSize(110,30) );
383 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
385 wxString choices2
[] =
391 panel
= new wxPanel(m_notebook
);
392 // panel->SetBackgroundColour("cadet blue");
393 // panel->SetForegroundColour("blue");
394 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
395 // m_radio->SetBackgroundColour("wheat");
396 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
397 // m_radio->SetBackgroundColour("wheat");
398 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
399 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
400 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
401 // m_fontButton->SetForegroundColour("blue");
402 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
403 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
404 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
405 rb
->SetValue( FALSE
);
406 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
407 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
409 panel
= new wxPanel(m_notebook
);
410 // panel->SetBackgroundColour("cadet blue");
411 // panel->SetForegroundColour("blue");
412 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
413 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155,-1) );
414 // m_gauge->SetBackgroundColour("wheat");
415 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
416 // m_slider->SetBackgroundColour("wheat");
417 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
418 (void)new wxStaticText( panel
, -1,
419 "In order see the gauge (aka progress bar)\n"
420 "control do something you have to drag the\n"
421 "handle of the slider to the right.\n"
423 "This is also supposed to demonstrate how\n"
424 "to use static controls.\n",
430 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
431 // m_spintext->SetBackgroundColour("wheat");
432 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
433 // m_spinbutton->SetBackgroundColour("wheat");
434 m_spinbutton
->SetRange(0,100);
436 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
439 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
443 if (!wxTheClipboard
->Open())
445 *m_text
<< "Error opening the clipboard." << "\n";
451 *m_text
<< "Successfully opened the clipboard." << "\n";
454 wxTextDataObject
*data
= new wxTextDataObject();
456 if (wxTheClipboard
->GetData( data
))
458 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
459 *m_multitext
<< data
->GetText() << "\n";
463 *m_text
<< "Error getting data from the clipboard." << "\n";
466 wxTheClipboard
->Close();
468 *m_text
<< "Closed the clipboard." << "\n";
475 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
479 wxString
text( m_multitext
->GetLineText(0) );
481 if (text
.IsEmpty()) return;
483 if (!wxTheClipboard
->Open())
485 *m_text
<< "Error opening the clipboard." << "\n";
491 *m_text
<< "Successfully opened the clipboard." << "\n";
494 wxTextDataObject
*data
= new wxTextDataObject( text
);
495 wxDataBroker
*broker
= new wxDataBroker();
498 if (!wxTheClipboard
->SetData( broker
))
500 *m_text
<< "Error while copying to the clipboard." << "\n";
504 *m_text
<< "Successfully copied data to the clipboard." << "\n";
507 wxTheClipboard
->Close();
509 *m_text
<< "Closed the clipboard." << "\n";
514 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
518 GetClientSize( &x
, &y
);
520 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
521 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
524 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
526 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
529 void MyPanel::OnListBox( wxCommandEvent
&event
)
531 m_text
->WriteText( "ListBox selection string is: " );
532 m_text
->WriteText( event
.GetString() );
533 m_text
->WriteText( "\n" );
536 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
538 m_text
->WriteText( "ListBox double click string is: " );
539 m_text
->WriteText( event
.GetString() );
540 m_text
->WriteText( "\n" );
543 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
545 switch (event
.GetId())
547 case ID_LISTBOX_ENABLE
:
549 m_text
->WriteText("Checkbox clicked.\n");
550 m_listbox
->Enable( event
.GetInt() == 0 );
553 case ID_LISTBOX_SEL_NUM
:
555 m_listbox
->SetSelection( 2 );
558 case ID_LISTBOX_SEL_STR
:
560 m_listbox
->SetStringSelection( "This" );
563 case ID_LISTBOX_CLEAR
:
568 case ID_LISTBOX_APPEND
:
570 m_listbox
->Append( "Hi!" );
573 case ID_LISTBOX_DELETE
:
575 int idx
= m_listbox
->GetSelection();
576 m_listbox
->Delete( idx
);
579 case ID_LISTBOX_FONT
:
581 m_listbox
->SetFont( *wxITALIC_FONT
);
582 m_checkbox
->SetFont( *wxITALIC_FONT
);
588 void MyPanel::OnChoice( wxCommandEvent
&event
)
590 m_text
->WriteText( "Choice selection string is: " );
591 m_text
->WriteText( event
.GetString() );
592 m_text
->WriteText( "\n" );
595 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
597 switch (event
.GetId())
599 case ID_CHOICE_ENABLE
:
601 m_choice
->Enable( event
.GetInt() == 0 );
604 case ID_CHOICE_SEL_NUM
:
606 m_choice
->SetSelection( 2 );
609 case ID_CHOICE_SEL_STR
:
611 m_choice
->SetStringSelection( "This" );
614 case ID_CHOICE_CLEAR
:
619 case ID_CHOICE_APPEND
:
621 m_choice
->Append( "Hi!" );
624 case ID_CHOICE_DELETE
:
626 int idx
= m_choice
->GetSelection();
627 m_choice
->Delete( idx
);
632 m_choice
->SetFont( *wxITALIC_FONT
);
638 void MyPanel::OnCombo( wxCommandEvent
&event
)
640 m_text
->WriteText( "ComboBox selection string is: " );
641 m_text
->WriteText( event
.GetString() );
642 m_text
->WriteText( "\n" );
645 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
647 switch (event
.GetId())
649 case ID_COMBO_ENABLE
:
651 m_combo
->Enable( event
.GetInt() == 0 );
654 case ID_COMBO_SEL_NUM
:
656 m_combo
->SetSelection( 2 );
659 case ID_COMBO_SEL_STR
:
661 m_combo
->SetStringSelection( "This" );
669 case ID_COMBO_APPEND
:
671 m_combo
->Append( "Hi!" );
674 case ID_COMBO_DELETE
:
676 int idx
= m_combo
->GetSelection();
677 m_combo
->Delete( idx
);
682 m_combo
->SetFont( *wxITALIC_FONT
);
688 void MyPanel::OnRadio( wxCommandEvent
&event
)
690 m_text
->WriteText( "RadioBox selection string is: " );
691 m_text
->WriteText( event
.GetString() );
692 m_text
->WriteText( "\n" );
695 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
697 switch (event
.GetId())
699 case ID_RADIOBOX_ENABLE
:
701 m_radio
->Enable( event
.GetInt() == 0 );
704 case ID_RADIOBOX_SEL_NUM
:
706 m_radio
->SetSelection( 2 );
709 case ID_RADIOBOX_SEL_STR
:
711 m_radio
->SetStringSelection( "This" );
714 case ID_RADIOBOX_FONT
:
716 m_radio
->SetFont( *wxITALIC_FONT
);
722 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
724 m_fontButton
->SetFont( *wxITALIC_FONT
);
725 m_text
->SetFont( *wxITALIC_FONT
);
728 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
730 m_gauge
->SetValue( m_slider
->GetValue() );
733 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
736 value
.sprintf( "%d", (int)event
.GetPosition() );
737 m_spintext
->SetValue( value
);
742 delete m_notebook
->GetImageList();
745 //----------------------------------------------------------------------
747 //----------------------------------------------------------------------
749 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
750 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
751 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
754 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
755 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
757 (void)new MyPanel( this, 10, 10, 300, 100 );
760 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
765 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
767 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);