svgtviewer/SvgtViewerPlugin/ScreenSaverPluginSrc/Svgtplugindllapi.cpp
branchRCL_3
changeset 20 5fd161fa28b6
parent 0 632761c941a7
equal deleted inserted replaced
17:e52958d06c29 20:5fd161fa28b6
       
     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:  SVGT Plugin Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <SVGTUIDialog.hrh>
       
    21 #include <eikenv.h>
       
    22 
       
    23 #include "Svgtplugin.h"
       
    24 #include "SvgRenderFrameControl.h"
       
    25 #include "SvgScreenSaver.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // SvgtPluginNewp
       
    29 // Creates the plugin.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 NPError SvgtPluginNewp(NPMIMEType /*pluginType*/,
       
    33                        NPP aInstance, 
       
    34                        uint16 /*mode*/, 
       
    35                        CDesCArray* /*argn*/, 
       
    36                        CDesCArray* /*argv*/, 
       
    37                        NPSavedData* /*saved*/)
       
    38     {
       
    39     CSvgtPlugin* lSvgtPlugin=NULL;
       
    40     TRAPD(err,lSvgtPlugin=CSvgtPlugin::NewL(aInstance));
       
    41 
       
    42     if (err == KErrNoMemory)
       
    43         {
       
    44         return NPERR_OUT_OF_MEMORY_ERROR;
       
    45         }
       
    46     if (err != KErrNone)
       
    47         {
       
    48         return NPERR_MODULE_LOAD_FAILED_ERROR;
       
    49         }
       
    50     if ( aInstance )
       
    51         {
       
    52         aInstance->pdata = (void *) lSvgtPlugin;        
       
    53         }
       
    54     else
       
    55         {
       
    56         return NPERR_INVALID_INSTANCE_ERROR;
       
    57         }
       
    58     return NPERR_NO_ERROR;
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // SvgtPluginDestroy
       
    64 // Destroy a plugin.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 NPError SvgtPluginDestroy(NPP aInstance, NPSavedData** /*save*/)
       
    68     {
       
    69     if ( !aInstance )
       
    70         {
       
    71         return NPERR_GENERIC_ERROR;
       
    72         }
       
    73     CSvgtPlugin* lSvgtPlugin = (CSvgtPlugin *)aInstance->pdata;
       
    74     if ( lSvgtPlugin )
       
    75         {
       
    76         TRAPD(err,lSvgtPlugin->PrepareToExitL());
       
    77         if (err != KErrNone)
       
    78             {
       
    79             #ifdef _DEBUG
       
    80             RDebug::Print(_L("SvgtPluginDestroy Error when printing Warning"));
       
    81             #endif //_DEBUG
       
    82             }
       
    83         /**Ignoring the error*/
       
    84         delete lSvgtPlugin;
       
    85         lSvgtPlugin = NULL;
       
    86         }
       
    87     return NPERR_NO_ERROR;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // SvgtPluginSetWindow
       
    92 // This sets the parent window of a plugin.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 NPError SvgtPluginSetWindow(NPP aInstance, NPWindow* aWindow)
       
    96     {
       
    97     if ( !aInstance )
       
    98         {
       
    99         return NPERR_INVALID_INSTANCE_ERROR;
       
   100         }
       
   101     if ( !aWindow )
       
   102         {
       
   103         return NPERR_GENERIC_ERROR; 
       
   104         }
       
   105     CSvgtPlugin* lSvgtPlugin = (CSvgtPlugin *) aInstance->pdata;
       
   106     TUint lWidth = aWindow->width;
       
   107     TUint lHeight = aWindow->height;
       
   108    
       
   109     TRAPD(err,lSvgtPlugin->SetWindowL(aWindow,TRect(TSize(lWidth,lHeight))));
       
   110     if (err == KErrNoMemory)
       
   111         {
       
   112         return NPERR_OUT_OF_MEMORY_ERROR;
       
   113         }
       
   114         
       
   115     if (err != KErrNone)
       
   116         {
       
   117         return NPERR_GENERIC_ERROR;
       
   118         }
       
   119         
       
   120     return NPERR_NO_ERROR;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // SvgtPluginAsFile
       
   125 // The name of the SVG file is set by AsFile
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void SvgtPluginAsFile(NPP aInstance, NPStream* /*stream*/, const TDesC& aFname)
       
   129     {
       
   130     CSvgtPlugin* lSvgtPlugin = (CSvgtPlugin*)aInstance->pdata;
       
   131     TInt err = lSvgtPlugin->Control()->AsFile(aFname);
       
   132     if ( err != KErrNone )
       
   133         {
       
   134         // Destroy myself
       
   135         SvgtPluginDestroy( aInstance, NULL );
       
   136         }
       
   137     }
       
   138 
       
   139 
       
   140 
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // SvgtPluginGetValue
       
   144 // Generic hook to retrieve values/attributes from the plugin.
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 NPError SvgtPluginGetValue(NPP aInstance, 
       
   148                            NPPVariable aVariable, 
       
   149                            void* aRetvalue)
       
   150     {
       
   151     TInt ret = NPERR_NO_ERROR;
       
   152     if ( !aInstance )
       
   153         {
       
   154         ret = NPERR_INVALID_INSTANCE_ERROR;
       
   155         }
       
   156     CSvgtPlugin* lSvgtPlugin = (CSvgtPlugin *)aInstance->pdata;       
       
   157     if ( lSvgtPlugin && aRetvalue )
       
   158         {        
       
   159         if ( aVariable == NPPCheckFileIsValid )
       
   160             {             
       
   161             NPCheckFile* checkFile = (NPCheckFile*)aRetvalue;
       
   162             checkFile->fileValidityCheckError = KErrNone;     
       
   163             TRAPD(err, SvgtPluginCheckFileL( aRetvalue ) );
       
   164             if ( err != KErrNone )
       
   165                 {
       
   166                 ret=  NPERR_GENERIC_ERROR;
       
   167                 }
       
   168             ret = NPERR_NO_ERROR;
       
   169             }    
       
   170         if ( aVariable == NPPScreenSaverGetLastError )
       
   171             { 
       
   172             TInt* error = (TInt*)aRetvalue;
       
   173             *error = lSvgtPlugin->Control()->GetLastError();
       
   174             ret =  NPERR_NO_ERROR;
       
   175             }               
       
   176         }
       
   177     else
       
   178         {
       
   179         ret =  NPERR_GENERIC_ERROR;
       
   180         }
       
   181     return ret;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // SvgtPluginCheckFileL
       
   186 // Helper function used to check the file's validity
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void SvgtPluginCheckFileL( void* aRetvalue )
       
   190     {
       
   191     if ( !aRetvalue )
       
   192         {
       
   193         User::Leave( KErrArgument );
       
   194         }
       
   195     NPCheckFile* checkFile = (NPCheckFile*)aRetvalue;    
       
   196     TFileName fileName = checkFile->fileName->Des();
       
   197     RFile fileHandle;
       
   198     TInt err = fileHandle.Open( CEikonEnv::Static()->FsSession(), 
       
   199                                  fileName, 
       
   200                                  EFileShareAny );
       
   201     User::LeaveIfError( err );
       
   202                 
       
   203     CleanupClosePushL( fileHandle );
       
   204     CSvgRenderFrameControl* control = new ( ELeave )
       
   205                       CSvgRenderFrameControl( fileHandle );
       
   206                       
       
   207     CleanupStack::PushL( control );                      
       
   208     TRAP( err, control->InitializeEngineL( ETrue, control ) ); /* CheckFile Mode */
       
   209     checkFile->fileValidityCheckError = err;
       
   210     CleanupStack::PopAndDestroy( control );
       
   211     CleanupStack::PopAndDestroy(&fileHandle); 
       
   212     }
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // SvgtPluginSetValue
       
   217 // Generic hook to set values/attributes within the plugin.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 NPError SvgtPluginSetValue(NPP aInstance, 
       
   221                            NPNVariable aVariable, 
       
   222                            void* aRetvalue)
       
   223     {
       
   224     TInt ret = NPERR_NO_ERROR;
       
   225     if ( !aInstance )
       
   226         {
       
   227         ret = NPERR_INVALID_INSTANCE_ERROR;
       
   228         }
       
   229     CSvgtPlugin* lSvgtPlugin = (CSvgtPlugin *)aInstance->pdata;    
       
   230     
       
   231     if ( lSvgtPlugin )
       
   232         {
       
   233         switch( aVariable )
       
   234             {
       
   235             case NPNInteractionMode:
       
   236             // do nothing
       
   237             break;
       
   238             case NPNScreenSaverAnimationEvent:
       
   239                 {
       
   240                 NPAnimationEvent animEvent = ( NPAnimationEvent )
       
   241                                     (*(NPAnimationEvent*)aRetvalue);
       
   242                                     
       
   243                 if ( animEvent == NPStartAnimation )
       
   244                     {
       
   245                     // Make the control Visible
       
   246                     lSvgtPlugin->Control()->MakeVisible( ETrue );
       
   247                     TRAPD(err, lSvgtPlugin->Control()->
       
   248                           SendCommandL(ESvgtDlgLoopOnCommand));
       
   249                     if ( err != KErrNone )
       
   250                         {
       
   251                         ret = NPERR_GENERIC_ERROR;            
       
   252                         }                                               
       
   253                     // Start the animation
       
   254                     TRAP( err, lSvgtPlugin->Control()->
       
   255                           SendCommandL( ESvgtDlgPlayCommand ) );
       
   256                     if ( err != KErrNone )
       
   257                         {
       
   258                         ret = NPERR_GENERIC_ERROR;
       
   259                         }        
       
   260                     }
       
   261                 if ( animEvent == NPEndAnimation )
       
   262                     {
       
   263                     // Make the control invisible
       
   264                     lSvgtPlugin->Control()->MakeVisible( EFalse );
       
   265                     // Stop the animation
       
   266                     TRAPD( err, lSvgtPlugin->Control()->
       
   267                         SendCommandL( ESvgtDlgPauseCommand ) );
       
   268                     if ( err != KErrNone )
       
   269                         {
       
   270                         ret= NPERR_GENERIC_ERROR;            
       
   271                         }
       
   272                     }        
       
   273                 }
       
   274             break;
       
   275             }       
       
   276         }
       
   277     return ret;
       
   278     }
       
   279 
       
   280 
       
   281 
       
   282 // End of File