LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/extended - AccessibleToolPanelDeck.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-12-27 Functions: 0 27 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             : 
      21             : #include "accessibility/extended/AccessibleToolPanelDeck.hxx"
      22             : 
      23             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      24             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      25             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : 
      28             : #include <svtools/toolpanel/toolpaneldeck.hxx>
      29             : #include <toolkit/awt/vclxwindow.hxx>
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : #include <vcl/svapp.hxx>
      32             : #include <osl/mutex.hxx>
      33             : #include <unotools/accessiblestatesethelper.hxx>
      34             : #include <tools/diagnose_ex.h>
      35             : 
      36             : #include <boost/noncopyable.hpp>
      37             : 
      38             : //......................................................................................................................
      39             : namespace accessibility
      40             : {
      41             : //......................................................................................................................
      42             : 
      43             :     /** === begin UNO using === **/
      44             :     using ::com::sun::star::uno::Reference;
      45             :     using ::com::sun::star::uno::XInterface;
      46             :     using ::com::sun::star::uno::UNO_QUERY;
      47             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      48             :     using ::com::sun::star::uno::UNO_SET_THROW;
      49             :     using ::com::sun::star::uno::Exception;
      50             :     using ::com::sun::star::uno::RuntimeException;
      51             :     using ::com::sun::star::uno::Any;
      52             :     using ::com::sun::star::uno::makeAny;
      53             :     using ::com::sun::star::uno::Sequence;
      54             :     using ::com::sun::star::uno::Type;
      55             :     using ::com::sun::star::accessibility::XAccessible;
      56             :     using ::com::sun::star::accessibility::XAccessibleContext;
      57             :     using ::com::sun::star::lang::DisposedException;
      58             :     using ::com::sun::star::lang::IndexOutOfBoundsException;
      59             :     using ::com::sun::star::lang::Locale;
      60             :     using ::com::sun::star::accessibility::XAccessibleRelationSet;
      61             :     using ::com::sun::star::accessibility::XAccessibleStateSet;
      62             :     using ::com::sun::star::accessibility::IllegalAccessibleComponentStateException;
      63             :     using ::com::sun::star::awt::XFont;
      64             :     /** === end UNO using === **/
      65             :     namespace AccessibleRole = ::com::sun::star::accessibility::AccessibleRole;
      66             :     namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
      67             :     namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType;
      68             : 
      69             :     typedef ::com::sun::star::awt::Point        UnoPoint;
      70             : 
      71             :     //==================================================================================================================
      72             :     //= AccessibleToolPanelDeck_Impl - declaration
      73             :     //==================================================================================================================
      74             :     class AccessibleToolPanelDeck_Impl  :public ::boost::noncopyable
      75             :                                         ,public ::svt::IToolPanelDeckListener
      76             :     {
      77             :     public:
      78             :         AccessibleToolPanelDeck_Impl(
      79             :             AccessibleToolPanelDeck& i_rAntiImpl,
      80             :             const Reference< XAccessible >& i_rAccessibleParent,
      81             :             ::svt::ToolPanelDeck& i_rPanelDeck
      82             :         );
      83             : 
      84             :         void    checkDisposed();
      85           0 :         bool    isDisposed() const { return m_pPanelDeck == NULL; }
      86             :         void    dispose();
      87             : 
      88             :         virtual ~AccessibleToolPanelDeck_Impl();
      89             : 
      90             :         Reference< XAccessible >    getOwnAccessible() const;
      91             :         Reference< XAccessible >    getActivePanelAccessible();
      92             : 
      93             :     protected:
      94             :         // IToolPanelDeckListener
      95             :         virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition );
      96             :         virtual void PanelRemoved( const size_t i_nPosition );
      97             :         virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
      98             :         virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter );
      99             :         virtual void Dying();
     100             : 
     101             :     public:
     102             :         AccessibleToolPanelDeck&    m_rAntiImpl;
     103             :         Reference< XAccessible >    m_xAccessibleParent;
     104             :         ::svt::ToolPanelDeck*       m_pPanelDeck;
     105             : 
     106             :         Reference< XAccessible >        m_xActivePanelAccessible;
     107             :     };
     108             : 
     109             :     //==================================================================================================================
     110             :     //= MethodGuard
     111             :     //==================================================================================================================
     112             :     namespace
     113             :     {
     114             :         class MethodGuard
     115             :         {
     116             :         public:
     117           0 :             MethodGuard( AccessibleToolPanelDeck_Impl& i_rImpl )
     118           0 :                 :m_aGuard()
     119             :             {
     120           0 :                 i_rImpl.checkDisposed();
     121           0 :             }
     122           0 :             ~MethodGuard()
     123           0 :             {
     124           0 :             }
     125             : 
     126             :         private:
     127             :             SolarMutexGuard  m_aGuard;
     128             :         };
     129             :     }
     130             : 
     131             :     //==================================================================================================================
     132             :     //= AccessibleToolPanelDeck_Impl - implementation
     133             :     //==================================================================================================================
     134             :     //------------------------------------------------------------------------------------------------------------------
     135           0 :     AccessibleToolPanelDeck_Impl::AccessibleToolPanelDeck_Impl( AccessibleToolPanelDeck& i_rAntiImpl, const Reference< XAccessible >& i_rAccessibleParent,
     136             :             ::svt::ToolPanelDeck& i_rPanelDeck )
     137             :         :m_rAntiImpl( i_rAntiImpl )
     138             :         ,m_xAccessibleParent( i_rAccessibleParent )
     139             :         ,m_pPanelDeck( &i_rPanelDeck )
     140           0 :         ,m_xActivePanelAccessible()
     141             :     {
     142           0 :         m_pPanelDeck->AddListener( *this );
     143           0 :     }
     144             : 
     145             :     //------------------------------------------------------------------------------------------------------------------
     146           0 :     AccessibleToolPanelDeck_Impl::~AccessibleToolPanelDeck_Impl()
     147             :     {
     148           0 :         if ( !isDisposed() )
     149           0 :             dispose();
     150           0 :     }
     151             : 
     152             :     //------------------------------------------------------------------------------------------------------------------
     153           0 :     void AccessibleToolPanelDeck_Impl::dispose()
     154             :     {
     155           0 :         ENSURE_OR_RETURN_VOID( !isDisposed(), "disposed twice" );
     156           0 :         m_pPanelDeck->RemoveListener( *this );
     157           0 :         m_pPanelDeck = NULL;
     158           0 :         m_xAccessibleParent.clear();
     159             :     }
     160             : 
     161             :     //------------------------------------------------------------------------------------------------------------------
     162           0 :     void AccessibleToolPanelDeck_Impl::checkDisposed()
     163             :     {
     164           0 :         if ( isDisposed() )
     165           0 :             throw DisposedException( OUString(), *&m_rAntiImpl );
     166           0 :     }
     167             : 
     168             :     //------------------------------------------------------------------------------------------------------------------
     169           0 :     Reference< XAccessible > AccessibleToolPanelDeck_Impl::getOwnAccessible() const
     170             :     {
     171           0 :         Reference< XAccessible > xOwnAccessible( static_cast< XAccessible* >( m_rAntiImpl.GetVCLXWindow() ) );
     172             :         OSL_ENSURE( xOwnAccessible->getAccessibleContext() == Reference< XAccessibleContext >( &m_rAntiImpl ),
     173             :             "AccessibleToolPanelDeck_Impl::getOwnAccessible: could not retrieve proper XAccessible for /myself!" );
     174           0 :         return xOwnAccessible;
     175             :     }
     176             : 
     177             :     //------------------------------------------------------------------------------------------------------------------
     178           0 :     Reference< XAccessible > AccessibleToolPanelDeck_Impl::getActivePanelAccessible()
     179             :     {
     180           0 :         ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: already disposed!", NULL );
     181             : 
     182           0 :         if ( !m_xActivePanelAccessible.is() )
     183             :         {
     184           0 :             ::boost::optional< size_t > aActivePanel( m_pPanelDeck->GetActivePanel() );
     185           0 :             ENSURE_OR_RETURN( !!aActivePanel, "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: this should not be called without an active panel!", NULL );
     186           0 :             ::svt::PToolPanel pActivePanel( m_pPanelDeck->GetPanel( *aActivePanel ) );
     187           0 :             ENSURE_OR_RETURN( pActivePanel.get() != NULL, "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: no active panel!", NULL );
     188           0 :             m_xActivePanelAccessible = pActivePanel->CreatePanelAccessible( getOwnAccessible() );
     189           0 :             OSL_ENSURE( m_xActivePanelAccessible.is(), "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: illegal accessible returned by the panel!" );
     190             :         }
     191             : 
     192           0 :         return m_xActivePanelAccessible;
     193             :     }
     194             : 
     195             :     //------------------------------------------------------------------------------------------------------------------
     196           0 :     void AccessibleToolPanelDeck_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
     197             :     {
     198             :         (void)i_pPanel;
     199             :         (void)i_nPosition;
     200           0 :     }
     201             : 
     202             :     //------------------------------------------------------------------------------------------------------------------
     203           0 :     void AccessibleToolPanelDeck_Impl::PanelRemoved( const size_t i_nPosition )
     204             :     {
     205             :         (void)i_nPosition;
     206           0 :     }
     207             : 
     208             :     //------------------------------------------------------------------------------------------------------------------
     209           0 :     void AccessibleToolPanelDeck_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
     210             :     {
     211           0 :         if ( !!i_rOldActive )
     212             :         {
     213           0 :             if ( !m_xActivePanelAccessible.is() )
     214             :             {
     215             :                 // again, this might in theory happen if the XAccessible for the active panel has never before been requested.
     216             :                 // In this case, just say that all our children are invalid, so they all must be re-requested.
     217           0 :                 m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN, Any(), Any() );
     218             :             }
     219             :             else
     220             :             {
     221           0 :                 m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, makeAny( m_xActivePanelAccessible ), Any() );
     222             :             }
     223             :         }
     224             : 
     225           0 :         m_xActivePanelAccessible.clear();
     226             : 
     227           0 :         if ( !!i_rNewActive )
     228             :         {
     229           0 :             m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), makeAny( getActivePanelAccessible() ) );
     230             :         }
     231           0 :     }
     232             : 
     233             :     //------------------------------------------------------------------------------------------------------------------
     234           0 :     void AccessibleToolPanelDeck_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
     235             :     {
     236           0 :         MethodGuard aGuard( *this );
     237             : 
     238             :         (void)i_rNewLayouter;
     239           0 :         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN, Any(), Any() );
     240           0 :     }
     241             : 
     242             :     //------------------------------------------------------------------------------------------------------------------
     243           0 :     void AccessibleToolPanelDeck_Impl::Dying()
     244             :     {
     245             :         // the tool panel deck is dying, so dispose ourself
     246           0 :         m_rAntiImpl.dispose();
     247           0 :     }
     248             : 
     249             :     //==================================================================================================================
     250             :     //= AccessibleToolPanelDeck
     251             :     //==================================================================================================================
     252             :     //------------------------------------------------------------------------------------------------------------------
     253           0 :     AccessibleToolPanelDeck::AccessibleToolPanelDeck( const Reference< XAccessible >& i_rAccessibleParent,
     254             :             ::svt::ToolPanelDeck& i_rPanelDeck )
     255             :         :AccessibleToolPanelDeck_Base( i_rPanelDeck.GetWindowPeer() )
     256           0 :         ,m_pImpl( new AccessibleToolPanelDeck_Impl( *this, i_rAccessibleParent, i_rPanelDeck ) )
     257             :     {
     258           0 :     }
     259             : 
     260             :     //------------------------------------------------------------------------------------------------------------------
     261           0 :     AccessibleToolPanelDeck::~AccessibleToolPanelDeck()
     262             :     {
     263           0 :     }
     264             : 
     265             :     //------------------------------------------------------------------------------------------------------------------
     266           0 :     sal_Int32 SAL_CALL AccessibleToolPanelDeck::getAccessibleChildCount(  ) throw (RuntimeException)
     267             :     {
     268           0 :         MethodGuard aGuard( *m_pImpl );
     269             : 
     270           0 :         sal_Int32 nChildCount( m_pImpl->m_pPanelDeck->GetLayouter()->GetAccessibleChildCount() );
     271             : 
     272           0 :         ::boost::optional< size_t > aActivePanel( m_pImpl->m_pPanelDeck->GetActivePanel() );
     273           0 :         if ( !!aActivePanel )
     274           0 :             return ++nChildCount;
     275             : 
     276           0 :         return nChildCount;
     277             :     }
     278             : 
     279             :     //------------------------------------------------------------------------------------------------------------------
     280           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeck::getAccessibleChild( sal_Int32 i_nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     281             :     {
     282           0 :         MethodGuard aGuard( *m_pImpl );
     283             : 
     284           0 :         const sal_Int32 nChildCount( getAccessibleChildCount() );
     285           0 :         if ( ( i_nIndex < 0 ) || ( i_nIndex >= nChildCount ) )
     286           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     287             : 
     288             :         // first "n" children are provided by the layouter
     289           0 :         const size_t nLayouterCount( m_pImpl->m_pPanelDeck->GetLayouter()->GetAccessibleChildCount() );
     290           0 :         if ( size_t( i_nIndex ) < nLayouterCount )
     291           0 :             return m_pImpl->m_pPanelDeck->GetLayouter()->GetAccessibleChild(
     292             :                 size_t( i_nIndex ),
     293             :                 m_pImpl->getOwnAccessible()
     294           0 :             );
     295             : 
     296             :         // the last child is the XAccessible of the active panel
     297           0 :         return m_pImpl->getActivePanelAccessible();
     298             :     }
     299             : 
     300             :     //------------------------------------------------------------------------------------------------------------------
     301           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeck::getAccessibleParent(  ) throw (RuntimeException)
     302             :     {
     303           0 :         MethodGuard aGuard( *m_pImpl );
     304           0 :         const Reference< XAccessible > xParent = implGetForeignControlledParent();
     305           0 :         if ( xParent.is() )
     306           0 :             return xParent;
     307           0 :         return m_pImpl->m_xAccessibleParent;
     308             :     }
     309             : 
     310             :     //------------------------------------------------------------------------------------------------------------------
     311           0 :     sal_Int16 SAL_CALL AccessibleToolPanelDeck::getAccessibleRole(  ) throw (RuntimeException)
     312             :     {
     313           0 :         MethodGuard aGuard( *m_pImpl );
     314           0 :         return AccessibleRole::PANEL;
     315             :     }
     316             : 
     317             :     //------------------------------------------------------------------------------------------------------------------
     318           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeck::getAccessibleAtPoint( const UnoPoint& i_rPoint ) throw (RuntimeException)
     319             :     {
     320           0 :         MethodGuard aGuard( *m_pImpl );
     321             : 
     322           0 :         const ::Point aRequestedPoint( VCLUnoHelper::ConvertToVCLPoint( i_rPoint ) );
     323             :         // check the panel window itself
     324           0 :         const ::Window& rActivePanelAnchor( m_pImpl->m_pPanelDeck->GetPanelWindowAnchor() );
     325           0 :         const Rectangle aPanelAnchorArea( rActivePanelAnchor.GetPosPixel(), rActivePanelAnchor.GetOutputSizePixel() );
     326           0 :         if ( aPanelAnchorArea.IsInside( aRequestedPoint ) )
     327             :             // note that this assumes that the Window which actually implements the concrete panel covers
     328             :             // the complete area of its "anchor" Window. But this is ensured by the ToolPanelDeck implementation.
     329           0 :             return m_pImpl->getActivePanelAccessible();
     330             : 
     331             :         // check the XAccessible instances provided by the layouter
     332             :         try
     333             :         {
     334           0 :             const ::svt::PDeckLayouter pLayouter( m_pImpl->m_pPanelDeck->GetLayouter() );
     335           0 :             ENSURE_OR_THROW( pLayouter.get() != NULL, "invalid layouter" );
     336             : 
     337           0 :             const size_t nLayouterChildren = pLayouter->GetAccessibleChildCount();
     338           0 :             for ( size_t i=0; i<nLayouterChildren; ++i )
     339             :             {
     340           0 :                 const Reference< XAccessible > xLayoutItemAccessible( pLayouter->GetAccessibleChild( i, m_pImpl->getOwnAccessible() ), UNO_SET_THROW );
     341           0 :                 const Reference< XAccessibleComponent > xLayoutItemComponent( xLayoutItemAccessible->getAccessibleContext(), UNO_QUERY_THROW );
     342           0 :                 const ::Rectangle aLayoutItemBounds( VCLUnoHelper::ConvertToVCLRect( xLayoutItemComponent->getBounds() ) );
     343           0 :                 if ( aLayoutItemBounds.IsInside( aRequestedPoint ) )
     344           0 :                     return xLayoutItemAccessible;
     345           0 :             }
     346             :         }
     347           0 :         catch( const Exception& )
     348             :         {
     349             :             DBG_UNHANDLED_EXCEPTION();
     350             :         }
     351             : 
     352           0 :         return NULL;
     353             :     }
     354             : 
     355             :     //------------------------------------------------------------------------------------------------------------------
     356           0 :     void SAL_CALL AccessibleToolPanelDeck::grabFocus(  ) throw (RuntimeException)
     357             :     {
     358           0 :         MethodGuard aGuard( *m_pImpl );
     359           0 :         m_pImpl->m_pPanelDeck->GrabFocus();
     360           0 :     }
     361             : 
     362             :     //------------------------------------------------------------------------------------------------------------------
     363           0 :     void SAL_CALL AccessibleToolPanelDeck::disposing()
     364             :     {
     365           0 :         AccessibleToolPanelDeck_Base::disposing();
     366           0 :         m_pImpl->dispose();
     367           0 :     }
     368             : 
     369             :     //------------------------------------------------------------------------------------------------------------------
     370           0 :     Reference< XAccessible > AccessibleToolPanelDeck::GetChildAccessible( const VclWindowEvent& i_rVclWindowEvent )
     371             :     {
     372             :         // don't let the base class generate any A11Y events from VclWindowEvent, we completely manage those
     373             :         // A11Y events ourself
     374             :         (void)i_rVclWindowEvent;
     375           0 :         return NULL;
     376             :     }
     377             : 
     378             :     //------------------------------------------------------------------------------------------------------------------
     379           0 :     void AccessibleToolPanelDeck::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& i_rStateSet )
     380             :     {
     381           0 :         AccessibleToolPanelDeck_Base::FillAccessibleStateSet( i_rStateSet );
     382           0 :         if ( m_pImpl->isDisposed() )
     383             :         {
     384           0 :             i_rStateSet.AddState( AccessibleStateType::DEFUNC );
     385             :         }
     386             :         else
     387             :         {
     388           0 :             i_rStateSet.AddState( AccessibleStateType::FOCUSABLE );
     389             :         }
     390           0 :     }
     391             : 
     392             : //......................................................................................................................
     393             : } // namespace accessibility
     394             : //......................................................................................................................
     395             : 
     396             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10