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