javauis/lcdui_akn/javalcdui/src/DateField.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_DateField.h"
       
    22 
       
    23 LOCAL_C void CreateL(CMIDToolkit* aToolkit,TInt* aHandle,jobject aDateField,const TDesC* aLabel,TInt aFieldType)
       
    24 {
       
    25     MMIDDateField* dateField = aToolkit->ComponentFactory()->CreateDateFieldL(*aLabel,(MMIDDateField::TFieldType)aFieldType);
       
    26     CleanupDisposePushL(dateField);
       
    27     *aHandle = aToolkit->RegisterComponentL(dateField, aDateField);
       
    28     CleanupPopComponent(dateField);
       
    29 }
       
    30 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_DateField__1create
       
    31 (JNIEnv* aJni,jobject,jint aToolkit,jobject aDateField,jstring aLabel,jint aFieldType)
       
    32 {
       
    33     jobject dateField = aJni->NewWeakGlobalRef(aDateField);
       
    34     if (dateField == 0)
       
    35         return KErrNoMemory;
       
    36     //
       
    37     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    38     RJString label(*aJni,aLabel);
       
    39     TInt h = 0;
       
    40     TInt err = toolkit->ExecuteTrap(&CreateL,toolkit,&h,dateField,(const TDesC*)&label,(TInt)aFieldType);
       
    41     if (err!=KErrNone)
       
    42     {
       
    43         aJni->DeleteWeakGlobalRef((jweak)dateField);
       
    44         return err;
       
    45     }
       
    46     return h;
       
    47 }
       
    48 
       
    49 LOCAL_C void Date(MMIDDateField* aItem,TTime* aTime)
       
    50 {
       
    51     *aTime = aItem->Date();
       
    52 }
       
    53 JNIEXPORT jlong JNICALL Java_javax_microedition_lcdui_DateField__1getDate
       
    54 (JNIEnv *,jobject,jint aToolkit,jint aItem)
       
    55 {
       
    56     MMIDDateField* item = MIDUnhandObject<MMIDDateField>(aItem);
       
    57     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    58     TTime time;
       
    59     toolkit->ExecuteV(&Date,item,&time);
       
    60     return JavaEpocTime::CreateJavaTime(time);
       
    61 }
       
    62 
       
    63 LOCAL_C void SetDate(MMIDDateField* aItem,TTime* aTime)
       
    64 {
       
    65     aItem->SetDate(*aTime);
       
    66 }
       
    67 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_DateField__1setDate
       
    68 (JNIEnv *,jobject,jint aToolkit,jint aItem,jlong aTime)
       
    69 {
       
    70     MMIDDateField* item = MIDUnhandObject<MMIDDateField>(aItem);
       
    71     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    72     TTime epocTime = JavaEpocTime::CreateEpocTTime(aTime);
       
    73     toolkit->ExecuteV(&SetDate,item,&epocTime);
       
    74 }
       
    75 
       
    76 void InvokeSetInputModeL(jint aDateField, jint aInputMode)
       
    77 {
       
    78     MMIDDateField* dateField = MIDUnhandObject<MMIDDateField>(aDateField);
       
    79     dateField->SetInputModeL((MMIDDateField::TInputMode)aInputMode);
       
    80 }
       
    81 
       
    82 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_DateField__1setInputMode
       
    83 (JNIEnv*,jobject,jint aToolkit, jint aItem, jint aInputMode)
       
    84 {
       
    85     //
       
    86     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    87     return toolkit->ExecuteTrap(InvokeSetInputModeL, aItem, aInputMode);
       
    88 }
       
    89 
       
    90 LOCAL_C void SetUninitialized(MMIDDateField* aItem)
       
    91 {
       
    92     aItem->SetUninitialized();
       
    93 }
       
    94 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_DateField__1setUninitialized
       
    95 (JNIEnv*,jobject,jint aToolkit,jint aDateField)
       
    96 {
       
    97     MMIDDateField* item = MIDUnhandObject<MMIDDateField>(aDateField);
       
    98     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    99     toolkit->ExecuteV(&SetUninitialized,item);
       
   100 }