LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaglobals.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 98 35.7 %
Date: 2012-08-25 Functions: 9 34 26.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 202 19.8 %

           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                 :            : #include <vbahelper/helperdecl.hxx>
      29                 :            : #include "vbaglobals.hxx"
      30                 :            : 
      31                 :            : #include <sal/macros.h>
      32                 :            : 
      33                 :            : #include <comphelper/unwrapargs.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      36                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      37                 :            : #include <cppuhelper/component_context.hxx>
      38                 :            : 
      39                 :            : #include "vbaapplication.hxx"
      40                 :            : #include "vbaworksheet.hxx"
      41                 :            : #include "vbarange.hxx"
      42                 :            : #include <cppuhelper/bootstrap.hxx>
      43                 :            : using namespace ::com::sun::star;
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using namespace ::ooo::vba;
      46                 :            : 
      47                 :            : 
      48                 :            : 
      49                 :            : // =============================================================================
      50                 :            : // ScVbaGlobals
      51                 :            : // =============================================================================
      52                 :            : 
      53                 :            : //ScVbaGlobals::ScVbaGlobals(  css::uno::Reference< css::uno::XComponentContext >const& rxContext,  ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
      54                 :          3 : rtl::OUString sDocCtxName( "ExcelDocumentContext" );
      55                 :            : 
      56         [ +  - ]:          5 : ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
      57                 :            : {
      58                 :            :     OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
      59                 :            : 
      60         [ +  - ]:          5 :         uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
      61         [ +  - ]:          5 :         aInitArgs[ 0 ].Name = rtl::OUString("Application");
      62 [ +  - ][ +  - ]:          5 :         aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
                 [ +  - ]
      63         [ +  - ]:          5 :         aInitArgs[ 1 ].Name = sDocCtxName;
      64 [ +  - ][ +  - ]:          5 :         aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
                 [ +  - ]
      65                 :            : 
      66 [ +  - ][ +  - ]:          5 :         init( aInitArgs );
      67                 :          5 : }
      68                 :            : 
      69                 :          5 : ScVbaGlobals::~ScVbaGlobals()
      70                 :            : {
      71                 :            :     OSL_TRACE("ScVbaGlobals::~ScVbaGlobals");
      72         [ -  + ]:          5 : }
      73                 :            : 
      74                 :            : // =============================================================================
      75                 :            : // XGlobals
      76                 :            : // =============================================================================
      77                 :            : uno::Reference<excel::XApplication >
      78                 :         87 : ScVbaGlobals::getApplication() throw (uno::RuntimeException)
      79                 :            : {
      80                 :            : //  OSL_TRACE("In ScVbaGlobals::getApplication");
      81         [ +  + ]:         87 :         if ( !mxApplication.is() )
      82 [ +  - ][ +  - ]:          5 :         mxApplication.set( new ScVbaApplication( mxContext) );
      83                 :         87 :        return mxApplication;
      84                 :            : }
      85                 :            : 
      86                 :            : 
      87                 :            : uno::Reference<excel::XApplication > SAL_CALL
      88                 :          0 : ScVbaGlobals::getExcel() throw (uno::RuntimeException)
      89                 :            : {
      90                 :          0 :        return getApplication();
      91                 :            : }
      92                 :            : 
      93                 :            : 
      94                 :            : 
      95                 :            : uno::Reference< excel::XWorkbook > SAL_CALL
      96                 :          0 : ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException)
      97                 :            : {
      98                 :            : //  OSL_TRACE("In ScVbaGlobals::getActiveWorkbook");
      99 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_QUERY);
                 [ #  # ]
     100         [ #  # ]:          0 :     if ( xWorkbook.is() )
     101                 :            :     {
     102                 :          0 :         return xWorkbook;
     103                 :            :     }
     104                 :            : // FIXME check if this is correct/desired behavior
     105                 :            :     throw uno::RuntimeException( rtl::OUString(
     106         [ #  # ]:          0 :         "No activeWorkbook available" ), Reference< uno::XInterface >() );
     107                 :            : }
     108                 :            : 
     109                 :            : 
     110                 :            : uno::Reference< excel::XWindow > SAL_CALL
     111                 :          0 : ScVbaGlobals::getActiveWindow() throw (uno::RuntimeException)
     112                 :            : {
     113 [ #  # ][ #  # ]:          0 :     return getApplication()->getActiveWindow();
     114                 :            : }
     115                 :            : 
     116                 :            : uno::Reference< excel::XWorksheet > SAL_CALL
     117                 :          0 : ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException)
     118                 :            : {
     119 [ #  # ][ #  # ]:          0 :     return getApplication()->getActiveSheet();
     120                 :            : }
     121                 :            : 
     122                 :            : uno::Any SAL_CALL
     123                 :          0 : ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException)
     124                 :            : {
     125 [ #  # ][ #  # ]:          0 :     return uno::Any( getApplication()->Workbooks(aIndex) );
     126                 :            : }
     127                 :            : 
     128                 :            : uno::Any SAL_CALL
     129                 :         22 : ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException)
     130                 :            : {
     131 [ +  - ][ +  - ]:         22 :     return getApplication()->Worksheets( aIndex );
     132                 :            : }
     133                 :            : uno::Any SAL_CALL
     134                 :          0 : ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
     135                 :            : {
     136                 :          0 :     return WorkSheets( aIndex );
     137                 :            : }
     138                 :            : 
     139                 :            : uno::Any SAL_CALL
     140                 :         48 : ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException)
     141                 :            : {
     142 [ +  - ][ +  + ]:         48 :     return getApplication()->Range( Cell1, Cell2 );
     143                 :            : }
     144                 :            : 
     145                 :            : uno::Any SAL_CALL
     146                 :          0 : ScVbaGlobals::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException )
     147                 :            : {
     148 [ #  # ][ #  # ]:          0 :     return getApplication()->Names( aIndex );
     149                 :            : }
     150                 :            : 
     151                 :            : uno::Reference< excel::XRange > SAL_CALL
     152                 :          0 : ScVbaGlobals::getActiveCell() throw (uno::RuntimeException)
     153                 :            : {
     154 [ #  # ][ #  # ]:          0 :     return getApplication()->getActiveCell();
     155                 :            : }
     156                 :            : 
     157                 :            : uno::Reference< XAssistant > SAL_CALL
     158                 :          0 : ScVbaGlobals::getAssistant() throw (uno::RuntimeException)
     159                 :            : {
     160 [ #  # ][ #  # ]:          0 :     return getApplication()->getAssistant();
     161                 :            : }
     162                 :            : 
     163                 :            : uno::Any SAL_CALL
     164                 :          0 : ScVbaGlobals::getSelection() throw (uno::RuntimeException)
     165                 :            : {
     166 [ #  # ][ #  # ]:          0 :     return getApplication()->getSelection();
     167                 :            : }
     168                 :            : 
     169                 :            : uno::Reference< excel::XWorkbook > SAL_CALL
     170                 :          0 : ScVbaGlobals::getThisWorkbook() throw (uno::RuntimeException)
     171                 :            : {
     172 [ #  # ][ #  # ]:          0 :     return getApplication()->getThisWorkbook();
     173                 :            : }
     174                 :            : void SAL_CALL
     175                 :          0 : ScVbaGlobals::Calculate()  throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
     176                 :            : {
     177 [ #  # ][ #  # ]:          0 :     return getApplication()->Calculate();
     178                 :            : }
     179                 :            : 
     180                 :            : uno::Reference< excel::XRange > SAL_CALL
     181                 :          0 : ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex ) throw (uno::RuntimeException)
     182                 :            : {
     183 [ #  # ][ #  # ]:          0 :     return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex );
         [ #  # ][ #  # ]
     184                 :            : }
     185                 :            : uno::Reference< excel::XRange > SAL_CALL
     186                 :         12 : ScVbaGlobals::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException)
     187                 :            : {
     188 [ +  - ][ +  - ]:         12 :     return getApplication()->getActiveSheet()->Columns( aIndex );
         [ +  - ][ +  - ]
     189                 :            : }
     190                 :            : 
     191                 :            : uno::Any SAL_CALL
     192                 :          0 : ScVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
     193                 :            : {
     194 [ #  # ][ #  # ]:          0 :     uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW );
     195 [ #  # ][ #  # ]:          0 :     return xBase->CommandBars( aIndex );
     196                 :            : }
     197                 :            : 
     198                 :            : css::uno::Reference< ov::excel::XRange > SAL_CALL
     199                 :          0 : ScVbaGlobals::Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
     200                 :            : {
     201 [ #  # ][ #  # ]:          0 :     return getApplication()->Union(  Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 );
     202                 :            : }
     203                 :            : css::uno::Reference< ov::excel::XRange > SAL_CALL
     204                 :          0 : ScVbaGlobals::Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
     205                 :            : {
     206 [ #  # ][ #  # ]:          0 :     return getApplication()->Intersect(  Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 );
     207                 :            : }
     208                 :            : 
     209                 :            : uno::Any SAL_CALL
     210                 :          0 : ScVbaGlobals::Evaluate( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
     211                 :            : {
     212 [ #  # ][ #  # ]:          0 :     return getApplication()->Evaluate( Name );
     213                 :            : }
     214                 :            : 
     215                 :            : css::uno::Any SAL_CALL
     216                 :          0 : ScVbaGlobals::WorksheetFunction(  ) throw (css::uno::RuntimeException)
     217                 :            : {
     218 [ #  # ][ #  # ]:          0 :     return getApplication()->WorksheetFunction();
     219                 :            : }
     220                 :            : 
     221                 :            : uno::Any SAL_CALL
     222                 :          0 : ScVbaGlobals::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException)
     223                 :            : {
     224 [ #  # ][ #  # ]:          0 :     return getApplication()->Windows( aIndex );
     225                 :            : }
     226                 :            : 
     227                 :            : uno::Reference< excel::XRange > SAL_CALL
     228                 :          0 : ScVbaGlobals::Rows( const uno::Any& aIndex ) throw (uno::RuntimeException)
     229                 :            : {
     230 [ #  # ][ #  # ]:          0 :     return getApplication()->getActiveSheet()->Rows( aIndex );
         [ #  # ][ #  # ]
     231                 :            : 
     232                 :            : }
     233                 :            : 
     234                 :            : 
     235                 :            : uno::Any SAL_CALL
     236                 :          0 : ScVbaGlobals::getDebug() throw (uno::RuntimeException)
     237                 :            : {
     238                 :            :     try // return empty object on error
     239                 :            :     {
     240         [ #  # ]:          0 :         uno::Sequence< uno::Any > aArgs( 1 );
     241 [ #  # ][ #  # ]:          0 :         aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this );
                 [ #  # ]
     242 [ #  # ][ #  # ]:          0 :         uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
                 [ #  # ]
     243         [ #  # ]:          0 :         uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithArgumentsAndContext(
     244         [ #  # ]:          0 :             ::rtl::OUString(  "ooo.vba.Debug"  ), aArgs, mxContext );
     245 [ #  # ][ #  # ]:          0 :         return uno::Any( xVBADebug );
                 [ #  # ]
     246                 :            :     }
     247                 :          0 :     catch( uno::Exception& )
     248                 :            :     {
     249                 :            :     }
     250                 :          0 :     return uno::Any();
     251                 :            : }
     252                 :            : 
     253                 :            : uno::Any SAL_CALL
     254                 :          0 : ScVbaGlobals::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
     255                 :            : {
     256 [ #  # ][ #  # ]:          0 :     return uno::Any( getApplication()->MenuBars(aIndex) );
     257                 :            : }
     258                 :            : 
     259                 :            : uno::Sequence< ::rtl::OUString > SAL_CALL
     260                 :         21 : ScVbaGlobals::getAvailableServiceNames(  ) throw (uno::RuntimeException)
     261                 :            : {
     262                 :            :     static bool bInit = false;
     263 [ +  + ][ +  - ]:         21 :     static uno::Sequence< rtl::OUString > serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() );
         [ +  - ][ #  # ]
     264         [ +  + ]:         21 :     if ( !bInit )
     265                 :            :     {
     266                 :            :          rtl::OUString names[] = {
     267                 :            :             ::rtl::OUString(  "ooo.vba.excel.Range"  ),
     268                 :            :             ::rtl::OUString(  "ooo.vba.excel.Workbook"  ),
     269                 :            :             ::rtl::OUString(  "ooo.vba.excel.Window"  ),
     270                 :            :             ::rtl::OUString(  "ooo.vba.excel.Worksheet"  ),
     271                 :            :             ::rtl::OUString(  "ooo.vba.excel.Application"  ),
     272                 :            :             ::rtl::OUString(  "ooo.vba.excel.Hyperlink"  ),
     273                 :            :             ::rtl::OUString(  "com.sun.star.script.vba.VBASpreadsheetEventProcessor"  )
     274                 :         24 :           };
     275                 :          3 :         sal_Int32 nExcelServices = ( sizeof( names )/ sizeof( names[0] ) );
     276                 :          3 :         sal_Int32 startIndex = serviceNames.getLength();
     277         [ +  - ]:          3 :         serviceNames.realloc( serviceNames.getLength() + nExcelServices );
     278         [ +  + ]:         24 :         for ( sal_Int32 index = 0; index < nExcelServices; ++index )
     279         [ +  - ]:         21 :              serviceNames[ startIndex + index ] = names[ index ];
     280 [ +  + ][ #  # ]:         24 :         bInit = true;
     281                 :            :     }
     282                 :         21 :     return serviceNames;
     283                 :            : }
     284                 :            : 
     285                 :            : rtl::OUString
     286                 :          0 : ScVbaGlobals::getServiceImplName()
     287                 :            : {
     288                 :          0 :     return rtl::OUString("ScVbaGlobals");
     289                 :            : }
     290                 :            : 
     291                 :            : uno::Sequence< rtl::OUString >
     292                 :          0 : ScVbaGlobals::getServiceNames()
     293                 :            : {
     294 [ #  # ][ #  # ]:          0 :         static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     295         [ #  # ]:          0 :         if ( aServiceNames.getLength() == 0 )
     296                 :            :         {
     297                 :          0 :                 aServiceNames.realloc( 1 );
     298         [ #  # ]:          0 :                 aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.excel.Globals"  );
     299                 :            :         }
     300                 :          0 :         return aServiceNames;
     301                 :            : }
     302                 :            : 
     303                 :            : namespace globals
     304                 :            : {
     305                 :            : namespace sdecl = comphelper::service_decl;
     306                 :          3 : sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<true> > serviceImpl;
     307                 :          3 : extern sdecl::ServiceDecl const serviceDecl(
     308                 :            :     serviceImpl,
     309                 :            :     "ScVbaGlobals",
     310                 :            :     "ooo.vba.excel.Globals" );
     311 [ +  - ][ +  - ]:          9 : }
     312                 :            : 
     313                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10