1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <osl/file.h> 32*cdf0e10cSrcweir #include <tools/vcompat.hxx> 33*cdf0e10cSrcweir #include <tools/urlobj.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 36*cdf0e10cSrcweir #include <unotools/tempfile.hxx> 37*cdf0e10cSrcweir #include <ucbhelper/content.hxx> 38*cdf0e10cSrcweir #include <vcl/graph.hxx> 39*cdf0e10cSrcweir #include <vcl/gfxlink.hxx> 40*cdf0e10cSrcweir #include <vcl/cvtgrf.hxx> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ----------- 44*cdf0e10cSrcweir // - GfxLink - 45*cdf0e10cSrcweir // ----------- 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir GfxLink::GfxLink() : 48*cdf0e10cSrcweir meType ( GFX_LINK_TYPE_NONE ), 49*cdf0e10cSrcweir mpBuf ( NULL ), 50*cdf0e10cSrcweir mpSwap ( NULL ), 51*cdf0e10cSrcweir mnBufSize ( 0 ), 52*cdf0e10cSrcweir mnUserId ( 0UL ), 53*cdf0e10cSrcweir mpImpData ( new ImpGfxLink ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // ------------------------------------------------------------------------ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir GfxLink::GfxLink( const GfxLink& rGfxLink ) : 60*cdf0e10cSrcweir mpImpData( new ImpGfxLink ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir ImplCopy( rGfxLink ); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // ------------------------------------------------------------------------ 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir GfxLink::GfxLink( sal_uInt8* pBuf, sal_uInt32 nSize, GfxLinkType nType, sal_Bool bOwns ) : 68*cdf0e10cSrcweir mpImpData( new ImpGfxLink ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir DBG_ASSERT( (pBuf != NULL && nSize) || (!bOwns && nSize == 0), 71*cdf0e10cSrcweir "GfxLink::GfxLink(): empty/NULL buffer given" ); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir meType = nType; 74*cdf0e10cSrcweir mnBufSize = nSize; 75*cdf0e10cSrcweir mpSwap = NULL; 76*cdf0e10cSrcweir mnUserId = 0UL; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir if( bOwns ) 79*cdf0e10cSrcweir mpBuf = new ImpBuffer( pBuf ); 80*cdf0e10cSrcweir else if( nSize ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir mpBuf = new ImpBuffer( nSize ); 83*cdf0e10cSrcweir memcpy( mpBuf->mpBuffer, pBuf, nSize ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir else 86*cdf0e10cSrcweir mpBuf = NULL; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // ------------------------------------------------------------------------ 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir GfxLink::~GfxLink() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir if( mpBuf && !( --mpBuf->mnRefCount ) ) 94*cdf0e10cSrcweir delete mpBuf; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir if( mpSwap && !( --mpSwap->mnRefCount ) ) 97*cdf0e10cSrcweir delete mpSwap; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir delete mpImpData; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ------------------------------------------------------------------------ 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir GfxLink& GfxLink::operator=( const GfxLink& rGfxLink ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir if( &rGfxLink != this ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if ( mpBuf && !( --mpBuf->mnRefCount ) ) 109*cdf0e10cSrcweir delete mpBuf; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir if( mpSwap && !( --mpSwap->mnRefCount ) ) 112*cdf0e10cSrcweir delete mpSwap; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir ImplCopy( rGfxLink ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir return *this; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // ------------------------------------------------------------------------ 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir sal_Bool GfxLink::IsEqual( const GfxLink& rGfxLink ) const 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir sal_Bool bIsEqual = sal_False; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir if ( ( mnBufSize == rGfxLink.mnBufSize ) && ( meType == rGfxLink.meType ) ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir const sal_uInt8* pSource = GetData(); 129*cdf0e10cSrcweir const sal_uInt8* pDest = rGfxLink.GetData(); 130*cdf0e10cSrcweir sal_uInt32 nSourceSize = GetDataSize(); 131*cdf0e10cSrcweir sal_uInt32 nDestSize = rGfxLink.GetDataSize(); 132*cdf0e10cSrcweir if ( pSource && pDest && ( nSourceSize == nDestSize ) ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir bIsEqual = memcmp( pSource, pDest, nSourceSize ) == 0; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else if ( ( pSource == 0 ) && ( pDest == 0 ) ) 137*cdf0e10cSrcweir bIsEqual = sal_True; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir return bIsEqual; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // ------------------------------------------------------------------------ 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void GfxLink::ImplCopy( const GfxLink& rGfxLink ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir mnBufSize = rGfxLink.mnBufSize; 147*cdf0e10cSrcweir meType = rGfxLink.meType; 148*cdf0e10cSrcweir mpBuf = rGfxLink.mpBuf; 149*cdf0e10cSrcweir mpSwap = rGfxLink.mpSwap; 150*cdf0e10cSrcweir mnUserId = rGfxLink.mnUserId; 151*cdf0e10cSrcweir *mpImpData = *rGfxLink.mpImpData; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if( mpBuf ) 154*cdf0e10cSrcweir mpBuf->mnRefCount++; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir if( mpSwap ) 157*cdf0e10cSrcweir mpSwap->mnRefCount++; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // ------------------------------------------------------------------------ 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir GfxLinkType GfxLink::GetType() const 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir return meType; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // ------------------------------------------------------------------------ 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sal_Bool GfxLink::IsNative() const 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir return( meType >= GFX_LINK_FIRST_NATIVE_ID && meType <= GFX_LINK_LAST_NATIVE_ID ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // ------------------------------------------------------------------------ 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir sal_uInt32 GfxLink::GetDataSize() const 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir return mnBufSize; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ------------------------------------------------------------------------ 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir const sal_uInt8* GfxLink::GetData() const 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if( IsSwappedOut() ) 186*cdf0e10cSrcweir ( (GfxLink*) this )->SwapIn(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir return( mpBuf ? mpBuf->mpBuffer : NULL ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ------------------------------------------------------------------------ 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir const Size& GfxLink::GetPrefSize() const 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir return mpImpData->maPrefSize; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // ------------------------------------------------------------------------ 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir void GfxLink::SetPrefSize( const Size& rPrefSize ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir mpImpData->maPrefSize = rPrefSize; 203*cdf0e10cSrcweir mpImpData->mbPrefSizeValid = true; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // ------------------------------------------------------------------------ 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir bool GfxLink::IsPrefSizeValid() 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir return mpImpData->mbPrefSizeValid; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // ------------------------------------------------------------------------ 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir const MapMode& GfxLink::GetPrefMapMode() const 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir return mpImpData->maPrefMapMode; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // ------------------------------------------------------------------------ 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir void GfxLink::SetPrefMapMode( const MapMode& rPrefMapMode ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir mpImpData->maPrefMapMode = rPrefMapMode; 225*cdf0e10cSrcweir mpImpData->mbPrefMapModeValid = true; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // ------------------------------------------------------------------------ 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir bool GfxLink::IsPrefMapModeValid() 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir return mpImpData->mbPrefMapModeValid; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // ------------------------------------------------------------------------ 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir sal_Bool GfxLink::LoadNative( Graphic& rGraphic ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir sal_Bool bRet = sal_False; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir if( IsNative() && mnBufSize ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir const sal_uInt8* pData = GetData(); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir if( pData ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir SvMemoryStream aMemStm; 248*cdf0e10cSrcweir sal_uLong nCvtType; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir aMemStm.SetBuffer( (char*) pData, mnBufSize, sal_False, mnBufSize ); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir switch( meType ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_GIF ): nCvtType = CVT_GIF; break; 255*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_JPG ): nCvtType = CVT_JPG; break; 256*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_PNG ): nCvtType = CVT_PNG; break; 257*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_TIF ): nCvtType = CVT_TIF; break; 258*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_WMF ): nCvtType = CVT_WMF; break; 259*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_MET ): nCvtType = CVT_MET; break; 260*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_PCT ): nCvtType = CVT_PCT; break; 261*cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_SVG ): nCvtType = CVT_SVG; break; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir default: nCvtType = CVT_UNKNOWN; break; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if( nCvtType && ( GraphicConverter::Import( aMemStm, rGraphic, nCvtType ) == ERRCODE_NONE ) ) 267*cdf0e10cSrcweir bRet = sal_True; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir return bRet; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // ------------------------------------------------------------------------ 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir void GfxLink::SwapOut() 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir if( !IsSwappedOut() && mpBuf ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir mpSwap = new ImpSwap( mpBuf->mpBuffer, mnBufSize ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if( !mpSwap->IsSwapped() ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir delete mpSwap; 285*cdf0e10cSrcweir mpSwap = NULL; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir else 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir if( !( --mpBuf->mnRefCount ) ) 290*cdf0e10cSrcweir delete mpBuf; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir mpBuf = NULL; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // ------------------------------------------------------------------------ 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir void GfxLink::SwapIn() 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir if( IsSwappedOut() ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir mpBuf = new ImpBuffer( mpSwap->GetData() ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir if( !( --mpSwap->mnRefCount ) ) 306*cdf0e10cSrcweir delete mpSwap; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir mpSwap = NULL; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir // ------------------------------------------------------------------------ 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir sal_Bool GfxLink::ExportNative( SvStream& rOStream ) const 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir if( GetDataSize() ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir if( IsSwappedOut() ) 319*cdf0e10cSrcweir mpSwap->WriteTo( rOStream ); 320*cdf0e10cSrcweir else if( GetData() ) 321*cdf0e10cSrcweir rOStream.Write( GetData(), GetDataSize() ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir return ( rOStream.GetError() == ERRCODE_NONE ); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // ------------------------------------------------------------------------ 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const GfxLink& rGfxLink ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rOStream, STREAM_WRITE, 2 ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // Version 1 334*cdf0e10cSrcweir rOStream << (sal_uInt16) rGfxLink.GetType() << rGfxLink.GetDataSize() << rGfxLink.GetUserId(); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // Version 2 337*cdf0e10cSrcweir rOStream << rGfxLink.GetPrefSize() << rGfxLink.GetPrefMapMode(); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir delete pCompat; 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir if( rGfxLink.GetDataSize() ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir if( rGfxLink.IsSwappedOut() ) 344*cdf0e10cSrcweir rGfxLink.mpSwap->WriteTo( rOStream ); 345*cdf0e10cSrcweir else if( rGfxLink.GetData() ) 346*cdf0e10cSrcweir rOStream.Write( rGfxLink.GetData(), rGfxLink.GetDataSize() ); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir return rOStream; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // ------------------------------------------------------------------------ 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, GfxLink& rGfxLink) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir Size aSize; 357*cdf0e10cSrcweir MapMode aMapMode; 358*cdf0e10cSrcweir sal_uInt32 nSize; 359*cdf0e10cSrcweir sal_uInt32 nUserId; 360*cdf0e10cSrcweir sal_uInt16 nType; 361*cdf0e10cSrcweir sal_uInt8* pBuf; 362*cdf0e10cSrcweir bool bMapAndSizeValid( false ); 363*cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rIStream, STREAM_READ ); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir // Version 1 366*cdf0e10cSrcweir rIStream >> nType >> nSize >> nUserId; 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir if( pCompat->GetVersion() >= 2 ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir rIStream >> aSize >> aMapMode; 371*cdf0e10cSrcweir bMapAndSizeValid = true; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir delete pCompat; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir pBuf = new sal_uInt8[ nSize ]; 377*cdf0e10cSrcweir rIStream.Read( pBuf, nSize ); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir rGfxLink = GfxLink( pBuf, nSize, (GfxLinkType) nType, sal_True ); 380*cdf0e10cSrcweir rGfxLink.SetUserId( nUserId ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir if( bMapAndSizeValid ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir rGfxLink.SetPrefSize( aSize ); 385*cdf0e10cSrcweir rGfxLink.SetPrefMapMode( aMapMode ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir return rIStream; 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir // ----------- 392*cdf0e10cSrcweir // - ImpSwap - 393*cdf0e10cSrcweir // ----------- 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir ImpSwap::ImpSwap( sal_uInt8* pData, sal_uLong nDataSize ) : 396*cdf0e10cSrcweir mnDataSize( nDataSize ), 397*cdf0e10cSrcweir mnRefCount( 1UL ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir if( pData && mnDataSize ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir ::utl::TempFile aTempFile; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir maURL = aTempFile.GetURL(); 404*cdf0e10cSrcweir if( maURL.getLength() ) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE ); 407*cdf0e10cSrcweir if( pOStm ) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir pOStm->Write( pData, mnDataSize ); 410*cdf0e10cSrcweir sal_Bool bError = ( ERRCODE_NONE != pOStm->GetError() ); 411*cdf0e10cSrcweir delete pOStm; 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir if( bError ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir osl_removeFile( maURL.pData ); 416*cdf0e10cSrcweir maURL = String(); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir // ------------------------------------------------------------------------ 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir ImpSwap::~ImpSwap() 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir if( IsSwapped() ) 428*cdf0e10cSrcweir osl_removeFile( maURL.pData ); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir // ------------------------------------------------------------------------ 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir sal_uInt8* ImpSwap::GetData() const 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir sal_uInt8* pData; 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if( IsSwapped() ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_READWRITE ); 440*cdf0e10cSrcweir if( pIStm ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir pData = new sal_uInt8[ mnDataSize ]; 443*cdf0e10cSrcweir pIStm->Read( pData, mnDataSize ); 444*cdf0e10cSrcweir sal_Bool bError = ( ERRCODE_NONE != pIStm->GetError() ); 445*cdf0e10cSrcweir delete pIStm; 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir if( bError ) 448*cdf0e10cSrcweir delete[] pData, pData = NULL; 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir else 451*cdf0e10cSrcweir pData = NULL; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir else 454*cdf0e10cSrcweir pData = NULL; 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir return pData; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir // ------------------------------------------------------------------------ 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir void ImpSwap::WriteTo( SvStream& rOStm ) const 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir sal_uInt8* pData = GetData(); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir if( pData ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir rOStm.Write( pData, mnDataSize ); 468*cdf0e10cSrcweir delete[] pData; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir } 471