LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaapplication.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 639 0.0 %
Date: 2014-04-14 Functions: 0 88 0.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           0 : 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           0 :     mbEnableCancelKey( sal_False )
     124             : {
     125           0 : }
     126             : 
     127             : struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {};
     128             : 
     129           0 : ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
     130             :     ScVbaApplication_BASE( xContext ),
     131           0 :     mrAppSettings( ScVbaStaticAppSettings::get() )
     132             : {
     133           0 : }
     134             : 
     135           0 : ScVbaApplication::~ScVbaApplication()
     136             : {
     137           0 : }
     138             : 
     139           0 : /*static*/ bool ScVbaApplication::getDocumentEventsEnabled()
     140             : {
     141           0 :     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           0 : ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException, std::exception)
     211             : {
     212           0 :     uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );
     213           0 :     uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
     214           0 :     if( xWorkbook.is() ) return xWorkbook;
     215             :     // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
     216           0 :     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           0 : ScVbaApplication::getSelection() throw (uno::RuntimeException, std::exception)
     237             : {
     238             :     OSL_TRACE("** ScVbaApplication::getSelection() ** ");
     239           0 :     uno::Reference< frame::XModel > xModel( getCurrentDocument() );
     240             : 
     241           0 :     Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), UNO_QUERY_THROW );
     242           0 :     Reference< beans::XPropertySet > xPropSet( xSelSupp, UNO_QUERY_THROW );
     243           0 :     OUString aPropName( SC_UNO_FILTERED_RANGE_SELECTION );
     244           0 :     uno::Any aOldVal = xPropSet->getPropertyValue( aPropName );
     245           0 :     uno::Any any;
     246           0 :     any <<= false;
     247           0 :     xPropSet->setPropertyValue( aPropName, any );
     248             :     uno::Reference< uno::XInterface > aSelection = ScUnoHelpFunctions::AnyToInterface(
     249           0 :         xSelSupp->getSelection() );
     250           0 :     xPropSet->setPropertyValue( aPropName, aOldVal );
     251             : 
     252           0 :     if (!aSelection.is())
     253             :     {
     254             :         throw uno::RuntimeException(
     255             :             OUString("failed to obtain current selection"),
     256           0 :             uno::Reference< uno::XInterface >() );
     257             :     }
     258             : 
     259           0 :     uno::Reference< lang::XServiceInfo > xServiceInfo( aSelection, uno::UNO_QUERY_THROW );
     260           0 :     OUString sImplementationName = xServiceInfo->getImplementationName();
     261             : 
     262           0 :     if( sImplementationName.equalsIgnoreAsciiCase("com.sun.star.drawing.SvxShapeCollection") )
     263             :     {
     264           0 :         uno::Reference< drawing::XShapes > xShapes( aSelection, uno::UNO_QUERY_THROW );
     265           0 :         uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
     266           0 :         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           0 :     if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape )
     271             :     {
     272           0 :         uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW );
     273           0 :         if ( xShapeServiceInfo->supportsService("com.sun.star.drawing.Text")  )
     274             :         {
     275           0 :                 return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
     276           0 :         }
     277             :     }
     278           0 :         return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) );
     279             :     }
     280           0 :     else if( xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRange") ||
     281           0 :              xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRanges") )
     282             :     {
     283           0 :         uno::Reference< table::XCellRange > xRange( aSelection, ::uno::UNO_QUERY);
     284           0 :         if ( !xRange.is() )
     285             :         {
     286           0 :             uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aSelection, ::uno::UNO_QUERY);
     287           0 :             if ( xRanges.is() )
     288           0 :                 return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), mxContext, xRanges ) ) );
     289             : 
     290             :         }
     291           0 :         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           0 :     }
     298             : }
     299             : 
     300             : uno::Reference< excel::XRange >
     301           0 : ScVbaApplication::getActiveCell() throw (uno::RuntimeException, std::exception )
     302             : {
     303           0 :     uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
     304           0 :     uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
     305           0 :     ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
     306           0 :     if ( !pViewShell )
     307           0 :         throw uno::RuntimeException("No ViewShell available", uno::Reference< uno::XInterface >() );
     308           0 :     ScViewData* pTabView = pViewShell->GetViewData();
     309           0 :     if ( !pTabView )
     310           0 :         throw uno::RuntimeException("No ViewData available", uno::Reference< uno::XInterface >() );
     311             : 
     312           0 :     sal_Int32 nCursorX = pTabView->GetCurX();
     313           0 :     sal_Int32 nCursorY = pTabView->GetCurY();
     314             : 
     315             :     // #i117392# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
     316           0 :     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           0 : ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
     330             : {
     331           0 :     uno::Reference< XCollection > xWorkBooks( new ScVbaWorkbooks( this, mxContext ) );
     332           0 :     if (  aIndex.getValueTypeClass() == uno::TypeClass_VOID )
     333             :     {
     334             :         // void then somebody did Workbooks.something in vba
     335           0 :         return uno::Any( xWorkBooks );
     336             :     }
     337             : 
     338           0 :     return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) );
     339             : }
     340             : 
     341             : uno::Any SAL_CALL
     342           0 : ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
     343             : {
     344           0 :     uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW );
     345           0 :     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           0 : ScVbaApplication::getActiveWindow() throw (uno::RuntimeException, std::exception)
     375             : {
     376           0 :     uno::Reference< frame::XModel > xModel = getCurrentDocument();
     377           0 :     uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
     378           0 :     uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW );
     379           0 :     uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) );
     380           0 :     return xWin;
     381             : }
     382             : 
     383             : uno::Any SAL_CALL
     384           0 : ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException, std::exception)
     385             : {
     386             :     //# FIXME TODO, implementation
     387           0 :     uno::Any result;
     388           0 :     result <<= sal_False;
     389           0 :     return result;
     390             : }
     391             : 
     392             : void SAL_CALL
     393           0 : ScVbaApplication::setCutCopyMode( const uno::Any& /* _cutcopymode */ ) throw (uno::RuntimeException, std::exception)
     394             : {
     395             :     //# FIXME TODO, implementation
     396           0 : }
     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           0 : ScVbaApplication::getCalculation() throw (uno::RuntimeException, std::exception)
     435             : {
     436             :     // TODO: in Excel, this is an application-wide setting
     437           0 :     uno::Reference<sheet::XCalculatable> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
     438           0 :     if(xCalc->isAutomaticCalculationEnabled())
     439           0 :         return excel::XlCalculation::xlCalculationAutomatic;
     440             :     else
     441           0 :         return excel::XlCalculation::xlCalculationManual;
     442             : }
     443             : 
     444             : void SAL_CALL
     445           0 : ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException, std::exception)
     446             : {
     447             :     // TODO: in Excel, this is an application-wide setting
     448           0 :     uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
     449           0 :     switch(_calculation)
     450             :     {
     451             :         case excel::XlCalculation::xlCalculationManual:
     452           0 :             xCalc->enableAutomaticCalculation(false);
     453           0 :             break;
     454             :         case excel::XlCalculation::xlCalculationAutomatic:
     455             :         case excel::XlCalculation::xlCalculationSemiautomatic:
     456           0 :             xCalc->enableAutomaticCalculation(sal_True);
     457           0 :             break;
     458           0 :     }
     459           0 : }
     460             : 
     461             : uno::Any SAL_CALL
     462           0 : ScVbaApplication::Windows( const uno::Any& aIndex  ) throw (uno::RuntimeException, std::exception)
     463             : {
     464           0 :     uno::Reference< excel::XWindows >  xWindows( new ScVbaWindows( this, mxContext ) );
     465           0 :     if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
     466           0 :         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           0 : ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
     490             : {
     491           0 :     uno::Reference< excel::XRange > xVbRange = ScVbaRange::ApplicationRange( mxContext, Cell1, Cell2 );
     492           0 :     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           0 : ScVbaApplication::getActiveSheet() throw (uno::RuntimeException, std::exception)
     514             : {
     515           0 :     uno::Reference< excel::XWorksheet > result;
     516           0 :     uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY );
     517           0 :     if ( xWorkbook.is() )
     518             :     {
     519             :         uno::Reference< excel::XWorksheet > xWorksheet(
     520           0 :             xWorkbook->getActiveSheet(), uno::UNO_QUERY );
     521           0 :         if ( xWorksheet.is() )
     522             :         {
     523           0 :             result = xWorksheet;
     524           0 :         }
     525             :     }
     526             : 
     527           0 :     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           0 :     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           0 : ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) throw (uno::RuntimeException, std::exception)
     549             : {
     550             :     //test Scroll is a boolean
     551           0 :     sal_Bool bScroll = false;
     552             :     //R1C1-style string or a string of procedure name.
     553             : 
     554           0 :     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           0 :     OUString sRangeName;
     567           0 :     if( Reference >>= sRangeName )
     568             :     {
     569           0 :         uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     570             :         uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
     571           0 :                 xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     572           0 :         uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
     573             : 
     574           0 :         ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
     575           0 :         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
     576             :         try
     577             :         {
     578             :             uno::Reference< excel::XRange > xVbaSheetRange = ScVbaRange::getRangeObjectForName(
     579           0 :                 mxContext, sRangeName, excel::getDocShell( xModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
     580             : 
     581           0 :             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           0 :                 xVbaSheetRange->Select();
     597           0 :                 gridWindow->GrabFocus();
     598           0 :             }
     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           0 :         return;
     612             :     }
     613           0 :     uno::Reference< excel::XRange > xRange;
     614           0 :     if( Reference >>= xRange )
     615             :     {
     616           0 :         uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
     617           0 :         ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
     618           0 :         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
     619           0 :         if ( xVbaRange.is() )
     620             :         {
     621             :             //TODO bScroll should be using, In this time, it doesenot have effection
     622           0 :             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           0 :                 xVbaRange->Select();
     638           0 :                 gridWindow->GrabFocus();
     639             :             }
     640             :         }
     641           0 :         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           0 : ScVbaApplication::getName() throw (uno::RuntimeException, std::exception)
     711             : {
     712           0 :     static OUString appName("Microsoft Excel" );
     713           0 :     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           0 : ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException, std::exception)
     724             : {
     725           0 :     mrAppSettings.mbDisplayAlerts = displayAlerts;
     726           0 : }
     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           0 : ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException, std::exception)
     736             : {
     737           0 :     mrAppSettings.mbEnableEvents = bEnable;
     738           0 : }
     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           0 : ScVbaApplication::Calculate() throw(  script::BasicErrorException , uno::RuntimeException, std::exception )
     866             : {
     867           0 :     uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
     868           0 :     uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW );
     869           0 :     xCalculatable->calculateAll();
     870           0 : }
     871             : 
     872           0 : static uno::Reference< util::XPathSettings > lcl_getPathSettingsService( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException )
     873             : {
     874           0 :     static uno::Reference< util::XPathSettings >  xPathSettings;
     875           0 :     if ( !xPathSettings.is() )
     876             :     {
     877           0 :         xPathSettings.set( util::PathSettings::create( xContext ) );
     878             :     }
     879           0 :     return xPathSettings;
     880             : }
     881           0 : OUString ScVbaApplication::getOfficePath( const OUString& _sPathType ) throw ( uno::RuntimeException )
     882             : {
     883           0 :     OUString sRetPath;
     884           0 :     uno::Reference< util::XPathSettings > xProps = lcl_getPathSettingsService( mxContext );
     885             :     try
     886             :     {
     887           0 :         OUString sUrl;
     888           0 :          xProps->getPropertyValue( _sPathType ) >>= sUrl;
     889             : 
     890             :         // if it's a list of paths then use the last one
     891           0 :         sal_Int32 nIndex =  sUrl.lastIndexOf( ';' ) ;
     892           0 :         if ( nIndex > 0 )
     893           0 :             sUrl = sUrl.copy( nIndex + 1 );
     894           0 :         ::osl::File::getSystemPathFromFileURL( sUrl, sRetPath );
     895             :     }
     896           0 :     catch (const uno::Exception&)
     897             :     {
     898           0 :         DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
     899             :     }
     900           0 :     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           0 : ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException, std::exception)
     914             : {
     915           0 :     return getOfficePath( OUString("Work"));
     916             : }
     917             : 
     918             : OUString SAL_CALL
     919           0 : ScVbaApplication::getLibraryPath() throw (uno::RuntimeException, std::exception)
     920             : {
     921           0 :     return getOfficePath( OUString("Basic"));
     922             : }
     923             : 
     924             : OUString SAL_CALL
     925           0 : ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException, std::exception)
     926             : {
     927           0 :     return getOfficePath( OUString("Template"));
     928             : }
     929             : 
     930             : OUString SAL_CALL
     931           0 : ScVbaApplication::getPathSeparator() throw (uno::RuntimeException, std::exception)
     932             : {
     933           0 :     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           0 : void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg )
     945             :         throw (script::BasicErrorException, uno::RuntimeException)
     946             : {
     947           0 :     if( rArg.hasValue() )
     948             :     {
     949           0 :         uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW );
     950           0 :         uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW );
     951           0 :         for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx )
     952             :         {
     953           0 :             uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW );
     954           0 :             uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW );
     955           0 :             ScRange aScRange;
     956           0 :             ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() );
     957           0 :             rList.push_back( aScRange );
     958           0 :         }
     959             :     }
     960           0 : }
     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           0 : bool lclTryJoin( ScRange& r1, const ScRange& r2 )
     965             : {
     966             :     // 1) r2 is completely inside r1
     967           0 :     if( r1.In( r2 ) )
     968           0 :         return true;
     969             : 
     970             :     // 2) r1 is completely inside r2
     971           0 :     if( r2.In( r1 ) )
     972             :     {
     973           0 :         r1 = r2;
     974           0 :         return true;
     975             :     }
     976             : 
     977           0 :     SCCOL n1L = r1.aStart.Col();
     978           0 :     SCCOL n1R = r1.aEnd.Col();
     979           0 :     SCROW n1T = r1.aStart.Row();
     980           0 :     SCROW n1B = r1.aEnd.Row();
     981           0 :     SCCOL n2L = r2.aStart.Col();
     982           0 :     SCCOL n2R = r2.aEnd.Col();
     983           0 :     SCROW n2T = r2.aStart.Row();
     984           0 :     SCROW n2B = r2.aEnd.Row();
     985             : 
     986             :     // 3) r1 and r2 have equal upper and lower border
     987           0 :     if( (n1T == n2T) && (n1B == n2B) )
     988             :     {
     989             :         // check that r1 overlaps or touches r2
     990           0 :         if( ((n1L < n2L) && (n2L - 1 <= n1R)) || ((n2L < n1L) && (n1L - 1 <= n2R)) )
     991             :         {
     992           0 :             r1.aStart.SetCol( ::std::min( n1L, n2L ) );
     993           0 :             r1.aEnd.SetCol( ::std::max( n1R, n2R ) );
     994           0 :             return true;
     995             :         }
     996           0 :         return false;
     997             :     }
     998             : 
     999             :     // 4) r1 and r2 have equal left and right border
    1000           0 :     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           0 :     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           0 : void lclJoinRanges( ListOfScRange& rList )
    1019             : {
    1020           0 :     ListOfScRange::iterator aOuterIt = rList.begin();
    1021           0 :     while( aOuterIt != rList.end() )
    1022             :     {
    1023           0 :         bool bAnyErased = false;    // true = any range erased from rList
    1024           0 :         ListOfScRange::iterator aInnerIt = rList.begin();
    1025           0 :         while( aInnerIt != rList.end() )
    1026             :         {
    1027           0 :             bool bInnerErased = false;   // true = aInnerIt erased from rList
    1028             :             // do not compare a range with itself
    1029           0 :             if( (aOuterIt != aInnerIt) && lclTryJoin( *aOuterIt, *aInnerIt ) )
    1030             :             {
    1031             :                 // aOuterIt points to joined range, aInnerIt will be removed
    1032           0 :                 aInnerIt = rList.erase( aInnerIt );
    1033           0 :                 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           0 :             if( !bInnerErased )
    1038           0 :                 ++aInnerIt;
    1039             :         }
    1040             :         // if any range has been erased, repeat outer loop with the same range
    1041           0 :         if( !bAnyErased )
    1042           0 :             ++aOuterIt;
    1043             :     }
    1044           0 : }
    1045             : 
    1046             : /** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */
    1047           0 : 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           0 :     ListOfScRange aList2;
    1052           0 :     lclAddToListOfScRange( aList2, rArg );
    1053             :     // do nothing, if the passed list is already empty
    1054           0 :     if( !rList.empty() && !aList2.empty() )
    1055             :     {
    1056             :         // save original list in a local
    1057           0 :         ListOfScRange aList1;
    1058           0 :         aList1.swap( rList );
    1059             :         // join ranges from passed argument
    1060           0 :         lclJoinRanges( aList2 );
    1061             :         // calculate intersection of the ranges in both lists
    1062           0 :         for( ListOfScRange::const_iterator aOuterIt = aList1.begin(), aOuterEnd = aList1.end(); aOuterIt != aOuterEnd; ++aOuterIt )
    1063             :         {
    1064           0 :             for( ListOfScRange::const_iterator aInnerIt = aList2.begin(), aInnerEnd = aList2.end(); aInnerIt != aInnerEnd; ++aInnerIt )
    1065             :             {
    1066           0 :                 if( aOuterIt->Intersects( *aInnerIt ) )
    1067             :                 {
    1068             :                     ScRange aIsectRange(
    1069           0 :                         std::max( aOuterIt->aStart.Col(), aInnerIt->aStart.Col() ),
    1070           0 :                         std::max( aOuterIt->aStart.Row(), aInnerIt->aStart.Row() ),
    1071           0 :                         std::max( aOuterIt->aStart.Tab(), aInnerIt->aStart.Tab() ),
    1072           0 :                         std::min( aOuterIt->aEnd.Col(),   aInnerIt->aEnd.Col() ),
    1073           0 :                         std::min( aOuterIt->aEnd.Row(),   aInnerIt->aEnd.Row() ),
    1074           0 :                         std::min( aOuterIt->aEnd.Tab(),   aInnerIt->aEnd.Tab() ) );
    1075           0 :                     rList.push_back( aIsectRange );
    1076             :                 }
    1077             :             }
    1078             :         }
    1079             :         // again, join the result ranges
    1080           0 :         lclJoinRanges( rList );
    1081           0 :     }
    1082           0 : }
    1083             : 
    1084             : /** Creates a VBA Range object from the passed list of ranges. */
    1085           0 : 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           0 :     ScDocShell* pDocShell = excel::getDocShell( rxModel );
    1091           0 :     if( !pDocShell ) throw uno::RuntimeException();
    1092             : 
    1093           0 :     ScRangeList aCellRanges;
    1094           0 :     for( ListOfScRange::const_iterator aIt = rList.begin(), aEnd = rList.end(); aIt != aEnd; ++aIt )
    1095           0 :         aCellRanges.Append( *aIt );
    1096             : 
    1097           0 :     if( aCellRanges.size() == 1 )
    1098             :     {
    1099           0 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocShell, *aCellRanges.front() ) );
    1100           0 :         return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), rxContext, xRange );
    1101             :     }
    1102           0 :     if( aCellRanges.size() > 1 )
    1103             :     {
    1104           0 :         uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocShell, aCellRanges ) );
    1105           0 :         return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), rxContext, xRanges );
    1106             :     }
    1107           0 :     return 0;
    1108             : }
    1109             : 
    1110             : } // namespace
    1111             : 
    1112           0 : 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           0 :     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           0 :     ListOfScRange aList;
    1128           0 :     lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
    1129           0 :     lclJoinRanges( aList );
    1130             : 
    1131             :     // process all other parameters, this updates the list with intersection
    1132           0 :     lclIntersectRanges( aList, uno::Any( rArg2 ) );
    1133           0 :     lclIntersectRanges( aList, rArg3 );
    1134           0 :     lclIntersectRanges( aList, rArg4 );
    1135           0 :     lclIntersectRanges( aList, rArg5 );
    1136           0 :     lclIntersectRanges( aList, rArg6 );
    1137           0 :     lclIntersectRanges( aList, rArg7 );
    1138           0 :     lclIntersectRanges( aList, rArg8 );
    1139           0 :     lclIntersectRanges( aList, rArg9 );
    1140           0 :     lclIntersectRanges( aList, rArg10 );
    1141           0 :     lclIntersectRanges( aList, rArg11 );
    1142           0 :     lclIntersectRanges( aList, rArg12 );
    1143           0 :     lclIntersectRanges( aList, rArg13 );
    1144           0 :     lclIntersectRanges( aList, rArg14 );
    1145           0 :     lclIntersectRanges( aList, rArg15 );
    1146           0 :     lclIntersectRanges( aList, rArg16 );
    1147           0 :     lclIntersectRanges( aList, rArg17 );
    1148           0 :     lclIntersectRanges( aList, rArg18 );
    1149           0 :     lclIntersectRanges( aList, rArg19 );
    1150           0 :     lclIntersectRanges( aList, rArg20 );
    1151           0 :     lclIntersectRanges( aList, rArg21 );
    1152           0 :     lclIntersectRanges( aList, rArg22 );
    1153           0 :     lclIntersectRanges( aList, rArg23 );
    1154           0 :     lclIntersectRanges( aList, rArg24 );
    1155           0 :     lclIntersectRanges( aList, rArg25 );
    1156           0 :     lclIntersectRanges( aList, rArg26 );
    1157           0 :     lclIntersectRanges( aList, rArg27 );
    1158           0 :     lclIntersectRanges( aList, rArg28 );
    1159           0 :     lclIntersectRanges( aList, rArg29 );
    1160           0 :     lclIntersectRanges( aList, rArg30 );
    1161             : 
    1162             :     // create the VBA Range object
    1163           0 :     return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
    1164             : }
    1165             : 
    1166           0 : 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           0 :     if( !rArg1.is() || !rArg2.is() )
    1178           0 :         DebugHelper::exception( SbERR_BAD_PARAMETER, OUString() );
    1179             : 
    1180           0 :     ListOfScRange aList;
    1181           0 :     lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
    1182           0 :     lclAddToListOfScRange( aList, uno::Any( rArg2 ) );
    1183           0 :     lclAddToListOfScRange( aList, rArg3 );
    1184           0 :     lclAddToListOfScRange( aList, rArg4 );
    1185           0 :     lclAddToListOfScRange( aList, rArg5 );
    1186           0 :     lclAddToListOfScRange( aList, rArg6 );
    1187           0 :     lclAddToListOfScRange( aList, rArg7 );
    1188           0 :     lclAddToListOfScRange( aList, rArg8 );
    1189           0 :     lclAddToListOfScRange( aList, rArg9 );
    1190           0 :     lclAddToListOfScRange( aList, rArg10 );
    1191           0 :     lclAddToListOfScRange( aList, rArg11 );
    1192           0 :     lclAddToListOfScRange( aList, rArg12 );
    1193           0 :     lclAddToListOfScRange( aList, rArg13 );
    1194           0 :     lclAddToListOfScRange( aList, rArg14 );
    1195           0 :     lclAddToListOfScRange( aList, rArg15 );
    1196           0 :     lclAddToListOfScRange( aList, rArg16 );
    1197           0 :     lclAddToListOfScRange( aList, rArg17 );
    1198           0 :     lclAddToListOfScRange( aList, rArg18 );
    1199           0 :     lclAddToListOfScRange( aList, rArg19 );
    1200           0 :     lclAddToListOfScRange( aList, rArg20 );
    1201           0 :     lclAddToListOfScRange( aList, rArg21 );
    1202           0 :     lclAddToListOfScRange( aList, rArg22 );
    1203           0 :     lclAddToListOfScRange( aList, rArg23 );
    1204           0 :     lclAddToListOfScRange( aList, rArg24 );
    1205           0 :     lclAddToListOfScRange( aList, rArg25 );
    1206           0 :     lclAddToListOfScRange( aList, rArg26 );
    1207           0 :     lclAddToListOfScRange( aList, rArg27 );
    1208           0 :     lclAddToListOfScRange( aList, rArg28 );
    1209           0 :     lclAddToListOfScRange( aList, rArg29 );
    1210           0 :     lclAddToListOfScRange( aList, rArg30 );
    1211             : 
    1212             :     // simply join together all ranges as much as possible, strip out covered ranges etc.
    1213           0 :     lclJoinRanges( aList );
    1214             : 
    1215             :     // create the VBA Range object
    1216           0 :     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           0 : ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
    1331             : {
    1332           0 :     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           0 : sdecl::vba_service_class_<ScVbaApplication, sdecl::with_args<false> > serviceImpl;
    1394           0 : extern sdecl::ServiceDecl const serviceDecl(
    1395             :     serviceImpl,
    1396             :     "ScVbaApplication",
    1397             :     "ooo.vba.excel.Application" );
    1398           0 : }
    1399             : 
    1400             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10