]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
686dc1bab460f6d73eb368bd4c547c4c3d15d475
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
);
83 void OnMoveToEndOfText( wxCommandEvent
&event
);
84 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
92 wxButton
*m_fontButton
;
93 wxSpinButton
*m_spinbutton
;
94 wxTextCtrl
*m_spintext
;
95 wxTextCtrl
*m_multitext
;
96 wxTextCtrl
*m_textentry
;
97 wxCheckBox
*m_checkbox
;
100 wxNotebook
*m_notebook
;
102 DECLARE_EVENT_TABLE()
105 class MyFrame
: public wxFrame
109 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
113 void OnQuit(wxCommandEvent
& event
);
114 void OnAbout(wxCommandEvent
& event
);
115 bool OnClose(void) { return TRUE
; }
117 DECLARE_EVENT_TABLE()
120 //----------------------------------------------------------------------
122 //----------------------------------------------------------------------
126 //----------------------------------------------------------------------
128 //----------------------------------------------------------------------
130 const int MINIMAL_QUIT
= 100;
131 const int MINIMAL_TEXT
= 101;
132 const int MINIMAL_ABOUT
= 102;
134 bool MyApp::OnInit(void)
136 // Create the main frame window
137 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
138 "Controls wxWindows App",
142 // The wxICON() macros loads an icon from a resource under Windows
143 // and uses an #included XPM image under GTK+ and Motif
145 frame
->SetIcon( wxICON(mondrian
) );
147 wxMenu
*file_menu
= new wxMenu
;
149 file_menu
->Append(MINIMAL_ABOUT
, "&About");
150 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
151 wxMenuBar
*menu_bar
= new wxMenuBar
;
152 menu_bar
->Append(file_menu
, "&File");
153 frame
->SetMenuBar(menu_bar
);
162 //----------------------------------------------------------------------
164 //----------------------------------------------------------------------
166 const int ID_NOTEBOOK
= 1000;
168 const int ID_LISTBOX
= 130;
169 const int ID_LISTBOX_SEL_NUM
= 131;
170 const int ID_LISTBOX_SEL_STR
= 132;
171 const int ID_LISTBOX_CLEAR
= 133;
172 const int ID_LISTBOX_APPEND
= 134;
173 const int ID_LISTBOX_DELETE
= 135;
174 const int ID_LISTBOX_FONT
= 136;
175 const int ID_LISTBOX_ENABLE
= 137;
177 const int ID_CHOICE
= 120;
178 const int ID_CHOICE_SEL_NUM
= 121;
179 const int ID_CHOICE_SEL_STR
= 122;
180 const int ID_CHOICE_CLEAR
= 123;
181 const int ID_CHOICE_APPEND
= 124;
182 const int ID_CHOICE_DELETE
= 125;
183 const int ID_CHOICE_FONT
= 126;
184 const int ID_CHOICE_ENABLE
= 127;
186 const int ID_COMBO
= 140;
187 const int ID_COMBO_SEL_NUM
= 141;
188 const int ID_COMBO_SEL_STR
= 142;
189 const int ID_COMBO_CLEAR
= 143;
190 const int ID_COMBO_APPEND
= 144;
191 const int ID_COMBO_DELETE
= 145;
192 const int ID_COMBO_FONT
= 146;
193 const int ID_COMBO_ENABLE
= 147;
195 const int ID_TEXT
= 150;
196 const int ID_PASTE_TEXT
= 151;
197 const int ID_COPY_TEXT
= 152;
198 const int ID_MOVE_END_ENTRY
= 153;
199 const int ID_MOVE_END_ZONE
= 154;
201 const int ID_RADIOBOX
= 160;
202 const int ID_RADIOBOX_SEL_NUM
= 161;
203 const int ID_RADIOBOX_SEL_STR
= 162;
204 const int ID_RADIOBOX_FONT
= 163;
205 const int ID_RADIOBOX_ENABLE
= 164;
207 const int ID_RADIOBUTTON_1
= 166;
208 const int ID_RADIOBUTTON_2
= 167;
210 const int ID_SET_FONT
= 170;
212 const int ID_GAUGE
= 180;
213 const int ID_SLIDER
= 181;
215 const int ID_SPIN
= 182;
218 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
219 EVT_SIZE ( MyPanel::OnSize
)
220 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
221 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
222 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
223 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
224 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
225 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
226 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
227 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
228 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
229 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
230 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
231 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
232 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
233 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
234 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
235 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
236 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
237 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
238 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
239 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
240 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
241 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
242 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
243 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
244 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
245 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
246 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
247 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
248 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
249 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
250 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
251 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
252 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
253 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
254 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
255 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
256 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
257 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
260 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
261 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
263 // SetBackgroundColour("cadet blue");
265 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
266 // m_text->SetBackgroundColour("wheat");
268 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
283 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
286 // fill the image list
287 wxImageList
*imagelist
= new wxImageList(32, 32);
289 imagelist
-> Add( wxBitmap( list_xpm
));
290 imagelist
-> Add( wxBitmap( choice_xpm
));
291 imagelist
-> Add( wxBitmap( combo_xpm
));
292 imagelist
-> Add( wxBitmap( text_xpm
));
293 imagelist
-> Add( wxBitmap( radio_xpm
));
294 imagelist
-> Add( wxBitmap( gauge_xpm
));
295 m_notebook
->SetImageList(imagelist
);
296 #elif defined(__WXMSW__)
297 // load images from resources
300 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
302 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
304 static const char *s_iconNames
[Image_Max
] =
306 "list", "choice", "combo", "text", "radio", "gauge"
309 for ( size_t n
= 0; n
< Image_Max
; n
++ )
311 wxBitmap
bmp(s_iconNames
[n
]);
312 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
314 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
319 m_notebook
->SetImageList(imagelist
);
323 #define Image_List -1
324 #define Image_Choice -1
325 #define Image_Combo -1
326 #define Image_Text -1
327 #define Image_Radio -1
328 #define Image_Gauge -1
333 wxButton
*button
= (wxButton
*)NULL
;
335 // m_notebook->SetBackgroundColour("cadet blue");
337 wxPanel
*panel
= (wxPanel
*) NULL
;
339 panel
= new wxPanel(m_notebook
);
340 // panel->SetBackgroundColour("cadet blue");
341 // panel->SetForegroundColour("blue");
342 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
344 m_listbox
->SetToolTip( "This is a list box" );
346 // m_listbox->SetBackgroundColour("wheat");
347 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
348 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
349 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
350 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
351 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
352 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
354 button
->SetToolTip( "Press here to set italic font" );
357 // button->SetForegroundColour( "red" );
358 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
359 m_checkbox
->SetValue(FALSE
);
361 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
363 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
365 panel
= new wxPanel(m_notebook
);
366 // panel->SetBackgroundColour("cadet blue");
367 // panel->SetForegroundColour("blue");
368 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
369 // m_choice->SetBackgroundColour("wheat");
370 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
371 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
372 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
373 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
374 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
375 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
376 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
377 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
379 panel
= new wxPanel(m_notebook
);
380 // panel->SetBackgroundColour("cadet blue");
381 // panel->SetForegroundColour("blue");
382 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
383 // m_combo->SetBackgroundColour("wheat");
384 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
385 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
386 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
387 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
388 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
389 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
390 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
391 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
393 panel
= new wxPanel(m_notebook
);
394 // panel->SetBackgroundColour("cadet blue");
395 // panel->SetForegroundColour("blue");
396 m_textentry
= new wxTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
397 (*m_textentry
) << " More text.";
398 // m_textentry->SetBackgroundColour("wheat");
399 m_multitext
= new wxTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
400 (*m_multitext
) << " More text.";
401 // m_multitext->SetBackgroundColour("wheat");
402 (void)new wxStaticBox( panel
, -1, "Move cursor to the end of:",
403 wxPoint(345, 0), wxSize(160, 100) );
404 (void)new wxButton(panel
, ID_MOVE_END_ENTRY
, "Text entry",
405 wxPoint(370, 20), wxSize(110, 30));
406 (void)new wxButton(panel
, ID_MOVE_END_ZONE
, "Text zone",
407 wxPoint(370, 60), wxSize(110, 30));
408 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,120), wxSize(160,100) );
409 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,140), wxSize(110,30) );
410 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,180), wxSize(110,30) );
411 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
413 wxString choices2
[] =
419 panel
= new wxPanel(m_notebook
);
420 // panel->SetBackgroundColour("cadet blue");
421 // panel->SetForegroundColour("blue");
422 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
423 // m_radio->SetBackgroundColour("wheat");
424 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
425 // m_radio->SetBackgroundColour("wheat");
426 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
427 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
428 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
429 // m_fontButton->SetForegroundColour("blue");
430 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
431 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
432 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
433 rb
->SetValue( FALSE
);
434 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
435 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
437 panel
= new wxPanel(m_notebook
);
438 // panel->SetBackgroundColour("cadet blue");
439 // panel->SetForegroundColour("blue");
440 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
441 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
442 // m_gauge->SetBackgroundColour("wheat");
443 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
444 // m_slider->SetBackgroundColour("wheat");
445 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
447 // No wrapping text in wxStaticText yet :-(
448 (void)new wxStaticText( panel
, -1,
454 (void)new wxStaticText( panel
, -1,
455 "In order see the gauge (aka progress bar)\n"
456 "control do something you have to drag the\n"
457 "handle of the slider to the right.\n"
459 "This is also supposed to demonstrate how\n"
460 "to use static controls.\n",
465 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
466 // m_spintext->SetBackgroundColour("wheat");
467 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
468 // m_spinbutton->SetBackgroundColour("wheat");
469 m_spinbutton
->SetRange(0,100);
471 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
474 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
478 if (!wxTheClipboard
->Open())
480 *m_text
<< "Error opening the clipboard." << "\n";
486 *m_text
<< "Successfully opened the clipboard." << "\n";
489 wxTextDataObject
*data
= new wxTextDataObject();
491 if (wxTheClipboard
->GetData( data
))
493 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
494 *m_multitext
<< data
->GetText() << "\n";
498 *m_text
<< "Error getting data from the clipboard." << "\n";
501 wxTheClipboard
->Close();
503 *m_text
<< "Closed the clipboard." << "\n";
510 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
514 wxString
text( m_multitext
->GetLineText(0) );
516 if (text
.IsEmpty()) return;
518 if (!wxTheClipboard
->Open())
520 *m_text
<< "Error opening the clipboard." << "\n";
526 *m_text
<< "Successfully opened the clipboard." << "\n";
529 wxTextDataObject
*data
= new wxTextDataObject( text
);
530 wxDataBroker
*broker
= new wxDataBroker();
533 if (!wxTheClipboard
->SetData( broker
))
535 *m_text
<< "Error while copying to the clipboard." << "\n";
539 *m_text
<< "Successfully copied data to the clipboard." << "\n";
542 wxTheClipboard
->Close();
544 *m_text
<< "Closed the clipboard." << "\n";
549 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
551 m_multitext
->SetInsertionPointEnd();
552 m_multitext
->SetFocus();
555 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
557 m_textentry
->SetInsertionPointEnd();
558 m_textentry
->SetFocus();
561 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
565 GetClientSize( &x
, &y
);
567 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
568 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
571 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
573 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
576 void MyPanel::OnListBox( wxCommandEvent
&event
)
578 m_text
->WriteText( "ListBox selection string is: " );
579 m_text
->WriteText( event
.GetString() );
580 m_text
->WriteText( "\n" );
583 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
585 m_text
->WriteText( "ListBox double click string is: " );
586 m_text
->WriteText( event
.GetString() );
587 m_text
->WriteText( "\n" );
590 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
592 switch (event
.GetId())
594 case ID_LISTBOX_ENABLE
:
596 m_text
->WriteText("Checkbox clicked.\n");
597 m_listbox
->Enable( event
.GetInt() == 0 );
600 case ID_LISTBOX_SEL_NUM
:
602 m_listbox
->SetSelection( 2 );
605 case ID_LISTBOX_SEL_STR
:
607 m_listbox
->SetStringSelection( "This" );
610 case ID_LISTBOX_CLEAR
:
615 case ID_LISTBOX_APPEND
:
617 m_listbox
->Append( "Hi!" );
620 case ID_LISTBOX_DELETE
:
622 int idx
= m_listbox
->GetSelection();
623 m_listbox
->Delete( idx
);
626 case ID_LISTBOX_FONT
:
628 m_listbox
->SetFont( *wxITALIC_FONT
);
629 m_checkbox
->SetFont( *wxITALIC_FONT
);
635 void MyPanel::OnChoice( wxCommandEvent
&event
)
637 m_text
->WriteText( "Choice selection string is: " );
638 m_text
->WriteText( event
.GetString() );
639 m_text
->WriteText( "\n" );
642 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
644 switch (event
.GetId())
646 case ID_CHOICE_ENABLE
:
648 m_choice
->Enable( event
.GetInt() == 0 );
651 case ID_CHOICE_SEL_NUM
:
653 m_choice
->SetSelection( 2 );
656 case ID_CHOICE_SEL_STR
:
658 m_choice
->SetStringSelection( "This" );
661 case ID_CHOICE_CLEAR
:
666 case ID_CHOICE_APPEND
:
668 m_choice
->Append( "Hi!" );
671 case ID_CHOICE_DELETE
:
673 int idx
= m_choice
->GetSelection();
674 m_choice
->Delete( idx
);
679 m_choice
->SetFont( *wxITALIC_FONT
);
685 void MyPanel::OnCombo( wxCommandEvent
&event
)
687 m_text
->WriteText( "ComboBox selection string is: " );
688 m_text
->WriteText( event
.GetString() );
689 m_text
->WriteText( "\n" );
692 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
694 switch (event
.GetId())
696 case ID_COMBO_ENABLE
:
698 m_combo
->Enable( event
.GetInt() == 0 );
701 case ID_COMBO_SEL_NUM
:
703 m_combo
->SetSelection( 2 );
706 case ID_COMBO_SEL_STR
:
708 m_combo
->SetStringSelection( "This" );
716 case ID_COMBO_APPEND
:
718 m_combo
->Append( "Hi!" );
721 case ID_COMBO_DELETE
:
723 int idx
= m_combo
->GetSelection();
724 m_combo
->Delete( idx
);
729 m_combo
->SetFont( *wxITALIC_FONT
);
735 void MyPanel::OnRadio( wxCommandEvent
&event
)
737 m_text
->WriteText( "RadioBox selection string is: " );
738 m_text
->WriteText( event
.GetString() );
739 m_text
->WriteText( "\n" );
742 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
744 switch (event
.GetId())
746 case ID_RADIOBOX_ENABLE
:
748 m_radio
->Enable( event
.GetInt() == 0 );
751 case ID_RADIOBOX_SEL_NUM
:
753 m_radio
->SetSelection( 2 );
756 case ID_RADIOBOX_SEL_STR
:
758 m_radio
->SetStringSelection( "This" );
761 case ID_RADIOBOX_FONT
:
763 m_radio
->SetFont( *wxITALIC_FONT
);
769 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
771 m_fontButton
->SetFont( *wxITALIC_FONT
);
772 m_text
->SetFont( *wxITALIC_FONT
);
775 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
777 m_gauge
->SetValue( m_slider
->GetValue() );
780 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
783 value
.sprintf( "%d", (int)event
.GetPosition() );
784 m_spintext
->SetValue( value
);
789 delete m_notebook
->GetImageList();
792 //----------------------------------------------------------------------
794 //----------------------------------------------------------------------
796 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
797 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
798 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
801 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
802 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
804 (void)new MyPanel( this, 10, 10, 300, 100 );
807 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
812 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
814 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);