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 "impanmvw.hxx" 32*cdf0e10cSrcweir #include <vcl/virdev.hxx> 33*cdf0e10cSrcweir #include <vcl/window.hxx> 34*cdf0e10cSrcweir #include <vcl/salbtype.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // ---------------- 37*cdf0e10cSrcweir // - ImplAnimView - 38*cdf0e10cSrcweir // ---------------- 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir ImplAnimView::ImplAnimView( Animation* pParent, OutputDevice* pOut, 41*cdf0e10cSrcweir const Point& rPt, const Size& rSz, 42*cdf0e10cSrcweir sal_uLong nExtraData, 43*cdf0e10cSrcweir OutputDevice* pFirstFrameOutDev ) : 44*cdf0e10cSrcweir mpParent ( pParent ), 45*cdf0e10cSrcweir mpOut ( pFirstFrameOutDev ? pFirstFrameOutDev : pOut ), 46*cdf0e10cSrcweir mnExtraData ( nExtraData ), 47*cdf0e10cSrcweir maPt ( rPt ), 48*cdf0e10cSrcweir maSz ( rSz ), 49*cdf0e10cSrcweir maSzPix ( mpOut->LogicToPixel( maSz ) ), 50*cdf0e10cSrcweir maClip ( mpOut->GetClipRegion() ), 51*cdf0e10cSrcweir mpBackground ( new VirtualDevice ), 52*cdf0e10cSrcweir mpRestore ( new VirtualDevice ), 53*cdf0e10cSrcweir meLastDisposal ( DISPOSE_BACK ), 54*cdf0e10cSrcweir mbPause ( sal_False ), 55*cdf0e10cSrcweir mbMarked ( sal_False ), 56*cdf0e10cSrcweir mbHMirr ( maSz.Width() < 0L ), 57*cdf0e10cSrcweir mbVMirr ( maSz.Height() < 0L ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir mpParent->ImplIncAnimCount(); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // mirrored horizontically? 62*cdf0e10cSrcweir if( mbHMirr ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir maDispPt.X() = maPt.X() + maSz.Width() + 1L; 65*cdf0e10cSrcweir maDispSz.Width() = -maSz.Width(); 66*cdf0e10cSrcweir maSzPix.Width() = -maSzPix.Width(); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir else 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir maDispPt.X() = maPt.X(); 71*cdf0e10cSrcweir maDispSz.Width() = maSz.Width(); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // mirrored vertically? 75*cdf0e10cSrcweir if( mbVMirr ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir maDispPt.Y() = maPt.Y() + maSz.Height() + 1L; 78*cdf0e10cSrcweir maDispSz.Height() = -maSz.Height(); 79*cdf0e10cSrcweir maSzPix.Height() = -maSzPix.Height(); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir else 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir maDispPt.Y() = maPt.Y(); 84*cdf0e10cSrcweir maDispSz.Height() = maSz.Height(); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // save background 88*cdf0e10cSrcweir mpBackground->SetOutputSizePixel( maSzPix ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir if( mpOut->GetOutDevType() == OUTDEV_WINDOW ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir MapMode aTempMap( mpOut->GetMapMode() ); 93*cdf0e10cSrcweir aTempMap.SetOrigin( Point() ); 94*cdf0e10cSrcweir mpBackground->SetMapMode( aTempMap ); 95*cdf0e10cSrcweir ( (Window*) mpOut )->SaveBackground( maDispPt, maDispSz, Point(), *mpBackground ); 96*cdf0e10cSrcweir mpBackground->SetMapMode( MapMode() ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir else 99*cdf0e10cSrcweir mpBackground->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // initial drawing to actual position 102*cdf0e10cSrcweir ImplDrawToPos( mpParent->ImplGetCurPos() ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // if first frame OutputDevice is set, update variables now for real OutputDevice 105*cdf0e10cSrcweir if( pFirstFrameOutDev ) 106*cdf0e10cSrcweir maClip = ( mpOut = pOut )->GetClipRegion(); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ------------------------------------------------------------------------ 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir ImplAnimView::~ImplAnimView() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir delete mpBackground; 114*cdf0e10cSrcweir delete mpRestore; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir mpParent->ImplDecAnimCount(); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // ------------------------------------------------------------------------ 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir sal_Bool ImplAnimView::ImplMatches( OutputDevice* pOut, long nExtraData ) const 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir sal_Bool bRet = sal_False; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir if( nExtraData ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir if( ( mnExtraData == nExtraData ) && ( !pOut || ( pOut == mpOut ) ) ) 128*cdf0e10cSrcweir bRet = sal_True; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else if( !pOut || ( pOut == mpOut ) ) 131*cdf0e10cSrcweir bRet = sal_True; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir return bRet; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // ------------------------------------------------------------------------ 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void ImplAnimView::ImplGetPosSize( const AnimationBitmap& rAnm, Point& rPosPix, Size& rSizePix ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir const Size& rAnmSize = mpParent->GetDisplaySizePixel(); 141*cdf0e10cSrcweir Point aPt2( rAnm.aPosPix.X() + rAnm.aSizePix.Width() - 1L, 142*cdf0e10cSrcweir rAnm.aPosPix.Y() + rAnm.aSizePix.Height() - 1L ); 143*cdf0e10cSrcweir double fFactX, fFactY; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // calculate x scaling 146*cdf0e10cSrcweir if( rAnmSize.Width() > 1L ) 147*cdf0e10cSrcweir fFactX = (double) ( maSzPix.Width() - 1L ) / ( rAnmSize.Width() - 1L ); 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir fFactX = 1.0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // calculate y scaling 152*cdf0e10cSrcweir if( rAnmSize.Height() > 1L ) 153*cdf0e10cSrcweir fFactY = (double) ( maSzPix.Height() - 1L ) / ( rAnmSize.Height() - 1L ); 154*cdf0e10cSrcweir else 155*cdf0e10cSrcweir fFactY = 1.0; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir rPosPix.X() = FRound( rAnm.aPosPix.X() * fFactX ); 158*cdf0e10cSrcweir rPosPix.Y() = FRound( rAnm.aPosPix.Y() * fFactY ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir aPt2.X() = FRound( aPt2.X() * fFactX ); 161*cdf0e10cSrcweir aPt2.Y() = FRound( aPt2.Y() * fFactY ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir rSizePix.Width() = aPt2.X() - rPosPix.X() + 1L; 164*cdf0e10cSrcweir rSizePix.Height() = aPt2.Y() - rPosPix.Y() + 1L; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // mirrored horizontically? 167*cdf0e10cSrcweir if( mbHMirr ) 168*cdf0e10cSrcweir rPosPix.X() = maSzPix.Width() - 1L - aPt2.X(); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // mirrored vertically? 171*cdf0e10cSrcweir if( mbVMirr ) 172*cdf0e10cSrcweir rPosPix.Y() = maSzPix.Height() - 1L - aPt2.Y(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // ------------------------------------------------------------------------ 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir void ImplAnimView::ImplDrawToPos( sal_uLong nPos ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir VirtualDevice aVDev; 180*cdf0e10cSrcweir Region* pOldClip = !maClip.IsNull() ? new Region( mpOut->GetClipRegion() ) : NULL; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir aVDev.SetOutputSizePixel( maSzPix, sal_False ); 183*cdf0e10cSrcweir nPos = Min( nPos, (sal_uLong) mpParent->Count() - 1UL ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir for( sal_uLong i = 0UL; i <= nPos; i++ ) 186*cdf0e10cSrcweir ImplDraw( i, &aVDev ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if( pOldClip ) 189*cdf0e10cSrcweir mpOut->SetClipRegion( maClip ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir mpOut->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, aVDev ); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if( pOldClip ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir mpOut->SetClipRegion( *pOldClip ); 196*cdf0e10cSrcweir delete pOldClip; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // ------------------------------------------------------------------------ 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void ImplAnimView::ImplDraw( sal_uLong nPos ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir ImplDraw( nPos, NULL ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // ------------------------------------------------------------------------ 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir void ImplAnimView::ImplDraw( sal_uLong nPos, VirtualDevice* pVDev ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir Rectangle aOutRect( mpOut->PixelToLogic( Point() ), mpOut->GetOutputSize() ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // check, if output lies out of display 214*cdf0e10cSrcweir if( aOutRect.Intersection( Rectangle( maDispPt, maDispSz ) ).IsEmpty() ) 215*cdf0e10cSrcweir ImplSetMarked( sal_True ); 216*cdf0e10cSrcweir else if( !mbPause ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir VirtualDevice* pDev; 219*cdf0e10cSrcweir Point aPosPix; 220*cdf0e10cSrcweir Point aBmpPosPix; 221*cdf0e10cSrcweir Size aSizePix; 222*cdf0e10cSrcweir Size aBmpSizePix; 223*cdf0e10cSrcweir const sal_uLong nLastPos = mpParent->Count() - 1; 224*cdf0e10cSrcweir const AnimationBitmap& rAnm = mpParent->Get( (sal_uInt16) ( mnActPos = Min( nPos, nLastPos ) ) ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir ImplGetPosSize( rAnm, aPosPix, aSizePix ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // mirrored horizontically? 229*cdf0e10cSrcweir if( mbHMirr ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir aBmpPosPix.X() = aPosPix.X() + aSizePix.Width() - 1L; 232*cdf0e10cSrcweir aBmpSizePix.Width() = -aSizePix.Width(); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir else 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir aBmpPosPix.X() = aPosPix.X(); 237*cdf0e10cSrcweir aBmpSizePix.Width() = aSizePix.Width(); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // mirrored vertically? 241*cdf0e10cSrcweir if( mbVMirr ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir aBmpPosPix.Y() = aPosPix.Y() + aSizePix.Height() - 1L; 244*cdf0e10cSrcweir aBmpSizePix.Height() = -aSizePix.Height(); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir aBmpPosPix.Y() = aPosPix.Y(); 249*cdf0e10cSrcweir aBmpSizePix.Height() = aSizePix.Height(); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir // get output device 253*cdf0e10cSrcweir if( !pVDev ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir pDev = new VirtualDevice; 256*cdf0e10cSrcweir pDev->SetOutputSizePixel( maSzPix, sal_False ); 257*cdf0e10cSrcweir pDev->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir else 260*cdf0e10cSrcweir pDev = pVDev; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir // restore background after each run 263*cdf0e10cSrcweir if( !nPos ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir meLastDisposal = DISPOSE_BACK; 266*cdf0e10cSrcweir maRestPt = Point(); 267*cdf0e10cSrcweir maRestSz = maSzPix; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // restore 271*cdf0e10cSrcweir if( ( DISPOSE_NOT != meLastDisposal ) && maRestSz.Width() && maRestSz.Height() ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir if( DISPOSE_BACK == meLastDisposal ) 274*cdf0e10cSrcweir pDev->DrawOutDev( maRestPt, maRestSz, maRestPt, maRestSz, *mpBackground ); 275*cdf0e10cSrcweir else 276*cdf0e10cSrcweir pDev->DrawOutDev( maRestPt, maRestSz, Point(), maRestSz, *mpRestore ); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir meLastDisposal = rAnm.eDisposal; 280*cdf0e10cSrcweir maRestPt = aPosPix; 281*cdf0e10cSrcweir maRestSz = aSizePix; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // Was muessen wir beim naechsten Mal restaurieren ? 284*cdf0e10cSrcweir // ==> ggf. in eine Bitmap stecken, ansonsten SaveBitmap 285*cdf0e10cSrcweir // aus Speichergruenden loeschen 286*cdf0e10cSrcweir if( ( meLastDisposal == DISPOSE_BACK ) || ( meLastDisposal == DISPOSE_NOT ) ) 287*cdf0e10cSrcweir mpRestore->SetOutputSizePixel( Size( 1, 1 ), sal_False ); 288*cdf0e10cSrcweir else 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir mpRestore->SetOutputSizePixel( maRestSz, sal_False ); 291*cdf0e10cSrcweir mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnm.aBmpEx ); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir if( !pVDev ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir Region* pOldClip = !maClip.IsNull() ? new Region( mpOut->GetClipRegion() ) : NULL; 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir if( pOldClip ) 301*cdf0e10cSrcweir mpOut->SetClipRegion( maClip ); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir mpOut->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *pDev ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir if( pOldClip ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir mpOut->SetClipRegion( *pOldClip ); 308*cdf0e10cSrcweir delete pOldClip; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir delete pDev; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir if( mpOut->GetOutDevType() == OUTDEV_WINDOW ) 314*cdf0e10cSrcweir ( (Window*) mpOut )->Sync(); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // ------------------------------------------------------------------------ 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir void ImplAnimView::ImplRepaint() 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir const sal_Bool bOldPause = mbPause; 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir if( mpOut->GetOutDevType() == OUTDEV_WINDOW ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir MapMode aTempMap( mpOut->GetMapMode() ); 328*cdf0e10cSrcweir aTempMap.SetOrigin( Point() ); 329*cdf0e10cSrcweir mpBackground->SetMapMode( aTempMap ); 330*cdf0e10cSrcweir ( (Window*) mpOut )->SaveBackground( maDispPt, maDispSz, Point(), *mpBackground ); 331*cdf0e10cSrcweir mpBackground->SetMapMode( MapMode() ); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir else 334*cdf0e10cSrcweir mpBackground->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut ); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir mbPause = sal_False; 337*cdf0e10cSrcweir ImplDrawToPos( mnActPos ); 338*cdf0e10cSrcweir mbPause = bOldPause; 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir // ------------------------------------------------------------------------ 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir AInfo* ImplAnimView::ImplCreateAInfo() const 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir AInfo* pAInfo = new AInfo; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir pAInfo->aStartOrg = maPt; 348*cdf0e10cSrcweir pAInfo->aStartSize = maSz; 349*cdf0e10cSrcweir pAInfo->pOutDev = mpOut; 350*cdf0e10cSrcweir pAInfo->pViewData = (void*) this; 351*cdf0e10cSrcweir pAInfo->nExtraData = mnExtraData; 352*cdf0e10cSrcweir pAInfo->bPause = mbPause; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir return pAInfo; 355*cdf0e10cSrcweir } 356