winaccessibility/source/UAccCOM/AccRelation.cxx | 57 ++++++++++++------------ winaccessibility/source/UAccCOM/AccRelation.h | 2 winaccessibility/source/UAccCOM/MAccessible.h | 1 3 files changed, 31 insertions(+), 29 deletions(-)
New commits: commit d38de2e655617c72976e9df327c89fef73abf422 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Aug 22 12:54:13 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Aug 23 07:39:44 2024 +0200 wina11y: Explicitly map UNO to IA2 relation type Use switch/case to explicitly map from UNO's `AccessibleRelationType` to the IAccessible2 relation type strings, instead of implicitly using the integer values of the `AccessibleRelationType` as indices into a map. Let the caller allocate the string to return. Use `sal_Int16` for the `AccessibleRelationType` param to match the type of the actual integer values. Change-Id: I8c094d763ca602131a578f20719d00cad53088d0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172257 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/winaccessibility/source/UAccCOM/AccRelation.cxx b/winaccessibility/source/UAccCOM/AccRelation.cxx index cd245d7f4567..50de3dd63a57 100644 --- a/winaccessibility/source/UAccCOM/AccRelation.cxx +++ b/winaccessibility/source/UAccCOM/AccRelation.cxx @@ -45,10 +45,8 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_relationType(BSTR* relationT if (relationType == nullptr) return E_INVALIDARG; - int type = relation.RelationType; SysFreeString(*relationType); - - *relationType = getRelationTypeBSTR(type); + *relationType = SysAllocString(mapToIA2RelationType(relation.RelationType)); return S_OK; } catch (...) @@ -194,31 +192,36 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::put_XSubInterface(hyper pXSubInt return S_OK; } -/** - * Get relation type string by type. - * @param type Relation type. - * @return relation type string. -*/ -BSTR CAccRelation::getRelationTypeBSTR(int type) +const wchar_t* CAccRelation::mapToIA2RelationType(sal_Int16 nUnoRelationType) { - static LPCWSTR map[] = { - L"INVALID", // AccessibleRelationType::INVALID - IA2_RELATION_FLOWS_FROM, // AccessibleRelationType::CONTENT_FLOWS_FROM - IA2_RELATION_FLOWS_TO, // AccessibleRelationType::CONTENT_FLOWS_TO - IA2_RELATION_CONTROLLED_BY, // AccessibleRelationType::CONTROLLED_BY - IA2_RELATION_CONTROLLER_FOR, // AccessibleRelationType::CONTROLLER_FOR - IA2_RELATION_LABEL_FOR, // AccessibleRelationType::LABEL_FOR - IA2_RELATION_LABELED_BY, // AccessibleRelationType::LABELED_BY - IA2_RELATION_MEMBER_OF, // AccessibleRelationType::MEMBER_OF - IA2_RELATION_SUBWINDOW_OF, // AccessibleRelationType::SUB_WINDOW_OF - IA2_RELATION_NODE_CHILD_OF, // AccessibleRelationType::NODE_CHILD_OF - IA2_RELATION_DESCRIBED_BY // AccessibleRelationType::DESCRIBED_BY - }; - - return ::SysAllocString( - (type >= AccessibleRelationType::INVALID && type <= AccessibleRelationType::DESCRIBED_BY) - ? map[type] - : L""); + switch (nUnoRelationType) + { + case AccessibleRelationType::CONTENT_FLOWS_FROM: + return IA2_RELATION_FLOWS_FROM; + case AccessibleRelationType::CONTENT_FLOWS_TO: + return IA2_RELATION_FLOWS_TO; + case AccessibleRelationType::CONTROLLED_BY: + return IA2_RELATION_CONTROLLED_BY; + case AccessibleRelationType::CONTROLLER_FOR: + return IA2_RELATION_CONTROLLER_FOR; + case AccessibleRelationType::LABEL_FOR: + return IA2_RELATION_LABEL_FOR; + case AccessibleRelationType::LABELED_BY: + return IA2_RELATION_LABELED_BY; + case AccessibleRelationType::MEMBER_OF: + return IA2_RELATION_MEMBER_OF; + case AccessibleRelationType::SUB_WINDOW_OF: + return IA2_RELATION_SUBWINDOW_OF; + case AccessibleRelationType::NODE_CHILD_OF: + return IA2_RELATION_NODE_CHILD_OF; + case AccessibleRelationType::DESCRIBED_BY: + return IA2_RELATION_DESCRIBED_BY; + case AccessibleRelationType::INVALID: + return L"INVALID"; + default: + assert(false && "unhandled AccessibleRelationType"); + return L""; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/winaccessibility/source/UAccCOM/AccRelation.h b/winaccessibility/source/UAccCOM/AccRelation.h index c96f33a2edc9..a576e23aa952 100644 --- a/winaccessibility/source/UAccCOM/AccRelation.h +++ b/winaccessibility/source/UAccCOM/AccRelation.h @@ -74,7 +74,7 @@ public: // Override of IUNOXWrapper. STDMETHOD(put_XSubInterface)(hyper pXSubInterface) override; - static BSTR getRelationTypeBSTR(int type); + static const wchar_t* mapToIA2RelationType(sal_Int16 nUnoRelationType); private: css::accessibility::AccessibleRelation relation; commit 408cf7e91bba3c727d48ade8b587976f1a1c82b7 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Aug 22 08:06:19 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Aug 23 07:39:36 2024 +0200 wina11y: Drop misleading comment The methods have actual implementations, not just empty dummy implementations by now, so this // These methods only declare here, and their implementation bodies are empty now. is misleading, maybe was true in an earlier stage of the process of implementing IAccessible2 support? Change-Id: I4a50f7199e18766947322d040cac52c0585c2567 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172255 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/winaccessibility/source/UAccCOM/MAccessible.h b/winaccessibility/source/UAccCOM/MAccessible.h index a0733fa0c9a9..b17a8d78b7d9 100644 --- a/winaccessibility/source/UAccCOM/MAccessible.h +++ b/winaccessibility/source/UAccCOM/MAccessible.h @@ -101,7 +101,6 @@ public: STDMETHOD(get_accParent)( IDispatch **ppdispParent) override; // methods which are defined only in the IAccessible2 - // These methods only declare here, and their implementation bodies are empty now. STDMETHOD(get_nRelations)( long __RPC_FAR *nRelations) override; STDMETHOD(get_relation)( long relationIndex, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation) override; STDMETHOD(get_relations)( long maxRelations, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation, long __RPC_FAR *nRelations) override;