]>
Commit | Line | Data |
---|---|---|
dbeddfb9 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/cocoa/slider.mm | |
3 | // Purpose: wxSlider | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
dbeddfb9 SC |
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 | { | |
dbeddfb9 | 20 | } |
dbeddfb9 SC |
21 | @end |
22 | ||
23 | @implementation wxNSSlider | |
24 | ||
4dd9fdf8 | 25 | + (void)initialize |
dbeddfb9 | 26 | { |
4dd9fdf8 | 27 | static BOOL initialized = NO; |
03647350 | 28 | if (!initialized) |
4dd9fdf8 SC |
29 | { |
30 | initialized = YES; | |
31 | wxOSXCocoaClassAddWXMethods(self); | |
32 | } | |
dbeddfb9 SC |
33 | } |
34 | ||
4dd9fdf8 SC |
35 | @end |
36 | ||
37 | class wxSliderCocoaImpl : public wxWidgetCocoaImpl | |
38 | { | |
39 | public : | |
40 | wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) : | |
41 | wxWidgetCocoaImpl(peer, w) | |
42 | { | |
43 | } | |
03647350 | 44 | |
4dd9fdf8 SC |
45 | ~wxSliderCocoaImpl() |
46 | { | |
47 | } | |
48 | ||
e32090ba | 49 | virtual void controlAction(WXWidget slf, void* _cmd, void *sender); |
4dd9fdf8 SC |
50 | virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd); |
51 | }; | |
19c7ac3d | 52 | |
03647350 | 53 | // we will have a mouseDown, then in the native |
19c7ac3d SC |
54 | // implementation of mouseDown the tracking code |
55 | // is calling clickedAction, therefore we wire this | |
03647350 | 56 | // to thumbtrack and only after super mouseDown |
19c7ac3d SC |
57 | // returns we will call the thumbrelease |
58 | ||
d8207702 | 59 | void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) |
dbeddfb9 | 60 | { |
4dd9fdf8 SC |
61 | wxWindow* wxpeer = (wxWindow*) GetWXPeer(); |
62 | if ( wxpeer ) | |
63 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK); | |
dbeddfb9 SC |
64 | } |
65 | ||
4dd9fdf8 | 66 | void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) |
19c7ac3d | 67 | { |
4dd9fdf8 | 68 | wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd); |
03647350 | 69 | |
4dd9fdf8 | 70 | if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 ) |
19c7ac3d | 71 | { |
4dd9fdf8 | 72 | wxWindow* wxpeer = (wxWindow*) GetWXPeer(); |
19c7ac3d | 73 | if ( wxpeer ) |
04236b74 | 74 | wxpeer->OSXHandleClicked(0); |
19c7ac3d SC |
75 | } |
76 | } | |
dbeddfb9 | 77 | |
4dd9fdf8 | 78 | |
dbeddfb9 | 79 | |
03647350 VZ |
80 | wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, |
81 | wxWindowMac* WXUNUSED(parent), | |
82 | wxWindowID WXUNUSED(id), | |
dbeddfb9 SC |
83 | wxInt32 value, |
84 | wxInt32 minimum, | |
85 | wxInt32 maximum, | |
03647350 | 86 | const wxPoint& pos, |
dbeddfb9 | 87 | const wxSize& size, |
03647350 | 88 | long style, |
d8207702 | 89 | long WXUNUSED(extraStyle)) |
dbeddfb9 | 90 | { |
dbeddfb9 | 91 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
f599a415 SC |
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 | } | |
dbeddfb9 SC |
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; | |
03647350 | 110 | |
dbeddfb9 SC |
111 | [v setNumberOfTickMarks:tickMarks]; |
112 | [v setTickMarkPosition:NSTickMarkBelow]; | |
113 | } | |
114 | ||
115 | [v setMinValue: minimum]; | |
116 | [v setMaxValue: maximum]; | |
117 | [v setFloatValue: (double) value]; | |
4dd9fdf8 | 118 | wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v ); |
dbeddfb9 SC |
119 | return c; |
120 | } | |
121 | ||
122 | #endif // wxUSE_SLIDER |