Tag: cws_src680_dba24c User: fs Date: 2007-10-22 08:27:01+0000 Modified: dba/dbaccess/source/core/dataaccess/documentdefinition.cxx dba/dbaccess/source/core/dataaccess/documentdefinition.hxx
Log: #i52527#/#i73705#: respect the DB doc's MacroExecutionMode when loading sub documents. Allow open arguments to to downgrade this MacroExecutionMode, but not to upgrade it 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.3&r2=1.46.20.4 Delta lines: +153 -109 ----------------------- --- documentdefinition.cxx 2007-10-09 21:12:18+0000 1.46.20.3 +++ documentdefinition.cxx 2007-10-22 08:26:59+0000 1.46.20.4 @@ -4,9 +4,9 @@ * * $RCSfile: documentdefinition.cxx,v $ * - * $Revision: 1.46.20.3 $ + * $Revision: 1.46.20.4 $ * - * last change: $Author: fs $ $Date: 2007/10/09 21:12:18 $ + * last change: $Author: fs $ $Date: 2007/10/22 08:26:59 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -668,7 +668,7 @@ } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_onActivateEmbeddedObject( bool _bOpenedInDesignMode ) +void ODocumentDefinition::impl_onActivateEmbeddedObject() { try { @@ -698,7 +698,7 @@ LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) ); // init the edit view - if ( _bOpenedInDesignMode ) + if ( m_bOpenInDesign ) impl_initObjectEditView( xController ); } catch( const RuntimeException& ) @@ -840,28 +840,31 @@ } // ----------------------------------------------------------------------------- -Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException) +void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate, + const Reference< XCommandEnvironment >& _rxEnvironment, Any& _out_rComponent ) { - Any aRet; - ::osl::MutexGuard aGuard(m_aMutex); - if ( !m_bInExecute ) - { OExecuteImpl aExecuteGuard(m_bInExecute); - sal_Bool bOpenInDesign = aCommand.Name.equalsAscii("openDesign"); - sal_Bool bOpenForMail = aCommand.Name.equalsAscii("openForMail"); - if ( aCommand.Name.compareToAscii( "open" ) == 0 || bOpenInDesign || bOpenForMail ) - { - ////////////////////////////////////////////////////////////////// - // open command for a folder content - ////////////////////////////////////////////////////////////////// - Reference< XConnection> xConnection; + + Reference< XConnection > xConnection; sal_Int32 nOpenMode = OpenMode::DOCUMENT; - Sequence< PropertyValue > aLoadArgs; - if ( !lcl_extractOpenMode( aCommand.Argument, nOpenMode ) ) + // our own macro execution mode + // Note that we don't pass an interaction handler here. If the user has not been asked/notified + // by now (i.e. during loading the whole DB document), then this won't happen anymore. + bool bExecuteOwnMacros = m_pImpl->m_pDataSource->m_aMacroMode.adjustMacroMode( NULL ); + sal_Int16 nDocumentMacroMode = MacroExecMode::ALWAYS_EXECUTE_NO_WARN; + + ::comphelper::NamedValueCollection aDocumentArgs; + + // for the document, default to the interaction handler as used for loading the DB doc + // This might be overwritten below, when examining _rOpenArgument. + ::comphelper::NamedValueCollection aDBDocArgs( m_pImpl->m_pDataSource->m_aArgs ); + aDocumentArgs.put( "InteractionHandler", aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); + + if ( !lcl_extractOpenMode( _rOpenArgument, nOpenMode ) ) { Sequence< PropertyValue > aArguments; - if ( aCommand.Argument >>= aArguments ) + if ( _rOpenArgument >>= aArguments ) { const PropertyValue* pIter = aArguments.getConstArray(); const PropertyValue* pEnd = pIter + aArguments.getLength(); @@ -876,14 +879,34 @@ if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) ) continue; + if ( pIter->Name.equalsAscii( "MacroExecutionMode" ) ) + { + OSL_VERIFY( pIter->Value >>= nDocumentMacroMode ); + continue; + } + // unknown argument -> pass to the loaded document - sal_Int32 nLoadArgs = aLoadArgs.getLength(); - aLoadArgs.realloc( nLoadArgs + 1 ); - aLoadArgs[ nLoadArgs ] = *pIter; + aDocumentArgs.put( pIter->Name, pIter->Value ); } } } + // allow the command arguments to downgrade the macro execution mode, but not to upgrade + // it + if ( !bExecuteOwnMacros ) + { + // no macros per DB doc -> no macros in the embedded doc + nDocumentMacroMode = MacroExecMode::NEVER_EXECUTE; + } + else + { + // DB doc allows macros -> allow macros in the embedded doc, unless explicitly prohibited + if ( nDocumentMacroMode != MacroExecMode::NEVER_EXECUTE ) + nDocumentMacroMode = MacroExecMode::ALWAYS_EXECUTE_NO_WARN; + } + aDocumentArgs.put( "MacroExecutionMode", nDocumentMacroMode ); + + if ( xConnection.is() ) m_xLastKnownConnection = xConnection; @@ -894,13 +917,13 @@ || ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_WRITE ) ) { - // opening as folder is not supported + // not supported ucbhelper::cancelCommandExecution( makeAny( UnsupportedOpenModeException( rtl::OUString(), static_cast< cppu::OWeakObject * >( this ), sal_Int16( nOpenMode ) ) ), - Environment ); + _rxEnvironment ); // Unreachable DBG_ERROR( "unreachable" ); } @@ -908,15 +931,14 @@ Reference<XModel> xModel; if ( m_pImpl->m_aProps.sPersistentName.getLength() ) { - m_bOpenInDesign = bOpenInDesign; - loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aLoadArgs, false, !bOpenInDesign ); + Sequence< PropertyValue > aLoadArgs; + aDocumentArgs >>= aLoadArgs; + loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aLoadArgs, false, !m_bOpenInDesign ); if ( m_xEmbeddedObject.is() ) { xModel.set(getComponent(),UNO_QUERY); - Reference< report::XReportDefinition> xReportDefinition(xModel,UNO_QUERY); + Reference< report::XReportDefinition > xReportDefinition(xModel,UNO_QUERY); - if ( !bOpenForMail && !(!bOpenInDesign && xReportDefinition.is()) ) - { Reference< XModule> xModule(xModel,UNO_QUERY); if ( xModule.is() ) { @@ -925,10 +947,9 @@ else if ( !xReportDefinition.is() ) xModule->setIdentifier(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.TextReportDesign"))); } - m_xEmbeddedObject->changeState(EmbedStates::ACTIVE); - impl_onActivateEmbeddedObject( bOpenInDesign ); - } - else if ( !bOpenInDesign && xReportDefinition.is() ) + + bool bIsAliveNewStyleReport = ( !m_bOpenInDesign && xReportDefinition.is() ); + if ( bIsAliveNewStyleReport ) { // we are in ReadOnly mode // we would like to open the Writer or Calc with the report direct, without design it. @@ -936,15 +957,37 @@ xReportEngine->setReportDefinition(xReportDefinition); xReportEngine->setActiveConnection(m_xLastKnownConnection); - aRet <<= xReportEngine->createDocumentAlive(NULL); - return aRet; + _out_rComponent <<= xReportEngine->createDocumentAlive(NULL); + return; } - fillReportData(!bOpenInDesign); - aRet <<= xModel; + if ( _bActivate ) + { + m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); + impl_onActivateEmbeddedObject(); } + + fillReportData(); + _out_rComponent <<= xModel; } } +} + +// ----------------------------------------------------------------------------- +Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException) +{ + Any aRet; + ::osl::MutexGuard aGuard(m_aMutex); + if ( !m_bInExecute ) + { + sal_Bool bOpen = aCommand.Name.equalsAscii( "open" ); + sal_Bool bOpenInDesign = aCommand.Name.equalsAscii( "openDesign" ); + sal_Bool bOpenForMail = aCommand.Name.equalsAscii( "openForMail" ); + if ( bOpen || bOpenInDesign || bOpenForMail ) + { + m_bOpenInDesign = bOpenInDesign; + onCommandOpenSomething( aCommand.Argument, !bOpenForMail, Environment, aRet ); + } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "copyTo" ) ) ) { Sequence<Any> aIni; @@ -976,7 +1019,7 @@ } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) ) { - generateNewImage(aRet); + onCommandPreview(aRet); } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) ) { @@ -995,11 +1038,11 @@ } ::rtl::OUString sURL; aIni[0] >>= sURL; - insert(sURL,Environment); + onCommandInsert( sURL, Environment ); } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getdocumentinfo" ) ) ) { - fillDocumentInfo(aRet); + onCommandGetDocumentInfo( aRet ); } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) ) { @@ -1071,7 +1114,7 @@ } } // ----------------------------------------------------------------------------- -void ODocumentDefinition::insert(const ::rtl::OUString& _sURL, const Reference< XCommandEnvironment >& Environment) +void ODocumentDefinition::onCommandInsert( const ::rtl::OUString& _sURL, const Reference< XCommandEnvironment >& Environment ) throw( Exception ) { osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); @@ -1079,7 +1122,7 @@ // Check, if all required properties were set. if ( !_sURL.getLength() || m_xEmbeddedObject.is() ) { - OSL_ENSURE( sal_False, "Content::insert - property value missing!" ); + OSL_ENSURE( sal_False, "Content::onCommandInsert - property value missing!" ); Sequence< rtl::OUString > aProps( 1 ); aProps[ 0 ] = PROPERTY_URL; @@ -1455,7 +1498,7 @@ } } // ----------------------------------------------------------------------------- -void ODocumentDefinition::generateNewImage(Any& _rImage) +void ODocumentDefinition::onCommandPreview(Any& _rImage) { loadEmbeddedObjectForPreview(); if ( m_xEmbeddedObject.is() ) @@ -1484,19 +1527,20 @@ _rDefault.clear(); } // ----------------------------------------------------------------------------- -void ODocumentDefinition::fillDocumentInfo(Any& _rInfo) +void ODocumentDefinition::onCommandGetDocumentInfo( Any& _rInfo ) { loadEmbeddedObjectForPreview(); if ( m_xEmbeddedObject.is() ) { try { - Reference<XDocumentInfoSupplier> xDocSup(getComponent(),UNO_QUERY); + Reference<XDocumentInfoSupplier> xDocSup( getComponent(), UNO_QUERY ); if ( xDocSup.is() ) _rInfo <<= xDocSup->getDocumentInfo(); } - catch( Exception e ) + catch( const Exception& ) { + DBG_UNHANDLED_EXCEPTION(); } } } @@ -1623,9 +1667,9 @@ return true; } // ----------------------------------------------------------------------------- -void ODocumentDefinition::fillReportData(sal_Bool _bFill) +void ODocumentDefinition::fillReportData() { - if ( !m_bForm && _bFill && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) // open a report in alive mode, so we need to fill it + if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate ) // open a report in alive mode, so we need to fill it { Sequence<Any> aArgs(2); PropertyValue aValue; File [changed]: documentdefinition.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/documentdefinition.hxx?r1=1.23.4.1&r2=1.23.4.2 Delta lines: +70 -61 --------------------- --- documentdefinition.hxx 2007-10-09 21:12:23+0000 1.23.4.1 +++ documentdefinition.hxx 2007-10-22 08:26:59+0000 1.23.4.2 @@ -4,9 +4,9 @@ * * $RCSfile: documentdefinition.hxx,v $ * - * $Revision: 1.23.4.1 $ + * $Revision: 1.23.4.2 $ * - * last change: $Author: fs $ $Date: 2007/10/09 21:12:23 $ + * last change: $Author: fs $ $Date: 2007/10/22 08:26:59 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -105,63 +105,6 @@ sal_Bool m_bInExecute; OEmbeddedClientHelper* m_pClientHelper; -private: - // Command "insert" - void insert( const ::rtl::OUString& _sURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw( ::com::sun::star::uno::Exception ); - - /** fills the load arguments - */ - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > - fillLoadArgs( - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, - const bool _bSuppressMacros, - const bool _bReadOnly, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor - ); - - /** loads the EmbeddedObject if not already loaded - @param _aClassID - If set, it will be used to create the embedded object. - */ - void loadEmbeddedObject( - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, - const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, - const bool _bSuppressMacros, - const bool _bReadOnly - ); - - void loadEmbeddedObject() - { - loadEmbeddedObject( - NULL, - ::com::sun::star::uno::Sequence< sal_Int8 >(), - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), - false, - false - ); - } - - void loadEmbeddedObjectForPreview() - { - loadEmbeddedObject( - NULL, - ::com::sun::star::uno::Sequence< sal_Int8 >(), - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), - true, - true - ); - } - - void generateNewImage(::com::sun::star::uno::Any& _rImage); - void fillDocumentInfo(::com::sun::star::uno::Any& _rInfo); - /** searches for read-only flag in the args of the model and sets it to the given value, - if the value was not found, it will be appended. - @param _bReadOnly - If <TRUE/> the document will be switched to readonly mode - */ - void updateDocumentTitle(); protected: virtual ~ODocumentDefinition(); @@ -205,7 +148,7 @@ sal_Bool save(sal_Bool _bApprove); void closeObject(); sal_Bool isModified(); - void fillReportData(sal_Bool _bFill = sal_True); + void fillReportData(); /** prepares closing the document component @@ -223,7 +166,7 @@ @param _bOpenedInDesignMode determines whether the embedded object has been opened for designing it or for data display */ - void impl_onActivateEmbeddedObject( bool _bOpenedInDesignMode ); + void impl_onActivateEmbeddedObject(); /** initializes a newly created view/controller which is displaying our embedded object @@ -255,8 +198,74 @@ virtual void SAL_CALL disposing(); private: + /** fills the load arguments + */ + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + fillLoadArgs( + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, + const bool _bSuppressMacros, + const bool _bReadOnly, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor + ); + + /** loads the EmbeddedObject if not already loaded + @param _aClassID + If set, it will be used to create the embedded object. + */ + void loadEmbeddedObject( + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, + const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, + const bool _bSuppressMacros, + const bool _bReadOnly + ); + + /** loads the embedded object, if not already loaded. No new object can be created with this method. + */ + void loadEmbeddedObject() + { + loadEmbeddedObject( + NULL, + ::com::sun::star::uno::Sequence< sal_Int8 >(), + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), + false, + false + ); + } + + /** loads the embedded object for preview. Macros will be suppressed, and the document will + be read-only. + */ + void loadEmbeddedObjectForPreview() + { + loadEmbeddedObject( + NULL, + ::com::sun::star::uno::Sequence< sal_Int8 >(), + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), + true, + true + ); + } + + /** searches for read-only flag in the args of the model and sets it to the given value, + if the value was not found, it will be appended. + @param _bReadOnly + If <TRUE/> the document will be switched to readonly mode + */ + void updateDocumentTitle(); + void registerProperties(); + //------------------------------------------------------------------------- + //- commands + //------------------------------------------------------------------------- + + void onCommandGetDocumentInfo( ::com::sun::star::uno::Any& _rInfo ); + void onCommandInsert( const ::rtl::OUString& _sURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw( ::com::sun::star::uno::Exception ); + void onCommandPreview( ::com::sun::star::uno::Any& _rImage ); + void onCommandOpenSomething( const ::com::sun::star::uno::Any& _rArgument, const bool _bActivate, + const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment, ::com::sun::star::uno::Any& _out_rComponent ); }; //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
