diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index 519a3fb714..3d81eed050 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -152,6 +152,7 @@ private: void OnCustomizeToolbar(wxCommandEvent& evt); void OnAllowNotebookDnD(wxAuiNotebookEvent& evt); void OnNotebookPageClose(wxAuiNotebookEvent& evt); + void OnNotebookPageClosed(wxAuiNotebookEvent& evt); void OnExit(wxCommandEvent& evt); void OnAbout(wxCommandEvent& evt); void OnTabAlignment(wxCommandEvent &evt); @@ -649,6 +650,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_AUI_PANE_CLOSE(MyFrame::OnPaneClose) EVT_AUINOTEBOOK_ALLOW_DND(wxID_ANY, MyFrame::OnAllowNotebookDnD) EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, MyFrame::OnNotebookPageClose) + EVT_AUINOTEBOOK_PAGE_CLOSED(wxID_ANY, MyFrame::OnNotebookPageClosed) END_EVENT_TABLE() @@ -1325,6 +1327,19 @@ void MyFrame::OnNotebookPageClose(wxAuiNotebookEvent& evt) } } +void MyFrame::OnNotebookPageClosed(wxAuiNotebookEvent& evt) +{ + wxAuiNotebook* ctrl = (wxAuiNotebook*)evt.GetEventObject(); + + // selection should always be a valid index + wxASSERT_MSG( ctrl->GetSelection() < (int)ctrl->GetPageCount(), + wxString::Format("Invalid selection %d, only %d pages left", + ctrl->GetSelection(), + (int)ctrl->GetPageCount()) ); + + evt.Skip(); +} + void MyFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& evt) { // for the purpose of this test application, explicitly diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index cc71a51e7b..c58da91092 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -3264,12 +3264,11 @@ bool wxAuiNotebook::RemovePage(size_t page_idx) RemoveEmptyTabFrames(); - // set new active pane + m_curpage = wxNOT_FOUND; + + // set new active pane unless we're being destroyed anyhow if (new_active && !m_isBeingDeleted) - { - m_curpage = -1; SetSelectionToWindow(new_active); - } return true; }