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