LCOV - code coverage report
Current view: top level - sw/source/core/access - accnotextframe.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 159 21.4 %
Date: 2015-06-13 12:38:46 Functions: 7 36 19.4 %
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 <osl/mutex.hxx>
      21             : #include <vcl/svapp.hxx>
      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 <unotools/accessiblestatesethelper.hxx>
      26             : #include <frmfmt.hxx>
      27             : #include <ndnotxt.hxx>
      28             : #include <flyfrm.hxx>
      29             : #include <cntfrm.hxx>
      30             : #include <hints.hxx>
      31             : #include "accnotextframe.hxx"
      32             : #include <fmturl.hxx>
      33             : #include <accnotexthyperlink.hxx>
      34             : #include <svtools/imap.hxx>
      35             : #include <unotools/accessiblerelationsethelper.hxx>
      36             : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
      37             : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
      38             : #include <doc.hxx>
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::accessibility;
      42             : using utl::AccessibleRelationSetHelper;
      43             : 
      44           2 : const SwNoTextNode *SwAccessibleNoTextFrame::GetNoTextNode() const
      45             : {
      46           2 :     const SwNoTextNode *pNd  = 0;
      47           2 :     const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm *>( GetFrm() );
      48           2 :     if( pFlyFrm->Lower() && pFlyFrm->Lower()->IsNoTextFrm() )
      49             :     {
      50             :         const SwContentFrm *pCntFrm =
      51           2 :             static_cast<const SwContentFrm *>( pFlyFrm->Lower() );
      52           2 :         const SwContentNode* pSwContentNode = pCntFrm->GetNode();
      53           2 :         if(pSwContentNode != NULL)
      54             :         {
      55           2 :             pNd = pSwContentNode->GetNoTextNode();
      56             :         }
      57             :     }
      58             : 
      59           2 :     return pNd;
      60             : }
      61             : 
      62           1 : SwAccessibleNoTextFrame::SwAccessibleNoTextFrame(
      63             :         SwAccessibleMap* pInitMap,
      64             :         sal_Int16 nInitRole,
      65             :         const SwFlyFrm* pFlyFrm  ) :
      66             :     SwAccessibleFrameBase( pInitMap, nInitRole, pFlyFrm ),
      67           1 :     aDepend( this, const_cast < SwNoTextNode * >( GetNoTextNode() ) ),
      68             :     msTitle(),
      69           2 :     msDesc()
      70             : {
      71           1 :     const SwNoTextNode* pNd = GetNoTextNode();
      72             :     // #i73249#
      73             :     // consider new attributes Title and Description
      74           1 :     if( pNd )
      75             :     {
      76           1 :         msTitle = pNd->GetTitle();
      77             : 
      78           1 :         msDesc = pNd->GetDescription();
      79           2 :         if ( msDesc.isEmpty() &&
      80           1 :              msTitle != GetName() )
      81             :         {
      82           1 :             msDesc = msTitle;
      83             :         }
      84             :     }
      85           1 : }
      86             : 
      87           1 : SwAccessibleNoTextFrame::~SwAccessibleNoTextFrame()
      88             : {
      89           1 : }
      90             : 
      91           0 : void SwAccessibleNoTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
      92             : {
      93           0 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
      94             :     // #i73249#
      95             :     // suppress handling of RES_NAME_CHANGED in case that attribute Title is
      96             :     // used as the accessible name.
      97           0 :     if ( nWhich != RES_NAME_CHANGED ||
      98           0 :          msTitle.isEmpty() )
      99             :     {
     100           0 :         SwAccessibleFrameBase::Modify( pOld, pNew );
     101           0 :         if (!GetRegisteredIn())
     102           0 :             return; // probably was deleted - avoid doing anything
     103             :     }
     104             : 
     105           0 :     const SwNoTextNode *pNd = GetNoTextNode();
     106             :     OSL_ENSURE( pNd == aDepend.GetRegisteredIn(), "invalid frame" );
     107           0 :     switch( nWhich )
     108             :     {
     109             :         // #i73249#
     110             :         case RES_TITLE_CHANGED:
     111             :         {
     112           0 :             OUString sOldTitle, sNewTitle;
     113           0 :             const SwStringMsgPoolItem* pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pOld);
     114           0 :             if (pOldItem)
     115           0 :                 sOldTitle = pOldItem->GetString();
     116           0 :             const SwStringMsgPoolItem* pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pNew);
     117           0 :             if (pNewItem)
     118           0 :                 sNewTitle = pNewItem->GetString();
     119           0 :             if ( sOldTitle == sNewTitle )
     120             :             {
     121           0 :                 break;
     122             :             }
     123           0 :             msTitle = sNewTitle;
     124           0 :             AccessibleEventObject aEvent;
     125           0 :             aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     126           0 :             aEvent.OldValue <<= sOldTitle;
     127           0 :             aEvent.NewValue <<= msTitle;
     128           0 :             FireAccessibleEvent( aEvent );
     129             : 
     130           0 :             if ( !pNd->GetDescription().isEmpty() )
     131             :             {
     132           0 :                 break;
     133           0 :             }
     134             :         }
     135             :         // intentional no break here
     136             :         case RES_DESCRIPTION_CHANGED:
     137             :         {
     138           0 :             if ( pNd && GetFrm() )
     139             :             {
     140           0 :                 const OUString sOldDesc( msDesc );
     141             : 
     142           0 :                 const OUString& rDesc = pNd->GetDescription();
     143           0 :                 msDesc = rDesc;
     144           0 :                 if ( msDesc.isEmpty() &&
     145           0 :                      msTitle != GetName() )
     146             :                 {
     147           0 :                     msDesc = msTitle;
     148             :                 }
     149             : 
     150           0 :                 if ( msDesc != sOldDesc )
     151             :                 {
     152           0 :                     AccessibleEventObject aEvent;
     153           0 :                     aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
     154           0 :                     aEvent.OldValue <<= sOldDesc;
     155           0 :                     aEvent.NewValue <<= msDesc;
     156           0 :                     FireAccessibleEvent( aEvent );
     157           0 :                 }
     158             :             }
     159             :         }
     160           0 :         break;
     161             :     }
     162             : }
     163             : 
     164           1 : void SwAccessibleNoTextFrame::Dispose( bool bRecursive )
     165             : {
     166           1 :     SolarMutexGuard aGuard;
     167             : 
     168           1 :     if( aDepend.GetRegisteredIn() )
     169           1 :         aDepend.GetRegisteredIn()->Remove( &aDepend );
     170             : 
     171           1 :     SwAccessibleFrameBase::Dispose( bRecursive );
     172           1 : }
     173             : 
     174             : // #i73249#
     175           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleName()
     176             :         throw (uno::RuntimeException, std::exception)
     177             : {
     178           0 :     SolarMutexGuard aGuard;
     179             : 
     180           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     181             : 
     182           0 :     if ( !msTitle.isEmpty() )
     183             :     {
     184           0 :         return msTitle;
     185             :     }
     186             : 
     187           0 :     return SwAccessibleFrameBase::getAccessibleName();
     188             : }
     189             : 
     190           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleDescription()
     191             :         throw (uno::RuntimeException, std::exception)
     192             : {
     193           0 :     SolarMutexGuard aGuard;
     194             : 
     195           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     196             : 
     197           0 :     return msDesc;
     198             : }
     199             : 
     200             : // XInterface
     201             : 
     202          70 : uno::Any SAL_CALL SwAccessibleNoTextFrame::queryInterface( const uno::Type& aType )
     203             :     throw (uno::RuntimeException, std::exception)
     204             : {
     205          70 :     if( aType ==
     206          70 :         ::cppu::UnoType<XAccessibleImage>::get() )
     207             :     {
     208           0 :         uno::Reference<XAccessibleImage> xImage = this;
     209           0 :         uno::Any aAny;
     210           0 :         aAny <<= xImage;
     211           0 :         return aAny;
     212             :     }
     213          70 :     else if ( aType == cppu::UnoType<XAccessibleHypertext>::get())
     214             :     {
     215           0 :         uno::Reference<XAccessibleHypertext> aAccHypertext = this;
     216           0 :         uno::Any aAny;
     217           0 :         aAny <<= aAccHypertext;
     218           0 :         return aAny;
     219             :     }
     220             :     else
     221          70 :         return SwAccessibleContext::queryInterface( aType );
     222             : }
     223             : 
     224             : // XTypeProvider
     225             : 
     226           0 : uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes() throw(uno::RuntimeException, std::exception)
     227             : {
     228           0 :     uno::Sequence< uno::Type > aTypes( SwAccessibleFrameBase::getTypes() );
     229             : 
     230           0 :     sal_Int32 nIndex = aTypes.getLength();
     231           0 :     aTypes.realloc( nIndex + 1 );
     232             : 
     233           0 :     uno::Type* pTypes = aTypes.getArray();
     234           0 :     pTypes[nIndex] = ::cppu::UnoType<XAccessibleImage>::get();
     235             : 
     236           0 :     return aTypes;
     237             : }
     238             : 
     239             : /// XAccessibleImage
     240             : /** implementation of the XAccessibleImage methods is a no-brainer, as
     241             :     all relevant information is already accessible through other
     242             :     methods. So we just delegate to those. */
     243             : 
     244           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageDescription()
     245             :     throw ( uno::RuntimeException, std::exception )
     246             : {
     247           0 :     return getAccessibleDescription();
     248             : }
     249             : 
     250           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageHeight(  )
     251             :     throw ( uno::RuntimeException, std::exception )
     252             : {
     253           0 :     return getSize().Height;
     254             : }
     255             : 
     256           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageWidth(  )
     257             :     throw ( uno::RuntimeException, std::exception )
     258             : {
     259           0 :     return getSize().Width;
     260             : }
     261             : 
     262             : // XAccesibleText
     263           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCaretPosition(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     264           0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::setCaretPosition( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     265           0 : sal_Unicode SAL_CALL SwAccessibleNoTextFrame::getCharacter( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     266           0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SwAccessibleNoTextFrame::getCharacterAttributes( sal_Int32 , const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
     267             : {
     268           0 :     uno::Sequence<beans::PropertyValue> aValues(0);
     269           0 :     return aValues;
     270             : }
     271           0 : ::com::sun::star::awt::Rectangle SAL_CALL SwAccessibleNoTextFrame::getCharacterBounds( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
     272             : {
     273           0 :     return com::sun::star::awt::Rectangle(0, 0, 0, 0 );
     274             : }
     275           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCharacterCount(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     276           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getIndexAtPoint( const ::com::sun::star::awt::Point& ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     277           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getSelectedText(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
     278           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionStart(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     279           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionEnd(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
     280           0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::setSelection( sal_Int32 , sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return sal_True;}
     281           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getText(  ) throw (::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
     282           0 : OUString SAL_CALL SwAccessibleNoTextFrame::getTextRange( sal_Int32 , sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
     283           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextAtIndex( sal_Int32 , sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     284             : {
     285           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     286           0 :     return aResult;
     287             : }
     288           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBeforeIndex( sal_Int32, sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     289             : {
     290           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     291           0 :     return aResult;
     292             : }
     293           0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBehindIndex( sal_Int32 , sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     294             : {
     295           0 :     ::com::sun::star::accessibility::TextSegment aResult;
     296           0 :     return aResult;
     297             : }
     298             : 
     299           0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::copyText( sal_Int32, sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return sal_True;}
     300             : 
     301             : //  XAccessibleHyperText
     302             : 
     303           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkCount()
     304             : throw (uno::RuntimeException, std::exception)
     305             : {
     306           0 :     SolarMutexGuard aGuard;
     307             : 
     308           0 :     CHECK_FOR_DEFUNC( XAccessibleHypertext );
     309             : 
     310           0 :     sal_Int32 nCount = 0;
     311           0 :     SwFormatURL aURL( static_cast<const SwLayoutFrm*>(GetFrm())->GetFormat()->GetURL() );
     312             : 
     313           0 :     if(aURL.GetMap() || !aURL.GetURL().isEmpty())
     314           0 :         nCount = 1;
     315             : 
     316           0 :     return nCount;
     317             : }
     318             : 
     319             : uno::Reference< XAccessibleHyperlink > SAL_CALL
     320           0 :     SwAccessibleNoTextFrame::getHyperLink( sal_Int32 nLinkIndex )
     321             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     322             : {
     323           0 :     SolarMutexGuard aGuard;
     324           0 :     CHECK_FOR_DEFUNC( XAccessibleHypertext );
     325             : 
     326           0 :     uno::Reference< XAccessibleHyperlink > xRet;
     327             : 
     328           0 :     SwFormatURL aURL( static_cast<const SwLayoutFrm*>(GetFrm())->GetFormat()->GetURL() );
     329             : 
     330           0 :     if( nLinkIndex > 0 )
     331           0 :         throw lang::IndexOutOfBoundsException();
     332             : 
     333           0 :     if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
     334             :     {
     335           0 :         if ( !alink.is() )
     336             :         {
     337           0 :             alink = new SwAccessibleNoTextHyperlink( this, GetFrm() );
     338             :         }
     339             : 
     340           0 :         return alink;
     341             :     }
     342             : 
     343           0 :     return NULL;
     344             : }
     345             : 
     346           0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkIndex( sal_Int32 )
     347             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     348             : {
     349           0 :     SolarMutexGuard aGuard;
     350             : 
     351           0 :     return 0;
     352             : }
     353             : 
     354           0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleNoTextFrame::getAccessibleRelationSet( )
     355             :     throw ( uno::RuntimeException, std::exception )
     356             : {
     357           0 :     SolarMutexGuard aGuard;
     358             : 
     359           0 :     return new AccessibleRelationSetHelper();
     360         177 : }
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11