]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
88f1d757fa350cfe746e9027f9c9fe8e6ef350b4
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 // a text ctrl which allows to call different wxTextCtrl functions
61 // interactively by pressing function keys in it
62 class MyTextCtrl
: public wxTextCtrl
65 MyTextCtrl(wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
66 const wxPoint
&pos
, const wxSize
&size
, int style
= 0)
67 : wxTextCtrl(parent
, id
, value
, pos
, size
, style
) { }
69 void OnChar(wxKeyEvent
& event
);
75 class MyPanel
: public wxPanel
79 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
82 void OnSize( wxSizeEvent
& event
);
83 void OnListBox( wxCommandEvent
&event
);
84 void OnListBoxDoubleClick( wxCommandEvent
&event
);
85 void OnListBoxButtons( wxCommandEvent
&event
);
86 void OnChoice( wxCommandEvent
&event
);
87 void OnChoiceButtons( wxCommandEvent
&event
);
88 void OnCombo( wxCommandEvent
&event
);
89 void OnComboButtons( wxCommandEvent
&event
);
90 void OnRadio( wxCommandEvent
&event
);
91 void OnRadioButtons( wxCommandEvent
&event
);
92 void OnSetFont( wxCommandEvent
&event
);
93 void OnPageChanged( wxNotebookEvent
&event
);
94 void OnSliderUpdate( wxCommandEvent
&event
);
95 void OnSpinUpdate( wxSpinEvent
&event
);
96 void OnPasteFromClipboard( wxCommandEvent
&event
);
97 void OnCopyToClipboard( wxCommandEvent
&event
);
98 void OnMoveToEndOfText( wxCommandEvent
&event
);
99 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
101 wxListBox
*m_listbox
;
107 wxButton
*m_fontButton
;
108 wxSpinButton
*m_spinbutton
;
109 wxTextCtrl
*m_spintext
;
110 MyTextCtrl
*m_multitext
;
111 MyTextCtrl
*m_textentry
;
112 wxCheckBox
*m_checkbox
;
115 wxNotebook
*m_notebook
;
117 DECLARE_EVENT_TABLE()
120 class MyFrame
: public wxFrame
124 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
128 void OnQuit(wxCommandEvent
& event
);
129 void OnAbout(wxCommandEvent
& event
);
130 bool OnClose(void) { return TRUE
; }
132 DECLARE_EVENT_TABLE()
135 //----------------------------------------------------------------------
137 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
143 //----------------------------------------------------------------------
145 const int MINIMAL_QUIT
= 100;
146 const int MINIMAL_TEXT
= 101;
147 const int MINIMAL_ABOUT
= 102;
149 bool MyApp::OnInit(void)
151 // Create the main frame window
152 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
153 "Controls wxWindows App",
157 // The wxICON() macros loads an icon from a resource under Windows
158 // and uses an #included XPM image under GTK+ and Motif
160 frame
->SetIcon( wxICON(mondrian
) );
162 wxMenu
*file_menu
= new wxMenu
;
164 file_menu
->Append(MINIMAL_ABOUT
, "&About");
165 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
166 wxMenuBar
*menu_bar
= new wxMenuBar
;
167 menu_bar
->Append(file_menu
, "&File");
168 frame
->SetMenuBar(menu_bar
);
177 //----------------------------------------------------------------------
179 //----------------------------------------------------------------------
181 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
182 EVT_CHAR(MyTextCtrl::OnChar
)
185 void MyTextCtrl::OnChar(wxKeyEvent
& event
)
187 switch ( event
.KeyCode() )
190 // show current position and text length
192 long line
, column
, pos
= GetInsertionPoint();
193 PositionToXY(pos
, &column
, &line
);
195 wxLogMessage("Current position: %ld\n"
196 "Current line, column: (%ld, %ld)\n"
197 "Number of lines: %ld\n"
198 "Current line length: %ld\n"
199 "Total text length: %ld",
210 SetInsertionPointEnd();
215 SetInsertionPoint(10);
223 //----------------------------------------------------------------------
225 //----------------------------------------------------------------------
227 const int ID_NOTEBOOK
= 1000;
229 const int ID_LISTBOX
= 130;
230 const int ID_LISTBOX_SEL_NUM
= 131;
231 const int ID_LISTBOX_SEL_STR
= 132;
232 const int ID_LISTBOX_CLEAR
= 133;
233 const int ID_LISTBOX_APPEND
= 134;
234 const int ID_LISTBOX_DELETE
= 135;
235 const int ID_LISTBOX_FONT
= 136;
236 const int ID_LISTBOX_ENABLE
= 137;
238 const int ID_CHOICE
= 120;
239 const int ID_CHOICE_SEL_NUM
= 121;
240 const int ID_CHOICE_SEL_STR
= 122;
241 const int ID_CHOICE_CLEAR
= 123;
242 const int ID_CHOICE_APPEND
= 124;
243 const int ID_CHOICE_DELETE
= 125;
244 const int ID_CHOICE_FONT
= 126;
245 const int ID_CHOICE_ENABLE
= 127;
247 const int ID_COMBO
= 140;
248 const int ID_COMBO_SEL_NUM
= 141;
249 const int ID_COMBO_SEL_STR
= 142;
250 const int ID_COMBO_CLEAR
= 143;
251 const int ID_COMBO_APPEND
= 144;
252 const int ID_COMBO_DELETE
= 145;
253 const int ID_COMBO_FONT
= 146;
254 const int ID_COMBO_ENABLE
= 147;
256 const int ID_TEXT
= 150;
257 const int ID_PASTE_TEXT
= 151;
258 const int ID_COPY_TEXT
= 152;
259 const int ID_MOVE_END_ENTRY
= 153;
260 const int ID_MOVE_END_ZONE
= 154;
262 const int ID_RADIOBOX
= 160;
263 const int ID_RADIOBOX_SEL_NUM
= 161;
264 const int ID_RADIOBOX_SEL_STR
= 162;
265 const int ID_RADIOBOX_FONT
= 163;
266 const int ID_RADIOBOX_ENABLE
= 164;
268 const int ID_RADIOBUTTON_1
= 166;
269 const int ID_RADIOBUTTON_2
= 167;
271 const int ID_SET_FONT
= 170;
273 const int ID_GAUGE
= 180;
274 const int ID_SLIDER
= 181;
276 const int ID_SPIN
= 182;
278 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
279 EVT_SIZE ( MyPanel::OnSize
)
280 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
281 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
282 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
283 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
284 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
285 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
286 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
287 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
288 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
289 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
290 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
291 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
292 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
293 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
294 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
295 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
296 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
297 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
298 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
299 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
300 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
301 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
302 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
303 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
304 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
305 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
306 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
307 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
308 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
309 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
310 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
311 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
312 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
313 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
314 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
315 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
316 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
317 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
320 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
321 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
323 // SetBackgroundColour("cadet blue");
325 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
326 // m_text->SetBackgroundColour("wheat");
328 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
343 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
346 // fill the image list
347 wxImageList
*imagelist
= new wxImageList(32, 32);
349 imagelist
-> Add( wxBitmap( list_xpm
));
350 imagelist
-> Add( wxBitmap( choice_xpm
));
351 imagelist
-> Add( wxBitmap( combo_xpm
));
352 imagelist
-> Add( wxBitmap( text_xpm
));
353 imagelist
-> Add( wxBitmap( radio_xpm
));
354 imagelist
-> Add( wxBitmap( gauge_xpm
));
355 m_notebook
->SetImageList(imagelist
);
356 #elif defined(__WXMSW__)
357 // load images from resources
360 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
362 wxImageList
*imagelist
= new wxImageList(32, 32, FALSE
, Image_Max
);
364 static const char *s_iconNames
[Image_Max
] =
366 "list", "choice", "combo", "text", "radio", "gauge"
369 for ( size_t n
= 0; n
< Image_Max
; n
++ )
371 wxBitmap
bmp(s_iconNames
[n
]);
372 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
374 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
379 m_notebook
->SetImageList(imagelist
);
383 #define Image_List -1
384 #define Image_Choice -1
385 #define Image_Combo -1
386 #define Image_Text -1
387 #define Image_Radio -1
388 #define Image_Gauge -1
393 wxButton
*button
= (wxButton
*)NULL
;
395 // m_notebook->SetBackgroundColour("cadet blue");
397 wxPanel
*panel
= (wxPanel
*) NULL
;
399 panel
= new wxPanel(m_notebook
);
400 // panel->SetBackgroundColour("cadet blue");
401 // panel->SetForegroundColour("blue");
402 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
404 m_listbox
->SetToolTip( "This is a list box" );
406 // m_listbox->SetBackgroundColour("wheat");
407 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
408 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
409 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
410 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
411 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
412 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
414 button
->SetToolTip( "Press here to set italic font" );
417 // button->SetForegroundColour( "red" );
418 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
419 m_checkbox
->SetValue(FALSE
);
421 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
423 m_notebook
->AddPage(panel
, "wxList", TRUE
, Image_List
);
425 panel
= new wxPanel(m_notebook
);
426 // panel->SetBackgroundColour("cadet blue");
427 // panel->SetForegroundColour("blue");
428 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
429 // m_choice->SetBackgroundColour("wheat");
430 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
431 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
432 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
433 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
434 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
435 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
436 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
437 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
439 panel
= new wxPanel(m_notebook
);
440 // panel->SetBackgroundColour("cadet blue");
441 // panel->SetForegroundColour("blue");
442 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
443 // m_combo->SetBackgroundColour("wheat");
444 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
445 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
446 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
447 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
448 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
449 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
450 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
451 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
453 panel
= new wxPanel(m_notebook
);
454 // panel->SetBackgroundColour("cadet blue");
455 // panel->SetForegroundColour("blue");
456 m_textentry
= new MyTextCtrl( panel
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(320,28));
457 (*m_textentry
) << " More text.";
458 // m_textentry->SetBackgroundColour("wheat");
459 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE
);
460 (*m_multitext
) << " More text."
461 << "\nPress Fn keys to test different wxTextCtrl functions";
462 // m_multitext->SetBackgroundColour("wheat");
463 (void)new wxStaticBox( panel
, -1, "Move cursor to the end of:",
464 wxPoint(345, 0), wxSize(160, 100) );
465 (void)new wxButton(panel
, ID_MOVE_END_ENTRY
, "Text entry",
466 wxPoint(370, 20), wxSize(110, 30));
467 (void)new wxButton(panel
, ID_MOVE_END_ZONE
, "Text zone",
468 wxPoint(370, 60), wxSize(110, 30));
469 (void)new wxStaticBox( panel
, -1, "wxClipboard", wxPoint(345,120), wxSize(160,100) );
470 (void)new wxButton( panel
, ID_COPY_TEXT
, "Copy line 1", wxPoint(370,140), wxSize(110,30) );
471 (void)new wxButton( panel
, ID_PASTE_TEXT
, "Paste text", wxPoint(370,180), wxSize(110,30) );
472 m_notebook
->AddPage(panel
, "wxTextCtrl" , FALSE
, Image_Text
);
474 wxString choices2
[] =
480 panel
= new wxPanel(m_notebook
);
481 // panel->SetBackgroundColour("cadet blue");
482 // panel->SetForegroundColour("blue");
483 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
484 // m_radio->SetBackgroundColour("wheat");
485 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
486 // m_radio->SetBackgroundColour("wheat");
487 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
488 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
489 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
490 // m_fontButton->SetForegroundColour("blue");
491 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
492 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
493 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
494 rb
->SetValue( FALSE
);
495 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
496 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
498 panel
= new wxPanel(m_notebook
);
499 // panel->SetBackgroundColour("cadet blue");
500 // panel->SetForegroundColour("blue");
501 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
502 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
503 // m_gauge->SetBackgroundColour("wheat");
504 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
505 // m_slider->SetBackgroundColour("wheat");
506 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
508 // No wrapping text in wxStaticText yet :-(
509 (void)new wxStaticText( panel
, -1,
515 (void)new wxStaticText( panel
, -1,
516 "In order see the gauge (aka progress bar)\n"
517 "control do something you have to drag the\n"
518 "handle of the slider to the right.\n"
520 "This is also supposed to demonstrate how\n"
521 "to use static controls.\n",
526 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
527 // m_spintext->SetBackgroundColour("wheat");
528 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
529 // m_spinbutton->SetBackgroundColour("wheat");
530 m_spinbutton
->SetRange(0,100);
532 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
535 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
539 if (!wxTheClipboard
->Open())
541 *m_text
<< "Error opening the clipboard." << "\n";
547 *m_text
<< "Successfully opened the clipboard." << "\n";
550 wxTextDataObject
*data
= new wxTextDataObject();
552 if (wxTheClipboard
->GetData( data
))
554 *m_text
<< "Successfully retrieved data from the clipboard." << "\n";
555 *m_multitext
<< data
->GetText() << "\n";
559 *m_text
<< "Error getting data from the clipboard." << "\n";
562 wxTheClipboard
->Close();
564 *m_text
<< "Closed the clipboard." << "\n";
571 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
575 wxString
text( m_multitext
->GetLineText(0) );
577 if (text
.IsEmpty()) return;
579 if (!wxTheClipboard
->Open())
581 *m_text
<< "Error opening the clipboard." << "\n";
587 *m_text
<< "Successfully opened the clipboard." << "\n";
590 wxTextDataObject
*data
= new wxTextDataObject( text
);
591 wxDataBroker
*broker
= new wxDataBroker();
594 if (!wxTheClipboard
->SetData( broker
))
596 *m_text
<< "Error while copying to the clipboard." << "\n";
600 *m_text
<< "Successfully copied data to the clipboard." << "\n";
603 wxTheClipboard
->Close();
605 *m_text
<< "Closed the clipboard." << "\n";
610 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
612 m_multitext
->SetInsertionPointEnd();
613 m_multitext
->SetFocus();
616 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
618 m_textentry
->SetInsertionPointEnd();
619 m_textentry
->SetFocus();
622 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
626 GetClientSize( &x
, &y
);
628 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
629 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
632 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
634 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
637 void MyPanel::OnListBox( wxCommandEvent
&event
)
639 m_text
->WriteText( "ListBox selection string is: " );
640 m_text
->WriteText( event
.GetString() );
641 m_text
->WriteText( "\n" );
644 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
646 m_text
->WriteText( "ListBox double click string is: " );
647 m_text
->WriteText( event
.GetString() );
648 m_text
->WriteText( "\n" );
651 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
653 switch (event
.GetId())
655 case ID_LISTBOX_ENABLE
:
657 m_text
->WriteText("Checkbox clicked.\n");
658 m_listbox
->Enable( event
.GetInt() == 0 );
661 case ID_LISTBOX_SEL_NUM
:
663 m_listbox
->SetSelection( 2 );
666 case ID_LISTBOX_SEL_STR
:
668 m_listbox
->SetStringSelection( "This" );
671 case ID_LISTBOX_CLEAR
:
676 case ID_LISTBOX_APPEND
:
678 m_listbox
->Append( "Hi!" );
681 case ID_LISTBOX_DELETE
:
683 int idx
= m_listbox
->GetSelection();
684 m_listbox
->Delete( idx
);
687 case ID_LISTBOX_FONT
:
689 m_listbox
->SetFont( *wxITALIC_FONT
);
690 m_checkbox
->SetFont( *wxITALIC_FONT
);
696 void MyPanel::OnChoice( wxCommandEvent
&event
)
698 m_text
->WriteText( "Choice selection string is: " );
699 m_text
->WriteText( event
.GetString() );
700 m_text
->WriteText( "\n" );
703 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
705 switch (event
.GetId())
707 case ID_CHOICE_ENABLE
:
709 m_choice
->Enable( event
.GetInt() == 0 );
712 case ID_CHOICE_SEL_NUM
:
714 m_choice
->SetSelection( 2 );
717 case ID_CHOICE_SEL_STR
:
719 m_choice
->SetStringSelection( "This" );
722 case ID_CHOICE_CLEAR
:
727 case ID_CHOICE_APPEND
:
729 m_choice
->Append( "Hi!" );
732 case ID_CHOICE_DELETE
:
734 int idx
= m_choice
->GetSelection();
735 m_choice
->Delete( idx
);
740 m_choice
->SetFont( *wxITALIC_FONT
);
746 void MyPanel::OnCombo( wxCommandEvent
&event
)
748 m_text
->WriteText( "ComboBox selection string is: " );
749 m_text
->WriteText( event
.GetString() );
750 m_text
->WriteText( "\n" );
753 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
755 switch (event
.GetId())
757 case ID_COMBO_ENABLE
:
759 m_combo
->Enable( event
.GetInt() == 0 );
762 case ID_COMBO_SEL_NUM
:
764 m_combo
->SetSelection( 2 );
767 case ID_COMBO_SEL_STR
:
769 m_combo
->SetStringSelection( "This" );
777 case ID_COMBO_APPEND
:
779 m_combo
->Append( "Hi!" );
782 case ID_COMBO_DELETE
:
784 int idx
= m_combo
->GetSelection();
785 m_combo
->Delete( idx
);
790 m_combo
->SetFont( *wxITALIC_FONT
);
796 void MyPanel::OnRadio( wxCommandEvent
&event
)
798 m_text
->WriteText( "RadioBox selection string is: " );
799 m_text
->WriteText( event
.GetString() );
800 m_text
->WriteText( "\n" );
803 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
805 switch (event
.GetId())
807 case ID_RADIOBOX_ENABLE
:
809 m_radio
->Enable( event
.GetInt() == 0 );
812 case ID_RADIOBOX_SEL_NUM
:
814 m_radio
->SetSelection( 2 );
817 case ID_RADIOBOX_SEL_STR
:
819 m_radio
->SetStringSelection( "This" );
822 case ID_RADIOBOX_FONT
:
824 m_radio
->SetFont( *wxITALIC_FONT
);
830 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
832 m_fontButton
->SetFont( *wxITALIC_FONT
);
833 m_text
->SetFont( *wxITALIC_FONT
);
836 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
838 m_gauge
->SetValue( m_slider
->GetValue() );
841 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
844 value
.sprintf( "%d", (int)event
.GetPosition() );
845 m_spintext
->SetValue( value
);
850 delete m_notebook
->GetImageList();
853 //----------------------------------------------------------------------
855 //----------------------------------------------------------------------
857 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
858 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
859 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
862 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
863 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
865 (void)new MyPanel( this, 10, 10, 300, 100 );
868 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
873 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
875 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);