S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CBitmapInst Class Reference

#include <Bitmapinst.h>

List of all members.

Public Member Functions

 ~CBitmapInst ()
NPError PluginNew (NPMIMEType aPluginType, NPP aInstance, uint16 aMode, CDesC16Array *aArgn, CDesC16Array *aArgv, NPSavedData *aSaved)
NPError PluginDestroy (NPSavedData **aSave)
NPError PluginSetWindowL (NPWindow *aWindow)
NPError PluginSetValue (NPNVariable aVariable, void *aValue)
NPError PluginNewStream (NPMIMEType aType, NPStream *aStream, NPBool aSeekable, uint16 *aStype)
NPError PluginDestroyStream (NPStream *aStream, NPReason aReason)
void PluginStreamAsFile (NPStream *aStream, const TDesC16 &aFileName)
int32 PluginWrite (NPStream *aStream, int32 aOffset, int32 aLength, void *aBuffer)
int32 PluginWriteReady (NPStream *aStream)
void PluginURLNotify (const TDesC16 &aUrl, NPReason aReason, void *aNotifyData)
TInt NotifyL (TNotificationType aCallType, TAny *aParam)
TCoeInputCapabilities InputCapabilities (void) const
TKeyResponse OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)
void HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)
void HandlePointerEventL (const TPointerEvent &aPointerEvent)
void FocusChanged (TDrawNow aDrawNow)
void SizeChanged (void)

Static Public Member Functions

static CBitmapInst * NewL (NPP aNpp)

Private Member Functions

 CBitmapInst (NPP aNpp)
void Construct ()
void Draw (const TRect &aRect) const
NPError HandleGet (void)

Private Attributes

NPStream * iStream
TInt iWriteReady
TUint16 * iSourceUrl
NPP iNpp
TBool iFirstTime
TBool iFlipBitmap
HBufC * iFileName
TInt iNumDownload


Detailed Description

CBitmapInst is the plugin control class. This class specifies the plugin APIs used to create and destroy plugin instances, handle events, streams, URLs etc

Definition at line 34 of file Bitmapinst.h.


Constructor & Destructor Documentation

CBitmapInst::~CBitmapInst (   ) 
 

Destructor

Definition at line 75 of file Bitmapecominst.cpp.

References iFileName, and iSourceUrl.

00076     {
00077     if ( iFileName )
00078         {
00079             delete iFileName;
00080             iFileName = NULL;
00081         }
00082     CBitmapEcomMain* npm = ( CBitmapEcomMain* ) Dll :: Tls();
00083     delete iSourceUrl;
00084     }

CBitmapInst::CBitmapInst (  NPP  aNpp  )  [private]
 

Constructor

Definition at line 53 of file Bitmapecominst.cpp.

References iFirstTime, iFlipBitmap, iNumDownload, iSourceUrl, and iWriteReady.

00053                                      : CCoeControl(), iNpp( aNpp )
00054     {
00055     iWriteReady     = 100;
00056     iSourceUrl      = NULL;
00057     iFirstTime      = ETrue;
00058     iFlipBitmap     = EFalse;
00059     iNumDownload    = 0;
00060     }


Member Function Documentation

CBitmapInst * CBitmapInst::NewL (  NPP  aNpp  )  [static]
 

Two phase construction.

Since:
3.0
Parameters:
aNpp - plug-in's opaque instance handle.
Returns:
- plug-in object.

Definition at line 40 of file Bitmapecominst.cpp.

References CBitmapInst().

00041     {
00042     CBitmapInst* self = new ( ELeave ) CBitmapInst( aNpp );
00043     CleanupStack :: PushL( self );
00044     self->Construct();
00045     CleanupStack :: Pop();
00046     return self;
00047     }

NPError CBitmapInst::PluginNew (  NPMIMEType  aPluginType,
NPP  aInstance,
uint16  aMode,
CDesC16Array *  aArgn,
CDesC16Array *  aArgv,
NPSavedData *  aSaved
) 
 

