epoc32/include/mw/aknbitmapanimation.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2002, 2006 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@4
     5
* under the terms of "Eclipse Public License v1.0"
williamr@2
     6
* which accompanies this distribution, and is available
williamr@4
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description: A control that can be used to display an animation. It can be constructed from 
williamr@2
    15
*   a skin, or from resource.
williamr@2
    16
* 
williamr@2
    17
*
williamr@2
    18
*/
williamr@2
    19
williamr@2
    20
// AKNBITMAPANIMATION.H
williamr@2
    21
//
williamr@2
    22
williamr@2
    23
#if !defined(__AKNBITMAPANIMATION_H__)
williamr@2
    24
#define __AKNBITMAPANIMATION_H__
williamr@2
    25
williamr@2
    26
#if !defined(__COECNTRL_H__)
williamr@2
    27
#include <coecntrl.h>
williamr@2
    28
#endif
williamr@2
    29
williamr@2
    30
#include <bmpancli.h>
williamr@2
    31
#include <AknControl.h>
williamr@2
    32
#include <AknIconUtils.h>
williamr@2
    33
williamr@2
    34
/**
williamr@2
    35
 * Client class for wserv animations based on bitmaps.
williamr@2
    36
 * 
williamr@2
    37
 * Enables a client to package animation data, and send it to the window server for display.
williamr@2
    38
 * Requires the RAnimDll to be already instantiated. Also provides functionality for sending
williamr@2
    39
 * specific messages to configure the animation.
williamr@2
    40
 *
williamr@2
    41
 *  @lib avkon
williamr@2
    42
 *  @since S60 0.9
williamr@2
    43
 */
williamr@2
    44
class RAknBitmapAnim : public RBitmapAnim
williamr@2
    45
    {
williamr@2
    46
public:
williamr@2
    47
    /**
williamr@2
    48
     * Constructor. 
williamr@2
    49
     *
williamr@2
    50
     * @param aAnimDll must be already instantiated.
williamr@2
    51
     */
williamr@2
    52
    RAknBitmapAnim(RAnimDll& aAnimDll);
williamr@2
    53
williamr@2
    54
    /**
williamr@2
    55
     * Starts the animation, and displays the last frame when finished.
williamr@2
    56
     */
williamr@2
    57
    void StartAndKeepLastFrameL();
williamr@2
    58
williamr@2
    59
    /**
williamr@2
    60
     * Stops the animation.
williamr@2
    61
     *
williamr@2
    62
     * @return the error value returned from wserv
williamr@2
    63
     */
williamr@2
    64
    TInt Stop();
williamr@2
    65
    };
williamr@2
    66
williamr@2
    67
// FORWARD DECLARATIONS
williamr@2
    68
class TResourceReader;
williamr@2
    69
class TAknsItemID;
williamr@2
    70
williamr@2
    71
/*
williamr@2
    72
 * A control that can be used to display an animation.
williamr@2
    73
 */
williamr@2
    74
