scrsaver/scrsaverplugins/ScreenSaverGifAnimPlugin/inc/GifAnimationPlugin.h
branchRCL_3
changeset 26 e8d784ac1a4b
equal deleted inserted replaced
25:aaeeca1f15af 26:e8d784ac1a4b
       
     1 /*
       
     2 * Copyright (c) 2005 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:   Screensaver GifAnimation plug-in implementation header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_GIFANIMATIONPLUGIN_H
       
    21 #define C_GIFANIMATIONPLUGIN_H
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <coecntrl.h>
       
    25 #include <coemain.h>
       
    26 #include <fbs.h>
       
    27 #include <barsread.h>
       
    28 
       
    29 #include <npupp.h>
       
    30 #include <pluginadapterinterface.h>
       
    31 #include <cecombrowserplugininterface.h>
       
    32 #include <MIHLViewerObserver.h>
       
    33 
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class MIHLFileImage;
       
    37 class MIHLBitmap;
       
    38 class MIHLImageViewer;
       
    39 
       
    40 class CCoeControl;
       
    41 class CGifAnimationPlugin;
       
    42 
       
    43 // CONSTANTS
       
    44 /** implementation id GifAnim Ecom Plugin */
       
    45 const TInt KGifAnimationPluginImplementationValue = 0x102750B4; 
       
    46 
       
    47 /******************************************
       
    48 * This class is specific to ECom Style Plugin.
       
    49 * This is used for passing plugin specific initialization information 
       
    50 * to and from browser.
       
    51 *******************************************/
       
    52 
       
    53 class CGifAnimationPluginEcomMain :  public CEcomBrowserPluginInterface
       
    54     {
       
    55     public: // Functions from base classes
       
    56 
       
    57         /**
       
    58         * Instance factory 
       
    59         * @param aInitParam an optional parameter
       
    60         */
       
    61         static CGifAnimationPluginEcomMain* NewL(TAny* aInitParam);
       
    62 
       
    63         /**
       
    64         * Destructor.
       
    65         */
       
    66         virtual ~CGifAnimationPluginEcomMain();
       
    67 
       
    68         /**
       
    69         * @return pointer to functions struct.
       
    70         */
       
    71         NPNetscapeFuncs* Funcs() { return iNpf; }
       
    72 
       
    73     private: // Constructors
       
    74         CGifAnimationPluginEcomMain( NPNetscapeFuncs* aNpf );
       
    75         void Construct( NPPluginFuncs* aPluginFuncs );
       
    76     private: // new functions
       
    77         /**
       
    78          * Sets pointers to interface functions
       
    79          * @param aPpf structure to fill
       
    80          */
       
    81         NPError InitializeFuncs( NPPluginFuncs* aPpf );
       
    82 
       
    83     private: // Data
       
    84         // pointer to plug-in function pointers struct
       
    85         NPNetscapeFuncs* iNpf;
       
    86     };
       
    87 
       
    88 /****************************************
       
    89 Class CGifAnimationPluginControl
       
    90 Class to Handle UI related actions
       
    91 ****************************************/
       
    92 class CGifAnimationPluginControl : public CCoeControl, 
       
    93                                    public MIHLViewerObserver
       
    94 
       
    95     {
       
    96 public: // Constructor and Destructor
       
    97 
       
    98     /**
       
    99      * Function:    NewL
       
   100      *
       
   101      * Description: Get instance of a CGifAnimationPluginControl object.
       
   102      * @param aParentControl a parent class to register to
       
   103      * @param aPluginAdapter pointer to plugin adapter
       
   104      */
       
   105     static CGifAnimationPluginControl* NewL( CCoeControl* aParentControl,
       
   106 										     MPluginAdapter* aPluginAdapter);
       
   107 
       
   108     /**
       
   109     * Destructor.
       
   110     */
       
   111     ~CGifAnimationPluginControl();
       
   112 
       
   113 public: // From MIHLViewerObserver
       
   114     /**
       
   115     * From MIHLViewerObserver Notifies client 
       
   116     * when viewer bitmap content is changed.
       
   117     * Leave situation is handled in ViewerError() callback.
       
   118     */
       
   119     void ViewerBitmapChangedL();
       
   120 
       
   121     /**
       
   122     * From MIHLViewerObserver Notifies client if error occurs in viewer.
       
   123     * @param aError     IN  System wide error code.
       
   124     */
       
   125     void ViewerError( TInt aError );
       
   126 
       
   127 public: // new methods
       
   128     /**
       
   129      * Loads the image into display.
       
   130      * @param aImageFileName image file name - expected to be valid image
       
   131      */
       
   132     void LoadImageL( const TDesC& aImageFileName );
       
   133     
       
   134     /**
       
   135      * @return last error, if any
       
   136      */
       
   137     TInt GetLastError() const;
       
   138     
       
   139     /**
       
   140      * Start animation.
       
   141      */
       
   142     void StartAnimationL();
       
   143     
       
   144     /**
       
   145      * Stop animation.
       
   146      */
       
   147     void StopAnimation();
       
   148     
       
   149     /**
       
   150      * Checks that the file is a valid image file.
       
   151      * Will leave otherwise
       
   152      *
       
   153      * @param aImageFileName image file name - expected to be valid image
       
   154      */
       
   155     static void CheckFileIsValidL( const TDesC& aImageFileName );
       
   156    
       
   157    
       
   158 private: // new methods
       
   159 
       
   160     /**
       
   161      * @return ETrue if loaded image is animation.
       
   162      */
       
   163     TBool IsAnimation() const;
       
   164     
       
   165     /**
       
   166      * Cancel animation.
       
   167      */
       
   168     void CancelAnimation();
       
   169 
       
   170     /**
       
   171      * Performs image loading steps.
       
   172      * Uses file name stored in LoadImageL()
       
   173      */                   
       
   174     void DoImageLoadingL();
       
   175     
       
   176     /**
       
   177      * Frees resources allocated with LoadImageL()
       
   178      */                   
       
   179     void DeleteAnimation();
       
   180     
       
   181     /**
       
   182      * If loading content fails, non-leaving HandleCallback
       
   183      * must be call always that parent can update its state
       
   184      * properly.
       
   185      */
       
   186     void HandleCallback( TInt aError );
       
   187     
       
   188     /** 
       
   189      * Informes that the plug-in wants to terminate
       
   190      */
       
   191     void InformPluginFinished();
       
   192     
       
   193     /**
       
   194      * Informs that DRM rights should not be consumed
       
   195      */
       
   196     void SetPreviewMode();
       
   197 
       
   198 private: // from CCoeControl
       
   199     void Draw(const TRect& aRect) const;
       
   200     void SizeChanged();
       
   201 
       
   202 private: // Constructor
       
   203     /**
       
   204      * Constructor.
       
   205      */
       
   206     CGifAnimationPluginControl();
       
   207     
       
   208     /**
       
   209      * ConstructL
       
   210      *
       
   211      * 2nd phase constructor.
       
   212      * @param aParentControl a parent class to register to
       
   213      * @param aPluginAdapter pointer to plugin adapter
       
   214      */
       
   215     void ConstructL( CCoeControl *aParentControl,
       
   216                      MPluginAdapter* aPluginAdapter );
       
   217 
       
   218 private: // Data
       
   219 
       
   220     /**
       
   221      * Possible animation states
       
   222      */
       
   223     enum TAnimationState
       
   224         {
       
   225         EAnimationNotReady=1, // the file was not loaded yet or corrupt
       
   226         EAnimationLoading=2,
       
   227         EAnimationPlaying=3
       
   228         };
       
   229         
       
   230         // Source image
       
   231         MIHLFileImage*      iSourceImage;
       
   232         
       
   233         // Destination bitmap
       
   234         MIHLBitmap*         iDrawingBitmap;
       
   235 
       
   236         // the bitmap is used for scaling our way, IHL will not do scaling
       
   237         CFbsBitmap*         iScalingBitmap;
       
   238 
       
   239         // the mask for scaled bitmap 
       
   240         CFbsBitmap*         iScalingBitmapMask; 
       
   241 
       
   242         // size of target bitmap
       
   243         TSize               iTargetSize;
       
   244         
       
   245         // new size of target bitmap
       
   246         TSize               iTargetNewSize;
       
   247         
       
   248         // Image viewer used as engine
       
   249         MIHLImageViewer*    iEngine;
       
   250                 
       
   251         // Internal animation state.
       
   252         TAnimationState     iAnimationState;
       
   253 
       
   254         // path and name of file being loaded
       
   255         TFileName           iFileName;
       
   256         
       
   257         // code of last loading error occured
       
   258         TInt                iLastError;        
       
   259 
       
   260         // pointer to adapter, we do not own the instance
       
   261         MPluginAdapter*             iPluginAdapter;
       
   262         
       
   263         // if true, no DRM rights are consumed
       
   264         TBool               isPreviewMode;
       
   265         
       
   266         // a flag to make sure the first ViewerBitmapChangedL is finished,
       
   267         // then we could draw image on screen
       
   268         TBool               isViewerBitmapChangedL;
       
   269     };
       
   270 
       
   271 
       
   272 /*******************************************************
       
   273 Class CGifAnimationPlugin
       
   274 ********************************************************/
       
   275 
       
   276 class CGifAnimationPlugin : public CBase
       
   277     {
       
   278 public: // Constructor and Destructor
       
   279     /** 
       
   280      * Instance factory 
       
   281      */
       
   282     static CGifAnimationPlugin* NewL( NPP anInstance );
       
   283     /**
       
   284      * Destructor
       
   285      */
       
   286     ~CGifAnimationPlugin();
       
   287 
       
   288     /**
       
   289      * Notifies host that plug-in has finished.
       
   290      */
       
   291     void PrepareToExitL();
       
   292 
       
   293     /**
       
   294      * @return ref of <code>CGifAnimationPluginControl</code>
       
   295      */
       
   296     CGifAnimationPluginControl* Control();
       
   297 
       
   298     /**
       
   299      * @return pointer on NPP instance
       
   300      */
       
   301     NPP Instance();
       
   302 
       
   303     /**
       
   304      * Sets the parent window to plug-in. If already set, only updates size.
       
   305      * @param aWindow a parent window
       
   306      * @param aRect a parent window rectangle
       
   307      */
       
   308     void SetWindowL( const NPWindow  *aWindow, const TRect& aRect );
       
   309 
       
   310 private:
       
   311     /**
       
   312      * Construct.
       
   313      *
       
   314      * 2nd phase constructor.
       
   315      * @param anInstance NPP structure
       
   316      */
       
   317     void Construct( NPP anInstance );
       
   318 
       
   319 private:
       
   320     // pointer to adapter
       
   321     MPluginAdapter*             iPluginAdapter;
       
   322 
       
   323     // pointer to Container
       
   324     CGifAnimationPluginControl* iControl;
       
   325 
       
   326     // structure with pointers
       
   327     NPP                         iInstance;
       
   328     };
       
   329 
       
   330 /****************************************************************************
       
   331 *
       
   332 *    Plugin API methods
       
   333 *
       
   334 */
       
   335 
       
   336 /**
       
   337   * Create a plugin.
       
   338   */
       
   339 NPError GifAnimationPluginNewp( NPMIMEType pluginType, 
       
   340                                 NPP instance, 
       
   341                                 uint16 mode, 
       
   342                                 CDesCArray* argn, 
       
   343                                 CDesCArray* argv, 
       
   344                                 NPSavedData* saved );
       
   345 
       
   346 /**
       
   347   * Destroy a plugin.
       
   348   */
       
   349 NPError GifAnimationPluginDestroy(NPP instance, NPSavedData** save);
       
   350 
       
   351 /**
       
   352   * This is the parent window of a plugin.
       
   353   */
       
   354 NPError GifAnimationPluginSetWindow(NPP instance, NPWindow* window);
       
   355 
       
   356 /**
       
   357   * A new data stream has been created for sending data to the plugin.
       
   358   */
       
   359 NPError GifAnimationPluginNewStream( NPP instance, 
       
   360                                      NPMIMEType type, 
       
   361                                      NPStream* stream, 
       
   362                                      NPBool seekable, 
       
   363                                      uint16* stype );
       
   364 
       
   365 /**
       
   366   * A data stream has been terminated.
       
   367   */
       
   368 NPError GifAnimationPluginDestroyStream( NPP instance, 
       
   369                                          NPStream* stream, 
       
   370                                          NPReason reason );
       
   371 
       
   372 /**
       
   373   * A data stream has been fully saved to a file.
       
   374   */
       
   375 void GifAnimationPluginAsFile( NPP instance, 
       
   376                                NPStream* stream, 
       
   377                                const TDesC& fname );
       
   378 
       
   379 /**
       
   380   * Return the maximum number of bytes this plugin can accept from the stream.
       
   381   * @param instance  - the plug-in instance
       
   382   * @param stream -  the stream to use
       
   383   */
       
   384 int32 GifAnimationPluginWriteReady( NPP instance, NPStream* stream );
       
   385 
       
   386 /**
       
   387   * Receive more data - return number of bytes processed.
       
   388   *
       
   389   * @param instance  - the plug-in instance
       
   390   * @param stream -  the stream to read from
       
   391   * @param buffer - contains the data.
       
   392   * @param len    - the number of bytes in buffer.
       
   393   * @param offset - the number of bytes already sent/processed.
       
   394   * @return TInt number of bytes processed.
       
   395   */
       
   396 int32 GifAnimationPluginWrite( NPP instance, 
       
   397                                NPStream* stream, 
       
   398                                int32 offset, 
       
   399                                int32 len, 
       
   400                                void* buffer );
       
   401 
       
   402 /**
       
   403   * Generic hook to retrieve values/attributes from the plugin.
       
   404   */
       
   405 NPError GifAnimationPluginGetValue( NPP instance, 
       
   406                                     NPPVariable variable, 
       
   407                                     void *ret_value );
       
   408 
       
   409 /**
       
   410   * Generic hook to set values/attributes within the plugin.
       
   411   */
       
   412 NPError GifAnimationPluginSetValue( NPP instance, 
       
   413                                     NPNVariable variable, 
       
   414                                     void *ret_value );
       
   415 
       
   416 /**
       
   417   * Event
       
   418   */
       
   419 int16 GifAnimationPluginEvent( NPP instance, void* event );
       
   420 
       
   421 /**
       
   422  * Notify
       
   423  */
       
   424 void GifAnimationPluginURLNotify( NPP instance, 
       
   425                                   const TDesC& url, 
       
   426                                   NPReason reason, 
       
   427                                   void* notifyData );
       
   428 
       
   429 /**
       
   430  * Print
       
   431  */
       
   432 void GifAnimationPluginPrint( NPP instance, NPPrint* platformPrint );
       
   433 
       
   434 #endif // C_GIFANIMATIONPLUGIN_H