LibreOffice Module accessibility (master) 1
AccessibleGridControlBase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22#include <utility>
24#include <vcl/svapp.hxx>
25#include <vcl/window.hxx>
27#include <sal/types.h>
28
29#include <com/sun/star/accessibility/AccessibleRole.hpp>
30#include <com/sun/star/accessibility/AccessibleStateType.hpp>
31#include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
33#include <sal/log.hxx>
34
35using ::com::sun::star::uno::Sequence;
36using ::com::sun::star::uno::Any;
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::accessibility;
40using namespace ::comphelper;
41using namespace ::vcl;
42using namespace ::vcl::table;
43
44
45namespace accessibility {
46
47using namespace com::sun::star::accessibility::AccessibleStateType;
48
49
51 css::uno::Reference< css::accessibility::XAccessible > xParent,
55 m_xParent(std::move( xParent )),
56 m_aTable( rTable),
57 m_eObjType( eObjType ),
58 m_aClientId(0)
59{
60}
61
63{
64 if( isAlive() )
65 {
66 // increment ref count to prevent double call of Dtor
67 osl_atomic_increment( &m_refCount );
68 dispose();
69 }
70}
71
73{
75
76 if ( getClientId( ) )
77 {
79 setClientId( 0 );
81 }
82
83 m_xParent = nullptr;
84 //m_aTable = NULL;
85}
86
87// css::accessibility::XAccessibleContext
88
89css::uno::Reference< css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent()
90{
92
94 return m_xParent;
95}
96
98{
100
102
103 // -1 for child not found/no parent (according to specification)
104 sal_Int64 nRet = -1;
105
106 css::uno::Reference< uno::XInterface > xMeMyselfAndI( static_cast< css::accessibility::XAccessibleContext* >( this ), uno::UNO_QUERY );
107
108 // iterate over parent's children and search for this object
109 if( m_xParent.is() )
110 {
111 css::uno::Reference< css::accessibility::XAccessibleContext >
112 xParentContext( m_xParent->getAccessibleContext() );
113 if( xParentContext.is() )
114 {
115 css::uno::Reference< uno::XInterface > xChild;
116
117 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
118 for( sal_Int64 nChild = 0; nChild < nChildCount; ++nChild )
119 {
120 xChild.set(xParentContext->getAccessibleChild( nChild ), css::uno::UNO_QUERY);
121 if ( xMeMyselfAndI.get() == xChild.get() )
122 {
123 nRet = nChild;
124 break;
125 }
126 }
127 }
128 }
129 return nRet;
130}
131
133{
135
138}
139
141{
143
146}
147
148css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL
150{
152
154 // GridControl does not have relations.
156}
157
158sal_Int64 SAL_CALL
160{
161 SolarMutexGuard aSolarGuard;
162
163 // don't check whether alive -> StateSet may contain DEFUNC
164 return implCreateStateSet();
165}
166
168{
170
172 if( m_xParent.is() )
173 {
174 css::uno::Reference< css::accessibility::XAccessibleContext >
175 xParentContext( m_xParent->getAccessibleContext() );
176 if( xParentContext.is() )
177 return xParentContext->getLocale();
178 }
179 throw IllegalAccessibleComponentStateException();
180}
181
182// css::accessibility::XAccessibleComponent
183
184sal_Bool SAL_CALL AccessibleGridControlBase::containsPoint( const awt::Point& rPoint )
185{
186 return tools::Rectangle( Point(), getBoundingBox().GetSize() ).Contains( VCLPoint( rPoint ) );
187}
188
190{
191 return AWTRectangle( getBoundingBox() );
192}
193
195{
196 return AWTPoint( getBoundingBox().TopLeft() );
197}
198
200{
202}
203
205{
206 return AWTSize( getBoundingBox().GetSize() );
207}
208
209// css::accessibility::XAccessibleEventBroadcaster
210
212 const css::uno::Reference< css::accessibility::XAccessibleEventListener>& _rxListener )
213{
214 if ( _rxListener.is() )
215 {
217
218 if ( !getClientId( ) )
220
222 }
223}
224
226 const css::uno::Reference< css::accessibility::XAccessibleEventListener>& _rxListener )
227{
228 if( !(_rxListener.is() && getClientId( )) )
229 return;
230
232
233 sal_Int32 nListenerCount = AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener );
234 if ( !nListenerCount )
235 {
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
241 setClientId( 0 );
243 }
244}
245
246// XTypeProvider
247
249{
250 return css::uno::Sequence<sal_Int8>();
251}
252
253// XServiceInfo
254
256 const OUString& rServiceName )
257{
258 return cppu::supportsService(this, rServiceName);
259}
260
262{
263 return { "com.sun.star.accessibility.AccessibleContext" };
264}
265// internal virtual methods
266
268{
269 bool bShowing = false;
270 if( m_xParent.is() )
271 {
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() ) );
277 }
278 return bShowing;
279}
280
282{
283 sal_Int64 nStateSet = 0;
284
285 if( isAlive() )
286 {
287 // SHOWING done with m_xParent
288 if( implIsShowing() )
289 nStateSet |= AccessibleStateType::SHOWING;
290 // GridControl fills StateSet with states depending on object type
292 }
293 else
294 nStateSet |= AccessibleStateType::DEFUNC;
295 return nStateSet;
296}
297
298// internal helper methods
299
301{
302 ::osl::MutexGuard g(m_aMutex); // guards rBHelper members
303 return !rBHelper.bDisposed && !rBHelper.bInDispose;
304}
305
307{
308 if( !isAlive() )
309 throw lang::DisposedException();
310}
311
313{
314 SolarMutexGuard aSolarGuard;
317 if ( aRect.Left() == 0 && aRect.Top() == 0 && aRect.Right() == 0 && aRect.Bottom() == 0 )
318 {
319 SAL_WARN( "accessibility", "rectangle doesn't exist" );
320 }
321 return aRect;
322}
323
325{
326 SolarMutexGuard aSolarGuard;
329 if ( aRect.Left() == 0 && aRect.Top() == 0 && aRect.Right() == 0 && aRect.Bottom() == 0 )
330 {
331 SAL_WARN( "accessibility", "rectangle doesn't exist" );
332 }
333 return aRect;
334}
335
337 sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
338{
340
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
344 return;
345
346 // build an event object
347 AccessibleEventObject aEvent(*this, _nEventId, _rNewValue, _rOldValue, -1);
348
349 // let the notifier handle this event
350
352}
353
355{
357 sal_Int16 nRole = AccessibleRole::UNKNOWN;
358 switch ( m_eObjType )
359 {
361 nRole = AccessibleRole::ROW_HEADER;
362 break;
364 nRole = AccessibleRole::COLUMN_HEADER;
365 break;
368 case TCTYPE_TABLE:
369 nRole = AccessibleRole::TABLE;
370 break;
371 case TCTYPE_TABLECELL:
372 nRole = AccessibleRole::TABLE_CELL;
373 break;
375 nRole = AccessibleRole::PANEL;
376 break;
377 }
378 return nRole;
379}
380
381css::uno::Reference<css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const css::awt::Point& )
382{
383 return nullptr;
384}
385
387{
388 SolarMutexGuard aSolarGuard;
389
391
392 Color nColor;
394 if ( pInst )
395 {
396 if ( pInst->IsControlForeground() )
397 nColor = pInst->GetControlForeground();
398 else
399 {
400 vcl::Font aFont;
401 if ( pInst->IsControlFont() )
402 aFont = pInst->GetControlFont();
403 else
404 aFont = pInst->GetFont();
405 nColor = aFont.GetColor();
406 }
407 }
408 return sal_Int32(nColor);
409}
410
412{
413 SolarMutexGuard aSolarGuard;
414
416 Color nColor;
418 if ( pInst )
419 {
420 if ( pInst->IsControlBackground() )
421 nColor = pInst->GetControlBackground();
422 else
423 nColor = pInst->GetBackground().GetColor();
424 }
425 return sal_Int32(nColor);
426}
427
428
429GridControlAccessibleElement::GridControlAccessibleElement( const css::uno::Reference< css::accessibility::XAccessible >& rxParent,
432 :AccessibleGridControlBase( rxParent, rTable, eObjType )
433{
434}
435
436// XInterface
438
439// XTypeProvider
441
442// css::accessibility::XAccessible
443
444css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL GridControlAccessibleElement::getAccessibleContext()
445{
447
448 ensureIsAlive();
449 return this;
450}
451
453{
454}
455
456
457} // namespace accessibility
458
459
460/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
const Color & GetColor() const
The GridControl accessible objects inherit from this base class.
css::uno::Reference< css::accessibility::XAccessible > m_xParent
The parent accessible object.
::vcl::table::IAccessibleTable & m_aTable
The SVT Table control.
virtual OUString SAL_CALL getAccessibleDescription() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual void commitEvent(sal_Int16 nEventId, const css::uno::Any &rNewValue, const css::uno::Any &rOldValue)
Commits an event to all listeners.
tools::Rectangle getBoundingBoxOnScreen()
‍** Locks all mutex's and calculates the bounding box in screen
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &rxListener) override
Removes an event listener.
virtual css::awt::Rectangle SAL_CALL getBounds() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual css::awt::Point SAL_CALL getLocation() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool implIsShowing()
Determines whether the Grid control is really showing inside of its parent accessible window.
virtual tools::Rectangle implGetBoundingBoxOnScreen()=0
‍** Derived classes return the bounding box in screen coordinates.
AccessibleGridControlBase(css::uno::Reference< css::accessibility::XAccessible > xParent, ::vcl::table::IAccessibleTable &rTable, ::vcl::table::AccessibleTableControlObjType eObjType)
Constructor.
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Int64 implCreateStateSet()
Creates a bitset of states of the current object.
virtual css::awt::Size SAL_CALL getSize() override
virtual void SAL_CALL disposing() override
Commits DeFunc event to listeners and cleans up members.
void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId)
inline ::vcl::table::AccessibleTableControlObjType getType() const
virtual sal_Int32 SAL_CALL getForeground() override
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &rxListener) override
Adds a new event listener.
::comphelper::AccessibleEventNotifier::TClientId getClientId() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &rPoint) override
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
tools::Rectangle getBoundingBox()
Locks all mutex's and calculates the bounding box relative to the parent window.
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual tools::Rectangle implGetBoundingBox()=0
Derived classes return the bounding box relative to the parent window.
::vcl::table::AccessibleTableControlObjType m_eObjType
The type of this object (for names, descriptions, state sets, ...).
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual sal_Int32 SAL_CALL getBackground() override
GridControlAccessibleElement(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ::vcl::table::IAccessibleTable &rTable, ::vcl::table::AccessibleTableControlObjType eObjType)
Constructor sets specified name and description.
static sal_Int32 addEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
static void addEvent(const TClientId _nClient, const css::accessibility::AccessibleEventObject &_rEvent)
static sal_Int32 removeEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
static void revokeClient(const TClientId _nClient)
static void revokeClientNotifyDisposing(const TClientId _nClient, const css::uno::Reference< css::uno::XInterface > &_rxEventSource)
mutable::osl::Mutex m_aMutex
bool Contains(const Point &rPOINT) const
bool Overlaps(const tools::Rectangle &rRect) const
constexpr tools::Long Top() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
const Color & GetColor() const
const Wallpaper & GetBackground() const
bool IsControlFont() const
const Color & GetControlForeground() const
bool IsControlForeground() const
vcl::Font GetControlFont() const
const vcl::Font & GetFont() const
bool IsControlBackground() const
const Color & GetControlBackground() const
virtual OUString GetAccessibleObjectDescription(AccessibleTableControlObjType eObjType) const=0
virtual vcl::Window * GetWindowInstance()=0
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet, AccessibleTableControlObjType eObjType) const=0
virtual OUString GetAccessibleObjectName(AccessibleTableControlObjType eObjType, sal_Int32 _nRow, sal_Int32 _nCol) const=0
css::awt::Size AWTSize(const Size &rVCLSize)
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
ULONG m_refCount
std::mutex m_aMutex
#define SAL_WARN(area, stream)
::cppu::WeakComponentImplHelper< css::accessibility::XAccessibleContext, css::accessibility::XAccessibleComponent, css::accessibility::XAccessibleEventBroadcaster, css::lang::XServiceInfo > AccessibleGridControlImplHelper
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
void dispose()
AccessibleTableControlObjType
TCTYPE_TABLECELL
TCTYPE_GRIDCONTROL
TCTYPE_ROWHEADERCELL
TCTYPE_ROWHEADERBAR
TCTYPE_COLUMNHEADERBAR
TCTYPE_COLUMNHEADERCELL
TCTYPE_TABLE
sal_Int16 nId
unsigned char sal_Bool