diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index c2611295ab..7900204a31 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -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); diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index e1375beee7..b9e06bde2f 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -2816,6 +2816,41 @@ bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text) 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); @@ -2830,6 +2865,9 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) if ( GetWXPeer()->OSXHandleKeyEvent(eventHook) && !eventHook.IsNextEventAllowed() ) return true; + + if (DoHandleKeyNavigation(wxevent)) + return true; } if ( IsUserPane() && [event type] == NSKeyDown)