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