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

Generated by: LCOV version 1.11