summaryrefslogtreecommitdiff
path: root/embeddedobj/source/commonembedding
diff options
context:
space:
mode:
Diffstat (limited to 'embeddedobj/source/commonembedding')
-rw-r--r--embeddedobj/source/commonembedding/embedobj.cxx701
-rw-r--r--embeddedobj/source/commonembedding/inplaceobj.cxx89
-rw-r--r--embeddedobj/source/commonembedding/makefile.mk56
-rw-r--r--embeddedobj/source/commonembedding/miscobj.cxx700
-rw-r--r--embeddedobj/source/commonembedding/persistence.cxx1918
-rw-r--r--embeddedobj/source/commonembedding/register.cxx133
-rw-r--r--embeddedobj/source/commonembedding/specialobject.cxx245
-rw-r--r--embeddedobj/source/commonembedding/visobj.cxx236
-rw-r--r--embeddedobj/source/commonembedding/xfactory.cxx579
-rw-r--r--embeddedobj/source/commonembedding/xfactory.hxx125
10 files changed, 4782 insertions, 0 deletions
diff --git a/embeddedobj/source/commonembedding/embedobj.cxx b/embeddedobj/source/commonembedding/embedobj.cxx
new file mode 100644
index 000000000000..3d360245f1ea
--- /dev/null
+++ b/embeddedobj/source/commonembedding/embedobj.cxx
@@ -0,0 +1,701 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#include <com/sun/star/embed/XEmbeddedClient.hpp>
+#include <com/sun/star/embed/XInplaceClient.hpp>
+#include <com/sun/star/embed/XWindowSupplier.hpp>
+#include <com/sun/star/embed/StateChangeInProgressException.hpp>
+#include <com/sun/star/embed/Aspects.hpp>
+
+#include <com/sun/star/awt/XWindowPeer.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+
+#include <com/sun/star/embed/EmbedMisc.hpp>
+
+#include <rtl/logfile.hxx>
+
+#include <targetstatecontrol.hxx>
+
+#include "commonembobj.hxx"
+#include "intercept.hxx"
+
+
+using namespace ::com::sun::star;
+
+awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 )
+{
+ awt::Rectangle aResult;
+
+ OSL_ENSURE( aRect1.Width >= 0 && aRect2.Width >= 0 && aRect1.Height >= 0 && aRect2.Height >= 0,
+ "Offset must not be less then zero!" );
+
+ aResult.X = aRect1.X > aRect2.X ? aRect1.X : aRect2.X;
+ aResult.Y = aRect1.Y > aRect2.Y ? aRect1.Y : aRect2.Y;
+
+ sal_Int32 nRight1 = aRect1.X + aRect1.Width;
+ sal_Int32 nBottom1 = aRect1.Y + aRect1.Height;
+ sal_Int32 nRight2 = aRect2.X + aRect2.Width;
+ sal_Int32 nBottom2 = aRect2.Y + aRect2.Height;
+ aResult.Width = ( nRight1 < nRight2 ? nRight1 : nRight2 ) - aResult.X;
+ aResult.Height = ( nBottom1 < nBottom2 ? nBottom1 : nBottom2 ) - aResult.Y;
+
+ return aResult;
+}
+
+//----------------------------------------------
+sal_Int32 OCommonEmbeddedObject::ConvertVerbToState_Impl( sal_Int32 nVerb )
+{
+ for ( sal_Int32 nInd = 0; nInd < m_aVerbTable.getLength(); nInd++ )
+ if ( m_aVerbTable[nInd][0] == nVerb )
+ return m_aVerbTable[nInd][1];
+
+ throw lang::IllegalArgumentException(); // TODO: unexpected verb provided
+}
+
+//----------------------------------------------
+void OCommonEmbeddedObject::Deactivate()
+{
+ uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ //MBA if ( !xModif.is() )
+ //MBA throw uno::RuntimeException();
+
+ // no need to lock for the initialization
+ uno::Reference< embed::XEmbeddedClient > xClientSite = m_xClientSite;
+ if ( !xClientSite.is() )
+ throw embed::WrongStateException(); //TODO: client site is not set!
+
+ // store document if it is modified
+ if ( xModif.is() && xModif->isModified() )
+ {
+ try {
+ xClientSite->saveObject();
+ }
+ catch( embed::ObjectSaveVetoException& )
+ {
+ }
+ catch( uno::Exception& e )
+ {
+ throw embed::StorageWrappedTargetException(
+ ::rtl::OUString::createFromAscii( "The client could not store the object!" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
+ uno::makeAny( e ) );
+ }
+ }
+
+ m_pDocHolder->CloseFrame();
+
+ xClientSite->visibilityChanged( sal_False );
+}
+
+//----------------------------------------------
+void OCommonEmbeddedObject::StateChangeNotification_Impl( sal_Bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState ,::osl::ResettableMutexGuard& rGuard )
+{
+ if ( m_pInterfaceContainer )
+ {
+ ::cppu::OInterfaceContainerHelper* pContainer = m_pInterfaceContainer->getContainer(
+ ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) );
+ if ( pContainer != NULL )
+ {
+ lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+
+ // should be locked after the method is finished successfully
+ rGuard.clear();
+
+ while (pIterator.hasMoreElements())
+ {
+ try
+ {
+ if ( bBeforeChange )
+ ((embed::XStateChangeListener*)pIterator.next())->changingState( aSource, nOldState, nNewState );
+ else
+ ((embed::XStateChangeListener*)pIterator.next())->stateChanged( aSource, nOldState, nNewState );
+ }
+ catch( uno::Exception& )
+ {
+ // even if the listener complains ignore it for now
+ }
+
+ if ( m_bDisposed )
+ return;
+ }
+
+ rGuard.reset();
+ }
+ }
+}
+
+//----------------------------------------------
+void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState )
+{
+ // TODO: may be needs interaction handler to detect wherether the object state
+ // can be changed even after errors
+
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ if ( nNextState == embed::EmbedStates::RUNNING )
+ {
+ // after the object reaches the running state the cloned size is not necessary any more
+ m_bHasClonedSize = sal_False;
+
+ if ( m_bIsLink )
+ {
+ m_pDocHolder->SetComponent( LoadLink_Impl(), m_bReadOnly );
+ }
+ else
+ {
+ uno::Reference < embed::XEmbedPersist > xPersist( static_cast < embed::XClassifiedObject* > (this), uno::UNO_QUERY );
+ if ( xPersist.is() )
+ {
+ // in case embedded object is in loaded state the contents must
+ // be stored in the related storage and the storage
+ // must be created already
+ if ( !m_xObjectStorage.is() )
+ throw io::IOException(); //TODO: access denied
+
+ m_pDocHolder->SetComponent( LoadDocumentFromStorage_Impl(), m_bReadOnly );
+ }
+ else
+ {
+ // objects without persistence will be initialized internally
+ uno::Sequence < uno::Any > aArgs(1);
+ aArgs[0] <<= uno::Reference < embed::XEmbeddedObject >( this );
+ uno::Reference< util::XCloseable > xDocument(
+ m_xFactory->createInstanceWithArguments( GetDocumentServiceName(), aArgs ), uno::UNO_QUERY );
+
+ uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
+ if ( xChild.is() )
+ xChild->setParent( m_xParent );
+
+ m_pDocHolder->SetComponent( xDocument, m_bReadOnly );
+ }
+ }
+
+ if ( !m_pDocHolder->GetComponent().is() )
+ throw embed::UnreachableStateException(); //TODO: can't open document
+
+ m_nObjectState = nNextState;
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
+ throw uno::RuntimeException(); // TODO
+ }
+ }
+ else if ( m_nObjectState == embed::EmbedStates::RUNNING )
+ {
+ if ( nNextState == embed::EmbedStates::LOADED )
+ {
+ m_nClonedMapUnit = m_pDocHolder->GetMapUnit( embed::Aspects::MSOLE_CONTENT );
+ m_bHasClonedSize = m_pDocHolder->GetExtent( embed::Aspects::MSOLE_CONTENT, &m_aClonedSize );
+
+ // actually frame should not exist at this point
+ m_pDocHolder->CloseDocument( sal_False, sal_False );
+
+ m_nObjectState = nNextState;
+ }
+ else
+ {
+ if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
+ {
+ if ( !m_xClientSite.is() )
+ throw embed::WrongStateException(); //TODO: client site is not set!
+
+ uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
+ if ( xInplaceClient.is() && xInplaceClient->canInplaceActivate() )
+ {
+ xInplaceClient->activatingInplace();
+
+ uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY );
+ if ( !xClientWindowSupplier.is() )
+ throw uno::RuntimeException(); // TODO: the inplace client implementation must support XWinSupp
+
+ m_xClientWindow = xClientWindowSupplier->getWindow();
+ m_aOwnRectangle = xInplaceClient->getPlacement();
+ m_aClipRectangle = xInplaceClient->getClipRectangle();
+ awt::Rectangle aRectangleToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle );
+
+ // create own window based on the client window
+ // place and resize the window according to the rectangles
+ uno::Reference< awt::XWindowPeer > xClientWindowPeer( m_xClientWindow, uno::UNO_QUERY );
+ if ( !xClientWindowPeer.is() )
+ throw uno::RuntimeException(); // TODO: the container window must support the interface
+
+ // dispatch provider may not be provided
+ uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
+ sal_Bool bOk = m_pDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, xContainerDP );
+ m_nObjectState = nNextState;
+ if ( !bOk )
+ {
+ SwitchStateTo_Impl( embed::EmbedStates::RUNNING );
+ throw embed::WrongStateException(); //TODO: can't activate inplace
+ }
+ }
+ else
+ throw embed::WrongStateException(); //TODO: can't activate inplace
+ }
+ else if ( nNextState == embed::EmbedStates::ACTIVE )
+ {
+ if ( !m_xClientSite.is() )
+ throw embed::WrongStateException(); //TODO: client site is not set!
+
+ // create frame and load document in the frame
+ m_pDocHolder->Show();
+
+ m_xClientSite->visibilityChanged( sal_True );
+ m_nObjectState = nNextState;
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
+ throw uno::RuntimeException(); // TODO
+ }
+ }
+ }
+ else if ( m_nObjectState == embed::EmbedStates::INPLACE_ACTIVE )
+ {
+ if ( nNextState == embed::EmbedStates::RUNNING )
+ {
+ uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
+ if ( !xInplaceClient.is() )
+ throw uno::RuntimeException();
+
+ m_xClientSite->visibilityChanged( sal_True );
+
+ xInplaceClient->deactivatedInplace();
+ Deactivate();
+ m_nObjectState = nNextState;
+ }
+ else if ( nNextState == embed::EmbedStates::UI_ACTIVE )
+ {
+ if ( !(m_nMiscStatus & embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
+ {
+ uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
+ // TODO:
+ uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
+ xInplaceClient->getLayoutManager();
+ if ( xContainerLM.is() )
+ {
+ // dispatch provider may not be provided
+ uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
+
+ // get the container module name
+ ::rtl::OUString aModuleName;
+ try
+ {
+ uno::Reference< embed::XComponentSupplier > xCompSupl( m_xClientSite, uno::UNO_QUERY_THROW );
+ uno::Reference< uno::XInterface > xContDoc( xCompSupl->getComponent(), uno::UNO_QUERY_THROW );
+
+ uno::Reference< frame::XModuleManager > xManager(
+ m_xFactory->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
+ uno::UNO_QUERY_THROW );
+
+ aModuleName = xManager->identify( xContDoc );
+ }
+ catch( uno::Exception& )
+ {}
+
+ // if currently another object is UIactive it will be deactivated; usually this will activate the LM of
+ // the container. Locking the LM will prevent flicker.
+ xContainerLM->lock();
+ xInplaceClient->activatingUI();
+ sal_Bool bOk = m_pDocHolder->ShowUI( xContainerLM, xContainerDP, aModuleName );
+ xContainerLM->unlock();
+
+ if ( bOk )
+ {
+ m_nObjectState = nNextState;
+ m_pDocHolder->ResizeHatchWindow();
+ }
+ else
+ {
+ xInplaceClient->deactivatedUI();
+ throw embed::WrongStateException(); //TODO: can't activate UI
+ }
+ }
+ else
+ throw embed::WrongStateException(); //TODO: can't activate UI
+ }
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
+ throw uno::RuntimeException(); // TODO
+ }
+ }
+ else if ( m_nObjectState == embed::EmbedStates::ACTIVE )
+ {
+ if ( nNextState == embed::EmbedStates::RUNNING )
+ {
+ Deactivate();
+ m_nObjectState = nNextState;
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
+ throw uno::RuntimeException(); // TODO
+ }
+ }
+ else if ( m_nObjectState == embed::EmbedStates::UI_ACTIVE )
+ {
+ if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
+ {
+ uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
+ uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
+ xInplaceClient->getLayoutManager();
+
+ sal_Bool bOk = sal_False;
+ if ( xContainerLM.is() )
+ bOk = m_pDocHolder->HideUI( xContainerLM );
+
+ if ( bOk )
+ {
+ m_nObjectState = nNextState;
+ m_pDocHolder->ResizeHatchWindow();
+ xInplaceClient->deactivatedUI();
+ }
+ else
+ throw embed::WrongStateException(); //TODO: can't activate UI
+ }
+ }
+ else
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+}
+
+//----------------------------------------------
+uno::Sequence< sal_Int32 > OCommonEmbeddedObject::GetIntermediateStatesSequence_Impl( sal_Int32 nNewState )
+{
+ sal_Int32 nCurInd = 0;
+ for ( nCurInd = 0; nCurInd < m_aAcceptedStates.getLength(); nCurInd++ )
+ if ( m_aAcceptedStates[nCurInd] == m_nObjectState )
+ break;
+
+ if ( nCurInd == m_aAcceptedStates.getLength() )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ sal_Int32 nDestInd = 0;
+ for ( nDestInd = 0; nDestInd < m_aAcceptedStates.getLength(); nDestInd++ )
+ if ( m_aAcceptedStates[nDestInd] == nNewState )
+ break;
+
+ if ( nDestInd == m_aAcceptedStates.getLength() )
+ throw embed::UnreachableStateException(
+ ::rtl::OUString::createFromAscii( "The state either not reachable, or the object allows the state only as an intermediate one!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ m_nObjectState,
+ nNewState );
+
+ return m_pIntermediateStatesSeqs[nCurInd][nDestInd];
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState )
+ throw ( embed::UnreachableStateException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::changeState" );
+
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY);
+ {
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ sal_Int32 nOldState = m_nObjectState;
+
+ if ( m_nTargetState != -1 )
+ {
+ // means that the object is currently trying to reach the target state
+ throw embed::StateChangeInProgressException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ m_nTargetState );
+ }
+ else
+ {
+ TargetStateControl_Impl aControl( m_nTargetState, nNewState );
+
+ // in case the object is already in requested state
+ if ( m_nObjectState == nNewState )
+ {
+ // if active object is activated again, bring it's window to top
+ if ( m_nObjectState == embed::EmbedStates::ACTIVE )
+ m_pDocHolder->Show();
+
+ return;
+ }
+
+ // retrieve sequence of states that should be passed to reach desired state
+ uno::Sequence< sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl( nNewState );
+
+ // notify listeners that the object is going to change the state
+ StateChangeNotification_Impl( sal_True, nOldState, nNewState,aGuard );
+
+ try {
+ for ( sal_Int32 nInd = 0; nInd < aIntermediateStates.getLength(); nInd++ )
+ SwitchStateTo_Impl( aIntermediateStates[nInd] );
+
+ SwitchStateTo_Impl( nNewState );
+ }
+ catch( uno::Exception& )
+ {
+ if ( nOldState != m_nObjectState )
+ // notify listeners that the object has changed the state
+ StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ,aGuard);
+
+ throw;
+ }
+ }
+
+ // notify listeners that the object has changed the state
+ StateChangeNotification_Impl( sal_False, nOldState, nNewState,aGuard );
+ }
+}
+
+//----------------------------------------------
+uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getReachableStates()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_aAcceptedStates;
+}
+
+//----------------------------------------------
+sal_Int32 SAL_CALL OCommonEmbeddedObject::getCurrentState()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_nObjectState;
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::doVerb( sal_Int32 nVerbID )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ embed::UnreachableStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::doVerb" );
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // for internal documents this call is just a duplicate of changeState
+ sal_Int32 nNewState = -1;
+ try
+ {
+ nNewState = ConvertVerbToState_Impl( nVerbID );
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( nNewState == -1 )
+ {
+ // TODO/LATER: Save Copy as... verb ( -8 ) is implemented by container
+ // TODO/LATER: check if the verb is a supported one and if it is produce related operation
+ }
+ else
+ changeState( nNewState );
+}
+
+//----------------------------------------------
+uno::Sequence< embed::VerbDescriptor > SAL_CALL OCommonEmbeddedObject::getSupportedVerbs()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_aObjectVerbs;
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::setClientSite(
+ const uno::Reference< embed::XEmbeddedClient >& xClient )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_xClientSite != xClient)
+ {
+ if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The client site can not be set currently!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ m_xClientSite = xClient;
+ }
+}
+
+//----------------------------------------------
+uno::Reference< embed::XEmbeddedClient > SAL_CALL OCommonEmbeddedObject::getClientSite()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_xClientSite;
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::update()
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::setUpdateMode( sal_Int32 nMode )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
+ || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
+ "Unknown update mode!\n" );
+ m_nUpdateMode = nMode;
+}
+
+//----------------------------------------------
+sal_Int64 SAL_CALL OCommonEmbeddedObject::getStatus( sal_Int64 )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_nMiscStatus;
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::setContainerName( const ::rtl::OUString& sName )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ m_aContainerName = sName;
+}
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL OCommonEmbeddedObject::getParent() throw (::com::sun::star::uno::RuntimeException)
+{
+ return m_xParent;
+}
+
+void SAL_CALL OCommonEmbeddedObject::setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xParent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
+{
+ m_xParent = xParent;
+ if ( m_nObjectState != -1 && m_nObjectState != embed::EmbedStates::LOADED )
+ {
+ uno::Reference < container::XChild > xChild( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xChild.is() )
+ xChild->setParent( xParent );
+ }
+}
+
+// XDefaultSizeTransmitter
+void SAL_CALL OCommonEmbeddedObject::setDefaultSize( const ::com::sun::star::awt::Size& rSize_100TH_MM ) throw (::com::sun::star::uno::RuntimeException)
+{
+ //#i103460# charts do not necessaryly have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
+ m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM;
+}
diff --git a/embeddedobj/source/commonembedding/inplaceobj.cxx b/embeddedobj/source/commonembedding/inplaceobj.cxx
new file mode 100644
index 000000000000..6881571eaeda
--- /dev/null
+++ b/embeddedobj/source/commonembedding/inplaceobj.cxx
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+
+#include "commonembobj.hxx"
+
+
+using namespace ::com::sun::star;
+
+awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 );
+sal_Bool RectanglesEqual( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 )
+{
+ return ( aRect1.X == aRect2.X
+ && aRect1.Y == aRect2.Y
+ && aRect1.Width == aRect2.Width
+ && aRect1.Height == aRect2.Height );
+}
+
+void SAL_CALL OCommonEmbeddedObject::setObjectRectangles( const awt::Rectangle& aPosRect,
+ const awt::Rectangle& aClipRect )
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState != embed::EmbedStates::INPLACE_ACTIVE
+ && m_nObjectState != embed::EmbedStates::UI_ACTIVE )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not activated inplace!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ awt::Rectangle aNewRectToShow = GetRectangleInterception( aPosRect, aClipRect );
+ awt::Rectangle aOldRectToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle );
+
+ // the clip rectangle changes view only in case interception is also changed
+ if ( !RectanglesEqual( m_aOwnRectangle, aPosRect )
+ || ( !RectanglesEqual( m_aClipRectangle, aPosRect ) && !RectanglesEqual( aOldRectToShow, aNewRectToShow ) ) )
+ m_pDocHolder->PlaceFrame( aNewRectToShow );
+
+ m_aOwnRectangle = aPosRect;
+ m_aClipRectangle = aClipRect;
+}
+
+void SAL_CALL OCommonEmbeddedObject::enableModeless( sal_Bool /*bEnable*/ )
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ // TODO: notify model that it can not use modal dialogs
+}
+
+void SAL_CALL OCommonEmbeddedObject::translateAccelerators(
+ const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ // TODO: UI activation related
+}
+
diff --git a/embeddedobj/source/commonembedding/makefile.mk b/embeddedobj/source/commonembedding/makefile.mk
new file mode 100644
index 000000000000..d731b729d919
--- /dev/null
+++ b/embeddedobj/source/commonembedding/makefile.mk
@@ -0,0 +1,56 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..
+
+PRJNAME=embeddedobj
+TARGET=commonembed
+ENABLE_EXCEPTIONS=true
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+LIBTARGET=NO
+USE_DEFFILE=NO
+
+# --- Files --------------------------------------------------------
+
+SLOFILES = \
+ $(SLO)$/register.obj\
+ $(SLO)$/xfactory.obj\
+ $(SLO)$/miscobj.obj\
+ $(SLO)$/embedobj.obj\
+ $(SLO)$/specialobject.obj\
+ $(SLO)$/persistence.obj\
+ $(SLO)$/inplaceobj.obj\
+ $(SLO)$/visobj.obj
+
+# --- Targets -------------------------------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
new file mode 100644
index 000000000000..97cc5d2d499b
--- /dev/null
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -0,0 +1,700 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+
+#include <commonembobj.hxx>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#include <com/sun/star/embed/XInplaceClient.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+
+#include <cppuhelper/typeprovider.hxx>
+#include <cppuhelper/interfacecontainer.h>
+
+#include "closepreventer.hxx"
+#include "intercept.hxx"
+
+using namespace ::com::sun::star;
+
+
+uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr,
+ sal_Bool bCanUseDocumentBaseURL );
+
+//------------------------------------------------------
+OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Sequence< beans::NamedValue >& aObjProps )
+: m_pDocHolder( NULL )
+, m_pInterfaceContainer( NULL )
+, m_bReadOnly( sal_False )
+, m_bDisposed( sal_False )
+, m_bClosed( sal_False )
+, m_nObjectState( -1 )
+, m_nTargetState( -1 )
+, m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE )
+, m_xFactory( xFactory )
+, m_nMiscStatus( 0 )
+, m_bEmbeddedScriptSupport( sal_True )
+, m_bDocumentRecoverySupport( sal_True )
+, m_bWaitSaveCompleted( sal_False )
+, m_bIsLink( sal_False )
+, m_bLinkHasPassword( sal_False )
+, m_bHasClonedSize( sal_False )
+, m_nClonedMapUnit( 0 )
+{
+ CommonInit_Impl( aObjProps );
+}
+
+//------------------------------------------------------
+OCommonEmbeddedObject::OCommonEmbeddedObject(
+ const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Sequence< beans::NamedValue >& aObjProps,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr,
+ const uno::Sequence< beans::PropertyValue >& aObjectDescr )
+: m_pDocHolder( NULL )
+, m_pInterfaceContainer( NULL )
+, m_bReadOnly( sal_False )
+, m_bDisposed( sal_False )
+, m_bClosed( sal_False )
+, m_nObjectState( embed::EmbedStates::LOADED )
+, m_nTargetState( -1 )
+, m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE )
+, m_xFactory( xFactory )
+, m_nMiscStatus( 0 )
+, m_bEmbeddedScriptSupport( sal_True )
+, m_bDocumentRecoverySupport( sal_True )
+, m_bWaitSaveCompleted( sal_False )
+, m_bIsLink( sal_True )
+, m_bLinkHasPassword( sal_False )
+, m_bHasClonedSize( sal_False )
+, m_nClonedMapUnit( 0 )
+{
+ // linked object has no own persistence so it is in loaded state starting from creation
+ LinkInit_Impl( aObjProps, aMediaDescr, aObjectDescr );
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence< beans::NamedValue >& aObjectProps )
+{
+ OSL_ENSURE( m_xFactory.is(), "No ServiceFactory is provided!\n" );
+ if ( !m_xFactory.is() )
+ throw uno::RuntimeException();
+
+ m_pDocHolder = new DocumentHolder( m_xFactory, this );
+ m_pDocHolder->acquire();
+
+ // parse configuration entries
+ // TODO/LATER: in future UI names can be also provided here
+ for ( sal_Int32 nInd = 0; nInd < aObjectProps.getLength(); nInd++ )
+ {
+ if ( aObjectProps[nInd].Name.equalsAscii( "ClassID" ) )
+ aObjectProps[nInd].Value >>= m_aClassID;
+ else if ( aObjectProps[nInd].Name.equalsAscii( "ObjectDocumentServiceName" ) )
+ aObjectProps[nInd].Value >>= m_aDocServiceName;
+ else if ( aObjectProps[nInd].Name.equalsAscii( "ObjectDocumentFilterName" ) )
+ aObjectProps[nInd].Value >>= m_aPresetFilterName;
+ else if ( aObjectProps[nInd].Name.equalsAscii( "ObjectMiscStatus" ) )
+ aObjectProps[nInd].Value >>= m_nMiscStatus;
+ else if ( aObjectProps[nInd].Name.equalsAscii( "ObjectVerbs" ) )
+ aObjectProps[nInd].Value >>= m_aObjectVerbs;
+ }
+
+ if ( m_aClassID.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
+ throw uno::RuntimeException(); // something goes really wrong
+
+ // accepted states
+ m_aAcceptedStates.realloc( NUM_SUPPORTED_STATES );
+
+ m_aAcceptedStates[0] = embed::EmbedStates::LOADED;
+ m_aAcceptedStates[1] = embed::EmbedStates::RUNNING;
+ m_aAcceptedStates[2] = embed::EmbedStates::INPLACE_ACTIVE;
+ m_aAcceptedStates[3] = embed::EmbedStates::UI_ACTIVE;
+ m_aAcceptedStates[4] = embed::EmbedStates::ACTIVE;
+
+
+ // intermediate states
+ // In the following table the first index points to starting state,
+ // the second one to the target state, and the sequence referenced by
+ // first two indexes contains intermediate states, that should be
+ // passed by object to reach the target state.
+ // If the sequence is empty that means that indirect switch from start
+ // state to the target state is forbidden, only if direct switch is possible
+ // the state can be reached.
+
+ m_pIntermediateStatesSeqs[0][2].realloc( 1 );
+ m_pIntermediateStatesSeqs[0][2][0] = embed::EmbedStates::RUNNING;
+
+ m_pIntermediateStatesSeqs[0][3].realloc( 2 );
+ m_pIntermediateStatesSeqs[0][3][0] = embed::EmbedStates::RUNNING;
+ m_pIntermediateStatesSeqs[0][3][1] = embed::EmbedStates::INPLACE_ACTIVE;
+
+ m_pIntermediateStatesSeqs[0][4].realloc( 1 );
+ m_pIntermediateStatesSeqs[0][4][0] = embed::EmbedStates::RUNNING;
+
+ m_pIntermediateStatesSeqs[1][3].realloc( 1 );
+ m_pIntermediateStatesSeqs[1][3][0] = embed::EmbedStates::INPLACE_ACTIVE;
+
+ m_pIntermediateStatesSeqs[2][0].realloc( 1 );
+ m_pIntermediateStatesSeqs[2][0][0] = embed::EmbedStates::RUNNING;
+
+ m_pIntermediateStatesSeqs[3][0].realloc( 2 );
+ m_pIntermediateStatesSeqs[3][0][0] = embed::EmbedStates::INPLACE_ACTIVE;
+ m_pIntermediateStatesSeqs[3][0][1] = embed::EmbedStates::RUNNING;
+
+ m_pIntermediateStatesSeqs[3][1].realloc( 1 );
+ m_pIntermediateStatesSeqs[3][1][0] = embed::EmbedStates::INPLACE_ACTIVE;
+
+ m_pIntermediateStatesSeqs[4][0].realloc( 1 );
+ m_pIntermediateStatesSeqs[4][0][0] = embed::EmbedStates::RUNNING;
+
+ // verbs table
+ sal_Int32 nVerbTableSize = 0;
+ for ( sal_Int32 nVerbInd = 0; nVerbInd < m_aObjectVerbs.getLength(); nVerbInd++ )
+ {
+ if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_PRIMARY )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
+ }
+ else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_SHOW )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
+ }
+ else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_OPEN )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::ACTIVE;
+ }
+ else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::INPLACE_ACTIVE;
+ }
+ else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
+ }
+ else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_HIDE )
+ {
+ m_aVerbTable.realloc( ++nVerbTableSize );
+ m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
+ m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
+ m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::RUNNING;
+ }
+ }
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::LinkInit_Impl(
+ const uno::Sequence< beans::NamedValue >& aObjectProps,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr,
+ const uno::Sequence< beans::PropertyValue >& aObjectDescr )
+{
+ // setPersistance has no effect on own links, so the complete initialization must be done here
+
+ for ( sal_Int32 nInd = 0; nInd < aMediaDescr.getLength(); nInd++ )
+ if ( aMediaDescr[nInd].Name.equalsAscii( "URL" ) )
+ aMediaDescr[nInd].Value >>= m_aLinkURL;
+ else if ( aMediaDescr[nInd].Name.equalsAscii( "FilterName" ) )
+ aMediaDescr[nInd].Value >>= m_aLinkFilterName;
+
+ OSL_ENSURE( m_aLinkURL.getLength() && m_aLinkFilterName.getLength(), "Filter and URL must be provided!\n" );
+
+ m_aDocMediaDescriptor = GetValuableArgs_Impl( aMediaDescr, sal_False );
+
+ uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
+ for ( sal_Int32 nObjInd = 0; nObjInd < aObjectDescr.getLength(); nObjInd++ )
+ if ( aObjectDescr[nObjInd].Name.equalsAscii( "OutplaceDispatchInterceptor" ) )
+ {
+ aObjectDescr[nObjInd].Value >>= xDispatchInterceptor;
+ break;
+ }
+ else if ( aObjectDescr[nObjInd].Name.equalsAscii( "Parent" ) )
+ {
+ aObjectDescr[nObjInd].Value >>= m_xParent;
+ }
+
+ CommonInit_Impl( aObjectProps );
+
+ if ( xDispatchInterceptor.is() )
+ m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
+}
+
+//------------------------------------------------------
+OCommonEmbeddedObject::~OCommonEmbeddedObject()
+{
+ if ( m_pInterfaceContainer || m_pDocHolder )
+ {
+ m_refCount++;
+ try {
+ lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
+
+ if ( m_pInterfaceContainer )
+ {
+ m_pInterfaceContainer->disposeAndClear( aSource );
+
+ delete m_pInterfaceContainer;
+ m_pInterfaceContainer = NULL;
+ }
+ } catch( uno::Exception& ) {}
+
+ try {
+ if ( m_pDocHolder )
+ {
+ m_pDocHolder->CloseFrame();
+ try {
+ m_pDocHolder->CloseDocument( sal_True, sal_True );
+ } catch ( uno::Exception& ) {}
+ m_pDocHolder->FreeOffice();
+
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+ }
+ } catch( uno::Exception& ) {}
+ }
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle& aRect )
+{
+ // the method is called in case object is inplace active and the object window was resized
+
+ OSL_ENSURE( m_xClientSite.is(), "The client site must be set for inplace active object!\n" );
+ if ( m_xClientSite.is() )
+ {
+ uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
+
+ OSL_ENSURE( xInplaceClient.is(), "The client site must support XInplaceClient to allow inplace activation!\n" );
+ if ( xInplaceClient.is() )
+ {
+ try {
+ xInplaceClient->changedPlacement( aRect );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Exception on request to resize!\n" );
+ }
+ }
+ }
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString& aEventName,
+ const uno::Reference< uno::XInterface >& /*xSource*/ )
+{
+ if ( m_pInterfaceContainer )
+ {
+ ::cppu::OInterfaceContainerHelper* pIC = m_pInterfaceContainer->getContainer(
+ ::getCppuType((const uno::Reference< document::XEventListener >*)0) );
+ if( pIC )
+ {
+ document::EventObject aEvent;
+ aEvent.EventName = aEventName;
+ aEvent.Source = uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) );
+ // For now all the events are sent as object events
+ // aEvent.Source = ( xSource.is() ? xSource
+ // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
+ ::cppu::OInterfaceIteratorHelper aIt( *pIC );
+ while( aIt.hasMoreElements() )
+ {
+ try
+ {
+ ((document::XEventListener *)aIt.next())->notifyEvent( aEvent );
+ }
+ catch( uno::RuntimeException& )
+ {
+ aIt.remove();
+ }
+
+ // the listener could dispose the object.
+ if ( m_bDisposed )
+ return;
+ }
+ }
+ }
+}
+
+//------------------------------------------------------
+uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType )
+ throw( uno::RuntimeException )
+{
+ uno::Any aReturn;
+
+ if ( rType == ::getCppuType( (uno::Reference< embed::XEmbeddedObject > const *)0 ))
+ {
+ void * p = static_cast< embed::XEmbeddedObject * >( this );
+ return uno::Any( &p, rType );
+ }
+ else
+ aReturn <<= ::cppu::queryInterface(
+ rType,
+ static_cast< embed::XInplaceObject* >( this ),
+ static_cast< embed::XVisualObject* >( this ),
+ static_cast< embed::XCommonEmbedPersist* >( static_cast< embed::XEmbedPersist* >( this ) ),
+ static_cast< embed::XEmbedPersist* >( this ),
+ static_cast< embed::XLinkageSupport* >( this ),
+ static_cast< embed::XStateChangeBroadcaster* >( this ),
+ static_cast< embed::XClassifiedObject* >( this ),
+ static_cast< embed::XComponentSupplier* >( this ),
+ static_cast< util::XCloseable* >( this ),
+ static_cast< container::XChild* >( this ),
+ static_cast< chart2::XDefaultSizeTransmitter* >( this ),
+ static_cast< document::XEventBroadcaster* >( this ) );
+
+ if ( aReturn.hasValue() )
+ return aReturn;
+ else
+ return ::cppu::OWeakObject::queryInterface( rType ) ;
+
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::acquire()
+ throw()
+{
+ ::cppu::OWeakObject::acquire() ;
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::release()
+ throw()
+{
+ ::cppu::OWeakObject::release() ;
+}
+
+//------------------------------------------------------
+uno::Sequence< uno::Type > SAL_CALL OCommonEmbeddedObject::getTypes()
+ throw( uno::RuntimeException )
+{
+ static ::cppu::OTypeCollection* pTypeCollection = NULL;
+
+ if ( !pTypeCollection )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if ( !pTypeCollection )
+ {
+ if ( m_bIsLink )
+ {
+ static ::cppu::OTypeCollection aTypeCollection(
+ ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
+ ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XLinkageSupport >*)NULL ) );
+
+ pTypeCollection = &aTypeCollection ;
+ }
+ else
+ {
+ static ::cppu::OTypeCollection aTypeCollection(
+ ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
+ ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ) );
+
+ pTypeCollection = &aTypeCollection ;
+ }
+ }
+ }
+
+ return pTypeCollection->getTypes() ;
+
+}
+
+//------------------------------------------------------
+uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getImplementationId()
+ throw( uno::RuntimeException )
+{
+ static ::cppu::OImplementationId* pID = NULL ;
+
+ if ( !pID )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ if ( !pID )
+ {
+ static ::cppu::OImplementationId aID( sal_False ) ;
+ pID = &aID ;
+ }
+ }
+
+ return pID->getImplementationId() ;
+}
+
+//------------------------------------------------------
+uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getClassID()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_aClassID;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OCommonEmbeddedObject::getClassName()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_aClassName;
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::setClassInfo(
+ const uno::Sequence< sal_Int8 >& /*aClassID*/, const ::rtl::OUString& /*aClassName*/ )
+ throw ( lang::NoSupportException,
+ uno::RuntimeException )
+{
+ // the object class info can not be changed explicitly
+ throw lang::NoSupportException(); //TODO:
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > SAL_CALL OCommonEmbeddedObject::getComponent()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ // add an exception
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ // if ( m_bWaitSaveCompleted )
+ // throw embed::WrongStateException(
+ // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return uno::Reference< util::XCloseable >( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pInterfaceContainer )
+ m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
+
+ m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
+ xListener );
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::removeStateChangeListener(
+ const uno::Reference< embed::XStateChangeListener >& xListener )
+ throw (uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pInterfaceContainer )
+ m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
+ xListener );
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership )
+ throw ( util::CloseVetoException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bClosed )
+ throw lang::DisposedException(); // TODO
+
+ uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
+ lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
+
+ if ( m_pInterfaceContainer )
+ {
+ ::cppu::OInterfaceContainerHelper* pContainer =
+ m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
+ if ( pContainer != NULL )
+ {
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while (pIterator.hasMoreElements())
+ {
+ try
+ {
+ ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pIterator.remove();
+ }
+ }
+ }
+
+ pContainer = m_pInterfaceContainer->getContainer(
+ ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
+ if ( pContainer != NULL )
+ {
+ ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
+ while (pCloseIterator.hasMoreElements())
+ {
+ try
+ {
+ ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pCloseIterator.remove();
+ }
+ }
+ }
+
+ m_pInterfaceContainer->disposeAndClear( aSource );
+ }
+
+ m_bDisposed = sal_True; // the object is disposed now for outside
+
+ // it is possible that the document can not be closed, in this case if the argument is false
+ // the exception will be thrown otherwise in addition to exception the object must register itself
+ // as termination listener and listen for document events
+
+ if ( m_pDocHolder )
+ {
+ m_pDocHolder->CloseFrame();
+
+ try {
+ m_pDocHolder->CloseDocument( bDeliverOwnership, bDeliverOwnership );
+ }
+ catch( uno::Exception& )
+ {
+ if ( bDeliverOwnership )
+ {
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+ m_bClosed = sal_True;
+ }
+
+ throw;
+ }
+
+ m_pDocHolder->FreeOffice();
+
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+ }
+
+ // TODO: for now the storage will be disposed by the object, but after the document
+ // will use the storage, the storage will be disposed by the document and recreated by the object
+ if ( m_xObjectStorage.is() )
+ {
+ uno::Reference< lang::XComponent > xComp( m_xObjectStorage, uno::UNO_QUERY );
+ OSL_ENSURE( xComp.is(), "Storage does not support XComponent!\n" );
+
+ if ( xComp.is() )
+ {
+ try {
+ xComp->dispose();
+ } catch ( uno::Exception& ) {}
+ }
+
+ m_xObjectStorage.clear();
+ m_xRecoveryStorage.clear();
+ }
+
+ m_bClosed = sal_True; // the closing succeeded
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pInterfaceContainer )
+ m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
+
+ m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener );
+}
+
+//----------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
+ throw (uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pInterfaceContainer )
+ m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ),
+ xListener );
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pInterfaceContainer )
+ m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
+
+ m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener );
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pInterfaceContainer )
+ m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ),
+ xListener );
+}
+
diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx
new file mode 100644
index 000000000000..0312d28315a6
--- /dev/null
+++ b/embeddedobj/source/commonembedding/persistence.cxx
@@ -0,0 +1,1918 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+
+#include <commonembobj.hxx>
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/embed/EntryInitModes.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/XOptimizedStorage.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/frame/XLoadable.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XModule.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+
+#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCEESS_HPP_
+#include <com/sun/star/container/XNameAccess.hpp>
+#endif
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/IllegalTypeException.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+
+#include <comphelper/fileformat.h>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/mimeconfighelper.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+
+#include <rtl/logfile.hxx>
+
+#include <tools/diagnose_ex.h>
+
+#define USE_STORAGEBASED_DOCUMENT
+
+using namespace ::com::sun::star;
+
+
+//------------------------------------------------------
+uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr,
+ sal_Bool bCanUseDocumentBaseURL )
+{
+ uno::Sequence< beans::PropertyValue > aResult;
+ sal_Int32 nResLen = 0;
+
+ for ( sal_Int32 nInd = 0; nInd < aMedDescr.getLength(); nInd++ )
+ {
+ if ( aMedDescr[nInd].Name.equalsAscii( "ComponentData" )
+ || aMedDescr[nInd].Name.equalsAscii( "DocumentTitle" )
+ || aMedDescr[nInd].Name.equalsAscii( "InteractionHandler" )
+ || aMedDescr[nInd].Name.equalsAscii( "JumpMark" )
+ // || aMedDescr[nInd].Name.equalsAscii( "Password" ) makes no sence for embedded objects
+ || aMedDescr[nInd].Name.equalsAscii( "Preview" )
+ || aMedDescr[nInd].Name.equalsAscii( "ReadOnly" )
+ || aMedDescr[nInd].Name.equalsAscii( "StartPresentation" )
+ || aMedDescr[nInd].Name.equalsAscii( "RepairPackage" )
+ || aMedDescr[nInd].Name.equalsAscii( "StatusIndicator" )
+ || aMedDescr[nInd].Name.equalsAscii( "ViewData" )
+ || aMedDescr[nInd].Name.equalsAscii( "ViewId" )
+ || aMedDescr[nInd].Name.equalsAscii( "MacroExecutionMode" )
+ || aMedDescr[nInd].Name.equalsAscii( "UpdateDocMode" )
+ || (aMedDescr[nInd].Name.equalsAscii( "DocumentBaseURL" ) && bCanUseDocumentBaseURL) )
+ {
+ aResult.realloc( ++nResLen );
+ aResult[nResLen-1] = aMedDescr[nInd];
+ }
+ }
+
+ return aResult;
+}
+
+//------------------------------------------------------
+uno::Sequence< beans::PropertyValue > addAsTemplate( const uno::Sequence< beans::PropertyValue >& aOrig )
+{
+ sal_Bool bAsTemplateSet = sal_False;
+ sal_Int32 nLength = aOrig.getLength();
+ uno::Sequence< beans::PropertyValue > aResult( nLength );
+
+ for ( sal_Int32 nInd = 0; nInd < nLength; nInd++ )
+ {
+ aResult[nInd].Name = aOrig[nInd].Name;
+ if ( aResult[nInd].Name.equalsAscii( "AsTemplate" ) )
+ {
+ aResult[nInd].Value <<= sal_True;
+ bAsTemplateSet = sal_True;
+ }
+ else
+ aResult[nInd].Value = aOrig[nInd].Value;
+ }
+
+ if ( !bAsTemplateSet )
+ {
+ aResult.realloc( nLength + 1 );
+ aResult[nLength].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
+ aResult[nLength].Value <<= sal_True;
+ }
+
+ return aResult;
+}
+
+//------------------------------------------------------
+uno::Reference< io::XInputStream > createTempInpStreamFromStor(
+ const uno::Reference< embed::XStorage >& xStorage,
+ const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+{
+ OSL_ENSURE( xStorage.is(), "The storage can not be empty!" );
+
+ uno::Reference< io::XInputStream > xResult;
+
+ const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
+ uno::Reference < io::XStream > xTempStream = uno::Reference < io::XStream > (
+ xFactory->createInstance ( aServiceName ),
+ uno::UNO_QUERY );
+ if ( xTempStream.is() )
+ {
+ uno::Reference < lang::XSingleServiceFactory > xStorageFactory(
+ xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ),
+ uno::UNO_QUERY );
+
+ uno::Sequence< uno::Any > aArgs( 2 );
+ aArgs[0] <<= xTempStream;
+ aArgs[1] <<= embed::ElementModes::READWRITE;
+ uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ),
+ uno::UNO_QUERY );
+ if ( !xTempStorage.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ try
+ {
+ xStorage->copyToStorage( xTempStorage );
+ } catch( uno::Exception& e )
+ {
+ throw embed::StorageWrappedTargetException(
+ ::rtl::OUString::createFromAscii( "Can't copy storage!" ),
+ uno::Reference< uno::XInterface >(),
+ uno::makeAny( e ) );
+ }
+
+ try {
+ uno::Reference< lang::XComponent > xComponent( xTempStorage, uno::UNO_QUERY );
+ OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" );
+ if ( xComponent.is() )
+ xComponent->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ try {
+ uno::Reference< io::XOutputStream > xTempOut = xTempStream->getOutputStream();
+ if ( xTempOut.is() )
+ xTempOut->closeOutput();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ xResult = xTempStream->getInputStream();
+ }
+
+ return xResult;
+
+}
+
+//------------------------------------------------------
+static void TransferMediaType( const uno::Reference< embed::XStorage >& i_rSource, const uno::Reference< embed::XStorage >& i_rTarget )
+{
+ try
+ {
+ const uno::Reference< beans::XPropertySet > xSourceProps( i_rSource, uno::UNO_QUERY_THROW );
+ const uno::Reference< beans::XPropertySet > xTargetProps( i_rTarget, uno::UNO_QUERY_THROW );
+ const ::rtl::OUString sMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
+ xTargetProps->setPropertyValue( sMediaTypePropName, xSourceProps->getPropertyValue( sMediaTypePropName ) );
+ }
+ catch( const uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+//------------------------------------------------------
+static uno::Reference< util::XCloseable > CreateDocument( const uno::Reference< lang::XMultiServiceFactory >& _rxFactory,
+ const ::rtl::OUString& _rDocumentServiceName, bool _bEmbeddedScriptSupport, const bool i_bDocumentRecoverySupport )
+{
+ ::comphelper::NamedValueCollection aArguments;
+ aArguments.put( "EmbeddedObject", (sal_Bool)sal_True );
+ aArguments.put( "EmbeddedScriptSupport", (sal_Bool)_bEmbeddedScriptSupport );
+ aArguments.put( "DocumentRecoverySupport", (sal_Bool)i_bDocumentRecoverySupport );
+
+ uno::Reference< uno::XInterface > xDocument;
+ try
+ {
+ xDocument = _rxFactory->createInstanceWithArguments( _rDocumentServiceName, aArguments.getWrappedPropertyValues() );
+ }
+ catch( const uno::Exception& )
+ {
+ // some of our embedded object implementations (in particular chart) do neither support
+ // the EmbeddedObject, nor the EmbeddedScriptSupport argument. Also, they do not support
+ // XInitialization, which means the default factory from cppuhelper will throw an
+ // IllegalArgumentException when we try to create the instance with arguments.
+ // Okay, so we fall back to creating the instance without any arguments.
+ xDocument = _rxFactory->createInstance( _rDocumentServiceName );
+ }
+
+ return uno::Reference< util::XCloseable >( xDocument, uno::UNO_QUERY );
+}
+
+//------------------------------------------------------
+static void SetDocToEmbedded( const uno::Reference< frame::XModel > xDocument, const ::rtl::OUString& aModuleName )
+{
+ if ( xDocument.is() )
+ {
+ uno::Sequence< beans::PropertyValue > aSeq( 1 );
+ aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" );
+ aSeq[0].Value <<= sal_True;
+ xDocument->attachResource( ::rtl::OUString(), aSeq );
+
+ if ( aModuleName.getLength() )
+ {
+ try
+ {
+ uno::Reference< frame::XModule > xModule( xDocument, uno::UNO_QUERY_THROW );
+ xModule->setIdentifier( aModuleName );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
+ const uno::Reference< embed::XStorage >& xNewObjectStorage,
+ const ::rtl::OUString& aNewName )
+{
+ if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
+ {
+ OSL_ENSURE( xNewObjectStorage == m_xObjectStorage, "The storage must be the same!\n" );
+ return;
+ }
+
+ uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY );
+ OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" );
+
+ m_xObjectStorage = xNewObjectStorage;
+ m_xParentStorage = xNewParentStorage;
+ m_aEntryName = aNewName;
+
+#ifdef USE_STORAGEBASED_DOCUMENT
+ // the linked document should not be switched
+ if ( !m_bIsLink )
+ {
+ uno::Reference< document::XStorageBasedDocument > xDoc( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xDoc.is() )
+ SwitchDocToStorage_Impl( xDoc, m_xObjectStorage );
+ }
+#endif
+
+ try {
+ if ( xComponent.is() )
+ xComponent->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
+ const ::rtl::OUString& aNewName )
+{
+ if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
+ return;
+
+ sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
+
+ uno::Reference< embed::XStorage > xNewOwnStorage = xNewParentStorage->openStorageElement( aNewName, nStorageMode );
+ OSL_ENSURE( xNewOwnStorage.is(), "The method can not return empty reference!" );
+
+ SwitchOwnPersistence( xNewParentStorage, xNewOwnStorage, aNewName );
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::EmbedAndReparentDoc_Impl( const uno::Reference< util::XCloseable >& i_rxDocument ) const
+{
+ SetDocToEmbedded( uno::Reference< frame::XModel >( i_rxDocument, uno::UNO_QUERY ), m_aModuleName );
+
+ try
+ {
+ uno::Reference < container::XChild > xChild( i_rxDocument, uno::UNO_QUERY );
+ if ( xChild.is() )
+ xChild->setParent( m_xParent );
+ }
+ catch( const lang::NoSupportException & )
+ {
+ OSL_ENSURE( false, "OCommonEmbeddedObject::EmbedAndReparentDoc: cannot set parent at document!" );
+ }
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > OCommonEmbeddedObject::InitNewDocument_Impl()
+{
+ uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(),
+ m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) );
+
+ uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY );
+ uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY );
+ if ( !xLoadable.is() )
+ throw uno::RuntimeException();
+
+ try
+ {
+ // set the document mode to embedded as the first action on document!!!
+ EmbedAndReparentDoc_Impl( xDocument );
+
+ // if we have a storage to recover the document from, do not use initNew, but instead load from that storage
+ bool bInitNew = true;
+ if ( m_xRecoveryStorage.is() )
+ {
+ uno::Reference< document::XStorageBasedDocument > xDoc( xLoadable, uno::UNO_QUERY );
+ OSL_ENSURE( xDoc.is(), "OCommonEmbeddedObject::InitNewDocument_Impl: cannot recover from a storage when the document is not storage based!" );
+ if ( xDoc.is() )
+ {
+ ::comphelper::NamedValueCollection aLoadArgs;
+ FillDefaultLoadArgs_Impl( m_xRecoveryStorage, aLoadArgs );
+
+ xDoc->loadFromStorage( m_xRecoveryStorage, aLoadArgs.getPropertyValues() );
+ SwitchDocToStorage_Impl( xDoc, m_xObjectStorage );
+ bInitNew = false;
+ }
+ }
+
+ if ( bInitNew )
+ {
+ // init document as a new
+ xLoadable->initNew();
+ }
+ xModel->attachResource( xModel->getURL(), m_aDocMediaDescriptor );
+ }
+ catch( uno::Exception& )
+ {
+ uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ {
+ try
+ {
+ xCloseable->close( sal_True );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ throw; // TODO
+ }
+
+ return xDocument;
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadLink_Impl()
+{
+ uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(),
+ m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) );
+
+ uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
+ if ( !xLoadable.is() )
+ throw uno::RuntimeException();
+
+ sal_Int32 nLen = 2;
+ uno::Sequence< beans::PropertyValue > aArgs( nLen );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "URL" );
+ aArgs[0].Value <<= m_aLinkURL;
+ aArgs[1].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[1].Value <<= m_aLinkFilterName;
+ if ( m_bLinkHasPassword )
+ {
+ aArgs.realloc( ++nLen );
+ aArgs[nLen-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) );
+ aArgs[nLen-1].Value <<= m_aLinkPassword;
+ }
+
+ aArgs.realloc( m_aDocMediaDescriptor.getLength() + nLen );
+ for ( sal_Int32 nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ )
+ {
+ aArgs[nInd+nLen].Name = m_aDocMediaDescriptor[nInd].Name;
+ aArgs[nInd+nLen].Value = m_aDocMediaDescriptor[nInd].Value;
+ }
+
+ try
+ {
+ // the document is not really an embedded one, it is a link
+ EmbedAndReparentDoc_Impl( xDocument );
+
+ // load the document
+ xLoadable->load( aArgs );
+
+ if ( !m_bLinkHasPassword )
+ {
+ // check if there is a password to cache
+ uno::Reference< frame::XModel > xModel( xLoadable, uno::UNO_QUERY_THROW );
+ uno::Sequence< beans::PropertyValue > aProps = xModel->getArgs();
+ for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ )
+ if ( aProps[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) )
+ && ( aProps[nInd].Value >>= m_aLinkPassword ) )
+ {
+ m_bLinkHasPassword = sal_True;
+ break;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ {
+ try
+ {
+ xCloseable->close( sal_True );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ throw; // TODO
+ }
+
+ return xDocument;
+
+}
+
+//------------------------------------------------------
+::rtl::OUString OCommonEmbeddedObject::GetFilterName( sal_Int32 nVersion ) const
+{
+ ::rtl::OUString aFilterName = GetPresetFilterName();
+ if ( !aFilterName.getLength() )
+ {
+ try {
+ ::comphelper::MimeConfigurationHelper aHelper( m_xFactory );
+ aFilterName = aHelper.GetDefaultFilterFromServiceName( GetDocumentServiceName(), nVersion );
+ } catch( uno::Exception& )
+ {}
+ }
+
+ return aFilterName;
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::FillDefaultLoadArgs_Impl( const uno::Reference< embed::XStorage >& i_rxStorage,
+ ::comphelper::NamedValueCollection& o_rLoadArgs ) const
+{
+ o_rLoadArgs.put( "DocumentBaseURL", GetBaseURL_Impl() );
+ o_rLoadArgs.put( "HierarchicalDocumentName", m_aEntryName );
+ o_rLoadArgs.put( "ReadOnly", m_bReadOnly );
+
+ ::rtl::OUString aFilterName = GetFilterName( ::comphelper::OStorageHelper::GetXStorageFormat( i_rxStorage ) );
+ OSL_ENSURE( aFilterName.getLength(), "OCommonEmbeddedObject::FillDefaultLoadArgs_Impl: Wrong document service name!" );
+ if ( !aFilterName.getLength() )
+ throw io::IOException(); // TODO: error message/code
+
+ o_rLoadArgs.put( "FilterName", aFilterName );
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadDocumentFromStorage_Impl()
+{
+ ENSURE_OR_THROW( m_xObjectStorage.is(), "no object storage" );
+
+ const uno::Reference< embed::XStorage > xSourceStorage( m_xRecoveryStorage.is() ? m_xRecoveryStorage : m_xObjectStorage );
+
+ uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(),
+ m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) );
+
+ //#i103460# ODF: take the size given from the parent frame as default
+ uno::Reference< chart2::XChartDocument > xChart( xDocument, uno::UNO_QUERY );
+ if( xChart.is() )
+ {
+ uno::Reference< embed::XVisualObject > xChartVisualObject( xChart, uno::UNO_QUERY );
+ if( xChartVisualObject.is() )
+ xChartVisualObject->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, m_aDefaultSizeForChart_In_100TH_MM );
+ }
+
+ uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
+ uno::Reference< document::XStorageBasedDocument > xDoc
+#ifdef USE_STORAGEBASED_DOCUMENT
+ ( xDocument, uno::UNO_QUERY )
+#endif
+ ;
+ if ( !xDoc.is() && !xLoadable.is() ) ///BUG: This should be || instead of && ?
+ throw uno::RuntimeException();
+
+ ::comphelper::NamedValueCollection aLoadArgs;
+ FillDefaultLoadArgs_Impl( xSourceStorage, aLoadArgs );
+
+ uno::Reference< io::XInputStream > xTempInpStream;
+ if ( !xDoc.is() )
+ {
+ xTempInpStream = createTempInpStreamFromStor( xSourceStorage, m_xFactory );
+ if ( !xTempInpStream.is() )
+ throw uno::RuntimeException();
+
+ ::rtl::OUString aTempFileURL;
+ try
+ {
+ // no need to let the file stay after the stream is removed since the embedded document
+ // can not be stored directly
+ uno::Reference< beans::XPropertySet > xTempStreamProps( xTempInpStream, uno::UNO_QUERY_THROW );
+ xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" );
+
+ aLoadArgs.put( "URL", aTempFileURL );
+ aLoadArgs.put( "InputStream", xTempInpStream );
+ }
+
+ // aLoadArgs.put( "AsTemplate", sal_True );
+
+ aLoadArgs.merge( m_aDocMediaDescriptor, true );
+
+ try
+ {
+ // set the document mode to embedded as the first step!!!
+ EmbedAndReparentDoc_Impl( xDocument );
+
+ if ( xDoc.is() )
+ {
+ xDoc->loadFromStorage( xSourceStorage, aLoadArgs.getPropertyValues() );
+ if ( xSourceStorage != m_xObjectStorage )
+ SwitchDocToStorage_Impl( xDoc, m_xObjectStorage );
+ }
+ else
+ xLoadable->load( aLoadArgs.getPropertyValues() );
+ }
+ catch( uno::Exception& )
+ {
+ uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ {
+ try
+ {
+ xCloseable->close( sal_True );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ throw; // TODO
+ }
+
+ return xDocument;
+}
+
+//------------------------------------------------------
+uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStream_Impl(
+ sal_Int32 nStorageFormat,
+ const ::rtl::OUString& aBaseURL,
+ const ::rtl::OUString& aHierarchName )
+{
+ uno::Reference < io::XOutputStream > xTempOut(
+ m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
+ uno::UNO_QUERY );
+ uno::Reference< io::XInputStream > aResult( xTempOut, uno::UNO_QUERY );
+
+ if ( !xTempOut.is() || !aResult.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ uno::Reference< frame::XStorable > xStorable;
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pDocHolder )
+ xStorable = uno::Reference< frame::XStorable > ( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ }
+
+ if( !xStorable.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ ::rtl::OUString aFilterName = GetFilterName( nStorageFormat );
+
+ OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" );
+ if ( !aFilterName.getLength() )
+ throw io::IOException(); // TODO:
+
+ uno::Sequence< beans::PropertyValue > aArgs( 4 );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[0].Value <<= aFilterName;
+ aArgs[1].Name = ::rtl::OUString::createFromAscii( "OutputStream" );
+ aArgs[1].Value <<= xTempOut;
+ aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" );
+ aArgs[2].Value <<= aBaseURL;
+ aArgs[3].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" );
+ aArgs[3].Value <<= aHierarchName;
+
+ xStorable->storeToURL( ::rtl::OUString::createFromAscii( "private:stream" ), aArgs );
+ try
+ {
+ xTempOut->closeOutput();
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Looks like stream was closed already" );
+ }
+
+ return aResult;
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::SaveObject_Impl()
+{
+ if ( m_xClientSite.is() )
+ {
+ try
+ {
+ // check whether the component is modified,
+ // if not there is no need for storing
+ uno::Reference< util::XModifiable > xModifiable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xModifiable.is() && !xModifiable->isModified() )
+ return;
+ }
+ catch( uno::Exception& )
+ {}
+
+ try {
+ m_xClientSite->saveObject();
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "The object was not stored!\n" );
+ }
+ }
+}
+
+//------------------------------------------------------
+::rtl::OUString OCommonEmbeddedObject::GetBaseURL_Impl() const
+{
+ ::rtl::OUString aBaseURL;
+ sal_Int32 nInd = 0;
+
+ if ( m_xClientSite.is() )
+ {
+ try
+ {
+ uno::Reference< frame::XModel > xParentModel( m_xClientSite->getComponent(), uno::UNO_QUERY_THROW );
+ uno::Sequence< beans::PropertyValue > aModelProps = xParentModel->getArgs();
+ for ( nInd = 0; nInd < aModelProps.getLength(); nInd++ )
+ if ( aModelProps[nInd].Name.equals(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
+ {
+ aModelProps[nInd].Value >>= aBaseURL;
+ break;
+ }
+
+
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( !aBaseURL.getLength() )
+ {
+ for ( nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ )
+ if ( m_aDocMediaDescriptor[nInd].Name.equals(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
+ {
+ m_aDocMediaDescriptor[nInd].Value >>= aBaseURL;
+ break;
+ }
+ }
+
+ if ( !aBaseURL.getLength() )
+ aBaseURL = m_aDefaultParentBaseURL;
+
+ return aBaseURL;
+}
+
+//------------------------------------------------------
+::rtl::OUString OCommonEmbeddedObject::GetBaseURLFrom_Impl(
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+{
+ ::rtl::OUString aBaseURL;
+ sal_Int32 nInd = 0;
+
+ for ( nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ if ( lArguments[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
+ {
+ lArguments[nInd].Value >>= aBaseURL;
+ break;
+ }
+
+ if ( !aBaseURL.getLength() )
+ {
+ for ( nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
+ if ( lObjArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultParentBaseURL" ) ) ) )
+ {
+ lObjArgs[nInd].Value >>= aBaseURL;
+ break;
+ }
+ }
+
+ return aBaseURL;
+}
+
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::SwitchDocToStorage_Impl( const uno::Reference< document::XStorageBasedDocument >& xDoc, const uno::Reference< embed::XStorage >& xStorage )
+{
+ xDoc->switchToStorage( xStorage );
+
+ uno::Reference< util::XModifiable > xModif( xDoc, uno::UNO_QUERY );
+ if ( xModif.is() )
+ xModif->setModified( sal_False );
+
+ if ( m_xRecoveryStorage.is() )
+ m_xRecoveryStorage.clear();
+}
+
+//------------------------------------------------------
+void OCommonEmbeddedObject::StoreDocToStorage_Impl( const uno::Reference< embed::XStorage >& xStorage,
+ sal_Int32 nStorageFormat,
+ const ::rtl::OUString& aBaseURL,
+ const ::rtl::OUString& aHierarchName,
+ sal_Bool bAttachToTheStorage )
+{
+ OSL_ENSURE( xStorage.is(), "No storage is provided for storing!" );
+
+ if ( !xStorage.is() )
+ throw uno::RuntimeException(); // TODO:
+
+#ifdef USE_STORAGEBASED_DOCUMENT
+ uno::Reference< document::XStorageBasedDocument > xDoc;
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pDocHolder )
+ xDoc = uno::Reference< document::XStorageBasedDocument >( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ }
+
+ if ( xDoc.is() )
+ {
+ ::rtl::OUString aFilterName = GetFilterName( nStorageFormat );
+
+ OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" );
+ if ( !aFilterName.getLength() )
+ throw io::IOException(); // TODO:
+
+ uno::Sequence< beans::PropertyValue > aArgs( 3 );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[0].Value <<= aFilterName;
+ aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" );
+ aArgs[2].Value <<= aBaseURL;
+ aArgs[1].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" );
+ aArgs[1].Value <<= aHierarchName;
+
+ xDoc->storeToStorage( xStorage, aArgs );
+ if ( bAttachToTheStorage )
+ SwitchDocToStorage_Impl( xDoc, xStorage );
+ }
+ else
+#endif
+ {
+ // store document to temporary stream based on temporary file
+ uno::Reference < io::XInputStream > xTempIn = StoreDocumentToTempStream_Impl( nStorageFormat, aBaseURL, aHierarchName );
+
+ OSL_ENSURE( xTempIn.is(), "The stream reference can not be empty!\n" );
+
+ // open storage based on document temporary file for reading
+ uno::Reference < lang::XSingleServiceFactory > xStorageFactory(
+ m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ),
+ uno::UNO_QUERY );
+
+ uno::Sequence< uno::Any > aArgs(1);
+ aArgs[0] <<= xTempIn;
+ uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ),
+ uno::UNO_QUERY );
+ if ( !xTempStorage.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ // object storage must be commited automatically
+ xTempStorage->copyToStorage( xStorage );
+ }
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateDocFromMediaDescr_Impl(
+ const uno::Sequence< beans::PropertyValue >& aMedDescr )
+{
+ uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(),
+ m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) );
+
+ uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
+ if ( !xLoadable.is() )
+ throw uno::RuntimeException();
+
+ try
+ {
+ // set the document mode to embedded as the first action on the document!!!
+ EmbedAndReparentDoc_Impl( xDocument );
+
+ xLoadable->load( addAsTemplate( aMedDescr ) );
+ }
+ catch( uno::Exception& )
+ {
+ uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ {
+ try
+ {
+ xCloseable->close( sal_True );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ throw; // TODO
+ }
+
+ return xDocument;
+}
+
+//------------------------------------------------------
+uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateTempDocFromLink_Impl()
+{
+ uno::Reference< util::XCloseable > xResult;
+
+ OSL_ENSURE( m_bIsLink, "The object is not a linked one!\n" );
+
+ uno::Sequence< beans::PropertyValue > aTempMediaDescr;
+
+ sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ try {
+ nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
+ }
+
+ if ( m_pDocHolder->GetComponent().is() )
+ {
+ aTempMediaDescr.realloc( 4 );
+
+ // TODO/LATER: may be private:stream should be used as target URL
+ ::rtl::OUString aTempFileURL;
+ uno::Reference< io::XInputStream > xTempStream = StoreDocumentToTempStream_Impl( SOFFICE_FILEFORMAT_CURRENT,
+ ::rtl::OUString(),
+ ::rtl::OUString() );
+ try
+ {
+ // no need to let the file stay after the stream is removed since the embedded document
+ // can not be stored directly
+ uno::Reference< beans::XPropertySet > xTempStreamProps( xTempStream, uno::UNO_QUERY_THROW );
+ xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" );
+
+ aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" );
+ aTempMediaDescr[0].Value <<= aTempFileURL;
+ aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "InputStream" );
+ aTempMediaDescr[1].Value <<= xTempStream;
+ aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aTempMediaDescr[2].Value <<= GetFilterName( nStorageFormat );
+ aTempMediaDescr[3].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
+ aTempMediaDescr[3].Value <<= sal_True;
+ }
+ else
+ {
+ aTempMediaDescr.realloc( 2 );
+ aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" );
+ aTempMediaDescr[0].Value <<= m_aLinkURL;
+ aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aTempMediaDescr[1].Value <<= m_aLinkFilterName;
+ // aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
+ // aTempMediaDescr[2].Value <<= sal_True;
+ }
+
+ xResult = CreateDocFromMediaDescr_Impl( aTempMediaDescr );
+
+ return xResult;
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ sal_Int32 nEntryConnectionMode,
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setPersistentEntry" );
+
+ // the type of the object must be already set
+ // a kind of typedetection should be done in the factory
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ // May be LOADED should be forbidden here ???
+ if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
+ && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
+ {
+ // if the object is not loaded
+ // it can not get persistant representation without initialization
+
+ // if the object is loaded
+ // it can switch persistant representation only without initialization
+
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "Can't change persistant representation of activated object!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ {
+ if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
+ saveCompleted( ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) );
+ else
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ // for now support of this interface is required to allow breaking of links and converting them to normal embedded
+ // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
+ // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
+ if ( m_bIsLink )
+ {
+ m_aEntryName = sEntName;
+ return;
+ }
+
+ uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
+ if ( !xNameAccess.is() )
+ throw uno::RuntimeException(); //TODO
+
+ // detect entry existence
+ sal_Bool bElExists = xNameAccess->hasByName( sEntName );
+
+ m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments,
+ nEntryConnectionMode != embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT );
+
+ m_bReadOnly = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) )
+ lArguments[nInd].Value >>= m_bReadOnly;
+
+ // TODO: use lObjArgs for StoreVisualReplacement
+ for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ )
+ if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceDispatchInterceptor" ) )
+ {
+ uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
+ if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor )
+ m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "DefaultParentBaseURL" ) )
+ {
+ lObjArgs[nObjInd].Value >>= m_aDefaultParentBaseURL;
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "Parent" ) )
+ {
+ lObjArgs[nObjInd].Value >>= m_xParent;
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "IndividualMiscStatus" ) )
+ {
+ sal_Int64 nMiscStatus=0;
+ lObjArgs[nObjInd].Value >>= nMiscStatus;
+ m_nMiscStatus |= nMiscStatus;
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "CloneFrom" ) )
+ {
+ uno::Reference < embed::XEmbeddedObject > xObj;
+ lObjArgs[nObjInd].Value >>= xObj;
+ if ( xObj.is() )
+ {
+ m_bHasClonedSize = sal_True;
+ m_aClonedSize = xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
+ m_nClonedMapUnit = xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT );
+ }
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceFrameProperties" ) )
+ {
+ uno::Sequence< uno::Any > aOutFrameProps;
+ uno::Sequence< beans::NamedValue > aOutFramePropsTyped;
+ if ( lObjArgs[nObjInd].Value >>= aOutFrameProps )
+ {
+ m_pDocHolder->SetOutplaceFrameProperties( aOutFrameProps );
+ }
+ else if ( lObjArgs[nObjInd].Value >>= aOutFramePropsTyped )
+ {
+ aOutFrameProps.realloc( aOutFramePropsTyped.getLength() );
+ uno::Any* pProp = aOutFrameProps.getArray();
+ for ( const beans::NamedValue* pTypedProp = aOutFramePropsTyped.getConstArray();
+ pTypedProp != aOutFramePropsTyped.getConstArray() + aOutFramePropsTyped.getLength();
+ ++pTypedProp, ++pProp
+ )
+ {
+ *pProp <<= *pTypedProp;
+ }
+ m_pDocHolder->SetOutplaceFrameProperties( aOutFrameProps );
+ }
+ else
+ OSL_ENSURE( false, "OCommonEmbeddedObject::setPersistentEntry: illegal type for argument 'OutplaceFrameProperties'!" );
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "ModuleName" ) )
+ {
+ lObjArgs[nObjInd].Value >>= m_aModuleName;
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "EmbeddedScriptSupport" ) )
+ {
+ OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_bEmbeddedScriptSupport );
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "DocumentRecoverySupport" ) )
+ {
+ OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_bDocumentRecoverySupport );
+ }
+ else if ( lObjArgs[nObjInd].Name.equalsAscii( "RecoveryStorage" ) )
+ {
+ OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_xRecoveryStorage );
+ }
+
+
+ sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
+
+ SwitchOwnPersistence( xStorage, sEntName );
+
+ if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT )
+ {
+ if ( bElExists )
+ {
+ // the initialization from existing storage allows to leave object in loaded state
+ m_nObjectState = embed::EmbedStates::LOADED;
+ }
+ else
+ {
+ m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly );
+ if ( !m_pDocHolder->GetComponent().is() )
+ throw io::IOException(); // TODO: can not create document
+
+ m_nObjectState = embed::EmbedStates::RUNNING;
+ }
+ }
+ else
+ {
+ if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE )
+ throw io::IOException();
+
+ if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
+ {
+ // the document just already changed its storage to store to
+ // the links to OOo documents for now ignore this call
+ // TODO: OOo links will have persistence so it will be switched here
+ }
+ else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT )
+ {
+ if ( m_xRecoveryStorage.is() )
+ TransferMediaType( m_xRecoveryStorage, m_xObjectStorage );
+
+ // TODO:
+ m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly );
+
+ if ( !m_pDocHolder->GetComponent().is() )
+ throw io::IOException(); // TODO: can not create document
+
+ m_nObjectState = embed::EmbedStates::RUNNING;
+ }
+ else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
+ {
+ m_pDocHolder->SetComponent( CreateDocFromMediaDescr_Impl( lArguments ), m_bReadOnly );
+ m_nObjectState = embed::EmbedStates::RUNNING;
+ }
+ //else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT )
+ //{
+ //TODO:
+ //}
+ else
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 3 );
+ }
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeToEntry" );
+
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // for now support of this interface is required to allow breaking of links and converting them to normal embedded
+ // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
+ // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
+ if ( m_bIsLink )
+ return;
+
+ OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
+
+ sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ try {
+ nTargetStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve target storage media type!\n" );
+ }
+
+ try
+ {
+ nOriginalStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve own storage media type!\n" );
+ }
+
+ sal_Bool bTryOptimization = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
+ {
+ // StoreVisualReplacement and VisualReplacement args have no sence here
+ if ( lObjArgs[nInd].Name.equalsAscii( "CanTryOptimization" ) )
+ lObjArgs[nInd].Value >>= bTryOptimization;
+ }
+
+ sal_Bool bSwitchBackToLoaded = sal_False;
+
+ // Storing to different format can be done only in running state.
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ // TODO/LATER: copying is not legal for documents with relative links.
+ if ( nTargetStorageFormat == nOriginalStorageFormat )
+ {
+ sal_Bool bOptimizationWorks = sal_False;
+ if ( bTryOptimization )
+ {
+ try
+ {
+ // try to use optimized copying
+ uno::Reference< embed::XOptimizedStorage > xSource( m_xParentStorage, uno::UNO_QUERY_THROW );
+ uno::Reference< embed::XOptimizedStorage > xTarget( xStorage, uno::UNO_QUERY_THROW );
+ xSource->copyElementDirectlyTo( m_aEntryName, xTarget, sEntName );
+ bOptimizationWorks = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ if ( !bOptimizationWorks )
+ m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
+ }
+ else
+ {
+ changeState( embed::EmbedStates::RUNNING );
+ bSwitchBackToLoaded = sal_True;
+ }
+ }
+
+ if ( m_nObjectState != embed::EmbedStates::LOADED )
+ {
+ uno::Reference< embed::XStorage > xSubStorage =
+ xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
+
+ if ( !xSubStorage.is() )
+ throw uno::RuntimeException(); //TODO
+
+ aGuard.clear();
+ // TODO/LATER: support hierarchical name for embedded objects in embedded objects
+ StoreDocToStorage_Impl( xSubStorage, nTargetStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName, sal_False );
+ aGuard.reset();
+
+ if ( bSwitchBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+ }
+
+ // TODO: should the listener notification be done?
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeAsEntry" );
+
+ // TODO: use lObjArgs
+
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // for now support of this interface is required to allow breaking of links and converting them to normal embedded
+ // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
+ // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
+ if ( m_bIsLink )
+ {
+ m_aNewEntryName = sEntName;
+ return;
+ }
+
+ OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
+
+ sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ try {
+ nTargetStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve target storage media type!\n" );
+ }
+
+ try
+ {
+ nOriginalStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve own storage media type!\n" );
+ }
+
+ PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAs" ) );
+
+ sal_Bool bTryOptimization = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
+ {
+ // StoreVisualReplacement and VisualReplacement args have no sence here
+ if ( lObjArgs[nInd].Name.equalsAscii( "CanTryOptimization" ) )
+ lObjArgs[nInd].Value >>= bTryOptimization;
+ }
+
+ sal_Bool bSwitchBackToLoaded = sal_False;
+
+ // Storing to different format can be done only in running state.
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ // TODO/LATER: copying is not legal for documents with relative links.
+ if ( nTargetStorageFormat == nOriginalStorageFormat )
+ {
+ sal_Bool bOptimizationWorks = sal_False;
+ if ( bTryOptimization )
+ {
+ try
+ {
+ // try to use optimized copying
+ uno::Reference< embed::XOptimizedStorage > xSource( m_xParentStorage, uno::UNO_QUERY_THROW );
+ uno::Reference< embed::XOptimizedStorage > xTarget( xStorage, uno::UNO_QUERY_THROW );
+ xSource->copyElementDirectlyTo( m_aEntryName, xTarget, sEntName );
+ bOptimizationWorks = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ if ( !bOptimizationWorks )
+ m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
+ }
+ else
+ {
+ changeState( embed::EmbedStates::RUNNING );
+ bSwitchBackToLoaded = sal_True;
+ }
+ }
+
+ uno::Reference< embed::XStorage > xSubStorage =
+ xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
+
+ if ( !xSubStorage.is() )
+ throw uno::RuntimeException(); //TODO
+
+ if ( m_nObjectState != embed::EmbedStates::LOADED )
+ {
+ aGuard.clear();
+ // TODO/LATER: support hierarchical name for embedded objects in embedded objects
+ StoreDocToStorage_Impl( xSubStorage, nTargetStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName, sal_False );
+ aGuard.reset();
+
+ if ( bSwitchBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+ }
+
+ m_bWaitSaveCompleted = sal_True;
+ m_xNewObjectStorage = xSubStorage;
+ m_xNewParentStorage = xStorage;
+ m_aNewEntryName = sEntName;
+ m_aNewDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True );
+
+ // TODO: register listeners for storages above, in case thay are disposed
+ // an exception will be thrown on saveCompleted( true )
+
+ // TODO: should the listener notification be done here or in saveCompleted?
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew )
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::saveCompleted" );
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ // for now support of this interface is required to allow breaking of links and converting them to normal embedded
+ // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
+ // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
+ if ( m_bIsLink )
+ {
+ if ( bUseNew )
+ m_aEntryName = m_aNewEntryName;
+ m_aNewEntryName = ::rtl::OUString();
+ return;
+ }
+
+ // it is allowed to call saveCompleted( false ) for nonstored objects
+ if ( !m_bWaitSaveCompleted && !bUseNew )
+ return;
+
+ OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
+ if ( !m_bWaitSaveCompleted )
+ throw io::IOException(); // TODO: illegal call
+
+ OSL_ENSURE( m_xNewObjectStorage.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" );
+ if ( !m_xNewObjectStorage.is() || !m_xNewParentStorage.is() )
+ throw uno::RuntimeException(); // TODO: broken internal information
+
+ if ( bUseNew )
+ {
+ SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStorage, m_aNewEntryName );
+ m_aDocMediaDescriptor = m_aNewDocMediaDescriptor;
+
+ uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xModif.is() )
+ xModif->setModified( sal_False );
+
+ PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAsDone" ) );
+ }
+ else
+ {
+ try {
+ uno::Reference< lang::XComponent > xComponent( m_xNewObjectStorage, uno::UNO_QUERY );
+ OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" );
+ if ( xComponent.is() )
+ xComponent->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+
+ m_xNewObjectStorage = uno::Reference< embed::XStorage >();
+ m_xNewParentStorage = uno::Reference< embed::XStorage >();
+ m_aNewEntryName = ::rtl::OUString();
+ m_aNewDocMediaDescriptor.realloc( 0 );
+ m_bWaitSaveCompleted = sal_False;
+
+ if ( bUseNew )
+ {
+ // TODO: notify listeners
+
+ if ( m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE )
+ {
+ // TODO: update visual representation
+ }
+ }
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OCommonEmbeddedObject::hasEntry()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_xObjectStorage.is() )
+ return sal_True;
+
+ return sal_False;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OCommonEmbeddedObject::getEntryName()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_aEntryName;
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::storeOwn()
+ throw ( embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeOwn" );
+
+ // during switching from Activated to Running and from Running to Loaded states the object will
+ // ask container to store the object, the container has to make decision
+ // to do so or not
+
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_bReadOnly )
+ throw io::IOException(); // TODO: access denied
+
+ // nothing to do, if the object is in loaded state
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ return;
+
+ PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSave" ) );
+
+ OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If an object is activated or in running state it must have a document!\n" );
+ if ( !m_pDocHolder->GetComponent().is() )
+ throw uno::RuntimeException();
+
+ if ( m_bIsLink )
+ {
+ // TODO: just store the document to it's location
+ uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( !xStorable.is() )
+ throw uno::RuntimeException(); // TODO
+
+ // free the main mutex for the storing time
+ aGuard.clear();
+
+ xStorable->store();
+
+ aGuard.reset();
+ }
+ else
+ {
+ OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
+
+ if ( !m_xObjectStorage.is() )
+ throw io::IOException(); //TODO: access denied
+
+ sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
+ try {
+ nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
+ }
+ catch ( beans::IllegalTypeException& )
+ {
+ // the container just has an unknown type, use current file format
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
+ }
+
+ aGuard.clear();
+ StoreDocToStorage_Impl( m_xObjectStorage, nStorageFormat, GetBaseURL_Impl(), m_aEntryName, sal_True );
+ aGuard.reset();
+ }
+
+ uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xModif.is() )
+ xModif->setModified( sal_False );
+
+ PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveDone" ) );
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OCommonEmbeddedObject::isReadonly()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_bReadOnly;
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::reload(
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ // TODO: use lObjArgs
+ // for now this method is used only to switch readonly state
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_nObjectState != embed::EmbedStates::LOADED )
+ {
+ // the object is still not loaded
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object must be in loaded state to be reloaded!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_bIsLink )
+ {
+ // reload of the link
+ ::rtl::OUString aOldLinkFilter = m_aLinkFilterName;
+
+ ::rtl::OUString aNewLinkFilter;
+ for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ {
+ if ( lArguments[nInd].Name.equalsAscii( "URL" ) )
+ {
+ // the new URL
+ lArguments[nInd].Value >>= m_aLinkURL;
+ m_aLinkFilterName = ::rtl::OUString();
+ }
+ else if ( lArguments[nInd].Name.equalsAscii( "FilterName" ) )
+ {
+ lArguments[nInd].Value >>= aNewLinkFilter;
+ m_aLinkFilterName = ::rtl::OUString();
+ }
+ }
+
+ ::comphelper::MimeConfigurationHelper aHelper( m_xFactory );
+ if ( !m_aLinkFilterName.getLength() )
+ {
+ if ( aNewLinkFilter.getLength() )
+ m_aLinkFilterName = aNewLinkFilter;
+ else
+ {
+ uno::Sequence< beans::PropertyValue > aArgs( 1 );
+ aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
+ aArgs[0].Value <<= m_aLinkURL;
+ m_aLinkFilterName = aHelper.UpdateMediaDescriptorWithFilterName( aArgs, sal_False );
+ }
+ }
+
+ if ( !aOldLinkFilter.equals( m_aLinkFilterName ) )
+ {
+ uno::Sequence< beans::NamedValue > aObject = aHelper.GetObjectPropsByFilter( m_aLinkFilterName );
+
+ // TODO/LATER: probably the document holder could be cleaned explicitly as in the destructor
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+
+ LinkInit_Impl( aObject, lArguments, lObjArgs );
+ }
+ }
+
+ m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True );
+
+ // TODO: use lObjArgs for StoreVisualReplacement
+ for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ )
+ if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceDispatchInterceptor" ) )
+ {
+ uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
+ if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor )
+ m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
+
+ break;
+ }
+
+ // TODO:
+ // when document allows reloading through API the object can be reloaded not only in loaded state
+
+ sal_Bool bOldReadOnlyValue = m_bReadOnly;
+
+ m_bReadOnly = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) )
+ lArguments[nInd].Value >>= m_bReadOnly;
+
+ if ( bOldReadOnlyValue != m_bReadOnly && !m_bIsLink )
+ {
+ // close own storage
+ try {
+ uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY );
+ OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" );
+ if ( xComponent.is() )
+ xComponent->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
+ m_xObjectStorage = m_xParentStorage->openStorageElement( m_aEntryName, nStorageMode );
+ }
+}
+
+//------------------------------------------------------
+void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_bIsLink )
+ {
+ // it must be a linked initialized object
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+#if 0
+ else
+ {
+ // the current implementation of OOo links does not implement this method since it does not implement
+ // all the set of interfaces required for OOo embedded object ( XEmbedPersist is not supported ).
+ throw io::IOException(); // TODO:
+ }
+#endif
+
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ if ( !m_bIsLink || m_nObjectState == -1 )
+ {
+ // it must be a linked initialized object
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ if ( m_bWaitSaveCompleted )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
+ if ( !xNameAccess.is() )
+ throw uno::RuntimeException(); //TODO
+
+ // detect entry existence
+ /*sal_Bool bElExists =*/ xNameAccess->hasByName( sEntName );
+
+ m_bReadOnly = sal_False;
+// sal_Int32 nStorageMode = embed::ElementModes::READWRITE;
+
+ if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) )
+ SwitchOwnPersistence( xStorage, sEntName );
+
+ // for linked object it means that it becomes embedded object
+ // the document must switch it's persistence also
+
+ // TODO/LATER: handle the case when temp doc can not be created
+ // the document is a new embedded object so it must be marked as modified
+ uno::Reference< util::XCloseable > xDocument = CreateTempDocFromLink_Impl();
+ uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( !xModif.is() )
+ throw uno::RuntimeException();
+ try
+ {
+ xModif->setModified( sal_True );
+ }
+ catch( uno::Exception& )
+ {}
+
+ m_pDocHolder->SetComponent( xDocument, m_bReadOnly );
+ OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If document cant be created, an exception must be thrown!\n" );
+
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ // the state is changed and can not be switched to loaded state back without saving
+ m_nObjectState = embed::EmbedStates::RUNNING;
+ StateChangeNotification_Impl( sal_False, embed::EmbedStates::LOADED, m_nObjectState, aGuard );
+ }
+ else if ( m_nObjectState == embed::EmbedStates::ACTIVE )
+ m_pDocHolder->Show();
+
+ m_bIsLink = sal_False;
+ m_aLinkFilterName = ::rtl::OUString();
+ m_aLinkURL = ::rtl::OUString();
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OCommonEmbeddedObject::isLink()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ // Actually this information is clear even in case object is wayting for saveCompleted
+ // if ( m_bWaitSaveCompleted )
+ // throw embed::WrongStateException(
+ // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_bIsLink;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OCommonEmbeddedObject::getLinkURL()
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ // Actually this information is clear even in case object is wayting for saveCompleted
+ // if ( m_bWaitSaveCompleted )
+ // throw embed::WrongStateException(
+ // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
+ // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( !m_bIsLink )
+ throw embed::WrongStateException(
+ ::rtl::OUString::createFromAscii( "The object is not a link object!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_aLinkURL;
+}
+
diff --git a/embeddedobj/source/commonembedding/register.cxx b/embeddedobj/source/commonembedding/register.cxx
new file mode 100644
index 000000000000..bd2a64b299f1
--- /dev/null
+++ b/embeddedobj/source/commonembedding/register.cxx
@@ -0,0 +1,133 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+
+
+#include <com/sun/star/registry/XRegistryKey.hpp>
+#include <com/sun/star/registry/InvalidRegistryException.hpp>
+#include <cppuhelper/factory.hxx>
+
+#include "xfactory.hxx"
+#include "xcreator.hxx"
+
+using namespace ::com::sun::star;
+
+
+extern "C" {
+
+void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
+{
+ void * pRet = 0;
+
+ ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
+ uno::Reference< lang::XSingleServiceFactory > xFactory;
+
+ if ( pServiceManager )
+ {
+ if ( aImplName.equals( OOoEmbeddedObjectFactory::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ OOoEmbeddedObjectFactory::impl_staticGetImplementationName(),
+ OOoEmbeddedObjectFactory::impl_staticCreateSelfInstance,
+ OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames() );
+ }
+ else if ( aImplName.equals( OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName(),
+ OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance,
+ OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames() );
+ }
+ else if ( aImplName.equals( UNOEmbeddedObjectCreator::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ UNOEmbeddedObjectCreator::impl_staticGetImplementationName(),
+ UNOEmbeddedObjectCreator::impl_staticCreateSelfInstance,
+ UNOEmbeddedObjectCreator::impl_staticGetSupportedServiceNames() );
+ }
+ }
+
+ if ( xFactory.is() )
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+
+ return pRet;
+}
+
+sal_Bool SAL_CALL component_writeInfo( void * /*pServiceManager*/, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ sal_Int32 nInd = 0;
+ uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) );
+
+ uno::Reference< registry::XRegistryKey > xNewKey;
+
+ xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
+ OOoEmbeddedObjectFactory::impl_staticGetImplementationName() +
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) );
+ uno::Sequence< ::rtl::OUString > rServices = OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames();
+ for( nInd = 0; nInd < rServices.getLength(); nInd++ )
+ xNewKey->createKey( rServices.getConstArray()[nInd] );
+
+ xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
+ OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName() +
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) );
+ rServices = OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames();
+ for( nInd = 0; nInd < rServices.getLength(); nInd++ )
+ xNewKey->createKey( rServices.getConstArray()[nInd] );
+
+ xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
+ UNOEmbeddedObjectCreator::impl_staticGetImplementationName() +
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) );
+ rServices = UNOEmbeddedObjectCreator::impl_staticGetSupportedServiceNames();
+ for( nInd = 0; nInd < rServices.getLength(); nInd++ )
+ xNewKey->createKey( rServices.getConstArray()[nInd] );
+
+ return sal_True;
+ }
+ catch (registry::InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+} // extern "C"
+
diff --git a/embeddedobj/source/commonembedding/specialobject.cxx b/embeddedobj/source/commonembedding/specialobject.cxx
new file mode 100644
index 000000000000..c23afd9e1237
--- /dev/null
+++ b/embeddedobj/source/commonembedding/specialobject.cxx
@@ -0,0 +1,245 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#include <com/sun/star/embed/XEmbeddedClient.hpp>
+#include <com/sun/star/embed/XInplaceClient.hpp>
+#include <com/sun/star/embed/XWindowSupplier.hpp>
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/awt/XWindowPeer.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/embed/EmbedMapUnits.hpp>
+
+#include <cppuhelper/typeprovider.hxx>
+
+#include "specialobject.hxx"
+#include "intercept.hxx"
+
+using namespace ::com::sun::star;
+
+
+OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const uno::Sequence< beans::NamedValue >& aObjectProps )
+: OCommonEmbeddedObject( xFactory, aObjectProps )
+{
+ maSize.Width = maSize.Height = 10000;
+ m_nObjectState = embed::EmbedStates::LOADED;
+}
+
+//------------------------------------------------------
+uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
+ throw( uno::RuntimeException )
+{
+ uno::Any aReturn;
+
+ aReturn <<= ::cppu::queryInterface( rType,
+ static_cast< embed::XEmbeddedObject* >( this ),
+ static_cast< embed::XInplaceObject* >( this ),
+ static_cast< embed::XVisualObject* >( this ),
+ static_cast< embed::XClassifiedObject* >( this ),
+ static_cast< embed::XComponentSupplier* >( this ),
+ static_cast< util::XCloseable* >( this ),
+ static_cast< document::XEventBroadcaster* >( this ) );
+ if ( aReturn.hasValue() )
+ return aReturn;
+ else
+ return ::cppu::OWeakObject::queryInterface( rType ) ;
+
+}
+
+//------------------------------------------------------
+uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
+ throw( uno::RuntimeException )
+{
+ static ::cppu::OTypeCollection* pTypeCollection = NULL;
+
+ if ( !pTypeCollection )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if ( !pTypeCollection )
+ {
+ static ::cppu::OTypeCollection aTypeCollection(
+ ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
+ ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) );
+
+ pTypeCollection = &aTypeCollection ;
+ }
+ }
+
+ return pTypeCollection->getTypes() ;
+
+}
+
+embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ // TODO: if object is in loaded state it should switch itself to the running state
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // TODO: return for the aspect of the document
+ embed::VisualRepresentation aVisualRepresentation;
+ /*
+ OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
+ uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( !xTransferable.is() )
+ throw uno::RuntimeException();
+
+ datatransfer::DataFlavor aDataFlavor(
+ ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
+ ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
+ ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
+
+ aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
+ aVisualRepresentation.Flavor = aDataFlavor;*/
+ return aVisualRepresentation;
+}
+
+void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ maSize = aSize;
+}
+
+awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ awt::Size aResult;
+ return maSize;
+}
+
+sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
+ throw ( uno::Exception,
+ uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return embed::EmbedMapUnits::ONE_100TH_MM;
+}
+
+void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
+ throw ( ::com::sun::star::embed::UnreachableStateException,
+ ::com::sun::star::embed::WrongStateException,
+ ::com::sun::star::uno::Exception,
+ ::com::sun::star::uno::RuntimeException )
+{
+ if ( nNewState == embed::EmbedStates::UI_ACTIVE )
+ nNewState = embed::EmbedStates::INPLACE_ACTIVE;
+ OCommonEmbeddedObject::changeState( nNewState );
+}
+
+void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ embed::UnreachableStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( nVerbID == -7 )
+ {
+
+ uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if ( xDlg.is() )
+ xDlg->execute();
+ else
+ throw embed::UnreachableStateException();
+ }
+ else
+ OCommonEmbeddedObject::doVerb( nVerbID );
+}
+
diff --git a/embeddedobj/source/commonembedding/visobj.cxx b/embeddedobj/source/commonembedding/visobj.cxx
new file mode 100644
index 000000000000..5a6813215517
--- /dev/null
+++ b/embeddedobj/source/commonembedding/visobj.cxx
@@ -0,0 +1,236 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/lang/DisposedException.hpp>
+
+#include <rtl/logfile.hxx>
+
+
+#include <commonembobj.hxx>
+
+
+using namespace ::com::sun::star;
+
+void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ m_bHasClonedSize = sal_False;
+
+ sal_Bool bBackToLoaded = sal_False;
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ changeState( embed::EmbedStates::RUNNING );
+
+ // the links should be switched back to loaded state for now to avoid locking problems
+ bBackToLoaded = m_bIsLink;
+ }
+
+ sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
+
+ if ( bBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+
+ if ( !bSuccess )
+ throw uno::Exception(); // TODO:
+}
+
+awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+
+ if ( m_bHasClonedSize )
+ return m_aClonedSize;
+
+ sal_Bool bBackToLoaded = sal_False;
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ changeState( embed::EmbedStates::RUNNING );
+
+ // the links should be switched back to loaded state for now to avoid locking problems
+ bBackToLoaded = m_bIsLink;
+ }
+
+ awt::Size aResult;
+ sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
+
+ if ( bBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+
+ if ( !bSuccess )
+ throw uno::Exception(); // TODO:
+
+ return aResult;
+}
+
+sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
+ throw ( uno::Exception,
+ uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_bHasClonedSize )
+ return m_nClonedMapUnit;
+
+ sal_Bool bBackToLoaded = sal_False;
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ changeState( embed::EmbedStates::RUNNING );
+
+ // the links should be switched back to loaded state for now to avoid locking problems
+ bBackToLoaded = m_bIsLink;
+ }
+
+ sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
+
+ if ( bBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+
+ if ( nResult < 0 )
+ throw uno::Exception(); // TODO:
+
+ return nResult;
+}
+
+embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+
+ OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
+ if ( nAspect == embed::Aspects::MSOLE_ICON )
+ // no representation can be retrieved
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
+
+ sal_Bool bBackToLoaded = sal_False;
+ if ( m_nObjectState == embed::EmbedStates::LOADED )
+ {
+ changeState( embed::EmbedStates::RUNNING );
+
+ // the links should be switched back to loaded state for now to avoid locking problems
+ bBackToLoaded = m_bIsLink;
+ }
+
+ OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
+
+ // TODO: return for the aspect of the document
+ embed::VisualRepresentation aVisualRepresentation;
+
+ uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if( xVisualObject.is())
+ {
+ aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
+ }
+ else
+ {
+ uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
+ if (!xTransferable.is() )
+ throw uno::RuntimeException();
+
+ datatransfer::DataFlavor aDataFlavor(
+ ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
+ ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
+ ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
+
+ if( xTransferable->isDataFlavorSupported( aDataFlavor ))
+ {
+ aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
+ aVisualRepresentation.Flavor = aDataFlavor;
+ }
+ else
+ throw uno::RuntimeException();
+ }
+
+ if ( bBackToLoaded )
+ changeState( embed::EmbedStates::LOADED );
+
+ return aVisualRepresentation;
+}
+
diff --git a/embeddedobj/source/commonembedding/xfactory.cxx b/embeddedobj/source/commonembedding/xfactory.cxx
new file mode 100644
index 000000000000..0edbaeb58fc0
--- /dev/null
+++ b/embeddedobj/source/commonembedding/xfactory.cxx
@@ -0,0 +1,579 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_embeddedobj.hxx"
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/EntryInitModes.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <rtl/logfile.hxx>
+
+
+#include "xfactory.hxx"
+#include "commonembobj.hxx"
+#include "specialobject.hxx"
+#include "oleembobj.hxx"
+
+
+using namespace ::com::sun::star;
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
+{
+ uno::Sequence< ::rtl::OUString > aRet(2);
+ aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OOoEmbeddedObjectFactory");
+ aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoEmbeddedObjectFactory");
+ return aRet;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OOoEmbeddedObjectFactory::impl_staticGetImplementationName()
+{
+ return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoEmbeddedObjectFactory");
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new OOoEmbeddedObjectFactory( xServiceManager ) );
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitFromEntry(
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ container::NoSuchElementException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException)
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromEntry" );
+
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
+ if ( !xNameAccess.is() )
+ throw uno::RuntimeException(); //TODO
+
+ // detect entry existence
+ if ( !xNameAccess->hasByName( sEntName ) )
+ throw container::NoSuchElementException();
+
+ uno::Reference< uno::XInterface > xResult;
+ if ( xStorage->isStorageElement( sEntName ) )
+ {
+ // the object must be based on storage
+ uno::Reference< embed::XStorage > xSubStorage =
+ xStorage->openStorageElement( sEntName, embed::ElementModes::READ );
+
+ uno::Reference< beans::XPropertySet > xPropSet( xSubStorage, uno::UNO_QUERY );
+ if ( !xPropSet.is() )
+ throw uno::RuntimeException();
+
+ ::rtl::OUString aMediaType;
+ try {
+ uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) );
+ aAny >>= aMediaType;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ try {
+ uno::Reference< lang::XComponent > xComp( xSubStorage, uno::UNO_QUERY );
+ if ( xComp.is() )
+ xComp->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ xSubStorage = uno::Reference< embed::XStorage >();
+
+#if 0
+ ::rtl::OUString aDocServiceName = m_aConfigHelper.GetDocumentServiceFromMediaType( aMediaType );
+ if ( !aDocServiceName.getLength() )
+ {
+ // only own document can be based on storage
+ // in case it is not possible to find related
+ // document service name the storage entry is invalid
+
+ throw io::IOException(); // unexpected mimetype of the storage
+ }
+#endif
+
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByMediaType( aMediaType );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+ xResult = uno::Reference< uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject ) ),
+#if 0
+ GetClassIDFromServName( aDocServiceName ),
+ GetClassNameFromServName( aDocServiceName ),
+ aDocServiceName ) ),
+#endif
+ uno::UNO_QUERY );
+ }
+ else
+ {
+ // the object must be OOo embedded object, if it is not an exception must be thrown
+ throw io::IOException(); // TODO:
+ }
+
+ uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
+
+ if ( !xPersist.is() )
+ throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
+
+ xPersist->setPersistentEntry( xStorage,
+ sEntName,
+ embed::EntryInitModes::DEFAULT_INIT,
+ aMediaDescr,
+ lObjArgs );
+
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException)
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
+
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr );
+
+ // check if there is FilterName
+ ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False );
+
+ uno::Reference< uno::XInterface > xResult;
+
+ // find document service name
+ if ( aFilterName.getLength() )
+ {
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByFilter( aFilterName );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+
+ xResult = uno::Reference< uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject ) ),
+ uno::UNO_QUERY );
+ }
+ else
+ {
+ // the object must be OOo embedded object, if it is not an exception must be thrown
+ throw io::IOException(); // TODO:
+ }
+
+ uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
+
+ if ( !xPersist.is() )
+ throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
+
+ xPersist->setPersistentEntry( xStorage,
+ sEntName,
+ embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
+ aTempMedDescr,
+ lObjArgs );
+
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitNew(
+ const uno::Sequence< sal_Int8 >& aClassID,
+ const ::rtl::OUString& /*aClassName*/,
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException)
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitNew" );
+
+ uno::Reference< uno::XInterface > xResult;
+
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 3 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 4 );
+
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+ xResult = uno::Reference< uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject ) ),
+ uno::UNO_QUERY );
+
+
+ uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
+
+ if ( !xPersist.is() )
+ throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
+
+ xPersist->setPersistentEntry( xStorage,
+ sEntName,
+ embed::EntryInitModes::TRUNCATE_INIT,
+ uno::Sequence< beans::PropertyValue >(),
+ lObjArgs );
+
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceUserInit(
+ const uno::Sequence< sal_Int8 >& aClassID,
+ const ::rtl::OUString& /*aClassName*/,
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ sal_Int32 nEntryConnectionMode,
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceUserInit" );
+
+ // the initialization is completelly controlled by user
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+ uno::Sequence< beans::PropertyValue > aTempMedDescr( lArguments );
+ if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
+ {
+ ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, aObject );
+ if ( !aFilterName.getLength() )
+ // the object must be OOo embedded object, if it is not an exception must be thrown
+ throw io::IOException(); // TODO:
+ }
+
+ uno::Reference< uno::XInterface > xResult = uno::Reference< uno::XInterface > (
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject ) ),
+ uno::UNO_QUERY );
+
+ uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
+ if ( xPersist.is() )
+ {
+ xPersist->setPersistentEntry( xStorage,
+ sEntName,
+ nEntryConnectionMode,
+ aTempMedDescr,
+ lObjArgs );
+
+ }
+ else
+ throw uno::RuntimeException(); // TODO:
+
+ return xResult;
+}
+
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceLink(
+ const uno::Reference< embed::XStorage >& /*xStorage*/,
+ const ::rtl::OUString& /*sEntName*/,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLink" );
+
+ uno::Reference< uno::XInterface > xResult;
+
+ uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr );
+
+ // check if there is URL, URL must exist
+ ::rtl::OUString aURL;
+ for ( sal_Int32 nInd = 0; nInd < aTempMedDescr.getLength(); nInd++ )
+ if ( aTempMedDescr[nInd].Name.equalsAscii( "URL" ) )
+ aTempMedDescr[nInd].Value >>= aURL;
+
+ if ( !aURL.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No URL for the link is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 3 );
+
+ ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False );
+
+ if ( aFilterName.getLength() )
+ {
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByFilter( aFilterName );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+
+ xResult = uno::Reference< uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject,
+ aTempMedDescr,
+ lObjArgs ) ),
+ uno::UNO_QUERY );
+ }
+ else
+ {
+ // the object must be OOo embedded object, if it is not an exception must be thrown
+ throw io::IOException(); // TODO:
+ }
+
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceLinkUserInit(
+ const uno::Sequence< sal_Int8 >& aClassID,
+ const ::rtl::OUString& /*aClassName*/,
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lArguments,
+ const uno::Sequence< beans::PropertyValue >& lObjArgs )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLinkUserInit" );
+
+ uno::Reference< uno::XInterface > xResult;
+
+ // the initialization is completelly controlled by user
+ if ( !xStorage.is() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ uno::Sequence< beans::PropertyValue > aTempMedDescr( lArguments );
+
+ ::rtl::OUString aURL;
+ for ( sal_Int32 nInd = 0; nInd < aTempMedDescr.getLength(); nInd++ )
+ if ( aTempMedDescr[nInd].Name.equalsAscii( "URL" ) )
+ aTempMedDescr[nInd].Value >>= aURL;
+
+ if ( !aURL.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No URL for the link is provided!\n" ),
+ uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
+ 3 );
+
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+ ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, aObject );
+
+ if ( aFilterName.getLength() )
+ {
+
+ xResult = uno::Reference< uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject(
+ m_xFactory,
+ aObject,
+ aTempMedDescr,
+ lObjArgs ) ),
+ uno::UNO_QUERY );
+ }
+ else
+ {
+ // the object must be OOo embedded object, if it is not an exception must be thrown
+ throw io::IOException(); // TODO:
+ }
+
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OOoEmbeddedObjectFactory::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetImplementationName();
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SAL_CALL OOoEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
+
+ for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
+ if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
+ return sal_True;
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OOoEmbeddedObjectFactory::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetSupportedServiceNames();
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
+{
+ uno::Sequence< ::rtl::OUString > aRet(2);
+ aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OOoSpecialEmbeddedObjectFactory");
+ aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
+ return aRet;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName()
+{
+ return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new OOoSpecialEmbeddedObjectFactory( xServiceManager ) );
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OOoSpecialEmbeddedObjectFactory::createInstanceUserInit(
+ const uno::Sequence< sal_Int8 >& aClassID,
+ const ::rtl::OUString& /*aClassName*/,
+ const uno::Reference< embed::XStorage >& /*xStorage*/,
+ const ::rtl::OUString& /*sEntName*/,
+ sal_Int32 /*nEntryConnectionMode*/,
+ const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
+ const uno::Sequence< beans::PropertyValue >& /*lObjArgs*/ )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID );
+ if ( !aObject.getLength() )
+ throw io::IOException(); // unexpected mimetype of the storage
+
+ uno::Reference< uno::XInterface > xResult(
+ static_cast< ::cppu::OWeakObject* > ( new OSpecialEmbeddedObject(
+ m_xFactory,
+ aObject ) ),
+ uno::UNO_QUERY );
+ return xResult;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OOoSpecialEmbeddedObjectFactory::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetImplementationName();
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SAL_CALL OOoSpecialEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
+
+ for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
+ if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
+ return sal_True;
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OOoSpecialEmbeddedObjectFactory::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetSupportedServiceNames();
+}
+
+
diff --git a/embeddedobj/source/commonembedding/xfactory.hxx b/embeddedobj/source/commonembedding/xfactory.hxx
new file mode 100644
index 000000000000..7675b7bf79ce
--- /dev/null
+++ b/embeddedobj/source/commonembedding/xfactory.hxx
@@ -0,0 +1,125 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __XFACTORY_HXX_
+#define __XFACTORY_HXX_
+
+#include <com/sun/star/embed/XEmbedObjectCreator.hpp>
+#include <com/sun/star/embed/XEmbedObjectFactory.hpp>
+#include <com/sun/star/embed/XLinkCreator.hpp>
+#include <com/sun/star/embed/XLinkFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase5.hxx>
+#include <comphelper/mimeconfighelper.hxx>
+
+class OOoEmbeddedObjectFactory : public ::cppu::WeakImplHelper5<
+ ::com::sun::star::embed::XEmbedObjectCreator,
+ ::com::sun::star::embed::XEmbedObjectFactory,
+ ::com::sun::star::embed::XLinkCreator,
+ ::com::sun::star::embed::XLinkFactory,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+
+ ::comphelper::MimeConfigurationHelper m_aConfigHelper;
+
+public:
+ OOoEmbeddedObjectFactory(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
+ : m_xFactory( xFactory )
+ , m_aConfigHelper( xFactory )
+ {
+ OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" );
+ }
+
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL impl_staticGetSupportedServiceNames();
+
+ static ::rtl::OUString SAL_CALL impl_staticGetImplementationName();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
+ impl_staticCreateSelfInstance(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+
+ // XEmbedObjectCreator
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceInitNew( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceInitFromEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceInitFromMediaDescriptor( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XEmbedObjectFactory
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceUserInit( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, sal_Int32 nEntryConnectionMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XLinkCreator
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceLink( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XLinkFactory
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceLinkUserInit( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+class OOoSpecialEmbeddedObjectFactory : public ::cppu::WeakImplHelper2<
+ ::com::sun::star::embed::XEmbedObjectFactory,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+
+ ::comphelper::MimeConfigurationHelper m_aConfigHelper;
+
+public:
+ OOoSpecialEmbeddedObjectFactory(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
+ : m_xFactory( xFactory )
+ , m_aConfigHelper( xFactory )
+ {
+ OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" );
+ }
+
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL impl_staticGetSupportedServiceNames();
+
+ static ::rtl::OUString SAL_CALL impl_staticGetImplementationName();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
+ impl_staticCreateSelfInstance(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+ // XEmbedObjectFactory
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceUserInit( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, sal_Int32 nEntryConnectionMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException);
+};
+
+#endif
+