]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/slider.cpp
Comment correction.
[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 32
20bc5ad8
WS
33#include <Form.h>
34#include <Control.h>
35
ffecfa5a
JS
36#if wxUSE_EXTENDED_RTTI
37WX_DEFINE_FLAGS( wxSliderStyle )
38
39wxBEGIN_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)
e2731512 48
ffecfa5a
JS
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)
56
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)
66
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)
77
78wxEND_FLAGS( wxSliderStyle )
79
80IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h")
81
82wxBEGIN_PROPERTIES_TABLE(wxSlider)
83 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
84 wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
85
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
93wxEND_PROPERTIES_TABLE()
94
95wxBEGIN_HANDLERS_TABLE(wxSlider)
96wxEND_HANDLERS_TABLE()
97
98wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
99#else
100IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
101#endif
102
103// Slider
721a9626 104void wxSlider::Init()
ffecfa5a 105{
8be10866 106 m_oldValue = m_oldPos = 0;
721a9626 107 m_lineSize = 1;
ffecfa5a
JS
108}
109
110bool wxSlider::Create(wxWindow *parent, wxWindowID id,
111 int value, int minValue, int maxValue,
112 const wxPoint& pos,
113 const wxSize& size, long style,
114 const wxValidator& validator,
115 const wxString& name)
116{
721a9626
WS
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
721a9626
WS
123 // wxSL_VERTICAL is impossible in native form
124 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
8be10866 125
a152561c
WS
126 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
127 return false;
128
20bc5ad8 129 FormType* form = (FormType*)GetParentForm();
ba889513
WS
130 if(form==NULL)
131 return false;
bdb54365 132
8be10866 133 m_oldValue = m_oldPos = value;
721a9626 134
be4e4e27
WS
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;
139
140 AdjustForParentClientOrigin(x, y);
141
bdb54365
WS
142 SliderControlType *slider = CtlNewSliderControl (
143 (void **)&form,
ba889513 144 GetId(),
bdb54365
WS
145 feedbackSliderCtl,
146 NULL,
147 0,
148 0,
be4e4e27
WS
149 x,
150 y,
151 w,
152 h,
bdb54365
WS
153 minValue,
154 maxValue,
155 1,
156 value
157 );
158
ba889513 159 if(slider==NULL)
bdb54365
WS
160 return false;
161
be4e4e27 162 SetInitialBestSize(size);
bdb54365
WS
163 Show();
164 return true;
ffecfa5a
JS
165}
166
bdb54365 167wxSlider::~wxSlider()
ffecfa5a 168{
ffecfa5a
JS
169}
170
bdb54365
WS
171int wxSlider::GetMin() const
172{
a152561c
WS
173 ControlType *control = (ControlType *)GetObjectPtr();
174 if(control==NULL)
175 return 0;
bdb54365 176 uint16_t ret;
a152561c 177 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
bdb54365
WS
178 return ret;
179}
180
181int wxSlider::GetMax() const
182{
a152561c
WS
183 ControlType *control = (ControlType *)GetObjectPtr();
184 if(control==NULL)
185 return 0;
bdb54365 186 uint16_t ret;
a152561c 187 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
bdb54365
WS
188 return ret;
189}
190
191int wxSlider::GetPageSize() const
ffecfa5a 192{
a152561c
WS
193 ControlType *control = (ControlType *)GetObjectPtr();
194 if(control==NULL)
195 return 0;
bdb54365 196 uint16_t ret;
a152561c 197 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
bdb54365 198 return ret;
ffecfa5a
JS
199}
200
201int wxSlider::GetValue() const
202{
a152561c
WS
203 ControlType *control = (ControlType *)GetObjectPtr();
204 if(control==NULL)
205 return 0;
bdb54365 206 uint16_t ret;
a152561c 207 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
01526d4f 208 return ValueInvertOrNot(ret);
ffecfa5a
JS
209}
210
211void wxSlider::SetValue(int value)
212{
01526d4f 213 SetIntValue(ValueInvertOrNot(value));
8be10866 214 m_oldValue = m_oldPos = value;
ffecfa5a
JS
215}
216
ffecfa5a
JS
217wxSize wxSlider::DoGetBestSize() const
218{
721a9626
WS
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);
ffecfa5a
JS
222}
223
224
721a9626 225void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
ffecfa5a 226{
721a9626 227 // unsupported feature
ffecfa5a
JS
228}
229
721a9626 230void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos))
ffecfa5a 231{
721a9626 232 // unsupported feature
ffecfa5a
JS
233}
234
235void wxSlider::SetPageSize(int pageSize)
236{
721a9626
WS
237 ControlType *control = (ControlType *)GetObjectPtr();
238 if(control==NULL)
239 return;
240 uint16_t val = pageSize;
241 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
ffecfa5a
JS
242}
243
ffecfa5a
JS
244void wxSlider::ClearSel()
245{
721a9626 246 // unsupported feature
ffecfa5a
JS
247}
248
249void wxSlider::ClearTicks()
250{
721a9626 251 // unsupported feature
ffecfa5a
JS
252}
253
254void wxSlider::SetLineSize(int lineSize)
255{
721a9626 256 m_lineSize = lineSize;
ffecfa5a
JS
257}
258
259int wxSlider::GetLineSize() const
260{
721a9626 261 return m_lineSize;
ffecfa5a
JS
262}
263
264int wxSlider::GetSelEnd() const
265{
721a9626
WS
266 // unsupported feature
267 return GetValue();
ffecfa5a
JS
268}
269
270int wxSlider::GetSelStart() const
271{
721a9626
WS
272 // unsupported feature
273 return GetValue();
ffecfa5a
JS
274}
275
721a9626 276void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
ffecfa5a 277{
721a9626 278 // unsupported feature
ffecfa5a
JS
279}
280
721a9626 281void wxSlider::SetThumbLength(int WXUNUSED(len))
ffecfa5a 282{
721a9626 283 // unsupported feature
ffecfa5a
JS
284}
285
286int wxSlider::GetThumbLength() const
287{
721a9626 288 // unsupported feature
ffecfa5a
JS
289 return 0;
290}
291
721a9626
WS
292int wxSlider::GetTickFreq() const
293{
294 // unsupported feature
295 return GetPageSize();
296}
297
298void wxSlider::SetTick(int WXUNUSED(tickPos))
ffecfa5a 299{
721a9626 300 // unsupported feature
ffecfa5a
JS
301}
302
9a727a3b
WS
303// ----------------------------------------------------------------------------
304// helpers
305// ----------------------------------------------------------------------------
306
307bool wxSlider::SendUpdatedEvent()
308{
721a9626
WS
309 m_oldPos = GetValue();
310
8be10866 311 // first thumb event
721a9626
WS
312 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
313 eventWxTrack.SetPosition(m_oldPos);
314 eventWxTrack.SetEventObject(this);
8be10866
WS
315 bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
316
317 // then slider event if position changed
318 if( m_oldValue != m_oldPos )
319 {
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);
325 }
721a9626 326
8be10866 327 return handled;
9a727a3b
WS
328}
329
20bc5ad8 330bool wxSlider::SendScrollEvent(WXEVENTPTR event)
721a9626 331{
20bc5ad8
WS
332 const EventType* palmEvent = (EventType*)event;
333 int newPos = ValueInvertOrNot(palmEvent->data.ctlRepeat.value);
8be10866 334 if ( newPos == m_oldPos )
721a9626 335 {
8be10866 336 // nothing changed since last event
721a9626
WS
337 return false;
338 }
339
340 m_oldPos = newPos;
341
342 // first track event
8be10866
WS
343 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
344 eventWx.SetPosition(newPos);
345 eventWx.SetEventObject(this);
346 return GetEventHandler()->ProcessEvent(eventWx);
721a9626
WS
347}
348
ffecfa5a
JS
349void wxSlider::Command (wxCommandEvent & event)
350{
351}
352
ffecfa5a 353#endif // wxUSE_SLIDER