1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/slider.h
3 // Purpose: wxSlider control for wxUniversal
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma interface "univslider.h"
16 #ifndef _WX_UNIV_SLIDER_H_
17 #define _WX_UNIV_SLIDER_H_
19 #include "wx/univ/scrthumb.h"
21 // ----------------------------------------------------------------------------
22 // the actions supported by this control
23 // ----------------------------------------------------------------------------
25 // our actions are the same as scrollbars
27 #define wxACTION_SLIDER_START _T("start") // to the beginning
28 #define wxACTION_SLIDER_END _T("end") // to the end
29 #define wxACTION_SLIDER_LINE_UP _T("lineup") // one line up/left
30 #define wxACTION_SLIDER_PAGE_UP _T("pageup") // one page up/left
31 #define wxACTION_SLIDER_LINE_DOWN _T("linedown") // one line down/right
32 #define wxACTION_SLIDER_PAGE_DOWN _T("pagedown") // one page down/right
33 #define wxACTION_SLIDER_PAGE_CHANGE _T("pagechange")// change page by numArg
35 #define wxACTION_SLIDER_THUMB_DRAG _T("thumbdrag")
36 #define wxACTION_SLIDER_THUMB_MOVE _T("thumbmove")
37 #define wxACTION_SLIDER_THUMB_RELEASE _T("thumbrelease")
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxSlider
: public wxSliderBase
,
44 public wxControlWithThumb
50 wxSlider(wxWindow
*parent
,
52 int value
, int minValue
, int maxValue
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
55 long style
= wxSL_HORIZONTAL
,
56 const wxValidator
& validator
= wxDefaultValidator
,
57 const wxString
& name
= wxSliderNameStr
);
59 bool Create(wxWindow
*parent
,
61 int value
, int minValue
, int maxValue
,
62 const wxPoint
& pos
= wxDefaultPosition
,
63 const wxSize
& size
= wxDefaultSize
,
64 long style
= wxSL_HORIZONTAL
,
65 const wxValidator
& validator
= wxDefaultValidator
,
66 const wxString
& name
= wxSliderNameStr
);
68 // implement base class pure virtuals
69 virtual int GetValue() const;
70 virtual void SetValue(int value
);
72 virtual void SetRange(int minValue
, int maxValue
);
73 virtual int GetMin() const;
74 virtual int GetMax() const;
76 virtual void SetLineSize(int lineSize
);
77 virtual void SetPageSize(int pageSize
);
78 virtual int GetLineSize() const;
79 virtual int GetPageSize() const;
81 virtual void SetThumbLength(int lenPixels
);
82 virtual int GetThumbLength() const;
84 virtual void SetTickFreq(int n
, int WXUNUSED(dummy
) = 0);
85 virtual int GetTickFreq() const { return m_tickFreq
; }
87 // wxUniv-specific methods
88 // -----------------------
90 // is this a vertical slider?
91 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL
) != 0; }
93 // get the slider orientation
94 wxOrientation
GetOrientation() const
95 { return IsVert() ? wxVERTICAL
: wxHORIZONTAL
; }
98 bool HasLabels() const { return (GetWindowStyle() & wxSL_LABELS
) != 0; }
101 bool HasTicks() const { return (GetWindowStyle() & wxSL_TICKS
) != 0; }
103 // implement wxControlWithThumb interface
104 virtual wxWindow
*GetWindow() { return this; }
105 virtual bool IsVertical() const { return IsVert(); }
107 virtual wxScrollThumb::Shaft
HitTest(const wxPoint
& pt
) const;
108 virtual wxCoord
ThumbPosToPixel() const;
109 virtual int PixelToThumbPos(wxCoord x
) const;
111 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart
,
115 virtual void OnThumbDragStart(int pos
);
116 virtual void OnThumbDrag(int pos
);
117 virtual void OnThumbDragEnd(int pos
);
118 virtual void OnPageScrollStart();
119 virtual bool OnPageScroll(int pageInc
);
121 // for wxStdSliderButtonInputHandler
122 wxScrollThumb
& GetThumb() { return m_thumb
; }
127 INVALID_THUMB_VALUE
= -0xffff
130 // overridden base class virtuals
131 virtual wxSize
DoGetBestClientSize() const;
132 virtual void DoDraw(wxControlRenderer
*renderer
);
133 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
135 virtual bool PerformAction(const wxControlAction
& action
,
137 const wxString
& strArg
= wxEmptyString
);
140 void OnSize(wxSizeEvent
& event
);
142 // common part of all ctors
145 // normalize the value to fit in the range
146 int NormalizeValue(int value
) const;
148 // change the value by the given increment, return TRUE if really changed
149 bool ChangeValueBy(int inc
);
151 // change the value to the given one
152 bool ChangeValueTo(int value
);
154 // is the value inside the range?
155 bool IsInRange(int value
) { return (value
>= m_min
) && (value
<= m_max
); }
157 // format the value for printing as label
158 virtual wxString
FormatValue(int value
) const;
160 // calculate max label size
161 wxSize
CalcLabelSize() const;
163 // calculate m_rectLabel/Slider
166 // get the thumb size
167 wxSize
GetThumbSize() const;
169 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
170 wxRect
GetShaftRect() const;
172 // calc the current thumb position using the shaft rect (if the pointer is
173 // NULL, we calculate it here too)
174 void CalcThumbRect(const wxRect
*rectShaft
,
175 wxRect
*rectThumbOut
,
176 wxRect
*rectLabelOut
,
177 int value
= INVALID_THUMB_VALUE
) const;
179 // return the slider rect calculating it if needed
180 const wxRect
& GetSliderRect() const;
182 // refresh the current thumb position
186 // get the default thumb size (without using m_thumbSize)
187 wxSize
GetDefaultThumbSize() const;
189 // the object which manages our thumb
190 wxScrollThumb m_thumb
;
192 // the slider range and value
197 // the tick frequence (default is 1)
200 // the line and page increments (logical units)
204 // the size of the thumb (in pixels)
207 // the part of the client area reserved for the label, the ticks and the
208 // part for the slider itself
213 // the state of the thumb (wxCONTROL_XXX constants sum)
216 DECLARE_EVENT_TABLE()
217 DECLARE_DYNAMIC_CLASS(wxSlider
)
220 // ----------------------------------------------------------------------------
221 // wxStdSliderButtonInputHandler: default slider input handling
222 // ----------------------------------------------------------------------------
224 class WXDLLEXPORT wxStdSliderButtonInputHandler
: public wxStdInputHandler
228 wxStdSliderButtonInputHandler(wxInputHandler
*inphand
)
229 : wxStdInputHandler(inphand
)
233 // base class methods
234 virtual bool HandleKey(wxControl
*control
,
235 const wxKeyEvent
& event
,
237 virtual bool HandleMouse(wxControl
*control
,
238 const wxMouseEvent
& event
);
239 virtual bool HandleMouseMove(wxControl
*control
,
240 const wxMouseEvent
& event
);
242 virtual bool HandleFocus(wxControl
*control
, const wxFocusEvent
& event
);
245 #endif // _WX_UNIV_SLIDER_H_