summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2003-11-13 16:01:50 +0000
committerMikhail Voitenko <mav@openoffice.org>2003-11-13 16:01:50 +0000
commit414bfcead9a16a37cfa22aba9d9433e04be9798e (patch)
treef7e540c2deb530da2d51006e2db5eabbc2549e2e
parent0f22e95e602700301863c7219bd34570382b7f07 (diff)
#112923# embedded object for MS OLE
-rw-r--r--embeddedobj/source/msole/advisesink.cxx163
-rw-r--r--embeddedobj/source/msole/advisesink.hxx89
-rw-r--r--embeddedobj/source/msole/makefile.mk102
-rw-r--r--embeddedobj/source/msole/olecomponent.cxx1104
-rw-r--r--embeddedobj/source/msole/olecomponent.hxx224
-rw-r--r--embeddedobj/source/msole/oleembed.cxx374
-rw-r--r--embeddedobj/source/msole/olemisc.cxx282
-rw-r--r--embeddedobj/source/msole/olepersist.cxx777
-rw-r--r--embeddedobj/source/msole/olevisual.cxx142
-rw-r--r--embeddedobj/source/msole/olewrapclient.cxx188
-rw-r--r--embeddedobj/source/msole/olewrapclient.hxx90
-rw-r--r--embeddedobj/source/msole/platform.h75
12 files changed, 3610 insertions, 0 deletions
diff --git a/embeddedobj/source/msole/advisesink.cxx b/embeddedobj/source/msole/advisesink.cxx
new file mode 100644
index 0000000000..4b7ae657e3
--- /dev/null
+++ b/embeddedobj/source/msole/advisesink.cxx
@@ -0,0 +1,163 @@
+/*************************************************************************
+ *
+ * $RCSfile: advisesink.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:12 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <osl/diagnose.h>
+#include <advisesink.hxx>
+#include <olecomponent.hxx>
+
+OleWrapperAdviseSink::OleWrapperAdviseSink( OleComponent* pOleComp )
+: m_nRefCount( 0 )
+, m_pOleComp( pOleComp )
+{
+ OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
+}
+
+OleWrapperAdviseSink::~OleWrapperAdviseSink()
+{
+}
+
+STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
+{
+ *ppv=NULL;
+
+ if ( riid == IID_IUnknown )
+ *ppv = (IUnknown*)this;
+
+ if ( riid == IID_IAdviseSink )
+ *ppv = (IAdviseSink*)this;
+
+ if ( *ppv != NULL )
+ {
+ ((IUnknown*)*ppv)->AddRef();
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
+{
+ return osl_incrementInterlockedCount( &m_nRefCount);
+}
+
+STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
+{
+ ULONG nReturn = --m_nRefCount;
+ if ( m_nRefCount == 0 )
+ delete this;
+
+ return nReturn;
+}
+
+void OleWrapperAdviseSink::disconnectOleComponent()
+{
+ // must not be called from the descructor of OleComponent!!!
+ osl::MutexGuard aGuard( m_aMutex );
+ m_pOleComp = NULL;
+}
+
+STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM)
+{
+ // Unused for now ( no registration for IDataObject events )
+}
+
+STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect, LONG lindex)
+{
+ OleComponent* pLockComponent = NULL;
+
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pOleComp )
+ {
+ pLockComponent = m_pOleComp;
+ pLockComponent->acquire();
+ }
+ }
+
+ if ( pLockComponent )
+ {
+ pLockComponent->OnViewChange_Impl( dwAspect );
+ pLockComponent->release();
+ }
+}
+
+STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(LPMONIKER pmk)
+{
+ // handled by default inprocess handler
+}
+
+STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
+{
+ // TODO: ???
+ /*
+ * A Container has nothing to do here as this notification is
+ * only useful when we have an ADVFCACHE_ONSAVE advise set up,
+ * which we don't. So we ignore it.
+ */
+}
+
+STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
+{
+ // mainly handled by inprocess handler
+
+ // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here
+}
+
diff --git a/embeddedobj/source/msole/advisesink.hxx b/embeddedobj/source/msole/advisesink.hxx
new file mode 100644
index 0000000000..a132662c16
--- /dev/null
+++ b/embeddedobj/source/msole/advisesink.hxx
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * $RCSfile: advisesink.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:32 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <osl/interlck.h>
+#include <osl/mutex.hxx>
+#include <platform.h>
+
+class OleComponent;
+class OleWrapperAdviseSink : public IAdviseSink
+{
+protected:
+ osl::Mutex m_aMutex;
+ oslInterlockedCount m_nRefCount;
+ OleComponent* m_pOleComp;
+
+public:
+ OleWrapperAdviseSink( OleComponent* pOleComp );
+ OleWrapperAdviseSink(void);
+
+ void disconnectOleComponent();
+ STDMETHODIMP QueryInterface(REFIID, void**);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP_(void) OnDataChange(LPFORMATETC, LPSTGMEDIUM);
+ STDMETHODIMP_(void) OnViewChange(DWORD, LONG);
+ STDMETHODIMP_(void) OnRename(LPMONIKER);
+ STDMETHODIMP_(void) OnSave(void);
+ STDMETHODIMP_(void) OnClose(void);
+};
+
diff --git a/embeddedobj/source/msole/makefile.mk b/embeddedobj/source/msole/makefile.mk
new file mode 100644
index 0000000000..77836eca1b
--- /dev/null
+++ b/embeddedobj/source/msole/makefile.mk
@@ -0,0 +1,102 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1 $
+#
+# last change: $Author: mav $ $Date: 2003-11-13 17:00:56 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library 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 for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=..$/..
+
+PRJNAME=embeddedobj
+TARGET=embedobj
+
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+LIBTARGET=NO
+USE_DEFFILE=NO
+INCPRE+=$(ATL_INCLUDE)
+
+# --- Files --------------------------------------------------------
+
+SLOFILES = \
+ $(SLO)$/olecomponent.obj\
+ $(SLO)$/olepersist.obj\
+ $(SLO)$/oleembed.obj\
+ $(SLO)$/olevisual.obj\
+ $(SLO)$/olemisc.obj\
+ $(SLO)$/olewrapclient.obj\
+ $(SLO)$/advisesink.obj
+
+
+EXCEPTIONSFILES= \
+ $(SLO)$/olecomponent.obj\
+ $(SLO)$/olepersist.obj\
+ $(SLO)$/oleembed.obj\
+ $(SLO)$/olevisual.obj\
+ $(SLO)$/olemisc.obj\
+ $(SLO)$/olewrapclient.obj\
+ $(SLO)$/advisesink.obj
+
+
+# --- Targets -------------------------------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx
new file mode 100644
index 0000000000..7254cff806
--- /dev/null
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -0,0 +1,1104 @@
+/*************************************************************************
+ *
+ * $RCSfile: olecomponent.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:13 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_FRAME_DOUBLEINITIALIZATIONEXCEPTION_HPP_
+#include <com/sun/star/frame/DoubleInitializationException.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_EMBED_WRONGSTATEEXCEPTION_HPP_
+#include <com/sun/star/embed/WrongStateException.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
+#include <com/sun/star/beans/XPropertySet.hpp>
+#endif
+
+
+#include <platform.h>
+
+#include <cppuhelper/interfacecontainer.h>
+#include <osl/file.hxx>
+
+#include "olecomponent.hxx"
+#include "olewrapclient.hxx"
+#include "advisesink.hxx"
+#include "oleembobj.hxx"
+
+
+using namespace ::com::sun::star;
+
+#define MAX_ENUM_ELE 20
+const sal_Int32 n_ConstBufferSize = 32000;
+
+STDAPI StarObject_SwitchDisplayAspect(IUnknown *pObj, LPDWORD pdwCurAspect
+ , DWORD dwNewAspect, HGLOBAL hMetaPict, BOOL fDeleteOld
+ , BOOL fViewAdvise, IAdviseSink *pSink, BOOL *pfMustUpdate)
+{
+ // TODO: implement the switching
+ return S_OK;
+}
+
+
+sal_Bool ConvertDataForFlavor( const STGMEDIUM& aMedium, const datatransfer::DataFlavor& aFlavor, uno::Any& aResult )
+{
+ // TODO: try to convert data from Medium format to specified Flavor format
+ return sal_False;
+}
+
+//----------------------------------------------
+sal_Bool GraphicalFlavor( const datatransfer::DataFlavor& aFlavor )
+{
+ // TODO: just check that the requested flavour is one of supported graphical flavours
+ return sal_False;
+}
+
+//-----------------------------------------------
+// TODO: probably later such a common function can be moved
+// to a separate helper library.
+void copyInputToOutput_Impl( const uno::Reference< io::XInputStream >& aIn,
+ const uno::Reference< io::XOutputStream >& aOut )
+{
+ sal_Int32 nRead;
+ uno::Sequence < sal_Int8 > aSequence ( n_ConstBufferSize );
+
+ do
+ {
+ nRead = aIn->readBytes ( aSequence, n_ConstBufferSize );
+ if ( nRead < n_ConstBufferSize )
+ {
+ uno::Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead );
+ aOut->writeBytes ( aTempBuf );
+ }
+ else
+ aOut->writeBytes ( aSequence );
+ }
+ while ( nRead == n_ConstBufferSize );
+}
+
+//-----------------------------------------------
+sal_Bool KillFile( const ::rtl::OUString& aURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+{
+ if ( !xFactory.is() )
+ return sal_False;
+
+ sal_Bool bRet = sal_False;
+
+ try
+ {
+ uno::Reference < ucb::XSimpleFileAccess > xAccess(
+ xFactory->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
+
+ if ( xAccess.is() )
+ {
+ xAccess->kill( aURL );
+ bRet = sal_True;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bRet;
+}
+
+//----------------------------------------------
+::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+{
+ OSL_ENSURE( xFactory.is(), "No factory is provided!\n" );
+
+ ::rtl::OUString aResult;
+
+ uno::Reference < beans::XPropertySet > xTempFile(
+ xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
+ uno::UNO_QUERY );
+
+ if ( !xTempFile.is() )
+ throw uno::RuntimeException(); // TODO
+
+ try {
+ xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ), uno::makeAny( sal_False ) );
+ uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
+ aUrl >>= aResult;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ if ( !aResult.getLength() )
+ throw uno::RuntimeException(); // TODO: can not create tempfile
+
+ return aResult;
+}
+
+//-----------------------------------------------
+::rtl::OUString GetNewFilledTempFile( const uno::Reference< io::XInputStream >& xInStream,
+ const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+ throw( io::IOException )
+{
+ OSL_ENSURE( xInStream.is() && xFactory.is(), "Wrong parameters are provided!\n" );
+
+ ::rtl::OUString aResult = GetNewTempFileURL( xFactory );
+
+ if ( aResult )
+ {
+ try {
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ xFactory->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
+
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aResult );
+ if ( xTempOutStream.is() )
+ {
+ // copy stream contents to the file
+ copyInputToOutput_Impl( xInStream, xTempOutStream );
+ xTempOutStream->closeOutput();
+ xTempOutStream = uno::Reference< io::XOutputStream >();
+ }
+ else
+ throw io::IOException(); // TODO:
+ }
+ catch( packages::WrongPasswordException& )
+ {
+ KillFile( aResult, xFactory );
+ throw io::IOException(); //TODO:
+ }
+ catch( io::IOException& )
+ {
+ KillFile( aResult, xFactory );
+ throw;
+ }
+ catch( uno::RuntimeException& )
+ {
+ KillFile( aResult, xFactory );
+ throw;
+ }
+ catch( uno::Exception& )
+ {
+ KillFile( aResult, xFactory );
+ aResult = ::rtl::OUString();
+ }
+ }
+
+ return aResult;
+}
+
+//----------------------------------------------
+sal_Bool GetClassIDFromSequence( uno::Sequence< sal_Int8 > aSeq, CLSID& aResult )
+{
+ if ( aSeq.getLength() == 16 )
+ {
+ aResult.Data1 = ( ( ( ( ( (sal_uInt8)aSeq[0] << 8 ) + (sal_uInt8)aSeq[1] ) << 8 ) + (sal_uInt8)aSeq[2] ) << 8 ) + (sal_uInt8)aSeq[3];
+ aResult.Data2 = ( (sal_uInt8)aSeq[4] << 8 ) + (sal_uInt8)aSeq[5];
+ aResult.Data3 = ( (sal_uInt8)aSeq[6] << 8 ) + (sal_uInt8)aSeq[7];
+ for( int nInd = 0; nInd < 8; nInd++ )
+ aResult.Data4[nInd] = (sal_uInt8)aSeq[nInd+8];
+
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//----------------------------------------------
+::rtl::OUString WinAccToVcl( const sal_Unicode* pStr )
+{
+ ::rtl::OUString aResult;
+
+ if( pStr )
+ {
+ while ( *pStr )
+ {
+ if ( *pStr == '&' )
+ {
+ aResult += ::rtl::OUString::createFromAscii( "~" );
+ while( *(++pStr) == '&' );
+ }
+ else
+ {
+ aResult += ::rtl::OUString( pStr, 1 );
+ pStr++;
+ }
+ }
+ }
+
+ return aResult;
+}
+
+//----------------------------------------------
+OleComponent::OleComponent( const uno::Reference< lang::XMultiServiceFactory >& xFactory, OleEmbeddedObject* pUnoOleObject )
+: m_pInterfaceContainer( NULL )
+, m_bDisposed( sal_False )
+, m_xFactory( xFactory )
+, m_pOleWrapClientSite( NULL )
+, m_pImplAdviseSink( NULL )
+, m_pUnoOleObject( pUnoOleObject )
+, m_nMSAspect( 0 )
+, m_nOLEMiscFlags( 0 )
+, m_nAdvConn( 0 )
+, m_nSupportedFormat( 0 )
+, m_nSupportedMedium( 0 )
+{
+ OSL_ENSURE( m_pUnoOleObject, "No owner object is provided!" );
+
+ m_pOleWrapClientSite = new OleWrapperClientSite( (OleComponent*)this );
+ m_pOleWrapClientSite->AddRef();
+
+ m_pImplAdviseSink = new OleWrapperAdviseSink( (OleComponent*)this );
+ m_pImplAdviseSink->AddRef();
+}
+
+//----------------------------------------------
+OleComponent::~OleComponent()
+{
+ if ( m_pOleWrapClientSite )
+ {
+ // must be done on close()
+ // here it means an error
+ OSL_ENSURE( sal_False, "Looks like the object was not closed before destruction - DISASTER is possible!" );
+
+ m_pOleWrapClientSite->disconnectOleComponent();
+ m_pOleWrapClientSite->Release();
+ m_pOleWrapClientSite = NULL;
+ }
+
+ if ( m_pImplAdviseSink )
+ {
+ // must be done on close()
+ // here it means an error
+ OSL_ENSURE( sal_False, "Looks like the object was not closed before destruction - DISASTER is possible!" );
+
+ m_pImplAdviseSink->disconnectOleComponent();
+ m_pImplAdviseSink->Release();
+ m_pImplAdviseSink = NULL;
+ }
+
+ if ( m_pInterfaceContainer )
+ {
+ delete m_pInterfaceContainer;
+ m_pInterfaceContainer = NULL;
+ }
+}
+
+//----------------------------------------------
+void OleComponent::disconnectEmbeddedObject()
+{
+ // must not be called from destructor of UNO OLE object!!!
+ osl::MutexGuard aGuard( m_aMutex );
+ m_pUnoOleObject = NULL;
+}
+
+//----------------------------------------------
+CComPtr< IStorage > OleComponent::CreateIStorageOnXInputStream_Impl( const uno::Reference< io::XInputStream >& xInStream )
+{
+ // TODO: in future a global memory should be used instead of file.
+
+ OSL_ENSURE( !m_aTempURL.getLength(), "The object already has temporary representation!\n" );
+
+ // write the stream to the temporary file
+ m_aTempURL = GetNewFilledTempFile( xInStream, m_xFactory );
+ if ( !m_aTempURL.getLength() )
+ throw uno::RuntimeException(); // TODO
+
+ // open an IStorage based on the temporary file
+ ::rtl::OUString aTempFilePath;
+ if ( ::osl::FileBase::getSystemPathFromFileURL( m_aTempURL, aTempFilePath ) != ::osl::FileBase::E_None )
+ throw uno::RuntimeException(); // TODO: something dangerous happend
+
+ HRESULT hr = StgCreateDocfile( aTempFilePath, STGM_READWRITE | STGM_DELETEONRELEASE, 0, &m_pIStorage );
+ if ( FAILED( hr ) || !m_pIStorage )
+ throw io::IOException(); // TODO: transport error code?
+
+ return m_pIStorage;
+}
+
+//----------------------------------------------
+CComPtr< IStorage > OleComponent::CreateNewIStorage_Impl()
+{
+ // TODO: in future a global memory should be used instead of file.
+
+ OSL_ENSURE( !m_aTempURL.getLength(), "The object already has temporary representation!\n" );
+
+ // write the stream to the temporary file
+ m_aTempURL = GetNewTempFileURL( m_xFactory );
+ if ( !m_aTempURL.getLength() )
+ throw uno::RuntimeException(); // TODO
+
+ // open an IStorage based on the temporary file
+ ::rtl::OUString aTempFilePath;
+ if ( ::osl::FileBase::getSystemPathFromFileURL( m_aTempURL, aTempFilePath ) != ::osl::FileBase::E_None )
+ throw uno::RuntimeException(); // TODO: something dangerous happend
+
+ HRESULT hr = StgCreateDocfile( aTempFilePath, STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED | STGM_DELETEONRELEASE, 0, &m_pIStorage );
+ if ( FAILED( hr ) || !m_pIStorage )
+ throw io::IOException(); // TODO: transport error code?
+
+ return m_pIStorage;
+}
+
+//----------------------------------------------
+void OleComponent::RetrieveObjectDataFlavors_Impl()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ if ( !m_aDataFlavors.getLength() )
+ {
+ CComPtr< IDataObject > pDataObject;
+ HRESULT hr = m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject );
+ if ( FAILED( hr ) || !pDataObject )
+ throw io::IOException(); // TODO: transport error code
+
+ CComPtr< IEnumFORMATETC > pFormatEnum;
+ hr = pDataObject->EnumFormatEtc( DATADIR_GET, &pFormatEnum );
+ if ( FAILED( hr ) || !pFormatEnum )
+ throw io::IOException(); // TODO: transport error code
+
+ FORMATETC pElem[ MAX_ENUM_ELE ];
+ ULONG nNum = 0;
+
+ do
+ {
+ HRESULT hr = pFormatEnum->Next( MAX_ENUM_ELE, pElem, &nNum );
+ if( hr == S_OK || hr == S_FALSE )
+ {
+ for( sal_uInt32 nInd = 0; nInd < nNum; nInd++ )
+ {
+ //TODO: add OOo format reachable from specified OLE format to the list
+ }
+ }
+ else
+ break;
+ }
+ while( nNum == MAX_ENUM_ELE );
+ }
+}
+
+//----------------------------------------------
+sal_Bool OleComponent::InitializeObject_Impl( sal_uInt32 nIconHandle )
+// There will be no static objects!
+{
+ if ( !m_pObj )
+ return sal_False;
+
+ // the linked object will be detected here
+ CComPtr< IOleLink > pOleLink;
+ HRESULT hr = m_pObj->QueryInterface( IID_IOleLink, (void**)&pOleLink );
+ m_pUnoOleObject->SetObjectIsLink_Impl( pOleLink != NULL );
+
+
+ hr = m_pObj->QueryInterface( IID_IViewObject2, (void**)&m_pViewObject2 );
+ if ( FAILED( hr ) || !m_pViewObject2 )
+ return sal_False;
+
+ m_pViewObject2->SetAdvise( m_nMSAspect, 0, m_pImplAdviseSink );
+
+ // register cache in case there is no ( Visio 2000 workaround )
+ IOleCache* pIOleCache = NULL;
+ if ( SUCCEEDED( m_pObj->QueryInterface( IID_IOleCache, (void**)&pIOleCache ) ) && pIOleCache )
+ {
+ IEnumSTATDATA* pEnumSD = NULL;
+ HRESULT hr = pIOleCache->EnumCache( &pEnumSD );
+
+ sal_Bool bRegister = sal_True;
+ if ( SUCCEEDED( hr ) && pEnumSD )
+ {
+ pEnumSD->Reset();
+ STATDATA aSD;
+ DWORD nNum;
+ while( SUCCEEDED( pEnumSD->Next( 1, &aSD, &nNum ) ) && nNum == 1 )
+ {
+ if ( aSD.formatetc.cfFormat == 0 )
+ {
+ bRegister = sal_False;
+ break;
+ }
+ }
+ }
+
+ if ( bRegister )
+ {
+ DWORD nConn;
+ FORMATETC aFormat = { 0, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT };
+ hr = pIOleCache->Cache( &aFormat, ADVFCACHE_ONSAVE, &nConn );
+ }
+
+ pIOleCache->Release();
+ pIOleCache = NULL;
+ }
+
+ hr = m_pObj->QueryInterface( IID_IOleObject, (void**)&m_pOleObject );
+ if ( FAILED( hr ) || !m_pOleObject )
+ return sal_False; // Static objects are not supported, they should be inserted as graphics
+
+ m_pOleObject->GetMiscStatus( m_nMSAspect, (DWORD*)&m_nOLEMiscFlags );
+ // TODO: use other misc flags also
+ // the object should have drawable aspect even in case it supports only iconic representation
+ // if ( m_nOLEMiscFlags & OLEMISC_ONLYICONIC )
+ // m_nMSAspect = DVASPECT_ICON;
+
+ m_pOleObject->SetClientSite( m_pOleWrapClientSite );
+ m_pOleObject->Advise( m_pImplAdviseSink, (DWORD*)&m_nAdvConn );
+
+ OleSetContainedObject( m_pOleObject, TRUE );
+
+ if ( m_nMSAspect & DVASPECT_ICON )
+ {
+ // TODO: the icon provided from dialog must be stored
+ // if there is no icon, it should be retrieved
+ DWORD nOldAspect = DVASPECT_CONTENT;
+ IAdviseSink *pSink;
+
+ pSink = ( nIconHandle == NULL ) ? NULL : m_pImplAdviseSink;
+
+ StarObject_SwitchDisplayAspect( m_pOleObject,
+ &nOldAspect,
+ DVASPECT_ICON,
+ (HGLOBAL)(UINT)nIconHandle,
+ FALSE,
+ nIconHandle != NULL,
+ pSink,
+ NULL );
+ }
+
+ return sal_True;
+}
+
+//----------------------------------------------
+void OleComponent::LoadEmbeddedObject( const uno::Reference< io::XInputStream >& xInStream, sal_Int64 nAspect )
+{
+ if ( !xInStream.is() )
+ throw lang::IllegalArgumentException(); // TODO
+
+ if ( m_pIStorage || m_aTempURL.getLength() )
+ throw frame::DoubleInitializationException(); // TODO the object is already initialized
+
+ m_nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects
+
+ m_pIStorage = CreateIStorageOnXInputStream_Impl( xInStream );
+ if ( !m_pIStorage )
+ throw uno::RuntimeException(); // TODO:
+
+ HRESULT hr = OleLoad( m_pIStorage, IID_IUnknown, NULL, (void**)&m_pObj );
+ if ( FAILED( hr ) || !m_pObj )
+ throw uno::RuntimeException();
+
+ if ( !InitializeObject_Impl( NULL ) )
+ throw uno::RuntimeException(); // TODO
+}
+
+//----------------------------------------------
+void OleComponent::CreateNewEmbeddedObject( const uno::Sequence< sal_Int8 >& aSeqCLSID,
+ sal_Int64 nAspect,
+ sal_uInt32 nIconHandle )
+{
+ CLSID aClsID;
+
+ if ( !GetClassIDFromSequence( aSeqCLSID, aClsID ) )
+ throw lang::IllegalArgumentException(); // TODO
+
+ if ( m_pIStorage || m_aTempURL.getLength() )
+ throw frame::DoubleInitializationException(); // the object is already initialized
+
+ m_pIStorage = CreateNewIStorage_Impl();
+ if ( !m_pIStorage )
+ throw uno::RuntimeException(); // TODO
+
+ // FORMATETC aFormat = { CF_METAFILEPICT, NULL, nAspect, -1, TYMED_MFPICT }; // for OLE..._DRAW should be NULL
+ m_nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects
+
+ HRESULT hr = OleCreate( aClsID,
+ IID_IUnknown,
+ OLERENDER_DRAW, // OLERENDER_FORMAT
+ NULL, // &aFormat,
+ NULL,
+ m_pIStorage,
+ (void**)&m_pObj );
+
+ if ( FAILED( hr ) || !m_pObj )
+ throw uno::RuntimeException(); // TODO
+
+ if ( !InitializeObject_Impl( nIconHandle ) )
+ throw uno::RuntimeException(); // TODO
+
+ // TODO: getExtent???
+}
+
+//----------------------------------------------
+void OleComponent::CreateObjectFromData( const uno::Reference< datatransfer::XTransferable >& xTransfer,
+ sal_Int64 nAspect )
+// Static objects are not supported, they should be inserted as graphics
+{
+ // TODO: May be this call is useless since there are no static objects
+ // and nonstatic objects will be created based on OLEstorage ( stream ).
+ // ???
+
+ // OleQueryCreateFromData...
+}
+
+//----------------------------------------------
+void OleComponent::CreateObjectFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle )
+{
+ // TODO:
+}
+
+//----------------------------------------------
+void OleComponent::CreateLinkFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle )
+{
+ // TODO:
+}
+
+//----------------------------------------------
+void OleComponent::RunObject()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ if ( !OleIsRunning( m_pOleObject ) )
+ {
+ HRESULT hr = OleRun( m_pObj );
+ if ( FAILED( hr ) )
+ throw io::IOException();
+ }
+}
+
+//----------------------------------------------
+void OleComponent::CloseObject()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ if ( OleIsRunning( m_pOleObject ) )
+ m_pOleObject->Close( OLECLOSE_NOSAVE ); // must be saved before
+}
+
+//----------------------------------------------
+uno::Sequence< embed::VerbDescr > OleComponent::GetVerbList()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ if( !m_aVerbList.getLength() )
+ {
+ // InitOle(); // TODO: makes sence to do in a central place
+
+ CComPtr< IEnumOLEVERB > pEnum;
+ if( SUCCEEDED( m_pOleObject->EnumVerbs( &pEnum ) ) )
+ {
+ OLEVERB szEle[ MAX_ENUM_ELE ];
+ ULONG nNum = 0;
+ sal_Int32 nSeqSize = 0;
+
+ do
+ {
+ HRESULT hr = pEnum->Next( MAX_ENUM_ELE, szEle, &nNum );
+ if( hr == S_OK || hr == S_FALSE )
+ {
+ m_aVerbList.realloc( nSeqSize += nNum );
+ for( sal_uInt32 nInd = 0; nInd < nNum; nInd++ )
+ {
+ m_aVerbList[nSeqSize-nNum+nInd].VerbID = szEle[ nInd ].lVerb;
+ m_aVerbList[nSeqSize-nNum+nInd].VerbName = WinAccToVcl( szEle[ nInd ].lpszVerbName );
+ m_aVerbList[nSeqSize-nNum+nInd].VerbFlags = szEle[ nInd ].fuFlags;
+ m_aVerbList[nSeqSize-nNum+nInd].VerbAttributes = szEle[ nInd ].grfAttribs;
+ }
+ }
+ else
+ break;
+ }
+ while( nNum == MAX_ENUM_ELE );
+ }
+ }
+
+ return m_aVerbList;
+}
+
+//----------------------------------------------
+void OleComponent::ExecuteVerb( sal_Int32 nVerbID )
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO
+
+ HRESULT hr = OleRun( m_pOleObject );
+ if ( FAILED( hr ) )
+ throw io::IOException(); // TODO: a specific exception that transport error code can be thrown here
+
+ // TODO: probably extents should be set here and stored in aRect
+ // TODO: probably the parent window also should be set
+ hr = m_pOleObject->DoVerb( nVerbID, NULL, m_pOleWrapClientSite, 0, NULL, NULL );
+
+ if ( FAILED( hr ) )
+ throw io::IOException(); // TODO
+}
+
+//----------------------------------------------
+void OleComponent::SetHostName( const ::rtl::OUString& aContName,
+ const ::rtl::OUString& aEmbDocName )
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ // TODO: use aContName and aEmbDocName in m_pOleObject->SetHostNames()
+}
+
+//----------------------------------------------
+void OleComponent::SetExtent( const awt::Size& aVisAreaSize, sal_Int64 nAspect )
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ DWORD nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects
+
+ SIZEL aSize = { aVisAreaSize.Width, aVisAreaSize.Height };
+ HRESULT hr = m_pOleObject->SetExtent( nMSAspect, &aSize );
+
+ if ( FAILED( hr ) )
+ throw io::IOException(); // TODO
+}
+
+//----------------------------------------------
+awt::Size OleComponent::GetExtent( sal_Int64 nAspect )
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ DWORD nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects
+ SIZEL aSize;
+ HRESULT hr = m_pOleObject->GetExtent( nMSAspect, &aSize );
+
+ if ( FAILED( hr ) )
+ throw io::IOException(); // TODO
+
+ return awt::Size( aSize.cx, aSize.cy );
+}
+
+//----------------------------------------------
+sal_Int64 OleComponent::GetMiscStatus()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ return (sal_Int64)m_nOLEMiscFlags; // first 32 bits are for MS flags
+}
+
+//----------------------------------------------
+sal_Int64 OleComponent::GetViewAspect()
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ return (sal_Int64)m_nMSAspect; // first 32 bits are for MS aspects
+}
+
+//----------------------------------------------
+void OleComponent::StoreObjectToStream( uno::Reference< io::XOutputStream > xOutStream, sal_Bool bStoreVisReplace )
+{
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ CComPtr< IPersistStorage > pPersistStorage;
+ HRESULT hr = m_pObj->QueryInterface(IID_IPersistStorage, (void**)&pPersistStorage);
+ if ( FAILED( hr ) || !pPersistStorage )
+ throw io::IOException(); // TODO
+
+ hr = OleSave(pPersistStorage, m_pIStorage, TRUE);
+ if ( FAILED( hr ) )
+ throw io::IOException(); // TODO
+
+ pPersistStorage->SaveCompleted(NULL);
+ m_pIStorage->Commit( STGC_DEFAULT );
+
+ // now all the changes should be in temporary location
+
+ // open temporary file for reading
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ m_xFactory->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
+
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ uno::Reference< io::XInputStream > xTempInStream = xTempAccess->openFileRead( m_aTempURL );
+ OSL_ENSURE( xTempInStream.is(), "The object's temporary file can not be reopened for reading!\n" );
+
+ // TODO: use bStoreVisReplace
+
+ if ( xTempInStream.is() )
+ {
+ // write all the contents to XOutStream
+ copyInputToOutput_Impl( xTempInStream, xOutStream );
+ }
+ else
+ throw io::IOException(); // TODO:
+
+ // TODO: should the view replacement be in the stream ???
+ // probably it must be specified on storing
+}
+
+//----------------------------------------------
+sal_Bool OleComponent::SaveObject_Impl()
+{
+ sal_Bool bResult = sal_False;
+ OleEmbeddedObject* pLockObject = NULL;
+
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pUnoOleObject )
+ {
+ pLockObject = m_pUnoOleObject;
+ pLockObject->acquire();
+ }
+ }
+
+ if ( pLockObject )
+ {
+ bResult = pLockObject->SaveObject_Impl();
+ pLockObject->release();
+ }
+
+ return bResult;
+}
+
+//----------------------------------------------
+sal_Bool OleComponent::OnShowWindow_Impl( sal_Bool bShow )
+{
+ sal_Bool bResult = sal_False;
+ OleEmbeddedObject* pLockObject = NULL;
+
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pUnoOleObject )
+ {
+ pLockObject = m_pUnoOleObject;
+ pLockObject->acquire();
+ }
+ }
+
+ if ( pLockObject )
+ {
+ bResult = m_pUnoOleObject->OnShowWindow_Impl( bShow );
+ pLockObject->release();
+ }
+
+ return bResult;
+}
+
+//----------------------------------------------
+void OleComponent::OnViewChange_Impl( DWORD dwAspect )
+{
+ // TODO: make a notification ?
+ // TODO: check if it is enough or may be saving notifications are required for Visio2000
+}
+
+//----------------------------------------------
+sal_Bool OleComponent::GetGraphicalCache_Impl( const datatransfer::DataFlavor& aFlavor, uno::Any& aResult )
+{
+ sal_Bool bOk = sal_False;
+ if ( m_pIStorage )
+ {
+ // try to retrieve cached representation
+ // TODO: in future it must be converted to requested format
+ for ( sal_uInt8 nInd = 0; nInd < 10; nInd++ )
+ {
+ CComPtr< IStream > pGrStream;
+ ::rtl::OUString aStreamName = ::rtl::OUString::createFromAscii( "\002OlePres00" );
+ aStreamName += ::rtl::OUString::valueOf( nInd );
+ HRESULT hr = m_pIStorage->OpenStream( aStreamName.getStr(),
+ NULL,
+ STGM_READ,
+ NULL,
+ &pGrStream );
+ if ( FAILED( hr ) || !pGrStream )
+ break;
+
+ // TODO: check that the format is acceptable
+ // if so - break
+
+ // create XInputStream ( for now SvStream ) with graphical representation
+ // try to generate a Metafile or Bitmap from it
+ // convert the result representation to requested format
+ // if ( succeeded ) (bOk = sal_True), break;
+ }
+ }
+
+ return bOk;
+}
+
+// XCloseable
+//----------------------------------------------
+void SAL_CALL OleComponent::close( sal_Bool bDeliverOwnership )
+ throw ( util::CloseVetoException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ 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 );
+ }
+}
+
+//----------------------------------------------
+void SAL_CALL OleComponent::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 OleComponent::removeCloseListener( 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->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ),
+ xListener );
+}
+
+// XTransferable
+//----------------------------------------------
+uno::Any SAL_CALL OleComponent::getTransferData( const datatransfer::DataFlavor& aFlavor )
+ throw ( datatransfer::UnsupportedFlavorException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ uno::Any aResult;
+ sal_Bool bSupportedFlavor = sal_False;
+
+ if ( GraphicalFlavor( aFlavor ) )
+ {
+ // first check if there is a cached representation
+ if ( m_pIStorage )
+ {
+ // try to retrieve cached representation
+ bSupportedFlavor = GetGraphicalCache_Impl( aFlavor, aResult );
+ }
+
+ if ( !bSupportedFlavor )
+ {
+ // TODO: retrieve MS METAFILE or bitmap and try to convert it to required format
+ CComPtr< IDataObject > pDataObject;
+ HRESULT hr = m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject );
+ if ( FAILED( hr ) || !pDataObject )
+ throw io::IOException(); // TODO: transport error code
+
+ if ( m_nSupportedFormat )
+ {
+ FORMATETC aFormatEtc = { m_nSupportedFormat, NULL, m_nMSAspect, -1, m_nSupportedMedium };
+ STGMEDIUM aMedium;
+ hr = pDataObject->GetData( &aFormatEtc, &aMedium );
+ if ( SUCCEEDED( hr ) )
+ bSupportedFlavor = ConvertDataForFlavor( aMedium, aFlavor, aResult );
+ }
+ else
+ {
+ // the supported format of the application is still not found, find one
+ sal_Int16 nFormats[3] = { CF_ENHMETAFILE, CF_METAFILEPICT, CF_BITMAP };
+ sal_Int32 nMediums[3] = { TYMED_ENHMF, TYMED_MFPICT, TYMED_GDI };
+
+ for ( sal_Int32 nInd = 0; nInd < 3; nInd++ )
+ {
+ FORMATETC aFormatEtc = { nFormats[nInd], NULL, m_nMSAspect, -1, nMediums[nInd] };
+ STGMEDIUM aMedium;
+ hr = pDataObject->GetData( &aFormatEtc, &aMedium );
+ if ( SUCCEEDED( hr ) )
+ {
+ m_nSupportedFormat = nFormats[nInd];
+ m_nSupportedMedium = nMediums[nInd];
+
+ bSupportedFlavor = ConvertDataForFlavor( aMedium, aFlavor, aResult );
+ break;
+ }
+ }
+ }
+
+ if ( !bSupportedFlavor )
+ {
+ // TODO: implement workaround for stampit
+ }
+ }
+ }
+ else
+ {
+ // TODO: allow to retrieve stream-representation of the object persistence
+ }
+
+ if ( !bSupportedFlavor )
+ throw datatransfer::UnsupportedFlavorException();
+
+ return aResult;
+}
+
+//----------------------------------------------
+uno::Sequence< datatransfer::DataFlavor > SAL_CALL OleComponent::getTransferDataFlavors()
+ throw (uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ RetrieveObjectDataFlavors_Impl();
+
+ return m_aDataFlavors;
+}
+
+//----------------------------------------------
+sal_Bool SAL_CALL OleComponent::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor )
+ throw (uno::RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( !m_pOleObject )
+ throw embed::WrongStateException(); // TODO: the object is in wrong state
+
+ if ( !m_aDataFlavors.getLength() )
+ {
+ // TODO: detect format, the object writes representation in, and return reachable from it formats
+ RetrieveObjectDataFlavors_Impl();
+ }
+
+ for ( sal_Int32 nInd = 0; nInd < m_aDataFlavors.getLength(); nInd++ )
+ if ( m_aDataFlavors[nInd].MimeType.equals( aFlavor.MimeType ) && m_aDataFlavors[nInd].DataType == aFlavor.DataType )
+ return sal_True;
+
+ return sal_False;
+}
+
diff --git a/embeddedobj/source/msole/olecomponent.hxx b/embeddedobj/source/msole/olecomponent.hxx
new file mode 100644
index 0000000000..53819a2182
--- /dev/null
+++ b/embeddedobj/source/msole/olecomponent.hxx
@@ -0,0 +1,224 @@
+/*************************************************************************
+ *
+ * $RCSfile: olecomponent.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:32 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _INC_OLECOMPONENT_HXX_
+#define _INC_OLECOMPONENT_HXX_
+
+#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
+#include <com/sun/star/uno/Sequence.hxx>
+#endif
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
+#include <com/sun/star/uno/Any.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
+#include <com/sun/star/util/XCloseable.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
+#include <com/sun/star/io/XInputStream.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_
+#include <com/sun/star/io/XOutputStream.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_EMBED_VERBDESCR_HPP_
+#include <com/sun/star/embed/VerbDescr.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
+#include <com/sun/star/awt/Size.hpp>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE2_HXX_
+#include <cppuhelper/implbase2.hxx>
+#endif
+
+#include <platform.h>
+
+namespace com { namespace sun { namespace star {
+}}}
+
+namespace cppu {
+ class OMultiTypeInterfaceContainerHelper;
+}
+
+class OleWrapperClientSite;
+class OleWrapperAdviseSink;
+class OleEmbeddedObject;
+class OleComponent : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCloseable,
+ ::com::sun::star::datatransfer::XTransferable >
+{
+ ::osl::Mutex m_aMutex;
+ ::cppu::OMultiTypeInterfaceContainerHelper* m_pInterfaceContainer;
+
+ sal_Bool m_bDisposed;
+
+ CComPtr< IUnknown > m_pObj;
+ CComPtr< IOleObject > m_pOleObject;
+ CComPtr< IViewObject2 > m_pViewObject2;
+
+ OleEmbeddedObject* m_pUnoOleObject;
+ OleWrapperClientSite* m_pOleWrapClientSite;
+ OleWrapperAdviseSink* m_pImplAdviseSink;
+
+ ::rtl::OUString m_aTempURL;
+ CComPtr< IStorage > m_pIStorage;
+
+ sal_Int32 m_nMSAspect;
+ sal_Int32 m_nOLEMiscFlags;
+ sal_Int32 m_nAdvConn;
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescr > m_aVerbList;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > m_aDataFlavors;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+
+ sal_uInt16 m_nSupportedFormat;
+ sal_uInt32 m_nSupportedMedium;
+
+
+ sal_Bool InitializeObject_Impl( sal_uInt32 nIconHandle );
+
+ CComPtr< IStorage > CreateIStorageOnXInputStream_Impl(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream );
+ CComPtr< IStorage > CreateNewIStorage_Impl();
+
+ void RetrieveObjectDataFlavors_Impl();
+
+public:
+ OleComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& m_xFactory,
+ OleEmbeddedObject* pOleObj );
+
+ virtual ~OleComponent();
+
+ void disconnectEmbeddedObject();
+
+ // ==== Initialization ==================================================
+ void LoadEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
+ sal_Int64 nAspect );
+
+ void CreateNewEmbeddedObject( const ::com::sun::star::uno::Sequence< sal_Int8 >& aSeqCLSID,
+ sal_Int64 nAspect,
+ sal_uInt32 nIconHandle );
+
+ void CreateObjectFromData(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTransfer,
+ sal_Int64 nAspect );
+
+ void CreateObjectFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle );
+
+ void CreateLinkFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle );
+ // ======================================================================
+
+ void RunObject(); // switch OLE object to running state
+
+ void CloseObject(); // switch OLE object to loaded state
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescr > GetVerbList();
+
+ void ExecuteVerb( sal_Int32 nVerbID );
+
+ void SetHostName( const ::rtl::OUString& aContName, const ::rtl::OUString& aEmbDocName );
+
+ void SetExtent( const ::com::sun::star::awt::Size& aVisAreaSize, sal_Int64 nAspect );
+
+ ::com::sun::star::awt::Size GetExtent( sal_Int64 nAspect );
+
+ sal_Int64 GetViewAspect();
+
+ sal_Int64 GetMiscStatus();
+
+ void StoreObjectToStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream,
+ sal_Bool bStoreVisReplace );
+
+ sal_Bool SaveObject_Impl();
+ sal_Bool OnShowWindow_Impl( sal_Bool bShow );
+ void OnViewChange_Impl( DWORD dwAspect );
+
+ sal_Bool GetGraphicalCache_Impl( const ::com::sun::star::datatransfer::DataFlavor& aFlavor,
+ ::com::sun::star::uno::Any& aResult );
+
+ // XCloseable
+ virtual void SAL_CALL close( sal_Bool DeliverOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
+
+ // XTransferable
+ virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+#endif
+
diff --git a/embeddedobj/source/msole/oleembed.cxx b/embeddedobj/source/msole/oleembed.cxx
new file mode 100644
index 0000000000..666ba6a5b5
--- /dev/null
+++ b/embeddedobj/source/msole/oleembed.cxx
@@ -0,0 +1,374 @@
+/*************************************************************************
+ *
+ * $RCSfile: oleembed.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:13 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <oleembobj.hxx>
+
+#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
+#include <com/sun/star/embed/EmbedStates.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ENTRYINITMODES_HPP_
+#include <com/sun/star/embed/EntryInitModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
+#include <com/sun/star/embed/XStorage.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
+#include <com/sun/star/embed/ElementModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
+#include <com/sun/star/embed/Aspects.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_NEEDSRUNNINGSTATEEXCEPTION_HPP_
+#include <com/sun/star/embed/NeedsRunningStateException.hpp>
+#endif
+
+
+
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
+
+#include <olecomponent.hxx>
+
+using namespace ::com::sun::star;
+
+//----------------------------------------------
+uno::Sequence< sal_Int32 > OleEmbeddedObject::GetReachableStatesList_Impl(
+ const uno::Sequence< embed::VerbDescr >& aVerbList )
+{
+ // TODO: find the sequence
+ return uno::Sequence< sal_Int32 >();
+}
+
+//----------------------------------------------
+uno::Sequence< sal_Int32 > OleEmbeddedObject::GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState )
+{
+ // TODO: find the sequence
+ OSL_ENSURE( m_nObjectState != embed::EmbedStates::EMBED_LOADED, "Loaded object is switched to running state without verbs using!" );
+
+ // actually there will be only one verb
+ if ( m_nObjectState == embed::EmbedStates::EMBED_RUNNING && nNewState == embed::EmbedStates::EMBED_ACTIVE )
+ {
+ uno::Sequence< sal_Int32 > aVerbs( 1 );
+ aVerbs[0] = embed::EmbedVerbs::MS_OLEVERB_OPEN;
+ }
+
+ return uno::Sequence< sal_Int32 >();
+}
+
+//----------------------------------------------
+void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
+ throw ( embed::UnreachableStateException,
+ 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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // in case the object is already in requested state
+ if ( m_nObjectState == nNewState )
+ return;
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ // TODO: additional verbs can be a problem, since nobody knows how the object
+ // will behave after activation
+
+ if ( nNewState == embed::EmbedStates::EMBED_LOADED )
+ {
+ // This means just closing of the current object
+ SaveObject_Impl();
+ m_pOleComponent->CloseObject();
+ }
+ else
+ {
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ {
+ // if the target object is in loaded state and a different state is specified
+ // as a new one the object first must be switched to running state.
+
+ m_pOleComponent->RunObject();
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ if ( m_nObjectState == nNewState )
+ return;
+ }
+
+ // so now the object is either switched from Active to Running state or vise versa
+ if ( m_nObjectState == embed::EmbedStates::EMBED_RUNNING && nNewState == embed::EmbedStates::EMBED_ACTIVE )
+ {
+ // execute OPEN verb, if object does not reach active state it is an object's problem
+ m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN );
+ }
+ else if ( m_nObjectState == embed::EmbedStates::EMBED_ACTIVE && nNewState == embed::EmbedStates::EMBED_RUNNING )
+ {
+ m_pOleComponent->CloseObject();
+ m_pOleComponent->RunObject();
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unreachable code executed!" );
+ }
+ }
+}
+
+//----------------------------------------------
+uno::Sequence< sal_Int32 > SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ {
+ // the list of supported verbs can be retrieved only when object is in running state
+ throw embed::NeedsRunningStateException(); // TODO:
+ }
+
+ // the list of states can only be guessed based on standard verbs,
+ // since there is no way to detect what additional verbs do
+ return GetReachableStatesList_Impl( m_pOleComponent->GetVerbList() );
+}
+
+//----------------------------------------------
+sal_Int32 SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // TODO: Shouldn't we ask object? ( I guess no )
+ return m_nObjectState;
+}
+
+//----------------------------------------------
+void SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ {
+ // if the target object is in loaded state
+ // it must be switched to running state to execute verb
+
+ m_pOleComponent->RunObject();
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ }
+
+ m_pOleComponent->ExecuteVerb( nVerbID );
+}
+
+//----------------------------------------------
+uno::Sequence< embed::VerbDescr > SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ {
+ // the list of supported verbs can be retrieved only when object is in running state
+ throw embed::NeedsRunningStateException(); // TODO:
+ }
+
+ return m_pOleComponent->GetVerbList();
+}
+
+//----------------------------------------------
+void SAL_CALL OleEmbeddedObject::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_nObjectState == -1 )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ m_xClientSite = xClient;
+}
+
+//----------------------------------------------
+uno::Reference< embed::XEmbeddedClient > SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_xClientSite;
+}
+
+//----------------------------------------------
+void SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_EXPLICIT_UPDATE )
+ {
+ // TODO: update view representation
+ }
+ else
+ {
+ // the object must be up to date
+ OSL_ENSURE( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE, "Unknown update mode!\n" );
+ }
+}
+
+//----------------------------------------------
+void SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ OSL_ENSURE( nMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE
+ || nMode == embed::EmbedUpdateModes::EMBED_EXPLICIT_UPDATE,
+ "Unknown update mode!\n" );
+ m_nUpdateMode = nMode;
+}
+
+//----------------------------------------------
+sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64 nAspect )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object must be in running state!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return m_pOleComponent->GetMiscStatus();
+}
+
diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx
new file mode 100644
index 0000000000..bc313a8cd2
--- /dev/null
+++ b/embeddedobj/source/msole/olemisc.cxx
@@ -0,0 +1,282 @@
+/*************************************************************************
+ *
+ * $RCSfile: olemisc.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:14 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
+#include <com/sun/star/embed/EmbedStates.hpp>
+#endif
+
+
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
+
+#include <cppuhelper/interfacecontainer.h>
+
+#include <oleembobj.hxx>
+#include <olecomponent.hxx>
+
+using namespace ::com::sun::star;
+
+//------------------------------------------------------
+OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Sequence< sal_Int8 >& aClassID,
+ const ::rtl::OUString& aClassName )
+: m_pOleComponent( NULL )
+, m_pInterfaceContainer( NULL )
+, m_bReadOnly( sal_False )
+, m_bDisposed( sal_False )
+, m_nObjectState( -1 )
+, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
+, m_bStoreVisRepl( sal_True )
+, m_xFactory( xFactory )
+, m_aClassID( aClassID )
+, m_aClassName( aClassName )
+, m_bWaitSaveCompleted( sal_False )
+, m_bIsLink( sal_False )
+{
+}
+
+//------------------------------------------------------
+// In case of loading from persistent entry the classID of the object
+// will be retrieved from the entry, during construction it is unknown
+OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+: m_pOleComponent( NULL )
+, m_pInterfaceContainer( NULL )
+, m_bReadOnly( sal_False )
+, m_bDisposed( sal_False )
+, m_nObjectState( -1 )
+, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
+, m_bStoreVisRepl( sal_True )
+, m_xFactory( xFactory )
+, m_bWaitSaveCompleted( sal_False )
+, m_bIsLink( sal_False )
+{
+}
+
+
+//------------------------------------------------------
+OleEmbeddedObject::~OleEmbeddedObject()
+{
+ if ( m_pOleComponent )
+ {
+ // the component must be cleaned during disposing
+ OSL_ENSURE( sal_False, "Looks like the object was not disposed - DISASTER is possible!\n" );
+
+ m_pOleComponent->disconnectEmbeddedObject();
+ m_pOleComponent->release();
+ m_pOleComponent = NULL;
+ }
+}
+
+//------------------------------------------------------
+uno::Sequence< sal_Int8 > SAL_CALL OleEmbeddedObject::getClassID()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_aClassID;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OleEmbeddedObject::getClassName()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_aClassName;
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::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< lang::XComponent > SAL_CALL OleEmbeddedObject::getComponent()
+ throw ( uno::RuntimeException )
+{
+ // TODO: The return type will be reference to XInterface
+
+ ::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 embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_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) ) );
+
+ // TODO:
+ return uno::Reference< lang::XComponent >();
+}
+
+// TODO: The object will support XCloseable
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::dispose()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_pInterfaceContainer )
+ {
+ lang::EventObject aEvent( (embed::XEmbeddedObject*)this );
+ m_pInterfaceContainer->disposeAndClear( aEvent );
+
+ delete m_pInterfaceContainer;
+ m_pInterfaceContainer = NULL;
+ }
+
+ if ( m_pOleComponent )
+ {
+ if ( m_nObjectState != embed::EmbedStates::EMBED_LOADED )
+ {
+ SaveObject_Impl();
+ m_pOleComponent->CloseObject();
+ }
+
+ m_pOleComponent->disconnectEmbeddedObject();
+ m_pOleComponent->release();
+ m_pOleComponent = NULL;
+ }
+
+ // TODO: dispose object
+
+ m_bDisposed = true;
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::addEventListener( const uno::Reference< lang::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< lang::XEventListener >*)0 ), xListener );
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::removeEventListener(
+ const uno::Reference< lang::XEventListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_pInterfaceContainer )
+ m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ),
+ xListener );
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::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 OleEmbeddedObject::removeEventListener(
+ 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->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ),
+ xListener );
+}
+
diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx
new file mode 100644
index 0000000000..fe19404837
--- /dev/null
+++ b/embeddedobj/source/msole/olepersist.cxx
@@ -0,0 +1,777 @@
+/*************************************************************************
+ *
+ * $RCSfile: olepersist.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:14 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <oleembobj.hxx>
+
+#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
+#include <com/sun/star/embed/EmbedStates.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ENTRYINITMODES_HPP_
+#include <com/sun/star/embed/EntryInitModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
+#include <com/sun/star/embed/XStorage.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
+#include <com/sun/star/embed/ElementModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_
+#include <com/sun/star/embed/EmbedUpdateModes.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
+#include <com/sun/star/embed/Aspects.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
+#include <com/sun/star/container/XNameAccess.hpp>
+#endif
+
+#include <olecomponent.hxx>
+
+
+using namespace ::com::sun::star;
+
+//----------------------------------------------
+sal_Bool OleEmbeddedObject::SaveObject_Impl()
+{
+ sal_Bool bResult = sal_False;
+
+ if ( m_xClientSite.is() )
+ {
+ try
+ {
+ m_xClientSite->saveObject();
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ return bResult;
+}
+
+//----------------------------------------------
+sal_Bool OleEmbeddedObject::OnShowWindow_Impl( sal_Bool bShow )
+{
+ sal_Bool bResult = sal_False;
+
+ OSL_ENSURE( m_nObjectState != -1, "The object has no persistence!\n" );
+ OSL_ENSURE( m_nObjectState != embed::EmbedStates::EMBED_LOADED, "The object get OnShowWindow in loaded state!\n" );
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ return sal_False;
+
+ // the object is either activated or deactivated
+ if ( bShow && m_nObjectState == embed::EmbedStates::EMBED_RUNNING )
+ m_nObjectState = embed::EmbedStates::EMBED_ACTIVE;
+ else if ( !bShow && m_nObjectState == embed::EmbedStates::EMBED_ACTIVE )
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+
+ if ( m_xClientSite.is() )
+ {
+ try
+ {
+ m_xClientSite->onShowWindow( bShow );
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ return bResult;
+}
+
+//------------------------------------------------------
+void OleEmbeddedObject::CreateOleComponent_Impl()
+{
+ if ( !m_pOleComponent )
+ {
+ m_pOleComponent = new OleComponent( m_xFactory, this );
+ m_pOleComponent->acquire(); // TODO: needs holder?
+ // TODO: register close listener
+ }
+ else
+ OSL_ENSURE( sal_False, "Trying to recreate OLE component!\n" );
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::setPersistentEntry(
+ const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ sal_Int32 nEntryConnectionMode,
+ const uno::Sequence< beans::PropertyValue >& lArguments )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ // the type of the object must be already set
+ // a kind of typedetection should be done in the factory;
+ // the only exception is object initialized from a stream,
+ // the class ID will be detected from the stream
+
+ ::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
+ 2 );
+
+ // May be EMBED_LOADED should be forbidden here ???
+ if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT )
+ && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::ENTRY_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 >( reinterpret_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) ) );
+
+ 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;
+ for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) )
+ lArguments[nInd].Value >>= m_bReadOnly;
+
+ sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::ELEMENT_READ : embed::ElementModes::ELEMENT_READWRITE;
+
+ m_xObjectStream = xStorage->openStreamElement( sEntName, nStorageMode );
+ m_xParentStorage = xStorage;
+ m_aEntryName = sEntName;
+
+ if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_DEFAULT_INIT )
+ {
+ CreateOleComponent_Impl();
+
+ if ( bElExists )
+ {
+ // load object from the stream
+ uno::Reference< io::XInputStream > xInStream = m_xObjectStream->getInputStream();
+ if ( !xInStream.is() )
+ throw io::IOException(); // TODO: access denied
+
+ // after the loading the object can appear as a link
+ // will be detected later by olecomponent
+ m_pOleComponent->LoadEmbeddedObject( xInStream, embed::Aspects::MSASPECT_CONTENT );
+ m_nObjectState = embed::EmbedStates::EMBED_LOADED;
+ }
+ else
+ {
+ // create a new object
+ m_pOleComponent->CreateNewEmbeddedObject( m_aClassID, embed::Aspects::MSASPECT_CONTENT, NULL );
+ m_pOleComponent->RunObject();
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ }
+ }
+ else
+ {
+ if ( ( nStorageMode & embed::ElementModes::ELEMENT_READWRITE ) != embed::ElementModes::ELEMENT_READWRITE )
+ throw io::IOException();
+
+ if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT )
+ {
+ // the document just already changed its stream to store to
+ // the links to OLE documents switch their persistence in the same way
+ // as normal embedded objects
+ }
+ else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRUNCATE_INIT )
+ {
+ // create a new object, that will be stored in specified stream
+ CreateOleComponent_Impl();
+
+ m_pOleComponent->CreateNewEmbeddedObject( m_aClassID, embed::Aspects::MSASPECT_CONTENT, NULL );
+ m_pOleComponent->RunObject();
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ }
+ else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_MEDIA_DESCRIPTOR_INIT )
+ {
+ // use URL ( may be content or stream later ) from MediaDescriptor to initialize object
+ ::rtl::OUString aURL;
+ for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
+ if ( lArguments[nInd].Name.equalsAscii( "URL" ) )
+ lArguments[nInd].Value >>= aURL;
+
+ if ( !aURL.getLength() )
+ throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii( "Empty URL is provided in the media descriptor!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
+ 4 );
+
+ CreateOleComponent_Impl();
+
+ // TODO: the m_bIsLink value must be set already
+ if ( !m_bIsLink )
+ m_pOleComponent->CreateObjectFromFile( aURL, embed::Aspects::MSASPECT_CONTENT, NULL );
+ else
+ m_pOleComponent->CreateLinkFromFile( aURL, embed::Aspects::MSASPECT_CONTENT, NULL );
+
+ m_pOleComponent->RunObject();
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ }
+ //else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRANSFERABLE_INIT )
+ //{
+ //TODO:
+ //}
+ else
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
+ 3 );
+ }
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::storeOwn()
+ throw ( embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ // 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::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 >( reinterpret_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) ) );
+
+ if ( m_bReadOnly )
+ throw io::IOException(); // TODO: access denied
+
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ return; // nothing to do, the object is in loaded state
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
+
+ if ( !m_xObjectStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ if ( m_bIsLink )
+ {
+ // just let the link store itself
+ // in case visual repersentation must be stored also
+ // the procedure should be the same as for embedded objects
+
+ uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ // should the component detect that it is a link???
+ m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
+ xOutStream->closeOutput(); //TODO: allow to reopen the stream object ???
+ }
+ else
+ {
+ uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw io::IOException(); //TODO: access denied
+ m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
+ xOutStream->closeOutput(); //TODO: allow to reopen the stream object ???
+ }
+
+ // TODO:
+ // notify listeners
+ if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
+ {
+ // TODO: update visual representation
+ }
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lArguments )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ 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( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_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) ) );
+
+ OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
+ // ???
+
+ uno::Reference< io::XStream > xTargetStream =
+ xStorage->openStreamElement( sEntName, embed::ElementModes::ELEMENT_READWRITE );
+ if ( !xTargetStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
+ xOutStream->closeOutput();
+
+ uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );
+ if ( xComp.is() )
+ {
+ try {
+ xComp->dispose();
+ } catch( uno::Exception& )
+ {
+ }
+ }
+
+ // TODO: should the listener notification be done?
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName,
+ const uno::Sequence< beans::PropertyValue >& lArguments )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ 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( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_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) ) );
+
+ OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
+ // ???
+
+ uno::Reference< io::XStream > xTargetStream =
+ xStorage->openStreamElement( sEntName, embed::ElementModes::ELEMENT_READWRITE );
+ if ( !xTargetStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw io::IOException(); //TODO: access denied
+
+ m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
+ xOutStream->closeOutput(); // TODO: allow to reuse the stream
+
+ try {
+ uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );
+ OSL_ENSURE( xComp.is(), "Wrong storage implementation!" );
+ if ( xComp.is() )
+ xComp->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ m_bWaitSaveCompleted = sal_True;
+ m_xNewObjectStream = xTargetStream;
+ m_xNewParentStorage = xStorage;
+ m_aEntryName = sEntName;
+
+ // 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 OleEmbeddedObject::saveCompleted( sal_Bool bUseNew )
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ 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( "Can't store object without persistence!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+ }
+
+ OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
+ if ( !m_bWaitSaveCompleted )
+ throw io::IOException(); // TODO: illegal call
+
+ OSL_ENSURE( m_xNewObjectStream.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" );
+ if ( !m_xNewObjectStream.is() || !m_xNewParentStorage.is() )
+ throw uno::RuntimeException(); // TODO: broken internal information
+
+ if ( bUseNew )
+ {
+ // the link object is not linked any more for OOo objects
+ // but since OLE objects have persistence storing them as an entry
+ // does not automatically break the link
+
+ // TODO: it is possible to leave the object in linked state,
+ // but since OOo object will become an embedded persistence after storing,
+ // may be this object must be also stored as embedded one ?
+
+ m_bIsLink = sal_False;
+ m_aLinkURL = ::rtl::OUString();
+
+ try {
+ uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY );
+ OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" );
+ if ( xComponent.is() )
+ xComponent->dispose();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ m_xObjectStream = m_xNewObjectStream;
+ m_xParentStorage = m_xNewParentStorage;
+ m_aEntryName = m_aNewEntryName;
+ }
+
+ m_xNewObjectStream = uno::Reference< io::XStream >();
+ m_xNewParentStorage = uno::Reference< embed::XStorage >();
+ m_aNewEntryName = ::rtl::OUString();
+ m_bWaitSaveCompleted = sal_False;
+
+ if ( bUseNew )
+ {
+ // TODO: notify listeners
+
+ if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
+ {
+ // TODO: update visual representation
+ }
+ }
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OleEmbeddedObject::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( m_xObjectStream.is() )
+ return sal_True;
+
+ return sal_False;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OleEmbeddedObject::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 >( reinterpret_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 m_aEntryName;
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OleEmbeddedObject::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 >( reinterpret_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 m_bReadOnly;
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::reload(
+ const uno::Sequence< beans::PropertyValue >& lArguments )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ 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 >( reinterpret_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) ) );
+
+ // TODO:
+ // throw away current document
+ // load new document from current storage
+ // use meaningfull part of lArguments
+}
+
+//------------------------------------------------------
+void SAL_CALL OleEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
+ const ::rtl::OUString& sEntName )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ io::IOException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
+ 1 );
+
+ if ( !sEntName.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_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 >( reinterpret_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) ) );
+
+ // TODO: if the parent storage and entry are the same as object uses the breaking of link must be done
+ // just by through OLE functionality
+
+ // TODO: if the storage or the name is different the object must be switched to the new storage in addition
+
+#if 0
+ 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 nStreamMode = embed::ElementModes::ELEMENT_READWRITE;
+
+ // only in case object must be switched
+ m_xObjectStream = xStorage->openStreamElement( sEntName, nStreamMode );
+ m_xParentStorage = xStorage;
+ m_aEntryName = sEntName;
+
+ // TODO: ???
+ if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
+ else if ( m_nObjectState == embed::EmbedStates::EMBED_ACTIVE )
+ m_pDocHolder->Show();
+
+ m_bIsLink = sal_False;
+ m_aLinkFilterName = ::rtl::OUString();
+ m_aLinkURL = ::rtl::OUString();
+#endif
+}
+
+//------------------------------------------------------
+sal_Bool SAL_CALL OleEmbeddedObject::isLink()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ return m_bIsLink;
+}
+
+//------------------------------------------------------
+::rtl::OUString SAL_CALL OleEmbeddedObject::getLinkURL()
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ 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 >( 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 >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ // TODO: probably the link URL can be retrieved from OLE
+
+ return m_aLinkURL;
+}
+
diff --git a/embeddedobj/source/msole/olevisual.cxx b/embeddedobj/source/msole/olevisual.cxx
new file mode 100644
index 0000000000..e8bb759d83
--- /dev/null
+++ b/embeddedobj/source/msole/olevisual.cxx
@@ -0,0 +1,142 @@
+/*************************************************************************
+ *
+ * $RCSfile: olevisual.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:14 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
+#include <com/sun/star/embed/EmbedStates.hpp>
+#endif
+
+#include <oleembobj.hxx>
+#include <olecomponent.hxx>
+
+
+using namespace ::com::sun::star;
+
+void SAL_CALL OleEmbeddedObject::setContainerName( const ::rtl::OUString& sName )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ m_aContainerName = sName;
+}
+
+void SAL_CALL OleEmbeddedObject::setVisAreaSize( 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
+
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ m_pOleComponent->SetExtent( aSize, nAspect ); // will throw an exception in case of failure
+}
+
+awt::Size SAL_CALL OleEmbeddedObject::getVisAreaSize( sal_Int64 nAspect )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ if ( !m_pOleComponent )
+ throw uno::RuntimeException();
+
+ return m_pOleComponent->GetExtent( nAspect ); // will throw an exception in case of failure
+}
+
+// Probably will be removed!!!
+uno::Any SAL_CALL OleEmbeddedObject::getVisualCache( sal_Int64 nAspect )
+ throw ( uno::Exception,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( m_bDisposed )
+ throw lang::DisposedException(); // TODO
+
+ if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
+ throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
+ uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
+
+ return uno::makeAny( uno::Sequence< sal_Int8 >() );
+}
+
+
diff --git a/embeddedobj/source/msole/olewrapclient.cxx b/embeddedobj/source/msole/olewrapclient.cxx
new file mode 100644
index 0000000000..891bb84b48
--- /dev/null
+++ b/embeddedobj/source/msole/olewrapclient.cxx
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * $RCSfile: olewrapclient.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:15 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <osl/diagnose.h>
+
+#include "olewrapclient.hxx"
+#include "olecomponent.hxx"
+
+// TODO: May be a mutex must be introduced
+
+OleWrapperClientSite::OleWrapperClientSite( OleComponent* pOleComp )
+: m_nRefCount( 0 )
+, m_pOleComp( pOleComp )
+{
+ OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
+}
+
+OleWrapperClientSite::~OleWrapperClientSite()
+{
+}
+
+STDMETHODIMP OleWrapperClientSite::QueryInterface( REFIID riid , void** ppv )
+{
+ *ppv=NULL;
+
+ if ( riid == IID_IUnknown )
+ *ppv = (IUnknown*)this;
+
+ if ( riid == IID_IOleClientSite )
+ *ppv = (IOleClientSite*)this;
+
+ if ( *ppv != NULL )
+ {
+ ((IUnknown*)*ppv)->AddRef();
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) OleWrapperClientSite::AddRef()
+{
+ return osl_incrementInterlockedCount( &m_nRefCount);
+}
+
+STDMETHODIMP_(ULONG) OleWrapperClientSite::Release()
+{
+ ULONG nReturn = --m_nRefCount;
+ if ( m_nRefCount == 0 )
+ delete this;
+
+ return nReturn;
+}
+
+void OleWrapperClientSite::disconnectOleComponent()
+{
+ // must not be called from the descructor of OleComponent!!!
+ osl::MutexGuard aGuard( m_aMutex );
+ m_pOleComp = NULL;
+}
+
+STDMETHODIMP OleWrapperClientSite::SaveObject()
+{
+ OleComponent* pLockComponent = NULL;
+ HRESULT hResult = E_FAIL;
+
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pOleComp )
+ {
+ pLockComponent = m_pOleComp;
+ pLockComponent->acquire();
+ }
+ }
+
+ if ( pLockComponent )
+ {
+ if ( pLockComponent->SaveObject_Impl() )
+ hResult = S_OK;
+
+ pLockComponent->release();
+ }
+
+ return hResult;
+}
+
+STDMETHODIMP OleWrapperClientSite::GetMoniker( DWORD dwAssign, DWORD dwWhich, LPMONIKER *ppmk )
+{
+ *ppmk = NULL;
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP OleWrapperClientSite::GetContainer( LPOLECONTAINER* ppContainer )
+{
+ *ppContainer = NULL;
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP OleWrapperClientSite::ShowObject(void)
+{
+ return S_OK;
+}
+
+STDMETHODIMP OleWrapperClientSite::OnShowWindow( BOOL bShow )
+{
+ OleComponent* pLockComponent = NULL;
+
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( m_pOleComp )
+ {
+ pLockComponent = m_pOleComp;
+ pLockComponent->acquire();
+ }
+ }
+
+ if ( pLockComponent )
+ {
+ pLockComponent->OnShowWindow_Impl( bShow ); // the result is not interesting
+ pLockComponent->release();
+ }
+
+ return S_OK;
+}
+
+STDMETHODIMP OleWrapperClientSite::RequestNewObjectLayout(void)
+{
+ return E_NOTIMPL;
+}
+
diff --git a/embeddedobj/source/msole/olewrapclient.hxx b/embeddedobj/source/msole/olewrapclient.hxx
new file mode 100644
index 0000000000..4057b09c1f
--- /dev/null
+++ b/embeddedobj/source/msole/olewrapclient.hxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * $RCSfile: olewrapclient.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:33 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <osl/interlck.h>
+#include <osl/mutex.hxx>
+#include <platform.h>
+
+class OleComponent;
+class OleWrapperClientSite : public IOleClientSite
+{
+ osl::Mutex m_aMutex;
+ oslInterlockedCount m_nRefCount;
+ OleComponent* m_pOleComp;
+
+public:
+ OleWrapperClientSite( OleComponent* pOleComp );
+ ~OleWrapperClientSite(void);
+
+ void disconnectOleComponent();
+
+ STDMETHODIMP QueryInterface(REFIID, void**);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP SaveObject(void);
+ STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
+ STDMETHODIMP GetContainer(LPOLECONTAINER *);
+ STDMETHODIMP ShowObject(void);
+ STDMETHODIMP OnShowWindow(BOOL);
+ STDMETHODIMP RequestNewObjectLayout(void);
+};
+
diff --git a/embeddedobj/source/msole/platform.h b/embeddedobj/source/msole/platform.h
new file mode 100644
index 0000000000..3ae7a78783
--- /dev/null
+++ b/embeddedobj/source/msole/platform.h
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * $RCSfile: platform.h,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: mav $ $Date: 2003-11-13 17:01:50 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _PLATFORM_H_
+#define _PLATFORM_H_
+
+#define STRICT
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0400
+#endif
+#define _ATL_APARTMENT_THREADED
+
+#include "windows.h"
+#include "atlcomcli.h"
+
+#endif
+