From 191bf98991e1934bfef115a1cec463ac250b0191 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Fri, 25 Mar 2011 10:40:25 +0100 Subject: calcvba: #164410# improve VBA compatibility implementation in various areas: Excel symbols, MSForms symbols, document and forms event handling Conflicts: sc/source/ui/docshell/docsh.cxx sc/source/ui/unoobj/docuno.cxx sc/source/ui/vba/vbaapplication.cxx sc/source/ui/vba/vbaapplication.hxx sc/source/ui/vba/vbaeventshelper.cxx sc/source/ui/vba/vbaglobals.cxx sc/source/ui/vba/vbarange.cxx sc/source/ui/vba/vbawindow.cxx sc/source/ui/vba/vbaworkbook.cxx sc/source/ui/vba/vbaworkbooks.cxx sc/source/ui/vba/vbaworksheets.cxx sc/util/makefile.mk --- sc/source/ui/vba/vbaapplication.cxx | 116 +++++++++++++++--------------------- 1 file changed, 48 insertions(+), 68 deletions(-) (limited to 'sc/source/ui/vba/vbaapplication.cxx') diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 317ee93c235b..a2874c47c42c 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -42,9 +42,6 @@ #include #include #include -#include -#include -#include #include "vbaapplication.hxx" #include "vbaworkbooks.hxx" @@ -117,16 +114,7 @@ using ::rtl::OUString; #define FILE_PATH_SEPERATOR "\\" #endif -class ActiveWorkbook : public ScVbaWorkbook -{ -protected: - virtual uno::Reference< frame::XModel > getModel() - { - return getCurrentExcelDoc(mxContext); - } -public: - ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){} -}; +uno::Any sbxToUnoValue( SbxVariable* pVar ); // ============================================================================ @@ -239,47 +227,15 @@ ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) throw(uno::RuntimeE uno::Reference< excel::XWorkbook > ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWrkbk; - ScDocShell* pShell = excel::getDocShell( getCurrentExcelDoc( mxContext ) ); - if ( pShell ) - { - String aName; - if ( pShell->GetDocument() ) - { - aName = pShell->GetDocument()->GetCodeName(); - xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); - // fallback ( e.g. it's possible a new document was created via the api ) - // in that case the document will not have the appropriate Document Modules - // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document - // vba mode etc. ) - if ( !xWrkbk.is() ) - return new ActiveWorkbook( this, mxContext ); - } - } - return xWrkbk; + // will throw if active document is not in VBA compatibility mode (no object for codename) + return uno::Reference< excel::XWorkbook >( getVBADocument( getCurrentExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW ); } uno::Reference< excel::XWorkbook > SAL_CALL ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWrkbk; - ScDocShell* pShell = excel::getDocShell( getThisExcelDoc( mxContext ) ); - if ( pShell ) - { - String aName; - if ( pShell->GetDocument() ) - { - aName = pShell->GetDocument()->GetCodeName(); - xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); - // fallback ( e.g. it's possible a new document was created via the api ) - // in that case the document will not have the appropriate Document Modules - // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document - // vba mode etc. ) - if ( !xWrkbk.is() ) - return new ActiveWorkbook( this, mxContext ); - } - } - return xWrkbk; + // should never throw as this model is in VBA compatibility mode + return uno::Reference< excel::XWorkbook >( getVBADocument( getThisExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW ); } uno::Reference< XAssistant > SAL_CALL @@ -388,17 +344,8 @@ ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeExcepti uno::Any SAL_CALL ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY ); - uno::Any result; - if ( xWorkbook.is() ) - result = xWorkbook->Worksheets( aIndex ); - - else - // Fixme - check if this is reasonable/desired behavior - throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No ActiveWorkBook available" )), - uno::Reference< uno::XInterface >() ); - - return result; + uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW ); + return xWorkbook->Worksheets( aIndex ); } uno::Any SAL_CALL @@ -914,37 +861,36 @@ rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) } return sRetPath; } + void SAL_CALL -ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext ); rtl::OUString aURL; osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL ); - xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::makeAny( aURL ) ); - - + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::Any( aURL ) ); } ::rtl::OUString SAL_CALL -ScVbaApplication::getDefaultFilePath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::LibraryPath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getLibraryPath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Basic"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::TemplatesPath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::PathSeparator( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getPathSeparator() throw (uno::RuntimeException) { static rtl::OUString sPathSep( RTL_CONSTASCII_USTRINGPARAM( FILE_PATH_SEPERATOR ) ); return sPathSep; @@ -1302,6 +1248,40 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeExcep return aRet; } +uno::Any SAL_CALL ScVbaApplication::GetOpenFilename( + const uno::Any& rFileFilter, const uno::Any& rFilterIndex, const uno::Any& rTitle, + const uno::Any& rButtonText, const uno::Any& rMultiSelect ) throw (uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 6 ); + aArgs[ 0 ] <<= getThisExcelDoc( mxContext ); + aArgs[ 1 ] = rFileFilter; + aArgs[ 2 ] = rFilterIndex; + aArgs[ 3 ] = rTitle; + aArgs[ 4 ] = rButtonText; + aArgs[ 5 ] = rMultiSelect; + uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.OpenFilePicker" ) ), aArgs, mxContext ), uno::UNO_QUERY_THROW ); + return xFilePicker->execute(); +} + +uno::Any SAL_CALL ScVbaApplication::GetSaveAsFilename( + const uno::Any& rInitialFileName, const uno::Any& rFileFilter, const uno::Any& rFilterIndex, + const uno::Any& rTitle, const uno::Any& rButtonText ) throw (uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 6 ); + aArgs[ 0 ] <<= getThisExcelDoc( mxContext ); + aArgs[ 1 ] = rInitialFileName; + aArgs[ 2 ] = rFileFilter; + aArgs[ 3 ] = rFilterIndex; + aArgs[ 4 ] = rTitle; + aArgs[ 5 ] = rButtonText; + uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.SaveAsFilePicker" ) ), aArgs, mxContext ), uno::UNO_QUERY_THROW ); + return xFilePicker->execute(); +} + uno::Reference< frame::XModel > ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException) { -- cgit