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

Generated by: LCOV version 1.10