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:
@@ -182,6 +182,21 @@ public:
|
||||
});
|
||||
@endcode
|
||||
does work as expected.
|
||||
|
||||
Please note that overriding Enable() to not actually disable this
|
||||
window itself has two possibly unexpected consequences:
|
||||
|
||||
- The box retains its enabled status, i.e. IsEnabled() still returns
|
||||
@true, after calling @c Enable(false).
|
||||
- The box children are enabled or disabled when the box is, which can
|
||||
result in the loss of their original state. E.g. if a box child is
|
||||
initially disabled, then the box itself is disabled and, finally, the
|
||||
box is enabled again, this child will end up being enabled too (this
|
||||
wouldn't happen with any other parent window as its children would
|
||||
inherit the disabled state from the parent instead of being really
|
||||
disabled themselves when it is disabled). To avoid this problem,
|
||||
consider using ::wxEVT_UPDATE_UI to ensure that the child state is
|
||||
always correct or restoring it manually after re-enabling the box.
|
||||
*/
|
||||
virtual bool Enable(bool enable = true);
|
||||
};
|
||||
|
Reference in New Issue
Block a user