]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/slider.cpp
[ 1596568 ] Fix for bug 1595339
[wxWidgets.git] / samples / widgets / slider.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
be5a51fb 2// Program: wxWidgets Widgets Sample
32b8ec41
VZ
3// Name: slider.cpp
4// Purpose: Part of the widgets sample showing wxSlider
5// Author: Vadim Zeitlin
6// Created: 16.04.01
7// Id: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin
9// License: wxWindows license
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_SLIDER
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/slider.h"
38 #include "wx/statbox.h"
39 #include "wx/textctrl.h"
40#endif
41
53b98211
JS
42#if wxUSE_TOOLTIPS
43 #include "wx/tooltip.h"
44#endif
45
32b8ec41
VZ
46#include "wx/sizer.h"
47
48#include "widgets.h"
61c083e7 49
32b8ec41
VZ
50#include "icons/slider.xpm"
51
52// ----------------------------------------------------------------------------
53// constants
54// ----------------------------------------------------------------------------
55
56// control ids
57enum
58{
d79b005a 59 SliderPage_Reset = wxID_HIGHEST,
32b8ec41
VZ
60 SliderPage_Clear,
61 SliderPage_SetValue,
62 SliderPage_SetMinAndMax,
d6c1aef8
MR
63 SliderPage_SetLineSize,
64 SliderPage_SetPageSize,
32b8ec41 65 SliderPage_SetTickFreq,
53b98211 66 SliderPage_SetThumbLen,
32b8ec41
VZ
67 SliderPage_CurValueText,
68 SliderPage_ValueText,
69 SliderPage_MinText,
70 SliderPage_MaxText,
d6c1aef8
MR
71 SliderPage_LineSizeText,
72 SliderPage_PageSizeText,
32b8ec41 73 SliderPage_TickFreqText,
53b98211
JS
74 SliderPage_ThumbLenText,
75 SliderPage_RadioSides,
76 SliderPage_BothSides,
32b8ec41
VZ
77 SliderPage_Slider
78};
79
53b98211
JS
80// sides radiobox values
81enum
82{
93103bab
VZ
83 SliderTicks_Top,
84 SliderTicks_Bottom,
85 SliderTicks_Left,
86 SliderTicks_Right
53b98211
JS
87};
88
32b8ec41
VZ
89// ----------------------------------------------------------------------------
90// SliderWidgetsPage
91// ----------------------------------------------------------------------------
92
93class SliderWidgetsPage : public WidgetsPage
94{
95public:
f2fdc4d5 96 SliderWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
8f6eaec9 97 virtual ~SliderWidgetsPage(){};
32b8ec41 98
195df7a7 99 virtual wxControl *GetWidget() const { return m_slider; }
1301e228 100 virtual void RecreateWidget() { CreateSlider(); }
195df7a7 101
453535a7
WS
102 // lazy creation of the content
103 virtual void CreateContent();
104
32b8ec41
VZ
105protected:
106 // event handlers
107 void OnButtonReset(wxCommandEvent& event);
108 void OnButtonClear(wxCommandEvent& event);
109 void OnButtonSetValue(wxCommandEvent& event);
110 void OnButtonSetMinAndMax(wxCommandEvent& event);
d6c1aef8
MR
111 void OnButtonSetLineSize(wxCommandEvent& event);
112 void OnButtonSetPageSize(wxCommandEvent& event);
32b8ec41 113 void OnButtonSetTickFreq(wxCommandEvent& event);
53b98211 114 void OnButtonSetThumbLen(wxCommandEvent& event);
32b8ec41
VZ
115
116 void OnCheckOrRadioBox(wxCommandEvent& event);
117
d79b005a 118 void OnSlider(wxScrollEvent& event);
32b8ec41 119
32b8ec41
VZ
120 void OnUpdateUIValueButton(wxUpdateUIEvent& event);
121 void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
d6c1aef8
MR
122 void OnUpdateUILineSize(wxUpdateUIEvent& event);
123 void OnUpdateUIPageSize(wxUpdateUIEvent& event);
32b8ec41 124 void OnUpdateUITickFreq(wxUpdateUIEvent& event);
53b98211
JS
125 void OnUpdateUIThumbLen(wxUpdateUIEvent& event);
126 void OnUpdateUIRadioSides(wxUpdateUIEvent& event);
127 void OnUpdateUIBothSides(wxUpdateUIEvent& event);
32b8ec41
VZ
128
129 void OnUpdateUIResetButton(wxUpdateUIEvent& event);
130
131 void OnUpdateUICurValueText(wxUpdateUIEvent& event);
132
133 // reset the slider parameters
134 void Reset();
135
136 // (re)create the slider
137 void CreateSlider();
138
d6c1aef8
MR
139 // set the line size from the text field value
140 void DoSetLineSize();
141
142 // set the page size from the text field value
143 void DoSetPageSize();
144
32b8ec41
VZ
145 // set the tick frequency from the text field value
146 void DoSetTickFreq();
147
53b98211
JS
148 // set the thumb len from the text field value
149 void DoSetThumbLen();
150
32b8ec41
VZ
151 // is this slider value in range?
152 bool IsValidValue(int val) const
153 { return (val >= m_min) && (val <= m_max); }
154
155 // the slider range
156 int m_min, m_max;
157
158 // the controls
159 // ------------
160
161 // the check/radio boxes for styles
162 wxCheckBox *m_chkLabels,
2bcdbe0f 163 *m_chkInverse,
53b98211
JS
164 *m_chkTicks,
165 *m_chkBothSides;
166
167 wxRadioBox *m_radioSides;
32b8ec41
VZ
168
169 // the slider itself and the sizer it is in
170 wxSlider *m_slider;
171 wxSizer *m_sizerSlider;
172
173 // the text entries for set value/range
174 wxTextCtrl *m_textValue,
175 *m_textMin,
176 *m_textMax,
d6c1aef8
MR
177 *m_textLineSize,
178 *m_textPageSize,
53b98211
JS
179 *m_textTickFreq,
180 *m_textThumbLen;
32b8ec41
VZ
181
182private:
5e173f35
GD
183 DECLARE_EVENT_TABLE()
184 DECLARE_WIDGETS_PAGE(SliderWidgetsPage)
32b8ec41
VZ
185};
186
187// ----------------------------------------------------------------------------
188// event tables
189// ----------------------------------------------------------------------------
190
191BEGIN_EVENT_TABLE(SliderWidgetsPage, WidgetsPage)
192 EVT_BUTTON(SliderPage_Reset, SliderWidgetsPage::OnButtonReset)
193 EVT_BUTTON(SliderPage_SetValue, SliderWidgetsPage::OnButtonSetValue)
194 EVT_BUTTON(SliderPage_SetMinAndMax, SliderWidgetsPage::OnButtonSetMinAndMax)
d6c1aef8
MR
195 EVT_BUTTON(SliderPage_SetLineSize, SliderWidgetsPage::OnButtonSetLineSize)
196 EVT_BUTTON(SliderPage_SetPageSize, SliderWidgetsPage::OnButtonSetPageSize)
32b8ec41 197 EVT_BUTTON(SliderPage_SetTickFreq, SliderWidgetsPage::OnButtonSetTickFreq)
53b98211 198 EVT_BUTTON(SliderPage_SetThumbLen, SliderWidgetsPage::OnButtonSetThumbLen)
32b8ec41
VZ
199
200 EVT_UPDATE_UI(SliderPage_SetValue, SliderWidgetsPage::OnUpdateUIValueButton)
201 EVT_UPDATE_UI(SliderPage_SetMinAndMax, SliderWidgetsPage::OnUpdateUIMinMaxButton)
d6c1aef8
MR
202 EVT_UPDATE_UI(SliderPage_SetLineSize, SliderWidgetsPage::OnUpdateUILineSize)
203 EVT_UPDATE_UI(SliderPage_SetPageSize, SliderWidgetsPage::OnUpdateUIPageSize)
32b8ec41 204 EVT_UPDATE_UI(SliderPage_SetTickFreq, SliderWidgetsPage::OnUpdateUITickFreq)
53b98211 205 EVT_UPDATE_UI(SliderPage_SetThumbLen, SliderWidgetsPage::OnUpdateUIThumbLen)
53b98211
JS
206 EVT_UPDATE_UI(SliderPage_RadioSides, SliderWidgetsPage::OnUpdateUIRadioSides)
207 EVT_UPDATE_UI(SliderPage_BothSides, SliderWidgetsPage::OnUpdateUIBothSides)
32b8ec41
VZ
208
209 EVT_UPDATE_UI(SliderPage_Reset, SliderWidgetsPage::OnUpdateUIResetButton)
210
211 EVT_UPDATE_UI(SliderPage_CurValueText, SliderWidgetsPage::OnUpdateUICurValueText)
212
d79b005a 213 EVT_COMMAND_SCROLL(SliderPage_Slider, SliderWidgetsPage::OnSlider)
32b8ec41 214
206d3a16
JS
215 EVT_CHECKBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
216 EVT_RADIOBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
32b8ec41
VZ
217END_EVENT_TABLE()
218
219// ============================================================================
220// implementation
221// ============================================================================
222
f0fa4312
WS
223#if defined(__WXUNIVERSAL__)
224 #define FAMILY_CTRLS UNIVERSAL_CTRLS
225#else
226 #define FAMILY_CTRLS NATIVE_CTRLS
227#endif
228
229IMPLEMENT_WIDGETS_PAGE(SliderWidgetsPage, _T("Slider"), FAMILY_CTRLS );
32b8ec41 230
f2fdc4d5 231SliderWidgetsPage::SliderWidgetsPage(WidgetsBookCtrl *book,
61c083e7 232 wxImageList *imaglist)
261357eb 233 : WidgetsPage(book, imaglist, slider_xpm)
32b8ec41 234{
32b8ec41
VZ
235 // init everything
236 m_min = 0;
237 m_max = 100;
238
dc3155f1 239 m_chkInverse =
32b8ec41
VZ
240 m_chkTicks =
241 m_chkLabels =
53b98211
JS
242 m_chkBothSides = (wxCheckBox *)NULL;
243
244 m_radioSides = (wxRadioBox *)NULL;
32b8ec41
VZ
245
246 m_slider = (wxSlider *)NULL;
247 m_sizerSlider = (wxSizer *)NULL;
453535a7 248}
32b8ec41 249
453535a7
WS
250void SliderWidgetsPage::CreateContent()
251{
32b8ec41
VZ
252 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
253
254 // left pane
206d3a16 255 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style"));
32b8ec41
VZ
256 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
257
2bcdbe0f 258 m_chkInverse = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Inverse"));
32b8ec41
VZ
259 m_chkTicks = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &ticks"));
260 m_chkLabels = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &labels"));
53b98211
JS
261 static const wxString sides[] =
262 {
263 _T("top"),
264 _T("bottom"),
265 _T("left"),
266 _T("right"),
267 };
268 m_radioSides = new wxRadioBox(this, SliderPage_RadioSides, _T("&Ticks/Labels"),
269 wxDefaultPosition, wxDefaultSize,
270 WXSIZEOF(sides), sides,
271 1, wxRA_SPECIFY_COLS);
272 sizerLeft->Add(m_radioSides, 0, wxGROW | wxALL, 5);
273 m_chkBothSides = CreateCheckBoxAndAddToSizer
274 (sizerLeft, _T("&Both sides"), SliderPage_BothSides);
275#if wxUSE_TOOLTIPS
276 m_chkBothSides->SetToolTip( _T("\"Both sides\" is only supported \nin Win95 and Universal") );
277#endif // wxUSE_TOOLTIPS
32b8ec41
VZ
278
279 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
280
281 wxButton *btn = new wxButton(this, SliderPage_Reset, _T("&Reset"));
282 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
283
284 // middle pane
206d3a16 285 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Change slider value"));
32b8ec41
VZ
286 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
287
288 wxTextCtrl *text;
289 wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Current value"),
290 SliderPage_CurValueText,
291 &text);
206d3a16 292 text->SetEditable(false);
32b8ec41
VZ
293
294 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
295
296 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetValue,
297 _T("Set &value"),
298 SliderPage_ValueText,
299 &m_textValue);
300 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
301
302 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetMinAndMax,
303 _T("&Min and max"),
304 SliderPage_MinText,
305 &m_textMin);
306
206d3a16 307 m_textMax = new wxTextCtrl(this, SliderPage_MaxText, wxEmptyString);
32b8ec41
VZ
308 sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
309
aec18ff7
MB
310 m_textMin->SetValue( wxString::Format(_T("%d"), m_min) );
311 m_textMax->SetValue( wxString::Format(_T("%d"), m_max) );
32b8ec41
VZ
312
313 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
314
d6c1aef8
MR
315 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetLineSize,
316 _T("Li&ne size"),
317 SliderPage_LineSizeText,
318 &m_textLineSize);
319
320 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
321
322 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetPageSize,
323 _T("P&age size"),
324 SliderPage_PageSizeText,
325 &m_textPageSize);
326
327 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
328
32b8ec41
VZ
329 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetTickFreq,
330 _T("Tick &frequency"),
331 SliderPage_TickFreqText,
332 &m_textTickFreq);
333
334 m_textTickFreq->SetValue(_T("10"));
335
336 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
337
53b98211 338 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetThumbLen,
a0d9c6cb 339 _T("Thumb &length"),
53b98211
JS
340 SliderPage_ThumbLenText,
341 &m_textThumbLen);
342
343 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
344
32b8ec41
VZ
345 // right pane
346 wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
53b98211 347 sizerRight->SetMinSize(150, 40);
32b8ec41
VZ
348 m_sizerSlider = sizerRight; // save it to modify it later
349
350 Reset();
351 CreateSlider();
352
d6c1aef8
MR
353 m_textLineSize->SetValue(wxString::Format(_T("%d"), m_slider->GetLineSize()));
354 m_textPageSize->SetValue(wxString::Format(_T("%d"), m_slider->GetPageSize()));
355
32b8ec41
VZ
356 // the 3 panes panes compose the window
357 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
7b127900 358 sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
32b8ec41
VZ
359 sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
360
361 // final initializations
32b8ec41
VZ
362 SetSizer(sizerTop);
363
364 sizerTop->Fit(this);
365}
366
32b8ec41
VZ
367// ----------------------------------------------------------------------------
368// operations
369// ----------------------------------------------------------------------------
370
371void SliderWidgetsPage::Reset()
372{
2bcdbe0f 373 m_chkInverse->SetValue(false);
206d3a16
JS
374 m_chkTicks->SetValue(true);
375 m_chkLabels->SetValue(true);
376 m_chkBothSides->SetValue(false);
53b98211 377
93103bab 378 m_radioSides->SetSelection(SliderTicks_Top);
32b8ec41
VZ
379}
380
381void SliderWidgetsPage::CreateSlider()
382{
1301e228 383 int flags = ms_defaultFlags;
32b8ec41 384
2bcdbe0f
KH
385 if ( m_chkInverse->GetValue() )
386 {
387 flags |= wxSL_INVERSE;
388 }
389
32b8ec41
VZ
390 if ( m_chkLabels->GetValue() )
391 {
392 flags |= wxSL_LABELS;
32b8ec41
VZ
393 }
394
395 if ( m_chkTicks->GetValue() )
396 {
397 flags |= wxSL_AUTOTICKS;
398 }
399
53b98211
JS
400 switch ( m_radioSides->GetSelection() )
401 {
93103bab 402 case SliderTicks_Top:
53b98211
JS
403 flags |= wxSL_TOP;
404 break;
93103bab
VZ
405
406 case SliderTicks_Left:
53b98211
JS
407 flags |= wxSL_LEFT;
408 break;
93103bab
VZ
409
410 case SliderTicks_Bottom:
53b98211
JS
411 flags |= wxSL_BOTTOM;
412 break;
93103bab
VZ
413
414 case SliderTicks_Right:
53b98211
JS
415 flags |= wxSL_RIGHT;
416 break;
93103bab 417
53b98211
JS
418 default:
419 wxFAIL_MSG(_T("unexpected radiobox selection"));
420 // fall through
421 }
422
423 if ( m_chkBothSides->GetValue() )
424 {
425 flags |= wxSL_BOTH;
426 }
427
32b8ec41
VZ
428 int val = m_min;
429 if ( m_slider )
430 {
431 int valOld = m_slider->GetValue();
432 if ( !IsValidValue(valOld) )
433 {
434 val = valOld;
435 }
436
12a3f227 437 m_sizerSlider->Detach( m_slider );
32b8ec41
VZ
438
439 if ( m_sizerSlider->GetChildren().GetCount() )
440 {
441 // we have 2 spacers, remove them too
9dd96c0f
VZ
442 m_sizerSlider->Remove( 0 );
443 m_sizerSlider->Remove( 0 );
32b8ec41
VZ
444 }
445
446 delete m_slider;
447 }
448
449 m_slider = new wxSlider(this, SliderPage_Slider,
450 val, m_min, m_max,
451 wxDefaultPosition, wxDefaultSize,
452 flags);
453
93103bab 454 if ( m_slider->HasFlag(wxSL_VERTICAL) )
32b8ec41
VZ
455 {
456 m_sizerSlider->Add(0, 0, 1);
457 m_sizerSlider->Add(m_slider, 0, wxGROW | wxALL, 5);
458 m_sizerSlider->Add(0, 0, 1);
459 }
460 else
461 {
462 m_sizerSlider->Add(m_slider, 1, wxCENTRE | wxALL, 5);
463 }
464
465 if ( m_chkTicks->GetValue() )
466 {
467 DoSetTickFreq();
468 }
469
470 m_sizerSlider->Layout();
471}
472
d6c1aef8
MR
473void SliderWidgetsPage::DoSetLineSize()
474{
475 long lineSize;
476 if ( !m_textLineSize->GetValue().ToLong(&lineSize) )
477 {
478 wxLogWarning(_T("Invalid slider line size"));
479
480 return;
481 }
482
483 m_slider->SetLineSize(lineSize);
484
485 if ( m_slider->GetLineSize() != lineSize )
486 {
487 wxLogWarning(_T("Invalid line size in slider."));
488 }
489}
490
491void SliderWidgetsPage::DoSetPageSize()
492{
493 long pageSize;
494 if ( !m_textPageSize->GetValue().ToLong(&pageSize) )
495 {
496 wxLogWarning(_T("Invalid slider page size"));
497
498 return;
499 }
500
501 m_slider->SetPageSize(pageSize);
502
503 if ( m_slider->GetPageSize() != pageSize )
504 {
505 wxLogWarning(_T("Invalid page size in slider."));
506 }
507}
508
32b8ec41
VZ
509void SliderWidgetsPage::DoSetTickFreq()
510{
511 long freq;
512 if ( !m_textTickFreq->GetValue().ToLong(&freq) )
513 {
514 wxLogWarning(_T("Invalid slider tick frequency"));
515
516 return;
517 }
518
519 m_slider->SetTickFreq(freq, 0 /* unused */);
520}
521
53b98211
JS
522void SliderWidgetsPage::DoSetThumbLen()
523{
524 long len;
525 if ( !m_textThumbLen->GetValue().ToLong(&len) )
526 {
a0d9c6cb 527 wxLogWarning(_T("Invalid slider thumb length"));
53b98211
JS
528
529 return;
530 }
531
532 m_slider->SetThumbLength(len);
533}
534
32b8ec41
VZ
535// ----------------------------------------------------------------------------
536// event handlers
537// ----------------------------------------------------------------------------
538
539void SliderWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
540{
541 Reset();
542
543 CreateSlider();
544}
545
d6c1aef8
MR
546void SliderWidgetsPage::OnButtonSetLineSize(wxCommandEvent& WXUNUSED(event))
547{
548 DoSetLineSize();
549}
550
551void SliderWidgetsPage::OnButtonSetPageSize(wxCommandEvent& WXUNUSED(event))
552{
553 DoSetPageSize();
554}
555
32b8ec41
VZ
556void SliderWidgetsPage::OnButtonSetTickFreq(wxCommandEvent& WXUNUSED(event))
557{
558 DoSetTickFreq();
559}
560
53b98211
JS
561void SliderWidgetsPage::OnButtonSetThumbLen(wxCommandEvent& WXUNUSED(event))
562{
563 DoSetThumbLen();
564}
565
32b8ec41
VZ
566void SliderWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
567{
568 long minNew,
569 maxNew = 0; // init to suppress compiler warning
570 if ( !m_textMin->GetValue().ToLong(&minNew) ||
571 !m_textMax->GetValue().ToLong(&maxNew) ||
572 minNew >= maxNew )
573 {
574 wxLogWarning(_T("Invalid min/max values for the slider."));
575
576 return;
577 }
578
579 m_min = minNew;
580 m_max = maxNew;
581
582 m_slider->SetRange(minNew, maxNew);
9690a439
WS
583
584 if ( m_slider->GetMin() != m_min ||
585 m_slider->GetMax() != m_max )
586 {
587 wxLogWarning(_T("Invalid range in slider."));
588 }
32b8ec41
VZ
589}
590
591void SliderWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
592{
593 long val;
594 if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
595 {
596 wxLogWarning(_T("Invalid slider value."));
597
598 return;
599 }
600
601 m_slider->SetValue(val);
602}
603
604void SliderWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
605{
606 long val;
607 event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
608}
609
d6c1aef8
MR
610void SliderWidgetsPage::OnUpdateUILineSize(wxUpdateUIEvent& event)
611{
612 long lineSize;
613 event.Enable( m_textLineSize->GetValue().ToLong(&lineSize) &&
614 (lineSize > 0) && (lineSize <= m_max - m_min) );
615}
616
617void SliderWidgetsPage::OnUpdateUIPageSize(wxUpdateUIEvent& event)
618{
619 long pageSize;
620 event.Enable( m_textPageSize->GetValue().ToLong(&pageSize) &&
621 (pageSize > 0) && (pageSize <= m_max - m_min) );
622}
623
32b8ec41
VZ
624void SliderWidgetsPage::OnUpdateUITickFreq(wxUpdateUIEvent& event)
625{
626 long freq;
627 event.Enable( m_chkTicks->GetValue() &&
628 m_textTickFreq->GetValue().ToLong(&freq) &&
629 (freq > 0) && (freq <= m_max - m_min) );
630}
631
53b98211
JS
632void SliderWidgetsPage::OnUpdateUIThumbLen(wxUpdateUIEvent& event)
633{
634 long val;
635 event.Enable( m_textThumbLen->GetValue().ToLong(&val));
636}
637
32b8ec41
VZ
638void SliderWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
639{
640 long mn, mx;
641 event.Enable( m_textMin->GetValue().ToLong(&mn) &&
642 m_textMax->GetValue().ToLong(&mx) &&
643 mn < mx);
644}
645
646void SliderWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
647{
93103bab 648 event.Enable( m_chkInverse->GetValue() ||
53b98211 649 !m_chkTicks->GetValue() ||
32b8ec41 650 !m_chkLabels->GetValue() ||
93103bab
VZ
651 m_chkBothSides->GetValue() ||
652 m_radioSides->GetSelection() != SliderTicks_Top );
32b8ec41
VZ
653}
654
c02e5a31 655void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
656{
657 CreateSlider();
658}
659
660void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
661{
aec18ff7 662 event.SetText( wxString::Format(_T("%d"), m_slider->GetValue()) );
32b8ec41
VZ
663}
664
53b98211
JS
665void SliderWidgetsPage::OnUpdateUIRadioSides(wxUpdateUIEvent& event)
666{
667 event.Enable( m_chkLabels->GetValue() || m_chkTicks->GetValue() );
668}
669
670void SliderWidgetsPage::OnUpdateUIBothSides(wxUpdateUIEvent& event)
32b8ec41 671{
a71d815b 672#if defined(__WXMSW__) || defined(__WXUNIVERSAL__)
53b98211
JS
673 event.Enable( m_chkTicks->GetValue() );
674#else
206d3a16 675 event.Enable( false );
a71d815b 676#endif // defined(__WXMSW__) || defined(__WXUNIVERSAL__)
32b8ec41
VZ
677}
678
d79b005a 679void SliderWidgetsPage::OnSlider(wxScrollEvent& event)
32b8ec41 680{
2b5f62a0
VZ
681 wxASSERT_MSG( event.GetInt() == m_slider->GetValue(),
682 wxT("slider value should be the same") );
32b8ec41 683
d79b005a
VZ
684 wxEventType eventType = event.GetEventType();
685
686 /*
687 This array takes the EXACT order of the declarations in
688 include/wx/event.h
689 (section "wxScrollBar and wxSlider event identifiers")
690 */
691 static const wxChar *eventNames[] =
692 {
693 wxT("wxEVT_SCROLL_TOP"),
694 wxT("wxEVT_SCROLL_BOTTOM"),
695 wxT("wxEVT_SCROLL_LINEUP"),
696 wxT("wxEVT_SCROLL_LINEDOWN"),
697 wxT("wxEVT_SCROLL_PAGEUP"),
698 wxT("wxEVT_SCROLL_PAGEDOWN"),
699 wxT("wxEVT_SCROLL_THUMBTRACK"),
700 wxT("wxEVT_SCROLL_THUMBRELEASE"),
cbc85508 701 wxT("wxEVT_SCROLL_CHANGED")
d79b005a
VZ
702 };
703
704 int index = eventType - wxEVT_SCROLL_TOP;
705
706 /*
707 If this assert is triggered, there is an unknown slider event which
708 should be added to the above eventNames array.
709 */
8b1d8f36 710 wxASSERT_MSG(index >= 0 && (size_t)index < WXSIZEOF(eventNames),
d79b005a
VZ
711 wxT("Unknown slider event") );
712
713
714 static int s_numSliderEvents = 0;
715
33cf9a19 716 wxLogMessage(wxT("Slider event #%d: %s (pos = %d, int value = %d)"),
580d78b3 717 s_numSliderEvents++,
d79b005a 718 eventNames[index],
2bcdbe0f
KH
719 event.GetPosition(),
720 event.GetInt());
32b8ec41
VZ
721}
722
61c083e7 723#endif // wxUSE_SLIDER