1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/slider.h
3 // Purpose: wxSlider control for wxUniversal
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIV_SLIDER_H_
12 #define _WX_UNIV_SLIDER_H_
14 #include "wx/univ/scrthumb.h"
16 // ----------------------------------------------------------------------------
17 // the actions supported by this control
18 // ----------------------------------------------------------------------------
20 // our actions are the same as scrollbars
22 #define wxACTION_SLIDER_START wxT("start") // to the beginning
23 #define wxACTION_SLIDER_END wxT("end") // to the end
24 #define wxACTION_SLIDER_LINE_UP wxT("lineup") // one line up/left
25 #define wxACTION_SLIDER_PAGE_UP wxT("pageup") // one page up/left
26 #define wxACTION_SLIDER_LINE_DOWN wxT("linedown") // one line down/right
27 #define wxACTION_SLIDER_PAGE_DOWN wxT("pagedown") // one page down/right
28 #define wxACTION_SLIDER_PAGE_CHANGE wxT("pagechange")// change page by numArg
30 #define wxACTION_SLIDER_THUMB_DRAG wxT("thumbdrag")
31 #define wxACTION_SLIDER_THUMB_MOVE wxT("thumbmove")
32 #define wxACTION_SLIDER_THUMB_RELEASE wxT("thumbrelease")
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxSlider
: public wxSliderBase
,
39 public wxControlWithThumb
45 wxSlider(wxWindow
*parent
,
47 int value
, int minValue
, int maxValue
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
50 long style
= wxSL_HORIZONTAL
,
51 const wxValidator
& validator
= wxDefaultValidator
,
52 const wxString
& name
= wxSliderNameStr
);
54 bool Create(wxWindow
*parent
,
56 int value
, int minValue
, int maxValue
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
59 long style
= wxSL_HORIZONTAL
,
60 const wxValidator
& validator
= wxDefaultValidator
,
61 const wxString
& name
= wxSliderNameStr
);
63 // implement base class pure virtuals
64 virtual int GetValue() const;
65 virtual void SetValue(int value
);
67 virtual void SetRange(int minValue
, int maxValue
);
68 virtual int GetMin() const;
69 virtual int GetMax() const;
71 virtual void SetLineSize(int lineSize
);
72 virtual void SetPageSize(int pageSize
);
73 virtual int GetLineSize() const;
74 virtual int GetPageSize() const;
76 virtual void SetThumbLength(int lenPixels
);
77 virtual int GetThumbLength() const;
79 virtual int GetTickFreq() const { return m_tickFreq
; }
81 // wxUniv-specific methods
82 // -----------------------
84 // is this a vertical slider?
85 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL
) != 0; }
87 // get the slider orientation
88 wxOrientation
GetOrientation() const
89 { return IsVert() ? wxVERTICAL
: wxHORIZONTAL
; }
92 bool HasLabels() const
93 { return ((GetWindowStyle() & wxSL_LABELS
) != 0) &&
94 ((GetWindowStyle() & (wxSL_TOP
|wxSL_BOTTOM
|wxSL_LEFT
|wxSL_RIGHT
)) != 0); }
98 { return ((GetWindowStyle() & wxSL_TICKS
) != 0) &&
99 ((GetWindowStyle() & (wxSL_TOP
|wxSL_BOTTOM
|wxSL_LEFT
|wxSL_RIGHT
|wxSL_BOTH
)) != 0); }
101 // implement wxControlWithThumb interface
102 virtual wxWindow
*GetWindow() { return this; }
103 virtual bool IsVertical() const { return IsVert(); }
105 virtual wxScrollThumb::Shaft
HitTest(const wxPoint
& pt
) const;
106 virtual wxCoord
ThumbPosToPixel() const;
107 virtual int PixelToThumbPos(wxCoord x
) const;
109 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart
,
113 virtual void OnThumbDragStart(int pos
);
114 virtual void OnThumbDrag(int pos
);
115 virtual void OnThumbDragEnd(int pos
);
116 virtual void OnPageScrollStart();
117 virtual bool OnPageScroll(int pageInc
);
119 // for wxStdSliderInputHandler
120 wxScrollThumb
& GetThumb() { return m_thumb
; }
122 virtual bool PerformAction(const wxControlAction
& action
,
124 const wxString
& strArg
= wxEmptyString
);
126 static wxInputHandler
*GetStdInputHandler(wxInputHandler
*handlerDef
);
127 virtual wxInputHandler
*DoGetStdInputHandler(wxInputHandler
*handlerDef
)
129 return GetStdInputHandler(handlerDef
);
135 INVALID_THUMB_VALUE
= -0xffff
138 // Platform-specific implementation of SetTickFreq
139 virtual void DoSetTickFreq(int freq
);
141 // overridden base class virtuals
142 virtual wxSize
DoGetBestClientSize() const;
143 virtual void DoDraw(wxControlRenderer
*renderer
);
144 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
147 void OnSize(wxSizeEvent
& event
);
149 // common part of all ctors
152 // normalize the value to fit in the range
153 int NormalizeValue(int value
) const;
155 // change the value by the given increment, return true if really changed
156 bool ChangeValueBy(int inc
);
158 // change the value to the given one
159 bool ChangeValueTo(int value
);
161 // is the value inside the range?
162 bool IsInRange(int value
) { return (value
>= m_min
) && (value
<= m_max
); }
164 // format the value for printing as label
165 virtual wxString
FormatValue(int value
) const;
167 // calculate max label size
168 wxSize
CalcLabelSize() const;
170 // calculate m_rectLabel/Slider
173 // get the thumb size
174 wxSize
GetThumbSize() const;
176 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
177 wxRect
GetShaftRect() const;
179 // calc the current thumb position using the shaft rect (if the pointer is
180 // NULL, we calculate it here too)
181 void CalcThumbRect(const wxRect
*rectShaft
,
182 wxRect
*rectThumbOut
,
183 wxRect
*rectLabelOut
,
184 int value
= INVALID_THUMB_VALUE
) const;
186 // return the slider rect calculating it if needed
187 const wxRect
& GetSliderRect() const;
189 // refresh the current thumb position
193 // get the default thumb size (without using m_thumbSize)
194 wxSize
GetDefaultThumbSize() const;
196 // the object which manages our thumb
197 wxScrollThumb m_thumb
;
199 // the slider range and value
204 // the tick frequence (default is 1)
207 // the line and page increments (logical units)
211 // the size of the thumb (in pixels)
214 // the part of the client area reserved for the label, the ticks and the
215 // part for the slider itself
220 // the state of the thumb (wxCONTROL_XXX constants sum)
223 DECLARE_EVENT_TABLE()
224 DECLARE_DYNAMIC_CLASS(wxSlider
)
227 #endif // _WX_UNIV_SLIDER_H_