diff options
Diffstat (limited to 'embeddedobj')
-rw-r--r-- | embeddedobj/source/inc/oleembobj.hxx | 7 | ||||
-rw-r--r-- | embeddedobj/source/msole/olecomponent.cxx | 89 | ||||
-rw-r--r-- | embeddedobj/source/msole/olecomponent.hxx | 6 | ||||
-rw-r--r-- | embeddedobj/source/msole/olemisc.cxx | 8 | ||||
-rw-r--r-- | embeddedobj/source/msole/olepersist.cxx | 8 | ||||
-rw-r--r-- | embeddedobj/test/Container1/EmbedContApp.java | 147 | ||||
-rw-r--r-- | embeddedobj/test/Container1/makefile.mk | 6 |
7 files changed, 219 insertions, 52 deletions
diff --git a/embeddedobj/source/inc/oleembobj.hxx b/embeddedobj/source/inc/oleembobj.hxx index c38e7fbc7d78..10f4c9819ba9 100644 --- a/embeddedobj/source/inc/oleembobj.hxx +++ b/embeddedobj/source/inc/oleembobj.hxx @@ -2,9 +2,9 @@ * * $RCSfile: oleembobj.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: mav $ $Date: 2003-11-20 17:02:21 $ + * last change: $Author: mav $ $Date: 2003-11-24 16:12:34 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -184,7 +184,8 @@ public: // in case object will be loaded from a persistent entry or from a file the class ID will be detected on loading // factory can do it for OOo objects, but for OLE objects OS dependent code is required - OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); + OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + sal_Bool bLink ); virtual ~OleEmbeddedObject(); diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx index 2680c3603655..a9dff7705c24 100644 --- a/embeddedobj/source/msole/olecomponent.cxx +++ b/embeddedobj/source/msole/olecomponent.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olecomponent.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: mav $ $Date: 2003-11-24 09:42:58 $ + * last change: $Author: mav $ $Date: 2003-11-24 16:12:38 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -103,6 +103,12 @@ using namespace ::com::sun::star; #define MAX_ENUM_ELE 20 const sal_Int32 n_ConstBufferSize = 32000; + +uno::Sequence< sal_Int8 > GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, + sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11, + sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 ); + +//---------------------------------------------- STDAPI StarObject_SwitchDisplayAspect(IUnknown *pObj, LPDWORD pdwCurAspect , DWORD dwNewAspect, HGLOBAL hMetaPict, BOOL fDeleteOld , BOOL fViewAdvise, IAdviseSink *pSink, BOOL *pfMustUpdate) @@ -111,7 +117,7 @@ STDAPI StarObject_SwitchDisplayAspect(IUnknown *pObj, LPDWORD pdwCurAspect 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 @@ -650,15 +656,66 @@ void OleComponent::CreateObjectFromData( const uno::Reference< datatransfer::XTr } //---------------------------------------------- -void OleComponent::CreateObjectFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle ) +void OleComponent::CreateObjectFromFile( const ::rtl::OUString& aFileURL, sal_Int64 nAspect, sal_uInt32 nIconHandle ) { - // TODO: + if ( m_pIStorage || m_aTempURL.getLength() ) + throw frame::DoubleInitializationException(); // the object is already initialized + + m_nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects + + m_pIStorage = CreateNewIStorage_Impl(); + if ( !m_pIStorage ) + throw uno::RuntimeException(); // TODO: + + ::rtl::OUString aFilePath; + if ( ::osl::FileBase::getSystemPathFromFileURL( aFileURL, aFilePath ) != ::osl::FileBase::E_None ) + throw uno::RuntimeException(); // TODO: something dangerous happend + + HRESULT hr = OleCreateFromFile( CLSID_NULL, + aFilePath.getStr(), + IID_IUnknown, + OLERENDER_DRAW, // OLERENDER_FORMAT + NULL, + NULL, + m_pIStorage, + (void**)&m_pObj ); + + if ( FAILED( hr ) || !m_pObj) + throw uno::RuntimeException(); // TODO + + if ( !InitializeObject_Impl( nIconHandle ) ) + throw uno::RuntimeException(); // TODO } //---------------------------------------------- -void OleComponent::CreateLinkFromFile( const ::rtl::OUString& aFileName, sal_Int64 nAspect, sal_uInt32 nIconHandle ) +void OleComponent::CreateLinkFromFile( const ::rtl::OUString& aFileURL, sal_Int64 nAspect, sal_uInt32 nIconHandle ) { - // TODO: + if ( m_pIStorage || m_aTempURL.getLength() ) + throw frame::DoubleInitializationException(); // the object is already initialized + + m_nMSAspect = (DWORD)nAspect; // first 32 bits are for MS aspects + + m_pIStorage = CreateNewIStorage_Impl(); + if ( !m_pIStorage ) + throw uno::RuntimeException(); // TODO: + + ::rtl::OUString aFilePath; + if ( ::osl::FileBase::getSystemPathFromFileURL( aFileURL, aFilePath ) != ::osl::FileBase::E_None ) + throw uno::RuntimeException(); // TODO: something dangerous happend + + HRESULT hr = OleCreateLinkToFile( aFilePath.getStr(), + IID_IUnknown, + OLERENDER_DRAW, // OLERENDER_FORMAT + NULL, + NULL, + m_pIStorage, + (void**)&m_pObj ); + + if ( FAILED( hr ) || !m_pObj) + throw uno::RuntimeException(); // TODO + + if ( !InitializeObject_Impl( nIconHandle ) ) + throw uno::RuntimeException(); // TODO } //---------------------------------------------- @@ -793,6 +850,24 @@ sal_Int64 OleComponent::GetMiscStatus() } //---------------------------------------------- +uno::Sequence< sal_Int8 > OleComponent::GetCLSID() +{ + if ( !m_pOleObject ) + throw embed::WrongStateException(); // TODO: the object is in wrong state + + GUID aCLSID; + HRESULT hr = m_pOleObject->GetUserClassID( &aCLSID ); + if ( FAILED( hr ) ) + throw io::IOException(); // TODO: + + return GetSequenceClassID( aCLSID.Data1, aCLSID.Data2, aCLSID.Data3, + aCLSID.Data4[0], aCLSID.Data4[1], + aCLSID.Data4[2], aCLSID.Data4[3], + aCLSID.Data4[4], aCLSID.Data4[5], + aCLSID.Data4[6], aCLSID.Data4[7] ); +} + +//---------------------------------------------- sal_Int64 OleComponent::GetViewAspect() { if ( !m_pOleObject ) diff --git a/embeddedobj/source/msole/olecomponent.hxx b/embeddedobj/source/msole/olecomponent.hxx index af17009295e2..a9acc7625254 100644 --- a/embeddedobj/source/msole/olecomponent.hxx +++ b/embeddedobj/source/msole/olecomponent.hxx @@ -2,9 +2,9 @@ * * $RCSfile: olecomponent.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-11-17 16:19:24 $ + * last change: $Author: mav $ $Date: 2003-11-24 16:12:39 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -201,6 +201,8 @@ public: sal_Int64 GetMiscStatus(); + ::com::sun::star::uno::Sequence< sal_Int8 > GetCLSID(); + void StoreObjectToStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream, sal_Bool bStoreVisReplace ); diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx index 3cf36d8b5b72..f901c0870160 100644 --- a/embeddedobj/source/msole/olemisc.cxx +++ b/embeddedobj/source/msole/olemisc.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olemisc.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: mav $ $Date: 2003-11-20 17:02:23 $ + * last change: $Author: mav $ $Date: 2003-11-24 16:12:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -102,7 +102,7 @@ OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceF //------------------------------------------------------ // 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 ) +OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, sal_Bool bLink ) : m_pOleComponent( NULL ) , m_pInterfaceContainer( NULL ) , m_bReadOnly( sal_False ) @@ -112,7 +112,7 @@ OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceF , m_bStoreVisRepl( sal_True ) , m_xFactory( xFactory ) , m_bWaitSaveCompleted( sal_False ) -, m_bIsLink( sal_False ) +, m_bIsLink( bLink ) { } diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx index ce43cd5200e1..27aed1ebc25f 100644 --- a/embeddedobj/source/msole/olepersist.cxx +++ b/embeddedobj/source/msole/olepersist.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olepersist.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: mav $ $Date: 2003-11-24 09:42:10 $ + * last change: $Author: mav $ $Date: 2003-11-24 16:12:41 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -273,6 +273,8 @@ void SAL_CALL OleEmbeddedObject::setPersistentEntry( // 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_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction + m_nObjectState = embed::EmbedStates::EMBED_LOADED; } else @@ -326,6 +328,8 @@ void SAL_CALL OleEmbeddedObject::setPersistentEntry( m_pOleComponent->CreateLinkFromFile( aURL, embed::Aspects::MSASPECT_CONTENT, NULL ); m_pOleComponent->RunObject(); + m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction + m_nObjectState = embed::EmbedStates::EMBED_RUNNING; } //else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRANSFERABLE_INIT ) diff --git a/embeddedobj/test/Container1/EmbedContApp.java b/embeddedobj/test/Container1/EmbedContApp.java index a9f1e7f785f0..1f5aa0fc58bd 100644 --- a/embeddedobj/test/Container1/EmbedContApp.java +++ b/embeddedobj/test/Container1/EmbedContApp.java @@ -19,6 +19,8 @@ import com.sun.star.uno.Any; import com.sun.star.lang.XComponent; import com.sun.star.util.XCloseable; +import com.sun.star.util.XURLTransformer; +import com.sun.star.util.URL; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.NamedValue; @@ -70,6 +72,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie private Object m_oInHandlerLock; private boolean m_bInHandler = false; + private XURLTransformer m_xTransformer; + // Constants private final byte DESTROY = 1; private final byte MOUSE_CLICKED = 2; @@ -96,6 +100,11 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie m_aToolkit = Toolkit.getDefaultToolkit(); + try { + Object oTransformer = m_xServiceFactory.createInstance( "com.sun.star.util.URLTransformer" ); + m_xTransformer = (XURLTransformer)UnoRuntime.queryInterface( XURLTransformer.class, oTransformer ); + } catch( Exception e ) { System.exit( 0 ); } + m_pActionsList = new byte[200]; m_nActionsNumber = 0; m_oActionsNumberLock = new Object(); @@ -246,14 +255,14 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( aFile != null ) { // create object from specified file - String aFileURI = aFile.toURI().toASCIIString(); + String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); try { - saveObject(); - + /* if ( m_bLinkObj ) - storeLinkToStorage(); - - saveStorageAsFileURI( aFileURI ); + storeLinkAsFileURI( aFileURI ); + else + */ + saveObjectAsFileURI( aFileURI ); } catch( Exception ex ) { @@ -283,7 +292,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( aFile != null ) { // create object from specified file - String aFileURI = aFile.toURI().toASCIIString(); + String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); // load from specified file loadFileURI( aFileURI ); @@ -360,14 +369,14 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( aFile != null ) { // create object from specified file - String aFileURI = aFile.toURI().toASCIIString(); + String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); try { - saveObject(); - + /* if ( m_bLinkObj ) - storeLinkToStorage(); - - saveStorageAsFileURI( aFileURI ); + storeLinkAsFileURI( aFileURI ); + else + */ + saveObjectAsFileURI( aFileURI ); } catch( Exception ex ) { @@ -447,7 +456,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( aFile != null ) { // create object from specified file - String aFileURI = aFile.toURI().toASCIIString(); + String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); m_xStorage = createTempStorage(); if ( m_xStorage != null ) @@ -489,7 +498,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( aFile != null ) { // create object from specified file - String aFileURI = aFile.toURI().toASCIIString(); + String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); m_xEmbedObj = createLinkObject( aFileURI ); @@ -954,7 +963,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie oEmbedFactory ); if ( xEmbedFactory != null ) { - Object oEmbObj = xEmbedFactory.createInstanceLink( aLinkURL ); + Object oEmbObj = xEmbedFactory.createInstanceLink( m_xStorage, "EmbedSub", aLinkURL, true ); xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); } else @@ -990,7 +999,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie aMedDescr[1].Value = (Object) new Boolean( false ); Object oEmbObj = xEmbedFactory.createInstanceInitFromMediaDescriptor( m_xStorage, "EmbedSub", - aMedDescr ); + aMedDescr, + true ); xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); } else @@ -1022,9 +1032,9 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie if ( m_xEmbedObj != null ) { try { - XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xEmbedObj ); - if ( xComponent != null ) - xComponent.dispose(); + XCloseable xClose = (XCloseable)UnoRuntime.queryInterface( XCloseable.class, m_xEmbedObj ); + if ( xClose != null ) + xClose.close( true ); } catch ( Exception ex ) {} @@ -1072,7 +1082,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie return xTempStorage; } - public void saveStorageAsFileURI( String aFileURI ) + public void saveObjectAsFileURI( String aFileURI ) { try { Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); @@ -1081,19 +1091,33 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie oStorageFactory ); if ( xStorageFactory != null ) { - Object aArgs[] = new Object[2]; - aArgs[0] = aFileURI; - aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); + XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj ); + if ( xPersist != null ) + { + Object aArgs[] = new Object[2]; + aArgs[0] = aFileURI; + aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); - Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); - XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); - m_xStorage.copyToStorage( xTargetStorage ); + Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); + XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); - XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); - xComponent.dispose(); + xPersist.storeAsEntry( xTargetStorage, "EmbedSub", new PropertyValue[0] ); + xPersist.saveCompleted( true ); - m_xStorage = xTargetStorage; - m_bOwnFile = true; + // the object must be already based on new storage + XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); + xComponent.dispose(); + + m_xStorage = xTargetStorage; + m_bOwnFile = true; + + XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, + m_xStorage ); + if ( xTransact != null ) + xTransact.commit(); + } + else + JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE ); } else JOptionPane.showMessageDialog( m_aFrame, @@ -1139,6 +1163,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie Object oEmbObj = null; if ( xNameAccess.hasByName( "LinkName" ) && xTargetStorage.isStreamElement( "LinkName" ) ) { + /* XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ ); if ( xLinkStream != null ) { @@ -1153,6 +1178,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie m_bLinkObj = true; } } + */ } else oEmbObj = xEmbedFactory.createInstanceInitFromEntry( xTargetStorage, @@ -1230,5 +1256,64 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie } } } + + public void storeLinkAsFileURI( String aFileURI ) + { + try { + Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); + XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( + XSingleServiceFactory.class, + oStorageFactory ); + if ( xStorageFactory != null ) + { + Object aArgs[] = new Object[2]; + aArgs[0] = aFileURI; + aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); + + Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); + XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); + + XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); + xComponent.dispose(); + + m_xStorage = xTargetStorage; + m_bOwnFile = true; + + storeLinkToStorage(); + + XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, + m_xStorage ); + if ( xTransact != null ) + xTransact.commit(); + } + else + JOptionPane.showMessageDialog( m_aFrame, + "Can't create StorageFactory!", + "Error:", + JOptionPane.ERROR_MESSAGE ); + } + catch( Exception e ) + { + JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE ); + } + } + + public String getValidURL( String sFileURL ) + { + // m_xTransformer must be set! + URL[] aURLs = { new URL() }; + aURLs[0].Complete = sFileURL; + + try { + if ( !m_xTransformer.parseSmart( aURLs, "" ) ) + throw new Exception(); + } + catch( Exception e ) + { + JOptionPane.showMessageDialog( m_aFrame, e, "Exception in getValidURL():", JOptionPane.ERROR_MESSAGE ); + } + + return aURLs[0].Complete; + } } diff --git a/embeddedobj/test/Container1/makefile.mk b/embeddedobj/test/Container1/makefile.mk index f6f64fa21d26..19b60e0a2551 100644 --- a/embeddedobj/test/Container1/makefile.mk +++ b/embeddedobj/test/Container1/makefile.mk @@ -3,9 +3,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.3 $ # -# last change: $Date: 2003-11-20 15:55:19 $ +# last change: $Date: 2003-11-24 16:12:44 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -95,7 +95,7 @@ JavaStorageTestExample : $(CLASSFILES) @echo -------------------------------------------------------------------------------- run: $(CLASSFILES) - jdb -classpath "$(CLASSPATH)" EmbedContFrame + java -classpath "$(CLASSPATH)" EmbedContFrame clean : -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS)) |