]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
fe99c4266e87f4f6d77aa5b9fb930c73d4760211
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"
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"
50 //----------------------------------------------------------------------
52 //----------------------------------------------------------------------
54 class MyApp
: public wxApp
60 class MyPanel
: public wxPanel
64 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
67 void OnSize( wxSizeEvent
& event
);
68 void OnListBox( wxCommandEvent
&event
);
69 void OnListBoxDoubleClick( wxCommandEvent
&event
);
70 void OnListBoxButtons( wxCommandEvent
&event
);
71 void OnChoice( wxCommandEvent
&event
);
72 void OnChoiceButtons( wxCommandEvent
&event
);
73 void OnCombo( wxCommandEvent
&event
);
74 void OnComboButtons( wxCommandEvent
&event
);
75 void OnRadio( wxCommandEvent
&event
);
76 void OnRadioButtons( wxCommandEvent
&event
);
77 void OnSetFont( wxCommandEvent
&event
);
78 void OnPageChanged( wxNotebookEvent
&event
);
79 void OnSliderUpdate( wxCommandEvent
&event
);
80 void OnSpinUpdate( wxSpinEvent
&event
);
81 void OnPasteFromClipboard( wxCommandEvent
&event
);
82 void OnCopyToClipboard( wxCommandEvent
&event
);
90 wxButton
*m_fontButton
;
91 wxSpinButton
*m_spinbutton
;
92 wxTextCtrl
*m_spintext
;
93 wxTextCtrl
*m_multitext
;
94 wxCheckBox
*m_checkbox
;
97 wxNotebook
*m_notebook
;
102 class MyFrame
: public wxFrame
106 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
110 void OnQuit(wxCommandEvent
& event
);
111 void OnAbout(wxCommandEvent
& event
);
112 bool OnClose(void) { return TRUE
; }
114 DECLARE_EVENT_TABLE()
117 //----------------------------------------------------------------------
119 //----------------------------------------------------------------------
121 IMPLEMENT_APP (MyApp
)
123 //----------------------------------------------------------------------
125 //----------------------------------------------------------------------
127 const int MINIMAL_QUIT
= 100;
128 const int MINIMAL_TEXT
= 101;
129 const int MINIMAL_ABOUT
= 102;
131 bool MyApp::OnInit(void)
133 // Create the main frame window
134 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
135 "Controls wxWindows App",
139 // The wxICON() macros loads an icon from a resource under Windows
140 // and uses an #included XPM image under GTK+ and Motif
142 frame
->SetIcon( wxICON(mondrian
) );
144 wxMenu
*file_menu
= new wxMenu
;
146 file_menu
->Append(MINIMAL_ABOUT
, "&About");
147 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
148 wxMenuBar
*menu_bar
= new wxMenuBar
;
149 menu_bar
->Append(file_menu
, "&File");
150 frame
->SetMenuBar(menu_bar
);
159 //----------------------------------------------------------------------
161 //----------------------------------------------------------------------
163 const int ID_NOTEBOOK
= 1000;
165 const int ID_LISTBOX
= 130;
166 const int ID_LISTBOX_SEL_NUM
= 131;
167 const int ID_LISTBOX_SEL_STR
= 132;
168 const int ID_LISTBOX_CLEAR
= 133;
169 const int ID_LISTBOX_APPEND
= 134;
170 const int ID_LISTBOX_DELETE
= 135;
171 const int ID_LISTBOX_FONT
= 136;
172 const int ID_LISTBOX_ENABLE
= 137;
174 const int ID_CHOICE
= 120;
175 const int ID_CHOICE_SEL_NUM
= 121;
176 const int ID_CHOICE_SEL_STR
= 122;
177 const int ID_CHOICE_CLEAR
= 123;
178 const int ID_CHOICE_APPEND
= 124;
179 const int ID_CHOICE_DELETE
= 125;
180 const int ID_CHOICE_FONT
= 126;
181 const int ID_CHOICE_ENABLE
= 127;
183 const int ID_COMBO
= 140;
184 const int ID_COMBO_SEL_NUM
= 141;
185 const int ID_COMBO_SEL_STR
= 142;
186 const int ID_COMBO_CLEAR
= 143;
187 const int ID_COMBO_APPEND
= 144;
188 const int ID_COMBO_DELETE
= 145;
189 const int ID_COMBO_FONT
= 146;
190 const int ID_COMBO_ENABLE
= 147;
192 const int ID_TEXT
= 150;
193 const int ID_PASTE_TEXT
= 151;
194 const int ID_COPY_TEXT
= 152;
196 const int ID_RADIOBOX
= 160;
197 const int ID_RADIOBOX_SEL_NUM
= 161;
198 const int ID_RADIOBOX_SEL_STR
= 162;
199 const int ID_RADIOBOX_FONT
= 163;
200 const int ID_RADIOBOX_ENABLE
= 164;
202 const int ID_RADIOBUTTON_1
= 166;
203 const int ID_RADIOBUTTON_2
= 167;
205 const int ID_SET_FONT
= 170;
207 const int ID_GAUGE
= 180;
208 const int ID_SLIDER
= 181;
210 const int ID_SPIN
= 182;
213 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
214 EVT_SIZE ( MyPanel::OnSize
)
215 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
216 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
217 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
218 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
219 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
220 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
221 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
222 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
223 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
224 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
225 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
226 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
227 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
228 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
229 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
230 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
231 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
232 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
233 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
234 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
235 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
236 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
237 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
238 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
239 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
240 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
241 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
242 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
243 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
244 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
245 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
246 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
247 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
248 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
249 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
250 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
253 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
254 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
256 // SetBackgroundColour("cadet blue");
258 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
259 // m_text->SetBackgroundColour("wheat");
261 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
276 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
279 // fill the image list
280 wxImageList
*imagelist
= new wxImageList(32, 32);
282 imagelist
-> Add( wxBitmap( list_xpm
));
283 imagelist
-> Add( wxBitmap( choice_xpm
));
284 imagelist
-> Add( wxBitmap( combo_xpm
));
285 imagelist
-> Add( wxBitmap( text_xpm
));
286 imagelist
-> Add( wxBitmap( radio_xpm
));
287 imagelist
-> Add( wxBitmap( gauge_xpm
));
288 m_notebook
->SetImageList(imagelist
);
289 #elif defined(__WXMSW__)
290 // load images from resources
293 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
295 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
297 static const char *s_iconNames
[Image_Max
] =
299 "list", "choice", "combo", "text", "radio", "gauge"
302 for ( size_t n
= 0; n
< Image_Max
; n
++ )
304 wxBitmap
bmp(s_iconNames
[n
]);
305 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
307 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
312 m_notebook
->SetImageList(imagelist
);
316 #define Image_List -1
317 #define Image_Choice -1
318 #define Image_Combo -1
319 #define Image_Text -1
320 #define Image_Radio -1
321 #define Image_Gauge -1
326 wxButton
*button
= (wxButton
*)NULL
;
328 // m_notebook->SetBackgroundColour("cadet blue");
330 wxPanel
*panel
= (wxPanel
*) NULL
;
332 panel
= new wxPanel(m_notebook
);
333 // panel->SetBackgroundColour("cadet blue");
334 // panel->SetForegroundColour("blue");
335 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
337 m_listbox
->SetToolTip( "This is a list box" );
339 // m_listbox->SetBackgroundColour("wheat");
340 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
341 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
342 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
343 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
344 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
345 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
347 button
->SetToolTip( "Press here to set italic font" );
350 // button->SetForegroundColour( "red" );
351 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
352 m_checkbox
->SetValue(FALSE
);
354 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
356 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
358 panel
= new wxPanel(m_notebook
);
359 // panel->SetBackgroundColour("cadet blue");
360 // panel->SetForegroundColour("blue");
361 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
362 // m_choice->SetBackgroundColour("wheat");
363 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
364 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
365 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
366 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
367 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
368 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
369 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
370 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
372 panel
= new wxPanel(m_notebook
);
373 // panel->SetBackgroundColour("cadet blue");
374 // panel->SetForegroundColour("blue");
375 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
376 // m_combo->SetBackgroundColour("wheat");
377 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
378 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
379 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
380 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
381 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
382 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
383 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
384 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
386 panel
= new wxPanel(m_notebook
);
387 // panel->SetBackgroundColour("cadet blue");
388 // panel->SetForegroundColour("blue");
389 wxTextCtrl
*tc
= new wxTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
390 (*tc
) << " More text.";
391 // tc->SetBackgroundColour("wheat");
392 m_multitext
= new wxTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
393 (*m_multitext
) << " More text.";
394 // m_multitext->SetBackgroundColour("wheat");
395 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
396 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
397 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,140), wxSize(110,30) );
398 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
400 wxString choices2
[] =
406 panel
= new wxPanel(m_notebook
);
407 // panel->SetBackgroundColour("cadet blue");
408 // panel->SetForegroundColour("blue");
409 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
410 // m_radio->SetBackgroundColour("wheat");
411 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
412 // m_radio->SetBackgroundColour("wheat");
413 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
414 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
415 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
416 // m_fontButton->SetForegroundColour("blue");
417 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
418 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
419 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
420 rb
->SetValue( FALSE
);
421 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
422 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
424 panel
= new wxPanel(m_notebook
);
425 // panel->SetBackgroundColour("cadet blue");
426 // panel->SetForegroundColour("blue");
427 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
428 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
429 // m_gauge->SetBackgroundColour("wheat");
430 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
431 // m_slider->SetBackgroundColour("wheat");
432 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
434 // No wrapping text in wxStaticText yet :-(
435 (void)new wxStaticText( panel
, -1,
441 (void)new wxStaticText( panel
, -1,
442 "In order see the gauge (aka progress bar)\n"
443 "control do something you have to drag the\n"
444 "handle of the slider to the right.\n"
446 "This is also supposed to demonstrate how\n"
447 "to use static controls.\n",
452 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
453 // m_spintext->SetBackgroundColour("wheat");
454 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
455 // m_spinbutton->SetBackgroundColour("wheat");
456 m_spinbutton
->SetRange(0,100);
458 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
461 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
465 if (!wxTheClipboard
->Open())
467 *m_text
<< "Error opening the clipboard." << "\n";
473 *m_text
<< "Successfully opened the clipboard." << "\n";
476 wxTextDataObject
*data
= new wxTextDataObject();
478 if (wxTheClipboard
->GetData( data
))
480 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
481 *m_multitext
<< data
->GetText() << "\n";
485 *m_text
<< "Error getting data from the clipboard." << "\n";
488 wxTheClipboard
->Close();
490 *m_text
<< "Closed the clipboard." << "\n";
497 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
501 wxString
text( m_multitext
->GetLineText(0) );
503 if (text
.IsEmpty()) return;
505 if (!wxTheClipboard
->Open())
507 *m_text
<< "Error opening the clipboard." << "\n";
513 *m_text
<< "Successfully opened the clipboard." << "\n";
516 wxTextDataObject
*data
= new wxTextDataObject( text
);
517 wxDataBroker
*broker
= new wxDataBroker();
520 if (!wxTheClipboard
->SetData( broker
))
522 *m_text
<< "Error while copying to the clipboard." << "\n";
526 *m_text
<< "Successfully copied data to the clipboard." << "\n";
529 wxTheClipboard
->Close();
531 *m_text
<< "Closed the clipboard." << "\n";
536 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
540 GetClientSize( &x
, &y
);
542 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
543 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
546 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
548 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
551 void MyPanel::OnListBox( wxCommandEvent
&event
)
553 m_text
->WriteText( "ListBox selection string is: " );
554 m_text
->WriteText( event
.GetString() );
555 m_text
->WriteText( "\n" );
558 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
560 m_text
->WriteText( "ListBox double click string is: " );
561 m_text
->WriteText( event
.GetString() );
562 m_text
->WriteText( "\n" );
565 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
567 switch (event
.GetId())
569 case ID_LISTBOX_ENABLE
:
571 m_text
->WriteText("Checkbox clicked.\n");
572 m_listbox
->Enable( event
.GetInt() == 0 );
575 case ID_LISTBOX_SEL_NUM
:
577 m_listbox
->SetSelection( 2 );
580 case ID_LISTBOX_SEL_STR
:
582 m_listbox
->SetStringSelection( "This" );
585 case ID_LISTBOX_CLEAR
:
590 case ID_LISTBOX_APPEND
:
592 m_listbox
->Append( "Hi!" );
595 case ID_LISTBOX_DELETE
:
597 int idx
= m_listbox
->GetSelection();
598 m_listbox
->Delete( idx
);
601 case ID_LISTBOX_FONT
:
603 m_listbox
->SetFont( *wxITALIC_FONT
);
604 m_checkbox
->SetFont( *wxITALIC_FONT
);
610 void MyPanel::OnChoice( wxCommandEvent
&event
)
612 m_text
->WriteText( "Choice selection string is: " );
613 m_text
->WriteText( event
.GetString() );
614 m_text
->WriteText( "\n" );
617 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
619 switch (event
.GetId())
621 case ID_CHOICE_ENABLE
:
623 m_choice
->Enable( event
.GetInt() == 0 );
626 case ID_CHOICE_SEL_NUM
:
628 m_choice
->SetSelection( 2 );
631 case ID_CHOICE_SEL_STR
:
633 m_choice
->SetStringSelection( "This" );
636 case ID_CHOICE_CLEAR
:
641 case ID_CHOICE_APPEND
:
643 m_choice
->Append( "Hi!" );
646 case ID_CHOICE_DELETE
:
648 int idx
= m_choice
->GetSelection();
649 m_choice
->Delete( idx
);
654 m_choice
->SetFont( *wxITALIC_FONT
);
660 void MyPanel::OnCombo( wxCommandEvent
&event
)
662 m_text
->WriteText( "ComboBox selection string is: " );
663 m_text
->WriteText( event
.GetString() );
664 m_text
->WriteText( "\n" );
667 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
669 switch (event
.GetId())
671 case ID_COMBO_ENABLE
:
673 m_combo
->Enable( event
.GetInt() == 0 );
676 case ID_COMBO_SEL_NUM
:
678 m_combo
->SetSelection( 2 );
681 case ID_COMBO_SEL_STR
:
683 m_combo
->SetStringSelection( "This" );
691 case ID_COMBO_APPEND
:
693 m_combo
->Append( "Hi!" );
696 case ID_COMBO_DELETE
:
698 int idx
= m_combo
->GetSelection();
699 m_combo
->Delete( idx
);
704 m_combo
->SetFont( *wxITALIC_FONT
);
710 void MyPanel::OnRadio( wxCommandEvent
&event
)
712 m_text
->WriteText( "RadioBox selection string is: " );
713 m_text
->WriteText( event
.GetString() );
714 m_text
->WriteText( "\n" );
717 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
719 switch (event
.GetId())
721 case ID_RADIOBOX_ENABLE
:
723 m_radio
->Enable( event
.GetInt() == 0 );
726 case ID_RADIOBOX_SEL_NUM
:
728 m_radio
->SetSelection( 2 );
731 case ID_RADIOBOX_SEL_STR
:
733 m_radio
->SetStringSelection( "This" );
736 case ID_RADIOBOX_FONT
:
738 m_radio
->SetFont( *wxITALIC_FONT
);
744 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
746 m_fontButton
->SetFont( *wxITALIC_FONT
);
747 m_text
->SetFont( *wxITALIC_FONT
);
750 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
752 m_gauge
->SetValue( m_slider
->GetValue() );
755 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
758 value
.sprintf( "%d", (int)event
.GetPosition() );
759 m_spintext
->SetValue( value
);
764 delete m_notebook
->GetImageList();
767 //----------------------------------------------------------------------
769 //----------------------------------------------------------------------
771 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
772 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
773 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
776 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
777 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
779 (void)new MyPanel( this, 10, 10, 300, 100 );
782 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
787 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
789 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);