1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "AccRelation.h"
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
29 #pragma clang diagnostic pop
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
;
44 * @param relationType Variant to get relation type.
47 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_relationType(BSTR
* relationType
)
53 if (relationType
== nullptr)
56 int type
= relation
.RelationType
;
57 SAFE_SYSFREESTRING(*relationType
);
59 *relationType
= getRelationTypeBSTR(type
);
65 // Gets what the type of localized relation is.
66 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_localizedRelationType(BSTR
*)
79 * @param nTargets Variant to get targets length.
82 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_nTargets(long * nTargets
)
88 if (nTargets
== nullptr)
91 Sequence
< Reference
< XInterface
> > xTargets
= relation
.TargetSet
;
92 *nTargets
= xTargets
.getLength();
100 * @param targetIndex target index.
101 * @param target Variant to get special target.
104 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_target(long targetIndex
, IUnknown
* * target
)
108 ENTER_PROTECTED_BLOCK
110 if (target
== nullptr)
113 Sequence
< Reference
< XInterface
> > xTargets
= relation
.TargetSet
;
114 int nCount
= xTargets
.getLength();
115 if( targetIndex
>= nCount
)
118 Reference
<XAccessible
> xRAcc(xTargets
[targetIndex
], UNO_QUERY
);
119 IAccessible
* pRet
= nullptr;
121 bool isGet
= CMAccessible::get_IAccessibleFromXAccessible(xRAcc
.get(), &pRet
);
124 *target
= /*(IAccessible2 *)*/static_cast<IUnknown
*>(pRet
);
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.
141 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_targets(long, IUnknown
* * target
, long * nTargets
)
145 ENTER_PROTECTED_BLOCK
148 if(target
== nullptr)
150 if (nTargets
== nullptr)
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)
164 for(int i
=0; i
<nCount
; i
++)
166 IUnknown
* pAcc
= nullptr;
167 HRESULT hr
= get_target(i
,&pAcc
);
175 LEAVE_PROTECTED_BLOCK
180 * @param pXSubInterface AccessibleRelation pointer.
183 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::put_XSubInterface(hyper pXSubInterface
)
185 // internal IUNOXWrapper - no mutex meeded
187 relation
= *reinterpret_cast<AccessibleRelation
*>(pXSubInterface
);
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
)
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */