Fix use of SetContainingSizer() in wxWrapSizer code.

Calling SetContainingSizer() on a window which had been contained in another
sizer previously asserts since efce9b2306, so
change wxWrapSizer to set the containing sizer to NULL before resetting it.
This commit is contained in:
Vadim Zeitlin
2015-06-12 14:34:26 +02:00
parent 6e72126894
commit 1c78ede551

View File

@@ -565,19 +565,29 @@ void wxWrapSizer::RecalcSizes()
sizer->Add(itemSpace); 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 // Notice that we reuse a pointer to our own sizer item here, so we
// must remember to remove it by calling ClearRows() to avoid // must remember to remove it by calling ClearRows() to avoid
// double deletion later // double deletion later
sizer->Add(item); 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; itemLast = item;
itemSpace = NULL; 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); FinishRow(nRow, rowTotalMajor, maxRowMinor, itemLast);