Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "unotools/accessiblestatesethelper.hxx"
21 : : #include <tools/debug.hxx>
22 : : #include <comphelper/servicehelper.hxx>
23 : :
24 : : // defines how many states the bitfield can contain
25 : : // it has the size of 64 because I use a uInt64
26 : : #define BITFIELDSIZE 64
27 : :
28 : : using namespace ::utl;
29 : : using namespace ::rtl;
30 : : using namespace ::com::sun::star;
31 : : using namespace ::com::sun::star::accessibility;
32 : :
33 : : class AccessibleStateSetHelperImpl
34 : : {
35 : : public:
36 : : AccessibleStateSetHelperImpl();
37 : : AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl);
38 : : ~AccessibleStateSetHelperImpl();
39 : :
40 : : sal_Bool IsEmpty () const
41 : : throw (uno::RuntimeException);
42 : : sal_Bool Contains (sal_Int16 aState) const
43 : : throw (uno::RuntimeException);
44 : : uno::Sequence<sal_Int16> GetStates() const
45 : : throw (uno::RuntimeException);
46 : : void AddState(sal_Int16 aState)
47 : : throw (uno::RuntimeException);
48 : : void RemoveState(sal_Int16 aState)
49 : : throw (uno::RuntimeException);
50 : :
51 : : inline void AddStates( const sal_Int64 _nStates ) SAL_THROW( ( ) );
52 : :
53 : : private:
54 : : sal_uInt64 maStates;
55 : : };
56 : :
57 : 6273 : AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl()
58 : 6273 : : maStates(0)
59 : : {
60 : 6273 : }
61 : :
62 : 59 : AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl)
63 : 59 : : maStates(rImpl.maStates)
64 : : {
65 : 59 : }
66 : :
67 : 6332 : AccessibleStateSetHelperImpl::~AccessibleStateSetHelperImpl()
68 : : {
69 : 6332 : }
70 : :
71 : 0 : inline sal_Bool AccessibleStateSetHelperImpl::IsEmpty () const
72 : : throw (uno::RuntimeException)
73 : : {
74 : 0 : return maStates == 0;
75 : : }
76 : :
77 : 6272 : inline sal_Bool AccessibleStateSetHelperImpl::Contains (sal_Int16 aState) const
78 : : throw (uno::RuntimeException)
79 : : {
80 : : DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
81 : 6272 : sal_uInt64 aTempBitSet(1);
82 : 6272 : aTempBitSet <<= aState;
83 : 6272 : return ((aTempBitSet & maStates) != 0);
84 : : }
85 : :
86 : 0 : inline uno::Sequence<sal_Int16> AccessibleStateSetHelperImpl::GetStates() const
87 : : throw (uno::RuntimeException)
88 : : {
89 : 0 : uno::Sequence<sal_Int16> aRet(BITFIELDSIZE);
90 [ # # ]: 0 : sal_Int16* pSeq = aRet.getArray();
91 : 0 : sal_Int16 nStateCount(0);
92 [ # # ]: 0 : for (sal_Int16 i = 0; i < BITFIELDSIZE; ++i)
93 [ # # ]: 0 : if (Contains(i))
94 : : {
95 : 0 : *pSeq = i;
96 : 0 : ++pSeq;
97 : 0 : ++nStateCount;
98 : : }
99 [ # # ]: 0 : aRet.realloc(nStateCount);
100 : 0 : return aRet;
101 : : }
102 : :
103 : 0 : inline void AccessibleStateSetHelperImpl::AddStates( const sal_Int64 _nStates ) SAL_THROW( ( ) )
104 : : {
105 : 0 : maStates |= _nStates;
106 : 0 : }
107 : :
108 : 29426 : inline void AccessibleStateSetHelperImpl::AddState(sal_Int16 aState)
109 : : throw (uno::RuntimeException)
110 : : {
111 : : DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
112 : 29426 : sal_uInt64 aTempBitSet(1);
113 : 29426 : aTempBitSet <<= aState;
114 : 29426 : maStates |= aTempBitSet;
115 : 29426 : }
116 : :
117 : 116 : inline void AccessibleStateSetHelperImpl::RemoveState(sal_Int16 aState)
118 : : throw (uno::RuntimeException)
119 : : {
120 : : DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
121 : 116 : sal_uInt64 aTempBitSet(1);
122 : 116 : aTempBitSet <<= aState;
123 : 116 : aTempBitSet = ~aTempBitSet;
124 : 116 : maStates &= aTempBitSet;
125 : 116 : }
126 : :
127 : : //===== internal ============================================================
128 : :
129 : 6273 : AccessibleStateSetHelper::AccessibleStateSetHelper ()
130 [ + - ]: 6273 : : mpHelperImpl(NULL)
131 : : {
132 [ + - ]: 6273 : mpHelperImpl = new AccessibleStateSetHelperImpl();
133 : 6273 : }
134 : :
135 : 0 : AccessibleStateSetHelper::AccessibleStateSetHelper ( const sal_Int64 _nInitialStates )
136 [ # # ]: 0 : : mpHelperImpl(NULL)
137 : : {
138 [ # # ]: 0 : mpHelperImpl = new AccessibleStateSetHelperImpl();
139 : 0 : mpHelperImpl->AddStates( _nInitialStates );
140 : 0 : }
141 : :
142 : 59 : AccessibleStateSetHelper::AccessibleStateSetHelper (const AccessibleStateSetHelper& rHelper)
143 : : : cppu::WeakImplHelper1<XAccessibleStateSet>()
144 [ + - ]: 59 : , mpHelperImpl(NULL)
145 : : {
146 [ + - ]: 59 : if (rHelper.mpHelperImpl)
147 [ + - ]: 59 : mpHelperImpl = new AccessibleStateSetHelperImpl(*rHelper.mpHelperImpl);
148 : : else
149 [ # # ]: 0 : mpHelperImpl = new AccessibleStateSetHelperImpl();
150 : 59 : }
151 : :
152 [ + - ]: 6332 : AccessibleStateSetHelper::~AccessibleStateSetHelper(void)
153 : : {
154 [ + - ]: 6332 : delete mpHelperImpl;
155 [ - + ]: 12664 : }
156 : :
157 : : //===== XAccessibleStateSet ==============================================
158 : :
159 : : /** Checks whether the current state set is empty.
160 : :
161 : : @return
162 : : Returns <TRUE/> if there is no state in this state set and
163 : : <FALSE/> if there is at least one state set in it.
164 : : */
165 : 0 : sal_Bool SAL_CALL AccessibleStateSetHelper::isEmpty ()
166 : : throw (uno::RuntimeException)
167 : : {
168 [ # # ]: 0 : osl::MutexGuard aGuard (maMutex);
169 [ # # ]: 0 : return mpHelperImpl->IsEmpty();
170 : : }
171 : :
172 : : /** Checks if the given state is a member of the state set of this
173 : : object.
174 : :
175 : : @param aState
176 : : The state for which to check membership. This has to be one of
177 : : the constants of <type>AccessibleStateType</type>.
178 : :
179 : : @return
180 : : Returns <TRUE/> if the given state is a memeber of this object's
181 : : state set and <FALSE/> otherwise.
182 : : */
183 : 6272 : sal_Bool SAL_CALL AccessibleStateSetHelper::contains (sal_Int16 aState)
184 : : throw (uno::RuntimeException)
185 : : {
186 [ + - ]: 6272 : osl::MutexGuard aGuard (maMutex);
187 [ + - ]: 6272 : return mpHelperImpl->Contains(aState);
188 : : }
189 : :
190 : : /** Checks if all of the given states are in this object's state
191 : : set.
192 : :
193 : : @param aStateSet
194 : : This sequence of states is interpreted as set and every of its
195 : : members, duplicates are ignored, is checked for membership in
196 : : this object's state set. Each state has to be one of the
197 : : constants of <type>AccessibleStateType</type>.
198 : :
199 : : @return
200 : : Returns <TRUE/> if all states of the given state set are members
201 : : of this object's state set. <FALSE/> is returned if at least
202 : : one of the states in the given state is not a member of this
203 : : object's state set.
204 : : */
205 : 0 : sal_Bool SAL_CALL AccessibleStateSetHelper::containsAll
206 : : (const uno::Sequence<sal_Int16>& rStateSet)
207 : : throw (uno::RuntimeException)
208 : : {
209 [ # # ]: 0 : osl::MutexGuard aGuard (maMutex);
210 : 0 : sal_Int32 nCount(rStateSet.getLength());
211 : 0 : const sal_Int16* pStates = rStateSet.getConstArray();
212 : 0 : sal_Int32 i = 0;
213 : 0 : sal_Bool bFound(sal_True);
214 [ # # ]: 0 : while (i < nCount)
215 : : {
216 : 0 : bFound = mpHelperImpl->Contains(pStates[i]);
217 : 0 : i++;
218 : : }
219 [ # # ]: 0 : return bFound;
220 : : }
221 : :
222 : 0 : uno::Sequence<sal_Int16> SAL_CALL AccessibleStateSetHelper::getStates()
223 : : throw (uno::RuntimeException)
224 : : {
225 [ # # ]: 0 : osl::MutexGuard aGuard(maMutex);
226 [ # # ][ # # ]: 0 : return mpHelperImpl->GetStates();
227 : : }
228 : :
229 : 29426 : void AccessibleStateSetHelper::AddState(sal_Int16 aState)
230 : : throw (uno::RuntimeException)
231 : : {
232 [ + - ]: 29426 : osl::MutexGuard aGuard (maMutex);
233 [ + - ]: 29426 : mpHelperImpl->AddState(aState);
234 : 29426 : }
235 : :
236 : 116 : void AccessibleStateSetHelper::RemoveState(sal_Int16 aState)
237 : : throw (uno::RuntimeException)
238 : : {
239 [ + - ]: 116 : osl::MutexGuard aGuard (maMutex);
240 [ + - ]: 116 : mpHelperImpl->RemoveState(aState);
241 : 116 : }
242 : :
243 : : //===== XTypeProvider =======================================================
244 : :
245 : : uno::Sequence< ::com::sun::star::uno::Type>
246 : 0 : AccessibleStateSetHelper::getTypes (void)
247 : : throw (::com::sun::star::uno::RuntimeException)
248 : : {
249 : : const ::com::sun::star::uno::Type aTypeList[] = {
250 : : ::getCppuType((const uno::Reference<
251 [ # # ]: 0 : XAccessibleStateSet>*)0),
252 : : ::getCppuType((const uno::Reference<
253 [ # # ]: 0 : lang::XTypeProvider>*)0)
254 [ # # # # ]: 0 : };
255 : : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
256 [ # # ]: 0 : aTypeSequence (aTypeList, 2);
257 [ # # ][ # # ]: 0 : return aTypeSequence;
258 : : }
259 : :
260 : : namespace
261 : : {
262 : : class theAccessibleStateSetHelperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theAccessibleStateSetHelperUnoTunnelId > {};
263 : : }
264 : :
265 : : uno::Sequence<sal_Int8> SAL_CALL
266 : 0 : AccessibleStateSetHelper::getImplementationId (void)
267 : : throw (::com::sun::star::uno::RuntimeException)
268 : : {
269 : 0 : return theAccessibleStateSetHelperUnoTunnelId::get().getSeq();
270 : : }
271 : :
272 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|