]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/slider.cpp
Removed wxClearVariant() and wxReleaseVariant().
[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
JS
32#if wxUSE_EXTENDED_RTTI
33WX_DEFINE_FLAGS( wxSliderStyle )
34
35wxBEGIN_FLAGS( wxSliderStyle )
36 // new style border flags, we put them first to
37 // use them for streaming out
38 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
39 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
40 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
41 wxFLAGS_MEMBER(wxBORDER_RAISED)
42 wxFLAGS_MEMBER(wxBORDER_STATIC)
43 wxFLAGS_MEMBER(wxBORDER_NONE)
e2731512 44
ffecfa5a
JS
45 // old style border flags
46 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
47 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
48 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
49 wxFLAGS_MEMBER(wxRAISED_BORDER)
50 wxFLAGS_MEMBER(wxSTATIC_BORDER)
51 wxFLAGS_MEMBER(wxBORDER)
52
53 // standard window styles
54 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
55 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
56 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
57 wxFLAGS_MEMBER(wxWANTS_CHARS)
58 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
59 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
60 wxFLAGS_MEMBER(wxVSCROLL)
61 wxFLAGS_MEMBER(wxHSCROLL)
62
63 wxFLAGS_MEMBER(wxSL_HORIZONTAL)
64 wxFLAGS_MEMBER(wxSL_VERTICAL)
65 wxFLAGS_MEMBER(wxSL_AUTOTICKS)
66 wxFLAGS_MEMBER(wxSL_LABELS)
67 wxFLAGS_MEMBER(wxSL_LEFT)
68 wxFLAGS_MEMBER(wxSL_TOP)
69 wxFLAGS_MEMBER(wxSL_RIGHT)
70 wxFLAGS_MEMBER(wxSL_BOTTOM)
71 wxFLAGS_MEMBER(wxSL_BOTH)
72 wxFLAGS_MEMBER(wxSL_SELRANGE)
73
74wxEND_FLAGS( wxSliderStyle )
75
851dee09 76IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/slider.h")
ffecfa5a
JS
77
78wxBEGIN_PROPERTIES_TABLE(wxSlider)
79 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
80 wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
81
82 wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
83 wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
84 wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
85 wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
86 wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
87 wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
88 wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
89wxEND_PROPERTIES_TABLE()
90
91wxBEGIN_HANDLERS_TABLE(wxSlider)
92wxEND_HANDLERS_TABLE()
93
94wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
95#else
96IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
97#endif
98
99// Slider
721a9626 100void wxSlider::Init()
ffecfa5a 101{
8be10866 102 m_oldValue = m_oldPos = 0;
721a9626 103 m_lineSize = 1;
ffecfa5a
JS
104}
105
106bool wxSlider::Create(wxWindow *parent, wxWindowID id,
107 int value, int minValue, int maxValue,
108 const wxPoint& pos,
109 const wxSize& size, long style,
110 const wxValidator& validator,
111 const wxString& name)
112{
721a9626
WS
113 // wxSL_AUTOTICKS is ignored - always on
114 // wxSL_LABELS is ignored - always off
115 // wxSL_LEFT is ignored - always off
116 // wxSL_RIGHT is ignored - always off
117 // wxSL_TOP is ignored - always off
118 // wxSL_SELRANGE is ignored - always off
721a9626 119 // wxSL_VERTICAL is impossible in native form
9a83f860 120 wxCHECK_MSG(!(style & wxSL_VERTICAL), false, wxT("non vertical slider on PalmOS"));
8be10866 121
a152561c
WS
122 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
123 return false;
124
20bc5ad8 125 FormType* form = (FormType*)GetParentForm();
ba889513
WS
126 if(form==NULL)
127 return false;
bdb54365 128
8be10866 129 m_oldValue = m_oldPos = value;
721a9626 130
be4e4e27
WS
131 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
132 y = pos.y == wxDefaultCoord ? 0 : pos.y,
133 w = size.x == wxDefaultCoord ? 1 : size.x,
134 h = size.y == wxDefaultCoord ? 1 : size.y;
135
136 AdjustForParentClientOrigin(x, y);
137
6afc1b46 138#ifdef __WXPALMOS6__
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 );
6afc1b46
VZ
155#else // __WXPALMOS5__
156 //SliderControlType *CtlNewSliderControl (void **formPP, UInt16 ID, ControlStyleType style, DmResID thumbID,
157 // DmResID backgroundID, Coord x, Coord y, Coord width, Coord height, UInt16 minValue, UInt16 maxValue,
158 // UInt16 pageSize, UInt16 value);
159 SliderControlType *slider = CtlNewSliderControl ((void **)&form,
160 GetId(),
161 feedbackSliderCtl,//style
162 0,//thumbID
163 0,//backgroundid
164 x, y, w, h, minValue, maxValue, 1, value);
165#endif // __WXPALMOS6__/__WXPALMOS5__
bdb54365 166
ba889513 167 if(slider==NULL)
bdb54365
WS
168 return false;
169
170acdc9 170 SetInitialSize(size);
bdb54365
WS
171 Show();
172 return true;
ffecfa5a
JS
173}
174
bdb54365 175wxSlider::~wxSlider()
ffecfa5a 176{
ffecfa5a
JS
177}
178
bdb54365
WS
179int wxSlider::GetMin() const
180{
a152561c
WS
181 ControlType *control = (ControlType *)GetObjectPtr();
182 if(control==NULL)
183 return 0;
bdb54365 184 uint16_t ret;
a152561c 185 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
bdb54365
WS
186 return ret;
187}
188
189int wxSlider::GetMax() const
190{
a152561c
WS
191 ControlType *control = (ControlType *)GetObjectPtr();
192 if(control==NULL)
193 return 0;
bdb54365 194 uint16_t ret;
a152561c 195 CtlGetSliderValues(control, NULL, &ret, NULL, NULL);
bdb54365
WS
196 return ret;
197}
198
199int wxSlider::GetPageSize() const
ffecfa5a 200{
a152561c
WS
201 ControlType *control = (ControlType *)GetObjectPtr();
202 if(control==NULL)
203 return 0;
bdb54365 204 uint16_t ret;
a152561c 205 CtlGetSliderValues(control, NULL, NULL, &ret, NULL);
bdb54365 206 return ret;
ffecfa5a
JS
207}
208
209int wxSlider::GetValue() const
210{
a152561c
WS
211 ControlType *control = (ControlType *)GetObjectPtr();
212 if(control==NULL)
213 return 0;
bdb54365 214 uint16_t ret;
a152561c 215 CtlGetSliderValues(control, NULL, NULL, NULL, &ret);
01526d4f 216 return ValueInvertOrNot(ret);
ffecfa5a
JS
217}
218
219void wxSlider::SetValue(int value)
220{
01526d4f 221 SetIntValue(ValueInvertOrNot(value));
8be10866 222 m_oldValue = m_oldPos = value;
ffecfa5a
JS
223}
224
ffecfa5a
JS
225wxSize wxSlider::DoGetBestSize() const
226{
721a9626
WS
227 // 15 is taken as used in one of official samples
228 // 45 is dummy height tripled, any idea what's better ?
229 return wxSize(45,15);
ffecfa5a
JS
230}
231
232
721a9626 233void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
ffecfa5a 234{
721a9626 235 // unsupported feature
ffecfa5a
JS
236}
237
721a9626 238void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos))
ffecfa5a 239{
721a9626 240 // unsupported feature
ffecfa5a
JS
241}
242
243void wxSlider::SetPageSize(int pageSize)
244{
721a9626
WS
245 ControlType *control = (ControlType *)GetObjectPtr();
246 if(control==NULL)
247 return;
248 uint16_t val = pageSize;
249 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
ffecfa5a
JS
250}
251
ffecfa5a
JS
252void wxSlider::ClearSel()
253{
721a9626 254 // unsupported feature
ffecfa5a
JS
255}
256
257void wxSlider::ClearTicks()
258{
721a9626 259 // unsupported feature
ffecfa5a
JS
260}
261
262void wxSlider::SetLineSize(int lineSize)
263{
721a9626 264 m_lineSize = lineSize;
ffecfa5a
JS
265}
266
267int wxSlider::GetLineSize() const
268{
721a9626 269 return m_lineSize;
ffecfa5a
JS
270}
271
272int wxSlider::GetSelEnd() const
273{
721a9626
WS
274 // unsupported feature
275 return GetValue();
ffecfa5a
JS
276}
277
278int wxSlider::GetSelStart() const
279{
721a9626
WS
280 // unsupported feature
281 return GetValue();
ffecfa5a
JS
282}
283
721a9626 284void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
ffecfa5a 285{
721a9626 286 // unsupported feature
ffecfa5a
JS
287}
288
721a9626 289void wxSlider::SetThumbLength(int WXUNUSED(len))
ffecfa5a 290{
721a9626 291 // unsupported feature
ffecfa5a
JS
292}
293
294int wxSlider::GetThumbLength() const
295{
721a9626 296 // unsupported feature
ffecfa5a
JS
297 return 0;
298}
299
721a9626
WS
300int wxSlider::GetTickFreq() const
301{
302 // unsupported feature
303 return GetPageSize();
304}
305
306void wxSlider::SetTick(int WXUNUSED(tickPos))
ffecfa5a 307{
721a9626 308 // unsupported feature
ffecfa5a
JS
309}
310
9a727a3b
WS
311// ----------------------------------------------------------------------------
312// helpers
313// ----------------------------------------------------------------------------
314
315bool wxSlider::SendUpdatedEvent()
316{
721a9626
WS
317 m_oldPos = GetValue();
318
8be10866 319 // first thumb event
721a9626
WS
320 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
321 eventWxTrack.SetPosition(m_oldPos);
322 eventWxTrack.SetEventObject(this);
937013e0 323 bool handled = HandleWindowEvent(eventWxTrack);
8be10866
WS
324
325 // then slider event if position changed
326 if( m_oldValue != m_oldPos )
327 {
328 m_oldValue = m_oldPos;
329 wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
330 event.SetEventObject(this);
331 event.SetInt(m_oldPos);
332 return ProcessCommand(event);
333 }
721a9626 334
8be10866 335 return handled;
9a727a3b
WS
336}
337
20bc5ad8 338bool wxSlider::SendScrollEvent(WXEVENTPTR event)
721a9626 339{
20bc5ad8
WS
340 const EventType* palmEvent = (EventType*)event;
341 int newPos = ValueInvertOrNot(palmEvent->data.ctlRepeat.value);
8be10866 342 if ( newPos == m_oldPos )
721a9626 343 {
8be10866 344 // nothing changed since last event
721a9626
WS
345 return false;
346 }
347
348 m_oldPos = newPos;
349
350 // first track event
8be10866
WS
351 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
352 eventWx.SetPosition(newPos);
353 eventWx.SetEventObject(this);
937013e0 354 return HandleWindowEvent(eventWx);
721a9626
WS
355}
356
ffecfa5a
JS
357void wxSlider::Command (wxCommandEvent & event)
358{
359}
360
ffecfa5a 361#endif // wxUSE_SLIDER