update dev300-m58
[ooovba.git] / unotools / source / accessibility / accessiblerelationsethelper.cxx
blob3df47aafac9e2ab4b3cecfc24ae4f755d6e2da72
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessiblerelationsethelper.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_unotools.hxx"
35 #include "unotools/accessiblerelationsethelper.hxx"
36 #include <rtl/uuid.h>
37 #include <vector>
38 #include <comphelper/sequence.hxx>
40 using namespace ::utl;
41 using namespace ::rtl;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::accessibility;
45 class AccessibleRelationSetHelperImpl
47 public:
48 AccessibleRelationSetHelperImpl();
49 AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl);
50 ~AccessibleRelationSetHelperImpl();
52 sal_Int32 getRelationCount( )
53 throw (uno::RuntimeException);
54 AccessibleRelation getRelation( sal_Int32 nIndex )
55 throw (lang::IndexOutOfBoundsException,
56 uno::RuntimeException);
57 sal_Bool containsRelation( sal_Int16 aRelationType )
58 throw (uno::RuntimeException);
59 AccessibleRelation getRelationByType( sal_Int16 aRelationType )
60 throw (uno::RuntimeException);
61 void AddRelation(const AccessibleRelation& rRelation)
62 throw (uno::RuntimeException);
64 private:
65 std::vector<AccessibleRelation> maRelations;
68 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
72 AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl)
73 : maRelations(rImpl.maRelations)
77 AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
81 sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount( )
82 throw (uno::RuntimeException)
84 return maRelations.size();
87 AccessibleRelation AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex )
88 throw (lang::IndexOutOfBoundsException,
89 uno::RuntimeException)
91 if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
92 throw lang::IndexOutOfBoundsException();
93 return maRelations[nIndex];
96 sal_Bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType )
97 throw (uno::RuntimeException)
99 AccessibleRelation defaultRelation; // default is INVALID
100 AccessibleRelation relationByType = getRelationByType(aRelationType);
101 return relationByType.RelationType != defaultRelation.RelationType;
104 AccessibleRelation AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType )
105 throw (uno::RuntimeException)
107 sal_Int32 nCount(getRelationCount());
108 sal_Int32 i(0);
109 sal_Bool bFound(sal_False);
110 while ((i < nCount) && !bFound)
112 if (maRelations[i].RelationType == aRelationType)
113 return maRelations[i];
114 else
115 i++;
117 return AccessibleRelation();
120 void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
121 throw (uno::RuntimeException)
123 sal_Int32 nCount(getRelationCount());
124 sal_Int32 i(0);
125 sal_Bool bFound(sal_False);
126 while ((i < nCount) && !bFound)
128 if (maRelations[i].RelationType == rRelation.RelationType)
129 bFound = sal_True;
130 else
131 i++;
133 if (bFound)
134 maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
135 else
136 maRelations.push_back(rRelation);
139 //===== internal ============================================================
141 AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
142 : mpHelperImpl(NULL)
144 mpHelperImpl = new AccessibleRelationSetHelperImpl();
147 AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
148 : cppu::WeakImplHelper1<XAccessibleRelationSet>()
149 , mpHelperImpl(NULL)
151 if (rHelper.mpHelperImpl)
152 mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
153 else
154 mpHelperImpl = new AccessibleRelationSetHelperImpl();
157 AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
159 delete mpHelperImpl;
162 //===== XAccessibleRelationSet ==============================================
164 /** Returns the number of relations in this relation set.
166 @return
167 Returns the number of relations or zero if there are none.
169 sal_Int32 SAL_CALL
170 AccessibleRelationSetHelper::getRelationCount( )
171 throw (uno::RuntimeException)
173 ::vos::OGuard aGuard (maMutex);
174 return mpHelperImpl->getRelationCount();
177 /** Returns the relation of this relation set that is specified by
178 the given index.
180 @param nIndex
181 This index specifies the relatio to return.
183 @return
184 For a valid index, i.e. inside the range 0 to the number of
185 relations minus one, the returned value is the requested
186 relation. If the index is invalid then the returned relation
187 has the type INVALID.
190 AccessibleRelation SAL_CALL
191 AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
192 throw (lang::IndexOutOfBoundsException,
193 uno::RuntimeException)
195 ::vos::OGuard aGuard (maMutex);
196 return mpHelperImpl->getRelation(nIndex);
199 /** Tests whether the relation set contains a relation matching the
200 specified key.
202 @param aRelationType
203 The type of relation to look for in this set of relations. This
204 has to be one of the constants of
205 <type>AccessibleRelationType</type>.
207 @return
208 Returns <TRUE/> if there is a (at least one) relation of the
209 given type and <FALSE/> if there is no such relation in the set.
211 sal_Bool SAL_CALL
212 AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType )
213 throw (uno::RuntimeException)
215 ::vos::OGuard aGuard (maMutex);
216 return mpHelperImpl->containsRelation(aRelationType);
219 /** Retrieve and return the relation with the given relation type.
221 @param aRelationType
222 The type of the relation to return. This has to be one of the
223 constants of <type>AccessibleRelationType</type>.
225 @return
226 If a relation with the given type could be found than (a copy
227 of) this relation is returned. Otherwise a relation with the
228 type INVALID is returned.
230 AccessibleRelation SAL_CALL
231 AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType )
232 throw (uno::RuntimeException)
234 ::vos::OGuard aGuard (maMutex);
235 return mpHelperImpl->getRelationByType(aRelationType);
238 void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
239 throw (uno::RuntimeException)
241 ::vos::OGuard aGuard (maMutex);
242 mpHelperImpl->AddRelation(rRelation);
245 //===== XTypeProvider =======================================================
247 uno::Sequence< ::com::sun::star::uno::Type>
248 AccessibleRelationSetHelper::getTypes (void)
249 throw (::com::sun::star::uno::RuntimeException)
251 ::vos::OGuard aGuard (maMutex);
252 const ::com::sun::star::uno::Type aTypeList[] = {
253 ::getCppuType((const uno::Reference<
254 XAccessibleRelationSet>*)0),
255 ::getCppuType((const uno::Reference<
256 lang::XTypeProvider>*)0)
258 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
259 aTypeSequence (aTypeList, 2);
260 return aTypeSequence;
263 uno::Sequence<sal_Int8> SAL_CALL
264 AccessibleRelationSetHelper::getImplementationId (void)
265 throw (::com::sun::star::uno::RuntimeException)
267 ::vos::OGuard aGuard (maMutex);
268 static uno::Sequence<sal_Int8> aId;
269 if (aId.getLength() == 0)
271 aId.realloc (16);
272 rtl_createUuid ((sal_uInt8 *)aId.getArray(), 0, sal_True);
274 return aId;