Update ooo320-m1
[ooovba.git] / comphelper / source / misc / accimplaccess.cxx
blobbbbb500c7020309df00813bf0f5af68ccab6de93
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: accimplaccess.cxx,v $
10 * $Revision: 1.9 $
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_comphelper.hxx"
33 #include <comphelper/accimplaccess.hxx>
34 #include <com/sun/star/accessibility/XAccessible.hpp>
35 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
36 #include <cppuhelper/typeprovider.hxx>
38 #include <set>
40 //.........................................................................
41 namespace comphelper
43 //.........................................................................
45 #define BITFIELDSIZE ( sizeof( sal_Int64 ) * 8 )
46 // maximum number of bits we have in a sal_Int64
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::uno::UNO_QUERY;
52 using ::com::sun::star::uno::RuntimeException;
53 using ::com::sun::star::lang::XUnoTunnel;
54 using ::com::sun::star::accessibility::XAccessible;
55 using ::com::sun::star::accessibility::XAccessibleContext;
57 //=====================================================================
58 //= OAccImpl_Impl
59 //=====================================================================
60 struct OAccImpl_Impl
62 Reference< XAccessible > m_xAccParent;
63 sal_Int64 m_nForeignControlledStates;
67 //=====================================================================
68 //= OAccessibleImplementationAccess
69 //=====================================================================
70 //---------------------------------------------------------------------
71 OAccessibleImplementationAccess::OAccessibleImplementationAccess( )
72 :m_pImpl( new OAccImpl_Impl )
76 //---------------------------------------------------------------------
77 OAccessibleImplementationAccess::~OAccessibleImplementationAccess( )
79 delete m_pImpl;
80 m_pImpl = NULL;
83 //---------------------------------------------------------------------
84 Reference< XAccessible > OAccessibleImplementationAccess::implGetForeignControlledParent( ) const
86 return m_pImpl->m_xAccParent;
89 //---------------------------------------------------------------------
90 void OAccessibleImplementationAccess::setAccessibleParent( const Reference< XAccessible >& _rxAccParent )
92 m_pImpl->m_xAccParent = _rxAccParent;
95 //---------------------------------------------------------------------
96 sal_Int64 OAccessibleImplementationAccess::implGetForeignControlledStates( ) const
98 return m_pImpl->m_nForeignControlledStates;
101 //---------------------------------------------------------------------
102 void OAccessibleImplementationAccess::setStateBit( const sal_Int16 _nState, const sal_Bool _bSet )
104 OSL_ENSURE( _nState >= 0 && static_cast< sal_uInt16 >(_nState) < BITFIELDSIZE, "OAccessibleImplementationAccess::setStateBit: no more bits (shutting down the universe now)!" );
106 sal_uInt64 nBitMask( 1 );
107 nBitMask <<= _nState;
108 if ( _bSet )
109 m_pImpl->m_nForeignControlledStates |= nBitMask;
110 else
111 m_pImpl->m_nForeignControlledStates &= ~nBitMask;
114 //---------------------------------------------------------------------
115 sal_Bool OAccessibleImplementationAccess::setForeignControlledState( const Reference< XAccessibleContext >& _rxComponent, const sal_Int16 _nState,
116 const sal_Bool _bSet )
118 OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
120 if ( pImplementation )
121 pImplementation->setStateBit( _nState, _bSet );
123 return ( NULL != pImplementation );
126 //---------------------------------------------------------------------
127 const Sequence< sal_Int8 >& OAccessibleImplementationAccess::getUnoTunnelImplementationId()
129 static Sequence< sal_Int8 > aId;
130 if ( !aId.getLength() )
132 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
133 if ( !aId.getLength() )
135 static ::cppu::OImplementationId aImplId;
136 // unfortunately, the OImplementationId::getImplementationId returns a copy, not a static reference ...
137 aId = aImplId.getImplementationId();
140 return aId;
143 //---------------------------------------------------------------------
144 sal_Int64 SAL_CALL OAccessibleImplementationAccess::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw (RuntimeException)
146 sal_Int64 nReturn( 0 );
148 if ( ( _rIdentifier.getLength() == 16 )
149 && ( 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
151 nReturn = reinterpret_cast< sal_Int64 >( this );
153 return nReturn;
156 //---------------------------------------------------------------------
157 OAccessibleImplementationAccess* OAccessibleImplementationAccess::getImplementation( const Reference< XAccessibleContext >& _rxComponent )
159 OAccessibleImplementationAccess* pImplementation = NULL;
162 Reference< XUnoTunnel > xTunnel( _rxComponent, UNO_QUERY );
163 if ( xTunnel.is() )
165 pImplementation = reinterpret_cast< OAccessibleImplementationAccess* >(
166 xTunnel->getSomething( getUnoTunnelImplementationId() ) );
169 catch( const Exception& )
171 OSL_ENSURE( sal_False, "OAccessibleImplementationAccess::setAccessibleParent: caught an exception while retrieving the implementation!" );
173 return pImplementation;
176 //---------------------------------------------------------------------
177 sal_Bool OAccessibleImplementationAccess::setAccessibleParent(
178 const Reference< XAccessibleContext >& _rxComponent, const Reference< XAccessible >& _rxNewParent )
180 OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
182 if ( pImplementation )
183 pImplementation->setAccessibleParent( _rxNewParent );
185 return ( NULL != pImplementation );
188 //.........................................................................
189 } // namespace comphelper
190 //.........................................................................