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