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