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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "slider.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/slider.h"
31 #include "wx/toplevel.h"
36 #if wxUSE_EXTENDED_RTTI
37 WX_DEFINE_FLAGS( wxSliderStyle
)
39 wxBEGIN_FLAGS( wxSliderStyle
)
40 // new style border flags, we put them first to
41 // use them for streaming out
42 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
43 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
44 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
45 wxFLAGS_MEMBER(wxBORDER_RAISED
)
46 wxFLAGS_MEMBER(wxBORDER_STATIC
)
47 wxFLAGS_MEMBER(wxBORDER_NONE
)
49 // old style border flags
50 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
51 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
52 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
53 wxFLAGS_MEMBER(wxRAISED_BORDER
)
54 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
55 wxFLAGS_MEMBER(wxBORDER
)
57 // standard window styles
58 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
59 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
60 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
61 wxFLAGS_MEMBER(wxWANTS_CHARS
)
62 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
63 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
64 wxFLAGS_MEMBER(wxVSCROLL
)
65 wxFLAGS_MEMBER(wxHSCROLL
)
67 wxFLAGS_MEMBER(wxSL_HORIZONTAL
)
68 wxFLAGS_MEMBER(wxSL_VERTICAL
)
69 wxFLAGS_MEMBER(wxSL_AUTOTICKS
)
70 wxFLAGS_MEMBER(wxSL_LABELS
)
71 wxFLAGS_MEMBER(wxSL_LEFT
)
72 wxFLAGS_MEMBER(wxSL_TOP
)
73 wxFLAGS_MEMBER(wxSL_RIGHT
)
74 wxFLAGS_MEMBER(wxSL_BOTTOM
)
75 wxFLAGS_MEMBER(wxSL_BOTH
)
76 wxFLAGS_MEMBER(wxSL_SELRANGE
)
78 wxEND_FLAGS( wxSliderStyle
)
80 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider
, wxControl
,"wx/scrolbar.h")
82 wxBEGIN_PROPERTIES_TABLE(wxSlider
)
83 wxEVENT_RANGE_PROPERTY( Scroll
, wxEVT_SCROLL_TOP
, wxEVT_SCROLL_ENDSCROLL
, wxScrollEvent
)
84 wxEVENT_PROPERTY( Updated
, wxEVT_COMMAND_SLIDER_UPDATED
, wxCommandEvent
)
86 wxPROPERTY( Value
, int , SetValue
, GetValue
, 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
87 wxPROPERTY( Minimum
, int , SetMin
, GetMin
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
88 wxPROPERTY( Maximum
, int , SetMax
, GetMax
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
89 wxPROPERTY( PageSize
, int , SetPageSize
, GetLineSize
, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
90 wxPROPERTY( LineSize
, int , SetLineSize
, GetLineSize
, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
91 wxPROPERTY( ThumbLength
, int , SetThumbLength
, GetThumbLength
, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
92 wxPROPERTY_FLAGS( WindowStyle
, wxSliderStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
93 wxEND_PROPERTIES_TABLE()
95 wxBEGIN_HANDLERS_TABLE(wxSlider
)
96 wxEND_HANDLERS_TABLE()
98 wxCONSTRUCTOR_8( wxSlider
, wxWindow
* , Parent
, wxWindowID
, Id
, int , Value
, int , Minimum
, int , Maximum
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
100 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
104 void wxSlider::Init()
106 m_oldValue
= m_oldPos
= 0;
110 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
111 int value
, int minValue
, int maxValue
,
113 const wxSize
& size
, long style
,
114 const wxValidator
& validator
,
115 const wxString
& name
)
117 // wxSL_AUTOTICKS is ignored - always on
118 // wxSL_LABELS is ignored - always off
119 // wxSL_LEFT is ignored - always off
120 // wxSL_RIGHT is ignored - always off
121 // wxSL_TOP is ignored - always off
122 // wxSL_SELRANGE is ignored - always off
123 // wxSL_VERTICAL is impossible in native form
124 wxCHECK_MSG(!(style
& wxSL_VERTICAL
), false, _T("non vertical slider on PalmOS"));
126 if(!wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
))
129 FormType
* form
= (FormType
*)GetParentForm();
133 m_oldValue
= m_oldPos
= value
;
135 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
136 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
137 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
138 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
140 AdjustForParentClientOrigin(x
, y
);
142 SliderControlType
*slider
= CtlNewSliderControl (
162 SetInitialBestSize(size
);
167 wxSlider::~wxSlider()
171 int wxSlider::GetMin() const
173 ControlType
*control
= (ControlType
*)GetObjectPtr();
177 CtlGetSliderValues(control
, &ret
, NULL
, NULL
, NULL
);
181 int wxSlider::GetMax() const
183 ControlType
*control
= (ControlType
*)GetObjectPtr();
187 CtlGetSliderValues(control
, NULL
, &ret
, NULL
, NULL
);
191 int wxSlider::GetPageSize() const
193 ControlType
*control
= (ControlType
*)GetObjectPtr();
197 CtlGetSliderValues(control
, NULL
, NULL
, &ret
, NULL
);
201 int wxSlider::GetValue() const
203 ControlType
*control
= (ControlType
*)GetObjectPtr();
207 CtlGetSliderValues(control
, NULL
, NULL
, NULL
, &ret
);
208 return ValueInvertOrNot(ret
);
211 void wxSlider::SetValue(int value
)
213 SetIntValue(ValueInvertOrNot(value
));
214 m_oldValue
= m_oldPos
= value
;
217 wxSize
wxSlider::DoGetBestSize() const
219 // 15 is taken as used in one of official samples
220 // 45 is dummy height tripled, any idea what's better ?
221 return wxSize(45,15);
225 void wxSlider::SetRange(int WXUNUSED(minValue
), int WXUNUSED(maxValue
))
227 // unsupported feature
230 void wxSlider::SetTickFreq(int WXUNUSED(n
), int WXUNUSED(pos
))
232 // unsupported feature
235 void wxSlider::SetPageSize(int pageSize
)
237 ControlType
*control
= (ControlType
*)GetObjectPtr();
240 uint16_t val
= pageSize
;
241 CtlSetSliderValues(control
, NULL
, NULL
, &val
, NULL
);
244 void wxSlider::ClearSel()
246 // unsupported feature
249 void wxSlider::ClearTicks()
251 // unsupported feature
254 void wxSlider::SetLineSize(int lineSize
)
256 m_lineSize
= lineSize
;
259 int wxSlider::GetLineSize() const
264 int wxSlider::GetSelEnd() const
266 // unsupported feature
270 int wxSlider::GetSelStart() const
272 // unsupported feature
276 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
278 // unsupported feature
281 void wxSlider::SetThumbLength(int WXUNUSED(len
))
283 // unsupported feature
286 int wxSlider::GetThumbLength() const
288 // unsupported feature
292 int wxSlider::GetTickFreq() const
294 // unsupported feature
295 return GetPageSize();
298 void wxSlider::SetTick(int WXUNUSED(tickPos
))
300 // unsupported feature
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
307 bool wxSlider::SendUpdatedEvent()
309 m_oldPos
= GetValue();
312 wxScrollEvent
eventWxTrack(wxEVT_SCROLL_THUMBRELEASE
, GetId());
313 eventWxTrack
.SetPosition(m_oldPos
);
314 eventWxTrack
.SetEventObject(this);
315 bool handled
= GetEventHandler()->ProcessEvent(eventWxTrack
);
317 // then slider event if position changed
318 if( m_oldValue
!= m_oldPos
)
320 m_oldValue
= m_oldPos
;
321 wxCommandEvent
event(wxEVT_COMMAND_SLIDER_UPDATED
, GetId());
322 event
.SetEventObject(this);
323 event
.SetInt(m_oldPos
);
324 return ProcessCommand(event
);
330 bool wxSlider::SendScrollEvent(WXEVENTPTR event
)
332 const EventType
* palmEvent
= (EventType
*)event
;
333 int newPos
= ValueInvertOrNot(palmEvent
->data
.ctlRepeat
.value
);
334 if ( newPos
== m_oldPos
)
336 // nothing changed since last event
343 wxScrollEvent
eventWx(wxEVT_SCROLL_THUMBTRACK
, GetId());
344 eventWx
.SetPosition(newPos
);
345 eventWx
.SetEventObject(this);
346 return GetEventHandler()->ProcessEvent(eventWx
);
349 void wxSlider::Command (wxCommandEvent
& event
)
353 #endif // wxUSE_SLIDER