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 ::com::sun::star
;
27 using namespace ::com::sun::star::accessibility
;
29 class AccessibleRelationSetHelperImpl
32 AccessibleRelationSetHelperImpl();
33 AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl
& rImpl
);
34 ~AccessibleRelationSetHelperImpl();
36 sal_Int32
getRelationCount( )
37 throw (uno::RuntimeException
);
38 AccessibleRelation
getRelation( sal_Int32 nIndex
)
39 throw (lang::IndexOutOfBoundsException
,
40 uno::RuntimeException
);
41 bool containsRelation( sal_Int16 aRelationType
)
42 throw (uno::RuntimeException
);
43 AccessibleRelation
getRelationByType( sal_Int16 aRelationType
)
44 throw (uno::RuntimeException
);
45 void AddRelation(const AccessibleRelation
& rRelation
)
46 throw (uno::RuntimeException
);
49 std::vector
<AccessibleRelation
> maRelations
;
52 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
56 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl
& rImpl
)
57 : maRelations(rImpl
.maRelations
)
61 AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
65 sal_Int32
AccessibleRelationSetHelperImpl::getRelationCount( )
66 throw (uno::RuntimeException
)
68 return maRelations
.size();
71 AccessibleRelation
AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex
)
72 throw (lang::IndexOutOfBoundsException
,
73 uno::RuntimeException
)
75 if ((nIndex
< 0) || (static_cast<sal_uInt32
>(nIndex
) >= maRelations
.size()))
76 throw lang::IndexOutOfBoundsException();
77 return maRelations
[nIndex
];
80 bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType
)
81 throw (uno::RuntimeException
)
83 AccessibleRelation defaultRelation
; // default is INVALID
84 AccessibleRelation relationByType
= getRelationByType(aRelationType
);
85 return relationByType
.RelationType
!= defaultRelation
.RelationType
;
88 AccessibleRelation
AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType
)
89 throw (uno::RuntimeException
)
91 sal_Int32
nCount(getRelationCount());
94 while ((i
< nCount
) && !bFound
)
96 if (maRelations
[i
].RelationType
== aRelationType
)
97 return maRelations
[i
];
101 return AccessibleRelation();
104 void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation
& rRelation
)
105 throw (uno::RuntimeException
)
107 sal_Int32
nCount(getRelationCount());
110 while ((i
< nCount
) && !bFound
)
112 if (maRelations
[i
].RelationType
== rRelation
.RelationType
)
118 maRelations
[i
].TargetSet
= comphelper::concatSequences(maRelations
[i
].TargetSet
, rRelation
.TargetSet
);
120 maRelations
.push_back(rRelation
);
123 //===== internal ============================================================
125 AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
128 mpHelperImpl
= new AccessibleRelationSetHelperImpl();
131 AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper
& rHelper
)
132 : cppu::WeakImplHelper1
<XAccessibleRelationSet
>()
135 if (rHelper
.mpHelperImpl
)
136 mpHelperImpl
= new AccessibleRelationSetHelperImpl(*rHelper
.mpHelperImpl
);
138 mpHelperImpl
= new AccessibleRelationSetHelperImpl();
141 AccessibleRelationSetHelper::~AccessibleRelationSetHelper()
146 //===== XAccessibleRelationSet ==============================================
148 /** Returns the number of relations in this relation set.
151 Returns the number of relations or zero if there are none.
154 AccessibleRelationSetHelper::getRelationCount( )
155 throw (uno::RuntimeException
, std::exception
)
157 osl::MutexGuard
aGuard (maMutex
);
158 return mpHelperImpl
->getRelationCount();
161 /** Returns the relation of this relation set that is specified by
165 This index specifies the relatio to return.
168 For a valid index, i.e. inside the range 0 to the number of
169 relations minus one, the returned value is the requested
170 relation. If the index is invalid then the returned relation
171 has the type INVALID.
174 AccessibleRelation SAL_CALL
175 AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex
)
176 throw (lang::IndexOutOfBoundsException
,
177 uno::RuntimeException
, std::exception
)
179 osl::MutexGuard
aGuard (maMutex
);
180 return mpHelperImpl
->getRelation(nIndex
);
183 /** Tests whether the relation set contains a relation matching the
187 The type of relation to look for in this set of relations. This
188 has to be one of the constants of
189 <type>AccessibleRelationType</type>.
192 Returns <TRUE/> if there is a (at least one) relation of the
193 given type and <FALSE/> if there is no such relation in the set.
196 AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType
)
197 throw (uno::RuntimeException
, std::exception
)
199 osl::MutexGuard
aGuard (maMutex
);
200 return mpHelperImpl
->containsRelation(aRelationType
);
203 /** Retrieve and return the relation with the given relation type.
206 The type of the relation to return. This has to be one of the
207 constants of <type>AccessibleRelationType</type>.
210 If a relation with the given type could be found than (a copy
211 of) this relation is returned. Otherwise a relation with the
212 type INVALID is returned.
214 AccessibleRelation SAL_CALL
215 AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType
)
216 throw (uno::RuntimeException
, std::exception
)
218 osl::MutexGuard
aGuard (maMutex
);
219 return mpHelperImpl
->getRelationByType(aRelationType
);
222 void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation
& rRelation
)
223 throw (uno::RuntimeException
)
225 osl::MutexGuard
aGuard (maMutex
);
226 mpHelperImpl
->AddRelation(rRelation
);
229 //===== XTypeProvider =======================================================
231 uno::Sequence
< ::com::sun::star::uno::Type
>
232 AccessibleRelationSetHelper::getTypes()
233 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
235 osl::MutexGuard
aGuard (maMutex
);
236 const ::com::sun::star::uno::Type aTypeList
[] = {
237 cppu::UnoType
<XAccessibleRelationSet
>::get(),
238 cppu::UnoType
<lang::XTypeProvider
>::get()
240 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
>
241 aTypeSequence (aTypeList
, 2);
242 return aTypeSequence
;
245 uno::Sequence
<sal_Int8
> SAL_CALL
246 AccessibleRelationSetHelper::getImplementationId()
247 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
249 return css::uno::Sequence
<sal_Int8
>();
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */