summaryrefslogtreecommitdiffstats
path: root/embeddedobj/source/msole
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2003-11-26 15:44:04 +0000
committerMikhail Voitenko <mav@openoffice.org>2003-11-26 15:44:04 +0000
commit586d6b72db065b86efa7940a91d0e02b8ac44f0c (patch)
treec6e8c6bf719df783d7581d6ae0dd0c4293fa1cbe /embeddedobj/source/msole
parent#112923# ole link breaking (diff)
downloadcore-586d6b72db065b86efa7940a91d0e02b8ac44f0c.tar.gz
core-586d6b72db065b86efa7940a91d0e02b8ac44f0c.zip
#112923# breaking of ole link and assertion fixes
Diffstat (limited to 'embeddedobj/source/msole')
-rw-r--r--embeddedobj/source/msole/olecomponent.cxx91
-rw-r--r--embeddedobj/source/msole/olepersist.cxx8
2 files changed, 80 insertions, 19 deletions
diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx
index 9a508b9e62ed..7a68d7914ea2 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: olecomponent.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: mav $ $Date: 2003-11-26 10:27:47 $
+ * last change: $Author: mav $ $Date: 2003-11-26 16:44:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -727,22 +727,83 @@ void OleComponent::InitEmbeddedCopyOfLink( OleComponent* pOleLinkComponent )
CComPtr< IDataObject > pDataObject;
HRESULT hr = pOleLinkComponent->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject );
- if ( FAILED( hr ) || !pDataObject || OleQueryCreateFromData( pDataObject ) )
- throw io::IOException(); // TODO: the object doesn't allow initialization based on data
+ if ( SUCCEEDED( hr ) && pDataObject && SUCCEEDED( OleQueryCreateFromData( pDataObject ) ) )
+ {
+ m_pIStorage = CreateNewIStorage_Impl();
+ if ( !m_pIStorage )
+ throw uno::RuntimeException(); // TODO:
+
+
+ hr = OleCreateFromData( pDataObject,
+ IID_IUnknown,
+ OLERENDER_DRAW,
+ NULL,
+ NULL,
+ m_pIStorage,
+ (void**)&m_pObj );
+ }
- m_pIStorage = CreateNewIStorage_Impl();
- if ( !m_pIStorage )
- throw uno::RuntimeException(); // TODO:
+ if ( !m_pObj )
+ {
+ CComPtr< IOleLink > pOleLink;
+ hr = pOleLinkComponent->m_pObj->QueryInterface( IID_IOleLink, (void**)&pOleLink );
+ if ( FAILED( hr ) || !pOleLink )
+ throw io::IOException(); // TODO: the object doesn't support IOleLink
+
+ CComPtr< IMoniker > pMoniker;
+ hr = pOleLink->GetSourceMoniker( &pMoniker );
+ if ( FAILED( hr ) || !pMoniker )
+ throw io::IOException(); // TODO: can not retrieve moniker
+
+ // In case of file moniker life is easy :)
+ DWORD aMonType = 0;
+ hr = pMoniker->IsSystemMoniker( &aMonType );
+ if ( SUCCEEDED( hr ) && aMonType == MKSYS_FILEMONIKER )
+ {
+ CComPtr< IMalloc > pMalloc;
+ CoGetMalloc( 1, &pMalloc ); // if fails there will be a memory leak
+ OSL_ENSURE( pMalloc, "CoGetMalloc() failed!" );
- hr = OleCreateFromData( pDataObject,
- IID_IUnknown,
- OLERENDER_DRAW,
- NULL,
- NULL,
- m_pIStorage,
- (void**)&m_pObj );
+ LPOLESTR pOleStr = NULL;
+ hr = pOleLink->GetSourceDisplayName( &pOleStr );
+ if ( SUCCEEDED( hr ) && pOleStr )
+ {
+ ::rtl::OUString aFilePath( (sal_Unicode*)pOleStr );
+ if ( pMalloc )
+ pMalloc->Free( (void*)pOleStr );
- if ( FAILED( hr ) || !m_pObj)
+ hr = OleCreateFromFile( CLSID_NULL,
+ aFilePath.getStr(),
+ IID_IUnknown,
+ OLERENDER_DRAW, // OLERENDER_FORMAT
+ NULL,
+ NULL,
+ m_pIStorage,
+ (void**)&m_pObj );
+ }
+ }
+
+ // in case of other moniker types the only way is to get storage
+ if ( !m_pObj )
+ {
+ CComPtr< IBindCtx > pBindCtx;
+ hr = CreateBindCtx( 0, (LPBC FAR*)&pBindCtx );
+ if ( SUCCEEDED( hr ) && pBindCtx )
+ {
+ CComPtr< IStorage > pObjectStorage;
+ hr = pMoniker->BindToStorage( pBindCtx, NULL, IID_IStorage, (void**)&pObjectStorage );
+ if ( SUCCEEDED( hr ) && pObjectStorage )
+ {
+ hr = pObjectStorage->CopyTo( 0, NULL, NULL, m_pIStorage );
+ if ( SUCCEEDED( hr ) )
+ hr = OleLoad( m_pIStorage, IID_IUnknown, NULL, (void**)&m_pObj );
+ }
+ }
+ }
+ }
+
+ // If object could not be created the only way is to use graphical representation
+ if ( FAILED( hr ) || !m_pObj )
throw uno::RuntimeException(); // TODO
// TODO: May be the Icon should be also copied?
diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx
index 30a8334c2ae9..c39889ac2066 100644
--- a/embeddedobj/source/msole/olepersist.cxx
+++ b/embeddedobj/source/msole/olepersist.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: olepersist.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: mav $ $Date: 2003-11-26 10:27:48 $
+ * last change: $Author: mav $ $Date: 2003-11-26 16:44:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -111,7 +111,7 @@ void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStor
{
try {
uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY );
- OSL_ENSURE( xComponent.is(), "Wrong stream implementation!" );
+ OSL_ENSURE( !m_xObjectStream.is() || xComponent.is(), "Wrong stream implementation!" );
if ( xComponent.is() )
xComponent->dispose();
}
@@ -766,7 +766,7 @@ void SAL_CALL OleEmbeddedObject::breakLink( const uno::Reference< embed::XStorag
GetRidOfComponent();
CreateOleComponent_Impl( pNewOleComponent );
- if ( m_xParentStorage != xStorage || !m_aNewEntryName.equals( sEntName ) )
+ if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) )
SwitchOwnPersistence( xStorage, sEntName );
if ( m_nObjectState != embed::EmbedStates::EMBED_LOADED )