javauis/lcdui_akn/javalcdui/src/CustomItem.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
parent 14 04becd199f91
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 1999 - 2003 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 <e32def.h> // MAKE_TINT_64
       
    19 #include "javax_microedition_lcdui_CustomItem.h"
       
    20 #include "CMIDToolkit.h"
       
    21 #include "MIDUtils.h"
       
    22 
       
    23 LOCAL_C void CreateL
       
    24 (
       
    25     CMIDToolkit*    aToolkit,
       
    26     TInt*       aHandle,
       
    27     jobject     aReference,
       
    28     const TDesC*    aLabel
       
    29 )
       
    30 //
       
    31 // Creates the plataform dependent MMIDCustomItem
       
    32 //
       
    33 {
       
    34     MMIDCustomItem* customItem = aToolkit->ComponentFactory()->CreateCustomItemL(*aLabel);
       
    35     CleanupDisposePushL(customItem);
       
    36     *aHandle = aToolkit->RegisterComponentL(customItem, aReference);
       
    37     CleanupPopComponent(customItem);
       
    38 }
       
    39 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_CustomItem__1create
       
    40 (
       
    41     JNIEnv* aJni,
       
    42     jobject,
       
    43     jint    aToolkit,
       
    44     jobject aCustomItem,
       
    45     jstring aLabel
       
    46 )
       
    47 {
       
    48     jobject customItem = aJni->NewWeakGlobalRef(aCustomItem);
       
    49     if (customItem == 0)
       
    50         return KErrNoMemory;
       
    51 
       
    52     //
       
    53     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    54     RJString label(*aJni,aLabel);
       
    55 
       
    56     TInt handle = 0;
       
    57     TInt err = toolkit->ExecuteTrap(&CreateL,toolkit,&handle,customItem,(const TDesC*)&label);
       
    58     if (err!=KErrNone)
       
    59     {
       
    60         aJni->DeleteWeakGlobalRef((jweak)customItem);
       
    61         return err;
       
    62     }
       
    63 
       
    64     return handle;
       
    65 }
       
    66 
       
    67 
       
    68 
       
    69 LOCAL_C TInt InvokeInteractionModes(MMIDCustomItem* aItem)
       
    70 {
       
    71     return aItem->InteractionModes();
       
    72 }
       
    73 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_CustomItem__1getInteractionModes
       
    74 (
       
    75     JNIEnv*,
       
    76     jobject,
       
    77     jint    aToolkit,
       
    78     jint    aItem
       
    79 )
       
    80 {
       
    81     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    82     MMIDCustomItem* customItem = MIDUnhand<MMIDCustomItem>(aItem);
       
    83     return toolkit->Execute(InvokeInteractionModes, customItem);
       
    84 }
       
    85 
       
    86 LOCAL_C void InvokeSetFocusAndScroll(MMIDCustomItem* aItem, TBool aKeepFocus, const TRect* aRect,TInt aDirection)
       
    87 {
       
    88     aItem->SetFocusAndScroll(aKeepFocus, aRect, aDirection);
       
    89 }
       
    90 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_CustomItem__1setFocusAndScroll
       
    91 (JNIEnv* aJni,jobject,jint aToolkit,jint aItem,jboolean aKeepFocus,jintArray aScrollRect,jint aDirection)
       
    92 {
       
    93     TRect rect;
       
    94     const TRect* pRect = (aScrollRect != NULL ? &rect : NULL);
       
    95     if (pRect)
       
    96     {
       
    97         ASSERT(sizeof(TRect) == 4*sizeof(jint));
       
    98         aJni->GetIntArrayRegion(aScrollRect, 0, 4, reinterpret_cast<jint*>(&rect));
       
    99         rect.iBr.iX+=rect.iTl.iX;
       
   100         rect.iBr.iY+=rect.iTl.iY;
       
   101     }
       
   102     MMIDCustomItem* item = MIDUnhandObject<MMIDCustomItem>(aItem);
       
   103     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   104 
       
   105     toolkit->ExecuteV(InvokeSetFocusAndScroll, item, (TBool)aKeepFocus, pRect,(TInt)aDirection);
       
   106 }
       
   107 
       
   108 LOCAL_C void Invalidate(MMIDCustomItem* aCustomItem, TSize aMinSize, TSize aPrefSize)
       
   109 {
       
   110     aCustomItem->Invalidate(aMinSize,aPrefSize);
       
   111 }
       
   112 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_CustomItem__1invalidate
       
   113 (JNIEnv*,jobject,jint aToolkit,jint aCustomItem,jint aMinWidth,jint aMinHeight,jint aPreWidth,jint aPreHeight)
       
   114 {
       
   115     CMIDToolkit*    toolkit    = JavaUnhand<CMIDToolkit>(aToolkit);
       
   116     MMIDCustomItem* customItem = MIDUnhand<MMIDCustomItem>(aCustomItem);
       
   117     TSize minSize(aMinWidth,aMinHeight);
       
   118     TSize prefSize(aPreWidth, aPreHeight);
       
   119 
       
   120     toolkit->ExecuteV(Invalidate, customItem, minSize, prefSize);
       
   121 }