+// ----------------------------------------------------------------------------
+// wxControlContainerBase
+// ----------------------------------------------------------------------------
+
+void wxControlContainerBase::UpdateParentCanFocus()
+{
+ // In the ports where it does something non trivial, the parent window
+ // should only be focusable if it doesn't have any focusable children
+ // (e.g. native focus handling in wxGTK totally breaks down otherwise).
+ m_winParent->SetCanFocus(m_acceptsFocusSelf && !m_acceptsFocusChildren);
+}
+
+bool wxControlContainerBase::UpdateCanFocusChildren()
+{
+ const bool acceptsFocusChildren = HasAnyFocusableChildren();
+ if ( acceptsFocusChildren != m_acceptsFocusChildren )
+ {
+ m_acceptsFocusChildren = acceptsFocusChildren;
+
+ UpdateParentCanFocus();
+ }
+
+ return m_acceptsFocusChildren;
+}
+
+bool wxControlContainerBase::HasAnyFocusableChildren() 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 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;
+ }
+
+ return false;
+}
+
+bool wxControlContainerBase::DoSetFocus()
+{
+ wxLogTrace(TRACE_FOCUS, wxT("SetFocus on wxPanel 0x%p."),
+ m_winParent->GetHandle());
+
+ if (m_inSetFocus)
+ return true;
+
+ // when the panel gets the focus we move the focus to either the last
+ // window that had the focus or the first one that can get it unless the
+ // focus had been already set to some other child
+
+ wxWindow *win = wxWindow::FindFocus();
+ while ( win )
+ {
+ if ( win == m_winParent )
+ {
+ // our child already has focus, don't take it away from it
+ return true;
+ }
+
+ if ( win->IsTopLevel() )
+ {
+ // don't look beyond the first top level parent - useless and
+ // unnecessary
+ break;
+ }
+
+ win = win->GetParent();
+ }
+
+ // protect against infinite recursion:
+ m_inSetFocus = true;
+
+ bool ret = SetFocusToChild();
+
+ m_inSetFocus = false;
+
+ return ret;
+}
+
+bool wxControlContainerBase::AcceptsFocus() const