From bd6ca54f63b93ae047e1039a46b91d6a8f4e5bf9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Jul 2013 12:44:33 +0000 Subject: [PATCH 1/1] Fix tab navigation bug with radio boxes without enabled items. There was a bug similar to the one in the preceding commit with radio boxes under wxMSW too: if all radio box buttons were disabled (or hidden, although this should be much more rare in practice, unlike the disabled case which was deemed to be rare in r74583 commit message but turned out to actually happen), the radio box still pretended to accept focus but didn't really do it. Fix this by allowing to override wxWindow::CanBeFocused() and do it in wxRadioBox to check whether we have any enabled visible items. Also add a check for CanBeFocused() to wxControlContainer code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74586 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/containr.h | 5 +++-- include/wx/msw/radiobox.h | 1 + include/wx/window.h | 9 +++++++-- src/msw/radiobox.cpp | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/wx/containr.h b/include/wx/containr.h index 3f91f3e6a3..b465e33c30 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -76,11 +76,12 @@ public: 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 - { return m_acceptsFocusSelf || + { return AcceptsFocus() || (m_acceptsFocusChildren && HasAnyChildrenAcceptingFocus()); } // We accept focus from keyboard if we accept it at all. diff --git a/include/wx/msw/radiobox.h b/include/wx/msw/radiobox.h index a0f546df9d..def96487c8 100644 --- a/include/wx/msw/radiobox.h +++ b/include/wx/msw/radiobox.h @@ -97,6 +97,7 @@ public: // override some base class methods virtual bool Show(bool show = true); virtual bool Enable(bool enable = true); + virtual bool CanBeFocused() const; virtual void SetFocus(); virtual bool SetFont(const wxFont& font); virtual bool ContainsHWND(WXHWND hWnd) const; diff --git a/include/wx/window.h b/include/wx/window.h index 52c7a4c466..a8f757037b 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -724,8 +724,13 @@ public: virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); } - // this is mostly a helper for the various functions using it below - bool CanBeFocused() const { return IsShown() && IsEnabled(); } + // Can this window be focused right now, in its current state? This + // shouldn't be called at all if AcceptsFocus() returns false. + // + // It is a convenient helper for the various functions using it below + // but also a hook allowing to override the default logic for some rare + // cases (currently just wxRadioBox in wxMSW) when it's inappropriate. + virtual bool CanBeFocused() const { return IsShown() && IsEnabled(); } // can this window itself have focus? bool IsFocusable() const { return AcceptsFocus() && CanBeFocused(); } diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index 7f811c9216..51fbac285a 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -444,6 +444,25 @@ void wxRadioBox::SetFocus() } } +bool wxRadioBox::CanBeFocused() const +{ + // If the control itself is hidden or disabled, no need to check anything + // else. + if ( !wxStaticBox::CanBeFocused() ) + return false; + + // Otherwise, check if we have any buttons that can be focused. + for ( size_t item = 0; item < m_radioButtons->GetCount(); item++ ) + { + if ( IsItemEnabled(item) && IsItemShown(item) ) + return true; + } + + // We didn't find any items that can accept focus, so neither can we as a + // whole accept it. + return false; +} + // Enable a specific button bool wxRadioBox::Enable(unsigned int item, bool enable) { -- 2.45.2