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

Generated by: LCOV version 1.10