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
This commit is contained in:
Vadim Zeitlin
1999-06-24 21:27:52 +00:00
parent b1cf23dc26
commit 96d3780753
3 changed files with 42 additions and 4 deletions

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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;
}