X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/76645ab3e55e068e8f1b7d8d752990a1d9a6199e..1e52188741389278cd99abf79218162c87024ba3:/samples/notebook/notebook.cpp diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index 3ed54df76a..ab4506cbd7 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -229,7 +229,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, ); m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, - wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER); + wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); // Create remaining controls @@ -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") ); @@ -271,16 +274,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, m_btnExit = new wxButton( m_panel, wxID_OK, wxT("&Exit") ); m_btnExit->SetDefault(); - m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK); - m_text = new wxTextCtrl(m_panel, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); - // Create the notebook's panels - m_notebook->CreateInitialPages(); - // Set sizers m_sizerFrame = new wxBoxSizer(wxVERTICAL); @@ -295,7 +293,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 @@ -310,6 +309,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, m_sizerFrame->Add(m_text, 0, wxEXPAND); ReInitNotebook(); + m_notebook->CreateInitialPages(); m_panel->SetSizer(m_sizerFrame); @@ -364,7 +364,7 @@ void MyFrame::ReInitNotebook() m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, - flags); + flags|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); if ( m_chkShowImages->IsChecked() ) { @@ -380,7 +380,7 @@ void MyFrame::ReInitNotebook() { wxString str = notebook->GetPageText(n); - wxNotebookPage *page = m_notebook->CreatePage(str); + wxWindow *page = m_notebook->CreatePage(str); m_notebook->AddPage(page, str, FALSE, m_notebook->GetIconIndex() ); } @@ -400,7 +400,7 @@ void MyFrame::ReInitNotebook() } - m_sizerNotebook = new wxNotebookSizer(m_notebook); + m_sizerNotebook = new wxBookCtrlSizer(m_notebook); m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4); m_sizerTop->Layout(); } @@ -411,36 +411,42 @@ 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) EVT_IDLE(MyFrame::OnIdle) END_EVENT_TABLE() -void MyFrame::OnCheckOrRadioBox(wxCommandEvent& event) +void MyFrame::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) { ReInitNotebook(); } void MyFrame::OnButtonAddPage( wxCommandEvent& WXUNUSED(event) ) { - static size_t s_pageAdded = 0; + static unsigned s_pageAdded = 0; wxPanel *panel = new wxPanel( m_notebook, -1 ); - (void) new wxButton( panel, -1, wxT("Button"), + (void) new wxButton( panel, -1, wxT("First 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) ) { - static size_t s_pageIns = 0; + static unsigned s_pageIns = 0; wxPanel *panel = m_notebook->CreateUserCreatedPage(); @@ -451,7 +457,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(); @@ -507,7 +523,7 @@ void MyFrame::OnNotebook(wxNotebookEvent& event) 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(); @@ -532,3 +548,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 ); +}