From 3251b8346678b487755102e2ddb5f2071ee1f1ca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 11 Apr 2003 13:48:27 +0000 Subject: [PATCH] containers don't always accept focus (patch 718913) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20134 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/containr.h | 8 ++++++++ src/common/containr.cpp | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/wx/containr.h b/include/wx/containr.h index 234161da03..fd3ba533ce 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -69,6 +69,9 @@ public: // the focus and the default processing should take place bool DoSetFocus(); + // can our child get the focus? + bool AcceptsFocus() const; + // called from OnChildFocus() handler, i.e. when one of our (grand) // children gets the focus void SetLastFocus(wxWindow *win); @@ -111,6 +114,7 @@ public: \ virtual wxWindow *GetDefaultItem() const; \ virtual wxWindow *SetDefaultItem(wxWindow *child); \ virtual void SetTmpDefaultItem(wxWindow *win); \ + virtual bool AcceptsFocus() const; \ \ protected: \ wxControlContainer m_container @@ -164,6 +168,10 @@ void classname::OnChildFocus(wxChildFocusEvent& event) \ void classname::OnFocus(wxFocusEvent& event) \ { \ m_container.HandleOnFocus(event); \ +} \ +bool classname::AcceptsFocus() const \ +{ \ + return m_container.AcceptsFocus(); \ } diff --git a/src/common/containr.cpp b/src/common/containr.cpp index cf52acee49..5f251fda7b 100644 --- a/src/common/containr.cpp +++ b/src/common/containr.cpp @@ -49,6 +49,28 @@ wxControlContainer::wxControlContainer(wxWindow *winParent) m_winDefault = NULL; } +bool wxControlContainer::AcceptsFocus() const +{ + // We can accept focus only when at last one child will accept focus + if ( m_winParent->IsShown() && m_winParent->IsEnabled() ) + { + wxWindowList::Node *node = m_winParent->GetChildren().GetFirst(); + while ( node ) + { + wxWindow *child = node->GetData(); + + if ( child->AcceptsFocus() ) + { + return TRUE; + } + + node = node->GetNext(); + } + } + + return FALSE; +} + void wxControlContainer::SetLastFocus(wxWindow *win) { // the panel itself should never get the focus at all but if it does happen @@ -386,3 +408,4 @@ bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused) return FALSE; } + -- 2.45.2