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"
55 // Win16 doesn't have them
56 #undef wxUSE_SPINBUTTON
57 #define wxUSE_SPINBUTTON 0
60 #include "wx/progdlg.h"
62 //----------------------------------------------------------------------
64 //----------------------------------------------------------------------
66 class MyApp
: public wxApp
72 // a text ctrl which allows to call different wxTextCtrl functions
73 // interactively by pressing function keys in it
74 class MyTextCtrl
: public wxTextCtrl
77 MyTextCtrl(wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
78 const wxPoint
&pos
, const wxSize
&size
, int style
= 0)
79 : wxTextCtrl(parent
, id
, value
, pos
, size
, style
) { }
81 void OnKeyDown(wxKeyEvent
& event
);
82 void OnKeyUp(wxKeyEvent
& event
);
83 void OnChar(wxKeyEvent
& event
);
86 static inline wxChar
GetChar(bool on
, wxChar c
) { return on
? c
: _T('-'); }
87 void LogEvent(const wxChar
*name
, wxKeyEvent
& event
) const;
92 class MyPanel
: public wxPanel
95 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
98 void OnSize( wxSizeEvent
& event
);
99 void OnListBox( wxCommandEvent
&event
);
100 void OnListBoxDoubleClick( wxCommandEvent
&event
);
101 void OnListBoxButtons( wxCommandEvent
&event
);
102 void OnChoice( wxCommandEvent
&event
);
103 void OnChoiceButtons( wxCommandEvent
&event
);
104 void OnCombo( wxCommandEvent
&event
);
105 void OnComboButtons( wxCommandEvent
&event
);
106 void OnRadio( wxCommandEvent
&event
);
107 void OnRadioButtons( wxCommandEvent
&event
);
108 void OnSetFont( wxCommandEvent
&event
);
109 void OnPageChanged( wxNotebookEvent
&event
);
110 void OnPageChanging( wxNotebookEvent
&event
);
111 void OnSliderUpdate( wxCommandEvent
&event
);
112 #ifndef wxUSE_SPINBUTTON
113 void OnSpinUpdate( wxSpinEvent
&event
);
114 void OnUpdateShowProgress( wxUpdateUIEvent
& event
);
115 void OnShowProgress( wxCommandEvent
&event
);
116 #endif // wxUSE_SPINBUTTON
117 void OnPasteFromClipboard( wxCommandEvent
&event
);
118 void OnCopyToClipboard( wxCommandEvent
&event
);
119 void OnMoveToEndOfText( wxCommandEvent
&event
);
120 void OnMoveToEndOfEntry( wxCommandEvent
&event
);
122 wxListBox
*m_listbox
;
128 wxButton
*m_fontButton
;
129 wxButton
*m_lbSelectNum
;
130 wxButton
*m_lbSelectThis
;
131 #ifndef wxUSE_SPINBUTTON
132 wxSpinButton
*m_spinbutton
;
133 wxButton
*m_btnProgress
;
135 wxTextCtrl
*m_spintext
;
136 MyTextCtrl
*m_multitext
;
137 MyTextCtrl
*m_textentry
;
138 wxCheckBox
*m_checkbox
;
141 wxNotebook
*m_notebook
;
144 DECLARE_EVENT_TABLE()
147 class MyFrame
: public wxFrame
150 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
152 void OnQuit(wxCommandEvent
& event
);
153 void OnAbout(wxCommandEvent
& event
);
155 void OnSetTooltipDelay(wxCommandEvent
& event
);
156 void OnToggleTooltips(wxCommandEvent
& event
);
157 #endif // wxUSE_TOOLTIPS
158 void OnIdle( wxIdleEvent
& event
);
159 void OnSize( wxSizeEvent
& event
);
162 DECLARE_EVENT_TABLE()
165 //----------------------------------------------------------------------
167 //----------------------------------------------------------------------
171 //----------------------------------------------------------------------
173 //----------------------------------------------------------------------
182 MINIMAL_SET_TOOLTIP_DELAY
= 200,
183 MINIMAL_ENABLE_TOOLTIPS
188 // Create the main frame window
189 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
,
190 "Controls wxWindows App",
194 // The wxICON() macros loads an icon from a resource under Windows
195 // and uses an #included XPM image under GTK+ and Motif
197 frame
->SetIcon( wxICON(mondrian
) );
199 wxMenu
*file_menu
= new wxMenu
;
200 file_menu
->Append(MINIMAL_ABOUT
, "&About\tF1");
201 file_menu
->Append(MINIMAL_QUIT
, "E&xit\tAlt-X", "Quit controls sample");
203 wxMenuBar
*menu_bar
= new wxMenuBar( wxMB_DOCKABLE
);
204 menu_bar
->Append(file_menu
, "&File");
207 wxMenu
*tooltip_menu
= new wxMenu
;
208 tooltip_menu
->Append(MINIMAL_SET_TOOLTIP_DELAY
, "Set &delay\tCtrl-D");
209 tooltip_menu
->AppendSeparator();
210 tooltip_menu
->Append(MINIMAL_ENABLE_TOOLTIPS
, "&Toggle tooltips\tCrtl-T",
211 "enable/disable tooltips", TRUE
);
212 tooltip_menu
->Check(MINIMAL_ENABLE_TOOLTIPS
, TRUE
);
213 menu_bar
->Append(tooltip_menu
, "&Tooltips");
214 #endif // wxUSE_TOOLTIPS
216 frame
->SetMenuBar(menu_bar
);
219 frame
->SetCursor(wxCursor(wxCURSOR_HAND
));
226 //----------------------------------------------------------------------
228 //----------------------------------------------------------------------
230 BEGIN_EVENT_TABLE(MyTextCtrl
, wxTextCtrl
)
231 EVT_KEY_DOWN(MyTextCtrl::OnKeyDown
)
232 EVT_KEY_UP(MyTextCtrl::OnKeyUp
)
233 EVT_CHAR(MyTextCtrl::OnChar
)
236 void MyTextCtrl::LogEvent(const wxChar
*name
, wxKeyEvent
& event
) const
239 long keycode
= event
.KeyCode();
240 if ( wxIsprint((int)keycode
) )
241 key
.Printf( _T("'%c'") , (char)keycode
);
246 case WXK_BACK
: key
= "BACK"; break;
247 case WXK_TAB
: key
= "TAB"; break;
248 case WXK_RETURN
: key
= "RETURN"; break;
249 case WXK_ESCAPE
: key
= "ESCAPE"; break;
250 case WXK_SPACE
: key
= "SPACE"; break;
251 case WXK_DELETE
: key
= "DELETE"; break;
252 case WXK_START
: key
= "START"; break;
253 case WXK_LBUTTON
: key
= "LBUTTON"; break;
254 case WXK_RBUTTON
: key
= "RBUTTON"; break;
255 case WXK_CANCEL
: key
= "CANCEL"; break;
256 case WXK_MBUTTON
: key
= "MBUTTON"; break;
257 case WXK_CLEAR
: key
= "CLEAR"; break;
258 case WXK_SHIFT
: key
= "SHIFT"; break;
259 case WXK_ALT
: key
= "ALT"; break;
260 case WXK_CONTROL
: key
= "CONTROL"; break;
261 case WXK_MENU
: key
= "MENU"; break;
262 case WXK_PAUSE
: key
= "PAUSE"; break;
263 case WXK_CAPITAL
: key
= "CAPITAL"; break;
264 case WXK_PRIOR
: key
= "PRIOR"; break;
265 case WXK_NEXT
: key
= "NEXT"; break;
266 case WXK_END
: key
= "END"; break;
267 case WXK_HOME
: key
= "HOME"; break;
268 case WXK_LEFT
: key
= "LEFT"; break;
269 case WXK_UP
: key
= "UP"; break;
270 case WXK_RIGHT
: key
= "RIGHT"; break;
271 case WXK_DOWN
: key
= "DOWN"; break;
272 case WXK_SELECT
: key
= "SELECT"; break;
273 case WXK_PRINT
: key
= "PRINT"; break;
274 case WXK_EXECUTE
: key
= "EXECUTE"; break;
275 case WXK_SNAPSHOT
: key
= "SNAPSHOT"; break;
276 case WXK_INSERT
: key
= "INSERT"; break;
277 case WXK_HELP
: key
= "HELP"; break;
278 case WXK_NUMPAD0
: key
= "NUMPAD0"; break;
279 case WXK_NUMPAD1
: key
= "NUMPAD1"; break;
280 case WXK_NUMPAD2
: key
= "NUMPAD2"; break;
281 case WXK_NUMPAD3
: key
= "NUMPAD3"; break;
282 case WXK_NUMPAD4
: key
= "NUMPAD4"; break;
283 case WXK_NUMPAD5
: key
= "NUMPAD5"; break;
284 case WXK_NUMPAD6
: key
= "NUMPAD6"; break;
285 case WXK_NUMPAD7
: key
= "NUMPAD7"; break;
286 case WXK_NUMPAD8
: key
= "NUMPAD8"; break;
287 case WXK_NUMPAD9
: key
= "NUMPAD9"; break;
288 case WXK_MULTIPLY
: key
= "MULTIPLY"; break;
289 case WXK_ADD
: key
= "ADD"; break;
290 case WXK_SEPARATOR
: key
= "SEPARATOR"; break;
291 case WXK_SUBTRACT
: key
= "SUBTRACT"; break;
292 case WXK_DECIMAL
: key
= "DECIMAL"; break;
293 case WXK_DIVIDE
: key
= "DIVIDE"; break;
294 case WXK_F1
: key
= "F1"; break;
295 case WXK_F2
: key
= "F2"; break;
296 case WXK_F3
: key
= "F3"; break;
297 case WXK_F4
: key
= "F4"; break;
298 case WXK_F5
: key
= "F5"; break;
299 case WXK_F6
: key
= "F6"; break;
300 case WXK_F7
: key
= "F7"; break;
301 case WXK_F8
: key
= "F8"; break;
302 case WXK_F9
: key
= "F9"; break;
303 case WXK_F10
: key
= "F10"; break;
304 case WXK_F11
: key
= "F11"; break;
305 case WXK_F12
: key
= "F12"; break;
306 case WXK_F13
: key
= "F13"; break;
307 case WXK_F14
: key
= "F14"; break;
308 case WXK_F15
: key
= "F15"; break;
309 case WXK_F16
: key
= "F16"; break;
310 case WXK_F17
: key
= "F17"; break;
311 case WXK_F18
: key
= "F18"; break;
312 case WXK_F19
: key
= "F19"; break;
313 case WXK_F20
: key
= "F20"; break;
314 case WXK_F21
: key
= "F21"; break;
315 case WXK_F22
: key
= "F22"; break;
316 case WXK_F23
: key
= "F23"; break;
317 case WXK_F24
: key
= "F24"; break;
318 case WXK_NUMLOCK
: key
= "NUMLOCK"; break;
319 case WXK_SCROLL
: key
= "SCROLL"; break;
320 case WXK_PAGEUP
: key
= "PAGEUP"; break;
321 case WXK_PAGEDOWN
: key
= "PAGEDOWN"; break;
322 case WXK_NUMPAD_SPACE
: key
= "NUMPAD_SPACE"; break;
323 case WXK_NUMPAD_TAB
: key
= "NUMPAD_TAB"; break;
324 case WXK_NUMPAD_ENTER
: key
= "NUMPAD_ENTER"; break;
325 case WXK_NUMPAD_F1
: key
= "NUMPAD_F1"; break;
326 case WXK_NUMPAD_F2
: key
= "NUMPAD_F2"; break;
327 case WXK_NUMPAD_F3
: key
= "NUMPAD_F3"; break;
328 case WXK_NUMPAD_F4
: key
= "NUMPAD_F4"; break;
329 case WXK_NUMPAD_HOME
: key
= "NUMPAD_HOME"; break;
330 case WXK_NUMPAD_LEFT
: key
= "NUMPAD_LEFT"; break;
331 case WXK_NUMPAD_UP
: key
= "NUMPAD_UP"; break;
332 case WXK_NUMPAD_RIGHT
: key
= "NUMPAD_RIGHT"; break;
333 case WXK_NUMPAD_DOWN
: key
= "NUMPAD_DOWN"; break;
334 case WXK_NUMPAD_PRIOR
: key
= "NUMPAD_PRIOR"; break;
335 case WXK_NUMPAD_PAGEUP
: key
= "NUMPAD_PAGEUP"; break;
336 case WXK_NUMPAD_PAGEDOWN
: key
= "NUMPAD_PAGEDOWN"; break;
337 case WXK_NUMPAD_END
: key
= "NUMPAD_END"; break;
338 case WXK_NUMPAD_BEGIN
: key
= "NUMPAD_BEGIN"; break;
339 case WXK_NUMPAD_INSERT
: key
= "NUMPAD_INSERT"; break;
340 case WXK_NUMPAD_DELETE
: key
= "NUMPAD_DELETE"; break;
341 case WXK_NUMPAD_EQUAL
: key
= "NUMPAD_EQUAL"; break;
342 case WXK_NUMPAD_MULTIPLY
: key
= "NUMPAD_MULTIPLY"; break;
343 case WXK_NUMPAD_ADD
: key
= "NUMPAD_ADD"; break;
344 case WXK_NUMPAD_SEPARATOR
: key
= "NUMPAD_SEPARATOR"; break;
345 case WXK_NUMPAD_SUBTRACT
: key
= "NUMPAD_SUBTRACT"; break;
346 case WXK_NUMPAD_DECIMAL
: key
= "NUMPAD_DECIMAL"; break;
349 key
.Printf( _T("unknown (%ld)"), keycode
);
353 wxLogMessage( _T("%s event: %s (flags = %c%c%c%c)"),
356 GetChar( event
.ControlDown(), _T('C') ),
357 GetChar( event
.AltDown(), _T('A') ),
358 GetChar( event
.ShiftDown(), _T('S') ),
359 GetChar( event
.MetaDown(), _T('M') ) );
363 void MyTextCtrl::OnChar(wxKeyEvent
& event
)
365 LogEvent( _T("Char"), event
);
370 void MyTextCtrl::OnKeyUp(wxKeyEvent
& event
)
372 LogEvent( _("Key up"), event
);
377 void MyTextCtrl::OnKeyDown(wxKeyEvent
& event
)
379 switch ( event
.KeyCode() )
382 // show current position and text length
384 long line
, column
, pos
= GetInsertionPoint();
385 PositionToXY(pos
, &column
, &line
);
387 wxLogMessage( _T("Current position: %ld\n"
388 "Current line, column: (%ld, %ld)\n"
389 "Number of lines: %ld\n"
390 "Current line length: %ld\n"
391 "Total text length: %ld"),
402 SetInsertionPointEnd();
407 SetInsertionPoint(10);
411 LogEvent( _("Key down"), event
);
416 //----------------------------------------------------------------------
418 //----------------------------------------------------------------------
420 const int ID_NOTEBOOK
= 1000;
422 const int ID_LISTBOX
= 130;
423 const int ID_LISTBOX_SEL_NUM
= 131;
424 const int ID_LISTBOX_SEL_STR
= 132;
425 const int ID_LISTBOX_CLEAR
= 133;
426 const int ID_LISTBOX_APPEND
= 134;
427 const int ID_LISTBOX_DELETE
= 135;
428 const int ID_LISTBOX_FONT
= 136;
429 const int ID_LISTBOX_ENABLE
= 137;
431 const int ID_CHOICE
= 120;
432 const int ID_CHOICE_SEL_NUM
= 121;
433 const int ID_CHOICE_SEL_STR
= 122;
434 const int ID_CHOICE_CLEAR
= 123;
435 const int ID_CHOICE_APPEND
= 124;
436 const int ID_CHOICE_DELETE
= 125;
437 const int ID_CHOICE_FONT
= 126;
438 const int ID_CHOICE_ENABLE
= 127;
440 const int ID_COMBO
= 140;
441 const int ID_COMBO_SEL_NUM
= 141;
442 const int ID_COMBO_SEL_STR
= 142;
443 const int ID_COMBO_CLEAR
= 143;
444 const int ID_COMBO_APPEND
= 144;
445 const int ID_COMBO_DELETE
= 145;
446 const int ID_COMBO_FONT
= 146;
447 const int ID_COMBO_ENABLE
= 147;
449 const int ID_TEXT
= 150;
450 const int ID_PASTE_TEXT
= 151;
451 const int ID_COPY_TEXT
= 152;
452 const int ID_MOVE_END_ENTRY
= 153;
453 const int ID_MOVE_END_ZONE
= 154;
455 const int ID_RADIOBOX
= 160;
456 const int ID_RADIOBOX_SEL_NUM
= 161;
457 const int ID_RADIOBOX_SEL_STR
= 162;
458 const int ID_RADIOBOX_FONT
= 163;
459 const int ID_RADIOBOX_ENABLE
= 164;
461 const int ID_RADIOBUTTON_1
= 166;
462 const int ID_RADIOBUTTON_2
= 167;
464 const int ID_SET_FONT
= 170;
466 const int ID_GAUGE
= 180;
467 const int ID_SLIDER
= 181;
469 const int ID_SPIN
= 182;
470 const int ID_BTNPROGRESS
= 183;
472 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
473 EVT_SIZE ( MyPanel::OnSize
)
474 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK
, MyPanel::OnPageChanging
)
475 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK
, MyPanel::OnPageChanged
)
476 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
477 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyPanel::OnListBoxDoubleClick
)
478 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
479 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
480 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
481 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
482 EVT_BUTTON (ID_LISTBOX_DELETE
, MyPanel::OnListBoxButtons
)
483 EVT_BUTTON (ID_LISTBOX_FONT
, MyPanel::OnListBoxButtons
)
484 EVT_CHECKBOX (ID_LISTBOX_ENABLE
, MyPanel::OnListBoxButtons
)
485 EVT_CHOICE (ID_CHOICE
, MyPanel::OnChoice
)
486 EVT_BUTTON (ID_CHOICE_SEL_NUM
, MyPanel::OnChoiceButtons
)
487 EVT_BUTTON (ID_CHOICE_SEL_STR
, MyPanel::OnChoiceButtons
)
488 EVT_BUTTON (ID_CHOICE_CLEAR
, MyPanel::OnChoiceButtons
)
489 EVT_BUTTON (ID_CHOICE_APPEND
, MyPanel::OnChoiceButtons
)
490 EVT_BUTTON (ID_CHOICE_DELETE
, MyPanel::OnChoiceButtons
)
491 EVT_BUTTON (ID_CHOICE_FONT
, MyPanel::OnChoiceButtons
)
492 EVT_CHECKBOX (ID_CHOICE_ENABLE
, MyPanel::OnChoiceButtons
)
493 EVT_COMBOBOX (ID_COMBO
, MyPanel::OnCombo
)
494 EVT_BUTTON (ID_COMBO_SEL_NUM
, MyPanel::OnComboButtons
)
495 EVT_BUTTON (ID_COMBO_SEL_STR
, MyPanel::OnComboButtons
)
496 EVT_BUTTON (ID_COMBO_CLEAR
, MyPanel::OnComboButtons
)
497 EVT_BUTTON (ID_COMBO_APPEND
, MyPanel::OnComboButtons
)
498 EVT_BUTTON (ID_COMBO_DELETE
, MyPanel::OnComboButtons
)
499 EVT_BUTTON (ID_COMBO_FONT
, MyPanel::OnComboButtons
)
500 EVT_CHECKBOX (ID_COMBO_ENABLE
, MyPanel::OnComboButtons
)
501 EVT_RADIOBOX (ID_RADIOBOX
, MyPanel::OnRadio
)
502 EVT_BUTTON (ID_RADIOBOX_SEL_NUM
, MyPanel::OnRadioButtons
)
503 EVT_BUTTON (ID_RADIOBOX_SEL_STR
, MyPanel::OnRadioButtons
)
504 EVT_BUTTON (ID_RADIOBOX_FONT
, MyPanel::OnRadioButtons
)
505 EVT_CHECKBOX (ID_RADIOBOX_ENABLE
, MyPanel::OnRadioButtons
)
506 EVT_BUTTON (ID_SET_FONT
, MyPanel::OnSetFont
)
507 EVT_SLIDER (ID_SLIDER
, MyPanel::OnSliderUpdate
)
508 #ifndef wxUSE_SPINBUTTON
509 EVT_SPIN (ID_SPIN
, MyPanel::OnSpinUpdate
)
510 EVT_UPDATE_UI (ID_BTNPROGRESS
, MyPanel::OnUpdateShowProgress
)
511 EVT_BUTTON (ID_BTNPROGRESS
, MyPanel::OnShowProgress
)
513 EVT_BUTTON (ID_PASTE_TEXT
, MyPanel::OnPasteFromClipboard
)
514 EVT_BUTTON (ID_COPY_TEXT
, MyPanel::OnCopyToClipboard
)
515 EVT_BUTTON (ID_MOVE_END_ZONE
, MyPanel::OnMoveToEndOfText
)
516 EVT_BUTTON (ID_MOVE_END_ENTRY
, MyPanel::OnMoveToEndOfEntry
)
519 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
)
520 : wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) ),
521 m_text(NULL
), m_notebook(NULL
)
523 // SetBackgroundColour("cadet blue");
525 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
526 // m_text->SetBackgroundColour("wheat");
528 delete wxLog::SetActiveTarget(new wxLogStderr
);
530 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
545 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
548 // fill the image list
549 wxImageList
*imagelist
= new wxImageList(32, 32);
551 imagelist
-> Add( wxBitmap( list_xpm
));
552 imagelist
-> Add( wxBitmap( choice_xpm
));
553 imagelist
-> Add( wxBitmap( combo_xpm
));
554 imagelist
-> Add( wxBitmap( text_xpm
));
555 imagelist
-> Add( wxBitmap( radio_xpm
));
556 imagelist
-> Add( wxBitmap( gauge_xpm
));
557 m_notebook
->SetImageList(imagelist
);
558 #elif defined(__WXMSW__)
559 // load images from resources
562 Image_List
, Image_Choice
, Image_Combo
, Image_Text
, Image_Radio
, Image_Gauge
, Image_Max
564 wxImageList
*imagelist
= new wxImageList(16, 16, FALSE
, Image_Max
);
566 static const char *s_iconNames
[Image_Max
] =
568 "list", "choice", "combo", "text", "radio", "gauge"
571 for ( size_t n
= 0; n
< Image_Max
; n
++ )
573 wxBitmap
bmp(s_iconNames
[n
]);
574 if ( !bmp
.Ok() || (imagelist
->Add(bmp
) == -1) )
576 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
581 m_notebook
->SetImageList(imagelist
);
585 #define Image_List -1
586 #define Image_Choice -1
587 #define Image_Combo -1
588 #define Image_Text -1
589 #define Image_Radio -1
590 #define Image_Gauge -1
595 wxButton
*button
= (wxButton
*) NULL
; /* who did this ? */
596 wxPanel
*panel
= (wxPanel
*) NULL
;
598 panel
= new wxPanel(m_notebook
);
599 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 5, choices
, wxLB_ALWAYS_SB
);
600 m_listbox
->SetCursor(*wxCROSS_CURSOR
);
602 m_listbox
->SetToolTip( "This is a list box" );
603 #endif // wxUSE_TOOLTIPS
605 m_lbSelectNum
= new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
606 m_lbSelectThis
= new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
607 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
608 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
609 (void)new wxButton( panel
, ID_LISTBOX_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
610 button
= new wxButton( panel
, ID_LISTBOX_FONT
, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
612 button
->SetToolTip( "Press here to set italic font" );
613 #endif // wxUSE_TOOLTIPS
615 m_checkbox
= new wxCheckBox( panel
, ID_LISTBOX_ENABLE
, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT
);
616 m_checkbox
->SetValue(FALSE
);
618 m_checkbox
->SetToolTip( "Click here to disable the listbox" );
619 #endif // wxUSE_TOOLTIPS
620 m_notebook
->AddPage(panel
, "wxListBox", TRUE
, Image_List
);
622 panel
= new wxPanel(m_notebook
);
623 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 5, choices
);
624 m_choice
->SetBackgroundColour( "red" );
625 (void)new wxButton( panel
, ID_CHOICE_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
626 (void)new wxButton( panel
, ID_CHOICE_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
627 (void)new wxButton( panel
, ID_CHOICE_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
628 (void)new wxButton( panel
, ID_CHOICE_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
629 (void)new wxButton( panel
, ID_CHOICE_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
630 (void)new wxButton( panel
, ID_CHOICE_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
631 (void)new wxCheckBox( panel
, ID_CHOICE_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
632 m_notebook
->AddPage(panel
, "wxChoice", FALSE
, Image_Choice
);
634 panel
= new wxPanel(m_notebook
);
635 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 5, choices
, wxCB_READONLY
);
636 (void)new wxButton( panel
, ID_COMBO_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
637 (void)new wxButton( panel
, ID_COMBO_SEL_STR
, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
638 (void)new wxButton( panel
, ID_COMBO_CLEAR
, "Clear", wxPoint(180,80), wxSize(140,30) );
639 (void)new wxButton( panel
, ID_COMBO_APPEND
, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
640 (void)new wxButton( panel
, ID_COMBO_DELETE
, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
641 (void)new wxButton( panel
, ID_COMBO_FONT
, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
642 (void)new wxCheckBox( panel
, ID_COMBO_ENABLE
, "Disable", wxPoint(20,130), wxSize(140,30) );
643 m_notebook
->AddPage(panel
, "wxComboBox", FALSE
, Image_Combo
);
645 panel
= new wxPanel(m_notebook
);
646 m_textentry
= new MyTextCtrl( panel
, -1, "Some text.", wxPoint(10,10), wxSize(320,28), //0);
648 (*m_textentry
) << " Appended.";
649 m_textentry
->SetInsertionPoint(0);
650 m_textentry
->WriteText( "Prepended. " );
652 m_multitext
= new MyTextCtrl( panel
, ID_TEXT
, "Some text.", wxPoint(10,50), wxSize(320,70), wxTE_MULTILINE
);
653 (*m_multitext
) << " Appended.";
654 m_multitext
->SetInsertionPoint(0);
655 m_multitext
->WriteText( "Prepended. " );
656 m_multitext
->AppendText( "\nPress function keys for test different tests." );
658 (*m_multitext
) << "\nDoes it have cross cursor?";
659 m_multitext
->SetCursor(*wxCROSS_CURSOR
);
661 new MyTextCtrl( panel
, -1, "This one is with wxTE_PROCESS_TAB style.", wxPoint(10,120), wxSize(320,70), wxTE_MULTILINE
| wxTE_PROCESS_TAB
);
663 m_multitext
->AppendText( "\nThis ctrl has a tooltip. " );
664 m_multitext
->SetToolTip("Press F1 here.");
665 #endif // wxUSE_TOOLTIPS
667 (void)new wxStaticBox( panel
, -1, "&Move cursor to the end of:", wxPoint(345, 0), wxSize(160, 100) );
668 (void)new wxButton( panel
, ID_MOVE_END_ENTRY
, "Text &entry", wxPoint(370, 20), wxSize(110, 30) );
669 (void)new wxButton( panel
, ID_MOVE_END_ZONE
, "Text &zone", wxPoint(370, 60), wxSize(110, 30) );
670 (void)new wxStaticBox( panel
, -1, "wx&Clipboard", wxPoint(345,100), wxSize(160,100) );
671 (void)new wxButton( panel
, ID_COPY_TEXT
, "C&opy line 1", wxPoint(370,120), wxSize(110,30) );
672 (void)new wxButton( panel
, ID_PASTE_TEXT
, "&Paste text", wxPoint(370,160), wxSize(110,30) );
673 m_notebook
->AddPage( panel
, "wxTextCtrl" , FALSE
, Image_Text
);
675 wxString choices2
[] =
679 "Fourth", "Fifth", "Sixth",
680 "Seventh", "Eighth", "Nineth", "Tenth" */
683 panel
= new wxPanel(m_notebook
);
684 (void)new wxRadioBox( panel
, ID_RADIOBOX
, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2
), choices2
, 1, wxRA_SPECIFY_ROWS
);
685 m_radio
= new wxRadioBox( panel
, ID_RADIOBOX
, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices
), choices
, 1, wxRA_SPECIFY_COLS
);
686 (void)new wxButton( panel
, ID_RADIOBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(140,30) );
687 (void)new wxButton( panel
, ID_RADIOBOX_SEL_STR
, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
688 m_fontButton
= new wxButton( panel
, ID_SET_FONT
, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
689 (void)new wxButton( panel
, ID_RADIOBOX_FONT
, "Set Italic font", wxPoint(340,80), wxSize(140,30) );
690 (void)new wxCheckBox( panel
, ID_RADIOBOX_ENABLE
, "Disable", wxPoint(340,130), wxSize(140,30) );
691 wxRadioButton
*rb
= new wxRadioButton( panel
, ID_RADIOBUTTON_1
, "Radiobutton1", wxPoint(210,170), wxSize(110,30) );
692 rb
->SetValue( FALSE
);
693 (void)new wxRadioButton( panel
, ID_RADIOBUTTON_2
, "Radiobutton2", wxPoint(340,170), wxSize(110,30) );
694 m_notebook
->AddPage(panel
, "wxRadioBox", FALSE
, Image_Radio
);
696 panel
= new wxPanel(m_notebook
);
697 (void)new wxStaticBox( panel
, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) );
698 m_gauge
= new wxGauge( panel
, -1, 200, wxPoint(18,50), wxSize(155, 30) );
699 m_slider
= new wxSlider( panel
, ID_SLIDER
, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS
);
700 (void)new wxStaticBox( panel
, -1, "Explanation", wxPoint(200,10), wxSize(290,130) );
702 // No wrapping text in wxStaticText yet :-(
703 (void)new wxStaticText( panel
, -1,
709 (void)new wxStaticText( panel
, -1,
710 "In order see the gauge (aka progress bar)\n"
711 "control do something you have to drag the\n"
712 "handle of the slider to the right.\n"
714 "This is also supposed to demonstrate how\n"
715 "to use static controls.\n",
720 m_spintext
= new wxTextCtrl( panel
, -1, "0", wxPoint(20,160), wxSize(80,-1) );
721 #ifndef wxUSE_SPINBUTTON
722 m_spinbutton
= new wxSpinButton( panel
, ID_SPIN
, wxPoint(103,159), wxSize(-1,-1) );
723 m_spinbutton
->SetRange(-10,30);
724 m_spinbutton
->SetValue(-5);
726 m_btnProgress
= new wxButton( panel
, ID_BTNPROGRESS
, "Show progress dialog",
729 m_notebook
->AddPage(panel
, "wxGauge", FALSE
, Image_Gauge
);
732 void MyPanel::OnPasteFromClipboard( wxCommandEvent
&WXUNUSED(event
) )
734 // We test for wxUSE_DRAG_AND_DROP also, because data objects
735 // may not be implemented for compilers that can't cope with the OLE
736 // parts in wxUSE_DRAG_AND_DROP.
738 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
739 if (!wxTheClipboard
->Open())
741 *m_text
<< "Error opening the clipboard.\n";
747 *m_text
<< "Successfully opened the clipboard.\n";
750 wxTextDataObject data
;
752 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
754 *m_text
<< "Clipboard supports requested format.\n";
756 if (wxTheClipboard
->GetData( &data
))
758 *m_text
<< "Successfully retrieved data from the clipboard.\n";
759 *m_multitext
<< data
.GetText() << "\n";
763 *m_text
<< "Error getting data from the clipboard.\n";
768 *m_text
<< "Clipboard doesn't support requested format.\n";
771 wxTheClipboard
->Close();
773 *m_text
<< "Closed the clipboard.\n";
775 wxLogError("Your version of wxWindows is compiled without clipboard support.");
779 void MyPanel::OnCopyToClipboard( wxCommandEvent
&WXUNUSED(event
) )
781 #if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
782 wxString
text( m_multitext
->GetLineText(0) );
786 *m_text
<< "No text to copy.\n";
791 if (!wxTheClipboard
->Open())
793 *m_text
<< "Error opening the clipboard.\n";
799 *m_text
<< "Successfully opened the clipboard.\n";
802 wxTextDataObject
*data
= new wxTextDataObject( text
);
804 if (!wxTheClipboard
->SetData( data
))
806 *m_text
<< "Error while copying to the clipboard.\n";
810 *m_text
<< "Successfully copied data to the clipboard.\n";
813 wxTheClipboard
->Close();
815 *m_text
<< "Closed the clipboard.\n";
817 wxLogError("Your version of wxWindows is compiled without clipboard support.");
821 void MyPanel::OnMoveToEndOfText( wxCommandEvent
&event
)
823 m_multitext
->SetInsertionPointEnd();
824 m_multitext
->SetFocus();
827 void MyPanel::OnMoveToEndOfEntry( wxCommandEvent
&event
)
829 m_textentry
->SetInsertionPointEnd();
830 m_textentry
->SetFocus();
833 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
837 GetClientSize( &x
, &y
);
839 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
*2/3-4 );
840 if (m_text
) m_text
->SetSize( 2, y
*2/3+2, x
-4, y
/3-4 );
843 void MyPanel::OnPageChanging( wxNotebookEvent
&event
)
845 int selNew
= event
.GetSelection(),
846 selOld
= event
.GetOldSelection();
847 if ( selOld
== 2 && selNew
== 4 )
849 wxMessageBox("This demonstrates how a program may prevent the "
850 "page change from taking place - the current page will "
851 "stay the third one", "Conntrol sample",
852 wxICON_INFORMATION
| wxOK
);
858 *m_text
<< "Notebook selection is being changed from "
859 << selOld
<< " to " << selNew
<< "\n";
863 void MyPanel::OnPageChanged( wxNotebookEvent
&event
)
865 *m_text
<< "Notebook selection is " << event
.GetSelection() << "\n";
868 void MyPanel::OnListBox( wxCommandEvent
&event
)
870 m_text
->AppendText( "ListBox event selection string is: " );
871 m_text
->AppendText( event
.GetString() );
872 m_text
->AppendText( "\n" );
873 m_text
->AppendText( "ListBox control selection string is: " );
874 m_text
->AppendText( m_listbox
->GetStringSelection() );
875 m_text
->AppendText( "\n" );
878 void MyPanel::OnListBoxDoubleClick( wxCommandEvent
&event
)
880 m_text
->AppendText( "ListBox double click string is: " );
881 m_text
->AppendText( event
.GetString() );
882 m_text
->AppendText( "\n" );
885 void MyPanel::OnListBoxButtons( wxCommandEvent
&event
)
887 switch (event
.GetId())
889 case ID_LISTBOX_ENABLE
:
891 m_text
->AppendText("Checkbox clicked.\n");
892 wxCheckBox
*cb
= (wxCheckBox
*)event
.GetEventObject();
895 cb
->SetToolTip( "Click to enable listbox" );
897 cb
->SetToolTip( "Click to disable listbox" );
898 #endif // wxUSE_TOOLTIPS
899 m_listbox
->Enable( event
.GetInt() == 0 );
902 case ID_LISTBOX_SEL_NUM
:
904 m_listbox
->SetSelection( 2 );
905 m_lbSelectThis
->WarpPointer( 40, 14 );
908 case ID_LISTBOX_SEL_STR
:
910 m_listbox
->SetStringSelection( "This" );
911 m_lbSelectNum
->WarpPointer( 40, 14 );
914 case ID_LISTBOX_CLEAR
:
919 case ID_LISTBOX_APPEND
:
921 m_listbox
->Append( "Hi!" );
924 case ID_LISTBOX_DELETE
:
926 int idx
= m_listbox
->GetSelection();
927 m_listbox
->Delete( idx
);
930 case ID_LISTBOX_FONT
:
932 m_listbox
->SetFont( *wxITALIC_FONT
);
933 m_checkbox
->SetFont( *wxITALIC_FONT
);
939 void MyPanel::OnChoice( wxCommandEvent
&event
)
941 m_text
->AppendText( "Choice event selection string is: " );
942 m_text
->AppendText( event
.GetString() );
943 m_text
->AppendText( "\n" );
944 m_text
->AppendText( "Choice control selection string is: " );
945 m_text
->AppendText( m_choice
->GetStringSelection() );
946 m_text
->AppendText( "\n" );
949 void MyPanel::OnChoiceButtons( wxCommandEvent
&event
)
951 switch (event
.GetId())
953 case ID_CHOICE_ENABLE
:
955 m_choice
->Enable( event
.GetInt() == 0 );
958 case ID_CHOICE_SEL_NUM
:
960 m_choice
->SetSelection( 2 );
963 case ID_CHOICE_SEL_STR
:
965 m_choice
->SetStringSelection( "This" );
968 case ID_CHOICE_CLEAR
:
973 case ID_CHOICE_APPEND
:
975 m_choice
->Append( "Hi!" );
978 case ID_CHOICE_DELETE
:
980 int idx
= m_choice
->GetSelection();
981 m_choice
->Delete( idx
);
986 m_choice
->SetFont( *wxITALIC_FONT
);
992 void MyPanel::OnCombo( wxCommandEvent
&event
)
994 m_text
->AppendText( "ComboBox event selection string is: " );
995 m_text
->AppendText( event
.GetString() );
996 m_text
->AppendText( "\n" );
997 m_text
->AppendText( "ComboBox control selection string is: " );
998 m_text
->AppendText( m_combo
->GetStringSelection() );
999 m_text
->AppendText( "\n" );
1002 void MyPanel::OnComboButtons( wxCommandEvent
&event
)
1004 switch (event
.GetId())
1006 case ID_COMBO_ENABLE
:
1008 m_combo
->Enable( event
.GetInt() == 0 );
1011 case ID_COMBO_SEL_NUM
:
1013 m_combo
->SetSelection( 2 );
1016 case ID_COMBO_SEL_STR
:
1018 m_combo
->SetStringSelection( "This" );
1021 case ID_COMBO_CLEAR
:
1026 case ID_COMBO_APPEND
:
1028 m_combo
->Append( "Hi!" );
1031 case ID_COMBO_DELETE
:
1033 int idx
= m_combo
->GetSelection();
1034 m_combo
->Delete( idx
);
1039 m_combo
->SetFont( *wxITALIC_FONT
);
1045 void MyPanel::OnRadio( wxCommandEvent
&event
)
1047 m_text
->AppendText( "RadioBox selection string is: " );
1048 m_text
->AppendText( event
.GetString() );
1049 m_text
->AppendText( "\n" );
1052 void MyPanel::OnRadioButtons( wxCommandEvent
&event
)
1054 switch (event
.GetId())
1056 case ID_RADIOBOX_ENABLE
:
1058 m_radio
->Enable( event
.GetInt() == 0 );
1061 case ID_RADIOBOX_SEL_NUM
:
1063 m_radio
->SetSelection( 2 );
1066 case ID_RADIOBOX_SEL_STR
:
1068 m_radio
->SetStringSelection( "This" );
1071 case ID_RADIOBOX_FONT
:
1073 m_radio
->SetFont( *wxITALIC_FONT
);
1079 void MyPanel::OnSetFont( wxCommandEvent
&WXUNUSED(event
) )
1081 m_fontButton
->SetFont( *wxITALIC_FONT
);
1082 m_text
->SetFont( *wxITALIC_FONT
);
1085 void MyPanel::OnSliderUpdate( wxCommandEvent
&WXUNUSED(event
) )
1087 m_gauge
->SetValue( m_slider
->GetValue() );
1090 #ifndef wxUSE_SPINBUTTON
1091 void MyPanel::OnSpinUpdate( wxSpinEvent
&event
)
1094 value
.Printf( _T("%d"), event
.GetPosition() );
1095 m_spintext
->SetValue( value
);
1097 value
.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1098 m_spinbutton
->GetMin(), m_spinbutton
->GetMax(),
1099 m_spinbutton
->GetValue());
1101 m_text
->AppendText(value
);
1104 void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent
& event
)
1106 event
.Enable( m_spinbutton
->GetValue() > 0 );
1109 void MyPanel::OnShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1111 int max
= m_spinbutton
->GetValue();
1112 wxProgressDialog
dialog("Progress dialog example",
1113 "An informative message",
1116 wxPD_CAN_ABORT
| wxPD_APP_MODAL
);
1120 for ( int i
= 0; i
< max
&& cont
; i
++ )
1125 cont
= dialog
.Update(i
, "That's all, folks!");
1127 else if ( i
== max
/ 2 )
1129 cont
= dialog
.Update(i
, "Only a half left!");
1133 cont
= dialog
.Update(i
);
1139 *m_text
<< "Progress dialog aborted!\n";
1143 *m_text
<< "Countdown from " << max
<< " finished.\n";
1147 #endif // wxUSE_SPINBUTTON
1151 delete m_notebook
->GetImageList();
1154 //----------------------------------------------------------------------
1156 //----------------------------------------------------------------------
1158 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1159 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
1160 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
1162 EVT_MENU(MINIMAL_SET_TOOLTIP_DELAY
, MyFrame::OnSetTooltipDelay
)
1163 EVT_MENU(MINIMAL_ENABLE_TOOLTIPS
, MyFrame::OnToggleTooltips
)
1164 #endif // wxUSE_TOOLTIPS
1165 EVT_SIZE(MyFrame::OnSize
)
1166 EVT_IDLE(MyFrame::OnIdle
)
1169 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
)
1170 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
1174 (void)new MyPanel( this, 10, 10, 300, 100 );
1177 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
1182 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
1184 wxBeginBusyCursor();
1186 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);
1193 void MyFrame::OnSetTooltipDelay(wxCommandEvent
& event
)
1195 static long s_delay
= 5000;
1198 delay
.Printf( _T("%ld"), s_delay
);
1200 delay
= wxGetTextFromUser("Enter delay (in milliseconds)",
1201 "Set tooltip delay",
1205 return; // cancelled
1207 wxSscanf(delay
, _T("%ld"), &s_delay
);
1209 wxToolTip::SetDelay(s_delay
);
1211 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay
);
1214 void MyFrame::OnToggleTooltips(wxCommandEvent
& event
)
1216 static bool s_enabled
= TRUE
;
1218 s_enabled
= !s_enabled
;
1220 wxToolTip::Enable(s_enabled
);
1222 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled
? _T("en") : _T("dis") );
1226 void MyFrame::OnSize( wxSizeEvent
& event
)
1229 msg
.Printf( _("%dx%d"), event
.GetSize().x
, event
.GetSize().y
);
1230 SetStatusText(msg
, 1);
1235 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1237 // track the window which has the focus in the status bar
1238 static wxWindow
*s_windowFocus
= (wxWindow
*)NULL
;
1239 wxWindow
*focus
= wxWindow::FindFocus();
1240 if ( focus
&& (focus
!= s_windowFocus
) )
1242 s_windowFocus
= focus
;
1247 _T("Focus: wxWindow = %p, HWND = %08x"),
1249 _T("Focus: wxWindow = %p"),
1253 , s_windowFocus
->GetHWND()