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 <toolkit/helper/convert.hxx>
23 #include <vcl/accessibletable.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/window.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <sal/types.h>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
32 #include <unotools/accessiblerelationsethelper.hxx>
33 #include <sal/log.hxx>
35 using ::com::sun::star::uno::Sequence
;
36 using ::com::sun::star::uno::Any
;
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::comphelper
;
41 using namespace ::vcl
;
42 using namespace ::vcl::table
;
45 namespace accessibility
{
47 using namespace com::sun::star::accessibility::AccessibleStateType
;
50 AccessibleGridControlBase::AccessibleGridControlBase(
51 css::uno::Reference
< css::accessibility::XAccessible
> xParent
,
52 ::vcl::table::IAccessibleTable
& rTable
,
53 ::vcl::table::AccessibleTableControlObjType eObjType
) :
54 AccessibleGridControlImplHelper( m_aMutex
),
55 m_xParent(std::move( xParent
)),
57 m_eObjType( eObjType
),
62 AccessibleGridControlBase::~AccessibleGridControlBase()
66 // increment ref count to prevent double call of Dtor
67 osl_atomic_increment( &m_refCount
);
72 void SAL_CALL
AccessibleGridControlBase::disposing()
78 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
80 AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
87 // css::accessibility::XAccessibleContext
89 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleParent()
97 sal_Int64 SAL_CALL
AccessibleGridControlBase::getAccessibleIndexInParent()
103 // -1 for child not found/no parent (according to specification)
106 css::uno::Reference
< uno::XInterface
> xMeMyselfAndI( static_cast< css::accessibility::XAccessibleContext
* >( this ), uno::UNO_QUERY
);
108 // iterate over parent's children and search for this object
111 css::uno::Reference
< css::accessibility::XAccessibleContext
>
112 xParentContext( m_xParent
->getAccessibleContext() );
113 if( xParentContext
.is() )
115 css::uno::Reference
< uno::XInterface
> xChild
;
117 sal_Int64 nChildCount
= xParentContext
->getAccessibleChildCount();
118 for( sal_Int64 nChild
= 0; nChild
< nChildCount
; ++nChild
)
120 xChild
.set(xParentContext
->getAccessibleChild( nChild
), css::uno::UNO_QUERY
);
121 if ( xMeMyselfAndI
.get() == xChild
.get() )
132 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleDescription()
137 return m_aTable
.GetAccessibleObjectDescription(m_eObjType
);
140 OUString SAL_CALL
AccessibleGridControlBase::getAccessibleName()
145 return m_aTable
.GetAccessibleObjectName(m_eObjType
, 0, 0);
148 css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
149 AccessibleGridControlBase::getAccessibleRelationSet()
154 // GridControl does not have relations.
155 return new utl::AccessibleRelationSetHelper
;
159 AccessibleGridControlBase::getAccessibleStateSet()
161 SolarMutexGuard aSolarGuard
;
163 // don't check whether alive -> StateSet may contain DEFUNC
164 return implCreateStateSet();
167 lang::Locale SAL_CALL
AccessibleGridControlBase::getLocale()
174 css::uno::Reference
< css::accessibility::XAccessibleContext
>
175 xParentContext( m_xParent
->getAccessibleContext() );
176 if( xParentContext
.is() )
177 return xParentContext
->getLocale();
179 throw IllegalAccessibleComponentStateException();
182 // css::accessibility::XAccessibleComponent
184 sal_Bool SAL_CALL
AccessibleGridControlBase::containsPoint( const awt::Point
& rPoint
)
186 return tools::Rectangle( Point(), getBoundingBox().GetSize() ).Contains( VCLPoint( rPoint
) );
189 awt::Rectangle SAL_CALL
AccessibleGridControlBase::getBounds()
191 return AWTRectangle( getBoundingBox() );
194 awt::Point SAL_CALL
AccessibleGridControlBase::getLocation()
196 return AWTPoint( getBoundingBox().TopLeft() );
199 awt::Point SAL_CALL
AccessibleGridControlBase::getLocationOnScreen()
201 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
204 awt::Size SAL_CALL
AccessibleGridControlBase::getSize()
206 return AWTSize( getBoundingBox().GetSize() );
209 // css::accessibility::XAccessibleEventBroadcaster
211 void SAL_CALL
AccessibleGridControlBase::addAccessibleEventListener(
212 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& _rxListener
)
214 if ( _rxListener
.is() )
218 if ( !getClientId( ) )
219 setClientId( AccessibleEventNotifier::registerClient( ) );
221 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
225 void SAL_CALL
AccessibleGridControlBase::removeAccessibleEventListener(
226 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& _rxListener
)
228 if( !(_rxListener
.is() && getClientId( )) )
233 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
234 if ( !nListenerCount
)
236 // no listeners anymore
237 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
238 // and at least to us not firing any events anymore, in case somebody calls
239 // NotifyAccessibleEvent, again
240 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
242 AccessibleEventNotifier::revokeClient( nId
);
248 Sequence
< sal_Int8
> SAL_CALL
AccessibleGridControlBase::getImplementationId()
250 return css::uno::Sequence
<sal_Int8
>();
255 sal_Bool SAL_CALL
AccessibleGridControlBase::supportsService(
256 const OUString
& rServiceName
)
258 return cppu::supportsService(this, rServiceName
);
261 Sequence
< OUString
> SAL_CALL
AccessibleGridControlBase::getSupportedServiceNames()
263 return { "com.sun.star.accessibility.AccessibleContext" };
265 // internal virtual methods
267 bool AccessibleGridControlBase::implIsShowing()
269 bool bShowing
= false;
272 css::uno::Reference
< css::accessibility::XAccessibleComponent
>
273 xParentComp( m_xParent
->getAccessibleContext(), uno::UNO_QUERY
);
274 if( xParentComp
.is() )
275 bShowing
= implGetBoundingBox().Overlaps(
276 VCLRectangle( xParentComp
->getBounds() ) );
281 sal_Int64
AccessibleGridControlBase::implCreateStateSet()
283 sal_Int64 nStateSet
= 0;
287 // SHOWING done with m_xParent
288 if( implIsShowing() )
289 nStateSet
|= AccessibleStateType::SHOWING
;
290 // GridControl fills StateSet with states depending on object type
291 m_aTable
.FillAccessibleStateSet( nStateSet
, getType() );
294 nStateSet
|= AccessibleStateType::DEFUNC
;
298 // internal helper methods
300 bool AccessibleGridControlBase::isAlive() const
302 ::osl::MutexGuard
g(m_aMutex
); // guards rBHelper members
303 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
;
306 void AccessibleGridControlBase::ensureIsAlive() const
309 throw lang::DisposedException();
312 tools::Rectangle
AccessibleGridControlBase::getBoundingBox()
314 SolarMutexGuard aSolarGuard
;
316 tools::Rectangle aRect
= implGetBoundingBox();
317 if ( aRect
.Left() == 0 && aRect
.Top() == 0 && aRect
.Right() == 0 && aRect
.Bottom() == 0 )
319 SAL_WARN( "accessibility", "rectangle doesn't exist" );
324 tools::Rectangle
AccessibleGridControlBase::getBoundingBoxOnScreen()
326 SolarMutexGuard aSolarGuard
;
328 tools::Rectangle aRect
= implGetBoundingBoxOnScreen();
329 if ( aRect
.Left() == 0 && aRect
.Top() == 0 && aRect
.Right() == 0 && aRect
.Bottom() == 0 )
331 SAL_WARN( "accessibility", "rectangle doesn't exist" );
336 void AccessibleGridControlBase::commitEvent(
337 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
341 if ( !getClientId( ) )
342 // if we don't have a client id for the notifier, then we don't have listeners, then
343 // we don't need to notify anything
346 // build an event object
347 AccessibleEventObject aEvent
;
348 aEvent
.Source
= *this;
349 aEvent
.EventId
= _nEventId
;
350 aEvent
.OldValue
= _rOldValue
;
351 aEvent
.NewValue
= _rNewValue
;
353 // let the notifier handle this event
355 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
358 sal_Int16 SAL_CALL
AccessibleGridControlBase::getAccessibleRole()
361 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
362 switch ( m_eObjType
)
364 case TCTYPE_ROWHEADERCELL
:
365 nRole
= AccessibleRole::ROW_HEADER
;
367 case TCTYPE_COLUMNHEADERCELL
:
368 nRole
= AccessibleRole::COLUMN_HEADER
;
370 case TCTYPE_COLUMNHEADERBAR
:
371 case TCTYPE_ROWHEADERBAR
:
373 nRole
= AccessibleRole::TABLE
;
375 case TCTYPE_TABLECELL
:
376 nRole
= AccessibleRole::TABLE_CELL
;
378 case TCTYPE_GRIDCONTROL
:
379 nRole
= AccessibleRole::PANEL
;
385 css::uno::Reference
<css::accessibility::XAccessible
> SAL_CALL
AccessibleGridControlBase::getAccessibleAtPoint( const css::awt::Point
& )
390 sal_Int32 SAL_CALL
AccessibleGridControlBase::getForeground( )
392 SolarMutexGuard aSolarGuard
;
397 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
400 if ( pInst
->IsControlForeground() )
401 nColor
= pInst
->GetControlForeground();
405 if ( pInst
->IsControlFont() )
406 aFont
= pInst
->GetControlFont();
408 aFont
= pInst
->GetFont();
409 nColor
= aFont
.GetColor();
412 return sal_Int32(nColor
);
415 sal_Int32 SAL_CALL
AccessibleGridControlBase::getBackground( )
417 SolarMutexGuard aSolarGuard
;
421 vcl::Window
* pInst
= m_aTable
.GetWindowInstance();
424 if ( pInst
->IsControlBackground() )
425 nColor
= pInst
->GetControlBackground();
427 nColor
= pInst
->GetBackground().GetColor();
429 return sal_Int32(nColor
);
433 GridControlAccessibleElement::GridControlAccessibleElement( const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
434 ::vcl::table::IAccessibleTable
& rTable
,
435 ::vcl::table::AccessibleTableControlObjType eObjType
)
436 :AccessibleGridControlBase( rxParent
, rTable
, eObjType
)
441 IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
444 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement
, AccessibleGridControlBase
, GridControlAccessibleElement_Base
)
446 // css::accessibility::XAccessible
448 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
GridControlAccessibleElement::getAccessibleContext()
456 GridControlAccessibleElement::~GridControlAccessibleElement( )
461 } // namespace accessibility
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */