Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccRelation.cxx
blobef3265000bab24c6f25e3f2e3742d9fc4bf32cdd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "stdafx.h"
21 #include <UAccCOM.h>
22 #include "AccRelation.h"
24 #include <vcl/svapp.hxx>
26 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
27 #include <com/sun/star/accessibility/XAccessible.hpp>
28 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
29 #include "MAccessible.h"
31 using namespace com::sun::star::accessibility;
32 using namespace com::sun::star::uno;
34 /**
35 * Get relation type.
36 * @param relationType Variant to get relation type.
37 * @return Result.
39 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_relationType(BSTR * relationType)
41 SolarMutexGuard g;
43 try {
45 if (relationType == nullptr)
46 return E_INVALIDARG;
48 int type = relation.RelationType;
49 SysFreeString(*relationType);
51 *relationType = getRelationTypeBSTR(type);
52 return S_OK;
54 } catch(...) { return E_FAIL; }
57 // Gets what the type of localized relation is.
58 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_localizedRelationType(BSTR *)
62 try {
64 return S_OK;
66 } catch(...) { return E_FAIL; }
69 /**
70 * Get targets length.
71 * @param nTargets Variant to get targets length.
72 * @return Result.
74 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_nTargets(long * nTargets)
76 SolarMutexGuard g;
78 try {
80 if (nTargets == nullptr)
81 return E_INVALIDARG;
83 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
84 *nTargets = xTargets.getLength();
85 return S_OK;
87 } catch(...) { return E_FAIL; }
90 /**
91 * Get special target.
92 * @param targetIndex target index.
93 * @param target Variant to get special target.
94 * @return Result.
96 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_target(long targetIndex, IUnknown * * target)
98 SolarMutexGuard g;
100 try {
102 if (target == nullptr)
103 return E_FAIL;
105 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
106 int nCount = xTargets.getLength();
107 if( targetIndex >= nCount )
108 return E_FAIL;
110 Reference<XAccessible> xRAcc(xTargets[targetIndex], UNO_QUERY);
111 IAccessible* pRet = nullptr;
113 bool isGet = CMAccessible::get_IAccessibleFromXAccessible(xRAcc.get(), &pRet);
114 if(isGet)
116 *target = /*(IAccessible2 *)*/pRet;
117 pRet->AddRef();
118 return S_OK;
121 return E_FAIL;
123 } catch(...) { return E_FAIL; }
127 * Get special targets.
128 * @param maxTargets Special targets count.
129 * @param target Variant to get special target.
130 * @param nTargets Variant to accept actual target length.
131 * @return Result.
133 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_targets(long, IUnknown * * target, long * nTargets)
135 SolarMutexGuard g;
137 try {
139 // #CHECK#
140 if(target == nullptr)
141 return E_INVALIDARG;
142 if (nTargets == nullptr)
143 return E_INVALIDARG;
145 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
146 int nCount = xTargets.getLength();
148 *target = static_cast<IUnknown*>(::CoTaskMemAlloc(nCount*sizeof(IUnknown)));
150 // #CHECK Memory Allocation#
151 if(*target == nullptr)
153 return E_FAIL;
156 for(int i=0; i<nCount ; i++)
158 IUnknown* pAcc = nullptr;
159 HRESULT hr = get_target(i,&pAcc);
160 if(SUCCEEDED(hr))
161 target[i] = pAcc;
164 *nTargets = nCount;
165 return S_OK;
167 } catch(...) { return E_FAIL; }
171 * Put UNO interface.
172 * @param pXSubInterface AccessibleRelation pointer.
173 * @return Result.
175 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::put_XSubInterface(hyper pXSubInterface)
177 // internal IUNOXWrapper - no mutex meeded
179 relation = *reinterpret_cast<AccessibleRelation*>(pXSubInterface);
180 return S_OK;
184 * Get relation type string by type.
185 * @param type Relation type.
186 * @return relation type string.
188 BSTR CAccRelation::getRelationTypeBSTR(int type)
190 static LPCWSTR map[] =
192 L"INVALID", // AccessibleRelationType::INVALID
193 IA2_RELATION_FLOWS_FROM, // AccessibleRelationType::CONTENT_FLOWS_FROM
194 IA2_RELATION_FLOWS_TO, // AccessibleRelationType::CONTENT_FLOWS_TO
195 IA2_RELATION_CONTROLLED_BY, // AccessibleRelationType::CONTROLLED_BY
196 IA2_RELATION_CONTROLLER_FOR, // AccessibleRelationType::CONTROLLER_FOR
197 IA2_RELATION_LABEL_FOR, // AccessibleRelationType::LABEL_FOR
198 IA2_RELATION_LABELED_BY, // AccessibleRelationType::LABELED_BY
199 IA2_RELATION_MEMBER_OF, // AccessibleRelationType::MEMBER_OF
200 IA2_RELATION_SUBWINDOW_OF, // AccessibleRelationType::SUB_WINDOW_OF
201 IA2_RELATION_NODE_CHILD_OF, // AccessibleRelationType::NODE_CHILD_OF
202 IA2_RELATION_DESCRIBED_BY // AccessibleRelationType::DESCRIBED_BY
205 return ::SysAllocString( (type >= AccessibleRelationType::INVALID && type <= AccessibleRelationType::DESCRIBED_BY)
206 ? map[type] : L"");
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */