1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include "accessibility/extended/AccessibleGridControlBase.hxx"
31 #include <svtools/accessibletable.hxx>
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <unotools/accessiblerelationsethelper.hxx>
38 // ============================================================================
40 using ::rtl::OUString
;
42 using ::com::sun::star::uno::Reference
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::uno::Any
;
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::accessibility
;
48 using namespace ::comphelper
;
49 using namespace ::svt
;
50 using namespace ::svt::table
;
53 // ============================================================================
55 namespace accessibility
{
57 using namespace com::sun::star::accessibility::AccessibleStateType
;
58 // ============================================================================
60 DBG_NAME( AccessibleGridControlBase
)
62 AccessibleGridControlBase::AccessibleGridControlBase(
63 const Reference
< XAccessible
>& rxParent
,
64 svt::table::IAccessibleTable
& rTable
,
65 AccessibleTableControlObjType eObjType
) :
66 AccessibleGridControlImplHelper( m_aMutex
),
67 m_xParent( rxParent
),
69 m_eObjType( eObjType
),
70 m_aName( rTable
.GetAccessibleObjectName( eObjType
, 0, 0 ) ),
71 m_aDescription( rTable
.GetAccessibleObjectDescription( eObjType
) ),
76 AccessibleGridControlBase::~AccessibleGridControlBase()
80 // increment ref count to prevent double call of Dtor
81 osl_incrementInterlockedCount( &m_refCount
);
86 void SAL_CALL
AccessibleGridControlBase::disposing()
88 ::osl::MutexGuard
aGuard( getOslMutex() );
92 // XAccessibleContext ---------------------------------------------------------
94 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleParent()
95 throw ( uno::RuntimeException
)
97 ::osl::MutexGuard
aGuard( getOslMutex() );
102 sal_Int32 SAL_CALL
AccessibleGridControlBase::getAccessibleIndexInParent()
103 throw ( uno::RuntimeException
)
105 ::osl::MutexGuard
aGuard( getOslMutex() );
108 // -1 for child not found/no parent (according to specification)
111 Reference
< uno::XInterface
> xMeMyselfAndI( static_cast< XAccessibleContext
* >( this ), uno::UNO_QUERY
);
113 // iterate over parent's children and search for this object
116 Reference
< XAccessibleContext
>
117 xParentContext( m_xParent
->getAccessibleContext() );
118 if( xParentContext
.is() )
120 Reference
< uno::XInterface
> xChild
;
122 sal_Int32 nChildCount
= xParentContext
->getAccessibleChildCount();
123 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; ++nChild
)
125 xChild
= xChild
.query( xParentContext
->getAccessibleChild( nChild
) );
126 if ( xMeMyselfAndI
.get() == xChild
.get() )
137 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleDescription()
138 throw ( uno::RuntimeException
)
140 ::osl::MutexGuard
aGuard( getOslMutex() );
142 return m_aDescription
;
145 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleName()
146 throw ( uno::RuntimeException
)
148 ::osl::MutexGuard
aGuard( getOslMutex() );
153 Reference
< XAccessibleRelationSet
> SAL_CALL
154 AccessibleGridControlBase::getAccessibleRelationSet()
155 throw ( uno::RuntimeException
)
158 // GridControl does not have relations.
159 return new utl::AccessibleRelationSetHelper
;
162 Reference
< XAccessibleStateSet
> SAL_CALL
163 AccessibleGridControlBase::getAccessibleStateSet()
164 throw ( uno::RuntimeException
)
166 TCSolarGuard aSolarGuard
;
167 ::osl::MutexGuard
aGuard( getOslMutex() );
168 // don't check whether alive -> StateSet may contain DEFUNC
169 return implCreateStateSetHelper();
172 lang::Locale SAL_CALL
AccessibleGridControlBase::getLocale()
173 throw ( IllegalAccessibleComponentStateException
, uno::RuntimeException
)
175 ::osl::MutexGuard
aGuard( getOslMutex() );
179 Reference
< XAccessibleContext
>
180 xParentContext( m_xParent
->getAccessibleContext() );
181 if( xParentContext
.is() )
182 return xParentContext
->getLocale();
184 throw IllegalAccessibleComponentStateException();
187 // XAccessibleComponent -------------------------------------------------------
189 sal_Bool SAL_CALL
AccessibleGridControlBase::containsPoint( const awt::Point
& rPoint
)
190 throw ( uno::RuntimeException
)
192 return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint
) );
195 awt::Rectangle SAL_CALL
AccessibleGridControlBase::getBounds()
196 throw ( uno::RuntimeException
)
198 return AWTRectangle( getBoundingBox() );
201 awt::Point SAL_CALL
AccessibleGridControlBase::getLocation()
202 throw ( uno::RuntimeException
)
204 return AWTPoint( getBoundingBox().TopLeft() );
207 awt::Point SAL_CALL
AccessibleGridControlBase::getLocationOnScreen()
208 throw ( uno::RuntimeException
)
210 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
213 awt::Size SAL_CALL
AccessibleGridControlBase::getSize()
214 throw ( uno::RuntimeException
)
216 return AWTSize( getBoundingBox().GetSize() );
219 sal_Bool SAL_CALL
AccessibleGridControlBase::isShowing()
220 throw ( uno::RuntimeException
)
222 TCSolarGuard aSolarGuard
;
223 ::osl::MutexGuard
aGuard( getOslMutex() );
225 return implIsShowing();
228 sal_Bool SAL_CALL
AccessibleGridControlBase::isVisible()
229 throw ( uno::RuntimeException
)
231 Reference
< XAccessibleStateSet
> xStateSet
= getAccessibleStateSet();
232 return xStateSet
.is() ?
233 xStateSet
->contains( AccessibleStateType::VISIBLE
) : sal_False
;
236 sal_Bool SAL_CALL
AccessibleGridControlBase::isFocusTraversable()
237 throw ( uno::RuntimeException
)
239 Reference
< XAccessibleStateSet
> xStateSet
= getAccessibleStateSet();
240 return xStateSet
.is() ?
241 xStateSet
->contains( AccessibleStateType::FOCUSABLE
) : sal_False
;
243 // XAccessibleEventBroadcaster ------------------------------------------------
245 void SAL_CALL
AccessibleGridControlBase::addEventListener(
246 const Reference
< XAccessibleEventListener
>& _rxListener
)
247 throw ( uno::RuntimeException
)
249 if ( _rxListener
.is() )
251 ::osl::MutexGuard
aGuard( getOslMutex() );
252 if ( !getClientId( ) )
253 setClientId( AccessibleEventNotifier::registerClient( ) );
255 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
259 void SAL_CALL
AccessibleGridControlBase::removeEventListener(
260 const Reference
< XAccessibleEventListener
>& _rxListener
)
261 throw ( uno::RuntimeException
)
263 if( _rxListener
.is() && getClientId( ) )
265 ::osl::MutexGuard
aGuard( getOslMutex() );
266 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
267 if ( !nListenerCount
)
269 // no listeners anymore
270 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
271 // and at least to us not firing any events anymore, in case somebody calls
272 // NotifyAccessibleEvent, again
273 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
275 AccessibleEventNotifier::revokeClient( nId
);
280 // XTypeProvider --------------------------------------------------------------
282 Sequence
< sal_Int8
> SAL_CALL
AccessibleGridControlBase::getImplementationId()
283 throw ( uno::RuntimeException
)
285 ::osl::MutexGuard
aGuard( getOslGlobalMutex() );
286 static Sequence
< sal_Int8
> aId
;
287 implCreateUuid( aId
);
291 // XServiceInfo ---------------------------------------------------------------
293 sal_Bool SAL_CALL
AccessibleGridControlBase::supportsService(
294 const OUString
& rServiceName
)
295 throw ( uno::RuntimeException
)
297 ::osl::MutexGuard
aGuard( getOslMutex() );
299 Sequence
< OUString
> aSupportedServices( getSupportedServiceNames() );
300 const OUString
* pArrBegin
= aSupportedServices
.getConstArray();
301 const OUString
* pArrEnd
= pArrBegin
+ aSupportedServices
.getLength();
302 const OUString
* pString
= pArrBegin
;
304 for( ; ( pString
!= pArrEnd
) && ( rServiceName
!= *pString
); ++pString
)
306 return pString
!= pArrEnd
;
309 Sequence
< OUString
> SAL_CALL
AccessibleGridControlBase::getSupportedServiceNames()
310 throw ( uno::RuntimeException
)
312 const OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
313 return Sequence
< OUString
>( &aServiceName
, 1 );
315 // internal virtual methods ---------------------------------------------------
317 sal_Bool
AccessibleGridControlBase::implIsShowing()
319 sal_Bool bShowing
= sal_False
;
322 Reference
< XAccessibleComponent
>
323 xParentComp( m_xParent
->getAccessibleContext(), uno::UNO_QUERY
);
324 if( xParentComp
.is() )
325 bShowing
= implGetBoundingBox().IsOver(
326 VCLRectangle( xParentComp
->getBounds() ) );
331 ::utl::AccessibleStateSetHelper
* AccessibleGridControlBase::implCreateStateSetHelper()
333 ::utl::AccessibleStateSetHelper
*
334 pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
338 // SHOWING done with m_xParent
339 if( implIsShowing() )
340 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
341 // GridControl fills StateSet with states depending on object type
342 m_aTable
.FillAccessibleStateSet( *pStateSetHelper
, getType() );
345 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
346 return pStateSetHelper
;
349 // internal helper methods ----------------------------------------------------
351 sal_Bool
AccessibleGridControlBase::isAlive() const
353 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
&& &m_aTable
;
356 void AccessibleGridControlBase::ensureIsAlive() const
357 throw ( lang::DisposedException
)
360 throw lang::DisposedException();
363 Rectangle
AccessibleGridControlBase::getBoundingBox()
364 throw ( lang::DisposedException
)
366 TCSolarGuard aSolarGuard
;
367 ::osl::MutexGuard
aGuard( getOslMutex() );
369 Rectangle aRect
= implGetBoundingBox();
370 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
372 DBG_ERRORFILE( "rectangle doesn't exist" );
377 Rectangle
AccessibleGridControlBase::getBoundingBoxOnScreen()
378 throw ( lang::DisposedException
)
380 TCSolarGuard aSolarGuard
;
381 ::osl::MutexGuard
aGuard( getOslMutex() );
383 Rectangle aRect
= implGetBoundingBoxOnScreen();
384 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
386 DBG_ERRORFILE( "rectangle doesn't exist" );
391 void AccessibleGridControlBase::commitEvent(
392 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
394 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
395 if ( !getClientId( ) )
396 // if we don't have a client id for the notifier, then we don't have listeners, then
397 // we don't need to notify anything
400 // build an event object
401 AccessibleEventObject aEvent
;
402 aEvent
.Source
= *this;
403 aEvent
.EventId
= _nEventId
;
404 aEvent
.OldValue
= _rOldValue
;
405 aEvent
.NewValue
= _rNewValue
;
407 // let the notifier handle this event
409 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
411 // -----------------------------------------------------------------------------
413 void AccessibleGridControlBase::implCreateUuid( Sequence
< sal_Int8
>& rId
)
415 if( !rId
.hasElements() )
418 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( rId
.getArray() ), 0, sal_True
);
421 // -----------------------------------------------------------------------------
422 sal_Int16 SAL_CALL
AccessibleGridControlBase::getAccessibleRole()
423 throw ( uno::RuntimeException
)
426 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
427 switch ( m_eObjType
)
429 case TCTYPE_ROWHEADERCELL
:
430 nRole
= AccessibleRole::ROW_HEADER
;
432 case TCTYPE_COLUMNHEADERCELL
:
433 nRole
= AccessibleRole::COLUMN_HEADER
;
435 case TCTYPE_COLUMNHEADERBAR
:
436 case TCTYPE_ROWHEADERBAR
:
438 nRole
= AccessibleRole::TABLE
;
440 case TCTYPE_TABLECELL
:
441 nRole
= AccessibleRole::TABLE_CELL
;
443 case TCTYPE_GRIDCONTROL
:
444 nRole
= AccessibleRole::PANEL
;
449 // -----------------------------------------------------------------------------
450 Any SAL_CALL
AccessibleGridControlBase::getAccessibleKeyBinding()
451 throw ( uno::RuntimeException
)
455 // -----------------------------------------------------------------------------
456 Reference
<XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point
& )
457 throw ( uno::RuntimeException
)
461 //// -----------------------------------------------------------------------------
462 sal_Int32 SAL_CALL
AccessibleGridControlBase::getForeground( ) throw (::com::sun::star::uno::RuntimeException
)
464 TCSolarGuard aSolarGuard
;
465 ::osl::MutexGuard
aGuard( getOslMutex() );
468 sal_Int32 nColor
= 0;
469 Window
* pInst
= m_aTable
.GetWindowInstance();
472 if ( pInst
->IsControlForeground() )
473 nColor
= pInst
->GetControlForeground().GetColor();
477 if ( pInst
->IsControlFont() )
478 aFont
= pInst
->GetControlFont();
480 aFont
= pInst
->GetFont();
481 nColor
= aFont
.GetColor().GetColor();
486 // -----------------------------------------------------------------------------
487 sal_Int32 SAL_CALL
AccessibleGridControlBase::getBackground( ) throw (::com::sun::star::uno::RuntimeException
)
489 TCSolarGuard aSolarGuard
;
490 ::osl::MutexGuard
aGuard( getOslMutex() );
492 sal_Int32 nColor
= 0;
493 Window
* pInst
= m_aTable
.GetWindowInstance();
496 if ( pInst
->IsControlBackground() )
497 nColor
= pInst
->GetControlBackground().GetColor();
499 nColor
= pInst
->GetBackground().GetColor().GetColor();
504 //// ============================================================================
505 GridControlAccessibleElement::GridControlAccessibleElement( const Reference
< XAccessible
>& rxParent
,
506 IAccessibleTable
& rTable
,
507 AccessibleTableControlObjType eObjType
)
508 :AccessibleGridControlBase( rxParent
, rTable
, eObjType
)
512 // XInterface -----------------------------------------------------------------
513 IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
515 // XTypeProvider --------------------------------------------------------------
516 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
518 // XAccessible ----------------------------------------------------------------
520 Reference
< XAccessibleContext
> SAL_CALL
GridControlAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException
)
525 // ----------------------------------------------------------------------------
526 GridControlAccessibleElement::~GridControlAccessibleElement( )
530 // ============================================================================
532 } // namespace accessibility
534 // ============================================================================