]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/slider.h
No real changes, just remove wxIsDebuggerRunning() stub from wxOSX.
[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 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
30
31 #define wxACTION_SLIDER_THUMB_DRAG wxT("thumbdrag")
32 #define wxACTION_SLIDER_THUMB_MOVE wxT("thumbmove")
33 #define wxACTION_SLIDER_THUMB_RELEASE wxT("thumbrelease")
34
35 // ----------------------------------------------------------------------------
36 // wxSlider
37 // ----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_CORE 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 int GetTickFreq() const { return m_tickFreq; }
81
82 // wxUniv-specific methods
83 // -----------------------
84
85 // is this a vertical slider?
86 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL) != 0; }
87
88 // get the slider orientation
89 wxOrientation GetOrientation() const
90 { return IsVert() ? wxVERTICAL : wxHORIZONTAL; }
91
92 // do we have labels?
93 bool HasLabels() const
94 { return ((GetWindowStyle() & wxSL_LABELS) != 0) &&
95 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT)) != 0); }
96
97 // do we have ticks?
98 bool HasTicks() const
99 { return ((GetWindowStyle() & wxSL_TICKS) != 0) &&
100 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT|wxSL_BOTH)) != 0); }
101
102 // implement wxControlWithThumb interface
103 virtual wxWindow *GetWindow() { return this; }
104 virtual bool IsVertical() const { return IsVert(); }
105
106 virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const;
107 virtual wxCoord ThumbPosToPixel() const;
108 virtual int PixelToThumbPos(wxCoord x) const;
109
110 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart,
111 int flag,
112 bool set = true);
113
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);
119
120 // for wxStdSliderInputHandler
121 wxScrollThumb& GetThumb() { return m_thumb; }
122
123 virtual bool PerformAction(const wxControlAction& action,
124 long numArg = 0,
125 const wxString& strArg = wxEmptyString);
126
127 static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
128 virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
129 {
130 return GetStdInputHandler(handlerDef);
131 }
132
133 protected:
134 enum
135 {
136 INVALID_THUMB_VALUE = -0xffff
137 };
138
139 // Platform-specific implementation of SetTickFreq
140 virtual void DoSetTickFreq(int freq);
141
142 // overridden base class virtuals
143 virtual wxSize DoGetBestClientSize() const;
144 virtual void DoDraw(wxControlRenderer *renderer);
145 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
146
147 // event handlers
148 void OnSize(wxSizeEvent& event);
149
150 // common part of all ctors
151 void Init();
152
153 // normalize the value to fit in the range
154 int NormalizeValue(int value) const;
155
156 // change the value by the given increment, return true if really changed
157 bool ChangeValueBy(int inc);
158
159 // change the value to the given one
160 bool ChangeValueTo(int value);
161
162 // is the value inside the range?
163 bool IsInRange(int value) { return (value >= m_min) && (value <= m_max); }
164
165 // format the value for printing as label
166 virtual wxString FormatValue(int value) const;
167
168 // calculate max label size
169 wxSize CalcLabelSize() const;
170
171 // calculate m_rectLabel/Slider
172 void CalcGeometry();
173
174 // get the thumb size
175 wxSize GetThumbSize() const;
176
177 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
178 wxRect GetShaftRect() const;
179
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;
186
187 // return the slider rect calculating it if needed
188 const wxRect& GetSliderRect() const;
189
190 // refresh the current thumb position
191 void RefreshThumb();
192
193 private:
194 // get the default thumb size (without using m_thumbSize)
195 wxSize GetDefaultThumbSize() const;
196
197 // the object which manages our thumb
198 wxScrollThumb m_thumb;
199
200 // the slider range and value
201 int m_min,
202 m_max,
203 m_value;
204
205 // the tick frequence (default is 1)
206 int m_tickFreq;
207
208 // the line and page increments (logical units)
209 int m_lineSize,
210 m_pageSize;
211
212 // the size of the thumb (in pixels)
213 int m_thumbSize;
214
215 // the part of the client area reserved for the label, the ticks and the
216 // part for the slider itself
217 wxRect m_rectLabel,
218 m_rectTicks,
219 m_rectSlider;
220
221 // the state of the thumb (wxCONTROL_XXX constants sum)
222 int m_thumbFlags;
223
224 DECLARE_EVENT_TABLE()
225 DECLARE_DYNAMIC_CLASS(wxSlider)
226 };
227
228 #endif // _WX_UNIV_SLIDER_H_