diff --git a/include/wx/containr.h b/include/wx/containr.h index 3783578f40..3f91f3e6a3 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -80,7 +80,8 @@ public: // Returns whether we or one of our children accepts focus. bool AcceptsFocusRecursively() const - { return m_acceptsFocusSelf || m_acceptsFocusChildren; } + { return m_acceptsFocusSelf || + (m_acceptsFocusChildren && HasAnyChildrenAcceptingFocus()); } // We accept focus from keyboard if we accept it at all. bool AcceptsFocusFromKeyboard() const { return AcceptsFocusRecursively(); } @@ -97,6 +98,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; diff --git a/src/common/containr.cpp b/src/common/containr.cpp index a194041631..ba1ffd220e 100644 --- a/src/common/containr.cpp +++ b/src/common/containr.cpp @@ -81,6 +81,30 @@ bool wxControlContainerBase::HasAnyFocusableChildren() const if ( !m_winParent->IsClientAreaChild(child) ) continue; + // Here we check whether the child can accept the focus at all, as we + // want to try focusing it later even if it can't accept it right now. + if ( child->AcceptsFocusRecursively() ) + return true; + } + + return false; +} + +bool wxControlContainerBase::HasAnyChildrenAcceptingFocus() const +{ + const wxWindowList& children = m_winParent->GetChildren(); + for ( wxWindowList::const_iterator i = children.begin(), + end = children.end(); + i != end; + ++i ) + { + const wxWindow * const child = *i; + + if ( !m_winParent->IsClientAreaChild(child) ) + continue; + + // Here we check if the child accepts focus right now as we need to + // know if we can give the focus to it or not. if ( child->CanAcceptFocus() ) return true; }