merged tag ooo/DEV300_m102
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlBase.cxx
blobea81bd3504267e93d1b3531af87c47321c038bd8
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>
32 #include <rtl/uuid.h>
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 ),
68 m_aTable( rTable),
69 m_eObjType( eObjType ),
70 m_aName( rTable.GetAccessibleObjectName( eObjType, 0, 0 ) ),
71 m_aDescription( rTable.GetAccessibleObjectDescription( eObjType ) ),
72 m_aClientId(0)
76 AccessibleGridControlBase::~AccessibleGridControlBase()
78 if( isAlive() )
80 // increment ref count to prevent double call of Dtor
81 osl_incrementInterlockedCount( &m_refCount );
82 dispose();
86 void SAL_CALL AccessibleGridControlBase::disposing()
88 ::osl::MutexGuard aGuard( getOslMutex() );
89 m_xParent = NULL;
92 // XAccessibleContext ---------------------------------------------------------
94 Reference< XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent()
95 throw ( uno::RuntimeException )
97 ::osl::MutexGuard aGuard( getOslMutex() );
98 ensureIsAlive();
99 return m_xParent;
102 sal_Int32 SAL_CALL AccessibleGridControlBase::getAccessibleIndexInParent()
103 throw ( uno::RuntimeException )
105 ::osl::MutexGuard aGuard( getOslMutex() );
106 ensureIsAlive();
108 // -1 for child not found/no parent (according to specification)
109 sal_Int32 nRet = -1;
111 Reference< uno::XInterface > xMeMyselfAndI( static_cast< XAccessibleContext* >( this ), uno::UNO_QUERY );
113 // iterate over parent's children and search for this object
114 if( m_xParent.is() )
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() )
128 nRet = nChild;
129 break;
134 return nRet;
137 OUString SAL_CALL AccessibleGridControlBase::getAccessibleDescription()
138 throw ( uno::RuntimeException )
140 ::osl::MutexGuard aGuard( getOslMutex() );
141 ensureIsAlive();
142 return m_aDescription;
145 OUString SAL_CALL AccessibleGridControlBase::getAccessibleName()
146 throw ( uno::RuntimeException )
148 ::osl::MutexGuard aGuard( getOslMutex() );
149 ensureIsAlive();
150 return m_aName;
153 Reference< XAccessibleRelationSet > SAL_CALL
154 AccessibleGridControlBase::getAccessibleRelationSet()
155 throw ( uno::RuntimeException )
157 ensureIsAlive();
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() );
176 ensureIsAlive();
177 if( m_xParent.is() )
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() );
224 ensureIsAlive();
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( ) );
274 setClientId( 0 );
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 );
288 return 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;
320 if( m_xParent.is() )
322 Reference< XAccessibleComponent >
323 xParentComp( m_xParent->getAccessibleContext(), uno::UNO_QUERY );
324 if( xParentComp.is() )
325 bShowing = implGetBoundingBox().IsOver(
326 VCLRectangle( xParentComp->getBounds() ) );
328 return bShowing;
331 ::utl::AccessibleStateSetHelper* AccessibleGridControlBase::implCreateStateSetHelper()
333 ::utl::AccessibleStateSetHelper*
334 pStateSetHelper = new ::utl::AccessibleStateSetHelper;
336 if( isAlive() )
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() );
344 else
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 )
359 if( !isAlive() )
360 throw lang::DisposedException();
363 Rectangle AccessibleGridControlBase::getBoundingBox()
364 throw ( lang::DisposedException )
366 TCSolarGuard aSolarGuard;
367 ::osl::MutexGuard aGuard( getOslMutex() );
368 ensureIsAlive();
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" );
374 return aRect;
377 Rectangle AccessibleGridControlBase::getBoundingBoxOnScreen()
378 throw ( lang::DisposedException )
380 TCSolarGuard aSolarGuard;
381 ::osl::MutexGuard aGuard( getOslMutex() );
382 ensureIsAlive();
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" );
388 return aRect;
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
398 return;
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() )
417 rId.realloc( 16 );
418 rtl_createUuid( reinterpret_cast< sal_uInt8* >( rId.getArray() ), 0, sal_True );
421 // -----------------------------------------------------------------------------
422 sal_Int16 SAL_CALL AccessibleGridControlBase::getAccessibleRole()
423 throw ( uno::RuntimeException )
425 ensureIsAlive();
426 sal_Int16 nRole = AccessibleRole::UNKNOWN;
427 switch ( m_eObjType )
429 case TCTYPE_ROWHEADERCELL:
430 nRole = AccessibleRole::ROW_HEADER;
431 break;
432 case TCTYPE_COLUMNHEADERCELL:
433 nRole = AccessibleRole::COLUMN_HEADER;
434 break;
435 case TCTYPE_COLUMNHEADERBAR:
436 case TCTYPE_ROWHEADERBAR:
437 case TCTYPE_TABLE:
438 nRole = AccessibleRole::TABLE;
439 break;
440 case TCTYPE_TABLECELL:
441 nRole = AccessibleRole::TABLE_CELL;
442 break;
443 case TCTYPE_GRIDCONTROL:
444 nRole = AccessibleRole::PANEL;
445 break;
447 return nRole;
449 // -----------------------------------------------------------------------------
450 Any SAL_CALL AccessibleGridControlBase::getAccessibleKeyBinding()
451 throw ( uno::RuntimeException )
453 return Any();
455 // -----------------------------------------------------------------------------
456 Reference<XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point& )
457 throw ( uno::RuntimeException )
459 return NULL;
461 //// -----------------------------------------------------------------------------
462 sal_Int32 SAL_CALL AccessibleGridControlBase::getForeground( ) throw (::com::sun::star::uno::RuntimeException)
464 TCSolarGuard aSolarGuard;
465 ::osl::MutexGuard aGuard( getOslMutex() );
466 ensureIsAlive();
468 sal_Int32 nColor = 0;
469 Window* pInst = m_aTable.GetWindowInstance();
470 if ( pInst )
472 if ( pInst->IsControlForeground() )
473 nColor = pInst->GetControlForeground().GetColor();
474 else
476 Font aFont;
477 if ( pInst->IsControlFont() )
478 aFont = pInst->GetControlFont();
479 else
480 aFont = pInst->GetFont();
481 nColor = aFont.GetColor().GetColor();
484 return nColor;
486 // -----------------------------------------------------------------------------
487 sal_Int32 SAL_CALL AccessibleGridControlBase::getBackground( ) throw (::com::sun::star::uno::RuntimeException)
489 TCSolarGuard aSolarGuard;
490 ::osl::MutexGuard aGuard( getOslMutex() );
491 ensureIsAlive();
492 sal_Int32 nColor = 0;
493 Window* pInst = m_aTable.GetWindowInstance();
494 if ( pInst )
496 if ( pInst->IsControlBackground() )
497 nColor = pInst->GetControlBackground().GetColor();
498 else
499 nColor = pInst->GetBackground().GetColor().GetColor();
501 return nColor;
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 )
522 ensureIsAlive();
523 return this;
525 // ----------------------------------------------------------------------------
526 GridControlAccessibleElement::~GridControlAccessibleElement( )
530 // ============================================================================
532 } // namespace accessibility
534 // ============================================================================