]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/slider.cpp
Add backend descriptions for all backends to the documentation.
[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
ffecfa5a
JS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#if wxUSE_SLIDER
20
ffecfa5a 21#include "wx/slider.h"
f4da9a94
WS
22
23#ifndef WX_PRECOMP
24 #include "wx/utils.h"
25 #include "wx/brush.h"
1832043f 26 #include "wx/toplevel.h"
ffecfa5a
JS
27#endif
28
20bc5ad8
WS
29#include <Form.h>
30#include <Control.h>
31
ffecfa5a 32// Slider
721a9626 33void wxSlider::Init()
ffecfa5a 34{
8be10866 35 m_oldValue = m_oldPos = 0;
721a9626 36 m_lineSize = 1;
ffecfa5a
JS
37}
38
39bool wxSlider::Create(wxWindow *parent, wxWindowID id,
40 int value, int minValue, int maxValue,
41 const wxPoint& pos,
42 const wxSize& size, long style,
43 const wxValidator& validator,
44 const wxString& name)
45{
721a9626
WS
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
721a9626 52 // wxSL_VERTICAL is impossible in native form
9a83f860 53 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, wxT("non vertical slider on PalmOS"));
8be10866 54
a152561c
WS
55 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
56 return false;
57
20bc5ad8 58 FormType* form = (FormType*)GetParentForm();
ba889513
WS
59 if(form==NULL)
60 return false;
bdb54365 61
8be10866 62 m_oldValue = m_oldPos = value;
721a9626 63
be4e4e27
WS
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;
68
69 AdjustForParentClientOrigin(x, y);
70
6afc1b46 71#ifdef __WXPALMOS6__
bdb54365
WS
72 SliderControlType *slider = CtlNewSliderControl (
73 (void **)&form,
ba889513 74 GetId(),
bdb54365
WS
75 feedbackSliderCtl,
76 NULL,
77 0,
78 0,
be4e4e27
WS
79 x,
80 y,
81 w,
82 h,
bdb54365
WS
83 minValue,
84 maxValue,
85 1,
86 value
87 );
6afc1b46
VZ
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,
93 GetId(),
94 feedbackSliderCtl,//style
95 0,//thumbID
96 0,//backgroundid
97 x, y, w, h, minValue, maxValue, 1, value);
98#endif // __WXPALMOS6__/__WXPALMOS5__
bdb54365 99
ba889513 100 if(slider==NULL)
bdb54365
WS
101 return false;
102
170acdc9 103 SetInitialSize(size);
bdb54365
WS
104 Show();
105 return true;
ffecfa5a
JS
106}
107
bdb54365 108wxSlider::~wxSlider()
ffecfa5a 109{
ffecfa5a
JS
110}
111
bdb54365
WS
112int wxSlider::GetMin() const
113{
a152561c
WS
114 ControlType *control = (ControlType *)GetObjectPtr();
115 if(control==NULL)
116 return 0;
bdb54365 117 uint16_t ret;
a152561c 118 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
bdb54365
WS
119 return ret;
120}
121
122int wxSlider::GetMax() const
123{
a152561c
WS
124 ControlType *control = (ControlType *)GetObjectPtr();
125 if(control==NULL)
126 return 0;
bdb54365 127 uint16_t ret;
a152561c 128 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
bdb54365
WS
129 return ret;
130}
131
132int wxSlider::GetPageSize() const
ffecfa5a 133{
a152561c
WS
134 ControlType *control = (ControlType *)GetObjectPtr();
135 if(control==NULL)
136 return 0;
bdb54365 137 uint16_t ret;
a152561c 138 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
bdb54365 139 return ret;
ffecfa5a
JS
140}
141
142int wxSlider::GetValue() const
143{
a152561c
WS
144 ControlType *control = (ControlType *)GetObjectPtr();
145 if(control==NULL)
146 return 0;
bdb54365 147 uint16_t ret;
a152561c 148 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
01526d4f 149 return ValueInvertOrNot(ret);
ffecfa5a
JS
150}
151
152void wxSlider::SetValue(int value)
153{
01526d4f 154 SetIntValue(ValueInvertOrNot(value));
8be10866 155 m_oldValue = m_oldPos = value;
ffecfa5a
JS
156}
157
ffecfa5a
JS
158wxSize wxSlider::DoGetBestSize() const
159{
721a9626
WS
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);
ffecfa5a
JS
163}
164
165
721a9626 166void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
ffecfa5a 167{
721a9626 168 // unsupported feature
ffecfa5a
JS
169}
170
0a12e013 171void wxSlider::DoSetTickFreq(int WXUNUSED(n))
ffecfa5a 172{
721a9626 173 // unsupported feature
ffecfa5a
JS
174}
175
176void wxSlider::SetPageSize(int pageSize)
177{
721a9626
WS
178 ControlType *control = (ControlType *)GetObjectPtr();
179 if(control==NULL)
180 return;
181 uint16_t val = pageSize;
182 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
ffecfa5a
JS
183}
184
ffecfa5a
JS
185void wxSlider::ClearSel()
186{
721a9626 187 // unsupported feature
ffecfa5a
JS
188}
189
190void wxSlider::ClearTicks()
191{
721a9626 192 // unsupported feature
ffecfa5a
JS
193}
194
195void wxSlider::SetLineSize(int lineSize)
196{
721a9626 197 m_lineSize = lineSize;
ffecfa5a
JS
198}
199
200int wxSlider::GetLineSize() const
201{
721a9626 202 return m_lineSize;
ffecfa5a
JS
203}
204
205int wxSlider::GetSelEnd() const
206{
721a9626
WS
207 // unsupported feature
208 return GetValue();
ffecfa5a
JS
209}
210
211int wxSlider::GetSelStart() const
212{
721a9626
WS
213 // unsupported feature
214 return GetValue();
ffecfa5a
JS
215}
216
721a9626 217void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
ffecfa5a 218{
721a9626 219 // unsupported feature
ffecfa5a
JS
220}
221
721a9626 222void wxSlider::SetThumbLength(int WXUNUSED(len))
ffecfa5a 223{
721a9626 224 // unsupported feature
ffecfa5a
JS
225}
226
227int wxSlider::GetThumbLength() const
228{
721a9626 229 // unsupported feature
ffecfa5a
JS
230 return 0;
231}
232
721a9626
WS
233int wxSlider::GetTickFreq() const
234{
235 // unsupported feature
236 return GetPageSize();
237}
238
239void wxSlider::SetTick(int WXUNUSED(tickPos))
ffecfa5a 240{
721a9626 241 // unsupported feature
ffecfa5a
JS
242}
243
9a727a3b
WS
244// ----------------------------------------------------------------------------
245// helpers
246// ----------------------------------------------------------------------------
247
248bool wxSlider::SendUpdatedEvent()
249{
721a9626
WS
250 m_oldPos = GetValue();
251
8be10866 252 // first thumb event
721a9626
WS
253 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
254 eventWxTrack.SetPosition(m_oldPos);
255 eventWxTrack.SetEventObject(this);
937013e0 256 bool handled = HandleWindowEvent(eventWxTrack);
8be10866
WS
257
258 // then slider event if position changed
259 if( m_oldValue != m_oldPos )
260 {
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);
266 }
721a9626 267
8be10866 268 return handled;
9a727a3b
WS
269}
270
20bc5ad8 271bool wxSlider::SendScrollEvent(WXEVENTPTR event)
721a9626 272{
20bc5ad8
WS
273 const EventType* palmEvent = (EventType*)event;
274 int newPos = ValueInvertOrNot(palmEvent->data.ctlRepeat.value);
8be10866 275 if ( newPos == m_oldPos )
721a9626 276 {
8be10866 277 // nothing changed since last event
721a9626
WS
278 return false;
279 }
280
281 m_oldPos = newPos;
282
283 // first track event
8be10866
WS
284 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
285 eventWx.SetPosition(newPos);
286 eventWx.SetEventObject(this);
937013e0 287 return HandleWindowEvent(eventWx);
721a9626
WS
288}
289
ffecfa5a
JS
290void wxSlider::Command (wxCommandEvent & event)
291{
292}
293
ffecfa5a 294#endif // wxUSE_SLIDER