]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/slider.cpp
implemented Freeze/Thaw() (patch 922156)
[wxWidgets.git] / src / mac / carbon / slider.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: slider.cpp
3// Purpose: wxSlider
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "slider.h"
14#endif
15
16#include "wx/slider.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5 18
2f1ae414 19#if !USE_SHARED_LIBRARY
e9576ca5
SC
20IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
21
22BEGIN_EVENT_TABLE(wxSlider, wxControl)
23END_EVENT_TABLE()
2f1ae414 24#endif
e9576ca5 25
9453cf2b 26 // The dimensions of the different styles of sliders (From Aqua document)
e40298d5
JS
27#define wxSLIDER_DIMENSIONACROSS 15
28#define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24
29#define wxSLIDER_DIMENSIONACROSS_ARROW 18
9453cf2b 30
e40298d5
JS
31// Distance between slider and text
32#define wxSLIDER_BORDERTEXT 5
9453cf2b 33
e40298d5
JS
34/* NB! The default orientation for a slider is horizontal however if the user specifies
35 * some slider styles but dosen't specify the orientation we have to assume he wants a
36 * horizontal one. Therefore in this file when testing for the sliders orientation
37 * vertical is tested for if this is not set then we use the horizontal one
38 * eg. if(GetWindowStyle() & wxSL_VERTICAL) {} else { horizontal case }>
39 */
40
41 // Slider
42 wxSlider::wxSlider()
e9576ca5 43{
e40298d5
JS
44 m_pageSize = 1;
45 m_lineSize = 1;
46 m_rangeMax = 0;
47 m_rangeMin = 0;
48 m_tickFreq = 0;
e9576ca5
SC
49}
50
519cb848
SC
51extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
52
e9576ca5 53bool wxSlider::Create(wxWindow *parent, wxWindowID id,
e40298d5
JS
54 int value, int minValue, int maxValue,
55 const wxPoint& pos,
56 const wxSize& size, long style,
57 const wxValidator& validator,
58 const wxString& name)
e9576ca5 59{
facd6764
SC
60 m_macIsUserPane = FALSE ;
61
b45ed7a2
VZ
62 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
63 return false;
64
e40298d5
JS
65 SInt16 procID;
66
67 m_macMinimumStatic = NULL ;
68 m_macMaximumStatic = NULL ;
69 m_macValueStatic = NULL ;
70
71
72 m_lineSize = 1;
73 m_tickFreq = 0;
74
75 m_rangeMax = maxValue;
76 m_rangeMin = minValue;
77
78 m_pageSize = (int)((maxValue-minValue)/10);
79
facd6764 80 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
e40298d5
JS
81
82 procID = kControlSliderProc + kControlSliderLiveFeedback;
83 if(style & wxSL_AUTOTICKS) {
84 procID += kControlSliderHasTickMarks;
03e11df5 85 }
e40298d5
JS
86
87
facd6764 88 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, "\p", true,
e40298d5
JS
89 value, minValue, maxValue, procID, (long) this);
90
facd6764 91 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5 92
facd6764
SC
93 ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ;
94
e40298d5
JS
95 if(style & wxSL_VERTICAL) {
96 SetSizeHints(10, -1, 10, -1); // Forces SetSize to use the proper width
97 }
98 else {
99 SetSizeHints(-1, 10, -1, 10); // Forces SetSize to use the proper height
100 }
101 // NB! SetSizeHints is overloaded by wxSlider and will substitute 10 with the
102 // proper dimensions, it also means other people cannot bugger the slider with
103 // other values
104
facd6764
SC
105 if(style & wxSL_LABELS)
106 {
107 m_macMinimumStatic = new wxStaticText( parent, -1, wxEmptyString );
108 m_macMaximumStatic = new wxStaticText( parent, -1, wxEmptyString );
109 m_macValueStatic = new wxStaticText( parent, -1, wxEmptyString );
110 SetRange(minValue, maxValue);
111 SetValue(value);
112 }
113
114 MacPostControlCreate(pos,size) ;
e40298d5
JS
115
116 return true;
e9576ca5
SC
117}
118
119wxSlider::~wxSlider()
120{
facd6764
SC
121 delete m_macMinimumStatic ;
122 delete m_macMaximumStatic ;
123 delete m_macValueStatic ;
e9576ca5
SC
124}
125
126int wxSlider::GetValue() const
127{
facd6764 128 return GetControl32BitValue( (ControlRef) m_macControl) ;
e9576ca5
SC
129}
130
131void wxSlider::SetValue(int value)
132{
e40298d5 133 wxString valuestring ;
427ff662 134 valuestring.Printf( wxT("%d") , value ) ;
e40298d5
JS
135 if ( m_macValueStatic )
136 m_macValueStatic->SetLabel( valuestring ) ;
facd6764 137 SetControl32BitValue( (ControlRef) m_macControl , value ) ;
e9576ca5
SC
138}
139
140void wxSlider::SetRange(int minValue, int maxValue)
141{
e40298d5
JS
142 wxString value;
143
144 m_rangeMin = minValue;
145 m_rangeMax = maxValue;
146
facd6764
SC
147 SetControl32BitMinimum( (ControlRef) m_macControl, m_rangeMin);
148 SetControl32BitMaximum( (ControlRef) m_macControl, m_rangeMax);
e40298d5
JS
149
150 if(m_macMinimumStatic) {
427ff662 151 value.Printf(wxT("%d"), m_rangeMin);
e40298d5
JS
152 m_macMinimumStatic->SetLabel(value);
153 }
154 if(m_macMaximumStatic) {
427ff662 155 value.Printf(wxT("%d"), m_rangeMax);
e40298d5
JS
156 m_macMaximumStatic->SetLabel(value);
157 }
158 SetValue(m_rangeMin);
e9576ca5
SC
159}
160
161// For trackbars only
162void wxSlider::SetTickFreq(int n, int pos)
163{
164 // TODO
165 m_tickFreq = n;
166}
167
168void wxSlider::SetPageSize(int pageSize)
169{
170 // TODO
171 m_pageSize = pageSize;
172}
173
174int wxSlider::GetPageSize() const
175{
176 return m_pageSize;
177}
178
179void wxSlider::ClearSel()
180{
181 // TODO
182}
183
184void wxSlider::ClearTicks()
185{
186 // TODO
187}
188
189void wxSlider::SetLineSize(int lineSize)
190{
191 m_lineSize = lineSize;
192 // TODO
193}
194
195int wxSlider::GetLineSize() const
196{
197 // TODO
198 return 0;
199}
200
201int wxSlider::GetSelEnd() const
202{
203 // TODO
204 return 0;
205}
206
207int wxSlider::GetSelStart() const
208{
209 // TODO
210 return 0;
211}
212
213void wxSlider::SetSelection(int minPos, int maxPos)
214{
215 // TODO
216}
217
218void wxSlider::SetThumbLength(int len)
219{
220 // TODO
221}
222
223int wxSlider::GetThumbLength() const
224{
225 // TODO
226 return 0;
227}
228
229void wxSlider::SetTick(int tickPos)
230{
231 // TODO
232}
233
234void wxSlider::Command (wxCommandEvent & event)
235{
e40298d5
JS
236 SetValue (event.GetInt());
237 ProcessCommand (event);
e9576ca5
SC
238}
239
cea9c546 240void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bool mouseStillDown )
519cb848 241{
facd6764 242 SInt16 value = ::GetControl32BitValue( (ControlRef) m_macControl ) ;
e40298d5
JS
243
244 SetValue( value ) ;
245
cea9c546
SC
246 wxEventType scrollEvent = wxEVT_NULL ;
247
248 if ( mouseStillDown )
249 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
250 else
251 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
252
253 wxScrollEvent event(scrollEvent, m_windowId);
e40298d5
JS
254 event.SetPosition(value);
255 event.SetEventObject( this );
256 GetEventHandler()->ProcessEvent(event);
257
258 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId );
259 cevent.SetInt( value );
260 cevent.SetEventObject( this );
261
262 GetEventHandler()->ProcessEvent( cevent );
263}
264
265/* This is overloaded in wxSlider so that the proper width/height will always be used
266* for the slider different values would cause redrawing and mouse detection problems */
267void wxSlider::SetSizeHints( int minW, int minH,
268 int maxW , int maxH ,
269 int incW , int incH )
270{
271 wxSize size = GetBestSize();
272
273 if(GetWindowStyle() & wxSL_VERTICAL) {
274 wxWindow::SetSizeHints(size.x, minH, size.x, maxH, incW, incH);
275 }
276 else {
277 wxWindow::SetSizeHints(minW, size.y, maxW, size.y, incW, incH);
278 }
519cb848 279}
9453cf2b 280
e40298d5
JS
281wxSize wxSlider::DoGetBestSize() const
282{
283 wxSize size;
284 int textwidth, textheight;
285
286 if(GetWindowStyle() & wxSL_LABELS)
287 {
288 wxString text;
289 int ht, wd;
290
291 // Get maximum text label width and height
427ff662 292 text.Printf(wxT("%d"), m_rangeMin);
e40298d5 293 GetTextExtent(text, &textwidth, &textheight);
427ff662 294 text.Printf(wxT("%d"), m_rangeMax);
e40298d5
JS
295 GetTextExtent(text, &wd, &ht);
296 if(ht > textheight) {
297 textheight = ht;
298 }
299 if (wd > textwidth) {
300 textwidth = wd;
301 }
302 }
303
304 if(GetWindowStyle() & wxSL_VERTICAL)
305 {
306 if(GetWindowStyle() & wxSL_AUTOTICKS) {
307 size.x = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
308 }
309 else {
310 size.x = wxSLIDER_DIMENSIONACROSS_ARROW;
311 }
312 if(GetWindowStyle() & wxSL_LABELS) {
313 size.x += textwidth + wxSLIDER_BORDERTEXT;
314 }
315 size.y = 150;
316 }
317 else
318 {
319 if(GetWindowStyle() & wxSL_AUTOTICKS) {
320 size.y = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
321 }
322 else {
323 size.y = wxSLIDER_DIMENSIONACROSS_ARROW;
324 }
325 if(GetWindowStyle() & wxSL_LABELS) {
326 size.y += textheight + wxSLIDER_BORDERTEXT;
327 }
328 size.x = 150;
329 }
330 return size;
331}
332
facd6764 333void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags)
327788ac 334{
e40298d5
JS
335 int xborder, yborder;
336 int minValWidth, maxValWidth, textwidth, textheight;
337 int sliderBreadth;
338
339 xborder = yborder = 0;
340
341 if (GetWindowStyle() & wxSL_LABELS)
342 {
343 wxString text;
344 int ht;
345
346 // Get maximum text label width and height
427ff662 347 text.Printf(wxT("%d"), m_rangeMin);
e40298d5 348 GetTextExtent(text, &minValWidth, &textheight);
427ff662 349 text.Printf(wxT("%d"), m_rangeMax);
e40298d5
JS
350 GetTextExtent(text, &maxValWidth, &ht);
351 if(ht > textheight) {
352 textheight = ht;
353 }
354 textwidth = (minValWidth > maxValWidth ? minValWidth : maxValWidth);
355
356 xborder = textwidth + wxSLIDER_BORDERTEXT;
357 yborder = textheight + wxSLIDER_BORDERTEXT;
358
359 // Get slider breadth
360 if(GetWindowStyle() & wxSL_AUTOTICKS) {
361 sliderBreadth = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
362 }
363 else {
364 sliderBreadth = wxSLIDER_DIMENSIONACROSS_ARROW;
365 }
366
367 if(GetWindowStyle() & wxSL_VERTICAL)
368 {
facd6764
SC
369
370 if ( m_macMinimumStatic )
371 m_macMinimumStatic->Move(x + sliderBreadth + wxSLIDER_BORDERTEXT,
372 y + h - yborder - textheight);
373 if ( m_macMaximumStatic )
374 m_macMaximumStatic->Move(x + sliderBreadth + wxSLIDER_BORDERTEXT, y + 0);
375 if ( m_macValueStatic )
376 m_macValueStatic->Move(0, y + h - textheight);
377 h = h - yborder ;
e40298d5
JS
378 }
379 else
380 {
facd6764
SC
381 if ( m_macMinimumStatic )
382 m_macMinimumStatic->Move(x + 0, y + sliderBreadth + wxSLIDER_BORDERTEXT);
383 if ( m_macMaximumStatic )
384 m_macMaximumStatic->Move(x + w - xborder - maxValWidth / 2,
385 y + sliderBreadth + wxSLIDER_BORDERTEXT);
386 if ( m_macValueStatic )
387 m_macValueStatic->Move(x + w - textwidth, y + 0);
388 w = w - xborder ;
e40298d5
JS
389 }
390 }
391
facd6764 392 wxControl::DoSetSize( x, y , w , h ,sizeFlags ) ;
327788ac
SC
393}
394
eb22f2a6
GD
395void wxSlider::DoMoveWindow(int x, int y, int width, int height)
396{
327788ac 397 wxControl::DoMoveWindow(x,y,width,height) ;
eb22f2a6 398}