From 85b5337160c14e0afed2d356f664ccac1310e4d7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Oct 2019 01:39:27 +0200 Subject: [PATCH] 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. --- src/osx/cocoa/window.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index f46386286b..8a8a12b948 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -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];