Try to improve CanFocus() behaviour for hidden windows

This should be less important now that we don't rely on CanFocus() to
determine if we should set focus to the window any longer, but it seems
to still be better to try to make it work better for hidden windows, so
at least return true from it when full keyboard access is on.

When it's off, the behaviour is the same as before, but this doesn't
affect wxTextCtrl, whose peer NSView overrides CanFocus() to always
return true.

We almost certainly need to override CanFocus() in other views, notably
wxDataViewCtrl, wxSearchCtrl, and any other controls that can have focus
even when full keyboard access is off.

See #17340.
This commit is contained in:
Vadim Zeitlin
2019-10-27 01:39:27 +02:00
parent 6530323f31
commit 85b5337160

View File

@@ -3090,6 +3090,16 @@ bool wxWidgetCocoaImpl::GetNeedsDisplay() const
bool wxWidgetCocoaImpl::CanFocus() const
{
if ( !IsVisible() )
{
// It's useless to call canBecomeKeyView in this case, it will always
// return false. Try to return something reasonable ourselves, knowing
// that most controls are not focusable when full keyboard access if
// off and wxNSTextViewControl overrides CanFocus() to always return
// true anyhow.
return [NSApp isFullKeyboardAccessEnabled];
}
NSView* targetView = m_osxView;
if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
targetView = [(NSScrollView*) m_osxView documentView];