Allow wxDataViewCtrl to gain focus in wxOSX

Fix numerous focus-handling bugs in wxOSX in combination with
NSScrollView (which cannot get focus by itself and which was already
treated specially in many, but not all, places), including

- inability to set the focus
- loss of wxEVT_SET_FOCUS events
- loss of wxWindow<->NSView association after clearing wxDVC columns
This commit is contained in:
Václav Slavík
2016-10-19 17:07:13 +02:00
parent f3b8dac3b7
commit 73f6bf7b6f
2 changed files with 24 additions and 5 deletions

View File

@@ -2328,12 +2328,18 @@ bool wxWidgetCocoaImpl::GetNeedsDisplay() const
bool wxWidgetCocoaImpl::CanFocus() const
{
return [m_osxView canBecomeKeyView] == YES;
NSView* targetView = m_osxView;
if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
targetView = [(NSScrollView*) m_osxView documentView];
return [targetView canBecomeKeyView] == YES;
}
bool wxWidgetCocoaImpl::HasFocus() const
{
return ( FindFocus() == m_osxView );
NSView* targetView = m_osxView;
if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
targetView = [(NSScrollView*) m_osxView documentView];
return ( FindFocus() == targetView );
}
bool wxWidgetCocoaImpl::SetFocus()
@@ -2341,6 +2347,10 @@ bool wxWidgetCocoaImpl::SetFocus()
if ( !CanFocus() )
return false;
NSView* targetView = m_osxView;
if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
targetView = [(NSScrollView*) m_osxView documentView];
// TODO remove if no issues arise: should not raise the window, only assign focus
//[[m_osxView window] makeKeyAndOrderFront:nil] ;
[[m_osxView window] makeFirstResponder: m_osxView] ;