javauis/lcdui_akn/javalcdui/src/ChoiceGroup.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
parent 14 04becd199f91
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 2001-2005 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 "lcdgr.h"
       
    21 
       
    22 #include "javax_microedition_lcdui_ChoiceGroup.h"
       
    23 
       
    24 LOCAL_C void CreateChoiceGroupL
       
    25 (
       
    26     CMIDToolkit*        aToolkit,
       
    27     jweak               aRef,
       
    28     const TDesC*        aLabel,
       
    29     TInt                aType,
       
    30     jint*               aHandle
       
    31 )
       
    32 {
       
    33     ASSERT(aLabel);
       
    34     MMIDComponentFactory& factory = *aToolkit->ComponentFactory();
       
    35     RArray<TPtrC> dummyTextArray;
       
    36     RArray<MMIDImage*> dummyImageArray;
       
    37     MMIDChoiceGroup* choice = factory.CreateChoiceGroupL(*aLabel, aType, dummyTextArray, dummyImageArray);
       
    38     CleanupDisposePushL(choice);
       
    39     *aHandle = aToolkit->RegisterComponentL(choice, aRef);
       
    40     CleanupPopComponent(choice);
       
    41 }
       
    42 
       
    43 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1create
       
    44 (
       
    45     JNIEnv*         aJni,
       
    46     jobject         aChoiceGroup,
       
    47     jint            aToolkit,
       
    48     jstring         aLabel,
       
    49     jint            aType
       
    50 )
       
    51 {
       
    52     jweak ref = aJni->NewWeakGlobalRef(aChoiceGroup);
       
    53     if (ref == 0)
       
    54     {
       
    55         return KErrNoMemory;
       
    56     }
       
    57 
       
    58     RJString label(*aJni, aLabel);
       
    59 
       
    60     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    61 
       
    62     jint handle = 0;
       
    63     jint error = toolkit->ExecuteTrap(
       
    64                      &CreateChoiceGroupL,
       
    65                      toolkit,
       
    66                      ref,
       
    67                      (const TDesC*)&label,
       
    68                      (TInt)aType,
       
    69                      &handle
       
    70                  );
       
    71 
       
    72     if (error != KErrNone)
       
    73     {
       
    74         ASSERT(ref);
       
    75         aJni->DeleteWeakGlobalRef(ref);
       
    76         return error;
       
    77     }
       
    78 
       
    79     return handle;
       
    80 }
       
    81 
       
    82 LOCAL_C void InsertElementL(MMIDChoiceGroup* aChoice,TInt aIndex,const TDesC* aText,MMIDImage* aImage)
       
    83 {
       
    84     aChoice->InsertElementL(aIndex,*aText, aImage);
       
    85 }
       
    86 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1insert
       
    87 (JNIEnv* aEnv,jobject,jint aItem,jint aToolkit,jint aIndex,jstring aStringItem,jint aImage)
       
    88 {
       
    89     RJString string(*aEnv,aStringItem);
       
    90     MMIDImage*       image  = MIDUnhand<MMIDImage>(aImage);
       
    91     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
    92     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&InsertElementL,choice,(TInt)aIndex,(const TDesC*)&string,image);
       
    93 }
       
    94 
       
    95 LOCAL_C void DeleteElementL(MMIDChoiceGroup* aChoice,TInt aIndex)
       
    96 {
       
    97     aChoice->DeleteElementL(aIndex);
       
    98 }
       
    99 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1delete
       
   100 (JNIEnv *, jobject, jint aItem, jint aToolkit, jint aIndex)
       
   101 {
       
   102     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   103     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&DeleteElementL,choice,(TInt)aIndex);
       
   104 }
       
   105 
       
   106 LOCAL_C void DeleteAllL(MMIDChoiceGroup* aChoice)
       
   107 {
       
   108     aChoice->DeleteAllL();
       
   109 }
       
   110 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1deleteAll
       
   111 (JNIEnv *, jobject, jint aItem, jint aToolkit)
       
   112 {
       
   113     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   114     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&DeleteAllL,choice);
       
   115 }
       
   116 
       
   117 LOCAL_C void SetElementL(MMIDChoiceGroup* aChoice,TInt aIndex,const TDesC* aText,MMIDImage* aImage)
       
   118 {
       
   119     aChoice->SetElementL(aIndex,*aText, aImage);
       
   120 }
       
   121 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1set
       
   122 (JNIEnv* aEnv,jobject,jint aItem,jint aToolkit,jint aIndex,jstring aStringItem,jint aImage)
       
   123 {
       
   124     RJString string(*aEnv,aStringItem);
       
   125     MMIDImage* image = MIDUnhand<MMIDImage>(aImage);
       
   126     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   127     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SetElementL,choice,(TInt)aIndex,(const TDesC*)&string,image);
       
   128 }
       
   129 
       
   130 LOCAL_C TBool IsSelected(MMIDChoiceGroup* aChoice,TInt aIndex)
       
   131 {
       
   132     return aChoice->IsSelected(aIndex);
       
   133 }
       
   134 JNIEXPORT jboolean JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1isSelected
       
   135 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aIndex)
       
   136 {
       
   137     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   138     return (jboolean)JavaUnhand<CMIDToolkit>(aToolkit)->Execute(&IsSelected,choice,(TInt)aIndex);
       
   139 }
       
   140 
       
   141 LOCAL_C void SelectElementL(MMIDChoiceGroup* aChoice,TInt aIndex,TBool aSelected)
       
   142 {
       
   143     aChoice->SelectElementL(aIndex,aSelected);
       
   144 }
       
   145 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1select
       
   146 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aIndex,jboolean aSelected)
       
   147 {
       
   148     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   149     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SelectElementL,choice,(TInt)aIndex,(TBool)aSelected);
       
   150 }
       
   151 
       
   152 LOCAL_C void SetFontL(MMIDChoiceGroup* aChoice,TInt aIndex, MMIDFont* aFont)
       
   153 {
       
   154     aChoice->SetFontL(aIndex,aFont);
       
   155 }
       
   156 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1setFont
       
   157 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aIndex,jint aFont)
       
   158 {
       
   159     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   160     MMIDFont* font = MIDUnhandObject<MMIDFont>(aFont);
       
   161     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   162     return toolkit->ExecuteTrap(&SetFontL,choice,(TInt)aIndex,font);
       
   163 }
       
   164 
       
   165 LOCAL_C void SetFitPolicyL(MMIDChoiceGroup* aChoice,TInt aFitPolicy)
       
   166 {
       
   167     aChoice->SetFitPolicyL(aFitPolicy);
       
   168 }
       
   169 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ChoiceGroup__1setFitPolicy
       
   170 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aFitPolicy)
       
   171 {
       
   172     MMIDChoiceGroup* choice = MIDUnhandObject<MMIDChoiceGroup>(aItem);
       
   173     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SetFitPolicyL,choice,(TInt)aFitPolicy);
       
   174 }