Skip to content

Commit

Permalink
Properly handle tab navigation for most controls on wxOSX wxWidgets#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrowne committed Jun 5, 2017
1 parent ff44703 commit 8bca6de
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/wx/osx/cocoa/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public :

void InstallEventHandler( WXWidget control = NULL );

virtual bool ShouldHandleKeyNavigation(const wxKeyEvent &event) const;
bool DoHandleKeyNavigation(const wxKeyEvent &event);
virtual bool DoHandleMouseEvent(NSEvent *event);
virtual bool DoHandleKeyEvent(NSEvent *event);
virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
Expand Down
38 changes: 38 additions & 0 deletions src/osx/cocoa/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,41 @@ static NSComparisonResult CocoaLowerWindowCompareFunction(KindOfView first, Kind
return result;
}

bool wxWidgetCocoaImpl::ShouldHandleKeyNavigation(const wxKeyEvent &WXUNUSED(event)) const
{
// Only controls that intercept tabs for different behavior should return false (ie wxTE_PROCESS_TAB)
return true;
}

bool wxWidgetCocoaImpl::DoHandleKeyNavigation(const wxKeyEvent &event)
{
bool handled = false;
wxWindow *focus = GetWXPeer();
if (focus && event.GetKeyCode() == WXK_TAB)
{
if (ShouldHandleKeyNavigation(event))
{
wxWindow* iter = focus->GetParent() ;
while (iter && !handled)
{
if (iter->HasFlag(wxTAB_TRAVERSAL))
{
wxNavigationKeyEvent new_event;
new_event.SetEventObject( focus );
new_event.SetDirection( !event.ShiftDown() );
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
new_event.SetWindowChange( event.ControlDown() );
new_event.SetCurrentFocus( focus );
handled = iter->HandleWindowEvent( new_event ) && !new_event.GetSkipped();
}

iter = iter->GetParent() ;
}
}
}
return handled;
}

bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
{
wxKeyEvent wxevent(wxEVT_KEY_DOWN);
Expand All @@ -2830,6 +2865,9 @@ static NSComparisonResult CocoaLowerWindowCompareFunction(KindOfView first, Kind
if ( GetWXPeer()->OSXHandleKeyEvent(eventHook)
&& !eventHook.IsNextEventAllowed() )
return true;

if (DoHandleKeyNavigation(wxevent))
return true;
}

if ( IsUserPane() && [event type] == NSKeyDown)
Expand Down

0 comments on commit 8bca6de

Please sign in to comment.