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
21 WXCOCOAIMPL_COMMON_MEMBERS
24 WXCOCOAIMPL_COMMON_INTERFACE
26 - (void) clickedAction: (id) sender;
30 @implementation wxNSSlider
32 - (id)initWithFrame:(NSRect)frame
34 [super initWithFrame:frame];
36 [self setTarget: self];
37 [self setAction: @selector(clickedAction:)];
41 WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
43 // we will have a mouseDown, then in the native
44 // implementation of mouseDown the tracking code
45 // is calling clickedAction, therefore we wire this
46 // to thumbtrack and only after super mouseDown
47 // returns we will call the thumbrelease
49 - (void) clickedAction: (id) sender
53 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
55 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
59 -(void)mouseDown:(NSEvent *)event
61 if ( !impl->DoHandleMouseEvent(event) )
62 [super mouseDown:event];
66 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
68 wxpeer->OSXHandleClicked(0);
74 wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
85 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
86 wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
89 if ( style & wxSL_AUTOTICKS )
91 tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
93 // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
95 while (tickMarks > 20)
98 [v setNumberOfTickMarks:tickMarks];
99 [v setTickMarkPosition:NSTickMarkBelow];
102 [v setMinValue: minimum];
103 [v setMaxValue: maximum];
104 [v setFloatValue: (double) value];
105 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
106 [v setImplementation:c];
110 #endif // wxUSE_SLIDER