LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessiblestatusbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 150 25.3 %
Date: 2012-08-25 Functions: 7 15 46.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 229 13.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <accessibility/standard/vclxaccessiblestatusbar.hxx>
      30                 :            : #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
      31                 :            : #include <toolkit/helper/convert.hxx>
      32                 :            : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      33                 :            : #include <vcl/status.hxx>
      34                 :            : 
      35                 :            : 
      36                 :            : using namespace ::com::sun::star;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::lang;
      39                 :            : using namespace ::com::sun::star::accessibility;
      40                 :            : using namespace ::comphelper;
      41                 :            : 
      42                 :            : 
      43                 :            : //  ----------------------------------------------------
      44                 :            : //  class VCLXAccessibleStatusBar
      45                 :            : //  ----------------------------------------------------
      46                 :            : 
      47                 :          2 : VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow* pVCLXWindow )
      48         [ +  - ]:          2 :     :VCLXAccessibleComponent( pVCLXWindow )
      49                 :            : {
      50         [ +  - ]:          2 :     m_pStatusBar = static_cast< StatusBar* >( GetWindow() );
      51                 :            : 
      52         [ +  - ]:          2 :     if ( m_pStatusBar )
      53 [ +  - ][ +  - ]:          2 :         m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), Reference< XAccessible >() );
      54                 :          2 : }
      55                 :            : 
      56                 :            : // -----------------------------------------------------------------------------
      57                 :            : 
      58                 :          2 : VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
      59                 :            : {
      60         [ -  + ]:          4 : }
      61                 :            : 
      62                 :            : // -----------------------------------------------------------------------------
      63                 :            : 
      64                 :          0 : void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, sal_Bool bShowing )
      65                 :            : {
      66 [ #  # ][ #  # ]:          0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
      67                 :            :     {
      68                 :          0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
      69         [ #  # ]:          0 :         if ( xChild.is() )
      70                 :            :         {
      71 [ #  # ][ #  # ]:          0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
      72         [ #  # ]:          0 :             if ( pVCLXAccessibleStatusBarItem )
      73         [ #  # ]:          0 :                 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
      74                 :          0 :         }
      75                 :            :     }
      76                 :          0 : }
      77                 :            : 
      78                 :            : // -----------------------------------------------------------------------------
      79                 :            : 
      80                 :          0 : void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
      81                 :            : {
      82 [ #  # ][ #  # ]:          0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
      83                 :            :     {
      84                 :          0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
      85         [ #  # ]:          0 :         if ( xChild.is() )
      86                 :            :         {
      87 [ #  # ][ #  # ]:          0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
      88         [ #  # ]:          0 :             if ( pVCLXAccessibleStatusBarItem )
      89                 :            :             {
      90         [ #  # ]:          0 :                 ::rtl::OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
      91         [ #  # ]:          0 :                 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
      92                 :            :             }
      93                 :          0 :         }
      94                 :            :     }
      95                 :          0 : }
      96                 :            : 
      97                 :            : // -----------------------------------------------------------------------------
      98                 :            : 
      99                 :          0 : void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
     100                 :            : {
     101 [ #  # ][ #  # ]:          0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
     102                 :            :     {
     103                 :          0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
     104         [ #  # ]:          0 :         if ( xChild.is() )
     105                 :            :         {
     106 [ #  # ][ #  # ]:          0 :             VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
     107         [ #  # ]:          0 :             if ( pVCLXAccessibleStatusBarItem )
     108                 :            :             {
     109         [ #  # ]:          0 :                 ::rtl::OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
     110         [ #  # ]:          0 :                 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
     111                 :            :             }
     112                 :          0 :         }
     113                 :            :     }
     114                 :          0 : }
     115                 :            : 
     116                 :            : // -----------------------------------------------------------------------------
     117                 :            : 
     118                 :          0 : void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
     119                 :            : {
     120 [ #  # ][ #  # ]:          0 :     if ( i >= 0 && i <= (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
     121                 :            :     {
     122                 :            :         // insert entry in child list
     123 [ #  # ][ #  # ]:          0 :         m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
     124                 :            : 
     125                 :            :         // send accessible child event
     126         [ #  # ]:          0 :         Reference< XAccessible > xChild( getAccessibleChild( i ) );
     127         [ #  # ]:          0 :         if ( xChild.is() )
     128                 :            :         {
     129                 :          0 :             Any aOldValue, aNewValue;
     130         [ #  # ]:          0 :             aNewValue <<= xChild;
     131         [ #  # ]:          0 :             NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
     132                 :          0 :         }
     133                 :            :     }
     134                 :          0 : }
     135                 :            : 
     136                 :            : // -----------------------------------------------------------------------------
     137                 :            : 
     138                 :          0 : void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
     139                 :            : {
     140 [ #  # ][ #  # ]:          0 :     if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
     141                 :            :     {
     142                 :            :         // get the accessible of the removed page
     143                 :          0 :         Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
     144                 :            : 
     145                 :            :         // remove entry in child list
     146 [ #  # ][ #  # ]:          0 :         m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
     147                 :            : 
     148                 :            :         // send accessible child event
     149         [ #  # ]:          0 :         if ( xChild.is() )
     150                 :            :         {
     151                 :          0 :             Any aOldValue, aNewValue;
     152         [ #  # ]:          0 :             aOldValue <<= xChild;
     153         [ #  # ]:          0 :             NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
     154                 :            : 
     155         [ #  # ]:          0 :             Reference< XComponent > xComponent( xChild, UNO_QUERY );
     156         [ #  # ]:          0 :             if ( xComponent.is() )
     157 [ #  # ][ #  # ]:          0 :                 xComponent->dispose();
     158                 :          0 :         }
     159                 :            :     }
     160                 :          0 : }
     161                 :            : 
     162                 :            : // -----------------------------------------------------------------------------
     163                 :            : 
     164                 :          2 : void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
     165                 :            : {
     166   [ -  -  -  -  :          2 :     switch ( rVclWindowEvent.GetId() )
             -  -  -  +  
                      - ]
     167                 :            :     {
     168                 :            :         case VCLEVENT_STATUSBAR_ITEMADDED:
     169                 :            :         {
     170         [ #  # ]:          0 :             if ( m_pStatusBar )
     171                 :            :             {
     172                 :          0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     173                 :          0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     174                 :          0 :                 InsertChild( nItemPos );
     175                 :            :             }
     176                 :            :         }
     177                 :          0 :         break;
     178                 :            :         case VCLEVENT_STATUSBAR_ITEMREMOVED:
     179                 :            :         {
     180         [ #  # ]:          0 :             if ( m_pStatusBar )
     181                 :            :             {
     182                 :          0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     183         [ #  # ]:          0 :                 for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
     184                 :            :                 {
     185         [ #  # ]:          0 :                     Reference< XAccessible > xChild( getAccessibleChild( i ) );
     186         [ #  # ]:          0 :                     if ( xChild.is() )
     187                 :            :                     {
     188 [ #  # ][ #  # ]:          0 :                         VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
     189 [ #  # ][ #  # ]:          0 :                         if ( pVCLXAccessibleStatusBarItem && pVCLXAccessibleStatusBarItem->GetItemId() == nItemId )
                 [ #  # ]
     190                 :            :                         {
     191         [ #  # ]:          0 :                             RemoveChild( i );
     192                 :            :                             break;
     193                 :            :                         }
     194                 :            :                     }
     195         [ #  # ]:          0 :                 }
     196                 :            :             }
     197                 :            :         }
     198                 :          0 :         break;
     199                 :            :         case VCLEVENT_STATUSBAR_ALLITEMSREMOVED:
     200                 :            :         {
     201         [ #  # ]:          0 :             for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
     202                 :          0 :                 RemoveChild( i );
     203                 :            :         }
     204                 :          0 :         break;
     205                 :            :         case VCLEVENT_STATUSBAR_SHOWITEM:
     206                 :            :         case VCLEVENT_STATUSBAR_HIDEITEM:
     207                 :            :         {
     208         [ #  # ]:          0 :             if ( m_pStatusBar )
     209                 :            :             {
     210                 :          0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     211                 :          0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     212                 :          0 :                 UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWITEM );
     213                 :            :             }
     214                 :            :         }
     215                 :          0 :         break;
     216                 :            :         case VCLEVENT_STATUSBAR_SHOWALLITEMS:
     217                 :            :         case VCLEVENT_STATUSBAR_HIDEALLITEMS:
     218                 :            :         {
     219         [ #  # ]:          0 :             for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     220                 :          0 :                 UpdateShowing( i, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS );
     221                 :            :         }
     222                 :          0 :         break;
     223                 :            :         case VCLEVENT_STATUSBAR_NAMECHANGED:
     224                 :            :         {
     225         [ #  # ]:          0 :             if ( m_pStatusBar )
     226                 :            :             {
     227                 :          0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     228                 :          0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     229                 :          0 :                 UpdateItemName( nItemPos );
     230                 :            :             }
     231                 :            :         }
     232                 :          0 :         break;
     233                 :            :         case VCLEVENT_STATUSBAR_DRAWITEM:
     234                 :            :         {
     235         [ #  # ]:          0 :             if ( m_pStatusBar )
     236                 :            :             {
     237                 :          0 :                 sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
     238                 :          0 :                 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     239                 :          0 :                 UpdateItemText( nItemPos );
     240                 :            :             }
     241                 :            :         }
     242                 :          0 :         break;
     243                 :            :         case VCLEVENT_OBJECT_DYING:
     244                 :            :         {
     245         [ +  - ]:          2 :             if ( m_pStatusBar )
     246                 :            :             {
     247                 :          2 :                 m_pStatusBar = NULL;
     248                 :            : 
     249                 :            :                 // dispose all children
     250         [ +  + ]:         26 :                 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     251                 :            :                 {
     252         [ +  - ]:         24 :                     Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
     253         [ +  + ]:         24 :                     if ( xComponent.is() )
     254 [ +  - ][ +  - ]:          4 :                         xComponent->dispose();
     255                 :         24 :                 }
     256                 :          2 :                 m_aAccessibleChildren.clear();
     257                 :            :             }
     258                 :            : 
     259                 :          2 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
     260                 :            :         }
     261                 :          2 :         break;
     262                 :            :         default:
     263                 :          0 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
     264                 :            :    }
     265                 :          2 : }
     266                 :            : 
     267                 :            : // -----------------------------------------------------------------------------
     268                 :            : // XComponent
     269                 :            : // -----------------------------------------------------------------------------
     270                 :            : 
     271                 :          2 : void VCLXAccessibleStatusBar::disposing()
     272                 :            : {
     273                 :          2 :     VCLXAccessibleComponent::disposing();
     274                 :            : 
     275         [ -  + ]:          2 :     if ( m_pStatusBar )
     276                 :            :     {
     277                 :          0 :         m_pStatusBar = NULL;
     278                 :            : 
     279                 :            :         // dispose all children
     280         [ #  # ]:          0 :         for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
     281                 :            :         {
     282         [ #  # ]:          0 :             Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
     283         [ #  # ]:          0 :             if ( xComponent.is() )
     284 [ #  # ][ #  # ]:          0 :                 xComponent->dispose();
     285                 :          0 :         }
     286                 :          0 :         m_aAccessibleChildren.clear();
     287                 :            :     }
     288                 :          2 : }
     289                 :            : 
     290                 :            : // -----------------------------------------------------------------------------
     291                 :            : // XServiceInfo
     292                 :            : // -----------------------------------------------------------------------------
     293                 :            : 
     294                 :          0 : ::rtl::OUString VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException)
     295                 :            : {
     296                 :          0 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleStatusBar") );
     297                 :            : }
     298                 :            : 
     299                 :            : // -----------------------------------------------------------------------------
     300                 :            : 
     301                 :          0 : Sequence< ::rtl::OUString > VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException)
     302                 :            : {
     303                 :          0 :     Sequence< ::rtl::OUString > aNames(1);
     304 [ #  # ][ #  # ]:          0 :     aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleStatusBar") );
     305                 :          0 :     return aNames;
     306                 :            : }
     307                 :            : 
     308                 :            : // -----------------------------------------------------------------------------
     309                 :            : // XAccessibleContext
     310                 :            : // -----------------------------------------------------------------------------
     311                 :            : 
     312                 :          4 : sal_Int32 VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException)
     313                 :            : {
     314         [ +  - ]:          4 :     OExternalLockGuard aGuard( this );
     315                 :            : 
     316         [ +  - ]:          4 :     return m_aAccessibleChildren.size();
     317                 :            : }
     318                 :            : 
     319                 :            : // -----------------------------------------------------------------------------
     320                 :            : 
     321                 :          4 : Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
     322                 :            : {
     323         [ +  - ]:          4 :     OExternalLockGuard aGuard( this );
     324                 :            : 
     325 [ +  - ][ +  - ]:          4 :     if ( i < 0 || i >= getAccessibleChildCount() )
         [ -  + ][ -  + ]
     326         [ #  # ]:          0 :         throw IndexOutOfBoundsException();
     327                 :            : 
     328                 :          4 :     Reference< XAccessible > xChild = m_aAccessibleChildren[i];
     329         [ +  - ]:          4 :     if ( !xChild.is() )
     330                 :            :     {
     331         [ +  - ]:          4 :         if ( m_pStatusBar )
     332                 :            :         {
     333         [ +  - ]:          4 :             sal_uInt16 nItemId = m_pStatusBar->GetItemId( (sal_uInt16)i );
     334                 :            : 
     335 [ +  - ][ +  - ]:          4 :             xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
                 [ +  - ]
     336                 :            : 
     337                 :            :             // insert into status bar item list
     338         [ +  - ]:          4 :             m_aAccessibleChildren[i] = xChild;
     339                 :            :         }
     340                 :            :     }
     341                 :            : 
     342         [ +  - ]:          4 :     return xChild;
     343                 :            : }
     344                 :            : 
     345                 :            : // -----------------------------------------------------------------------------
     346                 :            : // XAccessibleComponent
     347                 :            : // -----------------------------------------------------------------------------
     348                 :            : 
     349                 :          0 : Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
     350                 :            : {
     351         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     352                 :            : 
     353                 :          0 :     Reference< XAccessible > xChild;
     354         [ #  # ]:          0 :     if ( m_pStatusBar )
     355                 :            :     {
     356         [ #  # ]:          0 :         sal_uInt16 nItemId = m_pStatusBar->GetItemId( VCLPoint( rPoint ) );
     357         [ #  # ]:          0 :         sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
     358 [ #  # ][ #  # ]:          0 :         if ( nItemPos >= 0 && nItemPos < (sal_Int32)m_aAccessibleChildren.size() )
                 [ #  # ]
     359 [ #  # ][ #  # ]:          0 :             xChild = getAccessibleChild( nItemPos );
     360                 :            :     }
     361                 :            : 
     362         [ #  # ]:          0 :     return xChild;
     363                 :            : }
     364                 :            : 
     365                 :            : // -----------------------------------------------------------------------------
     366                 :            : 
     367                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10