Merge branch 'notebook-add-page-events'

Harmonize events sent by wxNotebook::AddPage(): they are now sent only
when adding any page except the first one if it is selected in all
ports.

See https://github.com/wxWidgets/wxWidgets/pull/1192
This commit is contained in:
Vadim Zeitlin
2019-01-30 17:38:51 +01:00
6 changed files with 76 additions and 23 deletions

View File

@@ -20,7 +20,9 @@
#endif // WX_PRECOMP
#include "wx/notebook.h"
#include "bookctrlbasetest.h"
#include "testableframe.h"
class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
{
@@ -118,4 +120,48 @@ void NotebookTestCase::NoEventsOnDestruction()
CHECK( m_numPageChanges == 1 );
}
TEST_CASE("wxNotebook::AddPageEvents", "[wxNotebook][AddPage][event]")
{
wxNotebook* const
notebook = new wxNotebook(wxTheApp->GetTopWindow(), wxID_ANY,
wxDefaultPosition, wxSize(400, 200));
CHECK( notebook->GetSelection() == wxNOT_FOUND );
EventCounter countPageChanging(notebook, wxEVT_NOTEBOOK_PAGE_CHANGING);
EventCounter countPageChanged(notebook, wxEVT_NOTEBOOK_PAGE_CHANGED);
// Add the first page, it is special.
notebook->AddPage(new wxPanel(notebook), "Initial page");
// The selection should have been changed.
CHECK( notebook->GetSelection() == 0 );
// But no events should have been generated.
CHECK( countPageChanging.GetCount() == 0 );
CHECK( countPageChanged.GetCount() == 0 );
// Add another page without selecting it.
notebook->AddPage(new wxPanel(notebook), "Unselected page");
// Selection shouldn't have changed.
CHECK( notebook->GetSelection() == 0 );
// And no events should have been generated, of course.
CHECK( countPageChanging.GetCount() == 0 );
CHECK( countPageChanged.GetCount() == 0 );
// Finally add another page and do select it.
notebook->AddPage(new wxPanel(notebook), "Selected page", true);
// It should have become selected.
CHECK( notebook->GetSelection() == 2 );
// And events for the selection change should have been generated.
CHECK( countPageChanging.GetCount() == 1 );
CHECK( countPageChanged.GetCount() == 1 );
}
#endif //wxUSE_NOTEBOOK