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

@ -1915,6 +1915,14 @@ outlineView:(NSOutlineView*)outlineView
}
}
-(BOOL) becomeFirstResponder
{
BOOL r = [super becomeFirstResponder];
if ( r )
implementation->DoNotifyFocusSet();
return r;
}
@end
// ============================================================================
@ -1942,15 +1950,16 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer,
[scrollview setAutohidesScrollers:YES];
[scrollview setDocumentView:m_OutlineView];
// we cannot call InstallHandler(m_OutlineView) here, because we are handling
// our action:s ourselves, only associate the view with this impl
Associate(m_OutlineView,this);
// initialize the native control itself too
InitOutlineView(style);
}
void wxCocoaDataViewControl::InitOutlineView(long style)
{
// we cannot call InstallHandler(m_OutlineView) here, because we are handling
// our action:s ourselves, only associate the view with this impl
Associate(m_OutlineView,this);
[m_OutlineView setImplementation:this];
[m_OutlineView setFocusRingType:NSFocusRingTypeNone];
[m_OutlineView setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];

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] ;