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 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_SLIDER_H_
13 #define _WX_UNIV_SLIDER_H_
15 #include "wx/univ/scrthumb.h"
17 // ----------------------------------------------------------------------------
18 // the actions supported by this control
19 // ----------------------------------------------------------------------------
21 // our actions are the same as scrollbars
23 #define wxACTION_SLIDER_START wxT("start") // to the beginning
24 #define wxACTION_SLIDER_END wxT("end") // to the end
25 #define wxACTION_SLIDER_LINE_UP wxT("lineup") // one line up/left
26 #define wxACTION_SLIDER_PAGE_UP wxT("pageup") // one page up/left
27 #define wxACTION_SLIDER_LINE_DOWN wxT("linedown") // one line down/right
28 #define wxACTION_SLIDER_PAGE_DOWN wxT("pagedown") // one page down/right
29 #define wxACTION_SLIDER_PAGE_CHANGE wxT("pagechange")// change page by numArg
31 #define wxACTION_SLIDER_THUMB_DRAG wxT("thumbdrag")
32 #define wxACTION_SLIDER_THUMB_MOVE wxT("thumbmove")
33 #define wxACTION_SLIDER_THUMB_RELEASE wxT("thumbrelease")
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class WXDLLIMPEXP_CORE wxSlider
: public wxSliderBase
,
40 public wxControlWithThumb
46 wxSlider(wxWindow
*parent
,
48 int value
, int minValue
, int maxValue
,
49 const wxPoint
& pos
= wxDefaultPosition
,
50 const wxSize
& size
= wxDefaultSize
,
51 long style
= wxSL_HORIZONTAL
,
52 const wxValidator
& validator
= wxDefaultValidator
,
53 const wxString
& name
= wxSliderNameStr
);
55 bool Create(wxWindow
*parent
,
57 int value
, int minValue
, int maxValue
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
60 long style
= wxSL_HORIZONTAL
,
61 const wxValidator
& validator
= wxDefaultValidator
,
62 const wxString
& name
= wxSliderNameStr
);
64 // implement base class pure virtuals
65 virtual int GetValue() const;
66 virtual void SetValue(int value
);
68 virtual void SetRange(int minValue
, int maxValue
);
69 virtual int GetMin() const;
70 virtual int GetMax() const;
72 virtual void SetLineSize(int lineSize
);
73 virtual void SetPageSize(int pageSize
);
74 virtual int GetLineSize() const;
75 virtual int GetPageSize() const;
77 virtual void SetThumbLength(int lenPixels
);
78 virtual int GetThumbLength() const;
80 virtual int GetTickFreq() const { return m_tickFreq
; }
82 // wxUniv-specific methods
83 // -----------------------
85 // is this a vertical slider?
86 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL
) != 0; }
88 // get the slider orientation
89 wxOrientation
GetOrientation() const
90 { return IsVert() ? wxVERTICAL
: wxHORIZONTAL
; }
93 bool HasLabels() const
94 { return ((GetWindowStyle() & wxSL_LABELS
) != 0) &&
95 ((GetWindowStyle() & (wxSL_TOP
|wxSL_BOTTOM
|wxSL_LEFT
|wxSL_RIGHT
)) != 0); }
99 { return ((GetWindowStyle() & wxSL_TICKS
) != 0) &&
100 ((GetWindowStyle() & (wxSL_TOP
|wxSL_BOTTOM
|wxSL_LEFT
|wxSL_RIGHT
|wxSL_BOTH
)) != 0); }
102 // implement wxControlWithThumb interface
103 virtual wxWindow
*GetWindow() { return this; }
104 virtual bool IsVertical() const { return IsVert(); }
106 virtual wxScrollThumb::Shaft
HitTest(const wxPoint
& pt
) const;
107 virtual wxCoord
ThumbPosToPixel() const;
108 virtual int PixelToThumbPos(wxCoord x
) const;
110 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart
,
114 virtual void OnThumbDragStart(int pos
);
115 virtual void OnThumbDrag(int pos
);
116 virtual void OnThumbDragEnd(int pos
);
117 virtual void OnPageScrollStart();
118 virtual bool OnPageScroll(int pageInc
);
120 // for wxStdSliderInputHandler
121 wxScrollThumb
& GetThumb() { return m_thumb
; }
123 virtual bool PerformAction(const wxControlAction
& action
,
125 const wxString
& strArg
= wxEmptyString
);
127 static wxInputHandler
*GetStdInputHandler(wxInputHandler
*handlerDef
);
128 virtual wxInputHandler
*DoGetStdInputHandler(wxInputHandler
*handlerDef
)
130 return GetStdInputHandler(handlerDef
);
136 INVALID_THUMB_VALUE
= -0xffff
139 // Platform-specific implementation of SetTickFreq
140 virtual void DoSetTickFreq(int freq
);
142 // overridden base class virtuals
143 virtual wxSize
DoGetBestClientSize() const;
144 virtual void DoDraw(wxControlRenderer
*renderer
);
145 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
148 void OnSize(wxSizeEvent
& event
);
150 // common part of all ctors
153 // normalize the value to fit in the range
154 int NormalizeValue(int value
) const;
156 // change the value by the given increment, return true if really changed
157 bool ChangeValueBy(int inc
);
159 // change the value to the given one
160 bool ChangeValueTo(int value
);
162 // is the value inside the range?
163 bool IsInRange(int value
) { return (value
>= m_min
) && (value
<= m_max
); }
165 // format the value for printing as label
166 virtual wxString
FormatValue(int value
) const;
168 // calculate max label size
169 wxSize
CalcLabelSize() const;
171 // calculate m_rectLabel/Slider
174 // get the thumb size
175 wxSize
GetThumbSize() const;
177 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
178 wxRect
GetShaftRect() const;
180 // calc the current thumb position using the shaft rect (if the pointer is
181 // NULL, we calculate it here too)
182 void CalcThumbRect(const wxRect
*rectShaft
,
183 wxRect
*rectThumbOut
,
184 wxRect
*rectLabelOut
,
185 int value
= INVALID_THUMB_VALUE
) const;
187 // return the slider rect calculating it if needed
188 const wxRect
& GetSliderRect() const;
190 // refresh the current thumb position
194 // get the default thumb size (without using m_thumbSize)
195 wxSize
GetDefaultThumbSize() const;
197 // the object which manages our thumb
198 wxScrollThumb m_thumb
;
200 // the slider range and value
205 // the tick frequence (default is 1)
208 // the line and page increments (logical units)
212 // the size of the thumb (in pixels)
215 // the part of the client area reserved for the label, the ticks and the
216 // part for the slider itself
221 // the state of the thumb (wxCONTROL_XXX constants sum)
224 DECLARE_EVENT_TABLE()
225 DECLARE_DYNAMIC_CLASS(wxSlider
)
228 #endif // _WX_UNIV_SLIDER_H_