X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/54f11060867c4c97ebbe7954353f5c311262fc4b..f8d0234d39c66f3d1d7fc2346562cb96c8c7be20:/src/osx/cocoa/scrolbar.mm diff --git a/src/osx/cocoa/scrolbar.mm b/src/osx/cocoa/scrolbar.mm index 804c5df533..3cac87abdf 100644 --- a/src/osx/cocoa/scrolbar.mm +++ b/src/osx/cocoa/scrolbar.mm @@ -23,38 +23,21 @@ @interface wxNSScroller : NSScroller { - WXCOCOAIMPL_COMMON_MEMBERS } - -WXCOCOAIMPL_COMMON_INTERFACE - - - (void) clickedAction: (id) sender; - @end @implementation wxNSScroller -- (id)initWithFrame:(NSRect)frame -{ - [super initWithFrame:frame]; - impl = NULL; - [self setTarget: self]; - [self setAction: @selector(clickedAction:)]; - return self; -} - -- (void) clickedAction: (id) sender ++ (void)initialize { - if ( impl ) + static BOOL initialized = NO; + if (!initialized) { - wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); - if ( wxpeer ) - wxpeer->HandleClicked(0); + initialized = YES; + wxOSXCocoaClassAddWXMethods(self); } } -WXCOCOAIMPL_COMMON_IMPLEMENTATION - @end class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl @@ -73,7 +56,7 @@ public : void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) { double v = ((double) value)/m_maximum; - double t = ((double) thumbSize)/m_maximum; + double t = ((double) thumbSize)/(m_maximum+thumbSize); #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t]; #else @@ -82,14 +65,76 @@ public : #endif } - wxInt32 GetValue() const + virtual wxInt32 GetValue() const { return [(wxNSScroller*) m_osxView floatValue] * m_maximum; } + + virtual wxInt32 GetMaximum() const + { + return m_maximum; + } + + virtual void controlAction(WXWidget slf, void* _cmd, void *sender); + virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd); protected: wxInt32 m_maximum; }; +// 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 + +void wxOSXScrollBarCocoaImpl::controlAction( WXWidget slf, void *_cmd, void *sender) +{ + wxEventType scrollEvent = wxEVT_NULL; + switch ([(NSScroller*)m_osxView hitPart]) + { + case NSScrollerIncrementLine: + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + case NSScrollerIncrementPage: + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + case NSScrollerDecrementLine: + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + case NSScrollerDecrementPage: + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + case NSScrollerKnob: + case NSScrollerKnobSlot: + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + case NSScrollerNoPart: + default: + return; + } + + wxWindow* wxpeer = (wxWindow*) GetWXPeer(); + if ( wxpeer ) + wxpeer->TriggerScrollEvent(scrollEvent); +} + +void wxOSXScrollBarCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) +{ + wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd); + + // send a release event in case we've been tracking the thumb + if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 ) + { + NSScrollerPart hit = [(NSScroller*)m_osxView hitPart]; + if ( (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) ) + { + wxWindow* wxpeer = (wxWindow*) GetWXPeer(); + if ( wxpeer ) + wxpeer->OSXHandleClicked(0); + } + } +} + wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, @@ -102,7 +147,6 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r]; wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v ); - [v setImplementation:c]; [v setEnabled:YES]; return c; }