]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
a7965e72da7a3b0379f5bd80b39a32c0fcb06a63
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 OnChar(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
);
129 DECLARE_EVENT_TABLE()
132 //----------------------------------------------------------------------
134 //----------------------------------------------------------------------
138 //----------------------------------------------------------------------
140 //----------------------------------------------------------------------
142 const int MINIMAL_QUIT
= 100;
143 const int MINIMAL_TEXT
= 101;
144 const int MINIMAL_ABOUT
= 102;
146 bool MyApp::OnInit(void)
148 // Create the main frame window
149 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
150 "Controls wxWindows App",
154 // The wxICON() macros loads an icon from a resource under Windows
155 // and uses an #included XPM image under GTK+ and Motif
157 frame
->SetIcon( wxICON(mondrian
) );
159 wxMenu
*file_menu
= new wxMenu
;
161 file_menu
->Append(MINIMAL_ABOUT
, "&About");
162 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
163 wxMenuBar
*menu_bar
= new wxMenuBar
;
164 menu_bar
->Append(file_menu
, "&File");
165 frame
->SetMenuBar(menu_bar
);
174 //----------------------------------------------------------------------
176 //----------------------------------------------------------------------
178 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
179 EVT_CHAR(MyTextCtrl::OnChar
)
182 void MyTextCtrl::OnChar(wxKeyEvent
& event
)
184 switch ( event
.KeyCode() )
187 // show current position and text length
189 long line
, column
, pos
= GetInsertionPoint();
190 PositionToXY(pos
, &column
, &line
);
192 wxLogMessage("Current position: %ld\n"
193 "Current line, column: (%ld, %ld)\n"
194 "Number of lines: %ld\n"
195 "Current line length: %ld\n"
196 "Total text length: %ld",
207 SetInsertionPointEnd();
212 SetInsertionPoint(10);
220 //----------------------------------------------------------------------
222 //----------------------------------------------------------------------
224 const int ID_NOTEBOOK
= 1000;
226 const int ID_LISTBOX
= 130;
227 const int ID_LISTBOX_SEL_NUM
= 131;
228 const int ID_LISTBOX_SEL_STR
= 132;
229 const int ID_LISTBOX_CLEAR
= 133;
230 const int ID_LISTBOX_APPEND
= 134;
231 const int ID_LISTBOX_DELETE
= 135;
232 const int ID_LISTBOX_FONT
= 136;
233 const int ID_LISTBOX_ENABLE
= 137;
235 const int ID_CHOICE
= 120;
236 const int ID_CHOICE_SEL_NUM
= 121;
237 const int ID_CHOICE_SEL_STR
= 122;
238 const int ID_CHOICE_CLEAR
= 123;
239 const int ID_CHOICE_APPEND
= 124;
240 const int ID_CHOICE_DELETE
= 125;
241 const int ID_CHOICE_FONT
= 126;
242 const int ID_CHOICE_ENABLE
= 127;
244 const int ID_COMBO
= 140;
245 const int ID_COMBO_SEL_NUM
= 141;
246 const int ID_COMBO_SEL_STR
= 142;
247 const int ID_COMBO_CLEAR
= 143;
248 const int ID_COMBO_APPEND
= 144;
249 const int ID_COMBO_DELETE
= 145;
250 const int ID_COMBO_FONT
= 146;
251 const int ID_COMBO_ENABLE
= 147;
253 const int ID_TEXT
= 150;
254 const int ID_PASTE_TEXT
= 151;
255 const int ID_COPY_TEXT
= 152;
256 const int ID_MOVE_END_ENTRY
= 153;
257 const int ID_MOVE_END_ZONE
= 154;
259 const int ID_RADIOBOX
= 160;
260 const int ID_RADIOBOX_SEL_NUM
= 161;
261 const int ID_RADIOBOX_SEL_STR
= 162;
262 const int ID_RADIOBOX_FONT
= 163;
263 const int ID_RADIOBOX_ENABLE
= 164;
265 const int ID_RADIOBUTTON_1
= 166;
266 const int ID_RADIOBUTTON_2
= 167;
268 const int ID_SET_FONT
= 170;
270 const int ID_GAUGE
= 180;
271 const int ID_SLIDER
= 181;
273 const int ID_SPIN
= 182;
275 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
276 EVT_SIZE ( MyPanel::OnSize
)
277 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
278 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
279 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
280 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
281 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
282 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
283 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
284 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
285 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
286 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
287 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
288 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
289 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
290 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
291 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
292 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
293 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
294 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
295 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
296 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
297 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
298 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
299 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
300 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
301 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
302 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
303 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
304 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
305 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
306 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
307 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
308 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
309 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
310 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
311 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
312 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
313 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
314 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
317 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
318 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
320 // SetBackgroundColour("cadet blue");
322 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
323 // m_text->SetBackgroundColour("wheat");
325 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
340 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
343 // fill the image list
344 wxImageList
*imagelist
= new wxImageList(32, 32);
346 imagelist
-> Add( wxBitmap( list_xpm
));
347 imagelist
-> Add( wxBitmap( choice_xpm
));
348 imagelist
-> Add( wxBitmap( combo_xpm
));
349 imagelist
-> Add( wxBitmap( text_xpm
));
350 imagelist
-> Add( wxBitmap( radio_xpm
));
351 imagelist
-> Add( wxBitmap( gauge_xpm
));
352 m_notebook
->SetImageList(imagelist
);
353 #elif defined(__WXMSW__)
354 // load images from resources
357 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
359 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
361 static const char *s_iconNames
[Image_Max
] =
363 "list", "choice", "combo", "text", "radio", "gauge"
366 for ( size_t n
= 0; n
< Image_Max
; n
++ )
368 wxBitmap
bmp(s_iconNames
[n
]);
369 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
371 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
376 m_notebook
->SetImageList(imagelist
);
380 #define Image_List -1
381 #define Image_Choice -1
382 #define Image_Combo -1
383 #define Image_Text -1
384 #define Image_Radio -1
385 #define Image_Gauge -1
390 wxButton
*button
= (wxButton
*)NULL
;
392 // m_notebook->SetBackgroundColour("cadet blue");
394 wxPanel
*panel
= (wxPanel
*) NULL
;
396 panel
= new wxPanel(m_notebook
);
397 // panel->SetBackgroundColour("cadet blue");
398 // panel->SetForegroundColour("blue");
399 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
400 m_listbox
->SetToolTip( "This is a list box" );
402 // m_listbox->SetBackgroundColour("wheat");
403 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
404 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
405 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
406 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
407 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
408 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
409 button
->SetToolTip( "Press here to set italic font" );
411 // button->SetForegroundColour( "red" );
412 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
413 m_checkbox
->SetValue(FALSE
);
414 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
415 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
417 panel
= new wxPanel(m_notebook
);
418 // panel->SetBackgroundColour("cadet blue");
419 // panel->SetForegroundColour("blue");
420 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
421 // m_choice->SetBackgroundColour("wheat");
422 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
423 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
424 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
425 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
426 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
427 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
428 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
429 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
431 panel
= new wxPanel(m_notebook
);
432 // panel->SetBackgroundColour("cadet blue");
433 // panel->SetForegroundColour("blue");
434 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
435 // m_combo->SetBackgroundColour("wheat");
436 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
437 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
438 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
439 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
440 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
441 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
442 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
443 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
445 panel
= new wxPanel(m_notebook
);
446 // panel->SetBackgroundColour("cadet blue");
447 // panel->SetForegroundColour("blue");
448 m_textentry
= new MyTextCtrl( panel
, -1, "Write text here.",
449 wxPoint(10,10), wxSize(320,28),
451 (*m_textentry
) << " More text.";
452 // m_textentry->SetBackgroundColour("wheat");
453 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "And here.",
454 wxPoint(10,50), wxSize(320,80),
456 (*m_multitext
) << " More text."
457 << "\nPress Fn keys to test different wxTextCtrl functions";
458 // m_multitext->SetBackgroundColour("wheat");
459 (void)new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.",
460 wxPoint(10,140), wxSize(320,80), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
462 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:",
463 wxPoint(345, 0), wxSize(160, 100) );
464 (void)new wxButton(panel
, ID_MOVE_END_ENTRY
, "Text &entry",
465 wxPoint(370, 20), wxSize(110, 30));
466 (void)new wxButton(panel
, ID_MOVE_END_ZONE
, "Text &zone",
467 wxPoint(370, 60), wxSize(110, 30));
468 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,120), wxSize(160,100) );
469 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(370,140), wxSize(110,30) );
470 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(370,180), wxSize(110,30) );
471 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
473 wxString choices2
[] =
479 panel
= new wxPanel(m_notebook
);
480 // panel->SetBackgroundColour("cadet blue");
481 // panel->SetForegroundColour("blue");
482 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
483 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 2, wxRA_SPECIFY_COLS
);
484 // m_radio->SetBackgroundColour("wheat");
485 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
486 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
487 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
488 // m_fontButton->SetForegroundColour("blue");
489 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
490 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
491 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
492 rb
->SetValue( FALSE
);
493 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
494 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
496 panel
= new wxPanel(m_notebook
);
497 // panel->SetBackgroundColour("cadet blue");
498 // panel->SetForegroundColour("blue");
499 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
500 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
501 // m_gauge->SetBackgroundColour("wheat");
502 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
503 // m_slider->SetBackgroundColour("wheat");
504 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
506 // No wrapping text in wxStaticText yet :-(
507 (void)new wxStaticText( panel
, -1,
513 (void)new wxStaticText( panel
, -1,
514 "In order see the gauge (aka progress bar)\n"
515 "control do something you have to drag the\n"
516 "handle of the slider to the right.\n"
518 "This is also supposed to demonstrate how\n"
519 "to use static controls.\n",
524 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
525 // m_spintext->SetBackgroundColour("wheat");
526 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
527 // m_spinbutton->SetBackgroundColour("wheat");
528 m_spinbutton
->SetRange(0,100);
530 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
533 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
537 if (!wxTheClipboard
->Open())
539 *m_text
<< "Error opening the clipboard." << "\n";
545 *m_text
<< "Successfully opened the clipboard." << "\n";
548 wxTextDataObject data
;
550 if (wxTheClipboard
->IsSupported( data
))
552 *m_text
<< "Clipboard supports requested format." << "\n";
554 if (wxTheClipboard
->GetData( data
))
556 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
557 *m_multitext
<< data
.GetText() << "\n";
561 *m_text
<< "Error getting data from the clipboard." << "\n";
566 *m_text
<< "Clipboard doesn't support requested format." << "\n";
569 wxTheClipboard
->Close();
571 *m_text
<< "Closed the clipboard." << "\n";
576 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
580 wxString
text( m_multitext
->GetLineText(0) );
582 if (text
.IsEmpty()) return;
584 if (!wxTheClipboard
->Open())
586 *m_text
<< "Error opening the clipboard." << "\n";
592 *m_text
<< "Successfully opened the clipboard." << "\n";
595 wxTextDataObject
*data
= new wxTextDataObject( text
);
597 if (!wxTheClipboard
->SetData( data
))
599 *m_text
<< "Error while copying to the clipboard." << "\n";
603 *m_text
<< "Successfully copied data to the clipboard." << "\n";
606 wxTheClipboard
->Close();
608 *m_text
<< "Closed the clipboard." << "\n";
613 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
615 m_multitext
->SetInsertionPointEnd();
616 m_multitext
->SetFocus();
619 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
621 m_textentry
->SetInsertionPointEnd();
622 m_textentry
->SetFocus();
625 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
629 GetClientSize( &x
, &y
);
631 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
632 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
635 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
637 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
640 void MyPanel::OnListBox( wxCommandEvent
&event
)
642 m_text
->WriteText( "ListBox selection string is: " );
643 m_text
->WriteText( event
.GetString() );
644 m_text
->WriteText( "\n" );
647 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
649 m_text
->WriteText( "ListBox double click string is: " );
650 m_text
->WriteText( event
.GetString() );
651 m_text
->WriteText( "\n" );
654 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
656 switch (event
.GetId())
658 case ID_LISTBOX_ENABLE
:
660 m_text
->WriteText("Checkbox clicked.\n");
661 m_listbox
->Enable( event
.GetInt() == 0 );
664 case ID_LISTBOX_SEL_NUM
:
666 m_listbox
->SetSelection( 2 );
669 case ID_LISTBOX_SEL_STR
:
671 m_listbox
->SetStringSelection( "This" );
674 case ID_LISTBOX_CLEAR
:
679 case ID_LISTBOX_APPEND
:
681 m_listbox
->Append( "Hi!" );
684 case ID_LISTBOX_DELETE
:
686 int idx
= m_listbox
->GetSelection();
687 m_listbox
->Delete( idx
);
690 case ID_LISTBOX_FONT
:
692 m_listbox
->SetFont( *wxITALIC_FONT
);
693 m_checkbox
->SetFont( *wxITALIC_FONT
);
699 void MyPanel::OnChoice( wxCommandEvent
&event
)
701 m_text
->WriteText( "Choice selection string is: " );
702 m_text
->WriteText( event
.GetString() );
703 m_text
->WriteText( "\n" );
706 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
708 switch (event
.GetId())
710 case ID_CHOICE_ENABLE
:
712 m_choice
->Enable( event
.GetInt() == 0 );
715 case ID_CHOICE_SEL_NUM
:
717 m_choice
->SetSelection( 2 );
720 case ID_CHOICE_SEL_STR
:
722 m_choice
->SetStringSelection( "This" );
725 case ID_CHOICE_CLEAR
:
730 case ID_CHOICE_APPEND
:
732 m_choice
->Append( "Hi!" );
735 case ID_CHOICE_DELETE
:
737 int idx
= m_choice
->GetSelection();
738 m_choice
->Delete( idx
);
743 m_choice
->SetFont( *wxITALIC_FONT
);
749 void MyPanel::OnCombo( wxCommandEvent
&event
)
751 m_text
->WriteText( "ComboBox selection string is: " );
752 m_text
->WriteText( event
.GetString() );
753 m_text
->WriteText( "\n" );
756 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
758 switch (event
.GetId())
760 case ID_COMBO_ENABLE
:
762 m_combo
->Enable( event
.GetInt() == 0 );
765 case ID_COMBO_SEL_NUM
:
767 m_combo
->SetSelection( 2 );
770 case ID_COMBO_SEL_STR
:
772 m_combo
->SetStringSelection( "This" );
780 case ID_COMBO_APPEND
:
782 m_combo
->Append( "Hi!" );
785 case ID_COMBO_DELETE
:
787 int idx
= m_combo
->GetSelection();
788 m_combo
->Delete( idx
);
793 m_combo
->SetFont( *wxITALIC_FONT
);
799 void MyPanel::OnRadio( wxCommandEvent
&event
)
801 m_text
->WriteText( "RadioBox selection string is: " );
802 m_text
->WriteText( event
.GetString() );
803 m_text
->WriteText( "\n" );
806 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
808 switch (event
.GetId())
810 case ID_RADIOBOX_ENABLE
:
812 m_radio
->Enable( event
.GetInt() == 0 );
815 case ID_RADIOBOX_SEL_NUM
:
817 m_radio
->SetSelection( 2 );
820 case ID_RADIOBOX_SEL_STR
:
822 m_radio
->SetStringSelection( "This" );
825 case ID_RADIOBOX_FONT
:
827 m_radio
->SetFont( *wxITALIC_FONT
);
833 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
835 m_fontButton
->SetFont( *wxITALIC_FONT
);
836 m_text
->SetFont( *wxITALIC_FONT
);
839 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
841 m_gauge
->SetValue( m_slider
->GetValue() );
844 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
847 value
.sprintf( "%d", (int)event
.GetPosition() );
848 m_spintext
->SetValue( value
);
853 delete m_notebook
->GetImageList();
856 //----------------------------------------------------------------------
858 //----------------------------------------------------------------------
860 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
861 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
862 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
863 EVT_IDLE(MyFrame::OnIdle
)
866 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
867 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
871 (void)new MyPanel( this, 10, 10, 300, 100 );
874 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
879 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
881 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
885 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
887 // track the window which has the focus in the status bar
888 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
889 wxWindow
*focus
= wxWindow::FindFocus();
890 if ( focus
&& (focus
!= s_windowFocus
) )
892 s_windowFocus
= focus
;
895 msg
.Printf("Focus: wxWindow = %p"
901 , s_windowFocus
->GetHWND()