diff --git a/include/wx/ribbon/toolbar.h b/include/wx/ribbon/toolbar.h index cb694194db..02578cd0c0 100644 --- a/include/wx/ribbon/toolbar.h +++ b/include/wx/ribbon/toolbar.h @@ -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; diff --git a/interface/wx/ribbon/toolbar.h b/interface/wx/ribbon/toolbar.h index 485dc57015..0829bd6ce6 100644 --- a/interface/wx/ribbon/toolbar.h +++ b/interface/wx/ribbon/toolbar.h @@ -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. diff --git a/src/ribbon/toolbar.cpp b/src/ribbon/toolbar.cpp index 0ed9b5926e..17ac365d6a 100644 --- a/src/ribbon/toolbar.cpp +++ b/src/ribbon/toolbar.cpp @@ -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);