nss: upgrade to release 3.73
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccRelation.cxx
blobe2586ec5c183f5047d2e459159cf31eecb0eb586
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 "AccRelation.h"
23 #if defined __clang__
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
26 #endif
27 #include <UAccCOM.h>
28 #if defined __clang__
29 #pragma clang diagnostic pop
30 #endif
32 #include <vcl/svapp.hxx>
34 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
35 #include <com/sun/star/accessibility/XAccessible.hpp>
36 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
37 #include "MAccessible.h"
39 using namespace com::sun::star::accessibility;
40 using namespace com::sun::star::uno;
42 /**
43 * Get relation type.
44 * @param relationType Variant to get relation type.
45 * @return Result.
47 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_relationType(BSTR * relationType)
49 SolarMutexGuard g;
51 ENTER_PROTECTED_BLOCK
53 if (relationType == nullptr)
54 return E_INVALIDARG;
56 int type = relation.RelationType;
57 SAFE_SYSFREESTRING(*relationType);
59 *relationType = getRelationTypeBSTR(type);
60 return S_OK;
62 LEAVE_PROTECTED_BLOCK
65 // Gets what the type of localized relation is.
66 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_localizedRelationType(BSTR *)
70 ENTER_PROTECTED_BLOCK
72 return S_OK;
74 LEAVE_PROTECTED_BLOCK
77 /**
78 * Get targets length.
79 * @param nTargets Variant to get targets length.
80 * @return Result.
82 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_nTargets(long * nTargets)
84 SolarMutexGuard g;
86 ENTER_PROTECTED_BLOCK
88 if (nTargets == nullptr)
89 return E_INVALIDARG;
91 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
92 *nTargets = xTargets.getLength();
93 return S_OK;
95 LEAVE_PROTECTED_BLOCK
98 /**
99 * Get special target.
100 * @param targetIndex target index.
101 * @param target Variant to get special target.
102 * @return Result.
104 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_target(long targetIndex, IUnknown * * target)
106 SolarMutexGuard g;
108 ENTER_PROTECTED_BLOCK
110 if (target == nullptr)
111 return E_FAIL;
113 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
114 int nCount = xTargets.getLength();
115 if( targetIndex >= nCount )
116 return E_FAIL;
118 Reference<XAccessible> xRAcc(xTargets[targetIndex], UNO_QUERY);
119 IAccessible* pRet = nullptr;
121 bool isGet = CMAccessible::get_IAccessibleFromXAccessible(xRAcc.get(), &pRet);
122 if(isGet)
124 *target = /*(IAccessible2 *)*/static_cast<IUnknown*>(pRet);
125 pRet->AddRef();
126 return S_OK;
129 return E_FAIL;
131 LEAVE_PROTECTED_BLOCK
135 * Get special targets.
136 * @param maxTargets Special targets count.
137 * @param target Variant to get special target.
138 * @param nTargets Variant to accept actual target length.
139 * @return Result.
141 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_targets(long, IUnknown * * target, long * nTargets)
143 SolarMutexGuard g;
145 ENTER_PROTECTED_BLOCK
147 // #CHECK#
148 if(target == nullptr)
149 return E_INVALIDARG;
150 if (nTargets == nullptr)
151 return E_INVALIDARG;
153 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
154 int nCount = xTargets.getLength();
156 *target = static_cast<IUnknown*>(::CoTaskMemAlloc(nCount*sizeof(IUnknown)));
158 // #CHECK Memory Allocation#
159 if(*target == nullptr)
161 return E_FAIL;
164 for(int i=0; i<nCount ; i++)
166 IUnknown* pAcc = nullptr;
167 HRESULT hr = get_target(i,&pAcc);
168 if(SUCCEEDED(hr))
169 target[i] = pAcc;
172 *nTargets = nCount;
173 return S_OK;
175 LEAVE_PROTECTED_BLOCK
179 * Put UNO interface.
180 * @param pXSubInterface AccessibleRelation pointer.
181 * @return Result.
183 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::put_XSubInterface(hyper pXSubInterface)
185 // internal IUNOXWrapper - no mutex meeded
187 relation = *reinterpret_cast<AccessibleRelation*>(pXSubInterface);
188 return S_OK;
192 * Get relation type string by type.
193 * @param type Relation type.
194 * @return relation type string.
196 BSTR CAccRelation::getRelationTypeBSTR(int type)
198 static LPCWSTR map[] =
200 L"INVALID", // AccessibleRelationType::INVALID
201 IA2_RELATION_FLOWS_FROM, // AccessibleRelationType::CONTENT_FLOWS_FROM
202 IA2_RELATION_FLOWS_TO, // AccessibleRelationType::CONTENT_FLOWS_TO
203 IA2_RELATION_CONTROLLED_BY, // AccessibleRelationType::CONTROLLED_BY
204 IA2_RELATION_CONTROLLER_FOR, // AccessibleRelationType::CONTROLLER_FOR
205 IA2_RELATION_LABEL_FOR, // AccessibleRelationType::LABEL_FOR
206 IA2_RELATION_LABELED_BY, // AccessibleRelationType::LABELED_BY
207 IA2_RELATION_MEMBER_OF, // AccessibleRelationType::MEMBER_OF
208 IA2_RELATION_SUBWINDOW_OF, // AccessibleRelationType::SUB_WINDOW_OF
209 IA2_RELATION_NODE_CHILD_OF, // AccessibleRelationType::NODE_CHILD_OF
210 IA2_RELATION_DESCRIBED_BY // AccessibleRelationType::DESCRIBED_BY
213 return ::SysAllocString( (type >= AccessibleRelationType::INVALID && type <= AccessibleRelationType::DESCRIBED_BY)
214 ? map[type] : L"");
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */