LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessiblePreviewCell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 135 68.1 %
Date: 2012-08-25 Functions: 14 19 73.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 98 258 38.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "scitems.hxx"
      30                 :            : #include <editeng/eeitem.hxx>
      31                 :            : #include <tools/gen.hxx>
      32                 :            : #include "AccessibleText.hxx"
      33                 :            : #include "editsrc.hxx"
      34                 :            : #include "AccessiblePreviewCell.hxx"
      35                 :            : #include "AccessibilityHints.hxx"
      36                 :            : #include "prevwsh.hxx"
      37                 :            : #include "prevloc.hxx"
      38                 :            : #include "document.hxx"
      39                 :            : #include <svx/AccessibleTextHelper.hxx>
      40                 :            : #include <unotools/accessiblestatesethelper.hxx>
      41                 :            : #include <editeng/brshitem.hxx>
      42                 :            : #include <vcl/window.hxx>
      43                 :            : #include <vcl/svapp.hxx>
      44                 :            : #include <toolkit/helper/convert.hxx>
      45                 :            : #include <comphelper/servicehelper.hxx>
      46                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      47                 :            : 
      48                 :            : using namespace ::com::sun::star;
      49                 :            : using namespace ::com::sun::star::accessibility;
      50                 :            : 
      51                 :            : //=====  internal  ============================================================
      52                 :            : 
      53                 :         22 : ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
      54                 :            :                                 ::com::sun::star::accessibility::XAccessible>& rxParent,
      55                 :            :                             ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
      56                 :            :                             sal_Int32 nIndex ) :
      57                 :            :     ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
      58                 :            :     mpViewShell( pViewShell ),
      59         [ +  - ]:         22 :     mpTextHelper(NULL)
      60                 :            : {
      61         [ +  - ]:         22 :     if (mpViewShell)
      62         [ +  - ]:         22 :         mpViewShell->AddAccessibilityObject(*this);
      63                 :         22 : }
      64                 :            : 
      65                 :         22 : ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
      66                 :            : {
      67 [ -  + ][ #  # ]:         22 :     if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
                 [ -  + ]
      68                 :            :     {
      69                 :            :         // increment refcount to prevent double call off dtor
      70         [ #  # ]:          0 :         osl_incrementInterlockedCount( &m_refCount );
      71                 :            :         // call dispose to inform object wich have a weak reference to this object
      72         [ #  # ]:          0 :         dispose();
      73                 :            :     }
      74         [ -  + ]:         44 : }
      75                 :            : 
      76                 :         22 : void SAL_CALL ScAccessiblePreviewCell::disposing()
      77                 :            : {
      78         [ +  - ]:         22 :     SolarMutexGuard aGuard;
      79         [ +  - ]:         22 :     if (mpViewShell)
      80                 :            :     {
      81         [ +  - ]:         22 :         mpViewShell->RemoveAccessibilityObject(*this);
      82                 :         22 :         mpViewShell = NULL;
      83                 :            :     }
      84                 :            : 
      85         [ +  + ]:         22 :     if (mpTextHelper)
      86 [ +  - ][ +  - ]:         15 :         DELETEZ(mpTextHelper);
      87                 :            : 
      88 [ +  - ][ +  - ]:         22 :     ScAccessibleCellBase::disposing();
      89                 :         22 : }
      90                 :            : 
      91                 :         30 : void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
      92                 :            : {
      93         [ +  + ]:         30 :     if (rHint.ISA( SfxSimpleHint ))
      94                 :            :     {
      95                 :         10 :         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
      96         [ +  - ]:         10 :         if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
      97                 :            :         {
      98         [ +  + ]:         10 :             if (mpTextHelper)
      99                 :          5 :                 mpTextHelper->UpdateChildren();
     100                 :            :         }
     101                 :            :     }
     102                 :            : 
     103                 :         30 :     ScAccessibleContextBase::Notify(rBC, rHint);
     104                 :         30 : }
     105                 :            : 
     106                 :            : //=====  XAccessibleComponent  ============================================
     107                 :            : 
     108                 :          0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
     109                 :            :                                 throw (uno::RuntimeException)
     110                 :            : {
     111                 :          0 :     uno::Reference<XAccessible> xRet;
     112 [ #  # ][ #  # ]:          0 :     if (containsPoint(rPoint))
     113                 :            :     {
     114         [ #  # ]:          0 :          SolarMutexGuard aGuard;
     115         [ #  # ]:          0 :         IsObjectValid();
     116                 :            : 
     117         [ #  # ]:          0 :         if(!mpTextHelper)
     118         [ #  # ]:          0 :             CreateTextHelper();
     119                 :            : 
     120 [ #  # ][ #  # ]:          0 :         xRet = mpTextHelper->GetAt(rPoint);
                 [ #  # ]
     121                 :            :     }
     122                 :            : 
     123                 :          0 :     return xRet;
     124                 :            : }
     125                 :            : 
     126                 :          0 : void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException)
     127                 :            : {
     128         [ #  # ]:          0 :      SolarMutexGuard aGuard;
     129         [ #  # ]:          0 :     IsObjectValid();
     130 [ #  # ][ #  # ]:          0 :     if (getAccessibleParent().is())
     131                 :            :     {
     132 [ #  # ][ #  # ]:          0 :         uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
         [ #  # ][ #  # ]
     133         [ #  # ]:          0 :         if (xAccessibleComponent.is())
     134 [ #  # ][ #  # ]:          0 :             xAccessibleComponent->grabFocus();
     135         [ #  # ]:          0 :     }
     136                 :          0 : }
     137                 :            : 
     138                 :            : //=====  XAccessibleContext  ==============================================
     139                 :            : 
     140                 :         36 : sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException)
     141                 :            : {
     142         [ +  - ]:         36 :     SolarMutexGuard aGuard;
     143         [ +  - ]:         36 :     IsObjectValid();
     144         [ +  + ]:         36 :     if (!mpTextHelper)
     145         [ +  - ]:         15 :         CreateTextHelper();
     146 [ +  - ][ +  - ]:         36 :     return mpTextHelper->GetChildCount();
     147                 :            : }
     148                 :            : 
     149                 :         17 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
     150                 :            :                             throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
     151                 :            : {
     152         [ +  - ]:         17 :     SolarMutexGuard aGuard;
     153         [ +  - ]:         17 :     IsObjectValid();
     154         [ -  + ]:         17 :     if (!mpTextHelper)
     155         [ #  # ]:          0 :         CreateTextHelper();
     156 [ +  - ][ +  - ]:         17 :     return mpTextHelper->GetChild(nIndex);
     157                 :            : }
     158                 :            : 
     159                 :         18 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
     160                 :            :                             throw(uno::RuntimeException)
     161                 :            : {
     162         [ +  - ]:         18 :     SolarMutexGuard aGuard;
     163                 :            : 
     164                 :         18 :     uno::Reference<XAccessibleStateSet> xParentStates;
     165 [ +  - ][ +  - ]:         18 :     if (getAccessibleParent().is())
     166                 :            :     {
     167 [ +  - ][ +  - ]:         18 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
                 [ +  - ]
     168 [ +  - ][ +  - ]:         18 :         xParentStates = xParentContext->getAccessibleStateSet();
                 [ +  - ]
     169                 :            :     }
     170         [ +  - ]:         18 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
     171 [ +  - ][ -  + ]:         18 :     if (IsDefunc(xParentStates))
     172         [ #  # ]:          0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
     173                 :            :     else
     174                 :            :     {
     175         [ +  - ]:         18 :         pStateSet->AddState(AccessibleStateType::ENABLED);
     176         [ +  - ]:         18 :         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
     177 [ +  - ][ -  + ]:         18 :         if (IsOpaque(xParentStates))
     178         [ #  # ]:          0 :             pStateSet->AddState(AccessibleStateType::OPAQUE);
     179 [ +  - ][ -  + ]:         18 :         if (isShowing())
     180         [ #  # ]:          0 :             pStateSet->AddState(AccessibleStateType::SHOWING);
     181         [ +  - ]:         18 :         pStateSet->AddState(AccessibleStateType::TRANSIENT);
     182 [ +  - ][ +  - ]:         18 :         if (isVisible())
     183         [ +  - ]:         18 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
     184                 :            :         // MANAGES_DESCENDANTS (for paragraphs)
     185         [ +  - ]:         18 :         pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
     186                 :            :     }
     187 [ +  - ][ +  - ]:         18 :     return pStateSet;
                 [ +  - ]
     188                 :            : }
     189                 :            : 
     190                 :            : //=====  XServiceInfo  ====================================================
     191                 :            : 
     192                 :         11 : rtl::OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException)
     193                 :            : {
     194                 :         11 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewCell"));
     195                 :            : }
     196                 :            : 
     197                 :          0 : uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
     198                 :            :                                                     throw(uno::RuntimeException)
     199                 :            : {
     200                 :          0 :     uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
     201                 :          0 :     sal_Int32 nOldSize(aSequence.getLength());
     202         [ #  # ]:          0 :     aSequence.realloc(nOldSize + 1);
     203         [ #  # ]:          0 :     ::rtl::OUString* pNames = aSequence.getArray();
     204                 :            : 
     205         [ #  # ]:          0 :     pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
     206                 :            : 
     207                 :          0 :     return aSequence;
     208                 :            : }
     209                 :            : 
     210                 :            : //=====  XTypeProvider  =======================================================
     211                 :            : 
     212                 :            : namespace
     213                 :            : {
     214                 :            :     class theScAccessiblePreviewCellImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePreviewCellImplementationId > {};
     215                 :            : }
     216                 :            : 
     217                 :            : uno::Sequence<sal_Int8> SAL_CALL
     218                 :          0 :     ScAccessiblePreviewCell::getImplementationId(void)
     219                 :            :     throw (uno::RuntimeException)
     220                 :            : {
     221                 :          0 :     return theScAccessiblePreviewCellImplementationId::get().getSeq();
     222                 :            : }
     223                 :            : 
     224                 :            : //====  internal  =========================================================
     225                 :            : 
     226                 :          0 : Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
     227                 :            : {
     228                 :          0 :     Rectangle aCellRect;
     229         [ #  # ]:          0 :     if (mpViewShell)
     230                 :            :     {
     231                 :          0 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     232                 :          0 :         Window* pWindow = mpViewShell->GetWindow();
     233         [ #  # ]:          0 :         if (pWindow)
     234                 :            :         {
     235         [ #  # ]:          0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
     236                 :          0 :             aCellRect.setX(aCellRect.getX() + aRect.getX());
     237                 :          0 :             aCellRect.setY(aCellRect.getY() + aRect.getY());
     238                 :            :         }
     239                 :            :     }
     240                 :          0 :     return aCellRect;
     241                 :            : }
     242                 :            : 
     243                 :         19 : Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException)
     244                 :            : {
     245                 :         19 :     Rectangle aCellRect;
     246         [ +  - ]:         19 :     if (mpViewShell)
     247                 :            :     {
     248 [ +  - ][ +  - ]:         19 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     249         [ +  - ]:         19 :         uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
     250         [ +  - ]:         19 :         if (xAccParent.is())
     251                 :            :         {
     252 [ +  - ][ +  - ]:         19 :             uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
     253         [ +  - ]:         19 :             uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
     254         [ +  - ]:         19 :             if (xAccParentComp.is())
     255                 :            :             {
     256 [ +  - ][ +  - ]:         19 :                 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
                 [ +  - ]
     257                 :         19 :                 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
     258                 :         19 :                 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
     259                 :         19 :             }
     260                 :         19 :         }
     261                 :            :     }
     262                 :         19 :     return aCellRect;
     263                 :            : }
     264                 :            : 
     265                 :         18 : sal_Bool ScAccessiblePreviewCell::IsDefunc(
     266                 :            :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     267                 :            : {
     268 [ +  - ][ +  - ]:         54 :     return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
                 [ #  # ]
     269         [ +  - ]:         54 :          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
           [ +  -  +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
                 [ +  - ]
     270                 :            : }
     271                 :            : 
     272                 :          2 : sal_Bool ScAccessiblePreviewCell::IsEditable(
     273                 :            :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     274                 :            : {
     275                 :          2 :     return false;
     276                 :            : }
     277                 :            : 
     278                 :         18 : sal_Bool ScAccessiblePreviewCell::IsOpaque(
     279                 :            :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     280                 :            : {
     281                 :            :     // test whether there is a background color
     282                 :            :     //! could be moved to ScAccessibleCellBase
     283                 :            : 
     284                 :         18 :     sal_Bool bOpaque(sal_True);
     285         [ +  - ]:         18 :     if (mpDoc)
     286                 :            :     {
     287                 :            :         const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
     288                 :         18 :             maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
     289         [ +  - ]:         18 :         if (pItem)
     290                 :         18 :             bOpaque = pItem->GetColor() != COL_TRANSPARENT;
     291                 :            :     }
     292                 :         18 :     return bOpaque;
     293                 :            : }
     294                 :            : 
     295                 :         15 : void ScAccessiblePreviewCell::CreateTextHelper()
     296                 :            : {
     297         [ +  - ]:         15 :     if (!mpTextHelper)
     298                 :            :     {
     299                 :            :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     300                 :            :         ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
     301 [ +  - ][ +  - ]:         15 :             (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
     302 [ +  - ][ +  - ]:         15 :         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
                 [ +  - ]
     303                 :            :         SAL_WNODEPRECATED_DECLARATIONS_POP
     304                 :            : 
     305 [ +  - ][ +  - ]:         15 :         mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
                 [ +  - ]
     306 [ +  - ][ +  - ]:         15 :         mpTextHelper->SetEventSource( this );
     307                 :            : 
     308                 :            :         // paragraphs in preview are transient
     309         [ +  - ]:         15 :         ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
     310         [ +  - ]:         15 :         aChildStates.push_back( AccessibleStateType::TRANSIENT );
     311 [ +  - ][ +  - ]:         15 :         mpTextHelper->SetAdditionalChildStates( aChildStates );
                 [ +  - ]
     312                 :            :     }
     313                 :         15 : }
     314                 :            : 
     315                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10