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 ()
126 : mpHelperImpl(new AccessibleRelationSetHelperImpl
)
130 AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper
& rHelper
)
131 : cppu::WeakImplHelper1
<XAccessibleRelationSet
>()
133 if (rHelper
.mpHelperImpl
)
134 mpHelperImpl
.reset(new AccessibleRelationSetHelperImpl(*rHelper
.mpHelperImpl
));
136 mpHelperImpl
.reset(new AccessibleRelationSetHelperImpl());
139 AccessibleRelationSetHelper::~AccessibleRelationSetHelper()
143 //===== XAccessibleRelationSet ==============================================
145 /** Returns the number of relations in this relation set.
148 Returns the number of relations or zero if there are none.
151 AccessibleRelationSetHelper::getRelationCount( )
152 throw (uno::RuntimeException
, std::exception
)
154 osl::MutexGuard
aGuard (maMutex
);
155 return mpHelperImpl
->getRelationCount();
158 /** Returns the relation of this relation set that is specified by
162 This index specifies the relatio to return.
165 For a valid index, i.e. inside the range 0 to the number of
166 relations minus one, the returned value is the requested
167 relation. If the index is invalid then the returned relation
168 has the type INVALID.
171 AccessibleRelation SAL_CALL
172 AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex
)
173 throw (lang::IndexOutOfBoundsException
,
174 uno::RuntimeException
, std::exception
)
176 osl::MutexGuard
aGuard (maMutex
);
177 return mpHelperImpl
->getRelation(nIndex
);
180 /** Tests whether the relation set contains a relation matching the
184 The type of relation to look for in this set of relations. This
185 has to be one of the constants of
186 <type>AccessibleRelationType</type>.
189 Returns <TRUE/> if there is a (at least one) relation of the
190 given type and <FALSE/> if there is no such relation in the set.
193 AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType
)
194 throw (uno::RuntimeException
, std::exception
)
196 osl::MutexGuard
aGuard (maMutex
);
197 return mpHelperImpl
->containsRelation(aRelationType
);
200 /** Retrieve and return the relation with the given relation type.
203 The type of the relation to return. This has to be one of the
204 constants of <type>AccessibleRelationType</type>.
207 If a relation with the given type could be found than (a copy
208 of) this relation is returned. Otherwise a relation with the
209 type INVALID is returned.
211 AccessibleRelation SAL_CALL
212 AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType
)
213 throw (uno::RuntimeException
, std::exception
)
215 osl::MutexGuard
aGuard (maMutex
);
216 return mpHelperImpl
->getRelationByType(aRelationType
);
219 void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation
& rRelation
)
220 throw (uno::RuntimeException
)
222 osl::MutexGuard
aGuard (maMutex
);
223 mpHelperImpl
->AddRelation(rRelation
);
226 //===== XTypeProvider =======================================================
228 uno::Sequence
< css::uno::Type
> AccessibleRelationSetHelper::getTypes()
229 throw (css::uno::RuntimeException
, std::exception
)
231 osl::MutexGuard
aGuard (maMutex
);
232 css::uno::Sequence
< css::uno::Type
> aTypeSequence
{
233 cppu::UnoType
<XAccessibleRelationSet
>::get(),
234 cppu::UnoType
<lang::XTypeProvider
>::get()
236 return aTypeSequence
;
239 uno::Sequence
<sal_Int8
> SAL_CALL
AccessibleRelationSetHelper::getImplementationId()
240 throw (css::uno::RuntimeException
, std::exception
)
242 return css::uno::Sequence
<sal_Int8
>();
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */