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 .
20 #include "unotools/accessiblerelationsethelper.hxx"
22 #include <comphelper/sequence.hxx>
23 #include <comphelper/servicehelper.hxx>
25 using namespace ::utl
;
26 using namespace ::rtl
;
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::accessibility
;
30 class AccessibleRelationSetHelperImpl
33 AccessibleRelationSetHelperImpl();
34 AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl
& rImpl
);
35 ~AccessibleRelationSetHelperImpl();
37 sal_Int32
getRelationCount( )
38 throw (uno::RuntimeException
);
39 AccessibleRelation
getRelation( sal_Int32 nIndex
)
40 throw (lang::IndexOutOfBoundsException
,
41 uno::RuntimeException
);
42 sal_Bool
containsRelation( sal_Int16 aRelationType
)
43 throw (uno::RuntimeException
);
44 AccessibleRelation
getRelationByType( sal_Int16 aRelationType
)
45 throw (uno::RuntimeException
);
46 void AddRelation(const AccessibleRelation
& rRelation
)
47 throw (uno::RuntimeException
);
50 std::vector
<AccessibleRelation
> maRelations
;
53 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
57 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl
& rImpl
)
58 : maRelations(rImpl
.maRelations
)
62 AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
66 sal_Int32
AccessibleRelationSetHelperImpl::getRelationCount( )
67 throw (uno::RuntimeException
)
69 return maRelations
.size();
72 AccessibleRelation
AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex
)
73 throw (lang::IndexOutOfBoundsException
,
74 uno::RuntimeException
)
76 if ((nIndex
< 0) || (static_cast<sal_uInt32
>(nIndex
) >= maRelations
.size()))
77 throw lang::IndexOutOfBoundsException();
78 return maRelations
[nIndex
];
81 sal_Bool
AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType
)
82 throw (uno::RuntimeException
)
84 AccessibleRelation defaultRelation
; // default is INVALID
85 AccessibleRelation relationByType
= getRelationByType(aRelationType
);
86 return relationByType
.RelationType
!= defaultRelation
.RelationType
;
89 AccessibleRelation
AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType
)
90 throw (uno::RuntimeException
)
92 sal_Int32
nCount(getRelationCount());
94 sal_Bool
bFound(sal_False
);
95 while ((i
< nCount
) && !bFound
)
97 if (maRelations
[i
].RelationType
== aRelationType
)
98 return maRelations
[i
];
102 return AccessibleRelation();
105 void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation
& rRelation
)
106 throw (uno::RuntimeException
)
108 sal_Int32
nCount(getRelationCount());
110 sal_Bool
bFound(sal_False
);
111 while ((i
< nCount
) && !bFound
)
113 if (maRelations
[i
].RelationType
== rRelation
.RelationType
)
119 maRelations
[i
].TargetSet
= comphelper::concatSequences(maRelations
[i
].TargetSet
, rRelation
.TargetSet
);
121 maRelations
.push_back(rRelation
);
124 //===== internal ============================================================
126 AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
129 mpHelperImpl
= new AccessibleRelationSetHelperImpl();
132 AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper
& rHelper
)
133 : cppu::WeakImplHelper1
<XAccessibleRelationSet
>()
136 if (rHelper
.mpHelperImpl
)
137 mpHelperImpl
= new AccessibleRelationSetHelperImpl(*rHelper
.mpHelperImpl
);
139 mpHelperImpl
= new AccessibleRelationSetHelperImpl();
142 AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
147 //===== XAccessibleRelationSet ==============================================
149 /** Returns the number of relations in this relation set.
152 Returns the number of relations or zero if there are none.
155 AccessibleRelationSetHelper::getRelationCount( )
156 throw (uno::RuntimeException
)
158 osl::MutexGuard
aGuard (maMutex
);
159 return mpHelperImpl
->getRelationCount();
162 /** Returns the relation of this relation set that is specified by
166 This index specifies the relatio to return.
169 For a valid index, i.e. inside the range 0 to the number of
170 relations minus one, the returned value is the requested
171 relation. If the index is invalid then the returned relation
172 has the type INVALID.
175 AccessibleRelation SAL_CALL
176 AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex
)
177 throw (lang::IndexOutOfBoundsException
,
178 uno::RuntimeException
)
180 osl::MutexGuard
aGuard (maMutex
);
181 return mpHelperImpl
->getRelation(nIndex
);
184 /** Tests whether the relation set contains a relation matching the
188 The type of relation to look for in this set of relations. This
189 has to be one of the constants of
190 <type>AccessibleRelationType</type>.
193 Returns <TRUE/> if there is a (at least one) relation of the
194 given type and <FALSE/> if there is no such relation in the set.
197 AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType
)
198 throw (uno::RuntimeException
)
200 osl::MutexGuard
aGuard (maMutex
);
201 return mpHelperImpl
->containsRelation(aRelationType
);
204 /** Retrieve and return the relation with the given relation type.
207 The type of the relation to return. This has to be one of the
208 constants of <type>AccessibleRelationType</type>.
211 If a relation with the given type could be found than (a copy
212 of) this relation is returned. Otherwise a relation with the
213 type INVALID is returned.
215 AccessibleRelation SAL_CALL
216 AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType
)
217 throw (uno::RuntimeException
)
219 osl::MutexGuard
aGuard (maMutex
);
220 return mpHelperImpl
->getRelationByType(aRelationType
);
223 void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation
& rRelation
)
224 throw (uno::RuntimeException
)
226 osl::MutexGuard
aGuard (maMutex
);
227 mpHelperImpl
->AddRelation(rRelation
);
230 //===== XTypeProvider =======================================================
232 uno::Sequence
< ::com::sun::star::uno::Type
>
233 AccessibleRelationSetHelper::getTypes (void)
234 throw (::com::sun::star::uno::RuntimeException
)
236 osl::MutexGuard
aGuard (maMutex
);
237 const ::com::sun::star::uno::Type aTypeList
[] = {
238 ::getCppuType((const uno::Reference
<
239 XAccessibleRelationSet
>*)0),
240 ::getCppuType((const uno::Reference
<
241 lang::XTypeProvider
>*)0)
243 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
>
244 aTypeSequence (aTypeList
, 2);
245 return aTypeSequence
;
250 class theAccessibleRelationSetHelperUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theAccessibleRelationSetHelperUnoTunnelId
> {};
253 uno::Sequence
<sal_Int8
> SAL_CALL
254 AccessibleRelationSetHelper::getImplementationId (void)
255 throw (::com::sun::star::uno::RuntimeException
)
257 return theAccessibleRelationSetHelperUnoTunnelId::get().getSeq();
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */