Focus handling fixes - make sure new windows activate on show, ensure focus events call SetWindow with the previous / next focus window respectively, and go back to native behavior for now with acceptsFirstResponder until we can figure out how to pass the results of AcceptsFocus() to it without getting in a loop as the wx API calls native and vice versa.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59467 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -398,9 +398,6 @@ long style, long extraStyle, const wxString& name )
|
|||||||
[m_macWindow setDelegate:controller];
|
[m_macWindow setDelegate:controller];
|
||||||
|
|
||||||
[m_macWindow setAcceptsMouseMovedEvents: YES];
|
[m_macWindow setAcceptsMouseMovedEvents: YES];
|
||||||
|
|
||||||
if ( ( style & wxPOPUP_WINDOW ) )
|
|
||||||
[m_macWindow makeKeyAndOrderFront:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -423,7 +420,7 @@ bool wxNonOwnedWindowCocoaImpl::Show(bool show)
|
|||||||
{
|
{
|
||||||
if ( show )
|
if ( show )
|
||||||
{
|
{
|
||||||
[m_macWindow orderFront:nil];
|
[m_macWindow makeKeyAndOrderFront:nil];
|
||||||
[[m_macWindow contentView] setNeedsDisplay:YES];
|
[[m_macWindow contentView] setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -791,21 +791,21 @@ bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, voi
|
|||||||
|
|
||||||
bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
|
bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
|
||||||
{
|
{
|
||||||
// Make sure wxWindows can receive focus by default like they do for other ports.
|
// FIXME: We need to find a way to query AcceptsFocus here, but when we do it
|
||||||
|
// it calls native APIs which lead us back here and into a loop.
|
||||||
// FIXME: It'd be nice to have some way to tie this in with AcceptsFocus
|
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
|
||||||
// but that currently causes loops because the call to m_peer->CanFocus()
|
return superimpl(slf, (SEL)_cmd);
|
||||||
// ends up calling this method again. Don't know how to avoid it without
|
|
||||||
// making a setter method for focus.
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
|
bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
|
||||||
{
|
{
|
||||||
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
|
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
|
||||||
|
// get the current focus before running becomeFirstResponder
|
||||||
|
NSView* otherView = [[NSApp keyWindow] firstResponder];
|
||||||
|
wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
|
||||||
BOOL r = superimpl(slf, (SEL)_cmd);
|
BOOL r = superimpl(slf, (SEL)_cmd);
|
||||||
if ( r )
|
if ( r )
|
||||||
DoNotifyFocusEvent( true );
|
DoNotifyFocusEvent( true, otherWindow );
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,8 +813,11 @@ bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
|
|||||||
{
|
{
|
||||||
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
|
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
|
||||||
BOOL r = superimpl(slf, (SEL)_cmd);
|
BOOL r = superimpl(slf, (SEL)_cmd);
|
||||||
|
// get the current focus after running resignFirstResponder
|
||||||
|
NSView* otherView = [[NSApp keyWindow] firstResponder];
|
||||||
|
wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
|
||||||
if ( r )
|
if ( r )
|
||||||
DoNotifyFocusEvent( false );
|
DoNotifyFocusEvent( false, otherWindow );
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1406,7 +1409,7 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
|
|||||||
return GetWXPeer()->HandleWindowEvent(wxevent);
|
return GetWXPeer()->HandleWindowEvent(wxevent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
|
void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
|
||||||
{
|
{
|
||||||
wxWindow* thisWindow = GetWXPeer();
|
wxWindow* thisWindow = GetWXPeer();
|
||||||
if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
|
if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
|
||||||
@@ -1427,8 +1430,8 @@ void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
|
|||||||
|
|
||||||
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
|
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
|
||||||
event.SetEventObject(thisWindow);
|
event.SetEventObject(thisWindow);
|
||||||
// TODO how to find out the targetFocusWindow ?
|
if (otherWindow)
|
||||||
// event.SetWindow(targetFocusWindow);
|
event.SetWindow(otherWindow->GetWXPeer());
|
||||||
thisWindow->HandleWindowEvent(event) ;
|
thisWindow->HandleWindowEvent(event) ;
|
||||||
}
|
}
|
||||||
else // !receivedFocuss
|
else // !receivedFocuss
|
||||||
@@ -1442,8 +1445,8 @@ void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
|
|||||||
|
|
||||||
wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
|
wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
|
||||||
event.SetEventObject(thisWindow);
|
event.SetEventObject(thisWindow);
|
||||||
// TODO how to find out the targetFocusWindow ?
|
if (otherWindow)
|
||||||
// event.SetWindow(targetFocusWindow);
|
event.SetWindow(otherWindow->GetWXPeer());
|
||||||
thisWindow->HandleWindowEvent(event) ;
|
thisWindow->HandleWindowEvent(event) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user