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") );
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
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)
static size_t s_pageAdded = 0;
wxPanel *panel = new wxPanel( m_notebook, -1 );
- (void) new wxButton( panel, -1, wxT("Button"),
+ (void) new wxButton( panel, -1, wxT("Frist button"),
wxPoint(10, 10), wxSize(-1, -1) );
+ (void) new wxButton( panel, -1, wxT("Second button"),
+ wxPoint(50, 100), wxSize(-1, -1) );
m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
- ++s_pageAdded), FALSE, m_notebook->GetIconIndex() );
+ ++s_pageAdded), TRUE, m_notebook->GetIconIndex() );
}
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();
static int s_numNotebookEvents = 0;
wxLogMessage(wxT("Notebook event #%d: %s (%d)"),
- s_numNotebookEvents++, str, eventType);
+ s_numNotebookEvents++, str.c_str(), eventType);
m_text->SetInsertionPointEnd();
SetTitle(title);
}
}
+
+void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event)
+{
+ event.Enable( m_notebook->GetSelection() != -1 );
+}
+
+void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event)
+{
+ event.Enable( m_notebook->GetPageCount() != 0 );
+}