javauis/lcdui_akn/javalcdui/src/ImageItem.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 1999-2001 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 
       
    20 #include "CMIDToolkit.h"
       
    21 #include "MIDUtils.h"
       
    22 #include "javax_microedition_lcdui_ImageItem.h"
       
    23 #include "lcdgr.h"
       
    24 
       
    25 
       
    26 LOCAL_C void CreateL(CMIDToolkit* aToolkit,TInt* aHandle,jobject aImageItem,const TDesC* aLabel,MMIDImage* aImage,TInt aLayout,TInt aAppearanceMode,const TDesC* aAltText)
       
    27 {
       
    28     MMIDImageItem* item = aToolkit->ComponentFactory()->CreateImageItemL(*aLabel,aImage,(MMIDItem::TLayout)aLayout,(MMIDItem::TAppearance)aAppearanceMode,*aAltText);
       
    29     CleanupDisposePushL(item);
       
    30     *aHandle = aToolkit->RegisterComponentL(item, aImageItem);
       
    31     CleanupPopComponent(item);
       
    32 }
       
    33 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ImageItem__1create
       
    34 (JNIEnv* aJni,jobject,jint aToolkit,jobject aImageItem,jstring aLabel,jint aImage,jint aLayout,jint aAppearanceMode,jstring aAltText)
       
    35 {
       
    36     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    37 
       
    38     TInt    handle    = 0;
       
    39     jobject imageItem = aJni->NewWeakGlobalRef(aImageItem);
       
    40     if (imageItem == 0)
       
    41         return KErrNoMemory;
       
    42 
       
    43     MMIDImage* image = MIDUnhandObject<MMIDImage>(aImage);
       
    44     RJString label(*aJni,aLabel);
       
    45     RJString altText(*aJni,aAltText);
       
    46 
       
    47     TInt err = toolkit->ExecuteTrap(&CreateL,toolkit,&handle,imageItem,(const TDesC*)&label,image,(TInt)aLayout,(TInt)aAppearanceMode,(const TDesC*)&altText);
       
    48     if (err!=KErrNone)
       
    49     {
       
    50         aJni->DeleteWeakGlobalRef((jweak)imageItem);
       
    51         return err;
       
    52     }
       
    53     return err == KErrNone ? handle : err;
       
    54 }
       
    55 
       
    56 LOCAL_C void SetImageL(MMIDImageItem* aImageItem,MMIDImage* aImage)
       
    57 {
       
    58     aImageItem->SetImageL(aImage);
       
    59 }
       
    60 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ImageItem__1setImage
       
    61 (JNIEnv*,jobject,jint aImageItem,jint aToolkit,jint aImage)
       
    62 {
       
    63     MMIDImageItem*  imageItem = MIDUnhandObject<MMIDImageItem>(aImageItem);
       
    64     MMIDImage*      image     = MIDUnhandObject<MMIDImage>(aImage);
       
    65     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SetImageL,imageItem,image);
       
    66 }
       
    67 
       
    68 LOCAL_C void SetAltTextL(MMIDImageItem* aImageItem,const TDesC* aAltText)
       
    69 {
       
    70     aImageItem->SetAltTextL(*aAltText);
       
    71 }
       
    72 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_ImageItem__1setAltText
       
    73 (JNIEnv* aEnv,jobject,jint aImageItem,jint aToolkit,jstring aAltText)
       
    74 {
       
    75     MMIDImageItem* imageItem = MIDUnhandObject<MMIDImageItem>(aImageItem);
       
    76     RJString text(*aEnv,aAltText);
       
    77     return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SetAltTextL,imageItem,(const TDesC*)&text);
       
    78 }