diff options
Diffstat (limited to 'sc/source/ui/vba/vbaworkbooks.cxx')
-rw-r--r-- | sc/source/ui/vba/vbaworkbooks.cxx | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index 7efee1505dcb..a9f1970be34e 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -46,7 +46,9 @@ #include <com/sun/star/document/XTypeDetection.hpp> #include <com/sun/star/uri/XUriReference.hpp> #include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/script/vba/VBAEventId.hpp> #include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> #include <com/sun/star/script/vba/XVBAModuleInfo.hpp> #include <com/sun/star/script/ModuleInfo.hpp> #include <com/sun/star/script/ModuleType.hpp> @@ -73,15 +75,19 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& ScDocShell* pShell = excel::getDocShell( xModel ); if ( pShell ) { + String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + pShell->GetBasicManager()->SetName( aPrjName ); + + /* Set library container to VBA compatibility mode. This will create + the VBA Globals object and store it in the Basic manager of the + document. */ uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer(); uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW ); xVBACompat->setVBACompatibilityMode( sal_True ); - String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); - pShell->GetBasicManager()->SetName( aPrjName ); if( xLibContainer.is() ) { - if( !xLibContainer->hasByName( aPrjName ) ) + if( !xLibContainer->hasByName( aPrjName ) ) xLibContainer->createLibrary( aPrjName ); uno::Any aLibAny = xLibContainer->getByName( aPrjName ); uno::Reference< container::XNameContainer > xLib; @@ -90,8 +96,6 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& { uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW ); uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW); - // bootstrap vbaglobals - xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals"))); uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW ); // set up the module info for the workbook and sheets in the nealy created // spreadsheet @@ -130,6 +134,18 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& } } } + + /* Trigger the Workbook_Open event, event processor will register + itself as listener for specific events. */ + try + { + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW ); + uno::Sequence< uno::Any > aArgs; + xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs ); + } + catch( uno::Exception& ) + { + } } } @@ -200,9 +216,41 @@ ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) uno::Any SAL_CALL -ScVbaWorkbooks::Add() throw (uno::RuntimeException) +ScVbaWorkbooks::Add( const uno::Any& Template ) throw (uno::RuntimeException) { - uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( VbaDocumentsBase::Add() , uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc; + sal_Int32 nWorkbookType = 0; + ::rtl::OUString aTemplateFileName; + if( Template >>= nWorkbookType ) + { + // nWorkbookType is a constant from XlWBATemplate (added in Excel 2007) + // TODO: create chart-sheet if supported by Calc + + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + // create a document with one sheet only + uno::Reference< sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_SET_THROW ); + uno::Reference< container::XIndexAccess > xSheetsIA( xSheets, uno::UNO_QUERY_THROW ); + while( xSheetsIA->getCount() > 1 ) + { + uno::Reference< container::XNamed > xSheetName( xSheetsIA->getByIndex( xSheetsIA->getCount() - 1 ), uno::UNO_QUERY_THROW ); + xSheets->removeByName( xSheetName->getName() ); + } + } + else if( Template >>= aTemplateFileName ) + { + // TODO: create document from template + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + } + else if( !Template.hasValue() ) + { + // regular spreadsheet document with configured number of sheets + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + } + else + { + // illegal argument + throw uno::RuntimeException(); + } // need to set up the document modules ( and vba mode ) here setUpDocumentModules( xSpreadDoc ); @@ -211,10 +259,10 @@ ScVbaWorkbooks::Add() throw (uno::RuntimeException) return uno::Any(); } -void +void SAL_CALL ScVbaWorkbooks::Close() throw (uno::RuntimeException) { - VbaDocumentsBase::Close(); + closeDocuments(); } bool @@ -254,7 +302,7 @@ ScVbaWorkbooks::getFileFilterType( const rtl::OUString& rFileName ) } // #TODO# #FIXME# can any of the unused params below be used? -uno::Any +uno::Any SAL_CALL ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLinks*/, const uno::Any& ReadOnly, const uno::Any& Format, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*IgnoreReadOnlyRecommended*/, const uno::Any& /*Origin*/, const uno::Any& Delimiter, const uno::Any& /*Editable*/, const uno::Any& /*Notify*/, const uno::Any& /*Converter*/, const uno::Any& /*AddToMru*/ ) throw (uno::RuntimeException) { // we need to detect if this is a URL, if not then assume its a file path @@ -333,7 +381,7 @@ ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLi else if ( !isSpreadSheetFile( sType ) ) throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Bad Format")), uno::Reference< uno::XInterface >() ); - uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( VbaDocumentsBase::Open( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( openDocument( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); if ( xWBook.is() ) @@ -341,12 +389,6 @@ ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLi return aRet; } -uno::Any -ScVbaWorkbooks::Open( const rtl::OUString& Filename, const uno::Any& ReadOnly, const uno::Sequence< beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException) -{ - return VbaDocumentsBase::Open( Filename, ReadOnly, rProps ); -} - rtl::OUString& ScVbaWorkbooks::getServiceImplName() { |