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