From 094fa9e9ef74842c293baf5e2596e1db173ac2c8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 2 Mar 2013 13:01:57 +0000 Subject: [PATCH] enabling cursor events, fixes #15044 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73595 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 2 + src/osx/cocoa/window.mm | 75 ++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index b759a862b3..949558c335 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -138,6 +138,8 @@ public : virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL); virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent); + void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent); + virtual bool SetupCursor(NSEvent* event); #if !wxOSX_USE_NATIVE_FLIPPED diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 0f8d583014..351bfe1f53 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -462,11 +462,8 @@ bool g_lastButtonWasFakeRight = false ; - (CGFloat)scrollingDeltaY; @end -void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) +void wxWidgetCocoaImpl::SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent* nsEvent) { - int eventType = [nsEvent type]; - UInt32 modifiers = [nsEvent modifierFlags] ; - NSPoint locationInWindow = [nsEvent locationInWindow]; // adjust coordinates for the window of the target view @@ -474,20 +471,30 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve { if ( [nsEvent window] != nil ) locationInWindow = [[nsEvent window] convertBaseToScreen:locationInWindow]; - + if ( [m_osxView window] != nil ) locationInWindow = [[m_osxView window] convertScreenToBase:locationInWindow]; } - + NSPoint locationInView = [m_osxView convertPoint:locationInWindow fromView:nil]; wxPoint locationInViewWX = wxFromNSPoint( m_osxView, locationInView ); + + x = locationInViewWX.x; + y = locationInViewWX.y; + +} + +void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) +{ + int eventType = [nsEvent type]; + UInt32 modifiers = [nsEvent modifierFlags] ; + + SetupCoordinates(wxevent.m_x, wxevent.m_y, nsEvent); // these parameters are not given for all events UInt32 button = [nsEvent buttonNumber]; UInt32 clickCount = 0; - wxevent.m_x = locationInViewWX.x; - wxevent.m_y = locationInViewWX.y; wxevent.m_shiftDown = modifiers & NSShiftKeyMask; wxevent.m_rawControlDown = modifiers & NSControlKeyMask; wxevent.m_altDown = modifiers & NSAlternateKeyMask; @@ -1176,20 +1183,40 @@ void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) void wxWidgetCocoaImpl::cursorUpdate(WX_NSEvent event, WXWidget slf, void *_cmd) { - NSCursor *cursor = (NSCursor*)GetWXPeer()->GetCursor().GetHCURSOR(); - if (cursor == NULL) + if ( !SetupCursor(event) ) { wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd]; - superimpl(slf, (SEL)_cmd, event); + superimpl(slf, (SEL)_cmd, event); } - else + } + +bool wxWidgetCocoaImpl::SetupCursor(WX_NSEvent event) +{ + extern wxCursor gGlobalCursor; + + if ( gGlobalCursor.IsOk() ) { - [cursor set]; + gGlobalCursor.MacInstall(); + return true; + } + else + { + wxWindow* cursorTarget = GetWXPeer(); + wxCoord x,y; + SetupCoordinates(x, y, event); + wxPoint cursorPoint( x , y ) ; + + while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) + { + cursorTarget = cursorTarget->GetParent() ; + if ( cursorTarget ) + cursorPoint += cursorTarget->GetPosition(); + } + + return cursorTarget != NULL; } } - - void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd) { if ( [event type] == NSKeyDown ) @@ -2539,7 +2566,11 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) { wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent(wxevent , event) ; - return GetWXPeer()->HandleWindowEvent(wxevent); + bool result = GetWXPeer()->HandleWindowEvent(wxevent); + + (void)SetupCursor(event); + + return result; } void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow) @@ -2656,11 +2687,13 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) { NSView* cv = [tlw contentView]; c = new wxWidgetCocoaImpl( now, cv, true ); - // increase ref count, because the impl destructor will decrement it again - CFRetain(cv); - if ( !now->IsShown() ) - [cv setHidden:NO]; - + if ( cv != nil ) + { + // increase ref count, because the impl destructor will decrement it again + CFRetain(cv); + if ( !now->IsShown() ) + [cv setHidden:NO]; + } } else { -- 2.45.2