Add functions for getting current ribbon tool rectangle

wxRibbonButtonBar::GetItemRect() and wxRibbonToolBar::GetActiveTool()
are helpful for positioning other windows (e.g. popup ones) that should
be aligned to tools and buttons in the ribbon bar.

Closes #22329.
This commit is contained in:
Uwe Runtemund
2022-04-18 12:01:28 +02:00
committed by Vadim Zeitlin
parent 692073ea7d
commit 94f698cc15
6 changed files with 51 additions and 0 deletions

View File

@@ -1508,6 +1508,29 @@ int wxRibbonButtonBar::GetItemId(wxRibbonButtonBarButtonBase *item) const
return item->id;
}
wxRect wxRibbonButtonBar::GetItemRect(int button_id)const
{
wxRibbonButtonBarLayout* layout = m_layouts.Item(m_current_layout);
size_t btn_count = layout->buttons.Count();
size_t btn_i;
for (btn_i = 0; btn_i < btn_count; ++btn_i)
{
wxRibbonButtonBarButtonInstance& instance = layout->buttons.Item(btn_i);
wxRibbonButtonBarButtonBase* button = instance.base;
if (button->id == button_id)
{
wxRibbonButtonBarButtonSizeInfo& size = button->sizes[instance.size];
wxRect btn_rect;
btn_rect.SetTopLeft(m_layout_offset + instance.position);
btn_rect.SetSize(size.size);
return btn_rect;
}
}
return wxRect();
}
bool wxRibbonButtonBarEvent::PopupMenu(wxMenu* menu)
{

View File

@@ -470,6 +470,11 @@ int wxRibbonToolBar::GetToolId(const wxRibbonToolBarToolBase* tool)const
return tool->id;
}
wxRibbonToolBarToolBase* wxRibbonToolBar::GetActiveTool() const
{
return m_active_tool == NULL ? NULL : m_active_tool;
}
wxObject* wxRibbonToolBar::GetToolClientData(int tool_id)const
{
wxRibbonToolBarToolBase* tool = FindById(tool_id);