]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/slider.cpp
Inversed slider and wrapper for datepicker control on PalmOS. WinHandle instead of...
[wxWidgets.git] / src / palmos / slider.cpp
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 #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
31 #include "wx/toplevel.h"
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)
45
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
101 void wxSlider::Init()
102 {
103 m_oldValue = m_oldPos = 0;
104 m_lineSize = 1;
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 {
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_VERTICAL is impossible in native form
121 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
122
123 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
124 return false;
125
126 FormType* form = GetParentForm();
127 if(form==NULL)
128 return false;
129
130 m_oldValue = m_oldPos = value;
131
132 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
133 y = pos.y == wxDefaultCoord ? 0 : pos.y,
134 w = size.x == wxDefaultCoord ? 1 : size.x,
135 h = size.y == wxDefaultCoord ? 1 : size.y;
136
137 AdjustForParentClientOrigin(x, y);
138
139 SliderControlType *slider = CtlNewSliderControl (
140 (void **)&form,
141 GetId(),
142 feedbackSliderCtl,
143 NULL,
144 0,
145 0,
146 x,
147 y,
148 w,
149 h,
150 minValue,
151 maxValue,
152 1,
153 value
154 );
155
156 if(slider==NULL)
157 return false;
158
159 SetInitialBestSize(size);
160 Show();
161 return true;
162 }
163
164 wxSlider::~wxSlider()
165 {
166 }
167
168 int wxSlider::GetMin() const
169 {
170 ControlType *control = (ControlType *)GetObjectPtr();
171 if(control==NULL)
172 return 0;
173 uint16_t ret;
174 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
175 return ret;
176 }
177
178 int wxSlider::GetMax() const
179 {
180 ControlType *control = (ControlType *)GetObjectPtr();
181 if(control==NULL)
182 return 0;
183 uint16_t ret;
184 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
185 return ret;
186 }
187
188 int wxSlider::GetPageSize() const
189 {
190 ControlType *control = (ControlType *)GetObjectPtr();
191 if(control==NULL)
192 return 0;
193 uint16_t ret;
194 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
195 return ret;
196 }
197
198 int wxSlider::PalmInvertOrNot(int value) const
199 {
200 if (m_windowStyle & wxSL_INVERSE)
201 return (GetMax() + GetMin()) - value;
202 else
203 return value;
204 }
205
206 int wxSlider::GetValue() const
207 {
208 ControlType *control = (ControlType *)GetObjectPtr();
209 if(control==NULL)
210 return 0;
211 uint16_t ret;
212 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
213 return PalmInvertOrNot(ret);
214 }
215
216 void wxSlider::SetValue(int value)
217 {
218 SetIntValue(PalmInvertOrNot(value));
219 m_oldValue = m_oldPos = value;
220 }
221
222 wxSize wxSlider::DoGetBestSize() const
223 {
224 // 15 is taken as used in one of official samples
225 // 45 is dummy height tripled, any idea what's better ?
226 return wxSize(45,15);
227 }
228
229
230 void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
231 {
232 // unsupported feature
233 }
234
235 void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos))
236 {
237 // unsupported feature
238 }
239
240 void wxSlider::SetPageSize(int pageSize)
241 {
242 ControlType *control = (ControlType *)GetObjectPtr();
243 if(control==NULL)
244 return;
245 uint16_t val = pageSize;
246 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
247 }
248
249 void wxSlider::ClearSel()
250 {
251 // unsupported feature
252 }
253
254 void wxSlider::ClearTicks()
255 {
256 // unsupported feature
257 }
258
259 void wxSlider::SetLineSize(int lineSize)
260 {
261 m_lineSize = lineSize;
262 }
263
264 int wxSlider::GetLineSize() const
265 {
266 return m_lineSize;
267 }
268
269 int wxSlider::GetSelEnd() const
270 {
271 // unsupported feature
272 return GetValue();
273 }
274
275 int wxSlider::GetSelStart() const
276 {
277 // unsupported feature
278 return GetValue();
279 }
280
281 void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
282 {
283 // unsupported feature
284 }
285
286 void wxSlider::SetThumbLength(int WXUNUSED(len))
287 {
288 // unsupported feature
289 }
290
291 int wxSlider::GetThumbLength() const
292 {
293 // unsupported feature
294 return 0;
295 }
296
297 int wxSlider::GetTickFreq() const
298 {
299 // unsupported feature
300 return GetPageSize();
301 }
302
303 void wxSlider::SetTick(int WXUNUSED(tickPos))
304 {
305 // unsupported feature
306 }
307
308 // ----------------------------------------------------------------------------
309 // helpers
310 // ----------------------------------------------------------------------------
311
312 bool wxSlider::SendUpdatedEvent()
313 {
314 m_oldPos = GetValue();
315
316 // first thumb event
317 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
318 eventWxTrack.SetPosition(m_oldPos);
319 eventWxTrack.SetEventObject(this);
320 bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
321
322 // then slider event if position changed
323 if( m_oldValue != m_oldPos )
324 {
325 m_oldValue = m_oldPos;
326 wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
327 event.SetEventObject(this);
328 event.SetInt(m_oldPos);
329 return ProcessCommand(event);
330 }
331
332 return handled;
333 }
334
335 bool wxSlider::SendScrollEvent(EventType* event)
336 {
337 wxEventType scrollEvent;
338 int newPos = PalmInvertOrNot(event->data.ctlRepeat.value);
339 if ( newPos == m_oldPos )
340 {
341 // nothing changed since last event
342 return false;
343 }
344
345 m_oldPos = newPos;
346
347 // first track event
348 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
349 eventWx.SetPosition(newPos);
350 eventWx.SetEventObject(this);
351 return GetEventHandler()->ProcessEvent(eventWx);
352 }
353
354 void wxSlider::Command (wxCommandEvent & event)
355 {
356 }
357
358 #endif // wxUSE_SLIDER