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,
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)
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);
+ }
+}
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
{
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;
}
// 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;
}