LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessiblePreviewCell.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 92 134 68.7 %
Date: 2014-04-11 Functions: 16 21 76.2 %
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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : #include <tools/gen.hxx>
      23             : #include "AccessibleText.hxx"
      24             : #include "editsrc.hxx"
      25             : #include "AccessiblePreviewCell.hxx"
      26             : #include "AccessibilityHints.hxx"
      27             : #include "prevwsh.hxx"
      28             : #include "prevloc.hxx"
      29             : #include "document.hxx"
      30             : #include <svx/AccessibleTextHelper.hxx>
      31             : #include <unotools/accessiblestatesethelper.hxx>
      32             : #include <editeng/brushitem.hxx>
      33             : #include <vcl/window.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : #include <toolkit/helper/convert.hxx>
      36             : #include <comphelper/servicehelper.hxx>
      37             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::accessibility;
      41             : 
      42             : //=====  internal  ============================================================
      43             : 
      44          11 : ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
      45             :                                 ::com::sun::star::accessibility::XAccessible>& rxParent,
      46             :                             ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
      47             :                             sal_Int32 nIndex ) :
      48             :     ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
      49             :     mpViewShell( pViewShell ),
      50          11 :     mpTextHelper(NULL)
      51             : {
      52          11 :     if (mpViewShell)
      53          11 :         mpViewShell->AddAccessibilityObject(*this);
      54          11 : }
      55             : 
      56          33 : ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
      57             : {
      58          11 :     if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
      59             :     {
      60             :         // increment refcount to prevent double call off dtor
      61           0 :         osl_atomic_increment( &m_refCount );
      62             :         // call dispose to inform object which have a weak reference to this object
      63           0 :         dispose();
      64             :     }
      65          22 : }
      66             : 
      67          11 : void SAL_CALL ScAccessiblePreviewCell::disposing()
      68             : {
      69          11 :     SolarMutexGuard aGuard;
      70          11 :     if (mpViewShell)
      71             :     {
      72          11 :         mpViewShell->RemoveAccessibilityObject(*this);
      73          11 :         mpViewShell = NULL;
      74             :     }
      75             : 
      76          11 :     if (mpTextHelper)
      77           7 :         DELETEZ(mpTextHelper);
      78             : 
      79          11 :     ScAccessibleCellBase::disposing();
      80          11 : }
      81             : 
      82          20 : void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
      83             : {
      84          20 :     if (rHint.ISA( SfxSimpleHint ))
      85             :     {
      86          10 :         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
      87          10 :         if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
      88             :         {
      89          10 :             if (mpTextHelper)
      90           5 :                 mpTextHelper->UpdateChildren();
      91             :         }
      92             :     }
      93             : 
      94          20 :     ScAccessibleContextBase::Notify(rBC, rHint);
      95          20 : }
      96             : 
      97             : //=====  XAccessibleComponent  ============================================
      98             : 
      99           0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
     100             :                                 throw (uno::RuntimeException, std::exception)
     101             : {
     102           0 :     uno::Reference<XAccessible> xRet;
     103           0 :     if (containsPoint(rPoint))
     104             :     {
     105           0 :          SolarMutexGuard aGuard;
     106           0 :         IsObjectValid();
     107             : 
     108           0 :         if(!mpTextHelper)
     109           0 :             CreateTextHelper();
     110             : 
     111           0 :         xRet = mpTextHelper->GetAt(rPoint);
     112             :     }
     113             : 
     114           0 :     return xRet;
     115             : }
     116             : 
     117           0 : void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException, std::exception)
     118             : {
     119           0 :      SolarMutexGuard aGuard;
     120           0 :     IsObjectValid();
     121           0 :     if (getAccessibleParent().is())
     122             :     {
     123           0 :         uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
     124           0 :         if (xAccessibleComponent.is())
     125           0 :             xAccessibleComponent->grabFocus();
     126           0 :     }
     127           0 : }
     128             : 
     129             : //=====  XAccessibleContext  ==============================================
     130             : 
     131          17 : sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException, std::exception)
     132             : {
     133          17 :     SolarMutexGuard aGuard;
     134          17 :     IsObjectValid();
     135          17 :     if (!mpTextHelper)
     136           7 :         CreateTextHelper();
     137          17 :     return mpTextHelper->GetChildCount();
     138             : }
     139             : 
     140           7 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
     141             :                             throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     142             : {
     143           7 :     SolarMutexGuard aGuard;
     144           7 :     IsObjectValid();
     145           7 :     if (!mpTextHelper)
     146           0 :         CreateTextHelper();
     147           7 :     return mpTextHelper->GetChild(nIndex);
     148             : }
     149             : 
     150          16 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
     151             :                             throw(uno::RuntimeException, std::exception)
     152             : {
     153          16 :     SolarMutexGuard aGuard;
     154             : 
     155          32 :     uno::Reference<XAccessibleStateSet> xParentStates;
     156          16 :     if (getAccessibleParent().is())
     157             :     {
     158          16 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
     159          16 :         xParentStates = xParentContext->getAccessibleStateSet();
     160             :     }
     161          16 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
     162          16 :     if (IsDefunc(xParentStates))
     163           0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
     164             :     else
     165             :     {
     166          16 :         pStateSet->AddState(AccessibleStateType::ENABLED);
     167          16 :         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
     168          16 :         if (IsOpaque(xParentStates))
     169           0 :             pStateSet->AddState(AccessibleStateType::OPAQUE);
     170          16 :         if (isShowing())
     171           0 :             pStateSet->AddState(AccessibleStateType::SHOWING);
     172          16 :         pStateSet->AddState(AccessibleStateType::TRANSIENT);
     173          16 :         if (isVisible())
     174          16 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
     175             :         // MANAGES_DESCENDANTS (for paragraphs)
     176          16 :         pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
     177             :     }
     178          32 :     return pStateSet;
     179             : }
     180             : 
     181             : //=====  XServiceInfo  ====================================================
     182             : 
     183           6 : OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException, std::exception)
     184             : {
     185           6 :     return OUString("ScAccessiblePreviewCell");
     186             : }
     187             : 
     188           0 : uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
     189             :                                                     throw(uno::RuntimeException, std::exception)
     190             : {
     191           0 :     uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
     192           0 :     sal_Int32 nOldSize(aSequence.getLength());
     193           0 :     aSequence.realloc(nOldSize + 1);
     194             : 
     195           0 :     aSequence[nOldSize] = "com.sun.star.table.AccessibleCellView";
     196             : 
     197           0 :     return aSequence;
     198             : }
     199             : 
     200             : //=====  XTypeProvider  =======================================================
     201             : 
     202             : uno::Sequence<sal_Int8> SAL_CALL
     203           0 :     ScAccessiblePreviewCell::getImplementationId(void)
     204             :     throw (uno::RuntimeException, std::exception)
     205             : {
     206           0 :     return css::uno::Sequence<sal_Int8>();
     207             : }
     208             : 
     209             : //====  internal  =========================================================
     210             : 
     211           0 : Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException, std::exception)
     212             : {
     213           0 :     Rectangle aCellRect;
     214           0 :     if (mpViewShell)
     215             :     {
     216           0 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     217           0 :         Window* pWindow = mpViewShell->GetWindow();
     218           0 :         if (pWindow)
     219             :         {
     220           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
     221           0 :             aCellRect.setX(aCellRect.getX() + aRect.getX());
     222           0 :             aCellRect.setY(aCellRect.getY() + aRect.getY());
     223             :         }
     224             :     }
     225           0 :     return aCellRect;
     226             : }
     227             : 
     228          17 : Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException, std::exception)
     229             : {
     230          17 :     Rectangle aCellRect;
     231          17 :     if (mpViewShell)
     232             :     {
     233          17 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     234          17 :         uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
     235          17 :         if (xAccParent.is())
     236             :         {
     237          17 :             uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
     238          34 :             uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
     239          17 :             if (xAccParentComp.is())
     240             :             {
     241          17 :                 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
     242          17 :                 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
     243          17 :                 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
     244          17 :             }
     245          17 :         }
     246             :     }
     247          17 :     return aCellRect;
     248             : }
     249             : 
     250          16 : bool ScAccessiblePreviewCell::IsDefunc(
     251             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     252             : {
     253          64 :     return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
     254          64 :          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
     255             : }
     256             : 
     257           1 : bool ScAccessiblePreviewCell::IsEditable(
     258             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     259             : {
     260           1 :     return false;
     261             : }
     262             : 
     263          16 : bool ScAccessiblePreviewCell::IsOpaque(
     264             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     265             : {
     266             :     // test whether there is a background color
     267             :     //! could be moved to ScAccessibleCellBase
     268             : 
     269          16 :     bool bOpaque(true);
     270          16 :     if (mpDoc)
     271             :     {
     272             :         const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
     273          16 :             maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
     274          16 :         if (pItem)
     275          16 :             bOpaque = pItem->GetColor() != COL_TRANSPARENT;
     276             :     }
     277          16 :     return bOpaque;
     278             : }
     279             : 
     280           7 : void ScAccessiblePreviewCell::CreateTextHelper()
     281             : {
     282           7 :     if (!mpTextHelper)
     283             :     {
     284             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     285             :         ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
     286           7 :             (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
     287          14 :         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
     288             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     289             : 
     290           7 :         mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
     291           7 :         mpTextHelper->SetEventSource( this );
     292             : 
     293             :         // paragraphs in preview are transient
     294          14 :         ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
     295           7 :         aChildStates.push_back( AccessibleStateType::TRANSIENT );
     296          14 :         mpTextHelper->SetAdditionalChildStates( aChildStates );
     297             :     }
     298         109 : }
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10