]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/slider.h
Add lambda-friendly wxDialog::ShowWindowModalThenDo().
[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 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_UNIV_SLIDER_H_
12 #define _WX_UNIV_SLIDER_H_
13
14 #include "wx/univ/scrthumb.h"
15
16 // ----------------------------------------------------------------------------
17 // the actions supported by this control
18 // ----------------------------------------------------------------------------
19
20 // our actions are the same as scrollbars
21
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
29
30 #define wxACTION_SLIDER_THUMB_DRAG wxT("thumbdrag")
31 #define wxACTION_SLIDER_THUMB_MOVE wxT("thumbmove")
32 #define wxACTION_SLIDER_THUMB_RELEASE wxT("thumbrelease")
33
34 // ----------------------------------------------------------------------------
35 // wxSlider
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxSlider : public wxSliderBase,
39 public wxControlWithThumb
40 {
41 public:
42 // ctors and such
43 wxSlider();
44
45 wxSlider(wxWindow *parent,
46 wxWindowID id,
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);
53
54 bool Create(wxWindow *parent,
55 wxWindowID id,
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);
62
63 // implement base class pure virtuals
64 virtual int GetValue() const;
65 virtual void SetValue(int value);
66
67 virtual void SetRange(int minValue, int maxValue);
68 virtual int GetMin() const;
69 virtual int GetMax() const;
70
71 virtual void SetLineSize(int lineSize);
72 virtual void SetPageSize(int pageSize);
73 virtual int GetLineSize() const;
74 virtual int GetPageSize() const;
75
76 virtual void SetThumbLength(int lenPixels);
77 virtual int GetThumbLength() const;
78
79 virtual int GetTickFreq() const { return m_tickFreq; }
80
81 // wxUniv-specific methods
82 // -----------------------
83
84 // is this a vertical slider?
85 bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL) != 0; }
86
87 // get the slider orientation
88 wxOrientation GetOrientation() const
89 { return IsVert() ? wxVERTICAL : wxHORIZONTAL; }
90
91 // do we have labels?
92 bool HasLabels() const
93 { return ((GetWindowStyle() & wxSL_LABELS) != 0) &&
94 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT)) != 0); }
95
96 // do we have ticks?
97 bool HasTicks() const
98 { return ((GetWindowStyle() & wxSL_TICKS) != 0) &&
99 ((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT|wxSL_BOTH)) != 0); }
100
101 // implement wxControlWithThumb interface
102 virtual wxWindow *GetWindow() { return this; }
103 virtual bool IsVertical() const { return IsVert(); }
104
105 virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const;
106 virtual wxCoord ThumbPosToPixel() const;
107 virtual int PixelToThumbPos(wxCoord x) const;
108
109 virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart,
110 int flag,
111 bool set = true);
112
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);
118
119 // for wxStdSliderInputHandler
120 wxScrollThumb& GetThumb() { return m_thumb; }
121
122 virtual bool PerformAction(const wxControlAction& action,
123 long numArg = 0,
124 const wxString& strArg = wxEmptyString);
125
126 static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
127 virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
128 {
129 return GetStdInputHandler(handlerDef);
130 }
131
132 protected:
133 enum
134 {
135 INVALID_THUMB_VALUE = -0xffff
136 };
137
138 // Platform-specific implementation of SetTickFreq
139 virtual void DoSetTickFreq(int freq);
140
141 // overridden base class virtuals
142 virtual wxSize DoGetBestClientSize() const;
143 virtual void DoDraw(wxControlRenderer *renderer);
144 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
145
146 // event handlers
147 void OnSize(wxSizeEvent& event);
148
149 // common part of all ctors
150 void Init();
151
152 // normalize the value to fit in the range
153 int NormalizeValue(int value) const;
154
155 // change the value by the given increment, return true if really changed
156 bool ChangeValueBy(int inc);
157
158 // change the value to the given one
159 bool ChangeValueTo(int value);
160
161 // is the value inside the range?
162 bool IsInRange(int value) { return (value >= m_min) && (value <= m_max); }
163
164 // format the value for printing as label
165 virtual wxString FormatValue(int value) const;
166
167 // calculate max label size
168 wxSize CalcLabelSize() const;
169
170 // calculate m_rectLabel/Slider
171 void CalcGeometry();
172
173 // get the thumb size
174 wxSize GetThumbSize() const;
175
176 // get the shaft rect (uses m_rectSlider which is supposed to be calculated)
177 wxRect GetShaftRect() const;
178
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;
185
186 // return the slider rect calculating it if needed
187 const wxRect& GetSliderRect() const;
188
189 // refresh the current thumb position
190 void RefreshThumb();
191
192 private:
193 // get the default thumb size (without using m_thumbSize)
194 wxSize GetDefaultThumbSize() const;
195
196 // the object which manages our thumb
197 wxScrollThumb m_thumb;
198
199 // the slider range and value
200 int m_min,
201 m_max,
202 m_value;
203
204 // the tick frequence (default is 1)
205 int m_tickFreq;
206
207 // the line and page increments (logical units)
208 int m_lineSize,
209 m_pageSize;
210
211 // the size of the thumb (in pixels)
212 int m_thumbSize;
213
214 // the part of the client area reserved for the label, the ticks and the
215 // part for the slider itself
216 wxRect m_rectLabel,
217 m_rectTicks,
218 m_rectSlider;
219
220 // the state of the thumb (wxCONTROL_XXX constants sum)
221 int m_thumbFlags;
222
223 DECLARE_EVENT_TABLE()
224 DECLARE_DYNAMIC_CLASS(wxSlider)
225 };
226
227 #endif // _WX_UNIV_SLIDER_H_