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

Generated by: LCOV version 1.10