diff options
author | Daniel Rentz <dr@openoffice.org> | 2010-06-15 20:02:53 +0200 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2010-06-15 20:02:53 +0200 |
commit | 5ed103d2dd5f8ee2f13183263c0930f84437bdc7 (patch) | |
tree | ab1c7cf7a0b884df473eeda6048030ee8629972b /basic/source/uno | |
parent | f9561071999b3c5c8505d648c14fff7b1bcd0caa (diff) |
mib16: contributed bugfixes and various new symbols in VBA compatibility implementation
Diffstat (limited to 'basic/source/uno')
-rw-r--r-- | basic/source/uno/dlgcont.cxx | 11 | ||||
-rw-r--r-- | basic/source/uno/namecont.cxx | 18 | ||||
-rw-r--r-- | basic/source/uno/scriptcont.cxx | 142 |
3 files changed, 149 insertions, 22 deletions
diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index 051b4fa9f077..004b61fbf198 100644 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -187,12 +187,13 @@ bool writeOasis2OOoLibraryElement( void SAL_CALL SfxDialogLibraryContainer::writeLibraryElement ( - Any aElement, - const OUString& /*aElementName*/, - Reference< XOutputStream > xOutput + const Reference < XNameContainer >& xLib, + const OUString& aElementName, + const Reference< XOutputStream >& xOutput ) throw(Exception) { + Any aElement = xLib->getByName( aElementName ); Reference< XInputStreamProvider > xISP; aElement >>= xISP; if( !xISP.is() ) @@ -256,7 +257,9 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement - ( const OUString& aFile, const uno::Reference< io::XInputStream >& xElementStream ) + ( const Reference < XNameContainer >& /*xLib*/, + const OUString& /*aElementName */, const OUString& aFile, + const uno::Reference< io::XInputStream >& xElementStream ) { Any aRetAny; diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index 90e7cb4cb4d5..f692277fc5ba 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -1369,8 +1369,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, OUString aStreamName = aElementName; aStreamName += String( RTL_CONSTASCII_USTRINGPARAM(".xml") ); - Any aElement = pLib->getByName( aElementName ); - if( !isLibraryElementValid( aElement ) ) + /*Any aElement = pLib->getByName( aElementName );*/ + if( !isLibraryElementValid( pLib->getByName( aElementName ) ) ) { #if OSL_DEBUG_LEVEL > 0 ::rtl::OStringBuffer aMessage; @@ -1406,7 +1406,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, xProps->setPropertyValue( aPropName, uno::makeAny( sal_True ) ); Reference< XOutputStream > xOutput = xElementStream->getOutputStream(); - writeLibraryElement( aElement, aElementName, xOutput ); + Reference< XNameContainer > xLib( pLib ); + writeLibraryElement( xLib, aElementName, xOutput ); // writeLibraryElement closes the stream // xOutput->closeOutput(); } @@ -1458,8 +1459,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, aElementInetObj.setExtension( maLibElementFileExtension ); String aElementPath( aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ) ); - Any aElement = pLib->getByName( aElementName ); - if( !isLibraryElementValid( aElement ) ) + /*Any aElement = pLib->getByName( aElementName );*/ + if( !isLibraryElementValid( pLib->getByName( aElementName ) ) ) { #if OSL_DEBUG_LEVEL > 0 ::rtl::OStringBuffer aMessage; @@ -1477,7 +1478,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, if( xSFI->exists( aElementPath ) ) xSFI->kill( aElementPath ); Reference< XOutputStream > xOutput = xSFI->openFileWrite( aElementPath ); - writeLibraryElement( aElement, aElementName, xOutput ); + Reference< XNameContainer > xLib( pLib ); + writeLibraryElement( xLib, aElementName, xOutput ); xOutput->closeOutput(); } catch( Exception& ) @@ -2380,7 +2382,9 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name ) aFile = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ); } - Any aAny = importLibraryElement( aFile, xInStream ); + Reference< XNameContainer > xLib( pImplLib ); + Any aAny = importLibraryElement( xLib, aElementName, + aFile, xInStream ); if( pImplLib->hasByName( aElementName ) ) { if( aAny.hasValue() ) diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index 4185b6f9579c..5622adc19af1 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -41,6 +41,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/task/ErrorCodeIOException.hpp> +#include <com/sun/star/script/ModuleType.hpp> #include <comphelper/processfactory.hxx> #ifndef _COMPHELPER_STORAGEHELPER_HXX_ #include <comphelper/storagehelper.hxx> @@ -60,6 +61,7 @@ #include <svtools/ehdl.hxx> #include <basic/basmgr.hxx> #include <basic/sbmod.hxx> +#include <basic/basicmanagerrepository.hxx> #include "modsizeexceeded.hxx" #include <xmlscript/xmlmod_imexp.hxx> #include <cppuhelper/factory.hxx> @@ -184,9 +186,9 @@ bool SAL_CALL SfxScriptLibraryContainer::isLibraryElementValid( Any aElement ) c void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement ( - Any aElement, + const Reference < XNameContainer >& xLib, const OUString& aElementName, - Reference< XOutputStream > xOutput + const Reference< XOutputStream >& xOutput ) throw(Exception) { @@ -211,13 +213,42 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement xmlscript::ModuleDescriptor aMod; aMod.aName = aElementName; aMod.aLanguage = maScriptLanguage; + Any aElement = xLib->getByName( aElementName ); aElement >>= aMod.aCode; + + Reference < script::XVBAModuleInfo > xModInfo( xLib, UNO_QUERY ); + + if( xModInfo.is() && xModInfo->hasModuleInfo( aElementName ) ) + { + script::ModuleInfo aModInfo = xModInfo->getModuleInfo( aElementName ); + switch( aModInfo.ModuleType ) + { + case ModuleType::NORMAL: + aMod.aModuleType = OUString( RTL_CONSTASCII_USTRINGPARAM("normal") ); + break; + case ModuleType::CLASS: + aMod.aModuleType = OUString( RTL_CONSTASCII_USTRINGPARAM("class") ); + break; + case ModuleType::FORM: + aMod.aModuleType = OUString( RTL_CONSTASCII_USTRINGPARAM("form") ); + break; + case ModuleType::DOCUMENT: + aMod.aModuleType = OUString( RTL_CONSTASCII_USTRINGPARAM("document") ); + break; + case ModuleType::UNKNOWN: + // nothing + break; + } + } + xmlscript::exportScriptModule( xHandler, aMod ); } Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement - ( const OUString& aFile, const uno::Reference< io::XInputStream >& xInStream ) + ( const Reference < XNameContainer >& xLib, + const OUString& aElementName, const OUString& aFile, + const uno::Reference< io::XInputStream >& xInStream ) { Any aRetAny; @@ -279,6 +310,86 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement // TODO: Check language // aMod.aLanguage // aMod.aName ignored + if( aMod.aModuleType.getLength() > 0 ) + { + if( !getVBACompatModeOn() ) + { + setVBACompatModeOn( sal_True ); + + Any aGlobs; + Sequence< Any > aArgs(1); + Reference<frame::XModel > xModel( mxOwnerDocument ); + aArgs[ 0 ] <<= xModel; + + BasicManager* pBasicMgr = getBasicManager(); + if( pBasicMgr ) + { + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs ); + pBasicMgr->SetGlobalUNOConstant( "VBAGlobals", aGlobs ); + } + pBasicMgr = BasicManagerRepository::getApplicationBasicManager( sal_False ); + if( pBasicMgr ) + pBasicMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[0] ); + } + + script::ModuleInfo aModInfo; + aModInfo.ModuleType = ModuleType::UNKNOWN; + if( aMod.aModuleType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("normal") )) + { + aModInfo.ModuleType = ModuleType::NORMAL; + } + else if( aMod.aModuleType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("class") )) + { + aModInfo.ModuleType = ModuleType::CLASS; + } + else if( aMod.aModuleType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("form") )) + { + aModInfo.ModuleType = ModuleType::FORM; + aModInfo.ModuleObject = mxOwnerDocument; + } + else if( aMod.aModuleType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("document") )) + { + aModInfo.ModuleType = ModuleType::DOCUMENT; + Reference<frame::XModel > xModel( mxOwnerDocument ); + Reference< XMultiServiceFactory> xSF( xModel, UNO_QUERY); + Reference< container::XNameAccess > xVBACodeNameAccess; + if( xSF.is() ) + { + try + { + xVBACodeNameAccess.set( xSF->createInstance( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "ooo.vba.VBAObjectModuleObjectProvider"))), + UNO_QUERY ); + } + catch(uno::Exception&) {} + } + if( xVBACodeNameAccess.is() ) + { + try + { + aModInfo.ModuleObject.set( xVBACodeNameAccess->getByName( aElementName), uno::UNO_QUERY ); + } + catch(uno::Exception&) + { + OSL_TRACE("Failed to get documument object for %s", rtl::OUStringToOString( aElementName, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + } + } + + Reference< script::XVBAModuleInfo > xVBAModuleInfo( xLib, + UNO_QUERY ); + if( xVBAModuleInfo.is() ) + { + if( xVBAModuleInfo->hasModuleInfo( aElementName ) ) + xVBAModuleInfo->removeModuleInfo( aElementName ); + xVBAModuleInfo->insertModuleInfo( aElementName, aModInfo ); + } + } return aRetAny; } @@ -574,8 +685,8 @@ sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, if( pLib->mbPasswordVerified || pLib->mbDoc50Password ) { - Any aElement = pLib->getByName( aElementName ); - if( !isLibraryElementValid( aElement ) ) + /*Any aElement = pLib->getByName( aElementName );*/ + if( !isLibraryElementValid( pLib->getByName( aElementName ) ) ) { #if OSL_DEBUG_LEVEL > 0 ::rtl::OStringBuffer aMessage; @@ -606,7 +717,8 @@ sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, setStreamKey( xSourceStream, pLib->maPassword ); Reference< XOutputStream > xOutput = xSourceStream->getOutputStream(); - writeLibraryElement( aElement, aElementName, xOutput ); + Reference< XNameContainer > xLib( pLib ); + writeLibraryElement( xLib, aElementName, xOutput ); // writeLibraryElement should have the stream already closed // xOutput->closeOutput(); } @@ -659,8 +771,8 @@ sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, aElementInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("pba") ) ); String aElementPath = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ); - Any aElement = pLib->getByName( aElementName ); - if( !isLibraryElementValid( aElement ) ) + /*Any aElement = pLib->getByName( aElementName );*/ + if( !isLibraryElementValid( pLib->getByName( aElementName ) ) ) { #if OSL_DEBUG_LEVEL > 0 ::rtl::OStringBuffer aMessage; @@ -741,7 +853,8 @@ sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, xProps->setPropertyValue( aPropName, uno::makeAny( aMime ) ); Reference< XOutputStream > xOut = xSourceStream->getOutputStream(); - writeLibraryElement( aElement, aElementName, xOut ); + Reference< XNameContainer > xLib( pLib ); + writeLibraryElement( xLib, aElementName, xOut ); // i50568: sax writer already closes stream // xOut->closeOutput(); @@ -903,7 +1016,10 @@ sal_Bool SfxScriptLibraryContainer::implLoadPasswordLibrary if ( !xInStream.is() ) throw io::IOException(); // read access denied, seems to be impossible - Any aAny = importLibraryElement( aSourceStreamName, xInStream ); + Reference< XNameContainer > xLib( pLib ); + Any aAny = importLibraryElement( xLib, + aElementName, aSourceStreamName, + xInStream ); if( pLib->hasByName( aElementName ) ) { if( aAny.hasValue() ) @@ -1006,7 +1122,11 @@ sal_Bool SfxScriptLibraryContainer::implLoadPasswordLibrary if ( !xInStream.is() ) throw io::IOException(); // read access denied, seems to be impossible - Any aAny = importLibraryElement( aSourceStreamName, xInStream ); + Reference< XNameContainer > xLib( pLib ); + Any aAny = importLibraryElement( xLib, + aElementName, + aSourceStreamName, + xInStream ); if( pLib->hasByName( aElementName ) ) { if( aAny.hasValue() ) |