Add wxRibbonBar::GetPageById()

To find a page by ID currently you have to use a recursive FindWindow
(which would also look at the child Panel windows). This function allows
for finding a page by ID more elegantly.

Closes #24211.
This commit is contained in:
Blake Madden 2024-01-11 19:39:15 -05:00 committed by Vadim Zeitlin
parent ee691af12d
commit 567f8c47af
3 changed files with 20 additions and 0 deletions

View file

@ -125,6 +125,7 @@ public:
bool SetActivePage(wxRibbonPage* page);
int GetActivePage() const;
wxRibbonPage* GetPage(int n);
wxRibbonPage* GetPageById(wxWindowID id);
size_t GetPageCount() const;
bool DismissExpandedPanel();
int GetPageNumber(wxRibbonPage* page) const;

View file

@ -303,6 +303,15 @@ public:
*/
wxRibbonPage* GetPage(int n);
/**
Get a page by window ID.
@NULL will be returned if no page with the ID is found.
@since 3.3.0
*/
wxRibbonPage* GetPageById(wxWindowID id);
/**
Get the number of pages in this bar.

View file

@ -316,6 +316,16 @@ wxRibbonPage* wxRibbonBar::GetPage(int n)
return m_pages.Item(n).page;
}
wxRibbonPage* wxRibbonBar::GetPageById(wxWindowID id)
{
for (const auto& page : m_pages)
{
if (page.page->GetId() == id)
return page.page;
}
return nullptr;
}
size_t wxRibbonBar::GetPageCount() const
{
return m_pages.GetCount();