LCOV - code coverage report
Current view: top level - accessibility/source/extended - AccessibleToolPanelDeckTabBarItem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 152 0.7 %
Date: 2014-11-03 Functions: 2 43 4.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             : 
      20             : #include "accessibility/extended/AccessibleToolPanelDeckTabBarItem.hxx"
      21             : 
      22             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      23             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      24             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      25             : #include <com/sun/star/lang/DisposedException.hpp>
      26             : 
      27             : #include <svtools/toolpanel/toolpaneldeck.hxx>
      28             : #include <svtools/toolpanel/paneltabbar.hxx>
      29             : #include <unotools/accessiblestatesethelper.hxx>
      30             : #include <unotools/accessiblerelationsethelper.hxx>
      31             : #include <toolkit/helper/externallock.hxx>
      32             : #include <tools/diagnose_ex.h>
      33             : #include <vcl/svapp.hxx>
      34             : #include <osl/mutex.hxx>
      35             : 
      36             : namespace accessibility
      37             : {
      38             :     typedef ::com::sun::star::awt::Rectangle    UnoRectangle;
      39             :     typedef ::com::sun::star::awt::Point        UnoPoint;
      40             : 
      41             :     using ::com::sun::star::uno::Reference;
      42             :     using ::com::sun::star::uno::XInterface;
      43             :     using ::com::sun::star::uno::UNO_QUERY;
      44             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      45             :     using ::com::sun::star::uno::UNO_SET_THROW;
      46             :     using ::com::sun::star::uno::Exception;
      47             :     using ::com::sun::star::uno::RuntimeException;
      48             :     using ::com::sun::star::uno::Any;
      49             :     using ::com::sun::star::uno::makeAny;
      50             :     using ::com::sun::star::uno::Sequence;
      51             :     using ::com::sun::star::uno::Type;
      52             :     using ::com::sun::star::accessibility::XAccessible;
      53             :     using ::com::sun::star::lang::DisposedException;
      54             :     using ::com::sun::star::lang::IndexOutOfBoundsException;
      55             :     using ::com::sun::star::accessibility::XAccessibleRelationSet;
      56             :     using ::com::sun::star::accessibility::XAccessibleStateSet;
      57             :     using ::com::sun::star::accessibility::XAccessibleComponent;
      58             :     using ::com::sun::star::accessibility::XAccessibleExtendedComponent;
      59             :     using ::com::sun::star::awt::XFont;
      60             : 
      61             :     namespace AccessibleRole = ::com::sun::star::accessibility::AccessibleRole;
      62             :     namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType;
      63             :     namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
      64             : 
      65             :     // AccessibleToolPanelDeckTabBarItem_Impl
      66             :     class AccessibleToolPanelDeckTabBarItem_Impl : public ::svt::IToolPanelDeckListener
      67             :     {
      68             :     public:
      69             :         AccessibleToolPanelDeckTabBarItem_Impl(
      70             :             AccessibleToolPanelDeckTabBarItem& i_rAntiImpl,
      71             :             const Reference< XAccessible >& i_rAccessibleParent,
      72             :             ::svt::IToolPanelDeck& i_rPanelDeck,
      73             :             ::svt::PanelTabBar& i_rTabBar,
      74             :             const size_t i_nItemPos
      75             :         );
      76             :         virtual ~AccessibleToolPanelDeckTabBarItem_Impl();
      77             : 
      78           0 :         ::svt::PanelTabBar* getTabBar() const { return m_pTabBar; }
      79             : 
      80             :         // IToolPanelDeckListener
      81             :         virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition ) SAL_OVERRIDE;
      82             :         virtual void PanelRemoved( const size_t i_nPosition ) SAL_OVERRIDE;
      83             :         virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive ) SAL_OVERRIDE;
      84             :         virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter ) SAL_OVERRIDE;
      85             :         virtual void Dying() SAL_OVERRIDE;
      86             : 
      87             :     public:
      88           0 :         bool    isDisposed() const { return m_pPanelDeck == NULL; }
      89             :         void    checkDisposed() const;
      90             :         void    dispose();
      91             : 
      92             :         const Reference< XAccessible >&
      93           0 :                 getAccessibleParent() const { return m_xAccessibleParent; }
      94           0 :         size_t  getItemPos() const { return m_nItemPos; }
      95             : 
      96             :         Reference< XAccessibleComponent >   getParentAccessibleComponent() const;
      97           0 :         ::svt::IToolPanelDeck*              getPanelDeck() const { return m_pPanelDeck; }
      98             :         OUString                            getPanelDisplayName();
      99             : 
     100             :     private:
     101             :         void impl_notifyBoundRectChanges();
     102             :         void impl_notifyStateChange( const sal_Int16 i_nLostState, const sal_Int16 i_nGainedState );
     103             : 
     104             :     private:
     105             :         AccessibleToolPanelDeckTabBarItem&  m_rAntiImpl;
     106             :         Reference< XAccessible >            m_xAccessibleParent;
     107             :         ::svt::IToolPanelDeck*              m_pPanelDeck;
     108             :         ::svt::PanelTabBar*                 m_pTabBar;
     109             :         size_t                              m_nItemPos;
     110             :     };
     111             : 
     112             :     // AccessibleToolPanelDeckTabBarItem_Impl
     113           0 :     AccessibleToolPanelDeckTabBarItem_Impl::AccessibleToolPanelDeckTabBarItem_Impl( AccessibleToolPanelDeckTabBarItem& i_rAntiImpl,
     114             :             const Reference< XAccessible >& i_rAccessibleParent, ::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar,
     115             :             const size_t i_nItemPos )
     116             :         :m_rAntiImpl( i_rAntiImpl )
     117             :         ,m_xAccessibleParent( i_rAccessibleParent )
     118             :         ,m_pPanelDeck( &i_rPanelDeck )
     119             :         ,m_pTabBar( &i_rTabBar )
     120           0 :         ,m_nItemPos( i_nItemPos )
     121             :     {
     122           0 :         m_pPanelDeck->AddListener( *this );
     123           0 :     }
     124             : 
     125           0 :     AccessibleToolPanelDeckTabBarItem_Impl::~AccessibleToolPanelDeckTabBarItem_Impl()
     126             :     {
     127           0 :     }
     128             : 
     129           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::checkDisposed() const
     130             :     {
     131           0 :         if ( isDisposed() )
     132           0 :             throw DisposedException( OUString(), *&m_rAntiImpl );
     133           0 :     }
     134             : 
     135           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::dispose()
     136             :     {
     137           0 :         ENSURE_OR_RETURN_VOID( !isDisposed(), "AccessibleToolPanelDeckTabBarItem_Impl::dispose: disposed twice!" );
     138             : 
     139           0 :         m_xAccessibleParent.clear();
     140           0 :         m_pPanelDeck->RemoveListener( *this );
     141           0 :         m_pPanelDeck = NULL;
     142           0 :         m_pTabBar = NULL;
     143             :     }
     144             : 
     145           0 :     Reference< XAccessibleComponent > AccessibleToolPanelDeckTabBarItem_Impl::getParentAccessibleComponent() const
     146             :     {
     147           0 :         Reference< XAccessible > xAccessibleParent( m_rAntiImpl.getAccessibleParent(), UNO_QUERY_THROW );
     148           0 :         return Reference< XAccessibleComponent >( xAccessibleParent->getAccessibleContext(), UNO_QUERY );
     149             :     }
     150             : 
     151           0 :     OUString AccessibleToolPanelDeckTabBarItem_Impl::getPanelDisplayName()
     152             :     {
     153           0 :         const ::svt::PToolPanel pPanel( m_pPanelDeck->GetPanel( getItemPos() ) );
     154           0 :         if ( pPanel.get() == NULL )
     155           0 :             throw DisposedException();
     156           0 :         return pPanel->GetDisplayName();
     157             :     }
     158             : 
     159           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::impl_notifyBoundRectChanges()
     160             :     {
     161           0 :         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
     162           0 :     }
     163             : 
     164           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::impl_notifyStateChange( const sal_Int16 i_nLostState, const sal_Int16 i_nGainedState )
     165             :     {
     166             :         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED,
     167           0 :             i_nLostState > -1 ? makeAny( i_nLostState ) : Any(),
     168           0 :             i_nGainedState > -1 ? makeAny( i_nGainedState ) : Any()
     169           0 :         );
     170           0 :     }
     171             : 
     172           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
     173             :     {
     174             :         (void)i_pPanel;
     175           0 :         if ( i_nPosition <= m_nItemPos )
     176           0 :             ++m_nItemPos;
     177           0 :         impl_notifyBoundRectChanges();
     178           0 :     }
     179             : 
     180           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::PanelRemoved( const size_t i_nPosition )
     181             :     {
     182           0 :         if ( i_nPosition == m_nItemPos )
     183             :         {
     184           0 :             m_rAntiImpl.dispose();
     185             :         }
     186           0 :         else if ( i_nPosition < m_nItemPos )
     187             :         {
     188           0 :             --m_nItemPos;
     189           0 :             impl_notifyBoundRectChanges();
     190             :         }
     191           0 :     }
     192             : 
     193           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
     194             :     {
     195           0 :         if ( m_nItemPos == i_rOldActive )
     196             :         {
     197           0 :             impl_notifyStateChange( AccessibleStateType::ACTIVE, -1 );
     198           0 :             impl_notifyStateChange( AccessibleStateType::SELECTED, -1 );
     199             :         }
     200           0 :         else if ( m_nItemPos == i_rNewActive )
     201             :         {
     202           0 :             impl_notifyStateChange( -1, AccessibleStateType::ACTIVE );
     203           0 :             impl_notifyStateChange( -1, AccessibleStateType::SELECTED );
     204             :         }
     205           0 :     }
     206             : 
     207           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
     208             :     {
     209             :         (void)i_rNewLayouter;
     210             :         // if the tool panel deck has a new layouter, then the old layouter, and thus all items it was
     211             :         // responsible for, died. So do we.
     212           0 :         dispose();
     213           0 :     }
     214             : 
     215           0 :     void AccessibleToolPanelDeckTabBarItem_Impl::Dying()
     216             :     {
     217             :         // if the tool panel deck is dying, then its layouter dies, so should we.
     218           0 :         dispose();
     219           0 :     }
     220             : 
     221             :     class ItemMethodGuard
     222             :     {
     223             :     public:
     224           0 :         ItemMethodGuard( AccessibleToolPanelDeckTabBarItem_Impl& i_rImpl )
     225           0 :             :m_aGuard()
     226             :         {
     227           0 :             i_rImpl.checkDisposed();
     228           0 :         }
     229           0 :         ~ItemMethodGuard()
     230           0 :         {
     231           0 :         }
     232             : 
     233             :     private:
     234             :         SolarMutexGuard  m_aGuard;
     235             :     };
     236             : 
     237           0 :     AccessibleToolPanelDeckTabBarItem::AccessibleToolPanelDeckTabBarItem( const Reference< XAccessible >& i_rAccessibleParent,
     238             :             ::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar, const size_t i_nItemPos )
     239             :         : ::comphelper::OAccessibleExtendedComponentHelper(
     240           0 :                 new VCLExternalSolarLock)
     241             :         , m_pImpl(new AccessibleToolPanelDeckTabBarItem_Impl(*this,
     242           0 :                 i_rAccessibleParent, i_rPanelDeck, i_rTabBar, i_nItemPos))
     243             :     {
     244           0 :     }
     245             : 
     246           0 :     AccessibleToolPanelDeckTabBarItem::~AccessibleToolPanelDeckTabBarItem()
     247             :     {
     248           0 :     }
     249             : 
     250           0 :     sal_Int32 SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleChildCount(  ) throw (RuntimeException, std::exception)
     251             :     {
     252           0 :         return 0;
     253             :     }
     254             : 
     255           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     256             :     {
     257             :         (void)i;
     258           0 :         throw IndexOutOfBoundsException( OUString(), *this );
     259             :     }
     260             : 
     261           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleParent(  ) throw (RuntimeException, std::exception)
     262             :     {
     263           0 :         ItemMethodGuard aGuard( *m_pImpl );
     264           0 :         return m_pImpl->getAccessibleParent();
     265             :     }
     266             : 
     267           0 :     sal_Int16 SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleRole(  ) throw (RuntimeException, std::exception)
     268             :     {
     269           0 :         return AccessibleRole::PAGE_TAB;
     270             :     }
     271             : 
     272           0 :     OUString SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleDescription(  ) throw (RuntimeException, std::exception)
     273             :     {
     274           0 :         ItemMethodGuard aGuard( *m_pImpl );
     275           0 :         return m_pImpl->getPanelDisplayName();
     276             :     }
     277             : 
     278           0 :     OUString SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleName(  ) throw (RuntimeException, std::exception)
     279             :     {
     280           0 :         ItemMethodGuard aGuard( *m_pImpl );
     281           0 :         return m_pImpl->getPanelDisplayName();
     282             :     }
     283             : 
     284           0 :     Reference< XAccessibleRelationSet > SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleRelationSet(  ) throw (RuntimeException, std::exception)
     285             :     {
     286           0 :         ItemMethodGuard aGuard( *m_pImpl );
     287           0 :         ::utl::AccessibleRelationSetHelper* pRelationSet = new utl::AccessibleRelationSetHelper;
     288           0 :         return pRelationSet;
     289             :     }
     290             : 
     291           0 :     Reference< XAccessibleStateSet > SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleStateSet(  ) throw (RuntimeException, std::exception)
     292             :     {
     293           0 :         ItemMethodGuard aGuard( *m_pImpl );
     294             : 
     295           0 :         ::utl::AccessibleStateSetHelper* pStateSet( new ::utl::AccessibleStateSetHelper );
     296           0 :         pStateSet->AddState( AccessibleStateType::FOCUSABLE );
     297           0 :         pStateSet->AddState( AccessibleStateType::SELECTABLE );
     298           0 :         pStateSet->AddState( AccessibleStateType::ICONIFIED );
     299             : 
     300           0 :         if ( m_pImpl->getItemPos() == m_pImpl->getPanelDeck()->GetActivePanel() )
     301             :         {
     302           0 :             pStateSet->AddState( AccessibleStateType::ACTIVE );
     303           0 :             pStateSet->AddState( AccessibleStateType::SELECTED );
     304             :         }
     305             : 
     306           0 :         if ( m_pImpl->getItemPos() == m_pImpl->getTabBar()->GetFocusedPanelItem() )
     307           0 :             pStateSet->AddState( AccessibleStateType::FOCUSED );
     308             : 
     309           0 :         if ( m_pImpl->getTabBar()->IsEnabled() )
     310           0 :             pStateSet->AddState( AccessibleStateType::ENABLED );
     311             : 
     312           0 :         if ( m_pImpl->getTabBar()->IsVisible() )
     313             :         {
     314           0 :             pStateSet->AddState( AccessibleStateType::SHOWING );
     315           0 :             pStateSet->AddState( AccessibleStateType::VISIBLE );
     316             :         }
     317             : 
     318           0 :         return pStateSet;
     319             :     }
     320             : 
     321           0 :     Reference< XAccessible > SAL_CALL AccessibleToolPanelDeckTabBarItem::getAccessibleAtPoint( const UnoPoint& i_rLocation ) throw (RuntimeException, std::exception)
     322             :     {
     323           0 :         ItemMethodGuard aGuard( *m_pImpl );
     324             :         // we do not have children ...
     325             :         (void)i_rLocation;
     326           0 :         return NULL;
     327             :     }
     328             : 
     329           0 :     void SAL_CALL AccessibleToolPanelDeckTabBarItem::grabFocus(  ) throw (RuntimeException, std::exception)
     330             :     {
     331           0 :         ItemMethodGuard aGuard( *m_pImpl );
     332           0 :         m_pImpl->getTabBar()->FocusPanelItem( m_pImpl->getItemPos() );
     333           0 :     }
     334             : 
     335           0 :     ::sal_Int32 SAL_CALL AccessibleToolPanelDeckTabBarItem::getForeground(  ) throw (RuntimeException, std::exception)
     336             :     {
     337           0 :         ItemMethodGuard aGuard( *m_pImpl );
     338           0 :         Reference< XAccessibleComponent > xParentComponent( m_pImpl->getParentAccessibleComponent(), UNO_SET_THROW );
     339           0 :         return xParentComponent->getForeground();
     340             :     }
     341             : 
     342           0 :     ::sal_Int32 SAL_CALL AccessibleToolPanelDeckTabBarItem::getBackground(  ) throw (RuntimeException, std::exception)
     343             :     {
     344           0 :         ItemMethodGuard aGuard( *m_pImpl );
     345           0 :         Reference< XAccessibleComponent > xParentComponent( m_pImpl->getParentAccessibleComponent(), UNO_SET_THROW );
     346           0 :         return xParentComponent->getBackground();
     347             :     }
     348             : 
     349           0 :     Reference< XFont > SAL_CALL AccessibleToolPanelDeckTabBarItem::getFont(  ) throw (RuntimeException, std::exception)
     350             :     {
     351           0 :         ItemMethodGuard aGuard( *m_pImpl );
     352           0 :         Reference< XAccessibleExtendedComponent > xParentComponent( m_pImpl->getParentAccessibleComponent(), UNO_QUERY_THROW );
     353             :         // TODO: strictly, this is not correct: The TabBar implementation of the TabLayouter might use
     354             :         // a different font ...
     355           0 :         return xParentComponent->getFont();
     356             :     }
     357             : 
     358           0 :     OUString SAL_CALL AccessibleToolPanelDeckTabBarItem::getTitledBorderText(  ) throw (RuntimeException, std::exception)
     359             :     {
     360           0 :         ItemMethodGuard aGuard( *m_pImpl );
     361             :         // no support
     362           0 :         return OUString();
     363             :     }
     364             : 
     365           0 :     OUString SAL_CALL AccessibleToolPanelDeckTabBarItem::getToolTipText(  ) throw (RuntimeException, std::exception)
     366             :     {
     367           0 :         ItemMethodGuard aGuard( *m_pImpl );
     368           0 :         return m_pImpl->getPanelDisplayName();
     369             :     }
     370             : 
     371           0 :     UnoRectangle AccessibleToolPanelDeckTabBarItem::implGetBounds() throw (RuntimeException)
     372             :     {
     373           0 :         ItemMethodGuard aGuard( *m_pImpl );
     374             : 
     375           0 :         const ::Rectangle aItemScreenRect( m_pImpl->getTabBar()->GetItemScreenRect( m_pImpl->getItemPos() ) );
     376             : 
     377           0 :         Reference< XAccessibleComponent > xParentComponent( m_pImpl->getParentAccessibleComponent(), UNO_SET_THROW );
     378           0 :         const UnoPoint aParentLocation( xParentComponent->getLocationOnScreen() );
     379             :         return UnoRectangle(
     380           0 :             aItemScreenRect.Left() - aParentLocation.X,
     381           0 :             aItemScreenRect.Top() - aParentLocation.Y,
     382           0 :             aItemScreenRect.GetWidth(),
     383           0 :             aItemScreenRect.GetHeight()
     384           0 :         );
     385             :     }
     386             : 
     387           0 :     void SAL_CALL AccessibleToolPanelDeckTabBarItem::disposing()
     388             :     {
     389           0 :         ItemMethodGuard aGuard( *m_pImpl );
     390           0 :         m_pImpl->dispose();
     391           0 :     }
     392          60 : } // namespace accessibility
     393             : 
     394             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10