LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/Accessibility - AccessiblePreviewCell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 135 0.7 %
Date: 2012-12-27 Functions: 2 21 9.5 %
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/brshitem.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 wich 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)
     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)
     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)
     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)
     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)
     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 : rtl::OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException)
     184             : {
     185           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewCell"));
     186             : }
     187             : 
     188           0 : uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
     189             :                                                     throw(uno::RuntimeException)
     190             : {
     191           0 :     uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
     192           0 :     sal_Int32 nOldSize(aSequence.getLength());
     193           0 :     aSequence.realloc(nOldSize + 1);
     194           0 :     ::rtl::OUString* pNames = aSequence.getArray();
     195             : 
     196           0 :     pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
     197             : 
     198           0 :     return aSequence;
     199             : }
     200             : 
     201             : //=====  XTypeProvider  =======================================================
     202             : 
     203             : namespace
     204             : {
     205             :     class theScAccessiblePreviewCellImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePreviewCellImplementationId > {};
     206             : }
     207             : 
     208             : uno::Sequence<sal_Int8> SAL_CALL
     209           0 :     ScAccessiblePreviewCell::getImplementationId(void)
     210             :     throw (uno::RuntimeException)
     211             : {
     212           0 :     return theScAccessiblePreviewCellImplementationId::get().getSeq();
     213             : }
     214             : 
     215             : //====  internal  =========================================================
     216             : 
     217           0 : Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
     218             : {
     219           0 :     Rectangle aCellRect;
     220           0 :     if (mpViewShell)
     221             :     {
     222           0 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     223           0 :         Window* pWindow = mpViewShell->GetWindow();
     224           0 :         if (pWindow)
     225             :         {
     226           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
     227           0 :             aCellRect.setX(aCellRect.getX() + aRect.getX());
     228           0 :             aCellRect.setY(aCellRect.getY() + aRect.getY());
     229             :         }
     230             :     }
     231           0 :     return aCellRect;
     232             : }
     233             : 
     234           0 : Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException)
     235             : {
     236           0 :     Rectangle aCellRect;
     237           0 :     if (mpViewShell)
     238             :     {
     239           0 :         mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
     240           0 :         uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
     241           0 :         if (xAccParent.is())
     242             :         {
     243           0 :             uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
     244           0 :             uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
     245           0 :             if (xAccParentComp.is())
     246             :             {
     247           0 :                 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
     248           0 :                 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
     249           0 :                 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
     250           0 :             }
     251           0 :         }
     252             :     }
     253           0 :     return aCellRect;
     254             : }
     255             : 
     256           0 : sal_Bool ScAccessiblePreviewCell::IsDefunc(
     257             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     258             : {
     259           0 :     return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
     260           0 :          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
     261             : }
     262             : 
     263           0 : sal_Bool ScAccessiblePreviewCell::IsEditable(
     264             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     265             : {
     266           0 :     return false;
     267             : }
     268             : 
     269           0 : sal_Bool ScAccessiblePreviewCell::IsOpaque(
     270             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     271             : {
     272             :     // test whether there is a background color
     273             :     //! could be moved to ScAccessibleCellBase
     274             : 
     275           0 :     sal_Bool bOpaque(sal_True);
     276           0 :     if (mpDoc)
     277             :     {
     278             :         const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
     279           0 :             maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
     280           0 :         if (pItem)
     281           0 :             bOpaque = pItem->GetColor() != COL_TRANSPARENT;
     282             :     }
     283           0 :     return bOpaque;
     284             : }
     285             : 
     286           0 : void ScAccessiblePreviewCell::CreateTextHelper()
     287             : {
     288           0 :     if (!mpTextHelper)
     289             :     {
     290             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     291             :         ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
     292           0 :             (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
     293           0 :         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
     294             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     295             : 
     296           0 :         mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
     297           0 :         mpTextHelper->SetEventSource( this );
     298             : 
     299             :         // paragraphs in preview are transient
     300           0 :         ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
     301           0 :         aChildStates.push_back( AccessibleStateType::TRANSIENT );
     302           0 :         mpTextHelper->SetAdditionalChildStates( aChildStates );
     303             :     }
     304          15 : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10