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/accessiblestatesethelper.hxx>
21 #include <tools/debug.hxx>
22 #include <comphelper/servicehelper.hxx>
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
28 using namespace ::utl
;
29 using namespace ::rtl
;
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::accessibility
;
33 class AccessibleStateSetHelperImpl
36 AccessibleStateSetHelperImpl();
37 AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl
& rImpl
);
38 ~AccessibleStateSetHelperImpl();
41 throw (uno::RuntimeException
);
42 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
);
51 inline void AddStates( const sal_Int64 _nStates
) SAL_THROW( ( ) );
57 AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl()
62 AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl
& rImpl
)
63 : maStates(rImpl
.maStates
)
67 AccessibleStateSetHelperImpl::~AccessibleStateSetHelperImpl()
71 inline bool AccessibleStateSetHelperImpl::IsEmpty () const
72 throw (uno::RuntimeException
)
77 inline bool AccessibleStateSetHelperImpl::Contains (sal_Int16 aState
) const
78 throw (uno::RuntimeException
)
80 DBG_ASSERT(aState
< BITFIELDSIZE
, "the statesset is too small");
81 sal_uInt64
aTempBitSet(1);
82 aTempBitSet
<<= aState
;
83 return ((aTempBitSet
& maStates
) != 0);
86 inline uno::Sequence
<sal_Int16
> AccessibleStateSetHelperImpl::GetStates() const
87 throw (uno::RuntimeException
)
89 uno::Sequence
<sal_Int16
> aRet(BITFIELDSIZE
);
90 sal_Int16
* pSeq
= aRet
.getArray();
91 sal_Int16
nStateCount(0);
92 for (sal_Int16 i
= 0; i
< BITFIELDSIZE
; ++i
)
99 aRet
.realloc(nStateCount
);
103 inline void AccessibleStateSetHelperImpl::AddStates( const sal_Int64 _nStates
) SAL_THROW( ( ) )
105 maStates
|= _nStates
;
108 inline void AccessibleStateSetHelperImpl::AddState(sal_Int16 aState
)
109 throw (uno::RuntimeException
)
111 DBG_ASSERT(aState
< BITFIELDSIZE
, "the statesset is too small");
112 sal_uInt64
aTempBitSet(1);
113 aTempBitSet
<<= aState
;
114 maStates
|= aTempBitSet
;
117 inline void AccessibleStateSetHelperImpl::RemoveState(sal_Int16 aState
)
118 throw (uno::RuntimeException
)
120 DBG_ASSERT(aState
< BITFIELDSIZE
, "the statesset is too small");
121 sal_uInt64
aTempBitSet(1);
122 aTempBitSet
<<= aState
;
123 aTempBitSet
= ~aTempBitSet
;
124 maStates
&= aTempBitSet
;
127 //===== internal ============================================================
129 AccessibleStateSetHelper::AccessibleStateSetHelper ()
132 mpHelperImpl
= new AccessibleStateSetHelperImpl();
135 AccessibleStateSetHelper::AccessibleStateSetHelper ( const sal_Int64 _nInitialStates
)
138 mpHelperImpl
= new AccessibleStateSetHelperImpl();
139 mpHelperImpl
->AddStates( _nInitialStates
);
142 AccessibleStateSetHelper::AccessibleStateSetHelper (const AccessibleStateSetHelper
& rHelper
)
143 : cppu::WeakImplHelper1
<XAccessibleStateSet
>()
146 if (rHelper
.mpHelperImpl
)
147 mpHelperImpl
= new AccessibleStateSetHelperImpl(*rHelper
.mpHelperImpl
);
149 mpHelperImpl
= new AccessibleStateSetHelperImpl();
152 AccessibleStateSetHelper::~AccessibleStateSetHelper(void)
157 //===== XAccessibleStateSet ==============================================
159 /** Checks whether the current state set is empty.
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.
165 sal_Bool SAL_CALL
AccessibleStateSetHelper::isEmpty ()
166 throw (uno::RuntimeException
, std::exception
)
168 osl::MutexGuard
aGuard (maMutex
);
169 return mpHelperImpl
->IsEmpty();
172 /** Checks if the given state is a member of the state set of this
176 The state for which to check membership. This has to be one of
177 the constants of <type>AccessibleStateType</type>.
180 Returns <TRUE/> if the given state is a member of this object's
181 state set and <FALSE/> otherwise.
183 sal_Bool SAL_CALL
AccessibleStateSetHelper::contains (sal_Int16 aState
)
184 throw (uno::RuntimeException
, std::exception
)
186 osl::MutexGuard
aGuard (maMutex
);
187 return mpHelperImpl
->Contains(aState
);
190 /** Checks if all of the given states are in this object's state
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>.
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
205 sal_Bool SAL_CALL
AccessibleStateSetHelper::containsAll
206 (const uno::Sequence
<sal_Int16
>& rStateSet
)
207 throw (uno::RuntimeException
, std::exception
)
209 osl::MutexGuard
aGuard (maMutex
);
210 sal_Int32
nCount(rStateSet
.getLength());
211 const sal_Int16
* pStates
= rStateSet
.getConstArray();
216 bFound
= mpHelperImpl
->Contains(pStates
[i
]);
222 uno::Sequence
<sal_Int16
> SAL_CALL
AccessibleStateSetHelper::getStates()
223 throw (uno::RuntimeException
, std::exception
)
225 osl::MutexGuard
aGuard(maMutex
);
226 return mpHelperImpl
->GetStates();
229 void AccessibleStateSetHelper::AddState(sal_Int16 aState
)
230 throw (uno::RuntimeException
)
232 osl::MutexGuard
aGuard (maMutex
);
233 mpHelperImpl
->AddState(aState
);
236 void AccessibleStateSetHelper::RemoveState(sal_Int16 aState
)
237 throw (uno::RuntimeException
)
239 osl::MutexGuard
aGuard (maMutex
);
240 mpHelperImpl
->RemoveState(aState
);
243 //===== XTypeProvider =======================================================
245 uno::Sequence
< ::com::sun::star::uno::Type
>
246 AccessibleStateSetHelper::getTypes (void)
247 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
249 const ::com::sun::star::uno::Type aTypeList
[] = {
250 ::getCppuType((const uno::Reference
<
251 XAccessibleStateSet
>*)0),
252 ::getCppuType((const uno::Reference
<
253 lang::XTypeProvider
>*)0)
255 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
>
256 aTypeSequence (aTypeList
, 2);
257 return aTypeSequence
;
260 uno::Sequence
<sal_Int8
> SAL_CALL
261 AccessibleStateSetHelper::getImplementationId (void)
262 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
264 return css::uno::Sequence
<sal_Int8
>();
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */