summaryrefslogtreecommitdiff
path: root/embedserv/source/embed/ed_ipersiststr.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'embedserv/source/embed/ed_ipersiststr.cxx')
-rw-r--r--embedserv/source/embed/ed_ipersiststr.cxx126
1 files changed, 58 insertions, 68 deletions
diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx
index 9679c4a1908f..86a2d93f6a8d 100644
--- a/embedserv/source/embed/ed_ipersiststr.cxx
+++ b/embedserv/source/embed/ed_ipersiststr.cxx
@@ -41,9 +41,11 @@
#include <osl/diagnose.h>
#include <sal/types.h>
+#include <guid.hxx>
+
#include <string.h>
-#define EXT_STREAM_LENGTH 16
+#define EXT_STREAM_LENGTH 4
namespace {
@@ -53,15 +55,11 @@ const sal_Int32 nConstBufferSize = 32000;
using namespace ::com::sun::star;
-extern OUString getStorageTypeFromGUID_Impl( GUID* guid );
-extern OUString getServiceNameFromGUID_Impl( GUID* );
-extern OUString getFilterNameFromGUID_Impl( GUID* );
-
const OUString aOfficeEmbedStreamName( "package_stream" );
const OUString aExtentStreamName( "properties_stream" );
uno::Reference< io::XInputStream > createTempXInStreamFromIStream(
- uno::Reference< lang::XMultiServiceFactory > xFactory,
+ uno::Reference< lang::XMultiServiceFactory > const & xFactory,
IStream *pStream )
{
uno::Reference< io::XInputStream > xResult;
@@ -88,7 +86,7 @@ uno::Reference< io::XInputStream > createTempXInStreamFromIStream(
sal_uInt32 nRead = 0;
do
{
- pStream->Read( (void*)aBuffer.getArray(), nConstBufferSize, &nRead );
+ pStream->Read( aBuffer.getArray(), nConstBufferSize, &nRead );
if ( nRead < nConstBufferSize )
aBuffer.realloc( nRead );
@@ -114,7 +112,7 @@ uno::Reference< io::XInputStream > createTempXInStreamFromIStream(
return xResult;
}
-HRESULT copyXTempOutToIStream( uno::Reference< io::XOutputStream > xTempOut, IStream* pStream )
+HRESULT copyXTempOutToIStream( uno::Reference< io::XOutputStream > const & xTempOut, IStream* pStream )
{
if ( !xTempOut.is() || !pStream )
return E_FAIL;
@@ -152,7 +150,7 @@ HRESULT copyXTempOutToIStream( uno::Reference< io::XOutputStream > xTempOut, ISt
}
sal_uInt32 nWritten = 0;
- hr = pStream->Write( (void*)aBuffer.getArray(), nReadBytes, &nWritten );
+ hr = pStream->Write( aBuffer.getArray(), nReadBytes, &nWritten );
if ( !SUCCEEDED( hr ) || nWritten != nReadBytes )
return E_FAIL;
@@ -169,9 +167,9 @@ EmbedDocument_Impl::EmbedDocument_Impl( const uno::Reference< lang::XMultiServic
: m_refCount( 0L )
, m_xFactory( xFactory )
, m_guid( *guid )
-, m_bIsDirty( sal_False )
+, m_bIsDirty( false )
, m_nAdviseNum( 0 )
-, m_bIsInVerbHandling( sal_False )
+, m_bIsInVerbHandling( false )
//, m_bLoadedFromFile( sal_False )
{
m_xOwnAccess = new EmbeddedDocumentInstanceAccess_Impl( this );
@@ -186,7 +184,7 @@ EmbedDocument_Impl::~EmbedDocument_Impl()
if ( m_pDocHolder->HasFrame() && m_pDocHolder->IsLink() )
{
// a link with frame should be only disconnected, not closed
- m_pDocHolder->DisconnectFrameDocument( sal_True );
+ m_pDocHolder->DisconnectFrameDocument( true );
}
else
{
@@ -197,7 +195,7 @@ EmbedDocument_Impl::~EmbedDocument_Impl()
m_pDocHolder->release();
}
-uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Impl( uno::Reference< io::XInputStream > xStream, DWORD /*nStreamMode*/, LPCOLESTR pFilePath )
+uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Impl( uno::Reference< io::XInputStream > const & xStream, DWORD /*nStreamMode*/, LPCOLESTR pFilePath )
{
uno::Sequence< beans::PropertyValue > aArgs( 3 );
@@ -239,7 +237,7 @@ uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Imp
return aArgs;
}
-uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForStoring_Impl( uno::Reference< io::XOutputStream > xStream)
+uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForStoring_Impl( uno::Reference< io::XOutputStream > const & xStream)
{
uno::Sequence< beans::PropertyValue > aArgs( xStream.is() ? 2 : 1 );
@@ -264,7 +262,7 @@ HRESULT EmbedDocument_Impl::SaveTo_Impl( IStorage* pStg )
// should not enter NoScribble mode
CComPtr< IStream > pOrigOwn = m_pOwnStream;
CComPtr< IStream > pOrigExt = m_pExtStream;
- HRESULT hr = Save( pStg, sal_False );
+ HRESULT hr = Save( pStg, false );
pStg->Commit( STGC_ONLYIFCURRENT );
m_pOwnStream = pOrigOwn;
m_pExtStream = pOrigExt;
@@ -280,65 +278,65 @@ STDMETHODIMP EmbedDocument_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv
if(IsEqualIID(riid, IID_IUnknown))
{
AddRef();
- *ppv = (IUnknown*) (IPersistStorage*) this;
+ *ppv = static_cast<IUnknown*>(static_cast<IPersistStorage*>(this));
return S_OK;
}
else if (IsEqualIID(riid, IID_IPersist))
{
AddRef();
- *ppv = (IPersist*) (IPersistStorage*) this;
+ *ppv = static_cast<IPersist*>(static_cast<IPersistStorage*>(this));
return S_OK;
}
else if (IsEqualIID(riid, IID_IExternalConnection))
{
AddRef();
- *ppv = (IExternalConnection*) this;
+ *ppv = static_cast<IExternalConnection*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IPersistStorage))
{
AddRef();
- *ppv = (IPersistStorage*) this;
+ *ppv = static_cast<IPersistStorage*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IDataObject))
{
AddRef();
- *ppv = (IDataObject*) this;
+ *ppv = static_cast<IDataObject*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IOleObject))
{
AddRef();
- *ppv = (IOleObject*) this;
+ *ppv = static_cast<IOleObject*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IOleWindow))
{
AddRef();
- *ppv = (IOleWindow*) this;
+ *ppv = static_cast<IOleWindow*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IOleInPlaceObject))
{
AddRef();
- *ppv = (IOleInPlaceObject*) this;
+ *ppv = static_cast<IOleInPlaceObject*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IPersistFile))
{
AddRef();
- *ppv = (IPersistFile*) this;
+ *ppv = static_cast<IPersistFile*>(this);
return S_OK;
}
else if (IsEqualIID(riid, IID_IDispatch))
{
AddRef();
- *ppv = (IDispatch*) this;
+ *ppv = static_cast<IDispatch*>(this);
return S_OK;
}
- *ppv = NULL;
+ *ppv = nullptr;
return ResultFromScode(E_NOINTERFACE);
}
@@ -427,7 +425,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg )
CLIPFORMAT cf = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
hr = WriteFmtUserTypeStg( pStg,
cf, // ???
- reinterpret_cast<LPWSTR>(( sal_Unicode* )aCurType.getStr()) );
+ const_cast<sal_Unicode *>(aCurType.getStr()) );
if ( hr == S_OK )
{
@@ -449,7 +447,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg )
{
m_pMasterStorage = pStg;
- m_bIsDirty = sal_True;
+ m_bIsDirty = true;
}
else
hr = E_FAIL;
@@ -486,7 +484,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg )
DWORD nStreamMode = aStat.grfMode;
hr = pStg->OpenStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()),
- 0,
+ nullptr,
nStreamMode & 0x73,
0,
&m_pOwnStream );
@@ -495,7 +493,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg )
if ( SUCCEEDED( hr ) )
{
hr = pStg->OpenStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()),
- 0,
+ nullptr,
nStreamMode & 0x73,
0,
&m_pExtStream );
@@ -512,9 +510,9 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg )
if ( SUCCEEDED( hr ) )
{
sal_uInt32 nRead;
- sal_Int8 aInf[EXT_STREAM_LENGTH];
- hr = m_pExtStream->Read( (void*)aInf, EXT_STREAM_LENGTH, &nRead );
- if ( nRead != EXT_STREAM_LENGTH ) hr = E_FAIL;
+ sal_Int32 aInf[EXT_STREAM_LENGTH];
+ hr = m_pExtStream->Read( aInf, sizeof aInf, &nRead );
+ if ( nRead != sizeof aInf ) hr = E_FAIL;
if ( SUCCEEDED( hr ) )
{
@@ -522,8 +520,8 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg )
// aRectToSet.top = *((sal_Int32*)&aInf[4]);
// aRectToSet.right = *((sal_Int32*)&aInf[8]);
// aRectToSet.bottom = *((sal_Int32*)&aInf[12]);
- aSizeToSet.cx = *((sal_Int32*)&aInf[8]) - *((sal_Int32*)aInf);
- aSizeToSet.cy = *((sal_Int32*)&aInf[12]) - *((sal_Int32*)&aInf[4]);
+ aSizeToSet.cx = aInf[2] - aInf[0];
+ aSizeToSet.cy = aInf[3] - aInf[1];
}
}
}
@@ -589,7 +587,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
if ( !fSameAsLoad && pStgSave != m_pMasterStorage )
{
OSL_ENSURE( m_pMasterStorage, "How could the document be initialized without storage!??\n" );
- HRESULT hr = m_pMasterStorage->CopyTo( NULL, NULL, NULL, pStgSave );
+ HRESULT hr = m_pMasterStorage->CopyTo( NULL, nullptr, nullptr, pStgSave );
if ( FAILED( hr ) ) return E_FAIL;
STATSTG aStat;
@@ -627,7 +625,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
{
try
{
- xStorable->storeToURL( OUString( "private:stream" ),
+ xStorable->storeToURL( "private:stream",
fillArgsForStoring_Impl( xTempOut ) );
hr = copyXTempOutToIStream( xTempOut, pTargetStream );
if ( SUCCEEDED( hr ) )
@@ -644,14 +642,10 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
if ( SUCCEEDED( hr ) )
{
sal_uInt32 nWritten;
- sal_Int8 aInf[EXT_STREAM_LENGTH];
- *((sal_Int32*)aInf) = 0;
- *((sal_Int32*)&aInf[4]) = 0;
- *((sal_Int32*)&aInf[8]) = aSize.cx;
- *((sal_Int32*)&aInf[12]) = aSize.cy;
+ sal_Int32 aInf[EXT_STREAM_LENGTH] = {0, 0, aSize.cx, aSize.cy};
- hr = pNewExtStream->Write( (void*)aInf, EXT_STREAM_LENGTH, &nWritten );
- if ( nWritten != EXT_STREAM_LENGTH ) hr = E_FAIL;
+ hr = pNewExtStream->Write( aInf, sizeof aInf, &nWritten );
+ if ( nWritten != sizeof aInf ) hr = E_FAIL;
if ( SUCCEEDED( hr ) )
{
@@ -661,8 +655,8 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
{
uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY );
if ( xMod.is() )
- xMod->setModified( sal_False );
- m_bIsDirty = sal_False;
+ xMod->setModified( false );
+ m_bIsDirty = false;
}
}
}
@@ -697,20 +691,20 @@ STDMETHODIMP EmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
DWORD nStreamMode = aStat.grfMode;
hr = m_pMasterStorage->OpenStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()),
- 0,
+ nullptr,
nStreamMode & 0x73,
0,
&m_pOwnStream );
if ( FAILED( hr ) || !m_pOwnStream ) return E_OUTOFMEMORY;
hr = m_pMasterStorage->OpenStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()),
- 0,
+ nullptr,
nStreamMode & 0x73,
0,
&m_pExtStream );
if ( FAILED( hr ) || !m_pExtStream ) return E_OUTOFMEMORY;
- sal_Bool bModified = sal_False;
+ bool bModified = false;
uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY );
if ( xMod.is() )
bModified = xMod->isModified();
@@ -748,7 +742,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
return E_FAIL;
DWORD nStreamMode = STGM_CREATE | STGM_READWRITE | STGM_DELETEONRELEASE | STGM_SHARE_EXCLUSIVE;
- HRESULT hr = StgCreateDocfile( NULL,
+ HRESULT hr = StgCreateDocfile( nullptr,
nStreamMode ,
0,
&m_pMasterStorage );
@@ -759,7 +753,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
CLIPFORMAT cf = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
hr = WriteFmtUserTypeStg( m_pMasterStorage,
cf, // ???
- reinterpret_cast<LPWSTR>(( sal_Unicode* )aCurType.getStr()) );
+ const_cast<sal_Unicode *>(aCurType.getStr()) );
if ( FAILED( hr ) ) return E_FAIL;
hr = m_pMasterStorage->SetClass( m_guid );
@@ -785,7 +779,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
uno::UNO_QUERY );
if ( aDocument.is() )
{
- m_pDocHolder->SetDocument( aDocument, sal_True );
+ m_pDocHolder->SetDocument( aDocument, true );
uno::Reference< frame::XLoadable > xLoadable( m_pDocHolder->GetDocument(), uno::UNO_QUERY );
if( xLoadable.is() )
@@ -810,7 +804,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
cf = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
hr = WriteFmtUserTypeStg( m_pMasterStorage,
cf, // ???
- reinterpret_cast<LPWSTR>(( sal_Unicode* )aCurType.getStr()) );
+ const_cast<sal_Unicode *>(aCurType.getStr()) );
if ( SUCCEEDED( hr ) )
{
@@ -826,20 +820,16 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
if ( SUCCEEDED( hr ) )
{
sal_uInt32 nWritten;
- sal_Int8 aInf[EXT_STREAM_LENGTH];
- *((sal_Int32*)aInf) = 0;
- *((sal_Int32*)&aInf[4]) = 0;
- *((sal_Int32*)&aInf[8]) = aSize.cx;
- *((sal_Int32*)&aInf[12]) = aSize.cy;
-
- hr = m_pExtStream->Write( (void*)aInf, EXT_STREAM_LENGTH, &nWritten );
- if ( nWritten != EXT_STREAM_LENGTH ) hr = E_FAIL;
+ sal_Int32 aInf[EXT_STREAM_LENGTH] = {0, 0, aSize.cx, aSize.cy};
+
+ hr = m_pExtStream->Write( aInf, sizeof aInf, &nWritten );
+ if ( nWritten != sizeof aInf ) hr = E_FAIL;
}
}
}
if ( SUCCEEDED( hr ) )
- m_bIsDirty = sal_True;
+ m_bIsDirty = true;
else
hr = E_FAIL;
}
@@ -847,9 +837,9 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ )
if ( FAILED( hr ) )
{
m_pDocHolder->CloseDocument();
- m_pOwnStream = NULL;
- m_pExtStream = NULL;
- m_pMasterStorage = NULL;
+ m_pOwnStream = nullptr;
+ m_pExtStream = nullptr;
+ m_pMasterStorage = nullptr;
}
}
@@ -912,7 +902,7 @@ STDMETHODIMP EmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
HRESULT hr = CoGetMalloc( 1, &pMalloc );
if ( FAILED( hr ) || !pMalloc ) return E_FAIL;
- *ppszFileName = (LPOLESTR)( pMalloc->Alloc( sizeof( sal_Unicode ) * ( m_aFileName.getLength() + 1 ) ) );
+ *ppszFileName = static_cast<LPOLESTR>( pMalloc->Alloc( sizeof( sal_Unicode ) * ( m_aFileName.getLength() + 1 ) ) );
wcsncpy( *ppszFileName, reinterpret_cast<LPCWSTR>(m_aFileName.getStr()), m_aFileName.getLength() + 1 );
return m_aFileName.getLength() ? S_OK : S_FALSE;
@@ -928,12 +918,12 @@ LockedEmbedDocument_Impl EmbeddedDocumentInstanceAccess_Impl::GetEmbedDocument()
void EmbeddedDocumentInstanceAccess_Impl::ClearEmbedDocument()
{
::osl::MutexGuard aGuard( m_aMutex );
- m_pEmbedDocument = NULL;
+ m_pEmbedDocument = nullptr;
}
LockedEmbedDocument_Impl::LockedEmbedDocument_Impl()
-: m_pEmbedDocument( NULL )
+: m_pEmbedDocument( nullptr )
{}
LockedEmbedDocument_Impl::LockedEmbedDocument_Impl( EmbedDocument_Impl* pEmbedDocument )