diff options
author | Noel Power <noel.power@suse.com> | 2013-06-04 15:24:29 +0100 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-06-04 15:29:45 +0100 |
commit | 25bb9d13b259dbfb73f1412506f0d051b3670089 (patch) | |
tree | c560d5d66e20b8f473eafbc54be374375d4a1489 /oox | |
parent | 78775f1ad9b3f394896179898db984e139d5b5cc (diff) |
fix for fdo#53042 fix ole object macro bindings ( for xlsm )
A number of fixes needed here
a) make sure convert properties of control model is done before inserting
control model into formcontainer, need to do that to ensure that
GenerateVBAEvents is set ( so the fake VBA event generation can be
triggered )
b) remove the IsAlieanExcel check in servuno.cxx ( it's too strict and
additionally seems there is confusion over the media type to check )
c) split the vba import so that we can ensure the VBA mode is set (if
we have modules to import ) before sheets are imported and defer further
processing ( actual assigning of the modules and associated objects )
until later
Change-Id: I8fdbe788b400d7e41d4cc4b51b15f692bd7b0ecc
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/ole/axcontrol.cxx | 10 | ||||
-rw-r--r-- | oox/source/ole/vbaproject.cxx | 79 |
2 files changed, 54 insertions, 35 deletions
diff --git a/oox/source/ole/axcontrol.cxx b/oox/source/ole/axcontrol.cxx index d5303a4eea7e..23f08e37bd4a 100644 --- a/oox/source/ole/axcontrol.cxx +++ b/oox/source/ole/axcontrol.cxx @@ -2704,6 +2704,7 @@ EmbeddedForm::EmbeddedForm( const Reference< XModel >& rxDocModel, Reference< XControlModel > EmbeddedForm::convertAndInsert( const EmbeddedControl& rControl, sal_Int32& rnCtrlIndex ) { + Reference< XControlModel > xRet; if( mxModelFactory.is() && rControl.hasModel() ) try { // create the UNO control model @@ -2711,20 +2712,19 @@ Reference< XControlModel > EmbeddedForm::convertAndInsert( const EmbeddedControl Reference< XFormComponent > xFormComp( mxModelFactory->createInstance( aServiceName ), UNO_QUERY_THROW ); Reference< XControlModel > xCtrlModel( xFormComp, UNO_QUERY_THROW ); + // convert the control properties + if( rControl.convertProperties( xCtrlModel, maControlConv ) ) + xRet = xCtrlModel; // insert the control into the form Reference< XIndexContainer > xFormIC( createXForm(), UNO_SET_THROW ); rnCtrlIndex = xFormIC->getCount(); xFormIC->insertByIndex( rnCtrlIndex, Any( xFormComp ) ); - - // convert the control properties - if( rControl.convertProperties( xCtrlModel, maControlConv ) ) - return xCtrlModel; } catch (const Exception& e) { SAL_WARN("oox", "exception creating Control: " << e.Message); } - return Reference< XControlModel >(); + return xRet; } Reference< XIndexContainer > EmbeddedForm::createXForm() diff --git a/oox/source/ole/vbaproject.cxx b/oox/source/ole/vbaproject.cxx index 91be35621d3d..b58710d0efcc 100644 --- a/oox/source/ole/vbaproject.cxx +++ b/oox/source/ole/vbaproject.cxx @@ -264,8 +264,14 @@ Reference< XNameContainer > VbaProject::createDialogLibrary() void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr ) { + readVbaModules( rVbaPrjStrg ); + importModulesAndForms(rVbaPrjStrg, rGraphicHelper, bDefaultColorBgr ); +} + +void VbaProject::readVbaModules( StorageBase& rVbaPrjStrg ) +{ StorageRef xVbaStrg = rVbaPrjStrg.openSubStorage( "VBA", false ); - OSL_ENSURE( xVbaStrg.get(), "VbaProject::importVba - cannot open 'VBA' substorage" ); + OSL_ENSURE( xVbaStrg.get(), "VbaProject::readVbaModules - cannot open 'VBA' substorage" ); if( !xVbaStrg ) return; @@ -288,8 +294,6 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap sal_uInt16 nModuleCount = 0; bool bExecutable = isImportVbaExecutable(); - typedef RefMap< OUString, VbaModule > VbaModuleMap; - VbaModuleMap aModules, aModulesByStrm; sal_uInt16 nRecId = 0; StreamDataSequence aRecData; @@ -304,7 +308,7 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap case VBA_ID_PROJECTCODEPAGE: { OOX_ENSURE_RECORDSIZE( nRecSize == 2 ); - OSL_ENSURE( aModules.empty(), "VbaProject::importVba - unexpected PROJECTCODEPAGE record" ); + OSL_ENSURE( maModules.empty(), "VbaProject::importVba - unexpected PROJECTCODEPAGE record" ); rtl_TextEncoding eNewTextEnc = rtl_getTextEncodingFromWindowsCodePage( aRecStrm.readuInt16() ); OSL_ENSURE( eNewTextEnc != RTL_TEXTENCODING_DONTKNOW, "VbaProject::importVba - unknown text encoding" ); if( eNewTextEnc != RTL_TEXTENCODING_DONTKNOW ) @@ -321,26 +325,26 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap break; case VBA_ID_PROJECTMODULES: OOX_ENSURE_RECORDSIZE( nRecSize == 2 ); - OSL_ENSURE( aModules.empty(), "VbaProject::importVba - unexpected PROJECTMODULES record" ); + OSL_ENSURE( maModules.empty(), "VbaProject::importVba - unexpected PROJECTMODULES record" ); aRecStrm >> nModuleCount; break; case VBA_ID_MODULENAME: { OUString aName = aRecStrm.readCharArrayUC( nRecSize, eTextEnc ); OSL_ENSURE( !aName.isEmpty(), "VbaProject::importVba - invalid module name" ); - OSL_ENSURE( !aModules.has( aName ), "VbaProject::importVba - multiple modules with the same name" ); - VbaModuleMap::mapped_type& rxModule = aModules[ aName ]; + OSL_ENSURE( !maModules.has( aName ), "VbaProject::importVba - multiple modules with the same name" ); + VbaModuleMap::mapped_type& rxModule = maModules[ aName ]; rxModule.reset( new VbaModule( mxContext, mxDocModel, aName, eTextEnc, bExecutable ) ); // read all remaining records until the MODULEEND record rxModule->importDirRecords( aDirStrm ); - OSL_ENSURE( !aModulesByStrm.has( rxModule->getStreamName() ), "VbaProject::importVba - multiple modules with the same stream name" ); - aModulesByStrm[ rxModule->getStreamName() ] = rxModule; + OSL_ENSURE( !maModulesByStrm.has( rxModule->getStreamName() ), "VbaProject::importVba - multiple modules with the same stream name" ); + maModulesByStrm[ rxModule->getStreamName() ] = rxModule; } break; #undef OOX_ENSURE_RECORDSIZE } } - OSL_ENSURE( nModuleCount == aModules.size(), "VbaProject::importVba - invalid module count" ); + OSL_ENSURE( nModuleCount == maModules.size(), "VbaProject::importVba - invalid module count" ); /* The directory does not contain the real type of the modules, it distinguishes only between 'procedural' and 'document' (the latter @@ -397,19 +401,48 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap if( (nType != ModuleType::UNKNOWN) && !aValue.isEmpty() ) { - OSL_ENSURE( aModules.has( aValue ), "VbaProject::importVba - module not found" ); - if( VbaModule* pModule = aModules.get( aValue ).get() ) + OSL_ENSURE( maModules.has( aValue ), "VbaProject::importVba - module not found" ); + if( VbaModule* pModule = maModules.get( aValue ).get() ) pModule->setType( nType ); } } } } + if( !maModules.empty() ) try + { + /* Set library container to VBA compatibility mode. This will create + the VBA Globals object and store it in the Basic manager of the + document. */ + try + { + Reference< XVBACompatibility > xVBACompat( getLibraryContainer( PROP_BasicLibraries ), UNO_QUERY_THROW ); + xVBACompat->setVBACompatibilityMode( sal_True ); + xVBACompat->setProjectName( maPrjName ); + + } + catch(const Exception& ) + { + } + } + catch(const Exception& ) + { + } +} + +void VbaProject::importModulesAndForms( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr ) +{ + StorageRef xVbaStrg = rVbaPrjStrg.openSubStorage( "VBA", false ); + OSL_ENSURE( xVbaStrg.get(), "VbaProject::importModulesAndForms - cannot open 'VBA' substorage" ); + if( !xVbaStrg ) + return; + rtl_TextEncoding eTextEnc = RTL_TEXTENCODING_MS_1252; + bool bExecutable = isImportVbaExecutable(); // create empty dummy modules VbaModuleMap aDummyModules; for( DummyModuleMap::iterator aIt = maDummyModules.begin(), aEnd = maDummyModules.end(); aIt != aEnd; ++aIt ) { - OSL_ENSURE( !aModules.has( aIt->first ) && !aDummyModules.has( aIt->first ), "VbaProject::importVba - multiple modules with the same name" ); + OSL_ENSURE( !maModules.has( aIt->first ) && !aDummyModules.has( aIt->first ), "VbaProject::importVba - multiple modules with the same name" ); VbaModuleMap::mapped_type& rxModule = aDummyModules[ aIt->first ]; rxModule.reset( new VbaModule( mxContext, mxDocModel, aIt->first, eTextEnc, bExecutable ) ); rxModule->setType( aIt->second ); @@ -419,26 +452,12 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap into the Basic library of the document specified by the 'maPrjName' member. Do not create the Basic library, if there are no modules specified. */ - if( !aModules.empty() || !aDummyModules.empty() ) try + if( !maModules.empty() || !aDummyModules.empty() ) try { // get the model factory and the basic library Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW ); Reference< XNameContainer > xBasicLib( createBasicLibrary(), UNO_SET_THROW ); - /* Set library container to VBA compatibility mode. This will create - the VBA Globals object and store it in the Basic manager of the - document. */ - try - { - Reference< XVBACompatibility > xVBACompat( getLibraryContainer( PROP_BasicLibraries ), UNO_QUERY_THROW ); - xVBACompat->setVBACompatibilityMode( sal_True ); - xVBACompat->setProjectName( maPrjName ); - - } - catch(const Exception& ) - { - } - // try to get access to document objects related to code modules Reference< XNameAccess > xDocObjectNA; try @@ -454,7 +473,7 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap { // #TODO cater for mxOleOverridesSink, like I used to before // call Basic source code import for each module, boost::[c]ref enforces pass-by-ref - aModules.forEachMem( &VbaModule::createAndImportModule, + maModules.forEachMem( &VbaModule::createAndImportModule, ::boost::ref( *xVbaStrg ), ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ) ); @@ -482,7 +501,7 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap if( xSubStrg.get() ) try { // resolve module name from storage name (which equals the module stream name) - VbaModule* pModule = aModulesByStrm.get( *aIt ).get(); + VbaModule* pModule = maModulesByStrm.get( *aIt ).get(); OSL_ENSURE( pModule && (pModule->getType() == ModuleType::FORM), "VbaProject::importVba - form substorage without form module" ); OUString aModuleName; |