javauis/lcdui_akn/javalcdui/inc/CMIDEnv.h
branchRCL_3
changeset 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMIDENV_H
       
    20 #define CMIDENV_H
       
    21 
       
    22 #include <e32def.h>
       
    23 #include <lcdui.h>
       
    24 
       
    25 class CMIDKeyTranslator;
       
    26 class CMIDToolkit;
       
    27 class CMIDToLcduiObserver;
       
    28 
       
    29 
       
    30 /**
       
    31  *
       
    32  * A MIDlet environment, one per MIDlet, providing utility methods for the
       
    33  * MIDP implementation
       
    34  *
       
    35  */
       
    36 class CMIDEnv : public CBase, public MMIDEnv
       
    37 {
       
    38 public:
       
    39     CMIDEnv(CMIDToolkit* aToolkit, const TSize& aSize);
       
    40     void ConstructL();
       
    41     ~CMIDEnv();
       
    42 
       
    43     void SetUtils(MMIDUtils* aUtils);
       
    44 
       
    45 public:
       
    46     virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TEventType aEventType,TInt aEventData,TInt aEventData1,TInt aEventData2);
       
    47     virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TEventType aEventType=ENoType,TInt aEventData=0);
       
    48     virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TInt aEventData);
       
    49     virtual TBool PostMidletEvent(TEventType aEventType);
       
    50 
       
    51     virtual MMIDNotifyEvent* NewNotifyL(MMIDComponent& aSource);
       
    52     virtual TBool   PostJavaNotify(MMIDNotifyEvent* aNotify);
       
    53 
       
    54     virtual TBool   TranslateKeyL(TMIDKeyEvent& aEvent, const TKeyEvent&, TEventCode aType);
       
    55     virtual TBool   PostKeyEvent(MMIDComponent& aSource, TMIDKeyEvent& aEvent);
       
    56     virtual void    ResetKeys();
       
    57 
       
    58     virtual MMIDDisplayable* Current();
       
    59     virtual TPtrC MidletName() const;
       
    60     virtual TUid MidletUid() const;
       
    61     virtual TPtrC MidletHome() const;
       
    62     virtual void DisplayableIsDestructed(const MMIDDisplayable* displayable);
       
    63 
       
    64 #ifdef RD_SCALABLE_UI_V2
       
    65     // This function can be moved out from RD_SCALABLE_UI_V2 flag if needed.
       
    66     // It is behind this flag because currently it is used only by Touch.
       
    67     /**
       
    68     * Returns MIDlet Suite uid that is parsed from the MIDlet home path.
       
    69     * In practise this function assumes that the midlet home path includes
       
    70     * Midlet suite uid inside the brackets, for example:
       
    71     * "e:\epoc32\winscw\c\private\102033E6\MIDlets\[101e0a27]"
       
    72     *
       
    73     * Note:
       
    74     * MIDlet suite uid could be retrieved from the Java registry based on
       
    75     * the midlet uid. But that operation is very time consuming because it
       
    76     * requires lot of file accessing, especially when there are many midlets
       
    77     * installed in the device.
       
    78     * @since S60 5.0
       
    79     * @return   TUid iMidletSuiteUid or
       
    80     *            KNullUidValue if midlet suite uid not found or error occured.
       
    81     */
       
    82     TUid MidletSuiteUid();
       
    83 #endif //RD_SCALABLE_UI_V2
       
    84 
       
    85     virtual TInt NumColors();
       
    86     virtual TDisplayMode DisplayMode();
       
    87 
       
    88     virtual void  SetCanvasZoomSize(const TSize& aSize);
       
    89     virtual TSize CanvasZoomSize();
       
    90     virtual TSize CanvasAssumedSize();
       
    91     virtual TInt MidletAttribute(const TDesC& aAttributeName, TPtrC& aAttributeValue);
       
    92 
       
    93     /**
       
    94      * @see MMIDEnv#MidletAttributeIsSetToVal()
       
    95      */
       
    96     virtual TBool MidletAttributeIsSetToVal(const TDesC& aAttributeName, const TDesC& aAttributeValue);
       
    97 
       
    98     /**
       
    99      * @see MMIDEnv#MidletAttributeContainsVal()
       
   100      */
       
   101     virtual TBool MidletAttributeContainsVal(const TDesC& aAttributeName, const TDesC& aAttributeValue);
       
   102 
       
   103     virtual void SetCanvasAssumedSize(const TSize& aSize);
       
   104 
       
   105     //
       
   106     virtual void AddObserverL(MMIDEnvObserver& aObserver);
       
   107     virtual void RemoveObserver(MMIDEnvObserver& aObserver);
       
   108     //
       
   109     void HandleSwitchOnL(TBool aSwitchOn);
       
   110     void HandleForegroundL(TBool aForeground);
       
   111     void HandleResourceChangeL(TInt aType);
       
   112 
       
   113     /**
       
   114      * @see MMIDEnv#ReserveCanvasFrameBuffer()
       
   115      */
       
   116     virtual CFbsBitmap* ReserveCanvasFrameBufferL(MMIDCanvas& aCanvas, const TSize& aSz);
       
   117 
       
   118     /**
       
   119      * @see MMIDEnv#ReleaseCanvasFrameBuffer()
       
   120      */
       
   121     virtual void ReleaseCanvasFrameBuffer(MMIDCanvas& aCanvas, CFbsBitmap*& aFrameBuffer);
       
   122 
       
   123     /**
       
   124      * @see MMIDEnv#CanvasHasBackground()
       
   125      */
       
   126     virtual TBool CanvasHasBackground(const MMIDCanvas& aCanvas) const;
       
   127 
       
   128     /**
       
   129      * Maps low level key event
       
   130      * @param    aMidKeyEvent key event output data
       
   131      * @param    aEvent key event input data
       
   132      * @see    virtual void MMIDEnv::MappingDataForKey( TKeyEvent& aEvent );
       
   133      */
       
   134     virtual void MappingDataForKey(TKeyEvent& aEvent, TEventCode aType);
       
   135 
       
   136     /**
       
   137      * Set last key event
       
   138      * @param    aEvent key event input data
       
   139      * @see    virtual void MMIDEnv::SetLastKeyEvent( const TKeyEvent& aEvent );
       
   140      */
       
   141     virtual void SetLastKeyEvent(const TKeyEvent& aEvent);
       
   142 
       
   143     /**
       
   144      * From MMIDEnv.
       
   145      * Gets an instance of ToLcduiObserver.
       
   146      *
       
   147      * @since S60 5.0
       
   148      * @return Pointer to ToLcduiObserver instance
       
   149      * @see iToLcduiObserver
       
   150      */
       
   151     virtual MMIDToLcduiObserver& ToLcduiObserver();
       
   152 
       
   153 #ifdef RD_JAVA_NGA_ENABLED
       
   154     /**
       
   155      * @see MMIDEnv#IsHardwareAccelerated()
       
   156      */
       
   157     virtual TBool IsHardwareAcceleratedL(
       
   158         MMIDEnv::THardwareType aHardwareType = MMIDEnv::EHardware3D);
       
   159 
       
   160 private:
       
   161     /**
       
   162      * Checks and initializes 2D & 3D harware status
       
   163      * @return Hardware status @see MMIDEnv::THardwareType
       
   164      * @since S60 9.2
       
   165      */
       
   166     TInt InitHardwareStatusL();
       
   167 
       
   168 #endif // RD_JAVA_NGA_ENABLED
       
   169 
       
   170 
       
   171 private:
       
   172     /**
       
   173      * Encapsulated canvas (frame buffer) data
       
   174      */
       
   175     struct TCanvasData
       
   176     {
       
   177 
       
   178         /**
       
   179          * Ctor
       
   180          */
       
   181         TCanvasData()
       
   182                 : iRefCount(0), iFrameBuffer(NULL), iHasBackground(EFalse)
       
   183         {
       
   184         }
       
   185 
       
   186         /**
       
   187          * Reset frame buffer data
       
   188          */
       
   189         inline void Reset()
       
   190         {
       
   191             delete iFrameBuffer;
       
   192             iFrameBuffer = NULL;
       
   193             iRefCount = 0;
       
   194         }
       
   195         TUint                       iRefCount;
       
   196         CFbsBitmap*                 iFrameBuffer;
       
   197         TBool                       iHasBackground;
       
   198         RMutex                      iLock;
       
   199     };
       
   200 
       
   201     /**
       
   202      * Autolocker class.
       
   203      */
       
   204     class TMutexAutoLock
       
   205     {
       
   206     public:
       
   207         /**
       
   208          * Ctor
       
   209          * @param aLock Syncronization primitive that is locked during construction
       
   210          */
       
   211         TMutexAutoLock(RMutex* aLock) : iLock(aLock)
       
   212         {
       
   213             iLock->Wait();
       
   214         }
       
   215 
       
   216         /**
       
   217          * Dtor. Signals the synchronization primitive
       
   218          */
       
   219         ~TMutexAutoLock()
       
   220         {
       
   221             iLock->Signal();
       
   222         }
       
   223     private:
       
   224         RMutex* iLock;
       
   225     };
       
   226 
       
   227 
       
   228     /**
       
   229      * Create a frame buffer for a <code>MMIDCanvas</code> instance.
       
   230      * @param   aCanvas Target canvas
       
   231      * @param   aWsBitmap If <code>ETrue</code> then the type of the frame buffer
       
   232      *          will be <code>WsBitmap</code> instead of a <code>CFbsBitmap</code>.
       
   233      * @param   aSz Frame buffer size
       
   234      * @return  Frame buffer instance
       
   235      * @since S60 5.0
       
   236      */
       
   237     CFbsBitmap* CreateCanvasFrameBufferL(
       
   238         MMIDCanvas& aCanvas, TBool aWsBitmap, const TSize& aSz);
       
   239 
       
   240 private:
       
   241     enum {EGranularity = 4};
       
   242 
       
   243 private:
       
   244     CMIDToolkit*                iToolkit;
       
   245     RArray<MMIDEnvObserver*>    iObservers;
       
   246     CMIDKeyTranslator*          iKeyTranslator;
       
   247     TSize                       iCanvasAssumedSize;
       
   248     TSize                       iCanvasZoomSize;
       
   249     TCanvasData                 iCanvasData;
       
   250 
       
   251 #ifdef RD_SCALABLE_UI_V2
       
   252     // MIDlet suite uid
       
   253     TUid                        iMidletSuiteUid;
       
   254 #endif //RD_SCALABLE_UI_V2
       
   255 
       
   256     /**
       
   257      * Provides possibility to make calls from non-LCDUI threads
       
   258      * to LCDUI ES thread.
       
   259      * Own.
       
   260      */
       
   261     CMIDToLcduiObserver*        iToLcduiObserver;
       
   262 
       
   263 #ifdef RD_JAVA_NGA_ENABLED
       
   264     TInt                        iHardwareStatus;
       
   265 #endif // RD_JAVA_NGA_ENABLED
       
   266 };
       
   267 
       
   268 #endif // CMIDENV_H