X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e68b7b364aff19665e2c6ee8c68266b6f3d56355..9c34a216817028bc533e07873d047208a96b05a2:/include/wx/containr.h?ds=inline diff --git a/include/wx/containr.h b/include/wx/containr.h index 69dc4a92c6..b465e33c30 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -62,18 +62,27 @@ public: // This can be called by the window to indicate that it never wants to have // the focus for itself. - void DisableSelfFocus() { m_acceptsFocusSelf = false; } + void DisableSelfFocus() + { m_acceptsFocusSelf = false; UpdateParentCanFocus(); } + + // This can be called to undo the effect of a previous DisableSelfFocus() + // (otherwise calling it is not necessary as the window does accept focus + // by default). + void EnableSelfFocus() + { m_acceptsFocusSelf = true; UpdateParentCanFocus(); } // should be called from SetFocus(), returns false if we did nothing with // the focus and the default processing should take place bool DoSetFocus(); // returns whether we should accept focus ourselves or not - bool AcceptsFocus() const { return m_acceptsFocusSelf; } + bool AcceptsFocus() const + { return m_acceptsFocusSelf && m_winParent->CanBeFocused(); } // Returns whether we or one of our children accepts focus. bool AcceptsFocusRecursively() const - bool AcceptsFocus() const { return m_acceptsFocus; } + { return AcceptsFocus() || + (m_acceptsFocusChildren && HasAnyChildrenAcceptingFocus()); } // We accept focus from keyboard if we accept it at all. bool AcceptsFocusFromKeyboard() const { return AcceptsFocusRecursively(); } @@ -90,6 +99,10 @@ protected: // return true if we have any children accepting focus bool HasAnyFocusableChildren() const; + // return true if we have any children that do accept focus right now + bool HasAnyChildrenAcceptingFocus() const; + + // the parent window we manage the children for wxWindow *m_winParent; @@ -97,6 +110,9 @@ protected: wxWindow *m_winLastFocused; private: + // Update the window status to reflect whether it is getting focus or not. + void UpdateParentCanFocus(); + // Indicates whether the associated window can ever have focus itself. // // Usually this is the case, e.g. a wxPanel can be used either as a @@ -205,7 +221,13 @@ public: { BaseWindowClass::AddChild(child); - m_container.UpdateCanFocusChildren(); + if ( m_container.UpdateCanFocusChildren() ) + { + // Under MSW we must have wxTAB_TRAVERSAL style for TAB navigation + // to work. + if ( !BaseWindowClass::HasFlag(wxTAB_TRAVERSAL) ) + BaseWindowClass::ToggleWindowStyle(wxTAB_TRAVERSAL); + } } WXDLLIMPEXP_INLINE_CORE virtual void RemoveChild(wxWindowBase *child) @@ -216,6 +238,8 @@ public: BaseWindowClass::RemoveChild(child); + // We could reset wxTAB_TRAVERSAL here but it doesn't seem to do any + // harm to keep it. m_container.UpdateCanFocusChildren(); }