]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/slider.cpp
Suppress errors from static bitmap page of widgets sample.
[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{
c0a9fe92 83 SliderTicks_None,
93103bab
VZ
84 SliderTicks_Top,
85 SliderTicks_Bottom,
86 SliderTicks_Left,
87 SliderTicks_Right
53b98211
JS
88};
89
32b8ec41
VZ
90// ----------------------------------------------------------------------------
91// SliderWidgetsPage
92// ----------------------------------------------------------------------------
93
94class SliderWidgetsPage : public WidgetsPage
95{
96public:
f2fdc4d5 97 SliderWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
8f6eaec9 98 virtual ~SliderWidgetsPage(){};
32b8ec41 99
195df7a7 100 virtual wxControl *GetWidget() const { return m_slider; }
1301e228 101 virtual void RecreateWidget() { CreateSlider(); }
195df7a7 102
453535a7
WS
103 // lazy creation of the content
104 virtual void CreateContent();
105
32b8ec41
VZ
106protected:
107 // event handlers
108 void OnButtonReset(wxCommandEvent& event);
109 void OnButtonClear(wxCommandEvent& event);
110 void OnButtonSetValue(wxCommandEvent& event);
111 void OnButtonSetMinAndMax(wxCommandEvent& event);
d6c1aef8
MR
112 void OnButtonSetLineSize(wxCommandEvent& event);
113 void OnButtonSetPageSize(wxCommandEvent& event);
32b8ec41 114 void OnButtonSetTickFreq(wxCommandEvent& event);
53b98211 115 void OnButtonSetThumbLen(wxCommandEvent& event);
32b8ec41
VZ
116
117 void OnCheckOrRadioBox(wxCommandEvent& event);
118
d79b005a 119 void OnSlider(wxScrollEvent& event);
32b8ec41 120
32b8ec41
VZ
121 void OnUpdateUIValueButton(wxUpdateUIEvent& event);
122 void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
d6c1aef8
MR
123 void OnUpdateUILineSize(wxUpdateUIEvent& event);
124 void OnUpdateUIPageSize(wxUpdateUIEvent& event);
32b8ec41 125 void OnUpdateUITickFreq(wxUpdateUIEvent& event);
53b98211
JS
126 void OnUpdateUIThumbLen(wxUpdateUIEvent& event);
127 void OnUpdateUIRadioSides(wxUpdateUIEvent& event);
128 void OnUpdateUIBothSides(wxUpdateUIEvent& event);
32b8ec41
VZ
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
d6c1aef8
MR
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
32b8ec41
VZ
146 // set the tick frequency from the text field value
147 void DoSetTickFreq();
148
53b98211
JS
149 // set the thumb len from the text field value
150 void DoSetThumbLen();
151
32b8ec41
VZ
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
7de83494
RR
163 wxCheckBox *m_chkMinMaxLabels,
164 *m_chkValueLabel,
2bcdbe0f 165 *m_chkInverse,
53b98211
JS
166 *m_chkTicks,
167 *m_chkBothSides;
168
169 wxRadioBox *m_radioSides;
32b8ec41
VZ
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,
d6c1aef8
MR
179 *m_textLineSize,
180 *m_textPageSize,
53b98211
JS
181 *m_textTickFreq,
182 *m_textThumbLen;
32b8ec41
VZ
183
184private:
5e173f35
GD
185 DECLARE_EVENT_TABLE()
186 DECLARE_WIDGETS_PAGE(SliderWidgetsPage)
32b8ec41
VZ
187};
188
189// ----------------------------------------------------------------------------
190// event tables
191// ----------------------------------------------------------------------------
192
193BEGIN_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)
d6c1aef8
MR
197 EVT_BUTTON(SliderPage_SetLineSize, SliderWidgetsPage::OnButtonSetLineSize)
198 EVT_BUTTON(SliderPage_SetPageSize, SliderWidgetsPage::OnButtonSetPageSize)
32b8ec41 199 EVT_BUTTON(SliderPage_SetTickFreq, SliderWidgetsPage::OnButtonSetTickFreq)
53b98211 200 EVT_BUTTON(SliderPage_SetThumbLen, SliderWidgetsPage::OnButtonSetThumbLen)
32b8ec41
VZ
201
202 EVT_UPDATE_UI(SliderPage_SetValue, SliderWidgetsPage::OnUpdateUIValueButton)
203 EVT_UPDATE_UI(SliderPage_SetMinAndMax, SliderWidgetsPage::OnUpdateUIMinMaxButton)
d6c1aef8
MR
204 EVT_UPDATE_UI(SliderPage_SetLineSize, SliderWidgetsPage::OnUpdateUILineSize)
205 EVT_UPDATE_UI(SliderPage_SetPageSize, SliderWidgetsPage::OnUpdateUIPageSize)
32b8ec41 206 EVT_UPDATE_UI(SliderPage_SetTickFreq, SliderWidgetsPage::OnUpdateUITickFreq)
53b98211 207 EVT_UPDATE_UI(SliderPage_SetThumbLen, SliderWidgetsPage::OnUpdateUIThumbLen)
53b98211
JS
208 EVT_UPDATE_UI(SliderPage_RadioSides, SliderWidgetsPage::OnUpdateUIRadioSides)
209 EVT_UPDATE_UI(SliderPage_BothSides, SliderWidgetsPage::OnUpdateUIBothSides)
32b8ec41
VZ
210
211 EVT_UPDATE_UI(SliderPage_Reset, SliderWidgetsPage::OnUpdateUIResetButton)
212
213 EVT_UPDATE_UI(SliderPage_CurValueText, SliderWidgetsPage::OnUpdateUICurValueText)
214
d79b005a 215 EVT_COMMAND_SCROLL(SliderPage_Slider, SliderWidgetsPage::OnSlider)
32b8ec41 216
206d3a16
JS
217 EVT_CHECKBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
218 EVT_RADIOBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
32b8ec41
VZ
219END_EVENT_TABLE()
220
221// ============================================================================
222// implementation
223// ============================================================================
224
f0fa4312
WS
225#if defined(__WXUNIVERSAL__)
226 #define FAMILY_CTRLS UNIVERSAL_CTRLS
227#else
228 #define FAMILY_CTRLS NATIVE_CTRLS
229#endif
230
9a83f860 231IMPLEMENT_WIDGETS_PAGE(SliderWidgetsPage, wxT("Slider"), FAMILY_CTRLS );
32b8ec41 232
f2fdc4d5 233SliderWidgetsPage::SliderWidgetsPage(WidgetsBookCtrl *book,
61c083e7 234 wxImageList *imaglist)
261357eb 235 : WidgetsPage(book, imaglist, slider_xpm)
32b8ec41 236{
32b8ec41
VZ
237 // init everything
238 m_min = 0;
239 m_max = 100;
240
dc3155f1 241 m_chkInverse =
32b8ec41 242 m_chkTicks =
7de83494
RR
243 m_chkMinMaxLabels =
244 m_chkValueLabel =
53b98211
JS
245 m_chkBothSides = (wxCheckBox *)NULL;
246
247 m_radioSides = (wxRadioBox *)NULL;
32b8ec41
VZ
248
249 m_slider = (wxSlider *)NULL;
250 m_sizerSlider = (wxSizer *)NULL;
453535a7 251}
32b8ec41 252
453535a7
WS
253void SliderWidgetsPage::CreateContent()
254{
32b8ec41
VZ
255 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
256
257 // left pane
9a83f860 258 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
32b8ec41
VZ
259 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
260
9a83f860
VZ
261 m_chkInverse = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Inverse"));
262 m_chkTicks = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Show &ticks"));
7de83494
RR
263 m_chkMinMaxLabels = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Show min/max &labels"));
264 m_chkValueLabel = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Show &value label"));
53b98211
JS
265 static const wxString sides[] =
266 {
c0a9fe92 267 wxT("default"),
9a83f860
VZ
268 wxT("top"),
269 wxT("bottom"),
270 wxT("left"),
271 wxT("right"),
53b98211 272 };
c0a9fe92 273 m_radioSides = new wxRadioBox(this, SliderPage_RadioSides, wxT("&Label position"),
53b98211
JS
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
9a83f860 279 (sizerLeft, wxT("&Both sides"), SliderPage_BothSides);
53b98211 280#if wxUSE_TOOLTIPS
9a83f860 281 m_chkBothSides->SetToolTip( wxT("\"Both sides\" is only supported \nin Win95 and Universal") );
53b98211 282#endif // wxUSE_TOOLTIPS
32b8ec41
VZ
283
284 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
285
9a83f860 286 wxButton *btn = new wxButton(this, SliderPage_Reset, wxT("&Reset"));
32b8ec41
VZ
287 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
288
289 // middle pane
9a83f860 290 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Change slider value"));
32b8ec41
VZ
291 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
292
293 wxTextCtrl *text;
9a83f860 294 wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Current value"),
32b8ec41
VZ
295 SliderPage_CurValueText,
296 &text);
206d3a16 297 text->SetEditable(false);
32b8ec41
VZ
298
299 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
300
301 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetValue,
9a83f860 302 wxT("Set &value"),
32b8ec41
VZ
303 SliderPage_ValueText,
304 &m_textValue);
305 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
306
307 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetMinAndMax,
9a83f860 308 wxT("&Min and max"),
32b8ec41
VZ
309 SliderPage_MinText,
310 &m_textMin);
311
206d3a16 312 m_textMax = new wxTextCtrl(this, SliderPage_MaxText, wxEmptyString);
32b8ec41
VZ
313 sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
314
9a83f860
VZ
315 m_textMin->SetValue( wxString::Format(wxT("%d"), m_min) );
316 m_textMax->SetValue( wxString::Format(wxT("%d"), m_max) );
32b8ec41
VZ
317
318 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
319
d6c1aef8 320 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetLineSize,
9a83f860 321 wxT("Li&ne size"),
d6c1aef8
MR
322 SliderPage_LineSizeText,
323 &m_textLineSize);
324
325 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
326
327 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetPageSize,
9a83f860 328 wxT("P&age size"),
d6c1aef8
MR
329 SliderPage_PageSizeText,
330 &m_textPageSize);
331
332 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
333
32b8ec41 334 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetTickFreq,
9a83f860 335 wxT("Tick &frequency"),
32b8ec41
VZ
336 SliderPage_TickFreqText,
337 &m_textTickFreq);
338
9a83f860 339 m_textTickFreq->SetValue(wxT("10"));
32b8ec41
VZ
340
341 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
342
53b98211 343 sizerRow = CreateSizerWithTextAndButton(SliderPage_SetThumbLen,
9a83f860 344 wxT("Thumb &length"),
53b98211
JS
345 SliderPage_ThumbLenText,
346 &m_textThumbLen);
347
348 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
349
32b8ec41
VZ
350 // right pane
351 wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
53b98211 352 sizerRight->SetMinSize(150, 40);
32b8ec41
VZ
353 m_sizerSlider = sizerRight; // save it to modify it later
354
355 Reset();
356 CreateSlider();
357
9a83f860
VZ
358 m_textLineSize->SetValue(wxString::Format(wxT("%d"), m_slider->GetLineSize()));
359 m_textPageSize->SetValue(wxString::Format(wxT("%d"), m_slider->GetPageSize()));
d6c1aef8 360
32b8ec41
VZ
361 // the 3 panes panes compose the window
362 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
7b127900 363 sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
32b8ec41
VZ
364 sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
365
366 // final initializations
32b8ec41 367 SetSizer(sizerTop);
32b8ec41
VZ
368}
369
32b8ec41
VZ
370// ----------------------------------------------------------------------------
371// operations
372// ----------------------------------------------------------------------------
373
374void SliderWidgetsPage::Reset()
375{
2bcdbe0f 376 m_chkInverse->SetValue(false);
206d3a16 377 m_chkTicks->SetValue(true);
7de83494
RR
378 m_chkValueLabel->SetValue(true);
379 m_chkMinMaxLabels->SetValue(true);
206d3a16 380 m_chkBothSides->SetValue(false);
53b98211 381
c0a9fe92 382 m_radioSides->SetSelection(SliderTicks_None);
32b8ec41
VZ
383}
384
385void SliderWidgetsPage::CreateSlider()
386{
1301e228 387 int flags = ms_defaultFlags;
32b8ec41 388
2bcdbe0f
KH
389 if ( m_chkInverse->GetValue() )
390 {
391 flags |= wxSL_INVERSE;
392 }
393
7de83494 394 if ( m_chkMinMaxLabels->GetValue() )
32b8ec41 395 {
7de83494
RR
396 flags |= wxSL_MIN_MAX_LABELS;
397 }
398
399 if ( m_chkValueLabel->GetValue() )
400 {
401 flags |= wxSL_VALUE_LABEL;
32b8ec41
VZ
402 }
403
404 if ( m_chkTicks->GetValue() )
405 {
406 flags |= wxSL_AUTOTICKS;
407 }
408
c0a9fe92
VZ
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
53b98211
JS
412 switch ( m_radioSides->GetSelection() )
413 {
c0a9fe92
VZ
414 case SliderTicks_None:
415 break;
416
93103bab 417 case SliderTicks_Top:
c0a9fe92 418 flags |= wxSL_BOTTOM;
53b98211 419 break;
93103bab
VZ
420
421 case SliderTicks_Left:
c0a9fe92 422 flags |= wxSL_RIGHT | wxSL_VERTICAL;
53b98211 423 break;
93103bab
VZ
424
425 case SliderTicks_Bottom:
c0a9fe92 426 flags |= wxSL_TOP;
53b98211 427 break;
93103bab 428
510878aa 429 case SliderTicks_Right:
c0a9fe92 430 flags |= wxSL_LEFT | wxSL_VERTICAL;
53b98211 431 break;
93103bab 432
53b98211 433 default:
9a83f860 434 wxFAIL_MSG(wxT("unexpected radiobox selection"));
53b98211
JS
435 // fall through
436 }
437
438 if ( m_chkBothSides->GetValue() )
439 {
440 flags |= wxSL_BOTH;
441 }
442
32b8ec41
VZ
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
12a3f227 452 m_sizerSlider->Detach( m_slider );
32b8ec41
VZ
453
454 if ( m_sizerSlider->GetChildren().GetCount() )
455 {
456 // we have 2 spacers, remove them too
9dd96c0f
VZ
457 m_sizerSlider->Remove( 0 );
458 m_sizerSlider->Remove( 0 );
32b8ec41
VZ
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
93103bab 469 if ( m_slider->HasFlag(wxSL_VERTICAL) )
32b8ec41
VZ
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
d6c1aef8
MR
488void SliderWidgetsPage::DoSetLineSize()
489{
490 long lineSize;
491 if ( !m_textLineSize->GetValue().ToLong(&lineSize) )
492 {
9a83f860 493 wxLogWarning(wxT("Invalid slider line size"));
d6c1aef8
MR
494
495 return;
496 }
497
498 m_slider->SetLineSize(lineSize);
499
500 if ( m_slider->GetLineSize() != lineSize )
501 {
9a83f860 502 wxLogWarning(wxT("Invalid line size in slider."));
d6c1aef8
MR
503 }
504}
505
506void SliderWidgetsPage::DoSetPageSize()
507{
508 long pageSize;
509 if ( !m_textPageSize->GetValue().ToLong(&pageSize) )
510 {
9a83f860 511 wxLogWarning(wxT("Invalid slider page size"));
d6c1aef8
MR
512
513 return;
514 }
515
516 m_slider->SetPageSize(pageSize);
517
518 if ( m_slider->GetPageSize() != pageSize )
519 {
9a83f860 520 wxLogWarning(wxT("Invalid page size in slider."));
d6c1aef8
MR
521 }
522}
523
32b8ec41
VZ
524void SliderWidgetsPage::DoSetTickFreq()
525{
526 long freq;
527 if ( !m_textTickFreq->GetValue().ToLong(&freq) )
528 {
9a83f860 529 wxLogWarning(wxT("Invalid slider tick frequency"));
32b8ec41
VZ
530
531 return;
532 }
533
534 m_slider->SetTickFreq(freq, 0 /* unused */);
535}
536
53b98211
JS
537void SliderWidgetsPage::DoSetThumbLen()
538{
539 long len;
540 if ( !m_textThumbLen->GetValue().ToLong(&len) )
541 {
9a83f860 542 wxLogWarning(wxT("Invalid slider thumb length"));
53b98211
JS
543
544 return;
545 }
546
547 m_slider->SetThumbLength(len);
548}
549
32b8ec41
VZ
550// ----------------------------------------------------------------------------
551// event handlers
552// ----------------------------------------------------------------------------
553
554void SliderWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
555{
556 Reset();
557
558 CreateSlider();
559}
560
d6c1aef8
MR
561void SliderWidgetsPage::OnButtonSetLineSize(wxCommandEvent& WXUNUSED(event))
562{
563 DoSetLineSize();
564}
565
566void SliderWidgetsPage::OnButtonSetPageSize(wxCommandEvent& WXUNUSED(event))
567{
568 DoSetPageSize();
569}
570
32b8ec41
VZ
571void SliderWidgetsPage::OnButtonSetTickFreq(wxCommandEvent& WXUNUSED(event))
572{
573 DoSetTickFreq();
574}
575
53b98211
JS
576void SliderWidgetsPage::OnButtonSetThumbLen(wxCommandEvent& WXUNUSED(event))
577{
578 DoSetThumbLen();
579}
580
32b8ec41
VZ
581void 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 {
9a83f860 589 wxLogWarning(wxT("Invalid min/max values for the slider."));
32b8ec41
VZ
590
591 return;
592 }
593
594 m_min = minNew;
595 m_max = maxNew;
596
597 m_slider->SetRange(minNew, maxNew);
9690a439
WS
598
599 if ( m_slider->GetMin() != m_min ||
600 m_slider->GetMax() != m_max )
601 {
9a83f860 602 wxLogWarning(wxT("Invalid range in slider."));
9690a439 603 }
32b8ec41
VZ
604}
605
606void SliderWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
607{
608 long val;
609 if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
610 {
9a83f860 611 wxLogWarning(wxT("Invalid slider value."));
32b8ec41
VZ
612
613 return;
614 }
615
616 m_slider->SetValue(val);
617}
618
619void SliderWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
620{
621 long val;
622 event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
623}
624
d6c1aef8
MR
625void 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
632void 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
32b8ec41
VZ
639void 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
53b98211
JS
647void SliderWidgetsPage::OnUpdateUIThumbLen(wxUpdateUIEvent& event)
648{
649 long val;
650 event.Enable( m_textThumbLen->GetValue().ToLong(&val));
651}
652
32b8ec41
VZ
653void 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
661void SliderWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
662{
93103bab 663 event.Enable( m_chkInverse->GetValue() ||
53b98211 664 !m_chkTicks->GetValue() ||
7de83494
RR
665 !m_chkValueLabel->GetValue() ||
666 !m_chkMinMaxLabels->GetValue() ||
93103bab 667 m_chkBothSides->GetValue() ||
c0a9fe92 668 m_radioSides->GetSelection() != SliderTicks_None );
32b8ec41
VZ
669}
670
c02e5a31 671void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
672{
673 CreateSlider();
674}
675
676void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
677{
9a83f860 678 event.SetText( wxString::Format(wxT("%d"), m_slider->GetValue()) );
32b8ec41
VZ
679}
680
53b98211
JS
681void SliderWidgetsPage::OnUpdateUIRadioSides(wxUpdateUIEvent& event)
682{
7de83494 683 event.Enable( m_chkValueLabel->GetValue() || m_chkTicks->GetValue() );
53b98211
JS
684}
685
686void SliderWidgetsPage::OnUpdateUIBothSides(wxUpdateUIEvent& event)
32b8ec41 687{
a71d815b 688#if defined(__WXMSW__) || defined(__WXUNIVERSAL__)
53b98211
JS
689 event.Enable( m_chkTicks->GetValue() );
690#else
206d3a16 691 event.Enable( false );
a71d815b 692#endif // defined(__WXMSW__) || defined(__WXUNIVERSAL__)
32b8ec41
VZ
693}
694
d79b005a 695void SliderWidgetsPage::OnSlider(wxScrollEvent& event)
32b8ec41 696{
2b5f62a0
VZ
697 wxASSERT_MSG( event.GetInt() == m_slider->GetValue(),
698 wxT("slider value should be the same") );
32b8ec41 699
d79b005a
VZ
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"),
cbc85508 717 wxT("wxEVT_SCROLL_CHANGED")
d79b005a
VZ
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 */
8b1d8f36 726 wxASSERT_MSG(index >= 0 && (size_t)index < WXSIZEOF(eventNames),
d79b005a
VZ
727 wxT("Unknown slider event") );
728
729
730 static int s_numSliderEvents = 0;
731
33cf9a19 732 wxLogMessage(wxT("Slider event #%d: %s (pos = %d, int value = %d)"),
580d78b3 733 s_numSliderEvents++,
d79b005a 734 eventNames[index],
2bcdbe0f
KH
735 event.GetPosition(),
736 event.GetInt());
32b8ec41
VZ
737}
738
61c083e7 739#endif // wxUSE_SLIDER