diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2006-02-09 12:37:13 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2006-02-09 12:37:13 +0000 |
commit | f727d23cc869866eceefdd0b8ef6b18a1fc8f6c6 (patch) | |
tree | 2f6fad46175abe588281dc01b2b8240741cd4efa | |
parent | 5f9177a7ecf70b059de1dbe17c6788a4e443360e (diff) |
INTEGRATION: CWS rtfpp2 (1.14.12); FILE MERGED
2006/02/06 16:13:05 mba 1.14.12.2: #128676#: wrong dirty flag implementation
2005/12/09 11:29:50 mav 1.14.12.1: #128676# truncate the stream before writing
-rwxr-xr-x | embedserv/source/embed/ed_ipersiststr.cxx | 137 |
1 files changed, 78 insertions, 59 deletions
diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx index 2d0f58b34..c70c6aadb 100755 --- a/embedserv/source/embed/ed_ipersiststr.cxx +++ b/embedserv/source/embed/ed_ipersiststr.cxx @@ -4,9 +4,9 @@ * * $RCSfile: ed_ipersiststr.cxx,v $ * - * $Revision: 1.15 $ + * $Revision: 1.16 $ * - * last change: $Author: obo $ $Date: 2006-01-20 09:53:18 $ + * last change: $Author: rt $ $Date: 2006-02-09 13:37:13 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -64,6 +64,9 @@ #ifndef _COM_SUN_STAR_FRAME_XLOADABLE_HPP_ #include <com/sun/star/frame/XLoadable.hpp> #endif +#ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_ +#include <com/sun/star/util/XModifiable.hpp> +#endif #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_ #include <com/sun/star/frame/XStorable.hpp> #endif @@ -97,17 +100,17 @@ extern ::rtl::OUString getFilterNameFromGUID_Impl( GUID* ); const ::rtl::OUString aOfficeEmbedStreamName( RTL_CONSTASCII_USTRINGPARAM ( "package_stream" ) ); const ::rtl::OUString aExtentStreamName( RTL_CONSTASCII_USTRINGPARAM ( "properties_stream" ) ); -uno::Reference< io::XInputStream > createTempXInStreamFromIStream( - uno::Reference< lang::XMultiServiceFactory > xFactory, +uno::Reference< io::XInputStream > createTempXInStreamFromIStream( + uno::Reference< lang::XMultiServiceFactory > xFactory, IStream *pStream ) { uno::Reference< io::XInputStream > xResult; if ( !pStream ) return xResult; - + const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( + uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( xFactory->createInstance ( aServiceName ), uno::UNO_QUERY ); if ( xTempOut.is() ) @@ -116,7 +119,7 @@ uno::Reference< io::XInputStream > createTempXInStreamFromIStream( LARGE_INTEGER aZero = { 0L, 0L }; HRESULT hr = pStream->Seek( aZero, STREAM_SEEK_SET, &nNewPos ); if ( FAILED( hr ) ) return xResult; - + STATSTG aStat; hr = pStream->Stat( &aStat, STATFLAG_NONAME ); if ( FAILED( hr ) ) return xResult; @@ -130,10 +133,10 @@ uno::Reference< io::XInputStream > createTempXInStreamFromIStream( do { pStream->Read( (void*)aBuffer.getArray(), nConstBufferSize, &nRead ); - + if ( nRead < nConstBufferSize ) aBuffer.realloc( nRead ); - + xTempOut->writeBytes( aBuffer ); nCopied += nRead; } while( nRead == nConstBufferSize ); @@ -182,7 +185,7 @@ HRESULT copyXTempOutToIStream( uno::Reference< io::XOutputStream > xTempOut, ISt uno::Sequence< sal_Int8 > aBuffer( nConstBufferSize ); sal_uInt32 nReadBytes = 0; - + do { try { @@ -197,7 +200,7 @@ HRESULT copyXTempOutToIStream( uno::Reference< io::XOutputStream > xTempOut, ISt HRESULT hr = pStream->Write( (void*)aBuffer.getArray(), nReadBytes, &nWritten ); if ( !SUCCEEDED( hr ) || nWritten != nReadBytes ) return E_FAIL; - + } while( nReadBytes == nConstBufferSize ); return S_OK; @@ -218,7 +221,7 @@ EmbedDocument_Impl::EmbedDocument_Impl( const uno::Reference< lang::XMultiServic { m_pDocHolder = new DocumentHolder( xFactory,this ); m_pDocHolder->acquire(); -} +} EmbedDocument_Impl::~EmbedDocument_Impl() { @@ -295,7 +298,7 @@ HRESULT EmbedDocument_Impl::SaveTo_Impl( IStorage* pStg ) if ( !pStg || pStg == m_pMasterStorage ) return E_FAIL; - // for saveto operation the master storage + // for saveto operation the master storage // should not enter NoScribble mode CComPtr< IStream > pOrigOwn = m_pOwnStream; CComPtr< IStream > pOrigExt = m_pExtStream; @@ -316,7 +319,7 @@ STDMETHODIMP EmbedDocument_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv AddRef(); *ppv = (IUnknown*) (IPersistStorage*) this; return S_OK; - } + } else if (IsEqualIID(riid, IID_IPersist)) { AddRef(); @@ -381,9 +384,9 @@ STDMETHODIMP_(ULONG) EmbedDocument_Impl::Release() sal_Int32 nCount = --m_refCount; if ( nCount == 0 ) { - delete this; + delete this; } - + return nCount; } @@ -401,13 +404,19 @@ STDMETHODIMP EmbedDocument_Impl::GetClassID( CLSID* pClassId ) STDMETHODIMP EmbedDocument_Impl::IsDirty() { - return m_bIsDirty ? S_OK : S_FALSE; + if ( m_bIsDirty ) + return S_OK; + + uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( xMod.is() ) + return xMod->isModified() ? S_OK : S_FALSE; + return S_FALSE; } STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) { HRESULT hr = CO_E_ALREADYINITIALIZED; - + if ( !m_pDocHolder->GetDocument().is() ) { @@ -420,8 +429,8 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) hr = E_FAIL; if ( m_xFactory.is() && pStg ) { - uno::Reference< frame::XModel > aDocument( - m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), + uno::Reference< frame::XModel > aDocument( + m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), uno::UNO_QUERY ); if ( aDocument.is() ) { @@ -440,7 +449,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) { } } - + if ( hr == S_OK ) { ::rtl::OUString aCurType = getStorageTypeFromGUID_Impl( &m_guid ); // ??? @@ -451,23 +460,23 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) if ( hr == S_OK ) { - hr = pStg->CreateStream( aOfficeEmbedStreamName, - STGM_CREATE | ( nStreamMode & 0x73 ), - 0, - 0, + hr = pStg->CreateStream( aOfficeEmbedStreamName, + STGM_CREATE | ( nStreamMode & 0x73 ), + 0, + 0, &m_pOwnStream ); - + if ( hr == S_OK && m_pOwnStream ) { - hr = pStg->CreateStream( aExtentStreamName, - STGM_CREATE | ( nStreamMode & 0x73 ), - 0, - 0, + hr = pStg->CreateStream( aExtentStreamName, + STGM_CREATE | ( nStreamMode & 0x73 ), + 0, + 0, &m_pExtStream ); - + if ( hr == S_OK && m_pExtStream ) { - + m_pMasterStorage = pStg; m_bIsDirty = sal_True; } @@ -480,7 +489,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) else hr = E_FAIL; } - + if ( hr != S_OK ) m_pDocHolder->CloseDocument(); } @@ -494,12 +503,12 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) { if ( m_pDocHolder->GetDocument().is() ) return CO_E_ALREADYINITIALIZED; - + if ( !m_xFactory.is() || !pStg ) return E_FAIL; HRESULT hr = E_FAIL; - + STATSTG aStat; hr = pStg->Stat( &aStat, STATFLAG_NONAME ); if ( FAILED( hr ) ) return E_FAIL; @@ -512,7 +521,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) &m_pOwnStream ); if ( !m_pOwnStream ) hr = E_FAIL; - if ( SUCCEEDED( hr ) ) + if ( SUCCEEDED( hr ) ) { hr = pStg->OpenStream( aExtentStreamName, 0, @@ -535,7 +544,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) sal_Int8 aInf[EXT_STREAM_LENGTH]; hr = m_pExtStream->Read( (void*)aInf, EXT_STREAM_LENGTH, &nRead ); if ( nRead != EXT_STREAM_LENGTH ) hr = E_FAIL; - + if ( SUCCEEDED( hr ) ) { // aRectToSet.left = *((sal_Int32*)aInf); @@ -551,17 +560,17 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) if ( SUCCEEDED( hr ) ) { hr = E_FAIL; - + uno::Reference < io::XInputStream > xTempIn = createTempXInStreamFromIStream( m_xFactory, m_pOwnStream ); if ( xTempIn.is() ) { - uno::Reference< frame::XModel > aDocument( - m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), + uno::Reference< frame::XModel > aDocument( + m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), uno::UNO_QUERY ); if ( aDocument.is() ) { m_pDocHolder->SetDocument( aDocument ); - + uno::Reference< frame::XLoadable > xLoadable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); if( xLoadable.is() ) { @@ -576,7 +585,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) { } } - + if ( FAILED( hr ) ) m_pDocHolder->CloseDocument(); } @@ -597,7 +606,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) return hr; } - + STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) { if ( !m_pDocHolder->GetDocument().is() || !m_xFactory.is() || !pStgSave || !m_pOwnStream || !m_pExtStream ) @@ -617,17 +626,17 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) if ( FAILED( hr ) ) return E_FAIL; DWORD nStreamMode = aStat.grfMode; - hr = pStgSave->CreateStream( aOfficeEmbedStreamName, + hr = pStgSave->CreateStream( aOfficeEmbedStreamName, STGM_CREATE | ( nStreamMode & 0x73 ), 0, - 0, + 0, &pTargetStream ); if ( FAILED( hr ) || !pTargetStream ) return E_FAIL; - hr = pStgSave->CreateStream( aExtentStreamName, + hr = pStgSave->CreateStream( aExtentStreamName, STGM_CREATE | ( nStreamMode & 0x73 ), 0, - 0, + 0, &pNewExtStream ); if ( FAILED( hr ) || !pNewExtStream ) return E_FAIL; } @@ -640,7 +649,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) HRESULT hr = E_FAIL; const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( + uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( m_xFactory->createInstance ( aServiceName ), uno::UNO_QUERY ); @@ -682,7 +691,12 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) m_pOwnStream = CComPtr< IStream >(); m_pExtStream = CComPtr< IStream >(); if ( fSameAsLoad || pStgSave == m_pMasterStorage ) + { + uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( xMod.is() ) + xMod->setModified( sal_False ); m_bIsDirty = sal_False; + } } } } @@ -707,7 +721,7 @@ STDMETHODIMP EmbedDocument_Impl::SaveCompleted( IStorage *pStgNew ) if ( !m_pMasterStorage && !pStgNew ) return E_INVALIDARG; - + if ( pStgNew ) m_pMasterStorage = pStgNew; @@ -718,14 +732,14 @@ STDMETHODIMP EmbedDocument_Impl::SaveCompleted( IStorage *pStgNew ) DWORD nStreamMode = aStat.grfMode; hr = m_pMasterStorage->OpenStream( aOfficeEmbedStreamName, 0, - nStreamMode & 0x73, + nStreamMode & 0x73, 0, &m_pOwnStream ); if ( FAILED( hr ) || !m_pOwnStream ) return E_OUTOFMEMORY; hr = m_pMasterStorage->OpenStream( aExtentStreamName, 0, - nStreamMode & 0x73, + nStreamMode & 0x73, 0, &m_pExtStream ); if ( FAILED( hr ) || !m_pExtStream ) return E_OUTOFMEMORY; @@ -765,7 +779,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) nStreamMode , 0, &m_pMasterStorage ); - + if ( FAILED( hr ) || !m_pMasterStorage ) return E_FAIL; ::rtl::OUString aCurType = getServiceNameFromGUID_Impl( &m_guid ); // ??? @@ -793,8 +807,8 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) if ( FAILED( hr ) || !m_pExtStream ) return E_FAIL; - uno::Reference< frame::XModel > aDocument( - m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), + uno::Reference< frame::XModel > aDocument( + m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), uno::UNO_QUERY ); if ( aDocument.is() ) { @@ -805,8 +819,8 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) { try { - xLoadable->load( fillArgsForLoading_Impl( uno::Reference< io::XInputStream >(), - STGM_READWRITE, + xLoadable->load( fillArgsForLoading_Impl( uno::Reference< io::XInputStream >(), + STGM_READWRITE, pszFileName ) ); hr = S_OK; @@ -817,7 +831,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) { } } - + if ( hr == S_OK ) { ::rtl::OUString aCurType = getServiceNameFromGUID_Impl( &m_guid ); // ??? @@ -857,7 +871,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) else hr = E_FAIL; } - + if ( FAILED( hr ) ) { m_pDocHolder->CloseDocument(); @@ -890,7 +904,12 @@ STDMETHODIMP EmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember ) m_aFileName = ::rtl::OUString(); if ( !pszFileName || fRemember ) + { + uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( xMod.is() ) + xMod->setModified( sal_False ); m_bIsDirty = sal_False; + } } catch( uno::Exception& ) { @@ -915,7 +934,7 @@ STDMETHODIMP EmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName ) *ppszFileName = (LPOLESTR)( pMalloc->Alloc( sizeof( sal_Unicode ) * ( m_aFileName.getLength() + 1 ) ) ); wcsncpy( *ppszFileName, m_aFileName.getStr(), m_aFileName.getLength() + 1 ); - + return m_aFileName.getLength() ? S_OK : S_FALSE; } |