From 34f430a016a98040ce2e2f9edcee0a48a9b1d085 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 29 Oct 2021 01:33:48 +0100 Subject: [PATCH] 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. --- src/common/sizer.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index beb1bbf243..d3ef62151a 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -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)