Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 :
25 : #include <set>
26 : #include <string.h>
27 :
28 : //.........................................................................
29 : namespace comphelper
30 : {
31 : //.........................................................................
32 :
33 : #define BITFIELDSIZE ( sizeof( sal_Int64 ) * 8 )
34 : // maximum number of bits we have in a sal_Int64
35 :
36 : using ::com::sun::star::uno::Reference;
37 : using ::com::sun::star::uno::Sequence;
38 : using ::com::sun::star::uno::Exception;
39 : using ::com::sun::star::uno::UNO_QUERY;
40 : using ::com::sun::star::uno::RuntimeException;
41 : using ::com::sun::star::lang::XUnoTunnel;
42 : using ::com::sun::star::accessibility::XAccessible;
43 : using ::com::sun::star::accessibility::XAccessibleContext;
44 :
45 : //=====================================================================
46 : //= OAccImpl_Impl
47 : //=====================================================================
48 0 : struct OAccImpl_Impl
49 : {
50 : Reference< XAccessible > m_xAccParent;
51 : sal_Int64 m_nForeignControlledStates;
52 : };
53 :
54 :
55 : //=====================================================================
56 : //= OAccessibleImplementationAccess
57 : //=====================================================================
58 : //---------------------------------------------------------------------
59 0 : OAccessibleImplementationAccess::OAccessibleImplementationAccess( )
60 0 : :m_pImpl( new OAccImpl_Impl )
61 : {
62 0 : }
63 :
64 : //---------------------------------------------------------------------
65 0 : OAccessibleImplementationAccess::~OAccessibleImplementationAccess( )
66 : {
67 0 : delete m_pImpl;
68 0 : m_pImpl = NULL;
69 0 : }
70 :
71 : //---------------------------------------------------------------------
72 0 : Reference< XAccessible > OAccessibleImplementationAccess::implGetForeignControlledParent( ) const
73 : {
74 0 : return m_pImpl->m_xAccParent;
75 : }
76 :
77 : //---------------------------------------------------------------------
78 0 : void OAccessibleImplementationAccess::setAccessibleParent( const Reference< XAccessible >& _rxAccParent )
79 : {
80 0 : m_pImpl->m_xAccParent = _rxAccParent;
81 0 : }
82 :
83 : //---------------------------------------------------------------------
84 0 : sal_Int64 OAccessibleImplementationAccess::implGetForeignControlledStates( ) const
85 : {
86 0 : return m_pImpl->m_nForeignControlledStates;
87 : }
88 :
89 : //---------------------------------------------------------------------
90 0 : void OAccessibleImplementationAccess::setStateBit( const sal_Int16 _nState, const sal_Bool _bSet )
91 : {
92 : OSL_ENSURE( _nState >= 0 && static_cast< sal_uInt16 >(_nState) < BITFIELDSIZE, "OAccessibleImplementationAccess::setStateBit: no more bits (shutting down the universe now)!" );
93 :
94 0 : sal_uInt64 nBitMask( 1 );
95 0 : nBitMask <<= _nState;
96 0 : if ( _bSet )
97 0 : m_pImpl->m_nForeignControlledStates |= nBitMask;
98 : else
99 0 : m_pImpl->m_nForeignControlledStates &= ~nBitMask;
100 0 : }
101 :
102 : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
103 :
104 : //---------------------------------------------------------------------
105 0 : const Sequence< sal_Int8 > OAccessibleImplementationAccess::getUnoTunnelImplementationId()
106 : {
107 0 : ::cppu::OImplementationId &rID = lcl_ImplId::get();
108 0 : return rID.getImplementationId();
109 : }
110 :
111 : //---------------------------------------------------------------------
112 0 : sal_Int64 SAL_CALL OAccessibleImplementationAccess::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw (RuntimeException)
113 : {
114 0 : sal_Int64 nReturn( 0 );
115 :
116 0 : if ( ( _rIdentifier.getLength() == 16 )
117 0 : && ( 0 == memcmp( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
118 : )
119 0 : nReturn = reinterpret_cast< sal_Int64 >( this );
120 :
121 0 : return nReturn;
122 : }
123 :
124 : //---------------------------------------------------------------------
125 0 : OAccessibleImplementationAccess* OAccessibleImplementationAccess::getImplementation( const Reference< XAccessibleContext >& _rxComponent )
126 : {
127 0 : OAccessibleImplementationAccess* pImplementation = NULL;
128 : try
129 : {
130 0 : Reference< XUnoTunnel > xTunnel( _rxComponent, UNO_QUERY );
131 0 : if ( xTunnel.is() )
132 : {
133 : pImplementation = reinterpret_cast< OAccessibleImplementationAccess* >(
134 0 : xTunnel->getSomething( getUnoTunnelImplementationId() ) );
135 0 : }
136 : }
137 0 : catch( const Exception& )
138 : {
139 : OSL_FAIL( "OAccessibleImplementationAccess::setAccessibleParent: caught an exception while retrieving the implementation!" );
140 : }
141 0 : return pImplementation;
142 : }
143 :
144 : //---------------------------------------------------------------------
145 0 : sal_Bool OAccessibleImplementationAccess::setAccessibleParent(
146 : const Reference< XAccessibleContext >& _rxComponent, const Reference< XAccessible >& _rxNewParent )
147 : {
148 0 : OAccessibleImplementationAccess* pImplementation = getImplementation( _rxComponent );
149 :
150 0 : if ( pImplementation )
151 0 : pImplementation->setAccessibleParent( _rxNewParent );
152 :
153 0 : return ( NULL != pImplementation );
154 : }
155 :
156 : //.........................................................................
157 : } // namespace comphelper
158 : //.........................................................................
159 :
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|