LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/Accessibility - AccessibleCellBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 124 136 91.2 %
Date: 2013-07-09 Functions: 17 22 77.3 %
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 "AccessibleCellBase.hxx"
      21             : #include "attrib.hxx"
      22             : #include "scitems.hxx"
      23             : #include "miscuno.hxx"
      24             : #include "document.hxx"
      25             : #include "docfunc.hxx"
      26             : #include "docsh.hxx"
      27             : #include "formulacell.hxx"
      28             : #include "scresid.hxx"
      29             : #include "sc.hrc"
      30             : #include "unonames.hxx"
      31             : 
      32             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      33             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      34             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      35             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      36             : #include <editeng/brushitem.hxx>
      37             : #include <comphelper/sequence.hxx>
      38             : #include <comphelper/servicehelper.hxx>
      39             : #include <sfx2/objsh.hxx>
      40             : #include <vcl/svapp.hxx>
      41             : 
      42             : #include <float.h>
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::accessibility;
      46             : 
      47             : //=====  internal  ============================================================
      48             : 
      49          17 : ScAccessibleCellBase::ScAccessibleCellBase(
      50             :         const uno::Reference<XAccessible>& rxParent,
      51             :         ScDocument* pDoc,
      52             :         const ScAddress& rCellAddress,
      53             :         sal_Int32 nIndex)
      54             :     :
      55             :     ScAccessibleContextBase(rxParent, AccessibleRole::TABLE_CELL),
      56             :     maCellAddress(rCellAddress),
      57             :     mpDoc(pDoc),
      58          17 :     mnIndex(nIndex)
      59             : {
      60          17 : }
      61             : 
      62          17 : ScAccessibleCellBase::~ScAccessibleCellBase()
      63             : {
      64          17 : }
      65             : 
      66             :     //=====  XAccessibleComponent  ============================================
      67             : 
      68          14 : sal_Bool SAL_CALL ScAccessibleCellBase::isVisible(  )
      69             :         throw (uno::RuntimeException)
      70             : {
      71          14 :      SolarMutexGuard aGuard;
      72          14 :     IsObjectValid();
      73             :     // test whether the cell is hidden (column/row - hidden/filtered)
      74          14 :     sal_Bool bVisible(sal_True);
      75          14 :     if (mpDoc)
      76             :     {
      77          14 :         bool bColHidden = mpDoc->ColHidden(maCellAddress.Col(), maCellAddress.Tab());
      78          14 :         bool bRowHidden = mpDoc->RowHidden(maCellAddress.Row(), maCellAddress.Tab());
      79          14 :         bool bColFiltered = mpDoc->ColFiltered(maCellAddress.Col(), maCellAddress.Tab());
      80          14 :         bool bRowFiltered = mpDoc->RowFiltered(maCellAddress.Row(), maCellAddress.Tab());
      81             : 
      82          14 :         if (bColHidden || bColFiltered || bRowHidden || bRowFiltered)
      83           0 :             bVisible = false;
      84             :     }
      85          14 :     return bVisible;
      86             : }
      87             : 
      88           1 : sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
      89             :     throw (uno::RuntimeException)
      90             : {
      91           1 :     SolarMutexGuard aGuard;
      92           1 :     IsObjectValid();
      93           1 :     sal_Int32 nColor(0);
      94           1 :     if (mpDoc)
      95             :     {
      96           1 :         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
      97           1 :         if ( pObjSh )
      98             :         {
      99           1 :             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
     100           1 :             if ( xSpreadDoc.is() )
     101             :             {
     102           1 :                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     103           2 :                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
     104           1 :                 if ( xIndex.is() )
     105             :                 {
     106           1 :                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
     107           2 :                     uno::Reference<sheet::XSpreadsheet> xTable;
     108           1 :                     if (aTable>>=xTable)
     109             :                     {
     110           1 :                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
     111           1 :                         if (xCell.is())
     112             :                         {
     113           1 :                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
     114           1 :                             if (xCellProps.is())
     115             :                             {
     116           1 :                                 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_CCOLOR));
     117           1 :                                 aAny >>= nColor;
     118           1 :                             }
     119           1 :                         }
     120           1 :                     }
     121           1 :                 }
     122           1 :             }
     123             :         }
     124             :     }
     125           1 :     return nColor;
     126             : }
     127             : 
     128           1 : sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
     129             :     throw (uno::RuntimeException)
     130             : {
     131           1 :     SolarMutexGuard aGuard;
     132           1 :     IsObjectValid();
     133           1 :     sal_Int32 nColor(0);
     134             : 
     135           1 :     if (mpDoc)
     136             :     {
     137           1 :         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
     138           1 :         if ( pObjSh )
     139             :         {
     140           1 :             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
     141           1 :             if ( xSpreadDoc.is() )
     142             :             {
     143           1 :                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     144           2 :                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
     145           1 :                 if ( xIndex.is() )
     146             :                 {
     147           1 :                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
     148           2 :                     uno::Reference<sheet::XSpreadsheet> xTable;
     149           1 :                     if (aTable>>=xTable)
     150             :                     {
     151           1 :                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
     152           1 :                         if (xCell.is())
     153             :                         {
     154           1 :                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
     155           1 :                             if (xCellProps.is())
     156             :                             {
     157           1 :                                 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_CELLBACK));
     158           1 :                                 aAny >>= nColor;
     159           1 :                             }
     160           1 :                         }
     161           1 :                     }
     162           1 :                 }
     163           1 :             }
     164             :         }
     165             :     }
     166             : 
     167           1 :     return nColor;
     168             : }
     169             : 
     170             :     //=====  XInterface  =====================================================
     171             : 
     172          81 : uno::Any SAL_CALL ScAccessibleCellBase::queryInterface( uno::Type const & rType )
     173             :     throw (uno::RuntimeException)
     174             : {
     175          81 :     uno::Any aAny (ScAccessibleCellBaseImpl::queryInterface(rType));
     176          81 :     return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
     177             : }
     178             : 
     179         500 : void SAL_CALL ScAccessibleCellBase::acquire()
     180             :     throw ()
     181             : {
     182         500 :     ScAccessibleContextBase::acquire();
     183         500 : }
     184             : 
     185         500 : void SAL_CALL ScAccessibleCellBase::release()
     186             :     throw ()
     187             : {
     188         500 :     ScAccessibleContextBase::release();
     189         500 : }
     190             : 
     191             :     //=====  XAccessibleContext  ==============================================
     192             : 
     193             : sal_Int32
     194           4 :     ScAccessibleCellBase::getAccessibleIndexInParent(void)
     195             :         throw (uno::RuntimeException)
     196             : {
     197           4 :     SolarMutexGuard aGuard;
     198           4 :     IsObjectValid();
     199           4 :     return mnIndex;
     200             : }
     201             : 
     202             : OUString SAL_CALL
     203          35 :     ScAccessibleCellBase::createAccessibleDescription(void)
     204             :     throw (uno::RuntimeException)
     205             : {
     206          35 :     OUString sDescription = String(ScResId(STR_ACC_CELL_DESCR));
     207             : 
     208          35 :     return sDescription;
     209             : }
     210             : 
     211             : OUString SAL_CALL
     212          23 :     ScAccessibleCellBase::createAccessibleName(void)
     213             :     throw (uno::RuntimeException)
     214             : {
     215          23 :     String sName( ScResId(STR_ACC_CELL_NAME) );
     216          46 :     String sAddress;
     217             :     // Document not needed, because only the cell address, but not the tablename is needed
     218             :     // always us OOO notation
     219          23 :     maCellAddress.Format( sAddress, SCA_VALID, NULL );
     220          23 :     sName.SearchAndReplaceAscii("%1", sAddress);
     221             :     /*  #i65103# ZoomText merges cell address and contents, e.g. if value 2 is
     222             :         contained in cell A1, ZT reads "cell A twelve" instead of "cell A1 - 2".
     223             :         Simple solution: Append a space character to the cell address. */
     224          23 :     sName.Append( ' ' );
     225          46 :     return OUString(sName);
     226             : }
     227             : 
     228             :     //=====  XAccessibleValue  ================================================
     229             : 
     230             : uno::Any SAL_CALL
     231           7 :     ScAccessibleCellBase::getCurrentValue(  )
     232             :     throw (uno::RuntimeException)
     233             : {
     234           7 :      SolarMutexGuard aGuard;
     235           7 :     IsObjectValid();
     236           7 :     uno::Any aAny;
     237           7 :     if (mpDoc)
     238           7 :         aAny <<= mpDoc->GetValue(maCellAddress);
     239             : 
     240           7 :     return aAny;
     241             : }
     242             : 
     243             : sal_Bool SAL_CALL
     244           6 :     ScAccessibleCellBase::setCurrentValue( const uno::Any& aNumber )
     245             :     throw (uno::RuntimeException)
     246             : {
     247           6 :     SolarMutexGuard aGuard;
     248           6 :     IsObjectValid();
     249           6 :     double fValue = 0;
     250           6 :     bool bResult = false;
     251           6 :     if((aNumber >>= fValue) && mpDoc && mpDoc->GetDocumentShell())
     252             :     {
     253           6 :         uno::Reference<XAccessibleStateSet> xParentStates;
     254           6 :         if (getAccessibleParent().is())
     255             :         {
     256           6 :             uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
     257           6 :             xParentStates = xParentContext->getAccessibleStateSet();
     258             :         }
     259           6 :         if (IsEditable(xParentStates))
     260             :         {
     261           5 :             ScDocShell* pDocShell = (ScDocShell*) mpDoc->GetDocumentShell();
     262           5 :             bResult = pDocShell->GetDocFunc().SetValueCell(maCellAddress, fValue, false);
     263           6 :         }
     264             :     }
     265           6 :     return bResult;
     266             : }
     267             : 
     268             : uno::Any SAL_CALL
     269           2 :     ScAccessibleCellBase::getMaximumValue(  )
     270             :     throw (uno::RuntimeException)
     271             : {
     272           2 :     uno::Any aAny;
     273           2 :     aAny <<= DBL_MAX;
     274             : 
     275           2 :     return aAny;
     276             : }
     277             : 
     278             : uno::Any SAL_CALL
     279           2 :     ScAccessibleCellBase::getMinimumValue(  )
     280             :     throw (uno::RuntimeException)
     281             : {
     282           2 :     uno::Any aAny;
     283           2 :     aAny <<= -DBL_MAX;
     284             : 
     285           2 :     return aAny;
     286             : }
     287             : 
     288             :     //=====  XServiceInfo  ====================================================
     289             : 
     290           0 : OUString SAL_CALL ScAccessibleCellBase::getImplementationName(void)
     291             :         throw (uno::RuntimeException)
     292             : {
     293           0 :     return OUString("ScAccessibleCellBase");
     294             : }
     295             : 
     296             :     //=====  XTypeProvider  ===================================================
     297             : 
     298           0 : uno::Sequence< uno::Type > SAL_CALL ScAccessibleCellBase::getTypes()
     299             :         throw (uno::RuntimeException)
     300             : {
     301           0 :     return comphelper::concatSequences(ScAccessibleCellBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
     302             : }
     303             : 
     304             : namespace
     305             : {
     306             :     class theScAccessibleCellBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessibleCellBaseImplementationId > {};
     307             : }
     308             : 
     309             : uno::Sequence<sal_Int8> SAL_CALL
     310           0 :     ScAccessibleCellBase::getImplementationId(void)
     311             :     throw (uno::RuntimeException)
     312             : {
     313           0 :     return theScAccessibleCellBaseImplementationId::get().getSeq();
     314             : }
     315             : 
     316           0 : sal_Bool ScAccessibleCellBase::IsEditable(
     317             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     318             : {
     319           0 :     sal_Bool bEditable(false);
     320           0 :     if (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::EDITABLE))
     321           0 :         bEditable = sal_True;
     322           0 :     return bEditable;
     323          93 : }
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10