]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/slider.cpp
Bump subrelease number
[wxWidgets.git] / src / palmos / slider.cpp
CommitLineData
ffecfa5a 1/////////////////////////////////////////////////////////////////////////////
e2731512 2// Name: src/palmos/slider.cpp
ffecfa5a 3// Purpose: wxSlider
e2731512 4// Author: William Osborne - minimal working wxPalmOS port
bdb54365 5// Modified by: Wlodzimierz ABX Skiba - native implementation
ffecfa5a 6// Created: 10/13/04
e2731512 7// RCS-ID: $Id$
bdb54365 8// Copyright: (c) William Osborne, Wlodzimierz Skiba
ffecfa5a
JS
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "slider.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#if wxUSE_SLIDER
24
25#ifndef WX_PRECOMP
26#include "wx/utils.h"
27#include "wx/brush.h"
28#include "wx/slider.h"
29#endif
30
bdb54365 31#include "wx/toplevel.h"
ffecfa5a
JS
32
33#if wxUSE_EXTENDED_RTTI
34WX_DEFINE_FLAGS( wxSliderStyle )
35
36wxBEGIN_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)
e2731512 45
ffecfa5a
JS
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)
53
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)
63
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)
74
75wxEND_FLAGS( wxSliderStyle )
76
77IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h")
78
79wxBEGIN_PROPERTIES_TABLE(wxSlider)
80 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
81 wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
82
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
90wxEND_PROPERTIES_TABLE()
91
92wxBEGIN_HANDLERS_TABLE(wxSlider)
93wxEND_HANDLERS_TABLE()
94
95wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
96#else
97IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
98#endif
99
100// Slider
721a9626 101void wxSlider::Init()
ffecfa5a 102{
8be10866 103 m_oldValue = m_oldPos = 0;
721a9626 104 m_lineSize = 1;
ffecfa5a
JS
105}
106
107bool wxSlider::Create(wxWindow *parent, wxWindowID id,
108 int value, int minValue, int maxValue,
109 const wxPoint& pos,
110 const wxSize& size, long style,
111 const wxValidator& validator,
112 const wxString& name)
113{
721a9626
WS
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
721a9626
WS
120 // wxSL_VERTICAL is impossible in native form
121 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
8be10866 122
a152561c
WS
123 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
124 return false;
125
ba889513
WS
126 FormType* form = GetParentForm();
127 if(form==NULL)
128 return false;
bdb54365 129
8be10866 130 m_oldValue = m_oldPos = value;
721a9626 131
be4e4e27
WS
132 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
133 y = pos.y == wxDefaultCoord ? 0 : pos.y,
134 w = size.x == wxDefaultCoord ? 1 : size.x,
135 h = size.y == wxDefaultCoord ? 1 : size.y;
136
137 AdjustForParentClientOrigin(x, y);
138
bdb54365
WS
139 SliderControlType *slider = CtlNewSliderControl (
140 (void **)&form,
ba889513 141 GetId(),
bdb54365
WS
142 feedbackSliderCtl,
143 NULL,
144 0,
145 0,
be4e4e27
WS
146 x,
147 y,
148 w,
149 h,
bdb54365
WS
150 minValue,
151 maxValue,
152 1,
153 value
154 );
155
ba889513 156 if(slider==NULL)
bdb54365
WS
157 return false;
158
be4e4e27 159 SetInitialBestSize(size);
bdb54365
WS
160 Show();
161 return true;
ffecfa5a
JS
162}
163
bdb54365 164wxSlider::~wxSlider()
ffecfa5a 165{
ffecfa5a
JS
166}
167
bdb54365
WS
168int wxSlider::GetMin() const
169{
a152561c
WS
170 ControlType *control = (ControlType *)GetObjectPtr();
171 if(control==NULL)
172 return 0;
bdb54365 173 uint16_t ret;
a152561c 174 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
bdb54365
WS
175 return ret;
176}
177
178int wxSlider::GetMax() const
179{
a152561c
WS
180 ControlType *control = (ControlType *)GetObjectPtr();
181 if(control==NULL)
182 return 0;
bdb54365 183 uint16_t ret;
a152561c 184 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
bdb54365
WS
185 return ret;
186}
187
188int wxSlider::GetPageSize() const
ffecfa5a 189{
a152561c
WS
190 ControlType *control = (ControlType *)GetObjectPtr();
191 if(control==NULL)
192 return 0;
bdb54365 193 uint16_t ret;
a152561c 194 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
bdb54365 195 return ret;
ffecfa5a
JS
196}
197
198int wxSlider::GetValue() const
199{
a152561c
WS
200 ControlType *control = (ControlType *)GetObjectPtr();
201 if(control==NULL)
202 return 0;
bdb54365 203 uint16_t ret;
a152561c 204 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
01526d4f 205 return ValueInvertOrNot(ret);
ffecfa5a
JS
206}
207
208void wxSlider::SetValue(int value)
209{
01526d4f 210 SetIntValue(ValueInvertOrNot(value));
8be10866 211 m_oldValue = m_oldPos = value;
ffecfa5a
JS
212}
213
ffecfa5a
JS
214wxSize wxSlider::DoGetBestSize() const
215{
721a9626
WS
216 // 15 is taken as used in one of official samples
217 // 45 is dummy height tripled, any idea what's better ?
218 return wxSize(45,15);
ffecfa5a
JS
219}
220
221
721a9626 222void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
ffecfa5a 223{
721a9626 224 // unsupported feature
ffecfa5a
JS
225}
226
721a9626 227void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos))
ffecfa5a 228{
721a9626 229 // unsupported feature
ffecfa5a
JS
230}
231
232void wxSlider::SetPageSize(int pageSize)
233{
721a9626
WS
234 ControlType *control = (ControlType *)GetObjectPtr();
235 if(control==NULL)
236 return;
237 uint16_t val = pageSize;
238 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
ffecfa5a
JS
239}
240
ffecfa5a
JS
241void wxSlider::ClearSel()
242{
721a9626 243 // unsupported feature
ffecfa5a
JS
244}
245
246void wxSlider::ClearTicks()
247{
721a9626 248 // unsupported feature
ffecfa5a
JS
249}
250
251void wxSlider::SetLineSize(int lineSize)
252{
721a9626 253 m_lineSize = lineSize;
ffecfa5a
JS
254}
255
256int wxSlider::GetLineSize() const
257{
721a9626 258 return m_lineSize;
ffecfa5a
JS
259}
260
261int wxSlider::GetSelEnd() const
262{
721a9626
WS
263 // unsupported feature
264 return GetValue();
ffecfa5a
JS
265}
266
267int wxSlider::GetSelStart() const
268{
721a9626
WS
269 // unsupported feature
270 return GetValue();
ffecfa5a
JS
271}
272
721a9626 273void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
ffecfa5a 274{
721a9626 275 // unsupported feature
ffecfa5a
JS
276}
277
721a9626 278void wxSlider::SetThumbLength(int WXUNUSED(len))
ffecfa5a 279{
721a9626 280 // unsupported feature
ffecfa5a
JS
281}
282
283int wxSlider::GetThumbLength() const
284{
721a9626 285 // unsupported feature
ffecfa5a
JS
286 return 0;
287}
288
721a9626
WS
289int wxSlider::GetTickFreq() const
290{
291 // unsupported feature
292 return GetPageSize();
293}
294
295void wxSlider::SetTick(int WXUNUSED(tickPos))
ffecfa5a 296{
721a9626 297 // unsupported feature
ffecfa5a
JS
298}
299
9a727a3b
WS
300// ----------------------------------------------------------------------------
301// helpers
302// ----------------------------------------------------------------------------
303
304bool wxSlider::SendUpdatedEvent()
305{
721a9626
WS
306 m_oldPos = GetValue();
307
8be10866 308 // first thumb event
721a9626
WS
309 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
310 eventWxTrack.SetPosition(m_oldPos);
311 eventWxTrack.SetEventObject(this);
8be10866
WS
312 bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
313
314 // then slider event if position changed
315 if( m_oldValue != m_oldPos )
316 {
317 m_oldValue = m_oldPos;
318 wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
319 event.SetEventObject(this);
320 event.SetInt(m_oldPos);
321 return ProcessCommand(event);
322 }
721a9626 323
8be10866 324 return handled;
9a727a3b
WS
325}
326
721a9626
WS
327bool wxSlider::SendScrollEvent(EventType* event)
328{
329 wxEventType scrollEvent;
01526d4f 330 int newPos = ValueInvertOrNot(event->data.ctlRepeat.value);
8be10866 331 if ( newPos == m_oldPos )
721a9626 332 {
8be10866 333 // nothing changed since last event
721a9626
WS
334 return false;
335 }
336
337 m_oldPos = newPos;
338
339 // first track event
8be10866
WS
340 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
341 eventWx.SetPosition(newPos);
342 eventWx.SetEventObject(this);
343 return GetEventHandler()->ProcessEvent(eventWx);
721a9626
WS
344}
345
ffecfa5a
JS
346void wxSlider::Command (wxCommandEvent & event)
347{
348}
349
ffecfa5a 350#endif // wxUSE_SLIDER