This function creates a new instance of the plug-in.

Since:
3.0
Parameters:
aPluginType - the MIME type.
aInstance - the plug-in instance.
aMode - the mode
aArgn - attribute of the <object> tag; the names
aArgv - attribute of the <object> tag; the values
aSaved - this parameter is not supported.
Returns:
- NPError status code.

Definition at line 98 of file Bitmapecominst.cpp.

References HandleGet(), and iSourceUrl.

00105     {
00106     if ( aInstance->pdata != this )
00107         {
00108         return NPERR_INVALID_INSTANCE_ERROR;
00109         }
00110 
00111     // Traverse the attribute list to find the Url from which to retrieve data
00112     for ( TInt i = 0; i < aArgn->Count(); i++ )
00113         {
00114         TPtrC16 namePtr( (*aArgn)[i] );
00115         TPtrC16 valPtr( (*aArgv)[i] );
00116 
00117         if ( ( KSourceUrl().FindF( namePtr ) == 0 ) )
00118             {
00119             iSourceUrl = new TUint16[valPtr.Length() + 1];
00120             if ( iSourceUrl == NULL )
00121                 {
00122                 return NPERR_OUT_OF_MEMORY_ERROR;
00123                 }
00124             TPtr16 ptr( iSourceUrl, 0, valPtr.Length() + 1 );
00125             ptr.Copy( valPtr );
00126             ptr.ZeroTerminate();
00127             break;
00128             }
00129         }
00130     return HandleGet();
00131     }

NPError CBitmapInst::PluginDestroy (  NPSavedData **  aSave  ) 
 

This function deletes a plug-in instance.

Since:
3.0
Parameters:
aSave - this parameter is not supported.
Returns:
- NPError status code.

Definition at line 140 of file Bitmapecominst.cpp.

00141     {
00142     delete this;
00143     return NPERR_NO_ERROR;
00144     }

NPError CBitmapInst::PluginSetWindowL (  NPWindow *  aWindow  ) 
 

This function sets the parent and the coordinates for the plug-in. It makes a call to the ExtractParentControlAndApiL API to extract the platform dependent window.The first time PluginSetWindowL() is called, it is important to construct the corresponding plug-in control. The other times this call is made, it is expected that the function simply updates the bounds of the control.

Since:
3.0
Parameters:
aWindow - a plug-in window structure that contains window coordinates and platform specific window information.
Returns:
- an error code, on success returns NPERR_NO_ERROR.

Definition at line 158 of file Bitmapecominst.cpp.

References iFirstTime.

00159     {
00160     MPluginAdapterPTR pPluginAdapter( NULL );
00161     pPluginAdapter = static_cast<MPluginAdapter*>( aWindow->window );
00162     CCoeControl* pParentControl = pPluginAdapter->GetParentControl();
00163 
00164         if ( !pParentControl )
00165                 return NPERR_NO_ERROR;
00166 
00167     if ( iFirstTime )
00168         {
00169             CreateWindowL( pParentControl );
00170         pPluginAdapter->SetPluginNotifier( this );
00171         pPluginAdapter->PluginConstructedL( this );
00172         }
00173   
00174     TPoint point( aWindow->x, aWindow->y );
00175     TSize size( aWindow->width, aWindow->height );
00176     SetExtent( point, size );
00177   
00178     if ( iFirstTime )
00179         {
00180         ActivateL();
00181         iFirstTime = EFalse;
00182         }
00183 
00184     return NPERR_NO_ERROR;
00185     }

NPError CBitmapInst::PluginSetValue (  NPNVariable  aVariable,
void *  aValue
) 
 

This function has an empty implementation here, but the actual purpose of the function is to set values for the plugin variables.

Since:
3.0
Parameters:
aVariable - the variable whose value is to be set.
aValue - pointer to the 32-bit parameter that contains the value.
Returns:
- NPError status code.

