javauis/lcdui_akn/javalcdui/src/Canvas.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
parent 14 04becd199f91
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     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 #include "CMIDToolkit.h"
       
    19 #include "MIDUtils.h"
       
    20 #include "javax_microedition_lcdui_Canvas.h"
       
    21 
       
    22 #ifdef LCDUI_DEBUG_ON
       
    23 #include <jdebug.h>
       
    24 #define LCDUI_DEBUG_INT2(msg, x, y) DEBUG_INT2(msg, x, y)
       
    25 #else
       
    26 #define LCDUI_DEBUG_INT2(msg, x, y)
       
    27 #endif
       
    28 
       
    29 struct TCanvasCreate
       
    30 {
       
    31     jweak       iRef;
       
    32     jint        iDisplayable;
       
    33     jboolean    iIsGameCanvas;
       
    34 };
       
    35 
       
    36 struct TCanvasAttribs
       
    37 {
       
    38     TInt  iHandle;
       
    39     TSize iSize;
       
    40     TBool iFrameBuffer;
       
    41     TBool iHasBackground;
       
    42 };
       
    43 
       
    44 LOCAL_C void CreateCanvasL(CMIDToolkit* aToolkit, TCanvasCreate* aCreate, TCanvasAttribs* aAttribs)
       
    45 {
       
    46     MMIDDisplayable* container = MIDUnhand<MMIDDisplayable>(aCreate->iDisplayable);
       
    47     // Create a new MMIDCanvas object
       
    48     MMIDCanvas* canvas = aToolkit->ComponentFactory()->CreateCanvasL(
       
    49                              *container,
       
    50                              (aCreate->iIsGameCanvas ? MMIDComponent::EGameCanvas : MMIDComponent::ECanvas));
       
    51     CleanupDisposePushL(canvas);
       
    52     aAttribs->iHandle = aToolkit->RegisterComponentL(canvas, aCreate->iRef);
       
    53     container->SetComponentL(*canvas);
       
    54     CleanupPopComponent(canvas);
       
    55     aCreate->iRef = 0;
       
    56     aAttribs->iSize = canvas->ContentSize();
       
    57     aAttribs->iFrameBuffer = static_cast< TBool >(canvas->FrameBuffer() != NULL);
       
    58 
       
    59     // Check from a MMIDEnv object if the canvas object has a background or not
       
    60     aAttribs->iHasBackground = aToolkit->Env()->CanvasHasBackground(*canvas);
       
    61 
       
    62 }
       
    63 
       
    64 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1create
       
    65 (
       
    66     JNIEnv*   aJni,
       
    67     jobject   aCanvas,
       
    68     jint      aToolkit,
       
    69     jint      aDisplayable,
       
    70     jboolean  aIsGameCanvas,
       
    71     jintArray aAttribsReturn
       
    72 )
       
    73 {
       
    74     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    75 
       
    76     TCanvasCreate create;
       
    77     create.iDisplayable=aDisplayable;
       
    78     create.iRef= aJni->NewWeakGlobalRef(aCanvas);
       
    79     create.iIsGameCanvas = aIsGameCanvas;
       
    80     TCanvasAttribs attribs;
       
    81     attribs.iFrameBuffer=EFalse;
       
    82 
       
    83     attribs.iHasBackground = EFalse;
       
    84     jint error;
       
    85     if (create.iRef)
       
    86     {
       
    87         error = toolkit->ExecuteTrap(&CreateCanvasL, toolkit, &create, &attribs);
       
    88     }
       
    89     else
       
    90     {
       
    91         error = KErrNoMemory;
       
    92     }
       
    93 
       
    94     if (create.iRef)
       
    95     {
       
    96         // should be cleared in CreateCanvasL if no error
       
    97         aJni->DeleteWeakGlobalRef(create.iRef);
       
    98     }
       
    99 
       
   100     ASSERT(aJni->GetArrayLength(aAttribsReturn) == 5);
       
   101     jint attribsArray[5];
       
   102     attribsArray[0] = static_cast< jint >(attribs.iHandle);
       
   103     attribsArray[1] = static_cast< jint >(attribs.iSize.iWidth);
       
   104     attribsArray[2] = static_cast< jint >(attribs.iSize.iHeight);
       
   105     attribsArray[3] = static_cast< jint >(attribs.iFrameBuffer);
       
   106     attribsArray[4] = static_cast< jint >(attribs.iHasBackground);
       
   107     aJni->SetIntArrayRegion(aAttribsReturn, 0, 5, &attribsArray[0]);
       
   108 
       
   109     LCDUI_DEBUG_INT2("Canvas_create(%x == %x)", handle, (TInt)MIDUnhandObject<MMIDCanvas>(handle));
       
   110     return error;
       
   111 }
       
   112 
       
   113 LOCAL_C TInt GetKeyCode(MMIDUtils* aUtils,TInt aGameAction)
       
   114 {
       
   115     return aUtils->GetKeyCode(aGameAction);
       
   116 }
       
   117 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1getKeyCode
       
   118 (JNIEnv *,jobject,jint aToolkit,jint aGameAction)
       
   119 {
       
   120     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   121     jint keyCode = toolkit->Execute(&GetKeyCode, toolkit->Utils(),(TInt)aGameAction);
       
   122     return keyCode;
       
   123 }
       
   124 
       
   125 LOCAL_C void GetKeyName(MMIDUtils* aUtils,TDes* aText,TInt aKeyCode)
       
   126 {
       
   127     aUtils->GetKeyName(*aText,aKeyCode);
       
   128 }
       
   129 JNIEXPORT jstring JNICALL Java_javax_microedition_lcdui_Canvas__1getKeyName
       
   130 (JNIEnv* aJni,jobject,jint aToolkit,jint aKeyCode)
       
   131 {
       
   132     TBuf<KMaxName> keyName;
       
   133     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   134     toolkit->ExecuteV(&GetKeyName,toolkit->Utils(),(TDes*)&keyName,(TInt)aKeyCode);
       
   135     jstring str = CreateJavaString(*aJni,keyName);
       
   136     return str;
       
   137 }
       
   138 
       
   139 LOCAL_C TInt GetGameAction(MMIDUtils* aUtils,TInt aKeyCode)
       
   140 {
       
   141     return aUtils->GetGameAction(aKeyCode);
       
   142 }
       
   143 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1getGameAction
       
   144 (JNIEnv*, jclass, jint aToolkit, jint aKeyCode)
       
   145 {
       
   146     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   147     jint gameAction = toolkit->Execute(&GetGameAction, toolkit->Utils(), (TInt)aKeyCode);
       
   148     LCDUI_DEBUG_INT2("getGameAction(%d) -> %d", aKeyCode, gameAction);
       
   149     return gameAction;
       
   150 }
       
   151 
       
   152 LOCAL_C void InvokeGetCanvasSize(MMIDCanvas* aCanvas, TSize* aSize)
       
   153 {
       
   154     *aSize = aCanvas->ContentSize();
       
   155 }
       
   156 
       
   157 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1getCanvasSize
       
   158 (
       
   159     JNIEnv*,
       
   160     jobject,
       
   161     jint aToolkit,
       
   162     jint aCanvas
       
   163 )
       
   164 {
       
   165     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   166     MMIDCanvas* canvas = MIDUnhand<MMIDCanvas>(aCanvas);
       
   167     TSize size;
       
   168     toolkit->ExecuteV(&InvokeGetCanvasSize, canvas, &size);
       
   169     return (size.iWidth << 16) | (size.iHeight & 0x0000ffff);
       
   170 }
       
   171 
       
   172 LOCAL_C void InvokeSuppressKeys(MMIDCanvas* aCanvas)
       
   173 {
       
   174     ASSERT(aCanvas);
       
   175     aCanvas->SuppressKeys();
       
   176 }
       
   177 
       
   178 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_Canvas__1suppressKeyEvents
       
   179 (JNIEnv*,jobject,jint aToolkit,jint aCanvas)
       
   180 {
       
   181     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   182     MMIDCanvas*  canvas  = MIDUnhand<MMIDCanvas>(aCanvas);
       
   183     toolkit->ExecuteV(&InvokeSuppressKeys, canvas);
       
   184 }
       
   185 
       
   186 LOCAL_C TInt InvokeGameActions(MMIDCanvas* aCanvas)
       
   187 {
       
   188     ASSERT(aCanvas);
       
   189     return TInt(aCanvas->GameActions());
       
   190 }
       
   191 
       
   192 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1getKeyStates
       
   193 (JNIEnv *,jobject,jint aToolkit, jint aCanvas)
       
   194 {
       
   195     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   196     MMIDCanvas*  canvas  = MIDUnhand<MMIDCanvas>(aCanvas);
       
   197 
       
   198     TInt actions = toolkit->Execute(&InvokeGameActions, canvas);
       
   199     return actions;
       
   200 }
       
   201 
       
   202 LOCAL_C void InvokeSetFullScreenModeL(jint aDisplayable,jboolean aFullScreen, jint* aSizeArray)
       
   203 {
       
   204     MMIDDisplayable* displayable = MIDUnhandObject<MMIDDisplayable>(aDisplayable);
       
   205     MMIDCanvas* canvas = (MMIDCanvas*)displayable->Component();
       
   206     displayable->SetFullScreenModeL(aFullScreen);
       
   207     TSize size = canvas->ContentSize();
       
   208     aSizeArray[0]=size.iWidth;
       
   209     aSizeArray[1]=size.iHeight;
       
   210 }
       
   211 
       
   212 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Canvas__1setFullScreenMode
       
   213 (JNIEnv* aEnv,jobject,jint aToolkit,jint aDisplayable,jboolean aFullScreen, jintArray aSizeReturn)
       
   214 {
       
   215     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   216     jint sizeArray[2];
       
   217     jint err = toolkit->ExecuteTrap(&InvokeSetFullScreenModeL, aDisplayable, aFullScreen, sizeArray);
       
   218     aEnv->SetIntArrayRegion(aSizeReturn, 0, 2, sizeArray);
       
   219     return err;
       
   220 }
       
   221 
       
   222 LOCAL_C jboolean InvokeNetworkIndicatorLocation(MMIDCanvas* aCanvas, jint* aPositionArray, jint* aSizeArray)
       
   223 {
       
   224     TSize size;
       
   225     TPoint position;
       
   226     TBool indicatorExists = aCanvas->NetworkIndicatorLocation(position, size);
       
   227     aPositionArray[0] = position.iX;
       
   228     aPositionArray[1] = position.iY;
       
   229     aSizeArray[0] = size.iWidth;
       
   230     aSizeArray[1] = size.iHeight;
       
   231     return indicatorExists;
       
   232 }
       
   233 
       
   234 JNIEXPORT jboolean JNICALL Java_javax_microedition_lcdui_Canvas__1getNetworkIndicatorLocation
       
   235 (JNIEnv* aEnv,jobject, jint aToolkit, jint aCanvas, jintArray aPosition, jintArray aSize)
       
   236 {
       
   237     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   238     MMIDCanvas*  canvas  = MIDUnhand<MMIDCanvas>(aCanvas);
       
   239     jint positionArray[2];
       
   240     jint sizeArray[2];
       
   241     jboolean indicatorExists = toolkit->Execute(&InvokeNetworkIndicatorLocation, canvas, positionArray, sizeArray);
       
   242     aEnv->SetIntArrayRegion(aPosition, 0, 2, positionArray);
       
   243     aEnv->SetIntArrayRegion(aSize,     0, 2, sizeArray);
       
   244     return indicatorExists;
       
   245 }
       
   246 
       
   247