LCOV - code coverage report
Current view: top level - accessibility/source/extended - AccessibleGridControlBase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 194 0.0 %
Date: 2014-04-11 Functions: 0 41 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : #include "accessibility/extended/AccessibleGridControlBase.hxx"
      21             : #include <svtools/accessibletable.hxx>
      22             : #include <comphelper/servicehelper.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : 
      25             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      27             : #include <unotools/accessiblerelationsethelper.hxx>
      28             : 
      29             : 
      30             : 
      31             : using ::com::sun::star::uno::Reference;
      32             : using ::com::sun::star::uno::Sequence;
      33             : using ::com::sun::star::uno::Any;
      34             : 
      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;
      40             : 
      41             : 
      42             : 
      43             : 
      44             : namespace accessibility {
      45             : 
      46             : using namespace com::sun::star::accessibility::AccessibleStateType;
      47             : 
      48             : 
      49           0 : AccessibleGridControlBase::AccessibleGridControlBase(
      50             :         const Reference< XAccessible >& rxParent,
      51             :         svt::table::IAccessibleTable& rTable,
      52             :         AccessibleTableControlObjType      eObjType ) :
      53             :     AccessibleGridControlImplHelper( m_aMutex ),
      54             :     m_xParent( rxParent ),
      55             :     m_aTable( rTable),
      56             :     m_eObjType( eObjType ),
      57           0 :     m_aName( rTable.GetAccessibleObjectName( eObjType, 0, 0 ) ),
      58           0 :     m_aDescription( rTable.GetAccessibleObjectDescription( eObjType ) ),
      59           0 :     m_aClientId(0)
      60             : {
      61           0 : }
      62             : 
      63           0 : AccessibleGridControlBase::~AccessibleGridControlBase()
      64             : {
      65           0 :     if( isAlive() )
      66             :     {
      67             :         // increment ref count to prevent double call of Dtor
      68           0 :         osl_atomic_increment( &m_refCount );
      69           0 :         dispose();
      70             :     }
      71           0 : }
      72             : 
      73           0 : void SAL_CALL AccessibleGridControlBase::disposing()
      74             : {
      75           0 :     SolarMutexGuard g;
      76             : 
      77           0 :     if ( getClientId( ) )
      78             :     {
      79           0 :         AccessibleEventNotifier::TClientId nId( getClientId( ) );
      80           0 :         setClientId( 0 );
      81           0 :         AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
      82             :     }
      83             : 
      84           0 :     m_xParent = NULL;
      85             :     //m_aTable = NULL;
      86           0 : }
      87             : 
      88             : // XAccessibleContext ---------------------------------------------------------
      89             : 
      90           0 : Reference< XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleParent()
      91             :     throw ( uno::RuntimeException, std::exception )
      92             : {
      93           0 :     SolarMutexGuard g;
      94             : 
      95           0 :     ensureIsAlive();
      96           0 :     return m_xParent;
      97             : }
      98             : 
      99           0 : sal_Int32 SAL_CALL AccessibleGridControlBase::getAccessibleIndexInParent()
     100             :     throw ( uno::RuntimeException, std::exception )
     101             : {
     102           0 :     SolarMutexGuard g;
     103             : 
     104           0 :     ensureIsAlive();
     105             : 
     106             :     // -1 for child not found/no parent (according to specification)
     107           0 :     sal_Int32 nRet = -1;
     108             : 
     109           0 :     Reference< uno::XInterface > xMeMyselfAndI( static_cast< XAccessibleContext* >( this ), uno::UNO_QUERY );
     110             : 
     111             :     //  iterate over parent's children and search for this object
     112           0 :     if( m_xParent.is() )
     113             :     {
     114             :         Reference< XAccessibleContext >
     115           0 :             xParentContext( m_xParent->getAccessibleContext() );
     116           0 :         if( xParentContext.is() )
     117             :         {
     118           0 :         Reference< uno::XInterface > xChild;
     119             : 
     120           0 :             sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
     121           0 :             for( sal_Int32 nChild = 0; nChild < nChildCount; ++nChild )
     122             :             {
     123           0 :             xChild = xChild.query( xParentContext->getAccessibleChild( nChild ) );
     124           0 :             if ( xMeMyselfAndI.get() == xChild.get() )
     125             :             {
     126           0 :                 nRet = nChild;
     127           0 :                 break;
     128             :             }
     129           0 :         }
     130           0 :         }
     131             :    }
     132           0 :    return nRet;
     133             : }
     134             : 
     135           0 : OUString SAL_CALL AccessibleGridControlBase::getAccessibleDescription()
     136             :     throw ( uno::RuntimeException, std::exception )
     137             : {
     138           0 :     SolarMutexGuard g;
     139             : 
     140           0 :     ensureIsAlive();
     141           0 :     return m_aDescription;
     142             : }
     143             : 
     144           0 : OUString SAL_CALL AccessibleGridControlBase::getAccessibleName()
     145             :     throw ( uno::RuntimeException, std::exception )
     146             : {
     147           0 :     SolarMutexGuard g;
     148             : 
     149           0 :     ensureIsAlive();
     150           0 :     return m_aName;
     151             : }
     152             : 
     153             : Reference< XAccessibleRelationSet > SAL_CALL
     154           0 : AccessibleGridControlBase::getAccessibleRelationSet()
     155             :     throw ( uno::RuntimeException, std::exception )
     156             : {
     157           0 :    SolarMutexGuard g;
     158             : 
     159           0 :    ensureIsAlive();
     160             :    // GridControl does not have relations.
     161           0 :    return new utl::AccessibleRelationSetHelper;
     162             : }
     163             : 
     164             : Reference< XAccessibleStateSet > SAL_CALL
     165           0 : AccessibleGridControlBase::getAccessibleStateSet()
     166             :     throw ( uno::RuntimeException, std::exception )
     167             : {
     168           0 :     SolarMutexGuard aSolarGuard;
     169             : 
     170             :     // don't check whether alive -> StateSet may contain DEFUNC
     171           0 :     return implCreateStateSetHelper();
     172             : }
     173             : 
     174           0 : lang::Locale SAL_CALL AccessibleGridControlBase::getLocale()
     175             :     throw ( IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception )
     176             : {
     177           0 :     SolarMutexGuard g;
     178             : 
     179           0 :     ensureIsAlive();
     180           0 :     if( m_xParent.is() )
     181             :     {
     182             :         Reference< XAccessibleContext >
     183           0 :             xParentContext( m_xParent->getAccessibleContext() );
     184           0 :         if( xParentContext.is() )
     185           0 :         return xParentContext->getLocale();
     186             :     }
     187           0 :     throw IllegalAccessibleComponentStateException();
     188             : }
     189             : 
     190             : // XAccessibleComponent -------------------------------------------------------
     191             : 
     192           0 : sal_Bool SAL_CALL AccessibleGridControlBase::containsPoint( const awt::Point& rPoint )
     193             :     throw ( uno::RuntimeException, std::exception )
     194             : {
     195           0 :    return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
     196             : }
     197             : 
     198           0 : awt::Rectangle SAL_CALL AccessibleGridControlBase::getBounds()
     199             :     throw ( uno::RuntimeException, std::exception )
     200             : {
     201           0 :    return AWTRectangle( getBoundingBox() );
     202             : }
     203             : 
     204           0 : awt::Point SAL_CALL AccessibleGridControlBase::getLocation()
     205             :     throw ( uno::RuntimeException, std::exception )
     206             : {
     207           0 :     return AWTPoint( getBoundingBox().TopLeft() );
     208             : }
     209             : 
     210           0 : awt::Point SAL_CALL AccessibleGridControlBase::getLocationOnScreen()
     211             :     throw ( uno::RuntimeException, std::exception )
     212             : {
     213           0 :     return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
     214             : }
     215             : 
     216           0 : awt::Size SAL_CALL AccessibleGridControlBase::getSize()
     217             :     throw ( uno::RuntimeException, std::exception )
     218             : {
     219           0 :     return AWTSize( getBoundingBox().GetSize() );
     220             : }
     221             : 
     222             : // XAccessibleEventBroadcaster ------------------------------------------------
     223             : 
     224           0 : void SAL_CALL AccessibleGridControlBase::addAccessibleEventListener(
     225             :         const Reference< XAccessibleEventListener>& _rxListener )
     226             :     throw ( uno::RuntimeException, std::exception )
     227             : {
     228           0 :     if ( _rxListener.is() )
     229             :     {
     230           0 :         SolarMutexGuard g;
     231             : 
     232           0 :         if ( !getClientId( ) )
     233           0 :             setClientId( AccessibleEventNotifier::registerClient( ) );
     234             : 
     235           0 :         AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener );
     236             :     }
     237           0 : }
     238             : 
     239           0 : void SAL_CALL AccessibleGridControlBase::removeAccessibleEventListener(
     240             :         const Reference< XAccessibleEventListener>& _rxListener )
     241             :     throw ( uno::RuntimeException, std::exception )
     242             : {
     243           0 :     if( _rxListener.is() && getClientId( ) )
     244             :     {
     245           0 :         SolarMutexGuard g;
     246             : 
     247           0 :         sal_Int32 nListenerCount = AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener );
     248           0 :     if ( !nListenerCount )
     249             :     {
     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           0 :         AccessibleEventNotifier::TClientId nId( getClientId( ) );
     255           0 :         setClientId( 0 );
     256           0 :         AccessibleEventNotifier::revokeClient( nId );
     257           0 :     }
     258             :     }
     259           0 : }
     260             : 
     261             : // XTypeProvider --------------------------------------------------------------
     262             : 
     263           0 : Sequence< sal_Int8 > SAL_CALL AccessibleGridControlBase::getImplementationId()
     264             :     throw ( uno::RuntimeException, std::exception )
     265             : {
     266           0 :     return css::uno::Sequence<sal_Int8>();
     267             : }
     268             : 
     269             : // XServiceInfo ---------------------------------------------------------------
     270             : 
     271           0 : sal_Bool SAL_CALL AccessibleGridControlBase::supportsService(
     272             :         const OUString& rServiceName )
     273             :     throw ( uno::RuntimeException, std::exception )
     274             : {
     275           0 :     return cppu::supportsService(this, rServiceName);
     276             : }
     277             : 
     278           0 : Sequence< OUString > SAL_CALL AccessibleGridControlBase::getSupportedServiceNames()
     279             :     throw ( uno::RuntimeException, std::exception )
     280             : {
     281           0 :     const OUString aServiceName( "com.sun.star.accessibility.AccessibleContext" );
     282           0 :     return Sequence< OUString >( &aServiceName, 1 );
     283             : }
     284             : // internal virtual methods ---------------------------------------------------
     285             : 
     286           0 : sal_Bool AccessibleGridControlBase::implIsShowing()
     287             : {
     288           0 :     sal_Bool bShowing = sal_False;
     289           0 :     if( m_xParent.is() )
     290             :     {
     291             :         Reference< XAccessibleComponent >
     292           0 :             xParentComp( m_xParent->getAccessibleContext(), uno::UNO_QUERY );
     293           0 :         if( xParentComp.is() )
     294           0 :             bShowing = implGetBoundingBox().IsOver(
     295           0 :                 VCLRectangle( xParentComp->getBounds() ) );
     296             :     }
     297           0 :     return bShowing;
     298             : }
     299             : 
     300           0 : ::utl::AccessibleStateSetHelper* AccessibleGridControlBase::implCreateStateSetHelper()
     301             : {
     302             :     ::utl::AccessibleStateSetHelper*
     303           0 :         pStateSetHelper = new ::utl::AccessibleStateSetHelper;
     304             : 
     305           0 :     if( isAlive() )
     306             :     {
     307             :         // SHOWING done with m_xParent
     308           0 :         if( implIsShowing() )
     309           0 :             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
     310             :         // GridControl fills StateSet with states depending on object type
     311           0 :         m_aTable.FillAccessibleStateSet( *pStateSetHelper, getType() );
     312             :     }
     313             :     else
     314           0 :         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
     315           0 :     return pStateSetHelper;
     316             : }
     317             : 
     318             : // internal helper methods ----------------------------------------------------
     319             : 
     320           0 : sal_Bool AccessibleGridControlBase::isAlive() const
     321             : {
     322           0 :     ::osl::MutexGuard g(m_aMutex); // guards rBHelper members
     323           0 :     return !rBHelper.bDisposed && !rBHelper.bInDispose && &m_aTable;
     324             : }
     325             : 
     326           0 : void AccessibleGridControlBase::ensureIsAlive() const
     327             :     throw ( lang::DisposedException )
     328             : {
     329           0 :     if( !isAlive() )
     330           0 :         throw lang::DisposedException();
     331           0 : }
     332             : 
     333           0 : Rectangle AccessibleGridControlBase::getBoundingBox()
     334             :     throw ( lang::DisposedException )
     335             : {
     336           0 :     SolarMutexGuard aSolarGuard;
     337           0 :     ensureIsAlive();
     338           0 :     Rectangle aRect = implGetBoundingBox();
     339           0 :     if ( 0 == aRect.Left() && 0 == aRect.Top() && 0 == aRect.Right() && 0 == aRect.Bottom() )
     340             :     {
     341             :         SAL_WARN( "accessibility", "rectangle doesn't exist" );
     342             :     }
     343           0 :     return aRect;
     344             : }
     345             : 
     346           0 : Rectangle AccessibleGridControlBase::getBoundingBoxOnScreen()
     347             :     throw ( lang::DisposedException )
     348             : {
     349           0 :     SolarMutexGuard aSolarGuard;
     350           0 :     ensureIsAlive();
     351           0 :     Rectangle aRect = implGetBoundingBoxOnScreen();
     352           0 :     if ( 0 == aRect.Left() && 0 == aRect.Top() && 0 == aRect.Right() && 0 == aRect.Bottom() )
     353             :     {
     354             :         SAL_WARN( "accessibility", "rectangle doesn't exist" );
     355             :     }
     356           0 :     return aRect;
     357             : }
     358             : 
     359           0 : void AccessibleGridControlBase::commitEvent(
     360             :         sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
     361             : {
     362           0 :     SolarMutexGuard g;
     363             : 
     364           0 :     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
     367           0 :             return;
     368             : 
     369             :     // build an event object
     370           0 :     AccessibleEventObject aEvent;
     371           0 :     aEvent.Source = *this;
     372           0 :     aEvent.EventId = _nEventId;
     373           0 :     aEvent.OldValue = _rOldValue;
     374           0 :     aEvent.NewValue = _rNewValue;
     375             : 
     376             :     // let the notifier handle this event
     377             : 
     378           0 :     AccessibleEventNotifier::addEvent( getClientId( ), aEvent );
     379             : }
     380             : 
     381           0 : sal_Int16 SAL_CALL AccessibleGridControlBase::getAccessibleRole()
     382             :     throw ( uno::RuntimeException, std::exception )
     383             : {
     384           0 :     ensureIsAlive();
     385           0 :     sal_Int16 nRole = AccessibleRole::UNKNOWN;
     386           0 :     switch ( m_eObjType )
     387             :     {
     388             :         case TCTYPE_ROWHEADERCELL:
     389           0 :         nRole = AccessibleRole::ROW_HEADER;
     390           0 :         break;
     391             :     case TCTYPE_COLUMNHEADERCELL:
     392           0 :         nRole = AccessibleRole::COLUMN_HEADER;
     393           0 :         break;
     394             :     case TCTYPE_COLUMNHEADERBAR:
     395             :     case TCTYPE_ROWHEADERBAR:
     396             :     case TCTYPE_TABLE:
     397           0 :         nRole = AccessibleRole::TABLE;
     398           0 :         break;
     399             :     case TCTYPE_TABLECELL:
     400           0 :         nRole = AccessibleRole::TABLE_CELL;
     401           0 :         break;
     402             :     case TCTYPE_GRIDCONTROL:
     403           0 :         nRole = AccessibleRole::PANEL;
     404           0 :         break;
     405             :     }
     406           0 :     return nRole;
     407             : }
     408             : 
     409           0 : Reference<XAccessible > SAL_CALL AccessibleGridControlBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point& )
     410             :         throw ( uno::RuntimeException, std::exception )
     411             : {
     412           0 :     return NULL;
     413             : }
     414             : 
     415           0 : sal_Int32 SAL_CALL AccessibleGridControlBase::getForeground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     416             : {
     417           0 :     SolarMutexGuard aSolarGuard;
     418             : 
     419           0 :     ensureIsAlive();
     420             : 
     421           0 :     sal_Int32 nColor = 0;
     422           0 :     Window* pInst = m_aTable.GetWindowInstance();
     423           0 :     if ( pInst )
     424             :     {
     425           0 :         if ( pInst->IsControlForeground() )
     426           0 :             nColor = pInst->GetControlForeground().GetColor();
     427             :     else
     428             :     {
     429           0 :         Font aFont;
     430           0 :         if ( pInst->IsControlFont() )
     431           0 :             aFont = pInst->GetControlFont();
     432             :         else
     433           0 :             aFont = pInst->GetFont();
     434           0 :         nColor = aFont.GetColor().GetColor();
     435             :     }
     436             :     }
     437           0 :     return nColor;
     438             : }
     439             : 
     440           0 : sal_Int32 SAL_CALL AccessibleGridControlBase::getBackground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     441             : {
     442           0 :     SolarMutexGuard aSolarGuard;
     443             : 
     444           0 :     ensureIsAlive();
     445           0 :     sal_Int32 nColor = 0;
     446           0 :     Window* pInst = m_aTable.GetWindowInstance();
     447           0 :     if ( pInst )
     448             :     {
     449           0 :         if ( pInst->IsControlBackground() )
     450           0 :             nColor = pInst->GetControlBackground().GetColor();
     451             :     else
     452           0 :             nColor = pInst->GetBackground().GetColor().GetColor();
     453             :     }
     454           0 :     return nColor;
     455             : }
     456             : 
     457             : 
     458           0 : GridControlAccessibleElement::GridControlAccessibleElement( const Reference< XAccessible >& rxParent,
     459             :                         IAccessibleTable& rTable,
     460             :                         AccessibleTableControlObjType  eObjType )
     461           0 :     :AccessibleGridControlBase( rxParent, rTable, eObjType )
     462             : {
     463           0 : }
     464             : 
     465             : // XInterface -----------------------------------------------------------------
     466           0 : IMPLEMENT_FORWARD_XINTERFACE2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base)
     467             : 
     468             : // XTypeProvider --------------------------------------------------------------
     469           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridControlAccessibleElement, AccessibleGridControlBase, GridControlAccessibleElement_Base )
     470             : 
     471             : // XAccessible ----------------------------------------------------------------
     472             : 
     473           0 : Reference< XAccessibleContext > SAL_CALL GridControlAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException, std::exception )
     474             : {
     475           0 :     SolarMutexGuard g;
     476             : 
     477           0 :     ensureIsAlive();
     478           0 :     return this;
     479             : }
     480             : 
     481           0 : GridControlAccessibleElement::~GridControlAccessibleElement( )
     482             : {
     483           0 : }
     484             : 
     485             : 
     486             : 
     487             : } // namespace accessibility
     488             : 
     489             : 
     490             : 
     491             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10