Don't pretend static box with enabled label is disabled

Trying to be smart by setting m_isEnabled to false in
wxStaticBox::Enable() without actually disabling the box itself (because
it can't be done if its label window is to remain enabled) didn't really
work. For example, it was impossible to TAB to a checkbox label of the
box when it was disabled, because keyboard navigation (correctly)
doesn't recurse into disabled windows and there could be similar
problems with any other code iterating over windows and skipping over
the disabled ones.

So, finally, simplify things and keep m_isEnabled in sync with the real
box state, even if this, counter-intuitively, means that IsEnabled() on
the box returns true after calling Enable(false) on it.

This also reverts 4ee35cf5ee569b6ee6c7d0d5702484d4d2a20f96 ("Don't
disable wxStaticBox children at wx level when disabling it") as we can't
avoid really disabling the children any more now that their parent is
not disabled: without this, their IsEnabled() would return true, i.e.
they wouldn't be disabled at all, from the program point of view. This
is unfortunate for the reasons that originally motivated that commit,
i.e. if some wxStaticBox child is disabled, disabling and re-enabling
the box will now re-enable this child, even if it shouldn't, but seems
impossible to avoid. The only possible alternative is to modify
IsEnabled() to add some wxStaticBox-specific hook to it, e.g. instead of
calling GetParent()->IsEnabled() there, we could call some now
AreChildrenEnable() method, which would delegate to IsEnabled() by
default but overridden in wxStaticBox. However this seems complicated,
and will add an extra virtual function call to all (frequently
happening) IsEnabled() calls.
This commit is contained in:
Vadim Zeitlin
2018-01-18 23:14:36 +01:00
parent 88c6ce344e
commit a67f4b8254
4 changed files with 36 additions and 35 deletions

View File

@@ -1580,11 +1580,6 @@ public:
return false;
}
// Recursively call our own and our children DoEnable() when the
// enabled/disabled status changed because a parent window had been
// enabled/disabled. This is only used by the library implementation.
void NotifyWindowOnEnableChange(bool enabled);
protected:
// helper for the derived class Create() methods: the first overload, with
@@ -1896,6 +1891,11 @@ protected:
static void NotifyCaptureLost();
private:
// recursively call our own and our children DoEnable() when the
// enabled/disabled status changed because a parent window had been
// enabled/disabled
void NotifyWindowOnEnableChange(bool enabled);
#if wxUSE_MENUS
// temporary event handlers used by GetPopupMenuSelectionFromUser()
void InternalOnPopupMenu(wxCommandEvent& event);