From: Vadim Zeitlin Date: Sat, 6 Mar 2010 13:30:01 +0000 (+0000) Subject: Reset wxAuiNotebook selection to wxNOT_FOUND if it becomes empty. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/917f228a1ff11c0580386828da786f2d04b29999?ds=inline Reset wxAuiNotebook selection to wxNOT_FOUND if it becomes empty. The selection was 0 in a notebook without any pages which was wrong as it must always be less than the page count. Fix this in wxAuiNotebook itself and add an assert checking for this invariant to the sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63642 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- 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; }