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

Generated by: LCOV version 1.10