X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..bbfd45484113ff0bafcd0007a4b6faecc7909561:/src/osx/cocoa/slider.mm?ds=sidebyside diff --git a/src/osx/cocoa/slider.mm b/src/osx/cocoa/slider.mm index a80fb434d6..08327c438f 100644 --- a/src/osx/cocoa/slider.mm +++ b/src/osx/cocoa/slider.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -18,67 +18,77 @@ @interface wxNSSlider : NSSlider { - wxWidgetImpl* impl; } - -- (void)setImplementation: (wxWidgetImpl *) theImplementation; -- (wxWidgetImpl*) implementation; -- (BOOL) isFlipped; - - (void) clickedAction: (id) sender; - @end @implementation wxNSSlider -- (id)initWithFrame:(NSRect)frame ++ (void)initialize { - [super initWithFrame:frame]; - impl = NULL; - [self setTarget: self]; - [self setAction: @selector(clickedAction:)]; - return self; + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods(self); + } } -- (void) clickedAction: (id) sender +@end + +class wxSliderCocoaImpl : public wxWidgetCocoaImpl { - if ( impl ) +public : + wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) : + wxWidgetCocoaImpl(peer, w) { - wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); - if ( wxpeer ) - wxpeer->HandleClicked(0); } -} -- (void)setImplementation: (wxWidgetImpl *) theImplementation -{ - impl = theImplementation; -} + ~wxSliderCocoaImpl() + { + } + + virtual void controlAction(WXWidget slf, void* _cmd, void *sender); + virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd); +}; + +// we will have a mouseDown, then in the native +// implementation of mouseDown the tracking code +// is calling clickedAction, therefore we wire this +// to thumbtrack and only after super mouseDown +// returns we will call the thumbrelease -- (wxWidgetImpl*) implementation +void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) { - return impl; + wxWindow* wxpeer = (wxWindow*) GetWXPeer(); + if ( wxpeer ) + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK); } -- (BOOL) isFlipped +void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) { - return YES; + wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd); + + if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 ) + { + wxWindow* wxpeer = (wxWindow*) GetWXPeer(); + if ( wxpeer ) + wxpeer->OSXHandleClicked(0); + } } -@end -wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, - wxWindowMac* parent, - wxWindowID id, + +wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), wxInt32 value, wxInt32 minimum, wxInt32 maximum, - const wxPoint& pos, + const wxPoint& pos, const wxSize& size, - long style, - long extraStyle) + long style, + long WXUNUSED(extraStyle)) { - NSView* sv = (wxpeer->GetParent()->GetHandle() ); - NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r]; @@ -91,7 +101,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, // it to a UInt16 while (tickMarks > 20) tickMarks /= 5; - + [v setNumberOfTickMarks:tickMarks]; [v setTickMarkPosition:NSTickMarkBelow]; } @@ -99,9 +109,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, [v setMinValue: minimum]; [v setMaxValue: maximum]; [v setFloatValue: (double) value]; - [sv addSubview:v]; - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); - [v setImplementation:c]; + wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v ); return c; }