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