1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/slider.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - native implementation
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/slider.h"
26 #include "wx/toplevel.h"
35 m_oldValue
= m_oldPos
= 0;
39 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
40 int value
, int minValue
, int maxValue
,
42 const wxSize
& size
, long style
,
43 const wxValidator
& validator
,
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"));
55 if(!wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
))
58 FormType
* form
= (FormType
*)GetParentForm();
62 m_oldValue
= m_oldPos
= value
;
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
;
69 AdjustForParentClientOrigin(x
, y
);
72 SliderControlType
*slider
= CtlNewSliderControl (
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
,
94 feedbackSliderCtl
,//style
97 x
, y
, w
, h
, minValue
, maxValue
, 1, value
);
98 #endif // __WXPALMOS6__/__WXPALMOS5__
103 SetInitialSize(size
);
108 wxSlider::~wxSlider()
112 int wxSlider::GetMin() const
114 ControlType
*control
= (ControlType
*)GetObjectPtr();
118 CtlGetSliderValues(control
, &ret
, NULL
, NULL
, NULL
);
122 int wxSlider::GetMax() const
124 ControlType
*control
= (ControlType
*)GetObjectPtr();
128 CtlGetSliderValues(control
, NULL
, &ret
, NULL
, NULL
);
132 int wxSlider::GetPageSize() const
134 ControlType
*control
= (ControlType
*)GetObjectPtr();
138 CtlGetSliderValues(control
, NULL
, NULL
, &ret
, NULL
);
142 int wxSlider::GetValue() const
144 ControlType
*control
= (ControlType
*)GetObjectPtr();
148 CtlGetSliderValues(control
, NULL
, NULL
, NULL
, &ret
);
149 return ValueInvertOrNot(ret
);
152 void wxSlider::SetValue(int value
)
154 SetIntValue(ValueInvertOrNot(value
));
155 m_oldValue
= m_oldPos
= value
;
158 wxSize
wxSlider::DoGetBestSize() const
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);
166 void wxSlider::SetRange(int WXUNUSED(minValue
), int WXUNUSED(maxValue
))
168 // unsupported feature
171 void wxSlider::SetTickFreq(int WXUNUSED(n
), int WXUNUSED(pos
))
173 // unsupported feature
176 void wxSlider::SetPageSize(int pageSize
)
178 ControlType
*control
= (ControlType
*)GetObjectPtr();
181 uint16_t val
= pageSize
;
182 CtlSetSliderValues(control
, NULL
, NULL
, &val
, NULL
);
185 void wxSlider::ClearSel()
187 // unsupported feature
190 void wxSlider::ClearTicks()
192 // unsupported feature
195 void wxSlider::SetLineSize(int lineSize
)
197 m_lineSize
= lineSize
;
200 int wxSlider::GetLineSize() const
205 int wxSlider::GetSelEnd() const
207 // unsupported feature
211 int wxSlider::GetSelStart() const
213 // unsupported feature
217 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
219 // unsupported feature
222 void wxSlider::SetThumbLength(int WXUNUSED(len
))
224 // unsupported feature
227 int wxSlider::GetThumbLength() const
229 // unsupported feature
233 int wxSlider::GetTickFreq() const
235 // unsupported feature
236 return GetPageSize();
239 void wxSlider::SetTick(int WXUNUSED(tickPos
))
241 // unsupported feature
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 bool wxSlider::SendUpdatedEvent()
250 m_oldPos
= GetValue();
253 wxScrollEvent
eventWxTrack(wxEVT_SCROLL_THUMBRELEASE
, GetId());
254 eventWxTrack
.SetPosition(m_oldPos
);
255 eventWxTrack
.SetEventObject(this);
256 bool handled
= HandleWindowEvent(eventWxTrack
);
258 // then slider event if position changed
259 if( m_oldValue
!= m_oldPos
)
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
);
271 bool wxSlider::SendScrollEvent(WXEVENTPTR event
)
273 const EventType
* palmEvent
= (EventType
*)event
;
274 int newPos
= ValueInvertOrNot(palmEvent
->data
.ctlRepeat
.value
);
275 if ( newPos
== m_oldPos
)
277 // nothing changed since last event
284 wxScrollEvent
eventWx(wxEVT_SCROLL_THUMBTRACK
, GetId());
285 eventWx
.SetPosition(newPos
);
286 eventWx
.SetEventObject(this);
287 return HandleWindowEvent(eventWx
);
290 void wxSlider::Command (wxCommandEvent
& event
)
294 #endif // wxUSE_SLIDER