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 .
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
;
36 * @param relationType Variant to get relation type.
39 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_relationType(BSTR
* relationType
)
45 if (relationType
== nullptr)
48 int type
= relation
.RelationType
;
49 SysFreeString(*relationType
);
51 *relationType
= getRelationTypeBSTR(type
);
54 } catch(...) { return E_FAIL
; }
57 // Gets what the type of localized relation is.
58 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_localizedRelationType(BSTR
*)
66 } catch(...) { return E_FAIL
; }
71 * @param nTargets Variant to get targets length.
74 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_nTargets(long * nTargets
)
80 if (nTargets
== nullptr)
83 Sequence
< Reference
< XInterface
> > xTargets
= relation
.TargetSet
;
84 *nTargets
= xTargets
.getLength();
87 } catch(...) { return E_FAIL
; }
92 * @param targetIndex target index.
93 * @param target Variant to get special target.
96 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_target(long targetIndex
, IUnknown
* * target
)
102 if (target
== nullptr)
105 Sequence
< Reference
< XInterface
> > xTargets
= relation
.TargetSet
;
106 int nCount
= xTargets
.getLength();
107 if( targetIndex
>= nCount
)
110 Reference
<XAccessible
> xRAcc(xTargets
[targetIndex
], UNO_QUERY
);
111 IAccessible
* pRet
= nullptr;
113 bool isGet
= CMAccessible::get_IAccessibleFromXAccessible(xRAcc
.get(), &pRet
);
116 *target
= /*(IAccessible2 *)*/pRet
;
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.
133 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::get_targets(long, IUnknown
* * target
, long * nTargets
)
140 if(target
== nullptr)
142 if (nTargets
== nullptr)
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)
156 for(int i
=0; i
<nCount
; i
++)
158 IUnknown
* pAcc
= nullptr;
159 HRESULT hr
= get_target(i
,&pAcc
);
167 } catch(...) { return E_FAIL
; }
172 * @param pXSubInterface AccessibleRelation pointer.
175 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccRelation::put_XSubInterface(hyper pXSubInterface
)
177 // internal IUNOXWrapper - no mutex meeded
179 relation
= *reinterpret_cast<AccessibleRelation
*>(pXSubInterface
);
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
)
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */