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"
33 #if wxUSE_EXTENDED_RTTI
34 WX_DEFINE_FLAGS( wxSliderStyle
)
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
)
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
)
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
)
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
)
75 wxEND_FLAGS( wxSliderStyle
)
77 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider
, wxControl
,"wx/scrolbar.h")
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
)
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()
92 wxBEGIN_HANDLERS_TABLE(wxSlider
)
93 wxEND_HANDLERS_TABLE()
95 wxCONSTRUCTOR_8( wxSlider
, wxWindow
* , Parent
, wxWindowID
, Id
, int , Value
, int , Minimum
, int , Maximum
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
97 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
101 void wxSlider::Init()
107 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
108 int value
, int minValue
, int maxValue
,
110 const wxSize
& size
, long style
,
111 const wxValidator
& validator
,
112 const wxString
& name
)
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_INVERSE is ignored - always off
121 // wxSL_VERTICAL is impossible in native form
122 wxCHECK_MSG(!(style
& wxSL_VERTICAL
), false, _T("non vertical slider on PalmOS"));
124 if(!wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
))
127 FormType
* form
= GetParentForm();
133 SliderControlType
*slider
= CtlNewSliderControl (
157 wxSlider::~wxSlider()
161 int wxSlider::GetMin() const
163 ControlType
*control
= (ControlType
*)GetObjectPtr();
167 CtlGetSliderValues(control
, &ret
, NULL
, NULL
, NULL
);
171 int wxSlider::GetMax() const
173 ControlType
*control
= (ControlType
*)GetObjectPtr();
177 CtlGetSliderValues(control
, NULL
, &ret
, NULL
, NULL
);
181 int wxSlider::GetPageSize() const
183 ControlType
*control
= (ControlType
*)GetObjectPtr();
187 CtlGetSliderValues(control
, NULL
, NULL
, &ret
, NULL
);
191 int wxSlider::GetValue() const
193 ControlType
*control
= (ControlType
*)GetObjectPtr();
197 CtlGetSliderValues(control
, NULL
, NULL
, NULL
, &ret
);
201 void wxSlider::SetValue(int value
)
207 wxSize
wxSlider::DoGetBestSize() const
209 // 15 is taken as used in one of official samples
210 // 45 is dummy height tripled, any idea what's better ?
211 return wxSize(45,15);
215 void wxSlider::SetRange(int WXUNUSED(minValue
), int WXUNUSED(maxValue
))
217 // unsupported feature
220 void wxSlider::SetTickFreq(int WXUNUSED(n
), int WXUNUSED(pos
))
222 // unsupported feature
225 void wxSlider::SetPageSize(int pageSize
)
227 ControlType
*control
= (ControlType
*)GetObjectPtr();
230 uint16_t val
= pageSize
;
231 CtlSetSliderValues(control
, NULL
, NULL
, &val
, NULL
);
234 void wxSlider::ClearSel()
236 // unsupported feature
239 void wxSlider::ClearTicks()
241 // unsupported feature
244 void wxSlider::SetLineSize(int lineSize
)
246 m_lineSize
= lineSize
;
249 int wxSlider::GetLineSize() const
254 int wxSlider::GetSelEnd() const
256 // unsupported feature
260 int wxSlider::GetSelStart() const
262 // unsupported feature
266 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
268 // unsupported feature
271 void wxSlider::SetThumbLength(int WXUNUSED(len
))
273 // unsupported feature
276 int wxSlider::GetThumbLength() const
278 // unsupported feature
282 int wxSlider::GetTickFreq() const
284 // unsupported feature
285 return GetPageSize();
288 void wxSlider::SetTick(int WXUNUSED(tickPos
))
290 // unsupported feature
293 // ----------------------------------------------------------------------------
295 // ----------------------------------------------------------------------------
297 bool wxSlider::SendUpdatedEvent()
299 m_oldPos
= GetValue();
302 wxScrollEvent
eventWxTrack(wxEVT_SCROLL_THUMBRELEASE
, GetId());
303 eventWxTrack
.SetPosition(m_oldPos
);
304 eventWxTrack
.SetEventObject(this);
305 GetEventHandler()->ProcessEvent(eventWxTrack
);
308 wxCommandEvent
event(wxEVT_COMMAND_SLIDER_UPDATED
, GetId());
309 event
.SetEventObject(this);
310 event
.SetInt(m_oldPos
);
311 return ProcessCommand(event
);
314 bool wxSlider::SendScrollEvent(EventType
* event
)
316 wxEventType scrollEvent
;
317 int newPos
= event
->data
.ctlRepeat
.value
;
318 if ( newPos
== GetMax() )
320 scrollEvent
= wxEVT_SCROLL_TOP
;
322 else if ( newPos
== GetMin() )
324 scrollEvent
= wxEVT_SCROLL_BOTTOM
;
326 else if ( newPos
== ( m_oldPos
+ GetLineSize() ) )
328 scrollEvent
= wxEVT_SCROLL_LINEUP
;
330 else if ( newPos
== ( m_oldPos
- GetLineSize() ) )
332 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
334 else if ( newPos
== ( m_oldPos
+ GetPageSize() ) )
336 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
338 else if ( newPos
== ( m_oldPos
- GetPageSize() ) )
340 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
350 wxScrollEvent
eventWxTrack(wxEVT_SCROLL_THUMBTRACK
, GetId());
351 eventWxTrack
.SetPosition(newPos
);
352 eventWxTrack
.SetEventObject(this);
353 GetEventHandler()->ProcessEvent(eventWxTrack
);
356 wxScrollEvent
eventWxScroll(scrollEvent
, GetId());
357 eventWxScroll
.SetPosition(newPos
);
358 eventWxScroll
.SetEventObject(this);
359 return GetEventHandler()->ProcessEvent(eventWxScroll
);
362 void wxSlider::Command (wxCommandEvent
& event
)
366 #endif // wxUSE_SLIDER