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

Generated by: LCOV version 1.10