From df7145da50005a9f512d8f3329b6ed2166e956d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Aug 2002 00:48:45 +0000 Subject: [PATCH] change the selection appropriately (and refresh it as needed) after deleting a notebook page git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16533 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/notebook.h | 2 -- src/msw/notebook.cpp | 59 +++++++++++++++------------------------ 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h index 142803edcc..b26643862e 100644 --- a/include/wx/msw/notebook.h +++ b/include/wx/msw/notebook.h @@ -89,8 +89,6 @@ public: // operations // ---------- - // remove one page from the notebook - bool DeletePage(int nPage); // remove all pages bool DeleteAllPages(); // adds a new page to the notebook (it will be deleted ny the notebook, diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 36e50c706b..065f983c79 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -304,48 +304,35 @@ void wxNotebook::SetTabSize(const wxSize& sz) // wxNotebook operations // ---------------------------------------------------------------------------- -// remove one page from the notebook -bool wxNotebook::DeletePage(int nPage) -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); - - if ( m_nSelection == nPage ) { - // advance selection backwards - the page being deleted shouldn't be left - // selected - AdvanceSelection(FALSE); - } - - TabCtrl_DeleteItem(m_hwnd, nPage); - - delete m_pages[nPage]; - m_pages.RemoveAt(nPage); - - if ( m_pages.IsEmpty() ) { - // no selection if the notebook became empty - m_nSelection = -1; - } - else - m_nSelection = TabCtrl_GetCurSel(m_hwnd); - - - return TRUE; -} - // remove one page from the notebook, without deleting wxNotebookPage *wxNotebook::DoRemovePage(int nPage) { - wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); - if ( !pageRemoved ) - return NULL; + wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); + if ( !pageRemoved ) + return NULL; - TabCtrl_DeleteItem(m_hwnd, nPage); + TabCtrl_DeleteItem(m_hwnd, nPage); + + if ( m_pages.IsEmpty() ) + { + // no selection any more, the notebook becamse empty + m_nSelection = -1; + } + else // notebook still not empty + { + // refresh the selected page and change it if it became invalid + if ( m_nSelection == GetPageCount() ) + { + m_nSelection--; + } - if ( m_pages.IsEmpty() ) - m_nSelection = -1; - else - m_nSelection = TabCtrl_GetCurSel(m_hwnd); + // force ChangePage() to really do something + int sel = m_nSelection; + m_nSelection = -1; + SetSelection(sel); + } - return pageRemoved; + return pageRemoved; } // remove all pages -- 2.45.2