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
);
74 void OnChar(wxKeyEvent
& event
);
80 class MyPanel
: public wxPanel
83 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
86 void OnSize( wxSizeEvent
& event
);
87 void OnListBox( wxCommandEvent
&event
);
88 void OnListBoxDoubleClick( wxCommandEvent
&event
);
89 void OnListBoxButtons( wxCommandEvent
&event
);
90 void OnChoice( wxCommandEvent
&event
);
91 void OnChoiceButtons( wxCommandEvent
&event
);
92 void OnCombo( wxCommandEvent
&event
);
93 void OnComboButtons( wxCommandEvent
&event
);
94 void OnRadio( wxCommandEvent
&event
);
95 void OnRadioButtons( wxCommandEvent
&event
);
96 void OnSetFont( wxCommandEvent
&event
);
97 void OnPageChanged( wxNotebookEvent
&event
);
98 void OnSliderUpdate( wxCommandEvent
&event
);
100 void OnSpinUpdate( wxSpinEvent
&event
);
102 void OnPasteFromClipboard( wxCommandEvent
&event
);
103 void OnCopyToClipboard( wxCommandEvent
&event
);
104 void OnMoveToEndOfText( wxCommandEvent
&event
);
105 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
107 wxListBox
*m_listbox
;
113 wxButton
*m_fontButton
;
115 wxSpinButton
*m_spinbutton
;
117 wxTextCtrl
*m_spintext
;
118 MyTextCtrl
*m_multitext
;
119 MyTextCtrl
*m_textentry
;
120 wxCheckBox
*m_checkbox
;
123 wxNotebook
*m_notebook
;
126 DECLARE_EVENT_TABLE()
129 class MyFrame
: public wxFrame
132 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
134 void OnQuit(wxCommandEvent
& event
);
135 void OnAbout(wxCommandEvent
& event
);
137 void OnSetTooltipDelay(wxCommandEvent
& event
);
138 void OnToggleTooltips(wxCommandEvent
& event
);
139 #endif // wxUSE_TOOLTIPS
140 void OnIdle( wxIdleEvent
& event
);
141 void OnSize( wxSizeEvent
& event
);
144 DECLARE_EVENT_TABLE()
147 //----------------------------------------------------------------------
149 //----------------------------------------------------------------------
153 //----------------------------------------------------------------------
155 //----------------------------------------------------------------------
164 MINIMAL_SET_TOOLTIP_DELAY
= 200,
165 MINIMAL_ENABLE_TOOLTIPS
170 // Create the main frame window
171 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
172 "Controls wxWindows App",
176 // The wxICON() macros loads an icon from a resource under Windows
177 // and uses an #included XPM image under GTK+ and Motif
179 frame
->SetIcon( wxICON(mondrian
) );
181 wxMenu
*file_menu
= new wxMenu
;
182 file_menu
->Append(MINIMAL_ABOUT
, "&About");
183 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
185 wxMenuBar
*menu_bar
= new wxMenuBar
;
186 menu_bar
->Append(file_menu
, "&File");
189 wxMenu
*tooltip_menu
= new wxMenu
;
190 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay");
191 tooltip_menu
->AppendSeparator();
192 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips",
193 "enable/disable tooltips", TRUE
);
194 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
195 menu_bar
->Append(tooltip_menu
, "&Tooltips");
196 #endif // wxUSE_TOOLTIPS
198 frame
->SetMenuBar(menu_bar
);
201 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
208 //----------------------------------------------------------------------
210 //----------------------------------------------------------------------
212 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
213 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown
)
214 EVT_CHAR(MyTextCtrl::OnChar
)
217 void MyTextCtrl::OnChar(wxKeyEvent
& event
)
219 static int s_keycode
= 0;
220 static size_t s_repeatCount
= 0;
222 int keycode
= event
.KeyCode();
223 if ( keycode
== s_keycode
)
231 wxLogStatus("Key event: %d (x%u), at position %ld",
232 s_keycode
, s_repeatCount
, GetInsertionPoint());
237 void MyTextCtrl::OnKeyDown(wxKeyEvent
& event
)
239 switch ( event
.KeyCode() )
242 // show current position and text length
244 long line
, column
, pos
= GetInsertionPoint();
245 PositionToXY(pos
, &column
, &line
);
247 wxLogMessage("Current position: %ld\n"
248 "Current line, column: (%ld, %ld)\n"
249 "Number of lines: %ld\n"
250 "Current line length: %ld\n"
251 "Total text length: %ld",
262 SetInsertionPointEnd();
267 SetInsertionPoint(10);
275 //----------------------------------------------------------------------
277 //----------------------------------------------------------------------
279 const int ID_NOTEBOOK
= 1000;
281 const int ID_LISTBOX
= 130;
282 const int ID_LISTBOX_SEL_NUM
= 131;
283 const int ID_LISTBOX_SEL_STR
= 132;
284 const int ID_LISTBOX_CLEAR
= 133;
285 const int ID_LISTBOX_APPEND
= 134;
286 const int ID_LISTBOX_DELETE
= 135;
287 const int ID_LISTBOX_FONT
= 136;
288 const int ID_LISTBOX_ENABLE
= 137;
290 const int ID_CHOICE
= 120;
291 const int ID_CHOICE_SEL_NUM
= 121;
292 const int ID_CHOICE_SEL_STR
= 122;
293 const int ID_CHOICE_CLEAR
= 123;
294 const int ID_CHOICE_APPEND
= 124;
295 const int ID_CHOICE_DELETE
= 125;
296 const int ID_CHOICE_FONT
= 126;
297 const int ID_CHOICE_ENABLE
= 127;
299 const int ID_COMBO
= 140;
300 const int ID_COMBO_SEL_NUM
= 141;
301 const int ID_COMBO_SEL_STR
= 142;
302 const int ID_COMBO_CLEAR
= 143;
303 const int ID_COMBO_APPEND
= 144;
304 const int ID_COMBO_DELETE
= 145;
305 const int ID_COMBO_FONT
= 146;
306 const int ID_COMBO_ENABLE
= 147;
308 const int ID_TEXT
= 150;
309 const int ID_PASTE_TEXT
= 151;
310 const int ID_COPY_TEXT
= 152;
311 const int ID_MOVE_END_ENTRY
= 153;
312 const int ID_MOVE_END_ZONE
= 154;
314 const int ID_RADIOBOX
= 160;
315 const int ID_RADIOBOX_SEL_NUM
= 161;
316 const int ID_RADIOBOX_SEL_STR
= 162;
317 const int ID_RADIOBOX_FONT
= 163;
318 const int ID_RADIOBOX_ENABLE
= 164;
320 const int ID_RADIOBUTTON_1
= 166;
321 const int ID_RADIOBUTTON_2
= 167;
323 const int ID_SET_FONT
= 170;
325 const int ID_GAUGE
= 180;
326 const int ID_SLIDER
= 181;
328 const int ID_SPIN
= 182;
330 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
331 EVT_SIZE ( MyPanel::OnSize
)
332 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
333 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
334 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
335 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
336 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
337 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
338 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
339 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
340 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
341 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
342 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
343 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
344 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
345 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
346 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
347 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
348 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
349 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
350 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
351 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
352 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
353 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
354 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
355 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
356 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
357 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
358 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
359 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
360 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
361 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
362 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
363 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
364 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
366 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
368 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
369 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
370 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
371 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
374 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
375 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
376 m_text(NULL
), m_notebook(NULL
)
378 // SetBackgroundColour("cadet blue");
380 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
381 // m_text->SetBackgroundColour("wheat");
383 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
398 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
401 // fill the image list
402 wxImageList
*imagelist
= new wxImageList(32, 32);
404 imagelist
-> Add( wxBitmap( list_xpm
));
405 imagelist
-> Add( wxBitmap( choice_xpm
));
406 imagelist
-> Add( wxBitmap( combo_xpm
));
407 imagelist
-> Add( wxBitmap( text_xpm
));
408 imagelist
-> Add( wxBitmap( radio_xpm
));
409 imagelist
-> Add( wxBitmap( gauge_xpm
));
410 m_notebook
->SetImageList(imagelist
);
411 #elif defined(__WXMSW__)
412 // load images from resources
415 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
417 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
419 static const char *s_iconNames
[Image_Max
] =
421 "list", "choice", "combo", "text", "radio", "gauge"
424 for ( size_t n
= 0; n
< Image_Max
; n
++ )
426 wxBitmap
bmp(s_iconNames
[n
]);
427 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
429 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
434 m_notebook
->SetImageList(imagelist
);
438 #define Image_List -1
439 #define Image_Choice -1
440 #define Image_Combo -1
441 #define Image_Text -1
442 #define Image_Radio -1
443 #define Image_Gauge -1
448 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
449 wxPanel
*panel
= (wxPanel
*) NULL
;
451 panel
= new wxPanel(m_notebook
);
452 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
453 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
455 m_listbox
->SetToolTip( "This is a list box" );
456 #endif // wxUSE_TOOLTIPS
458 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
459 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
460 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
461 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
462 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
463 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
465 button
->SetToolTip( "Press here to set italic font" );
466 #endif // wxUSE_TOOLTIPS
468 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
469 m_checkbox
->SetValue(FALSE
);
471 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
472 #endif // wxUSE_TOOLTIPS
473 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
475 panel
= new wxPanel(m_notebook
);
476 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
477 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
478 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
479 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
480 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
481 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
482 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
483 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
484 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
486 panel
= new wxPanel(m_notebook
);
487 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
);
488 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
489 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
490 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
491 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
492 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
493 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
494 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
495 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
497 panel
= new wxPanel(m_notebook
);
498 m_textentry
= new MyTextCtrl( panel
, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0);
500 (*m_textentry
) << " Appended.";
501 m_textentry
->SetInsertionPoint(0);
502 m_textentry
->WriteText( "Prepended. " );
504 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE
);
505 (*m_multitext
) << " Appended.";
506 m_multitext
->SetInsertionPoint(0);
507 m_multitext
->WriteText( "Prepended. " );
508 m_multitext
->AppendText( "\nPress function keys to test different wxTextCtrl functions." );
510 (*m_multitext
) << "\nDoes it have cross cursor?";
511 m_multitext
->SetCursor(*wxCROSS_CURSOR
);
513 new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
515 m_multitext
->AppendText( "\nThis ctrl has a tooltip. " );
516 m_multitext
->SetToolTip("Press F1 here.");
517 #endif // wxUSE_TOOLTIPS
519 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
520 (void)new wxButton( panel
, ID_MOVE_END_ENTRY
, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
521 (void)new wxButton( panel
, ID_MOVE_END_ZONE
, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
522 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) );
523 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(370,120), wxSize(110,30) );
524 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(370,160), wxSize(110,30) );
525 m_notebook
->AddPage( panel
, "wxTextCtrl" , FALSE
, Image_Text
);
527 wxString choices2
[] =
531 "Fourth", "Fifth", "Sixth",
532 "Seventh", "Eighth", "Nineth", "Tenth" */
535 panel
= new wxPanel(m_notebook
);
536 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
537 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
538 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
539 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
540 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
541 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
542 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
543 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
544 rb
->SetValue( FALSE
);
545 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
546 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
548 panel
= new wxPanel(m_notebook
);
549 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
550 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
551 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1) );
552 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
554 // No wrapping text in wxStaticText yet :-(
555 (void)new wxStaticText( panel
, -1,
561 (void)new wxStaticText( panel
, -1,
562 "In order see the gauge (aka progress bar)\n"
563 "control do something you have to drag the\n"
564 "handle of the slider to the right.\n"
566 "This is also supposed to demonstrate how\n"
567 "to use static controls.\n",
572 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
574 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
575 m_spinbutton
->SetRange(-10,30);
576 m_spinbutton
->SetValue(-5);
578 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
581 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
583 // We test for wxUSE_DRAG_AND_DROP also, because data objects
584 // may not be implemented for compilers that can't cope with the OLE
585 // parts in wxUSE_DRAG_AND_DROP.
587 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
588 if (!wxTheClipboard
->Open())
590 *m_text
<< "Error opening the clipboard.\n";
596 *m_text
<< "Successfully opened the clipboard.\n";
599 wxTextDataObject data
;
601 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
603 *m_text
<< "Clipboard supports requested format.\n";
605 if (wxTheClipboard
->GetData( &data
))
607 *m_text
<< "Successfully retrieved data from the clipboard.\n";
608 *m_multitext
<< data
.GetText() << "\n";
612 *m_text
<< "Error getting data from the clipboard.\n";
617 *m_text
<< "Clipboard doesn't support requested format.\n";
620 wxTheClipboard
->Close();
622 *m_text
<< "Closed the clipboard.\n";
624 wxLogError("Your version of wxWindows is compiled without clipboard support.");
628 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
630 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
631 wxString
text( m_multitext
->GetLineText(0) );
635 *m_text
<< "No text to copy.\n";
640 if (!wxTheClipboard
->Open())
642 *m_text
<< "Error opening the clipboard.\n";
648 *m_text
<< "Successfully opened the clipboard.\n";
651 wxTextDataObject
*data
= new wxTextDataObject( text
);
653 if (!wxTheClipboard
->SetData( data
))
655 *m_text
<< "Error while copying to the clipboard.\n";
659 *m_text
<< "Successfully copied data to the clipboard.\n";
662 wxTheClipboard
->Close();
664 *m_text
<< "Closed the clipboard.\n";
666 wxLogError("Your version of wxWindows is compiled without clipboard support.");
670 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
672 m_multitext
->SetInsertionPointEnd();
673 m_multitext
->SetFocus();
676 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
678 m_textentry
->SetInsertionPointEnd();
679 m_textentry
->SetFocus();
682 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
686 GetClientSize( &x
, &y
);
688 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
689 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
692 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
694 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
697 void MyPanel::OnListBox( wxCommandEvent
&event
)
699 m_text
->AppendText( "ListBox selection string is: " );
700 m_text
->AppendText( event
.GetString() );
701 m_text
->AppendText( "\n" );
704 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
706 m_text
->AppendText( "ListBox double click string is: " );
707 m_text
->AppendText( event
.GetString() );
708 m_text
->AppendText( "\n" );
711 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
713 switch (event
.GetId())
715 case ID_LISTBOX_ENABLE
:
717 m_text
->AppendText("Checkbox clicked.\n");
718 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
721 cb
->SetToolTip( "Click to enable listbox" );
723 cb
->SetToolTip( "Click to disable listbox" );
724 #endif // wxUSE_TOOLTIPS
725 m_listbox
->Enable( event
.GetInt() == 0 );
728 case ID_LISTBOX_SEL_NUM
:
730 m_listbox
->SetSelection( 2 );
733 case ID_LISTBOX_SEL_STR
:
735 m_listbox
->SetStringSelection( "This" );
738 case ID_LISTBOX_CLEAR
:
743 case ID_LISTBOX_APPEND
:
745 m_listbox
->Append( "Hi!" );
748 case ID_LISTBOX_DELETE
:
750 int idx
= m_listbox
->GetSelection();
751 m_listbox
->Delete( idx
);
754 case ID_LISTBOX_FONT
:
756 m_listbox
->SetFont( *wxITALIC_FONT
);
757 m_checkbox
->SetFont( *wxITALIC_FONT
);
763 void MyPanel::OnChoice( wxCommandEvent
&event
)
765 m_text
->AppendText( "Choice selection string is: " );
766 m_text
->AppendText( event
.GetString() );
767 m_text
->AppendText( "\n" );
770 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
772 switch (event
.GetId())
774 case ID_CHOICE_ENABLE
:
776 m_choice
->Enable( event
.GetInt() == 0 );
779 case ID_CHOICE_SEL_NUM
:
781 m_choice
->SetSelection( 2 );
784 case ID_CHOICE_SEL_STR
:
786 m_choice
->SetStringSelection( "This" );
789 case ID_CHOICE_CLEAR
:
794 case ID_CHOICE_APPEND
:
796 m_choice
->Append( "Hi!" );
799 case ID_CHOICE_DELETE
:
801 int idx
= m_choice
->GetSelection();
802 m_choice
->Delete( idx
);
807 m_choice
->SetFont( *wxITALIC_FONT
);
813 void MyPanel::OnCombo( wxCommandEvent
&event
)
815 m_text
->AppendText( "ComboBox selection string is: " );
816 m_text
->AppendText( event
.GetString() );
817 m_text
->AppendText( "\n" );
820 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
822 switch (event
.GetId())
824 case ID_COMBO_ENABLE
:
826 m_combo
->Enable( event
.GetInt() == 0 );
829 case ID_COMBO_SEL_NUM
:
831 m_combo
->SetSelection( 2 );
834 case ID_COMBO_SEL_STR
:
836 m_combo
->SetStringSelection( "This" );
844 case ID_COMBO_APPEND
:
846 m_combo
->Append( "Hi!" );
849 case ID_COMBO_DELETE
:
851 int idx
= m_combo
->GetSelection();
852 m_combo
->Delete( idx
);
857 m_combo
->SetFont( *wxITALIC_FONT
);
863 void MyPanel::OnRadio( wxCommandEvent
&event
)
865 m_text
->AppendText( "RadioBox selection string is: " );
866 m_text
->AppendText( event
.GetString() );
867 m_text
->AppendText( "\n" );
870 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
872 switch (event
.GetId())
874 case ID_RADIOBOX_ENABLE
:
876 m_radio
->Enable( event
.GetInt() == 0 );
879 case ID_RADIOBOX_SEL_NUM
:
881 m_radio
->SetSelection( 2 );
884 case ID_RADIOBOX_SEL_STR
:
886 m_radio
->SetStringSelection( "This" );
889 case ID_RADIOBOX_FONT
:
891 m_radio
->SetFont( *wxITALIC_FONT
);
897 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
899 m_fontButton
->SetFont( *wxITALIC_FONT
);
900 m_text
->SetFont( *wxITALIC_FONT
);
903 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
905 m_gauge
->SetValue( m_slider
->GetValue() );
909 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
912 value
.Printf( "%d", event
.GetPosition() );
913 m_spintext
->SetValue( value
);
915 value
.Printf("Spin control range: (%d, %d), current = %d\n",
916 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
917 m_spinbutton
->GetValue());
919 m_text
->AppendText(value
);
925 delete m_notebook
->GetImageList();
928 //----------------------------------------------------------------------
930 //----------------------------------------------------------------------
932 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
933 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
934 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
936 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
937 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
938 #endif // wxUSE_TOOLTIPS
939 EVT_SIZE(MyFrame::OnSize
)
940 EVT_IDLE(MyFrame::OnIdle
)
943 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
944 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
948 (void)new MyPanel( this, 10, 10, 300, 100 );
951 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
956 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
960 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
967 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
969 static long s_delay
= 5000;
972 delay
.Printf("%ld", s_delay
);
974 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
981 sscanf(delay
, "%ld", &s_delay
);
983 wxToolTip::SetDelay(s_delay
);
985 wxLogStatus(this, "Tooltip delay set to %ld milliseconds", s_delay
);
988 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
990 static bool s_enabled
= TRUE
;
992 s_enabled
= !s_enabled
;
994 wxToolTip::Enable(s_enabled
);
996 wxLogStatus(this, "Tooltips %sabled", s_enabled
? "en" : "dis");
1000 void MyFrame::OnSize( wxSizeEvent
& event
)
1003 msg
.Printf("%dx%d", event
.GetSize().x
, event
.GetSize().y
);
1004 SetStatusText(msg
, 1);
1009 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1011 // track the window which has the focus in the status bar
1012 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1013 wxWindow
*focus
= wxWindow::FindFocus();
1014 if ( focus
&& (focus
!= s_windowFocus
) )
1016 s_windowFocus
= focus
;
1019 msg
.Printf("Focus: wxWindow = %p"
1025 , s_windowFocus
->GetHWND()