Tag: cws_src680_dba24c User: fs Date: 2007-10-09 21:12:21+0000 Modified: dba/dbaccess/source/core/dataaccess/documentdefinition.cxx
Log: #i82110#: when loading an embedded object, respect the load arguments given to our execute call. In particular, do *not* overwrite an MacroExecutionMode if it is present File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: documentdefinition.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/documentdefinition.cxx?r1=1.46.20.2&r2=1.46.20.3 Delta lines: +100 -68 ---------------------- --- documentdefinition.cxx 2007-09-28 19:18:49+0000 1.46.20.2 +++ documentdefinition.cxx 2007-10-09 21:12:18+0000 1.46.20.3 @@ -4,9 +4,9 @@ * * $RCSfile: documentdefinition.cxx,v $ * - * $Revision: 1.46.20.2 $ + * $Revision: 1.46.20.3 $ * - * last change: $Author: fs $ $Date: 2007/09/28 19:18:49 $ + * last change: $Author: fs $ $Date: 2007/10/09 21:12:18 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -60,6 +60,9 @@ #ifndef _COMPHELPER_MEDIADESCRIPTOR_HXX_ #include <comphelper/mediadescriptor.hxx> #endif +#ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX +#include <comphelper/namedvaluecollection.hxx> +#endif #ifndef _SO_CLSIDS_HXX #include <so3/clsids.hxx> #endif @@ -537,7 +540,7 @@ DBG_CTOR(ODocumentDefinition, NULL); registerProperties(); if ( _aClassID.getLength() ) - loadEmbeddedObject(MacroExecMode::USE_CONFIG,_aClassID,_xConnection); + loadEmbeddedObject( _xConnection, _aClassID, Sequence< PropertyValue >(), false, false ); } //-------------------------------------------------------------------------- @@ -637,16 +640,16 @@ // ----------------------------------------------------------------------------- namespace { - bool lcl_extractOpenMode( const Any& _rValue, sal_Int32& /* [out] */ _rMode ) + bool lcl_extractOpenMode( const Any& _rValue, sal_Int32& _out_rMode ) { OpenCommandArgument aOpenCommand; if ( _rValue >>= aOpenCommand ) - _rMode = aOpenCommand.Mode; + _out_rMode = aOpenCommand.Mode; else { OpenCommandArgument2 aOpenCommand2; if ( _rValue >>= aOpenCommand2 ) - _rMode = aOpenCommand2.Mode; + _out_rMode = aOpenCommand2.Mode; else return false; } @@ -854,19 +857,30 @@ Reference< XConnection> xConnection; sal_Int32 nOpenMode = OpenMode::DOCUMENT; - lcl_extractOpenMode( aCommand.Argument, nOpenMode ); - + Sequence< PropertyValue > aLoadArgs; + if ( !lcl_extractOpenMode( aCommand.Argument, nOpenMode ) ) + { Sequence< PropertyValue > aArguments; if ( aCommand.Argument >>= aArguments ) { const PropertyValue* pIter = aArguments.getConstArray(); const PropertyValue* pEnd = pIter + aArguments.getLength(); - for(;pIter != pEnd;++pIter) + for ( ;pIter != pEnd; ++pIter ) { if ( pIter->Name == PROPERTY_ACTIVECONNECTION ) - xConnection.set(pIter->Value,UNO_QUERY); - else - lcl_extractOpenMode( pIter->Value, nOpenMode ); + { + xConnection.set( pIter->Value, UNO_QUERY ); + continue; + } + + if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) ) + continue; + + // unknown argument -> pass to the loaded document + sal_Int32 nLoadArgs = aLoadArgs.getLength(); + aLoadArgs.realloc( nLoadArgs + 1 ); + aLoadArgs[ nLoadArgs ] = *pIter; + } } } @@ -895,7 +909,7 @@ if ( m_pImpl->m_aProps.sPersistentName.getLength() ) { m_bOpenInDesign = bOpenInDesign; - loadEmbeddedObject(MacroExecMode::USE_CONFIG,Sequence< sal_Int8 >(),xConnection,!bOpenInDesign); + loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aLoadArgs, false, !bOpenInDesign ); if ( m_xEmbeddedObject.is() ) { xModel.set(getComponent(),UNO_QUERY); @@ -949,7 +963,7 @@ Reference< XStorage> xStorage(aIni[0],UNO_QUERY); ::rtl::OUString sPersistentName; aIni[1] >>= sPersistentName; - loadEmbeddedObject(MacroExecMode::USE_CONFIG, Sequence< sal_Int8 >(), Reference< XConnection >(), sal_False ); + loadEmbeddedObject(); Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY); if ( xPersist.is() ) { @@ -1211,10 +1225,41 @@ } return sal_True; } + +namespace +{ + // ......................................................................... + void lcl_putLoadArgs( ::comphelper::NamedValueCollection& _io_rArgs, const bool _bSuppressMacros, const bool _bReadOnly, + const ::rtl::OUString& _rDocTitle ) + { + if ( _bSuppressMacros ) + { + // if we're to suppress macros, do exactly this + _io_rArgs.put( "MacroExecutionMode", MacroExecMode::NEVER_EXECUTE ); + } + else + { + // otherwise, put the setting only if not already present + if ( !_io_rArgs.has( "MacroExecutionMode" ) ) + { + _io_rArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); + } + } + + _io_rArgs.put( "ReadOnly", _bReadOnly ); + + if ( _rDocTitle.getLength() ) + { + _io_rArgs.put( "DocumentTitle", _rDocTitle ); + } + } +} + // ----------------------------------------------------------------------------- -void ODocumentDefinition::fillLoadArgs(Sequence<PropertyValue>& _rArgs,Sequence<PropertyValue>& _rEmbeddedObjectDescriptor,const Reference<XConnection>& _xConnection,sal_Bool _bReadOnly,sal_Int16 _nMarcoExcecMode) +Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly, + const Sequence< PropertyValue >& _rAdditionalArgs, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor ) { - sal_Int32 nLen = _rArgs.getLength(); + ::comphelper::NamedValueCollection aMediaDesc( _rAdditionalArgs ); { Sequence<PropertyValue> aDocumentContext(2); aDocumentContext[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")); @@ -1223,24 +1268,10 @@ aDocumentContext[1].Name = PROPERTY_APPLYFORMDESIGNMODE; aDocumentContext[1].Value <<= !_bReadOnly; - _rArgs.realloc(nLen+1); - _rArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ComponentData")); - _rArgs[nLen++].Value <<= aDocumentContext; + aMediaDesc.put( "ComponentData", aDocumentContext ); } - _rArgs.realloc(nLen+2); - _rArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); - _rArgs[nLen++].Value <<= _bReadOnly; - - _rArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")); - _rArgs[nLen++].Value <<= _nMarcoExcecMode; - - if ( m_pImpl->m_aProps.aTitle.getLength() ) - { - _rArgs.realloc(nLen+1); - _rArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")); - _rArgs[nLen++].Value <<= m_pImpl->m_aProps.aTitle; - } + lcl_putLoadArgs( aMediaDesc, _bSuppressMacros, _bReadOnly, m_pImpl->m_aProps.aTitle ); if ( m_pInterceptor ) { @@ -1253,10 +1284,10 @@ m_pInterceptor->acquire(); Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor; - _rEmbeddedObjectDescriptor.realloc(2); - nLen = 0; - _rEmbeddedObjectDescriptor[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutplaceDispatchInterceptor")); - _rEmbeddedObjectDescriptor[nLen++].Value <<= xInterceptor; + _out_rEmbeddedObjectDescriptor.realloc(2); + sal_Int32 nLen = 0; + _out_rEmbeddedObjectDescriptor[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutplaceDispatchInterceptor")); + _out_rEmbeddedObjectDescriptor[nLen++].Value <<= xInterceptor; uno::Sequence< uno::Any > aOutFrameProps(2); PropertyValue aProp; @@ -1279,11 +1310,16 @@ aOutFrameProps[1] <<= aProp; } - _rEmbeddedObjectDescriptor[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutplaceFrameProperties")); - _rEmbeddedObjectDescriptor[nLen++].Value <<= aOutFrameProps; + _out_rEmbeddedObjectDescriptor[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutplaceFrameProperties")); + _out_rEmbeddedObjectDescriptor[nLen++].Value <<= aOutFrameProps; + + Sequence< PropertyValue > aLoadArgs; + aMediaDesc >>= aLoadArgs; + return aLoadArgs; } // ----------------------------------------------------------------------------- -void ODocumentDefinition::loadEmbeddedObject(sal_Int16 _nMarcoExcecMode,const Sequence< sal_Int8 >& _aClassID,const Reference<XConnection>& _xConnection,sal_Bool _bReadOnly) +void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _xConnection, const Sequence< sal_Int8 >& _aClassID, + const Sequence< PropertyValue >& _rAdditionalArgs, const bool _bSuppressMacros, const bool _bReadOnly ) { if ( !m_xEmbeddedObject.is() ) { @@ -1333,15 +1369,16 @@ OSL_ENSURE( aClassID.getLength(),"No Class ID" ); - Sequence<PropertyValue> aArgs,aEmbeddedObjectDescriptor; - fillLoadArgs(aArgs,aEmbeddedObjectDescriptor,_xConnection,_bReadOnly,_nMarcoExcecMode); + Sequence< PropertyValue > aEmbeddedObjectDescriptor; + Sequence< PropertyValue > aLoadArgs( fillLoadArgs( + _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID ,sDocumentService ,xStorage ,m_pImpl->m_aProps.sPersistentName ,nEntryConnectionMode - ,aArgs + ,aLoadArgs ,aEmbeddedObjectDescriptor ),UNO_QUERY); if ( m_xEmbeddedObject.is() ) @@ -1376,12 +1413,14 @@ Reference<XEmbeddedClient> xClient = m_pClientHelper; m_xEmbeddedObject->setClientSite(xClient); - Sequence<PropertyValue> aArgs,aEmbeddedObjectDescriptor; - fillLoadArgs(aArgs,aEmbeddedObjectDescriptor,_xConnection,_bReadOnly,_nMarcoExcecMode); + Sequence< PropertyValue > aEmbeddedObjectDescriptor; + Sequence< PropertyValue > aLoadArgs( fillLoadArgs( + _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); + Reference<XCommonEmbedPersist> xCommon(m_xEmbeddedObject,UNO_QUERY); OSL_ENSURE(xCommon.is(),"unsupported interface!"); if ( xCommon.is() ) - xCommon->reload(aArgs,aEmbeddedObjectDescriptor); + xCommon->reload( aLoadArgs, aEmbeddedObjectDescriptor ); m_xEmbeddedObject->changeState(EmbedStates::RUNNING); } @@ -1400,32 +1439,25 @@ } catch( const Exception& ) { - OSL_ENSURE( sal_False, "ODocumentDefinition::loadEmbeddedObject: caught an exception while setting the parent of the embedded object!" ); + DBG_UNHANDLED_EXCEPTION(); } } if ( xModel.is() ) { Sequence<PropertyValue> aArgs = xModel->getArgs(); - ::comphelper::MediaDescriptor aHelper(aArgs); - aHelper[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ReadOnly" ) )] <<= _bReadOnly; - if ( m_pImpl->m_aProps.aTitle.getLength() ) - aHelper[ - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentTitle" ) )] <<= m_pImpl->m_aProps.aTitle; - - aHelper[ - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MacroExecutionMode" ))] <<= _nMarcoExcecMode; + ::comphelper::NamedValueCollection aMediaDesc( aArgs ); + lcl_putLoadArgs( aMediaDesc, _bSuppressMacros, _bReadOnly, m_pImpl->m_aProps.aTitle ); - aHelper >> aArgs; - - xModel->attachResource(xModel->getURL(),aArgs); + aMediaDesc >>= aArgs; + xModel->attachResource( xModel->getURL(), aArgs ); } } // ----------------------------------------------------------------------------- void ODocumentDefinition::generateNewImage(Any& _rImage) { - loadEmbeddedObject( MacroExecMode::NEVER_EXECUTE,Sequence< sal_Int8 >(), Reference< XConnection >(), sal_True ); + loadEmbeddedObjectForPreview(); if ( m_xEmbeddedObject.is() ) { try @@ -1454,7 +1486,7 @@ // ----------------------------------------------------------------------------- void ODocumentDefinition::fillDocumentInfo(Any& _rInfo) { - loadEmbeddedObject( MacroExecMode::NEVER_EXECUTE,Sequence< sal_Int8 >(), Reference< XConnection >(), sal_True ); + loadEmbeddedObjectForPreview(); if ( m_xEmbeddedObject.is() ) { try --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
