From: Vadim Zeitlin Date: Fri, 16 Aug 2002 00:09:29 +0000 (+0000) Subject: added a command to delete last page and not only the current one X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3957448a34ce9f4860051ba292b35ad70f8fb9db added a command to delete last page and not only the current one git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16531 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index 3ed54df76a..9bfb7e0930 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -262,8 +262,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, m_btnInsertPage = new wxButton( m_panel, ID_BTN_INSERT_PAGE, wxT("&Insert page") ); - m_btnDeletePage = new wxButton( m_panel, ID_BTN_DELETE_PAGE, - wxT("&Delete page") ); + m_btnDeleteCurPage = new wxButton( m_panel, ID_BTN_DELETE_CUR_PAGE, + wxT("&Delete current page") ); + + m_btnDeleteLastPage = new wxButton( m_panel, ID_BTN_DELETE_LAST_PAGE, + wxT("Delete las&t page") ); m_btnNextPage = new wxButton( m_panel, ID_BTN_NEXT_PAGE, wxT("&Next page") ); @@ -295,7 +298,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, sizerLeft->Add(m_btnAddPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); sizerLeft->Add(m_btnInsertPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); - sizerLeft->Add(m_btnDeletePage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); + sizerLeft->Add(m_btnDeleteCurPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); + sizerLeft->Add(m_btnDeleteLastPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); sizerLeft->Add(m_btnNextPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); sizerLeft->Add(0, 0, 1); // Spacer @@ -411,10 +415,14 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_BUTTON(ID_BTN_ADD_PAGE, MyFrame::OnButtonAddPage) EVT_BUTTON(ID_BTN_INSERT_PAGE, MyFrame::OnButtonInsertPage) - EVT_BUTTON(ID_BTN_DELETE_PAGE, MyFrame::OnButtonDeletePage) + EVT_BUTTON(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnButtonDeleteCurPage) + EVT_BUTTON(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnButtonDeleteLastPage) EVT_BUTTON(ID_BTN_NEXT_PAGE, MyFrame::OnButtonNextPage) EVT_BUTTON(wxID_OK, MyFrame::OnButtonExit) + EVT_UPDATE_UI(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnUpdateUIBtnDeleteCurPage) + EVT_UPDATE_UI(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnUpdateUIBtnDeleteLastPage) + EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook) EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook) @@ -451,7 +459,17 @@ void MyFrame::OnButtonInsertPage( wxCommandEvent& WXUNUSED(event) ) m_notebook->SetSelection(0); } -void MyFrame::OnButtonDeletePage( wxCommandEvent& WXUNUSED(event) ) +void MyFrame::OnButtonDeleteLastPage( wxCommandEvent& WXUNUSED(event) ) +{ + int page = m_notebook->GetPageCount(); + + if ( page != 0 ) + { + m_notebook->DeletePage(page - 1); + } +} + +void MyFrame::OnButtonDeleteCurPage( wxCommandEvent& WXUNUSED(event) ) { int sel = m_notebook->GetSelection(); @@ -532,3 +550,13 @@ void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) SetTitle(title); } } + +void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event) +{ + event.Enable( m_notebook->GetSelection() != -1 ); +} + +void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event) +{ + event.Enable( m_notebook->GetPageCount() != 0 ); +} diff --git a/samples/notebook/notebook.h b/samples/notebook/notebook.h index ca8b05d3af..4bb0005270 100644 --- a/samples/notebook/notebook.h +++ b/samples/notebook/notebook.h @@ -60,15 +60,17 @@ public: void OnButtonAddPage(wxCommandEvent& event); void OnButtonInsertPage(wxCommandEvent& event); - void OnButtonDeletePage(wxCommandEvent& event); + void OnButtonDeleteCurPage(wxCommandEvent& event); + void OnButtonDeleteLastPage(wxCommandEvent& event); void OnButtonNextPage(wxCommandEvent& event); - void OnButtonExit(wxCommandEvent& event); void OnNotebook(wxNotebookEvent& event); - void OnIdle(wxIdleEvent& event); + void OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event); + void OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event); + void OnIdle(wxIdleEvent& event); private: wxLog *m_logTargetOld; @@ -83,7 +85,8 @@ private: wxButton *m_btnAddPage; wxButton *m_btnInsertPage; - wxButton *m_btnDeletePage; + wxButton *m_btnDeleteCurPage; + wxButton *m_btnDeleteLastPage; wxButton *m_btnNextPage; wxButton *m_btnExit; @@ -116,7 +119,8 @@ enum ID_CONTROLS ID_CHK_SHOWIMAGES, ID_BTN_ADD_PAGE, ID_BTN_INSERT_PAGE, - ID_BTN_DELETE_PAGE, + ID_BTN_DELETE_CUR_PAGE, + ID_BTN_DELETE_LAST_PAGE, ID_BTN_NEXT_PAGE, ID_NOTEBOOK };