]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/slider.cpp
Added XRC handler for wxTimePickerCtrl.
[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 // 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 #include "wx/slider.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/utils.h"
25 #include "wx/brush.h"
26 #include "wx/toplevel.h"
27 #endif
28
29 #include <Form.h>
30 #include <Control.h>
31
32 // Slider
33 void wxSlider::Init()
34 {
35 m_oldValue = m_oldPos = 0;
36 m_lineSize = 1;
37 }
38
39 bool wxSlider::Create(wxWindow *parent, wxWindowID id,
40 int value, int minValue, int maxValue,
41 const wxPoint& pos,
42 const wxSize& size, long style,
43 const wxValidator& validator,
44 const wxString& name)
45 {
46 // wxSL_AUTOTICKS is ignored - always on
47 // wxSL_LABELS is ignored - always off
48 // wxSL_LEFT is ignored - always off
49 // wxSL_RIGHT is ignored - always off
50 // wxSL_TOP is ignored - always off
51 // wxSL_SELRANGE is ignored - always off
52 // wxSL_VERTICAL is impossible in native form
53 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, wxT("non vertical slider on PalmOS"));
54
55 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
56 return false;
57
58 FormType* form = (FormType*)GetParentForm();
59 if(form==NULL)
60 return false;
61
62 m_oldValue = m_oldPos = value;
63
64 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
65 y = pos.y == wxDefaultCoord ? 0 : pos.y,
66 w = size.x == wxDefaultCoord ? 1 : size.x,
67 h = size.y == wxDefaultCoord ? 1 : size.y;
68
69 AdjustForParentClientOrigin(x, y);
70
71 #ifdef __WXPALMOS6__
72 SliderControlType *slider = CtlNewSliderControl (
73 (void **)&form,
74 GetId(),
75 feedbackSliderCtl,
76 NULL,
77 0,
78 0,
79 x,
80 y,
81 w,
82 h,
83 minValue,
84 maxValue,
85 1,
86 value
87 );
88 #else // __WXPALMOS5__
89 //SliderControlType *CtlNewSliderControl (void **formPP, UInt16 ID, ControlStyleType style, DmResID thumbID,
90 // DmResID backgroundID, Coord x, Coord y, Coord width, Coord height, UInt16 minValue, UInt16 maxValue,
91 // UInt16 pageSize, UInt16 value);
92 SliderControlType *slider = CtlNewSliderControl ((void **)&form,
93 GetId(),
94 feedbackSliderCtl,//style
95 0,//thumbID
96 0,//backgroundid
97 x, y, w, h, minValue, maxValue, 1, value);
98 #endif // __WXPALMOS6__/__WXPALMOS5__
99
100 if(slider==NULL)
101 return false;
102
103 SetInitialSize(size);
104 Show();
105 return true;
106 }
107
108 wxSlider::~wxSlider()
109 {
110 }
111
112 int wxSlider::GetMin() const
113 {
114 ControlType *control = (ControlType *)GetObjectPtr();
115 if(control==NULL)
116 return 0;
117 uint16_t ret;
118 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
119 return ret;
120 }
121
122 int wxSlider::GetMax() const
123 {
124 ControlType *control = (ControlType *)GetObjectPtr();
125 if(control==NULL)
126 return 0;
127 uint16_t ret;
128 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
129 return ret;
130 }
131
132 int wxSlider::GetPageSize() const
133 {
134 ControlType *control = (ControlType *)GetObjectPtr();
135 if(control==NULL)
136 return 0;
137 uint16_t ret;
138 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
139 return ret;
140 }
141
142 int wxSlider::GetValue() const
143 {
144 ControlType *control = (ControlType *)GetObjectPtr();
145 if(control==NULL)
146 return 0;
147 uint16_t ret;
148 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
149 return ValueInvertOrNot(ret);
150 }
151
152 void wxSlider::SetValue(int value)
153 {
154 SetIntValue(ValueInvertOrNot(value));
155 m_oldValue = m_oldPos = value;
156 }
157
158 wxSize wxSlider::DoGetBestSize() const
159 {
160 // 15 is taken as used in one of official samples
161 // 45 is dummy height tripled, any idea what's better ?
162 return wxSize(45,15);
163 }
164
165
166 void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
167 {
168 // unsupported feature
169 }
170
171 void wxSlider::DoSetTickFreq(int WXUNUSED(n))
172 {
173 // unsupported feature
174 }
175
176 void wxSlider::SetPageSize(int pageSize)
177 {
178 ControlType *control = (ControlType *)GetObjectPtr();
179 if(control==NULL)
180 return;
181 uint16_t val = pageSize;
182 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
183 }
184
185 void wxSlider::ClearSel()
186 {
187 // unsupported feature
188 }
189
190 void wxSlider::ClearTicks()
191 {
192 // unsupported feature
193 }
194
195 void wxSlider::SetLineSize(int lineSize)
196 {
197 m_lineSize = lineSize;
198 }
199
200 int wxSlider::GetLineSize() const
201 {
202 return m_lineSize;
203 }
204
205 int wxSlider::GetSelEnd() const
206 {
207 // unsupported feature
208 return GetValue();
209 }
210
211 int wxSlider::GetSelStart() const
212 {
213 // unsupported feature
214 return GetValue();
215 }
216
217 void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
218 {
219 // unsupported feature
220 }
221
222 void wxSlider::SetThumbLength(int WXUNUSED(len))
223 {
224 // unsupported feature
225 }
226
227 int wxSlider::GetThumbLength() const
228 {
229 // unsupported feature
230 return 0;
231 }
232
233 int wxSlider::GetTickFreq() const
234 {
235 // unsupported feature
236 return GetPageSize();
237 }
238
239 void wxSlider::SetTick(int WXUNUSED(tickPos))
240 {
241 // unsupported feature
242 }
243
244 // ----------------------------------------------------------------------------
245 // helpers
246 // ----------------------------------------------------------------------------
247
248 bool wxSlider::SendUpdatedEvent()
249 {
250 m_oldPos = GetValue();
251
252 // first thumb event
253 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
254 eventWxTrack.SetPosition(m_oldPos);
255 eventWxTrack.SetEventObject(this);
256 bool handled = HandleWindowEvent(eventWxTrack);
257
258 // then slider event if position changed
259 if( m_oldValue != m_oldPos )
260 {
261 m_oldValue = m_oldPos;
262 wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
263 event.SetEventObject(this);
264 event.SetInt(m_oldPos);
265 return ProcessCommand(event);
266 }
267
268 return handled;
269 }
270
271 bool wxSlider::SendScrollEvent(WXEVENTPTR event)
272 {
273 const EventType* palmEvent = (EventType*)event;
274 int newPos = ValueInvertOrNot(palmEvent->data.ctlRepeat.value);
275 if ( newPos == m_oldPos )
276 {
277 // nothing changed since last event
278 return false;
279 }
280
281 m_oldPos = newPos;
282
283 // first track event
284 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
285 eventWx.SetPosition(newPos);
286 eventWx.SetEventObject(this);
287 return HandleWindowEvent(eventWx);
288 }
289
290 void wxSlider::Command (wxCommandEvent & event)
291 {
292 }
293
294 #endif // wxUSE_SLIDER