1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "accessibility/extended/AccessibleGridControlBase.hxx"
21 #include <svtools/accessibletable.hxx>
22 #include <comphelper/servicehelper.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <unotools/accessiblerelationsethelper.hxx>
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::com::sun::star::uno::Any
;
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::accessibility
;
37 using namespace ::comphelper
;
38 using namespace ::svt
;
39 using namespace ::svt::table
;
44 namespace accessibility
{
46 using namespace com::sun::star::accessibility::AccessibleStateType
;
49 AccessibleGridControlBase::AccessibleGridControlBase(
50 const Reference
< XAccessible
>& rxParent
,
51 svt::table::IAccessibleTable
& rTable
,
52 AccessibleTableControlObjType eObjType
) :
53 AccessibleGridControlImplHelper( m_aMutex
),
54 m_xParent( rxParent
),
56 m_eObjType( eObjType
),
57 m_aName( rTable
.GetAccessibleObjectName( eObjType
, 0, 0 ) ),
58 m_aDescription( rTable
.GetAccessibleObjectDescription( eObjType
) ),
63 AccessibleGridControlBase::~AccessibleGridControlBase()
67 // increment ref count to prevent double call of Dtor
68 osl_atomic_increment( &m_refCount
);
73 void SAL_CALL
AccessibleGridControlBase::disposing()
79 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
81 AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
88 // XAccessibleContext ---------------------------------------------------------
90 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleParent()
91 throw ( uno::RuntimeException
, std::exception
)
99 sal_Int32 SAL_CALL
AccessibleGridControlBase::getAccessibleIndexInParent()
100 throw ( uno::RuntimeException
, std::exception
)
106 // -1 for child not found/no parent (according to specification)
109 Reference
< uno::XInterface
> xMeMyselfAndI( static_cast< XAccessibleContext
* >( this ), uno::UNO_QUERY
);
111 // iterate over parent's children and search for this object
114 Reference
< XAccessibleContext
>
115 xParentContext( m_xParent
->getAccessibleContext() );
116 if( xParentContext
.is() )
118 Reference
< uno::XInterface
> xChild
;
120 sal_Int32 nChildCount
= xParentContext
->getAccessibleChildCount();
121 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; ++nChild
)
123 xChild
.set(xParentContext
->getAccessibleChild( nChild
), css::uno::UNO_QUERY
);
124 if ( xMeMyselfAndI
.get() == xChild
.get() )
135 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleDescription()
136 throw ( uno::RuntimeException
, std::exception
)
141 return m_aDescription
;
144 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleName()
145 throw ( uno::RuntimeException
, std::exception
)
153 Reference
< XAccessibleRelationSet
> SAL_CALL
154 AccessibleGridControlBase::getAccessibleRelationSet()
155 throw ( uno::RuntimeException
, std::exception
)
160 // GridControl does not have relations.
161 return new utl::AccessibleRelationSetHelper
;
164 Reference
< XAccessibleStateSet
> SAL_CALL
165 AccessibleGridControlBase::getAccessibleStateSet()
166 throw ( uno::RuntimeException
, std::exception
)
168 SolarMutexGuard aSolarGuard
;
170 // don't check whether alive -> StateSet may contain DEFUNC
171 return implCreateStateSetHelper();
174 lang::Locale SAL_CALL
AccessibleGridControlBase::getLocale()
175 throw ( IllegalAccessibleComponentStateException
, uno::RuntimeException
, std::exception
)
182 Reference
< XAccessibleContext
>
183 xParentContext( m_xParent
->getAccessibleContext() );
184 if( xParentContext
.is() )
185 return xParentContext
->getLocale();
187 throw IllegalAccessibleComponentStateException();
190 // XAccessibleComponent -------------------------------------------------------
192 sal_Bool SAL_CALL
AccessibleGridControlBase::containsPoint( const awt::Point
& rPoint
)
193 throw ( uno::RuntimeException
, std::exception
)
195 return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint
) );
198 awt::Rectangle SAL_CALL
AccessibleGridControlBase::getBounds()
199 throw ( uno::RuntimeException
, std::exception
)
201 return AWTRectangle( getBoundingBox() );
204 awt::Point SAL_CALL
AccessibleGridControlBase::getLocation()
205 throw ( uno::RuntimeException
, std::exception
)
207 return AWTPoint( getBoundingBox().TopLeft() );
210 awt::Point SAL_CALL
AccessibleGridControlBase::getLocationOnScreen()
211 throw ( uno::RuntimeException
, std::exception
)
213 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
216 awt::Size SAL_CALL
AccessibleGridControlBase::getSize()
217 throw ( uno::RuntimeException
, std::exception
)
219 return AWTSize( getBoundingBox().GetSize() );
222 // XAccessibleEventBroadcaster ------------------------------------------------
224 void SAL_CALL
AccessibleGridControlBase::addAccessibleEventListener(
225 const Reference
< XAccessibleEventListener
>& _rxListener
)
226 throw ( uno::RuntimeException
, std::exception
)
228 if ( _rxListener
.is() )
232 if ( !getClientId( ) )
233 setClientId( AccessibleEventNotifier::registerClient( ) );
235 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
239 void SAL_CALL
AccessibleGridControlBase::removeAccessibleEventListener(
240 const Reference
< XAccessibleEventListener
>& _rxListener
)
241 throw ( uno::RuntimeException
, std::exception
)
243 if( _rxListener
.is() && getClientId( ) )
247 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
248 if ( !nListenerCount
)
250 // no listeners anymore
251 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
252 // and at least to us not firing any events anymore, in case somebody calls
253 // NotifyAccessibleEvent, again
254 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
256 AccessibleEventNotifier::revokeClient( nId
);
261 // XTypeProvider --------------------------------------------------------------
263 Sequence
< sal_Int8
> SAL_CALL
AccessibleGridControlBase::getImplementationId()
264 throw ( uno::RuntimeException
, std::exception
)
266 return css::uno::Sequence
<sal_Int8
>();
269 // XServiceInfo ---------------------------------------------------------------
271 sal_Bool SAL_CALL
AccessibleGridControlBase::supportsService(
272 const OUString
& rServiceName
)
273 throw ( uno::RuntimeException
, std::exception
)
275 return cppu::supportsService(this, rServiceName
);
278 Sequence
< OUString
> SAL_CALL
AccessibleGridControlBase::getSupportedServiceNames()
279 throw ( uno::RuntimeException
, std::exception
)
281 const OUString
aServiceName( "com.sun.star.accessibility.AccessibleContext" );
282 return Sequence
< OUString
>( &aServiceName
, 1 );
284 // internal virtual methods ---------------------------------------------------
286 bool AccessibleGridControlBase::implIsShowing()
288 bool bShowing
= false;
291 Reference
< XAccessibleComponent
>
292 xParentComp( m_xParent
->getAccessibleContext(), uno::UNO_QUERY
);
293 if( xParentComp
.is() )
294 bShowing
= implGetBoundingBox().IsOver(
295 VCLRectangle( xParentComp
->getBounds() ) );
300 ::utl::AccessibleStateSetHelper
* AccessibleGridControlBase::implCreateStateSetHelper()
302 ::utl::AccessibleStateSetHelper
*
303 pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
307 // SHOWING done with m_xParent
308 if( implIsShowing() )
309 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
310 // GridControl fills StateSet with states depending on object type
311 m_aTable
.FillAccessibleStateSet( *pStateSetHelper
, getType() );
314 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
315 return pStateSetHelper
;
318 // internal helper methods ----------------------------------------------------
320 bool AccessibleGridControlBase::isAlive() const
322 ::osl::MutexGuard
g(m_aMutex
); // guards rBHelper members
323 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
;
326 void AccessibleGridControlBase::ensureIsAlive() const
327 throw ( lang::DisposedException
)
330 throw lang::DisposedException();
333 Rectangle
AccessibleGridControlBase::getBoundingBox()
334 throw ( lang::DisposedException
)
336 SolarMutexGuard aSolarGuard
;
338 Rectangle aRect
= implGetBoundingBox();
339 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
341 SAL_WARN( "accessibility", "rectangle doesn't exist" );
346 Rectangle
AccessibleGridControlBase::getBoundingBoxOnScreen()
347 throw ( lang::DisposedException
)
349 SolarMutexGuard aSolarGuard
;
351 Rectangle aRect
= implGetBoundingBoxOnScreen();
352 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
354 SAL_WARN( "accessibility", "rectangle doesn't exist" );
359 void AccessibleGridControlBase::commitEvent(
360 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
364 if ( !getClientId( ) )
365 // if we don't have a client id for the notifier, then we don't have listeners, then
366 // we don't need to notify anything
369 // build an event object
370 AccessibleEventObject aEvent
;
371 aEvent
.Source
= *this;
372 aEvent
.EventId
= _nEventId
;
373 aEvent
.OldValue
= _rOldValue
;
374 aEvent
.NewValue
= _rNewValue
;
376 // let the notifier handle this event
378 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
381 sal_Int16 SAL_CALL
AccessibleGridControlBase::getAccessibleRole()
382 throw ( uno::RuntimeException
, std::exception
)
385 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
386 switch ( m_eObjType
)
388 case TCTYPE_ROWHEADERCELL
:
389 nRole
= AccessibleRole::ROW_HEADER
;
391 case TCTYPE_COLUMNHEADERCELL
:
392 nRole
= AccessibleRole::COLUMN_HEADER
;
394 case TCTYPE_COLUMNHEADERBAR
:
395 case TCTYPE_ROWHEADERBAR
:
397 nRole
= AccessibleRole::TABLE
;
399 case TCTYPE_TABLECELL
:
400 nRole
= AccessibleRole::TABLE_CELL
;
402 case TCTYPE_GRIDCONTROL
:
403 nRole
= AccessibleRole::PANEL
;
409 Reference
<XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point
& )
410 throw ( uno::RuntimeException
, std::exception
)
415 sal_Int32 SAL_CALL
AccessibleGridControlBase::getForeground( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
417 SolarMutexGuard aSolarGuard
;
421 sal_Int32 nColor
= 0;
422 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
425 if ( pInst
->IsControlForeground() )
426 nColor
= pInst
->GetControlForeground().GetColor();
430 if ( pInst
->IsControlFont() )
431 aFont
= pInst
->GetControlFont();
433 aFont
= pInst
->GetFont();
434 nColor
= aFont
.GetColor().GetColor();
440 sal_Int32 SAL_CALL
AccessibleGridControlBase::getBackground( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
442 SolarMutexGuard aSolarGuard
;
445 sal_Int32 nColor
= 0;
446 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
449 if ( pInst
->IsControlBackground() )
450 nColor
= pInst
->GetControlBackground().GetColor();
452 nColor
= pInst
->GetBackground().GetColor().GetColor();
458 GridControlAccessibleElement::GridControlAccessibleElement( const Reference
< XAccessible
>& rxParent
,
459 IAccessibleTable
& rTable
,
460 AccessibleTableControlObjType eObjType
)
461 :AccessibleGridControlBase( rxParent
, rTable
, eObjType
)
465 // XInterface -----------------------------------------------------------------
466 IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
468 // XTypeProvider --------------------------------------------------------------
469 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
471 // XAccessible ----------------------------------------------------------------
473 Reference
< XAccessibleContext
> SAL_CALL
GridControlAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException
, std::exception
)
481 GridControlAccessibleElement::~GridControlAccessibleElement( )
487 } // namespace accessibility
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */