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 <extended/AccessibleGridControlBase.hxx>
21 #include <vcl/accessibletable.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <sal/types.h>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <sal/log.hxx>
31 using ::com::sun::star::uno::Sequence
;
32 using ::com::sun::star::uno::Any
;
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::accessibility
;
36 using namespace ::comphelper
;
37 using namespace ::vcl
;
38 using namespace ::vcl::table
;
41 namespace accessibility
{
43 using namespace com::sun::star::accessibility::AccessibleStateType
;
46 AccessibleGridControlBase::AccessibleGridControlBase(
47 const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
48 ::vcl::table::IAccessibleTable
& rTable
,
49 ::vcl::table::AccessibleTableControlObjType eObjType
) :
50 AccessibleGridControlImplHelper( m_aMutex
),
51 m_xParent( rxParent
),
53 m_eObjType( eObjType
),
54 m_aName( rTable
.GetAccessibleObjectName( eObjType
, 0, 0 ) ),
55 m_aDescription( rTable
.GetAccessibleObjectDescription( eObjType
) ),
60 AccessibleGridControlBase::~AccessibleGridControlBase()
64 // increment ref count to prevent double call of Dtor
65 osl_atomic_increment( &m_refCount
);
70 void SAL_CALL
AccessibleGridControlBase::disposing()
76 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
78 AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
85 // css::accessibility::XAccessibleContext
87 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleParent()
95 sal_Int32 SAL_CALL
AccessibleGridControlBase::getAccessibleIndexInParent()
101 // -1 for child not found/no parent (according to specification)
104 css::uno::Reference
< uno::XInterface
> xMeMyselfAndI( static_cast< css::accessibility::XAccessibleContext
* >( this ), uno::UNO_QUERY
);
106 // iterate over parent's children and search for this object
109 css::uno::Reference
< css::accessibility::XAccessibleContext
>
110 xParentContext( m_xParent
->getAccessibleContext() );
111 if( xParentContext
.is() )
113 css::uno::Reference
< uno::XInterface
> xChild
;
115 sal_Int32 nChildCount
= xParentContext
->getAccessibleChildCount();
116 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; ++nChild
)
118 xChild
.set(xParentContext
->getAccessibleChild( nChild
), css::uno::UNO_QUERY
);
119 if ( xMeMyselfAndI
.get() == xChild
.get() )
130 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleDescription()
135 return m_aDescription
;
138 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleName()
146 css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
147 AccessibleGridControlBase::getAccessibleRelationSet()
152 // GridControl does not have relations.
153 return new utl::AccessibleRelationSetHelper
;
156 css::uno::Reference
< css::accessibility::XAccessibleStateSet
> SAL_CALL
157 AccessibleGridControlBase::getAccessibleStateSet()
159 SolarMutexGuard aSolarGuard
;
161 // don't check whether alive -> StateSet may contain DEFUNC
162 return implCreateStateSetHelper();
165 lang::Locale SAL_CALL
AccessibleGridControlBase::getLocale()
172 css::uno::Reference
< css::accessibility::XAccessibleContext
>
173 xParentContext( m_xParent
->getAccessibleContext() );
174 if( xParentContext
.is() )
175 return xParentContext
->getLocale();
177 throw IllegalAccessibleComponentStateException();
180 // css::accessibility::XAccessibleComponent
182 sal_Bool SAL_CALL
AccessibleGridControlBase::containsPoint( const awt::Point
& rPoint
)
184 return tools::Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint
) );
187 awt::Rectangle SAL_CALL
AccessibleGridControlBase::getBounds()
189 return AWTRectangle( getBoundingBox() );
192 awt::Point SAL_CALL
AccessibleGridControlBase::getLocation()
194 return AWTPoint( getBoundingBox().TopLeft() );
197 awt::Point SAL_CALL
AccessibleGridControlBase::getLocationOnScreen()
199 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
202 awt::Size SAL_CALL
AccessibleGridControlBase::getSize()
204 return AWTSize( getBoundingBox().GetSize() );
207 // css::accessibility::XAccessibleEventBroadcaster
209 void SAL_CALL
AccessibleGridControlBase::addAccessibleEventListener(
210 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& _rxListener
)
212 if ( _rxListener
.is() )
216 if ( !getClientId( ) )
217 setClientId( AccessibleEventNotifier::registerClient( ) );
219 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
223 void SAL_CALL
AccessibleGridControlBase::removeAccessibleEventListener(
224 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& _rxListener
)
226 if( _rxListener
.is() && getClientId( ) )
230 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
231 if ( !nListenerCount
)
233 // no listeners anymore
234 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
235 // and at least to us not firing any events anymore, in case somebody calls
236 // NotifyAccessibleEvent, again
237 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
239 AccessibleEventNotifier::revokeClient( nId
);
246 Sequence
< sal_Int8
> SAL_CALL
AccessibleGridControlBase::getImplementationId()
248 return css::uno::Sequence
<sal_Int8
>();
253 sal_Bool SAL_CALL
AccessibleGridControlBase::supportsService(
254 const OUString
& rServiceName
)
256 return cppu::supportsService(this, rServiceName
);
259 Sequence
< OUString
> SAL_CALL
AccessibleGridControlBase::getSupportedServiceNames()
261 return { "com.sun.star.accessibility.AccessibleContext" };
263 // internal virtual methods
265 bool AccessibleGridControlBase::implIsShowing()
267 bool bShowing
= false;
270 css::uno::Reference
< css::accessibility::XAccessibleComponent
>
271 xParentComp( m_xParent
->getAccessibleContext(), uno::UNO_QUERY
);
272 if( xParentComp
.is() )
273 bShowing
= implGetBoundingBox().IsOver(
274 VCLRectangle( xParentComp
->getBounds() ) );
279 ::utl::AccessibleStateSetHelper
* AccessibleGridControlBase::implCreateStateSetHelper()
281 ::utl::AccessibleStateSetHelper
*
282 pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
286 // SHOWING done with m_xParent
287 if( implIsShowing() )
288 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
289 // GridControl fills StateSet with states depending on object type
290 m_aTable
.FillAccessibleStateSet( *pStateSetHelper
, getType() );
293 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
294 return pStateSetHelper
;
297 // internal helper methods
299 bool AccessibleGridControlBase::isAlive() const
301 ::osl::MutexGuard
g(m_aMutex
); // guards rBHelper members
302 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
;
305 void AccessibleGridControlBase::ensureIsAlive() const
308 throw lang::DisposedException();
311 tools::Rectangle
AccessibleGridControlBase::getBoundingBox()
313 SolarMutexGuard aSolarGuard
;
315 tools::Rectangle aRect
= implGetBoundingBox();
316 if ( aRect
.Left() == 0 && aRect
.Top() == 0 && aRect
.Right() == 0 && aRect
.Bottom() == 0 )
318 SAL_WARN( "accessibility", "rectangle doesn't exist" );
323 tools::Rectangle
AccessibleGridControlBase::getBoundingBoxOnScreen()
325 SolarMutexGuard aSolarGuard
;
327 tools::Rectangle aRect
= implGetBoundingBoxOnScreen();
328 if ( aRect
.Left() == 0 && aRect
.Top() == 0 && aRect
.Right() == 0 && aRect
.Bottom() == 0 )
330 SAL_WARN( "accessibility", "rectangle doesn't exist" );
335 void AccessibleGridControlBase::commitEvent(
336 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
340 if ( !getClientId( ) )
341 // if we don't have a client id for the notifier, then we don't have listeners, then
342 // we don't need to notify anything
345 // build an event object
346 AccessibleEventObject aEvent
;
347 aEvent
.Source
= *this;
348 aEvent
.EventId
= _nEventId
;
349 aEvent
.OldValue
= _rOldValue
;
350 aEvent
.NewValue
= _rNewValue
;
352 // let the notifier handle this event
354 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
357 sal_Int16 SAL_CALL
AccessibleGridControlBase::getAccessibleRole()
360 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
361 switch ( m_eObjType
)
363 case TCTYPE_ROWHEADERCELL
:
364 nRole
= AccessibleRole::ROW_HEADER
;
366 case TCTYPE_COLUMNHEADERCELL
:
367 nRole
= AccessibleRole::COLUMN_HEADER
;
369 case TCTYPE_COLUMNHEADERBAR
:
370 case TCTYPE_ROWHEADERBAR
:
372 nRole
= AccessibleRole::TABLE
;
374 case TCTYPE_TABLECELL
:
375 nRole
= AccessibleRole::TABLE_CELL
;
377 case TCTYPE_GRIDCONTROL
:
378 nRole
= AccessibleRole::PANEL
;
384 css::uno::Reference
<css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleAtPoint( const css::awt::Point
& )
389 sal_Int32 SAL_CALL
AccessibleGridControlBase::getForeground( )
391 SolarMutexGuard aSolarGuard
;
396 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
399 if ( pInst
->IsControlForeground() )
400 nColor
= pInst
->GetControlForeground();
404 if ( pInst
->IsControlFont() )
405 aFont
= pInst
->GetControlFont();
407 aFont
= pInst
->GetFont();
408 nColor
= aFont
.GetColor();
411 return sal_Int32(nColor
);
414 sal_Int32 SAL_CALL
AccessibleGridControlBase::getBackground( )
416 SolarMutexGuard aSolarGuard
;
420 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
423 if ( pInst
->IsControlBackground() )
424 nColor
= pInst
->GetControlBackground();
426 nColor
= pInst
->GetBackground().GetColor();
428 return sal_Int32(nColor
);
432 GridControlAccessibleElement::GridControlAccessibleElement( const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
433 ::vcl::table::IAccessibleTable
& rTable
,
434 ::vcl::table::AccessibleTableControlObjType eObjType
)
435 :AccessibleGridControlBase( rxParent
, rTable
, eObjType
)
440 IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
443 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
445 // css::accessibility::XAccessible
447 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
GridControlAccessibleElement::getAccessibleContext()
455 GridControlAccessibleElement::~GridControlAccessibleElement( )
460 } // namespace accessibility
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */