LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaapplication.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 325 639 50.9 %
Date: 2014-04-11 Functions: 37 88 42.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : 
      22             : #include <com/sun/star/frame/XLayoutManager.hpp>
      23             : #include <com/sun/star/frame/XDesktop.hpp>
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/sheet/XCalculatable.hpp>
      26             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      27             : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      28             : #include <com/sun/star/sheet/XNamedRanges.hpp>
      29             : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      30             : #include <com/sun/star/sheet/XSpreadsheets.hpp>
      31             : #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
      32             : #include <com/sun/star/task/XStatusIndicator.hpp>
      33             : #include <com/sun/star/util/PathSettings.hpp>
      34             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      35             : #include <ooo/vba/XExecutableDialog.hpp>
      36             : #include <ooo/vba/excel/XlCalculation.hpp>
      37             : #include <ooo/vba/excel/XlMousePointer.hpp>
      38             : 
      39             : #include "vbaapplication.hxx"
      40             : #include "vbaworkbooks.hxx"
      41             : #include "vbaworkbook.hxx"
      42             : #include "vbaworksheets.hxx"
      43             : #include "vbarange.hxx"
      44             : #include "vbawsfunction.hxx"
      45             : #include "vbadialogs.hxx"
      46             : #include "vbawindow.hxx"
      47             : #include "vbawindows.hxx"
      48             : #include "vbaglobals.hxx"
      49             : #include "vbamenubars.hxx"
      50             : #include "tabvwsh.hxx"
      51             : #include "gridwin.hxx"
      52             : #include "vbanames.hxx"
      53             : #include <vbahelper/vbashape.hxx>
      54             : #include "vbatextboxshape.hxx"
      55             : #include "vbaassistant.hxx"
      56             : #include "sc.hrc"
      57             : #include "macromgr.hxx"
      58             : #include "defaultsoptions.hxx"
      59             : 
      60             : #include <osl/file.hxx>
      61             : #include <rtl/instance.hxx>
      62             : 
      63             : #include <sfx2/request.hxx>
      64             : #include <sfx2/objsh.hxx>
      65             : #include <sfx2/viewfrm.hxx>
      66             : #include <sfx2/app.hxx>
      67             : 
      68             : #include <comphelper/processfactory.hxx>
      69             : 
      70             : #include <toolkit/awt/vclxwindow.hxx>
      71             : #include <toolkit/helper/vclunohelper.hxx>
      72             : 
      73             : #include <tools/diagnose_ex.h>
      74             : #include <tools/urlobj.hxx>
      75             : 
      76             : #include <docuno.hxx>
      77             : 
      78             : #include <basic/sbx.hxx>
      79             : #include <basic/sbstar.hxx>
      80             : #include <basic/sbuno.hxx>
      81             : #include <basic/sbmeth.hxx>
      82             : 
      83             : #include "convuno.hxx"
      84             : #include "cellsuno.hxx"
      85             : #include "miscuno.hxx"
      86             : #include "unonames.hxx"
      87             : #include "docsh.hxx"
      88             : #include <vbahelper/helperdecl.hxx>
      89             : #include "excelvbahelper.hxx"
      90             : 
      91             : #include <basic/sbmod.hxx>
      92             : #include <basic/sbxobj.hxx>
      93             : 
      94             : #include "viewutil.hxx"
      95             : #include "docoptio.hxx"
      96             : 
      97             : using namespace ::ooo::vba;
      98             : using namespace ::com::sun::star;
      99             : using ::com::sun::star::uno::Reference;
     100             : using ::com::sun::star::uno::UNO_QUERY_THROW;
     101             : using ::com::sun::star::uno::UNO_QUERY;
     102             : 
     103             : /** Global application settings shared by all open workbooks. */
     104             : struct ScVbaAppSettings
     105             : {
     106             :     sal_Int32 mnCalculation;
     107             :     sal_Bool mbDisplayAlerts;
     108             :     sal_Bool mbEnableEvents;
     109             :     sal_Bool mbExcel4Menus;
     110             :     sal_Bool mbDisplayNoteIndicator;
     111             :     sal_Bool mbShowWindowsInTaskbar;
     112             :     sal_Bool mbEnableCancelKey;
     113             :     explicit ScVbaAppSettings();
     114             : };
     115             : 
     116           2 : ScVbaAppSettings::ScVbaAppSettings() :
     117             :     mnCalculation( excel::XlCalculation::xlCalculationAutomatic ),
     118             :     mbDisplayAlerts( sal_True ),
     119             :     mbEnableEvents( sal_True ),
     120             :     mbExcel4Menus( sal_False ),
     121             :     mbDisplayNoteIndicator( sal_True ),
     122             :     mbShowWindowsInTaskbar( sal_True ),
     123           2 :     mbEnableCancelKey( sal_False )
     124             : {
     125           2 : }
     126             : 
     127             : struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {};
     128             : 
     129          26 : ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
     130             :     ScVbaApplication_BASE( xContext ),
     131          26 :     mrAppSettings( ScVbaStaticAppSettings::get() )
     132             : {
     133          26 : }
     134             : 
     135           0 : ScVbaApplication::~ScVbaApplication()
     136             : {
     137           0 : }
     138             : 
     139        2475 : /*static*/ bool ScVbaApplication::getDocumentEventsEnabled()
     140             : {
     141        2475 :     return ScVbaStaticAppSettings::get().mbEnableEvents;
     142             : }
     143             : 
     144           0 : SfxObjectShell* ScVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     145             : {
     146           0 :     return static_cast< SfxObjectShell* >( excel::getDocShell( xModel ) );
     147             : }
     148             : 
     149             : OUString SAL_CALL
     150           0 : ScVbaApplication::getExactName( const OUString& aApproximateName ) throw (uno::RuntimeException, std::exception)
     151             : {
     152           0 :     uno::Reference< beans::XExactName > xWSF( new ScVbaWSFunction( this, mxContext ) );
     153           0 :     return xWSF->getExactName( aApproximateName );
     154             : }
     155             : 
     156             : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
     157           0 : ScVbaApplication::getIntrospection() throw(css::uno::RuntimeException, std::exception)
     158             : {
     159           0 :     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     160           0 :     return xWSF->getIntrospection();
     161             : }
     162             : 
     163             : uno::Any SAL_CALL
     164           0 : ScVbaApplication::invoke( const OUString& FunctionName, const uno::Sequence< uno::Any >& Params, uno::Sequence< sal_Int16 >& OutParamIndex, uno::Sequence< uno::Any >& OutParam) throw(lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
     165             : {
     166             :     /*  When calling the functions directly at the Application object, no runtime
     167             :         errors are thrown, but the error is inserted into the return value. */
     168           0 :     uno::Any aAny;
     169             :     try
     170             :     {
     171           0 :         uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     172           0 :         aAny = xWSF->invoke( FunctionName, Params, OutParamIndex, OutParam );
     173             :     }
     174           0 :     catch (const uno::Exception&)
     175             :     {
     176           0 :         aAny <<= script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), 1000, OUString() );
     177             :     }
     178           0 :     return aAny;
     179             : }
     180             : 
     181             : void SAL_CALL
     182           0 : ScVbaApplication::setValue( const OUString& PropertyName, const uno::Any& Value ) throw(beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
     183             : {
     184           0 :     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     185           0 :     xWSF->setValue( PropertyName, Value );
     186           0 : }
     187             : 
     188             : uno::Any SAL_CALL
     189           0 : ScVbaApplication::getValue( const OUString& PropertyName ) throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     190             : {
     191           0 :     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     192           0 :     return xWSF->getValue( PropertyName );
     193             : }
     194             : 
     195             : sal_Bool SAL_CALL
     196           0 : ScVbaApplication::hasMethod( const OUString& Name ) throw(uno::RuntimeException, std::exception)
     197             : {
     198           0 :     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     199           0 :     return xWSF->hasMethod( Name );
     200             : }
     201             : 
     202             : sal_Bool SAL_CALL
     203           0 : ScVbaApplication::hasProperty( const OUString& Name ) throw(uno::RuntimeException, std::exception)
     204             : {
     205           0 :     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
     206           0 :     return xWSF->hasProperty( Name );
     207             : }
     208             : 
     209             : uno::Reference< excel::XWorkbook >
     210         263 : ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException, std::exception)
     211             : {
     212         263 :     uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );
     213         526 :     uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
     214         263 :     if( xWorkbook.is() ) return xWorkbook;
     215             :     // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
     216         263 :     return new ScVbaWorkbook( this, mxContext, xModel );
     217             : }
     218             : 
     219             : uno::Reference< excel::XWorkbook > SAL_CALL
     220           0 : ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException, std::exception)
     221             : {
     222           0 :     uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW );
     223           0 :     uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
     224           0 :     if( xWorkbook.is() ) return xWorkbook;
     225             :     // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
     226           0 :     return new ScVbaWorkbook( this, mxContext, xModel );
     227             : }
     228             : 
     229             : uno::Reference< XAssistant > SAL_CALL
     230           0 : ScVbaApplication::getAssistant() throw (uno::RuntimeException, std::exception)
     231             : {
     232           0 :     return uno::Reference< XAssistant >( new ScVbaAssistant( this, mxContext ) );
     233             : }
     234             : 
     235             : uno::Any SAL_CALL
     236          25 : ScVbaApplication::getSelection() throw (uno::RuntimeException, std::exception)
     237             : {
     238             :     OSL_TRACE("** ScVbaApplication::getSelection() ** ");
     239          25 :     uno::Reference< frame::XModel > xModel( getCurrentDocument() );
     240             : 
     241          50 :     Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), UNO_QUERY_THROW );
     242          50 :     Reference< beans::XPropertySet > xPropSet( xSelSupp, UNO_QUERY_THROW );
     243          50 :     OUString aPropName( SC_UNO_FILTERED_RANGE_SELECTION );
     244          50 :     uno::Any aOldVal = xPropSet->getPropertyValue( aPropName );
     245          50 :     uno::Any any;
     246          25 :     any <<= false;
     247          25 :     xPropSet->setPropertyValue( aPropName, any );
     248             :     uno::Reference< uno::XInterface > aSelection = ScUnoHelpFunctions::AnyToInterface(
     249          50 :         xSelSupp->getSelection() );
     250          25 :     xPropSet->setPropertyValue( aPropName, aOldVal );
     251             : 
     252          25 :     if (!aSelection.is())
     253             :     {
     254             :         throw uno::RuntimeException(
     255             :             OUString("failed to obtain current selection"),
     256           0 :             uno::Reference< uno::XInterface >() );
     257             :     }
     258             : 
     259          50 :     uno::Reference< lang::XServiceInfo > xServiceInfo( aSelection, uno::UNO_QUERY_THROW );
     260          50 :     OUString sImplementationName = xServiceInfo->getImplementationName();
     261             : 
     262          25 :     if( sImplementationName.equalsIgnoreAsciiCase("com.sun.star.drawing.SvxShapeCollection") )
     263             :     {
     264           2 :         uno::Reference< drawing::XShapes > xShapes( aSelection, uno::UNO_QUERY_THROW );
     265           4 :         uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
     266           4 :         uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
     267             :     // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape
     268             :     // and the uno object implements the com.sun.star.drawing.Text service
     269             :     // return a textboxshape object
     270           2 :     if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape )
     271             :     {
     272           2 :         uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW );
     273           2 :         if ( xShapeServiceInfo->supportsService("com.sun.star.drawing.Text")  )
     274             :         {
     275           2 :                 return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
     276           0 :         }
     277             :     }
     278           2 :         return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) );
     279             :     }
     280          54 :     else if( xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRange") ||
     281          31 :              xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRanges") )
     282             :     {
     283          23 :         uno::Reference< table::XCellRange > xRange( aSelection, ::uno::UNO_QUERY);
     284          23 :         if ( !xRange.is() )
     285             :         {
     286           4 :             uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aSelection, ::uno::UNO_QUERY);
     287           4 :             if ( xRanges.is() )
     288           4 :                 return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), mxContext, xRanges ) ) );
     289             : 
     290             :         }
     291          19 :         return uno::makeAny( uno::Reference< excel::XRange >(new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange ) ) );
     292             :     }
     293             :     else
     294             :     {
     295           0 :         throw uno::RuntimeException( sImplementationName + OUString(
     296           0 :               " not supported"), uno::Reference< uno::XInterface >() );
     297          25 :     }
     298             : }
     299             : 
     300             : uno::Reference< excel::XRange >
     301          30 : ScVbaApplication::getActiveCell() throw (uno::RuntimeException, std::exception )
     302             : {
     303          30 :     uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
     304          60 :     uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
     305          30 :     ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
     306          30 :     if ( !pViewShell )
     307           0 :         throw uno::RuntimeException("No ViewShell available", uno::Reference< uno::XInterface >() );
     308          30 :     ScViewData* pTabView = pViewShell->GetViewData();
     309          30 :     if ( !pTabView )
     310           0 :         throw uno::RuntimeException("No ViewData available", uno::Reference< uno::XInterface >() );
     311             : 
     312          30 :     sal_Int32 nCursorX = pTabView->GetCurX();
     313          30 :     sal_Int32 nCursorY = pTabView->GetCurY();
     314             : 
     315             :     // #i117392# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
     316          60 :     return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) );
     317             : }
     318             : 
     319             : uno::Any SAL_CALL
     320           0 : ScVbaApplication::International( sal_Int32 /*Index*/ ) throw (uno::RuntimeException, std::exception)
     321             : {
     322             :     // complete stub for now
     323             :     // #TODO flesh out some of the Indices we could handle
     324           0 :     uno::Any aRet;
     325           0 :     return aRet;
     326             : }
     327             : 
     328             : uno::Any SAL_CALL
     329          10 : ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
     330             : {
     331          10 :     uno::Reference< XCollection > xWorkBooks( new ScVbaWorkbooks( this, mxContext ) );
     332          10 :     if (  aIndex.getValueTypeClass() == uno::TypeClass_VOID )
     333             :     {
     334             :         // void then somebody did Workbooks.something in vba
     335           2 :         return uno::Any( xWorkBooks );
     336             :     }
     337             : 
     338           8 :     return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) );
     339             : }
     340             : 
     341             : uno::Any SAL_CALL
     342         127 : ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
     343             : {
     344         127 :     uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW );
     345         127 :     return xWorkbook->Worksheets( aIndex );
     346             : }
     347             : 
     348             : uno::Any SAL_CALL
     349           0 : ScVbaApplication::WorksheetFunction( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     350             : {
     351           0 :     return uno::makeAny( uno::Reference< script::XInvocation >( new ScVbaWSFunction( this, mxContext ) ) );
     352             : }
     353             : 
     354             : uno::Any SAL_CALL
     355           0 : ScVbaApplication::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
     356             : {
     357             :     // #TODO Evaluate allows other things to be evaluated, e.g. functions
     358             :     // I think ( like SIN(3) etc. ) need to investigate that
     359             :     // named Ranges also? e.g. [MyRange] if so need a list of named ranges
     360           0 :     uno::Any aVoid;
     361           0 :     return uno::Any( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name ), aVoid ) );
     362             : }
     363             : 
     364             : uno::Any
     365           0 : ScVbaApplication::Dialogs( const uno::Any &aIndex ) throw (uno::RuntimeException, std::exception)
     366             : {
     367           0 :     uno::Reference< excel::XDialogs > xDialogs( new ScVbaDialogs( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) );
     368           0 :     if( !aIndex.hasValue() )
     369           0 :         return uno::Any( xDialogs );
     370           0 :     return uno::Any( xDialogs->Item( aIndex ) );
     371             : }
     372             : 
     373             : uno::Reference< excel::XWindow > SAL_CALL
     374          13 : ScVbaApplication::getActiveWindow() throw (uno::RuntimeException, std::exception)
     375             : {
     376          13 :     uno::Reference< frame::XModel > xModel = getCurrentDocument();
     377          26 :     uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
     378          26 :     uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW );
     379          13 :     uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) );
     380          26 :     return xWin;
     381             : }
     382             : 
     383             : uno::Any SAL_CALL
     384           1 : ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException, std::exception)
     385             : {
     386             :     //# FIXME TODO, implementation
     387           1 :     uno::Any result;
     388           1 :     result <<= sal_False;
     389           1 :     return result;
     390             : }
     391             : 
     392             : void SAL_CALL
     393           1 : ScVbaApplication::setCutCopyMode( const uno::Any& /* _cutcopymode */ ) throw (uno::RuntimeException, std::exception)
     394             : {
     395             :     //# FIXME TODO, implementation
     396           1 : }
     397             : 
     398             : uno::Any SAL_CALL
     399           0 : ScVbaApplication::getStatusBar() throw (uno::RuntimeException, std::exception)
     400             : {
     401           0 :     return uno::makeAny( !getDisplayStatusBar() );
     402             : }
     403             : 
     404             : void SAL_CALL
     405           0 : ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::RuntimeException, std::exception)
     406             : {
     407           0 :     OUString sText;
     408           0 :     sal_Bool bDefault = false;
     409           0 :     uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     410           0 :     uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     411           0 :     uno::Reference< task::XStatusIndicator > xStatusIndicator( xStatusIndicatorSupplier->getStatusIndicator(), uno::UNO_QUERY_THROW );
     412           0 :     if( _statusbar >>= sText )
     413             :     {
     414           0 :         setDisplayStatusBar( sal_True );
     415           0 :         if ( !sText.isEmpty() )
     416           0 :             xStatusIndicator->start( sText, 100 );
     417             :         else
     418           0 :             xStatusIndicator->end();        // restore normal state for empty text
     419             :     }
     420           0 :     else if( _statusbar >>= bDefault )
     421             :     {
     422           0 :         if( !bDefault )
     423             :         {
     424           0 :             xStatusIndicator->end();
     425           0 :             setDisplayStatusBar( sal_True );
     426             :         }
     427             :     }
     428             :     else
     429             :         throw uno::RuntimeException("Invalid prarameter. It should be a string or False",
     430           0 :             uno::Reference< uno::XInterface >() );
     431           0 : }
     432             : 
     433             : ::sal_Int32 SAL_CALL
     434           5 : ScVbaApplication::getCalculation() throw (uno::RuntimeException, std::exception)
     435             : {
     436             :     // TODO: in Excel, this is an application-wide setting
     437           5 :     uno::Reference<sheet::XCalculatable> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
     438           5 :     if(xCalc->isAutomaticCalculationEnabled())
     439           2 :         return excel::XlCalculation::xlCalculationAutomatic;
     440             :     else
     441           3 :         return excel::XlCalculation::xlCalculationManual;
     442             : }
     443             : 
     444             : void SAL_CALL
     445           4 : ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException, std::exception)
     446             : {
     447             :     // TODO: in Excel, this is an application-wide setting
     448           4 :     uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
     449           4 :     switch(_calculation)
     450             :     {
     451             :         case excel::XlCalculation::xlCalculationManual:
     452           2 :             xCalc->enableAutomaticCalculation(false);
     453           2 :             break;
     454             :         case excel::XlCalculation::xlCalculationAutomatic:
     455             :         case excel::XlCalculation::xlCalculationSemiautomatic:
     456           2 :             xCalc->enableAutomaticCalculation(sal_True);
     457           2 :             break;
     458           4 :     }
     459           4 : }
     460             : 
     461             : uno::Any SAL_CALL
     462          25 : ScVbaApplication::Windows( const uno::Any& aIndex  ) throw (uno::RuntimeException, std::exception)
     463             : {
     464          25 :     uno::Reference< excel::XWindows >  xWindows( new ScVbaWindows( this, mxContext ) );
     465          25 :     if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
     466          25 :         return uno::Any( xWindows );
     467           0 :     return uno::Any( xWindows->Item( aIndex, uno::Any() ) );
     468             : }
     469             : void SAL_CALL
     470           0 : ScVbaApplication::wait( double time ) throw (uno::RuntimeException, std::exception)
     471             : {
     472           0 :     StarBASIC* pBasic = SFX_APP()->GetBasic();
     473           0 :     SbxArrayRef aArgs = new SbxArray;
     474           0 :     SbxVariableRef aRef = new SbxVariable;
     475           0 :     aRef->PutDouble( time );
     476           0 :     aArgs->Put(  aRef, 1 );
     477           0 :     SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( OUString("WaitUntil"), SbxCLASS_METHOD );
     478             : 
     479           0 :     if ( pMeth )
     480             :     {
     481           0 :         pMeth->SetParameters( aArgs );
     482           0 :         SbxVariableRef refTemp = pMeth;
     483             :         // forces a broadcast
     484           0 :         SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
     485           0 :     }
     486           0 : }
     487             : 
     488             : uno::Any SAL_CALL
     489         671 : ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
     490             : {
     491         671 :     uno::Reference< excel::XRange > xVbRange = ScVbaRange::ApplicationRange( mxContext, Cell1, Cell2 );
     492         669 :     return uno::makeAny( xVbRange );
     493             : }
     494             : 
     495             : uno::Any SAL_CALL
     496           0 : ScVbaApplication::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
     497             : {
     498           0 :     uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     499           0 :     uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
     500           0 :     uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue(
     501           0 :         OUString( "NamedRanges" ) ), uno::UNO_QUERY_THROW );
     502             : 
     503           0 :     css::uno::Reference< excel::XNames > xNames ( new ScVbaNames( this , mxContext , xNamedRanges , xModel ) );
     504           0 :     if (  aIndex.getValueTypeClass() == uno::TypeClass_VOID )
     505             :     {
     506           0 :         return uno::Any( xNames );
     507             : }
     508           0 :     return uno::Any( xNames->Item( aIndex, uno::Any() ) );
     509             : }
     510             : 
     511             : 
     512             : uno::Reference< excel::XWorksheet > SAL_CALL
     513          80 : ScVbaApplication::getActiveSheet() throw (uno::RuntimeException, std::exception)
     514             : {
     515          80 :     uno::Reference< excel::XWorksheet > result;
     516         160 :     uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY );
     517          80 :     if ( xWorkbook.is() )
     518             :     {
     519             :         uno::Reference< excel::XWorksheet > xWorksheet(
     520          80 :             xWorkbook->getActiveSheet(), uno::UNO_QUERY );
     521          80 :         if ( xWorksheet.is() )
     522             :         {
     523          80 :             result = xWorksheet;
     524          80 :         }
     525             :     }
     526             : 
     527          80 :     if ( !result.is() )
     528             :     {
     529             :         // Fixme - check if this is reasonable/desired behavior
     530             :         throw uno::RuntimeException("No activeSheet available",
     531           0 :             uno::Reference< uno::XInterface >() );
     532             :     }
     533         160 :     return result;
     534             : 
     535             : }
     536             : 
     537             : /*******************************************************************************
     538             :  *  In msdn:
     539             :  *  Reference   Optional Variant. The destination. Can be a Range
     540             :  *  object, a string that contains a cell reference in R1C1-style notation,
     541             :  *  or a string that contains a Visual Basic procedure name.
     542             :  *  Scroll   Optional Variant. True to scrol, False to not scroll through
     543             :  *  the window. The default is False.
     544             :  *  Parser is split to three parts, Range, R1C1 string and procedure name.
     545             :  *  by test excel, it seems Scroll no effect. ???
     546             : *******************************************************************************/
     547             : void SAL_CALL
     548           3 : ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) throw (uno::RuntimeException, std::exception)
     549             : {
     550             :     //test Scroll is a boolean
     551           3 :     sal_Bool bScroll = false;
     552             :     //R1C1-style string or a string of procedure name.
     553             : 
     554           3 :     if( Scroll.hasValue() )
     555             :     {
     556           0 :         sal_Bool aScroll = false;
     557           0 :         if( Scroll >>= aScroll )
     558             :         {
     559           0 :             bScroll = aScroll;
     560             :         }
     561             :         else
     562             :             throw uno::RuntimeException("second parameter should be boolean",
     563           0 :                     uno::Reference< uno::XInterface >() );
     564             :     }
     565             : 
     566           3 :     OUString sRangeName;
     567           3 :     if( Reference >>= sRangeName )
     568             :     {
     569           2 :         uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     570             :         uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
     571           4 :                 xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     572           4 :         uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
     573             : 
     574           2 :         ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
     575           2 :         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
     576             :         try
     577             :         {
     578             :             uno::Reference< excel::XRange > xVbaSheetRange = ScVbaRange::getRangeObjectForName(
     579           2 :                 mxContext, sRangeName, excel::getDocShell( xModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
     580             : 
     581           2 :             if( bScroll )
     582             :             {
     583           0 :                 xVbaSheetRange->Select();
     584           0 :                 uno::Reference< excel::XWindow >  xWindow = getActiveWindow();
     585           0 :                 ScSplitPos eWhich = pShell->GetViewData()->GetActivePart();
     586           0 :                 sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich));
     587           0 :                 sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich));
     588           0 :                 xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaSheetRange->getRow() - 1) ),
     589             :                          uno::makeAny( (sal_Int16)nValueY ),
     590           0 :                          uno::makeAny( (sal_Int16)(xVbaSheetRange->getColumn() - 1)  ),
     591           0 :                          uno::makeAny( (sal_Int16)nValueX ) );
     592           0 :                 gridWindow->GrabFocus();
     593             :             }
     594             :             else
     595             :             {
     596           2 :                 xVbaSheetRange->Select();
     597           2 :                 gridWindow->GrabFocus();
     598           2 :             }
     599             :         }
     600           0 :         catch (const uno::RuntimeException&)
     601             :         {
     602             :             //maybe this should be a procedure name
     603             :             //TODO for procedure name
     604             :             //browse::XBrowseNodeFactory is a singlton. OUString( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory")
     605             :             //and the createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) to get a root browse::XBrowseNode.
     606             :             //for query XInvocation interface.
     607             :             //but how to directly get the XInvocation?
     608             :             throw uno::RuntimeException("invalid reference for range name, it should be procedure name",
     609           0 :                     uno::Reference< uno::XInterface >() );
     610             :         }
     611           4 :         return;
     612             :     }
     613           2 :     uno::Reference< excel::XRange > xRange;
     614           1 :     if( Reference >>= xRange )
     615             :     {
     616           1 :         uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
     617           1 :         ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
     618           1 :         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
     619           1 :         if ( xVbaRange.is() )
     620             :         {
     621             :             //TODO bScroll should be using, In this time, it doesenot have effection
     622           1 :             if( bScroll )
     623             :             {
     624           0 :                 xVbaRange->Select();
     625           0 :                 uno::Reference< excel::XWindow >  xWindow = getActiveWindow();
     626           0 :                 ScSplitPos eWhich = pShell->GetViewData()->GetActivePart();
     627           0 :                 sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich));
     628           0 :                 sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich));
     629           0 :                 xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaRange->getRow() - 1) ),
     630             :                          uno::makeAny( (sal_Int16)nValueY ),
     631           0 :                          uno::makeAny( (sal_Int16)(xVbaRange->getColumn() - 1)  ),
     632           0 :                          uno::makeAny( (sal_Int16)nValueX ) );
     633           0 :                 gridWindow->GrabFocus();
     634             :             }
     635             :             else
     636             :             {
     637           1 :                 xVbaRange->Select();
     638           1 :                 gridWindow->GrabFocus();
     639             :             }
     640             :         }
     641           1 :         return;
     642             :     }
     643             :     throw uno::RuntimeException("invalid reference or name",
     644           0 :             uno::Reference< uno::XInterface >() );
     645             : }
     646             : 
     647             : sal_Int32 SAL_CALL
     648           0 : ScVbaApplication::getCursor() throw (uno::RuntimeException, std::exception)
     649             : {
     650           0 :     sal_Int32 nPointerStyle =  getPointerStyle(getCurrentDocument());
     651             : 
     652           0 :     switch( nPointerStyle )
     653             :     {
     654             :         case POINTER_ARROW:
     655           0 :             return excel::XlMousePointer::xlNorthwestArrow;
     656             :         case POINTER_NULL:
     657           0 :             return excel::XlMousePointer::xlDefault;
     658             :         case POINTER_WAIT:
     659           0 :             return excel::XlMousePointer::xlWait;
     660             :         case POINTER_TEXT:
     661           0 :             return excel::XlMousePointer::xlIBeam;
     662             :         default:
     663           0 :             return excel::XlMousePointer::xlDefault;
     664             :     }
     665             : }
     666             : 
     667             : void SAL_CALL
     668           0 : ScVbaApplication::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException, std::exception)
     669             : {
     670             :     try
     671             :     {
     672           0 :     uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     673           0 :         switch( _cursor )
     674             :         {
     675             :             case excel::XlMousePointer::xlNorthwestArrow:
     676             :             {
     677           0 :                 const Pointer& rPointer( POINTER_ARROW );
     678           0 :                 setCursorHelper( xModel, rPointer, false );
     679           0 :                 break;
     680             :             }
     681             :             case excel::XlMousePointer::xlWait:
     682             :             case excel::XlMousePointer::xlIBeam:
     683             :             {
     684           0 :                 const Pointer& rPointer( static_cast< PointerStyle >( _cursor ) );
     685             :                 //It will set the edit window, toobar and statusbar's mouse pointer.
     686           0 :                 setCursorHelper( xModel, rPointer, true );
     687           0 :                 break;
     688             :             }
     689             :             case excel::XlMousePointer::xlDefault:
     690             :             {
     691           0 :                 const Pointer& rPointer( POINTER_NULL );
     692           0 :                 setCursorHelper( xModel, rPointer, false );
     693           0 :                 break;
     694             :             }
     695             :             default:
     696           0 :                 throw uno::RuntimeException("Unknown value for Cursor pointer", uno::Reference< uno::XInterface >() );
     697             :                 // TODO: isn't this a flaw in the API? It should be allowed to throw an
     698             :                 // IllegalArgumentException, or so
     699           0 :         }
     700             :     }
     701           0 :     catch (const uno::Exception&)
     702             :     {
     703             :         DBG_UNHANDLED_EXCEPTION();
     704             :     }
     705           0 : }
     706             : 
     707             : // #TODO perhaps we should switch the return type depending of the filter
     708             : // type, e.g. return Calc for Calc and Excel if its an imported doc
     709             : OUString SAL_CALL
     710           4 : ScVbaApplication::getName() throw (uno::RuntimeException, std::exception)
     711             : {
     712           4 :     static OUString appName("Microsoft Excel" );
     713           4 :     return appName;
     714             : }
     715             : 
     716             : // #TODO #FIXME get/setDisplayAlerts are just stub impl
     717             : // here just the status of the switch is set
     718             : // the function that throws an error message needs to
     719             : // evaluate this switch in order to know whether it has to disable the
     720             : // error message thrown by OpenOffice
     721             : 
     722             : void SAL_CALL
     723           3 : ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException, std::exception)
     724             : {
     725           3 :     mrAppSettings.mbDisplayAlerts = displayAlerts;
     726           3 : }
     727             : 
     728             : sal_Bool SAL_CALL
     729           0 : ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException, std::exception)
     730             : {
     731           0 :     return mrAppSettings.mbDisplayAlerts;
     732             : }
     733             : 
     734             : void SAL_CALL
     735          44 : ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException, std::exception)
     736             : {
     737          44 :     mrAppSettings.mbEnableEvents = bEnable;
     738          44 : }
     739             : 
     740             : sal_Bool SAL_CALL
     741           0 : ScVbaApplication::getEnableEvents() throw (uno::RuntimeException, std::exception)
     742             : {
     743           0 :     return mrAppSettings.mbEnableEvents;
     744             : }
     745             : 
     746             : void SAL_CALL
     747           0 : ScVbaApplication::setEnableCancelKey(sal_Bool bEnable) throw (uno::RuntimeException, std::exception)
     748             : {
     749             :     // Stub, does nothing
     750           0 :     mrAppSettings.mbEnableCancelKey = bEnable;
     751           0 : }
     752             : 
     753             : sal_Bool SAL_CALL
     754           0 : ScVbaApplication::getEnableCancelKey() throw (uno::RuntimeException, std::exception)
     755             : {
     756           0 :     return mrAppSettings.mbEnableCancelKey;
     757             : }
     758             : 
     759             : sal_Bool SAL_CALL
     760           0 : ScVbaApplication::getDisplayFullScreen()  throw (uno::RuntimeException, std::exception)
     761             : {
     762           0 :     SfxViewShell* pShell  = excel::getCurrentBestViewShell( mxContext );
     763           0 :     if ( pShell )
     764           0 :         return ScViewUtil::IsFullScreen( *pShell );
     765           0 :     return sal_False;
     766             : }
     767             : 
     768             : void SAL_CALL
     769           0 : ScVbaApplication::setDisplayFullScreen( sal_Bool bSet )  throw (uno::RuntimeException, std::exception)
     770             : {
     771             :     // #FIXME calling  ScViewUtil::SetFullScreen( *pShell, bSet );
     772             :     // directly results in a strange crash, using dispatch instead
     773           0 :     if ( bSet != getDisplayFullScreen() )
     774           0 :         dispatchRequests( getCurrentDocument(), OUString(".uno:FullScreen") );
     775           0 : }
     776             : 
     777             : sal_Bool SAL_CALL
     778           0 : ScVbaApplication::getDisplayScrollBars()  throw (uno::RuntimeException, std::exception)
     779             : {
     780           0 :     ScTabViewShell* pShell  = excel::getCurrentBestViewShell( mxContext );
     781           0 :     if ( pShell )
     782             :     {
     783           0 :         return ( pShell->GetViewData()->IsHScrollMode() && pShell->GetViewData()->IsVScrollMode() );
     784             :     }
     785           0 :     return true;
     786             : }
     787             : 
     788             : void SAL_CALL
     789           0 : ScVbaApplication::setDisplayScrollBars( sal_Bool bSet )  throw (uno::RuntimeException, std::exception)
     790             : {
     791             :     // use uno here as it does all he repainting etc. magic
     792           0 :     uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
     793           0 :     uno::Reference< beans::XPropertySet > xProps( xView, uno::UNO_QUERY );
     794           0 :     xProps->setPropertyValue("HasVerticalScrollBar", uno::makeAny( bSet ) );
     795           0 :     xProps->setPropertyValue("HasHorizontalScrollBar", uno::makeAny( bSet ) );
     796           0 : }
     797             : 
     798             : sal_Bool SAL_CALL
     799           0 : ScVbaApplication::getDisplayExcel4Menus() throw (css::uno::RuntimeException, std::exception)
     800             : {
     801           0 :     return mrAppSettings.mbExcel4Menus;
     802             : }
     803             : 
     804             : void SAL_CALL
     805           0 : ScVbaApplication::setDisplayExcel4Menus( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
     806             : {
     807           0 :     mrAppSettings.mbExcel4Menus = bSet;
     808           0 : }
     809             : 
     810             : sal_Bool SAL_CALL
     811           0 : ScVbaApplication::getDisplayNoteIndicator() throw (css::uno::RuntimeException, std::exception)
     812             : {
     813           0 :     return mrAppSettings.mbDisplayNoteIndicator;
     814             : }
     815             : 
     816             : void SAL_CALL
     817           0 : ScVbaApplication::setDisplayNoteIndicator( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
     818             : {
     819           0 :     mrAppSettings.mbDisplayNoteIndicator = bSet;
     820           0 : }
     821             : 
     822             : sal_Bool SAL_CALL
     823           0 : ScVbaApplication::getShowWindowsInTaskbar() throw (css::uno::RuntimeException, std::exception)
     824             : {
     825           0 :     return mrAppSettings.mbShowWindowsInTaskbar;
     826             : }
     827             : 
     828             : void SAL_CALL
     829           0 : ScVbaApplication::setShowWindowsInTaskbar( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
     830             : {
     831           0 :     mrAppSettings.mbShowWindowsInTaskbar = bSet;
     832           0 : }
     833             : 
     834             : sal_Bool SAL_CALL
     835           0 : ScVbaApplication::getIteration() throw (css::uno::RuntimeException, std::exception)
     836             : {
     837           0 :     return SC_MOD()->GetDocOptions().IsIter();
     838             : }
     839             : 
     840             : void SAL_CALL
     841           0 : ScVbaApplication::setIteration( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
     842             : {
     843             :     uno::Reference< lang::XMultiComponentFactory > xSMgr(
     844           0 :         mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
     845             : 
     846             :     uno::Reference< frame::XDesktop > xDesktop
     847           0 :         (xSMgr->createInstanceWithContext( "com.sun.star.frame.Desktop" , mxContext), uno::UNO_QUERY_THROW );
     848           0 :     uno::Reference< container::XEnumeration > xComponents = xDesktop->getComponents()->createEnumeration();
     849           0 :     while ( xComponents->hasMoreElements() )
     850             :     {
     851           0 :         uno::Reference< lang::XServiceInfo > xServiceInfo( xComponents->nextElement(), uno::UNO_QUERY );
     852           0 :         if ( xServiceInfo.is() && xServiceInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
     853             :         {
     854           0 :             uno::Reference< beans::XPropertySet > xProps( xServiceInfo, uno::UNO_QUERY );
     855           0 :             if ( xProps.is() )
     856           0 :                 xProps->setPropertyValue(  SC_UNO_ITERENABLED, uno::Any( bSet ) );
     857             :         }
     858           0 :     }
     859           0 :     ScDocOptions aOpts( SC_MOD()->GetDocOptions() );
     860           0 :     aOpts.SetIter( bSet );
     861           0 :     SC_MOD()->SetDocOptions( aOpts );
     862           0 : }
     863             : 
     864             : void SAL_CALL
     865           2 : ScVbaApplication::Calculate() throw(  script::BasicErrorException , uno::RuntimeException, std::exception )
     866             : {
     867           2 :     uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     868           4 :     uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW );
     869           4 :     xCalculatable->calculateAll();
     870           2 : }
     871             : 
     872           6 : static uno::Reference< util::XPathSettings > lcl_getPathSettingsService( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException )
     873             : {
     874           6 :     static uno::Reference< util::XPathSettings >  xPathSettings;
     875           6 :     if ( !xPathSettings.is() )
     876             :     {
     877           1 :         xPathSettings.set( util::PathSettings::create( xContext ) );
     878             :     }
     879           6 :     return xPathSettings;
     880             : }
     881           6 : OUString ScVbaApplication::getOfficePath( const OUString& _sPathType ) throw ( uno::RuntimeException )
     882             : {
     883           6 :     OUString sRetPath;
     884          12 :     uno::Reference< util::XPathSettings > xProps = lcl_getPathSettingsService( mxContext );
     885             :     try
     886             :     {
     887           6 :         OUString sUrl;
     888           6 :          xProps->getPropertyValue( _sPathType ) >>= sUrl;
     889             : 
     890             :         // if it's a list of paths then use the last one
     891           6 :         sal_Int32 nIndex =  sUrl.lastIndexOf( ';' ) ;
     892           6 :         if ( nIndex > 0 )
     893           4 :             sUrl = sUrl.copy( nIndex + 1 );
     894           6 :         ::osl::File::getSystemPathFromFileURL( sUrl, sRetPath );
     895             :     }
     896           0 :     catch (const uno::Exception&)
     897             :     {
     898           0 :         DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
     899             :     }
     900          12 :     return sRetPath;
     901             : }
     902             : 
     903             : void SAL_CALL
     904           0 : ScVbaApplication::setDefaultFilePath( const OUString& DefaultFilePath ) throw (uno::RuntimeException, std::exception)
     905             : {
     906           0 :     uno::Reference< util::XPathSettings > xProps = lcl_getPathSettingsService( mxContext );
     907           0 :     OUString aURL;
     908           0 :     osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL );
     909           0 :     xProps->setWork( aURL );
     910           0 : }
     911             : 
     912             : OUString SAL_CALL
     913           2 : ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException, std::exception)
     914             : {
     915           2 :     return getOfficePath( OUString("Work"));
     916             : }
     917             : 
     918             : OUString SAL_CALL
     919           2 : ScVbaApplication::getLibraryPath() throw (uno::RuntimeException, std::exception)
     920             : {
     921           2 :     return getOfficePath( OUString("Basic"));
     922             : }
     923             : 
     924             : OUString SAL_CALL
     925           2 : ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException, std::exception)
     926             : {
     927           2 :     return getOfficePath( OUString("Template"));
     928             : }
     929             : 
     930             : OUString SAL_CALL
     931           3 : ScVbaApplication::getPathSeparator() throw (uno::RuntimeException, std::exception)
     932             : {
     933           3 :     return OUString( (sal_Unicode) SAL_PATHDELIMITER );
     934             : }
     935             : 
     936             : 
     937             : // Helpers for Intersect and Union
     938             : 
     939             : namespace {
     940             : 
     941             : typedef ::std::list< ScRange > ListOfScRange;
     942             : 
     943             : /** Appends all ranges of a VBA Range object in the passed Any to the list of ranges. */
     944         540 : void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg )
     945             :         throw (script::BasicErrorException, uno::RuntimeException)
     946             : {
     947         540 :     if( rArg.hasValue() )
     948             :     {
     949          37 :         uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW );
     950          74 :         uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW );
     951         100 :         for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx )
     952             :         {
     953          63 :             uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW );
     954         126 :             uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW );
     955          63 :             ScRange aScRange;
     956          63 :             ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() );
     957          63 :             rList.push_back( aScRange );
     958         100 :         }
     959             :     }
     960         540 : }
     961             : 
     962             : /** Returns true, if the passed ranges can be expressed by a single range. The
     963             :     new range will be contained in r1 then, the range r2 can be removed. */
     964          65 : bool lclTryJoin( ScRange& r1, const ScRange& r2 )
     965             : {
     966             :     // 1) r2 is completely inside r1
     967          65 :     if( r1.In( r2 ) )
     968           3 :         return true;
     969             : 
     970             :     // 2) r1 is completely inside r2
     971          62 :     if( r2.In( r1 ) )
     972             :     {
     973           2 :         r1 = r2;
     974           2 :         return true;
     975             :     }
     976             : 
     977          60 :     SCCOL n1L = r1.aStart.Col();
     978          60 :     SCCOL n1R = r1.aEnd.Col();
     979          60 :     SCROW n1T = r1.aStart.Row();
     980          60 :     SCROW n1B = r1.aEnd.Row();
     981          60 :     SCCOL n2L = r2.aStart.Col();
     982          60 :     SCCOL n2R = r2.aEnd.Col();
     983          60 :     SCROW n2T = r2.aStart.Row();
     984          60 :     SCROW n2B = r2.aEnd.Row();
     985             : 
     986             :     // 3) r1 and r2 have equal upper and lower border
     987          60 :     if( (n1T == n2T) && (n1B == n2B) )
     988             :     {
     989             :         // check that r1 overlaps or touches r2
     990          23 :         if( ((n1L < n2L) && (n2L - 1 <= n1R)) || ((n2L < n1L) && (n1L - 1 <= n2R)) )
     991             :         {
     992          15 :             r1.aStart.SetCol( ::std::min( n1L, n2L ) );
     993          15 :             r1.aEnd.SetCol( ::std::max( n1R, n2R ) );
     994          15 :             return true;
     995             :         }
     996           8 :         return false;
     997             :     }
     998             : 
     999             :     // 4) r1 and r2 have equal left and right border
    1000          37 :     if( (n1L == n2L) && (n1R == n2R) )
    1001             :     {
    1002             :         // check that r1 overlaps or touches r2
    1003           0 :         if( ((n1T < n2T) && (n2T + 1 <= n1B)) || ((n2T < n1T) && (n1T + 1 <= n2B)) )
    1004             :         {
    1005           0 :             r1.aStart.SetRow( ::std::min( n1T, n2T ) );
    1006           0 :             r1.aEnd.SetRow( ::std::max( n1B, n2B ) );
    1007           0 :             return true;
    1008             :         }
    1009           0 :         return false;
    1010             :     }
    1011             : 
    1012             :     // 5) cannot join these ranges
    1013          37 :     return false;
    1014             : }
    1015             : 
    1016             : /** Strips out ranges that are contained by other ranges, joins ranges that can be joined
    1017             :     together (aligned borders, e.g. A4:D10 and B4:E10 would be combined to A4:E10. */
    1018          48 : void lclJoinRanges( ListOfScRange& rList )
    1019             : {
    1020          48 :     ListOfScRange::iterator aOuterIt = rList.begin();
    1021         176 :     while( aOuterIt != rList.end() )
    1022             :     {
    1023          80 :         bool bAnyErased = false;    // true = any range erased from rList
    1024          80 :         ListOfScRange::iterator aInnerIt = rList.begin();
    1025         305 :         while( aInnerIt != rList.end() )
    1026             :         {
    1027         145 :             bool bInnerErased = false;   // true = aInnerIt erased from rList
    1028             :             // do not compare a range with itself
    1029         145 :             if( (aOuterIt != aInnerIt) && lclTryJoin( *aOuterIt, *aInnerIt ) )
    1030             :             {
    1031             :                 // aOuterIt points to joined range, aInnerIt will be removed
    1032          20 :                 aInnerIt = rList.erase( aInnerIt );
    1033          20 :                 bInnerErased = bAnyErased = true;
    1034             :             }
    1035             :             /*  If aInnerIt has been erased from rList, it already points to
    1036             :                 the next element (return value of list::erase()). */
    1037         145 :             if( !bInnerErased )
    1038         125 :                 ++aInnerIt;
    1039             :         }
    1040             :         // if any range has been erased, repeat outer loop with the same range
    1041          80 :         if( !bAnyErased )
    1042          64 :             ++aOuterIt;
    1043             :     }
    1044          48 : }
    1045             : 
    1046             : /** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */
    1047         406 : void lclIntersectRanges( ListOfScRange& rList, const uno::Any& rArg )
    1048             :         throw (script::BasicErrorException, uno::RuntimeException)
    1049             : {
    1050             :     // extract the ranges from the passed argument, will throw on invalid data
    1051         406 :     ListOfScRange aList2;
    1052         406 :     lclAddToListOfScRange( aList2, rArg );
    1053             :     // do nothing, if the passed list is already empty
    1054         406 :     if( !rList.empty() && !aList2.empty() )
    1055             :     {
    1056             :         // save original list in a local
    1057          15 :         ListOfScRange aList1;
    1058          15 :         aList1.swap( rList );
    1059             :         // join ranges from passed argument
    1060          15 :         lclJoinRanges( aList2 );
    1061             :         // calculate intersection of the ranges in both lists
    1062          37 :         for( ListOfScRange::const_iterator aOuterIt = aList1.begin(), aOuterEnd = aList1.end(); aOuterIt != aOuterEnd; ++aOuterIt )
    1063             :         {
    1064          45 :             for( ListOfScRange::const_iterator aInnerIt = aList2.begin(), aInnerEnd = aList2.end(); aInnerIt != aInnerEnd; ++aInnerIt )
    1065             :             {
    1066          23 :                 if( aOuterIt->Intersects( *aInnerIt ) )
    1067             :                 {
    1068             :                     ScRange aIsectRange(
    1069          42 :                         std::max( aOuterIt->aStart.Col(), aInnerIt->aStart.Col() ),
    1070          42 :                         std::max( aOuterIt->aStart.Row(), aInnerIt->aStart.Row() ),
    1071          42 :                         std::max( aOuterIt->aStart.Tab(), aInnerIt->aStart.Tab() ),
    1072          42 :                         std::min( aOuterIt->aEnd.Col(),   aInnerIt->aEnd.Col() ),
    1073          42 :                         std::min( aOuterIt->aEnd.Row(),   aInnerIt->aEnd.Row() ),
    1074         147 :                         std::min( aOuterIt->aEnd.Tab(),   aInnerIt->aEnd.Tab() ) );
    1075          21 :                     rList.push_back( aIsectRange );
    1076             :                 }
    1077             :             }
    1078             :         }
    1079             :         // again, join the result ranges
    1080          15 :         lclJoinRanges( rList );
    1081         406 :     }
    1082         406 : }
    1083             : 
    1084             : /** Creates a VBA Range object from the passed list of ranges. */
    1085          18 : uno::Reference< excel::XRange > lclCreateVbaRange(
    1086             :         const uno::Reference< uno::XComponentContext >& rxContext,
    1087             :         const uno::Reference< frame::XModel >& rxModel,
    1088             :         const ListOfScRange& rList ) throw (uno::RuntimeException)
    1089             : {
    1090          18 :     ScDocShell* pDocShell = excel::getDocShell( rxModel );
    1091          18 :     if( !pDocShell ) throw uno::RuntimeException();
    1092             : 
    1093          18 :     ScRangeList aCellRanges;
    1094          44 :     for( ListOfScRange::const_iterator aIt = rList.begin(), aEnd = rList.end(); aIt != aEnd; ++aIt )
    1095          26 :         aCellRanges.Append( *aIt );
    1096             : 
    1097          18 :     if( aCellRanges.size() == 1 )
    1098             :     {
    1099          12 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocShell, *aCellRanges.front() ) );
    1100          12 :         return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), rxContext, xRange );
    1101             :     }
    1102           6 :     if( aCellRanges.size() > 1 )
    1103             :     {
    1104           6 :         uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocShell, aCellRanges ) );
    1105           6 :         return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), rxContext, xRanges );
    1106             :     }
    1107           0 :     return 0;
    1108             : }
    1109             : 
    1110             : } // namespace
    1111             : 
    1112          14 : uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect(
    1113             :         const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
    1114             :         const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
    1115             :         const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
    1116             :         const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
    1117             :         const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
    1118             :         const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
    1119             :         const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
    1120             :         const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
    1121             :         throw (script::BasicErrorException, uno::RuntimeException, std::exception)
    1122             : {
    1123          14 :     if( !rArg1.is() || !rArg2.is() )
    1124           0 :         DebugHelper::exception( SbERR_BAD_PARAMETER, OUString() );
    1125             : 
    1126             :     // initialize the result list with 1st parameter, join its ranges together
    1127          14 :     ListOfScRange aList;
    1128          14 :     lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
    1129          14 :     lclJoinRanges( aList );
    1130             : 
    1131             :     // process all other parameters, this updates the list with intersection
    1132          14 :     lclIntersectRanges( aList, uno::Any( rArg2 ) );
    1133          14 :     lclIntersectRanges( aList, rArg3 );
    1134          14 :     lclIntersectRanges( aList, rArg4 );
    1135          14 :     lclIntersectRanges( aList, rArg5 );
    1136          14 :     lclIntersectRanges( aList, rArg6 );
    1137          14 :     lclIntersectRanges( aList, rArg7 );
    1138          14 :     lclIntersectRanges( aList, rArg8 );
    1139          14 :     lclIntersectRanges( aList, rArg9 );
    1140          14 :     lclIntersectRanges( aList, rArg10 );
    1141          14 :     lclIntersectRanges( aList, rArg11 );
    1142          14 :     lclIntersectRanges( aList, rArg12 );
    1143          14 :     lclIntersectRanges( aList, rArg13 );
    1144          14 :     lclIntersectRanges( aList, rArg14 );
    1145          14 :     lclIntersectRanges( aList, rArg15 );
    1146          14 :     lclIntersectRanges( aList, rArg16 );
    1147          14 :     lclIntersectRanges( aList, rArg17 );
    1148          14 :     lclIntersectRanges( aList, rArg18 );
    1149          14 :     lclIntersectRanges( aList, rArg19 );
    1150          14 :     lclIntersectRanges( aList, rArg20 );
    1151          14 :     lclIntersectRanges( aList, rArg21 );
    1152          14 :     lclIntersectRanges( aList, rArg22 );
    1153          14 :     lclIntersectRanges( aList, rArg23 );
    1154          14 :     lclIntersectRanges( aList, rArg24 );
    1155          14 :     lclIntersectRanges( aList, rArg25 );
    1156          14 :     lclIntersectRanges( aList, rArg26 );
    1157          14 :     lclIntersectRanges( aList, rArg27 );
    1158          14 :     lclIntersectRanges( aList, rArg28 );
    1159          14 :     lclIntersectRanges( aList, rArg29 );
    1160          14 :     lclIntersectRanges( aList, rArg30 );
    1161             : 
    1162             :     // create the VBA Range object
    1163          14 :     return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
    1164             : }
    1165             : 
    1166           4 : uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union(
    1167             :         const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
    1168             :         const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
    1169             :         const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
    1170             :         const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
    1171             :         const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
    1172             :         const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
    1173             :         const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
    1174             :         const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
    1175             :         throw (script::BasicErrorException, uno::RuntimeException, std::exception)
    1176             : {
    1177           4 :     if( !rArg1.is() || !rArg2.is() )
    1178           0 :         DebugHelper::exception( SbERR_BAD_PARAMETER, OUString() );
    1179             : 
    1180           4 :     ListOfScRange aList;
    1181           4 :     lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
    1182           4 :     lclAddToListOfScRange( aList, uno::Any( rArg2 ) );
    1183           4 :     lclAddToListOfScRange( aList, rArg3 );
    1184           4 :     lclAddToListOfScRange( aList, rArg4 );
    1185           4 :     lclAddToListOfScRange( aList, rArg5 );
    1186           4 :     lclAddToListOfScRange( aList, rArg6 );
    1187           4 :     lclAddToListOfScRange( aList, rArg7 );
    1188           4 :     lclAddToListOfScRange( aList, rArg8 );
    1189           4 :     lclAddToListOfScRange( aList, rArg9 );
    1190           4 :     lclAddToListOfScRange( aList, rArg10 );
    1191           4 :     lclAddToListOfScRange( aList, rArg11 );
    1192           4 :     lclAddToListOfScRange( aList, rArg12 );
    1193           4 :     lclAddToListOfScRange( aList, rArg13 );
    1194           4 :     lclAddToListOfScRange( aList, rArg14 );
    1195           4 :     lclAddToListOfScRange( aList, rArg15 );
    1196           4 :     lclAddToListOfScRange( aList, rArg16 );
    1197           4 :     lclAddToListOfScRange( aList, rArg17 );
    1198           4 :     lclAddToListOfScRange( aList, rArg18 );
    1199           4 :     lclAddToListOfScRange( aList, rArg19 );
    1200           4 :     lclAddToListOfScRange( aList, rArg20 );
    1201           4 :     lclAddToListOfScRange( aList, rArg21 );
    1202           4 :     lclAddToListOfScRange( aList, rArg22 );
    1203           4 :     lclAddToListOfScRange( aList, rArg23 );
    1204           4 :     lclAddToListOfScRange( aList, rArg24 );
    1205           4 :     lclAddToListOfScRange( aList, rArg25 );
    1206           4 :     lclAddToListOfScRange( aList, rArg26 );
    1207           4 :     lclAddToListOfScRange( aList, rArg27 );
    1208           4 :     lclAddToListOfScRange( aList, rArg28 );
    1209           4 :     lclAddToListOfScRange( aList, rArg29 );
    1210           4 :     lclAddToListOfScRange( aList, rArg30 );
    1211             : 
    1212             :     // simply join together all ranges as much as possible, strip out covered ranges etc.
    1213           4 :     lclJoinRanges( aList );
    1214             : 
    1215             :     // create the VBA Range object
    1216           4 :     return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
    1217             : }
    1218             : 
    1219             : double
    1220           0 : ScVbaApplication::InchesToPoints( double Inches ) throw (uno::RuntimeException, std::exception )
    1221             : {
    1222           0 :    double result = ( Inches * 72.0 );
    1223           0 :    return result;
    1224             : }
    1225             : 
    1226             : void
    1227           0 : ScVbaApplication::Volatile( const uno::Any& aVolatile )  throw ( uno::RuntimeException, std::exception )
    1228             : {
    1229           0 :     sal_Bool bVolatile = sal_True;
    1230           0 :     aVolatile >>= bVolatile;
    1231           0 :     SbMethod* pMeth = StarBASIC::GetActiveMethod();
    1232           0 :     if ( pMeth )
    1233             :     {
    1234             :         OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
    1235           0 :         uno::Reference< frame::XModel > xModel( getCurrentDocument() );
    1236           0 :         ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
    1237           0 :         pDoc->GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile);
    1238             :     }
    1239             : 
    1240             : // this is bound to break when loading the document
    1241           0 :     return;
    1242             : }
    1243             : 
    1244             : sal_Bool SAL_CALL
    1245           0 : ScVbaApplication::getDisplayFormulaBar()
    1246             :     throw (css::uno::RuntimeException, std::exception)
    1247             : {
    1248           0 :     sal_Bool bRes = false;
    1249           0 :     ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
    1250           0 :     if ( pViewShell )
    1251             :     {
    1252           0 :         SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE);
    1253           0 :         SfxAllItemSet reqList(  SFX_APP()->GetPool() );
    1254           0 :         reqList.Put( sfxFormBar );
    1255             : 
    1256           0 :         pViewShell->GetState( reqList );
    1257           0 :         const SfxPoolItem *pItem=0;
    1258           0 :         if ( reqList.GetItemState( FID_TOGGLEINPUTLINE, false, &pItem ) == SFX_ITEM_SET )
    1259           0 :             bRes =   ((SfxBoolItem*)pItem)->GetValue();
    1260             :     }
    1261           0 :     return bRes;
    1262             : }
    1263             : 
    1264             : void SAL_CALL
    1265           0 : ScVbaApplication::setDisplayFormulaBar( sal_Bool _displayformulabar )
    1266             :     throw(css::uno::RuntimeException, std::exception)
    1267             : {
    1268           0 :     ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
    1269           0 :     if ( pViewShell && ( _displayformulabar !=  getDisplayFormulaBar() ) )
    1270             :     {
    1271           0 :         SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar);
    1272           0 :         SfxAllItemSet reqList(  SFX_APP()->GetPool() );
    1273           0 :         SfxRequest aReq( FID_TOGGLEINPUTLINE, 0, reqList );
    1274           0 :         pViewShell->Execute( aReq );
    1275             :     }
    1276           0 : }
    1277             : 
    1278             : uno::Any SAL_CALL
    1279           0 : ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeException, std::exception )
    1280             : {
    1281           0 :     StarBASIC* pBasic = SFX_APP()->GetBasic();
    1282           0 :     SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( OUString("FuncCaller"), SbxCLASS_METHOD );
    1283           0 :     uno::Any aRet;
    1284           0 :     if ( pMeth )
    1285             :     {
    1286           0 :         SbxVariableRef refTemp = pMeth;
    1287             :         // forces a broadcast
    1288           0 :         SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
    1289             :                 OSL_TRACE("pNew has type %d and string value %s", pNew->GetType(), OUStringToOString( pNew->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
    1290           0 :         aRet = sbxToUnoValue( pNew );
    1291             :     }
    1292           0 :     return aRet;
    1293             : }
    1294             : 
    1295           0 : uno::Any SAL_CALL ScVbaApplication::GetOpenFilename(
    1296             :         const uno::Any& rFileFilter, const uno::Any& rFilterIndex, const uno::Any& rTitle,
    1297             :         const uno::Any& rButtonText, const uno::Any& rMultiSelect ) throw (uno::RuntimeException)
    1298             : {
    1299           0 :     uno::Sequence< uno::Any > aArgs( 6 );
    1300           0 :     aArgs[ 0 ] <<= getThisExcelDoc( mxContext );
    1301           0 :     aArgs[ 1 ] = rFileFilter;
    1302           0 :     aArgs[ 2 ] = rFilterIndex;
    1303           0 :     aArgs[ 3 ] = rTitle;
    1304           0 :     aArgs[ 4 ] = rButtonText;
    1305           0 :     aArgs[ 5 ] = rMultiSelect;
    1306           0 :     uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW );
    1307           0 :     uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext(
    1308           0 :         OUString( "ooo.vba.OpenFilePicker" ), aArgs, mxContext ), uno::UNO_QUERY_THROW );
    1309           0 :     return xFilePicker->execute();
    1310             : }
    1311             : 
    1312           0 : uno::Any SAL_CALL ScVbaApplication::GetSaveAsFilename(
    1313             :         const uno::Any& rInitialFileName, const uno::Any& rFileFilter, const uno::Any& rFilterIndex,
    1314             :         const uno::Any& rTitle, const uno::Any& rButtonText ) throw (uno::RuntimeException)
    1315             : {
    1316           0 :     uno::Sequence< uno::Any > aArgs( 6 );
    1317           0 :     aArgs[ 0 ] <<= getThisExcelDoc( mxContext );
    1318           0 :     aArgs[ 1 ] = rInitialFileName;
    1319           0 :     aArgs[ 2 ] = rFileFilter;
    1320           0 :     aArgs[ 3 ] = rFilterIndex;
    1321           0 :     aArgs[ 4 ] = rTitle;
    1322           0 :     aArgs[ 5 ] = rButtonText;
    1323           0 :     uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW );
    1324           0 :     uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext(
    1325           0 :         OUString( "ooo.vba.SaveAsFilePicker" ), aArgs, mxContext ), uno::UNO_QUERY_THROW );
    1326           0 :     return xFilePicker->execute();
    1327             : }
    1328             : 
    1329             : uno::Reference< frame::XModel >
    1330         103 : ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
    1331             : {
    1332         103 :     return getCurrentExcelDoc(mxContext);
    1333             : }
    1334             : 
    1335             : uno::Any SAL_CALL
    1336           0 : ScVbaApplication::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
    1337             : {
    1338           0 :     uno::Reference< XCommandBars > xCommandBars( CommandBars( uno::Any() ), uno::UNO_QUERY_THROW );
    1339           0 :     uno::Reference< XCollection > xMenuBars( new ScVbaMenuBars( this, mxContext, xCommandBars ) );
    1340           0 :     if (  aIndex.hasValue() )
    1341             :     {
    1342           0 :         return uno::Any ( xMenuBars->Item( aIndex, uno::Any() ) );
    1343             :     }
    1344             : 
    1345           0 :     return uno::Any( xMenuBars );
    1346             : }
    1347             : 
    1348           0 : void SAL_CALL ScVbaApplication::OnKey( const OUString& Key, const uno::Any& Procedure ) throw (uno::RuntimeException, std::exception)
    1349             : {
    1350             :     try
    1351             :     {
    1352             :         // Perhaps we can catch some excel specific
    1353             :         // related behaviour here
    1354           0 :         VbaApplicationBase::OnKey( Key, Procedure );
    1355             :     }
    1356           0 :     catch( container::NoSuchElementException& )
    1357             :     {
    1358             :         // #TODO special handling for unhandled
    1359             :         // bindings
    1360             :     }
    1361           0 : }
    1362             : 
    1363           0 : void SAL_CALL ScVbaApplication::Undo() throw (uno::RuntimeException, std::exception)
    1364             : {
    1365           0 :     uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW );
    1366             : 
    1367           0 :     ScTabViewShell* pViewShell = excel::getBestViewShell( xModel );
    1368           0 :     if ( pViewShell )
    1369           0 :         dispatchExecute( pViewShell, SID_UNDO );
    1370           0 : }
    1371             : 
    1372             : OUString
    1373           0 : ScVbaApplication::getServiceImplName()
    1374             : {
    1375           0 :     return OUString("ScVbaApplication");
    1376             : }
    1377             : 
    1378             : uno::Sequence< OUString >
    1379           0 : ScVbaApplication::getServiceNames()
    1380             : {
    1381           0 :     static uno::Sequence< OUString > aServiceNames;
    1382           0 :     if ( aServiceNames.getLength() == 0 )
    1383             :     {
    1384           0 :         aServiceNames.realloc( 1 );
    1385           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.Application";
    1386             :     }
    1387           0 :     return aServiceNames;
    1388             : }
    1389             : 
    1390             : namespace application
    1391             : {
    1392             : namespace sdecl = comphelper::service_decl;
    1393           2 : sdecl::vba_service_class_<ScVbaApplication, sdecl::with_args<false> > serviceImpl;
    1394           2 : extern sdecl::ServiceDecl const serviceDecl(
    1395             :     serviceImpl,
    1396             :     "ScVbaApplication",
    1397             :     "ooo.vba.excel.Application" );
    1398           6 : }
    1399             : 
    1400             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10