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