LCOV - code coverage report
Current view: top level - sw/source/core/access - accselectionhelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 178 0.0 %
Date: 2014-04-14 Functions: 0 12 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/XAccessibleSelection.hpp>
      21             : #include <accselectionhelper.hxx>
      22             : 
      23             : #include <acccontext.hxx>
      24             : #include <accmap.hxx>
      25             : #include <svx/AccessibleShape.hxx>
      26             : #include <viewsh.hxx>
      27             : #include <fesh.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <flyfrm.hxx>
      30             : 
      31             : #include <com/sun/star/uno/Reference.hxx>
      32             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      33             : #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
      34             : #include <fmtanchr.hxx>
      35             : 
      36             : using namespace ::com::sun::star::accessibility;
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : 
      40             : using ::com::sun::star::accessibility::XAccessible;
      41             : using ::com::sun::star::accessibility::XAccessibleContext;
      42             : using ::com::sun::star::accessibility::XAccessibleSelection;
      43             : 
      44             : using namespace ::sw::access;
      45             : 
      46           0 : SwAccessibleSelectionHelper::SwAccessibleSelectionHelper(
      47             :     SwAccessibleContext& rCtxt ) :
      48           0 :         rContext( rCtxt )
      49             : {
      50           0 : }
      51             : 
      52           0 : SwAccessibleSelectionHelper::~SwAccessibleSelectionHelper()
      53             : {
      54           0 : }
      55             : 
      56           0 : SwFEShell* SwAccessibleSelectionHelper::GetFEShell()
      57             : {
      58             :     OSL_ENSURE( rContext.GetMap() != NULL, "no map?" );
      59           0 :     SwViewShell* pViewShell = rContext.GetMap()->GetShell();
      60             :     OSL_ENSURE( pViewShell != NULL,
      61             :                 "No view shell? Then what are you looking at?" );
      62             : 
      63           0 :     SwFEShell* pFEShell = NULL;
      64           0 :     if( pViewShell->ISA( SwFEShell ) )
      65             :     {
      66           0 :         pFEShell = static_cast<SwFEShell*>( pViewShell );
      67             :     }
      68             : 
      69           0 :     return pFEShell;
      70             : }
      71             : 
      72           0 : void SwAccessibleSelectionHelper::throwIndexOutOfBoundsException()
      73             :         throw ( lang::IndexOutOfBoundsException )
      74             : {
      75           0 :     Reference < XAccessibleContext > xThis( &rContext );
      76           0 :     Reference < XAccessibleSelection >xSelThis( xThis, UNO_QUERY );
      77             :     lang::IndexOutOfBoundsException aExcept(
      78             :                 OUString( "index out of bounds" ),
      79           0 :                 xSelThis );                                     \
      80           0 :     throw aExcept;
      81             : }
      82             : 
      83             : // XAccessibleSelection
      84           0 : void SwAccessibleSelectionHelper::selectAccessibleChild(
      85             :     sal_Int32 nChildIndex )
      86             :     throw ( lang::IndexOutOfBoundsException,
      87             :             RuntimeException )
      88             : {
      89           0 :     SolarMutexGuard aGuard;
      90             : 
      91             :     // Get the respective child as SwFrm (also do index checking), ...
      92           0 :     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
      93           0 :                                                         nChildIndex );
      94           0 :     if( !aChild.IsValid() )
      95           0 :         throwIndexOutOfBoundsException();
      96             : 
      97             :     // we can only select fly frames, so we ignore (should: return
      98             :     // false) all other attempts at child selection
      99           0 :     SwFEShell* pFEShell = GetFEShell();
     100           0 :     if( pFEShell != NULL )
     101             :     {
     102           0 :         const SdrObject *pObj = aChild.GetDrawObject();
     103           0 :         if( pObj )
     104           0 :             rContext.Select( const_cast< SdrObject *>( pObj ), 0==aChild.GetSwFrm());
     105           0 :     }
     106             :     // no frame shell, or no frame, or no fly frame -> can't select
     107           0 : }
     108             : 
     109             : //When the selected state of the SwFrmOrObj is setted, return true.
     110           0 : static sal_Bool lcl_getSelectedState(const SwAccessibleChild& aChild,
     111             :                                      SwAccessibleContext* pContext,
     112             :                                      SwAccessibleMap* pMap)
     113             : {
     114           0 :     Reference< XAccessible > xAcc;
     115           0 :     if ( aChild.GetSwFrm() )
     116             :     {
     117           0 :         xAcc = pMap->GetContext( aChild.GetSwFrm(), sal_False );
     118             :     }
     119           0 :     else if ( aChild.GetDrawObject() )
     120             :     {
     121           0 :         xAcc = pMap->GetContext( aChild.GetDrawObject(), pContext, sal_False );
     122             :     }
     123             : 
     124           0 :     if( xAcc.is() )
     125             :     {
     126           0 :         Reference< XAccessibleContext > pRContext = xAcc->getAccessibleContext();
     127           0 :         if(!pRContext.is())
     128           0 :             return sal_False;
     129           0 :         Reference<XAccessibleStateSet> pRStateSet = pRContext->getAccessibleStateSet();
     130           0 :         if( pRStateSet.is() )
     131             :         {
     132           0 :             Sequence<short> pStates = pRStateSet->getStates();
     133           0 :             long count = pStates.getLength();
     134           0 :             for( int i = 0; i < count; i++ )
     135             :             {
     136           0 :                 if( pStates[i] == AccessibleStateType::SELECTED)
     137           0 :                     return sal_True;
     138           0 :             }
     139           0 :         }
     140             :     }
     141           0 :     return sal_False;
     142             : }
     143             : 
     144           0 : sal_Bool SwAccessibleSelectionHelper::isAccessibleChildSelected(
     145             :     sal_Int32 nChildIndex )
     146             :     throw ( lang::IndexOutOfBoundsException,
     147             :             RuntimeException )
     148             : {
     149           0 :     SolarMutexGuard aGuard;
     150             : 
     151             :     // Get the respective child as SwFrm (also do index checking), ...
     152           0 :     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
     153           0 :                                                         nChildIndex );
     154           0 :     if( !aChild.IsValid() )
     155           0 :         throwIndexOutOfBoundsException();
     156             : 
     157             :     // ... and compare to the currently selected frame
     158           0 :     sal_Bool bRet = sal_False;
     159           0 :     SwFEShell* pFEShell = GetFEShell();
     160           0 :     if( pFEShell )
     161             :     {
     162           0 :         if ( aChild.GetSwFrm() != 0 )
     163             :         {
     164           0 :             bRet = (pFEShell->GetCurrFlyFrm() == aChild.GetSwFrm());
     165             :         }
     166           0 :         else if ( aChild.GetDrawObject() )
     167             :         {
     168           0 :             bRet = pFEShell->IsObjSelected( *aChild.GetDrawObject() );
     169             :         }
     170             :         //If the SwFrmOrObj is not selected directly in the UI, we should check whether it is selected in the selection cursor.
     171           0 :         if( !bRet )
     172             :         {
     173           0 :             if( lcl_getSelectedState( aChild, &rContext, rContext.GetMap() ) == sal_True)
     174           0 :                 bRet = sal_True;
     175             :         }
     176             :     }
     177             : 
     178           0 :     return bRet;
     179             : }
     180             : 
     181           0 : void SwAccessibleSelectionHelper::clearAccessibleSelection(  )
     182             :     throw ( RuntimeException )
     183             : {
     184             :     // return sal_False     // we can't deselect
     185           0 : }
     186             : 
     187           0 : void SwAccessibleSelectionHelper::selectAllAccessibleChildren(  )
     188             :     throw ( RuntimeException )
     189             : {
     190           0 :     SolarMutexGuard aGuard;
     191             : 
     192             :     // We can select only one. So iterate over the children to find
     193             :     // the first we can select, and select it.
     194             : 
     195           0 :     SwFEShell* pFEShell = GetFEShell();
     196           0 :     if( pFEShell )
     197             :     {
     198           0 :         ::std::list< SwAccessibleChild > aChildren;
     199           0 :         rContext.GetChildren( *(rContext.GetMap()), aChildren );
     200             : 
     201           0 :         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
     202           0 :         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
     203           0 :         while( aIter != aEndIter )
     204             :         {
     205           0 :             const SwAccessibleChild& rChild = *aIter;
     206           0 :             const SdrObject* pObj = rChild.GetDrawObject();
     207           0 :             const SwFrm* pFrm = rChild.GetSwFrm();
     208           0 :             if( pObj && !(pFrm != 0 && pFEShell->IsObjSelected()) )
     209             :             {
     210           0 :                 rContext.Select( const_cast< SdrObject *>( pObj ), 0==pFrm );
     211           0 :                 if( pFrm )
     212           0 :                     break;
     213             :             }
     214           0 :             ++aIter;
     215           0 :         }
     216           0 :     }
     217           0 : }
     218             : 
     219           0 : sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount(  )
     220             :     throw ( RuntimeException )
     221             : {
     222           0 :     SolarMutexGuard aGuard;
     223             : 
     224           0 :     sal_Int32 nCount = 0;
     225             :     // Only one frame can be selected at a time, and we only frames
     226             :     // for selectable children.
     227           0 :     SwFEShell* pFEShell = GetFEShell();
     228           0 :     if( pFEShell != 0 )
     229             :     {
     230           0 :         const SwFlyFrm* pFlyFrm = pFEShell->GetCurrFlyFrm();
     231           0 :         if( pFlyFrm )
     232             :         {
     233           0 :             nCount = 1;
     234             :         }
     235             :         else
     236             :         {
     237           0 :             sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
     238           0 :             if( nSelObjs > 0 )
     239             :             {
     240           0 :                 ::std::list< SwAccessibleChild > aChildren;
     241           0 :                 rContext.GetChildren( *(rContext.GetMap()), aChildren );
     242             : 
     243             :                 ::std::list< SwAccessibleChild >::const_iterator aIter =
     244           0 :                     aChildren.begin();
     245             :                 ::std::list< SwAccessibleChild >::const_iterator aEndIter =
     246           0 :                     aChildren.end();
     247           0 :                 while( aIter != aEndIter && nCount < nSelObjs )
     248             :                 {
     249           0 :                     const SwAccessibleChild& rChild = *aIter;
     250           0 :                     if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
     251           0 :                         rContext.GetParent(rChild, rContext.IsInPagePreview())
     252           0 :                            == rContext.GetFrm() &&
     253           0 :                         pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
     254             :                     {
     255           0 :                         nCount++;
     256             :                     }
     257           0 :                     ++aIter;
     258           0 :                 }
     259             :             }
     260             :         }
     261             :         //If the SwFrmOrObj is not selected directly in the UI,
     262             :         //we should check whether it is selected in the selection cursor.
     263           0 :         if( nCount == 0 )
     264             :         {
     265           0 :             ::std::list< SwAccessibleChild > aChildren;
     266           0 :             rContext.GetChildren( *(rContext.GetMap()), aChildren );
     267             :             ::std::list< SwAccessibleChild >::const_iterator aIter =
     268           0 :                 aChildren.begin();
     269             :             ::std::list< SwAccessibleChild >::const_iterator aEndIter =
     270           0 :                 aChildren.end();
     271           0 :             while( aIter != aEndIter )
     272             :             {
     273           0 :                 const SwAccessibleChild& aChild = *aIter;
     274           0 :                 if( lcl_getSelectedState( aChild, &rContext, rContext.GetMap() ) )
     275           0 :                     nCount++;
     276           0 :                 ++aIter;
     277           0 :             }
     278             :         }
     279             :     }
     280           0 :     return nCount;
     281             : }
     282             : 
     283           0 : Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
     284             :     sal_Int32 nSelectedChildIndex )
     285             :     throw ( lang::IndexOutOfBoundsException,
     286             :             RuntimeException)
     287             : {
     288           0 :     SolarMutexGuard aGuard;
     289             : 
     290             :     // Since the index is relative to the selected children, and since
     291             :     // there can be at most one selected frame child, the index must
     292             :     // be 0, and a selection must exist, otherwise we have to throw an
     293             :     // lang::IndexOutOfBoundsException
     294           0 :     SwFEShell* pFEShell = GetFEShell();
     295           0 :     if( 0 == pFEShell )
     296           0 :         throwIndexOutOfBoundsException();
     297             : 
     298           0 :     SwAccessibleChild aChild;
     299           0 :     const SwFlyFrm *pFlyFrm = pFEShell->GetCurrFlyFrm();
     300           0 :     if( pFlyFrm )
     301             :     {
     302           0 :         if( 0 == nSelectedChildIndex )
     303             :         {
     304           0 :             if(rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) == rContext.GetFrm() )
     305             :             {
     306           0 :                 aChild = pFlyFrm;
     307             :             }
     308             :             else
     309             :             {
     310           0 :                 const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     311           0 :                 if (pFrmFmt)
     312             :                 {
     313           0 :                     const SwFmtAnchor& pAnchor = pFrmFmt->GetAnchor();
     314           0 :                     if( pAnchor.GetAnchorId() == FLY_AS_CHAR )
     315             :                     {
     316           0 :                         const SwFrm  *pParaFrm =  rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview() );
     317           0 :                         aChild  = pParaFrm;
     318             :                     }
     319             :                 }
     320             :             }
     321             :         }
     322             :     }
     323             :     else
     324             :     {
     325           0 :         sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
     326           0 :         if( 0 == nSelObjs || nSelectedChildIndex >= nSelObjs )
     327           0 :             throwIndexOutOfBoundsException();
     328             : 
     329           0 :         ::std::list< SwAccessibleChild > aChildren;
     330           0 :         rContext.GetChildren( *(rContext.GetMap()), aChildren );
     331             : 
     332           0 :         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
     333           0 :         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
     334           0 :         while( aIter != aEndIter && !aChild.IsValid() )
     335             :         {
     336           0 :             const SwAccessibleChild& rChild = *aIter;
     337           0 :             if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
     338           0 :                 rContext.GetParent(rChild, rContext.IsInPagePreview()) ==
     339           0 :                     rContext.GetFrm() &&
     340           0 :                 pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
     341             :             {
     342           0 :                 if( 0 == nSelectedChildIndex )
     343           0 :                     aChild = rChild;
     344             :                 else
     345           0 :                     --nSelectedChildIndex;
     346             :             }
     347           0 :             ++aIter;
     348           0 :         }
     349             :     }
     350             : 
     351           0 :     if( !aChild.IsValid() )
     352           0 :         throwIndexOutOfBoundsException();
     353             : 
     354             :     OSL_ENSURE( rContext.GetMap() != NULL, "We need the map." );
     355           0 :     Reference< XAccessible > xChild;
     356           0 :     if( aChild.GetSwFrm() )
     357             :     {
     358             :         ::rtl::Reference < SwAccessibleContext > xChildImpl(
     359             :                 rContext.GetMap()->GetContextImpl( aChild.GetSwFrm(),
     360           0 :                 sal_True ) );
     361           0 :         if( xChildImpl.is() )
     362             :         {
     363           0 :             xChildImpl->SetParent( &rContext );
     364           0 :             xChild = xChildImpl.get();
     365           0 :         }
     366             :     }
     367           0 :     else if ( aChild.GetDrawObject() )
     368             :     {
     369             :         ::rtl::Reference < ::accessibility::AccessibleShape > xChildImpl(
     370             :                 rContext.GetMap()->GetContextImpl( aChild.GetDrawObject(),
     371           0 :                                           &rContext, sal_True )  );
     372           0 :         if( xChildImpl.is() )
     373           0 :             xChild = xChildImpl.get();
     374             :     }
     375           0 :     return xChild;
     376             : }
     377             : 
     378             : // index has to be treated as global child index.
     379           0 : void SwAccessibleSelectionHelper::deselectAccessibleChild(
     380             :     sal_Int32 nChildIndex )
     381             :     throw ( lang::IndexOutOfBoundsException,
     382             :             RuntimeException )
     383             : {
     384           0 :     SolarMutexGuard g;
     385             : 
     386           0 :     if( nChildIndex < 0 ||
     387           0 :         nChildIndex >= rContext.GetChildCount( *(rContext.GetMap()) ) )
     388           0 :         throwIndexOutOfBoundsException();
     389           0 : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10