bump product version to 7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlBase.cxx
blob37e3235ee711116a994ac9bc35fe4d2603924dec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <utility>
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 )),
56 m_aTable( rTable),
57 m_eObjType( eObjType ),
58 m_aClientId(0)
62 AccessibleGridControlBase::~AccessibleGridControlBase()
64 if( isAlive() )
66 // increment ref count to prevent double call of Dtor
67 osl_atomic_increment( &m_refCount );
68 dispose();
72 void SAL_CALL AccessibleGridControlBase::disposing()
74 SolarMutexGuard g;
76 if ( getClientId( ) )
78 AccessibleEventNotifier::TClientId nId( getClientId( ) );
79 setClientId( 0 );
80 AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
83 m_xParent = nullptr;
84 //m_aTable = NULL;
87 // css::accessibility::XAccessibleContext
89 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent()
91 SolarMutexGuard g;
93 ensureIsAlive();
94 return m_xParent;
97 sal_Int64 SAL_CALL AccessibleGridControlBase::getAccessibleIndexInParent()
99 SolarMutexGuard g;
101 ensureIsAlive();
103 // -1 for child not found/no parent (according to specification)
104 sal_Int64 nRet = -1;
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
109 if( m_xParent.is() )
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() )
123 nRet = nChild;
124 break;
129 return nRet;
132 OUString SAL_CALL AccessibleGridControlBase::getAccessibleDescription()
134 SolarMutexGuard g;
136 ensureIsAlive();
137 return m_aTable.GetAccessibleObjectDescription(m_eObjType);
140 OUString SAL_CALL AccessibleGridControlBase::getAccessibleName()
142 SolarMutexGuard g;
144 ensureIsAlive();
145 return m_aTable.GetAccessibleObjectName(m_eObjType, 0, 0);
148 css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL
149 AccessibleGridControlBase::getAccessibleRelationSet()
151 SolarMutexGuard g;
153 ensureIsAlive();
154 // GridControl does not have relations.
155 return new utl::AccessibleRelationSetHelper;
158 sal_Int64 SAL_CALL
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()
169 SolarMutexGuard g;
171 ensureIsAlive();
172 if( m_xParent.is() )
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() )
216 SolarMutexGuard g;
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( )) )
229 return;
231 SolarMutexGuard g;
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( ) );
241 setClientId( 0 );
242 AccessibleEventNotifier::revokeClient( nId );
246 // XTypeProvider
248 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlBase::getImplementationId()
250 return css::uno::Sequence<sal_Int8>();
253 // XServiceInfo
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;
270 if( m_xParent.is() )
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() ) );
278 return bShowing;
281 sal_Int64 AccessibleGridControlBase::implCreateStateSet()
283 sal_Int64 nStateSet = 0;
285 if( isAlive() )
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() );
293 else
294 nStateSet |= AccessibleStateType::DEFUNC;
295 return nStateSet;
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
308 if( !isAlive() )
309 throw lang::DisposedException();
312 tools::Rectangle AccessibleGridControlBase::getBoundingBox()
314 SolarMutexGuard aSolarGuard;
315 ensureIsAlive();
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" );
321 return aRect;
324 tools::Rectangle AccessibleGridControlBase::getBoundingBoxOnScreen()
326 SolarMutexGuard aSolarGuard;
327 ensureIsAlive();
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" );
333 return aRect;
336 void AccessibleGridControlBase::commitEvent(
337 sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
339 SolarMutexGuard g;
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;
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()
360 ensureIsAlive();
361 sal_Int16 nRole = AccessibleRole::UNKNOWN;
362 switch ( m_eObjType )
364 case TCTYPE_ROWHEADERCELL:
365 nRole = AccessibleRole::ROW_HEADER;
366 break;
367 case TCTYPE_COLUMNHEADERCELL:
368 nRole = AccessibleRole::COLUMN_HEADER;
369 break;
370 case TCTYPE_COLUMNHEADERBAR:
371 case TCTYPE_ROWHEADERBAR:
372 case TCTYPE_TABLE:
373 nRole = AccessibleRole::TABLE;
374 break;
375 case TCTYPE_TABLECELL:
376 nRole = AccessibleRole::TABLE_CELL;
377 break;
378 case TCTYPE_GRIDCONTROL:
379 nRole = AccessibleRole::PANEL;
380 break;
382 return nRole;
385 css::uno::Reference<css::accessibility::XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const css::awt::Point& )
387 return nullptr;
390 sal_Int32 SAL_CALL AccessibleGridControlBase::getForeground( )
392 SolarMutexGuard aSolarGuard;
394 ensureIsAlive();
396 Color nColor;
397 vcl::Window* pInst = m_aTable.GetWindowInstance();
398 if ( pInst )
400 if ( pInst->IsControlForeground() )
401 nColor = pInst->GetControlForeground();
402 else
404 vcl::Font aFont;
405 if ( pInst->IsControlFont() )
406 aFont = pInst->GetControlFont();
407 else
408 aFont = pInst->GetFont();
409 nColor = aFont.GetColor();
412 return sal_Int32(nColor);
415 sal_Int32 SAL_CALL AccessibleGridControlBase::getBackground( )
417 SolarMutexGuard aSolarGuard;
419 ensureIsAlive();
420 Color nColor;
421 vcl::Window* pInst = m_aTable.GetWindowInstance();
422 if ( pInst )
424 if ( pInst->IsControlBackground() )
425 nColor = pInst->GetControlBackground();
426 else
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 )
440 // XInterface
441 IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base)
443 // XTypeProvider
444 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base )
446 // css::accessibility::XAccessible
448 css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL GridControlAccessibleElement::getAccessibleContext()
450 SolarMutexGuard g;
452 ensureIsAlive();
453 return this;
456 GridControlAccessibleElement::~GridControlAccessibleElement( )
461 } // namespace accessibility
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */