1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/slider.mm
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/slider.h"
17 #include "wx/osx/private.h"
19 @interface wxNSSlider : NSSlider
24 @implementation wxNSSlider
28 static BOOL initialized = NO;
32 wxOSXCocoaClassAddWXMethods(self);
38 class wxSliderCocoaImpl : public wxWidgetCocoaImpl
41 wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
42 wxWidgetCocoaImpl(peer, w)
50 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
51 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
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
60 void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
62 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
64 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
67 void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
69 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
71 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
73 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
75 wxpeer->OSXHandleClicked(0);
81 wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
82 wxWindowMac* WXUNUSED(parent),
83 wxWindowID WXUNUSED(id),
90 long WXUNUSED(extraStyle))
92 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
93 wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
96 if ( style & wxSL_AUTOTICKS )
98 tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
100 // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
102 while (tickMarks > 20)
105 [v setNumberOfTickMarks:tickMarks];
106 [v setTickMarkPosition:NSTickMarkBelow];
109 [v setMinValue: minimum];
110 [v setMaxValue: maximum];
111 [v setFloatValue: (double) value];
112 wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
116 #endif // wxUSE_SLIDER