/** * KNI function that creates new native resource for the current ImageItem. * * Class: javax.microedition.lcdui.ImageItemLFImpl * Java prototype: * private native int createNativeResource0(int ownerId, String label, * int layout, * Image img, String altText, * int appearanceMode) * * INTERFACE (operand stack manipulation): * parameters: ownerId pointer to the owner's native resource * label ImageItem's label * layout ImageItem's layout * img ImageItem's image * altText ImageItem's attText * appearanceMode the appearanceMode of ImageItem * return pointer to the created native resource */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_ImageItemLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr; MidpItem *itemPtr = NULL; pcsl_string label, altText; pcsl_string_status rc1,rc2; unsigned char* imgPtr = NULL; int appearanceMode, layout; KNI_StartHandles(3); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(image); KNI_DeclareHandle(altTextJString); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelJString); layout = KNI_GetParameterAsInt(3); KNI_GetParameterAsObject(4, image); KNI_GetParameterAsObject(5, altTextJString); if (KNI_IsNullHandle(image) != KNI_TRUE) { imgPtr = gxp_get_imagedata(image); } appearanceMode = KNI_GetParameterAsInt(6); rc1 = midp_jstring_to_pcsl_string(labelJString, &label); rc2 = midp_jstring_to_pcsl_string(altTextJString, &altText); KNI_EndHandles(); /* NULL and empty strings are acceptable. */ if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2 ) { err = KNI_ENOMEM; goto cleanup; } itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_IMAGE_ITEM_TYPE+appearanceMode); if (itemPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } err = lfpport_imageitem_create(itemPtr, ownerPtr, &label, layout, imgPtr, &altText, appearanceMode); cleanup: pcsl_string_free(&altText); pcsl_string_free(&label); if (err != KNI_OK) { MidpDeleteItem(itemPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(itemPtr); }
/** * KNI function that creates new native resource for the current CustomItem. * * The native widget created by this function must take into account * label and body locations, using Item methods. * Also it must be able to grab key/pointer events directed to this * item in order to pass them to java through the event queue. * The implementation should create a native offline buffer to be used * as the target for draw operation os the CustomItem, and as a source for * screen refresh in case a repaint is requested from the operating system. * * Class: javax.microedition.lcdui.CustomItemLFImpl * Java prototype: * private native int createNativeResource0(int ownerId, String label, * int layout) * * INTERFACE (operand stack manipulation): * parameters: ownerId pointer to the owner's native resource * label CustomItem's label * layout CustomItem's layout * return pointer to the created native resource */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_CustomItemLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpItem *ciPtr = NULL; pcsl_string label; pcsl_string_status rc; MidpDisplayable *ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); int layout = KNI_GetParameterAsInt(3); KNI_StartHandles(1); KNI_DeclareHandle(labelHandle); KNI_GetParameterAsObject(2, labelHandle); rc = midp_jstring_to_pcsl_string(labelHandle, &label); KNI_EndHandles(); if (PCSL_STRING_OK != rc) { err = KNI_ENOMEM; goto cleanup; } ciPtr = MidpNewItem(ownerPtr, MIDP_CUSTOM_ITEM_TYPE); if (ciPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } err = lfpport_customitem_create(ciPtr, ownerPtr, &label, layout); cleanup: pcsl_string_free(&label); if (err != KNI_OK) { MidpDeleteItem(ciPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(ciPtr); }
/** * KNI function that create native resource for current Gauge. * Class: javax.microedition.lcdui.GaugeLFImpl * Java prototype: * private native int createNativeResource0(int ownerId, * String label, int layout, * boolean interactive, * int maxValue, int initialValue) */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_GaugeLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpItem *gaugePtr = NULL; MidpDisplayable *ownerPtr; int maxValue, initialValue, layout; jboolean interactive; KNI_StartHandles(1); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); GET_PARAMETER_AS_PCSL_STRING(2, label) layout = KNI_GetParameterAsInt(3); interactive = KNI_GetParameterAsBoolean(4); maxValue = KNI_GetParameterAsInt(5); initialValue = KNI_GetParameterAsInt(6); { gaugePtr = MidpNewItem(ownerPtr, interactive ? MIDP_INTERACTIVE_GAUGE_TYPE : MIDP_NON_INTERACTIVE_GAUGE_TYPE); if (gaugePtr == NULL) { err = KNI_ENOMEM; } else { err = lfpport_gauge_create(gaugePtr, ownerPtr, &label, layout, interactive, maxValue, initialValue); } /* cleanup: */ if (err != KNI_OK) { MidpDeleteItem(gaugePtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } } RELEASE_PCSL_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnInt(gaugePtr); }
/** * KNI function that creates native resource for the current StringItem. * * Class: javax.microedition.lcdui.StringItemLFImpl * * Java prototype: * private native int createNativeResource0(int ownerId, * String label, int layout, String text, int maxSize, * int constraints, String initialInputMode) * * INTERFACE (operand stack manipulation): * parameters: ownerId id of the owner's native resource * label StringItem's label * layout StringItem's layout * text StringItem's text * appearanceMode the appearanceMode of StringItem * font font to paint text * returns: id of the created platform widget */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_StringItemLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr; MidpItem *itemPtr = NULL; pcsl_string label, text; pcsl_string_status rc1 = PCSL_STRING_OK, rc2 = PCSL_STRING_OK; PlatformFontPtr fontPtr = NULL; int appearanceMode, layout; KNI_StartHandles(4); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(textJString); KNI_DeclareHandle(fontJFont); KNI_DeclareHandle(fontHandle); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelJString); layout = KNI_GetParameterAsInt(3); KNI_GetParameterAsObject(4, textJString); appearanceMode = KNI_GetParameterAsInt(5); KNI_GetParameterAsObject(6, fontJFont); if (KNI_IsNullHandle(fontJFont) != KNI_TRUE) { int face, style, size; KNI_FindClass("javax/microedition/lcdui/Font", fontHandle); face = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face", "I", _f_face_cache)); style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "style", "I", _f_style_cache)); size = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size", "I", _f_size_cache)); err = lfpport_get_font(&fontPtr, face, style, size); } if (err == KNI_OK) { rc1 = midp_kjstring_to_pcsl_string(labelJString, &label); rc2 = midp_kjstring_to_pcsl_string(textJString, &text); } KNI_EndHandles(); if (err != KNI_OK || PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) { err = KNI_ENOMEM; goto cleanup; } itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_STRING_ITEM_TYPE+appearanceMode); if (itemPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } err = lfpport_stringitem_create(itemPtr, ownerPtr, &label, layout, &text, fontPtr, appearanceMode); cleanup: pcsl_string_free(&text); pcsl_string_free(&label); if (err != KNI_OK) { MidpDeleteItem(itemPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(itemPtr); }
/** * KNI function that creates native resource for the current StringItem. * <p> * Java declaration: * <pre> * createNativeResource0(ISIII[OII)I * </pre> * * @param ownerId Owner screen's native resource id (MidpDisplayable *) * @param label - label to be used for this ChoiceGroup * @param layout layout directive associated with this ChoiceGroup * @param choiceType - should be EXCLUSIVE, MULTIPLE, IMPLICIT, POPUP * @param fitPolicy - to be used to display created ChoiceGroup * @param cgElements - elements array with string, image, font, selected state * information per element * @param numChoices - number of elements in the ChoiceGroup * @param selectedIndex - currently selected index (for EXCLUSIVE, IMPLICIT, and * POPUP) * @return native resource id (MidpItem *) of this StringItem */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_ChoiceGroupLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr = NULL; MidpItem *cgPtr = NULL; pcsl_string label_str; MidpChoiceGroupElement *cgChoices = NULL; int choiceType, layout; int fitPolicy; int numChoices = 0; int selectedIndex; int i = 0; pcsl_string_status perr; ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); layout = KNI_GetParameterAsInt(3); choiceType = KNI_GetParameterAsInt(4); fitPolicy = KNI_GetParameterAsInt(5); numChoices = KNI_GetParameterAsInt(7); selectedIndex = KNI_GetParameterAsInt(8); KNI_StartHandles(8); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(cgElementsJObject); KNI_DeclareHandle(cgElement); KNI_DeclareHandle(strJString); KNI_DeclareHandle(imgJImage); KNI_DeclareHandle(fontJFont); KNI_DeclareHandle(cgElementHandle); KNI_DeclareHandle(fontHandle); KNI_GetParameterAsObject(2, labelJString); KNI_GetParameterAsObject(6, cgElementsJObject); if (numChoices > 0) { jobjectArray cgElementsArray; KNI_FindClass("javax/microedition/lcdui/ChoiceGroup$CGElement", cgElementHandle); KNI_FindClass("javax/microedition/lcdui/Font", fontHandle); cgElementsArray = (jobjectArray)cgElementsJObject; cgChoices = (MidpChoiceGroupElement *) midpMalloc(sizeof(MidpChoiceGroupElement) * numChoices); if (cgChoices == NULL) { err = KNI_ENOMEM; } for (i = 0; err == KNI_OK && i < numChoices; i++) { KNI_GetObjectArrayElement(cgElementsArray, i, cgElement); KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "stringEl", "Ljava/lang/String;", _cgEl_stringEl_cache), strJString); perr = midp_jstring_to_pcsl_string(strJString, &cgChoices[i].string); if (PCSL_STRING_OK != perr) { err = KNI_ENOMEM; } else { KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "imageDataEl", "Ljavax/microedition/lcdui/ImageData;", _cgEl_imageDataEl_cache), imgJImage); if (KNI_IsNullHandle(imgJImage) == KNI_TRUE) { cgChoices[i].image = NULL; } else { cgChoices[i].image = gxp_get_imagedata(imgJImage); } cgChoices[i].selected = KNI_GetBooleanField(cgElement, _CACHE_FIELDID(cgElementHandle, "selected", "Z", _cgEl_selected_cache)); KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "fontEl", "Ljavax/microedition/lcdui/Font;", _cgEl_font_cache), fontJFont); if (KNI_IsNullHandle(fontJFont) == KNI_TRUE) { cgChoices[i].font = NULL; } else { int face, style, size; /* usually only few fonts are set */ face = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face", "I", _f_face_cache)); style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "style", "I", _f_style_cache)); size = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size", "I", _f_size_cache)); if ((err = lfpport_get_font(&(cgChoices[i].font), face, style, size)) != KNI_OK) { err = KNI_ENOMEM; i++; break; } } } } } if (err == KNI_OK) { if(PCSL_STRING_OK != midp_jstring_to_pcsl_string(labelJString, &label_str)) { err = KNI_ENOMEM; } } KNI_EndHandles(); if (err == KNI_OK) { cgPtr = MidpNewItem(ownerPtr, MIDP_EXCLUSIVE_CHOICE_GROUP_TYPE + choiceType - 1); if (cgPtr == NULL) { err = KNI_ENOMEM; } else { err = lfpport_choicegroup_create(cgPtr, ownerPtr, &label_str, layout, choiceType, cgChoices, numChoices, selectedIndex, fitPolicy); } } // do clean up pcsl_string_free(&label_str); for (i--; i >= 0; i--) { pcsl_string_free(&cgChoices[i].string); } midpFree(cgChoices); if (err != KNI_OK) { MidpDeleteItem(cgPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(cgPtr); }
/** * KNI function that create native resource for current DateField. * * The native widget created by this function must take into account * label and body locations, using Item methods. * The implementation must create a native date/time widget that can be * displayed as date only, time only, or date/time modes. * * The displayMode is a two bit mask in which the MSB is the date, and the * LSB (ie. binary 10 is date only, 01 is time only, 11 is both). * * As the datetime parameter coming from java is in milliseconds since the * epoch 00:00 1/1/1970, it is needed to translate this value to the native * date/time representation. (for example, QT uses the same epoch, but in * resolution of seconds rather than milliseconds). * * * Class: javax.microedition.lcdui.DateFieldLFImpl * Java prototype: * private native int createNativeResource0 ( int ownerId , * String label , int layout, long datetime , int displayMode, * String timeZone); * @param datetime in milliseconds since 00:00 1/1/1970 */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_DateFieldLFImpl_createNativeResource0() { MidpDisplayable *ownerPtr; pcsl_string label; pcsl_string timezone; pcsl_string_status rc1, rc2; jint layout; jint displayMode; jlong datetime; long qtime = 0; MidpError err = KNI_OK; MidpItem *dfPtr = NULL; KNI_StartHandles(2); KNI_DeclareHandle(labelHandle); KNI_DeclareHandle(timezoneHandle); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelHandle); layout = KNI_GetParameterAsInt(3); datetime = KNI_GetParameterAsLong(4); /* Long occupies two parameters */ displayMode = KNI_GetParameterAsInt(6); KNI_GetParameterAsObject(7, timezoneHandle); rc1 = midp_jstring_to_pcsl_string(labelHandle, &label); rc2 = midp_jstring_to_pcsl_string(timezoneHandle, &timezone); KNI_EndHandles(); /* NULL and empty strings are acceptable */ if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) { err = KNI_ENOMEM; goto cleanup; } dfPtr = MidpNewItem(ownerPtr, MIDP_DATE_FIELD_TYPE); if (dfPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } qtime = (long)(datetime/1000); /* qt date works in seconds */ err = lfpport_datefield_create(dfPtr, ownerPtr, &label, layout, displayMode, qtime, &timezone); cleanup: pcsl_string_free(&label); pcsl_string_free(&timezone); if (err != KNI_OK) { MidpDeleteItem(dfPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(dfPtr); }