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