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