xref: /aoo41x/main/vcl/source/gdi/gfxlink.cxx (revision 270a30df)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/file.h>
28cdf0e10cSrcweir #include <tools/vcompat.hxx>
29cdf0e10cSrcweir #include <tools/urlobj.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
32cdf0e10cSrcweir #include <unotools/tempfile.hxx>
33cdf0e10cSrcweir #include <ucbhelper/content.hxx>
34cdf0e10cSrcweir #include <vcl/graph.hxx>
35cdf0e10cSrcweir #include <vcl/gfxlink.hxx>
36cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
37cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // -----------
40cdf0e10cSrcweir // - GfxLink -
41cdf0e10cSrcweir // -----------
42cdf0e10cSrcweir 
GfxLink()43cdf0e10cSrcweir GfxLink::GfxLink() :
44cdf0e10cSrcweir 	meType		( GFX_LINK_TYPE_NONE ),
45cdf0e10cSrcweir 	mpBuf		( NULL ),
46cdf0e10cSrcweir 	mpSwap		( NULL ),
47cdf0e10cSrcweir 	mnBufSize	( 0 ),
48cdf0e10cSrcweir 	mnUserId	( 0UL ),
49cdf0e10cSrcweir     mpImpData   ( new ImpGfxLink )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // ------------------------------------------------------------------------
54cdf0e10cSrcweir 
GfxLink(const GfxLink & rGfxLink)55cdf0e10cSrcweir GfxLink::GfxLink( const GfxLink& rGfxLink ) :
56cdf0e10cSrcweir     mpImpData( new ImpGfxLink )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	ImplCopy( rGfxLink );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // ------------------------------------------------------------------------
62cdf0e10cSrcweir 
GfxLink(sal_uInt8 * pBuf,sal_uInt32 nSize,GfxLinkType nType,sal_Bool bOwns)63cdf0e10cSrcweir GfxLink::GfxLink( sal_uInt8* pBuf, sal_uInt32 nSize, GfxLinkType nType, sal_Bool bOwns ) :
64cdf0e10cSrcweir     mpImpData( new ImpGfxLink )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     DBG_ASSERT( (pBuf != NULL && nSize) || (!bOwns && nSize == 0),
67cdf0e10cSrcweir                 "GfxLink::GfxLink(): empty/NULL buffer given" );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	meType = nType;
70cdf0e10cSrcweir 	mnBufSize = nSize;
71cdf0e10cSrcweir 	mpSwap = NULL;
72cdf0e10cSrcweir 	mnUserId = 0UL;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	if( bOwns )
75cdf0e10cSrcweir 		mpBuf = new ImpBuffer( pBuf );
76cdf0e10cSrcweir 	else if( nSize )
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 		mpBuf = new ImpBuffer( nSize );
79cdf0e10cSrcweir 		memcpy( mpBuf->mpBuffer, pBuf, nSize );
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 	else
82cdf0e10cSrcweir 		mpBuf = NULL;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // ------------------------------------------------------------------------
86cdf0e10cSrcweir 
~GfxLink()87cdf0e10cSrcweir GfxLink::~GfxLink()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	if( mpBuf && !( --mpBuf->mnRefCount ) )
90cdf0e10cSrcweir 		delete mpBuf;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	if( mpSwap && !( --mpSwap->mnRefCount ) )
93cdf0e10cSrcweir 		delete mpSwap;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     delete mpImpData;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // ------------------------------------------------------------------------
99cdf0e10cSrcweir 
operator =(const GfxLink & rGfxLink)100cdf0e10cSrcweir GfxLink& GfxLink::operator=( const GfxLink& rGfxLink )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	if( &rGfxLink != this )
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		if ( mpBuf && !( --mpBuf->mnRefCount ) )
105cdf0e10cSrcweir 			delete mpBuf;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		if( mpSwap && !( --mpSwap->mnRefCount ) )
108cdf0e10cSrcweir 			delete mpSwap;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		ImplCopy( rGfxLink );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	return *this;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // ------------------------------------------------------------------------
117cdf0e10cSrcweir 
IsEqual(const GfxLink & rGfxLink) const118cdf0e10cSrcweir sal_Bool GfxLink::IsEqual( const GfxLink& rGfxLink ) const
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	sal_Bool bIsEqual = sal_False;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	if ( ( mnBufSize == rGfxLink.mnBufSize ) && ( meType == rGfxLink.meType ) )
123cdf0e10cSrcweir 	{
124cdf0e10cSrcweir 		const sal_uInt8* pSource = GetData();
125cdf0e10cSrcweir 		const sal_uInt8* pDest = rGfxLink.GetData();
126cdf0e10cSrcweir 		sal_uInt32 nSourceSize = GetDataSize();
127cdf0e10cSrcweir 		sal_uInt32 nDestSize = rGfxLink.GetDataSize();
128cdf0e10cSrcweir 		if ( pSource && pDest && ( nSourceSize == nDestSize ) )
129cdf0e10cSrcweir 		{
130cdf0e10cSrcweir 			bIsEqual = memcmp( pSource, pDest, nSourceSize ) == 0;
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 		else if ( ( pSource == 0 ) && ( pDest == 0 ) )
133cdf0e10cSrcweir 			bIsEqual = sal_True;
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 	return bIsEqual;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir // ------------------------------------------------------------------------
139cdf0e10cSrcweir 
ImplCopy(const GfxLink & rGfxLink)140cdf0e10cSrcweir void GfxLink::ImplCopy( const GfxLink& rGfxLink )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	mnBufSize = rGfxLink.mnBufSize;
143cdf0e10cSrcweir 	meType = rGfxLink.meType;
144cdf0e10cSrcweir 	mpBuf = rGfxLink.mpBuf;
145cdf0e10cSrcweir 	mpSwap = rGfxLink.mpSwap;
146cdf0e10cSrcweir 	mnUserId = rGfxLink.mnUserId;
147cdf0e10cSrcweir     *mpImpData = *rGfxLink.mpImpData;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	if( mpBuf )
150cdf0e10cSrcweir 		mpBuf->mnRefCount++;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	if( mpSwap )
153cdf0e10cSrcweir 		mpSwap->mnRefCount++;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // ------------------------------------------------------------------------
157cdf0e10cSrcweir 
GetType() const158cdf0e10cSrcweir GfxLinkType GfxLink::GetType() const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	return meType;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir // ------------------------------------------------------------------------
164cdf0e10cSrcweir 
IsNative() const165cdf0e10cSrcweir sal_Bool GfxLink::IsNative() const
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	return( meType >= GFX_LINK_FIRST_NATIVE_ID && meType <= GFX_LINK_LAST_NATIVE_ID );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir // ------------------------------------------------------------------------
171cdf0e10cSrcweir 
GetDataSize() const172cdf0e10cSrcweir sal_uInt32 GfxLink::GetDataSize() const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return mnBufSize;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // ------------------------------------------------------------------------
178cdf0e10cSrcweir 
GetData() const179cdf0e10cSrcweir const sal_uInt8* GfxLink::GetData() const
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	if( IsSwappedOut() )
182cdf0e10cSrcweir 		( (GfxLink*) this )->SwapIn();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	return( mpBuf ? mpBuf->mpBuffer : NULL );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // ------------------------------------------------------------------------
188cdf0e10cSrcweir 
GetPrefSize() const189cdf0e10cSrcweir const Size&	GfxLink::GetPrefSize() const
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     return mpImpData->maPrefSize;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // ------------------------------------------------------------------------
195cdf0e10cSrcweir 
SetPrefSize(const Size & rPrefSize)196cdf0e10cSrcweir void GfxLink::SetPrefSize( const Size& rPrefSize )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     mpImpData->maPrefSize = rPrefSize;
199cdf0e10cSrcweir     mpImpData->mbPrefSizeValid = true;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // ------------------------------------------------------------------------
203cdf0e10cSrcweir 
IsPrefSizeValid()204cdf0e10cSrcweir bool GfxLink::IsPrefSizeValid()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     return mpImpData->mbPrefSizeValid;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // ------------------------------------------------------------------------
210cdf0e10cSrcweir 
GetPrefMapMode() const211cdf0e10cSrcweir const MapMode& GfxLink::GetPrefMapMode() const
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     return mpImpData->maPrefMapMode;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // ------------------------------------------------------------------------
217cdf0e10cSrcweir 
SetPrefMapMode(const MapMode & rPrefMapMode)218cdf0e10cSrcweir void GfxLink::SetPrefMapMode( const MapMode& rPrefMapMode )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     mpImpData->maPrefMapMode = rPrefMapMode;
221cdf0e10cSrcweir     mpImpData->mbPrefMapModeValid = true;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir // ------------------------------------------------------------------------
225cdf0e10cSrcweir 
IsPrefMapModeValid()226cdf0e10cSrcweir bool GfxLink::IsPrefMapModeValid()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     return mpImpData->mbPrefMapModeValid;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir // ------------------------------------------------------------------------
232cdf0e10cSrcweir 
LoadNative(Graphic & rGraphic)233cdf0e10cSrcweir sal_Bool GfxLink::LoadNative( Graphic& rGraphic )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	if( IsNative() && mnBufSize )
238cdf0e10cSrcweir 	{
239cdf0e10cSrcweir 		const sal_uInt8* pData = GetData();
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		if( pData )
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			SvMemoryStream	aMemStm;
244cdf0e10cSrcweir 			sal_uLong			nCvtType;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 			aMemStm.SetBuffer( (char*) pData, mnBufSize, sal_False, mnBufSize );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 			switch( meType )
249cdf0e10cSrcweir 			{
250cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_GIF ): nCvtType = CVT_GIF; break;
251*270a30dfSArmin Le Grand 
252*270a30dfSArmin Le Grand                 // #15508# added BMP type for better exports (reload when swapped - checked, works)
253*270a30dfSArmin Le Grand                 case( GFX_LINK_TYPE_NATIVE_BMP ): nCvtType = CVT_BMP; break;
254*270a30dfSArmin Le Grand 
255cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_JPG ): nCvtType = CVT_JPG; break;
256cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PNG ): nCvtType = CVT_PNG; break;
257cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_TIF ): nCvtType = CVT_TIF; break;
258cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_WMF ): nCvtType = CVT_WMF; break;
259cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_MET ): nCvtType = CVT_MET; break;
260cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PCT ): nCvtType = CVT_PCT; break;
261cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_SVG ): nCvtType = CVT_SVG; break;
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 				default: nCvtType = CVT_UNKNOWN; break;
264cdf0e10cSrcweir 			}
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 			if( nCvtType && ( GraphicConverter::Import( aMemStm, rGraphic, nCvtType ) == ERRCODE_NONE ) )
267cdf0e10cSrcweir 				bRet = sal_True;
268cdf0e10cSrcweir 		}
269cdf0e10cSrcweir 	}
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	return bRet;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir // ------------------------------------------------------------------------
275cdf0e10cSrcweir 
SwapOut()276cdf0e10cSrcweir void GfxLink::SwapOut()
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	if( !IsSwappedOut() && mpBuf )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		mpSwap = new ImpSwap( mpBuf->mpBuffer, mnBufSize );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 		if( !mpSwap->IsSwapped() )
283cdf0e10cSrcweir 		{
284cdf0e10cSrcweir 			delete mpSwap;
285cdf0e10cSrcweir 			mpSwap = NULL;
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 		else
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             if( !( --mpBuf->mnRefCount ) )
290cdf0e10cSrcweir                 delete mpBuf;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir             mpBuf = NULL;
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir 	}
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir // ------------------------------------------------------------------------
298cdf0e10cSrcweir 
SwapIn()299cdf0e10cSrcweir void GfxLink::SwapIn()
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	if( IsSwappedOut() )
302cdf0e10cSrcweir 	{
303cdf0e10cSrcweir 		mpBuf = new ImpBuffer( mpSwap->GetData() );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 		if( !( --mpSwap->mnRefCount ) )
306cdf0e10cSrcweir 			delete mpSwap;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 		mpSwap = NULL;
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir // ------------------------------------------------------------------------
313cdf0e10cSrcweir 
ExportNative(SvStream & rOStream) const314cdf0e10cSrcweir sal_Bool GfxLink::ExportNative( SvStream& rOStream ) const
315cdf0e10cSrcweir {
316cdf0e10cSrcweir 	if( GetDataSize() )
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		if( IsSwappedOut() )
319cdf0e10cSrcweir 			mpSwap->WriteTo( rOStream );
320cdf0e10cSrcweir 		else if( GetData() )
321cdf0e10cSrcweir 			rOStream.Write( GetData(), GetDataSize() );
322cdf0e10cSrcweir 	}
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	return ( rOStream.GetError() == ERRCODE_NONE );
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir // ------------------------------------------------------------------------
328cdf0e10cSrcweir 
operator <<(SvStream & rOStream,const GfxLink & rGfxLink)329cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const GfxLink& rGfxLink )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir 	VersionCompat* pCompat = new VersionCompat( rOStream, STREAM_WRITE, 2 );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	// Version 1
334cdf0e10cSrcweir     rOStream << (sal_uInt16) rGfxLink.GetType() << rGfxLink.GetDataSize() << rGfxLink.GetUserId();
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     // Version 2
337cdf0e10cSrcweir     rOStream << rGfxLink.GetPrefSize() << rGfxLink.GetPrefMapMode();
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	delete pCompat;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	if( rGfxLink.GetDataSize() )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		if( rGfxLink.IsSwappedOut() )
344cdf0e10cSrcweir 			rGfxLink.mpSwap->WriteTo( rOStream );
345cdf0e10cSrcweir 		else if( rGfxLink.GetData() )
346cdf0e10cSrcweir 			rOStream.Write( rGfxLink.GetData(), rGfxLink.GetDataSize() );
347cdf0e10cSrcweir 	}
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	return rOStream;
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir // ------------------------------------------------------------------------
353cdf0e10cSrcweir 
operator >>(SvStream & rIStream,GfxLink & rGfxLink)354cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, GfxLink& rGfxLink)
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     Size            aSize;
357cdf0e10cSrcweir     MapMode         aMapMode;
358cdf0e10cSrcweir 	sal_uInt32		nSize;
359cdf0e10cSrcweir 	sal_uInt32		nUserId;
360cdf0e10cSrcweir 	sal_uInt16			nType;
361cdf0e10cSrcweir 	sal_uInt8*			pBuf;
362cdf0e10cSrcweir     bool			bMapAndSizeValid( false );
363cdf0e10cSrcweir 	VersionCompat*	pCompat = new VersionCompat( rIStream, STREAM_READ );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	// Version 1
366cdf0e10cSrcweir     rIStream >> nType >> nSize >> nUserId;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     if( pCompat->GetVersion() >= 2 )
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir         rIStream >> aSize >> aMapMode;
371cdf0e10cSrcweir         bMapAndSizeValid = true;
372cdf0e10cSrcweir     }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	delete pCompat;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	pBuf = new sal_uInt8[ nSize ];
377cdf0e10cSrcweir 	rIStream.Read( pBuf, nSize );
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	rGfxLink = GfxLink( pBuf, nSize, (GfxLinkType) nType, sal_True );
380cdf0e10cSrcweir 	rGfxLink.SetUserId( nUserId );
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     if( bMapAndSizeValid )
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         rGfxLink.SetPrefSize( aSize );
385cdf0e10cSrcweir         rGfxLink.SetPrefMapMode( aMapMode );
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	return rIStream;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // -----------
392cdf0e10cSrcweir // - ImpSwap -
393cdf0e10cSrcweir // -----------
394cdf0e10cSrcweir 
ImpSwap(sal_uInt8 * pData,sal_uLong nDataSize)395cdf0e10cSrcweir ImpSwap::ImpSwap( sal_uInt8* pData, sal_uLong nDataSize ) :
396cdf0e10cSrcweir 			mnDataSize( nDataSize ),
397cdf0e10cSrcweir 			mnRefCount( 1UL )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir 	if( pData && mnDataSize )
400cdf0e10cSrcweir 	{
401cdf0e10cSrcweir 		::utl::TempFile aTempFile;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 		maURL = aTempFile.GetURL();
404cdf0e10cSrcweir 		if( maURL.getLength() )
405cdf0e10cSrcweir 		{
406cdf0e10cSrcweir 			SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE );
407cdf0e10cSrcweir 			if( pOStm )
408cdf0e10cSrcweir 			{
409cdf0e10cSrcweir 				pOStm->Write( pData, mnDataSize );
410cdf0e10cSrcweir 				sal_Bool bError = ( ERRCODE_NONE != pOStm->GetError() );
411cdf0e10cSrcweir 				delete pOStm;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 				if( bError )
414cdf0e10cSrcweir 				{
415cdf0e10cSrcweir 					osl_removeFile( maURL.pData );
416cdf0e10cSrcweir 					maURL = String();
417cdf0e10cSrcweir 				}
418cdf0e10cSrcweir 			}
419cdf0e10cSrcweir 		}
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir // ------------------------------------------------------------------------
424cdf0e10cSrcweir 
~ImpSwap()425cdf0e10cSrcweir ImpSwap::~ImpSwap()
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	if( IsSwapped() )
428cdf0e10cSrcweir 		osl_removeFile( maURL.pData );
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir // ------------------------------------------------------------------------
432cdf0e10cSrcweir 
GetData() const433cdf0e10cSrcweir sal_uInt8* ImpSwap::GetData() const
434cdf0e10cSrcweir {
435cdf0e10cSrcweir 	sal_uInt8* pData;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	if( IsSwapped() )
438cdf0e10cSrcweir 	{
439cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE );
440cdf0e10cSrcweir 		if( pIStm )
441cdf0e10cSrcweir 		{
442cdf0e10cSrcweir 			pData = new sal_uInt8[ mnDataSize ];
443cdf0e10cSrcweir 			pIStm->Read( pData, mnDataSize );
444cdf0e10cSrcweir 			sal_Bool bError = ( ERRCODE_NONE != pIStm->GetError() );
44582b4b565SAndre Fischer 			sal_Size nActReadSize = pIStm->Tell();
44682b4b565SAndre Fischer 			if (nActReadSize != mnDataSize)
44782b4b565SAndre Fischer 			{
44882b4b565SAndre Fischer 				bError = sal_True;
44982b4b565SAndre Fischer 			}
450cdf0e10cSrcweir 			delete pIStm;
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 			if( bError )
453cdf0e10cSrcweir 				delete[] pData, pData = NULL;
454cdf0e10cSrcweir 		}
455cdf0e10cSrcweir 		else
456cdf0e10cSrcweir 			pData = NULL;
457cdf0e10cSrcweir 	}
458cdf0e10cSrcweir 	else
459cdf0e10cSrcweir 		pData = NULL;
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 	return pData;
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir // ------------------------------------------------------------------------
465cdf0e10cSrcweir 
WriteTo(SvStream & rOStm) const466cdf0e10cSrcweir void ImpSwap::WriteTo( SvStream& rOStm ) const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	sal_uInt8* pData = GetData();
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	if( pData )
471cdf0e10cSrcweir 	{
472cdf0e10cSrcweir 		rOStm.Write( pData, mnDataSize );
473cdf0e10cSrcweir 		delete[] pData;
474cdf0e10cSrcweir 	}
475cdf0e10cSrcweir }
476