startupservices/startupanimation/sanimihlplugin/inc/sanimihlctrl.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declaration of CSAnimIhlCtrl class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SANIMIHLCTRL_H
       
    20 #define SANIMIHLCTRL_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <MIHLViewerObserver.h>
       
    24 
       
    25 class MIHLBitmap;
       
    26 class MIHLFileImage;
       
    27 class MIHLImageViewer;
       
    28 class MSAnimObserver;
       
    29 class RFs;
       
    30 
       
    31 /**
       
    32 *  Controls interaction with IHL.
       
    33 *
       
    34 *  @lib None
       
    35 *  @since S60 3.2
       
    36 */
       
    37 NONSHARABLE_CLASS( CSAnimIhlCtrl ) : public CActive,
       
    38                                      public MIHLViewerObserver
       
    39     {
       
    40 
       
    41 public:
       
    42 
       
    43     /**
       
    44     * Constructs a CSAnimIhlCtrl object.
       
    45     *
       
    46     * @since S60 3.2
       
    47     *
       
    48     * @param aObserver Observer for screen update events.
       
    49     * @param aFs Fileserver reference.
       
    50     * @param aFileName Name of the image file to load.
       
    51     * @param aDisplayMode Display mode to use, if supported by the image.
       
    52     * @param aSize Requested size for the image.
       
    53     * @param aFrameDelay Frame delay for animation, unless specified in the
       
    54     * animation file itself.
       
    55     * @param aScalingEnabled Identifies whether to try to scale the image to fit
       
    56     * the screen size or just use the target size of the animation as it is.
       
    57     * @return The new object
       
    58     */
       
    59     static CSAnimIhlCtrl* NewL(
       
    60         MSAnimObserver& aObserver,
       
    61         RFs& aFs,
       
    62         const TDesC& aFileName,
       
    63         const TDisplayMode aDisplayMode,
       
    64         const TSize& aSize,
       
    65         const TTimeIntervalMicroSeconds32& aFrameDelay,
       
    66         const TBool aScalingEnabled );
       
    67 
       
    68     /**
       
    69     * Destructor.
       
    70     *
       
    71     * @since S60 3.2
       
    72     */
       
    73     virtual ~CSAnimIhlCtrl();
       
    74 
       
    75     /**
       
    76     * Get the backgroud colour of the image.
       
    77     * Should only be called after successfully loading the image.
       
    78     *
       
    79     * @since S60 3.2
       
    80     *
       
    81     * @return The backgroud colour requested for the image.
       
    82     */
       
    83     TRgb BackroundColour() const;
       
    84 
       
    85     /**
       
    86     * Start loading the animation.
       
    87     *
       
    88     * @since S60 3.2
       
    89     *
       
    90     * @param aCallBack To be called when the animation has been loaded.
       
    91     */
       
    92     void Load( const TCallBack& aCallBack );
       
    93 
       
    94     /**
       
    95     * Start loading the animation.
       
    96     *
       
    97     * @since S60 3.2
       
    98     *
       
    99     * @param aCallBack To be called when the animation has been loaded.
       
   100     */
       
   101     void Play( const TCallBack& aCallBack );
       
   102 
       
   103     /**
       
   104     * Returns a Symbian error code indicating the success / failure if loading
       
   105     * a frame. Only returns useful data when called after a call-back event,
       
   106     * before re-issuing LoadNextFrame.
       
   107     *
       
   108     * @since S60 3.2
       
   109     *
       
   110     * @return One of Symbian error codes.
       
   111     */
       
   112     TInt SuccessCode() const;
       
   113 
       
   114     /**
       
   115     * Stop loading and playing the animation.
       
   116     *
       
   117     * @since S60 3.2
       
   118     */
       
   119     void Stop();
       
   120 
       
   121 
       
   122 protected:
       
   123 
       
   124     /**
       
   125     * From CActive.
       
   126     * Implements cancellation of an outstanding request.
       
   127     *
       
   128     * @since S60 3.2
       
   129     */
       
   130     virtual void DoCancel();
       
   131 
       
   132     /**
       
   133     * From CActive.
       
   134     * Handles an active object's request completion event.
       
   135     * Never leaves.
       
   136     *
       
   137     * @since S60 3.2
       
   138     */
       
   139     virtual void RunL();
       
   140 
       
   141 
       
   142 private:
       
   143 
       
   144     /**
       
   145     * First phase constructor.
       
   146     *
       
   147     * @since S60 3.2
       
   148     *
       
   149     * @param aObserver Observer for screen update events.
       
   150     * @param aFrameDelay Frame delay for animation, unless specified in the
       
   151     * animation file itself.
       
   152     */
       
   153     CSAnimIhlCtrl(
       
   154         MSAnimObserver& aObserver,
       
   155         const TTimeIntervalMicroSeconds32& aFrameDelay );
       
   156 
       
   157     /**
       
   158     * Second phase constructor.
       
   159     *
       
   160     * @since S60 3.2
       
   161     *
       
   162     * @param aFs Fileserver reference.
       
   163     * @param aFileName Name of the image file to load.
       
   164     * @param aDisplayMode Display mode to use, if supported by the image.
       
   165     * @param aSize Requested size for the image.
       
   166     * @param aScalingEnabled Identifies whether to try to scale the image to fit
       
   167     * the screen size or just use the target size of the animation as it is.
       
   168     */
       
   169     void ConstructL(
       
   170         RFs& aFs,
       
   171         const TDesC& aFileName,
       
   172         const TDisplayMode aDisplayMode,
       
   173         const TSize& aSize,
       
   174         const TBool aScalingEnabled );
       
   175 
       
   176     /**
       
   177     * Select size to load the image to.
       
   178     *
       
   179     * @since S60 3.2
       
   180     *
       
   181     * @param aSize Requested size for the image.
       
   182     * @param aScalingEnabled Identifies whether to try to scale the image to fit
       
   183     * the screen size or just use the target size of the animation as it is.
       
   184     * @return A size that most closely matches the requested size but still
       
   185     * can be used as a load size for the image.
       
   186     */
       
   187     TSize SelectSize( const TSize& aSize, const TBool aScalingEnabled ) const;
       
   188 
       
   189     /**
       
   190     * Find an item in the array which is
       
   191     * a) as close as the target as possible and
       
   192     * b) smaller that the target (both width and height) and
       
   193     * c) closer to the target than the optimal size.
       
   194     * If there is no such item in the array, return the optimal size.
       
   195     *
       
   196     * @since S60 3.2
       
   197     *
       
   198     * @param aTarget Requested size.
       
   199     * @param aOptimalSize The optimal size for the image.
       
   200     * @param aOptions The available options.
       
   201     * @return Selected item in the array, or TSize( 0, 0 ).
       
   202     */
       
   203     TSize FindClosestMatch(
       
   204         const TSize& aTarget,
       
   205         const TSize& aOptimalSize,
       
   206         const RArray<TSize>& aOptions ) const;
       
   207 
       
   208 
       
   209     /**
       
   210     * Start loading the image in a multi-frame file.
       
   211     *
       
   212     * @since S60 3.2
       
   213     */
       
   214     void LoadNextSubImage();
       
   215 
       
   216     /**
       
   217     * If there are frames left, increment frame index, show the next frame and
       
   218     * set the timer. Otherwise call the call-back function.
       
   219     *
       
   220     * @since S60 3.2
       
   221     */
       
   222     void ShowNextFrame();
       
   223 
       
   224     /**
       
   225     * Update frame to screen.
       
   226     *
       
   227     * @since S60 3.2
       
   228     *
       
   229     * @param aFrameIndex Frame index to update.
       
   230     */
       
   231     void UpdateFrameToScreen( TInt aFrameIndex ) const;
       
   232 
       
   233     /**
       
   234     * Starts frame timer.
       
   235     *
       
   236     * @since S60 3.2
       
   237     */
       
   238     void StartFrameTimer();
       
   239 
       
   240     /**
       
   241     * Stops load or play before notifying client.
       
   242     *
       
   243     * @since S60 3.2
       
   244     *
       
   245     * @param aError System wide error code used in notification.
       
   246     * @param aNextState Next state to enter
       
   247     */
       
   248     void StopAndNotify( TInt aError, TInt aNextState );
       
   249 
       
   250     /**
       
   251     * Notifies client.
       
   252     *
       
   253     * @since S60 3.2
       
   254     *
       
   255     * @param aError System wide error code used in notification.
       
   256     * @param aNextState Next state to enter
       
   257     */
       
   258     void Notify( TInt aError, TInt aNextState );
       
   259 
       
   260 private:
       
   261 
       
   262     /**
       
   263     * From MIHLViewerObserver.
       
   264     * Handles notifications from IHL image viewer.
       
   265     *
       
   266     * @since S60 3.2
       
   267     */
       
   268     void ViewerBitmapChangedL();
       
   269 
       
   270     /**
       
   271     * From MIHLViewerObserver.
       
   272     * Handles error from IHL image viewer.
       
   273     *
       
   274     * @since S60 3.2
       
   275     *
       
   276     * @param aError System wide error code.
       
   277     */
       
   278     void ViewerError( TInt aError );
       
   279 
       
   280 
       
   281 private: // data
       
   282 
       
   283     /** Handle to the file containing the animation to use. */
       
   284     RFile iFile;
       
   285 
       
   286     /** Observer for animation events. */
       
   287     MSAnimObserver& iObserver;
       
   288 
       
   289     /**
       
   290     * Frame delay for animation, unless specified in the animation file itself.
       
   291     */
       
   292     TTimeIntervalMicroSeconds32 iFrameDelay;
       
   293 
       
   294     /** Image object from IHL. Owned. May not be NULL. */
       
   295     MIHLFileImage* iImage;
       
   296 
       
   297     /** Identifies the number of animation frames in the image. */
       
   298     TInt iFrameCount;
       
   299 
       
   300     /** Identifies the animation frame currently being loaded. */
       
   301     TInt iFrameIndex;
       
   302 
       
   303     /** Animation frames . */
       
   304     RPointerArray<MIHLBitmap> iFrames;
       
   305 
       
   306     /** To be called when a frame has been loaded. */
       
   307     TCallBack iCallBack;
       
   308 
       
   309     /**
       
   310     * One of Symbian error codes indicating whether the loading of a frame
       
   311     * was successful.
       
   312     */
       
   313     TInt iSuccessCode;
       
   314 
       
   315     enum TType
       
   316         {
       
   317         EStillImage = 1,
       
   318         EAnimation,
       
   319         EMultiFrame
       
   320         };
       
   321     /** Type of the image. */
       
   322     TType iType;
       
   323 
       
   324     enum TState
       
   325         {
       
   326         EInitial = 1,
       
   327         ELoading,
       
   328         ELoaded,
       
   329         EPlaying,
       
   330         EFinished,
       
   331         EFailed
       
   332         };
       
   333 
       
   334     /** Internal state of the object. */
       
   335     TInt iState;
       
   336 
       
   337     /** Timer for timing the frame showing durations. */
       
   338     RTimer iTimer;
       
   339 
       
   340     /** Image viewer object from IHL. Owned. May be NULL. */
       
   341     MIHLImageViewer* iViewer;
       
   342 
       
   343     /** Size for IHL image viewer. */
       
   344     TSize iViewerSize;
       
   345     
       
   346     /* Buffer for image */
       
   347 	HBufC8* iBuffer;
       
   348     };
       
   349 
       
   350 #endif // SANIMIHLCTRL_H