]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/slider.cpp
Make storing non-trivial data in wxThreadSpecificInfo possible.
[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 // Copyright: (c) 2001 Vadim Zeitlin
8 // Licence: wxWindows licence
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
26 #if wxUSE_SLIDER
27
28 // for all others, include the necessary headers
29 #ifndef WX_PRECOMP
30 #include "wx/log.h"
31
32 #include "wx/bitmap.h"
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobox.h"
36 #include "wx/slider.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39 #endif
40
41 #if wxUSE_TOOLTIPS
42 #include "wx/tooltip.h"
43 #endif
44
45 #include "wx/sizer.h"
46
47 #include "widgets.h"
48
49 #include "icons/slider.xpm"
50
51 // ----------------------------------------------------------------------------
52 // constants
53 // ----------------------------------------------------------------------------
54
55 // control ids
56 enum
57 {
58 SliderPage_Reset = wxID_HIGHEST,
59 SliderPage_Clear,
60 SliderPage_SetValue,
61 SliderPage_SetMinAndMax,
62 SliderPage_SetLineSize,
63 SliderPage_SetPageSize,
64 SliderPage_SetTickFreq,
65 SliderPage_SetThumbLen,
66 SliderPage_CurValueText,
67 SliderPage_ValueText,
68 SliderPage_MinText,
69 SliderPage_MaxText,
70 SliderPage_LineSizeText,
71 SliderPage_PageSizeText,
72 SliderPage_TickFreqText,
73 SliderPage_ThumbLenText,
74 SliderPage_RadioSides,
75 SliderPage_BothSides,
76 SliderPage_Slider
77 };
78
79 // sides radiobox values
80 enum
81 {
82 SliderTicks_None,
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("default"),
267 wxT("top"),
268 wxT("bottom"),
269 wxT("left"),
270 wxT("right"),
271 };
272 m_radioSides = new wxRadioBox(this, SliderPage_RadioSides, wxT("&Label position"),
273 wxDefaultPosition, wxDefaultSize,
274 WXSIZEOF(sides), sides,
275 1, wxRA_SPECIFY_COLS);
276 sizerLeft->Add(m_radioSides, 0, wxGROW | wxALL, 5);
277 m_chkBothSides = CreateCheckBoxAndAddToSizer
278 (sizerLeft, wxT("&Both sides"), SliderPage_BothSides);
279 #if wxUSE_TOOLTIPS
280 m_chkBothSides->SetToolTip( wxT("\"Both sides\" is only supported \nin Win95 and Universal") );
281 #endif // wxUSE_TOOLTIPS
282
283 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
284
285 wxButton *btn = new wxButton(this, SliderPage_Reset, wxT("&Reset"));
286 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
287
288 // middle pane
289 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Change slider value"));
290 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
291
292 wxTextCtrl *text;
293 wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Current value"),
294 SliderPage_CurValueText,
295 &text);
296 text->SetEditable(false);
297
298 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
299
300 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetValue,
301 wxT("Set &value"),
302 SliderPage_ValueText,
303 &m_textValue);
304 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
305
306 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetMinAndMax,
307 wxT("&Min and max"),
308 SliderPage_MinText,
309 &m_textMin);
310
311 m_textMax = new wxTextCtrl(this, SliderPage_MaxText, wxEmptyString);
312 sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
313
314 m_textMin->SetValue( wxString::Format(wxT("%d"), m_min) );
315 m_textMax->SetValue( wxString::Format(wxT("%d"), m_max) );
316
317 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
318
319 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetLineSize,
320 wxT("Li&ne size"),
321 SliderPage_LineSizeText,
322 &m_textLineSize);
323
324 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
325
326 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetPageSize,
327 wxT("P&age size"),
328 SliderPage_PageSizeText,
329 &m_textPageSize);
330
331 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
332
333 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetTickFreq,
334 wxT("Tick &frequency"),
335 SliderPage_TickFreqText,
336 &m_textTickFreq);
337
338 m_textTickFreq->SetValue(wxT("10"));
339
340 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
341
342 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetThumbLen,
343 wxT("Thumb &length"),
344 SliderPage_ThumbLenText,
345 &m_textThumbLen);
346
347 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
348
349 // right pane
350 wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
351 sizerRight->SetMinSize(150, 40);
352 m_sizerSlider = sizerRight; // save it to modify it later
353
354 Reset();
355 CreateSlider();
356
357 m_textLineSize->SetValue(wxString::Format(wxT("%d"), m_slider->GetLineSize()));
358 m_textPageSize->SetValue(wxString::Format(wxT("%d"), m_slider->GetPageSize()));
359
360 // the 3 panes panes compose the window
361 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
362 sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
363 sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
364
365 // final initializations
366 SetSizer(sizerTop);
367 }
368
369 // ----------------------------------------------------------------------------
370 // operations
371 // ----------------------------------------------------------------------------
372
373 void SliderWidgetsPage::Reset()
374 {
375 m_chkInverse->SetValue(false);
376 m_chkTicks->SetValue(true);
377 m_chkValueLabel->SetValue(true);
378 m_chkMinMaxLabels->SetValue(true);
379 m_chkBothSides->SetValue(false);
380
381 m_radioSides->SetSelection(SliderTicks_None);
382 }
383
384 void SliderWidgetsPage::CreateSlider()
385 {
386 int flags = ms_defaultFlags;
387
388 if ( m_chkInverse->GetValue() )
389 {
390 flags |= wxSL_INVERSE;
391 }
392
393 if ( m_chkMinMaxLabels->GetValue() )
394 {
395 flags |= wxSL_MIN_MAX_LABELS;
396 }
397
398 if ( m_chkValueLabel->GetValue() )
399 {
400 flags |= wxSL_VALUE_LABEL;
401 }
402
403 if ( m_chkTicks->GetValue() )
404 {
405 flags |= wxSL_AUTOTICKS;
406 }
407
408 // notice that the style names refer to the _ticks_ positions while we want
409 // to allow the user to select the label(s) positions and the labels are on
410 // the opposite side from the ticks, hence the apparent reversal below
411 switch ( m_radioSides->GetSelection() )
412 {
413 case SliderTicks_None:
414 break;
415
416 case SliderTicks_Top:
417 flags |= wxSL_BOTTOM;
418 break;
419
420 case SliderTicks_Left:
421 flags |= wxSL_RIGHT | wxSL_VERTICAL;
422 break;
423
424 case SliderTicks_Bottom:
425 flags |= wxSL_TOP;
426 break;
427
428 case SliderTicks_Right:
429 flags |= wxSL_LEFT | wxSL_VERTICAL;
430 break;
431
432 default:
433 wxFAIL_MSG(wxT("unexpected radiobox selection"));
434 // fall through
435 }
436
437 if ( m_chkBothSides->GetValue() )
438 {
439 flags |= wxSL_BOTH;
440 }
441
442 int val = m_min;
443 if ( m_slider )
444 {
445 int valOld = m_slider->GetValue();
446 if ( !IsValidValue(valOld) )
447 {
448 val = valOld;
449 }
450
451 m_sizerSlider->Detach( m_slider );
452
453 if ( m_sizerSlider->GetChildren().GetCount() )
454 {
455 // we have 2 spacers, remove them too
456 m_sizerSlider->Remove( 0 );
457 m_sizerSlider->Remove( 0 );
458 }
459
460 delete m_slider;
461 }
462
463 m_slider = new wxSlider(this, SliderPage_Slider,
464 val, m_min, m_max,
465 wxDefaultPosition, wxDefaultSize,
466 flags);
467
468 if ( m_slider->HasFlag(wxSL_VERTICAL) )
469 {
470 m_sizerSlider->Add(0, 0, 1);
471 m_sizerSlider->Add(m_slider, 0, wxGROW | wxALL, 5);
472 m_sizerSlider->Add(0, 0, 1);
473 }
474 else
475 {
476 m_sizerSlider->Add(m_slider, 1, wxCENTRE | wxALL, 5);
477 }
478
479 if ( m_chkTicks->GetValue() )
480 {
481 DoSetTickFreq();
482 }
483
484 m_sizerSlider->Layout();
485 }
486
487 void SliderWidgetsPage::DoSetLineSize()
488 {
489 long lineSize;
490 if ( !m_textLineSize->GetValue().ToLong(&lineSize) )
491 {
492 wxLogWarning(wxT("Invalid slider line size"));
493
494 return;
495 }
496
497 m_slider->SetLineSize(lineSize);
498
499 if ( m_slider->GetLineSize() != lineSize )
500 {
501 wxLogWarning(wxT("Invalid line size in slider."));
502 }
503 }
504
505 void SliderWidgetsPage::DoSetPageSize()
506 {
507 long pageSize;
508 if ( !m_textPageSize->GetValue().ToLong(&pageSize) )
509 {
510 wxLogWarning(wxT("Invalid slider page size"));
511
512 return;
513 }
514
515 m_slider->SetPageSize(pageSize);
516
517 if ( m_slider->GetPageSize() != pageSize )
518 {
519 wxLogWarning(wxT("Invalid page size in slider."));
520 }
521 }
522
523 void SliderWidgetsPage::DoSetTickFreq()
524 {
525 long freq;
526 if ( !m_textTickFreq->GetValue().ToLong(&freq) )
527 {
528 wxLogWarning(wxT("Invalid slider tick frequency"));
529
530 return;
531 }
532
533 m_slider->SetTickFreq(freq);
534 }
535
536 void SliderWidgetsPage::DoSetThumbLen()
537 {
538 long len;
539 if ( !m_textThumbLen->GetValue().ToLong(&len) )
540 {
541 wxLogWarning(wxT("Invalid slider thumb length"));
542
543 return;
544 }
545
546 m_slider->SetThumbLength(len);
547 }
548
549 // ----------------------------------------------------------------------------
550 // event handlers
551 // ----------------------------------------------------------------------------
552
553 void SliderWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
554 {
555 Reset();
556
557 CreateSlider();
558 }
559
560 void SliderWidgetsPage::OnButtonSetLineSize(wxCommandEvent& WXUNUSED(event))
561 {
562 DoSetLineSize();
563 }
564
565 void SliderWidgetsPage::OnButtonSetPageSize(wxCommandEvent& WXUNUSED(event))
566 {
567 DoSetPageSize();
568 }
569
570 void SliderWidgetsPage::OnButtonSetTickFreq(wxCommandEvent& WXUNUSED(event))
571 {
572 DoSetTickFreq();
573 }
574
575 void SliderWidgetsPage::OnButtonSetThumbLen(wxCommandEvent& WXUNUSED(event))
576 {
577 DoSetThumbLen();
578 }
579
580 void SliderWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
581 {
582 long minNew,
583 maxNew = 0; // init to suppress compiler warning
584 if ( !m_textMin->GetValue().ToLong(&minNew) ||
585 !m_textMax->GetValue().ToLong(&maxNew) ||
586 minNew >= maxNew )
587 {
588 wxLogWarning(wxT("Invalid min/max values for the slider."));
589
590 return;
591 }
592
593 m_min = minNew;
594 m_max = maxNew;
595
596 m_slider->SetRange(minNew, maxNew);
597
598 if ( m_slider->GetMin() != m_min ||
599 m_slider->GetMax() != m_max )
600 {
601 wxLogWarning(wxT("Invalid range in slider."));
602 }
603 }
604
605 void SliderWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
606 {
607 long val;
608 if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
609 {
610 wxLogWarning(wxT("Invalid slider value."));
611
612 return;
613 }
614
615 m_slider->SetValue(val);
616 }
617
618 void SliderWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
619 {
620 long val;
621 event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
622 }
623
624 void SliderWidgetsPage::OnUpdateUILineSize(wxUpdateUIEvent& event)
625 {
626 long lineSize;
627 event.Enable( m_textLineSize->GetValue().ToLong(&lineSize) &&
628 (lineSize > 0) && (lineSize <= m_max - m_min) );
629 }
630
631 void SliderWidgetsPage::OnUpdateUIPageSize(wxUpdateUIEvent& event)
632 {
633 long pageSize;
634 event.Enable( m_textPageSize->GetValue().ToLong(&pageSize) &&
635 (pageSize > 0) && (pageSize <= m_max - m_min) );
636 }
637
638 void SliderWidgetsPage::OnUpdateUITickFreq(wxUpdateUIEvent& event)
639 {
640 long freq;
641 event.Enable( m_chkTicks->GetValue() &&
642 m_textTickFreq->GetValue().ToLong(&freq) &&
643 (freq > 0) && (freq <= m_max - m_min) );
644 }
645
646 void SliderWidgetsPage::OnUpdateUIThumbLen(wxUpdateUIEvent& event)
647 {
648 long val;
649 event.Enable( m_textThumbLen->GetValue().ToLong(&val));
650 }
651
652 void SliderWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
653 {
654 long mn, mx;
655 event.Enable( m_textMin->GetValue().ToLong(&mn) &&
656 m_textMax->GetValue().ToLong(&mx) &&
657 mn < mx);
658 }
659
660 void SliderWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
661 {
662 event.Enable( m_chkInverse->GetValue() ||
663 !m_chkTicks->GetValue() ||
664 !m_chkValueLabel->GetValue() ||
665 !m_chkMinMaxLabels->GetValue() ||
666 m_chkBothSides->GetValue() ||
667 m_radioSides->GetSelection() != SliderTicks_None );
668 }
669
670 void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
671 {
672 CreateSlider();
673 }
674
675 void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
676 {
677 event.SetText( wxString::Format(wxT("%d"), m_slider->GetValue()) );
678 }
679
680 void SliderWidgetsPage::OnUpdateUIRadioSides(wxUpdateUIEvent& event)
681 {
682 event.Enable( m_chkValueLabel->GetValue() || m_chkTicks->GetValue() );
683 }
684
685 void SliderWidgetsPage::OnUpdateUIBothSides(wxUpdateUIEvent& event)
686 {
687 #if defined(__WXMSW__) || defined(__WXUNIVERSAL__)
688 event.Enable( m_chkTicks->GetValue() );
689 #else
690 event.Enable( false );
691 #endif // defined(__WXMSW__) || defined(__WXUNIVERSAL__)
692 }
693
694 void SliderWidgetsPage::OnSlider(wxScrollEvent& event)
695 {
696 wxASSERT_MSG( event.GetInt() == m_slider->GetValue(),
697 wxT("slider value should be the same") );
698
699 wxEventType eventType = event.GetEventType();
700
701 /*
702 This array takes the EXACT order of the declarations in
703 include/wx/event.h
704 (section "wxScrollBar and wxSlider event identifiers")
705 */
706 static const wxChar *eventNames[] =
707 {
708 wxT("wxEVT_SCROLL_TOP"),
709 wxT("wxEVT_SCROLL_BOTTOM"),
710 wxT("wxEVT_SCROLL_LINEUP"),
711 wxT("wxEVT_SCROLL_LINEDOWN"),
712 wxT("wxEVT_SCROLL_PAGEUP"),
713 wxT("wxEVT_SCROLL_PAGEDOWN"),
714 wxT("wxEVT_SCROLL_THUMBTRACK"),
715 wxT("wxEVT_SCROLL_THUMBRELEASE"),
716 wxT("wxEVT_SCROLL_CHANGED")
717 };
718
719 int index = eventType - wxEVT_SCROLL_TOP;
720
721 /*
722 If this assert is triggered, there is an unknown slider event which
723 should be added to the above eventNames array.
724 */
725 wxASSERT_MSG(index >= 0 && (size_t)index < WXSIZEOF(eventNames),
726 wxT("Unknown slider event") );
727
728
729 static int s_numSliderEvents = 0;
730
731 wxLogMessage(wxT("Slider event #%d: %s (pos = %d, int value = %d)"),
732 s_numSliderEvents++,
733 eventNames[index],
734 event.GetPosition(),
735 event.GetInt());
736 }
737
738 #endif // wxUSE_SLIDER