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