Definition at line 196 of file Bitmapecominst.cpp.

00199     {
00200     return NPERR_NO_ERROR;
00201     }

NPError CBitmapInst::PluginNewStream (  NPMIMEType  aType,
NPStream *  aStream,
NPBool  aSeekable,
uint16 *  aStype
) 
 

This function notifies a plug-in instance of a new data stream.

Since:
3.0
Parameters:
aMimeType - the MIME type of the stream.
aStream - the new stream object.
aSeekable - flag that indicates whether or not stream is searchable.
aStype - the type of the stream. The plug-in sets the stream type. Currently supported stream types are: NP_NORMAL NP_ASFILE NP_ASFILEONLY
Returns:
- NPError status code.

Definition at line 217 of file Bitmapecominst.cpp.

References iStream.

00222     {
00223     *aStype         = NP_ASFILE;
00224     iStream         = aStream;
00225     iStream->pdata  = this;
00226     return NPERR_NO_ERROR;
00227     }

NPError CBitmapInst::PluginDestroyStream (  NPStream *  aStream,
NPReason  aReason
) 
 

This function destroys the stream that was previously created to stream data to the plug-in.

Since:
3.0
Parameters:
aStream - the stream to be destroyed.
aReason - the reason for destroying the stream. Possible values are: NPRES_DONE - normal completion and all data was sent to the instance. NPRES_USER_BREAK - the user canceled the stream NPRES_NETWORK_ERR - stream failed because of problems with the network, disk I/O error, lack of memory, or some other problem.
Returns:
- NPError status code.

Definition at line 244 of file Bitmapecominst.cpp.

00247     {
00248     return NPERR_NO_ERROR;
00249     }

void CBitmapInst::PluginStreamAsFile (  NPStream *  aStream,
const TDesC16 &  aFileName
) 
 

This function passes a file name to the plug-in in which the stream data is stored.

Since:
3.0
Parameters:
aStream - the stream
aFileName - the file name

Definition at line 259 of file Bitmapecominst.cpp.

References iFileName, iNumDownload, and iStream.

00262     {
00263     if ( ( aStream->pdata != this ) || ( aStream != iStream ) 
00264                                     || ( iNumDownload > 0 ) )
00265         {
00266         return;
00267         }    
00268     iFileName = aFileName.Alloc();
00269     iNumDownload ++;
00270     }

int32 CBitmapInst::PluginWrite (  NPStream *  aStream,
int32  aOffset,
int32  aLength,
void *  aBuffer
) 
 

This function writes a chunk of data to the plug-in.

Since:
3.0
Parameters:
aStream - the stream
aOffset - the offset in the stream.
aLength - the size of the new data.
aBuffer - the data.
Returns:
- the number of bytes consumed by the plug-in instance.

Definition at line 282 of file Bitmapecominst.cpp.

References iStream.

00287     {
00288     if ( aStream->pdata != this || aStream != iStream )
00289         {
00290         return 0;
00291         }
00292 
00293     return aLength;
00294     }

int32 CBitmapInst::PluginWriteReady (  NPStream *  aStream  ) 
 

The browser calls the NPP_Write function with the amount of data returned from the NPP_WriteReady function.

Since:
3.0
Parameters:
aStream - the stream
Returns:
- maximum data size that the plug-in can handle.

Definition at line 304 of file Bitmapecominst.cpp.

References iWriteReady.

00305     {
00306     return iWriteReady;
00307     }

void CBitmapInst::PluginURLNotify (  const TDesC16 &  aUrl,
NPReason  aReason,
void *  aNotifyData
) 
 

The browser calls the NPP_URLNotify function to notify the plug-in of the completion of a URL request made by the NPN_GetURLNotify function or the NPN_PostURLNotify function.

Since:
3.0
Parameters:
aUrl - url of the NPN_GetURLNotify function or of the NPN_PostURLNotify function request.
aReason - reason code for completion of the request.
aNotifyData - contains the private plug-in data passed to the corresponding call to the NPN_GetURLNotify function.

