Relax the sizer parent check to account for wxStaticBoxSizer

The check added in 62c3d921b2 (Check that all windows in a sizer use
associated window as parent, 2021-10-20) didn't work correctly when
using wxStaticBoxSizer, as the windows in this sizer are grandchildren
(or possibly even further descendants, in case of nested sizers) of the
window that the sizer is associated with, with the static box being the
immediate parent.

Relax the check to account for this and to avoid triggering for any use
of wxStaticBoxSizer.

Closes #19308.
This commit is contained in:
Vadim Zeitlin
2021-10-29 01:33:48 +01:00
parent e2a0c87f1d
commit 34f430a016

View File

@@ -189,13 +189,33 @@ wxString MakeFlagsCheckMessage(const char* start, const char* whatToRemove)
bool CheckExpectedParentIs(wxWindow* w, wxWindow* expectedParent)
{
wxWindow* parent = w->GetParent();
// We specifically exclude the case of a window with a null parent as it
// typically doesn't happen accidentally, but does happen intentionally in
// our own wxTabFrame which is a hack used by AUI for whatever reason, and
// could presumably be also done on purpose in application code.
wxWindow* const parent = w->GetParent();
if ( !parent )
return true;
return !parent || parent == expectedParent;
// We also allow the window to be a (grand)grandchild of this window, as
// this happens with children of wxStaticBox in (possibly nested)
// wxStaticBoxSizer.
while ( parent != expectedParent )
{
#if wxUSE_STATBOX
if ( wxDynamicCast(parent, wxStaticBox) )
{
parent = parent->GetParent();
if ( parent )
continue;
}
#endif // wxUSE_STATBOX
return false;
}
return true;
}
wxString MakeExpectedParentMessage(wxWindow* w, wxWindow* expectedParent)