xref: /trunk/main/accessibility/source/extended/AccessibleGridControlBase.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
30*cdf0e10cSrcweir #include "accessibility/extended/AccessibleGridControlBase.hxx"
31*cdf0e10cSrcweir #include <svtools/accessibletable.hxx>
32*cdf0e10cSrcweir #include <rtl/uuid.h>
33*cdf0e10cSrcweir //
34*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36*cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // ============================================================================
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using ::rtl::OUString;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
43*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
44*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace ::com::sun::star;
47*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
48*cdf0e10cSrcweir using namespace ::comphelper;
49*cdf0e10cSrcweir using namespace ::svt;
50*cdf0e10cSrcweir using namespace ::svt::table;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir // ============================================================================
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace accessibility {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace com::sun::star::accessibility::AccessibleStateType;
58*cdf0e10cSrcweir // ============================================================================
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir DBG_NAME( AccessibleGridControlBase )
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir AccessibleGridControlBase::AccessibleGridControlBase(
63*cdf0e10cSrcweir         const Reference< XAccessible >& rxParent,
64*cdf0e10cSrcweir         svt::table::IAccessibleTable& rTable,
65*cdf0e10cSrcweir         AccessibleTableControlObjType      eObjType ) :
66*cdf0e10cSrcweir     AccessibleGridControlImplHelper( m_aMutex ),
67*cdf0e10cSrcweir     m_xParent( rxParent ),
68*cdf0e10cSrcweir     m_aTable( rTable),
69*cdf0e10cSrcweir     m_eObjType( eObjType ),
70*cdf0e10cSrcweir     m_aName( rTable.GetAccessibleObjectName( eObjType, 0, 0 ) ),
71*cdf0e10cSrcweir     m_aDescription( rTable.GetAccessibleObjectDescription( eObjType ) ),
72*cdf0e10cSrcweir     m_aClientId(0)
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir AccessibleGridControlBase::~AccessibleGridControlBase()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     if( isAlive() )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         // increment ref count to prevent double call of Dtor
81*cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
82*cdf0e10cSrcweir         dispose();
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir void SAL_CALL AccessibleGridControlBase::disposing()
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     if ( getClientId( ) )
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         AccessibleEventNotifier::TClientId nId( getClientId( ) );
93*cdf0e10cSrcweir         setClientId( 0 );
94*cdf0e10cSrcweir         AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     m_xParent = NULL;
98*cdf0e10cSrcweir     //m_aTable = NULL;
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // XAccessibleContext ---------------------------------------------------------
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent()
104*cdf0e10cSrcweir     throw ( uno::RuntimeException )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
107*cdf0e10cSrcweir     ensureIsAlive();
108*cdf0e10cSrcweir     return m_xParent;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlBase::getAccessibleIndexInParent()
112*cdf0e10cSrcweir     throw ( uno::RuntimeException )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
115*cdf0e10cSrcweir     ensureIsAlive();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     // -1 for child not found/no parent (according to specification)
118*cdf0e10cSrcweir     sal_Int32 nRet = -1;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     Reference< uno::XInterface > xMeMyselfAndI( static_cast< XAccessibleContext* >( this ), uno::UNO_QUERY );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     //  iterate over parent's children and search for this object
123*cdf0e10cSrcweir     if( m_xParent.is() )
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         Reference< XAccessibleContext >
126*cdf0e10cSrcweir             xParentContext( m_xParent->getAccessibleContext() );
127*cdf0e10cSrcweir         if( xParentContext.is() )
128*cdf0e10cSrcweir         {
129*cdf0e10cSrcweir         Reference< uno::XInterface > xChild;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir             sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
132*cdf0e10cSrcweir             for( sal_Int32 nChild = 0; nChild < nChildCount; ++nChild )
133*cdf0e10cSrcweir             {
134*cdf0e10cSrcweir             xChild = xChild.query( xParentContext->getAccessibleChild( nChild ) );
135*cdf0e10cSrcweir             if ( xMeMyselfAndI.get() == xChild.get() )
136*cdf0e10cSrcweir             {
137*cdf0e10cSrcweir                 nRet = nChild;
138*cdf0e10cSrcweir                 break;
139*cdf0e10cSrcweir             }
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir         }
142*cdf0e10cSrcweir    }
143*cdf0e10cSrcweir    return nRet;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir OUString SAL_CALL AccessibleGridControlBase::getAccessibleDescription()
147*cdf0e10cSrcweir     throw ( uno::RuntimeException )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
150*cdf0e10cSrcweir     ensureIsAlive();
151*cdf0e10cSrcweir     return m_aDescription;
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir OUString SAL_CALL AccessibleGridControlBase::getAccessibleName()
155*cdf0e10cSrcweir     throw ( uno::RuntimeException )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
158*cdf0e10cSrcweir     ensureIsAlive();
159*cdf0e10cSrcweir     return m_aName;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir Reference< XAccessibleRelationSet > SAL_CALL
163*cdf0e10cSrcweir AccessibleGridControlBase::getAccessibleRelationSet()
164*cdf0e10cSrcweir     throw ( uno::RuntimeException )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir    ensureIsAlive();
167*cdf0e10cSrcweir    // GridControl does not have relations.
168*cdf0e10cSrcweir    return new utl::AccessibleRelationSetHelper;
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir Reference< XAccessibleStateSet > SAL_CALL
172*cdf0e10cSrcweir AccessibleGridControlBase::getAccessibleStateSet()
173*cdf0e10cSrcweir     throw ( uno::RuntimeException )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
176*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
177*cdf0e10cSrcweir     // don't check whether alive -> StateSet may contain DEFUNC
178*cdf0e10cSrcweir     return implCreateStateSetHelper();
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir lang::Locale SAL_CALL AccessibleGridControlBase::getLocale()
182*cdf0e10cSrcweir     throw ( IllegalAccessibleComponentStateException, uno::RuntimeException )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
185*cdf0e10cSrcweir     ensureIsAlive();
186*cdf0e10cSrcweir     if( m_xParent.is() )
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         Reference< XAccessibleContext >
189*cdf0e10cSrcweir             xParentContext( m_xParent->getAccessibleContext() );
190*cdf0e10cSrcweir         if( xParentContext.is() )
191*cdf0e10cSrcweir         return xParentContext->getLocale();
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir     throw IllegalAccessibleComponentStateException();
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir // XAccessibleComponent -------------------------------------------------------
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleGridControlBase::containsPoint( const awt::Point& rPoint )
199*cdf0e10cSrcweir     throw ( uno::RuntimeException )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir    return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir awt::Rectangle SAL_CALL AccessibleGridControlBase::getBounds()
205*cdf0e10cSrcweir     throw ( uno::RuntimeException )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir    return AWTRectangle( getBoundingBox() );
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir awt::Point SAL_CALL AccessibleGridControlBase::getLocation()
211*cdf0e10cSrcweir     throw ( uno::RuntimeException )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     return AWTPoint( getBoundingBox().TopLeft() );
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir awt::Point SAL_CALL AccessibleGridControlBase::getLocationOnScreen()
217*cdf0e10cSrcweir     throw ( uno::RuntimeException )
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir awt::Size SAL_CALL AccessibleGridControlBase::getSize()
223*cdf0e10cSrcweir     throw ( uno::RuntimeException )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     return AWTSize( getBoundingBox().GetSize() );
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleGridControlBase::isShowing()
229*cdf0e10cSrcweir     throw ( uno::RuntimeException )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
232*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
233*cdf0e10cSrcweir     ensureIsAlive();
234*cdf0e10cSrcweir     return implIsShowing();
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleGridControlBase::isVisible()
238*cdf0e10cSrcweir     throw ( uno::RuntimeException )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir     Reference< XAccessibleStateSet > xStateSet = getAccessibleStateSet();
241*cdf0e10cSrcweir     return xStateSet.is() ?
242*cdf0e10cSrcweir         xStateSet->contains( AccessibleStateType::VISIBLE ) : sal_False;
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleGridControlBase::isFocusTraversable()
246*cdf0e10cSrcweir     throw ( uno::RuntimeException )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     Reference< XAccessibleStateSet > xStateSet = getAccessibleStateSet();
249*cdf0e10cSrcweir     return xStateSet.is() ?
250*cdf0e10cSrcweir         xStateSet->contains( AccessibleStateType::FOCUSABLE ) : sal_False;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir // XAccessibleEventBroadcaster ------------------------------------------------
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir void SAL_CALL AccessibleGridControlBase::addEventListener(
255*cdf0e10cSrcweir         const Reference< XAccessibleEventListener>& _rxListener )
256*cdf0e10cSrcweir     throw ( uno::RuntimeException )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     if ( _rxListener.is() )
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( getOslMutex() );
261*cdf0e10cSrcweir         if ( !getClientId( ) )
262*cdf0e10cSrcweir             setClientId( AccessibleEventNotifier::registerClient( ) );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener );
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir void SAL_CALL AccessibleGridControlBase::removeEventListener(
269*cdf0e10cSrcweir         const Reference< XAccessibleEventListener>& _rxListener )
270*cdf0e10cSrcweir     throw ( uno::RuntimeException )
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir     if( _rxListener.is() && getClientId( ) )
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
275*cdf0e10cSrcweir         sal_Int32 nListenerCount = AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener );
276*cdf0e10cSrcweir     if ( !nListenerCount )
277*cdf0e10cSrcweir     {
278*cdf0e10cSrcweir         // no listeners anymore
279*cdf0e10cSrcweir         // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
280*cdf0e10cSrcweir         // and at least to us not firing any events anymore, in case somebody calls
281*cdf0e10cSrcweir         // NotifyAccessibleEvent, again
282*cdf0e10cSrcweir         AccessibleEventNotifier::TClientId nId( getClientId( ) );
283*cdf0e10cSrcweir         setClientId( 0 );
284*cdf0e10cSrcweir         AccessibleEventNotifier::revokeClient( nId );
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir // XTypeProvider --------------------------------------------------------------
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL AccessibleGridControlBase::getImplementationId()
292*cdf0e10cSrcweir     throw ( uno::RuntimeException )
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslGlobalMutex() );
295*cdf0e10cSrcweir     static Sequence< sal_Int8 > aId;
296*cdf0e10cSrcweir     implCreateUuid( aId );
297*cdf0e10cSrcweir     return aId;
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir // XServiceInfo ---------------------------------------------------------------
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleGridControlBase::supportsService(
303*cdf0e10cSrcweir         const OUString& rServiceName )
304*cdf0e10cSrcweir     throw ( uno::RuntimeException )
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     Sequence< OUString > aSupportedServices( getSupportedServiceNames() );
309*cdf0e10cSrcweir     const OUString* pArrBegin = aSupportedServices.getConstArray();
310*cdf0e10cSrcweir     const OUString* pArrEnd = pArrBegin + aSupportedServices.getLength();
311*cdf0e10cSrcweir     const OUString* pString = pArrBegin;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     for( ; ( pString != pArrEnd ) && ( rServiceName != *pString ); ++pString )
314*cdf0e10cSrcweir         ;
315*cdf0e10cSrcweir     return pString != pArrEnd;
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir Sequence< OUString > SAL_CALL AccessibleGridControlBase::getSupportedServiceNames()
319*cdf0e10cSrcweir     throw ( uno::RuntimeException )
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir     const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
322*cdf0e10cSrcweir     return Sequence< OUString >( &aServiceName, 1 );
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir // internal virtual methods ---------------------------------------------------
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir sal_Bool AccessibleGridControlBase::implIsShowing()
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     sal_Bool bShowing = sal_False;
329*cdf0e10cSrcweir     if( m_xParent.is() )
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         Reference< XAccessibleComponent >
332*cdf0e10cSrcweir             xParentComp( m_xParent->getAccessibleContext(), uno::UNO_QUERY );
333*cdf0e10cSrcweir         if( xParentComp.is() )
334*cdf0e10cSrcweir             bShowing = implGetBoundingBox().IsOver(
335*cdf0e10cSrcweir                 VCLRectangle( xParentComp->getBounds() ) );
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir     return bShowing;
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir ::utl::AccessibleStateSetHelper* AccessibleGridControlBase::implCreateStateSetHelper()
341*cdf0e10cSrcweir {
342*cdf0e10cSrcweir     ::utl::AccessibleStateSetHelper*
343*cdf0e10cSrcweir         pStateSetHelper = new ::utl::AccessibleStateSetHelper;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     if( isAlive() )
346*cdf0e10cSrcweir     {
347*cdf0e10cSrcweir         // SHOWING done with m_xParent
348*cdf0e10cSrcweir         if( implIsShowing() )
349*cdf0e10cSrcweir             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
350*cdf0e10cSrcweir         // GridControl fills StateSet with states depending on object type
351*cdf0e10cSrcweir         m_aTable.FillAccessibleStateSet( *pStateSetHelper, getType() );
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir     else
354*cdf0e10cSrcweir         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
355*cdf0e10cSrcweir     return pStateSetHelper;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir // internal helper methods ----------------------------------------------------
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir sal_Bool AccessibleGridControlBase::isAlive() const
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     return !rBHelper.bDisposed && !rBHelper.bInDispose && &m_aTable;
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir void AccessibleGridControlBase::ensureIsAlive() const
366*cdf0e10cSrcweir     throw ( lang::DisposedException )
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir     if( !isAlive() )
369*cdf0e10cSrcweir         throw lang::DisposedException();
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir Rectangle AccessibleGridControlBase::getBoundingBox()
373*cdf0e10cSrcweir     throw ( lang::DisposedException )
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
376*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
377*cdf0e10cSrcweir     ensureIsAlive();
378*cdf0e10cSrcweir     Rectangle aRect = implGetBoundingBox();
379*cdf0e10cSrcweir     if ( 0 == aRect.Left() && 0 == aRect.Top() && 0 == aRect.Right() && 0 == aRect.Bottom() )
380*cdf0e10cSrcweir     {
381*cdf0e10cSrcweir         DBG_ERRORFILE( "rectangle doesn't exist" );
382*cdf0e10cSrcweir     }
383*cdf0e10cSrcweir     return aRect;
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir Rectangle AccessibleGridControlBase::getBoundingBoxOnScreen()
387*cdf0e10cSrcweir     throw ( lang::DisposedException )
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
390*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
391*cdf0e10cSrcweir     ensureIsAlive();
392*cdf0e10cSrcweir     Rectangle aRect = implGetBoundingBoxOnScreen();
393*cdf0e10cSrcweir     if ( 0 == aRect.Left() && 0 == aRect.Top() && 0 == aRect.Right() && 0 == aRect.Bottom() )
394*cdf0e10cSrcweir     {
395*cdf0e10cSrcweir         DBG_ERRORFILE( "rectangle doesn't exist" );
396*cdf0e10cSrcweir     }
397*cdf0e10cSrcweir     return aRect;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir void AccessibleGridControlBase::commitEvent(
401*cdf0e10cSrcweir         sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     ::osl::ClearableMutexGuard aGuard( getOslMutex() );
404*cdf0e10cSrcweir     if ( !getClientId( ) )
405*cdf0e10cSrcweir             // if we don't have a client id for the notifier, then we don't have listeners, then
406*cdf0e10cSrcweir             // we don't need to notify anything
407*cdf0e10cSrcweir             return;
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir     // build an event object
410*cdf0e10cSrcweir     AccessibleEventObject aEvent;
411*cdf0e10cSrcweir     aEvent.Source = *this;
412*cdf0e10cSrcweir     aEvent.EventId = _nEventId;
413*cdf0e10cSrcweir     aEvent.OldValue = _rOldValue;
414*cdf0e10cSrcweir     aEvent.NewValue = _rNewValue;
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     // let the notifier handle this event
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     AccessibleEventNotifier::addEvent( getClientId( ), aEvent );
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir // -----------------------------------------------------------------------------
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir void AccessibleGridControlBase::implCreateUuid( Sequence< sal_Int8 >& rId )
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir     if( !rId.hasElements() )
425*cdf0e10cSrcweir     {
426*cdf0e10cSrcweir         rId.realloc( 16 );
427*cdf0e10cSrcweir         rtl_createUuid( reinterpret_cast< sal_uInt8* >( rId.getArray() ), 0, sal_True );
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir // -----------------------------------------------------------------------------
431*cdf0e10cSrcweir sal_Int16 SAL_CALL AccessibleGridControlBase::getAccessibleRole()
432*cdf0e10cSrcweir     throw ( uno::RuntimeException )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir     ensureIsAlive();
435*cdf0e10cSrcweir     sal_Int16 nRole = AccessibleRole::UNKNOWN;
436*cdf0e10cSrcweir     switch ( m_eObjType )
437*cdf0e10cSrcweir     {
438*cdf0e10cSrcweir         case TCTYPE_ROWHEADERCELL:
439*cdf0e10cSrcweir         nRole = AccessibleRole::ROW_HEADER;
440*cdf0e10cSrcweir         break;
441*cdf0e10cSrcweir     case TCTYPE_COLUMNHEADERCELL:
442*cdf0e10cSrcweir         nRole = AccessibleRole::COLUMN_HEADER;
443*cdf0e10cSrcweir         break;
444*cdf0e10cSrcweir     case TCTYPE_COLUMNHEADERBAR:
445*cdf0e10cSrcweir     case TCTYPE_ROWHEADERBAR:
446*cdf0e10cSrcweir     case TCTYPE_TABLE:
447*cdf0e10cSrcweir         nRole = AccessibleRole::TABLE;
448*cdf0e10cSrcweir         break;
449*cdf0e10cSrcweir     case TCTYPE_TABLECELL:
450*cdf0e10cSrcweir         nRole = AccessibleRole::TABLE_CELL;
451*cdf0e10cSrcweir         break;
452*cdf0e10cSrcweir     case TCTYPE_GRIDCONTROL:
453*cdf0e10cSrcweir         nRole = AccessibleRole::PANEL;
454*cdf0e10cSrcweir         break;
455*cdf0e10cSrcweir     }
456*cdf0e10cSrcweir     return nRole;
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir // -----------------------------------------------------------------------------
459*cdf0e10cSrcweir Any SAL_CALL AccessibleGridControlBase::getAccessibleKeyBinding()
460*cdf0e10cSrcweir         throw ( uno::RuntimeException )
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     return Any();
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir // -----------------------------------------------------------------------------
465*cdf0e10cSrcweir Reference<XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point& )
466*cdf0e10cSrcweir         throw ( uno::RuntimeException )
467*cdf0e10cSrcweir {
468*cdf0e10cSrcweir     return NULL;
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir //// -----------------------------------------------------------------------------
471*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlBase::getForeground(  ) throw (::com::sun::star::uno::RuntimeException)
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
474*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
475*cdf0e10cSrcweir     ensureIsAlive();
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     sal_Int32 nColor = 0;
478*cdf0e10cSrcweir     Window* pInst = m_aTable.GetWindowInstance();
479*cdf0e10cSrcweir     if ( pInst )
480*cdf0e10cSrcweir     {
481*cdf0e10cSrcweir         if ( pInst->IsControlForeground() )
482*cdf0e10cSrcweir             nColor = pInst->GetControlForeground().GetColor();
483*cdf0e10cSrcweir     else
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         Font aFont;
486*cdf0e10cSrcweir         if ( pInst->IsControlFont() )
487*cdf0e10cSrcweir             aFont = pInst->GetControlFont();
488*cdf0e10cSrcweir         else
489*cdf0e10cSrcweir             aFont = pInst->GetFont();
490*cdf0e10cSrcweir         nColor = aFont.GetColor().GetColor();
491*cdf0e10cSrcweir     }
492*cdf0e10cSrcweir     }
493*cdf0e10cSrcweir     return nColor;
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir // -----------------------------------------------------------------------------
496*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlBase::getBackground(  ) throw (::com::sun::star::uno::RuntimeException)
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir     TCSolarGuard aSolarGuard;
499*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getOslMutex() );
500*cdf0e10cSrcweir     ensureIsAlive();
501*cdf0e10cSrcweir     sal_Int32 nColor = 0;
502*cdf0e10cSrcweir     Window* pInst = m_aTable.GetWindowInstance();
503*cdf0e10cSrcweir     if ( pInst )
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         if ( pInst->IsControlBackground() )
506*cdf0e10cSrcweir             nColor = pInst->GetControlBackground().GetColor();
507*cdf0e10cSrcweir     else
508*cdf0e10cSrcweir             nColor = pInst->GetBackground().GetColor().GetColor();
509*cdf0e10cSrcweir     }
510*cdf0e10cSrcweir     return nColor;
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir //// ============================================================================
514*cdf0e10cSrcweir GridControlAccessibleElement::GridControlAccessibleElement( const Reference< XAccessible >& rxParent,
515*cdf0e10cSrcweir                         IAccessibleTable& rTable,
516*cdf0e10cSrcweir                         AccessibleTableControlObjType  eObjType )
517*cdf0e10cSrcweir     :AccessibleGridControlBase( rxParent, rTable, eObjType )
518*cdf0e10cSrcweir {
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir // XInterface -----------------------------------------------------------------
522*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base)
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir // XTypeProvider --------------------------------------------------------------
525*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base )
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir // XAccessible ----------------------------------------------------------------
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL GridControlAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException )
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     ensureIsAlive();
532*cdf0e10cSrcweir     return this;
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir // ----------------------------------------------------------------------------
535*cdf0e10cSrcweir GridControlAccessibleElement::~GridControlAccessibleElement( )
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir // ============================================================================
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir } // namespace accessibility
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir // ============================================================================
544*cdf0e10cSrcweir 
545