1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew 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 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 55cdf0e10cSrcweir GfxLink::GfxLink( const GfxLink& rGfxLink ) : 56cdf0e10cSrcweir mpImpData( new ImpGfxLink ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir ImplCopy( rGfxLink ); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir // ------------------------------------------------------------------------ 62cdf0e10cSrcweir 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 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 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 118cdf0e10cSrcweir 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 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 158cdf0e10cSrcweir GfxLinkType GfxLink::GetType() const 159cdf0e10cSrcweir { 160cdf0e10cSrcweir return meType; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir // ------------------------------------------------------------------------ 164cdf0e10cSrcweir 165cdf0e10cSrcweir sal_Bool GfxLink::IsNative() const 166cdf0e10cSrcweir { 167cdf0e10cSrcweir return( meType >= GFX_LINK_FIRST_NATIVE_ID && meType <= GFX_LINK_LAST_NATIVE_ID ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir // ------------------------------------------------------------------------ 171cdf0e10cSrcweir 172cdf0e10cSrcweir sal_uInt32 GfxLink::GetDataSize() const 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return mnBufSize; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir // ------------------------------------------------------------------------ 178cdf0e10cSrcweir 179cdf0e10cSrcweir 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 189cdf0e10cSrcweir const Size& GfxLink::GetPrefSize() const 190cdf0e10cSrcweir { 191cdf0e10cSrcweir return mpImpData->maPrefSize; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir // ------------------------------------------------------------------------ 195cdf0e10cSrcweir 196cdf0e10cSrcweir void GfxLink::SetPrefSize( const Size& rPrefSize ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir mpImpData->maPrefSize = rPrefSize; 199cdf0e10cSrcweir mpImpData->mbPrefSizeValid = true; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir // ------------------------------------------------------------------------ 203cdf0e10cSrcweir 204cdf0e10cSrcweir bool GfxLink::IsPrefSizeValid() 205cdf0e10cSrcweir { 206cdf0e10cSrcweir return mpImpData->mbPrefSizeValid; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir // ------------------------------------------------------------------------ 210cdf0e10cSrcweir 211cdf0e10cSrcweir const MapMode& GfxLink::GetPrefMapMode() const 212cdf0e10cSrcweir { 213cdf0e10cSrcweir return mpImpData->maPrefMapMode; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir // ------------------------------------------------------------------------ 217cdf0e10cSrcweir 218cdf0e10cSrcweir void GfxLink::SetPrefMapMode( const MapMode& rPrefMapMode ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir mpImpData->maPrefMapMode = rPrefMapMode; 221cdf0e10cSrcweir mpImpData->mbPrefMapModeValid = true; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir // ------------------------------------------------------------------------ 225cdf0e10cSrcweir 226cdf0e10cSrcweir bool GfxLink::IsPrefMapModeValid() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir return mpImpData->mbPrefMapModeValid; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir // ------------------------------------------------------------------------ 232cdf0e10cSrcweir 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; 251cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_JPG ): nCvtType = CVT_JPG; break; 252cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_PNG ): nCvtType = CVT_PNG; break; 253cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_TIF ): nCvtType = CVT_TIF; break; 254cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_WMF ): nCvtType = CVT_WMF; break; 255cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_MET ): nCvtType = CVT_MET; break; 256cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_PCT ): nCvtType = CVT_PCT; break; 257cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_SVG ): nCvtType = CVT_SVG; break; 258cdf0e10cSrcweir 259cdf0e10cSrcweir default: nCvtType = CVT_UNKNOWN; break; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir if( nCvtType && ( GraphicConverter::Import( aMemStm, rGraphic, nCvtType ) == ERRCODE_NONE ) ) 263cdf0e10cSrcweir bRet = sal_True; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir return bRet; 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir // ------------------------------------------------------------------------ 271cdf0e10cSrcweir 272cdf0e10cSrcweir void GfxLink::SwapOut() 273cdf0e10cSrcweir { 274cdf0e10cSrcweir if( !IsSwappedOut() && mpBuf ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir mpSwap = new ImpSwap( mpBuf->mpBuffer, mnBufSize ); 277cdf0e10cSrcweir 278cdf0e10cSrcweir if( !mpSwap->IsSwapped() ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir delete mpSwap; 281cdf0e10cSrcweir mpSwap = NULL; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir else 284cdf0e10cSrcweir { 285cdf0e10cSrcweir if( !( --mpBuf->mnRefCount ) ) 286cdf0e10cSrcweir delete mpBuf; 287cdf0e10cSrcweir 288cdf0e10cSrcweir mpBuf = NULL; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir // ------------------------------------------------------------------------ 294cdf0e10cSrcweir 295cdf0e10cSrcweir void GfxLink::SwapIn() 296cdf0e10cSrcweir { 297cdf0e10cSrcweir if( IsSwappedOut() ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir mpBuf = new ImpBuffer( mpSwap->GetData() ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir if( !( --mpSwap->mnRefCount ) ) 302cdf0e10cSrcweir delete mpSwap; 303cdf0e10cSrcweir 304cdf0e10cSrcweir mpSwap = NULL; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // ------------------------------------------------------------------------ 309cdf0e10cSrcweir 310cdf0e10cSrcweir sal_Bool GfxLink::ExportNative( SvStream& rOStream ) const 311cdf0e10cSrcweir { 312cdf0e10cSrcweir if( GetDataSize() ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir if( IsSwappedOut() ) 315cdf0e10cSrcweir mpSwap->WriteTo( rOStream ); 316cdf0e10cSrcweir else if( GetData() ) 317cdf0e10cSrcweir rOStream.Write( GetData(), GetDataSize() ); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir return ( rOStream.GetError() == ERRCODE_NONE ); 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir // ------------------------------------------------------------------------ 324cdf0e10cSrcweir 325cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const GfxLink& rGfxLink ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rOStream, STREAM_WRITE, 2 ); 328cdf0e10cSrcweir 329cdf0e10cSrcweir // Version 1 330cdf0e10cSrcweir rOStream << (sal_uInt16) rGfxLink.GetType() << rGfxLink.GetDataSize() << rGfxLink.GetUserId(); 331cdf0e10cSrcweir 332cdf0e10cSrcweir // Version 2 333cdf0e10cSrcweir rOStream << rGfxLink.GetPrefSize() << rGfxLink.GetPrefMapMode(); 334cdf0e10cSrcweir 335cdf0e10cSrcweir delete pCompat; 336cdf0e10cSrcweir 337cdf0e10cSrcweir if( rGfxLink.GetDataSize() ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir if( rGfxLink.IsSwappedOut() ) 340cdf0e10cSrcweir rGfxLink.mpSwap->WriteTo( rOStream ); 341cdf0e10cSrcweir else if( rGfxLink.GetData() ) 342cdf0e10cSrcweir rOStream.Write( rGfxLink.GetData(), rGfxLink.GetDataSize() ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir return rOStream; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir // ------------------------------------------------------------------------ 349cdf0e10cSrcweir 350cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, GfxLink& rGfxLink) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir Size aSize; 353cdf0e10cSrcweir MapMode aMapMode; 354cdf0e10cSrcweir sal_uInt32 nSize; 355cdf0e10cSrcweir sal_uInt32 nUserId; 356cdf0e10cSrcweir sal_uInt16 nType; 357cdf0e10cSrcweir sal_uInt8* pBuf; 358cdf0e10cSrcweir bool bMapAndSizeValid( false ); 359cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rIStream, STREAM_READ ); 360cdf0e10cSrcweir 361cdf0e10cSrcweir // Version 1 362cdf0e10cSrcweir rIStream >> nType >> nSize >> nUserId; 363cdf0e10cSrcweir 364cdf0e10cSrcweir if( pCompat->GetVersion() >= 2 ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir rIStream >> aSize >> aMapMode; 367cdf0e10cSrcweir bMapAndSizeValid = true; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir delete pCompat; 371cdf0e10cSrcweir 372cdf0e10cSrcweir pBuf = new sal_uInt8[ nSize ]; 373cdf0e10cSrcweir rIStream.Read( pBuf, nSize ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir rGfxLink = GfxLink( pBuf, nSize, (GfxLinkType) nType, sal_True ); 376cdf0e10cSrcweir rGfxLink.SetUserId( nUserId ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir if( bMapAndSizeValid ) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir rGfxLink.SetPrefSize( aSize ); 381cdf0e10cSrcweir rGfxLink.SetPrefMapMode( aMapMode ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir return rIStream; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir // ----------- 388cdf0e10cSrcweir // - ImpSwap - 389cdf0e10cSrcweir // ----------- 390cdf0e10cSrcweir 391cdf0e10cSrcweir ImpSwap::ImpSwap( sal_uInt8* pData, sal_uLong nDataSize ) : 392cdf0e10cSrcweir mnDataSize( nDataSize ), 393cdf0e10cSrcweir mnRefCount( 1UL ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir if( pData && mnDataSize ) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir ::utl::TempFile aTempFile; 398cdf0e10cSrcweir 399cdf0e10cSrcweir maURL = aTempFile.GetURL(); 400cdf0e10cSrcweir if( maURL.getLength() ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE ); 403cdf0e10cSrcweir if( pOStm ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir pOStm->Write( pData, mnDataSize ); 406cdf0e10cSrcweir sal_Bool bError = ( ERRCODE_NONE != pOStm->GetError() ); 407cdf0e10cSrcweir delete pOStm; 408cdf0e10cSrcweir 409cdf0e10cSrcweir if( bError ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir osl_removeFile( maURL.pData ); 412cdf0e10cSrcweir maURL = String(); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir } 416cdf0e10cSrcweir } 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir // ------------------------------------------------------------------------ 420cdf0e10cSrcweir 421cdf0e10cSrcweir ImpSwap::~ImpSwap() 422cdf0e10cSrcweir { 423cdf0e10cSrcweir if( IsSwapped() ) 424cdf0e10cSrcweir osl_removeFile( maURL.pData ); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir // ------------------------------------------------------------------------ 428cdf0e10cSrcweir 429cdf0e10cSrcweir sal_uInt8* ImpSwap::GetData() const 430cdf0e10cSrcweir { 431cdf0e10cSrcweir sal_uInt8* pData; 432cdf0e10cSrcweir 433cdf0e10cSrcweir if( IsSwapped() ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE ); 436cdf0e10cSrcweir if( pIStm ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir pData = new sal_uInt8[ mnDataSize ]; 439cdf0e10cSrcweir pIStm->Read( pData, mnDataSize ); 440cdf0e10cSrcweir sal_Bool bError = ( ERRCODE_NONE != pIStm->GetError() ); 441cdf0e10cSrcweir delete pIStm; 442cdf0e10cSrcweir 443cdf0e10cSrcweir if( bError ) 444cdf0e10cSrcweir delete[] pData, pData = NULL; 445cdf0e10cSrcweir } 446cdf0e10cSrcweir else 447cdf0e10cSrcweir pData = NULL; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir else 450cdf0e10cSrcweir pData = NULL; 451cdf0e10cSrcweir 452cdf0e10cSrcweir return pData; 453cdf0e10cSrcweir } 454cdf0e10cSrcweir 455cdf0e10cSrcweir // ------------------------------------------------------------------------ 456cdf0e10cSrcweir 457cdf0e10cSrcweir void ImpSwap::WriteTo( SvStream& rOStm ) const 458cdf0e10cSrcweir { 459cdf0e10cSrcweir sal_uInt8* pData = GetData(); 460cdf0e10cSrcweir 461cdf0e10cSrcweir if( pData ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir rOStm.Write( pData, mnDataSize ); 464cdf0e10cSrcweir delete[] pData; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir } 467