LCOV - code coverage report
Current view: top level - sw/source/core/access - acctextframe.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 148 0.7 %
Date: 2014-11-03 Functions: 2 25 8.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 <com/sun/star/accessibility/XAccessibleContext.hpp>
      21             : #include <comphelper/servicehelper.hxx>
      22             : #include <cppuhelper/supportsservice.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 <doc.hxx>
      37             : #include <hints.hxx>
      38             : #include "acctextframe.hxx"
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::accessibility;
      42             : 
      43             : using utl::AccessibleRelationSetHelper;
      44             : using ::com::sun::star::accessibility::XAccessibleContext;
      45             : 
      46           0 : SwAccessibleTextFrame::SwAccessibleTextFrame(
      47             :         SwAccessibleMap* pInitMap,
      48             :         const SwFlyFrm& rFlyFrm  ) :
      49             :     SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, &rFlyFrm ),
      50             :     msTitle(),
      51           0 :     msDesc()
      52             : {
      53             :     const SwFlyFrmFmt* pFlyFrmFmt =
      54           0 :                     dynamic_cast<const SwFlyFrmFmt*>( rFlyFrm.GetFmt() );
      55           0 :     msTitle = pFlyFrmFmt->GetObjTitle();
      56             : 
      57           0 :     msDesc = pFlyFrmFmt->GetObjDescription();
      58           0 :     if ( msDesc.isEmpty() &&
      59           0 :          msTitle != GetName() )
      60             :     {
      61           0 :         msDesc = msTitle;
      62             :     }
      63           0 : }
      64             : 
      65           0 : SwAccessibleTextFrame::~SwAccessibleTextFrame()
      66             : {
      67           0 : }
      68             : 
      69           0 : void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
      70             : {
      71           0 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
      72             :     // #i73249# - suppress handling of RES_NAME_CHANGED
      73             :     // in case that attribute Title is used as the accessible name.
      74           0 :     if ( nWhich != RES_NAME_CHANGED ||
      75           0 :          msTitle.isEmpty() )
      76             :     {
      77           0 :         SwAccessibleFrameBase::Modify( pOld, pNew );
      78             :     }
      79             : 
      80           0 :     const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
      81           0 :     switch( nWhich )
      82             :     {
      83             :         // #i73249#
      84             :         case RES_TITLE_CHANGED:
      85             :         {
      86           0 :             OUString sOldTitle, sNewTitle;
      87           0 :             const SwStringMsgPoolItem *pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pOld);
      88           0 :             if (pOldItem)
      89           0 :                 sOldTitle = pOldItem->GetString();
      90           0 :             const SwStringMsgPoolItem *pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pNew);
      91           0 :             if (pNewItem)
      92           0 :                 sNewTitle = pNewItem->GetString();
      93           0 :             if (sOldTitle == sNewTitle)
      94             :             {
      95           0 :                 break;
      96             :             }
      97           0 :             msTitle = sNewTitle;
      98           0 :             AccessibleEventObject aEvent;
      99           0 :             aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     100           0 :             aEvent.OldValue <<= OUString( sOldTitle );
     101           0 :             aEvent.NewValue <<= msTitle;
     102           0 :             FireAccessibleEvent( aEvent );
     103             : 
     104             :             const SwFlyFrmFmt* pFlyFrmFmt =
     105           0 :                             dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
     106           0 :             if (!pFlyFrmFmt || !pFlyFrmFmt->GetObjDescription().isEmpty())
     107             :             {
     108           0 :                 break;
     109           0 :             }
     110             :         }
     111             :         // intentionally no break here
     112             :         case RES_DESCRIPTION_CHANGED:
     113             :         {
     114           0 :             if ( pFlyFrm )
     115             :             {
     116           0 :                 const OUString sOldDesc( msDesc );
     117             : 
     118             :                 const SwFlyFrmFmt* pFlyFrmFmt =
     119           0 :                                 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
     120           0 :                 const OUString& rDesc = pFlyFrmFmt->GetObjDescription();
     121           0 :                 msDesc = rDesc;
     122           0 :                 if ( msDesc.isEmpty() &&
     123           0 :                      msTitle != GetName() )
     124             :                 {
     125           0 :                     msDesc = msTitle;
     126             :                 }
     127             : 
     128           0 :                 if ( msDesc != sOldDesc )
     129             :                 {
     130           0 :                     AccessibleEventObject aEvent;
     131           0 :                     aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
     132           0 :                     aEvent.OldValue <<= sOldDesc;
     133           0 :                     aEvent.NewValue <<= msDesc;
     134           0 :                     FireAccessibleEvent( aEvent );
     135           0 :                 }
     136             :             }
     137             :         }
     138           0 :         break;
     139             :     }
     140           0 : }
     141             : 
     142             : // XInterface
     143             : 
     144             : com::sun::star::uno::Any SAL_CALL
     145           0 :     SwAccessibleTextFrame::queryInterface (const com::sun::star::uno::Type & rType)
     146             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     147             : {
     148           0 :     ::com::sun::star::uno::Any aReturn = SwAccessibleContext::queryInterface (rType);
     149           0 :     if ( ! aReturn.hasValue())
     150           0 :         aReturn = ::cppu::queryInterface (rType,
     151             :             static_cast< ::com::sun::star::accessibility::XAccessibleSelection* >(this)
     152           0 :             );
     153           0 :     return aReturn;
     154             : }
     155             : 
     156             : void SAL_CALL
     157           0 :     SwAccessibleTextFrame::acquire (void)
     158             :     throw ()
     159             : {
     160           0 :     SwAccessibleContext::acquire ();
     161           0 : }
     162             : 
     163             : void SAL_CALL
     164           0 :     SwAccessibleTextFrame::release (void)
     165             :     throw ()
     166             : {
     167           0 :     SwAccessibleContext::release ();
     168           0 : }
     169             : 
     170             : // XAccessibleSelection
     171             : 
     172           0 : void SAL_CALL SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 )
     173             :     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
     174             : {
     175             :     DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 )> - missing implementation" );
     176           0 : }
     177             : 
     178           0 : sal_Bool SAL_CALL SwAccessibleTextFrame::isAccessibleChildSelected( sal_Int32 nChildIndex )
     179             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
     180             : {
     181           0 :     SolarMutexGuard g;
     182             : 
     183           0 :     uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
     184           0 :     uno::Reference<XAccessibleContext> xContext;
     185           0 :     if( xAcc.is() )
     186           0 :         xContext = xAcc->getAccessibleContext();
     187             : 
     188           0 :     if( xContext.is() )
     189             :     {
     190           0 :         if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
     191             :         {
     192             :             uno::Reference< ::com::sun::star::accessibility::XAccessibleText >
     193           0 :                 xText(xAcc, uno::UNO_QUERY);
     194           0 :             if( xText.is() )
     195             :             {
     196           0 :                 if( xText->getSelectionStart() >= 0 ) return sal_True;
     197           0 :             }
     198             :         }
     199             :     }
     200             : 
     201           0 :     return sal_False;
     202             : }
     203             : 
     204           0 : void SAL_CALL SwAccessibleTextFrame::clearAccessibleSelection(  )
     205             :     throw ( uno::RuntimeException, std::exception )
     206             : {
     207             :     DBG_ASSERT( false, "<SwAccessibleTextFrame::clearAccessibleSelection(  )> - missing implementation" );
     208           0 : }
     209             : 
     210           0 : void SAL_CALL SwAccessibleTextFrame::selectAllAccessibleChildren(  )
     211             :     throw ( uno::RuntimeException, std::exception )
     212             : {
     213             :     DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAllAccessibleChildren(  )> - missing implementation" );
     214           0 : }
     215             : 
     216           0 : sal_Int32 SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChildCount()
     217             :     throw ( uno::RuntimeException, std::exception )
     218             : {
     219           0 :     sal_Int32 nCount = 0;
     220           0 :     sal_Int32 TotalCount = getAccessibleChildCount();
     221           0 :     for( sal_Int32 i = 0; i < TotalCount; i++ )
     222           0 :         if( isAccessibleChildSelected(i) ) nCount++;
     223             : 
     224           0 :     return nCount;
     225             : }
     226             : 
     227           0 : uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
     228             :     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     229             : {
     230           0 :     SolarMutexGuard g;
     231             : 
     232           0 :     if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
     233           0 :         throw lang::IndexOutOfBoundsException();
     234             :     sal_Int32 i1, i2;
     235           0 :     for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
     236           0 :         if( isAccessibleChildSelected(i1) )
     237             :         {
     238           0 :             if( i2 == nSelectedChildIndex )
     239           0 :                 return getAccessibleChild( i1 );
     240           0 :             i2++;
     241             :         }
     242           0 :     return uno::Reference<XAccessible>();
     243             : }
     244             : 
     245           0 : void SAL_CALL SwAccessibleTextFrame::deselectAccessibleChild( sal_Int32 )
     246             :     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
     247             : {
     248             :     DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAllAccessibleChildren( sal_Int32 )> - missing implementation" );
     249           0 : }
     250             : 
     251             : // #i73249#
     252           0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void)
     253             :         throw (uno::RuntimeException, std::exception)
     254             : {
     255           0 :     SolarMutexGuard aGuard;
     256             : 
     257           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     258             : 
     259           0 :     if ( !msTitle.isEmpty() )
     260             :     {
     261           0 :         return msTitle;
     262             :     }
     263             : 
     264           0 :     return SwAccessibleFrameBase::getAccessibleName();
     265             : }
     266             : 
     267           0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void)
     268             :         throw (uno::RuntimeException, std::exception)
     269             : {
     270           0 :     SolarMutexGuard aGuard;
     271             : 
     272           0 :     CHECK_FOR_DEFUNC( XAccessibleContext )
     273             : 
     274           0 :     return msDesc;
     275             : 
     276             : }
     277             : 
     278           0 : OUString SAL_CALL SwAccessibleTextFrame::getImplementationName()
     279             :         throw( uno::RuntimeException, std::exception )
     280             : {
     281           0 :     return OUString("com.sun.star.comp.Writer.SwAccessibleTextFrameView");
     282             : }
     283             : 
     284           0 : sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(const OUString& sTestServiceName)
     285             :     throw (uno::RuntimeException, std::exception)
     286             : {
     287           0 :     return cppu::supportsService(this, sTestServiceName);
     288             : }
     289             : 
     290           0 : uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
     291             :         throw( uno::RuntimeException, std::exception )
     292             : {
     293           0 :     uno::Sequence< OUString > aRet(2);
     294           0 :     OUString* pArray = aRet.getArray();
     295           0 :     pArray[0] = "com.sun.star.text.AccessibleTextFrameView";
     296           0 :     pArray[1] = OUString( sAccessibleServiceName );
     297           0 :     return aRet;
     298             : }
     299             : 
     300           0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
     301             :         throw(uno::RuntimeException, std::exception)
     302             : {
     303           0 :     return css::uno::Sequence<sal_Int8>();
     304             : }
     305             : 
     306             : // XAccessibleRelationSet
     307             : 
     308           0 : SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const
     309             : {
     310           0 :     SwFlyFrm* pFlyFrm = NULL;
     311             : 
     312           0 :     const SwFrm* pFrm = GetFrm();
     313             :     OSL_ENSURE( pFrm != NULL, "frame expected" );
     314           0 :     if( pFrm->IsFlyFrm() )
     315             :     {
     316           0 :         pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
     317             :     }
     318             : 
     319           0 :     return pFlyFrm;
     320             : }
     321             : 
     322           0 : AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm )
     323             : {
     324           0 :     uno::Sequence<uno::Reference<XInterface> > aSequence(1);
     325           0 :     aSequence[0] = GetMap()->GetContext( pFrm );
     326           0 :     return AccessibleRelation( nType, aSequence );
     327             : }
     328             : 
     329           0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
     330             :     throw ( uno::RuntimeException, std::exception )
     331             : {
     332           0 :     SolarMutexGuard aGuard;
     333           0 :     CHECK_FOR_DEFUNC( XAccessibleContext );
     334             : 
     335             :     // get the frame, and insert prev/next relations into helper
     336             : 
     337           0 :     AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper();
     338             : 
     339           0 :     SwFlyFrm* pFlyFrm = getFlyFrm();
     340             :     OSL_ENSURE( pFlyFrm != NULL, "fly frame expected" );
     341             : 
     342           0 :     const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink();
     343           0 :     if( pPrevFrm != NULL )
     344             :         pHelper->AddRelation( makeRelation(
     345           0 :             AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) );
     346             : 
     347           0 :     const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink();
     348           0 :     if( pNextFrm != NULL )
     349             :         pHelper->AddRelation( makeRelation(
     350           0 :             AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) );
     351             : 
     352           0 :     return pHelper;
     353         270 : }
     354             : 
     355             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10