javauis/lcdui_akn/javalcdui/src/Toolkit.cpp
branchRCL_3
changeset 19 04becd199f91
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 #include "CMIDToolkit.h"
       
    20 #include "MIDUtils.h"
       
    21 #include "javax_microedition_lcdui_Toolkit.h"
       
    22 #include "lcdgr.h"
       
    23 #include "CMIDEvent.h"
       
    24 #include <mevents.h>
       
    25 #include <CJavaEventServer.h>
       
    26 
       
    27 #ifdef LCDUI_DEBUG_ON
       
    28 #include <jdebug.h>
       
    29 #define LCDUI_DEBUG(msg) DEBUG(msg)
       
    30 #define LCDUI_DEBUG_INT(msg,x) DEBUG_INT(msg,x)
       
    31 #define LCDUI_DEBUG_INT2(msg,x,y) DEBUG_INT2(msg, x, y)
       
    32 #else
       
    33 #define LCDUI_DEBUG(msg)
       
    34 #define LCDUI_DEBUG_INT(msg, x)
       
    35 #define LCDUI_DEBUG_INT2(msg, x, y)
       
    36 #endif
       
    37 
       
    38 /**
       
    39  * Flag indexes and total number of flags
       
    40  * @since S60 9.2
       
    41  */
       
    42 enum TFlags
       
    43 {
       
    44     EFlagNgaEnabledIndex = 0,
       
    45     EFlagCount
       
    46 };
       
    47 
       
    48 //
       
    49 // Close the Java peers handle onto the toolkit.
       
    50 //
       
    51 // This stops any remaining events from being posted or dispatched.
       
    52 //
       
    53 // If there are any events on the queue the toolkit will continue
       
    54 // to exists until the last event has been dequeued.
       
    55 //
       
    56 LOCAL_C void DisposeToolkit(JNIEnv& aJni, TInt aHandle)
       
    57 {
       
    58     CMIDToolkit::Unhand(aHandle).Dispose(aJni);
       
    59 }
       
    60 
       
    61 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1create
       
    62 (
       
    63     JNIEnv* aJni,
       
    64     jobject aToolkit,
       
    65     jint aServer,
       
    66     jstring aName,
       
    67     jint aUid,
       
    68     jstring aHomeDir,
       
    69     jobjectArray aAttributes,
       
    70     jintArray aFlags
       
    71 )
       
    72 {
       
    73     RJString name(*aJni,aName);
       
    74     RJString homeDir(*aJni,aHomeDir);
       
    75     RPointerArray<HBufC>* attribArray = NULL;
       
    76 
       
    77     jint error = 0;
       
    78     RPointerArray<HBufC> attributes;
       
    79     if (aAttributes)
       
    80     {
       
    81         jint count = aJni->GetArrayLength(aAttributes);
       
    82         jint index = 0;
       
    83         ASSERT(count%2 == 0);
       
    84         while ((index<count) && (0 == error))
       
    85         {
       
    86             jstring jniString = NULL;
       
    87 
       
    88             jniString = (jstring)aJni->GetObjectArrayElement(aAttributes, index);
       
    89             {
       
    90                 RJString rjString(*aJni,jniString);
       
    91 
       
    92                 HBufC* element = NULL;
       
    93                 TRAP(error, element = rjString.AllocL())
       
    94                 if (error == KErrNone)
       
    95                 {
       
    96                     error = attributes.Append(element);
       
    97                     if (error) delete element;
       
    98                 }
       
    99             }
       
   100             // Delete only after rjString has been destructed
       
   101             aJni->DeleteLocalRef(jniString);
       
   102 
       
   103             ++index;
       
   104         }
       
   105     }
       
   106     if (error)
       
   107     {
       
   108         attributes.ResetAndDestroy();
       
   109         attributes.Close();
       
   110         return error;
       
   111     }
       
   112     attribArray=&attributes;
       
   113     jint handle = CMIDToolkit::New(*aJni, aToolkit, aServer, name, aUid, homeDir, attribArray);
       
   114     attributes.ResetAndDestroy();
       
   115     attributes.Close();
       
   116 
       
   117     jint flags[EFlagCount];
       
   118 #ifdef RD_JAVA_NGA_ENABLED
       
   119     flags[EFlagNgaEnabledIndex] = 1;
       
   120 #else // !RD_JAVA_NGA_ENABLED
       
   121     flags[EFlagNgaEnabledIndex] = 0;
       
   122 #endif // RD_JAVA_NGA_ENABLED
       
   123     aJni->SetIntArrayRegion(aFlags, 0, EFlagCount, &flags[0]);
       
   124     return handle;
       
   125 }
       
   126 
       
   127 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_Toolkit__1dispose(JNIEnv* aJni,jobject,jint aToolkit)
       
   128 {
       
   129     DisposeToolkit(*aJni, aToolkit);
       
   130 }
       
   131 
       
   132 LOCAL_C void InvokeDisposeObject(CMIDToolkit* aToolkit, jint aObject)
       
   133 {
       
   134     MMIDComponent* object = MIDUnhandObject<MMIDComponent>(aObject);
       
   135     aToolkit->DisposeObject(object);
       
   136 }
       
   137 
       
   138 extern void DoDisposeObject(CMIDToolkit& aToolkit, jint aObject)
       
   139 {
       
   140     aToolkit.ExecuteV(&InvokeDisposeObject, &aToolkit, aObject);
       
   141 }
       
   142 
       
   143 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_Toolkit__1disposeObject
       
   144 (JNIEnv*,jobject,jint aToolkit,jint aObject)
       
   145 {
       
   146     LCDUI_DEBUG_INT("Toolkit_disposeObject(%x)", aObject);
       
   147     DoDisposeObject(*JavaUnhand<CMIDToolkit>(aToolkit), aObject);
       
   148 }
       
   149 
       
   150 void InvokeSetCurrentL(CMIDToolkit* aToolkit, MMIDDisplayable* aDisplayable)
       
   151 {
       
   152     LCDUI_DEBUG_INT2("Toolkit_setCurrent(%x, [%d])", (TInt)aDisplayable, (TInt)aDisplayable->Component()->Type());
       
   153     aToolkit->SetCurrentL(aDisplayable);
       
   154 }
       
   155 
       
   156 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1setCurrent
       
   157 (
       
   158     JNIEnv*,
       
   159     jobject,
       
   160     jint aToolkitHandle,
       
   161     jint aDisplayable
       
   162 )
       
   163 {
       
   164     CMIDToolkit* toolkit =JavaUnhand<CMIDToolkit>(aToolkitHandle);
       
   165     MMIDDisplayable* displayable = MIDUnhandObject<MMIDDisplayable>(aDisplayable);
       
   166     return toolkit->ExecuteTrap(&InvokeSetCurrentL,toolkit,displayable);
       
   167 }
       
   168 
       
   169 void InvokeSetForeground(CMIDToolkit* aToolkit, jboolean aForeground)
       
   170 {
       
   171     LCDUI_DEBUG_INT("Toolkit_requestForeground(%d)", (TInt)aForeground);
       
   172     if (aForeground)
       
   173     {
       
   174         aToolkit->BringToForeground();
       
   175     }
       
   176     else
       
   177     {
       
   178         aToolkit->SendToBackground();
       
   179     }
       
   180 }
       
   181 
       
   182 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1setForeground
       
   183 (
       
   184     JNIEnv*,
       
   185     jobject,
       
   186     jint        aToolkit,
       
   187     jboolean    aForeground
       
   188 )
       
   189 {
       
   190     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   191     toolkit->ExecuteV(&InvokeSetForeground,toolkit, aForeground);
       
   192     return KErrNone;
       
   193 }
       
   194 
       
   195 void InvokeSetCanvasAssumedSize(CMIDToolkit* aToolkit, jint aWidth, jint aHeight)
       
   196 {
       
   197     CMIDEnv& env = *(CMIDEnv*)aToolkit->Env();
       
   198     env.SetCanvasAssumedSize(TSize(aWidth, aHeight));
       
   199 }
       
   200 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1setCanvasSize
       
   201 (
       
   202     JNIEnv*, jobject, jint aToolkit, jint aWidth, jint aHeight
       
   203 )
       
   204 {
       
   205     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   206     toolkit->ExecuteV(InvokeSetCanvasAssumedSize, toolkit, aWidth, aHeight);
       
   207     return KErrNone;
       
   208 }
       
   209 
       
   210 void InvokeActivateL(CMIDToolkit* aToolkit)
       
   211 {
       
   212     aToolkit->ActivateL();
       
   213 }
       
   214 
       
   215 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1activate(JNIEnv*, jobject, jint aToolkit)
       
   216 {
       
   217     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   218     return toolkit->ExecuteTrap(&InvokeActivateL, toolkit);
       
   219 }
       
   220 
       
   221 extern "C" void pss();
       
   222 
       
   223 jint InvokePostEvent(CMIDToolkit* aToolkit, jint aSource, jint aType, jint aEvent)
       
   224 {
       
   225     LCDUI_DEBUG_INT2("InvokePostEvent(%x,%d)", aSource, aEvent);
       
   226     //pss();
       
   227     MMIDComponent* source = MIDUnhand<MMIDComponent>(aSource);
       
   228     switch (aType)
       
   229     {
       
   230     case EItem:
       
   231         return aToolkit->PostItemEvent(*source, (TEventType)aEvent, 0, 0, 0);
       
   232     case EDisplayable:
       
   233         return aToolkit->PostDisplayableEvent(*source, (TEventType)aEvent, 0, 0);
       
   234     case EMIDlet:
       
   235         return aToolkit->PostDisplayEvent((TEventType)aEvent);
       
   236     case ECanvasGraphicsItemPainterEvent:
       
   237         return aToolkit->PostCanvasGraphicsItemPainterEvent(*source, (TEventType)aEvent, 0, 0);
       
   238     default:
       
   239         ASSERT(EFalse);
       
   240     }
       
   241     return KErrArgument;
       
   242 }
       
   243 
       
   244 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Toolkit__1postEvent
       
   245 (
       
   246     JNIEnv* /*aEnv*/,
       
   247     jobject /*aToolkit*/,
       
   248     jint    aHandle,
       
   249     jint    aSource,
       
   250     jint    aType,
       
   251     jint    aEvent
       
   252 )
       
   253 {
       
   254     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aHandle);
       
   255     return toolkit->Execute(&InvokePostEvent, toolkit, aSource, aType, aEvent);
       
   256 }