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