]> git.saurik.com Git - wxWidgets.git/commitdiff
Reset wxAuiNotebook selection to wxNOT_FOUND if it becomes empty.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Mar 2010 13:30:01 +0000 (13:30 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Mar 2010 13:30:01 +0000 (13:30 +0000)
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

samples/aui/auidemo.cpp
src/aui/auibook.cpp

index 519a3fb7148693d580ea9f787e3dc94b9d7a1bac..3d81eed0502695f2f736d058be4239e016d2bd2e 100644 (file)
@@ -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
index cc71a51e7b1be31d5e061a120afc9d3328b02ca1..c58da91092d1fd7b6ba1599d78641ac84b95919a 100644 (file)
@@ -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;
 }