NONSHARABLE_CLASS(CAknBitmapAnimation) : public CAknControl
williamr@2
    75
    {
williamr@2
    76
public:
williamr@2
    77
    /**
williamr@2
    78
     * 2 phase construction. The pattern for constructing this class is non-standard. Call 
williamr@2
    79
     * NewL, set the container window, then call the appropriate method to contruct from
williamr@2
    80
     * either skin or resource.
williamr@2
    81
     */
williamr@2
    82
    IMPORT_C static CAknBitmapAnimation* NewL();
williamr@2
    83
williamr@2
    84
    /**
williamr@2
    85
     * Destructor.
williamr@2
    86
     */
williamr@2
    87
    IMPORT_C virtual ~CAknBitmapAnimation();
williamr@2
    88
williamr@2
    89
public:
williamr@2
    90
    /**
williamr@2
    91
     * gives access to RBitmapAnimation.
williamr@2
    92
     *
williamr@2
    93
     * @return the RBitmapAnim
williamr@2
    94
     */
williamr@2
    95
    IMPORT_C RBitmapAnim& Animation();
williamr@2
    96
williamr@2
    97
    /**
williamr@2
    98
     * gives access to CBitmapAnimClientData.
williamr@2
    99
     *
williamr@2
   100
     * @return the CBitmapAnimClientData
williamr@2
   101
     */
williamr@2
   102
    IMPORT_C CBitmapAnimClientData* BitmapAnimData() const;
williamr@2
   103
williamr@2
   104
    /**
williamr@2
   105
     * Cancels the animation.
williamr@2
   106
     *
williamr@2
   107
     * @return the error code from stopping the animation
williamr@2
   108
     */
williamr@2
   109
    IMPORT_C TInt CancelAnimation();
williamr@2
   110
williamr@2
   111
    /**
williamr@2
   112
     * Sets the frame index, initialising the animation if necessary.
williamr@2
   113
     *
williamr@2
   114
     * @param aIndex the frame index
williamr@2
   115
     */
williamr@2
   116
    IMPORT_C void SetFrameIndexL(TInt aIndex);
williamr@2
   117
williamr@2
   118
    /**
williamr@2
   119
     * Sets the frame interval in milliSeconds, initialising the animation if necessary.
williamr@2
   120
     *
williamr@2
   121
     * @param aFrameIntervalInMilliSeconds the frame interval
williamr@2
   122
     */
williamr@2
   123
    IMPORT_C void SetFrameIntervalL(TInt aFrameIntervalInMilliSeconds);
williamr@2
   124
williamr@2
   125
    /**
williamr@2
   126
     * Starts the animation, initialising the animation if necessary, and starting the timer
williamr@2
   127
     * if necessary.
williamr@2
   128
     */
williamr@2
   129
    IMPORT_C void StartAnimationL();
williamr@2
   130
williamr@2
   131
    /**
williamr@2
   132
    * Sets the scale mode for the animation frames that is used when the
williamr@2
   133
    * animation frames are scaled to the size of the control.
williamr@2
   134
    * Default scale mode is EAspectRatioPreserved.
williamr@2
   135
    *
williamr@2
   136
    * @since 3.1
williamr@2
   137
    * @param aMode scale mode
williamr@2
   138
    */
williamr@2
   139
    IMPORT_C void SetScaleModeForAnimationFrames(TScaleMode aMode);
williamr@2
   140
williamr@2
   141
    /**
williamr@2
   142
    * Sets the scale mode for the animation background frame that is used when the
williamr@2
   143
    * animation background frame is scaled to the size of the control.
williamr@2
   144
    * Default scale mode is EAspectRatioPreserved.
williamr@2
   145
    *
williamr@2
   146
    * @since 3.1
williamr@2
   147
    * @param aMode scale mode
williamr@2
   148
    */
williamr@2
   149
    IMPORT_C void SetScaleModeForAnimationBackgroundFrame(TScaleMode aMode);
williamr@2
   150
williamr@2
   151
    /**
williamr@2
   152
    * Excludes the animation frames from the icon cache.    
williamr@2
   153
    * Note that this method should be called before setting the size of the control
williamr@2
   154
    * to be in effect. If the animation frames are created outside of the scope of this 
williamr@2
   155
    * class method AknIconUtils::ExcludeFromCache should be called for animation frames
williamr@2
   156
    * to get the same effect.
williamr@2
   157
    * 
williamr@2
   158
    * By default scalable animation frames are being put to icon cache after they are
williamr@2
   159
    * no longer used. 
williamr@2
   160
    * This makes it possible to retrieve recently used animation frames fast
williamr@2
   161
    * without the need to render them again.
williamr@2
   162
    * Excluding infrequently used animation frames from icon cache could 
williamr@2
   163
    * improve performance and memory usage of the system.
williamr@2
   164
    * 
williamr@2
   165
    * @since 3.1    
williamr@2
   166
    */
williamr@2
   167
    IMPORT_C void ExcludeAnimationFramesFromCache();
williamr@2
   168
    
williamr@2
   169
public: 
williamr@2
   170
    /**
williamr@2
   171
     * Records whether the animation has started. If there is a timer, it is cancelled.
williamr@2
   172
     *
williamr@2
   173
     * @param aHasStarted if ETrue, started flag is recorded; if EFalse, the existing flag value is not changed.
williamr@2
   174
     * @return returns KErrNone in the case of no error occurring.
williamr@2
   175
     */
williamr@2
   176
    TInt AnimationHasStarted(TBool aHasStarted);
williamr@2
   177
williamr@2
   178
public:
williamr@2
   179
    /**
williamr@2
   180
    * Construct the animation from skin.
williamr@2
   181
    *
williamr@2
   182
    * Usually this method should be called before ConstructFromResourceL,
williamr@2
   183
    * and if EFalse is returned the caller should try to construct the
williamr@2
   184
    * same animation with ConstructFromResourceL. The ownership of the
williamr@2
   185
    * constructed animation and its frames is vested in this class.
williamr@2
   186
    * Furthermore, the animation is not automatically updated during
williamr@2
   187
    * a skin change.
williamr@2
   188
    *
williamr@2
   189
    * @since 2.0
williamr@2
   190
    * @param aItemID Item ID of the animation.
williamr@2
   191
    * @return ETrue if the animation was found and succesfully constructed.
williamr@2
   192
    *   EFalse if the animation (or at least one of its frames) was not
williamr@2
   193
    *   found.
williamr@2
   194
    */
williamr@2
   195
    IMPORT_C TBool ConstructFromSkinL( const TAknsItemID& aItemID );
williamr@2
   196
williamr@2
   197
public: // from CCoeControl
williamr@2
   198
    /**
williamr@2
   199
     * Construct animation from resource. This can be called after a call to NewL. Can
williamr@2
   200
     * also be called after a failed attempt to call ConstructFromSkinL.
williamr@2
   201
     * 
williamr@2
   202
     * @param aResourceReader the resource reader
williamr@2
   203
     */
williamr@2
   204
    IMPORT_C virtual void ConstructFromResourceL(TResourceReader& aResourceReader);
williamr@2
   205
williamr@2
   206
    /**
williamr@2
   207
     * Minimum size.
williamr@2
   208
     */
williamr@2
   209
    IMPORT_C virtual TSize MinimumSize();
williamr@4
   210
    
williamr@4
   211
public:
williamr@4
   212
    /**
williamr@4
   213
     * Starts the animation, initialising the animation if necessary, and starting the timer
williamr@4
   214
     * if necessary.
williamr@4
   215
     */
williamr@4
   216
    IMPORT_C void StartAnimationL( TBool aKeepLastFrame );
williamr@2
   217
williamr@2
   218
private: // from CCoeControl
williamr@2
   219
    
williamr@2
   220
    /*
williamr@2
   221
     * Size changed.
williamr@2
   222
     */
williamr@2
   223
    virtual void SizeChanged();
williamr@2
   224
    
williamr@2
   225
    /*
williamr@2
   226
     * Position Changed
williamr@2
   227
     */
williamr@2
   228
    virtual void PositionChanged();
williamr@2
   229
    
williamr@2
   230
    /*
williamr@2
   231
     * Draw
williamr@2
   232
     *
williamr@2
   233
     * @parm aRect the drawing rect
williamr@2
   234
     */
williamr@2
   235
    virtual void Draw(const TRect& aRect) const;
williamr@2
   236
williamr@2
   237
    /*
williamr@2
   238
     * Focus Changed
williamr@2
   239
     */
williamr@2
   240
    virtual void FocusChanged(TDrawNow aDrawNow);
williamr@2
   241
private:
williamr@2
   242
williamr@2
   243
    /* 
williamr@2
   244
     * Constructor
williamr@2
   245
     */
williamr@2
   246
    CAknBitmapAnimation();
williamr@2
   247
    
williamr@2
   248
    /*
williamr@2
   249
     * Second phase construction
williamr@2
   250
     */
williamr@2
   251
    void ConstructL();
williamr@2
   252
    
williamr@2
   253
    /*
williamr@2
   254
     * Complete animation initialisation. Sets the animation window, 
williamr@2
   255
     * the position, and the animation data. Records the fact that 
williamr@2
   256
     * initialisation has occurred.
williamr@2
   257
     */
williamr@2
   258
    void CompleteAnimationInitialisationL();
williamr@2
   259
    
williamr@2
   260
    /*
williamr@2
   261
     * Checks the animation initialisation completion flag
williamr@2
   262
     *
williamr@2
   263
     * @return the initialisation flag
williamr@2
   264
     */
williamr@2
   265
    TBool IsInitialisationCompleted();
williamr@2
   266
    
williamr@2
   267
    /*
williamr@2
   268
     * Create frame data, by extracting the interval and position from
williamr@2
   269
     * the resource, and the frame data from the animation itself.
williamr@2
   270
     *
williamr@2
   271
     * @param aFramesReader the resource reader
williamr@2
   272
     * @param aFileName the animation file
williamr@2
   273
     * @param aVersion version of BMPANIM_DATA
williamr@2
   274
     * @return the frame data
williamr@2
   275
     */
williamr@2
   276
	CBitmapFrameData* CreateFrameDataFromResourceL(TResourceReader& aFramesReader, const TDesC& aFileName, const TInt8 aVersion);
williamr@2
   277
    
williamr@2
   278
    /*
williamr@2
   279
     * Set animation window
williamr@2
   280
     */
williamr@2
   281
    void SetAnimationWindowL();
williamr@2
   282
williamr@2
   283
private: // timer
williamr@2
   284
    /*
williamr@2
   285
     * Callback for the animation timer
williamr@2
   286
     *
williamr@2
   287
     * @param aPtr pointer to the owning class
williamr@2
   288
     * @return any error value from the timer
williamr@2
   289
     */
williamr@2
   290
    static TInt AnimationStartedCallback(TAny* aPtr);
williamr@2
   291
williamr@2
   292
private:
williamr@2
   293
    CBitmapAnimClientData* iBitmapAnimData;
williamr@2
   294
    RAnimDll iAnimDll;
williamr@2
   295
    RAknBitmapAnim iAnimation;
williamr@2
   296
    TInt iFlags;
williamr@2
   297
    CPeriodic* iTimer;
williamr@2
   298
    TScaleMode iScaleModeFrames;
williamr@2
   299
    TScaleMode iScaleModeBackgroundFrame;
williamr@2
   300
    TBool iGainedFocus;
williamr@2
   301
    };
williamr@2
   302
williamr@2
   303
#endif