Relax the sizer parent check to allow for null parent too

Normally non-toplevel windows must have non-null parents, as creating
them with null parent would fail, but our own wxTabFrame used in AUI is
an example of a window which can have null parent because it's actually
never created at all. This does look like a pretty bad hack, but it's
very unlikely to happen accidentally, so relax the assertion check added
in the previous commit to allow for it.
This commit is contained in:
Vadim Zeitlin
2021-10-21 15:33:49 +01:00
parent 62c3d921b2
commit b88f472291

View File

@@ -187,6 +187,17 @@ wxString MakeFlagsCheckMessage(const char* start, const char* whatToRemove)
);
}
bool CheckExpectedParentIs(wxWindow* w, wxWindow* expectedParent)
{
// 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();
return !parent || parent == expectedParent;
}
wxString MakeExpectedParentMessage(wxWindow* w, wxWindow* expectedParent)
{
return wxString::Format
@@ -249,7 +260,7 @@ wxString MakeExpectedParentMessage(wxWindow* w, wxWindow* expectedParent)
#define ASSERT_WINDOW_PARENT_IS(w, expectedParent) \
wxASSERT_MSG \
( \
w->GetParent() == expectedParent, \
CheckExpectedParentIs(w, expectedParent), \
MakeExpectedParentMessage(w, expectedParent) \
)