From 71a77e77d1738cd48d7505efda59ab8110d88766 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Sep 2012 20:01:12 +0000 Subject: [PATCH] Add wxRibbonButtonBar::GetItem(), GetItemById() and GetItemId(). Allow accessing the ribbon bar buttons either by index or ID. See #14630. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/ribbon/buttonbar.h | 4 ++++ interface/wx/ribbon/buttonbar.h | 23 +++++++++++++++++++++++ src/ribbon/buttonbar.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/include/wx/ribbon/buttonbar.h b/include/wx/ribbon/buttonbar.h index 440a6c2af0..216d6e2a2e 100644 --- a/include/wx/ribbon/buttonbar.h +++ b/include/wx/ribbon/buttonbar.h @@ -126,6 +126,10 @@ public: wxObject* client_data = NULL); virtual size_t GetButtonCount() const; + virtual wxRibbonButtonBarButtonBase *GetItem(size_t n) const; + virtual wxRibbonButtonBarButtonBase *GetItemById(int id) const; + virtual int GetItemId(wxRibbonButtonBarButtonBase *button) const; + virtual bool Realize(); virtual void ClearButtons(); diff --git a/interface/wx/ribbon/buttonbar.h b/interface/wx/ribbon/buttonbar.h index e7e80e806a..292d21b326 100644 --- a/interface/wx/ribbon/buttonbar.h +++ b/interface/wx/ribbon/buttonbar.h @@ -377,6 +377,29 @@ public: */ virtual size_t GetButtonCount() const; + /** + Returns the N-th button of the bar. + + @see GetButtonCount() + + @since 2.9.5 + */ + virtual wxRibbonButtonBarButtonBase *GetItem(size_t n) const; + + /** + Returns the first button having a given id or NULL if none matches. + + @since 2.9.5 + */ + virtual wxRibbonButtonBarButtonBase *GetItemById(int id) const; + + /** + Returns the id of a button. + + @since 2.9.5 + */ + virtual int GetItemId(wxRibbonButtonBarButtonBase *) const; + /** Calculate button layouts and positions. diff --git a/src/ribbon/buttonbar.cpp b/src/ribbon/buttonbar.cpp index a40938b9e0..b558e6daac 100644 --- a/src/ribbon/buttonbar.cpp +++ b/src/ribbon/buttonbar.cpp @@ -1139,6 +1139,32 @@ void wxRibbonButtonBar::OnMouseLeave(wxMouseEvent& WXUNUSED(evt)) if(repaint) Refresh(false); } +wxRibbonButtonBarButtonBase *wxRibbonButtonBar::GetItem(size_t n) const +{ + wxCHECK_MSG(n >= 0 && n < m_buttons.GetCount(), NULL, "wxRibbonButtonBar item's index is out of bound"); + return m_buttons.Item(n); +} + +wxRibbonButtonBarButtonBase *wxRibbonButtonBar::GetItemById(int button_id) const +{ + size_t count = m_buttons.GetCount(); + for ( size_t i = 0; i < count; ++i ) + { + wxRibbonButtonBarButtonBase* button = m_buttons.Item(i); + if ( button->id == button_id ) + return button; + } + + return NULL; + +} + +int wxRibbonButtonBar::GetItemId(wxRibbonButtonBarButtonBase *item) const +{ + wxCHECK_MSG(item != NULL, wxNOT_FOUND, "wxRibbonButtonBar item should not be NULL"); + return item->id; +} + bool wxRibbonButtonBarEvent::PopupMenu(wxMenu* menu) {