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"
32 #if wxUSE_EXTENDED_RTTI
33 WX_DEFINE_FLAGS( wxSliderStyle
)
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
)
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
)
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
)
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
)
74 wxEND_FLAGS( wxSliderStyle
)
76 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider
, wxControl
,"wx/slider.h")
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
)
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()
91 wxBEGIN_HANDLERS_TABLE(wxSlider
)
92 wxEND_HANDLERS_TABLE()
94 wxCONSTRUCTOR_8( wxSlider
, wxWindow
* , Parent
, wxWindowID
, Id
, int , Value
, int , Minimum
, int , Maximum
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
96 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
100 void wxSlider::Init()
102 m_oldValue
= m_oldPos
= 0;
106 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
107 int value
, int minValue
, int maxValue
,
109 const wxSize
& size
, long style
,
110 const wxValidator
& validator
,
111 const wxString
& name
)
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, wxT("non vertical slider on PalmOS"));
122 if(!wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
))
125 FormType
* form
= (FormType
*)GetParentForm();
129 m_oldValue
= m_oldPos
= value
;
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
;
136 AdjustForParentClientOrigin(x
, y
);
139 SliderControlType
*slider
= CtlNewSliderControl (
155 #else // __WXPALMOS5__
156 //SliderControlType *CtlNewSliderControl (void **formPP, UInt16 ID, ControlStyleType style, DmResID thumbID,
157 // DmResID backgroundID, Coord x, Coord y, Coord width, Coord height, UInt16 minValue, UInt16 maxValue,
158 // UInt16 pageSize, UInt16 value);
159 SliderControlType
*slider
= CtlNewSliderControl ((void **)&form
,
161 feedbackSliderCtl
,//style
164 x
, y
, w
, h
, minValue
, maxValue
, 1, value
);
165 #endif // __WXPALMOS6__/__WXPALMOS5__
170 SetInitialSize(size
);
175 wxSlider::~wxSlider()
179 int wxSlider::GetMin() const
181 ControlType
*control
= (ControlType
*)GetObjectPtr();
185 CtlGetSliderValues(control
, &ret
, NULL
, NULL
, NULL
);
189 int wxSlider::GetMax() const
191 ControlType
*control
= (ControlType
*)GetObjectPtr();
195 CtlGetSliderValues(control
, NULL
, &ret
, NULL
, NULL
);
199 int wxSlider::GetPageSize() const
201 ControlType
*control
= (ControlType
*)GetObjectPtr();
205 CtlGetSliderValues(control
, NULL
, NULL
, &ret
, NULL
);
209 int wxSlider::GetValue() const
211 ControlType
*control
= (ControlType
*)GetObjectPtr();
215 CtlGetSliderValues(control
, NULL
, NULL
, NULL
, &ret
);
216 return ValueInvertOrNot(ret
);
219 void wxSlider::SetValue(int value
)
221 SetIntValue(ValueInvertOrNot(value
));
222 m_oldValue
= m_oldPos
= value
;
225 wxSize
wxSlider::DoGetBestSize() const
227 // 15 is taken as used in one of official samples
228 // 45 is dummy height tripled, any idea what's better ?
229 return wxSize(45,15);
233 void wxSlider::SetRange(int WXUNUSED(minValue
), int WXUNUSED(maxValue
))
235 // unsupported feature
238 void wxSlider::SetTickFreq(int WXUNUSED(n
), int WXUNUSED(pos
))
240 // unsupported feature
243 void wxSlider::SetPageSize(int pageSize
)
245 ControlType
*control
= (ControlType
*)GetObjectPtr();
248 uint16_t val
= pageSize
;
249 CtlSetSliderValues(control
, NULL
, NULL
, &val
, NULL
);
252 void wxSlider::ClearSel()
254 // unsupported feature
257 void wxSlider::ClearTicks()
259 // unsupported feature
262 void wxSlider::SetLineSize(int lineSize
)
264 m_lineSize
= lineSize
;
267 int wxSlider::GetLineSize() const
272 int wxSlider::GetSelEnd() const
274 // unsupported feature
278 int wxSlider::GetSelStart() const
280 // unsupported feature
284 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
286 // unsupported feature
289 void wxSlider::SetThumbLength(int WXUNUSED(len
))
291 // unsupported feature
294 int wxSlider::GetThumbLength() const
296 // unsupported feature
300 int wxSlider::GetTickFreq() const
302 // unsupported feature
303 return GetPageSize();
306 void wxSlider::SetTick(int WXUNUSED(tickPos
))
308 // unsupported feature
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
315 bool wxSlider::SendUpdatedEvent()
317 m_oldPos
= GetValue();
320 wxScrollEvent
eventWxTrack(wxEVT_SCROLL_THUMBRELEASE
, GetId());
321 eventWxTrack
.SetPosition(m_oldPos
);
322 eventWxTrack
.SetEventObject(this);
323 bool handled
= HandleWindowEvent(eventWxTrack
);
325 // then slider event if position changed
326 if( m_oldValue
!= m_oldPos
)
328 m_oldValue
= m_oldPos
;
329 wxCommandEvent
event(wxEVT_COMMAND_SLIDER_UPDATED
, GetId());
330 event
.SetEventObject(this);
331 event
.SetInt(m_oldPos
);
332 return ProcessCommand(event
);
338 bool wxSlider::SendScrollEvent(WXEVENTPTR event
)
340 const EventType
* palmEvent
= (EventType
*)event
;
341 int newPos
= ValueInvertOrNot(palmEvent
->data
.ctlRepeat
.value
);
342 if ( newPos
== m_oldPos
)
344 // nothing changed since last event
351 wxScrollEvent
eventWx(wxEVT_SCROLL_THUMBTRACK
, GetId());
352 eventWx
.SetPosition(newPos
);
353 eventWx
.SetEventObject(this);
354 return HandleWindowEvent(eventWx
);
357 void wxSlider::Command (wxCommandEvent
& event
)
361 #endif // wxUSE_SLIDER