LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/Accessibility - AccessibleCell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 200 0.5 %
Date: 2012-12-17 Functions: 2 32 6.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 "AccessibleCell.hxx"
      21             : #include "scitems.hxx"
      22             : #include <editeng/eeitem.hxx>
      23             : 
      24             : 
      25             : #include "AccessibleText.hxx"
      26             : #include "AccessibleDocument.hxx"
      27             : #include "tabvwsh.hxx"
      28             : #include "document.hxx"
      29             : #include "attrib.hxx"
      30             : #include "miscuno.hxx"
      31             : #include "editsrc.hxx"
      32             : #include "dociter.hxx"
      33             : #include "cell.hxx"
      34             : #include "markdata.hxx"
      35             : 
      36             : #include <unotools/accessiblestatesethelper.hxx>
      37             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      38             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      39             : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
      40             : #include <com/sun/star/accessibility/XAccessibleTable.hpp>
      41             : #include <editeng/brshitem.hxx>
      42             : #include <comphelper/sequence.hxx>
      43             : #include <float.h>
      44             : #include <vcl/svapp.hxx>
      45             : 
      46             : using namespace ::com::sun::star;
      47             : using namespace ::com::sun::star::accessibility;
      48             : 
      49             : //=====  internal  ============================================================
      50             : 
      51           0 : ScAccessibleCell::ScAccessibleCell(
      52             :         const uno::Reference<XAccessible>& rxParent,
      53             :         ScTabViewShell* pViewShell,
      54             :         ScAddress& rCellAddress,
      55             :         sal_Int32 nIndex,
      56             :         ScSplitPos eSplitPos,
      57             :         ScAccessibleDocument* pAccDoc)
      58             :     :
      59             :     ScAccessibleCellBase(rxParent, GetDocument(pViewShell), rCellAddress, nIndex),
      60             :         ::accessibility::AccessibleStaticTextBase(CreateEditSource(pViewShell, rCellAddress, eSplitPos)),
      61             :     mpViewShell(pViewShell),
      62             :     mpAccDoc(pAccDoc),
      63           0 :     meSplitPos(eSplitPos)
      64             : {
      65           0 :     if (pViewShell)
      66           0 :         pViewShell->AddAccessibilityObject(*this);
      67           0 : }
      68             : 
      69           0 : ScAccessibleCell::~ScAccessibleCell()
      70             : {
      71           0 :     if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
      72             :     {
      73             :         // increment refcount to prevent double call off dtor
      74           0 :         osl_atomic_increment( &m_refCount );
      75             :         // call dispose to inform object wich have a weak reference to this object
      76           0 :         dispose();
      77             :     }
      78           0 : }
      79             : 
      80           0 : void ScAccessibleCell::Init()
      81             : {
      82           0 :     ScAccessibleCellBase::Init();
      83             : 
      84           0 :     SetEventSource(this);
      85           0 : }
      86             : 
      87           0 : void SAL_CALL ScAccessibleCell::disposing()
      88             : {
      89           0 :     SolarMutexGuard aGuard;
      90             :     // dispose in AccessibleStaticTextBase
      91           0 :     Dispose();
      92             : 
      93           0 :     if (mpViewShell)
      94             :     {
      95           0 :         mpViewShell->RemoveAccessibilityObject(*this);
      96           0 :         mpViewShell = NULL;
      97             :     }
      98           0 :     mpAccDoc = NULL;
      99             : 
     100           0 :     ScAccessibleCellBase::disposing();
     101           0 : }
     102             : 
     103             :     //=====  XInterface  =====================================================
     104             : 
     105           0 : IMPLEMENT_FORWARD_XINTERFACE2( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase )
     106             : 
     107             :     //=====  XTypeProvider  ===================================================
     108             : 
     109           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase )
     110             : 
     111             :     //=====  XAccessibleComponent  ============================================
     112             : 
     113           0 : uno::Reference< XAccessible > SAL_CALL ScAccessibleCell::getAccessibleAtPoint(
     114             :         const awt::Point& rPoint )
     115             :         throw (uno::RuntimeException)
     116             : {
     117           0 :     return AccessibleStaticTextBase::getAccessibleAtPoint(rPoint);
     118             : }
     119             : 
     120           0 : void SAL_CALL ScAccessibleCell::grabFocus(  )
     121             :         throw (uno::RuntimeException)
     122             : {
     123           0 :      SolarMutexGuard aGuard;
     124           0 :     IsObjectValid();
     125           0 :     if (getAccessibleParent().is() && mpViewShell)
     126             :     {
     127           0 :         uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
     128           0 :         if (xAccessibleComponent.is())
     129             :         {
     130           0 :             xAccessibleComponent->grabFocus();
     131           0 :             mpViewShell->SetCursor(maCellAddress.Col(), maCellAddress.Row());
     132           0 :         }
     133           0 :     }
     134           0 : }
     135             : 
     136           0 : Rectangle ScAccessibleCell::GetBoundingBoxOnScreen(void) const
     137             :         throw (uno::RuntimeException)
     138             : {
     139           0 :     Rectangle aCellRect(GetBoundingBox());
     140           0 :     if (mpViewShell)
     141             :     {
     142           0 :         Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
     143           0 :         if (pWindow)
     144             :         {
     145           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
     146           0 :             aCellRect.setX(aCellRect.getX() + aRect.getX());
     147           0 :             aCellRect.setY(aCellRect.getY() + aRect.getY());
     148             :         }
     149             :     }
     150           0 :     return aCellRect;
     151             : }
     152             : 
     153           0 : Rectangle ScAccessibleCell::GetBoundingBox(void) const
     154             :         throw (uno::RuntimeException)
     155             : {
     156           0 :     Rectangle aCellRect;
     157           0 :     if (mpViewShell)
     158             :     {
     159             :         long nSizeX, nSizeY;
     160             :         mpViewShell->GetViewData()->GetMergeSizePixel(
     161           0 :             maCellAddress.Col(), maCellAddress.Row(), nSizeX, nSizeY);
     162           0 :         aCellRect.SetSize(Size(nSizeX, nSizeY));
     163           0 :         aCellRect.SetPos(mpViewShell->GetViewData()->GetScrPos(maCellAddress.Col(), maCellAddress.Row(), meSplitPos, sal_True));
     164             : 
     165           0 :         Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
     166           0 :         if (pWindow)
     167             :         {
     168           0 :             Rectangle aRect(pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow()));
     169           0 :             aRect.Move(-aRect.Left(), -aRect.Top());
     170           0 :             aCellRect = aRect.Intersection(aCellRect);
     171             :         }
     172             : 
     173             :         /*  #i19430# Gnopernicus reads text partly if it sticks out of the cell
     174             :             boundaries. This leads to wrong results in cases where the cell
     175             :             text is rotated, because rotation is not taken into account when
     176             :             calculating the visible part of the text. In these cases we will
     177             :             simply expand the cell size to the width of the unrotated text. */
     178           0 :         if (mpDoc)
     179             :         {
     180             :             const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
     181           0 :                 mpDoc->GetAttr( maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_ROTATE_VALUE ) );
     182           0 :             if( pItem && (pItem->GetValue() != 0) )
     183             :             {
     184           0 :                 Rectangle aParaRect = GetParagraphBoundingBox();
     185           0 :                 if( !aParaRect.IsEmpty() && (aCellRect.GetWidth() < aParaRect.GetWidth()) )
     186           0 :                     aCellRect.SetSize( Size( aParaRect.GetWidth(), aCellRect.GetHeight() ) );
     187             :             }
     188             :         }
     189             :     }
     190           0 :     if (aCellRect.IsEmpty())
     191           0 :         aCellRect.SetPos(Point(-1, -1));
     192           0 :     return aCellRect;
     193             : }
     194             : 
     195             :     //=====  XAccessibleContext  ==============================================
     196             : 
     197             : sal_Int32 SAL_CALL
     198           0 :     ScAccessibleCell::getAccessibleChildCount(void)
     199             :                     throw (uno::RuntimeException)
     200             : {
     201           0 :     return AccessibleStaticTextBase::getAccessibleChildCount();
     202             : }
     203             : 
     204             : uno::Reference< XAccessible > SAL_CALL
     205           0 :     ScAccessibleCell::getAccessibleChild(sal_Int32 nIndex)
     206             :         throw (uno::RuntimeException,
     207             :         lang::IndexOutOfBoundsException)
     208             : {
     209           0 :     return AccessibleStaticTextBase::getAccessibleChild(nIndex);
     210             : }
     211             : 
     212             : uno::Reference<XAccessibleStateSet> SAL_CALL
     213           0 :     ScAccessibleCell::getAccessibleStateSet(void)
     214             :     throw (uno::RuntimeException)
     215             : {
     216           0 :     SolarMutexGuard aGuard;
     217           0 :     uno::Reference<XAccessibleStateSet> xParentStates;
     218           0 :     if (getAccessibleParent().is())
     219             :     {
     220           0 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
     221           0 :         xParentStates = xParentContext->getAccessibleStateSet();
     222             :     }
     223           0 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
     224           0 :     if (IsDefunc(xParentStates))
     225           0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
     226             :     else
     227             :     {
     228           0 :         if (IsEditable(xParentStates))
     229             :         {
     230           0 :             pStateSet->AddState(AccessibleStateType::EDITABLE);
     231           0 :             pStateSet->AddState(AccessibleStateType::RESIZABLE);
     232             :         }
     233           0 :         pStateSet->AddState(AccessibleStateType::ENABLED);
     234           0 :         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
     235           0 :         pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
     236           0 :         if (IsOpaque(xParentStates))
     237           0 :             pStateSet->AddState(AccessibleStateType::OPAQUE);
     238           0 :         pStateSet->AddState(AccessibleStateType::SELECTABLE);
     239           0 :         if (IsSelected())
     240           0 :             pStateSet->AddState(AccessibleStateType::SELECTED);
     241           0 :         if (isShowing())
     242           0 :             pStateSet->AddState(AccessibleStateType::SHOWING);
     243           0 :         pStateSet->AddState(AccessibleStateType::TRANSIENT);
     244           0 :         if (isVisible())
     245           0 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
     246             :     }
     247           0 :     return pStateSet;
     248             : }
     249             : 
     250             : uno::Reference<XAccessibleRelationSet> SAL_CALL
     251           0 :        ScAccessibleCell::getAccessibleRelationSet(void)
     252             :     throw (uno::RuntimeException)
     253             : {
     254           0 :     SolarMutexGuard aGuard;
     255           0 :     IsObjectValid();
     256           0 :     utl::AccessibleRelationSetHelper* pRelationSet = NULL;
     257           0 :     if (mpAccDoc)
     258           0 :         pRelationSet = mpAccDoc->GetRelationSet(&maCellAddress);
     259           0 :     if (!pRelationSet)
     260           0 :         pRelationSet = new utl::AccessibleRelationSetHelper();
     261           0 :     FillDependends(pRelationSet);
     262           0 :     FillPrecedents(pRelationSet);
     263           0 :     return pRelationSet;
     264             : }
     265             : 
     266             :     //=====  XServiceInfo  ====================================================
     267             : 
     268           0 : ::rtl::OUString SAL_CALL ScAccessibleCell::getImplementationName(void)
     269             :         throw (uno::RuntimeException)
     270             : {
     271           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCell"));
     272             : }
     273             : 
     274             : uno::Sequence< ::rtl::OUString> SAL_CALL
     275           0 :     ScAccessibleCell::getSupportedServiceNames(void)
     276             :         throw (uno::RuntimeException)
     277             : {
     278           0 :     uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
     279           0 :     sal_Int32 nOldSize(aSequence.getLength());
     280           0 :     aSequence.realloc(nOldSize + 1);
     281           0 :     ::rtl::OUString* pNames = aSequence.getArray();
     282             : 
     283           0 :     pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.AccessibleCell"));
     284             : 
     285           0 :     return aSequence;
     286             : }
     287             : 
     288             :     //====  internal  =========================================================
     289             : 
     290           0 : sal_Bool ScAccessibleCell::IsDefunc(
     291             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     292             : {
     293           0 :     return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
     294           0 :          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
     295             : }
     296             : 
     297           0 : sal_Bool ScAccessibleCell::IsEditable(
     298             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     299             : {
     300           0 :     sal_Bool bEditable(sal_True);
     301           0 :     if (rxParentStates.is() && !rxParentStates->contains(AccessibleStateType::EDITABLE) &&
     302             :         mpDoc)
     303             :     {
     304             :         // here I have to test whether the protection of the table should influence this cell.
     305             :         const ScProtectionAttr* pItem = (const ScProtectionAttr*)mpDoc->GetAttr(
     306           0 :             maCellAddress.Col(), maCellAddress.Row(),
     307           0 :             maCellAddress.Tab(), ATTR_PROTECTION);
     308           0 :         if (pItem)
     309           0 :             bEditable = !pItem->GetProtection();
     310             :     }
     311           0 :     return bEditable;
     312             : }
     313             : 
     314           0 : sal_Bool ScAccessibleCell::IsOpaque(
     315             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
     316             : {
     317             :     // test whether there is a background color
     318           0 :     sal_Bool bOpaque(sal_True);
     319           0 :     if (mpDoc)
     320             :     {
     321             :         const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
     322           0 :             maCellAddress.Col(), maCellAddress.Row(),
     323           0 :             maCellAddress.Tab(), ATTR_BACKGROUND);
     324           0 :         if (pItem)
     325           0 :             bOpaque = pItem->GetColor() != COL_TRANSPARENT;
     326             :     }
     327           0 :     return bOpaque;
     328             : }
     329             : 
     330           0 : sal_Bool ScAccessibleCell::IsSelected()
     331             : {
     332           0 :     sal_Bool bResult(false);
     333           0 :     if (mpViewShell && mpViewShell->GetViewData())
     334             :     {
     335           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     336           0 :         bResult = rMarkdata.IsCellMarked(maCellAddress.Col(), maCellAddress.Row());
     337             :     }
     338           0 :     return bResult;
     339             : }
     340             : 
     341           0 : ScDocument* ScAccessibleCell::GetDocument(ScTabViewShell* pViewShell)
     342             : {
     343           0 :     ScDocument* pDoc = NULL;
     344           0 :     if (pViewShell && pViewShell->GetViewData())
     345           0 :         pDoc = pViewShell->GetViewData()->GetDocument();
     346           0 :     return pDoc;
     347             : }
     348             : 
     349             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     350           0 : ::std::auto_ptr< SvxEditSource > ScAccessibleCell::CreateEditSource(ScTabViewShell* pViewShell, ScAddress aCell, ScSplitPos eSplitPos)
     351             : {
     352             :     ::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData
     353           0 :         ( new ScAccessibleCellTextData( pViewShell, aCell, eSplitPos, this ) );
     354           0 :     ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleCellTextData));
     355             : 
     356           0 :     return pEditSource;
     357             : }
     358             : SAL_WNODEPRECATED_DECLARATIONS_POP
     359             : 
     360           0 : void ScAccessibleCell::FillDependends(utl::AccessibleRelationSetHelper* pRelationSet)
     361             : {
     362           0 :     if (mpDoc)
     363             :     {
     364           0 :         ScCellIterator aCellIter( mpDoc, 0,0, maCellAddress.Tab(), MAXCOL,MAXROW, maCellAddress.Tab() );
     365           0 :         ScBaseCell* pCell = aCellIter.GetFirst();
     366           0 :         while (pCell)
     367             :         {
     368           0 :             if (pCell->GetCellType() == CELLTYPE_FORMULA)
     369             :             {
     370           0 :                 sal_Bool bFound(false);
     371           0 :                 ScDetectiveRefIter aIter( (ScFormulaCell*) pCell );
     372           0 :                 ScRange aRef;
     373           0 :                 while ( !bFound && aIter.GetNextRef( aRef ) )
     374             :                 {
     375           0 :                     if (aRef.In(maCellAddress))
     376           0 :                         bFound = sal_True;
     377             :                 }
     378           0 :                 if (bFound)
     379           0 :                     AddRelation(ScAddress(aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab()), AccessibleRelationType::CONTROLLER_FOR, pRelationSet);
     380             :             }
     381           0 :             pCell = aCellIter.GetNext();
     382             :         }
     383             :     }
     384           0 : }
     385             : 
     386           0 : void ScAccessibleCell::FillPrecedents(utl::AccessibleRelationSetHelper* pRelationSet)
     387             : {
     388           0 :     if (mpDoc)
     389             :     {
     390           0 :         ScBaseCell* pBaseCell = mpDoc->GetCell(maCellAddress);
     391           0 :         if (pBaseCell && (pBaseCell->GetCellType() == CELLTYPE_FORMULA))
     392             :         {
     393           0 :             ScFormulaCell* pFCell = (ScFormulaCell*) pBaseCell;
     394             : 
     395           0 :             ScDetectiveRefIter aIter( pFCell );
     396           0 :             ScRange aRef;
     397           0 :             while ( aIter.GetNextRef( aRef ) )
     398             :             {
     399           0 :                 AddRelation( aRef, AccessibleRelationType::CONTROLLED_BY, pRelationSet);
     400             :             }
     401             :         }
     402             :     }
     403           0 : }
     404             : 
     405           0 : void ScAccessibleCell::AddRelation(const ScAddress& rCell,
     406             :     const sal_uInt16 aRelationType,
     407             :     utl::AccessibleRelationSetHelper* pRelationSet)
     408             : {
     409           0 :     AddRelation(ScRange(rCell, rCell), aRelationType, pRelationSet);
     410           0 : }
     411             : 
     412           0 : void ScAccessibleCell::AddRelation(const ScRange& rRange,
     413             :     const sal_uInt16 aRelationType,
     414             :     utl::AccessibleRelationSetHelper* pRelationSet)
     415             : {
     416           0 :     uno::Reference < XAccessibleTable > xTable ( getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY );
     417           0 :     if (xTable.is())
     418             :     {
     419           0 :         sal_uInt32 nCount(static_cast<sal_uInt32>(rRange.aEnd.Col() -
     420           0 :                     rRange.aStart.Col() + 1) * (rRange.aEnd.Row() -
     421           0 :                     rRange.aStart.Row() + 1));
     422           0 :         uno::Sequence < uno::Reference < uno::XInterface > > aTargetSet( nCount );
     423           0 :         uno::Reference < uno::XInterface >* pTargetSet = aTargetSet.getArray();
     424           0 :         if (pTargetSet)
     425             :         {
     426           0 :             sal_uInt32 nPos(0);
     427           0 :             for (sal_uInt32 nRow = rRange.aStart.Row(); nRow <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Row()); ++nRow)
     428             :             {
     429           0 :                 for (sal_uInt32 nCol = rRange.aStart.Col(); nCol <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Col()); ++nCol)
     430             :                 {
     431           0 :                     pTargetSet[nPos] = xTable->getAccessibleCellAt(nRow, nCol);
     432           0 :                     ++nPos;
     433             :                 }
     434             :             }
     435             :             OSL_ENSURE(nCount == nPos, "something wents wrong");
     436             :         }
     437           0 :         AccessibleRelation aRelation;
     438           0 :         aRelation.RelationType = aRelationType;
     439           0 :         aRelation.TargetSet = aTargetSet;
     440           0 :         pRelationSet->AddRelation(aRelation);
     441           0 :     }
     442         102 : }
     443             : 
     444             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10