]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/controls/controls.cpp
Added wxDbTable::SetOrderByColNums() function
[wxWidgets.git] / samples / controls / controls.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: controls.cpp
3// Purpose: Controls wxWindows sample
4// Author: Robert Roebling
5// Modified by:
6// RCS-ID: $Id$
7// Copyright: (c) Robert Roebling, Julian Smart
8// Licence: wxWindows license
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12 #pragma implementation "controls.h"
13#endif
14
15// For compilers that support precompilation, includes "wx/wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
22#ifndef WX_PRECOMP
23 #include "wx/wx.h"
24#endif
25
26#if !defined( __WXMSW__ ) || defined( __WIN95__ )
27#include "wx/spinbutt.h"
28#endif
29#include "wx/notebook.h"
30#include "wx/imaglist.h"
31
32#if wxUSE_TOOLTIPS
33 #include "wx/tooltip.h"
34#endif
35
36#if defined(__WXGTK__) || defined(__WXMOTIF__)
37 #define USE_XPM
38#endif
39
40#ifdef USE_XPM
41 #include "mondrian.xpm"
42 #include "icons/choice.xpm"
43 #include "icons/combo.xpm"
44 #include "icons/list.xpm"
45 #include "icons/radio.xpm"
46 #include "icons/text.xpm"
47 #include "icons/gauge.xpm"
48#endif
49
50#ifdef __WIN16__
51 // Win16 doesn't have them
52 #ifdef wxUSE_SPINBTN
53 #undef wxUSE_SPINBTN
54 #endif
55 #define wxUSE_SPINBTN 0
56#else
57 #ifndef wxUSE_SPINBTN
58 #define wxUSE_SPINBTN 1
59 #endif
60#endif // __WIN16__
61
62#include "wx/progdlg.h"
63
64#if wxUSE_SPINCTRL
65 #include "wx/spinctrl.h"
66#endif // wxUSE_SPINCTRL
67
68//----------------------------------------------------------------------
69// class definitions
70//----------------------------------------------------------------------
71
72class MyApp: public wxApp
73{
74public:
75 bool OnInit();
76};
77
78class MyPanel: public wxPanel
79{
80public:
81 MyPanel(wxFrame *frame, int x, int y, int w, int h);
82 virtual ~MyPanel();
83
84 void OnSize( wxSizeEvent& event );
85 void OnListBox( wxCommandEvent &event );
86 void OnListBoxDoubleClick( wxCommandEvent &event );
87 void OnListBoxButtons( wxCommandEvent &event );
88 void OnChoice( wxCommandEvent &event );
89 void OnChoiceButtons( wxCommandEvent &event );
90 void OnCombo( wxCommandEvent &event );
91 void OnComboTextChanged( wxCommandEvent &event );
92 void OnComboTextEnter( 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 OnPageChanging( wxNotebookEvent &event );
99 void OnSliderUpdate( wxCommandEvent &event );
100 void OnUpdateLabel( wxCommandEvent &event );
101#if wxUSE_SPINBTN
102 void OnSpinUp( wxSpinEvent &event );
103 void OnSpinDown( wxSpinEvent &event );
104 void OnSpinUpdate( wxSpinEvent &event );
105 void OnUpdateShowProgress( wxUpdateUIEvent& event );
106 void OnShowProgress( wxCommandEvent &event );
107#endif // wxUSE_SPINBTN
108
109#if wxUSE_SPINCTRL
110 void OnSpinCtrl(wxSpinEvent& event);
111#endif // wxUSE_SPINCTRL
112
113 void OnEnableAll(wxCommandEvent& event);
114 void OnChangeColour(wxCommandEvent& event);
115 void OnTestButton(wxCommandEvent& event);
116 void OnBmpButton(wxCommandEvent& event);
117
118 wxListBox *m_listbox,
119 *m_listboxSorted;
120 wxChoice *m_choice,
121 *m_choiceSorted;
122 wxComboBox *m_combo;
123 wxRadioBox *m_radio;
124 wxGauge *m_gauge;
125 wxSlider *m_slider;
126 wxButton *m_fontButton;
127 wxButton *m_lbSelectNum;
128 wxButton *m_lbSelectThis;
129#if wxUSE_SPINBTN
130 wxSpinButton *m_spinbutton;
131 wxButton *m_btnProgress;
132#endif // wxUSE_SPINBTN
133
134#if wxUSE_SPINCTRL
135 wxSpinCtrl *m_spinctrl;
136#endif // wxUSE_SPINCTRL
137
138 wxTextCtrl *m_spintext;
139 wxCheckBox *m_checkbox;
140
141 wxTextCtrl *m_text;
142 wxNotebook *m_notebook;
143
144 wxStaticText *m_label;
145
146private:
147 wxLog *m_logTargetOld;
148
149 DECLARE_EVENT_TABLE()
150};
151
152class MyFrame: public wxFrame
153{
154public:
155 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
156
157 void OnQuit(wxCommandEvent& event);
158 void OnAbout(wxCommandEvent& event);
159 void OnClearLog(wxCommandEvent& event);
160
161#if wxUSE_TOOLTIPS
162 void OnSetTooltipDelay(wxCommandEvent& event);
163 void OnToggleTooltips(wxCommandEvent& event);
164#endif // wxUSE_TOOLTIPS
165
166 void OnEnableAll(wxCommandEvent& event);
167
168 void OnIdle( wxIdleEvent& event );
169 void OnSize( wxSizeEvent& event );
170 void OnMove( wxMoveEvent& event );
171
172 MyPanel *GetPanel() const { return m_panel; }
173
174private:
175 void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
176 {
177 wxString msg;
178 msg.Printf(_("pos=(%d, %d), size=%dx%d"),
179 pos.x, pos.y, size.x, size.y);
180 SetStatusText(msg, 1);
181 }
182
183 MyPanel *m_panel;
184
185 DECLARE_EVENT_TABLE()
186};
187
188// a button which intercepts double clicks (for testing...)
189class MyButton : public wxButton
190{
191public:
192 MyButton(wxWindow *parent,
193 wxWindowID id,
194 const wxString& label = wxEmptyString,
195 const wxPoint& pos = wxDefaultPosition,
196 const wxSize& size = wxDefaultSize)
197 : wxButton(parent, id, label, pos, size)
198 {
199 }
200
201 void OnDClick(wxMouseEvent& event)
202 {
203 wxLogMessage(_T("MyButton::OnDClick"));
204
205 event.Skip();
206 }
207
208private:
209 DECLARE_EVENT_TABLE()
210};
211
212// a combo which intercepts chars (to test Windows behaviour)
213class MyComboBox : public wxComboBox
214{
215public:
216 MyComboBox(wxWindow *parent, wxWindowID id,
217 const wxString& value = wxEmptyString,
218 const wxPoint& pos = wxDefaultPosition,
219 const wxSize& size = wxDefaultSize,
220 int n = 0, const wxString choices[] = NULL,
221 long style = 0,
222 const wxValidator& validator = wxDefaultValidator,
223 const wxString& name = wxComboBoxNameStr)
224 : wxComboBox(parent, id, value, pos, size, n, choices, style,
225 validator, name) { }
226
227protected:
228 void OnChar(wxKeyEvent& event);
229 void OnKeyDown(wxKeyEvent& event);
230 void OnKeyUp(wxKeyEvent& event);
231 void OnFocusGot(wxFocusEvent& event)
232 {
233 wxLogMessage(_T("MyComboBox::OnFocusGot"));
234
235 event.Skip();
236 }
237
238private:
239 DECLARE_EVENT_TABLE()
240};
241
242// a radiobox which handles focus set/kill (for testing)
243class MyRadioBox : public wxRadioBox
244{
245public:
246 MyRadioBox(wxWindow *parent,
247 wxWindowID id,
248 const wxString& title = wxEmptyString,
249 const wxPoint& pos = wxDefaultPosition,
250 const wxSize& size = wxDefaultSize,
251 int n = 0, const wxString choices[] = NULL,
252 int majorDim = 1,
253 long style = wxRA_HORIZONTAL,
254 const wxValidator& validator = wxDefaultValidator,
255 const wxString& name = wxComboBoxNameStr)
256 : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
257 style, validator, name) { }
258
259protected:
260 void OnFocusGot(wxFocusEvent& event)
261 {
262 wxLogMessage(_T("MyRadioBox::OnFocusGot"));
263
264 event.Skip();
265 }
266
267 void OnFocusLost(wxFocusEvent& event)
268 {
269 wxLogMessage(_T("MyRadioBox::OnFocusLost"));
270
271 event.Skip();
272 }
273
274private:
275 DECLARE_EVENT_TABLE()
276};
277
278//----------------------------------------------------------------------
279// other
280//----------------------------------------------------------------------
281
282static void SetControlClientData(const char *name,
283 wxControlWithItems *control);
284
285IMPLEMENT_APP(MyApp)
286
287//----------------------------------------------------------------------
288// MyApp
289//----------------------------------------------------------------------
290
291enum
292{
293 CONTROLS_QUIT = 100,
294 CONTROLS_TEXT,
295 CONTROLS_ABOUT,
296 CONTROLS_CLEAR_LOG,
297
298 // tooltip menu
299 CONTROLS_SET_TOOLTIP_DELAY = 200,
300 CONTROLS_ENABLE_TOOLTIPS,
301
302 // panel menu
303 CONTROLS_ENABLE_ALL
304};
305
306bool MyApp::OnInit()
307{
308 // parse the cmd line
309 int x = 50,
310 y = 50;
311 if ( argc == 3 )
312 {
313 wxSscanf(argv[1], "%d", &x);
314 wxSscanf(argv[2], "%d", &y);
315 }
316
317 // Create the main frame window
318 MyFrame *frame = new MyFrame((wxFrame *) NULL,
319 "Controls wxWindows App",
320 x, y, 540, 430);
321
322 frame->SetSizeHints( 500, 425 );
323
324 // Give it an icon
325 // The wxICON() macros loads an icon from a resource under Windows
326 // and uses an #included XPM image under GTK+ and Motif
327
328 frame->SetIcon( wxICON(mondrian) );
329
330 wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF);
331
332 file_menu->Append(CONTROLS_CLEAR_LOG, "&Clear log\tCtrl-L");
333 file_menu->AppendSeparator();
334 file_menu->Append(CONTROLS_ABOUT, "&About\tF1");
335 file_menu->AppendSeparator();
336 file_menu->Append(CONTROLS_QUIT, "E&xit\tAlt-X", "Quit controls sample");
337
338 wxMenuBar *menu_bar = new wxMenuBar;
339 menu_bar->Append(file_menu, "&File");
340
341#if wxUSE_TOOLTIPS
342 wxMenu *tooltip_menu = new wxMenu;
343 tooltip_menu->Append(CONTROLS_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
344 tooltip_menu->AppendSeparator();
345 tooltip_menu->Append(CONTROLS_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
346 "enable/disable tooltips", TRUE);
347 tooltip_menu->Check(CONTROLS_ENABLE_TOOLTIPS, TRUE);
348 menu_bar->Append(tooltip_menu, "&Tooltips");
349#endif // wxUSE_TOOLTIPS
350
351 wxMenu *panel_menu = new wxMenu;
352 panel_menu->Append(CONTROLS_ENABLE_ALL, "&Disable all\tCtrl-E",
353 "Enable/disable all panel controls", TRUE);
354 menu_bar->Append(panel_menu, "&Panel");
355
356 frame->SetMenuBar(menu_bar);
357
358 frame->Show(TRUE);
359
360 //frame->GetPanel()->m_notebook->SetSelection(6);
361
362 SetTopWindow(frame);
363
364 return TRUE;
365}
366
367//----------------------------------------------------------------------
368// MyPanel
369//----------------------------------------------------------------------
370
371const int ID_NOTEBOOK = 1000;
372
373const int ID_LISTBOX = 130;
374const int ID_LISTBOX_SEL_NUM = 131;
375const int ID_LISTBOX_SEL_STR = 132;
376const int ID_LISTBOX_CLEAR = 133;
377const int ID_LISTBOX_APPEND = 134;
378const int ID_LISTBOX_DELETE = 135;
379const int ID_LISTBOX_FONT = 136;
380const int ID_LISTBOX_ENABLE = 137;
381const int ID_LISTBOX_SORTED = 138;
382
383const int ID_CHOICE = 120;
384const int ID_CHOICE_SEL_NUM = 121;
385const int ID_CHOICE_SEL_STR = 122;
386const int ID_CHOICE_CLEAR = 123;
387const int ID_CHOICE_APPEND = 124;
388const int ID_CHOICE_DELETE = 125;
389const int ID_CHOICE_FONT = 126;
390const int ID_CHOICE_ENABLE = 127;
391const int ID_CHOICE_SORTED = 128;
392
393const int ID_COMBO = 140;
394const int ID_COMBO_SEL_NUM = 141;
395const int ID_COMBO_SEL_STR = 142;
396const int ID_COMBO_CLEAR = 143;
397const int ID_COMBO_APPEND = 144;
398const int ID_COMBO_DELETE = 145;
399const int ID_COMBO_FONT = 146;
400const int ID_COMBO_ENABLE = 147;
401
402const int ID_RADIOBOX = 160;
403const int ID_RADIOBOX_SEL_NUM = 161;
404const int ID_RADIOBOX_SEL_STR = 162;
405const int ID_RADIOBOX_FONT = 163;
406const int ID_RADIOBOX_ENABLE = 164;
407
408const int ID_RADIOBUTTON_1 = 166;
409const int ID_RADIOBUTTON_2 = 167;
410
411const int ID_SET_FONT = 170;
412
413const int ID_GAUGE = 180;
414const int ID_SLIDER = 181;
415
416const int ID_SPIN = 182;
417const int ID_BTNPROGRESS = 183;
418const int ID_BUTTON_LABEL = 184;
419const int ID_SPINCTRL = 185;
420
421const int ID_BUTTON_TEST1 = 190;
422const int ID_BUTTON_TEST2 = 191;
423const int ID_BITMAP_BTN = 192;
424
425const int ID_CHANGE_COLOUR = 200;
426
427BEGIN_EVENT_TABLE(MyPanel, wxPanel)
428EVT_SIZE ( MyPanel::OnSize)
429EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
430EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
431EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox)
432EVT_LISTBOX (ID_LISTBOX_SORTED, MyPanel::OnListBox)
433EVT_LISTBOX_DCLICK(ID_LISTBOX, MyPanel::OnListBoxDoubleClick)
434EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyPanel::OnListBoxButtons)
435EVT_BUTTON (ID_LISTBOX_SEL_STR, MyPanel::OnListBoxButtons)
436EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
437EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
438EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
439EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
440EVT_CHECKBOX (ID_LISTBOX_ENABLE, MyPanel::OnListBoxButtons)
441EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
442EVT_CHOICE (ID_CHOICE_SORTED, MyPanel::OnChoice)
443EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
444EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
445EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
446EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
447EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
448EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
449EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
450EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
451EVT_TEXT (ID_COMBO, MyPanel::OnComboTextChanged)
452EVT_TEXT_ENTER(ID_COMBO, MyPanel::OnComboTextEnter)
453EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
454EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
455EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
456EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
457EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
458EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
459EVT_CHECKBOX (ID_COMBO_ENABLE, MyPanel::OnComboButtons)
460EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
461EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
462EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
463EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
464EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
465EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
466EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
467#if wxUSE_SPINBTN
468EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
469EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp)
470EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown)
471EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
472EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
473#endif // wxUSE_SPINBTN
474#if wxUSE_SPINCTRL
475EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl)
476#endif // wxUSE_SPINCTRL
477EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel)
478EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
479EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
480EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
481EVT_BUTTON (ID_BITMAP_BTN, MyPanel::OnBmpButton)
482END_EVENT_TABLE()
483
484BEGIN_EVENT_TABLE(MyButton, wxButton)
485 EVT_LEFT_DCLICK(MyButton::OnDClick)
486END_EVENT_TABLE()
487
488BEGIN_EVENT_TABLE(MyComboBox, wxComboBox)
489 EVT_CHAR(MyComboBox::OnChar)
490 EVT_KEY_DOWN(MyComboBox::OnKeyDown)
491 EVT_KEY_UP(MyComboBox::OnKeyUp)
492
493 EVT_SET_FOCUS(MyComboBox::OnFocusGot)
494END_EVENT_TABLE()
495
496BEGIN_EVENT_TABLE(MyRadioBox, wxRadioBox)
497 EVT_SET_FOCUS(MyRadioBox::OnFocusGot)
498 EVT_KILL_FOCUS(MyRadioBox::OnFocusLost)
499END_EVENT_TABLE()
500
501// ============================================================================
502// implementation
503// ============================================================================
504
505MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
506 : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
507 m_text(NULL), m_notebook(NULL)
508{
509 wxLayoutConstraints *c;
510
511 m_text = new wxTextCtrl(this, -1, "This is the log window.\n",
512 wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
513 m_text->SetBackgroundColour("wheat");
514
515 if ( 0 )
516 wxLog::AddTraceMask(_T("focus"));
517 m_logTargetOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
518
519 m_notebook = new wxNotebook(this, ID_NOTEBOOK);
520
521 wxString choices[] =
522 {
523 "This",
524 "is one of my",
525 "really",
526 "wonderful",
527 "examples."
528 };
529
530#ifdef USE_XPM
531 // image ids
532 enum
533 {
534 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
535 };
536
537 // fill the image list
538 wxImageList *imagelist = new wxImageList(32, 32);
539
540 imagelist-> Add( wxBitmap( list_xpm ));
541 imagelist-> Add( wxBitmap( choice_xpm ));
542 imagelist-> Add( wxBitmap( combo_xpm ));
543 imagelist-> Add( wxBitmap( text_xpm ));
544 imagelist-> Add( wxBitmap( radio_xpm ));
545 imagelist-> Add( wxBitmap( gauge_xpm ));
546 m_notebook->SetImageList(imagelist);
547#elif defined(__WXMSW__)
548 // load images from resources
549 enum
550 {
551 Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max
552 };
553 wxImageList *imagelist = new wxImageList(16, 16, FALSE, Image_Max);
554
555 static const char *s_iconNames[Image_Max] =
556 {
557 "list", "choice", "combo", "text", "radio", "gauge"
558 };
559
560 for ( size_t n = 0; n < Image_Max; n++ )
561 {
562 wxBitmap bmp(s_iconNames[n]);
563 if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
564 {
565 wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
566 s_iconNames[n], n);
567 }
568 }
569
570 m_notebook->SetImageList(imagelist);
571#else
572
573 // No images for now
574#define Image_List -1
575#define Image_Choice -1
576#define Image_Combo -1
577#define Image_Text -1
578#define Image_Radio -1
579#define Image_Gauge -1
580#define Image_Max -1
581
582#endif
583
584 wxPanel *panel = new wxPanel(m_notebook);
585 m_listbox = new wxListBox( panel, ID_LISTBOX,
586 wxPoint(10,10), wxSize(120,70),
587 5, choices, wxLB_ALWAYS_SB );
588 m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
589 wxPoint(10,90), wxSize(120,70),
590 5, choices, wxLB_SORT );
591
592 SetControlClientData("listbox", m_listbox);
593 SetControlClientData("listbox", m_listboxSorted);
594
595 m_listbox->SetCursor(*wxCROSS_CURSOR);
596#if wxUSE_TOOLTIPS
597 m_listbox->SetToolTip( "This is a list box" );
598#endif // wxUSE_TOOLTIPS
599
600 m_lbSelectNum = new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
601 m_lbSelectThis = new wxButton( panel, ID_LISTBOX_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
602 (void)new wxButton( panel, ID_LISTBOX_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
603 (void)new MyButton( panel, ID_LISTBOX_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
604 (void)new wxButton( panel, ID_LISTBOX_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
605 wxButton *button = new MyButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
606
607 button->SetDefault();
608
609 button->SetForegroundColour(*wxBLUE);
610
611#if wxUSE_TOOLTIPS
612 button->SetToolTip( "Press here to set italic font" );
613#endif // wxUSE_TOOLTIPS
614
615 m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,170) );
616 m_checkbox->SetValue(FALSE);
617#if wxUSE_TOOLTIPS
618 m_checkbox->SetToolTip( "Click here to disable the listbox" );
619#endif // wxUSE_TOOLTIPS
620 (void)new wxCheckBox( panel, ID_CHANGE_COLOUR, "&Toggle colour",
621 wxPoint(110,170) );
622 panel->SetCursor(wxCursor(wxCURSOR_HAND));
623 m_notebook->AddPage(panel, "wxListBox", TRUE, Image_List);
624
625 panel = new wxPanel(m_notebook);
626 m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
627 m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
628 5, choices, wxCB_SORT );
629
630 SetControlClientData("choice", m_choice);
631 SetControlClientData("choice", m_choiceSorted);
632
633 m_choice->SetSelection(2);
634 m_choice->SetBackgroundColour( "red" );
635 (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
636 (void)new wxButton( panel, ID_CHOICE_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
637 (void)new wxButton( panel, ID_CHOICE_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
638 (void)new wxButton( panel, ID_CHOICE_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
639 (void)new wxButton( panel, ID_CHOICE_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
640 (void)new wxButton( panel, ID_CHOICE_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
641 (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "&Disable", wxPoint(20,130), wxSize(140,30) );
642
643 m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
644
645 panel = new wxPanel(m_notebook);
646 (void)new wxStaticBox( panel, -1, "&Box around combobox",
647 wxPoint(5, 5), wxSize(150, 100));
648 m_combo = new MyComboBox( panel, ID_COMBO, "This",
649 wxPoint(20,25), wxSize(120, -1),
650 5, choices,
651 /* wxCB_READONLY | */ wxPROCESS_ENTER);
652
653 (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
654 (void)new wxButton( panel, ID_COMBO_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
655 (void)new wxButton( panel, ID_COMBO_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
656 (void)new wxButton( panel, ID_COMBO_APPEND, "&Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
657 (void)new wxButton( panel, ID_COMBO_DELETE, "D&elete selected item", wxPoint(180,130), wxSize(140,30) );
658 (void)new wxButton( panel, ID_COMBO_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) );
659 (void)new wxCheckBox( panel, ID_COMBO_ENABLE, "&Disable", wxPoint(20,130), wxSize(140,30) );
660 m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
661
662 wxString choices2[] =
663 {
664 "First", "Second",
665 /* "Third",
666 "Fourth", "Fifth", "Sixth",
667 "Seventh", "Eighth", "Nineth", "Tenth" */
668 };
669
670 panel = new wxPanel(m_notebook);
671 (void)new MyRadioBox( panel, ID_RADIOBOX, "&That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
672 m_radio = new wxRadioBox( panel, ID_RADIOBOX, "T&his", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
673
674#if wxUSE_TOOLTIPS
675 m_combo->SetToolTip("This is a natural\ncombobox - can you believe me?");
676 m_radio->SetToolTip("Ever seen a radiobox?");
677#endif // wxUSE_TOOLTIPS
678
679 (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
680 (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "&Select 'This'", wxPoint(180,80), wxSize(140,30) );
681 m_fontButton = new wxButton( panel, ID_SET_FONT, "Set &more Italic font", wxPoint(340,30), wxSize(140,30) );
682 (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set &Italic font", wxPoint(340,80), wxSize(140,30) );
683 (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "&Disable", wxPoint(340,130), wxDefaultSize );
684 wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxDefaultSize, wxRB_GROUP );
685 rb->SetValue( FALSE );
686 (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "&Radiobutton2", wxPoint(340,170), wxDefaultSize );
687 m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
688
689 panel = new wxPanel(m_notebook);
690 (void)new wxStaticBox( panel, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
691 m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
692 m_gauge->SetBackgroundColour(*wxGREEN);
693 m_gauge->SetForegroundColour(*wxRED);
694 m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
695 (void)new wxStaticBox( panel, -1, "&Explanation", wxPoint(220,10), wxSize(270,130) );
696#ifdef __WXMOTIF__
697 // No wrapping text in wxStaticText yet :-(
698 (void)new wxStaticText( panel, -1,
699 "Drag the slider!",
700 wxPoint(228,30),
701 wxSize(240, -1)
702 );
703#else
704 (void)new wxStaticText( panel, -1,
705 "In order see the gauge (aka progress bar)\n"
706 "control do something you have to drag the\n"
707 "handle of the slider to the right.\n"
708 "\n"
709 "This is also supposed to demonstrate how\n"
710 "to use static controls.\n",
711 wxPoint(228,25),
712 wxSize(240, 110)
713 );
714#endif
715 int initialSpinValue = -5;
716 wxString s;
717 s << initialSpinValue;
718 m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) );
719#if wxUSE_SPINBTN
720 m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(80, -1) );
721 m_spinbutton->SetRange(-10,30);
722 m_spinbutton->SetValue(initialSpinValue);
723
724 m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "&Show progress dialog",
725 wxPoint(300, 160) );
726#endif // wxUSE_SPINBTN
727
728#if wxUSE_SPINCTRL
729 m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) );
730 m_spinctrl->SetRange(10,30);
731 m_spinctrl->SetValue(15);
732#endif // wxUSE_SPINCTRL
733
734 m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
735
736 panel = new wxPanel(m_notebook);
737
738#if !defined(__WXMOTIF__) && !defined(__WIN16__) // wxStaticBitmap not working under Motif yet; and icons not allowed under WIN16.
739 wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
740 wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
741 wxPoint(10, 10));
742
743 bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
744 bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
745#endif // !Motif
746
747 wxBitmap bitmap( 100, 100 );
748 wxMemoryDC dc;
749 dc.SelectObject( bitmap );
750 dc.SetPen(*wxGREEN_PEN);
751 dc.Clear();
752 dc.DrawEllipse(5, 5, 90, 90);
753 dc.DrawText("Bitmap", 30, 40);
754 dc.SelectObject( wxNullBitmap );
755
756 (void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20));
757
758#ifdef __WXMSW__
759 // test for masked bitmap display
760 bitmap = wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP);
761 if (bitmap.Ok())
762 {
763 bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
764
765 (void)new wxStaticBitmap /* wxBitmapButton */ (panel, -1, bitmap, wxPoint(300, 120));
766 }
767#endif
768
769 wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
770 bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
771 bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
772 wxBitmapButton *bmpBtn = new wxBitmapButton
773 (
774 panel, -1,
775 bmp1,
776 wxPoint(30, 50)
777 );
778 bmpBtn->SetBitmapSelected(bmp2);
779 bmpBtn->SetBitmapFocus(bmp3);
780
781 (void)new wxButton(panel, ID_BUTTON_LABEL, "&Toggle label", wxPoint(250, 20));
782 m_label = new wxStaticText(panel, -1, "Label with some long text",
783 wxPoint(250, 60), wxDefaultSize,
784 wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
785 m_label->SetForegroundColour( *wxBLUE );
786
787 m_notebook->AddPage(panel, "wxBitmapXXX");
788
789 // layout constraints
790
791 panel = new wxPanel(m_notebook);
792 panel->SetAutoLayout( TRUE );
793
794 c = new wxLayoutConstraints;
795 c->top.SameAs( panel, wxTop, 10 );
796 c->height.AsIs( );
797 c->left.SameAs( panel, wxLeft, 10 );
798 c->width.PercentOf( panel, wxWidth, 40 );
799
800 wxButton *pMyButton = new wxButton(panel, ID_BUTTON_TEST1, "Test Button &1" );
801 pMyButton->SetConstraints( c );
802
803 c = new wxLayoutConstraints;
804 c->top.SameAs( panel, wxTop, 10 );
805 c->bottom.SameAs( panel, wxBottom, 10 );
806 c->right.SameAs( panel, wxRight, 10 );
807 c->width.PercentOf( panel, wxWidth, 40 );
808
809 wxButton *pMyButton2 = new wxButton(panel, ID_BUTTON_TEST2, "Test Button &2" );
810 pMyButton2->SetConstraints( c );
811
812 m_notebook->AddPage(panel, "wxLayoutConstraint");
813
814 // sizer
815
816 panel = new wxPanel(m_notebook);
817 panel->SetAutoLayout( TRUE );
818
819 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
820
821 sizer->Add( new wxButton(panel, -1, "Test Button &1" ), 3, wxALL, 10 );
822 sizer->Add( 20,20, 1 );
823 sizer->Add( new wxButton(panel, -1, "Test Button &2" ), 3, wxGROW|wxALL, 10 );
824
825 panel->SetSizer( sizer );
826
827 m_notebook->AddPage(panel, "wxSizer");
828}
829
830void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
831{
832 int x = 0;
833 int y = 0;
834 GetClientSize( &x, &y );
835
836 if (m_notebook) m_notebook->SetSize( 2, 2, x-4, y*2/3-4 );
837 if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 );
838}
839
840void MyPanel::OnPageChanging( wxNotebookEvent &event )
841{
842 int selOld = event.GetOldSelection();
843 if ( selOld == 2 )
844 {
845 if ( wxMessageBox("This demonstrates how a program may prevent the\n"
846 "page change from taking place - if you select\n"
847 "[No] the current page will stay the third one\n",
848 "Control sample",
849 wxICON_QUESTION | wxYES_NO, this) != wxYES )
850 {
851 event.Veto();
852
853 return;
854 }
855 }
856
857 *m_text << "Notebook selection is being changed from " << selOld << "\n";
858}
859
860void MyPanel::OnPageChanged( wxNotebookEvent &event )
861{
862 *m_text << "Notebook selection is " << event.GetSelection() << "\n";
863}
864
865void MyPanel::OnTestButton(wxCommandEvent& event)
866{
867 wxLogMessage(_T("Button %c clicked."),
868 event.GetId() == ID_BUTTON_TEST1 ? _T('1') : _T('2'));
869}
870
871void MyPanel::OnBmpButton(wxCommandEvent& event)
872{
873 wxLogMessage(_T("Bitmap button clicked."));
874}
875
876void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
877{
878 static wxColour s_colOld;
879
880 // test panel colour changing and propagation to the subcontrols
881 if ( s_colOld.Ok() )
882 {
883 SetBackgroundColour(s_colOld);
884 s_colOld = wxNullColour;
885
886 m_lbSelectThis->SetForegroundColour("red");
887 m_lbSelectThis->SetBackgroundColour("white");
888 }
889 else
890 {
891 s_colOld = wxColour("red");
892 SetBackgroundColour("white");
893
894 m_lbSelectThis->SetForegroundColour("white");
895 m_lbSelectThis->SetBackgroundColour("red");
896 }
897
898 m_lbSelectThis->Refresh();
899 Refresh();
900}
901
902void MyPanel::OnListBox( wxCommandEvent &event )
903{
904// GetParent()->Move(100, 100);
905
906 if (event.GetInt() == -1)
907 {
908 m_text->AppendText( "ListBox has no selections anymore\n" );
909 return;
910 }
911
912 wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
913 : m_listboxSorted;
914
915 m_text->AppendText( "ListBox event selection string is: '" );
916 m_text->AppendText( event.GetString() );
917 m_text->AppendText( "'\n" );
918 m_text->AppendText( "ListBox control selection string is: '" );
919 m_text->AppendText( listbox->GetStringSelection() );
920 m_text->AppendText( "'\n" );
921
922 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
923 m_text->AppendText( "ListBox event client data string is: '" );
924 if (obj) // BC++ doesn't like use of '? .. : .. ' in this context
925 m_text->AppendText( obj->GetData() );
926 else
927 m_text->AppendText( wxString("none") );
928
929 m_text->AppendText( "'\n" );
930 m_text->AppendText( "ListBox control client data string is: '" );
931 obj = (wxStringClientData *)listbox->GetClientObject(listbox->GetSelection());
932 if (obj)
933 m_text->AppendText( obj->GetData() );
934 else
935 m_text->AppendText( wxString("none") );
936 m_text->AppendText( "'\n" );
937}
938
939void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
940{
941 m_text->AppendText( "ListBox double click string is: " );
942 m_text->AppendText( event.GetString() );
943 m_text->AppendText( "\n" );
944}
945
946void MyPanel::OnListBoxButtons( wxCommandEvent &event )
947{
948 switch (event.GetId())
949 {
950 case ID_LISTBOX_ENABLE:
951 {
952 m_text->AppendText("Checkbox clicked.\n");
953 wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
954#if wxUSE_TOOLTIPS
955 if (event.GetInt())
956 cb->SetToolTip( "Click to enable listbox" );
957 else
958 cb->SetToolTip( "Click to disable listbox" );
959#endif // wxUSE_TOOLTIPS
960 m_listbox->Enable( event.GetInt() == 0 );
961 m_lbSelectThis->Enable( event.GetInt() == 0 );
962 m_lbSelectNum->Enable( event.GetInt() == 0 );
963 m_listboxSorted->Enable( event.GetInt() == 0 );
964 FindWindow(ID_CHANGE_COLOUR)->Enable( event.GetInt() == 0 );
965 break;
966 }
967 case ID_LISTBOX_SEL_NUM:
968 {
969 m_listbox->SetSelection( 2 );
970 m_listboxSorted->SetSelection( 2 );
971 m_lbSelectThis->WarpPointer( 40, 14 );
972 break;
973 }
974 case ID_LISTBOX_SEL_STR:
975 {
976 m_listbox->SetStringSelection( "This" );
977 m_listboxSorted->SetStringSelection( "This" );
978 m_lbSelectNum->WarpPointer( 40, 14 );
979 break;
980 }
981 case ID_LISTBOX_CLEAR:
982 {
983 m_listbox->Clear();
984 m_listboxSorted->Clear();
985 break;
986 }
987 case ID_LISTBOX_APPEND:
988 {
989 m_listbox->Append( "Hi!" );
990 m_listboxSorted->Append( "Hi!" );
991 break;
992 }
993 case ID_LISTBOX_DELETE:
994 {
995 int idx;
996 idx = m_listbox->GetSelection();
997 if ( idx != wxNOT_FOUND )
998 m_listbox->Delete( idx );
999 idx = m_listboxSorted->GetSelection();
1000 if ( idx != wxNOT_FOUND )
1001 m_listboxSorted->Delete( idx );
1002 break;
1003 }
1004 case ID_LISTBOX_FONT:
1005 {
1006 m_listbox->SetFont( *wxITALIC_FONT );
1007 m_listboxSorted->SetFont( *wxITALIC_FONT );
1008 m_checkbox->SetFont( *wxITALIC_FONT );
1009 break;
1010 }
1011 }
1012}
1013
1014void MyPanel::OnChoice( wxCommandEvent &event )
1015{
1016 wxChoice *choice = event.GetId() == ID_CHOICE ? m_choice
1017 : m_choiceSorted;
1018
1019 m_text->AppendText( "Choice event selection string is: '" );
1020 m_text->AppendText( event.GetString() );
1021 m_text->AppendText( "'\n" );
1022 m_text->AppendText( "Choice control selection string is: '" );
1023 m_text->AppendText( choice->GetStringSelection() );
1024 m_text->AppendText( "'\n" );
1025
1026 wxStringClientData *obj = ((wxStringClientData *)event.GetClientObject());
1027 m_text->AppendText( "Choice event client data string is: '" );
1028
1029 if (obj)
1030 m_text->AppendText( obj->GetData() );
1031 else
1032 m_text->AppendText( wxString("none") );
1033
1034 m_text->AppendText( "'\n" );
1035 m_text->AppendText( "Choice control client data string is: '" );
1036 obj = (wxStringClientData *)choice->GetClientObject(choice->GetSelection());
1037
1038 if (obj)
1039 m_text->AppendText( obj->GetData() );
1040 else
1041 m_text->AppendText( wxString("none") );
1042 m_text->AppendText( "'\n" );
1043}
1044
1045void MyPanel::OnChoiceButtons( wxCommandEvent &event )
1046{
1047 switch (event.GetId())
1048 {
1049 case ID_CHOICE_ENABLE:
1050 {
1051 m_choice->Enable( event.GetInt() == 0 );
1052 m_choiceSorted->Enable( event.GetInt() == 0 );
1053 break;
1054 }
1055 case ID_CHOICE_SEL_NUM:
1056 {
1057 m_choice->SetSelection( 2 );
1058 m_choiceSorted->SetSelection( 2 );
1059 break;
1060 }
1061 case ID_CHOICE_SEL_STR:
1062 {
1063 m_choice->SetStringSelection( "This" );
1064 m_choiceSorted->SetStringSelection( "This" );
1065 break;
1066 }
1067 case ID_CHOICE_CLEAR:
1068 {
1069 m_choice->Clear();
1070 m_choiceSorted->Clear();
1071 break;
1072 }
1073 case ID_CHOICE_APPEND:
1074 {
1075 m_choice->Append( "Hi!" );
1076 m_choiceSorted->Append( "Hi!" );
1077 break;
1078 }
1079 case ID_CHOICE_DELETE:
1080 {
1081 int idx = m_choice->GetSelection();
1082 if ( idx != wxNOT_FOUND )
1083 m_choice->Delete( idx );
1084 idx = m_choiceSorted->GetSelection();
1085 if ( idx != wxNOT_FOUND )
1086 m_choiceSorted->Delete( idx );
1087 break;
1088 }
1089 case ID_CHOICE_FONT:
1090 {
1091 m_choice->SetFont( *wxITALIC_FONT );
1092 m_choiceSorted->SetFont( *wxITALIC_FONT );
1093 break;
1094 }
1095 }
1096}
1097
1098void MyPanel::OnCombo( wxCommandEvent &event )
1099{
1100 m_text->AppendText( "ComboBox event selection string is: " );
1101 m_text->AppendText( event.GetString() );
1102 m_text->AppendText( "\n" );
1103 m_text->AppendText( "ComboBox control selection string is: " );
1104 m_text->AppendText( m_combo->GetStringSelection() );
1105 m_text->AppendText( "\n" );
1106}
1107
1108void MyPanel::OnComboTextChanged(wxCommandEvent& WXUNUSED(event))
1109{
1110 wxLogMessage(_T("Text in the combobox changed: now is '%s'."),
1111 m_combo->GetValue().c_str());
1112}
1113
1114void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))
1115{
1116 wxLogMessage(_T("Enter pressed in the combobox: value is '%s'."),
1117 m_combo->GetValue().c_str());
1118}
1119
1120void MyPanel::OnComboButtons( wxCommandEvent &event )
1121{
1122 switch (event.GetId())
1123 {
1124 case ID_COMBO_ENABLE:
1125 {
1126 m_combo->Enable( event.GetInt() == 0 );
1127 break;
1128 }
1129 case ID_COMBO_SEL_NUM:
1130 {
1131 m_combo->SetSelection( 2 );
1132 break;
1133 }
1134 case ID_COMBO_SEL_STR:
1135 {
1136 m_combo->SetStringSelection( "This" );
1137 break;
1138 }
1139 case ID_COMBO_CLEAR:
1140 {
1141 m_combo->Clear();
1142 break;
1143 }
1144 case ID_COMBO_APPEND:
1145 {
1146 m_combo->Append( "Hi!" );
1147 break;
1148 }
1149 case ID_COMBO_DELETE:
1150 {
1151 int idx = m_combo->GetSelection();
1152 m_combo->Delete( idx );
1153 break;
1154 }
1155 case ID_COMBO_FONT:
1156 {
1157 m_combo->SetFont( *wxITALIC_FONT );
1158 break;
1159 }
1160 }
1161}
1162
1163void MyPanel::OnRadio( wxCommandEvent &event )
1164{
1165 m_text->AppendText( "RadioBox selection string is: " );
1166 m_text->AppendText( event.GetString() );
1167 m_text->AppendText( "\n" );
1168}
1169
1170void MyPanel::OnRadioButtons( wxCommandEvent &event )
1171{
1172 switch (event.GetId())
1173 {
1174 case ID_RADIOBOX_ENABLE:
1175 {
1176 m_radio->Enable( event.GetInt() == 0 );
1177 break;
1178 }
1179 case ID_RADIOBOX_SEL_NUM:
1180 {
1181 m_radio->SetSelection( 2 );
1182 break;
1183 }
1184 case ID_RADIOBOX_SEL_STR:
1185 {
1186 m_radio->SetStringSelection( "This" );
1187 break;
1188 }
1189 case ID_RADIOBOX_FONT:
1190 {
1191 m_radio->SetFont( *wxITALIC_FONT );
1192 break;
1193 }
1194 }
1195}
1196
1197void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
1198{
1199 m_fontButton->SetFont( *wxITALIC_FONT );
1200 m_text->SetFont( *wxITALIC_FONT );
1201}
1202
1203void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
1204{
1205 static bool s_long = TRUE;
1206
1207 s_long = !s_long;
1208 m_label->SetLabel(s_long ? "Very very very very very long text." : "Shorter text.");
1209}
1210
1211void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
1212{
1213 m_gauge->SetValue( m_slider->GetValue() );
1214}
1215
1216#if wxUSE_SPINCTRL
1217
1218void MyPanel::OnSpinCtrl(wxSpinEvent& event)
1219{
1220 wxString s;
1221 s.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"),
1222 m_spinctrl->GetValue(), event.GetInt());
1223 m_text->AppendText(s);
1224}
1225
1226#endif // wxUSE_SPINCTRL
1227
1228#if wxUSE_SPINBTN
1229void MyPanel::OnSpinUp( wxSpinEvent &event )
1230{
1231 wxString value;
1232 value.Printf( _T("Spin control up: current = %d\n"),
1233 m_spinbutton->GetValue());
1234
1235 if ( m_spinbutton->GetValue() > 17 )
1236 {
1237 value += _T("Preventing the spin button from going above 17.\n");
1238
1239 event.Veto();
1240 }
1241
1242 m_text->AppendText(value);
1243}
1244
1245void MyPanel::OnSpinDown( wxSpinEvent &event )
1246{
1247 wxString value;
1248 value.Printf( _T("Spin control down: current = %d\n"),
1249 m_spinbutton->GetValue());
1250
1251 if ( m_spinbutton->GetValue() < -17 )
1252 {
1253 value += _T("Preventing the spin button from going below -17.\n");
1254
1255 event.Veto();
1256 }
1257
1258 m_text->AppendText(value);
1259}
1260
1261void MyPanel::OnSpinUpdate( wxSpinEvent &event )
1262{
1263 wxString value;
1264 value.Printf( _T("%d"), event.GetPosition() );
1265 m_spintext->SetValue( value );
1266
1267 value.Printf( _T("Spin control range: (%d, %d), current = %d\n"),
1268 m_spinbutton->GetMin(), m_spinbutton->GetMax(),
1269 m_spinbutton->GetValue());
1270
1271 m_text->AppendText(value);
1272}
1273
1274void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
1275{
1276 event.Enable( m_spinbutton->GetValue() > 0 );
1277}
1278
1279void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
1280{
1281 int max = m_spinbutton->GetValue();
1282 wxProgressDialog dialog("Progress dialog example",
1283 "An informative message",
1284 max, // range
1285 this, // parent
1286 wxPD_CAN_ABORT |
1287 wxPD_AUTO_HIDE |
1288 wxPD_APP_MODAL |
1289 wxPD_ELAPSED_TIME |
1290 wxPD_ESTIMATED_TIME |
1291 wxPD_REMAINING_TIME);
1292
1293
1294 bool cont = TRUE;
1295 for ( int i = 0; i <= max && cont; i++ )
1296 {
1297 wxSleep(1);
1298 if ( i == max )
1299 {
1300 cont = dialog.Update(i, "That's all, folks!");
1301 }
1302 else if ( i == max / 2 )
1303 {
1304 cont = dialog.Update(i, "Only a half left (very long message)!");
1305 }
1306 else
1307 {
1308 cont = dialog.Update(i);
1309 }
1310 }
1311
1312 if ( !cont )
1313 {
1314 *m_text << "Progress dialog aborted!\n";
1315 }
1316 else
1317 {
1318 *m_text << "Countdown from " << max << " finished.\n";
1319 }
1320}
1321
1322#endif // wxUSE_SPINBTN
1323
1324MyPanel::~MyPanel()
1325{
1326 //wxLog::RemoveTraceMask(_T("focus"));
1327 delete wxLog::SetActiveTarget(m_logTargetOld);
1328
1329 delete m_notebook->GetImageList();
1330}
1331
1332//----------------------------------------------------------------------
1333// MyFrame
1334//----------------------------------------------------------------------
1335
1336BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1337 EVT_MENU(CONTROLS_QUIT, MyFrame::OnQuit)
1338 EVT_MENU(CONTROLS_ABOUT, MyFrame::OnAbout)
1339 EVT_MENU(CONTROLS_CLEAR_LOG, MyFrame::OnClearLog)
1340#if wxUSE_TOOLTIPS
1341 EVT_MENU(CONTROLS_SET_TOOLTIP_DELAY, MyFrame::OnSetTooltipDelay)
1342 EVT_MENU(CONTROLS_ENABLE_TOOLTIPS, MyFrame::OnToggleTooltips)
1343#endif // wxUSE_TOOLTIPS
1344
1345 EVT_MENU(CONTROLS_ENABLE_ALL, MyFrame::OnEnableAll)
1346
1347 EVT_SIZE(MyFrame::OnSize)
1348 EVT_MOVE(MyFrame::OnMove)
1349
1350 EVT_IDLE(MyFrame::OnIdle)
1351END_EVENT_TABLE()
1352
1353MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
1354: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
1355{
1356 CreateStatusBar(2);
1357
1358 m_panel = new MyPanel( this, 10, 10, 300, 100 );
1359}
1360
1361void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) )
1362{
1363 Close(TRUE);
1364}
1365
1366void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
1367{
1368 wxBusyCursor bc;
1369
1370 wxMessageDialog dialog(this, "This is a control sample", "About Controls", wxOK );
1371 dialog.ShowModal();
1372}
1373
1374void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
1375{
1376 m_panel->m_text->Clear();
1377}
1378
1379#if wxUSE_TOOLTIPS
1380void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
1381{
1382 static long s_delay = 5000;
1383
1384 wxString delay;
1385 delay.Printf( _T("%ld"), s_delay);
1386
1387 delay = wxGetTextFromUser("Enter delay (in milliseconds)",
1388 "Set tooltip delay",
1389 delay,
1390 this);
1391 if ( !delay )
1392 return; // cancelled
1393
1394 wxSscanf(delay, _T("%ld"), &s_delay);
1395
1396 wxToolTip::SetDelay(s_delay);
1397
1398 wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
1399}
1400
1401void MyFrame::OnToggleTooltips(wxCommandEvent& event)
1402{
1403 static bool s_enabled = TRUE;
1404
1405 s_enabled = !s_enabled;
1406
1407 wxToolTip::Enable(s_enabled);
1408
1409 wxLogStatus(this, _T("Tooltips %sabled"), s_enabled ? _T("en") : _T("dis") );
1410}
1411#endif // tooltips
1412
1413void MyFrame::OnEnableAll(wxCommandEvent& WXUNUSED(event))
1414{
1415 static bool s_enable = TRUE;
1416
1417 s_enable = !s_enable;
1418 m_panel->Enable(s_enable);
1419}
1420
1421void MyFrame::OnMove( wxMoveEvent& event )
1422{
1423 UpdateStatusBar(event.GetPosition(), GetSize());
1424
1425 event.Skip();
1426}
1427
1428void MyFrame::OnSize( wxSizeEvent& event )
1429{
1430 UpdateStatusBar(GetPosition(), event.GetSize());
1431
1432 event.Skip();
1433}
1434
1435void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
1436{
1437 // track the window which has the focus in the status bar
1438 static wxWindow *s_windowFocus = (wxWindow *)NULL;
1439 wxWindow *focus = wxWindow::FindFocus();
1440 if ( focus && (focus != s_windowFocus) )
1441 {
1442 s_windowFocus = focus;
1443
1444 wxString msg;
1445 msg.Printf(
1446#ifdef __WXMSW__
1447 _T("Focus: %s, HWND = %08x"),
1448#else
1449 _T("Focus: %s"),
1450#endif
1451 s_windowFocus->GetClassInfo()->GetClassName()
1452#ifdef __WXMSW__
1453 , s_windowFocus->GetHWND()
1454#endif
1455 );
1456
1457 SetStatusText(msg);
1458 }
1459}
1460
1461void MyComboBox::OnChar(wxKeyEvent& event)
1462{
1463 wxLogMessage(_T("MyComboBox::OnChar"));
1464
1465 if ( event.KeyCode() == 'w' )
1466 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1467 else
1468 event.Skip();
1469}
1470
1471void MyComboBox::OnKeyDown(wxKeyEvent& event)
1472{
1473 wxLogMessage(_T("MyComboBox::OnKeyDown"));
1474
1475 if ( event.KeyCode() == 'w' )
1476 wxLogMessage(_T("MyComboBox: 'w' will be ignored."));
1477 else
1478 event.Skip();
1479}
1480
1481void MyComboBox::OnKeyUp(wxKeyEvent& event)
1482{
1483 wxLogMessage(_T("MyComboBox::OnKeyUp"));
1484
1485 event.Skip();
1486}
1487
1488static void SetControlClientData(const char *name,
1489 wxControlWithItems *control)
1490{
1491 size_t count = control->GetCount();
1492 for ( size_t n = 0; n < count; n++ )
1493 {
1494 wxString s;
1495 s.Printf("%s client data for '%s'",
1496 name, control->GetString(n).c_str());
1497
1498 control->SetClientObject(n, new wxStringClientData(s));
1499 }
1500}