]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
3 | // Name: spinbtn.cpp |
4 | // Purpose: Part of the widgets sample showing wxSpinButton | |
5 | // Author: Vadim Zeitlin | |
6 | // Created: 16.04.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
526954c5 | 9 | // Licence: wxWindows licence |
32b8ec41 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
61c083e7 WS |
27 | #if wxUSE_SPINBTN |
28 | ||
32b8ec41 VZ |
29 | // for all others, include the necessary headers |
30 | #ifndef WX_PRECOMP | |
31 | #include "wx/log.h" | |
32 | ||
3bb70c40 | 33 | #include "wx/bitmap.h" |
32b8ec41 VZ |
34 | #include "wx/button.h" |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/radiobox.h" | |
37 | #include "wx/statbox.h" | |
38 | #include "wx/textctrl.h" | |
39 | #endif | |
40 | ||
41 | #include "wx/spinbutt.h" | |
42 | #include "wx/spinctrl.h" | |
43 | ||
44 | #include "wx/sizer.h" | |
2a998b73 | 45 | #include "wx/stattext.h" |
32b8ec41 | 46 | #include "widgets.h" |
61c083e7 | 47 | |
32b8ec41 VZ |
48 | #include "icons/spinbtn.xpm" |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // constants | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // control ids | |
55 | enum | |
56 | { | |
f0fa4312 | 57 | SpinBtnPage_Reset = wxID_HIGHEST, |
32b8ec41 VZ |
58 | SpinBtnPage_Clear, |
59 | SpinBtnPage_SetValue, | |
60 | SpinBtnPage_SetMinAndMax, | |
61 | SpinBtnPage_CurValueText, | |
62 | SpinBtnPage_ValueText, | |
63 | SpinBtnPage_MinText, | |
64 | SpinBtnPage_MaxText, | |
65 | SpinBtnPage_SpinBtn, | |
8cd6a9ad VZ |
66 | SpinBtnPage_SpinCtrl, |
67 | SpinBtnPage_SpinCtrlDouble | |
32b8ec41 VZ |
68 | }; |
69 | ||
7e4952db VZ |
70 | // alignment radiobox values |
71 | enum | |
72 | { | |
73 | Align_Left, | |
74 | Align_Centre, | |
75 | Align_Right | |
76 | }; | |
77 | ||
32b8ec41 VZ |
78 | // ---------------------------------------------------------------------------- |
79 | // SpinBtnWidgetsPage | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | class SpinBtnWidgetsPage : public WidgetsPage | |
83 | { | |
84 | public: | |
f2fdc4d5 | 85 | SpinBtnWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); |
8f6eaec9 | 86 | virtual ~SpinBtnWidgetsPage(){}; |
32b8ec41 | 87 | |
195df7a7 | 88 | virtual wxControl *GetWidget() const { return m_spinbtn; } |
ca288f2a VZ |
89 | virtual Widgets GetWidgets() const |
90 | { | |
91 | Widgets widgets(WidgetsPage::GetWidgets()); | |
92 | widgets.push_back(m_spinctrl); | |
93 | widgets.push_back(m_spinctrldbl); | |
94 | return widgets; | |
95 | } | |
96 | ||
1301e228 | 97 | virtual void RecreateWidget() { CreateSpin(); } |
195df7a7 | 98 | |
453535a7 WS |
99 | // lazy creation of the content |
100 | virtual void CreateContent(); | |
101 | ||
32b8ec41 VZ |
102 | protected: |
103 | // event handlers | |
104 | void OnButtonReset(wxCommandEvent& event); | |
105 | void OnButtonClear(wxCommandEvent& event); | |
106 | void OnButtonSetValue(wxCommandEvent& event); | |
107 | void OnButtonSetMinAndMax(wxCommandEvent& event); | |
108 | ||
109 | void OnCheckOrRadioBox(wxCommandEvent& event); | |
110 | ||
0a3d26b8 VZ |
111 | void OnSpinBtn(wxSpinEvent& event); |
112 | void OnSpinBtnUp(wxSpinEvent& event); | |
113 | void OnSpinBtnDown(wxSpinEvent& event); | |
114 | void OnSpinCtrl(wxSpinEvent& event); | |
8cd6a9ad | 115 | void OnSpinCtrlDouble(wxSpinDoubleEvent& event); |
6ceb105f | 116 | void OnSpinText(wxCommandEvent& event); |
952ff7bc | 117 | void OnSpinTextEnter(wxCommandEvent& event); |
32b8ec41 VZ |
118 | |
119 | void OnUpdateUIValueButton(wxUpdateUIEvent& event); | |
120 | void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event); | |
121 | ||
122 | void OnUpdateUIResetButton(wxUpdateUIEvent& event); | |
123 | ||
124 | void OnUpdateUICurValueText(wxUpdateUIEvent& event); | |
125 | ||
126 | // reset the spinbtn parameters | |
127 | void Reset(); | |
128 | ||
129 | // (re)create the spinbtn | |
130 | void CreateSpin(); | |
131 | ||
132 | // is this spinbtn value in range? | |
133 | bool IsValidValue(int val) const | |
134 | { return (val >= m_min) && (val <= m_max); } | |
135 | ||
136 | // the spinbtn range | |
137 | int m_min, m_max; | |
138 | ||
139 | // the controls | |
140 | // ------------ | |
141 | ||
142 | // the check/radio boxes for styles | |
143 | wxCheckBox *m_chkVert, | |
fd07e185 | 144 | *m_chkArrowKeys, |
242ec2f7 VZ |
145 | *m_chkWrap, |
146 | *m_chkProcessEnter; | |
7e4952db | 147 | wxRadioBox *m_radioAlign; |
32b8ec41 VZ |
148 | |
149 | // the spinbtn and the spinctrl and the sizer containing them | |
150 | wxSpinButton *m_spinbtn; | |
151 | wxSpinCtrl *m_spinctrl; | |
8cd6a9ad | 152 | wxSpinCtrlDouble *m_spinctrldbl; |
32b8ec41 VZ |
153 | |
154 | wxSizer *m_sizerSpin; | |
155 | ||
156 | // the text entries for set value/range | |
157 | wxTextCtrl *m_textValue, | |
158 | *m_textMin, | |
159 | *m_textMax; | |
160 | ||
161 | private: | |
5e173f35 GD |
162 | DECLARE_EVENT_TABLE() |
163 | DECLARE_WIDGETS_PAGE(SpinBtnWidgetsPage) | |
32b8ec41 VZ |
164 | }; |
165 | ||
166 | // ---------------------------------------------------------------------------- | |
167 | // event tables | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
170 | BEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage) | |
171 | EVT_BUTTON(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnButtonReset) | |
172 | EVT_BUTTON(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnButtonSetValue) | |
173 | EVT_BUTTON(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnButtonSetMinAndMax) | |
174 | ||
175 | EVT_UPDATE_UI(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnUpdateUIValueButton) | |
176 | EVT_UPDATE_UI(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnUpdateUIMinMaxButton) | |
177 | ||
178 | EVT_UPDATE_UI(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnUpdateUIResetButton) | |
179 | ||
180 | EVT_UPDATE_UI(SpinBtnPage_CurValueText, SpinBtnWidgetsPage::OnUpdateUICurValueText) | |
181 | ||
182 | EVT_SPIN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtn) | |
183 | EVT_SPIN_UP(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnUp) | |
184 | EVT_SPIN_DOWN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnDown) | |
185 | EVT_SPINCTRL(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinCtrl) | |
8cd6a9ad | 186 | EVT_SPINCTRLDOUBLE(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinCtrlDouble) |
6ceb105f | 187 | EVT_TEXT(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinText) |
952ff7bc | 188 | EVT_TEXT_ENTER(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinTextEnter) |
8cd6a9ad | 189 | EVT_TEXT(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinText) |
32b8ec41 | 190 | |
206d3a16 JS |
191 | EVT_CHECKBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox) |
192 | EVT_RADIOBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
193 | END_EVENT_TABLE() |
194 | ||
195 | // ============================================================================ | |
196 | // implementation | |
197 | // ============================================================================ | |
198 | ||
f0fa4312 WS |
199 | #if defined(__WXUNIVERSAL__) |
200 | #define FAMILY_CTRLS UNIVERSAL_CTRLS | |
201 | #else | |
202 | #define FAMILY_CTRLS NATIVE_CTRLS | |
203 | #endif | |
204 | ||
9a83f860 | 205 | IMPLEMENT_WIDGETS_PAGE(SpinBtnWidgetsPage, wxT("Spin"), |
f0fa4312 | 206 | FAMILY_CTRLS | EDITABLE_CTRLS |
f2fdc4d5 | 207 | ); |
32b8ec41 | 208 | |
f2fdc4d5 | 209 | SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book, |
32b8ec41 | 210 | wxImageList *imaglist) |
261357eb | 211 | : WidgetsPage(book, imaglist, spinbtn_xpm) |
32b8ec41 | 212 | { |
59b9edf0 | 213 | m_chkVert = NULL; |
fd07e185 | 214 | m_chkArrowKeys = NULL; |
59b9edf0 | 215 | m_chkWrap = NULL; |
242ec2f7 | 216 | m_chkProcessEnter = NULL; |
7e4952db | 217 | m_radioAlign = NULL; |
59b9edf0 JS |
218 | m_spinbtn = NULL; |
219 | m_spinctrl = NULL; | |
8cd6a9ad | 220 | m_spinctrldbl = NULL; |
59b9edf0 JS |
221 | m_textValue = NULL; |
222 | m_textMin = NULL; | |
223 | m_textMax = NULL; | |
32b8ec41 | 224 | |
32b8ec41 VZ |
225 | m_min = 0; |
226 | m_max = 10; | |
227 | ||
242ec2f7 | 228 | m_sizerSpin = NULL; |
453535a7 | 229 | } |
32b8ec41 | 230 | |
453535a7 WS |
231 | void SpinBtnWidgetsPage::CreateContent() |
232 | { | |
32b8ec41 VZ |
233 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); |
234 | ||
235 | // left pane | |
9a83f860 | 236 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style")); |
32b8ec41 VZ |
237 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); |
238 | ||
9a83f860 VZ |
239 | m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Vertical")); |
240 | m_chkArrowKeys = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Arrow Keys")); | |
241 | m_chkWrap = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Wrap")); | |
242ec2f7 | 242 | m_chkProcessEnter = CreateCheckBoxAndAddToSizer(sizerLeft, |
9a83f860 | 243 | wxT("Process &Enter")); |
32b8ec41 VZ |
244 | |
245 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
246 | ||
7e4952db VZ |
247 | static const wxString halign[] = |
248 | { | |
9a83f860 VZ |
249 | wxT("left"), |
250 | wxT("centre"), | |
251 | wxT("right"), | |
7e4952db VZ |
252 | }; |
253 | ||
9a83f860 | 254 | m_radioAlign = new wxRadioBox(this, wxID_ANY, wxT("&Text alignment"), |
7e4952db VZ |
255 | wxDefaultPosition, wxDefaultSize, |
256 | WXSIZEOF(halign), halign, 1); | |
257 | ||
258 | sizerLeft->Add(m_radioAlign, 0, wxGROW | wxALL, 5); | |
259 | ||
260 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
261 | ||
9a83f860 | 262 | wxButton *btn = new wxButton(this, SpinBtnPage_Reset, wxT("&Reset")); |
32b8ec41 VZ |
263 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); |
264 | ||
265 | // middle pane | |
206d3a16 | 266 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, |
9a83f860 | 267 | wxT("&Change spinbtn value")); |
206d3a16 | 268 | |
32b8ec41 VZ |
269 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
270 | ||
271 | wxTextCtrl *text; | |
9a83f860 | 272 | wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Current value"), |
32b8ec41 VZ |
273 | SpinBtnPage_CurValueText, |
274 | &text); | |
206d3a16 | 275 | text->SetEditable(false); |
32b8ec41 VZ |
276 | |
277 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
278 | ||
279 | sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetValue, | |
9a83f860 | 280 | wxT("Set &value"), |
32b8ec41 VZ |
281 | SpinBtnPage_ValueText, |
282 | &m_textValue); | |
283 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
284 | ||
285 | sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetMinAndMax, | |
9a83f860 | 286 | wxT("&Min and max"), |
32b8ec41 VZ |
287 | SpinBtnPage_MinText, |
288 | &m_textMin); | |
289 | ||
206d3a16 | 290 | m_textMax = new wxTextCtrl(this, SpinBtnPage_MaxText, wxEmptyString); |
32b8ec41 VZ |
291 | sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5); |
292 | ||
9a83f860 VZ |
293 | m_textMin->SetValue( wxString::Format(wxT("%d"), m_min) ); |
294 | m_textMax->SetValue( wxString::Format(wxT("%d"), m_max) ); | |
32b8ec41 VZ |
295 | |
296 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
297 | ||
298 | // right pane | |
299 | wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); | |
7b127900 | 300 | sizerRight->SetMinSize(150, 0); |
32b8ec41 VZ |
301 | m_sizerSpin = sizerRight; // save it to modify it later |
302 | ||
303 | Reset(); | |
304 | CreateSpin(); | |
305 | ||
306 | // the 3 panes panes compose the window | |
307 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
7b127900 | 308 | sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10); |
32b8ec41 VZ |
309 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); |
310 | ||
311 | // final initializations | |
32b8ec41 | 312 | SetSizer(sizerTop); |
32b8ec41 VZ |
313 | } |
314 | ||
32b8ec41 VZ |
315 | // ---------------------------------------------------------------------------- |
316 | // operations | |
317 | // ---------------------------------------------------------------------------- | |
318 | ||
319 | void SpinBtnWidgetsPage::Reset() | |
320 | { | |
206d3a16 | 321 | m_chkVert->SetValue(true); |
fd07e185 | 322 | m_chkArrowKeys->SetValue(true); |
206d3a16 | 323 | m_chkWrap->SetValue(false); |
242ec2f7 | 324 | m_chkProcessEnter->SetValue(false); |
7e4952db | 325 | m_radioAlign->SetSelection(Align_Right); |
32b8ec41 VZ |
326 | } |
327 | ||
328 | void SpinBtnWidgetsPage::CreateSpin() | |
329 | { | |
1301e228 | 330 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
331 | |
332 | bool isVert = m_chkVert->GetValue(); | |
333 | if ( isVert ) | |
334 | flags |= wxSP_VERTICAL; | |
335 | else | |
336 | flags |= wxSP_HORIZONTAL; | |
337 | ||
fd07e185 VZ |
338 | if ( m_chkArrowKeys->GetValue() ) |
339 | flags |= wxSP_ARROW_KEYS; | |
340 | ||
32b8ec41 VZ |
341 | if ( m_chkWrap->GetValue() ) |
342 | flags |= wxSP_WRAP; | |
343 | ||
242ec2f7 VZ |
344 | if ( m_chkProcessEnter->GetValue() ) |
345 | flags |= wxTE_PROCESS_ENTER; | |
346 | ||
7e4952db VZ |
347 | int textFlags = 0; |
348 | switch ( m_radioAlign->GetSelection() ) | |
349 | { | |
350 | default: | |
9a83f860 | 351 | wxFAIL_MSG(wxT("unexpected radiobox selection")); |
7e4952db VZ |
352 | // fall through |
353 | ||
354 | case Align_Left: | |
355 | textFlags |= wxALIGN_LEFT; // no-op | |
356 | break; | |
357 | ||
358 | case Align_Centre: | |
359 | textFlags |= wxALIGN_CENTRE_HORIZONTAL; | |
360 | break; | |
361 | ||
362 | case Align_Right: | |
363 | textFlags |= wxALIGN_RIGHT; | |
364 | break; | |
365 | } | |
366 | ||
32b8ec41 VZ |
367 | int val = m_min; |
368 | if ( m_spinbtn ) | |
369 | { | |
370 | int valOld = m_spinbtn->GetValue(); | |
371 | if ( !IsValidValue(valOld) ) | |
372 | { | |
373 | val = valOld; | |
374 | } | |
375 | ||
55ab5200 | 376 | m_sizerSpin->Clear(true /* delete windows */); |
32b8ec41 VZ |
377 | } |
378 | ||
379 | m_spinbtn = new wxSpinButton(this, SpinBtnPage_SpinBtn, | |
380 | wxDefaultPosition, wxDefaultSize, | |
381 | flags); | |
382 | ||
383 | m_spinbtn->SetValue(val); | |
384 | m_spinbtn->SetRange(m_min, m_max); | |
385 | ||
386 | m_spinctrl = new wxSpinCtrl(this, SpinBtnPage_SpinCtrl, | |
9a83f860 | 387 | wxString::Format(wxT("%d"), val), |
32b8ec41 | 388 | wxDefaultPosition, wxDefaultSize, |
7e4952db | 389 | flags | textFlags, |
32b8ec41 VZ |
390 | m_min, m_max, val); |
391 | ||
8cd6a9ad | 392 | m_spinctrldbl = new wxSpinCtrlDouble(this, SpinBtnPage_SpinCtrlDouble, |
9a83f860 | 393 | wxString::Format(wxT("%d"), val), |
8cd6a9ad | 394 | wxDefaultPosition, wxDefaultSize, |
7e4952db | 395 | flags | textFlags, |
8cd6a9ad VZ |
396 | m_min, m_max, val, 0.1); |
397 | ||
2a998b73 | 398 | // Add spacers, labels and spin controls to the sizer. |
32b8ec41 | 399 | m_sizerSpin->Add(0, 0, 1); |
2a998b73 VZ |
400 | m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinButton")), |
401 | 0, wxALIGN_CENTRE | wxALL, 5); | |
32b8ec41 VZ |
402 | m_sizerSpin->Add(m_spinbtn, 0, wxALIGN_CENTRE | wxALL, 5); |
403 | m_sizerSpin->Add(0, 0, 1); | |
2a998b73 VZ |
404 | m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinCtrl")), |
405 | 0, wxALIGN_CENTRE | wxALL, 5); | |
32b8ec41 VZ |
406 | m_sizerSpin->Add(m_spinctrl, 0, wxALIGN_CENTRE | wxALL, 5); |
407 | m_sizerSpin->Add(0, 0, 1); | |
2a998b73 VZ |
408 | m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, wxT("wxSpinCtrlDouble")), |
409 | 0, wxALIGN_CENTRE | wxALL, 5); | |
8cd6a9ad VZ |
410 | m_sizerSpin->Add(m_spinctrldbl, 0, wxALIGN_CENTRE | wxALL, 5); |
411 | m_sizerSpin->Add(0, 0, 1); | |
32b8ec41 VZ |
412 | |
413 | m_sizerSpin->Layout(); | |
414 | } | |
415 | ||
416 | // ---------------------------------------------------------------------------- | |
417 | // event handlers | |
418 | // ---------------------------------------------------------------------------- | |
419 | ||
420 | void SpinBtnWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
421 | { | |
422 | Reset(); | |
423 | ||
424 | CreateSpin(); | |
425 | } | |
426 | ||
427 | void SpinBtnWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event)) | |
428 | { | |
429 | long minNew, | |
430 | maxNew = 0; // init to suppress compiler warning | |
431 | if ( !m_textMin->GetValue().ToLong(&minNew) || | |
432 | !m_textMax->GetValue().ToLong(&maxNew) || | |
6dd21271 | 433 | minNew > maxNew ) |
32b8ec41 | 434 | { |
9a83f860 | 435 | wxLogWarning(wxT("Invalid min/max values for the spinbtn.")); |
32b8ec41 VZ |
436 | |
437 | return; | |
438 | } | |
439 | ||
440 | m_min = minNew; | |
441 | m_max = maxNew; | |
442 | ||
443 | m_spinbtn->SetRange(minNew, maxNew); | |
444 | m_spinctrl->SetRange(minNew, maxNew); | |
8cd6a9ad | 445 | m_spinctrldbl->SetRange(minNew, maxNew); |
32b8ec41 VZ |
446 | } |
447 | ||
448 | void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) | |
449 | { | |
450 | long val; | |
451 | if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) ) | |
452 | { | |
9a83f860 | 453 | wxLogWarning(wxT("Invalid spinbtn value.")); |
32b8ec41 VZ |
454 | |
455 | return; | |
456 | } | |
457 | ||
458 | m_spinbtn->SetValue(val); | |
459 | m_spinctrl->SetValue(val); | |
8cd6a9ad | 460 | m_spinctrldbl->SetValue(val); |
32b8ec41 VZ |
461 | } |
462 | ||
463 | void SpinBtnWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event) | |
464 | { | |
465 | long val; | |
466 | event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) ); | |
467 | } | |
468 | ||
469 | void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event) | |
470 | { | |
471 | long mn, mx; | |
472 | event.Enable( m_textMin->GetValue().ToLong(&mn) && | |
473 | m_textMax->GetValue().ToLong(&mx) && | |
6dd21271 | 474 | mn <= mx); |
32b8ec41 VZ |
475 | } |
476 | ||
477 | void SpinBtnWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) | |
478 | { | |
242ec2f7 VZ |
479 | event.Enable( !m_chkVert->GetValue() || |
480 | m_chkWrap->GetValue() || | |
481 | m_chkProcessEnter->GetValue() ); | |
32b8ec41 VZ |
482 | } |
483 | ||
c02e5a31 | 484 | void SpinBtnWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
485 | { |
486 | CreateSpin(); | |
487 | } | |
488 | ||
489 | void SpinBtnWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event) | |
490 | { | |
9a83f860 | 491 | event.SetText( wxString::Format(wxT("%d"), m_spinbtn->GetValue())); |
32b8ec41 VZ |
492 | } |
493 | ||
0a3d26b8 | 494 | void SpinBtnWidgetsPage::OnSpinBtn(wxSpinEvent& event) |
32b8ec41 VZ |
495 | { |
496 | int value = event.GetInt(); | |
497 | ||
498 | wxASSERT_MSG( value == m_spinbtn->GetValue(), | |
9a83f860 | 499 | wxT("spinbtn value should be the same") ); |
32b8ec41 | 500 | |
9a83f860 | 501 | wxLogMessage(wxT("Spin button value changed, now %d"), value); |
32b8ec41 VZ |
502 | } |
503 | ||
0a3d26b8 | 504 | void SpinBtnWidgetsPage::OnSpinBtnUp(wxSpinEvent& event) |
32b8ec41 | 505 | { |
9a83f860 | 506 | wxLogMessage( wxT("Spin button value incremented, will be %d (was %d)"), |
aec18ff7 | 507 | event.GetInt(), m_spinbtn->GetValue() ); |
32b8ec41 VZ |
508 | } |
509 | ||
0a3d26b8 | 510 | void SpinBtnWidgetsPage::OnSpinBtnDown(wxSpinEvent& event) |
32b8ec41 | 511 | { |
9a83f860 | 512 | wxLogMessage( wxT("Spin button value decremented, will be %d (was %d)"), |
aec18ff7 | 513 | event.GetInt(), m_spinbtn->GetValue() ); |
32b8ec41 VZ |
514 | } |
515 | ||
0a3d26b8 | 516 | void SpinBtnWidgetsPage::OnSpinCtrl(wxSpinEvent& event) |
32b8ec41 VZ |
517 | { |
518 | int value = event.GetInt(); | |
519 | ||
520 | wxASSERT_MSG( value == m_spinctrl->GetValue(), | |
9a83f860 | 521 | wxT("spinctrl value should be the same") ); |
32b8ec41 | 522 | |
9a83f860 | 523 | wxLogMessage(wxT("Spin control value changed, now %d"), value); |
32b8ec41 | 524 | } |
6ceb105f | 525 | |
8cd6a9ad VZ |
526 | void SpinBtnWidgetsPage::OnSpinCtrlDouble(wxSpinDoubleEvent& event) |
527 | { | |
528 | double value = event.GetValue(); | |
529 | ||
9a83f860 | 530 | wxLogMessage(wxT("Spin control value changed, now %g"), value); |
8cd6a9ad VZ |
531 | } |
532 | ||
6ceb105f VZ |
533 | void SpinBtnWidgetsPage::OnSpinText(wxCommandEvent& event) |
534 | { | |
9a83f860 | 535 | wxLogMessage(wxT("Text changed in spin control, now \"%s\""), |
6ceb105f VZ |
536 | event.GetString().c_str()); |
537 | } | |
538 | ||
952ff7bc VZ |
539 | void SpinBtnWidgetsPage::OnSpinTextEnter(wxCommandEvent& event) |
540 | { | |
541 | wxLogMessage("\"Enter\" pressed in spin control, text is \"%s\"", | |
542 | event.GetString()); | |
543 | } | |
544 | ||
6ceb105f | 545 | #endif // wxUSE_SPINBTN |