From 60d66be369d360e1528e4dd4bb65a909a8c6ac9a Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 3 Jun 2013 10:37:01 +0000 Subject: [PATCH] attempt to get the 'new focus' window parameter of a focus kill event set correctly git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74094 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 2 ++ src/osx/cocoa/nonownedwnd.mm | 26 ++++++++++++++++++++++++++ src/osx/cocoa/textctrl.mm | 18 +++++++++++++++--- src/osx/cocoa/window.mm | 8 ++++---- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index aae5939607..290f71c1b4 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -258,6 +258,8 @@ public : CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; } void RestoreWindowLevel(); + + static WX_NSResponder GetNextFirstResponder() ; protected : CGWindowLevel m_macWindowLevel; WXWindow m_macWindow; diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 6ae40522fe..030b1e6a23 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -145,6 +145,8 @@ bool shouldHandleSelector(SEL selector) // wx native implementation // +static NSResponder* s_nextFirstResponder = NULL; + @interface wxNSWindow : NSWindow { } @@ -152,6 +154,7 @@ bool shouldHandleSelector(SEL selector) - (void) sendEvent:(NSEvent *)event; - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen; - (void)noResponderFor: (SEL) selector; +- (BOOL)makeFirstResponder:(NSResponder *)aResponder; @end @implementation wxNSWindow @@ -206,6 +209,14 @@ bool shouldHandleSelector(SEL selector) return YES; } +- (BOOL)makeFirstResponder:(NSResponder *)aResponder +{ + s_nextFirstResponder = aResponder; + BOOL retval = [super makeFirstResponder:aResponder]; + s_nextFirstResponder = nil; + return retval; +} + @end @interface wxNSPanel : NSPanel @@ -215,6 +226,7 @@ bool shouldHandleSelector(SEL selector) - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen; - (void)noResponderFor: (SEL) selector; - (void)sendEvent:(NSEvent *)event; +- (BOOL)makeFirstResponder:(NSResponder *)aResponder; @end @implementation wxNSPanel @@ -265,6 +277,14 @@ bool shouldHandleSelector(SEL selector) } } +- (BOOL)makeFirstResponder:(NSResponder *)aResponder +{ + s_nextFirstResponder = aResponder; + BOOL retval = [super makeFirstResponder:aResponder]; + s_nextFirstResponder = nil; + return retval; +} + @end @@ -1041,6 +1061,12 @@ void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel() [m_macWindow setLevel:m_macWindowLevel]; } +WX_NSResponder wxNonOwnedWindowCocoaImpl::GetNextFirstResponder() +{ + return s_nextFirstResponder; +} + + // // // diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 6c4b6c1a88..4d4398e2d2 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -182,7 +182,11 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) { - impl->DoNotifyFocusEvent( false, NULL ); + NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); + NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + + wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + impl->DoNotifyFocusEvent( false, otherWindow ); } } @@ -336,7 +340,11 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) { - impl->DoNotifyFocusEvent( false, NULL ); + NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); + NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + + wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + impl->DoNotifyFocusEvent( false, otherWindow ); } } @@ -506,7 +514,11 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; timpl->SetInternalSelection(range.location, range.location + range.length); } - impl->DoNotifyFocusEvent( false, NULL ); + NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); + NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + + wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + impl->DoNotifyFocusEvent( false, otherWindow ); } } @end diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index a9efa58485..c46dcd273f 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1347,10 +1347,10 @@ bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd) { wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd]; BOOL r = superimpl(slf, (SEL)_cmd); - // get the current focus after running resignFirstResponder - // note that this value isn't reliable, it might return the same view that - // is resigning - NSView* otherView = FindFocus(); + + NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); + NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + wxWidgetImpl* otherWindow = FindFromWXWidget(otherView); // CS: the fix for #12267 leads to missed focus events like in #14938 , as #12267 doesn't seem to happen anymore even -- 2.45.2