X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..8fdd04f882cd54893dcf0aff4940faac64e2efb9:/samples/notebook/notebook.cpp diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index b69850bd96..8e196ba498 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -1,12 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: notebook.cpp -// Purpose: wxNotebook demo +// Name: samples/notebook/notebook.cpp +// Purpose: a sample demonstrating notebook usage // Author: Julian Smart -// Modified by: +// Modified by: Dimitri Schoolwerth // Created: 26/10/98 // RCS-ID: $Id$ -// Copyright: (c) -// Licence: wxWindows licence +// Copyright: (c) 1998-2002 wxWidgets team +// License: wxWindows license ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". @@ -20,295 +20,526 @@ #include "wx/wx.h" #endif +#include "wx/imaglist.h" +#include "wx/artprov.h" #include "notebook.h" -// If 1, use a dialog. Otherwise use a frame. -#define USE_TABBED_DIALOG 0 -#if USE_TABBED_DIALOG -MyDialog* dialog = (MyDialog *) NULL; -#else // !USE_TABBED_DIALOG -MyFrame* frame = (MyFrame *) NULL; -#endif // USE_TABBED_DIALOG - IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { - // Create the main window -#if USE_TABBED_DIALOG - dialog = new MyDialog((wxFrame *) NULL, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE); - - dialog->ShowModal(); - - // Quit immediately the dialog has been dismissed - return FALSE; -#else - frame = new MyFrame((wxFrame*) NULL, -1, "Notebook", wxPoint(-1, -1), wxSize(465, 390) ); - - // Problem with generic wxNotebook implementation whereby it doesn't size properly unless - // you set the size again -#if defined(__WIN16__) - int width, height; - frame->GetSize(& width, & height); - frame->SetSize(-1, -1, width, height); + // Create the main window + MyFrame *frame = new MyFrame( wxT("Notebook sample") ); + + // Problem with generic wxNotebook implementation whereby it doesn't size + // properly unless you set the size again +#if defined(__WXMOTIF__) + int width, height; + frame->GetSize(& width, & height); + frame->SetSize(wxDefaultPosition.x, wxDefaultPosition.y, width, height); #endif - return TRUE; -#endif + frame->Show(); + + return true; } -void MyApp::InitTabView(wxNotebook* notebook, wxPanel* window) +MyNotebook::MyNotebook(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, long style) + : wxNotebook(parent, id, pos, size, style) { - m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25)); - m_cancelButton = new wxButton(window, ID_DELETE_PAGE, "&Delete page", wxPoint(-1, -1), wxSize(80, 25)); - m_addPageButton = new wxButton(window, ID_ADD_PAGE, "&Add page", wxPoint(-1, -1), wxSize(80, 25)); - m_insertPageButton = new wxButton(window, ID_INSERT_PAGE, "&Insert page", wxPoint(-1, -1), wxSize(80, 25)); - m_nextPageButton = new wxButton(window, ID_NEXT_PAGE, "&Next page", wxPoint(-1, -1), wxSize(80, 25)); - m_okButton->SetDefault(); - - wxLayoutConstraints *c; - c = new wxLayoutConstraints; - c->right.SameAs(window, wxRight, 4); - c->bottom.SameAs(window, wxBottom, 4); - c->height.AsIs(); - c->width.AsIs(); - m_addPageButton->SetConstraints(c); - - c = new wxLayoutConstraints; - c->right.SameAs(m_addPageButton, wxLeft, 4); - c->bottom.SameAs(window, wxBottom, 4); - c->height.AsIs(); - c->width.AsIs(); - m_insertPageButton->SetConstraints(c); - - c = new wxLayoutConstraints; - c->right.SameAs(m_insertPageButton, wxLeft, 4); - c->bottom.SameAs(window, wxBottom, 4); - c->height.AsIs(); - c->width.AsIs(); - m_nextPageButton->SetConstraints(c); - - c = new wxLayoutConstraints; - c->right.SameAs(m_nextPageButton, wxLeft, 4); - c->bottom.SameAs(window, wxBottom, 4); - c->height.AsIs(); - c->width.AsIs(); - m_cancelButton->SetConstraints(c); - - c = new wxLayoutConstraints; - c->right.SameAs(m_cancelButton, wxLeft, 4); - c->bottom.SameAs(window, wxBottom, 4); - c->height.AsIs(); - c->width.AsIs(); - m_okButton->SetConstraints(c); - - // Add some panels - wxPanel *panel1 = new wxPanel(notebook, -1); - // panel1->SetBackgroundColour(wxColour("RED")); - (void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10)); - (void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150)); - - notebook->AddPage(panel1, "Cat", TRUE); - - wxPanel *panel2 = new wxPanel(notebook, -1); - panel2->SetAutoLayout(TRUE); - panel2->SetBackgroundColour(wxColour("BLUE")); - - wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" }; - wxRadioBox *radiobox = new wxRadioBox(panel2, -1, "Choose one", - wxDefaultPosition, wxDefaultSize, 5, animals, - 2, wxRA_SPECIFY_ROWS); - - c = new wxLayoutConstraints; - c->left.SameAs(panel2, wxLeft, 10); - c->top.SameAs(panel2, wxTop, 5); - c->height.PercentOf(panel2, wxHeight, 50); - c->right.SameAs(panel2, wxRight, 10); - radiobox->SetConstraints(c); - - wxRadioBox *radiobox2 = new wxRadioBox(panel2, -1, "Choose one", - wxDefaultPosition, wxDefaultSize, - 5, animals, - 2, wxRA_SPECIFY_ROWS); - - c = new wxLayoutConstraints; - c->left.SameAs(radiobox, wxLeft); - c->height.AsIs(); - c->top.Below(radiobox, 5); - c->right.SameAs(radiobox, wxRight); - radiobox2->SetConstraints(c); - - notebook->AddPage(panel2, "Dog"); - - wxPanel *panel3 = new wxPanel(notebook, -1); - panel3->SetBackgroundColour(wxColour("WHITE")); - notebook->AddPage(panel3, "Goat"); - - wxPanel *panel4 = new wxPanel(notebook, -1); - panel4->SetBackgroundColour(wxColour("YELLOW")); - notebook->AddPage(panel4, "Sheep"); - - wxPanel *panel5 = new wxPanel(notebook, -1); - panel5->SetBackgroundColour(wxColour("MAGENTA")); - (void)new wxStaticText(panel5, -1, "This page has been inserted, not added", wxPoint(10, 10) ); - notebook->InsertPage(0, panel5, "Sheep"); - - notebook->SetSelection(2); + // Empty } -#if USE_TABBED_DIALOG +wxPanel *MyNotebook::CreatePage(const wxString&pageName) +{ + if + ( + pageName.Contains(INSERTED_PAGE_NAME) + || pageName.Contains(ADDED_PAGE_NAME) + ) + { + return CreateUserCreatedPage(); + } + + if (pageName == I_WAS_INSERTED_PAGE_NAME) + { + return CreateInsertPage(); + } -BEGIN_EVENT_TABLE(MyDialog, wxDialog) - EVT_BUTTON(wxID_OK, MyDialog::OnOK) - EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK) -END_EVENT_TABLE() + if (pageName == VETO_PAGE_NAME) + { + return CreateVetoPage(); + } + + if (pageName == RADIOBUTTONS_PAGE_NAME) + { + return CreateRadioButtonsPage(); + } + + + if (pageName == MAXIMIZED_BUTTON_PAGE_NAME) + { + return CreateBigButtonPage(); + } -MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long windowStyle): - wxDialog(parent, id, title, pos, size, windowStyle) + wxFAIL; + + return (wxPanel *) NULL; +} + +wxPanel *MyNotebook::CreateUserCreatedPage() { - Init(); + wxPanel *panel = new wxPanel(this); + + (void) new wxButton( panel, wxID_ANY, wxT("Button"), + wxPoint(10, 10), wxDefaultSize ); + + return panel; } -void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) +wxPanel *MyNotebook::CreateRadioButtonsPage() { - EndModal(wxID_OK); + wxPanel *panel = new wxPanel(this); + + wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"), + wxT("Sabre-toothed tiger"), wxT("T Rex") }; + + wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"), + wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS); + + wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"), + wxT("Another") }; + + wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY, + wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize, + 4, computers, 0, wxRA_SPECIFY_COLS); + + wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); + sizerPanel->Add(radiobox1, 2, wxEXPAND); + sizerPanel->Add(radiobox2, 1, wxEXPAND); + panel->SetSizer(sizerPanel); + + return panel; } -void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) +wxPanel *MyNotebook::CreateVetoPage() { - EndModal(wxID_CANCEL); + wxPanel *panel = new wxPanel(this); + + (void) new wxStaticText( panel, wxID_ANY, + wxT("This page intentionally left blank"), wxPoint(10, 10) ); + + return panel; } -void MyDialog::Init() +wxPanel *MyNotebook::CreateBigButtonPage() { - m_notebook = new wxNotebook(this, ID_NOTEBOOK); + wxPanel *panel = new wxPanel(this); - wxLayoutConstraints* c = new wxLayoutConstraints; - c->left.SameAs(this, wxLeft, 4); - c->right.SameAs(this, wxRight, 4); - c->top.SameAs(this, wxTop, 4); - c->bottom.SameAs(this, wxBottom, 40); + wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button")); - m_notebook->SetConstraints(c); + wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); + sizerPanel->Add(buttonBig, 1, wxEXPAND); + panel->SetSizer(sizerPanel); - wxGetApp().InitTabView(m_notebook, this); + return panel; +} - SetAutoLayout(TRUE); - Layout(); - Centre(wxBOTH); +wxPanel *MyNotebook::CreateInsertPage() +{ + wxPanel *panel = new wxPanel(this); + + panel->SetBackgroundColour( wxColour( wxT("MAROON") ) ); + (void) new wxStaticText( panel, wxID_ANY, + wxT("This page has been inserted, not added."), wxPoint(10, 10) ); + + return panel; } -#else // USE_TABBED_DIALOG +void MyNotebook::CreateInitialPages() +{ + // Create and add some panels to the notebook + + wxPanel *panel = CreateRadioButtonsPage(); + AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex() ); -BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_BUTTON(wxID_OK, MyFrame::OnOK) - EVT_BUTTON(ID_DELETE_PAGE, MyFrame::OnDeletePage) - EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage) - EVT_BUTTON(ID_INSERT_PAGE, MyFrame::OnInsertPage) - EVT_BUTTON(ID_NEXT_PAGE, MyFrame::OnNextPage) - EVT_IDLE(MyFrame::OnIdle) -END_EVENT_TABLE() + panel = CreateVetoPage(); + AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex() ); + + panel = CreateBigButtonPage(); + AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex() ); -MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long windowStyle): - wxFrame(parent, id, title, pos, size, windowStyle) + panel = CreateInsertPage(); + InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex() ); + + + SetSelection(1); +} + +int MyNotebook::GetIconIndex() const { - m_panel = (wxPanel*) NULL; - m_notebook = (wxNotebook*) NULL; - Init(); + if (m_imageList) + { + int nImages = m_imageList->GetImageCount(); + if (nImages > 0) + { + return GetPageCount() % nImages; + } + } + + return -1; } -void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) +MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, + long style) + : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style) { - static size_t s_pageAdded = 0; + m_panel = (wxPanel *) NULL; + m_notebook = (MyNotebook *) NULL; + + // create a dummy image list with a few icons + wxSize imageSize(32, 32); + + m_imageList + = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() ); + + m_imageList->Add + ( + wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize) + ); + + m_imageList->Add + ( + wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize) + ); + + m_imageList->Add + ( + wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize) + ); + + m_imageList->Add + ( + wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize) + ); + + m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); + + // Create remaining controls + + // must be in sync with Orient enum + wxString strOrientations[] = + { + wxT("&Top"), + wxT("&Bottom"), + wxT("&Left"), + wxT("&Right"), + }; + + wxASSERT_MSG( WXSIZEOF(strOrientations) == ORIENT_MAX, + wxT("Forgot to update something") ); + + m_radioOrient = new wxRadioBox + ( + m_panel, ID_RADIO_ORIENT, + wxT("&Tab orientation"), + wxDefaultPosition, wxDefaultSize, + WXSIZEOF(strOrientations), strOrientations, + 1, wxRA_SPECIFY_COLS + ); + + m_chkShowImages = new wxCheckBox( m_panel, ID_CHK_SHOWIMAGES, + wxT("&Show images") ); +#ifndef TEST_LISTBOOK + m_chkMultiLine = new wxCheckBox( m_panel, ID_CHK_MULTILINE, + wxT("&Multiple lines") ); +#endif // !TEST_LISTBOOK + + m_btnAddPage = new wxButton( m_panel, ID_BTN_ADD_PAGE, wxT("&Add page") ); + + m_btnInsertPage = new wxButton( m_panel, ID_BTN_INSERT_PAGE, + wxT("&Insert 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") ); + + m_btnExit = new wxButton( m_panel, wxID_OK, wxT("&Exit") ); + m_btnExit->SetDefault(); + + m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, + wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); + + m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); + + // Set sizers + m_sizerFrame = new wxBoxSizer(wxVERTICAL); + + m_sizerTop = new wxBoxSizer(wxHORIZONTAL); + + wxBoxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL); + sizerLeft->Add(m_radioOrient, 0, wxEXPAND); + sizerLeft->Add(m_chkShowImages, 0, wxEXPAND | wxTOP, 4); +#ifndef TEST_LISTBOOK + sizerLeft->Add(m_chkMultiLine, 0, wxEXPAND | wxTOP, 4); +#endif // !TEST_LISTBOOK + + sizerLeft->Add(0, 0, 1); // Spacer - wxPanel *panel = new wxPanel( m_notebook, -1 ); - (void)new wxButton( panel, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) ); + sizerLeft->Add(m_btnAddPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); + sizerLeft->Add(m_btnInsertPage, 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 + + sizerLeft->Add(m_btnExit, 0, wxEXPAND); + + m_sizerTop->Add(sizerLeft, 0, wxEXPAND | wxALL, 4); + + + m_sizerFrame->Add(m_sizerTop, 1, wxEXPAND); + m_sizerFrame->Add(m_text, 0, wxEXPAND); + + ReInitNotebook(); + m_notebook->CreateInitialPages(); + + m_panel->SetSizer(m_sizerFrame); + + m_sizerFrame->Fit(this); + m_sizerFrame->SetSizeHints(this); + + Centre(wxBOTH); - m_notebook->AddPage( panel, wxString::Format("Added %u", ++s_pageAdded) ); } -void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event)) +MyFrame::~MyFrame() { - static size_t s_pageIns = 0; + delete wxLog::SetActiveTarget(m_logTargetOld); - wxPanel *panel = new wxPanel( m_notebook, -1 ); - (void)new wxButton( panel, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) ); + if (m_imageList) + { + delete m_imageList; + m_imageList = (wxImageList *) NULL; + } - m_notebook->InsertPage(0, panel, wxString::Format("Inserted %u", ++s_pageIns) ); - m_notebook->SetSelection(0); } -wxWindow *test = NULL; - -void MyFrame::OnDeletePage(wxCommandEvent& WXUNUSED(event)) +void MyFrame::ReInitNotebook() { - if (m_notebook->GetPageCount() > 0) - m_notebook->DeletePage( m_notebook->GetPageCount()-1 ); + int flags; -/* - if (test) + switch ( m_radioOrient->GetSelection() ) { - m_notebook->AddPage( test, "Readded" ); - test = NULL; + default: + wxFAIL_MSG( wxT("unknown notebook orientation") ); + // fall through + + case ORIENT_TOP: + flags = wxNB_TOP; + break; + + case ORIENT_BOTTOM: + flags = wxNB_BOTTOM; + break; + + case ORIENT_LEFT: + flags = wxNB_LEFT; + break; + + case ORIENT_RIGHT: + flags = wxNB_RIGHT; + break; } - else + +#ifndef TEST_LISTBOOK + if ( m_chkMultiLine->IsChecked() ) + flags |= wxNB_MULTILINE; +#endif // !TEST_LISTBOOK + + MyNotebook *notebook = m_notebook; + + m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK, + wxDefaultPosition, wxDefaultSize, + flags); + + if ( m_chkShowImages->IsChecked() ) + { + m_notebook->SetImageList(m_imageList); + } + + if (notebook) { - test = m_notebook->GetPage( m_notebook->GetPageCount()-1 ); - m_notebook->RemovePage( m_notebook->GetPageCount()-1 ); + int sel = notebook->GetSelection(); + + int count = notebook->GetPageCount(); + for (int n = 0; n < count; n++) + { + wxString str = notebook->GetPageText(n); + + wxWindow *page = m_notebook->CreatePage(str); + m_notebook->AddPage(page, str, false, m_notebook->GetIconIndex() ); + } + + if (m_sizerNotebook) + { + m_sizerTop->Remove(m_sizerNotebook); + } + + delete notebook; + + // restore selection + if (sel != -1) + { + m_notebook->SetSelection(sel); + } + } -*/ + + + m_sizerNotebook = new wxBookCtrlSizer(m_notebook); + m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4); + m_sizerTop->Layout(); } -void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event)) +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_RADIOBOX(ID_RADIO_ORIENT, MyFrame::OnCheckOrRadioBox) + EVT_CHECKBOX(ID_CHK_SHOWIMAGES, MyFrame::OnCheckOrRadioBox) +#ifndef TEST_LISTBOOK + EVT_CHECKBOX(ID_CHK_MULTILINE, MyFrame::OnCheckOrRadioBox) +#endif // !TEST_LISTBOOK + + EVT_BUTTON(ID_BTN_ADD_PAGE, MyFrame::OnButtonAddPage) + EVT_BUTTON(ID_BTN_INSERT_PAGE, MyFrame::OnButtonInsertPage) + 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& WXUNUSED(event)) { - m_notebook->AdvanceSelection(); + ReInitNotebook(); +} + +void MyFrame::OnButtonAddPage( wxCommandEvent& WXUNUSED(event) ) +{ + static unsigned s_pageAdded = 0; + + wxPanel *panel = new wxPanel( m_notebook, wxID_ANY ); + (void) new wxButton( panel, wxID_ANY, wxT("First button"), + wxPoint(10, 10), wxDefaultSize ); + (void) new wxButton( panel, wxID_ANY, wxT("Second button"), + wxPoint(50, 100), wxDefaultSize ); + + m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), + ++s_pageAdded), true, m_notebook->GetIconIndex() ); } -void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) ) +void MyFrame::OnButtonInsertPage( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + static unsigned s_pageIns = 0; + + wxPanel *panel = m_notebook->CreateUserCreatedPage(); + + m_notebook->InsertPage( 0, panel, + wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false, + m_notebook->GetIconIndex() ); + + m_notebook->SetSelection(0); +} + +void MyFrame::OnButtonDeleteLastPage( wxCommandEvent& WXUNUSED(event) ) +{ + int page = m_notebook->GetPageCount(); + + if ( page != 0 ) + { + m_notebook->DeletePage(page - 1); + } } -void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) +void MyFrame::OnButtonDeleteCurPage( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + int sel = m_notebook->GetSelection(); + + if (sel != -1) + { + m_notebook->DeletePage(sel); + } } -void MyFrame::Init() +void MyFrame::OnButtonNextPage( wxCommandEvent& WXUNUSED(event) ) { - m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN); + m_notebook->AdvanceSelection(); +} - wxLayoutConstraints* c = new wxLayoutConstraints; - c->left.SameAs(this, wxLeft); - c->right.SameAs(this, wxRight); - c->top.SameAs(this, wxTop); - c->bottom.SameAs(this, wxBottom); - m_panel->SetConstraints(c); +void MyFrame::OnButtonExit( wxCommandEvent& WXUNUSED(event) ) +{ + Close(); +} - m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK); +void MyFrame::OnNotebook(wxNotebookEvent& event) +{ + wxString str = wxT("Unknown notebook event"); - c = new wxLayoutConstraints; - c->left.SameAs(m_panel, wxLeft, 4); - c->right.SameAs(m_panel, wxRight, 4); - c->top.SameAs(m_panel, wxTop, 4); - c->bottom.SameAs(m_panel, wxBottom, 40); + wxEventType eventType = event.GetEventType(); - m_notebook->SetConstraints(c); + if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) + { + str = wxT("Notebook changed"); + } + else if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) + { + int idx = event.GetOldSelection(); + if ( idx != -1 && m_notebook->GetPageText(idx) == VETO_PAGE_NAME ) + { + if + ( + wxMessageBox( + wxT("Are you sure you want to leave this notebook page?\n") + wxT("(This demonstrates veto-ing)"), + wxT("Notebook sample"), + wxICON_QUESTION | wxYES_NO, this) != wxYES ) + { + event.Veto(); + + return; + } + + } + + str = wxT("Notebook changing"); + } - wxGetApp().InitTabView(m_notebook, m_panel); + static int s_numNotebookEvents = 0; - m_panel->SetAutoLayout(TRUE); - SetAutoLayout(TRUE); + wxLogMessage(wxT("Notebook event #%d: %s (%d)"), + s_numNotebookEvents++, str.c_str(), eventType); - Centre(wxBOTH); + m_text->SetInsertionPointEnd(); - Show(TRUE); + event.Skip(); } -void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) +void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) { static int s_nPages = -1; static int s_nSel = -1; @@ -321,10 +552,18 @@ void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) s_nSel = nSel; wxString title; - title.Printf("Notebook (%d pages, selection: %d)", nPages, nSel); + title.Printf(wxT("Notebook (%d pages, selection: %d)"), nPages, nSel); SetTitle(title); } } -#endif // USE_TABBED_DIALOG +void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event) +{ + event.Enable( m_notebook->GetSelection() != -1 ); +} + +void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event) +{ + event.Enable( m_notebook->GetPageCount() != 0 ); +}