xref: /trunk/main/comphelper/source/misc/accimplaccess.cxx (revision dde7d3faf6dcd9cbeb7b48ba6d0cea5ffcc883d0)
1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*dde7d3faSAndrew Rist  * distributed with this work for additional information
6*dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17*dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*dde7d3faSAndrew Rist  *************************************************************/
21*dde7d3faSAndrew Rist 
22*dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #include <comphelper/accimplaccess.hxx>
27cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
28cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleContext.hpp>
29cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <set>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //.........................................................................
34cdf0e10cSrcweir namespace comphelper
35cdf0e10cSrcweir {
36cdf0e10cSrcweir //.........................................................................
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #define BITFIELDSIZE    ( sizeof( sal_Int64 ) * 8 )
39cdf0e10cSrcweir     // maximum number of bits we have in a sal_Int64
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
42cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
43cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
44cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY;
45cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
46cdf0e10cSrcweir     using ::com::sun::star::lang::XUnoTunnel;
47cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessible;
48cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessibleContext;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     //=====================================================================
51cdf0e10cSrcweir     //= OAccImpl_Impl
52cdf0e10cSrcweir     //=====================================================================
53cdf0e10cSrcweir     struct OAccImpl_Impl
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         Reference< XAccessible >    m_xAccParent;
56cdf0e10cSrcweir         sal_Int64                   m_nForeignControlledStates;
57cdf0e10cSrcweir     };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     //=====================================================================
61cdf0e10cSrcweir     //= OAccessibleImplementationAccess
62cdf0e10cSrcweir     //=====================================================================
63cdf0e10cSrcweir     //---------------------------------------------------------------------
64cdf0e10cSrcweir     OAccessibleImplementationAccess::OAccessibleImplementationAccess( )
65cdf0e10cSrcweir         :m_pImpl( new OAccImpl_Impl )
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     //---------------------------------------------------------------------
70cdf0e10cSrcweir     OAccessibleImplementationAccess::~OAccessibleImplementationAccess( )
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         delete m_pImpl;
73cdf0e10cSrcweir         m_pImpl = NULL;
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     //---------------------------------------------------------------------
77cdf0e10cSrcweir     Reference< XAccessible > OAccessibleImplementationAccess::implGetForeignControlledParent( ) const
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         return m_pImpl->m_xAccParent;
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     //---------------------------------------------------------------------
83cdf0e10cSrcweir     void OAccessibleImplementationAccess::setAccessibleParent( const Reference< XAccessible >& _rxAccParent )
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         m_pImpl->m_xAccParent = _rxAccParent;
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     //---------------------------------------------------------------------
89cdf0e10cSrcweir     sal_Int64 OAccessibleImplementationAccess::implGetForeignControlledStates( ) const
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         return m_pImpl->m_nForeignControlledStates;
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     //---------------------------------------------------------------------
95cdf0e10cSrcweir     void OAccessibleImplementationAccess::setStateBit( const sal_Int16 _nState, const sal_Bool _bSet )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         OSL_ENSURE( _nState >= 0 && static_cast< sal_uInt16 >(_nState) < BITFIELDSIZE, "OAccessibleImplementationAccess::setStateBit: no more bits (shutting down the universe now)!" );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         sal_uInt64 nBitMask( 1 );
100cdf0e10cSrcweir         nBitMask <<= _nState;
101cdf0e10cSrcweir         if ( _bSet )
102cdf0e10cSrcweir             m_pImpl->m_nForeignControlledStates |= nBitMask;
103cdf0e10cSrcweir         else
104cdf0e10cSrcweir             m_pImpl->m_nForeignControlledStates &= ~nBitMask;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     //---------------------------------------------------------------------
108cdf0e10cSrcweir     sal_Bool OAccessibleImplementationAccess::setForeignControlledState( const Reference< XAccessibleContext >& _rxComponent, const sal_Int16 _nState,
109cdf0e10cSrcweir         const sal_Bool  _bSet )
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         if ( pImplementation )
114cdf0e10cSrcweir             pImplementation->setStateBit( _nState, _bSet );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         return ( NULL != pImplementation );
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     //---------------------------------------------------------------------
120cdf0e10cSrcweir     const Sequence< sal_Int8 >& OAccessibleImplementationAccess::getUnoTunnelImplementationId()
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         static Sequence< sal_Int8 > aId;
123cdf0e10cSrcweir         if ( !aId.getLength() )
124cdf0e10cSrcweir         {
125cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
126cdf0e10cSrcweir             if ( !aId.getLength() )
127cdf0e10cSrcweir             {
128cdf0e10cSrcweir                 static ::cppu::OImplementationId aImplId;
129cdf0e10cSrcweir                 // unfortunately, the OImplementationId::getImplementationId returns a copy, not a static reference ...
130cdf0e10cSrcweir                 aId = aImplId.getImplementationId();
131cdf0e10cSrcweir             }
132cdf0e10cSrcweir         }
133cdf0e10cSrcweir         return aId;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     //---------------------------------------------------------------------
137cdf0e10cSrcweir     sal_Int64 SAL_CALL OAccessibleImplementationAccess::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw (RuntimeException)
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         sal_Int64 nReturn( 0 );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         if  (   ( _rIdentifier.getLength() == 16 )
142cdf0e10cSrcweir             &&  ( 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
143cdf0e10cSrcweir             )
144cdf0e10cSrcweir             nReturn = reinterpret_cast< sal_Int64 >( this );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         return nReturn;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     //---------------------------------------------------------------------
150cdf0e10cSrcweir     OAccessibleImplementationAccess* OAccessibleImplementationAccess::getImplementation( const Reference< XAccessibleContext >& _rxComponent )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         OAccessibleImplementationAccess* pImplementation = NULL;
153cdf0e10cSrcweir         try
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             Reference< XUnoTunnel > xTunnel( _rxComponent, UNO_QUERY );
156cdf0e10cSrcweir             if ( xTunnel.is() )
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 pImplementation = reinterpret_cast< OAccessibleImplementationAccess* >(
159cdf0e10cSrcweir                         xTunnel->getSomething( getUnoTunnelImplementationId() ) );
160cdf0e10cSrcweir             }
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir         catch( const Exception& )
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir             OSL_ENSURE( sal_False, "OAccessibleImplementationAccess::setAccessibleParent: caught an exception while retrieving the implementation!" );
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir         return pImplementation;
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     //---------------------------------------------------------------------
170cdf0e10cSrcweir     sal_Bool OAccessibleImplementationAccess::setAccessibleParent(
171cdf0e10cSrcweir             const Reference< XAccessibleContext >& _rxComponent, const Reference< XAccessible >& _rxNewParent )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         if ( pImplementation )
176cdf0e10cSrcweir             pImplementation->setAccessibleParent( _rxNewParent );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         return ( NULL != pImplementation );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir //.........................................................................
182cdf0e10cSrcweir }   // namespace comphelper
183cdf0e10cSrcweir //.........................................................................
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 
186