From fd3a3e607b36877882cbc3e1019d0f0e46f19a15 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 21 Nov 2017 23:17:11 +0100 Subject: [PATCH] Extract SetupCoordinates() from wxWidgetCocoaImpl Add a free function that can be used from outside wxWidgetCocoaImpl class too and keep the old method as a trivial wrapper around it. No changes, this is a pure refactoring. --- src/osx/cocoa/window.mm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 9df2c4b17c..44abf0198c 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -528,29 +528,35 @@ bool g_lastButtonWasFakeRight = false ; - (CGFloat)scrollingDeltaY; @end -void wxWidgetCocoaImpl::SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent* nsEvent) +static void +wxSetupCoordinates(NSView* view, wxCoord &x, wxCoord &y, NSEvent* nsEvent) { NSRect locationInWindow = NSZeroRect; locationInWindow.origin = [nsEvent locationInWindow]; // adjust coordinates for the window of the target view - if ( [nsEvent window] != [m_osxView window] ) + if ( [nsEvent window] != [view window] ) { if ( [nsEvent window] != nil ) locationInWindow = [[nsEvent window] convertRectToScreen:locationInWindow]; - if ( [m_osxView window] != nil ) - locationInWindow = [[m_osxView window] convertRectFromScreen:locationInWindow]; + if ( [view window] != nil ) + locationInWindow = [[view window] convertRectFromScreen:locationInWindow]; } - NSPoint locationInView = [m_osxView convertPoint:locationInWindow.origin fromView:nil]; - wxPoint locationInViewWX = wxFromNSPoint( m_osxView, locationInView ); + NSPoint locationInView = [view convertPoint:locationInWindow.origin fromView:nil]; + wxPoint locationInViewWX = wxFromNSPoint( view, locationInView ); x = locationInViewWX.x; y = locationInViewWX.y; } +void wxWidgetCocoaImpl::SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent* nsEvent) +{ + wxSetupCoordinates(m_osxView, x, y, nsEvent); +} + void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) { int eventType = [nsEvent type];