1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b5088357SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b5088357SAndrew Rist * distributed with this work for additional information
6*b5088357SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b5088357SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist * with the License. You may obtain a copy of the License at
10*b5088357SAndrew Rist *
11*b5088357SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist *
13*b5088357SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist * software distributed under the License is distributed on an
15*b5088357SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist * KIND, either express or implied. See the License for the
17*b5088357SAndrew Rist * specific language governing permissions and limitations
18*b5088357SAndrew Rist * under the License.
19*b5088357SAndrew Rist *
20*b5088357SAndrew Rist *************************************************************/
21*b5088357SAndrew Rist
22*b5088357SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "unotools/accessiblerelationsethelper.hxx"
29cdf0e10cSrcweir #include <rtl/uuid.h>
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir #include <comphelper/sequence.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::utl;
34cdf0e10cSrcweir using namespace ::rtl;
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
37cdf0e10cSrcweir
38cdf0e10cSrcweir class AccessibleRelationSetHelperImpl
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir AccessibleRelationSetHelperImpl();
42cdf0e10cSrcweir AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl);
43cdf0e10cSrcweir ~AccessibleRelationSetHelperImpl();
44cdf0e10cSrcweir
45cdf0e10cSrcweir sal_Int32 getRelationCount( )
46cdf0e10cSrcweir throw (uno::RuntimeException);
47cdf0e10cSrcweir AccessibleRelation getRelation( sal_Int32 nIndex )
48cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException,
49cdf0e10cSrcweir uno::RuntimeException);
50cdf0e10cSrcweir sal_Bool containsRelation( sal_Int16 aRelationType )
51cdf0e10cSrcweir throw (uno::RuntimeException);
52cdf0e10cSrcweir AccessibleRelation getRelationByType( sal_Int16 aRelationType )
53cdf0e10cSrcweir throw (uno::RuntimeException);
54cdf0e10cSrcweir void AddRelation(const AccessibleRelation& rRelation)
55cdf0e10cSrcweir throw (uno::RuntimeException);
56cdf0e10cSrcweir
57cdf0e10cSrcweir private:
58cdf0e10cSrcweir std::vector<AccessibleRelation> maRelations;
59cdf0e10cSrcweir };
60cdf0e10cSrcweir
AccessibleRelationSetHelperImpl()61cdf0e10cSrcweir AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl & rImpl)65cdf0e10cSrcweir AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl)
66cdf0e10cSrcweir : maRelations(rImpl.maRelations)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
~AccessibleRelationSetHelperImpl()70cdf0e10cSrcweir AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
getRelationCount()74cdf0e10cSrcweir sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount( )
75cdf0e10cSrcweir throw (uno::RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir return maRelations.size();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
getRelation(sal_Int32 nIndex)80cdf0e10cSrcweir AccessibleRelation AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex )
81cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException,
82cdf0e10cSrcweir uno::RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
85cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
86cdf0e10cSrcweir return maRelations[nIndex];
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
containsRelation(sal_Int16 aRelationType)89cdf0e10cSrcweir sal_Bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType )
90cdf0e10cSrcweir throw (uno::RuntimeException)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir AccessibleRelation defaultRelation; // default is INVALID
93cdf0e10cSrcweir AccessibleRelation relationByType = getRelationByType(aRelationType);
94cdf0e10cSrcweir return relationByType.RelationType != defaultRelation.RelationType;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
getRelationByType(sal_Int16 aRelationType)97cdf0e10cSrcweir AccessibleRelation AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType )
98cdf0e10cSrcweir throw (uno::RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir sal_Int32 nCount(getRelationCount());
101cdf0e10cSrcweir sal_Int32 i(0);
102cdf0e10cSrcweir sal_Bool bFound(sal_False);
103cdf0e10cSrcweir while ((i < nCount) && !bFound)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if (maRelations[i].RelationType == aRelationType)
106cdf0e10cSrcweir return maRelations[i];
107cdf0e10cSrcweir else
108cdf0e10cSrcweir i++;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir return AccessibleRelation();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
AddRelation(const AccessibleRelation & rRelation)113cdf0e10cSrcweir void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
114cdf0e10cSrcweir throw (uno::RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir sal_Int32 nCount(getRelationCount());
117cdf0e10cSrcweir sal_Int32 i(0);
118cdf0e10cSrcweir sal_Bool bFound(sal_False);
119cdf0e10cSrcweir while ((i < nCount) && !bFound)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir if (maRelations[i].RelationType == rRelation.RelationType)
122cdf0e10cSrcweir bFound = sal_True;
123cdf0e10cSrcweir else
124cdf0e10cSrcweir i++;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir if (bFound)
127cdf0e10cSrcweir maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
128cdf0e10cSrcweir else
129cdf0e10cSrcweir maRelations.push_back(rRelation);
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir //===== internal ============================================================
133cdf0e10cSrcweir
AccessibleRelationSetHelper()134cdf0e10cSrcweir AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
135cdf0e10cSrcweir : mpHelperImpl(NULL)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir mpHelperImpl = new AccessibleRelationSetHelperImpl();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
AccessibleRelationSetHelper(const AccessibleRelationSetHelper & rHelper)140cdf0e10cSrcweir AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
141cdf0e10cSrcweir : cppu::WeakImplHelper1<XAccessibleRelationSet>()
142cdf0e10cSrcweir , mpHelperImpl(NULL)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir if (rHelper.mpHelperImpl)
145cdf0e10cSrcweir mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
146cdf0e10cSrcweir else
147cdf0e10cSrcweir mpHelperImpl = new AccessibleRelationSetHelperImpl();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
~AccessibleRelationSetHelper(void)150cdf0e10cSrcweir AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir delete mpHelperImpl;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir //===== XAccessibleRelationSet ==============================================
156cdf0e10cSrcweir
157cdf0e10cSrcweir /** Returns the number of relations in this relation set.
158cdf0e10cSrcweir
159cdf0e10cSrcweir @return
160cdf0e10cSrcweir Returns the number of relations or zero if there are none.
161cdf0e10cSrcweir */
162cdf0e10cSrcweir sal_Int32 SAL_CALL
getRelationCount()163cdf0e10cSrcweir AccessibleRelationSetHelper::getRelationCount( )
164cdf0e10cSrcweir throw (uno::RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
167cdf0e10cSrcweir return mpHelperImpl->getRelationCount();
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir /** Returns the relation of this relation set that is specified by
171cdf0e10cSrcweir the given index.
172cdf0e10cSrcweir
173cdf0e10cSrcweir @param nIndex
174cdf0e10cSrcweir This index specifies the relatio to return.
175cdf0e10cSrcweir
176cdf0e10cSrcweir @return
177cdf0e10cSrcweir For a valid index, i.e. inside the range 0 to the number of
178cdf0e10cSrcweir relations minus one, the returned value is the requested
179cdf0e10cSrcweir relation. If the index is invalid then the returned relation
180cdf0e10cSrcweir has the type INVALID.
181cdf0e10cSrcweir
182cdf0e10cSrcweir */
183cdf0e10cSrcweir AccessibleRelation SAL_CALL
getRelation(sal_Int32 nIndex)184cdf0e10cSrcweir AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
185cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException,
186cdf0e10cSrcweir uno::RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
189cdf0e10cSrcweir return mpHelperImpl->getRelation(nIndex);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir /** Tests whether the relation set contains a relation matching the
193cdf0e10cSrcweir specified key.
194cdf0e10cSrcweir
195cdf0e10cSrcweir @param aRelationType
196cdf0e10cSrcweir The type of relation to look for in this set of relations. This
197cdf0e10cSrcweir has to be one of the constants of
198cdf0e10cSrcweir <type>AccessibleRelationType</type>.
199cdf0e10cSrcweir
200cdf0e10cSrcweir @return
201cdf0e10cSrcweir Returns <TRUE/> if there is a (at least one) relation of the
202cdf0e10cSrcweir given type and <FALSE/> if there is no such relation in the set.
203cdf0e10cSrcweir */
204cdf0e10cSrcweir sal_Bool SAL_CALL
containsRelation(sal_Int16 aRelationType)205cdf0e10cSrcweir AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType )
206cdf0e10cSrcweir throw (uno::RuntimeException)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
209cdf0e10cSrcweir return mpHelperImpl->containsRelation(aRelationType);
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir /** Retrieve and return the relation with the given relation type.
213cdf0e10cSrcweir
214cdf0e10cSrcweir @param aRelationType
215cdf0e10cSrcweir The type of the relation to return. This has to be one of the
216cdf0e10cSrcweir constants of <type>AccessibleRelationType</type>.
217cdf0e10cSrcweir
218cdf0e10cSrcweir @return
219cdf0e10cSrcweir If a relation with the given type could be found than (a copy
220cdf0e10cSrcweir of) this relation is returned. Otherwise a relation with the
221cdf0e10cSrcweir type INVALID is returned.
222cdf0e10cSrcweir */
223cdf0e10cSrcweir AccessibleRelation SAL_CALL
getRelationByType(sal_Int16 aRelationType)224cdf0e10cSrcweir AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType )
225cdf0e10cSrcweir throw (uno::RuntimeException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
228cdf0e10cSrcweir return mpHelperImpl->getRelationByType(aRelationType);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
AddRelation(const AccessibleRelation & rRelation)231cdf0e10cSrcweir void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
232cdf0e10cSrcweir throw (uno::RuntimeException)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
235cdf0e10cSrcweir mpHelperImpl->AddRelation(rRelation);
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir //===== XTypeProvider =======================================================
239cdf0e10cSrcweir
240cdf0e10cSrcweir uno::Sequence< ::com::sun::star::uno::Type>
getTypes(void)241cdf0e10cSrcweir AccessibleRelationSetHelper::getTypes (void)
242cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
245cdf0e10cSrcweir const ::com::sun::star::uno::Type aTypeList[] = {
246cdf0e10cSrcweir ::getCppuType((const uno::Reference<
247cdf0e10cSrcweir XAccessibleRelationSet>*)0),
248cdf0e10cSrcweir ::getCppuType((const uno::Reference<
249cdf0e10cSrcweir lang::XTypeProvider>*)0)
250cdf0e10cSrcweir };
251cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
252cdf0e10cSrcweir aTypeSequence (aTypeList, 2);
253cdf0e10cSrcweir return aTypeSequence;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
getImplementationId(void)257cdf0e10cSrcweir AccessibleRelationSetHelper::getImplementationId (void)
258cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir ::vos::OGuard aGuard (maMutex);
261cdf0e10cSrcweir static uno::Sequence<sal_Int8> aId;
262cdf0e10cSrcweir if (aId.getLength() == 0)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir aId.realloc (16);
265cdf0e10cSrcweir rtl_createUuid ((sal_uInt8 *)aId.getArray(), 0, sal_True);
266cdf0e10cSrcweir }
267cdf0e10cSrcweir return aId;
268cdf0e10cSrcweir }
269