javauis/lcdui_akn/javalcdui/src/Alert.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14: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_Alert.h"
       
    22 
       
    23 struct TAlertCreate
       
    24 {
       
    25     jweak iRef;
       
    26     jint  iDisplayable;
       
    27     jint  iType;
       
    28     TPtrC iText;
       
    29     jint  iImage;
       
    30 };
       
    31 
       
    32 struct TAlertAttribs
       
    33 {
       
    34     jint    iHandle;
       
    35     TSize   iSize;
       
    36 };
       
    37 
       
    38 LOCAL_C void CreateAlertL(CMIDToolkit* aToolkit, TAlertCreate* aCreate, TAlertAttribs* aAttribs)
       
    39 {
       
    40     MMIDComponentFactory& factory = *aToolkit->ComponentFactory();
       
    41     MMIDDisplayable* displayable = MIDUnhand<MMIDDisplayable>(aCreate->iDisplayable);
       
    42     MMIDImage* image = MIDUnhand<MMIDImage>(aCreate->iImage);
       
    43     MMIDAlert* alert = factory.CreateAlertL(*displayable, (MMIDAlert::TAlertType)aCreate->iType, aCreate->iText, image);
       
    44     CleanupDisposePushL(alert);
       
    45     aAttribs->iHandle = aToolkit->RegisterComponentL(alert, aCreate->iRef);
       
    46     CleanupPopComponent(alert);
       
    47     aCreate->iRef = 0;      // register takes ownership
       
    48     aAttribs->iSize = displayable->ContentSize();
       
    49 }
       
    50 
       
    51 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1create
       
    52 (
       
    53     JNIEnv* aJni,
       
    54     jobject aAlert,
       
    55     jint    aToolkit,
       
    56     jint    aDisplayable,
       
    57     jstring aString,
       
    58     jint    aImage,
       
    59     jint    aType,
       
    60     jintArray aCreateAlertReturn
       
    61 )
       
    62 {
       
    63     RJString string(*aJni,aString);
       
    64 
       
    65     TAlertCreate create;
       
    66     create.iDisplayable=aDisplayable;
       
    67     create.iType=aType;
       
    68     create.iText.Set(string);
       
    69     create.iImage=aImage;
       
    70     create.iRef=aJni->NewWeakGlobalRef(aAlert);
       
    71 
       
    72     TAlertAttribs attribs;
       
    73     attribs.iHandle=0;
       
    74 
       
    75     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    76     jint error;
       
    77 
       
    78     if (create.iRef)
       
    79     {
       
    80         error = toolkit->ExecuteTrap(CreateAlertL, toolkit, &create, &attribs);
       
    81     }
       
    82     else
       
    83     {
       
    84         error = KErrNoMemory;
       
    85     }
       
    86 
       
    87     if (create.iRef)   // should be cleared by CreateAlertL if successful
       
    88     {
       
    89         aJni->DeleteWeakGlobalRef(create.iRef);
       
    90     }
       
    91 
       
    92     jint arrayReturn[3];
       
    93     arrayReturn[0] = attribs.iHandle;
       
    94     arrayReturn[1] = attribs.iSize.iWidth;
       
    95     arrayReturn[2] = attribs.iSize.iHeight;
       
    96     aJni->SetIntArrayRegion(aCreateAlertReturn, 0, 3, arrayReturn);
       
    97 
       
    98     return error;
       
    99 }
       
   100 
       
   101 LOCAL_C void SetStringL(MMIDAlert* aAlert,const TDesC* aString)
       
   102 {
       
   103     aAlert->SetStringL(*aString);
       
   104 }
       
   105 
       
   106 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setString
       
   107 (JNIEnv* aJni,jobject,jint aAlert,jint aToolkit,jstring aString)
       
   108 {
       
   109     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   110     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   111     RJString string(*aJni,aString);
       
   112     return toolkit->ExecuteTrap(&SetStringL,alert,(const TDesC*)&string);
       
   113 }
       
   114 
       
   115 LOCAL_C void SetImageL(MMIDAlert* aAlert,MMIDImage* aImage)
       
   116 {
       
   117     aAlert->SetImageL(aImage);
       
   118 }
       
   119 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setImage
       
   120 (JNIEnv*,jobject,jint aAlert,jint aToolkit,jint aImage)
       
   121 {
       
   122     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   123     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   124     MMIDImage* image = MIDUnhandObject<MMIDImage>(aImage);
       
   125     return toolkit->ExecuteTrap(&SetImageL,alert,image);
       
   126 }
       
   127 
       
   128 LOCAL_C void SetIndicatorL(MMIDAlert* aAlert,MMIDGauge* aGauge)
       
   129 {
       
   130     aAlert->SetIndicatorL(aGauge);
       
   131 }
       
   132 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setIndicator
       
   133 (JNIEnv*,jobject,jint aAlert,jint aToolkit,jint aGauge)
       
   134 {
       
   135     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   136     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   137     MMIDGauge* gauge = MIDUnhandObject<MMIDGauge>(aGauge);
       
   138     return toolkit->ExecuteTrap(&SetIndicatorL,alert,gauge);
       
   139 }
       
   140 
       
   141 LOCAL_C void SetTypeL(MMIDAlert* aAlert,TInt aType)
       
   142 {
       
   143     aAlert->SetTypeL((MMIDAlert::TAlertType)aType);
       
   144 }
       
   145 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setType
       
   146 (JNIEnv*,jobject,jint aAlert,jint aToolkit,jint aType)
       
   147 {
       
   148     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   149     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   150     return toolkit->ExecuteTrap(&SetTypeL,alert,(TInt)aType);
       
   151 }
       
   152 
       
   153 LOCAL_C jint DefaultTimeout(MMIDAlert* aAlert)
       
   154 {
       
   155     return aAlert->DefaultTimeout();
       
   156 }
       
   157 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1getDefaultTimeout
       
   158 (JNIEnv*,jobject,jint aAlert,jint aToolkit)
       
   159 {
       
   160     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   161     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   162     return toolkit->Execute(&DefaultTimeout,alert);
       
   163 }
       
   164 
       
   165 LOCAL_C void SetTimeoutL(MMIDAlert* aAlert,TInt aTimeout)
       
   166 {
       
   167     aAlert->SetTimeoutL(aTimeout);
       
   168 }
       
   169 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setTimeout
       
   170 (JNIEnv*,jobject,jint aAlert,jint aToolkit,jint aTimeout)
       
   171 {
       
   172     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   173     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   174     return toolkit->ExecuteTrap(&SetTimeoutL,alert,(TInt)aTimeout);
       
   175 }
       
   176 
       
   177 LOCAL_C void SetModalL(MMIDAlert* aAlert)
       
   178 {
       
   179     aAlert->SetModalL();
       
   180 }
       
   181 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Alert__1setModal
       
   182 (JNIEnv*,jobject,jint aAlert,jint aToolkit)
       
   183 {
       
   184     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   185     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   186     return toolkit->ExecuteTrap(&SetModalL,alert);
       
   187 }
       
   188 
       
   189 LOCAL_C jboolean IsModal(MMIDAlert* aAlert)
       
   190 {
       
   191     return (jboolean)aAlert->IsModal();
       
   192 }
       
   193 JNIEXPORT jboolean JNICALL Java_javax_microedition_lcdui_Alert__1isModal(JNIEnv*, jobject,jint aAlert,jint aToolkit)
       
   194 {
       
   195     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   196     MMIDAlert* alert = MIDUnhandObject<MMIDAlert>(aAlert);
       
   197     return toolkit->Execute(&IsModal,alert);
       
   198 }