From c21b99e0e2f3976d26d9b7a8057d47e27f055523 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Jun 2012 16:33:18 +0000 Subject: [PATCH] Add wxRibbonBar::DeletePage() and ClearPages() methods. Also add a trivial GetPageCount() helper. Closes #14437. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71888 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/ribbon/bar.h | 4 +++ interface/wx/ribbon/bar.h | 26 +++++++++++++- samples/ribbon/ribbondemo.cpp | 23 ++++++++++-- src/ribbon/bar.cpp | 67 +++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 4be062302f..a3d08e1243 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -542,6 +542,7 @@ All (GUI): - Send wxEVT_UPDATE_UI for wxRibbonButtonBar and wxRibbonToolBar (Emilien Kia). - Add InsertXXXButton() to wxRibbonButtonBar and wxRibbonToolBar (Emilien Kia). - Allow enabling/disabling and toggling tools in wxRibbonToolBar (Emilien Kia). +- Add wxRibbonBar::DeletePage() and ClearPages() methods (Emilien Kia). - Implement support for extension button to wxRibbonPanel (Emilien Kia). - Fix multiple item selection in generic wxTreeCtrl (Igor Korot). - Implement wxMenuBar::IsEnabledTop() for all major ports (Igor Korot). diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index a1cb1c2d6d..99d0ef50d0 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -113,8 +113,12 @@ public: bool SetActivePage(wxRibbonPage* page); int GetActivePage() const; wxRibbonPage* GetPage(int n); + size_t GetPageCount() const; bool DismissExpandedPanel(); + void DeletePage(size_t n); + void ClearPages(); + void ShowPanels(bool show = true); void HidePanels() { ShowPanels(false); } bool ArePanelsShown() const { return m_arePanelsShown; } diff --git a/interface/wx/ribbon/bar.h b/interface/wx/ribbon/bar.h index 00a53cb199..112e4c0deb 100644 --- a/interface/wx/ribbon/bar.h +++ b/interface/wx/ribbon/bar.h @@ -206,14 +206,38 @@ public: */ wxRibbonPage* GetPage(int n); + /** + Get the number of pages in this bar. + + @since 2.9.4 + */ + size_t GetPageCount() const; + /** Dismiss the expanded panel of the currently active page. - Calls and returns the value fromwxRibbonPage::DismissExpandedPanel() + Calls and returns the value from wxRibbonPage::DismissExpandedPanel() for the currently active page, or @false if there is no active page. */ bool DismissExpandedPanel(); + /** + Delete a single page from this ribbon bar. + + The user must call wxRibbonBar::Realize() after one (or more) calls to + this function. + + @since 2.9.4 + */ + void DeletePage(size_t n); + + /** + Delete all pages from the ribbon bar. + + @since 2.9.4 + */ + void ClearPages(); + /** Shows or hides the panel area of the ribbon bar. diff --git a/samples/ribbon/ribbondemo.cpp b/samples/ribbon/ribbondemo.cpp index 65a3b95b2f..30bbdd7da2 100644 --- a/samples/ribbon/ribbondemo.cpp +++ b/samples/ribbon/ribbondemo.cpp @@ -82,7 +82,8 @@ public: ID_UI_CHECK_UPDATED, ID_CHANGE_TEXT1, ID_CHANGE_TEXT2, - ID_UI_CHANGE_TEXT_UPDATED + ID_UI_CHANGE_TEXT_UPDATED, + ID_REMOVE_PAGE }; void OnEnableUpdateUI(wxUpdateUIEvent& evt); @@ -127,7 +128,7 @@ public: void OnPositionLeftIcons(wxCommandEvent& evt); void OnPositionLeftBoth(wxCommandEvent& evt); void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt); - + void OnRemovePage(wxRibbonButtonBarEvent& evt); void OnTogglePanels(wxCommandEvent& evt); void OnExtButton(wxRibbonPanelEvent& evt); @@ -226,6 +227,7 @@ EVT_MENU(ID_POSITION_TOP_ICONS, MyFrame::OnPositionTopIcons) EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth) EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS, MyFrame::OnTogglePanels) EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton) +EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage) END_EVENT_TABLE() #include "align_center.xpm" @@ -386,7 +388,12 @@ MyFrame::MyFrame() bar->AddButton(ID_UI_CHANGE_TEXT_UPDATED, wxT("Zero"), ribbon_xpm); } new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm); - new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm); + { + wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm); + wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Page manipulation"), ribbon_xpm); + wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY); + bar->AddButton(ID_REMOVE_PAGE, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE, wxART_OTHER, wxSize(24, 24))); + } m_ribbon->Realize(); @@ -967,3 +974,13 @@ void MyFrame::SetArtProvider(wxRibbonArtProvider *prov) m_ribbon->Thaw(); GetSizer()->Layout(); } + +void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt)) +{ + size_t n = m_ribbon->GetPageCount(); + if(n > 0) + { + m_ribbon->DeletePage(n-1); + m_ribbon->Realize(); + } +} diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index 625324fa7d..7ad41b70be 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -20,6 +20,7 @@ #include "wx/ribbon/bar.h" #include "wx/ribbon/art.h" #include "wx/dcbuffer.h" +#include "wx/app.h" #ifndef WX_PRECOMP #endif @@ -275,6 +276,72 @@ wxRibbonPage* wxRibbonBar::GetPage(int n) return m_pages.Item(n).page; } +size_t wxRibbonBar::GetPageCount() const +{ + return m_pages.GetCount(); +} + +void wxRibbonBar::DeletePage(size_t n) +{ + if(n < m_pages.GetCount()) + { + wxRibbonPage *page = m_pages.Item(n).page; + + // Schedule page object for destruction and not destroying directly + // as this function can be called in an event handler and page functions + // can be called afeter removing. + // Like in wxRibbonButtonBar::OnMouseUp + if(!wxTheApp->IsScheduledForDestruction(page)) + { + wxTheApp->ScheduleForDestruction(page); + } + + m_pages.RemoveAt(n); + + if(m_current_page == static_cast(n)) + { + m_current_page = -1; + + if(m_pages.GetCount() > 0) + { + if(n >= m_pages.GetCount()) + { + SetActivePage(m_pages.GetCount() - 1); + } + else + { + SetActivePage(n - 1); + } + } + } + else if(m_current_page > static_cast(n)) + { + m_current_page--; + } + } +} + +void wxRibbonBar::ClearPages() +{ + size_t i; + for(i=0; iIsScheduledForDestruction(page)) + { + wxTheApp->ScheduleForDestruction(page); + } + } + m_pages.Empty(); + Realize(); + m_current_page = -1; + Refresh(); +} + bool wxRibbonBar::SetActivePage(size_t page) { if(m_current_page == (int)page) -- 2.45.2