]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/slider.cpp
Use parents client size and origin in placement of controls.
[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
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"));
8be10866 123
a152561c
WS
124 if(!wxControl::Create(parent, id, pos, size, style, validator, name))
125 return false;
126
ba889513
WS
127 FormType* form = GetParentForm();
128 if(form==NULL)
129 return false;
bdb54365 130
8be10866 131 m_oldValue = m_oldPos = value;
721a9626 132
be4e4e27
WS
133 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
134 y = pos.y == wxDefaultCoord ? 0 : pos.y,
135 w = size.x == wxDefaultCoord ? 1 : size.x,
136 h = size.y == wxDefaultCoord ? 1 : size.y;
137
138 AdjustForParentClientOrigin(x, y);
139
bdb54365
WS
140 SliderControlType *slider = CtlNewSliderControl (
141 (void **)&form,
ba889513 142 GetId(),
bdb54365
WS
143 feedbackSliderCtl,
144 NULL,
145 0,
146 0,
be4e4e27
WS
147 x,
148 y,
149 w,
150 h,
bdb54365
WS
151 minValue,
152 maxValue,
153 1,
154 value
155 );
156
ba889513 157 if(slider==NULL)
bdb54365
WS
158 return false;
159
be4e4e27 160 SetInitialBestSize(size);
bdb54365
WS
161 Show();
162 return true;
ffecfa5a
JS
163}
164
bdb54365 165wxSlider::~wxSlider()
ffecfa5a 166{
ffecfa5a
JS
167}
168
bdb54365
WS
169int wxSlider::GetMin() const
170{
a152561c
WS
171 ControlType *control = (ControlType *)GetObjectPtr();
172 if(control==NULL)
173 return 0;
bdb54365 174 uint16_t ret;
a152561c 175 CtlGetSliderValues(control, &ret, NULL, NULL, NULL);
bdb54365
WS
176 return ret;
177}
178
179int wxSlider::GetMax() 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, NULL, &ret, NULL, NULL);
bdb54365
WS
186 return ret;
187}
188
189int wxSlider::GetPageSize() const
ffecfa5a 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, NULL, &ret, NULL);
bdb54365 196 return ret;
ffecfa5a
JS
197}
198
199int wxSlider::GetValue() const
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, NULL, &ret);
bdb54365 206 return ret;
ffecfa5a
JS
207}
208
209void wxSlider::SetValue(int value)
210{
ba889513 211 SetIntValue(value);
8be10866 212 m_oldValue = m_oldPos = value;
ffecfa5a
JS
213}
214
ffecfa5a
JS
215wxSize wxSlider::DoGetBestSize() const
216{
721a9626
WS
217 // 15 is taken as used in one of official samples
218 // 45 is dummy height tripled, any idea what's better ?
219 return wxSize(45,15);
ffecfa5a
JS
220}
221
222
721a9626 223void wxSlider::SetRange(int WXUNUSED(minValue), int WXUNUSED(maxValue))
ffecfa5a 224{
721a9626 225 // unsupported feature
ffecfa5a
JS
226}
227
721a9626 228void wxSlider::SetTickFreq(int WXUNUSED(n), int WXUNUSED(pos))
ffecfa5a 229{
721a9626 230 // unsupported feature
ffecfa5a
JS
231}
232
233void wxSlider::SetPageSize(int pageSize)
234{
721a9626
WS
235 ControlType *control = (ControlType *)GetObjectPtr();
236 if(control==NULL)
237 return;
238 uint16_t val = pageSize;
239 CtlSetSliderValues(control, NULL, NULL, &val, NULL);
ffecfa5a
JS
240}
241
ffecfa5a
JS
242void wxSlider::ClearSel()
243{
721a9626 244 // unsupported feature
ffecfa5a
JS
245}
246
247void wxSlider::ClearTicks()
248{
721a9626 249 // unsupported feature
ffecfa5a
JS
250}
251
252void wxSlider::SetLineSize(int lineSize)
253{
721a9626 254 m_lineSize = lineSize;
ffecfa5a
JS
255}
256
257int wxSlider::GetLineSize() const
258{
721a9626 259 return m_lineSize;
ffecfa5a
JS
260}
261
262int wxSlider::GetSelEnd() const
263{
721a9626
WS
264 // unsupported feature
265 return GetValue();
ffecfa5a
JS
266}
267
268int wxSlider::GetSelStart() const
269{
721a9626
WS
270 // unsupported feature
271 return GetValue();
ffecfa5a
JS
272}
273
721a9626 274void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
ffecfa5a 275{
721a9626 276 // unsupported feature
ffecfa5a
JS
277}
278
721a9626 279void wxSlider::SetThumbLength(int WXUNUSED(len))
ffecfa5a 280{
721a9626 281 // unsupported feature
ffecfa5a
JS
282}
283
284int wxSlider::GetThumbLength() const
285{
721a9626 286 // unsupported feature
ffecfa5a
JS
287 return 0;
288}
289
721a9626
WS
290int wxSlider::GetTickFreq() const
291{
292 // unsupported feature
293 return GetPageSize();
294}
295
296void wxSlider::SetTick(int WXUNUSED(tickPos))
ffecfa5a 297{
721a9626 298 // unsupported feature
ffecfa5a
JS
299}
300
9a727a3b
WS
301// ----------------------------------------------------------------------------
302// helpers
303// ----------------------------------------------------------------------------
304
305bool wxSlider::SendUpdatedEvent()
306{
721a9626
WS
307 m_oldPos = GetValue();
308
8be10866 309 // first thumb event
721a9626
WS
310 wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
311 eventWxTrack.SetPosition(m_oldPos);
312 eventWxTrack.SetEventObject(this);
8be10866
WS
313 bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
314
315 // then slider event if position changed
316 if( m_oldValue != m_oldPos )
317 {
318 m_oldValue = m_oldPos;
319 wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
320 event.SetEventObject(this);
321 event.SetInt(m_oldPos);
322 return ProcessCommand(event);
323 }
721a9626 324
8be10866 325 return handled;
9a727a3b
WS
326}
327
721a9626
WS
328bool wxSlider::SendScrollEvent(EventType* event)
329{
330 wxEventType scrollEvent;
331 int newPos = event->data.ctlRepeat.value;
8be10866 332 if ( newPos == m_oldPos )
721a9626 333 {
8be10866 334 // nothing changed since last event
721a9626
WS
335 return false;
336 }
337
338 m_oldPos = newPos;
339
340 // first track event
8be10866
WS
341 wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
342 eventWx.SetPosition(newPos);
343 eventWx.SetEventObject(this);
344 return GetEventHandler()->ProcessEvent(eventWx);
721a9626
WS
345}
346
ffecfa5a
JS
347void wxSlider::Command (wxCommandEvent & event)
348{
349}
350
ffecfa5a 351#endif // wxUSE_SLIDER