From 96d3780753c7f6acfa4e29c1365f8abbfaba8f8c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 Jun 1999 21:27:52 +0000 Subject: [PATCH] several notebook bugs fixed: 1. deleting the last page sets selection to -1 2. deleting the selected page unselects it first 3. adding page calls Layout() on it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2888 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/notebook/test.cpp | 25 ++++++++++++++++++++++--- samples/notebook/test.h | 5 ++++- src/msw/notebook.cpp | 16 ++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/samples/notebook/test.cpp b/samples/notebook/test.cpp index 9a35002ed6..6413033ed4 100644 --- a/samples/notebook/test.cpp +++ b/samples/notebook/test.cpp @@ -162,6 +162,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_BUTTON(ID_DELETE_PAGE, MyFrame::OnDeletePage) EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage) EVT_SIZE(MyFrame::OnSize) + EVT_IDLE(MyFrame::OnIdle) END_EVENT_TABLE() MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title, @@ -183,17 +184,17 @@ void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDeletePage(wxCommandEvent& WXUNUSED(event)) { - m_notebook->DeletePage( m_notebook->GetPageCount()-1 ); + m_notebook->DeletePage( m_notebook->GetPageCount()-1 ); } void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) ) { - this->Destroy(); + Destroy(); } void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) { - this->Destroy(); + Destroy(); } void MyFrame::Init(void) @@ -229,3 +230,21 @@ void MyFrame::OnSize(wxSizeEvent& event) m_panel->Layout(); } +void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) +{ + static int s_nPages = -1; + static int s_nSel = -1; + + int nPages = m_notebook->GetPageCount(); + int nSel = m_notebook->GetSelection(); + if ( nPages != s_nPages || nSel != s_nSel ) + { + s_nPages = nPages; + s_nSel = nSel; + + wxString title; + title.Printf("Notebook (%d pages, selection: %d)", nPages, nSel); + + SetTitle(title); + } +} diff --git a/samples/notebook/test.h b/samples/notebook/test.h index f9f482ecf8..70b52a00e4 100644 --- a/samples/notebook/test.h +++ b/samples/notebook/test.h @@ -52,7 +52,10 @@ public: void OnAddPage(wxCommandEvent& event); void OnDeletePage(wxCommandEvent& event); void OnSize(wxSizeEvent& event); - void Init(void); + void OnIdle(wxIdleEvent& event); + + void Init(); + protected: wxNotebook* m_notebook; wxPanel* m_panel; // Panel containing notebook and OK/Cancel/Help diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index d6c5fc5234..d94b86b315 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -274,11 +274,22 @@ bool wxNotebook::DeletePage(int nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("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_aPages[nPage]; m_aPages.Remove(nPage); + if ( m_aPages.IsEmpty() ) { + // no selection if the notebook became empty + m_nSelection = -1; + } + return TRUE; } @@ -370,6 +381,11 @@ bool wxNotebook::InsertPage(int nPage, // this updates internal flag too - otherwise it will get out of sync pPage->Show(FALSE); + // FIXME this is ugly, I'm breaking my own rules... but needed to get display + // right (why?) + wxSizeEvent event; + OnSize(event); + return TRUE; } -- 2.49.0