Definition at line 321 of file Bitmapecominst.cpp.

00325     {
00326     return;
00327     }

TInt CBitmapInst::NotifyL (  TNotificationType  aCallType,
TAny *  aParam
) 
 

This function implements the NotifyL() function of the MPluginNotifier interface. It notifies the plug-in of an event.

Since:
3.0
Parameters:
aCallType - the event type that is passed to the plug-in. Possible values are : EEditCut, EEditCopy, EEditPaste, EEditDelete, EApplicationFocusChanged, ESystemNotification
aParam - the parameter associated with the event.
Returns:
- not used.

Definition at line 386 of file Bitmapecominst.cpp.

References iFlipBitmap.

00387     {
00388     switch ( aCallType )
00389         {
00390         case EApplicationFocusChanged:
00391             {
00392                         if ( iFlipBitmap )
00393                 {
00394                         iFlipBitmap = EFalse;
00395                 }
00396                 else 
00397                 {
00398                         iFlipBitmap = ETrue;
00399                 }
00400             DrawNow();
00401             break;
00402             }
00403         default:
00404             break;
00405         }
00406     return 0;
00407     }

TCoeInputCapabilities CBitmapInst::InputCapabilities (  void   )  const
 

Returns the supported input capabilities which correspond to the behaviour of the OfferKeyEventL() function of the control;

Since:
3.0
Returns:
- TCoeInputCapabilities::EAllText which supports all types of text.

Definition at line 417 of file Bitmapecominst.cpp.

00418     {
00419         return TCoeInputCapabilities( TCoeInputCapabilities::EAllText );
00420     }

TKeyResponse CBitmapInst::OfferKeyEventL (  const TKeyEvent &  aKeyEvent,
TEventCode  aType
) 
 

This function handles key events. when 'Enter' key or 'OK' key is pressed, the bitmap rendered is flipped from redflower to blueflower and viceversa.

Since:
3.0
Parameters:
aKeyEvent - the key event.
aType - type of key event:EEventKey, EEventKeyUp or EEventKeyDown
Returns:
- the function returns EKeyWasNotConsumed if it does not do anything in response to a key event. If it is able to process the event it returns EKeyWasConsumed.

Definition at line 433 of file Bitmapecominst.cpp.

References iFlipBitmap.

00436     {
00437         if ( aType == EEventKeyUp )
00438             {
00439                 switch ( aKeyEvent.iScanCode )
00440                     {
00441                     case EStdKeyEnter:
00442                     case EStdKeyDevice3:
00443                 {
00444                                 if ( iFlipBitmap )
00445                     {
00446                             iFlipBitmap = EFalse;
00447                     }
00448                     else 
00449                     {
00450                             iFlipBitmap = ETrue;
00451                     }
00452                             DrawNow();
00453                             return EKeyWasConsumed;
00454                 }
00455                     default:
00456                             return EKeyWasNotConsumed;
00457                     }
00458             }
00459         return EKeyWasNotConsumed;
00460     }

void CBitmapInst::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
) 
 

This function inherited from MCoeControlObserver handles an event from an observed control.

Since:
3.0
Parameters:
aControl - pointer to the control from which the event originated.
aEventType - the event type.

Definition at line 470 of file Bitmapecominst.cpp.

References iNpp.

00473     {
00474     if ( aControl != (( MPluginAdapter* ) ( iNpp->ndata ))->GetParentControl() )
00475         {
00476         return;
00477         }
00478 
00479     switch ( aEventType )
00480         {
00481         case EEventRequestFocus:
00482             default:
00483                 break;
00484         }
00485     }

void CBitmapInst::HandlePointerEventL (  const TPointerEvent &  aPointerEvent  ) 
 

This function handles pointer events. On clicking the left mouse button, the bitmap rendered is flipped from redflower to blueflower and viceversa.

