LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessibleCellBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 123 135 91.1 %
Date: 2012-08-25 Functions: 15 20 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 109 226 48.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "AccessibleCellBase.hxx"
      30                 :            : #include "attrib.hxx"
      31                 :            : #include "scitems.hxx"
      32                 :            : #include "miscuno.hxx"
      33                 :            : #include "document.hxx"
      34                 :            : #include "docfunc.hxx"
      35                 :            : #include "docsh.hxx"
      36                 :            : #include "cell.hxx"
      37                 :            : #include "scresid.hxx"
      38                 :            : #include "sc.hrc"
      39                 :            : #include "unonames.hxx"
      40                 :            : 
      41                 :            : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      42                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      43                 :            : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      44                 :            : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      45                 :            : #include <editeng/brshitem.hxx>
      46                 :            : #include <comphelper/sequence.hxx>
      47                 :            : #include <comphelper/servicehelper.hxx>
      48                 :            : #include <sfx2/objsh.hxx>
      49                 :            : #include <vcl/svapp.hxx>
      50                 :            : 
      51                 :            : #include <float.h>
      52                 :            : 
      53                 :            : using namespace ::com::sun::star;
      54                 :            : using namespace ::com::sun::star::accessibility;
      55                 :            : 
      56                 :            : //=====  internal  ============================================================
      57                 :            : 
      58                 :         33 : ScAccessibleCellBase::ScAccessibleCellBase(
      59                 :            :         const uno::Reference<XAccessible>& rxParent,
      60                 :            :         ScDocument* pDoc,
      61                 :            :         const ScAddress& rCellAddress,
      62                 :            :         sal_Int32 nIndex)
      63                 :            :     :
      64                 :            :     ScAccessibleContextBase(rxParent, AccessibleRole::TABLE_CELL),
      65                 :            :     maCellAddress(rCellAddress),
      66                 :            :     mpDoc(pDoc),
      67                 :         33 :     mnIndex(nIndex)
      68                 :            : {
      69                 :         33 : }
      70                 :            : 
      71                 :         33 : ScAccessibleCellBase::~ScAccessibleCellBase()
      72                 :            : {
      73         [ -  + ]:         33 : }
      74                 :            : 
      75                 :            :     //=====  XAccessibleComponent  ============================================
      76                 :            : 
      77                 :         29 : sal_Bool SAL_CALL ScAccessibleCellBase::isVisible(  )
      78                 :            :         throw (uno::RuntimeException)
      79                 :            : {
      80         [ +  - ]:         29 :      SolarMutexGuard aGuard;
      81         [ +  - ]:         29 :     IsObjectValid();
      82                 :            :     // test whether the cell is hidden (column/row - hidden/filtered)
      83                 :         29 :     sal_Bool bVisible(sal_True);
      84         [ +  - ]:         29 :     if (mpDoc)
      85                 :            :     {
      86         [ +  - ]:         29 :         bool bColHidden = mpDoc->ColHidden(maCellAddress.Col(), maCellAddress.Tab());
      87         [ +  - ]:         29 :         bool bRowHidden = mpDoc->RowHidden(maCellAddress.Row(), maCellAddress.Tab());
      88         [ +  - ]:         29 :         bool bColFiltered = mpDoc->ColFiltered(maCellAddress.Col(), maCellAddress.Tab());
      89         [ +  - ]:         29 :         bool bRowFiltered = mpDoc->RowFiltered(maCellAddress.Row(), maCellAddress.Tab());
      90                 :            : 
      91 [ +  - ][ +  - ]:         29 :         if (bColHidden || bColFiltered || bRowHidden || bRowFiltered)
         [ +  - ][ -  + ]
      92                 :          0 :             bVisible = false;
      93                 :            :     }
      94         [ +  - ]:         29 :     return bVisible;
      95                 :            : }
      96                 :            : 
      97                 :          2 : sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
      98                 :            :     throw (uno::RuntimeException)
      99                 :            : {
     100         [ +  - ]:          2 :     SolarMutexGuard aGuard;
     101         [ +  - ]:          2 :     IsObjectValid();
     102                 :          2 :     sal_Int32 nColor(0);
     103         [ +  - ]:          2 :     if (mpDoc)
     104                 :            :     {
     105                 :          2 :         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
     106         [ +  - ]:          2 :         if ( pObjSh )
     107                 :            :         {
     108 [ +  - ][ +  - ]:          2 :             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
     109         [ +  - ]:          2 :             if ( xSpreadDoc.is() )
     110                 :            :             {
     111 [ +  - ][ +  - ]:          2 :                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     112         [ +  - ]:          2 :                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
     113         [ +  - ]:          2 :                 if ( xIndex.is() )
     114                 :            :                 {
     115 [ +  - ][ +  - ]:          2 :                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
     116                 :          2 :                     uno::Reference<sheet::XSpreadsheet> xTable;
     117 [ +  - ][ +  - ]:          2 :                     if (aTable>>=xTable)
     118                 :            :                     {
     119 [ +  - ][ +  - ]:          2 :                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
     120         [ +  - ]:          2 :                         if (xCell.is())
     121                 :            :                         {
     122         [ +  - ]:          2 :                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
     123         [ +  - ]:          2 :                             if (xCellProps.is())
     124                 :            :                             {
     125 [ +  - ][ +  - ]:          2 :                                 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR)));
                 [ +  - ]
     126                 :          2 :                                 aAny >>= nColor;
     127                 :          2 :                             }
     128                 :          2 :                         }
     129                 :          2 :                     }
     130                 :          2 :                 }
     131                 :          2 :             }
     132                 :            :         }
     133                 :            :     }
     134         [ +  - ]:          2 :     return nColor;
     135                 :            : }
     136                 :            : 
     137                 :          2 : sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
     138                 :            :     throw (uno::RuntimeException)
     139                 :            : {
     140         [ +  - ]:          2 :     SolarMutexGuard aGuard;
     141         [ +  - ]:          2 :     IsObjectValid();
     142                 :          2 :     sal_Int32 nColor(0);
     143                 :            : 
     144         [ +  - ]:          2 :     if (mpDoc)
     145                 :            :     {
     146                 :          2 :         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
     147         [ +  - ]:          2 :         if ( pObjSh )
     148                 :            :         {
     149 [ +  - ][ +  - ]:          2 :             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
     150         [ +  - ]:          2 :             if ( xSpreadDoc.is() )
     151                 :            :             {
     152 [ +  - ][ +  - ]:          2 :                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     153         [ +  - ]:          2 :                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
     154         [ +  - ]:          2 :                 if ( xIndex.is() )
     155                 :            :                 {
     156 [ +  - ][ +  - ]:          2 :                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
     157                 :          2 :                     uno::Reference<sheet::XSpreadsheet> xTable;
     158 [ +  - ][ +  - ]:          2 :                     if (aTable>>=xTable)
     159                 :            :                     {
     160 [ +  - ][ +  - ]:          2 :                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
     161         [ +  - ]:          2 :                         if (xCell.is())
     162                 :            :                         {
     163         [ +  - ]:          2 :                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
     164         [ +  - ]:          2 :                             if (xCellProps.is())
     165                 :            :                             {
     166 [ +  - ][ +  - ]:          2 :                                 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK)));
                 [ +  - ]
     167                 :          2 :                                 aAny >>= nColor;
     168                 :          2 :                             }
     169                 :          2 :                         }
     170                 :          2 :                     }
     171                 :          2 :                 }
     172                 :          2 :             }
     173                 :            :         }
     174                 :            :     }
     175                 :            : 
     176         [ +  - ]:          2 :     return nColor;
     177                 :            : }
     178                 :            : 
     179                 :            :     //=====  XInterface  =====================================================
     180                 :            : 
     181                 :        157 : uno::Any SAL_CALL ScAccessibleCellBase::queryInterface( uno::Type const & rType )
     182                 :            :     throw (uno::RuntimeException)
     183                 :            : {
     184         [ +  - ]:        157 :     uno::Any aAny (ScAccessibleCellBaseImpl::queryInterface(rType));
     185 [ +  + ][ +  - ]:        157 :     return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
     186                 :            : }
     187                 :            : 
     188                 :        987 : void SAL_CALL ScAccessibleCellBase::acquire()
     189                 :            :     throw ()
     190                 :            : {
     191                 :        987 :     ScAccessibleContextBase::acquire();
     192                 :        987 : }
     193                 :            : 
     194                 :        987 : void SAL_CALL ScAccessibleCellBase::release()
     195                 :            :     throw ()
     196                 :            : {
     197                 :        987 :     ScAccessibleContextBase::release();
     198                 :        987 : }
     199                 :            : 
     200                 :            :     //=====  XAccessibleContext  ==============================================
     201                 :            : 
     202                 :            : sal_Int32
     203                 :          6 :     ScAccessibleCellBase::getAccessibleIndexInParent(void)
     204                 :            :         throw (uno::RuntimeException)
     205                 :            : {
     206         [ +  - ]:          6 :     SolarMutexGuard aGuard;
     207         [ +  - ]:          6 :     IsObjectValid();
     208         [ +  - ]:          6 :     return mnIndex;
     209                 :            : }
     210                 :            : 
     211                 :            : ::rtl::OUString SAL_CALL
     212                 :         69 :     ScAccessibleCellBase::createAccessibleDescription(void)
     213                 :            :     throw (uno::RuntimeException)
     214                 :            : {
     215 [ +  - ][ +  - ]:         69 :     rtl::OUString sDescription = String(ScResId(STR_ACC_CELL_DESCR));
                 [ +  - ]
     216                 :            : 
     217                 :         69 :     return sDescription;
     218                 :            : }
     219                 :            : 
     220                 :            : ::rtl::OUString SAL_CALL
     221                 :         47 :     ScAccessibleCellBase::createAccessibleName(void)
     222                 :            :     throw (uno::RuntimeException)
     223                 :            : {
     224 [ +  - ][ +  - ]:         47 :     String sName( ScResId(STR_ACC_CELL_NAME) );
     225         [ +  - ]:         47 :     String sAddress;
     226                 :            :     // Document not needed, because only the cell address, but not the tablename is needed
     227                 :            :     // always us OOO notation
     228         [ +  - ]:         47 :     maCellAddress.Format( sAddress, SCA_VALID, NULL );
     229         [ +  - ]:         47 :     sName.SearchAndReplaceAscii("%1", sAddress);
     230                 :            :     /*  #i65103# ZoomText merges cell address and contents, e.g. if value 2 is
     231                 :            :         contained in cell A1, ZT reads "cell A twelve" instead of "cell A1 - 2".
     232                 :            :         Simple solution: Append a space character to the cell address. */
     233         [ +  - ]:         47 :     sName.Append( ' ' );
     234 [ +  - ][ +  - ]:         47 :     return rtl::OUString(sName);
                 [ +  - ]
     235                 :            : }
     236                 :            : 
     237                 :            :     //=====  XAccessibleValue  ================================================
     238                 :            : 
     239                 :            : uno::Any SAL_CALL
     240                 :         14 :     ScAccessibleCellBase::getCurrentValue(  )
     241                 :            :     throw (uno::RuntimeException)
     242                 :            : {
     243         [ +  - ]:         14 :      SolarMutexGuard aGuard;
     244         [ +  - ]:         14 :     IsObjectValid();
     245                 :         14 :     uno::Any aAny;
     246         [ +  - ]:         14 :     if (mpDoc)
     247 [ +  - ][ +  - ]:         14 :         aAny <<= mpDoc->GetValue(maCellAddress);
     248                 :            : 
     249         [ +  - ]:         14 :     return aAny;
     250                 :            : }
     251                 :            : 
     252                 :            : sal_Bool SAL_CALL
     253                 :         12 :     ScAccessibleCellBase::setCurrentValue( const uno::Any& aNumber )
     254                 :            :     throw (uno::RuntimeException)
     255                 :            : {
     256         [ +  - ]:         12 :      SolarMutexGuard aGuard;
     257         [ +  - ]:         12 :     IsObjectValid();
     258                 :         12 :     double fValue = 0;
     259                 :         12 :     sal_Bool bResult(false);
     260 [ +  - ][ +  - ]:         12 :     if((aNumber >>= fValue) && mpDoc && mpDoc->GetDocumentShell())
         [ +  - ][ +  - ]
     261                 :            :     {
     262                 :         12 :         uno::Reference<XAccessibleStateSet> xParentStates;
     263 [ +  - ][ +  - ]:         12 :         if (getAccessibleParent().is())
     264                 :            :         {
     265 [ +  - ][ +  - ]:         12 :             uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
                 [ +  - ]
     266 [ +  - ][ +  - ]:         12 :             xParentStates = xParentContext->getAccessibleStateSet();
                 [ +  - ]
     267                 :            :         }
     268 [ +  - ][ +  + ]:         12 :         if (IsEditable(xParentStates))
     269                 :            :         {
     270                 :         10 :             ScDocShell* pDocShell = (ScDocShell*) mpDoc->GetDocumentShell();
     271 [ +  - ][ +  - ]:         10 :             bResult = pDocShell->GetDocFunc().PutCell( maCellAddress, new ScValueCell(fValue), sal_True );
                 [ +  - ]
     272                 :         12 :         }
     273                 :            :     }
     274         [ +  - ]:         12 :     return bResult;
     275                 :            : }
     276                 :            : 
     277                 :            : uno::Any SAL_CALL
     278                 :          4 :     ScAccessibleCellBase::getMaximumValue(  )
     279                 :            :     throw (uno::RuntimeException)
     280                 :            : {
     281                 :          4 :     uno::Any aAny;
     282         [ +  - ]:          4 :     aAny <<= DBL_MAX;
     283                 :            : 
     284                 :          4 :     return aAny;
     285                 :            : }
     286                 :            : 
     287                 :            : uno::Any SAL_CALL
     288                 :          4 :     ScAccessibleCellBase::getMinimumValue(  )
     289                 :            :     throw (uno::RuntimeException)
     290                 :            : {
     291                 :          4 :     uno::Any aAny;
     292         [ +  - ]:          4 :     aAny <<= -DBL_MAX;
     293                 :            : 
     294                 :          4 :     return aAny;
     295                 :            : }
     296                 :            : 
     297                 :            :     //=====  XServiceInfo  ====================================================
     298                 :            : 
     299                 :          0 : ::rtl::OUString SAL_CALL ScAccessibleCellBase::getImplementationName(void)
     300                 :            :         throw (uno::RuntimeException)
     301                 :            : {
     302                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCellBase"));
     303                 :            : }
     304                 :            : 
     305                 :            :     //=====  XTypeProvider  ===================================================
     306                 :            : 
     307                 :          0 : uno::Sequence< uno::Type > SAL_CALL ScAccessibleCellBase::getTypes()
     308                 :            :         throw (uno::RuntimeException)
     309                 :            : {
     310 [ #  # ][ #  # ]:          0 :     return comphelper::concatSequences(ScAccessibleCellBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
                 [ #  # ]
     311                 :            : }
     312                 :            : 
     313                 :            : namespace
     314                 :            : {
     315                 :            :     class theScAccessibleCellBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessibleCellBaseImplementationId > {};
     316                 :            : }
     317                 :            : 
     318                 :            : uno::Sequence<sal_Int8> SAL_CALL
     319                 :          0 :     ScAccessibleCellBase::getImplementationId(void)
     320                 :            :     throw (uno::RuntimeException)
     321                 :            : {
     322                 :          0 :     return theScAccessibleCellBaseImplementationId::get().getSeq();
     323                 :            : }
     324                 :            : 
     325                 :          0 : sal_Bool ScAccessibleCellBase::IsEditable(
     326                 :            :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
     327                 :            : {
     328                 :          0 :     sal_Bool bEditable(false);
     329 [ #  # ][ #  # ]:          0 :     if (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::EDITABLE))
                 [ #  # ]
     330                 :          0 :         bEditable = sal_True;
     331                 :          0 :     return bEditable;
     332                 :            : }
     333                 :            : 
     334                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10