]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/slider.mm
No changes, just use wxRecursionGuard instead of manual boolean flag.
[wxWidgets.git] / src / osx / cocoa / slider.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/slider.mm
3 // Purpose: wxSlider
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_SLIDER
14
15 #include "wx/slider.h"
16 #include "wx/osx/private.h"
17
18 @interface wxNSSlider : NSSlider
19 {
20 }
21 @end
22
23 @implementation wxNSSlider
24
25 + (void)initialize
26 {
27 static BOOL initialized = NO;
28 if (!initialized)
29 {
30 initialized = YES;
31 wxOSXCocoaClassAddWXMethods(self);
32 }
33 }
34
35 @end
36
37 class wxSliderCocoaImpl : public wxWidgetCocoaImpl
38 {
39 public :
40 wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
41 wxWidgetCocoaImpl(peer, w)
42 {
43 }
44
45 ~wxSliderCocoaImpl()
46 {
47 }
48
49 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
50 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
51 };
52
53 // we will have a mouseDown, then in the native
54 // implementation of mouseDown the tracking code
55 // is calling clickedAction, therefore we wire this
56 // to thumbtrack and only after super mouseDown
57 // returns we will call the thumbrelease
58
59 void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
60 {
61 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
62 if ( wxpeer )
63 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
64 }
65
66 void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
67 {
68 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
69
70 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
71 {
72 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
73 if ( wxpeer )
74 wxpeer->OSXHandleClicked(0);
75 }
76 }
77
78
79
80 wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
81 wxWindowMac* WXUNUSED(parent),
82 wxWindowID WXUNUSED(id),
83 wxInt32 value,
84 wxInt32 minimum,
85 wxInt32 maximum,
86 const wxPoint& pos,
87 const wxSize& size,
88 long style,
89 long WXUNUSED(extraStyle))
90 {
91 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
92 if ( size == wxDefaultSize )
93 {
94 if ( style & wxSL_VERTICAL )
95 r.size.height = r.size.width * 2;
96 else
97 r.size.width = r.size.height * 2;
98 }
99 wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
100
101 int tickMarks = 0;
102 if ( style & wxSL_AUTOTICKS )
103 {
104 tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
105
106 // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
107 // it to a UInt16
108 while (tickMarks > 20)
109 tickMarks /= 5;
110
111 [v setNumberOfTickMarks:tickMarks];
112 [v setTickMarkPosition:NSTickMarkBelow];
113 }
114
115 [v setMinValue: minimum];
116 [v setMaxValue: maximum];
117 [v setFloatValue: (double) value];
118 wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
119 return c;
120 }
121
122 #endif // wxUSE_SLIDER