LCOV - code coverage report
Current view: top level - svtools/source/control - accessibleruler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 46 171 26.9 %
Date: 2014-11-03 Functions: 13 41 31.7 %
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             : #include <svtools/accessibleruler.hxx>
      20             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      21             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      22             : #include <unotools/accessiblestatesethelper.hxx>
      23             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      24             : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
      25             : #include <com/sun/star/awt/XWindow.hpp>
      26             : #include <comphelper/accessibleeventnotifier.hxx>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : #include <toolkit/helper/vclunohelper.hxx>
      30             : #include <toolkit/helper/convert.hxx>
      31             : #include <vcl/svapp.hxx>
      32             : #include <osl/mutex.hxx>
      33             : #include <rtl/uuid.h>
      34             : #include <tools/gen.hxx>
      35             : 
      36             : #include <svtools/ruler.hxx>
      37             : 
      38             : using namespace ::cppu;
      39             : using namespace ::osl;
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::accessibility;
      43             : 
      44             : 
      45             : 
      46             : //=====  internal  ============================================================
      47             : 
      48          20 : SvtRulerAccessible::SvtRulerAccessible(
      49             :     const uno::Reference< XAccessible >& rxParent, Ruler& rRepr, const OUString& rName ) :
      50             : 
      51             :     SvtRulerAccessible_Base( m_aMutex ),
      52             :     msName( rName ),
      53             :     mxParent( rxParent ),
      54             :     mpRepr( &rRepr ),
      55          20 :     mnClientId( 0 )
      56             : {
      57          20 : }
      58             : 
      59          60 : SvtRulerAccessible::~SvtRulerAccessible()
      60             : {
      61             : 
      62          20 :     if( IsAlive() )
      63             :     {
      64           0 :         osl_atomic_increment( &m_refCount );
      65           0 :         dispose();      // set mpRepr = NULL & release all children
      66             :     }
      67          40 : }
      68             : 
      69             : //=====  XAccessible  =========================================================
      70             : 
      71          20 : uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext( void ) throw( RuntimeException, std::exception )
      72             : {
      73          20 :     return this;
      74             : }
      75             : 
      76             : //=====  XAccessibleComponent  ================================================
      77             : 
      78           0 : sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
      79             : {
      80             :     // no guard -> done in getBounds()
      81             : //  return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
      82           0 :     return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
      83             : }
      84             : 
      85           0 : uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& ) throw( RuntimeException, std::exception )
      86             : {
      87           0 :     ::osl::MutexGuard           aGuard( m_aMutex );
      88             : 
      89           0 :     ThrowExceptionIfNotAlive();
      90             : 
      91           0 :     uno::Reference< XAccessible >   xRet;
      92             : 
      93             : 
      94           0 :     return xRet;
      95             : }
      96             : 
      97           0 : awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds() throw( RuntimeException, std::exception )
      98             : {
      99             :     // no guard -> done in GetBoundingBox()
     100           0 :     return AWTRectangle( GetBoundingBox() );
     101             : }
     102             : 
     103           0 : awt::Point SAL_CALL SvtRulerAccessible::getLocation() throw( RuntimeException, std::exception )
     104             : {
     105             :     // no guard -> done in GetBoundingBox()
     106           0 :     return AWTPoint( GetBoundingBox().TopLeft() );
     107             : }
     108             : 
     109           0 : awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen() throw( RuntimeException, std::exception )
     110             : {
     111             :     // no guard -> done in GetBoundingBoxOnScreen()
     112           0 :     return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
     113             : }
     114             : 
     115           0 : awt::Size SAL_CALL SvtRulerAccessible::getSize() throw( RuntimeException, std::exception )
     116             : {
     117             :     // no guard -> done in GetBoundingBox()
     118           0 :     return AWTSize( GetBoundingBox().GetSize() );
     119             : }
     120             : 
     121          20 : bool SAL_CALL SvtRulerAccessible::isShowing() throw( RuntimeException )
     122             : {
     123          20 :     return true;
     124             : }
     125             : 
     126          20 : bool SAL_CALL SvtRulerAccessible::isVisible() throw( RuntimeException )
     127             : {
     128          20 :     ::osl::MutexGuard           aGuard( m_aMutex );
     129             : 
     130          20 :     ThrowExceptionIfNotAlive();
     131             : 
     132          20 :     return mpRepr->IsVisible();
     133             : }
     134             : 
     135           0 : bool SAL_CALL SvtRulerAccessible::isFocusTraversable() throw( RuntimeException )
     136             : {
     137           0 :     return true;
     138             : }
     139             : 
     140             : //=====  XAccessibleContext  ==================================================
     141             : 
     142          40 : sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleChildCount( void ) throw( RuntimeException, std::exception )
     143             : {
     144          40 :     ::osl::MutexGuard   aGuard( m_aMutex );
     145             : 
     146          40 :     ThrowExceptionIfNotAlive();
     147             : 
     148          40 :     return 0;
     149             : }
     150             : 
     151           0 : uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int32 )
     152             :     throw( RuntimeException, lang::IndexOutOfBoundsException, std::exception )
     153             : {
     154           0 :     uno::Reference< XAccessible >   xChild ;
     155             : 
     156           0 :     return xChild;
     157             : }
     158             : 
     159           0 : uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent( void ) throw( RuntimeException, std::exception )
     160             : {
     161           0 :     return mxParent;
     162             : }
     163             : 
     164           0 : sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent( void ) throw( RuntimeException, std::exception )
     165             : {
     166           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     167             :     //  Use a simple but slow solution for now.  Optimize later.
     168             : 
     169             :     //  Iterate over all the parent's children and search for this object.
     170           0 :     if( mxParent.is() )
     171             :     {
     172           0 :         uno::Reference< XAccessibleContext >        xParentContext( mxParent->getAccessibleContext() );
     173           0 :         if( xParentContext.is() )
     174             :         {
     175           0 :             sal_Int32                       nChildCount = xParentContext->getAccessibleChildCount();
     176           0 :             for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
     177             :             {
     178           0 :                 uno::Reference< XAccessible >   xChild( xParentContext->getAccessibleChild( i ) );
     179           0 :                 if( xChild.get() == ( XAccessible* ) this )
     180           0 :                     return i;
     181           0 :             }
     182           0 :         }
     183             :    }
     184             : 
     185             :    //   Return -1 to indicate that this object's parent does not know about the
     186             :    //   object.
     187           0 :    return -1;
     188             : }
     189             : 
     190          20 : sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole( void ) throw( RuntimeException, std::exception )
     191             : {
     192          20 :     return AccessibleRole::RULER;
     193             : }
     194             : 
     195           0 : OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription( void ) throw( RuntimeException, std::exception )
     196             : {
     197           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     198           0 :     return msDescription;
     199             : }
     200             : 
     201           0 : OUString SAL_CALL SvtRulerAccessible::getAccessibleName( void ) throw( RuntimeException, std::exception )
     202             : {
     203           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     204           0 :     return msName;
     205             : }
     206             : 
     207             : /** Return empty uno::Reference to indicate that the relation set is not
     208             :     supported.
     209             : */
     210           0 : uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet( void ) throw( RuntimeException, std::exception )
     211             : {
     212           0 :     return uno::Reference< XAccessibleRelationSet >();
     213             : }
     214             : 
     215             : 
     216          20 : uno::Reference< XAccessibleStateSet > SAL_CALL SvtRulerAccessible::getAccessibleStateSet( void ) throw( RuntimeException, std::exception )
     217             : {
     218          20 :     ::osl::MutexGuard                       aGuard( m_aMutex );
     219          20 :     utl::AccessibleStateSetHelper*          pStateSetHelper = new utl::AccessibleStateSetHelper;
     220             : 
     221          20 :     if( IsAlive() )
     222             :     {
     223          20 :         pStateSetHelper->AddState( AccessibleStateType::ENABLED );
     224             : 
     225          20 :         if( isShowing() )
     226          20 :             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
     227             : 
     228          20 :         if( isVisible() )
     229          20 :             pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
     230             : 
     231             : 
     232          20 :         if ( mpRepr )
     233             :         {
     234          20 :             if ( mpRepr->GetStyle() & WB_HORZ )
     235          10 :                 pStateSetHelper->AddState( AccessibleStateType::HORIZONTAL );
     236             :             else
     237          10 :                 pStateSetHelper->AddState( AccessibleStateType::VERTICAL );
     238             :         }
     239          20 :         if(pStateSetHelper->contains(AccessibleStateType::FOCUSABLE))
     240             :         {
     241           0 :             pStateSetHelper->RemoveState( AccessibleStateType::FOCUSABLE );
     242             :         }
     243             : 
     244             :     }
     245             : 
     246             : 
     247          20 :     return pStateSetHelper;
     248             : }
     249             : 
     250           0 : lang::Locale SAL_CALL SvtRulerAccessible::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException, std::exception )
     251             : {
     252           0 :     ::osl::MutexGuard                           aGuard( m_aMutex );
     253           0 :     if( mxParent.is() )
     254             :     {
     255           0 :         uno::Reference< XAccessibleContext >    xParentContext( mxParent->getAccessibleContext() );
     256           0 :         if( xParentContext.is() )
     257           0 :             return xParentContext->getLocale();
     258             :     }
     259             : 
     260             :     //  No parent.  Therefore throw exception to indicate this cluelessness.
     261           0 :     throw IllegalAccessibleComponentStateException();
     262             : }
     263             : 
     264           0 : void SAL_CALL SvtRulerAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
     265             :     throw( RuntimeException, std::exception )
     266             : {
     267           0 :     if (xListener.is())
     268             :     {
     269           0 :         ::osl::MutexGuard   aGuard( m_aMutex );
     270           0 :         if (!mnClientId)
     271           0 :             mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
     272           0 :         comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
     273             :     }
     274           0 : }
     275             : 
     276           0 : void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
     277             :     throw( RuntimeException, std::exception )
     278             : {
     279           0 :     if (xListener.is())
     280             :     {
     281           0 :         ::osl::MutexGuard   aGuard( m_aMutex );
     282             : 
     283           0 :         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
     284           0 :         if ( !nListenerCount )
     285             :         {
     286             :             // no listeners anymore
     287             :             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
     288             :             // and at least to us not firing any events anymore, in case somebody calls
     289             :             // NotifyAccessibleEvent, again
     290           0 :             comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
     291           0 :             mnClientId = 0;
     292           0 :         }
     293             :     }
     294           0 : }
     295             : 
     296           0 : void SAL_CALL SvtRulerAccessible::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
     297             :     throw( RuntimeException )
     298             : {
     299           0 :     if( xListener.is() )
     300             :     {
     301           0 :         ::osl::MutexGuard   aGuard( m_aMutex );
     302             : 
     303           0 :         ThrowExceptionIfNotAlive();
     304             : 
     305           0 :         uno::Reference< awt::XWindow >  xWindow = VCLUnoHelper::GetInterface( mpRepr );
     306           0 :         if( xWindow.is() )
     307           0 :             xWindow->addFocusListener( xListener );
     308             :     }
     309           0 : }
     310             : 
     311           0 : void SAL_CALL SvtRulerAccessible::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
     312             :     throw (RuntimeException)
     313             : {
     314           0 :     if( xListener.is() )
     315             :     {
     316           0 :         ::osl::MutexGuard   aGuard( m_aMutex );
     317             : 
     318           0 :         ThrowExceptionIfNotAlive();
     319             : 
     320           0 :         uno::Reference< awt::XWindow >  xWindow = VCLUnoHelper::GetInterface( mpRepr );
     321           0 :         if( xWindow.is() )
     322           0 :             xWindow->removeFocusListener( xListener );
     323             :     }
     324           0 : }
     325             : 
     326           0 : void SAL_CALL SvtRulerAccessible::grabFocus() throw( RuntimeException, std::exception )
     327             : {
     328           0 :     SolarMutexGuard     aSolarGuard;
     329           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     330             : 
     331           0 :     ThrowExceptionIfNotAlive();
     332             : 
     333           0 :     mpRepr->GrabFocus();
     334           0 : }
     335             : 
     336           0 : Any SAL_CALL SvtRulerAccessible::getAccessibleKeyBinding() throw( RuntimeException )
     337             : {
     338             :     // here is no implementation, because here are no KeyBindings for every object
     339           0 :     return Any();
     340             : }
     341             : 
     342           0 : sal_Int32 SvtRulerAccessible::getForeground(  )
     343             :         throw (::com::sun::star::uno::RuntimeException, std::exception)
     344             : {
     345           0 :     SolarMutexGuard     aSolarGuard;
     346           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     347           0 :     ThrowExceptionIfNotAlive();
     348             : 
     349           0 :     return mpRepr->GetControlForeground().GetColor();
     350             : }
     351           0 : sal_Int32 SvtRulerAccessible::getBackground(  )
     352             :         throw (::com::sun::star::uno::RuntimeException, std::exception)
     353             : {
     354           0 :     SolarMutexGuard     aSolarGuard;
     355           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     356           0 :     ThrowExceptionIfNotAlive();
     357             : 
     358           0 :     return mpRepr->GetControlBackground().GetColor();
     359             : }
     360             : 
     361             : //=====  XServiceInfo  ========================================================
     362           0 : OUString SAL_CALL SvtRulerAccessible::getImplementationName( void ) throw( RuntimeException, std::exception )
     363             : {
     364           0 :     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.SvtRulerAccessible" ) );
     365             : }
     366             : 
     367           0 : sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
     368             : {
     369           0 :     return cppu::supportsService( this, sServiceName );
     370             : }
     371             : 
     372           0 : Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames( void ) throw( RuntimeException, std::exception )
     373             : {
     374           0 :     const OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
     375           0 :     return Sequence< OUString >( &sServiceName, 1 );
     376             : }
     377             : 
     378             : //=====  XTypeProvider  =======================================================
     379           0 : Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId( void ) throw( RuntimeException, std::exception )
     380             : {
     381           0 :     return css::uno::Sequence<sal_Int8>();
     382             : }
     383             : 
     384          20 : void SAL_CALL SvtRulerAccessible::disposing()
     385             : {
     386          20 :     if( !rBHelper.bDisposed )
     387             :     {
     388             :         {
     389          20 :             ::osl::MutexGuard   aGuard( m_aMutex );
     390          20 :             mpRepr = NULL;      // object dies with representation
     391             : 
     392             :         }
     393             : 
     394             :         {
     395          20 :             ::osl::MutexGuard   aGuard( m_aMutex );
     396             : 
     397             :             // Send a disposing to all listeners.
     398          20 :             if ( mnClientId )
     399             :             {
     400           0 :                 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
     401           0 :                 mnClientId =  0;
     402             :             }
     403          20 :             mxParent = uno::Reference< XAccessible >();
     404             :         }
     405             :     }
     406          20 : }
     407             : 
     408           0 : Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
     409             : {
     410           0 :     SolarMutexGuard     aSolarGuard;
     411           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     412             : 
     413           0 :     ThrowExceptionIfNotAlive();
     414           0 :     return Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
     415             : }
     416             : 
     417           0 : Rectangle SvtRulerAccessible::GetBoundingBox( void ) throw( RuntimeException )
     418             : {
     419           0 :     SolarMutexGuard     aSolarGuard;
     420           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     421             : 
     422           0 :     ThrowExceptionIfNotAlive();
     423             : 
     424           0 :     return Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
     425             : }
     426             : 
     427          60 : void SvtRulerAccessible::ThrowExceptionIfNotAlive( void ) throw( lang::DisposedException )
     428             : {
     429          60 :     if( IsNotAlive() )
     430           0 :         throw lang::DisposedException();
     431        1287 : }
     432             : 
     433             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10