xref: /trunk/main/vcl/source/gdi/animate.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #define ENABLE_BYTESTRING_STREAM_OPERATORS
32*cdf0e10cSrcweir #include <vcl/animate.hxx>
33*cdf0e10cSrcweir #include <tools/debug.hxx>
34*cdf0e10cSrcweir #include <tools/stream.hxx>
35*cdf0e10cSrcweir #include <rtl/crc.h>
36*cdf0e10cSrcweir #include <vcl/virdev.hxx>
37*cdf0e10cSrcweir #include <vcl/window.hxx>
38*cdf0e10cSrcweir #include <impanmvw.hxx>
39*cdf0e10cSrcweir DBG_NAME( Animation )
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir // -----------
42*cdf0e10cSrcweir // - Defines -
43*cdf0e10cSrcweir // -----------
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define MIN_TIMEOUT 2L
46*cdf0e10cSrcweir #define INC_TIMEOUT 0L
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir // -----------
49*cdf0e10cSrcweir // - statics -
50*cdf0e10cSrcweir // -----------
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir sal_uLong Animation::mnAnimCount = 0UL;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir // -------------------
55*cdf0e10cSrcweir // - AnimationBitmap -
56*cdf0e10cSrcweir // -------------------
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir sal_uLong AnimationBitmap::GetChecksum() const
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     sal_uInt32  nCrc = aBmpEx.GetChecksum();
61*cdf0e10cSrcweir     SVBT32      aBT32;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     UInt32ToSVBT32( aPosPix.X(), aBT32 );
64*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     UInt32ToSVBT32( aPosPix.Y(), aBT32 );
67*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     UInt32ToSVBT32( aSizePix.Width(), aBT32 );
70*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     UInt32ToSVBT32( aSizePix.Height(), aBT32 );
73*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     UInt32ToSVBT32( (long) nWait, aBT32 );
76*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     UInt32ToSVBT32( (long) eDisposal, aBT32 );
79*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     UInt32ToSVBT32( (long) bUserInput, aBT32 );
82*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     return nCrc;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // -------------
88*cdf0e10cSrcweir // - Animation -
89*cdf0e10cSrcweir // -------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir Animation::Animation() :
92*cdf0e10cSrcweir     mnLoopCount         ( 0 ),
93*cdf0e10cSrcweir     mnLoops             ( 0 ),
94*cdf0e10cSrcweir     mnPos               ( 0 ),
95*cdf0e10cSrcweir     meCycleMode         ( CYCLE_NORMAL ),
96*cdf0e10cSrcweir     mbIsInAnimation     ( sal_False ),
97*cdf0e10cSrcweir     mbLoopTerminated    ( sal_False ),
98*cdf0e10cSrcweir     mbIsWaiting         ( sal_False )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     DBG_CTOR( Animation, NULL );
101*cdf0e10cSrcweir     maTimer.SetTimeoutHdl( LINK( this, Animation, ImplTimeoutHdl ) );
102*cdf0e10cSrcweir     mpViewList = new List;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir // -----------------------------------------------------------------------
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir Animation::Animation( const Animation& rAnimation ) :
108*cdf0e10cSrcweir     maBitmapEx          ( rAnimation.maBitmapEx ),
109*cdf0e10cSrcweir     maGlobalSize        ( rAnimation.maGlobalSize ),
110*cdf0e10cSrcweir     mnLoopCount         ( rAnimation.mnLoopCount ),
111*cdf0e10cSrcweir     mnPos               ( rAnimation.mnPos ),
112*cdf0e10cSrcweir     meCycleMode         ( rAnimation.meCycleMode ),
113*cdf0e10cSrcweir     mbIsInAnimation     ( sal_False ),
114*cdf0e10cSrcweir     mbLoopTerminated    ( rAnimation.mbLoopTerminated ),
115*cdf0e10cSrcweir     mbIsWaiting         ( rAnimation.mbIsWaiting )
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     DBG_CTOR( Animation, NULL );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     for( long i = 0, nCount = rAnimation.maList.Count(); i < nCount; i++ )
120*cdf0e10cSrcweir         maList.Insert( new AnimationBitmap( *(AnimationBitmap*) rAnimation.maList.GetObject( i ) ), LIST_APPEND );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     maTimer.SetTimeoutHdl( LINK( this, Animation, ImplTimeoutHdl ) );
123*cdf0e10cSrcweir     mpViewList = new List;
124*cdf0e10cSrcweir     mnLoops = mbLoopTerminated ? 0 : mnLoopCount;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir // -----------------------------------------------------------------------
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir Animation::~Animation()
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     DBG_DTOR( Animation, NULL );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     if( mbIsInAnimation )
134*cdf0e10cSrcweir         Stop();
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     for( void* pStepBmp = maList.First(); pStepBmp; pStepBmp = maList.Next() )
137*cdf0e10cSrcweir         delete (AnimationBitmap*) pStepBmp;
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     for( void* pView = mpViewList->First(); pView; pView = mpViewList->Next() )
140*cdf0e10cSrcweir         delete (ImplAnimView*) pView;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     delete mpViewList;
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir // -----------------------------------------------------------------------
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir Animation& Animation::operator=( const Animation& rAnimation )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     Clear();
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     for( long i = 0, nCount = rAnimation.maList.Count(); i < nCount; i++ )
152*cdf0e10cSrcweir         maList.Insert( new AnimationBitmap( *(AnimationBitmap*) rAnimation.maList.GetObject( i ) ), LIST_APPEND );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     maGlobalSize = rAnimation.maGlobalSize;
155*cdf0e10cSrcweir     maBitmapEx = rAnimation.maBitmapEx;
156*cdf0e10cSrcweir     meCycleMode = rAnimation.meCycleMode;
157*cdf0e10cSrcweir     mnLoopCount = rAnimation.mnLoopCount;
158*cdf0e10cSrcweir     mnPos = rAnimation.mnPos;
159*cdf0e10cSrcweir     mbLoopTerminated = rAnimation.mbLoopTerminated;
160*cdf0e10cSrcweir     mbIsWaiting = rAnimation.mbIsWaiting;
161*cdf0e10cSrcweir     mnLoops = mbLoopTerminated ? 0 : mnLoopCount;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     return *this;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir // -----------------------------------------------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir sal_Bool Animation::operator==( const Animation& rAnimation ) const
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     const sal_uLong nCount = maList.Count();
171*cdf0e10cSrcweir     sal_Bool        bRet = sal_False;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     if( rAnimation.maList.Count() == nCount &&
174*cdf0e10cSrcweir         rAnimation.maBitmapEx == maBitmapEx &&
175*cdf0e10cSrcweir         rAnimation.maGlobalSize == maGlobalSize &&
176*cdf0e10cSrcweir         rAnimation.meCycleMode == meCycleMode )
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         bRet = sal_True;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         for( sal_uLong n = 0; n < nCount; n++ )
181*cdf0e10cSrcweir         {
182*cdf0e10cSrcweir             if( ( *(AnimationBitmap*) maList.GetObject( n ) ) !=
183*cdf0e10cSrcweir                 ( *(AnimationBitmap*) rAnimation.maList.GetObject( n ) ) )
184*cdf0e10cSrcweir             {
185*cdf0e10cSrcweir                 bRet = sal_False;
186*cdf0e10cSrcweir                 break;
187*cdf0e10cSrcweir             }
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     return bRet;
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir // ------------------------------------------------------------------
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir sal_Bool Animation::IsEqual( const Animation& rAnimation ) const
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     const sal_uLong nCount = maList.Count();
199*cdf0e10cSrcweir     sal_Bool        bRet = sal_False;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     if( rAnimation.maList.Count() == nCount &&
202*cdf0e10cSrcweir         rAnimation.maBitmapEx.IsEqual( maBitmapEx ) &&
203*cdf0e10cSrcweir         rAnimation.maGlobalSize == maGlobalSize &&
204*cdf0e10cSrcweir         rAnimation.meCycleMode == meCycleMode )
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         for( sal_uLong n = 0; ( n < nCount ) && !bRet; n++ )
207*cdf0e10cSrcweir             if( ( (AnimationBitmap*) maList.GetObject( n ) )->IsEqual( *(AnimationBitmap*) rAnimation.maList.GetObject( n ) ) )
208*cdf0e10cSrcweir                 bRet = sal_True;
209*cdf0e10cSrcweir     }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     return bRet;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir // ------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir sal_Bool Animation::IsEmpty() const
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     return( maBitmapEx.IsEmpty() && !maList.Count() );
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir // ------------------------------------------------------------------
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void Animation::SetEmpty()
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     maTimer.Stop();
226*cdf0e10cSrcweir     mbIsInAnimation = sal_False;
227*cdf0e10cSrcweir     maGlobalSize = Size();
228*cdf0e10cSrcweir     maBitmapEx.SetEmpty();
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     for( void* pStepBmp = maList.First(); pStepBmp; pStepBmp = maList.Next() )
231*cdf0e10cSrcweir         delete (AnimationBitmap*) pStepBmp;
232*cdf0e10cSrcweir     maList.Clear();
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     for( void* pView = mpViewList->First(); pView; pView = mpViewList->Next() )
235*cdf0e10cSrcweir         delete (ImplAnimView*) pView;
236*cdf0e10cSrcweir     mpViewList->Clear();
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir // -----------------------------------------------------------------------
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void Animation::Clear()
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     SetEmpty();
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir // -----------------------------------------------------------------------
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir sal_Bool Animation::IsTransparent() const
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     Point       aPoint;
251*cdf0e10cSrcweir     Rectangle   aRect( aPoint, maGlobalSize );
252*cdf0e10cSrcweir     sal_Bool        bRet = sal_False;
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     // Falls irgendein 'kleines' Bildchen durch den Hintergrund
255*cdf0e10cSrcweir     // ersetzt werden soll, muessen wir 'transparent' sein, um
256*cdf0e10cSrcweir     // richtig dargestellt zu werden, da die Appl. aus Optimierungsgruenden
257*cdf0e10cSrcweir     // kein Invalidate auf nicht-transp. Grafiken ausfuehren
258*cdf0e10cSrcweir     for( long i = 0, nCount = maList.Count(); i < nCount; i++ )
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         const AnimationBitmap* pAnimBmp = (AnimationBitmap*) maList.GetObject( i );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir         if( DISPOSE_BACK == pAnimBmp->eDisposal && Rectangle( pAnimBmp->aPosPix, pAnimBmp->aSizePix ) != aRect )
263*cdf0e10cSrcweir         {
264*cdf0e10cSrcweir             bRet = sal_True;
265*cdf0e10cSrcweir             break;
266*cdf0e10cSrcweir         }
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     if( !bRet )
270*cdf0e10cSrcweir         bRet = maBitmapEx.IsTransparent();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     return bRet;
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir // -----------------------------------------------------------------------
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir sal_uLong Animation::GetSizeBytes() const
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     sal_uLong nSizeBytes = GetBitmapEx().GetSizeBytes();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     for( long i = 0, nCount = maList.Count(); i < nCount; i++ )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         const AnimationBitmap* pAnimBmp = (AnimationBitmap*) maList.GetObject( i );
284*cdf0e10cSrcweir         nSizeBytes += pAnimBmp->aBmpEx.GetSizeBytes();
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     return nSizeBytes;
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir // -----------------------------------------------------------------------
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir sal_uLong Animation::GetChecksum() const
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     SVBT32      aBT32;
295*cdf0e10cSrcweir     sal_uInt32  nCrc = GetBitmapEx().GetChecksum();
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     UInt32ToSVBT32( maList.Count(), aBT32 );
298*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     UInt32ToSVBT32( maGlobalSize.Width(), aBT32 );
301*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     UInt32ToSVBT32( maGlobalSize.Height(), aBT32 );
304*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     UInt32ToSVBT32( (long) meCycleMode, aBT32 );
307*cdf0e10cSrcweir     nCrc = rtl_crc32( nCrc, aBT32, 4 );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     for( long i = 0, nCount = maList.Count(); i < nCount; i++ )
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         UInt32ToSVBT32( ( (AnimationBitmap*) maList.GetObject( i ) )->GetChecksum(), aBT32 );
312*cdf0e10cSrcweir         nCrc = rtl_crc32( nCrc, aBT32, 4 );
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     return nCrc;
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir // -----------------------------------------------------------------------
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir sal_Bool Animation::Start( OutputDevice* pOut, const Point& rDestPt, long nExtraData,
321*cdf0e10cSrcweir                        OutputDevice* pFirstFrameOutDev )
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     return Start( pOut, rDestPt, pOut->PixelToLogic( maGlobalSize ), nExtraData, pFirstFrameOutDev );
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir // -----------------------------------------------------------------------
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir sal_Bool Animation::Start( OutputDevice* pOut, const Point& rDestPt, const Size& rDestSz, long nExtraData,
329*cdf0e10cSrcweir                        OutputDevice* pFirstFrameOutDev )
330*cdf0e10cSrcweir {
331*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     if( maList.Count() )
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         if( ( pOut->GetOutDevType() == OUTDEV_WINDOW ) && !mbLoopTerminated &&
336*cdf0e10cSrcweir             ( ANIMATION_TIMEOUT_ON_CLICK != ( (AnimationBitmap*) maList.GetObject( mnPos ) )->nWait ) )
337*cdf0e10cSrcweir         {
338*cdf0e10cSrcweir             ImplAnimView*   pView;
339*cdf0e10cSrcweir             ImplAnimView*   pMatch = NULL;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir             for( pView = (ImplAnimView*) mpViewList->First(); pView; pView = (ImplAnimView*) mpViewList->Next() )
342*cdf0e10cSrcweir             {
343*cdf0e10cSrcweir                 if( pView->ImplMatches( pOut, nExtraData ) )
344*cdf0e10cSrcweir                 {
345*cdf0e10cSrcweir                     if( pView->ImplGetOutPos() == rDestPt &&
346*cdf0e10cSrcweir                         pView->ImplGetOutSizePix() == pOut->LogicToPixel( rDestSz ) )
347*cdf0e10cSrcweir                     {
348*cdf0e10cSrcweir                         pView->ImplRepaint();
349*cdf0e10cSrcweir                         pMatch = pView;
350*cdf0e10cSrcweir                     }
351*cdf0e10cSrcweir                     else
352*cdf0e10cSrcweir                     {
353*cdf0e10cSrcweir                         delete (ImplAnimView*) mpViewList->Remove( pView );
354*cdf0e10cSrcweir                         pView = NULL;
355*cdf0e10cSrcweir                     }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir                     break;
358*cdf0e10cSrcweir                 }
359*cdf0e10cSrcweir             }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir             if( !mpViewList->Count() )
362*cdf0e10cSrcweir             {
363*cdf0e10cSrcweir                 maTimer.Stop();
364*cdf0e10cSrcweir                 mbIsInAnimation = sal_False;
365*cdf0e10cSrcweir                 mnPos = 0UL;
366*cdf0e10cSrcweir             }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir             if( !pMatch )
369*cdf0e10cSrcweir                 mpViewList->Insert( new ImplAnimView( this, pOut, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev ), LIST_APPEND );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir             if( !mbIsInAnimation )
372*cdf0e10cSrcweir             {
373*cdf0e10cSrcweir                 ImplRestartTimer( ( (AnimationBitmap*) maList.GetObject( mnPos ) )->nWait );
374*cdf0e10cSrcweir                 mbIsInAnimation = sal_True;
375*cdf0e10cSrcweir             }
376*cdf0e10cSrcweir         }
377*cdf0e10cSrcweir         else
378*cdf0e10cSrcweir             Draw( pOut, rDestPt, rDestSz );
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir         bRet = sal_True;
381*cdf0e10cSrcweir     }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     return bRet;
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir // -----------------------------------------------------------------------
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir void Animation::Stop( OutputDevice* pOut, long nExtraData )
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir     ImplAnimView* pView = (ImplAnimView*) mpViewList->First();
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     while( pView )
393*cdf0e10cSrcweir     {
394*cdf0e10cSrcweir         if( pView->ImplMatches( pOut, nExtraData ) )
395*cdf0e10cSrcweir         {
396*cdf0e10cSrcweir             delete (ImplAnimView*) mpViewList->Remove( pView );
397*cdf0e10cSrcweir             pView = (ImplAnimView*) mpViewList->GetCurObject();
398*cdf0e10cSrcweir         }
399*cdf0e10cSrcweir         else
400*cdf0e10cSrcweir             pView = (ImplAnimView*) mpViewList->Next();
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     if( !mpViewList->Count() )
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         maTimer.Stop();
406*cdf0e10cSrcweir         mbIsInAnimation = sal_False;
407*cdf0e10cSrcweir     }
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // -----------------------------------------------------------------------
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir void Animation::Draw( OutputDevice* pOut, const Point& rDestPt ) const
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir     Draw( pOut, rDestPt, pOut->PixelToLogic( maGlobalSize ) );
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir // -----------------------------------------------------------------------
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir void Animation::Draw( OutputDevice* pOut, const Point& rDestPt, const Size& rDestSz ) const
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir     const sal_uLong nCount = maList.Count();
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     if( nCount )
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         AnimationBitmap* pObj = (AnimationBitmap*) maList.GetObject( Min( mnPos, (long) nCount - 1L ) );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         if( pOut->GetConnectMetaFile() || ( pOut->GetOutDevType() == OUTDEV_PRINTER ) )
428*cdf0e10cSrcweir             ( (AnimationBitmap*) maList.GetObject( 0 ) )->aBmpEx.Draw( pOut, rDestPt, rDestSz );
429*cdf0e10cSrcweir         else if( ANIMATION_TIMEOUT_ON_CLICK == pObj->nWait )
430*cdf0e10cSrcweir             pObj->aBmpEx.Draw( pOut, rDestPt, rDestSz );
431*cdf0e10cSrcweir         else
432*cdf0e10cSrcweir         {
433*cdf0e10cSrcweir             const sal_uLong nOldPos = mnPos;
434*cdf0e10cSrcweir             ( (Animation*) this )->mnPos = mbLoopTerminated ? ( nCount - 1UL ) : mnPos;
435*cdf0e10cSrcweir             delete new ImplAnimView( (Animation*) this, pOut, rDestPt, rDestSz, 0 );
436*cdf0e10cSrcweir             ( (Animation*) this )->mnPos = nOldPos;
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir // -----------------------------------------------------------------------
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir void Animation::ImplRestartTimer( sal_uLong nTimeout )
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     maTimer.SetTimeout( Max( nTimeout, (sal_uLong)(MIN_TIMEOUT + ( mnAnimCount - 1 ) * INC_TIMEOUT) ) * 10L );
446*cdf0e10cSrcweir     maTimer.Start();
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir // -----------------------------------------------------------------------
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir IMPL_LINK( Animation, ImplTimeoutHdl, Timer*, EMPTYARG )
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     const sal_uLong nAnimCount = maList.Count();
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     if( nAnimCount )
456*cdf0e10cSrcweir     {
457*cdf0e10cSrcweir         ImplAnimView*   pView;
458*cdf0e10cSrcweir         sal_Bool            bGlobalPause = sal_True;
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir         if( maNotifyLink.IsSet() )
461*cdf0e10cSrcweir         {
462*cdf0e10cSrcweir             AInfo* pAInfo;
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir             // create AInfo-List
465*cdf0e10cSrcweir             for( pView = (ImplAnimView*) mpViewList->First(); pView; pView = (ImplAnimView*) mpViewList->Next() )
466*cdf0e10cSrcweir                 maAInfoList.Insert( pView->ImplCreateAInfo() );
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir             maNotifyLink.Call( this );
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir             // set view state from AInfo structure
471*cdf0e10cSrcweir             for( pAInfo = (AInfo*) maAInfoList.First(); pAInfo; pAInfo = (AInfo*) maAInfoList.Next() )
472*cdf0e10cSrcweir             {
473*cdf0e10cSrcweir                 if( !pAInfo->pViewData )
474*cdf0e10cSrcweir                 {
475*cdf0e10cSrcweir                     pView = new ImplAnimView( this, pAInfo->pOutDev,
476*cdf0e10cSrcweir                                               pAInfo->aStartOrg, pAInfo->aStartSize, pAInfo->nExtraData );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir                     mpViewList->Insert( pView, LIST_APPEND );
479*cdf0e10cSrcweir                 }
480*cdf0e10cSrcweir                 else
481*cdf0e10cSrcweir                     pView = (ImplAnimView*) pAInfo->pViewData;
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir                 pView->ImplPause( pAInfo->bPause );
484*cdf0e10cSrcweir                 pView->ImplSetMarked( sal_True );
485*cdf0e10cSrcweir             }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir             // delete AInfo structures
488*cdf0e10cSrcweir             for( pAInfo = (AInfo*) maAInfoList.First(); pAInfo; pAInfo = (AInfo*) maAInfoList.Next() )
489*cdf0e10cSrcweir                 delete (AInfo*) pAInfo;
490*cdf0e10cSrcweir             maAInfoList.Clear();
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir             // delete all unmarked views and reset marked state
493*cdf0e10cSrcweir             pView = (ImplAnimView*) mpViewList->First();
494*cdf0e10cSrcweir             while( pView )
495*cdf0e10cSrcweir             {
496*cdf0e10cSrcweir                 if( !pView->ImplIsMarked() )
497*cdf0e10cSrcweir                 {
498*cdf0e10cSrcweir                     delete (ImplAnimView*) mpViewList->Remove( pView );
499*cdf0e10cSrcweir                     pView = (ImplAnimView*) mpViewList->GetCurObject();
500*cdf0e10cSrcweir                 }
501*cdf0e10cSrcweir                 else
502*cdf0e10cSrcweir                 {
503*cdf0e10cSrcweir                     if( !pView->ImplIsPause() )
504*cdf0e10cSrcweir                         bGlobalPause = sal_False;
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir                     pView->ImplSetMarked( sal_False );
507*cdf0e10cSrcweir                     pView = (ImplAnimView*) mpViewList->Next();
508*cdf0e10cSrcweir                 }
509*cdf0e10cSrcweir             }
510*cdf0e10cSrcweir         }
511*cdf0e10cSrcweir         else
512*cdf0e10cSrcweir             bGlobalPause = sal_False;
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir         if( !mpViewList->Count() )
515*cdf0e10cSrcweir             Stop();
516*cdf0e10cSrcweir         else if( bGlobalPause )
517*cdf0e10cSrcweir             ImplRestartTimer( 10 );
518*cdf0e10cSrcweir         else
519*cdf0e10cSrcweir         {
520*cdf0e10cSrcweir             AnimationBitmap* pStepBmp = (AnimationBitmap*) maList.GetObject( ++mnPos );
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir             if( !pStepBmp )
523*cdf0e10cSrcweir             {
524*cdf0e10cSrcweir                 if( mnLoops == 1 )
525*cdf0e10cSrcweir                 {
526*cdf0e10cSrcweir                     Stop();
527*cdf0e10cSrcweir                     mbLoopTerminated = sal_True;
528*cdf0e10cSrcweir                     mnPos = nAnimCount - 1UL;
529*cdf0e10cSrcweir                     maBitmapEx = ( (AnimationBitmap*) maList.GetObject( mnPos ) )->aBmpEx;
530*cdf0e10cSrcweir                     return 0L;
531*cdf0e10cSrcweir                 }
532*cdf0e10cSrcweir                 else
533*cdf0e10cSrcweir                 {
534*cdf0e10cSrcweir                     if( mnLoops )
535*cdf0e10cSrcweir                         mnLoops--;
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir                     mnPos = 0;
538*cdf0e10cSrcweir                     pStepBmp = (AnimationBitmap*) maList.GetObject( mnPos );
539*cdf0e10cSrcweir                 }
540*cdf0e10cSrcweir             }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir             // Paint all views; after painting check, if view is
543*cdf0e10cSrcweir             // marked; in this case remove view, because area of output
544*cdf0e10cSrcweir             // lies out of display area of window; mark state is
545*cdf0e10cSrcweir             // set from view itself
546*cdf0e10cSrcweir             pView = (ImplAnimView*) mpViewList->First();
547*cdf0e10cSrcweir             while( pView )
548*cdf0e10cSrcweir             {
549*cdf0e10cSrcweir                 pView->ImplDraw( mnPos );
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir                 if( pView->ImplIsMarked() )
552*cdf0e10cSrcweir                 {
553*cdf0e10cSrcweir                     delete (ImplAnimView*) mpViewList->Remove( pView );
554*cdf0e10cSrcweir                     pView = (ImplAnimView*) mpViewList->GetCurObject();
555*cdf0e10cSrcweir                 }
556*cdf0e10cSrcweir                 else
557*cdf0e10cSrcweir                     pView = (ImplAnimView*) mpViewList->Next();
558*cdf0e10cSrcweir             }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir             // stop or restart timer
561*cdf0e10cSrcweir             if( !mpViewList->Count() )
562*cdf0e10cSrcweir                 Stop();
563*cdf0e10cSrcweir             else
564*cdf0e10cSrcweir                 ImplRestartTimer( pStepBmp->nWait );
565*cdf0e10cSrcweir         }
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     else
568*cdf0e10cSrcweir         Stop();
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     return 0L;
571*cdf0e10cSrcweir }
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir // -----------------------------------------------------------------------
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir sal_Bool Animation::Insert( const AnimationBitmap& rStepBmp )
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     if( !IsInAnimation() )
580*cdf0e10cSrcweir     {
581*cdf0e10cSrcweir         Point       aPoint;
582*cdf0e10cSrcweir         Rectangle   aGlobalRect( aPoint, maGlobalSize );
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir         maGlobalSize = aGlobalRect.Union( Rectangle( rStepBmp.aPosPix, rStepBmp.aSizePix ) ).GetSize();
585*cdf0e10cSrcweir         maList.Insert( new AnimationBitmap( rStepBmp ), LIST_APPEND );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir         // zunaechst nehmen wir die erste BitmapEx als Ersatz-BitmapEx
588*cdf0e10cSrcweir         if( maList.Count() == 1 )
589*cdf0e10cSrcweir             maBitmapEx = rStepBmp.aBmpEx;
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         bRet = sal_True;
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     return bRet;
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir // -----------------------------------------------------------------------
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir const AnimationBitmap& Animation::Get( sal_uInt16 nAnimation ) const
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir     DBG_ASSERT( ( nAnimation < maList.Count() ), "No object at this position" );
602*cdf0e10cSrcweir     return *(AnimationBitmap*) maList.GetObject( nAnimation );
603*cdf0e10cSrcweir }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir // -----------------------------------------------------------------------
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir void Animation::Replace( const AnimationBitmap& rNewAnimationBitmap, sal_uInt16 nAnimation )
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir     DBG_ASSERT( ( nAnimation < maList.Count() ), "No object at this position" );
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir     delete (AnimationBitmap*) maList.Replace( new AnimationBitmap( rNewAnimationBitmap ), nAnimation );
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir     // Falls wir an erster Stelle einfuegen,
614*cdf0e10cSrcweir     // muessen wir natuerlich auch,
615*cdf0e10cSrcweir     // auch die Ersatzdarstellungs-BitmapEx
616*cdf0e10cSrcweir     // aktualisieren;
617*cdf0e10cSrcweir     if ( ( !nAnimation && ( !mbLoopTerminated || ( maList.Count() == 1 ) ) ) ||
618*cdf0e10cSrcweir          ( ( nAnimation == maList.Count() - 1 ) && mbLoopTerminated ) )
619*cdf0e10cSrcweir     {
620*cdf0e10cSrcweir         maBitmapEx = rNewAnimationBitmap.aBmpEx;
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir }
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir // -----------------------------------------------------------------------
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir void Animation::SetLoopCount( const sal_uLong nLoopCount )
627*cdf0e10cSrcweir {
628*cdf0e10cSrcweir     mnLoopCount = nLoopCount;
629*cdf0e10cSrcweir     ResetLoopCount();
630*cdf0e10cSrcweir }
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir // -----------------------------------------------------------------------
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir void Animation::ResetLoopCount()
635*cdf0e10cSrcweir {
636*cdf0e10cSrcweir     mnLoops = mnLoopCount;
637*cdf0e10cSrcweir     mbLoopTerminated = sal_False;
638*cdf0e10cSrcweir }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir // -----------------------------------------------------------------------
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir sal_Bool Animation::Convert( BmpConversion eConversion )
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir     sal_Bool bRet;
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
649*cdf0e10cSrcweir     {
650*cdf0e10cSrcweir         bRet = sal_True;
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
653*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.Convert( eConversion );
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir         maBitmapEx.Convert( eConversion );
656*cdf0e10cSrcweir     }
657*cdf0e10cSrcweir     else
658*cdf0e10cSrcweir         bRet = sal_False;
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir     return bRet;
661*cdf0e10cSrcweir }
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir // -----------------------------------------------------------------------
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir sal_Bool Animation::ReduceColors( sal_uInt16 nNewColorCount, BmpReduce eReduce )
666*cdf0e10cSrcweir {
667*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     sal_Bool bRet;
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
672*cdf0e10cSrcweir     {
673*cdf0e10cSrcweir         bRet = sal_True;
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
676*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.ReduceColors( nNewColorCount, eReduce );
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir         maBitmapEx.ReduceColors( nNewColorCount, eReduce );
679*cdf0e10cSrcweir     }
680*cdf0e10cSrcweir     else
681*cdf0e10cSrcweir         bRet = sal_False;
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     return bRet;
684*cdf0e10cSrcweir }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir // -----------------------------------------------------------------------
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir sal_Bool Animation::Invert()
689*cdf0e10cSrcweir {
690*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir     sal_Bool bRet;
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
695*cdf0e10cSrcweir     {
696*cdf0e10cSrcweir         bRet = sal_True;
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
699*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.Invert();
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir         maBitmapEx.Invert();
702*cdf0e10cSrcweir     }
703*cdf0e10cSrcweir     else
704*cdf0e10cSrcweir         bRet = sal_False;
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir     return bRet;
707*cdf0e10cSrcweir }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir // -----------------------------------------------------------------------
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir sal_Bool Animation::Mirror( sal_uLong nMirrorFlags )
712*cdf0e10cSrcweir {
713*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     sal_Bool    bRet;
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
718*cdf0e10cSrcweir     {
719*cdf0e10cSrcweir         bRet = sal_True;
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir         if( nMirrorFlags )
722*cdf0e10cSrcweir         {
723*cdf0e10cSrcweir             for( AnimationBitmap* pStepBmp = (AnimationBitmap*) maList.First();
724*cdf0e10cSrcweir                  pStepBmp && bRet;
725*cdf0e10cSrcweir                  pStepBmp = (AnimationBitmap*) maList.Next() )
726*cdf0e10cSrcweir             {
727*cdf0e10cSrcweir                 if( ( bRet = pStepBmp->aBmpEx.Mirror( nMirrorFlags ) ) == sal_True )
728*cdf0e10cSrcweir                 {
729*cdf0e10cSrcweir                     if( nMirrorFlags & BMP_MIRROR_HORZ )
730*cdf0e10cSrcweir                         pStepBmp->aPosPix.X() = maGlobalSize.Width() - pStepBmp->aPosPix.X() - pStepBmp->aSizePix.Width();
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir                     if( nMirrorFlags & BMP_MIRROR_VERT )
733*cdf0e10cSrcweir                         pStepBmp->aPosPix.Y() = maGlobalSize.Height() - pStepBmp->aPosPix.Y() - pStepBmp->aSizePix.Height();
734*cdf0e10cSrcweir                 }
735*cdf0e10cSrcweir             }
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir             maBitmapEx.Mirror( nMirrorFlags );
738*cdf0e10cSrcweir         }
739*cdf0e10cSrcweir     }
740*cdf0e10cSrcweir     else
741*cdf0e10cSrcweir         bRet = sal_False;
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     return bRet;
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir // -----------------------------------------------------------------------
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir sal_Bool Animation::Dither( sal_uLong nDitherFlags )
749*cdf0e10cSrcweir {
750*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir     sal_Bool bRet;
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
755*cdf0e10cSrcweir     {
756*cdf0e10cSrcweir         bRet = sal_True;
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
759*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.Dither( nDitherFlags );
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir         maBitmapEx.Dither( nDitherFlags );
762*cdf0e10cSrcweir     }
763*cdf0e10cSrcweir     else
764*cdf0e10cSrcweir         bRet = sal_False;
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir     return bRet;
767*cdf0e10cSrcweir }
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir // -----------------------------------------------------------------------
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir sal_Bool Animation::Adjust( short nLuminancePercent, short nContrastPercent,
772*cdf0e10cSrcweir              short nChannelRPercent, short nChannelGPercent, short nChannelBPercent,
773*cdf0e10cSrcweir              double fGamma, sal_Bool bInvert )
774*cdf0e10cSrcweir {
775*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir     sal_Bool bRet;
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
780*cdf0e10cSrcweir     {
781*cdf0e10cSrcweir         bRet = sal_True;
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
784*cdf0e10cSrcweir         {
785*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.Adjust( nLuminancePercent, nContrastPercent,
786*cdf0e10cSrcweir                                                                     nChannelRPercent, nChannelGPercent, nChannelBPercent,
787*cdf0e10cSrcweir                                                                     fGamma, bInvert );
788*cdf0e10cSrcweir         }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir         maBitmapEx.Adjust( nLuminancePercent, nContrastPercent,
791*cdf0e10cSrcweir                            nChannelRPercent, nChannelGPercent, nChannelBPercent,
792*cdf0e10cSrcweir                            fGamma, bInvert );
793*cdf0e10cSrcweir     }
794*cdf0e10cSrcweir     else
795*cdf0e10cSrcweir         bRet = sal_False;
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir     return bRet;
798*cdf0e10cSrcweir }
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir // -----------------------------------------------------------------------
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir sal_Bool Animation::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam, const Link* pProgress )
803*cdf0e10cSrcweir {
804*cdf0e10cSrcweir     DBG_ASSERT( !IsInAnimation(), "Animation modified while it is animated" );
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     sal_Bool bRet;
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir     if( !IsInAnimation() && maList.Count() )
809*cdf0e10cSrcweir     {
810*cdf0e10cSrcweir         bRet = sal_True;
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir         for( void* pStepBmp = maList.First(); pStepBmp && bRet; pStepBmp = maList.Next() )
813*cdf0e10cSrcweir             bRet = ( ( AnimationBitmap*) pStepBmp )->aBmpEx.Filter( eFilter, pFilterParam, pProgress );
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir         maBitmapEx.Filter( eFilter, pFilterParam, pProgress );
816*cdf0e10cSrcweir     }
817*cdf0e10cSrcweir     else
818*cdf0e10cSrcweir         bRet = sal_False;
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir     return bRet;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir // -----------------------------------------------------------------------
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const Animation& rAnimation )
826*cdf0e10cSrcweir {
827*cdf0e10cSrcweir     const sal_uInt16 nCount = rAnimation.Count();
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir     if( nCount )
830*cdf0e10cSrcweir     {
831*cdf0e10cSrcweir         const ByteString    aDummyStr;
832*cdf0e10cSrcweir         const sal_uInt32        nDummy32 = 0UL;
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir         // Falls keine BitmapEx gesetzt wurde, schreiben wir
835*cdf0e10cSrcweir         // einfach die erste Bitmap der Animation
836*cdf0e10cSrcweir         if( !rAnimation.GetBitmapEx().GetBitmap() )
837*cdf0e10cSrcweir             rOStm << rAnimation.Get( 0 ).aBmpEx;
838*cdf0e10cSrcweir         else
839*cdf0e10cSrcweir             rOStm << rAnimation.GetBitmapEx();
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir         // Kennung schreiben ( SDANIMA1 )
842*cdf0e10cSrcweir         rOStm << (sal_uInt32) 0x5344414e << (sal_uInt32) 0x494d4931;
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < nCount; i++ )
845*cdf0e10cSrcweir         {
846*cdf0e10cSrcweir             const AnimationBitmap&  rAnimBmp = rAnimation.Get( i );
847*cdf0e10cSrcweir             const sal_uInt16            nRest = nCount - i - 1;
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir             // AnimationBitmap schreiben
850*cdf0e10cSrcweir             rOStm << rAnimBmp.aBmpEx;
851*cdf0e10cSrcweir             rOStm << rAnimBmp.aPosPix;
852*cdf0e10cSrcweir             rOStm << rAnimBmp.aSizePix;
853*cdf0e10cSrcweir             rOStm << rAnimation.maGlobalSize;
854*cdf0e10cSrcweir             rOStm << (sal_uInt16) ( ( ANIMATION_TIMEOUT_ON_CLICK == rAnimBmp.nWait ) ? 65535 : rAnimBmp.nWait );
855*cdf0e10cSrcweir             rOStm << (sal_uInt16) rAnimBmp.eDisposal;
856*cdf0e10cSrcweir             rOStm << (sal_uInt8) rAnimBmp.bUserInput;
857*cdf0e10cSrcweir             rOStm << (sal_uInt32) rAnimation.mnLoopCount;
858*cdf0e10cSrcweir             rOStm << nDummy32;  // unbenutzt
859*cdf0e10cSrcweir             rOStm << nDummy32;  // unbenutzt
860*cdf0e10cSrcweir             rOStm << nDummy32;  // unbenutzt
861*cdf0e10cSrcweir             rOStm << aDummyStr; // unbenutzt
862*cdf0e10cSrcweir             rOStm << nRest;     // Anzahl der Strukturen, die noch _folgen_
863*cdf0e10cSrcweir         }
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     return rOStm;
867*cdf0e10cSrcweir }
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir // -----------------------------------------------------------------------
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, Animation& rAnimation )
872*cdf0e10cSrcweir {
873*cdf0e10cSrcweir     Bitmap  aBmp;
874*cdf0e10cSrcweir     sal_uLong   nStmPos = rIStm.Tell();
875*cdf0e10cSrcweir     sal_uInt32  nAnimMagic1, nAnimMagic2;
876*cdf0e10cSrcweir     sal_uInt16  nOldFormat = rIStm.GetNumberFormatInt();
877*cdf0e10cSrcweir     sal_Bool    bReadAnimations = sal_False;
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir     rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
880*cdf0e10cSrcweir     nStmPos = rIStm.Tell();
881*cdf0e10cSrcweir     rIStm >> nAnimMagic1 >> nAnimMagic2;
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir     rAnimation.Clear();
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir     // Wenn die BitmapEx am Anfang schon gelesen
886*cdf0e10cSrcweir     // wurde ( von Graphic ), koennen wir direkt die Animationsbitmaps einlesen
887*cdf0e10cSrcweir     if( ( nAnimMagic1 == 0x5344414e ) && ( nAnimMagic2 == 0x494d4931 ) && !rIStm.GetError() )
888*cdf0e10cSrcweir         bReadAnimations = sal_True;
889*cdf0e10cSrcweir     // ansonsten versuchen wir erstmal die Bitmap(-Ex) zu lesen
890*cdf0e10cSrcweir     else
891*cdf0e10cSrcweir     {
892*cdf0e10cSrcweir         rIStm.Seek( nStmPos );
893*cdf0e10cSrcweir         rIStm >> rAnimation.maBitmapEx;
894*cdf0e10cSrcweir         nStmPos = rIStm.Tell();
895*cdf0e10cSrcweir         rIStm >> nAnimMagic1 >> nAnimMagic2;
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir         if( ( nAnimMagic1 == 0x5344414e ) && ( nAnimMagic2 == 0x494d4931 ) && !rIStm.GetError() )
898*cdf0e10cSrcweir             bReadAnimations = sal_True;
899*cdf0e10cSrcweir         else
900*cdf0e10cSrcweir             rIStm.Seek( nStmPos );
901*cdf0e10cSrcweir     }
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir     // ggf. Animationsbitmaps lesen
904*cdf0e10cSrcweir     if( bReadAnimations )
905*cdf0e10cSrcweir     {
906*cdf0e10cSrcweir         AnimationBitmap aAnimBmp;
907*cdf0e10cSrcweir         BitmapEx        aBmpEx;
908*cdf0e10cSrcweir         ByteString      aDummyStr;
909*cdf0e10cSrcweir         sal_uInt32          nTmp32;
910*cdf0e10cSrcweir         sal_uInt16          nTmp16;
911*cdf0e10cSrcweir         sal_uInt8           cTmp;
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir         do
914*cdf0e10cSrcweir         {
915*cdf0e10cSrcweir             rIStm >> aAnimBmp.aBmpEx;
916*cdf0e10cSrcweir             rIStm >> aAnimBmp.aPosPix;
917*cdf0e10cSrcweir             rIStm >> aAnimBmp.aSizePix;
918*cdf0e10cSrcweir             rIStm >> rAnimation.maGlobalSize;
919*cdf0e10cSrcweir             rIStm >> nTmp16; aAnimBmp.nWait = ( ( 65535 == nTmp16 ) ? ANIMATION_TIMEOUT_ON_CLICK : nTmp16 );
920*cdf0e10cSrcweir             rIStm >> nTmp16; aAnimBmp.eDisposal = ( Disposal) nTmp16;
921*cdf0e10cSrcweir             rIStm >> cTmp; aAnimBmp.bUserInput = (sal_Bool) cTmp;
922*cdf0e10cSrcweir             rIStm >> nTmp32; rAnimation.mnLoopCount = (sal_uInt16) nTmp32;
923*cdf0e10cSrcweir             rIStm >> nTmp32;    // unbenutzt
924*cdf0e10cSrcweir             rIStm >> nTmp32;    // unbenutzt
925*cdf0e10cSrcweir             rIStm >> nTmp32;    // unbenutzt
926*cdf0e10cSrcweir             rIStm >> aDummyStr; // unbenutzt
927*cdf0e10cSrcweir             rIStm >> nTmp16;    // Rest zu lesen
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir             rAnimation.Insert( aAnimBmp );
930*cdf0e10cSrcweir         }
931*cdf0e10cSrcweir         while( nTmp16 && !rIStm.GetError() );
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir         rAnimation.ResetLoopCount();
934*cdf0e10cSrcweir     }
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir     rIStm.SetNumberFormatInt( nOldFormat );
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir     return rIStm;
939*cdf0e10cSrcweir }
940