From 1c78ede5515a99b38d35a72a5428c281545d5895 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 12 Jun 2015 14:34:26 +0200 Subject: [PATCH] Fix use of SetContainingSizer() in wxWrapSizer code. Calling SetContainingSizer() on a window which had been contained in another sizer previously asserts since efce9b23067c5110daad6466c2c5283d5dfb11c1, so change wxWrapSizer to set the containing sizer to NULL before resetting it. --- src/common/wrapsizer.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/wrapsizer.cpp b/src/common/wrapsizer.cpp index a726f26065..3df35e7e40 100644 --- a/src/common/wrapsizer.cpp +++ b/src/common/wrapsizer.cpp @@ -565,19 +565,29 @@ void wxWrapSizer::RecalcSizes() sizer->Add(itemSpace); } + // We must pretend that any window item is not part of this sizer, + // otherwise adding it to another one would trigger an assert due + // to a conflict with the current containing sizer. + wxWindow * const win = item->GetWindow(); + if ( win ) + win->SetContainingSizer(NULL); + // Notice that we reuse a pointer to our own sizer item here, so we // must remember to remove it by calling ClearRows() to avoid // double deletion later sizer->Add(item); + // If item is a window, it now has a pointer to the child sizer, + // which is wrong. Set it to point to us. + if ( win ) + { + win->SetContainingSizer(NULL); + win->SetContainingSizer(this); + } + itemLast = item; itemSpace = NULL; } - - // If item is a window, it now has a pointer to the child sizer, - // which is wrong. Set it to point to us. - if ( wxWindow *win = item->GetWindow() ) - win->SetContainingSizer(this); } FinishRow(nRow, rowTotalMajor, maxRowMinor, itemLast);