Bump version to 4.3-4
[LibreOffice.git] / unotools / source / accessibility / accessiblerelationsethelper.cxx
blob91753e43c7c648bb9ea016327a808fca6e2b4d8b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <vector>
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
32 public:
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 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);
49 private:
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 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());
93 sal_Int32 i(0);
94 bool bFound(false);
95 while ((i < nCount) && !bFound)
97 if (maRelations[i].RelationType == aRelationType)
98 return maRelations[i];
99 else
100 i++;
102 return AccessibleRelation();
105 void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
106 throw (uno::RuntimeException)
108 sal_Int32 nCount(getRelationCount());
109 sal_Int32 i(0);
110 bool bFound(false);
111 while ((i < nCount) && !bFound)
113 if (maRelations[i].RelationType == rRelation.RelationType)
114 bFound = true;
115 else
116 i++;
118 if (bFound)
119 maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
120 else
121 maRelations.push_back(rRelation);
124 //===== internal ============================================================
126 AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
127 : mpHelperImpl(NULL)
129 mpHelperImpl = new AccessibleRelationSetHelperImpl();
132 AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
133 : cppu::WeakImplHelper1<XAccessibleRelationSet>()
134 , mpHelperImpl(NULL)
136 if (rHelper.mpHelperImpl)
137 mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
138 else
139 mpHelperImpl = new AccessibleRelationSetHelperImpl();
142 AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
144 delete mpHelperImpl;
147 //===== XAccessibleRelationSet ==============================================
149 /** Returns the number of relations in this relation set.
151 @return
152 Returns the number of relations or zero if there are none.
154 sal_Int32 SAL_CALL
155 AccessibleRelationSetHelper::getRelationCount( )
156 throw (uno::RuntimeException, std::exception)
158 osl::MutexGuard aGuard (maMutex);
159 return mpHelperImpl->getRelationCount();
162 /** Returns the relation of this relation set that is specified by
163 the given index.
165 @param nIndex
166 This index specifies the relatio to return.
168 @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, std::exception)
180 osl::MutexGuard aGuard (maMutex);
181 return mpHelperImpl->getRelation(nIndex);
184 /** Tests whether the relation set contains a relation matching the
185 specified key.
187 @param aRelationType
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>.
192 @return
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.
196 sal_Bool SAL_CALL
197 AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType )
198 throw (uno::RuntimeException, std::exception)
200 osl::MutexGuard aGuard (maMutex);
201 return mpHelperImpl->containsRelation(aRelationType);
204 /** Retrieve and return the relation with the given relation type.
206 @param aRelationType
207 The type of the relation to return. This has to be one of the
208 constants of <type>AccessibleRelationType</type>.
210 @return
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, std::exception)
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, std::exception)
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;
248 uno::Sequence<sal_Int8> SAL_CALL
249 AccessibleRelationSetHelper::getImplementationId (void)
250 throw (::com::sun::star::uno::RuntimeException, std::exception)
252 return css::uno::Sequence<sal_Int8>();
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */