Add wxRibbonToolBar GetToolPos and GetToolRect coord functions

This commit is contained in:
Gary Allen
2020-12-23 20:08:39 +02:00
parent a5c2276965
commit ae9a62d5a2
3 changed files with 69 additions and 0 deletions

View File

@@ -131,6 +131,7 @@ public:
virtual wxRibbonToolBarToolBase* FindById(int tool_id)const;
virtual wxRibbonToolBarToolBase* GetToolByPos(size_t pos)const;
virtual wxRibbonToolBarToolBase* GetToolByPos(wxCoord x, wxCoord y)const;
virtual size_t GetToolCount() const;
virtual int GetToolId(const wxRibbonToolBarToolBase* tool)const;
@@ -139,6 +140,7 @@ public:
virtual wxString GetToolHelpString(int tool_id)const;
virtual wxRibbonButtonKind GetToolKind(int tool_id)const;
virtual int GetToolPos(int tool_id)const;
virtual wxRect GetToolRect(int tool_id)const;
virtual bool GetToolState(int tool_id)const;
virtual bool Realize() wxOVERRIDE;

View File

@@ -307,6 +307,16 @@ public:
*/
wxRibbonToolBarToolBase* GetToolByPos(size_t pos)const;
/**
Return the opaque pointer corresponding to the given tool, given specified coordinates.
@return an opaque pointer, NULL if is not found.
@since 2.9.4
*/
virtual wxRibbonToolBarToolBase* GetToolByPos(wxCoord x, wxCoord y)const;
/**
Returns the number of tools in the toolbar.
@@ -380,6 +390,18 @@ public:
*/
virtual int GetToolPos(int tool_id)const;
/**
Returns the rect in the toolbar, or a default-constructed rect if the tool
is not found.
@param tool_id
ID of the tool in question, as passed to AddTool().
@since 3.1.5
*/
virtual wxRect GetToolRect(int tool_id)const;
/**
Gets the on/off state of a toggle tool.

View File

@@ -429,6 +429,27 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::GetToolByPos(size_t pos)const
return NULL;
}
wxRibbonToolBarToolBase* wxRibbonToolBar::GetToolByPos(wxCoord x, wxCoord y)const
{
size_t group_count = m_groups.GetCount();
size_t g, t;
for(g = 0; g < group_count; ++g)
{
wxRibbonToolBarToolGroup* group = m_groups.Item(g);
size_t tool_count = group->tools.GetCount();
for(t = 0; t < tool_count; ++t)
{
wxRibbonToolBarToolBase* tool = group->tools.Item(t);
wxRect rect(tool->position.x, tool->position.y, tool->size.GetWidth(), tool->size.GetHeight());
if(rect.Contains(x, y))
{
return tool;
}
}
}
return NULL;
}
size_t wxRibbonToolBar::GetToolCount() const
{
size_t count = 0;
@@ -501,6 +522,30 @@ int wxRibbonToolBar::GetToolPos(int tool_id)const
return wxNOT_FOUND;
}
wxRect wxRibbonToolBar::GetToolRect(int tool_id)const
{
size_t group_count = m_groups.GetCount();
size_t g, t;
int pos = 0;
for(g = 0; g < group_count; ++g)
{
wxRibbonToolBarToolGroup* group = m_groups.Item(g);
size_t tool_count = group->tools.GetCount();
for(t = 0; t < tool_count; ++t)
{
wxRibbonToolBarToolBase* tool = group->tools.Item(t);
if (tool->id == tool_id)
{
wxRect rect(tool->position.x, tool->position.y, tool->size.GetWidth(), tool->size.GetHeight());
return rect;
}
++pos;
}
++pos; // Increment pos for group separator.
}
return wxRect();
}
bool wxRibbonToolBar::GetToolState(int tool_id)const
{
wxRibbonToolBarToolBase* tool = FindById(tool_id);