From 10199e27d54df4a0a2a7b2577645ce4561e8ed5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 2 Jul 2001 19:37:51 +0000 Subject: [PATCH] fixed deleting pages from the notebook git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/notebook.h | 2 +- src/common/nbkbase.cpp | 11 +++++++++++ src/gtk/notebook.cpp | 17 ++++++----------- src/gtk1/notebook.cpp | 17 ++++++----------- src/msw/notebook.cpp | 7 +++---- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/wx/notebook.h b/include/wx/notebook.h index ac8e965466..0a05ec9120 100644 --- a/include/wx/notebook.h +++ b/include/wx/notebook.h @@ -155,7 +155,7 @@ public: protected: // remove the page and return a pointer to it - virtual wxNotebookPage *DoRemovePage(int page) = 0; + virtual wxNotebookPage *DoRemovePage(int page); // common part of all ctors void Init(); diff --git a/src/common/nbkbase.cpp b/src/common/nbkbase.cpp index da418151d9..aabd7476dd 100644 --- a/src/common/nbkbase.cpp +++ b/src/common/nbkbase.cpp @@ -113,6 +113,17 @@ bool wxNotebookBase::DeletePage(int nPage) return TRUE; } +wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage) +{ + wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL, + _T("invalid page index in wxNotebookBase::DoRemovePage()") ); + + wxNotebookPage *pageRemoved = m_pages[nPage]; + m_pages.Remove(nPage); + + return pageRemoved; +} + int wxNotebookBase::GetNextPage(bool forward) const { int nPage; diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 1754454371..7976e5cd15 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -522,14 +522,11 @@ bool wxNotebook::DeleteAllPages() wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") ); - return TRUE; + return wxNotebookBase::DeleteAllPages(); } bool wxNotebook::DeletePage( int page ) { - wxGtkNotebookPage* nb_page = GetNotebookPage(page); - wxCHECK_MSG( nb_page, FALSE, _T("invalid page in wxNotebook::DeletePage") ); - // GTK sets GtkNotebook.cur_page to NULL before sending the switch page // event so we have to store the selection internally if ( m_selection == -1 ) @@ -542,25 +539,23 @@ bool wxNotebook::DeletePage( int page ) } } - m_pagesData.DeleteObject( nb_page ); - + // it will call our DoRemovePage() to do the real work return wxNotebookBase::DeletePage(page); } wxNotebookPage *wxNotebook::DoRemovePage( int page ) { - wxGtkNotebookPage* nb_page = GetNotebookPage(page); - - wxCHECK_MSG( nb_page, NULL, _T("wxNotebook::RemovePage: invalid page") ); + wxNotebookPage *client = wxNotebookBase::DoRemovePage(page); + if ( !client ) + return NULL; - wxNotebookPage *client = GetPage(page); gtk_widget_ref( client->m_widget ); gtk_widget_unrealize( client->m_widget ); gtk_widget_unparent( client->m_widget ); gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); - m_pagesData.DeleteObject( nb_page ); + m_pagesData.DeleteObject(GetNotebookPage(page)); return client; } diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 1754454371..7976e5cd15 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -522,14 +522,11 @@ bool wxNotebook::DeleteAllPages() wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") ); - return TRUE; + return wxNotebookBase::DeleteAllPages(); } bool wxNotebook::DeletePage( int page ) { - wxGtkNotebookPage* nb_page = GetNotebookPage(page); - wxCHECK_MSG( nb_page, FALSE, _T("invalid page in wxNotebook::DeletePage") ); - // GTK sets GtkNotebook.cur_page to NULL before sending the switch page // event so we have to store the selection internally if ( m_selection == -1 ) @@ -542,25 +539,23 @@ bool wxNotebook::DeletePage( int page ) } } - m_pagesData.DeleteObject( nb_page ); - + // it will call our DoRemovePage() to do the real work return wxNotebookBase::DeletePage(page); } wxNotebookPage *wxNotebook::DoRemovePage( int page ) { - wxGtkNotebookPage* nb_page = GetNotebookPage(page); - - wxCHECK_MSG( nb_page, NULL, _T("wxNotebook::RemovePage: invalid page") ); + wxNotebookPage *client = wxNotebookBase::DoRemovePage(page); + if ( !client ) + return NULL; - wxNotebookPage *client = GetPage(page); gtk_widget_ref( client->m_widget ); gtk_widget_unrealize( client->m_widget ); gtk_widget_unparent( client->m_widget ); gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); - m_pagesData.DeleteObject( nb_page ); + m_pagesData.DeleteObject(GetNotebookPage(page)); return client; } diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 707a2f1db4..c6c7066c5b 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -342,13 +342,12 @@ bool wxNotebook::DeletePage(int nPage) // remove one page from the notebook, without deleting wxNotebookPage *wxNotebook::DoRemovePage(int nPage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, wxT("notebook page out of range") ); + wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); + if ( !pageRemoved ) + return NULL; TabCtrl_DeleteItem(m_hwnd, nPage); - wxNotebookPage *pageRemoved = m_pages[nPage]; - m_pages.Remove(nPage); - if ( m_pages.IsEmpty() ) m_nSelection = -1; else -- 2.45.2