]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
12cc3c414ccbf24770d69aa92edf8b1e5d2ba79e
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"
31 #include "wx/tooltip.h"
33 #if defined(__WXGTK__) || defined(__WXMOTIF__)
38 #include "mondrian.xpm"
39 #include "icons/choice.xpm"
40 #include "icons/combo.xpm"
41 #include "icons/list.xpm"
42 #include "icons/radio.xpm"
43 #include "icons/text.xpm"
44 #include "icons/gauge.xpm"
47 //----------------------------------------------------------------------
49 //----------------------------------------------------------------------
51 class MyApp
: public wxApp
57 // a text ctrl which allows to call different wxTextCtrl functions
58 // interactively by pressing function keys in it
59 class MyTextCtrl
: public wxTextCtrl
62 MyTextCtrl(wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
63 const wxPoint
&pos
, const wxSize
&size
, int style
= 0)
64 : wxTextCtrl(parent
, id
, value
, pos
, size
, style
) { }
66 void OnKeyDown(wxKeyEvent
& event
);
72 class MyPanel
: public wxPanel
76 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
79 void OnSize( wxSizeEvent
& event
);
80 void OnListBox( wxCommandEvent
&event
);
81 void OnListBoxDoubleClick( wxCommandEvent
&event
);
82 void OnListBoxButtons( wxCommandEvent
&event
);
83 void OnChoice( wxCommandEvent
&event
);
84 void OnChoiceButtons( wxCommandEvent
&event
);
85 void OnCombo( wxCommandEvent
&event
);
86 void OnComboButtons( wxCommandEvent
&event
);
87 void OnRadio( wxCommandEvent
&event
);
88 void OnRadioButtons( wxCommandEvent
&event
);
89 void OnSetFont( wxCommandEvent
&event
);
90 void OnPageChanged( wxNotebookEvent
&event
);
91 void OnSliderUpdate( wxCommandEvent
&event
);
92 void OnSpinUpdate( wxSpinEvent
&event
);
93 void OnPasteFromClipboard( wxCommandEvent
&event
);
94 void OnCopyToClipboard( wxCommandEvent
&event
);
95 void OnMoveToEndOfText( wxCommandEvent
&event
);
96 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
104 wxButton
*m_fontButton
;
105 wxSpinButton
*m_spinbutton
;
106 wxTextCtrl
*m_spintext
;
107 MyTextCtrl
*m_multitext
;
108 MyTextCtrl
*m_textentry
;
109 wxCheckBox
*m_checkbox
;
112 wxNotebook
*m_notebook
;
114 DECLARE_EVENT_TABLE()
117 class MyFrame
: public wxFrame
121 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
125 void OnQuit(wxCommandEvent
& event
);
126 void OnAbout(wxCommandEvent
& event
);
127 void OnIdle( wxIdleEvent
& event
);
128 void OnSize( wxSizeEvent
& event
);
130 DECLARE_EVENT_TABLE()
133 //----------------------------------------------------------------------
135 //----------------------------------------------------------------------
139 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
143 const int MINIMAL_QUIT
= 100;
144 const int MINIMAL_TEXT
= 101;
145 const int MINIMAL_ABOUT
= 102;
147 bool MyApp::OnInit(void)
149 // Create the main frame window
150 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
151 "Controls wxWindows App",
155 // The wxICON() macros loads an icon from a resource under Windows
156 // and uses an #included XPM image under GTK+ and Motif
158 frame
->SetIcon( wxICON(mondrian
) );
160 wxMenu
*file_menu
= new wxMenu
;
162 file_menu
->Append(MINIMAL_ABOUT
, "&About");
163 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
164 wxMenuBar
*menu_bar
= new wxMenuBar
;
165 menu_bar
->Append(file_menu
, "&File");
166 frame
->SetMenuBar(menu_bar
);
175 //----------------------------------------------------------------------
177 //----------------------------------------------------------------------
179 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
180 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown
)
183 void MyTextCtrl::OnKeyDown(wxKeyEvent
& event
)
185 switch ( event
.KeyCode() )
188 // show current position and text length
190 long line
, column
, pos
= GetInsertionPoint();
191 PositionToXY(pos
, &column
, &line
);
193 wxLogMessage("Current position: %ld\n"
194 "Current line, column: (%ld, %ld)\n"
195 "Number of lines: %ld\n"
196 "Current line length: %ld\n"
197 "Total text length: %ld",
208 SetInsertionPointEnd();
213 SetInsertionPoint(10);
221 //----------------------------------------------------------------------
223 //----------------------------------------------------------------------
225 const int ID_NOTEBOOK
= 1000;
227 const int ID_LISTBOX
= 130;
228 const int ID_LISTBOX_SEL_NUM
= 131;
229 const int ID_LISTBOX_SEL_STR
= 132;
230 const int ID_LISTBOX_CLEAR
= 133;
231 const int ID_LISTBOX_APPEND
= 134;
232 const int ID_LISTBOX_DELETE
= 135;
233 const int ID_LISTBOX_FONT
= 136;
234 const int ID_LISTBOX_ENABLE
= 137;
236 const int ID_CHOICE
= 120;
237 const int ID_CHOICE_SEL_NUM
= 121;
238 const int ID_CHOICE_SEL_STR
= 122;
239 const int ID_CHOICE_CLEAR
= 123;
240 const int ID_CHOICE_APPEND
= 124;
241 const int ID_CHOICE_DELETE
= 125;
242 const int ID_CHOICE_FONT
= 126;
243 const int ID_CHOICE_ENABLE
= 127;
245 const int ID_COMBO
= 140;
246 const int ID_COMBO_SEL_NUM
= 141;
247 const int ID_COMBO_SEL_STR
= 142;
248 const int ID_COMBO_CLEAR
= 143;
249 const int ID_COMBO_APPEND
= 144;
250 const int ID_COMBO_DELETE
= 145;
251 const int ID_COMBO_FONT
= 146;
252 const int ID_COMBO_ENABLE
= 147;
254 const int ID_TEXT
= 150;
255 const int ID_PASTE_TEXT
= 151;
256 const int ID_COPY_TEXT
= 152;
257 const int ID_MOVE_END_ENTRY
= 153;
258 const int ID_MOVE_END_ZONE
= 154;
260 const int ID_RADIOBOX
= 160;
261 const int ID_RADIOBOX_SEL_NUM
= 161;
262 const int ID_RADIOBOX_SEL_STR
= 162;
263 const int ID_RADIOBOX_FONT
= 163;
264 const int ID_RADIOBOX_ENABLE
= 164;
266 const int ID_RADIOBUTTON_1
= 166;
267 const int ID_RADIOBUTTON_2
= 167;
269 const int ID_SET_FONT
= 170;
271 const int ID_GAUGE
= 180;
272 const int ID_SLIDER
= 181;
274 const int ID_SPIN
= 182;
276 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
277 EVT_SIZE ( MyPanel::OnSize
)
278 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
279 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
280 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
281 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
282 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
283 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
284 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
285 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
286 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
287 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
288 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
289 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
290 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
291 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
292 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
293 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
294 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
295 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
296 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
297 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
298 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
299 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
300 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
301 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
302 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
303 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
304 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
305 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
306 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
307 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
308 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
309 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
310 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
311 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
312 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
313 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
314 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
315 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
318 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
319 : m_notebook(NULL
), m_text(NULL
),
320 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
322 // SetBackgroundColour("cadet blue");
324 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
325 // m_text->SetBackgroundColour("wheat");
327 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
342 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
345 // fill the image list
346 wxImageList
*imagelist
= new wxImageList(32, 32);
348 imagelist
-> Add( wxBitmap( list_xpm
));
349 imagelist
-> Add( wxBitmap( choice_xpm
));
350 imagelist
-> Add( wxBitmap( combo_xpm
));
351 imagelist
-> Add( wxBitmap( text_xpm
));
352 imagelist
-> Add( wxBitmap( radio_xpm
));
353 imagelist
-> Add( wxBitmap( gauge_xpm
));
354 m_notebook
->SetImageList(imagelist
);
355 #elif defined(__WXMSW__)
356 // load images from resources
359 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
361 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
363 static const char *s_iconNames
[Image_Max
] =
365 "list", "choice", "combo", "text", "radio", "gauge"
368 for ( size_t n
= 0; n
< Image_Max
; n
++ )
370 wxBitmap
bmp(s_iconNames
[n
]);
371 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
373 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
378 m_notebook
->SetImageList(imagelist
);
382 #define Image_List -1
383 #define Image_Choice -1
384 #define Image_Combo -1
385 #define Image_Text -1
386 #define Image_Radio -1
387 #define Image_Gauge -1
392 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
393 wxPanel
*panel
= (wxPanel
*) NULL
;
395 panel
= new wxPanel(m_notebook
);
396 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
397 m_listbox
->SetToolTip( "This is a list box" );
399 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
400 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
401 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
402 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
403 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
404 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
405 button
->SetToolTip( "Press here to set italic font" );
407 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
408 m_checkbox
->SetValue(FALSE
);
409 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
410 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
412 panel
= new wxPanel(m_notebook
);
413 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
414 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
415 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
416 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
417 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
418 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
419 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
420 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
421 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
423 panel
= new wxPanel(m_notebook
);
424 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
425 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
426 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
427 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
428 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
429 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
430 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
431 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
432 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
434 panel
= new wxPanel(m_notebook
);
435 m_textentry
= new MyTextCtrl( panel
, -1, "Write text here.", wxPoint(10,10), wxSize(320,28),
437 (*m_textentry
) << " More text."; // this text is appended
438 m_textentry
->SetInsertionPoint(0);
439 m_textentry
->WriteText("Less text."); // this text is prepended
441 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,70),
443 (*m_multitext
) << " More text.\nPress function keys to test different \nwxTextCtrl functions.";
444 new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.",
445 wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
447 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
448 (void)new wxButton( panel
, ID_MOVE_END_ENTRY
, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
449 (void)new wxButton( panel
, ID_MOVE_END_ZONE
, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
450 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,110), wxSize(160,100) );
451 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(375,130), wxSize(110,30) );
452 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(375,170), wxSize(110,30) );
453 m_notebook
->AddPage( panel
, "wxTextCtrl" , FALSE
, Image_Text
);
455 wxString choices2
[] =
461 panel
= new wxPanel(m_notebook
);
462 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
463 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
464 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
465 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
466 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
467 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
468 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
469 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
470 rb
->SetValue( FALSE
);
471 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
472 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
474 panel
= new wxPanel(m_notebook
);
475 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
476 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
477 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
478 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
480 // No wrapping text in wxStaticText yet :-(
481 (void)new wxStaticText( panel
, -1,
487 (void)new wxStaticText( panel
, -1,
488 "In order see the gauge (aka progress bar)\n"
489 "control do something you have to drag the\n"
490 "handle of the slider to the right.\n"
492 "This is also supposed to demonstrate how\n"
493 "to use static controls.\n",
498 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
499 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
500 m_spinbutton
->SetRange(0,100);
501 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
504 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
508 if (!wxTheClipboard
->Open())
510 *m_text
<< "Error opening the clipboard." << "\n";
516 *m_text
<< "Successfully opened the clipboard." << "\n";
519 wxTextDataObject data
;
521 if (wxTheClipboard
->IsSupported( data
))
523 *m_text
<< "Clipboard supports requested format." << "\n";
525 if (wxTheClipboard
->GetData( data
))
527 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
528 *m_multitext
<< data
.GetText() << "\n";
532 *m_text
<< "Error getting data from the clipboard." << "\n";
537 *m_text
<< "Clipboard doesn't support requested format." << "\n";
540 wxTheClipboard
->Close();
542 *m_text
<< "Closed the clipboard." << "\n";
547 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
551 wxString
text( m_multitext
->GetLineText(0) );
553 if (text
.IsEmpty()) return;
555 if (!wxTheClipboard
->Open())
557 *m_text
<< "Error opening the clipboard." << "\n";
563 *m_text
<< "Successfully opened the clipboard." << "\n";
566 wxTextDataObject
*data
= new wxTextDataObject( text
);
568 if (!wxTheClipboard
->SetData( data
))
570 *m_text
<< "Error while copying to the clipboard." << "\n";
574 *m_text
<< "Successfully copied data to the clipboard." << "\n";
577 wxTheClipboard
->Close();
579 *m_text
<< "Closed the clipboard." << "\n";
584 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
586 m_multitext
->SetInsertionPointEnd();
587 m_multitext
->SetFocus();
590 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
592 m_textentry
->SetInsertionPointEnd();
593 m_textentry
->SetFocus();
596 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
600 GetClientSize( &x
, &y
);
602 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
603 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
606 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
608 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
611 void MyPanel::OnListBox( wxCommandEvent
&event
)
613 m_text
->AppendText( "ListBox selection string is: " );
614 m_text
->AppendText( event
.GetString() );
615 m_text
->AppendText( "\n" );
618 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
620 m_text
->AppendText( "ListBox double click string is: " );
621 m_text
->AppendText( event
.GetString() );
622 m_text
->AppendText( "\n" );
625 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
627 switch (event
.GetId())
629 case ID_LISTBOX_ENABLE
:
631 m_text
->AppendText("Checkbox clicked.\n");
632 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
634 cb
->SetToolTip( "Click to enable listbox" );
636 cb
->SetToolTip( "Click to disable listbox" );
637 m_listbox
->Enable( event
.GetInt() == 0 );
640 case ID_LISTBOX_SEL_NUM
:
642 m_listbox
->SetSelection( 2 );
645 case ID_LISTBOX_SEL_STR
:
647 m_listbox
->SetStringSelection( "This" );
650 case ID_LISTBOX_CLEAR
:
655 case ID_LISTBOX_APPEND
:
657 m_listbox
->Append( "Hi!" );
660 case ID_LISTBOX_DELETE
:
662 int idx
= m_listbox
->GetSelection();
663 m_listbox
->Delete( idx
);
666 case ID_LISTBOX_FONT
:
668 m_listbox
->SetFont( *wxITALIC_FONT
);
669 m_checkbox
->SetFont( *wxITALIC_FONT
);
675 void MyPanel::OnChoice( wxCommandEvent
&event
)
677 m_text
->AppendText( "Choice selection string is: " );
678 m_text
->AppendText( event
.GetString() );
679 m_text
->AppendText( "\n" );
682 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
684 switch (event
.GetId())
686 case ID_CHOICE_ENABLE
:
688 m_choice
->Enable( event
.GetInt() == 0 );
691 case ID_CHOICE_SEL_NUM
:
693 m_choice
->SetSelection( 2 );
696 case ID_CHOICE_SEL_STR
:
698 m_choice
->SetStringSelection( "This" );
701 case ID_CHOICE_CLEAR
:
706 case ID_CHOICE_APPEND
:
708 m_choice
->Append( "Hi!" );
711 case ID_CHOICE_DELETE
:
713 int idx
= m_choice
->GetSelection();
714 m_choice
->Delete( idx
);
719 m_choice
->SetFont( *wxITALIC_FONT
);
725 void MyPanel::OnCombo( wxCommandEvent
&event
)
727 m_text
->AppendText( "ComboBox selection string is: " );
728 m_text
->AppendText( event
.GetString() );
729 m_text
->AppendText( "\n" );
732 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
734 switch (event
.GetId())
736 case ID_COMBO_ENABLE
:
738 m_combo
->Enable( event
.GetInt() == 0 );
741 case ID_COMBO_SEL_NUM
:
743 m_combo
->SetSelection( 2 );
746 case ID_COMBO_SEL_STR
:
748 m_combo
->SetStringSelection( "This" );
756 case ID_COMBO_APPEND
:
758 m_combo
->Append( "Hi!" );
761 case ID_COMBO_DELETE
:
763 int idx
= m_combo
->GetSelection();
764 m_combo
->Delete( idx
);
769 m_combo
->SetFont( *wxITALIC_FONT
);
775 void MyPanel::OnRadio( wxCommandEvent
&event
)
777 m_text
->AppendText( "RadioBox selection string is: " );
778 m_text
->AppendText( event
.GetString() );
779 m_text
->AppendText( "\n" );
782 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
784 switch (event
.GetId())
786 case ID_RADIOBOX_ENABLE
:
788 m_radio
->Enable( event
.GetInt() == 0 );
791 case ID_RADIOBOX_SEL_NUM
:
793 m_radio
->SetSelection( 2 );
796 case ID_RADIOBOX_SEL_STR
:
798 m_radio
->SetStringSelection( "This" );
801 case ID_RADIOBOX_FONT
:
803 m_radio
->SetFont( *wxITALIC_FONT
);
809 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
811 m_fontButton
->SetFont( *wxITALIC_FONT
);
812 m_text
->SetFont( *wxITALIC_FONT
);
815 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
817 m_gauge
->SetValue( m_slider
->GetValue() );
820 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
823 value
.sprintf( "%d", (int)event
.GetPosition() );
824 m_spintext
->SetValue( value
);
829 delete m_notebook
->GetImageList();
832 //----------------------------------------------------------------------
834 //----------------------------------------------------------------------
836 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
837 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
838 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
839 EVT_SIZE(MyFrame::OnSize
)
840 EVT_IDLE(MyFrame::OnIdle
)
843 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
844 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
848 (void)new MyPanel( this, 10, 10, 300, 100 );
851 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
856 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
858 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
862 void MyFrame::OnSize( wxSizeEvent
& event
)
865 msg
.Printf("%dx%d", event
.GetSize().x
, event
.GetSize().y
);
866 SetStatusText(msg
, 1);
871 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
873 // track the window which has the focus in the status bar
874 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
875 wxWindow
*focus
= wxWindow::FindFocus();
876 if ( focus
&& (focus
!= s_windowFocus
) )
878 s_windowFocus
= focus
;
881 msg
.Printf("Focus: wxWindow = %p"
887 , s_windowFocus
->GetHWND()