LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/access - accselectionhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 140 49.3 %
Date: 2013-07-09 Functions: 13 13 100.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>        // for SolarMutex
      29             : #include <flyfrm.hxx>
      30             : 
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::uno;
      34             : 
      35             : using ::com::sun::star::accessibility::XAccessible;
      36             : using ::com::sun::star::accessibility::XAccessibleContext;
      37             : using ::com::sun::star::accessibility::XAccessibleSelection;
      38             : 
      39             : using namespace ::sw::access;
      40             : 
      41          29 : SwAccessibleSelectionHelper::SwAccessibleSelectionHelper(
      42             :     SwAccessibleContext& rCtxt ) :
      43          29 :         rContext( rCtxt )
      44             : {
      45          29 : }
      46             : 
      47          29 : SwAccessibleSelectionHelper::~SwAccessibleSelectionHelper()
      48             : {
      49          29 : }
      50             : 
      51          10 : SwFEShell* SwAccessibleSelectionHelper::GetFEShell()
      52             : {
      53             :     OSL_ENSURE( rContext.GetMap() != NULL, "no map?" );
      54          10 :     ViewShell* pViewShell = rContext.GetMap()->GetShell();
      55             :     OSL_ENSURE( pViewShell != NULL,
      56             :                 "No view shell? Then what are you looking at?" );
      57             : 
      58          10 :     SwFEShell* pFEShell = NULL;
      59          10 :     if( pViewShell->ISA( SwFEShell ) )
      60             :     {
      61          10 :         pFEShell = static_cast<SwFEShell*>( pViewShell );
      62             :     }
      63             : 
      64          10 :     return pFEShell;
      65             : }
      66             : 
      67           8 : void SwAccessibleSelectionHelper::throwIndexOutOfBoundsException()
      68             :         throw ( lang::IndexOutOfBoundsException )
      69             : {
      70           8 :     Reference < XAccessibleContext > xThis( &rContext );
      71          16 :     Reference < XAccessibleSelection >xSelThis( xThis, UNO_QUERY );
      72             :     lang::IndexOutOfBoundsException aExcept(
      73             :                 OUString( "index out of bounds" ),
      74          16 :                 xSelThis );                                     \
      75          16 :     throw aExcept;
      76             : }
      77             : 
      78             : 
      79             : // XAccessibleSelection
      80           2 : void SwAccessibleSelectionHelper::selectAccessibleChild(
      81             :     sal_Int32 nChildIndex )
      82             :     throw ( lang::IndexOutOfBoundsException,
      83             :             RuntimeException )
      84             : {
      85           2 :     SolarMutexGuard aGuard;
      86             : 
      87             :     // Get the respective child as SwFrm (also do index checking), ...
      88           2 :     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
      89           2 :                                                         nChildIndex );
      90           2 :     if( !aChild.IsValid() )
      91           2 :         throwIndexOutOfBoundsException();
      92             : 
      93             :     // we can only select fly frames, so we ignore (should: return
      94             :     // false) all other attempts at child selection
      95           0 :     SwFEShell* pFEShell = GetFEShell();
      96           0 :     if( pFEShell != NULL )
      97             :     {
      98           0 :         const SdrObject *pObj = aChild.GetDrawObject();
      99           0 :         if( pObj )
     100           0 :             rContext.Select( const_cast< SdrObject *>( pObj ), 0==aChild.GetSwFrm());
     101           2 :     }
     102             :     // no frame shell, or no frame, or no fly frame -> can't select
     103           0 : }
     104             : 
     105           2 : sal_Bool SwAccessibleSelectionHelper::isAccessibleChildSelected(
     106             :     sal_Int32 nChildIndex )
     107             :     throw ( lang::IndexOutOfBoundsException,
     108             :             RuntimeException )
     109             : {
     110           2 :     SolarMutexGuard aGuard;
     111             : 
     112             :     // Get the respective child as SwFrm (also do index checking), ...
     113           2 :     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
     114           2 :                                                         nChildIndex );
     115           2 :     if( !aChild.IsValid() )
     116           2 :         throwIndexOutOfBoundsException();
     117             : 
     118             :     // ... and compare to the currently selected frame
     119           0 :     sal_Bool bRet = sal_False;
     120           0 :     SwFEShell* pFEShell = GetFEShell();
     121           0 :     if( pFEShell )
     122             :     {
     123           0 :         if ( aChild.GetSwFrm() != 0 )
     124             :         {
     125           0 :             bRet = (pFEShell->GetCurrFlyFrm() == aChild.GetSwFrm());
     126             :         }
     127           0 :         else if ( aChild.GetDrawObject() )
     128             :         {
     129           0 :             bRet = pFEShell->IsObjSelected( *aChild.GetDrawObject() );
     130             :         }
     131             :     }
     132             : 
     133           0 :     return bRet;
     134             : }
     135             : 
     136           2 : void SwAccessibleSelectionHelper::clearAccessibleSelection(  )
     137             :     throw ( RuntimeException )
     138             : {
     139             :     // return sal_False     // we can't deselect
     140           2 : }
     141             : 
     142           3 : void SwAccessibleSelectionHelper::selectAllAccessibleChildren(  )
     143             :     throw ( RuntimeException )
     144             : {
     145           3 :     SolarMutexGuard aGuard;
     146             : 
     147             :     // We can select only one. So iterate over the children to find
     148             :     // the first we can select, and select it.
     149             : 
     150           3 :     SwFEShell* pFEShell = GetFEShell();
     151           3 :     if( pFEShell )
     152             :     {
     153           3 :         ::std::list< SwAccessibleChild > aChildren;
     154           3 :         rContext.GetChildren( *(rContext.GetMap()), aChildren );
     155             : 
     156           3 :         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
     157           3 :         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
     158           6 :         while( aIter != aEndIter )
     159             :         {
     160           0 :             const SwAccessibleChild& rChild = *aIter;
     161           0 :             const SdrObject* pObj = rChild.GetDrawObject();
     162           0 :             const SwFrm* pFrm = rChild.GetSwFrm();
     163           0 :             if( pObj && !(pFrm != 0 && pFEShell->IsObjSelected()) )
     164             :             {
     165           0 :                 rContext.Select( const_cast< SdrObject *>( pObj ), 0==pFrm );
     166           0 :                 if( pFrm )
     167           0 :                     break;
     168             :             }
     169           0 :             ++aIter;
     170           3 :         }
     171           3 :     }
     172           3 : }
     173             : 
     174           5 : sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount(  )
     175             :     throw ( RuntimeException )
     176             : {
     177           5 :     SolarMutexGuard aGuard;
     178             : 
     179           5 :     sal_Int32 nCount = 0;
     180             :     // Only one frame can be selected at a time, and we only frames
     181             :     // for selectable children.
     182           5 :     SwFEShell* pFEShell = GetFEShell();
     183           5 :     if( pFEShell != 0 )
     184             :     {
     185           5 :         const SwFlyFrm* pFlyFrm = pFEShell->GetCurrFlyFrm();
     186           5 :         if( pFlyFrm )
     187             :         {
     188           0 :             if( rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) ==
     189           0 :                     rContext.GetFrm() )
     190             :             {
     191           0 :                 nCount = 1;
     192             :             }
     193             :         }
     194             :         else
     195             :         {
     196           5 :             sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
     197           5 :             if( nSelObjs > 0 )
     198             :             {
     199           0 :                 ::std::list< SwAccessibleChild > aChildren;
     200           0 :                 rContext.GetChildren( *(rContext.GetMap()), aChildren );
     201             : 
     202             :                 ::std::list< SwAccessibleChild >::const_iterator aIter =
     203           0 :                     aChildren.begin();
     204             :                 ::std::list< SwAccessibleChild >::const_iterator aEndIter =
     205           0 :                     aChildren.end();
     206           0 :                 while( aIter != aEndIter && nCount < nSelObjs )
     207             :                 {
     208           0 :                     const SwAccessibleChild& rChild = *aIter;
     209           0 :                     if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
     210           0 :                         rContext.GetParent(rChild, rContext.IsInPagePreview())
     211           0 :                            == rContext.GetFrm() &&
     212           0 :                         pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
     213             :                     {
     214           0 :                         nCount++;
     215             :                     }
     216           0 :                     ++aIter;
     217           0 :                 }
     218             :             }
     219             :         }
     220             :     }
     221           5 :     return nCount;
     222             : }
     223             : 
     224           2 : Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
     225             :     sal_Int32 nSelectedChildIndex )
     226             :     throw ( lang::IndexOutOfBoundsException,
     227             :             RuntimeException)
     228             : {
     229           2 :     SolarMutexGuard aGuard;
     230             : 
     231             :     // Since the index is relative to the selected children, and since
     232             :     // there can be at most one selected frame child, the index must
     233             :     // be 0, and a selection must exist, otherwise we have to throw an
     234             :     // lang::IndexOutOfBoundsException
     235           2 :     SwFEShell* pFEShell = GetFEShell();
     236           2 :     if( 0 == pFEShell )
     237           0 :         throwIndexOutOfBoundsException();
     238             : 
     239           2 :     SwAccessibleChild aChild;
     240           2 :     const SwFlyFrm *pFlyFrm = pFEShell->GetCurrFlyFrm();
     241           2 :     if( pFlyFrm )
     242             :     {
     243           0 :         if( 0 == nSelectedChildIndex &&
     244           0 :             rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) ==
     245           0 :                 rContext.GetFrm() )
     246             :         {
     247           0 :             aChild = pFlyFrm;
     248             :         }
     249             :     }
     250             :     else
     251             :     {
     252           2 :         sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
     253           2 :         if( 0 == nSelObjs || nSelectedChildIndex >= nSelObjs )
     254           2 :             throwIndexOutOfBoundsException();
     255             : 
     256           0 :         ::std::list< SwAccessibleChild > aChildren;
     257           0 :         rContext.GetChildren( *(rContext.GetMap()), aChildren );
     258             : 
     259           0 :         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
     260           0 :         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
     261           0 :         while( aIter != aEndIter && !aChild.IsValid() )
     262             :         {
     263           0 :             const SwAccessibleChild& rChild = *aIter;
     264           0 :             if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
     265           0 :                 rContext.GetParent(rChild, rContext.IsInPagePreview()) ==
     266           0 :                     rContext.GetFrm() &&
     267           0 :                 pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
     268             :             {
     269           0 :                 if( 0 == nSelectedChildIndex )
     270           0 :                     aChild = rChild;
     271             :                 else
     272           0 :                     --nSelectedChildIndex;
     273             :             }
     274           0 :             ++aIter;
     275           0 :         }
     276             :     }
     277             : 
     278           0 :     if( !aChild.IsValid() )
     279           0 :         throwIndexOutOfBoundsException();
     280             : 
     281             :     OSL_ENSURE( rContext.GetMap() != NULL, "We need the map." );
     282           0 :     Reference< XAccessible > xChild;
     283           0 :     if( aChild.GetSwFrm() )
     284             :     {
     285             :         ::rtl::Reference < SwAccessibleContext > xChildImpl(
     286             :                 rContext.GetMap()->GetContextImpl( aChild.GetSwFrm(),
     287           0 :                 sal_True ) );
     288           0 :         if( xChildImpl.is() )
     289             :         {
     290           0 :             xChildImpl->SetParent( &rContext );
     291           0 :             xChild = xChildImpl.get();
     292           0 :         }
     293             :     }
     294           0 :     else if ( aChild.GetDrawObject() )
     295             :     {
     296             :         ::rtl::Reference < ::accessibility::AccessibleShape > xChildImpl(
     297             :                 rContext.GetMap()->GetContextImpl( aChild.GetDrawObject(),
     298           0 :                                           &rContext, sal_True )  );
     299           0 :         if( xChildImpl.is() )
     300           0 :             xChild = xChildImpl.get();
     301             :     }
     302           2 :     return xChild;
     303             : }
     304             : 
     305             : // index has to be treated as global child index.
     306           2 : void SwAccessibleSelectionHelper::deselectAccessibleChild(
     307             :     sal_Int32 nChildIndex )
     308             :     throw ( lang::IndexOutOfBoundsException,
     309             :             RuntimeException )
     310             : {
     311           3 :     if( nChildIndex < 0 ||
     312           1 :         nChildIndex >= rContext.GetChildCount( *(rContext.GetMap()) ) )
     313           2 :         throwIndexOutOfBoundsException();
     314          99 : }
     315             : 
     316             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10