2 * Copyright (c) 2002, 2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: A control that can be used to display an animation. It can be constructed from
15 * a skin, or from resource.
20 // AKNBITMAPANIMATION.H
23 #if !defined(__AKNBITMAPANIMATION_H__)
24 #define __AKNBITMAPANIMATION_H__
26 #if !defined(__COECNTRL_H__)
31 #include <AknControl.h>
32 #include <AknIconUtils.h>
35 * Client class for wserv animations based on bitmaps.
37 * Enables a client to package animation data, and send it to the window server for display.
38 * Requires the RAnimDll to be already instantiated. Also provides functionality for sending
39 * specific messages to configure the animation.
44 class RAknBitmapAnim : public RBitmapAnim
50 * @param aAnimDll must be already instantiated.
52 RAknBitmapAnim(RAnimDll& aAnimDll);
55 * Starts the animation, and displays the last frame when finished.
57 void StartAndKeepLastFrameL();
60 * Stops the animation.
62 * @return the error value returned from wserv
67 // FORWARD DECLARATIONS
68 class TResourceReader;
72 * A control that can be used to display an animation.
74 NONSHARABLE_CLASS(CAknBitmapAnimation) : public CAknControl
78 * 2 phase construction. The pattern for constructing this class is non-standard. Call
79 * NewL, set the container window, then call the appropriate method to contruct from
80 * either skin or resource.
82 IMPORT_C static CAknBitmapAnimation* NewL();
87 IMPORT_C virtual ~CAknBitmapAnimation();
91 * gives access to RBitmapAnimation.
93 * @return the RBitmapAnim
95 IMPORT_C RBitmapAnim& Animation();
98 * gives access to CBitmapAnimClientData.
100 * @return the CBitmapAnimClientData
102 IMPORT_C CBitmapAnimClientData* BitmapAnimData() const;
105 * Cancels the animation.
107 * @return the error code from stopping the animation
109 IMPORT_C TInt CancelAnimation();
112 * Sets the frame index, initialising the animation if necessary.
114 * @param aIndex the frame index
116 IMPORT_C void SetFrameIndexL(TInt aIndex);
119 * Sets the frame interval in milliSeconds, initialising the animation if necessary.
121 * @param aFrameIntervalInMilliSeconds the frame interval
123 IMPORT_C void SetFrameIntervalL(TInt aFrameIntervalInMilliSeconds);
126 * Starts the animation, initialising the animation if necessary, and starting the timer
129 IMPORT_C void StartAnimationL();
132 * Sets the scale mode for the animation frames that is used when the
133 * animation frames are scaled to the size of the control.
134 * Default scale mode is EAspectRatioPreserved.
137 * @param aMode scale mode
139 IMPORT_C void SetScaleModeForAnimationFrames(TScaleMode aMode);
142 * Sets the scale mode for the animation background frame that is used when the
143 * animation background frame is scaled to the size of the control.
144 * Default scale mode is EAspectRatioPreserved.
147 * @param aMode scale mode
149 IMPORT_C void SetScaleModeForAnimationBackgroundFrame(TScaleMode aMode);
152 * Excludes the animation frames from the icon cache.
153 * Note that this method should be called before setting the size of the control
154 * to be in effect. If the animation frames are created outside of the scope of this
155 * class method AknIconUtils::ExcludeFromCache should be called for animation frames
156 * to get the same effect.
158 * By default scalable animation frames are being put to icon cache after they are
160 * This makes it possible to retrieve recently used animation frames fast
161 * without the need to render them again.
162 * Excluding infrequently used animation frames from icon cache could
163 * improve performance and memory usage of the system.
167 IMPORT_C void ExcludeAnimationFramesFromCache();
171 * Records whether the animation has started. If there is a timer, it is cancelled.
173 * @param aHasStarted if ETrue, started flag is recorded; if EFalse, the existing flag value is not changed.
174 * @return returns KErrNone in the case of no error occurring.
176 TInt AnimationHasStarted(TBool aHasStarted);
180 * Construct the animation from skin.
182 * Usually this method should be called before ConstructFromResourceL,
183 * and if EFalse is returned the caller should try to construct the
184 * same animation with ConstructFromResourceL. The ownership of the
185 * constructed animation and its frames is vested in this class.
186 * Furthermore, the animation is not automatically updated during
190 * @param aItemID Item ID of the animation.
191 * @return ETrue if the animation was found and succesfully constructed.
192 * EFalse if the animation (or at least one of its frames) was not
195 IMPORT_C TBool ConstructFromSkinL( const TAknsItemID& aItemID );
197 public: // from CCoeControl
199 * Construct animation from resource. This can be called after a call to NewL. Can
200 * also be called after a failed attempt to call ConstructFromSkinL.
202 * @param aResourceReader the resource reader
204 IMPORT_C virtual void ConstructFromResourceL(TResourceReader& aResourceReader);
209 IMPORT_C virtual TSize MinimumSize();
213 * Starts the animation, initialising the animation if necessary, and starting the timer
216 IMPORT_C void StartAnimationL( TBool aKeepLastFrame );
218 private: // from CCoeControl
223 virtual void SizeChanged();
228 virtual void PositionChanged();
233 * @parm aRect the drawing rect
235 virtual void Draw(const TRect& aRect) const;
240 virtual void FocusChanged(TDrawNow aDrawNow);
246 CAknBitmapAnimation();
249 * Second phase construction
254 * Complete animation initialisation. Sets the animation window,
255 * the position, and the animation data. Records the fact that
256 * initialisation has occurred.
258 void CompleteAnimationInitialisationL();
261 * Checks the animation initialisation completion flag
263 * @return the initialisation flag
265 TBool IsInitialisationCompleted();
268 * Create frame data, by extracting the interval and position from
269 * the resource, and the frame data from the animation itself.
271 * @param aFramesReader the resource reader
272 * @param aFileName the animation file
273 * @param aVersion version of BMPANIM_DATA
274 * @return the frame data
276 CBitmapFrameData* CreateFrameDataFromResourceL(TResourceReader& aFramesReader, const TDesC& aFileName, const TInt8 aVersion);
279 * Set animation window
281 void SetAnimationWindowL();
285 * Callback for the animation timer
287 * @param aPtr pointer to the owning class
288 * @return any error value from the timer
290 static TInt AnimationStartedCallback(TAny* aPtr);
293 CBitmapAnimClientData* iBitmapAnimData;
295 RAknBitmapAnim iAnimation;
298 TScaleMode iScaleModeFrames;
299 TScaleMode iScaleModeBackgroundFrame;