LCOV - code coverage report
Current view: top level - sc/source/ui/vba - excelvbahelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 263 13.7 %
Date: 2012-08-25 Functions: 9 34 26.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 538 5.9 %

           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 "excelvbahelper.hxx"
      30                 :            : 
      31                 :            : #include <comphelper/processfactory.hxx>
      32                 :            : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      33                 :            : #include "docuno.hxx"
      34                 :            : #include "tabvwsh.hxx"
      35                 :            : #include "transobj.hxx"
      36                 :            : #include "scmod.hxx"
      37                 :            : #include "cellsuno.hxx"
      38                 :            : #include "compiler.hxx"
      39                 :            : #include "token.hxx"
      40                 :            : #include "tokenarray.hxx"
      41                 :            : 
      42                 :            : #include <com/sun/star/script/vba/VBAEventId.hpp>
      43                 :            : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
      44                 :            : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
      45                 :            : #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
      46                 :            : #include <com/sun/star/script/ModuleInfo.hpp>
      47                 :            : #include <com/sun/star/script/ModuleType.hpp>
      48                 :            : 
      49                 :            : using namespace ::com::sun::star;
      50                 :            : using namespace ::ooo::vba;
      51                 :            : 
      52                 :            : namespace ooo {
      53                 :            : namespace vba {
      54                 :            : namespace excel {
      55                 :            : 
      56                 :            : // ============================================================================
      57                 :            : 
      58                 :            : uno::Reference< sheet::XUnnamedDatabaseRanges >
      59                 :          0 : GetUnnamedDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException )
      60                 :            : {
      61                 :          0 :     uno::Reference< frame::XModel > xModel;
      62         [ #  # ]:          0 :     if ( pShell )
      63 [ #  # ][ #  # ]:          0 :         xModel.set( pShell->GetModel(), uno::UNO_QUERY_THROW );
      64         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW );
      65 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnnamedDatabaseRanges") ) ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
      66                 :          0 :     return xUnnamedDBRanges;
      67                 :            : }
      68                 :            : 
      69                 :            : // returns the XDatabaseRange for the autofilter on sheet (nSheet)
      70                 :            : // also populates sName with the name of range
      71                 :            : uno::Reference< sheet::XDatabaseRange >
      72                 :          0 : GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet ) throw ( uno::RuntimeException )
      73                 :            : {
      74 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( GetUnnamedDataBaseRanges( pShell ), uno::UNO_QUERY_THROW );
      75                 :          0 :     uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
      76 [ #  # ][ #  # ]:          0 :     if (xUnnamedDBRanges->hasByTable( nSheet ) )
                 [ #  # ]
      77                 :            :     {
      78 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW );
                 [ #  # ]
      79                 :          0 :         sal_Bool bHasAuto = false;
      80         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
      81 [ #  # ][ #  # ]:          0 :         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto;
                 [ #  # ]
      82         [ #  # ]:          0 :         if ( bHasAuto )
      83                 :            :         {
      84         [ #  # ]:          0 :             xDataBaseRange=xDBRange;
      85                 :          0 :         }
      86                 :            :     }
      87                 :          0 :     return xDataBaseRange;
      88                 :            : }
      89                 :            : 
      90                 :        544 : ScDocShell* GetDocShellFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException )
      91                 :            : {
      92         [ +  - ]:        544 :     ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xRange );
      93         [ -  + ]:        544 :     if ( !pScCellRangesBase )
      94                 :            :     {
      95 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying doc shell uno range object" ) ), uno::Reference< uno::XInterface >() );
      96                 :            :     }
      97                 :        544 :     return pScCellRangesBase->GetDocShell();
      98                 :            : }
      99                 :            : 
     100                 :            : uno::Reference< XHelperInterface >
     101                 :        112 : getUnoSheetModuleObj( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException )
     102                 :            : {
     103         [ +  - ]:        112 :     uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW );
     104 [ +  - ][ +  - ]:        112 :     uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
                 [ +  - ]
     105         [ +  - ]:        112 :     return getUnoSheetModuleObj( xSheet );
     106                 :            : }
     107                 :            : 
     108                 :          0 : ScDocShell* GetDocShellFromRanges( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException )
     109                 :            : {
     110                 :            :     // need the ScCellRangesBase to get docshell
     111         [ #  # ]:          0 :     uno::Reference< uno::XInterface > xIf( xRanges, uno::UNO_QUERY_THROW );
     112         [ #  # ]:          0 :     return GetDocShellFromRange( xIf );
     113                 :            : }
     114                 :            : 
     115                 :         42 : ScDocument* GetDocumentFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException )
     116                 :            : {
     117                 :         42 :         ScDocShell* pDocShell = GetDocShellFromRange( xRange );
     118         [ -  + ]:         42 :         if ( !pDocShell )
     119                 :            :         {
     120 [ #  # ][ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying document from uno range object" ) ), uno::Reference< uno::XInterface >() );
     121                 :            :         }
     122                 :         42 :         return pDocShell->GetDocument();
     123                 :            : }
     124                 :            : 
     125                 :        220 : uno::Reference< frame::XModel > GetModelFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException )
     126                 :            : {
     127                 :        220 :     ScDocShell* pDocShell = GetDocShellFromRange( xRange );
     128         [ -  + ]:        220 :     if ( !pDocShell )
     129                 :            :     {
     130 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying model uno range object" ) ), uno::Reference< uno::XInterface >() );
     131                 :            :     }
     132                 :        220 :     return pDocShell->GetModel();
     133                 :            : }
     134                 :            : 
     135                 :          0 : void implSetZoom( const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs )
     136                 :            : {
     137         [ #  # ]:          0 :     ScTabViewShell* pViewSh = excel::getBestViewShell( xModel );
     138         [ #  # ]:          0 :     Fraction aFract( nZoom, 100 );
     139         [ #  # ]:          0 :     pViewSh->GetViewData()->SetZoom( aFract, aFract, nTabs );
     140         [ #  # ]:          0 :     pViewSh->RefreshZoom();
     141                 :          0 : }
     142                 :            : 
     143                 :          3 : const ::rtl::OUString REPLACE_CELLS_WARNING(  RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning"));
     144                 :            : 
     145                 :            : class PasteCellsWarningReseter
     146                 :            : {
     147                 :            : private:
     148                 :            :     bool bInitialWarningState;
     149                 :          0 :     static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException )
     150                 :            :     {
     151 [ #  # ][ #  # ]:          0 :         static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
                 [ #  # ]
     152 [ #  # ][ #  # ]:          0 :         static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     153                 :            :         static uno::Reference<lang::XMultiComponentFactory > xServiceManager(
     154 [ #  # ][ #  # ]:          0 :                 xContext->getServiceManager(), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     155 [ #  # ][ #  # ]:          0 :         static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     156                 :          0 :         return xProps;
     157                 :            :     }
     158                 :            : 
     159                 :          0 :     bool getReplaceCellsWarning() throw ( uno::RuntimeException )
     160                 :            :     {
     161                 :          0 :         sal_Bool res = false;
     162 [ #  # ][ #  # ]:          0 :         getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res;
                 [ #  # ]
     163                 :          0 :         return ( res == sal_True );
     164                 :            :     }
     165                 :            : 
     166                 :          0 :     void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException )
     167                 :            :     {
     168 [ #  # ][ #  # ]:          0 :         getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) );
                 [ #  # ]
     169                 :          0 :     }
     170                 :            : public:
     171                 :          0 :     PasteCellsWarningReseter() throw ( uno::RuntimeException )
     172                 :            :     {
     173                 :          0 :         bInitialWarningState = getReplaceCellsWarning();
     174         [ #  # ]:          0 :         if ( bInitialWarningState )
     175                 :          0 :             setReplaceCellsWarning( false );
     176                 :          0 :     }
     177                 :          0 :     ~PasteCellsWarningReseter()
     178                 :            :     {
     179         [ #  # ]:          0 :         if ( bInitialWarningState )
     180                 :            :         {
     181                 :            :             // don't allow dtor to throw
     182                 :            :             try
     183                 :            :             {
     184         [ #  # ]:          0 :                 setReplaceCellsWarning( true );
     185                 :            :             }
     186                 :          0 :             catch ( uno::Exception& /*e*/ ){}
     187                 :            :         }
     188         [ #  # ]:          0 :     }
     189                 :            : };
     190                 :            : 
     191                 :            : void
     192                 :          0 : implnPaste( const uno::Reference< frame::XModel>& xModel )
     193                 :            : {
     194         [ #  # ]:          0 :     PasteCellsWarningReseter resetWarningBox;
     195         [ #  # ]:          0 :     ScTabViewShell* pViewShell = getBestViewShell( xModel );
     196         [ #  # ]:          0 :     if ( pViewShell )
     197                 :            :     {
     198         [ #  # ]:          0 :         pViewShell->PasteFromSystem();
     199         [ #  # ]:          0 :         pViewShell->CellContentChanged();
     200         [ #  # ]:          0 :     }
     201                 :          0 : }
     202                 :            : 
     203                 :            : 
     204                 :            : void
     205                 :          0 : implnCopy( const uno::Reference< frame::XModel>& xModel )
     206                 :            : {
     207                 :          0 :     ScTabViewShell* pViewShell = getBestViewShell( xModel );
     208         [ #  # ]:          0 :     if ( pViewShell )
     209                 :            :     {
     210                 :          0 :         pViewShell->CopyToClip(NULL,false,false,true);
     211                 :            : 
     212                 :            :         // mark the copied transfer object so it is used in ScVbaRange::Insert
     213                 :          0 :         ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL );
     214         [ #  # ]:          0 :         if (pClipObj)
     215                 :          0 :             pClipObj->SetUseInApi( true );
     216                 :            :     }
     217                 :          0 : }
     218                 :            : 
     219                 :            : void
     220                 :          0 : implnCut( const uno::Reference< frame::XModel>& xModel )
     221                 :            : {
     222                 :          0 :     ScTabViewShell* pViewShell =  getBestViewShell( xModel );
     223         [ #  # ]:          0 :     if ( pViewShell )
     224                 :            :     {
     225                 :          0 :         pViewShell->CutToClip( NULL, sal_True );
     226                 :            : 
     227                 :            :         // mark the copied transfer object so it is used in ScVbaRange::Insert
     228                 :          0 :         ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL );
     229         [ #  # ]:          0 :         if (pClipObj)
     230                 :          0 :             pClipObj->SetUseInApi( true );
     231                 :            :     }
     232                 :          0 : }
     233                 :            : 
     234                 :          0 : void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
     235                 :            : {
     236         [ #  # ]:          0 :     PasteCellsWarningReseter resetWarningBox;
     237                 :          0 :     sal_Bool bAsLink(false), bOtherDoc(false);
     238                 :          0 :     InsCellCmd eMoveMode = INS_NONE;
     239                 :            : 
     240         [ #  # ]:          0 :     ScTabViewShell* pTabViewShell = getBestViewShell( xModel );
     241         [ #  # ]:          0 :     if ( pTabViewShell )
     242                 :            :     {
     243                 :          0 :         ScViewData* pView = pTabViewShell->GetViewData();
     244 [ #  # ][ #  # ]:          0 :         Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL;
     245 [ #  # ][ #  # ]:          0 :         if ( pView && pWin )
     246                 :            :         {
     247 [ #  # ][ #  # ]:          0 :             if ( bAsLink && bOtherDoc )
     248         [ #  # ]:          0 :                 pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK
     249                 :            :             else
     250                 :            :             {
     251         [ #  # ]:          0 :                 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
     252                 :          0 :                 ScDocument* pDoc = NULL;
     253         [ #  # ]:          0 :                 if ( pOwnClip )
     254                 :          0 :                     pDoc = pOwnClip->GetDocument();
     255                 :            :                 pTabViewShell->PasteFromClip( nFlags, pDoc,
     256                 :            :                     nFunction, bSkipEmpty, bTranspose, bAsLink,
     257         [ #  # ]:          0 :                     eMoveMode, IDF_NONE, sal_True );
     258         [ #  # ]:          0 :                 pTabViewShell->CellContentChanged();
     259                 :            :             }
     260                 :            :         }
     261         [ #  # ]:          0 :     }
     262                 :            : 
     263                 :          0 : }
     264                 :            : 
     265                 :          0 : bool implnCopyRanges( const uno::Reference< frame::XModel>& xModel, ScRangeList& rRangeList )
     266                 :            : {
     267                 :          0 :     bool bResult = false;
     268                 :          0 :     ScTabViewShell* pViewShell = getBestViewShell( xModel );
     269         [ #  # ]:          0 :     if ( pViewShell )
     270                 :            :     {
     271                 :          0 :         bResult = pViewShell->CopyToClip( NULL, rRangeList, false, true, true );
     272                 :            :     }
     273                 :          0 :     return bResult;
     274                 :            : }
     275                 :            : 
     276                 :          0 : bool implnCopyRange( const uno::Reference< frame::XModel>& xModel, const ScRange& rRange )
     277                 :            : {
     278         [ #  # ]:          0 :     ScRangeList aRanges;
     279         [ #  # ]:          0 :     aRanges.Append( rRange );
     280 [ #  # ][ #  # ]:          0 :     return implnCopyRanges( xModel, aRanges );
     281                 :            : }
     282                 :            : 
     283                 :            : ScDocShell*
     284                 :         68 : getDocShell( const css::uno::Reference< css::frame::XModel>& xModel )
     285                 :            : {
     286         [ +  - ]:         68 :     uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW );
     287 [ +  - ][ -  + ]:         68 :     ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() );
     288                 :         68 :     ScDocShell* pDocShell = NULL;
     289         [ +  - ]:         68 :     if ( pModel )
     290         [ +  - ]:         68 :         pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
     291                 :         68 :     return pDocShell;
     292                 :            : 
     293                 :            : }
     294                 :            : 
     295                 :            : ScTabViewShell*
     296                 :          0 : getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel )
     297                 :            : {
     298                 :          0 :     ScDocShell* pDocShell = getDocShell( xModel );
     299         [ #  # ]:          0 :     if ( pDocShell )
     300                 :          0 :         return pDocShell->GetBestViewShell();
     301                 :          0 :     return NULL;
     302                 :            : }
     303                 :            : 
     304                 :            : ScTabViewShell*
     305                 :          0 : getCurrentBestViewShell(  const uno::Reference< uno::XComponentContext >& xContext )
     306                 :            : {
     307         [ #  # ]:          0 :     uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
     308         [ #  # ]:          0 :     return getBestViewShell( xModel );
     309                 :            : }
     310                 :            : 
     311                 :          0 : sal_Bool IsR1C1ReferFormat( ScDocument* pDoc, const rtl::OUString& sRangeStr )
     312                 :            : {
     313         [ #  # ]:          0 :     ScRangeList aCellRanges;
     314         [ #  # ]:          0 :     String sAddress( sRangeStr );
     315                 :          0 :     sal_uInt16 nMask = SCA_VALID;
     316         [ #  # ]:          0 :     sal_uInt16 rResFlags = aCellRanges.Parse( sAddress, pDoc, nMask, formula::FormulaGrammar::CONV_XL_R1C1 );
     317         [ #  # ]:          0 :     if ( rResFlags & SCA_VALID )
     318                 :            :     {
     319                 :          0 :         return sal_True;
     320                 :            :     }
     321 [ #  # ][ #  # ]:          0 :     return false;
     322                 :            : }
     323                 :            : 
     324                 :            : uno::Reference< vba::XHelperInterface >
     325                 :        112 : getUnoSheetModuleObj( const uno::Reference< sheet::XSpreadsheet >& xSheet ) throw ( uno::RuntimeException )
     326                 :            : {
     327         [ +  - ]:        112 :     uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW );
     328                 :        112 :     rtl::OUString sCodeName;
     329 [ +  - ][ +  - ]:        112 :     xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CodeName") ) ) >>= sCodeName;
                 [ +  - ]
     330                 :            :     // #TODO #FIXME ideally we should 'throw' here if we don't get a valid parent, but... it is possible
     331                 :            :     // to create a module ( and use 'Option VBASupport 1' ) for a calc document, in this scenario there
     332                 :            :     // are *NO* special document module objects ( of course being able to switch between vba/non vba mode at
     333                 :            :     // the document in the future could fix this, especially IF the switching of the vba mode takes care to
     334                 :            :     // create the special document module objects if they don't exist.
     335 [ +  - ][ +  - ]:        112 :     uno::Reference< XHelperInterface > xParent( ov::getUnoDocModule( sCodeName, GetDocShellFromRange( xSheet ) ), uno::UNO_QUERY );
         [ +  - ][ +  - ]
                 [ +  - ]
     336                 :        112 :     return xParent;
     337                 :            : }
     338                 :            : 
     339                 :          0 : formula::FormulaGrammar::Grammar GetFormulaGrammar( ScDocument* pDoc, const ScAddress& sAddress, const css::uno::Any& aFormula )
     340                 :            : {
     341                 :          0 :     formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_NATIVE_XL_A1;
     342 [ #  # ][ #  # ]:          0 :     if ( pDoc && aFormula.hasValue() && aFormula.getValueTypeClass() == uno::TypeClass_STRING )
         [ #  # ][ #  # ]
     343                 :            :     {
     344                 :          0 :         rtl::OUString sFormula;
     345                 :          0 :         aFormula >>= sFormula;
     346                 :            : 
     347         [ #  # ]:          0 :         ScCompiler aCompiler( pDoc, sAddress );
     348         [ #  # ]:          0 :         aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
     349 [ #  # ][ #  # ]:          0 :         ScTokenArray* pCode = aCompiler.CompileString( sFormula );
                 [ #  # ]
     350         [ #  # ]:          0 :         if ( pCode )
     351                 :            :         {
     352                 :          0 :             sal_uInt16 nLen = pCode->GetLen();
     353                 :          0 :             formula::FormulaToken** pTokens = pCode->GetArray();
     354         [ #  # ]:          0 :             for ( sal_uInt16 nPos = 0; nPos < nLen; nPos++ )
     355                 :            :             {
     356                 :          0 :                 const formula::FormulaToken& rToken = *pTokens[nPos];
     357         [ #  # ]:          0 :                 switch ( rToken.GetType() )
     358                 :            :                 {
     359                 :            :                     case formula::svSingleRef:
     360                 :            :                     case formula::svDoubleRef:
     361                 :            :                     {
     362                 :          0 :                         return formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1;
     363                 :            :                     }
     364                 :            :                     break;
     365                 :          0 :                     default: break;
     366                 :            :                 }
     367                 :            :             }
     368 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     369                 :            :     }
     370                 :          0 :     return eGrammar;
     371                 :            : }
     372                 :            : 
     373                 :          0 : void CompileExcelFormulaToODF( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula )
     374                 :            : {
     375         [ #  # ]:          0 :     if ( !pDoc )
     376                 :            :     {
     377                 :          0 :         return;
     378                 :            :     }
     379         [ #  # ]:          0 :     ScCompiler aCompiler( pDoc, ScAddress() );
     380 [ #  # ][ #  # ]:          0 :     aCompiler.SetGrammar( excel::GetFormulaGrammar( pDoc, ScAddress(), uno::Any( rtl::OUString( rOldFormula ) ) ) );
         [ #  # ][ #  # ]
     381         [ #  # ]:          0 :     aCompiler.CompileString( rOldFormula );
     382         [ #  # ]:          0 :     aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 );
     383 [ #  # ][ #  # ]:          0 :     aCompiler.CreateStringFromTokenArray( rNewFormula );
     384                 :            : }
     385                 :            : 
     386                 :          0 : void CompileODFFormulaToExcel( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula, const formula::FormulaGrammar::Grammar eGrammar )
     387                 :            : {
     388                 :            :     // eGrammar can be formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 and formula::FormulaGrammar::GRAM_NATIVE_XL_A1
     389         [ #  # ]:          0 :     if ( !pDoc )
     390                 :            :     {
     391                 :            :         return;
     392                 :            :     }
     393         [ #  # ]:          0 :     ScCompiler aCompiler( pDoc, ScAddress() );
     394         [ #  # ]:          0 :     aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 );
     395         [ #  # ]:          0 :     ScTokenArray* pCode = aCompiler.CompileString( rOldFormula );
     396         [ #  # ]:          0 :     aCompiler.SetGrammar( eGrammar );
     397         [ #  # ]:          0 :     if ( !pCode )
     398                 :            :     {
     399                 :            :         return;
     400                 :            :     }
     401                 :          0 :     sal_uInt16 nLen = pCode->GetLen();
     402                 :          0 :     formula::FormulaToken** pTokens = pCode->GetArray();
     403 [ #  # ][ #  # ]:          0 :     for ( sal_uInt16 nPos = 0; nPos < nLen && pTokens[nPos]; nPos++ )
                 [ #  # ]
     404                 :            :     {
     405         [ #  # ]:          0 :         String rFormula;
     406                 :          0 :         formula::FormulaToken* pToken = pTokens[nPos];
     407         [ #  # ]:          0 :         aCompiler.CreateStringFromToken( rFormula, pToken, true );
     408         [ #  # ]:          0 :         if ( pToken->GetOpCode() == ocSep )
     409                 :            :         {
     410                 :            :             // Excel formula separator is ",".
     411         [ #  # ]:          0 :             rFormula = rtl::OUString(",");
     412                 :            :         }
     413         [ #  # ]:          0 :         rNewFormula += rFormula;
     414 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     415                 :            : }
     416                 :            : 
     417                 :            : uno::Reference< XHelperInterface >
     418                 :          2 : getUnoSheetModuleObj( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException )
     419                 :            : {
     420         [ +  - ]:          2 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW );
     421 [ +  - ][ +  - ]:          2 :     uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
     422 [ +  - ][ +  - ]:          2 :     uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
                 [ +  - ]
     423         [ +  - ]:          2 :     return getUnoSheetModuleObj( xRange );
     424                 :            : }
     425                 :            : 
     426                 :            : uno::Reference< XHelperInterface >
     427                 :          0 : getUnoSheetModuleObj( const uno::Reference< table::XCell >& xCell ) throw ( uno::RuntimeException )
     428                 :            : {
     429         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xSheetRange( xCell, uno::UNO_QUERY_THROW );
     430 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
                 [ #  # ]
     431         [ #  # ]:          0 :     return getUnoSheetModuleObj( xSheet );
     432                 :            : }
     433                 :            : 
     434                 :            : uno::Reference< XHelperInterface >
     435                 :          0 : getUnoSheetModuleObj( const uno::Reference< frame::XModel >& xModel, SCTAB nTab ) throw ( uno::RuntimeException )
     436                 :            : {
     437         [ #  # ]:          0 :     uno::Reference< sheet::XSpreadsheetDocument > xDoc( xModel, uno::UNO_QUERY_THROW );
     438 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XIndexAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW );
                 [ #  # ]
     439 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSpreadsheet > xSheet( xSheets->getByIndex( nTab ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     440         [ #  # ]:          0 :     return getUnoSheetModuleObj( xSheet );
     441                 :            : }
     442                 :            : 
     443                 :          0 : void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& xDoc )
     444                 :            : {
     445         [ #  # ]:          0 :     uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
     446         [ #  # ]:          0 :     ScDocShell* pShell = excel::getDocShell( xModel );
     447         [ #  # ]:          0 :     if ( pShell )
     448                 :            :     {
     449         [ #  # ]:          0 :         String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
     450 [ #  # ][ #  # ]:          0 :         pShell->GetBasicManager()->SetName( aPrjName );
     451                 :            : 
     452                 :            :         /*  Set library container to VBA compatibility mode. This will create
     453                 :            :             the VBA Globals object and store it in the Basic manager of the
     454                 :            :             document. */
     455         [ #  # ]:          0 :         uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer();
     456         [ #  # ]:          0 :         uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
     457 [ #  # ][ #  # ]:          0 :         xVBACompat->setVBACompatibilityMode( sal_True );
     458                 :            : 
     459         [ #  # ]:          0 :         if( xLibContainer.is() )
     460                 :            :         {
     461 [ #  # ][ #  # ]:          0 :             if( !xLibContainer->hasByName( aPrjName ) )
         [ #  # ][ #  # ]
     462 [ #  # ][ #  # ]:          0 :                 xLibContainer->createLibrary( aPrjName );
                 [ #  # ]
     463 [ #  # ][ #  # ]:          0 :             uno::Any aLibAny = xLibContainer->getByName( aPrjName );
                 [ #  # ]
     464                 :          0 :             uno::Reference< container::XNameContainer > xLib;
     465         [ #  # ]:          0 :             aLibAny >>= xLib;
     466         [ #  # ]:          0 :             if( xLib.is()  )
     467                 :            :             {
     468         [ #  # ]:          0 :                 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
     469 [ #  # ][ #  # ]:          0 :                 uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW);
     470 [ #  # ][ #  # ]:          0 :                 uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     471                 :            :                 // set up the module info for the workbook and sheets in the nealy created
     472                 :            :                 // spreadsheet
     473                 :          0 :                 ScDocument* pDoc = pShell->GetDocument();
     474         [ #  # ]:          0 :                 String sCodeName = pDoc->GetCodeName();
     475         [ #  # ]:          0 :                 if ( sCodeName.Len() == 0 )
     476                 :            :                 {
     477 [ #  # ][ #  # ]:          0 :                     sCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
                 [ #  # ]
     478         [ #  # ]:          0 :                     pDoc->SetCodeName( sCodeName );
     479                 :            :                 }
     480                 :            : 
     481         [ #  # ]:          0 :                 std::vector< rtl::OUString > sDocModuleNames;
     482 [ #  # ][ #  # ]:          0 :                 sDocModuleNames.push_back( sCodeName );
     483                 :            : 
     484 [ #  # ][ #  # ]:          0 :                 for ( SCTAB index = 0; index < pDoc->GetTableCount(); index++)
     485                 :            :                 {
     486                 :          0 :                     rtl::OUString aName;
     487         [ #  # ]:          0 :                     pDoc->GetCodeName( index, aName );
     488         [ #  # ]:          0 :                     sDocModuleNames.push_back( aName );
     489                 :          0 :                 }
     490                 :            : 
     491                 :          0 :                 std::vector<rtl::OUString>::iterator it_end = sDocModuleNames.end();
     492                 :            : 
     493 [ #  # ][ #  # ]:          0 :                 for ( std::vector<rtl::OUString>::iterator it = sDocModuleNames.begin(); it != it_end; ++it )
     494                 :            :                 {
     495         [ #  # ]:          0 :                     script::ModuleInfo sModuleInfo;
     496                 :            : 
     497 [ #  # ][ #  # ]:          0 :                     uno::Any aName= xVBACodeNamedObjectAccess->getByName( *it );
     498         [ #  # ]:          0 :                     sModuleInfo.ModuleObject.set( aName, uno::UNO_QUERY );
     499                 :          0 :                     sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
     500 [ #  # ][ #  # ]:          0 :                     xVBAModuleInfo->insertModuleInfo( *it, sModuleInfo );
     501 [ #  # ][ #  # ]:          0 :                     if( xLib->hasByName( *it ) )
                 [ #  # ]
     502 [ #  # ][ #  # ]:          0 :                         xLib->replaceByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n") ) ) );
         [ #  # ][ #  # ]
     503                 :            :                     else
     504 [ #  # ][ #  # ]:          0 :                         xLib->insertByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ) ) );
         [ #  # ][ #  # ]
     505 [ #  # ][ #  # ]:          0 :                 }
     506                 :          0 :             }
     507                 :            :         }
     508                 :            : 
     509                 :            :         /*  Trigger the Workbook_Open event, event processor will register
     510                 :            :             itself as listener for specific events. */
     511                 :            :         try
     512                 :            :         {
     513 [ #  # ][ #  # ]:          0 :             uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW );
     514         [ #  # ]:          0 :             uno::Sequence< uno::Any > aArgs;
     515 [ #  # ][ #  # ]:          0 :             xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
         [ #  # ][ #  # ]
     516                 :            :         }
     517         [ #  # ]:          0 :         catch( uno::Exception& )
     518                 :            :         {
     519         [ #  # ]:          0 :         }
     520                 :          0 :     }
     521                 :          0 : }
     522                 :            : 
     523                 :            : SfxItemSet*
     524                 :          0 : ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj )
     525                 :            : {
     526         [ #  # ]:          0 :     return pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : 0;
     527                 :            : }
     528                 :            : 
     529                 :            : // ============================================================================
     530                 :            : 
     531                 :            : } // namespace excel
     532                 :            : } // namespace vba
     533 [ +  - ][ +  - ]:          9 : } // namespace ooo

Generated by: LCOV version 1.10