Since:
3.0
Parameters:
aPointerEvent - The pointer event.

Definition at line 494 of file Bitmapecominst.cpp.

References iFlipBitmap.

00495     {
00496     switch ( aPointerEvent.iType )
00497         {
00498         case TPointerEvent::EButton1Down:
00499             {
00500                         if ( iFlipBitmap )
00501                 {
00502                         iFlipBitmap = EFalse;
00503                 }
00504                 else 
00505                 {
00506                         iFlipBitmap = ETrue;
00507                 }
00508                 DrawNow();
00509                 break;
00510             }       
00511         default:
00512                 break;
00513         }
00514     }

void CBitmapInst::FocusChanged (  TDrawNow  aDrawNow  ) 
 

This function is called whenever a control gains or loses focus - as a result of a call to SetFocus().

Since:
3.0
Parameters:
aDrawNow - Contains the value that was passed to it by SetFocus().

Definition at line 523 of file Bitmapecominst.cpp.

00524     {
00525     DrawNow();
00526     }

void CBitmapInst::SizeChanged (  void   ) 
 

This function which responds to size changes to set the size and position of the contents of the control does nothing and has an empty implementation.

Since:
3.0

Definition at line 533 of file Bitmapecominst.cpp.

00534     {
00535     return;
00536     }

void CBitmapInst::Construct (   )  [private]
 

second phase constructor

Definition at line 66 of file Bitmapecominst.cpp.

00067     {
00068     return;
00069     }

void CBitmapInst::Draw (  const TRect &  aRect  )  const [private]
 

This function draws the control. When iFlipBitmap is true it renders one bitmap, and when iFlipBitmap is false it renders another one.

Since:
3.0
Parameters:
aRect - The region of the control to be redrawn. Co-ordinates are relative to the control's origin (top left corner).

Definition at line 337 of file Bitmapecominst.cpp.

References iFileName, and iFlipBitmap.

00338     {   
00339     TInt ret( KErrNone );
00340     CFbsBitmap* bitmap = NULL;
00341   
00342     bitmap = new CFbsBitmap();
00343     if ( !bitmap )
00344         {
00345         return;
00346         }
00347 
00348     if ( iFileName )
00349                 {
00350                 if( iFlipBitmap )
00351                         {
00352                         ret = bitmap->Load( iFileName->Des(), EMbmAllbitmapsRedflower, ETrue );
00353                         }
00354                 else 
00355                         {
00356                         ret = bitmap->Load( iFileName->Des(), EMbmAllbitmapsBlueflower, ETrue );
00357                         }
00358                 }
00359     if ( ret != KErrNone )
00360         {
00361         delete ( bitmap );
00362         bitmap = NULL;
00363         return;
00364         }
00365 
00366     SystemGc().Clear();
00367     SystemGc().DrawBitmap( aRect, bitmap );
00368     delete ( bitmap );
00369     bitmap = NULL;
00370     }

NPError CBitmapInst::HandleGet (  void   )  [private]
 

This function calls the NPN_GetURL function to ask the browser to deliver the data to the plug-in instance in a new stream.

Since:
3.0
Returns:
- if the url is NULL returns NPERR_GENERIC_ERROR, otherwise returns NPError status code from calling the NPN_GetURL function.

Definition at line 546 of file Bitmapecominst.cpp.

References CBitmapEcomMain::Funcs(), iNpp, and iSourceUrl.

00547     {
00548     CBitmapEcomMain* npm = ( CBitmapEcomMain* ) Dll :: Tls();
00549     TPtrC url;
00550 
00551     if ( iSourceUrl ) // iSourceUrl is non-null
00552         {
00553         url.Set( iSourceUrl );
00554         return ( npm->Funcs()->geturl( iNpp, url, NULL ) );
00555         }
00556     else
00557         {
00558         return NPERR_GENERIC_ERROR;
00559         }
00560     }


© Nokia 2006

Back to top