S60 3rd Edition SDK for Symbian OS
Example Applications Guide

Bitmapinst.h

00001 /**
00002 * =============================================================================
00003 *  Name        : Bitmapinst.h
00004 *  Part of     : Plugin test
00005 *  Interface   : Browser Plug-in API
00006 *  Description : Example for developing a plugin
00007 *  Version     : 1.0
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef BITMAPINST_H
00017 #define BITMAPINST_H
00018 
00019 // INCLUDES
00020 
00021 #include <e32std.h>
00022 #include <coecntrl.h>
00023 #include <npupp.h>
00024 #include <PluginAdapterInterface.h>
00025 
00026 // CLASS DECLARATION
00027 
00028 /**
00029 * CBitmapInst is the plugin control class. 
00030 * This class specifies the plugin APIs used to create and destroy 
00031 * plugin instances, handle events, streams, URLs etc 
00032 * 
00033 */
00034 class CBitmapInst : public CCoeControl, 
00035                     public MCoeControlObserver, 
00036                     public MPluginNotifier
00037     {
00038     public:
00039         /**
00040                 * Two phase construction.
00041                 * @since 3.0
00042                 * @param aNpp - plug-in's opaque instance handle.
00043                 * @return     - plug-in object.
00044                 */
00045         static CBitmapInst* NewL ( NPP aNpp );
00046 
00047                 /**
00048                 * Destructor
00049                 */
00050 
00051         ~CBitmapInst();
00052 
00053                 /**
00054                 * This function creates a new instance of the plug-in.
00055                 * @since 3.0
00056                 * @param aPluginType - the MIME type.
00057                 * @param aInstance   - the plug-in instance.
00058                 * @param aMode       - the mode
00059                 * @param aArgn       - attribute of the <object> tag; the names
00060                 * @param aArgv       - attribute of the <object> tag; the values
00061                 * @param aSaved      - this parameter is not supported.
00062                 * @return            - NPError status code.
00063                 */
00064         NPError PluginNew(
00065                     NPMIMEType aPluginType, 
00066                     NPP aInstance, 
00067                     uint16 aMode, 
00068                     CDesC16Array* aArgn, 
00069                     CDesC16Array* aArgv, 
00070                     NPSavedData* aSaved );
00071   
00072                 /**
00073                 * This function deletes a plug-in instance.
00074                 * @since 3.0 
00075                 * @param aSave - this parameter is not supported.
00076                 * @return      - NPError status code.
00077                 */
00078         NPError PluginDestroy ( NPSavedData** aSave );
00079   
00080                 /**
00081                 * This function sets the parent and the coordinates for the plug-in. It makes 
00082                 * a call to the ExtractParentControlAndApiL API to extract the platform 
00083                 * dependent window.The first time PluginSetWindowL() is called, it is 
00084                 * important to construct the corresponding plug-in control. The other times 
00085                 * this call is made, it is expected that the function simply updates the 
00086                 * bounds of the control.
00087                 * @since 3.0
00088                 * @param aWindow - a plug-in window structure that contains window coordinates
00089                 *                  and platform specific window information.
00090                 * @return        - an error code, on success returns NPERR_NO_ERROR.
00091                 */
00092         NPError PluginSetWindowL ( NPWindow* aWindow );
00093         
00094         /**
00095                 * This function has an empty implementation here, but the actual purpose of 
00096                 * the function is to set values for the plugin variables. 
00097                 * @since 3.0
00098                 * @param aVariable - the variable whose value is to be set.
00099                 * @param aValue    - pointer to the 32-bit parameter that contains the value.
00100                 * @return          - NPError status code.
00101                 */
00102         NPError PluginSetValue ( NPNVariable aVariable, void *aValue );
00103 
00104         /**
00105                 * This function notifies a plug-in instance of a new data stream.
00106                 * @since 3.0 
00107                 * @param aMimeType - the MIME type of the stream.
00108                 * @param aStream   - the new stream object.
00109                 * @param aSeekable - flag that indicates whether or not stream is searchable.
00110                 * @param aStype    - the type of the stream. The plug-in sets the stream type.
00111                 *                    Currently supported stream types are:      
00112                 *                        NP_NORMAL
00113                 *                        NP_ASFILE
00114             *                        NP_ASFILEONLY
00115                 * @return          - NPError status code.
00116                 */
00117         NPError PluginNewStream(
00118                         NPMIMEType aType, 
00119                         NPStream* aStream, 
00120                         NPBool aSeekable, 
00121                         uint16* aStype );
00122 
00123                 /**
00124                 * This function destroys the stream that was previously created to stream data
00125                 * to the plug-in.
00126                 * @since 3.0
00127                 * @param aStream - the stream to be destroyed.
00128                 * @param aReason - the reason for destroying the stream. Possible values are:
00129                 *                      NPRES_DONE - normal completion and all data was sent to
00130                 *                      the instance. 
00131                 *                      NPRES_USER_BREAK - the user canceled the stream
00132                 *                      NPRES_NETWORK_ERR - stream failed because of problems 
00133                 *                      with the network, disk I/O error, lack of memory, or 
00134                 *                      some other problem.        
00135                 * @return        - NPError status code.
00136                 */
00137         NPError PluginDestroyStream ( NPStream* aStream, NPReason aReason );
00138 
00139                 /**
00140                 * This function passes a file name to the plug-in in which the stream data 
00141                 * is stored. 
00142                 * @since 3.0
00143                 * @param aStream   - the stream
00144                 * @param aFileName - the file name
00145                 */
00146         void PluginStreamAsFile ( NPStream* aStream, const TDesC16& aFileName );
00147   
00148                 /**
00149                 * This function writes a chunk of data to the plug-in.
00150                 * @since 3.0
00151                 * @param aStream - the stream
00152                 * @param aOffset - the offset in the stream.
00153                 * @param aLength - the size of the new data.
00154                 * @param aBuffer - the data.
00155                 * @return        - the number of bytes consumed by the plug-in instance.
00156                 */
00157         int32 PluginWrite(
00158                     NPStream* aStream, 
00159                     int32 aOffset, 
00160                     int32 aLength, 
00161                     void* aBuffer );
00162 
00163                 /**
00164                 * The browser calls the NPP_Write function with the amount of data returned 
00165                 * from the NPP_WriteReady function.
00166                 * @since 3.0
00167                 * @param aStream - the stream
00168                 * @return        - maximum data size that the plug-in can handle.
00169                 */
00170         int32 PluginWriteReady ( NPStream* aStream );
00171     
00172                 /**
00173                 * The browser calls the NPP_URLNotify function to notify the plug-in of the 
00174                 * completion of a URL request made by the NPN_GetURLNotify function or the 
00175                 * NPN_PostURLNotify function.
00176                 * @since 3.0
00177                 * @param aUrl        - url of the NPN_GetURLNotify function or of the 
00178                 *                      NPN_PostURLNotify function request.
00179                 * @param aReason     - reason code for completion of the request.
00180                 * @param aNotifyData - contains the private plug-in data passed to the 
00181                 *                      corresponding call to the NPN_GetURLNotify function.
00182                 */
00183         void PluginURLNotify(
00184                         const TDesC16& aUrl, 
00185                         NPReason aReason, 
00186                         void* aNotifyData );
00187 
00188         // Methods derived from base classes
00189         
00190                 /**
00191                 * This function implements the NotifyL() function of the MPluginNotifier 
00192                 * interface. It notifies the plug-in of an event. 
00193                 * @since 3.0
00194                 * @param aCallType - the event type that is passed to the plug-in. 
00195                 *                    Possible values are :
00196                 *                    EEditCut, 
00197                 *                    EEditCopy, 
00198                 *                    EEditPaste, 
00199                 *                    EEditDelete, 
00200                 *                    EApplicationFocusChanged, 
00201                 *                    ESystemNotification
00202                 * @param aParam    - the parameter associated with the event.
00203                 * @return          - not used.
00204                 */
00205         TInt NotifyL ( TNotificationType aCallType, TAny* aParam ); 
00206 
00207                 /**
00208                 * Returns the supported input capabilities which correspond to the behaviour 
00209                 * of the OfferKeyEventL() function of the control; 
00210                 * @since 3.0
00211                 * @return - TCoeInputCapabilities::EAllText which supports all types of text.
00212                 */
00213         TCoeInputCapabilities InputCapabilities ( void ) const;
00214   
00215                 /**
00216                 * This function handles key events. when 'Enter' key or 'OK' key is pressed, 
00217                 * the bitmap rendered is flipped from redflower to blueflower and viceversa.
00218                 * @since 3.0
00219                 * @param aKeyEvent - the key event.
00220                 * @param aType     - type of key event:EEventKey, EEventKeyUp or EEventKeyDown
00221                 * @return          - the function returns EKeyWasNotConsumed if it does not do 
00222                 *                    anything in response to a key event. If it is able to 
00223                 *                    process the event it returns EKeyWasConsumed.
00224                 */
00225         TKeyResponse OfferKeyEventL(
00226                             const TKeyEvent& aKeyEvent,
00227                             TEventCode aType );
00228 
00229                 /**
00230                 * This function inherited from MCoeControlObserver handles an event from an 
00231                 * observed control.
00232                 * @since 3.0
00233                 * @param aControl   - pointer to the control from which the event originated.
00234                 * @param aEventType - the event type.
00235                 */
00236         void HandleControlEventL ( CCoeControl* aControl, TCoeEvent aEventType );
00237 
00238                 /**
00239                 * This function handles pointer events. On clicking the left mouse button, 
00240                 * the bitmap rendered is flipped from redflower to blueflower and viceversa.
00241                 * @since 3.0
00242                 * @param aPointerEvent - The pointer event.
00243                 */
00244         void HandlePointerEventL ( const TPointerEvent& aPointerEvent );
00245   
00246                 /**
00247                 * This function is called whenever a control gains or loses focus - as a 
00248                 * result of a call to SetFocus(). 
00249                 * @since 3.0
00250                 * @param aDrawNow  - Contains the value that was passed to it by SetFocus().
00251                 */
00252         void FocusChanged ( TDrawNow aDrawNow );
00253 
00254                 /**
00255                 * This function which responds to size changes to set the size and position of 
00256                 * the contents of the control does nothing and has an empty implementation.
00257                 * @since 3.0
00258                 */
00259         void SizeChanged ( void );
00260   
00261     private:
00262                 /**
00263                 * Constructor
00264                 */
00265         CBitmapInst ( NPP aNpp );
00266 
00267                 /**
00268                 * second phase constructor
00269                 */
00270         void Construct();
00271 
00272                 /**
00273                 * This function draws the control. When iFlipBitmap is true it renders one 
00274                 * bitmap, and when iFlipBitmap is false it renders another one.
00275                 * @since 3.0
00276                 * @param aRect - The region of the control to be redrawn. Co-ordinates are 
00277                 *                relative to the control's origin (top left corner).
00278                 */
00279         void Draw ( const TRect& aRect ) const; // derived from CCoeControl
00280 
00281                 /**
00282                 * This function calls the NPN_GetURL function to ask the browser to deliver 
00283                 * the data to the plug-in instance in a new stream.
00284                 * @since 3.0
00285                 * @return - if the url is NULL returns NPERR_GENERIC_ERROR, otherwise returns
00286                 *           NPError status code from calling the NPN_GetURL function.
00287                 */
00288         NPError HandleGet ( void );
00289 
00290         NPStream*   iStream;
00291         TInt        iWriteReady;
00292         TUint16*    iSourceUrl;
00293         NPP         iNpp;
00294         TBool       iFirstTime;
00295         TBool       iFlipBitmap;
00296         HBufC*      iFileName;
00297         TInt        iNumDownload;
00298     };
00299 
00300 #endif // BITMAPINST_H
00301 
00302 // End of File
00303 

© Nokia 2006

Back to top