Fix adding pages without associated window to wxTreebook

wxTreebook is supposed to allow not specifying any valid window for the
top-level pages, but this didn't work any longer, probably since the
changes of 02a92e23f3 (see #4379), as a
possibly null page was dereferenced without checking, resulting in a
crash.

Fix this by adding a missing check.

Also rename DoGetNonNullPage() to TryGetNonNullPage() to make it more
clear that this function can return null and add a unit test checking
that calling AddPage(NULL) really works (or at least doesn't crash).

See https://github.com/wxWidgets/wxWidgets/pull/921
This commit is contained in:
Vadim Zeitlin
2018-09-18 00:33:59 +02:00
parent 39e19a8f8c
commit b88d5e08ce
5 changed files with 32 additions and 8 deletions

View File

@@ -493,11 +493,18 @@ int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
if ( allowed )
{
if ( oldSel != wxNOT_FOUND )
DoShowPage(DoGetNonNullPage(oldSel), false);
{
if ( wxWindow* const oldPage = TryGetNonNullPage(oldSel) )
{
DoShowPage(oldPage, false);
}
}
wxWindow* const page = DoGetNonNullPage(n);
page->SetSize(GetPageRect());
DoShowPage(page, true);
if ( wxWindow* const page = TryGetNonNullPage(n) )
{
page->SetSize(GetPageRect());
DoShowPage(page, true);
}
// change selection now to ignore the selection change event
m_selection = n;