]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/palmos/slider.cpp | |
3 | // Purpose: wxSlider | |
4 | // Author: William Osborne - minimal working wxPalmOS port | |
5 | // Modified by: Wlodzimierz ABX Skiba - native implementation | |
6 | // Created: 10/13/04 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) William Osborne, Wlodzimierz Skiba | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #if wxUSE_SLIDER | |
20 | ||
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/utils.h" | |
23 | #include "wx/brush.h" | |
24 | #include "wx/slider.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/toplevel.h" | |
28 | ||
29 | #include <Form.h> | |
30 | #include <Control.h> | |
31 | ||
32 | #if wxUSE_EXTENDED_RTTI | |
33 | WX_DEFINE_FLAGS( wxSliderStyle ) | |
34 | ||
35 | wxBEGIN_FLAGS( wxSliderStyle ) | |
36 | // new style border flags, we put them first to | |
37 | // use them for streaming out | |
38 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
39 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
40 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
41 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
42 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
43 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
44 | ||
45 | // old style border flags | |
46 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
47 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
48 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
49 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
50 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
51 | wxFLAGS_MEMBER(wxBORDER) | |
52 | ||
53 | // standard window styles | |
54 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
55 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
56 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
57 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
58 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
59 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
60 | wxFLAGS_MEMBER(wxVSCROLL) | |
61 | wxFLAGS_MEMBER(wxHSCROLL) | |
62 | ||
63 | wxFLAGS_MEMBER(wxSL_HORIZONTAL) | |
64 | wxFLAGS_MEMBER(wxSL_VERTICAL) | |
65 | wxFLAGS_MEMBER(wxSL_AUTOTICKS) | |
66 | wxFLAGS_MEMBER(wxSL_LABELS) | |
67 | wxFLAGS_MEMBER(wxSL_LEFT) | |
68 | wxFLAGS_MEMBER(wxSL_TOP) | |
69 | wxFLAGS_MEMBER(wxSL_RIGHT) | |
70 | wxFLAGS_MEMBER(wxSL_BOTTOM) | |
71 | wxFLAGS_MEMBER(wxSL_BOTH) | |
72 | wxFLAGS_MEMBER(wxSL_SELRANGE) | |
73 | ||
74 | wxEND_FLAGS( wxSliderStyle ) | |
75 | ||
76 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h") | |
77 | ||
78 | wxBEGIN_PROPERTIES_TABLE(wxSlider) | |
79 | wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent ) | |
80 | wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent ) | |
81 | ||
82 | wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
83 | wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
84 | wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
85 | wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
86 | wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
87 | wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
88 | wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
89 | wxEND_PROPERTIES_TABLE() | |
90 | ||
91 | wxBEGIN_HANDLERS_TABLE(wxSlider) | |
92 | wxEND_HANDLERS_TABLE() | |
93 | ||
94 | wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
95 | #else | |
96 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) | |
97 | #endif | |
98 | ||
99 | // Slider | |
100 | void wxSlider::Init() | |
101 | { | |
102 | m_oldValue = m_oldPos = 0; | |
103 | m_lineSize = 1; | |
104 | } | |
105 | ||
106 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, | |
107 | int value, int minValue, int maxValue, | |
108 | const wxPoint& pos, | |
109 | const wxSize& size, long style, | |
110 | const wxValidator& validator, | |
111 | const wxString& name) | |
112 | { | |
113 | // wxSL_AUTOTICKS is ignored - always on | |
114 | // wxSL_LABELS is ignored - always off | |
115 | // wxSL_LEFT is ignored - always off | |
116 | // wxSL_RIGHT is ignored - always off | |
117 | // wxSL_TOP is ignored - always off | |
118 | // wxSL_SELRANGE is ignored - always off | |
119 | // wxSL_VERTICAL is impossible in native form | |
120 | wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS")); | |
121 | ||
122 | if(!wxControl::Create(parent, id, pos, size, style, validator, name)) | |
123 | return false; | |
124 | ||
125 | FormType* form = (FormType*)GetParentForm(); | |
126 | if(form==NULL) | |
127 | return false; | |
128 | ||
129 | m_oldValue = m_oldPos = value; | |
130 | ||
131 | wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x, | |
132 | y = pos.y == wxDefaultCoord ? 0 : pos.y, | |
133 | w = size.x == wxDefaultCoord ? 1 : size.x, | |
134 | h = size.y == wxDefaultCoord ? 1 : size.y; | |
135 | ||
136 | AdjustForParentClientOrigin(x, y); | |
137 | ||
138 | SliderControlType *slider = CtlNewSliderControl ( | |
139 | (void **)&form, | |
140 | GetId(), | |
141 | feedbackSliderCtl, | |
142 | NULL, | |
143 | 0, | |
144 | 0, | |
145 | x, | |
146 | y, | |
147 | w, | |
148 | h, | |
149 | minValue, | |
150 | maxValue, | |
151 | 1, | |
152 | value | |
153 | ); | |
154 | ||
155 | if(slider==NULL) | |
156 | return false; | |
157 | ||
158 | SetInitialBestSize(size); | |
159 | Show(); | |
160 | return true; | |
161 | } | |
162 | ||
163 | wxSlider::~wxSlider() | |
164 | { | |
165 | } | |
166 | ||
167 | int wxSlider::GetMin() const | |
168 | { | |
169 | ControlType *control = (ControlType *)GetObjectPtr(); | |
170 | if(control==NULL) | |
171 | return 0; | |
172 | uint16_t ret; | |
173 | CtlGetSliderValues(control, &ret, NULL, NULL, NULL); | |
174 | return ret; | |
175 | } | |
176 | ||
177 | int wxSlider::GetMax() const | |
178 | { | |
179 | ControlType *control = (ControlType *)GetObjectPtr(); | |
180 | if(control==NULL) | |
181 | return 0; | |
182 | uint16_t ret; | |
183 | CtlGetSliderValues(control, NULL, &ret, NULL, NULL); | |
184 | return ret; | |
185 | } | |
186 | ||
187 | int wxSlider::GetPageSize() const | |
188 | { | |
189 | ControlType *control = (ControlType *)GetObjectPtr(); | |
190 | if(control==NULL) | |
191 | return 0; | |
192 | uint16_t ret; | |
193 | CtlGetSliderValues(control, NULL, NULL, &ret, NULL); | |
194 | return ret; | |
195 | } | |
196 | ||
197 | int wxSlider::GetValue() const | |
198 | { | |
199 | ControlType *control = (ControlType *)GetObjectPtr(); | |
200 | if(control==NULL) | |
201 | return 0; | |
202 | uint16_t ret; | |
203 | CtlGetSliderValues(control, NULL, NULL, NULL, &ret); | |
204 | return ValueInvertOrNot(ret); | |
205 | } | |
206 | ||
207 | void wxSlider::SetValue(int value) | |
208 | { | |
209 | SetIntValue(ValueInvertOrNot(value)); | |
210 | m_oldValue = m_oldPos = value; | |
211 | } | |
212 | ||
213 | wxSize wxSlider::DoGetBestSize() const | |
214 | { | |
215 | // 15 is taken as used in one of official samples | |
216 | // 45 is dummy height tripled, any idea what's better ? | |
217 | return wxSize(45,15); | |
218 | } | |
219 | ||
220 | ||
221 | void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue)) | |
222 | { | |
223 | // unsupported feature | |
224 | } | |
225 | ||
226 | void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos)) | |
227 | { | |
228 | // unsupported feature | |
229 | } | |
230 | ||
231 | void wxSlider::SetPageSize(int pageSize) | |
232 | { | |
233 | ControlType *control = (ControlType *)GetObjectPtr(); | |
234 | if(control==NULL) | |
235 | return; | |
236 | uint16_t val = pageSize; | |
237 | CtlSetSliderValues(control, NULL, NULL, &val, NULL); | |
238 | } | |
239 | ||
240 | void wxSlider::ClearSel() | |
241 | { | |
242 | // unsupported feature | |
243 | } | |
244 | ||
245 | void wxSlider::ClearTicks() | |
246 | { | |
247 | // unsupported feature | |
248 | } | |
249 | ||
250 | void wxSlider::SetLineSize(int lineSize) | |
251 | { | |
252 | m_lineSize = lineSize; | |
253 | } | |
254 | ||
255 | int wxSlider::GetLineSize() const | |
256 | { | |
257 | return m_lineSize; | |
258 | } | |
259 | ||
260 | int wxSlider::GetSelEnd() const | |
261 | { | |
262 | // unsupported feature | |
263 | return GetValue(); | |
264 | } | |
265 | ||
266 | int wxSlider::GetSelStart() const | |
267 | { | |
268 | // unsupported feature | |
269 | return GetValue(); | |
270 | } | |
271 | ||
272 | void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) | |
273 | { | |
274 | // unsupported feature | |
275 | } | |
276 | ||
277 | void wxSlider::SetThumbLength(int WXUNUSED(len)) | |
278 | { | |
279 | // unsupported feature | |
280 | } | |
281 | ||
282 | int wxSlider::GetThumbLength() const | |
283 | { | |
284 | // unsupported feature | |
285 | return 0; | |
286 | } | |
287 | ||
288 | int wxSlider::GetTickFreq() const | |
289 | { | |
290 | // unsupported feature | |
291 | return GetPageSize(); | |
292 | } | |
293 | ||
294 | void wxSlider::SetTick(int WXUNUSED(tickPos)) | |
295 | { | |
296 | // unsupported feature | |
297 | } | |
298 | ||
299 | // ---------------------------------------------------------------------------- | |
300 | // helpers | |
301 | // ---------------------------------------------------------------------------- | |
302 | ||
303 | bool wxSlider::SendUpdatedEvent() | |
304 | { | |
305 | m_oldPos = GetValue(); | |
306 | ||
307 | // first thumb event | |
308 | wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId()); | |
309 | eventWxTrack.SetPosition(m_oldPos); | |
310 | eventWxTrack.SetEventObject(this); | |
311 | bool handled = GetEventHandler()->ProcessEvent(eventWxTrack); | |
312 | ||
313 | // then slider event if position changed | |
314 | if( m_oldValue != m_oldPos ) | |
315 | { | |
316 | m_oldValue = m_oldPos; | |
317 | wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId()); | |
318 | event.SetEventObject(this); | |
319 | event.SetInt(m_oldPos); | |
320 | return ProcessCommand(event); | |
321 | } | |
322 | ||
323 | return handled; | |
324 | } | |
325 | ||
326 | bool wxSlider::SendScrollEvent(WXEVENTPTR event) | |
327 | { | |
328 | const EventType* palmEvent = (EventType*)event; | |
329 | int newPos = ValueInvertOrNot(palmEvent->data.ctlRepeat.value); | |
330 | if ( newPos == m_oldPos ) | |
331 | { | |
332 | // nothing changed since last event | |
333 | return false; | |
334 | } | |
335 | ||
336 | m_oldPos = newPos; | |
337 | ||
338 | // first track event | |
339 | wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId()); | |
340 | eventWx.SetPosition(newPos); | |
341 | eventWx.SetEventObject(this); | |
342 | return GetEventHandler()->ProcessEvent(eventWx); | |
343 | } | |
344 | ||
345 | void wxSlider::Command (wxCommandEvent & event) | |
346 | { | |
347 | } | |
348 | ||
349 | #endif // wxUSE_SLIDER |