X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5e173f35d2a8177371d13d059d9f897e2c4f98be..084db46c8b4f3f8d5e6a5f55e09e04f5a680c8a5:/samples/widgets/notebook.cpp diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 92d8c089d5..8534da6d87 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -41,9 +41,10 @@ #include "wx/sizer.h" #include "wx/notebook.h" +#include "wx/artprov.h" #include "widgets.h" - +#if 1 #include "icons/notebook.xpm" // ---------------------------------------------------------------------------- @@ -133,6 +134,10 @@ protected: // get the numeric value of text ctrl int GetTextValue(wxTextCtrl *text) const; + // is the value in range? + bool IsValidValue(int val) const + { return (val >= 0) && (val < m_notebook->GetPageCount()); } + // the controls // ------------ @@ -279,7 +284,7 @@ NotebookWidgetsPage::NotebookWidgetsPage(wxNotebook *notebook, wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL); m_notebook = new wxNotebook(this, NotebookPage_Notebook); sizerRight->Add(m_notebook, 1, wxGROW | wxALL, 5); - sizerRight->SetMinSize(250, 0); + sizerRight->SetMinSize(150, 0); m_sizerNotebook = sizerRight; // save it to modify it later // the 3 panes panes compose the window @@ -320,10 +325,11 @@ void NotebookWidgetsPage::CreateImageList() { // create a dummy image list with a few icons m_imageList = new wxImageList(32, 32); - m_imageList->Add(wxTheApp->GetStdIcon(wxICON_INFORMATION)); - m_imageList->Add(wxTheApp->GetStdIcon(wxICON_QUESTION)); - m_imageList->Add(wxTheApp->GetStdIcon(wxICON_WARNING)); - m_imageList->Add(wxTheApp->GetStdIcon(wxICON_ERROR)); + wxSize size(32, 32); + m_imageList->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size)); + m_imageList->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size)); + m_imageList->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size)); + m_imageList->Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, size)); } m_notebook->SetImageList(m_imageList); @@ -378,21 +384,20 @@ void NotebookWidgetsPage::CreateNotebook() if ( notebook ) { - int sel = notebook->GetSelection(); + const int sel = notebook->GetSelection(); + + const int count = notebook->GetPageCount(); - int count = notebook->GetPageCount(); + // recreate the pages for ( int n = 0; n < count; n++ ) { - wxNotebookPage *page = notebook->GetPage(0); - page->Reparent(m_notebook); - - m_notebook->AddPage(page, notebook->GetPageText(0), FALSE, - notebook->GetPageImage(0)); - - notebook->RemovePage(0); + m_notebook->AddPage(CreateNewPage(), + notebook->GetPageText(n), + FALSE, + notebook->GetPageImage(n)); } - m_sizerNotebook->Remove(notebook); + m_sizerNotebook->Detach( notebook ); delete notebook; // restore selection @@ -457,7 +462,7 @@ void NotebookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event)) void NotebookWidgetsPage::OnButtonSelectPage(wxCommandEvent& event) { int pos = GetTextValue(m_textSelect); - wxCHECK_RET( pos >= 0, _T("button should be disabled") ); + wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); m_notebook->SetSelection(pos); } @@ -471,7 +476,7 @@ void NotebookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event)) void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event)) { int pos = GetTextValue(m_textInsert); - wxCHECK_RET( pos >= 0, _T("button should be disabled") ); + wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); m_notebook->InsertPage(pos, CreateNewPage(), _T("Inserted page"), FALSE, GetIconIndex()); @@ -480,24 +485,24 @@ void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event)) void NotebookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event)) { int pos = GetTextValue(m_textRemove); - wxCHECK_RET( pos >= 0, _T("button should be disabled") ); + wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); m_notebook->DeletePage(pos); } void NotebookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event) { - event.Enable( GetTextValue(m_textSelect) >= 0 ); + event.Enable( IsValidValue(GetTextValue(m_textSelect)) ); } void NotebookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event) { - event.Enable( GetTextValue(m_textInsert) >= 0 ); + event.Enable( IsValidValue(GetTextValue(m_textInsert)) ); } void NotebookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event) { - event.Enable( GetTextValue(m_textRemove) >= 0 ); + event.Enable( IsValidValue(GetTextValue(m_textRemove)) ); } void NotebookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) @@ -541,3 +546,4 @@ void NotebookWidgetsPage::OnPageChanged(wxNotebookEvent& event) event.Skip(); } +#endif