LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/access - acctextframe.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 93 0.0 %
Date: 2012-12-17 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
      22             : #include <comphelper/servicehelper.hxx>
      23             : #include <osl/mutex.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleRelation.hpp>
      28             : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
      29             : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
      30             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      31             : #include <unotools/accessiblestatesethelper.hxx>
      32             : #include <frmfmt.hxx>
      33             : #include <flyfrm.hxx>
      34             : #include <accmap.hxx>
      35             : #include <unotools/accessiblerelationsethelper.hxx>
      36             : #include <hints.hxx> // #i73249#
      37             : #include "acctextframe.hxx"
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::accessibility;
      41             : using ::rtl::OUString;
      42             : 
      43             : using utl::AccessibleRelationSetHelper;
      44             : using ::com::sun::star::accessibility::XAccessibleContext;
      45             : 
      46             : const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView";
      47             : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
      48             : 
      49           0 : SwAccessibleTextFrame::SwAccessibleTextFrame(
      50             :         SwAccessibleMap* pInitMap,
      51             :         const SwFlyFrm* pFlyFrm  ) :
      52             :     SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ),
      53             :     msTitle(),
      54           0 :     msDesc()
      55             : {
      56           0 :     if ( pFlyFrm )
      57             :     {
      58             :         const SwFlyFrmFmt* pFlyFrmFmt =
      59           0 :                         dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
      60           0 :         msTitle = pFlyFrmFmt->GetObjTitle();
      61             : 
      62           0 :         msDesc = pFlyFrmFmt->GetObjDescription();
      63           0 :         if ( msDesc.isEmpty() &&
      64           0 :              msTitle != GetName() )
      65             :         {
      66           0 :             msDesc = msTitle;
      67             :         }
      68             :     }
      69           0 : }
      70             : 
      71           0 : SwAccessibleTextFrame::~SwAccessibleTextFrame()
      72             : {
      73           0 : }
      74             : 
      75           0 : void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
      76             : {
      77           0 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
      78             :     // #i73249# - suppress handling of RES_NAME_CHANGED
      79             :     // in case that attribute Title is used as the accessible name.
      80           0 :     if ( nWhich != RES_NAME_CHANGED ||
      81           0 :          msTitle.isEmpty() )
      82             :     {
      83           0 :         SwAccessibleFrameBase::Modify( pOld, pNew );
      84             :     }
      85             : 
      86           0 :     const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
      87           0 :     switch( nWhich )
      88             :     {
      89             :         // #i73249#
      90             :         case RES_TITLE_CHANGED:
      91             :         {
      92             :             const String& sOldTitle(
      93           0 :                         dynamic_cast<const SwStringMsgPoolItem*>(pOld)->GetString() );
      94             :             const String& sNewTitle(
      95           0 :                         dynamic_cast<const SwStringMsgPoolItem*>(pNew)->GetString() );
      96           0 :             if ( sOldTitle == sNewTitle )
      97             :             {
      98             :                 break;
      99             :             }
     100           0 :             msTitle = sNewTitle;
     101           0 :             AccessibleEventObject aEvent;
     102           0 :             aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     103           0 :             aEvent.OldValue <<= OUString( sOldTitle );
     104           0 :             aEvent.NewValue <<= msTitle;
     105           0 :             FireAccessibleEvent( aEvent );
     106             : 
     107             :             const SwFlyFrmFmt* pFlyFrmFmt =
     108           0 :                             dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
     109           0 :             if ( pFlyFrmFmt->GetObjDescription().Len() != 0 )
     110             :             {
     111             :                 break;
     112           0 :             }
     113             :         }
     114             :         // intentional no break here
     115             :         case RES_DESCRIPTION_CHANGED:
     116             :         {
     117           0 :             if ( pFlyFrm )
     118             :             {
     119           0 :                 const OUString sOldDesc( msDesc );
     120             : 
     121             :                 const SwFlyFrmFmt* pFlyFrmFmt =
     122           0 :                                 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
     123           0 :                 const String& rDesc = pFlyFrmFmt->GetObjDescription();
     124           0 :                 msDesc = rDesc;
     125           0 :                 if ( msDesc.isEmpty() &&
     126           0 :                      msTitle != GetName() )
     127             :                 {
     128           0 :                     msDesc = msTitle;
     129             :                 }
     130             : 
     131           0 :                 if ( msDesc != sOldDesc )
     132             :                 {
     133           0 :                     AccessibleEventObject aEvent;
     134           0 :                     aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
     135           0 :                     aEvent.OldValue <<= sOldDesc;
     136           0 :                     aEvent.NewValue <<= msDesc;
     137           0 :                     FireAccessibleEvent( aEvent );
     138           0 :                 }
     139             :             }
     140             :         }
     141           0 :         break;
     142             :     }
     143           0 : }
     144             : 
     145             : // #i73249#
     146           0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void)
     147             :         throw (uno::RuntimeException)
     148             : {
     149           0 :     SolarMutexGuard aGuard;
     150             : 
     151           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     152             : 
     153           0 :     if ( !msTitle.isEmpty() )
     154             :     {
     155           0 :         return msTitle;
     156             :     }
     157             : 
     158           0 :     return SwAccessibleFrameBase::getAccessibleName();
     159             : }
     160           0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void)
     161             :         throw (uno::RuntimeException)
     162             : {
     163           0 :     SolarMutexGuard aGuard;
     164             : 
     165           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     166             : 
     167           0 :     return msDesc;
     168             : 
     169             : }
     170             : 
     171           0 : OUString SAL_CALL SwAccessibleTextFrame::getImplementationName()
     172             :         throw( uno::RuntimeException )
     173             : {
     174           0 :     return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
     175             : }
     176             : 
     177           0 : sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(
     178             :         const OUString& sTestServiceName)
     179             :     throw (uno::RuntimeException)
     180             : {
     181             :     return sTestServiceName.equalsAsciiL( sServiceName,
     182           0 :                                           sizeof(sServiceName)-1 ) ||
     183             :            sTestServiceName.equalsAsciiL( sAccessibleServiceName,
     184           0 :                                              sizeof(sAccessibleServiceName)-1 );
     185             : }
     186             : 
     187           0 : uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
     188             :         throw( uno::RuntimeException )
     189             : {
     190           0 :     uno::Sequence< OUString > aRet(2);
     191           0 :     OUString* pArray = aRet.getArray();
     192           0 :     pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
     193           0 :     pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
     194           0 :     return aRet;
     195             : }
     196             : 
     197             : namespace
     198             : {
     199             :     class theSwAccessibleTextFrameImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleTextFrameImplementationId > {};
     200             : }
     201             : 
     202           0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
     203             :         throw(uno::RuntimeException)
     204             : {
     205           0 :     return theSwAccessibleTextFrameImplementationId::get().getSeq();
     206             : }
     207             : 
     208             : 
     209             : //
     210             : // XAccessibleRelationSet
     211             : //
     212             : 
     213             : 
     214           0 : SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const
     215             : {
     216           0 :     SwFlyFrm* pFlyFrm = NULL;
     217             : 
     218           0 :     const SwFrm* pFrm = GetFrm();
     219             :     OSL_ENSURE( pFrm != NULL, "frame expected" );
     220           0 :     if( pFrm->IsFlyFrm() )
     221             :     {
     222           0 :         pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
     223             :     }
     224             : 
     225           0 :     return pFlyFrm;
     226             : }
     227             : 
     228           0 : AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm )
     229             : {
     230           0 :     uno::Sequence<uno::Reference<XInterface> > aSequence(1);
     231           0 :     aSequence[0] = GetMap()->GetContext( pFrm );
     232           0 :     return AccessibleRelation( nType, aSequence );
     233             : }
     234             : 
     235             : 
     236           0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
     237             :     throw ( uno::RuntimeException )
     238             : {
     239           0 :     SolarMutexGuard aGuard;
     240           0 :     CHECK_FOR_DEFUNC( XAccessibleContext );
     241             : 
     242             :     // get the frame, and insert prev/next relations into helper
     243             : 
     244           0 :     AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper();
     245             : 
     246           0 :     SwFlyFrm* pFlyFrm = getFlyFrm();
     247             :     OSL_ENSURE( pFlyFrm != NULL, "fly frame expected" );
     248             : 
     249           0 :     const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink();
     250           0 :     if( pPrevFrm != NULL )
     251             :         pHelper->AddRelation( makeRelation(
     252           0 :             AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) );
     253             : 
     254           0 :     const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink();
     255           0 :     if( pNextFrm != NULL )
     256             :         pHelper->AddRelation( makeRelation(
     257           0 :             AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) );
     258             : 
     259           0 :     return pHelper;
     260             : }
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10