LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - vclxaccessiblestatusbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 150 0.0 %
Date: 2012-12-27 Functions: 0 15 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/standard/vclxaccessiblestatusbar.hxx>
      21             : #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
      22             : #include <toolkit/helper/convert.hxx>
      23             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      24             : #include <vcl/status.hxx>
      25             : 
      26             : 
      27             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star::lang;
      30             : using namespace ::com::sun::star::accessibility;
      31             : using namespace ::comphelper;
      32             : 
      33             : 
      34             : //  ----------------------------------------------------
      35             : //  class VCLXAccessibleStatusBar
      36             : //  ----------------------------------------------------
      37             : 
      38           0 : VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow* pVCLXWindow )
      39           0 :     :VCLXAccessibleComponent( pVCLXWindow )
      40             : {
      41           0 :     m_pStatusBar = static_cast< StatusBar* >( GetWindow() );
      42             : 
      43           0 :     if ( m_pStatusBar )
      44           0 :         m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), Reference< XAccessible >() );
      45           0 : }
      46             : 
      47             : // -----------------------------------------------------------------------------
      48             : 
      49           0 : VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
      50             : {
      51           0 : }
      52             : 
      53             : // -----------------------------------------------------------------------------
      54             : 
      55           0 : void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, sal_Bool bShowing )
      56             : {
      57           0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
      58             :     {
      59           0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
      60           0 :         if ( xChild.is() )
      61             :         {
      62           0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
      63           0 :             if ( pVCLXAccessibleStatusBarItem )
      64           0 :                 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
      65           0 :         }
      66             :     }
      67           0 : }
      68             : 
      69             : // -----------------------------------------------------------------------------
      70             : 
      71           0 : void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
      72             : {
      73           0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
      74             :     {
      75           0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
      76           0 :         if ( xChild.is() )
      77             :         {
      78           0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
      79           0 :             if ( pVCLXAccessibleStatusBarItem )
      80             :             {
      81           0 :                 OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
      82           0 :                 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
      83             :             }
      84           0 :         }
      85             :     }
      86           0 : }
      87             : 
      88             : // -----------------------------------------------------------------------------
      89             : 
      90           0 : void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
      91             : {
      92           0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
      93             :     {
      94           0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
      95           0 :         if ( xChild.is() )
      96             :         {
      97           0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
      98           0 :             if ( pVCLXAccessibleStatusBarItem )
      99             :             {
     100           0 :                 OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
     101           0 :                 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
     102             :             }
     103           0 :         }
     104             :     }
     105           0 : }
     106             : 
     107             : // -----------------------------------------------------------------------------
     108             : 
     109           0 : void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
     110             : {
     111           0 :     if ( i >= 0 && i <= (sal_Int32)m_aAccessibleChildren.size() )
     112             :     {
     113             :         // insert entry in child list
     114           0 :         m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
     115             : 
     116             :         // send accessible child event
     117           0 :         Reference< XAccessible > xChild( getAccessibleChild( i ) );
     118           0 :         if ( xChild.is() )
     119             :         {
     120           0 :             Any aOldValue, aNewValue;
     121           0 :             aNewValue <<= xChild;
     122           0 :             NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
     123           0 :         }
     124             :     }
     125           0 : }
     126             : 
     127             : // -----------------------------------------------------------------------------
     128             : 
     129           0 : void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
     130             : {
     131           0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
     132             :     {
     133             :         // get the accessible of the removed page
     134           0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
     135             : 
     136             :         // remove entry in child list
     137           0 :         m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
     138             : 
     139             :         // send accessible child event
     140           0 :         if ( xChild.is() )
     141             :         {
     142           0 :             Any aOldValue, aNewValue;
     143           0 :             aOldValue <<= xChild;
     144           0 :             NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
     145             : 
     146           0 :             Reference< XComponent > xComponent( xChild, UNO_QUERY );
     147           0 :             if ( xComponent.is() )
     148           0 :                 xComponent->dispose();
     149           0 :         }
     150             :     }
     151           0 : }
     152             : 
     153             : // -----------------------------------------------------------------------------
     154             : 
     155           0 : void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
     156             : {
     157           0 :     switch ( rVclWindowEvent.GetId() )
     158             :     {
     159             :         case VCLEVENT_STATUSBAR_ITEMADDED:
     160             :         {
     161           0 :             if ( m_pStatusBar )
     162             :             {
     163           0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     164           0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     165           0 :                 InsertChild( nItemPos );
     166             :             }
     167             :         }
     168           0 :         break;
     169             :         case VCLEVENT_STATUSBAR_ITEMREMOVED:
     170             :         {
     171           0 :             if ( m_pStatusBar )
     172             :             {
     173           0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     174           0 :                 for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
     175             :                 {
     176           0 :                     Reference< XAccessible > xChild( getAccessibleChild( i ) );
     177           0 :                     if ( xChild.is() )
     178             :                     {
     179           0 :                         VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
     180           0 :                         if ( pVCLXAccessibleStatusBarItem && pVCLXAccessibleStatusBarItem->GetItemId() == nItemId )
     181             :                         {
     182           0 :                             RemoveChild( i );
     183             :                             break;
     184             :                         }
     185             :                     }
     186           0 :                 }
     187             :             }
     188             :         }
     189           0 :         break;
     190             :         case VCLEVENT_STATUSBAR_ALLITEMSREMOVED:
     191             :         {
     192           0 :             for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
     193           0 :                 RemoveChild( i );
     194             :         }
     195           0 :         break;
     196             :         case VCLEVENT_STATUSBAR_SHOWITEM:
     197             :         case VCLEVENT_STATUSBAR_HIDEITEM:
     198             :         {
     199           0 :             if ( m_pStatusBar )
     200             :             {
     201           0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     202           0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     203           0 :                 UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWITEM );
     204             :             }
     205             :         }
     206           0 :         break;
     207             :         case VCLEVENT_STATUSBAR_SHOWALLITEMS:
     208             :         case VCLEVENT_STATUSBAR_HIDEALLITEMS:
     209             :         {
     210           0 :             for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     211           0 :                 UpdateShowing( i, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS );
     212             :         }
     213           0 :         break;
     214             :         case VCLEVENT_STATUSBAR_NAMECHANGED:
     215             :         {
     216           0 :             if ( m_pStatusBar )
     217             :             {
     218           0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     219           0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     220           0 :                 UpdateItemName( nItemPos );
     221             :             }
     222             :         }
     223           0 :         break;
     224             :         case VCLEVENT_STATUSBAR_DRAWITEM:
     225             :         {
     226           0 :             if ( m_pStatusBar )
     227             :             {
     228           0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     229           0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     230           0 :                 UpdateItemText( nItemPos );
     231             :             }
     232             :         }
     233           0 :         break;
     234             :         case VCLEVENT_OBJECT_DYING:
     235             :         {
     236           0 :             if ( m_pStatusBar )
     237             :             {
     238           0 :                 m_pStatusBar = NULL;
     239             : 
     240             :                 // dispose all children
     241           0 :                 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     242             :                 {
     243           0 :                     Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
     244           0 :                     if ( xComponent.is() )
     245           0 :                         xComponent->dispose();
     246           0 :                 }
     247           0 :                 m_aAccessibleChildren.clear();
     248             :             }
     249             : 
     250           0 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
     251             :         }
     252           0 :         break;
     253             :         default:
     254           0 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
     255             :    }
     256           0 : }
     257             : 
     258             : // -----------------------------------------------------------------------------
     259             : // XComponent
     260             : // -----------------------------------------------------------------------------
     261             : 
     262           0 : void VCLXAccessibleStatusBar::disposing()
     263             : {
     264           0 :     VCLXAccessibleComponent::disposing();
     265             : 
     266           0 :     if ( m_pStatusBar )
     267             :     {
     268           0 :         m_pStatusBar = NULL;
     269             : 
     270             :         // dispose all children
     271           0 :         for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     272             :         {
     273           0 :             Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
     274           0 :             if ( xComponent.is() )
     275           0 :                 xComponent->dispose();
     276           0 :         }
     277           0 :         m_aAccessibleChildren.clear();
     278             :     }
     279           0 : }
     280             : 
     281             : // -----------------------------------------------------------------------------
     282             : // XServiceInfo
     283             : // -----------------------------------------------------------------------------
     284             : 
     285           0 : OUString VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException)
     286             : {
     287           0 :     return OUString( "com.sun.star.comp.toolkit.AccessibleStatusBar" );
     288             : }
     289             : 
     290             : // -----------------------------------------------------------------------------
     291             : 
     292           0 : Sequence< OUString > VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException)
     293             : {
     294           0 :     Sequence< OUString > aNames(1);
     295           0 :     aNames[0] = OUString( "com.sun.star.awt.AccessibleStatusBar" );
     296           0 :     return aNames;
     297             : }
     298             : 
     299             : // -----------------------------------------------------------------------------
     300             : // XAccessibleContext
     301             : // -----------------------------------------------------------------------------
     302             : 
     303           0 : sal_Int32 VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException)
     304             : {
     305           0 :     OExternalLockGuard aGuard( this );
     306             : 
     307           0 :     return m_aAccessibleChildren.size();
     308             : }
     309             : 
     310             : // -----------------------------------------------------------------------------
     311             : 
     312           0 : Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
     313             : {
     314           0 :     OExternalLockGuard aGuard( this );
     315             : 
     316           0 :     if ( i < 0 || i >= getAccessibleChildCount() )
     317           0 :         throw IndexOutOfBoundsException();
     318             : 
     319           0 :     Reference< XAccessible > xChild = m_aAccessibleChildren[i];
     320           0 :     if ( !xChild.is() )
     321             :     {
     322           0 :         if ( m_pStatusBar )
     323             :         {
     324           0 :             sal_uInt16 nItemId = m_pStatusBar->GetItemId( (sal_uInt16)i );
     325             : 
     326           0 :             xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
     327             : 
     328             :             // insert into status bar item list
     329           0 :             m_aAccessibleChildren[i] = xChild;
     330             :         }
     331             :     }
     332             : 
     333           0 :     return xChild;
     334             : }
     335             : 
     336             : // -----------------------------------------------------------------------------
     337             : // XAccessibleComponent
     338             : // -----------------------------------------------------------------------------
     339             : 
     340           0 : Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
     341             : {
     342           0 :     OExternalLockGuard aGuard( this );
     343             : 
     344           0 :     Reference< XAccessible > xChild;
     345           0 :     if ( m_pStatusBar )
     346             :     {
     347           0 :         sal_uInt16 nItemId = m_pStatusBar->GetItemId( VCLPoint( rPoint ) );
     348           0 :         sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     349           0 :         if ( nItemPos >= 0 && nItemPos < (sal_Int32)m_aAccessibleChildren.size() )
     350           0 :             xChild = getAccessibleChild( nItemPos );
     351             :     }
     352             : 
     353           0 :     return xChild;
     354             : }
     355             : 
     356             : // -----------------------------------------------------------------------------
     357             : 
     358             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10