LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessiblePreviewCell.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 134 0.0 %
Date: 2014-04-14 Functions: 0 21 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 "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           0 : 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           0 :     mpTextHelper(NULL)
      51             : {
      52           0 :     if (mpViewShell)
      53           0 :         mpViewShell->AddAccessibilityObject(*this);
      54           0 : }
      55             : 
      56           0 : ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
      57             : {
      58           0 :     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           0 : }
      66             : 
      67           0 : void SAL_CALL ScAccessiblePreviewCell::disposing()
      68             : {
      69           0 :     SolarMutexGuard aGuard;
      70           0 :     if (mpViewShell)
      71             :     {
      72           0 :         mpViewShell->RemoveAccessibilityObject(*this);
      73           0 :         mpViewShell = NULL;
      74             :     }
      75             : 
      76           0 :     if (mpTextHelper)
      77           0 :         DELETEZ(mpTextHelper);
      78             : 
      79           0 :     ScAccessibleCellBase::disposing();
      80           0 : }
      81             : 
      82           0 : void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
      83             : {
      84           0 :     if (rHint.ISA( SfxSimpleHint ))
      85             :     {
      86           0 :         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
      87           0 :         if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
      88             :         {
      89           0 :             if (mpTextHelper)
      90           0 :                 mpTextHelper->UpdateChildren();
      91             :         }
      92             :     }
      93             : 
      94           0 :     ScAccessibleContextBase::Notify(rBC, rHint);
      95           0 : }
      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           0 : sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException, std::exception)
     132             : {
     133           0 :     SolarMutexGuard aGuard;
     134           0 :     IsObjectValid();
     135           0 :     if (!mpTextHelper)
     136           0 :         CreateTextHelper();
     137           0 :     return mpTextHelper->GetChildCount();
     138             : }
     139             : 
     140           0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
     141             :                             throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     142             : {
     143           0 :     SolarMutexGuard aGuard;
     144           0 :     IsObjectValid();
     145           0 :     if (!mpTextHelper)
     146           0 :         CreateTextHelper();
     147           0 :     return mpTextHelper->GetChild(nIndex);
     148             : }
     149             : 
     150           0 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
     151             :                             throw(uno::RuntimeException, std::exception)
     152             : {
     153           0 :     SolarMutexGuard aGuard;
     154             : 
     155           0 :     uno::Reference<XAccessibleStateSet> xParentStates;
     156           0 :     if (getAccessibleParent().is())
     157             :     {
     158           0 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
     159           0 :         xParentStates = xParentContext->getAccessibleStateSet();
     160             :     }
     161           0 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
     162           0 :     if (IsDefunc(xParentStates))
     163           0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
     164             :     else
     165             :     {
     166           0 :         pStateSet->AddState(AccessibleStateType::ENABLED);
     167           0 :         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
     168           0 :         if (IsOpaque(xParentStates))
     169           0 :             pStateSet->AddState(AccessibleStateType::OPAQUE);
     170           0 :         if (isShowing())
     171           0 :             pStateSet->AddState(AccessibleStateType::SHOWING);
     172           0 :         pStateSet->AddState(AccessibleStateType::TRANSIENT);
     173           0 :         if (isVisible())
     174           0 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
     175             :         // MANAGES_DESCENDANTS (for paragraphs)
     176           0 :         pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
     177             :     }
     178           0 :     return pStateSet;
     179             : }
     180             : 
     181             : //=====  XServiceInfo  ====================================================
     182             : 
     183           0 : OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException, std::exception)
     184             : {
     185           0 :     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           0 : Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException, std::exception)
     229             : {
     230           0 :     Rectangle aCellRect;
     231           0 :     if (mpViewShell)
     232             :     {
     233           0 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     234           0 :         uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
     235           0 :         if (xAccParent.is())
     236             :         {
     237           0 :             uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
     238           0 :             uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
     239           0 :             if (xAccParentComp.is())
     240             :             {
     241           0 :                 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
     242           0 :                 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
     243           0 :                 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
     244           0 :             }
     245           0 :         }
     246             :     }
     247           0 :     return aCellRect;
     248             : }
     249             : 
     250           0 : bool ScAccessiblePreviewCell::IsDefunc(
     251             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     252             : {
     253           0 :     return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
     254           0 :          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
     255             : }
     256             : 
     257           0 : bool ScAccessiblePreviewCell::IsEditable(
     258             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     259             : {
     260           0 :     return false;
     261             : }
     262             : 
     263           0 : 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           0 :     bool bOpaque(true);
     270           0 :     if (mpDoc)
     271             :     {
     272             :         const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
     273           0 :             maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
     274           0 :         if (pItem)
     275           0 :             bOpaque = pItem->GetColor() != COL_TRANSPARENT;
     276             :     }
     277           0 :     return bOpaque;
     278             : }
     279             : 
     280           0 : void ScAccessiblePreviewCell::CreateTextHelper()
     281             : {
     282           0 :     if (!mpTextHelper)
     283             :     {
     284             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     285             :         ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
     286           0 :             (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
     287           0 :         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
     288             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     289             : 
     290           0 :         mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
     291           0 :         mpTextHelper->SetEventSource( this );
     292             : 
     293             :         // paragraphs in preview are transient
     294           0 :         ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
     295           0 :         aChildStates.push_back( AccessibleStateType::TRANSIENT );
     296           0 :         mpTextHelper->SetAdditionalChildStates( aChildStates );
     297             :     }
     298           0 : }
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10