LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/access - acccell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 118 147 80.3 %
Date: 2013-07-09 Functions: 20 25 80.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 <osl/mutex.hxx>
      21             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      22             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      23             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      24             : #include <unotools/accessiblestatesethelper.hxx>
      25             : #include <comphelper/servicehelper.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <cellfrm.hxx>
      28             : #include <tabfrm.hxx>
      29             : #include <swtable.hxx>
      30             : #include "crsrsh.hxx"
      31             : #include "viscrs.hxx"
      32             : #include <accfrmobj.hxx>
      33             : #include <accfrmobjslist.hxx>
      34             : #include "frmfmt.hxx"
      35             : #include "cellatr.hxx"
      36             : #include "accmap.hxx"
      37             : #include <acccell.hxx>
      38             : 
      39             : #include <cfloat>
      40             : #include <limits.h>
      41             : 
      42             : using namespace ::com::sun::star;
      43             : using namespace ::com::sun::star::accessibility;
      44             : using namespace sw::access;
      45             : 
      46             : const sal_Char sServiceName[] = "com.sun.star.table.AccessibleCellView";
      47             : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleCellView";
      48             : 
      49          26 : sal_Bool SwAccessibleCell::IsSelected()
      50             : {
      51          26 :     sal_Bool bRet = sal_False;
      52             : 
      53             :     OSL_ENSURE( GetMap(), "no map?" );
      54          26 :     const ViewShell *pVSh = GetMap()->GetShell();
      55             :     OSL_ENSURE( pVSh, "no shell?" );
      56          26 :     if( pVSh->ISA( SwCrsrShell ) )
      57             :     {
      58          26 :         const SwCrsrShell *pCSh = static_cast< const SwCrsrShell * >( pVSh );
      59          26 :         if( pCSh->IsTableMode() )
      60             :         {
      61             :             const SwCellFrm *pCFrm =
      62          18 :                 static_cast< const SwCellFrm * >( GetFrm() );
      63             :             SwTableBox *pBox =
      64          18 :                 const_cast< SwTableBox *>( pCFrm->GetTabBox() );
      65          18 :             SwSelBoxes const& rBoxes(pCSh->GetTableCrsr()->GetSelectedBoxes());
      66          18 :             bRet = rBoxes.find(pBox) != rBoxes.end();
      67             :         }
      68             :     }
      69             : 
      70          26 :     return bRet;
      71             : }
      72             : 
      73           4 : void SwAccessibleCell::GetStates( ::utl::AccessibleStateSetHelper& rStateSet )
      74             : {
      75           4 :     SwAccessibleContext::GetStates( rStateSet );
      76             : 
      77             :     // SELECTABLE
      78           4 :     const ViewShell *pVSh = GetMap()->GetShell();
      79             :     OSL_ENSURE( pVSh, "no shell?" );
      80           4 :     if( pVSh->ISA( SwCrsrShell ) )
      81           4 :         rStateSet.AddState( AccessibleStateType::SELECTABLE );
      82             : 
      83             :     // SELECTED
      84           4 :     if( IsSelected() )
      85             :     {
      86           0 :         rStateSet.AddState( AccessibleStateType::SELECTED );
      87             :         OSL_ENSURE( bIsSelected, "bSelected out of sync" );
      88           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
      89           0 :         GetMap()->SetCursorContext( xThis );
      90             :     }
      91           4 : }
      92             : 
      93           7 : SwAccessibleCell::SwAccessibleCell( SwAccessibleMap *pInitMap,
      94             :                                     const SwCellFrm *pCellFrm )
      95             :     : SwAccessibleContext( pInitMap, AccessibleRole::TABLE_CELL, pCellFrm )
      96           7 :     , bIsSelected( sal_False )
      97             : {
      98           7 :     SolarMutexGuard aGuard;
      99          14 :     OUString sBoxName( pCellFrm->GetTabBox()->GetName() );
     100           7 :     SetName( sBoxName );
     101             : 
     102          14 :     bIsSelected = IsSelected();
     103           7 : }
     104             : 
     105          15 : sal_Bool SwAccessibleCell::_InvalidateMyCursorPos()
     106             : {
     107          15 :     sal_Bool bNew = IsSelected();
     108             :     sal_Bool bOld;
     109             :     {
     110          15 :         osl::MutexGuard aGuard( aMutex );
     111          15 :         bOld = bIsSelected;
     112          15 :         bIsSelected = bNew;
     113             :     }
     114          15 :     if( bNew )
     115             :     {
     116             :         // remember that object as the one that has the caret. This is
     117             :         // necessary to notify that object if the cursor leaves it.
     118          13 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
     119          13 :         GetMap()->SetCursorContext( xThis );
     120             :     }
     121             : 
     122          15 :     sal_Bool bChanged = bOld != bNew;
     123          15 :     if( bChanged )
     124           5 :         FireStateChangedEvent( AccessibleStateType::SELECTED, bNew );
     125             : 
     126          15 :     return bChanged;
     127             : }
     128             : 
     129          30 : sal_Bool SwAccessibleCell::_InvalidateChildrenCursorPos( const SwFrm *pFrm )
     130             : {
     131          30 :     sal_Bool bChanged = sal_False;
     132             : 
     133          30 :     const SwAccessibleChildSList aVisList( GetVisArea(), *pFrm, *GetMap() );
     134          30 :     SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     135         120 :     while( aIter != aVisList.end() )
     136             :     {
     137          60 :         const SwAccessibleChild& rLower = *aIter;
     138          60 :         const SwFrm *pLower = rLower.GetSwFrm();
     139          60 :         if( pLower )
     140             :         {
     141          60 :             if( rLower.IsAccessible( GetMap()->GetShell()->IsPreView() )  )
     142             :             {
     143             :                 ::rtl::Reference< SwAccessibleContext > xAccImpl(
     144          40 :                     GetMap()->GetContextImpl( pLower, sal_False ) );
     145          40 :                 if( xAccImpl.is() )
     146             :                 {
     147             :                     OSL_ENSURE( xAccImpl->GetFrm()->IsCellFrm(),
     148             :                              "table child is not a cell frame" );
     149             :                     bChanged |= static_cast< SwAccessibleCell *>(
     150          15 :                             xAccImpl.get() )->_InvalidateMyCursorPos();
     151             :                 }
     152             :                 else
     153          25 :                     bChanged = sal_True; // If the context is not know we
     154             :                                          // don't know whether the selection
     155             :                                          // changed or not.
     156             :             }
     157             :             else
     158             :             {
     159             :                 // This is a box with sub rows.
     160          20 :                 bChanged |= _InvalidateChildrenCursorPos( pLower );
     161             :             }
     162             :         }
     163          60 :         ++aIter;
     164             :     }
     165             : 
     166          30 :     return bChanged;
     167             : }
     168             : 
     169          10 : void SwAccessibleCell::_InvalidateCursorPos()
     170             : {
     171             : 
     172          10 :     const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
     173             :     OSL_ENSURE( pParent->IsTabFrm(), "parent is not a tab frame" );
     174          10 :     const SwTabFrm *pTabFrm = static_cast< const SwTabFrm * >( pParent );
     175          10 :     if( pTabFrm->IsFollow() )
     176           0 :         pTabFrm = pTabFrm->FindMaster();
     177             : 
     178          30 :     while( pTabFrm )
     179             :     {
     180          10 :         sal_Bool bChanged = _InvalidateChildrenCursorPos( pTabFrm );
     181          10 :         if( bChanged )
     182             :         {
     183             :             ::rtl::Reference< SwAccessibleContext > xAccImpl(
     184          10 :                 GetMap()->GetContextImpl( pTabFrm, sal_False ) );
     185          10 :             if( xAccImpl.is() )
     186             :             {
     187          10 :                 AccessibleEventObject aEvent;
     188          10 :                 aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
     189          10 :                 xAccImpl->FireAccessibleEvent( aEvent );
     190          10 :             }
     191             :         }
     192             : 
     193          10 :         pTabFrm = pTabFrm->GetFollow();
     194             :     }
     195          10 : }
     196             : 
     197           7 : sal_Bool SwAccessibleCell::HasCursor()
     198             : {
     199           7 :     osl::MutexGuard aGuard( aMutex );
     200           7 :     return bIsSelected;
     201             : }
     202             : 
     203          14 : SwAccessibleCell::~SwAccessibleCell()
     204             : {
     205          14 : }
     206             : 
     207           7 : OUString SAL_CALL SwAccessibleCell::getAccessibleDescription (void)
     208             :         throw (uno::RuntimeException)
     209             : {
     210           7 :     return GetName();
     211             : }
     212             : 
     213           3 : OUString SAL_CALL SwAccessibleCell::getImplementationName()
     214             :         throw( uno::RuntimeException )
     215             : {
     216           3 :     return OUString(sImplementationName);
     217             : }
     218             : 
     219           0 : sal_Bool SAL_CALL SwAccessibleCell::supportsService(
     220             :         const OUString& sTestServiceName)
     221             :     throw (uno::RuntimeException)
     222             : {
     223             :     return sTestServiceName.equalsAsciiL( sServiceName,
     224           0 :                                           sizeof(sServiceName)-1 ) ||
     225             :            sTestServiceName.equalsAsciiL( sAccessibleServiceName,
     226           0 :                                              sizeof(sAccessibleServiceName)-1 );
     227             : }
     228             : 
     229           0 : uno::Sequence< OUString > SAL_CALL SwAccessibleCell::getSupportedServiceNames()
     230             :         throw( uno::RuntimeException )
     231             : {
     232           0 :     uno::Sequence< OUString > aRet(2);
     233           0 :     OUString* pArray = aRet.getArray();
     234           0 :     pArray[0] = OUString(sServiceName );
     235           0 :     pArray[1] = OUString(sAccessibleServiceName );
     236           0 :     return aRet;
     237             : }
     238             : 
     239           2 : void SwAccessibleCell::Dispose( sal_Bool bRecursive )
     240             : {
     241           2 :     const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
     242             :     ::rtl::Reference< SwAccessibleContext > xAccImpl(
     243           2 :             GetMap()->GetContextImpl( pParent, sal_False ) );
     244           2 :     if( xAccImpl.is() )
     245           2 :         xAccImpl->DisposeChild( SwAccessibleChild(GetFrm()), bRecursive );
     246           2 :     SwAccessibleContext::Dispose( bRecursive );
     247           2 : }
     248             : 
     249           0 : void SwAccessibleCell::InvalidatePosOrSize( const SwRect& rOldBox )
     250             : {
     251           0 :     const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
     252             :     ::rtl::Reference< SwAccessibleContext > xAccImpl(
     253           0 :             GetMap()->GetContextImpl( pParent, sal_False ) );
     254           0 :     if( xAccImpl.is() )
     255           0 :         xAccImpl->InvalidateChildPosOrSize( SwAccessibleChild(GetFrm()), rOldBox );
     256           0 :     SwAccessibleContext::InvalidatePosOrSize( rOldBox );
     257           0 : }
     258             : 
     259             : 
     260             : // XAccessibleInterface
     261             : 
     262          88 : uno::Any SwAccessibleCell::queryInterface( const uno::Type& rType )
     263             :     throw( uno::RuntimeException )
     264             : {
     265          88 :     if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleValue > * >( 0 ) ) )
     266             :     {
     267           1 :         uno::Reference<XAccessibleValue> xValue = this;
     268           2 :         uno::Any aRet;
     269           1 :         aRet <<= xValue;
     270           2 :         return aRet;
     271             :     }
     272             :     else
     273             :     {
     274          87 :         return SwAccessibleContext::queryInterface( rType );
     275             :     }
     276             : }
     277             : 
     278             : // XTypeProvider
     279           0 : uno::Sequence< uno::Type > SAL_CALL SwAccessibleCell::getTypes()
     280             :     throw(uno::RuntimeException)
     281             : {
     282           0 :     uno::Sequence< uno::Type > aTypes( SwAccessibleContext::getTypes() );
     283             : 
     284           0 :     sal_Int32 nIndex = aTypes.getLength();
     285           0 :     aTypes.realloc( nIndex + 1 );
     286             : 
     287           0 :     uno::Type* pTypes = aTypes.getArray();
     288           0 :     pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleValue > * >( 0 ) );
     289             : 
     290           0 :     return aTypes;
     291             : }
     292             : 
     293             : namespace
     294             : {
     295             :     class theSwAccessibleCellImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleCellImplementationId > {};
     296             : }
     297             : 
     298           0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleCell::getImplementationId()
     299             :         throw(uno::RuntimeException)
     300             : {
     301           0 :     return theSwAccessibleCellImplementationId::get().getSeq();
     302             : }
     303             : 
     304             : // XAccessibleValue
     305             : 
     306          11 : SwFrmFmt* SwAccessibleCell::GetTblBoxFormat() const
     307             : {
     308             :     OSL_ENSURE( GetFrm() != NULL, "no frame?" );
     309             :     OSL_ENSURE( GetFrm()->IsCellFrm(), "no cell frame?" );
     310             : 
     311          11 :     const SwCellFrm* pCellFrm = static_cast<const SwCellFrm*>( GetFrm() );
     312          11 :     return pCellFrm->GetTabBox()->GetFrmFmt();
     313             : }
     314             : 
     315             : 
     316           6 : uno::Any SwAccessibleCell::getCurrentValue( )
     317             :     throw( uno::RuntimeException )
     318             : {
     319           6 :     SolarMutexGuard aGuard;
     320           6 :     CHECK_FOR_DEFUNC( XAccessibleValue );
     321             : 
     322           6 :     uno::Any aAny;
     323           6 :     aAny <<= GetTblBoxFormat()->GetTblBoxValue().GetValue();
     324           6 :     return aAny;
     325             : }
     326             : 
     327           5 : sal_Bool SwAccessibleCell::setCurrentValue( const uno::Any& aNumber )
     328             :     throw( uno::RuntimeException )
     329             : {
     330           5 :     SolarMutexGuard aGuard;
     331           5 :     CHECK_FOR_DEFUNC( XAccessibleValue );
     332             : 
     333           5 :     double fValue = 0;
     334           5 :     sal_Bool bValid = (aNumber >>= fValue);
     335           5 :     if( bValid )
     336             :     {
     337           5 :         SwTblBoxValue aValue( fValue );
     338           5 :         GetTblBoxFormat()->SetFmtAttr( aValue );
     339             :     }
     340           5 :     return bValid;
     341             : }
     342             : 
     343           1 : uno::Any SwAccessibleCell::getMaximumValue( )
     344             :     throw( uno::RuntimeException )
     345             : {
     346           1 :     uno::Any aAny;
     347           1 :     aAny <<= DBL_MAX;
     348           1 :     return aAny;
     349             : }
     350             : 
     351           1 : uno::Any SwAccessibleCell::getMinimumValue(  )
     352             :     throw( uno::RuntimeException )
     353             : {
     354           1 :     uno::Any aAny;
     355           1 :     aAny <<= -DBL_MAX;
     356           1 :     return aAny;
     357          99 : }
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10