summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-08-22 12:54:13 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2024-08-23 07:39:44 +0200
commitd38de2e655617c72976e9df327c89fef73abf422 (patch)
tree743c339f5af594fcdb44c8767a593ebe8691f497
parent408cf7e91bba3c727d48ade8b587976f1a1c82b7 (diff)
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.weghorn@posteo.de>
-rw-r--r--winaccessibility/source/UAccCOM/AccRelation.cxx57
-rw-r--r--winaccessibility/source/UAccCOM/AccRelation.h2
2 files changed, 31 insertions, 28 deletions
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;