bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / accimplaccess.cxx
blob9042b371b6a8de429a920278b07b27d02c81209d
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>
24 #include <osl/diagnose.h>
26 #include <set>
27 #include <string.h>
30 namespace comphelper
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::uno::Exception;
37 using ::com::sun::star::uno::UNO_QUERY;
38 using ::com::sun::star::uno::RuntimeException;
39 using ::com::sun::star::lang::XUnoTunnel;
40 using ::com::sun::star::accessibility::XAccessible;
41 using ::com::sun::star::accessibility::XAccessibleContext;
43 struct OAccImpl_Impl
45 Reference< XAccessible > m_xAccParent;
46 sal_Int64 m_nForeignControlledStates;
49 OAccessibleImplementationAccess::OAccessibleImplementationAccess( )
50 :m_pImpl( new OAccImpl_Impl )
55 OAccessibleImplementationAccess::~OAccessibleImplementationAccess( )
57 delete m_pImpl;
58 m_pImpl = NULL;
62 Reference< XAccessible > OAccessibleImplementationAccess::implGetForeignControlledParent( ) const
64 return m_pImpl->m_xAccParent;
68 void OAccessibleImplementationAccess::setAccessibleParent( const Reference< XAccessible >& _rxAccParent )
70 m_pImpl->m_xAccParent = _rxAccParent;
74 sal_Int64 OAccessibleImplementationAccess::implGetForeignControlledStates( ) const
76 return m_pImpl->m_nForeignControlledStates;
80 void OAccessibleImplementationAccess::setStateBit( const sal_Int16 _nState, const bool _bSet )
82 OSL_ENSURE( _nState >= 0 && static_cast< sal_uInt16 >(_nState) < sizeof( sal_Int64 ) * 8, "OAccessibleImplementationAccess::setStateBit: no more bits (shutting down the universe now)!" );
84 sal_uInt64 nBitMask( 1 );
85 nBitMask <<= _nState;
86 if ( _bSet )
87 m_pImpl->m_nForeignControlledStates |= nBitMask;
88 else
89 m_pImpl->m_nForeignControlledStates &= ~nBitMask;
92 namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
95 const Sequence< sal_Int8 > OAccessibleImplementationAccess::getUnoTunnelImplementationId()
97 ::cppu::OImplementationId &rID = lcl_ImplId::get();
98 return rID.getImplementationId();
102 sal_Int64 SAL_CALL OAccessibleImplementationAccess::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw (RuntimeException, std::exception)
104 sal_Int64 nReturn( 0 );
106 if ( ( _rIdentifier.getLength() == 16 )
107 && ( 0 == memcmp( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
109 nReturn = reinterpret_cast< sal_Int64 >( this );
111 return nReturn;
115 OAccessibleImplementationAccess* OAccessibleImplementationAccess::getImplementation( const Reference< XAccessibleContext >& _rxComponent )
117 OAccessibleImplementationAccess* pImplementation = NULL;
120 Reference< XUnoTunnel > xTunnel( _rxComponent, UNO_QUERY );
121 if ( xTunnel.is() )
123 pImplementation = reinterpret_cast< OAccessibleImplementationAccess* >(
124 xTunnel->getSomething( getUnoTunnelImplementationId() ) );
127 catch( const Exception& )
129 OSL_FAIL( "OAccessibleImplementationAccess::setAccessibleParent: caught an exception while retrieving the implementation!" );
131 return pImplementation;
135 bool OAccessibleImplementationAccess::setAccessibleParent(
136 const Reference< XAccessibleContext >& _rxComponent, const Reference< XAccessible >& _rxNewParent )
138 OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
140 if ( pImplementation )
141 pImplementation->setAccessibleParent( _rxNewParent );
143 return ( NULL != pImplementation );
147 } // namespace comphelper
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */