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
);
99 void OnSpinUpdate( wxSpinEvent
&event
);
101 void OnPasteFromClipboard( wxCommandEvent
&event
);
102 void OnCopyToClipboard( wxCommandEvent
&event
);
103 void OnMoveToEndOfText( wxCommandEvent
&event
);
104 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
106 wxListBox
*m_listbox
;
112 wxButton
*m_fontButton
;
114 wxSpinButton
*m_spinbutton
;
116 wxTextCtrl
*m_spintext
;
117 MyTextCtrl
*m_multitext
;
118 MyTextCtrl
*m_textentry
;
119 wxCheckBox
*m_checkbox
;
122 wxNotebook
*m_notebook
;
125 DECLARE_EVENT_TABLE()
128 class MyFrame
: public wxFrame
131 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
133 void OnQuit(wxCommandEvent
& event
);
134 void OnAbout(wxCommandEvent
& event
);
136 void OnSetTooltipDelay(wxCommandEvent
& event
);
137 void OnToggleTooltips(wxCommandEvent
& event
);
138 #endif // wxUSE_TOOLTIPS
139 void OnIdle( wxIdleEvent
& event
);
140 void OnSize( wxSizeEvent
& event
);
143 DECLARE_EVENT_TABLE()
146 //----------------------------------------------------------------------
148 //----------------------------------------------------------------------
152 //----------------------------------------------------------------------
154 //----------------------------------------------------------------------
163 MINIMAL_SET_TOOLTIP_DELAY
= 200,
164 MINIMAL_ENABLE_TOOLTIPS
169 // Create the main frame window
170 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
171 "Controls wxWindows App",
175 // The wxICON() macros loads an icon from a resource under Windows
176 // and uses an #included XPM image under GTK+ and Motif
178 frame
->SetIcon( wxICON(mondrian
) );
180 wxMenu
*file_menu
= new wxMenu
;
181 file_menu
->Append(MINIMAL_ABOUT
, "&About");
182 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
184 wxMenuBar
*menu_bar
= new wxMenuBar
;
185 menu_bar
->Append(file_menu
, "&File");
188 wxMenu
*tooltip_menu
= new wxMenu
;
189 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay");
190 tooltip_menu
->AppendSeparator();
191 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips",
192 "enable/disable tooltips", TRUE
);
193 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
194 menu_bar
->Append(tooltip_menu
, "&Tooltips");
195 #endif // wxUSE_TOOLTIPS
197 frame
->SetMenuBar(menu_bar
);
200 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
207 //----------------------------------------------------------------------
209 //----------------------------------------------------------------------
211 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
212 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown
)
215 void MyTextCtrl::OnKeyDown(wxKeyEvent
& event
)
217 switch ( event
.KeyCode() )
220 // show current position and text length
222 long line
, column
, pos
= GetInsertionPoint();
223 PositionToXY(pos
, &column
, &line
);
225 wxLogMessage("Current position: %ld\n"
226 "Current line, column: (%ld, %ld)\n"
227 "Number of lines: %ld\n"
228 "Current line length: %ld\n"
229 "Total text length: %ld",
240 SetInsertionPointEnd();
245 SetInsertionPoint(10);
253 //----------------------------------------------------------------------
255 //----------------------------------------------------------------------
257 const int ID_NOTEBOOK
= 1000;
259 const int ID_LISTBOX
= 130;
260 const int ID_LISTBOX_SEL_NUM
= 131;
261 const int ID_LISTBOX_SEL_STR
= 132;
262 const int ID_LISTBOX_CLEAR
= 133;
263 const int ID_LISTBOX_APPEND
= 134;
264 const int ID_LISTBOX_DELETE
= 135;
265 const int ID_LISTBOX_FONT
= 136;
266 const int ID_LISTBOX_ENABLE
= 137;
268 const int ID_CHOICE
= 120;
269 const int ID_CHOICE_SEL_NUM
= 121;
270 const int ID_CHOICE_SEL_STR
= 122;
271 const int ID_CHOICE_CLEAR
= 123;
272 const int ID_CHOICE_APPEND
= 124;
273 const int ID_CHOICE_DELETE
= 125;
274 const int ID_CHOICE_FONT
= 126;
275 const int ID_CHOICE_ENABLE
= 127;
277 const int ID_COMBO
= 140;
278 const int ID_COMBO_SEL_NUM
= 141;
279 const int ID_COMBO_SEL_STR
= 142;
280 const int ID_COMBO_CLEAR
= 143;
281 const int ID_COMBO_APPEND
= 144;
282 const int ID_COMBO_DELETE
= 145;
283 const int ID_COMBO_FONT
= 146;
284 const int ID_COMBO_ENABLE
= 147;
286 const int ID_TEXT
= 150;
287 const int ID_PASTE_TEXT
= 151;
288 const int ID_COPY_TEXT
= 152;
289 const int ID_MOVE_END_ENTRY
= 153;
290 const int ID_MOVE_END_ZONE
= 154;
292 const int ID_RADIOBOX
= 160;
293 const int ID_RADIOBOX_SEL_NUM
= 161;
294 const int ID_RADIOBOX_SEL_STR
= 162;
295 const int ID_RADIOBOX_FONT
= 163;
296 const int ID_RADIOBOX_ENABLE
= 164;
298 const int ID_RADIOBUTTON_1
= 166;
299 const int ID_RADIOBUTTON_2
= 167;
301 const int ID_SET_FONT
= 170;
303 const int ID_GAUGE
= 180;
304 const int ID_SLIDER
= 181;
306 const int ID_SPIN
= 182;
308 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
309 EVT_SIZE ( MyPanel::OnSize
)
310 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
311 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
312 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
313 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
314 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
315 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
316 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
317 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
318 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
319 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
320 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
321 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
322 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
323 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
324 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
325 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
326 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
327 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
328 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
329 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
330 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
331 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
332 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
333 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
334 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
335 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
336 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
337 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
338 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
339 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
340 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
341 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
342 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
344 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
346 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
347 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
348 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
349 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
352 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
353 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
354 m_text(NULL
), m_notebook(NULL
)
356 // SetBackgroundColour("cadet blue");
358 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
359 // m_text->SetBackgroundColour("wheat");
361 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
376 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
379 // fill the image list
380 wxImageList
*imagelist
= new wxImageList(32, 32);
382 imagelist
-> Add( wxBitmap( list_xpm
));
383 imagelist
-> Add( wxBitmap( choice_xpm
));
384 imagelist
-> Add( wxBitmap( combo_xpm
));
385 imagelist
-> Add( wxBitmap( text_xpm
));
386 imagelist
-> Add( wxBitmap( radio_xpm
));
387 imagelist
-> Add( wxBitmap( gauge_xpm
));
388 m_notebook
->SetImageList(imagelist
);
389 #elif defined(__WXMSW__)
390 // load images from resources
393 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
395 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
397 static const char *s_iconNames
[Image_Max
] =
399 "list", "choice", "combo", "text", "radio", "gauge"
402 for ( size_t n
= 0; n
< Image_Max
; n
++ )
404 wxBitmap
bmp(s_iconNames
[n
]);
405 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
407 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
412 m_notebook
->SetImageList(imagelist
);
416 #define Image_List -1
417 #define Image_Choice -1
418 #define Image_Combo -1
419 #define Image_Text -1
420 #define Image_Radio -1
421 #define Image_Gauge -1
426 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
427 wxPanel
*panel
= (wxPanel
*) NULL
;
429 panel
= new wxPanel(m_notebook
);
430 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
);
431 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
433 m_listbox
->SetToolTip( "This is a list box" );
434 #endif // wxUSE_TOOLTIPS
436 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
437 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
438 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
439 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
440 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
441 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
443 button
->SetToolTip( "Press here to set italic font" );
444 #endif // wxUSE_TOOLTIPS
446 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
447 m_checkbox
->SetValue(FALSE
);
449 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
450 #endif // wxUSE_TOOLTIPS
451 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
453 panel
= new wxPanel(m_notebook
);
454 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
455 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
456 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
457 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
458 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
459 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
460 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
461 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
462 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
464 panel
= new wxPanel(m_notebook
);
465 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
466 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
467 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
468 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
469 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
470 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
471 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
472 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
473 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
475 panel
= new wxPanel(m_notebook
);
476 m_textentry
= new MyTextCtrl( panel
, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0);
478 (*m_textentry
) << " Appended.";
479 m_textentry
->SetInsertionPoint(0);
480 m_textentry
->WriteText( "Prepended. " );
482 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE
);
483 (*m_multitext
) << " Appended.";
484 m_multitext
->SetInsertionPoint(0);
485 m_multitext
->WriteText( "Prepended. " );
486 m_multitext
->AppendText( "\nPress function keys to test different wxTextCtrl functions." );
488 (*m_multitext
) << "\nDoes it have cross cursor?";
489 m_multitext
->SetCursor(*wxCROSS_CURSOR
);
491 new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
493 m_multitext
->AppendText( "\nThis ctrl has a tooltip. " );
494 m_multitext
->SetToolTip("Press F1 here.");
495 #endif // wxUSE_TOOLTIPS
497 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
498 (void)new wxButton( panel
, ID_MOVE_END_ENTRY
, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
499 (void)new wxButton( panel
, ID_MOVE_END_ZONE
, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
500 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) );
501 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(370,120), wxSize(110,30) );
502 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(370,160), wxSize(110,30) );
503 m_notebook
->AddPage( panel
, "wxTextCtrl" , FALSE
, Image_Text
);
505 wxString choices2
[] =
509 "Fourth", "Fifth", "Sixth",
510 "Seventh", "Eighth", "Nineth", "Tenth" */
513 panel
= new wxPanel(m_notebook
);
514 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
515 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
516 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
517 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
518 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
519 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
520 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
521 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
522 rb
->SetValue( FALSE
);
523 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
524 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
526 panel
= new wxPanel(m_notebook
);
527 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
528 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
529 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
530 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
532 // No wrapping text in wxStaticText yet :-(
533 (void)new wxStaticText( panel
, -1,
539 (void)new wxStaticText( panel
, -1,
540 "In order see the gauge (aka progress bar)\n"
541 "control do something you have to drag the\n"
542 "handle of the slider to the right.\n"
544 "This is also supposed to demonstrate how\n"
545 "to use static controls.\n",
550 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
552 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
553 m_spinbutton
->SetRange(-10,30);
554 m_spinbutton
->SetValue(-5);
556 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
559 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
561 // We test for wxUSE_DRAG_AND_DROP also, because data objects
562 // may not be implemented for compilers that can't cope with the OLE
563 // parts in wxUSE_DRAG_AND_DROP.
565 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
566 if (!wxTheClipboard
->Open())
568 *m_text
<< "Error opening the clipboard.\n";
574 *m_text
<< "Successfully opened the clipboard.\n";
577 wxTextDataObject data
;
579 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
581 *m_text
<< "Clipboard supports requested format.\n";
583 if (wxTheClipboard
->GetData( &data
))
585 *m_text
<< "Successfully retrieved data from the clipboard.\n";
586 *m_multitext
<< data
.GetText() << "\n";
590 *m_text
<< "Error getting data from the clipboard.\n";
595 *m_text
<< "Clipboard doesn't support requested format.\n";
598 wxTheClipboard
->Close();
600 *m_text
<< "Closed the clipboard.\n";
602 wxLogError("Your version of wxWindows is compiled without clipboard support.");
606 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
608 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
609 wxString
text( m_multitext
->GetLineText(0) );
613 *m_text
<< "No text to copy.\n";
618 if (!wxTheClipboard
->Open())
620 *m_text
<< "Error opening the clipboard.\n";
626 *m_text
<< "Successfully opened the clipboard.\n";
629 wxTextDataObject
*data
= new wxTextDataObject( text
);
631 if (!wxTheClipboard
->SetData( data
))
633 *m_text
<< "Error while copying to the clipboard.\n";
637 *m_text
<< "Successfully copied data to the clipboard.\n";
640 wxTheClipboard
->Close();
642 *m_text
<< "Closed the clipboard.\n";
644 wxLogError("Your version of wxWindows is compiled without clipboard support.");
648 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
650 m_multitext
->SetInsertionPointEnd();
651 m_multitext
->SetFocus();
654 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
656 m_textentry
->SetInsertionPointEnd();
657 m_textentry
->SetFocus();
660 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
664 GetClientSize( &x
, &y
);
666 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
667 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
670 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
672 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
675 void MyPanel::OnListBox( wxCommandEvent
&event
)
677 m_text
->AppendText( "ListBox selection string is: " );
678 m_text
->AppendText( event
.GetString() );
679 m_text
->AppendText( "\n" );
682 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
684 m_text
->AppendText( "ListBox double click string is: " );
685 m_text
->AppendText( event
.GetString() );
686 m_text
->AppendText( "\n" );
689 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
691 switch (event
.GetId())
693 case ID_LISTBOX_ENABLE
:
695 m_text
->AppendText("Checkbox clicked.\n");
696 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
699 cb
->SetToolTip( "Click to enable listbox" );
701 cb
->SetToolTip( "Click to disable listbox" );
702 #endif // wxUSE_TOOLTIPS
703 m_listbox
->Enable( event
.GetInt() == 0 );
706 case ID_LISTBOX_SEL_NUM
:
708 m_listbox
->SetSelection( 2 );
711 case ID_LISTBOX_SEL_STR
:
713 m_listbox
->SetStringSelection( "This" );
716 case ID_LISTBOX_CLEAR
:
721 case ID_LISTBOX_APPEND
:
723 m_listbox
->Append( "Hi!" );
726 case ID_LISTBOX_DELETE
:
728 int idx
= m_listbox
->GetSelection();
729 m_listbox
->Delete( idx
);
732 case ID_LISTBOX_FONT
:
734 m_listbox
->SetFont( *wxITALIC_FONT
);
735 m_checkbox
->SetFont( *wxITALIC_FONT
);
741 void MyPanel::OnChoice( wxCommandEvent
&event
)
743 m_text
->AppendText( "Choice selection string is: " );
744 m_text
->AppendText( event
.GetString() );
745 m_text
->AppendText( "\n" );
748 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
750 switch (event
.GetId())
752 case ID_CHOICE_ENABLE
:
754 m_choice
->Enable( event
.GetInt() == 0 );
757 case ID_CHOICE_SEL_NUM
:
759 m_choice
->SetSelection( 2 );
762 case ID_CHOICE_SEL_STR
:
764 m_choice
->SetStringSelection( "This" );
767 case ID_CHOICE_CLEAR
:
772 case ID_CHOICE_APPEND
:
774 m_choice
->Append( "Hi!" );
777 case ID_CHOICE_DELETE
:
779 int idx
= m_choice
->GetSelection();
780 m_choice
->Delete( idx
);
785 m_choice
->SetFont( *wxITALIC_FONT
);
791 void MyPanel::OnCombo( wxCommandEvent
&event
)
793 m_text
->AppendText( "ComboBox selection string is: " );
794 m_text
->AppendText( event
.GetString() );
795 m_text
->AppendText( "\n" );
798 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
800 switch (event
.GetId())
802 case ID_COMBO_ENABLE
:
804 m_combo
->Enable( event
.GetInt() == 0 );
807 case ID_COMBO_SEL_NUM
:
809 m_combo
->SetSelection( 2 );
812 case ID_COMBO_SEL_STR
:
814 m_combo
->SetStringSelection( "This" );
822 case ID_COMBO_APPEND
:
824 m_combo
->Append( "Hi!" );
827 case ID_COMBO_DELETE
:
829 int idx
= m_combo
->GetSelection();
830 m_combo
->Delete( idx
);
835 m_combo
->SetFont( *wxITALIC_FONT
);
841 void MyPanel::OnRadio( wxCommandEvent
&event
)
843 m_text
->AppendText( "RadioBox selection string is: " );
844 m_text
->AppendText( event
.GetString() );
845 m_text
->AppendText( "\n" );
848 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
850 switch (event
.GetId())
852 case ID_RADIOBOX_ENABLE
:
854 m_radio
->Enable( event
.GetInt() == 0 );
857 case ID_RADIOBOX_SEL_NUM
:
859 m_radio
->SetSelection( 2 );
862 case ID_RADIOBOX_SEL_STR
:
864 m_radio
->SetStringSelection( "This" );
867 case ID_RADIOBOX_FONT
:
869 m_radio
->SetFont( *wxITALIC_FONT
);
875 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
877 m_fontButton
->SetFont( *wxITALIC_FONT
);
878 m_text
->SetFont( *wxITALIC_FONT
);
881 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
883 m_gauge
->SetValue( m_slider
->GetValue() );
887 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
890 value
.Printf( "%d", event
.GetPosition() );
891 m_spintext
->SetValue( value
);
893 value
.Printf("Spin control range: (%d, %d), current = %d\n",
894 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
895 m_spinbutton
->GetValue());
897 m_text
->AppendText(value
);
903 delete m_notebook
->GetImageList();
906 //----------------------------------------------------------------------
908 //----------------------------------------------------------------------
910 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
911 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
912 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
914 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
915 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
916 #endif // wxUSE_TOOLTIPS
917 EVT_SIZE(MyFrame::OnSize
)
918 EVT_IDLE(MyFrame::OnIdle
)
921 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
922 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
926 (void)new MyPanel( this, 10, 10, 300, 100 );
929 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
934 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
938 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
945 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
947 static long s_delay
= 5000;
950 delay
.Printf("%ld", s_delay
);
952 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
959 sscanf(delay
, "%ld", &s_delay
);
961 wxToolTip::SetDelay(s_delay
);
963 wxLogStatus(this, "Tooltip delay set to %ld milliseconds", s_delay
);
966 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
968 static bool s_enabled
= TRUE
;
970 s_enabled
= !s_enabled
;
972 wxToolTip::Enable(s_enabled
);
974 wxLogStatus(this, "Tooltips %sabled", s_enabled
? "en" : "dis");
978 void MyFrame::OnSize( wxSizeEvent
& event
)
981 msg
.Printf("%dx%d", event
.GetSize().x
, event
.GetSize().y
);
982 SetStatusText(msg
, 1);
987 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
989 // track the window which has the focus in the status bar
990 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
991 wxWindow
*focus
= wxWindow::FindFocus();
992 if ( focus
&& (focus
!= s_windowFocus
) )
994 s_windowFocus
= focus
;
997 msg
.Printf("Focus: wxWindow = %p"
1003 , s_windowFocus
->GetHWND()