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"
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
37 #include "wx/tooltip.h"
40 #if defined(__WXGTK__) || defined(__WXMOTIF__)
45 #include "mondrian.xpm"
46 #include "icons/choice.xpm"
47 #include "icons/combo.xpm"
48 #include "icons/list.xpm"
49 #include "icons/radio.xpm"
50 #include "icons/text.xpm"
51 #include "icons/gauge.xpm"
54 //----------------------------------------------------------------------
56 //----------------------------------------------------------------------
58 class MyApp
: public wxApp
64 // a text ctrl which allows to call different wxTextCtrl functions
65 // interactively by pressing function keys in it
66 class MyTextCtrl
: public wxTextCtrl
69 MyTextCtrl(wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
70 const wxPoint
&pos
, const wxSize
&size
, int style
= 0)
71 : wxTextCtrl(parent
, id
, value
, pos
, size
, style
) { }
73 void OnKeyDown(wxKeyEvent
& event
);
79 class MyPanel
: public wxPanel
82 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
85 void OnSize( wxSizeEvent
& event
);
86 void OnListBox( wxCommandEvent
&event
);
87 void OnListBoxDoubleClick( wxCommandEvent
&event
);
88 void OnListBoxButtons( wxCommandEvent
&event
);
89 void OnChoice( wxCommandEvent
&event
);
90 void OnChoiceButtons( wxCommandEvent
&event
);
91 void OnCombo( wxCommandEvent
&event
);
92 void OnComboButtons( wxCommandEvent
&event
);
93 void OnRadio( wxCommandEvent
&event
);
94 void OnRadioButtons( wxCommandEvent
&event
);
95 void OnSetFont( wxCommandEvent
&event
);
96 void OnPageChanged( wxNotebookEvent
&event
);
97 void OnSliderUpdate( wxCommandEvent
&event
);
98 void OnSpinUpdate( wxSpinEvent
&event
);
99 void OnPasteFromClipboard( wxCommandEvent
&event
);
100 void OnCopyToClipboard( wxCommandEvent
&event
);
101 void OnMoveToEndOfText( wxCommandEvent
&event
);
102 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
104 wxListBox
*m_listbox
;
110 wxButton
*m_fontButton
;
111 wxSpinButton
*m_spinbutton
;
112 wxTextCtrl
*m_spintext
;
113 MyTextCtrl
*m_multitext
;
114 MyTextCtrl
*m_textentry
;
115 wxCheckBox
*m_checkbox
;
118 wxNotebook
*m_notebook
;
121 DECLARE_EVENT_TABLE()
124 class MyFrame
: public wxFrame
127 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
129 void OnQuit(wxCommandEvent
& event
);
130 void OnAbout(wxCommandEvent
& event
);
132 void OnSetTooltipDelay(wxCommandEvent
& event
);
133 void OnToggleTooltips(wxCommandEvent
& event
);
134 #endif // wxUSE_TOOLTIPS
135 void OnIdle( wxIdleEvent
& event
);
136 void OnSize( wxSizeEvent
& event
);
139 DECLARE_EVENT_TABLE()
142 //----------------------------------------------------------------------
144 //----------------------------------------------------------------------
148 //----------------------------------------------------------------------
150 //----------------------------------------------------------------------
159 MINIMAL_SET_TOOLTIP_DELAY
= 200,
160 MINIMAL_ENABLE_TOOLTIPS
165 // Create the main frame window
166 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
167 "Controls wxWindows App",
171 // The wxICON() macros loads an icon from a resource under Windows
172 // and uses an #included XPM image under GTK+ and Motif
174 frame
->SetIcon( wxICON(mondrian
) );
176 wxMenu
*file_menu
= new wxMenu
;
177 file_menu
->Append(MINIMAL_ABOUT
, "&About");
178 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
180 wxMenuBar
*menu_bar
= new wxMenuBar
;
181 menu_bar
->Append(file_menu
, "&File");
184 wxMenu
*tooltip_menu
= new wxMenu
;
185 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay");
186 tooltip_menu
->AppendSeparator();
187 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips",
188 "enable/disable tooltips", TRUE
);
189 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
190 menu_bar
->Append(tooltip_menu
, "&Tooltips");
191 #endif // wxUSE_TOOLTIPS
193 frame
->SetMenuBar(menu_bar
);
202 //----------------------------------------------------------------------
204 //----------------------------------------------------------------------
206 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
207 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown
)
210 void MyTextCtrl::OnKeyDown(wxKeyEvent
& event
)
212 switch ( event
.KeyCode() )
215 // show current position and text length
217 long line
, column
, pos
= GetInsertionPoint();
218 PositionToXY(pos
, &column
, &line
);
220 wxLogMessage("Current position: %ld\n"
221 "Current line, column: (%ld, %ld)\n"
222 "Number of lines: %ld\n"
223 "Current line length: %ld\n"
224 "Total text length: %ld",
235 SetInsertionPointEnd();
240 SetInsertionPoint(10);
248 //----------------------------------------------------------------------
250 //----------------------------------------------------------------------
252 const int ID_NOTEBOOK
= 1000;
254 const int ID_LISTBOX
= 130;
255 const int ID_LISTBOX_SEL_NUM
= 131;
256 const int ID_LISTBOX_SEL_STR
= 132;
257 const int ID_LISTBOX_CLEAR
= 133;
258 const int ID_LISTBOX_APPEND
= 134;
259 const int ID_LISTBOX_DELETE
= 135;
260 const int ID_LISTBOX_FONT
= 136;
261 const int ID_LISTBOX_ENABLE
= 137;
263 const int ID_CHOICE
= 120;
264 const int ID_CHOICE_SEL_NUM
= 121;
265 const int ID_CHOICE_SEL_STR
= 122;
266 const int ID_CHOICE_CLEAR
= 123;
267 const int ID_CHOICE_APPEND
= 124;
268 const int ID_CHOICE_DELETE
= 125;
269 const int ID_CHOICE_FONT
= 126;
270 const int ID_CHOICE_ENABLE
= 127;
272 const int ID_COMBO
= 140;
273 const int ID_COMBO_SEL_NUM
= 141;
274 const int ID_COMBO_SEL_STR
= 142;
275 const int ID_COMBO_CLEAR
= 143;
276 const int ID_COMBO_APPEND
= 144;
277 const int ID_COMBO_DELETE
= 145;
278 const int ID_COMBO_FONT
= 146;
279 const int ID_COMBO_ENABLE
= 147;
281 const int ID_TEXT
= 150;
282 const int ID_PASTE_TEXT
= 151;
283 const int ID_COPY_TEXT
= 152;
284 const int ID_MOVE_END_ENTRY
= 153;
285 const int ID_MOVE_END_ZONE
= 154;
287 const int ID_RADIOBOX
= 160;
288 const int ID_RADIOBOX_SEL_NUM
= 161;
289 const int ID_RADIOBOX_SEL_STR
= 162;
290 const int ID_RADIOBOX_FONT
= 163;
291 const int ID_RADIOBOX_ENABLE
= 164;
293 const int ID_RADIOBUTTON_1
= 166;
294 const int ID_RADIOBUTTON_2
= 167;
296 const int ID_SET_FONT
= 170;
298 const int ID_GAUGE
= 180;
299 const int ID_SLIDER
= 181;
301 const int ID_SPIN
= 182;
303 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
304 EVT_SIZE ( MyPanel::OnSize
)
305 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
306 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
307 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
308 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
309 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
310 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
311 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
312 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
313 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
314 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
315 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
316 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
317 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
318 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
319 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
320 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
321 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
322 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
323 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
324 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
325 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
326 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
327 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
328 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
329 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
330 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
331 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
332 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
333 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
334 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
335 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
336 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
337 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
338 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
339 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
340 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
341 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
342 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
345 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
346 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
347 m_text(NULL
), m_notebook(NULL
)
349 // SetBackgroundColour("cadet blue");
351 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
352 // m_text->SetBackgroundColour("wheat");
354 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
369 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
372 // fill the image list
373 wxImageList
*imagelist
= new wxImageList(32, 32);
375 imagelist
-> Add( wxBitmap( list_xpm
));
376 imagelist
-> Add( wxBitmap( choice_xpm
));
377 imagelist
-> Add( wxBitmap( combo_xpm
));
378 imagelist
-> Add( wxBitmap( text_xpm
));
379 imagelist
-> Add( wxBitmap( radio_xpm
));
380 imagelist
-> Add( wxBitmap( gauge_xpm
));
381 m_notebook
->SetImageList(imagelist
);
382 #elif defined(__WXMSW__)
383 // load images from resources
386 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
388 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
390 static const char *s_iconNames
[Image_Max
] =
392 "list", "choice", "combo", "text", "radio", "gauge"
395 for ( size_t n
= 0; n
< Image_Max
; n
++ )
397 wxBitmap
bmp(s_iconNames
[n
]);
398 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
400 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
405 m_notebook
->SetImageList(imagelist
);
409 #define Image_List -1
410 #define Image_Choice -1
411 #define Image_Combo -1
412 #define Image_Text -1
413 #define Image_Radio -1
414 #define Image_Gauge -1
419 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
420 wxPanel
*panel
= (wxPanel
*) NULL
;
422 panel
= new wxPanel(m_notebook
);
423 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
424 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
426 m_listbox
->SetToolTip( "This is a list box" );
427 #endif // wxUSE_TOOLTIPS
429 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
430 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
431 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
432 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
433 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
434 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
436 button
->SetToolTip( "Press here to set italic font" );
437 #endif // wxUSE_TOOLTIPS
439 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
440 m_checkbox
->SetValue(FALSE
);
442 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
443 #endif // wxUSE_TOOLTIPS
444 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
446 panel
= new wxPanel(m_notebook
);
447 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
448 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
449 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
450 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
451 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
452 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
453 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
454 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
455 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
457 panel
= new wxPanel(m_notebook
);
458 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
459 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
460 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
461 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
462 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
463 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
464 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
465 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
466 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
468 panel
= new wxPanel(m_notebook
);
469 m_textentry
= new MyTextCtrl( panel
, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0);
471 (*m_textentry
) << " Appended.";
472 m_textentry
->SetInsertionPoint(0);
473 m_textentry
->WriteText( "Prepended. " );
475 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE
);
476 (*m_multitext
) << " Appended.";
477 m_multitext
->SetInsertionPoint(0);
478 m_multitext
->WriteText( "Prepended. " );
479 m_multitext
->AppendText( "\nPress function keys to test different wxTextCtrl functions." );
481 (*m_multitext
) << "\nDoes it have cross cursor?";
482 m_multitext
->SetCursor(*wxCROSS_CURSOR
);
484 new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
486 m_multitext
->AppendText( "\nThis ctrl has a tooltip. " );
487 m_multitext
->SetToolTip("Press F1 here.");
488 #endif // wxUSE_TOOLTIPS
490 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
491 (void)new wxButton( panel
, ID_MOVE_END_ENTRY
, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
492 (void)new wxButton( panel
, ID_MOVE_END_ZONE
, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
493 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) );
494 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(370,120), wxSize(110,30) );
495 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(370,160), wxSize(110,30) );
496 m_notebook
->AddPage( panel
, "wxTextCtrl" , FALSE
, Image_Text
);
498 wxString choices2
[] =
504 panel
= new wxPanel(m_notebook
);
505 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2
, 1, wxRA_SPECIFY_ROWS
);
506 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices
, 1, wxRA_SPECIFY_COLS
);
507 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
508 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
509 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
510 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
511 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
512 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
513 rb
->SetValue( FALSE
);
514 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
515 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
517 panel
= new wxPanel(m_notebook
);
518 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
519 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
520 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
521 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
523 // No wrapping text in wxStaticText yet :-(
524 (void)new wxStaticText( panel
, -1,
530 (void)new wxStaticText( panel
, -1,
531 "In order see the gauge (aka progress bar)\n"
532 "control do something you have to drag the\n"
533 "handle of the slider to the right.\n"
535 "This is also supposed to demonstrate how\n"
536 "to use static controls.\n",
541 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
542 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
543 m_spinbutton
->SetRange(0,100);
544 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
547 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
549 // We test for wxUSE_DRAG_AND_DROP also, because data objects
550 // may not be implemented for compilers that can't cope with the OLE
551 // parts in wxUSE_DRAG_AND_DROP.
553 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
554 if (!wxTheClipboard
->Open())
556 *m_text
<< "Error opening the clipboard.\n";
562 *m_text
<< "Successfully opened the clipboard.\n";
565 wxTextDataObject data
;
567 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
569 *m_text
<< "Clipboard supports requested format.\n";
571 if (wxTheClipboard
->GetData( &data
))
573 *m_text
<< "Successfully retrieved data from the clipboard.\n";
574 *m_multitext
<< data
.GetText() << "\n";
578 *m_text
<< "Error getting data from the clipboard.\n";
583 *m_text
<< "Clipboard doesn't support requested format.\n";
586 wxTheClipboard
->Close();
588 *m_text
<< "Closed the clipboard.\n";
590 wxLogError("Your version of wxWindows is compiled without clipboard support.");
594 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
596 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
597 wxString
text( m_multitext
->GetLineText(0) );
601 *m_text
<< "No text to copy.\n";
606 if (!wxTheClipboard
->Open())
608 *m_text
<< "Error opening the clipboard.\n";
614 *m_text
<< "Successfully opened the clipboard.\n";
617 wxTextDataObject
*data
= new wxTextDataObject( text
);
619 if (!wxTheClipboard
->SetData( data
))
621 *m_text
<< "Error while copying to the clipboard.\n";
625 *m_text
<< "Successfully copied data to the clipboard.\n";
628 wxTheClipboard
->Close();
630 *m_text
<< "Closed the clipboard.\n";
632 wxLogError("Your version of wxWindows is compiled without clipboard support.");
636 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
638 m_multitext
->SetInsertionPointEnd();
639 m_multitext
->SetFocus();
642 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
644 m_textentry
->SetInsertionPointEnd();
645 m_textentry
->SetFocus();
648 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
652 GetClientSize( &x
, &y
);
654 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
655 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
658 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
660 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
663 void MyPanel::OnListBox( wxCommandEvent
&event
)
665 m_text
->AppendText( "ListBox selection string is: " );
666 m_text
->AppendText( event
.GetString() );
667 m_text
->AppendText( "\n" );
670 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
672 m_text
->AppendText( "ListBox double click string is: " );
673 m_text
->AppendText( event
.GetString() );
674 m_text
->AppendText( "\n" );
677 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
679 switch (event
.GetId())
681 case ID_LISTBOX_ENABLE
:
683 m_text
->AppendText("Checkbox clicked.\n");
684 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
687 cb
->SetToolTip( "Click to enable listbox" );
689 cb
->SetToolTip( "Click to disable listbox" );
690 #endif // wxUSE_TOOLTIPS
691 m_listbox
->Enable( event
.GetInt() == 0 );
694 case ID_LISTBOX_SEL_NUM
:
696 m_listbox
->SetSelection( 2 );
699 case ID_LISTBOX_SEL_STR
:
701 m_listbox
->SetStringSelection( "This" );
704 case ID_LISTBOX_CLEAR
:
709 case ID_LISTBOX_APPEND
:
711 m_listbox
->Append( "Hi!" );
714 case ID_LISTBOX_DELETE
:
716 int idx
= m_listbox
->GetSelection();
717 m_listbox
->Delete( idx
);
720 case ID_LISTBOX_FONT
:
722 m_listbox
->SetFont( *wxITALIC_FONT
);
723 m_checkbox
->SetFont( *wxITALIC_FONT
);
729 void MyPanel::OnChoice( wxCommandEvent
&event
)
731 m_text
->AppendText( "Choice selection string is: " );
732 m_text
->AppendText( event
.GetString() );
733 m_text
->AppendText( "\n" );
736 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
738 switch (event
.GetId())
740 case ID_CHOICE_ENABLE
:
742 m_choice
->Enable( event
.GetInt() == 0 );
745 case ID_CHOICE_SEL_NUM
:
747 m_choice
->SetSelection( 2 );
750 case ID_CHOICE_SEL_STR
:
752 m_choice
->SetStringSelection( "This" );
755 case ID_CHOICE_CLEAR
:
760 case ID_CHOICE_APPEND
:
762 m_choice
->Append( "Hi!" );
765 case ID_CHOICE_DELETE
:
767 int idx
= m_choice
->GetSelection();
768 m_choice
->Delete( idx
);
773 m_choice
->SetFont( *wxITALIC_FONT
);
779 void MyPanel::OnCombo( wxCommandEvent
&event
)
781 m_text
->AppendText( "ComboBox selection string is: " );
782 m_text
->AppendText( event
.GetString() );
783 m_text
->AppendText( "\n" );
786 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
788 switch (event
.GetId())
790 case ID_COMBO_ENABLE
:
792 m_combo
->Enable( event
.GetInt() == 0 );
795 case ID_COMBO_SEL_NUM
:
797 m_combo
->SetSelection( 2 );
800 case ID_COMBO_SEL_STR
:
802 m_combo
->SetStringSelection( "This" );
810 case ID_COMBO_APPEND
:
812 m_combo
->Append( "Hi!" );
815 case ID_COMBO_DELETE
:
817 int idx
= m_combo
->GetSelection();
818 m_combo
->Delete( idx
);
823 m_combo
->SetFont( *wxITALIC_FONT
);
829 void MyPanel::OnRadio( wxCommandEvent
&event
)
831 m_text
->AppendText( "RadioBox selection string is: " );
832 m_text
->AppendText( event
.GetString() );
833 m_text
->AppendText( "\n" );
836 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
838 switch (event
.GetId())
840 case ID_RADIOBOX_ENABLE
:
842 m_radio
->Enable( event
.GetInt() == 0 );
845 case ID_RADIOBOX_SEL_NUM
:
847 m_radio
->SetSelection( 2 );
850 case ID_RADIOBOX_SEL_STR
:
852 m_radio
->SetStringSelection( "This" );
855 case ID_RADIOBOX_FONT
:
857 m_radio
->SetFont( *wxITALIC_FONT
);
863 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
865 m_fontButton
->SetFont( *wxITALIC_FONT
);
866 m_text
->SetFont( *wxITALIC_FONT
);
869 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
871 m_gauge
->SetValue( m_slider
->GetValue() );
874 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
877 value
.sprintf( "%d", (int)event
.GetPosition() );
878 m_spintext
->SetValue( value
);
883 delete m_notebook
->GetImageList();
886 //----------------------------------------------------------------------
888 //----------------------------------------------------------------------
890 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
891 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
892 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
894 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
895 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
896 #endif // wxUSE_TOOLTIPS
897 EVT_SIZE(MyFrame::OnSize
)
898 EVT_IDLE(MyFrame::OnIdle
)
901 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
902 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
906 (void)new MyPanel( this, 10, 10, 300, 100 );
909 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
914 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
918 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
925 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
927 static long s_delay
= 5000;
930 delay
.Printf("%ld", s_delay
);
932 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
939 sscanf(delay
, "%ld", &s_delay
);
941 wxToolTip::SetDelay(s_delay
);
943 wxLogStatus(this, "Tooltip delay set to %ld milliseconds", s_delay
);
946 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
948 static bool s_enabled
= TRUE
;
950 s_enabled
= !s_enabled
;
952 wxToolTip::Enable(s_enabled
);
954 wxLogStatus(this, "Tooltips %sabled", s_enabled
? "en" : "dis");
958 void MyFrame::OnSize( wxSizeEvent
& event
)
961 msg
.Printf("%dx%d", event
.GetSize().x
, event
.GetSize().y
);
962 SetStatusText(msg
, 1);
967 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
969 // track the window which has the focus in the status bar
970 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
971 wxWindow
*focus
= wxWindow::FindFocus();
972 if ( focus
&& (focus
!= s_windowFocus
) )
974 s_windowFocus
= focus
;
977 msg
.Printf("Focus: wxWindow = %p"
983 , s_windowFocus
->GetHWND()