Bump version to 4.3-4
[LibreOffice.git] / comphelper / source / misc / accimplaccess.cxx
blob6cf56370a0067c39fc0513fb060b49077ac953ad
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/accimplaccess.hxx>
21 #include <com/sun/star/accessibility/XAccessible.hpp>
22 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
23 #include <cppuhelper/typeprovider.hxx>
25 #include <set>
26 #include <string.h>
29 namespace comphelper
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
35 using ::com::sun::star::uno::Exception;
36 using ::com::sun::star::uno::UNO_QUERY;
37 using ::com::sun::star::uno::RuntimeException;
38 using ::com::sun::star::lang::XUnoTunnel;
39 using ::com::sun::star::accessibility::XAccessible;
40 using ::com::sun::star::accessibility::XAccessibleContext;
43 //= OAccImpl_Impl
45 struct OAccImpl_Impl
47 Reference< XAccessible > m_xAccParent;
48 sal_Int64 m_nForeignControlledStates;
53 //= OAccessibleImplementationAccess
56 OAccessibleImplementationAccess::OAccessibleImplementationAccess( )
57 :m_pImpl( new OAccImpl_Impl )
62 OAccessibleImplementationAccess::~OAccessibleImplementationAccess( )
64 delete m_pImpl;
65 m_pImpl = NULL;
69 Reference< XAccessible > OAccessibleImplementationAccess::implGetForeignControlledParent( ) const
71 return m_pImpl->m_xAccParent;
75 void OAccessibleImplementationAccess::setAccessibleParent( const Reference< XAccessible >& _rxAccParent )
77 m_pImpl->m_xAccParent = _rxAccParent;
81 sal_Int64 OAccessibleImplementationAccess::implGetForeignControlledStates( ) const
83 return m_pImpl->m_nForeignControlledStates;
87 void OAccessibleImplementationAccess::setStateBit( const sal_Int16 _nState, const sal_Bool _bSet )
89 OSL_ENSURE( _nState >= 0 && static_cast< sal_uInt16 >(_nState) < sizeof( sal_Int64 ) * 8, "OAccessibleImplementationAccess::setStateBit: no more bits (shutting down the universe now)!" );
91 sal_uInt64 nBitMask( 1 );
92 nBitMask <<= _nState;
93 if ( _bSet )
94 m_pImpl->m_nForeignControlledStates |= nBitMask;
95 else
96 m_pImpl->m_nForeignControlledStates &= ~nBitMask;
99 namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
102 const Sequence< sal_Int8 > OAccessibleImplementationAccess::getUnoTunnelImplementationId()
104 ::cppu::OImplementationId &rID = lcl_ImplId::get();
105 return rID.getImplementationId();
109 sal_Int64 SAL_CALL OAccessibleImplementationAccess::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw (RuntimeException, std::exception)
111 sal_Int64 nReturn( 0 );
113 if ( ( _rIdentifier.getLength() == 16 )
114 && ( 0 == memcmp( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
116 nReturn = reinterpret_cast< sal_Int64 >( this );
118 return nReturn;
122 OAccessibleImplementationAccess* OAccessibleImplementationAccess::getImplementation( const Reference< XAccessibleContext >& _rxComponent )
124 OAccessibleImplementationAccess* pImplementation = NULL;
127 Reference< XUnoTunnel > xTunnel( _rxComponent, UNO_QUERY );
128 if ( xTunnel.is() )
130 pImplementation = reinterpret_cast< OAccessibleImplementationAccess* >(
131 xTunnel->getSomething( getUnoTunnelImplementationId() ) );
134 catch( const Exception& )
136 OSL_FAIL( "OAccessibleImplementationAccess::setAccessibleParent: caught an exception while retrieving the implementation!" );
138 return pImplementation;
142 bool OAccessibleImplementationAccess::setAccessibleParent(
143 const Reference< XAccessibleContext >& _rxComponent, const Reference< XAccessible >& _rxNewParent )
145 OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
147 if ( pImplementation )
148 pImplementation->setAccessibleParent( _rxNewParent );
150 return ( NULL != pImplementation );
154 } // namespace comphelper
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */