]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/slider.h
don't use dynamic handlers for standard buttons as this prevents static event handler...
[wxWidgets.git] / include / wx / univ / slider.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/slider.h
3 // Purpose: wxSlider control for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 09.02.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_SLIDER_H_
13 #define _WX_UNIV_SLIDER_H_
14
15 #include "wx/univ/scrthumb.h"
16
17 // ----------------------------------------------------------------------------
18 // the actions supported by this control
19 // ----------------------------------------------------------------------------
20
21 // our actions are the same as scrollbars
22
23 #define wxACTION_SLIDER_START _T("start") // to the beginning
24 #define wxACTION_SLIDER_END _T("end") // to the end
25 #define wxACTION_SLIDER_LINE_UP _T("lineup") // one line up/left
26 #define wxACTION_SLIDER_PAGE_UP _T("pageup") // one page up/left
27 #define wxACTION_SLIDER_LINE_DOWN _T("linedown") // one line down/right
28 #define wxACTION_SLIDER_PAGE_DOWN _T("pagedown") // one page down/right
29 #define wxACTION_SLIDER_PAGE_CHANGE _T("pagechange")// change page by numArg
30
31 #define wxACTION_SLIDER_THUMB_DRAG _T("thumbdrag")
32 #define wxACTION_SLIDER_THUMB_MOVE _T("thumbmove")
33 #define wxACTION_SLIDER_THUMB_RELEASE _T("thumbrelease")
34
35 // ----------------------------------------------------------------------------
36 // wxSlider
37 // ----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxSlider : public wxSliderBase,
40 public wxControlWithThumb
41 {
42 public:
43 // ctors and such
44 wxSlider();
45
46 wxSlider(wxWindow *parent,
47 wxWindowID id,
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);
54
55 bool Create(wxWindow *parent,
56 wxWindowID id,
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);
63
64 // implement base class pure virtuals
65 virtual int GetValue() const;
66 virtual void SetValue(int value);
67
68 virtual void SetRange(int minValue, int maxValue);
69 virtual int GetMin() const;
70 virtual int GetMax() const;
71
72 virtual void SetLineSize(int lineSize);
73 virtual void SetPageSize(int pageSize);
74 virtual int GetLineSize() const;
75 virtual int GetPageSize() const;
76
77 virtual void SetThumbLength(int lenPixels);
78 virtual int GetThumbLength() const;
79
80 virtual void SetTickFreq(int n, int WXUNUSED(dummy) = 0);
81 virtual int GetTickFreq() const { return m_tickFreq; }
82
83 // wxUniv-specific methods
84 // -----------------------
85
86 // is this a vertical slider?
87 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL) != 0; }
88
89 // get the slider orientation
90 wxOrientation GetOrientation() const
91 { return IsVert() ? wxVERTICAL : wxHORIZONTAL; }
92
93 // do we have labels?
94 bool HasLabels() const
95 { return ((GetWindowStyle() & wxSL_LABELS) != 0) &&
96 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT)) != 0); }
97
98 // do we have ticks?
99 bool HasTicks() const
100 { return ((GetWindowStyle() & wxSL_TICKS) != 0) &&
101 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT|wxSL_BOTH)) != 0); }
102
103 // implement wxControlWithThumb interface
104 virtual wxWindow *GetWindow() { return this; }
105 virtual bool IsVertical() const { return IsVert(); }
106
107 virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const;
108 virtual wxCoord ThumbPosToPixel() const;
109 virtual int PixelToThumbPos(wxCoord x) const;
110
111 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart,
112 int flag,
113 bool set = true);
114
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);
120
121 // for wxStdSliderButtonInputHandler
122 wxScrollThumb& GetThumb() { return m_thumb; }
123
124 virtual bool PerformAction(const wxControlAction& action,
125 long numArg = 0,
126 const wxString& strArg = wxEmptyString);
127
128 protected:
129 enum
130 {
131 INVALID_THUMB_VALUE = -0xffff
132 };
133
134 // overridden base class virtuals
135 virtual wxSize DoGetBestClientSize() const;
136 virtual void DoDraw(wxControlRenderer *renderer);
137 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
138
139 // event handlers
140 void OnSize(wxSizeEvent& event);
141
142 // common part of all ctors
143 void Init();
144
145 // normalize the value to fit in the range
146 int NormalizeValue(int value) const;
147
148 // change the value by the given increment, return true if really changed
149 bool ChangeValueBy(int inc);
150
151 // change the value to the given one
152 bool ChangeValueTo(int value);
153
154 // is the value inside the range?
155 bool IsInRange(int value) { return (value >= m_min) && (value <= m_max); }
156
157 // format the value for printing as label
158 virtual wxString FormatValue(int value) const;
159
160 // calculate max label size
161 wxSize CalcLabelSize() const;
162
163 // calculate m_rectLabel/Slider
164 void CalcGeometry();
165
166 // get the thumb size
167 wxSize GetThumbSize() const;
168
169 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
170 wxRect GetShaftRect() const;
171
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;
178
179 // return the slider rect calculating it if needed
180 const wxRect& GetSliderRect() const;
181
182 // refresh the current thumb position
183 void RefreshThumb();
184
185 private:
186 // get the default thumb size (without using m_thumbSize)
187 wxSize GetDefaultThumbSize() const;
188
189 // the object which manages our thumb
190 wxScrollThumb m_thumb;
191
192 // the slider range and value
193 int m_min,
194 m_max,
195 m_value;
196
197 // the tick frequence (default is 1)
198 int m_tickFreq;
199
200 // the line and page increments (logical units)
201 int m_lineSize,
202 m_pageSize;
203
204 // the size of the thumb (in pixels)
205 int m_thumbSize;
206
207 // the part of the client area reserved for the label, the ticks and the
208 // part for the slider itself
209 wxRect m_rectLabel,
210 m_rectTicks,
211 m_rectSlider;
212
213 // the state of the thumb (wxCONTROL_XXX constants sum)
214 int m_thumbFlags;
215
216 DECLARE_EVENT_TABLE()
217 DECLARE_DYNAMIC_CLASS(wxSlider)
218 };
219
220 // ----------------------------------------------------------------------------
221 // wxStdSliderButtonInputHandler: default slider input handling
222 // ----------------------------------------------------------------------------
223
224 class WXDLLEXPORT wxStdSliderButtonInputHandler : public wxStdInputHandler
225 {
226 public:
227 // default ctor
228 wxStdSliderButtonInputHandler(wxInputHandler *inphand)
229 : wxStdInputHandler(inphand)
230 {
231 }
232
233 // base class methods
234 virtual bool HandleKey(wxInputConsumer *consumer,
235 const wxKeyEvent& event,
236 bool pressed);
237 virtual bool HandleMouse(wxInputConsumer *consumer,
238 const wxMouseEvent& event);
239 virtual bool HandleMouseMove(wxInputConsumer *consumer,
240 const wxMouseEvent& event);
241
242 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
243 };
244
245 #endif // _WX_UNIV_SLIDER_H_