]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
d0f9bbb2d5b720ed5e3efb1726f14b4bebf0f881
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_CHOICE (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
);
336 // m_listbox->SetBackgroundColour("wheat");
337 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
338 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
339 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
340 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
341 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
342 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
345 wxToolTip::Add( button
, "Press here to set italic font" );
347 // button->SetForegroundColour( "red" );
348 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
349 m_checkbox
->SetValue(FALSE
);
350 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
352 panel
= new wxPanel(m_notebook
);
353 // panel->SetBackgroundColour("cadet blue");
354 // panel->SetForegroundColour("blue");
355 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
356 // m_choice->SetBackgroundColour("wheat");
357 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
358 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
359 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
360 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
361 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
362 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
363 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
364 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
366 panel
= new wxPanel(m_notebook
);
367 // panel->SetBackgroundColour("cadet blue");
368 // panel->SetForegroundColour("blue");
369 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
370 // m_combo->SetBackgroundColour("wheat");
371 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
372 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
373 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
374 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
375 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
376 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
377 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
378 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
380 panel
= new wxPanel(m_notebook
);
381 // panel->SetBackgroundColour("cadet blue");
382 // panel->SetForegroundColour("blue");
383 wxTextCtrl
*tc
= new wxTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
384 (*tc
) << " More text.";
385 // tc->SetBackgroundColour("wheat");
386 m_multitext
= new wxTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
387 (*m_multitext
) << " More text.";
388 m_multitext
->SetBackgroundColour("wheat");
389 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
390 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
391 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,140), wxSize(110,30) );
392 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
394 wxString choices2
[] =
400 panel
= new wxPanel(m_notebook
);
401 // panel->SetBackgroundColour("cadet blue");
402 // panel->SetForegroundColour("blue");
403 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
404 // m_radio->SetBackgroundColour("wheat");
405 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
406 // m_radio->SetBackgroundColour("wheat");
407 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
408 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
409 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
410 // m_fontButton->SetForegroundColour("blue");
411 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
412 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
413 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
414 rb
->SetValue( FALSE
);
415 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
416 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
418 panel
= new wxPanel(m_notebook
);
419 // panel->SetBackgroundColour("cadet blue");
420 // panel->SetForegroundColour("blue");
421 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
422 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
423 // m_gauge->SetBackgroundColour("wheat");
424 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
425 // m_slider->SetBackgroundColour("wheat");
426 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
428 // No wrapping text in wxStaticText yet :-(
429 (void)new wxStaticText( panel
, -1,
435 (void)new wxStaticText( panel
, -1,
436 "In order see the gauge (aka progress bar)\n"
437 "control do something you have to drag the\n"
438 "handle of the slider to the right.\n"
440 "This is also supposed to demonstrate how\n"
441 "to use static controls.\n",
446 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
447 // m_spintext->SetBackgroundColour("wheat");
448 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
449 // m_spinbutton->SetBackgroundColour("wheat");
450 m_spinbutton
->SetRange(0,100);
452 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
455 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
459 if (!wxTheClipboard
->Open())
461 *m_text
<< "Error opening the clipboard." << "\n";
467 *m_text
<< "Successfully opened the clipboard." << "\n";
470 wxTextDataObject
*data
= new wxTextDataObject();
472 if (wxTheClipboard
->GetData( data
))
474 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
475 *m_multitext
<< data
->GetText() << "\n";
479 *m_text
<< "Error getting data from the clipboard." << "\n";
482 wxTheClipboard
->Close();
484 *m_text
<< "Closed the clipboard." << "\n";
491 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
495 wxString
text( m_multitext
->GetLineText(0) );
497 if (text
.IsEmpty()) return;
499 if (!wxTheClipboard
->Open())
501 *m_text
<< "Error opening the clipboard." << "\n";
507 *m_text
<< "Successfully opened the clipboard." << "\n";
510 wxTextDataObject
*data
= new wxTextDataObject( text
);
511 wxDataBroker
*broker
= new wxDataBroker();
514 if (!wxTheClipboard
->SetData( broker
))
516 *m_text
<< "Error while copying to the clipboard." << "\n";
520 *m_text
<< "Successfully copied data to the clipboard." << "\n";
523 wxTheClipboard
->Close();
525 *m_text
<< "Closed the clipboard." << "\n";
530 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
534 GetClientSize( &x
, &y
);
536 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
537 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
540 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
542 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
545 void MyPanel::OnListBox( wxCommandEvent
&event
)
547 m_text
->WriteText( "ListBox selection string is: " );
548 m_text
->WriteText( event
.GetString() );
549 m_text
->WriteText( "\n" );
552 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
554 m_text
->WriteText( "ListBox double click string is: " );
555 m_text
->WriteText( event
.GetString() );
556 m_text
->WriteText( "\n" );
559 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
561 switch (event
.GetId())
563 case ID_LISTBOX_ENABLE
:
565 m_text
->WriteText("Checkbox clicked.\n");
566 m_listbox
->Enable( event
.GetInt() == 0 );
569 case ID_LISTBOX_SEL_NUM
:
571 m_listbox
->SetSelection( 2 );
574 case ID_LISTBOX_SEL_STR
:
576 m_listbox
->SetStringSelection( "This" );
579 case ID_LISTBOX_CLEAR
:
584 case ID_LISTBOX_APPEND
:
586 m_listbox
->Append( "Hi!" );
589 case ID_LISTBOX_DELETE
:
591 int idx
= m_listbox
->GetSelection();
592 m_listbox
->Delete( idx
);
595 case ID_LISTBOX_FONT
:
597 m_listbox
->SetFont( *wxITALIC_FONT
);
598 m_checkbox
->SetFont( *wxITALIC_FONT
);
604 void MyPanel::OnChoice( wxCommandEvent
&event
)
606 m_text
->WriteText( "Choice selection string is: " );
607 m_text
->WriteText( event
.GetString() );
608 m_text
->WriteText( "\n" );
611 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
613 switch (event
.GetId())
615 case ID_CHOICE_ENABLE
:
617 m_choice
->Enable( event
.GetInt() == 0 );
620 case ID_CHOICE_SEL_NUM
:
622 m_choice
->SetSelection( 2 );
625 case ID_CHOICE_SEL_STR
:
627 m_choice
->SetStringSelection( "This" );
630 case ID_CHOICE_CLEAR
:
635 case ID_CHOICE_APPEND
:
637 m_choice
->Append( "Hi!" );
640 case ID_CHOICE_DELETE
:
642 int idx
= m_choice
->GetSelection();
643 m_choice
->Delete( idx
);
648 m_choice
->SetFont( *wxITALIC_FONT
);
654 void MyPanel::OnCombo( wxCommandEvent
&event
)
656 m_text
->WriteText( "ComboBox selection string is: " );
657 m_text
->WriteText( event
.GetString() );
658 m_text
->WriteText( "\n" );
661 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
663 switch (event
.GetId())
665 case ID_COMBO_ENABLE
:
667 m_combo
->Enable( event
.GetInt() == 0 );
670 case ID_COMBO_SEL_NUM
:
672 m_combo
->SetSelection( 2 );
675 case ID_COMBO_SEL_STR
:
677 m_combo
->SetStringSelection( "This" );
685 case ID_COMBO_APPEND
:
687 m_combo
->Append( "Hi!" );
690 case ID_COMBO_DELETE
:
692 int idx
= m_combo
->GetSelection();
693 m_combo
->Delete( idx
);
698 m_combo
->SetFont( *wxITALIC_FONT
);
704 void MyPanel::OnRadio( wxCommandEvent
&event
)
706 m_text
->WriteText( "RadioBox selection string is: " );
707 m_text
->WriteText( event
.GetString() );
708 m_text
->WriteText( "\n" );
711 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
713 switch (event
.GetId())
715 case ID_RADIOBOX_ENABLE
:
717 m_radio
->Enable( event
.GetInt() == 0 );
720 case ID_RADIOBOX_SEL_NUM
:
722 m_radio
->SetSelection( 2 );
725 case ID_RADIOBOX_SEL_STR
:
727 m_radio
->SetStringSelection( "This" );
730 case ID_RADIOBOX_FONT
:
732 m_radio
->SetFont( *wxITALIC_FONT
);
738 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
740 m_fontButton
->SetFont( *wxITALIC_FONT
);
741 m_text
->SetFont( *wxITALIC_FONT
);
744 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
746 m_gauge
->SetValue( m_slider
->GetValue() );
749 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
752 value
.sprintf( "%d", (int)event
.GetPosition() );
753 m_spintext
->SetValue( value
);
758 delete m_notebook
->GetImageList();
761 //----------------------------------------------------------------------
763 //----------------------------------------------------------------------
765 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
766 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
767 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
770 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
771 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
773 (void)new MyPanel( this, 10, 10, 300, 100 );
776 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
781 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
783 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);