LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - addruno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 152 7.9 %
Date: 2012-08-25 Functions: 4 15 26.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 290 3.4 %

           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 <com/sun/star/table/CellAddress.hpp>
      30                 :            : #include <com/sun/star/table/CellRangeAddress.hpp>
      31                 :            : 
      32                 :            : #include <svl/itemprop.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : 
      35                 :            : #include "docsh.hxx"
      36                 :            : #include "unonames.hxx"
      37                 :            : #include "miscuno.hxx"
      38                 :            : #include "convuno.hxx"
      39                 :            : #include "addruno.hxx"
      40                 :            : 
      41                 :            : using namespace com::sun::star;
      42                 :            : 
      43                 :            : //------------------------------------------------------------------------
      44                 :            : 
      45                 :          2 : ScAddressConversionObj::ScAddressConversionObj(ScDocShell* pDocSh, sal_Bool bForRange) :
      46                 :            :     pDocShell( pDocSh ),
      47                 :            :     nRefSheet( 0 ),
      48         [ +  - ]:          2 :     bIsRange( bForRange )
      49                 :            : {
      50         [ +  - ]:          2 :     pDocShell->GetDocument()->AddUnoObject(*this);
      51                 :          2 : }
      52                 :            : 
      53         [ +  - ]:          2 : ScAddressConversionObj::~ScAddressConversionObj()
      54                 :            : {
      55         [ -  + ]:          2 :     if (pDocShell)
      56         [ #  # ]:          0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
      57         [ -  + ]:          4 : }
      58                 :            : 
      59                 :        130 : void ScAddressConversionObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      60                 :            : {
      61   [ +  -  +  + ]:        260 :     if ( rHint.ISA( SfxSimpleHint ) &&
                 [ +  + ]
      62                 :        130 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
      63                 :            :     {
      64                 :          2 :         pDocShell = NULL;       // invalid
      65                 :            :     }
      66                 :        130 : }
      67                 :            : 
      68                 :          0 : sal_Bool ScAddressConversionObj::ParseUIString( const String& rUIString, ::formula::FormulaGrammar::AddressConvention eConv )
      69                 :            : {
      70         [ #  # ]:          0 :     if (!pDocShell)
      71                 :          0 :         return false;
      72                 :            : 
      73                 :          0 :     ScDocument* pDoc = pDocShell->GetDocument();
      74                 :          0 :     sal_Bool bSuccess = false;
      75         [ #  # ]:          0 :     if ( bIsRange )
      76                 :            :     {
      77         [ #  # ]:          0 :         sal_uInt16 nResult = aRange.ParseAny( rUIString, pDoc, eConv );
      78         [ #  # ]:          0 :         if ( nResult & SCA_VALID )
      79                 :            :         {
      80         [ #  # ]:          0 :             if ( ( nResult & SCA_TAB_3D ) == 0 )
      81                 :          0 :                 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
      82         [ #  # ]:          0 :             if ( ( nResult & SCA_TAB2_3D ) == 0 )
      83                 :          0 :                 aRange.aEnd.SetTab( aRange.aStart.Tab() );
      84                 :            :             // different sheets are not supported in CellRangeAddress
      85         [ #  # ]:          0 :             if ( aRange.aStart.Tab() == aRange.aEnd.Tab() )
      86                 :          0 :                 bSuccess = sal_True;
      87                 :            :         }
      88                 :            :     }
      89                 :            :     else
      90                 :            :     {
      91         [ #  # ]:          0 :         sal_uInt16 nResult = aRange.aStart.Parse( rUIString, pDoc, eConv );
      92         [ #  # ]:          0 :         if ( nResult & SCA_VALID )
      93                 :            :         {
      94         [ #  # ]:          0 :             if ( ( nResult & SCA_TAB_3D ) == 0 )
      95                 :          0 :                 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
      96                 :          0 :             bSuccess = sal_True;
      97                 :            :         }
      98                 :            :     }
      99                 :          0 :     return bSuccess;
     100                 :            : }
     101                 :            : 
     102                 :            : // XPropertySet
     103                 :            : 
     104                 :          0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAddressConversionObj::getPropertySetInfo()
     105                 :            :                                                         throw(uno::RuntimeException)
     106                 :            : {
     107         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     108                 :            : 
     109         [ #  # ]:          0 :     if ( bIsRange )
     110                 :            :     {
     111                 :            :         static SfxItemPropertyMapEntry aPropertyMap[] =
     112                 :            :         {
     113         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_ADDRESS),  0,  &getCppuType((table::CellRangeAddress*)0), 0, 0 },
     114         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_PERSREPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     115         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_XLA1REPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     116         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_REFSHEET), 0,  &getCppuType((sal_Int32*)0),        0, 0 },
     117         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_UIREPR),   0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     118         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_XLA1REPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     119                 :            :             {0,0,0,0,0,0}
     120 [ #  # ][ #  # ]:          0 :         };
                 [ #  # ]
     121 [ #  # ][ #  # ]:          0 :         static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     122                 :          0 :         return aRef;
     123                 :            :     }
     124                 :            :     else
     125                 :            :     {
     126                 :            :         static SfxItemPropertyMapEntry aPropertyMap[] =
     127                 :            :         {
     128         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_ADDRESS),  0,  &getCppuType((table::CellAddress*)0), 0, 0 },
     129         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_PERSREPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     130         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_XLA1REPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     131         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_REFSHEET), 0,  &getCppuType((sal_Int32*)0),        0, 0 },
     132         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_UIREPR),   0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     133         [ #  # ]:          0 :             {MAP_CHAR_LEN(SC_UNONAME_XLA1REPR), 0,  &getCppuType((rtl::OUString*)0),    0, 0 },
     134                 :            :             {0,0,0,0,0,0}
     135 [ #  # ][ #  # ]:          0 :         };
                 [ #  # ]
     136 [ #  # ][ #  # ]:          0 :         static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     137                 :          0 :         return aRef;
     138         [ #  # ]:          0 :     }
     139                 :            : }
     140                 :            : 
     141                 :          0 : void SAL_CALL ScAddressConversionObj::setPropertyValue( const rtl::OUString& aPropertyName, const uno::Any& aValue )
     142                 :            :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
     143                 :            :                         lang::IllegalArgumentException, lang::WrappedTargetException,
     144                 :            :                         uno::RuntimeException)
     145                 :            : {
     146         [ #  # ]:          0 :     if ( !pDocShell )
     147         [ #  # ]:          0 :         throw uno::RuntimeException();
     148                 :            : 
     149                 :          0 :     sal_Bool bSuccess = false;
     150         [ #  # ]:          0 :     String aNameStr(aPropertyName);
     151 [ #  # ][ #  # ]:          0 :     if ( aNameStr.EqualsAscii( SC_UNONAME_ADDRESS ) )
     152                 :            :     {
     153                 :            :         //  read the cell/range address from API struct
     154         [ #  # ]:          0 :         if ( bIsRange )
     155                 :            :         {
     156                 :          0 :             table::CellRangeAddress aRangeAddress;
     157 [ #  # ][ #  # ]:          0 :             if ( aValue >>= aRangeAddress )
     158                 :            :             {
     159                 :          0 :                 ScUnoConversion::FillScRange( aRange, aRangeAddress );
     160                 :          0 :                 bSuccess = sal_True;
     161                 :            :             }
     162                 :            :         }
     163                 :            :         else
     164                 :            :         {
     165                 :          0 :             table::CellAddress aCellAddress;
     166 [ #  # ][ #  # ]:          0 :             if ( aValue >>= aCellAddress )
     167                 :            :             {
     168                 :          0 :                 ScUnoConversion::FillScAddress( aRange.aStart, aCellAddress );
     169                 :          0 :                 bSuccess = sal_True;
     170                 :            :             }
     171                 :            :         }
     172                 :            :     }
     173 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_REFSHEET ) )
     174                 :            :     {
     175                 :            :         //  set the reference sheet
     176                 :          0 :         sal_Int32 nIntVal = 0;
     177         [ #  # ]:          0 :         if ( aValue >>= nIntVal )
     178                 :            :         {
     179                 :          0 :             nRefSheet = nIntVal;
     180                 :          0 :             bSuccess = sal_True;
     181                 :            :         }
     182                 :            :     }
     183 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_UIREPR ) )
     184                 :            :     {
     185                 :            :         //  parse the UI representation string
     186                 :          0 :         rtl::OUString sRepresentation;
     187         [ #  # ]:          0 :         if (aValue >>= sRepresentation)
     188                 :            :         {
     189         [ #  # ]:          0 :             String aUIString = sRepresentation;
     190 [ #  # ][ #  # ]:          0 :             bSuccess = ParseUIString( aUIString );
     191                 :          0 :         }
     192                 :            :     }
     193 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_PERSREPR ) || aNameStr.EqualsAscii( SC_UNONAME_XLA1REPR ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     194                 :            :     {
     195         [ #  # ]:          0 :         ::formula::FormulaGrammar::AddressConvention aConv = aNameStr.EqualsAscii( SC_UNONAME_PERSREPR ) ?
     196         [ #  # ]:          0 :             ::formula::FormulaGrammar::CONV_OOO : ::formula::FormulaGrammar::CONV_XL_A1;
     197                 :            : 
     198                 :            :         //  parse the file format string
     199                 :          0 :         rtl::OUString sRepresentation;
     200         [ #  # ]:          0 :         if (aValue >>= sRepresentation)
     201                 :            :         {
     202         [ #  # ]:          0 :             String aUIString(sRepresentation);
     203                 :            : 
     204                 :            :             //  cell or range: strip a single "." at the start
     205         [ #  # ]:          0 :             if ( aUIString.GetChar(0) == (sal_Unicode) '.' )
     206         [ #  # ]:          0 :                 aUIString.Erase( 0, 1 );
     207                 :            : 
     208         [ #  # ]:          0 :             if ( bIsRange )
     209                 :            :             {
     210                 :            :                 //  range: also strip a "." after the last colon
     211         [ #  # ]:          0 :                 sal_Int32 nColon = rtl::OUString(aUIString).lastIndexOf( (sal_Unicode) ':' );
     212   [ #  #  #  # ]:          0 :                 if ( nColon >= 0 && nColon < aUIString.Len() - 1 &&
         [ #  # ][ #  # ]
     213                 :          0 :                      aUIString.GetChar((xub_StrLen)nColon+1) == (sal_Unicode) '.' )
     214         [ #  # ]:          0 :                     aUIString.Erase( (xub_StrLen)nColon+1, 1 );
     215                 :            :             }
     216                 :            : 
     217                 :            :             //  parse the rest like a UI string
     218 [ #  # ][ #  # ]:          0 :             bSuccess = ParseUIString( aUIString, aConv );
     219                 :          0 :         }
     220                 :            :     }
     221                 :            :     else
     222         [ #  # ]:          0 :         throw beans::UnknownPropertyException();
     223                 :            : 
     224         [ #  # ]:          0 :     if ( !bSuccess )
     225 [ #  # ][ #  # ]:          0 :         throw lang::IllegalArgumentException();
     226                 :          0 : }
     227                 :            : 
     228                 :          0 : uno::Any SAL_CALL ScAddressConversionObj::getPropertyValue( const rtl::OUString& aPropertyName )
     229                 :            :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
     230                 :            :                         uno::RuntimeException)
     231                 :            : {
     232         [ #  # ]:          0 :     if ( !pDocShell )
     233         [ #  # ]:          0 :         throw uno::RuntimeException();
     234                 :            : 
     235                 :          0 :     ScDocument* pDoc = pDocShell->GetDocument();
     236                 :          0 :     uno::Any aRet;
     237                 :            : 
     238         [ #  # ]:          0 :     String aNameStr(aPropertyName);
     239 [ #  # ][ #  # ]:          0 :     if ( aNameStr.EqualsAscii( SC_UNONAME_ADDRESS ) )
     240                 :            :     {
     241         [ #  # ]:          0 :         if ( bIsRange )
     242                 :            :         {
     243                 :          0 :             table::CellRangeAddress aRangeAddress;
     244                 :          0 :             ScUnoConversion::FillApiRange( aRangeAddress, aRange );
     245         [ #  # ]:          0 :             aRet <<= aRangeAddress;
     246                 :            :         }
     247                 :            :         else
     248                 :            :         {
     249                 :          0 :             table::CellAddress aCellAddress;
     250                 :          0 :             ScUnoConversion::FillApiAddress( aCellAddress, aRange.aStart );
     251         [ #  # ]:          0 :             aRet <<= aCellAddress;
     252                 :            :         }
     253                 :            :     }
     254 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_REFSHEET ) )
     255                 :            :     {
     256         [ #  # ]:          0 :         aRet <<= nRefSheet;
     257                 :            :     }
     258 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_UIREPR ) )
     259                 :            :     {
     260                 :            :         //  generate UI representation string - include sheet only if different from ref sheet
     261         [ #  # ]:          0 :         String aFormatStr;
     262                 :          0 :         sal_uInt16 nFlags = SCA_VALID;
     263         [ #  # ]:          0 :         if ( aRange.aStart.Tab() != nRefSheet )
     264                 :          0 :             nFlags |= SCA_TAB_3D;
     265         [ #  # ]:          0 :         if ( bIsRange )
     266         [ #  # ]:          0 :             aRange.Format( aFormatStr, nFlags, pDoc );
     267                 :            :         else
     268         [ #  # ]:          0 :             aRange.aStart.Format( aFormatStr, nFlags, pDoc );
     269 [ #  # ][ #  # ]:          0 :         aRet <<= rtl::OUString( aFormatStr );
                 [ #  # ]
     270                 :            :     }
     271 [ #  # ][ #  # ]:          0 :     else if ( aNameStr.EqualsAscii( SC_UNONAME_PERSREPR ) || aNameStr.EqualsAscii( SC_UNONAME_XLA1REPR ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     272                 :            :     {
     273         [ #  # ]:          0 :         ::formula::FormulaGrammar::AddressConvention eConv = aNameStr.EqualsAscii( SC_UNONAME_PERSREPR ) ?
     274         [ #  # ]:          0 :             ::formula::FormulaGrammar::CONV_OOO : ::formula::FormulaGrammar::CONV_XL_A1;
     275                 :            : 
     276                 :            :         //  generate file format string - always include sheet
     277         [ #  # ]:          0 :         String aFormatStr;
     278         [ #  # ]:          0 :         aRange.aStart.Format( aFormatStr, SCA_VALID | SCA_TAB_3D, pDoc, eConv );
     279         [ #  # ]:          0 :         if ( bIsRange )
     280                 :            :         {
     281                 :            :             //  manually concatenate range so both parts always have the sheet name
     282         [ #  # ]:          0 :             aFormatStr.Append( (sal_Unicode) ':' );
     283         [ #  # ]:          0 :             String aSecond;
     284                 :          0 :             sal_uInt16 nFlags = SCA_VALID;
     285         [ #  # ]:          0 :             if( eConv != ::formula::FormulaGrammar::CONV_XL_A1 )
     286                 :          0 :                 nFlags |= SCA_TAB_3D;
     287         [ #  # ]:          0 :             aRange.aEnd.Format( aSecond, SCA_VALID | SCA_TAB_3D, pDoc, eConv );
     288 [ #  # ][ #  # ]:          0 :             aFormatStr.Append( aSecond );
     289                 :            :         }
     290 [ #  # ][ #  # ]:          0 :         aRet <<= rtl::OUString( aFormatStr );
                 [ #  # ]
     291                 :            :     }
     292                 :            :     else
     293         [ #  # ]:          0 :         throw beans::UnknownPropertyException();
     294                 :            : 
     295         [ #  # ]:          0 :     return aRet;
     296                 :            : }
     297                 :            : 
     298                 :          0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAddressConversionObj )
     299                 :            : 
     300                 :            : // lang::XServiceInfo
     301                 :            : 
     302                 :          0 : rtl::OUString SAL_CALL ScAddressConversionObj::getImplementationName() throw(uno::RuntimeException)
     303                 :            : {
     304                 :          0 :     return rtl::OUString("ScAddressConversionObj" );
     305                 :            : }
     306                 :            : 
     307                 :          0 : sal_Bool SAL_CALL ScAddressConversionObj::supportsService( const rtl::OUString& rServiceName )
     308                 :            :                                                     throw(uno::RuntimeException)
     309                 :            : {
     310         [ #  # ]:          0 :     String aServiceStr( rServiceName );
     311                 :            :     return aServiceStr.EqualsAscii( bIsRange ? SC_SERVICENAME_RANGEADDRESS
     312 [ #  # ][ #  # ]:          0 :                                              : SC_SERVICENAME_CELLADDRESS );
                 [ #  # ]
     313                 :            : }
     314                 :            : 
     315                 :          0 : uno::Sequence<rtl::OUString> SAL_CALL ScAddressConversionObj::getSupportedServiceNames()
     316                 :            :                                                     throw(uno::RuntimeException)
     317                 :            : {
     318                 :          0 :     uno::Sequence<rtl::OUString> aRet(1);
     319         [ #  # ]:          0 :     rtl::OUString* pArray = aRet.getArray();
     320                 :            :     pArray[0] = bIsRange ? rtl::OUString(SC_SERVICENAME_RANGEADDRESS)
     321 [ #  # ][ #  # ]:          0 :                          : rtl::OUString(SC_SERVICENAME_CELLADDRESS);
                 [ #  # ]
     322                 :          0 :     return aRet;
     323                 :            : }
     324                 :            : 
     325                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10