X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..33f4afdbc08a2a8b8438420aa9d16aadee0bacc2:/src/osx/cocoa/scrolbar.mm diff --git a/src/osx/cocoa/scrolbar.mm b/src/osx/cocoa/scrolbar.mm index 5571d10c95..74168cf6e0 100644 --- a/src/osx/cocoa/scrolbar.mm +++ b/src/osx/cocoa/scrolbar.mm @@ -23,12 +23,11 @@ @interface wxNSScroller : NSScroller { - wxWidgetImpl* impl; + WXCOCOAIMPL_COMMON_MEMBERS } -- (void)setImplementation: (wxWidgetImpl *) theImplementation; -- (wxWidgetImpl*) implementation; -- (BOOL) isFlipped; +WXCOCOAIMPL_COMMON_INTERFACE + - (void) clickedAction: (id) sender; @end @@ -44,29 +43,61 @@ return self; } +WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN + +// 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) clickedAction: (id) sender { if ( impl ) { + wxEventType scrollEvent = wxEVT_NULL; + switch ([self 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*) impl->GetWXPeer(); if ( wxpeer ) - wxpeer->HandleClicked(0); + wxpeer->TriggerScrollEvent(scrollEvent); } } -- (void)setImplementation: (wxWidgetImpl *) theImplementation +-(void)mouseDown:(NSEvent *)event { - impl = theImplementation; -} + if ( !impl->DoHandleMouseEvent(event) ) + [super mouseDown:event]; -- (wxWidgetImpl*) implementation -{ - return impl ; -} - -- (BOOL) isFlipped -{ - return YES; + // send a release event in case we've been tracking the thumb + NSScrollerPart hit = [self hitPart]; + if ( impl && (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE); + } } @end @@ -76,11 +107,12 @@ class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl public : wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w ) { + m_maximum = 1; } void SetMaximum(wxInt32 v) { - m_maximum = v; + m_maximum = (v == 0) ? 1 : v; } void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) @@ -99,6 +131,11 @@ public : { return [(wxNSScroller*) m_osxView floatValue] * m_maximum; } + + wxInt32 GetMaximum() const + { + return m_maximum; + } protected: wxInt32 m_maximum; }; @@ -111,13 +148,11 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, long style, long extraStyle) { - NSView* sv = (wxpeer->GetParent()->GetHandle() ); - NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r]; - [sv addSubview:v]; wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v ); [v setImplementation:c]; + [v setEnabled:YES]; return c; }