]>
Commit | Line | Data |
---|---|---|
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 | #ifdef __GNUG__ | |
13 | #pragma interface "univslider.h" | |
14 | #endif | |
15 | ||
16 | #ifndef _WX_UNIV_SLIDER_H_ | |
17 | #define _WX_UNIV_SLIDER_H_ | |
18 | ||
19 | #include "wx/univ/scrthumb.h" | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // the actions supported by this control | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | // our actions are the same as scrollbars | |
26 | ||
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 | |
34 | ||
35 | #define wxACTION_SLIDER_THUMB_DRAG _T("thumbdrag") | |
36 | #define wxACTION_SLIDER_THUMB_MOVE _T("thumbmove") | |
37 | #define wxACTION_SLIDER_THUMB_RELEASE _T("thumbrelease") | |
38 | ||
39 | // ---------------------------------------------------------------------------- | |
40 | // wxSlider | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
43 | class WXDLLEXPORT wxSlider : public wxSliderBase, | |
44 | public wxControlWithThumb | |
45 | { | |
46 | public: | |
47 | // ctors and such | |
48 | wxSlider(); | |
49 | ||
50 | wxSlider(wxWindow *parent, | |
51 | wxWindowID id, | |
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); | |
58 | ||
59 | bool Create(wxWindow *parent, | |
60 | wxWindowID id, | |
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); | |
67 | ||
68 | // implement base class pure virtuals | |
69 | virtual int GetValue() const; | |
70 | virtual void SetValue(int value); | |
71 | ||
72 | virtual void SetRange(int minValue, int maxValue); | |
73 | virtual int GetMin() const; | |
74 | virtual int GetMax() const; | |
75 | ||
76 | virtual void SetLineSize(int lineSize); | |
77 | virtual void SetPageSize(int pageSize); | |
78 | virtual int GetLineSize() const; | |
79 | virtual int GetPageSize() const; | |
80 | ||
81 | virtual void SetThumbLength(int lenPixels); | |
82 | virtual int GetThumbLength() const; | |
83 | ||
84 | virtual void SetTickFreq(int n, int WXUNUSED(dummy) = 0); | |
85 | virtual int GetTickFreq() const { return m_tickFreq; } | |
86 | ||
87 | // wxUniv-specific methods | |
88 | // ----------------------- | |
89 | ||
90 | // is this a vertical slider? | |
91 | bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL) != 0; } | |
92 | ||
93 | // get the slider orientation | |
94 | wxOrientation GetOrientation() const | |
95 | { return IsVert() ? wxVERTICAL : wxHORIZONTAL; } | |
96 | ||
97 | // do we have labels? | |
98 | bool HasLabels() const | |
99 | { return ((GetWindowStyle() & wxSL_LABELS) != 0) & | |
100 | ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT)) != 0); } | |
101 | ||
102 | // do we have ticks? | |
103 | bool HasTicks() const | |
104 | { return ((GetWindowStyle() & wxSL_TICKS) != 0) & | |
105 | ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT|wxSL_BOTH)) != 0); } | |
106 | ||
107 | // implement wxControlWithThumb interface | |
108 | virtual wxWindow *GetWindow() { return this; } | |
109 | virtual bool IsVertical() const { return IsVert(); } | |
110 | ||
111 | virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const; | |
112 | virtual wxCoord ThumbPosToPixel() const; | |
113 | virtual int PixelToThumbPos(wxCoord x) const; | |
114 | ||
115 | virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart, | |
116 | int flag, | |
117 | bool set = TRUE); | |
118 | ||
119 | virtual void OnThumbDragStart(int pos); | |
120 | virtual void OnThumbDrag(int pos); | |
121 | virtual void OnThumbDragEnd(int pos); | |
122 | virtual void OnPageScrollStart(); | |
123 | virtual bool OnPageScroll(int pageInc); | |
124 | ||
125 | // for wxStdSliderButtonInputHandler | |
126 | wxScrollThumb& GetThumb() { return m_thumb; } | |
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 | virtual bool PerformAction(const wxControlAction& action, | |
140 | long numArg = 0, | |
141 | const wxString& strArg = wxEmptyString); | |
142 | ||
143 | // event handlers | |
144 | void OnSize(wxSizeEvent& event); | |
145 | ||
146 | // common part of all ctors | |
147 | void Init(); | |
148 | ||
149 | // normalize the value to fit in the range | |
150 | int NormalizeValue(int value) const; | |
151 | ||
152 | // change the value by the given increment, return TRUE if really changed | |
153 | bool ChangeValueBy(int inc); | |
154 | ||
155 | // change the value to the given one | |
156 | bool ChangeValueTo(int value); | |
157 | ||
158 | // is the value inside the range? | |
159 | bool IsInRange(int value) { return (value >= m_min) && (value <= m_max); } | |
160 | ||
161 | // format the value for printing as label | |
162 | virtual wxString FormatValue(int value) const; | |
163 | ||
164 | // calculate max label size | |
165 | wxSize CalcLabelSize() const; | |
166 | ||
167 | // calculate m_rectLabel/Slider | |
168 | void CalcGeometry(); | |
169 | ||
170 | // get the thumb size | |
171 | wxSize GetThumbSize() const; | |
172 | ||
173 | // get the shaft rect (uses m_rectSlider which is supposed to be calculated) | |
174 | wxRect GetShaftRect() const; | |
175 | ||
176 | // calc the current thumb position using the shaft rect (if the pointer is | |
177 | // NULL, we calculate it here too) | |
178 | void CalcThumbRect(const wxRect *rectShaft, | |
179 | wxRect *rectThumbOut, | |
180 | wxRect *rectLabelOut, | |
181 | int value = INVALID_THUMB_VALUE) const; | |
182 | ||
183 | // return the slider rect calculating it if needed | |
184 | const wxRect& GetSliderRect() const; | |
185 | ||
186 | // refresh the current thumb position | |
187 | void RefreshThumb(); | |
188 | ||
189 | private: | |
190 | // get the default thumb size (without using m_thumbSize) | |
191 | wxSize GetDefaultThumbSize() const; | |
192 | ||
193 | // the object which manages our thumb | |
194 | wxScrollThumb m_thumb; | |
195 | ||
196 | // the slider range and value | |
197 | int m_min, | |
198 | m_max, | |
199 | m_value; | |
200 | ||
201 | // the tick frequence (default is 1) | |
202 | int m_tickFreq; | |
203 | ||
204 | // the line and page increments (logical units) | |
205 | int m_lineSize, | |
206 | m_pageSize; | |
207 | ||
208 | // the size of the thumb (in pixels) | |
209 | int m_thumbSize; | |
210 | ||
211 | // the part of the client area reserved for the label, the ticks and the | |
212 | // part for the slider itself | |
213 | wxRect m_rectLabel, | |
214 | m_rectTicks, | |
215 | m_rectSlider; | |
216 | ||
217 | // the state of the thumb (wxCONTROL_XXX constants sum) | |
218 | int m_thumbFlags; | |
219 | ||
220 | DECLARE_EVENT_TABLE() | |
221 | DECLARE_DYNAMIC_CLASS(wxSlider) | |
222 | }; | |
223 | ||
224 | // ---------------------------------------------------------------------------- | |
225 | // wxStdSliderButtonInputHandler: default slider input handling | |
226 | // ---------------------------------------------------------------------------- | |
227 | ||
228 | class WXDLLEXPORT wxStdSliderButtonInputHandler : public wxStdInputHandler | |
229 | { | |
230 | public: | |
231 | // default ctor | |
232 | wxStdSliderButtonInputHandler(wxInputHandler *inphand) | |
233 | : wxStdInputHandler(inphand) | |
234 | { | |
235 | } | |
236 | ||
237 | // base class methods | |
238 | virtual bool HandleKey(wxInputConsumer *consumer, | |
239 | const wxKeyEvent& event, | |
240 | bool pressed); | |
241 | virtual bool HandleMouse(wxInputConsumer *consumer, | |
242 | const wxMouseEvent& event); | |
243 | virtual bool HandleMouseMove(wxInputConsumer *consumer, | |
244 | const wxMouseEvent& event); | |
245 | ||
246 | virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event); | |
247 | }; | |
248 | ||
249 | #endif // _WX_UNIV_SLIDER_H_ |