📄 defaultlcdui.c
字号:
break; /* Get out of allocation for() loop */ } KNI_GetStringRegion(str, 0, c[j].numChars, c[j].chars); /* get long label */ KNI_GetObjectField(i, _CACHE_FIELDID(clazz, "longLabel", "Ljava/lang/String;", _c_longlabel_cache), longstring); chrsLen = KNI_GetStringLength(longstring); if ((chrsLen = KNI_GetStringLength(longstring)) == -1) { /* long label is null */ c[j].useLongChars = 0; } else { /* long label is not null */ c[j].useLongChars = 1; c[j].numLongChars = (chrsLen > MAX_MENU_COMMAND_LENGTH) ? MAX_MENU_COMMAND_LENGTH : chrsLen; c[j].longChars = (unicode*) midpCalloc(c[j].numLongChars, sizeof(unicode)); if (c[j].longChars == NULL) { undoAllocs = 1; break; } KNI_GetStringRegion(longstring, 0, c[j].numLongChars, c[j].longChars); } if ((nc > 1) && ((highestCmdIndx == -1) || (compareForButton(c+highestCmdIndx, c+j) > 0))) { highestCmdIndx = j; } } /* end for (j=0; j<nc; ++j); */ if (undoAllocs) { /* Whoops! We need to undo all previous allocs */ int i; for (i = 0; i < j; ++i) { midpFree(c[i].chars); if (c[i].useLongChars != 0) { midpFree(c[i].longChars); } } midpFree(c); c = NULL; } if ((c != NULL) && (nc > 1)) { /* swap highest command index to spot zero in commands array! */ if (highestCmdIndx != 0) { commandStruct tmp = c[0]; c[0] = c[highestCmdIndx]; c[highestCmdIndx] = tmp; } if (numCommands > 2) { qsort(c+1, nc-1, sizeof(commandStruct), compareForMenu); } } KNI_EndHandles(); return c;}void clearVibrationFlag() { vibrationPlaying = 0;}/*========================================================================= * FUNCTION: getPopupElements * OVERVIEW: import popup choice-group elements into native data * structures * INTERFACE: * parameters: ARRAY stringElements: string component of elements * ARRAY imageElements: image component of element * int numElements: number of elements * * returns: a list of popup elements, or NULL if we are unable to * allocate enough memory for the structure. *=======================================================================*/static popupElementStruct *getPopupElements(jobject stringElements, jobject imageElements, int numElements) { /* for some reason, we need to allocate an extra element in order */ /* to avoid a memory smash. */ int i; char undoAllocs = 0; int slen; jobjectArray imageArr = (jobjectArray)imageElements; popupElementStruct *popupList = (popupElementStruct*)midpCalloc(numElements + 1, sizeof(popupElementStruct)); if (popupList == NULL) { return NULL; } KNI_StartHandles(3); KNI_DeclareHandle(str); /* current string object */ KNI_DeclareHandle(img); /* current image object */ KNI_DeclareHandle(clazz); /* * Note: We need to copy the string data (not just keep a * pointer to it) becuase if the garbage collector is allowed * to move the contents of the heap, the pointers will become * invalid. Also, the first numElements of * <code>stringElements</code> are non-null (checked by caller) */ for (i = 0; i < numElements; ++i) { KNI_GetObjectArrayElement(stringElements, i, str); slen = KNI_GetStringLength(str); /*FIX...insted of 40 define a max string len!*/ popupList[i].idx = i; popupList[i].numChars = (slen > 40) ? 40 : slen; popupList[i].chars = (unicode*) midpCalloc(popupList[i].numChars, sizeof(unicode)); popupList[i].useImage = 0; if (popupList[i].chars == NULL) { undoAllocs = 1; break; /* Get out of allocation for() loop */ } KNI_GetStringRegion(str, 0, popupList[i].numChars, popupList[i].chars); /* if there's an image present for this element, we need to * save it as well...*/ if (!KNI_IsNullHandle(imageArr)) { KNI_GetObjectArrayElement(imageElements, i, img); if (!KNI_IsNullHandle(img)) { popupList[i].useImage = 1; KNI_GetObjectClass(img, clazz); popupList[i].image = (void*) KNI_GetIntField(img, _CACHE_FIELDID(clazz, "imgData", "I", _i_imgData_cache)); popupList[i].imageHeight = KNI_GetIntField(img, _CACHE_FIELDID(clazz, "height", "I", _i_height_cache)); popupList[i].imageWidth = KNI_GetIntField(img, _CACHE_FIELDID(clazz, "width", "I", _i_width_cache)); if (popupList[i].image == (void*)-1){ popupList[i].useImage = 0; } } } } /* end for (i=0; i<numElements; ++i); */ if (undoAllocs) { /* Whoops! We need to undo all previous allocs */ int j; for (j = 0; j < i; ++j) { midpFree(popupList[j].chars); } midpFree(popupList); popupList = NULL; } KNI_EndHandles(); return popupList;}/*========================================================================= * FUNCTION: nVibrate(I)I * CLASS: javax.microedition.lcdui.Display * TYPE: native function to play vibraton * OVERVIEW: launch a native thread and push the audio data to the * devices * INTERFACE (operand stack manipulation): * parameters: keyCode A system-specific keyCode * returns: The abstract game action associated with the keyCode *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_javax_microedition_lcdui_Display_nVibrate() { int dur = KNI_GetParameterAsInt(1); if (vibrationPlaying == 1) { stopVibrate(); } if (dur == 0) { vibrationPlaying = 0; KNI_ReturnInt (1); } else { vibrationPlaying = 1; KNI_ReturnInt(startVibrate(dur<<3)); } }/*========================================================================= * FUNCTION: incomingCall()V * CLASS: com.sun.midp.lcdui.DefaultEventHandler * TYPE: virtual native function * OVERVIEW: Native method to draw a dialog on the screen indicating * there is an incoming phone call and ask the user to * answer * INTERFACE (operand stack manipulation): * parameters: <none> * returns: <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_lcdui_DefaultEventHandler_incomingCall() { LCDUIincomingCall(); KNI_ReturnVoid();}/*========================================================================= * FUNCTION: getKeyCode(I)I * CLASS: com.sun.midp.lcdui.DefaultEventHandler * TYPE: virtual native function * OVERVIEW: Get the system-specific key code corresponding to * the given gameAction. * INTERFACE (operand stack manipulation): * parameters: gameAction A game action * returns: The keyCode associated with that action *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_lcdui_DefaultEventHandler_getKeyCode() { int gameAction = KNI_GetParameterAsInt(1); KNI_ReturnInt(LCDUIgetKeyCode(gameAction));}/*========================================================================= * FUNCTION: getSystemKey(I)I * CLASS: com.sun.midp.lcdui.DefaultEventHandler * TYPE: virtual native function * OVERVIEW: Get the abstract system key that corresponds to keyCode. * INTERFACE (operand stack manipulation): * parameters: keyCode A system-specific keyCode * returns: The SYSTEM_KEY_ constant for this keyCode, or 0 if none *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_lcdui_DefaultEventHandler_getSystemKey() { int gameAction = KNI_GetParameterAsInt(1); KNI_ReturnInt(LCDUIgetSystemKey(gameAction));}/*========================================================================= * FUNCTION: getGameAction(I)I * CLASS: com.sun.midp.lcdui.DefaultEventHandler * TYPE: virtual native function * OVERVIEW: Get the abstract gameAction corresponding to the * given keyCode * INTERFACE (operand stack manipulation): * parameters: keyCode A system-specific keyCode * returns: The abstract game action associated with the keyCode *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_lcdui_DefaultEventHandler_getGameAction() { int keyCode = KNI_GetParameterAsInt(1); KNI_ReturnInt(LCDUIgetGameAction(keyCode));}/*========================================================================= * FUNCTION: getKeyName(I)Ljava/lang/String; * CLASS: com.sun.midp.lcdui.DefaultEventHandler * TYPE: virtual native function * OVERVIEW: Get the informative key string corresponding to * the given keyCode. * INTERFACE (operand stack manipulation): * parameters: keyCode A system-specific keyCode * returns: A string name for the key, or null if no name is * available *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_OBJECTJava_com_sun_midp_lcdui_DefaultEventHandler_getKeyName() { int keyCode = KNI_GetParameterAsInt(1); char *keyName = LCDUIgetKeyName(keyCode); KNI_StartHandles(1); KNI_DeclareHandle(str); if (keyName != NULL) { KNI_NewStringUTF(keyName, str); } else { KNI_ReleaseHandle(str); /* Set 'str' to null String object */ } KNI_EndHandlesAndReturnObject(str);}/*========================================================================= * FUNCTION: updatePopupElements([Ljavax/microedition/lcdui/String; * [Ljavax/microedition/lcdui/Image;I)V * CLASS: com.sun.midp.lcdui.ChoiceGroup * TYPE: virtual native function * OVERVIEW: Set the current set of popup choice group elements * INTERFACE (operand stack manipulation): * parameters: stringElems The list of string elements * imageElems The list of image elements * numElems The number of elements in the popup list * selectedElem The currently selected popup index * xPos The x position of the ideal upper right * corner for the popup window * yPos The y position of the ideal upper right * corner for the popup window * vWidth The width of the viewport * vHeight The height of the viewport * maxWidth The widest choice element in the group * tickerflag true if there is a ticker on screen * titleflag true if there is a title on screen * returns: <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_ChoiceGroup_updatePopupElements() { int numElements = KNI_GetParameterAsInt(3); int selectedIdx = KNI_GetParameterAsInt(4); int xPos = KNI_GetParameterAsInt(5); int yPos = KNI_GetParameterAsInt(6); int vWidth = KNI_GetParameterAsInt(7); int vHeight = KNI_GetParameterAsInt(8); int maxWidth = KNI_GetParameterAsInt(9); jboolean tickerFlag = KNI_GetParameterAsBoolean(10); jboolean titleFlag = KNI_GetParameterAsBoolean(11); KNI_StartHandles(2); KNI_DeclareHandle(stringElems); KNI_DeclareHandle(imageElems); KNI_GetParameterAsObject(1, stringElems); KNI_GetParameterAsObject(2, imageElems); if (numElements == 0) { LCDUIupdatePopupElements(NULL, 0, 0, 0, 0, 0, 0, 0, KNI_FALSE, KNI_FALSE); } else { popupElementStruct *elementList = getPopupElements(stringElems, imageElems, numElements); if (elementList != NULL) { LCDUIinitPopupMenu(); LCDUIupdatePopupElements(elementList, numElements, selectedIdx, xPos, yPos, vWidth, vHeight, maxWidth, tickerFlag, titleFlag); } else { LCDUIupdatePopupElements(NULL, 0, 0, 0, 0, 0, 0, 0, KNI_FALSE, KNI_FALSE); KNI_ThrowNew("java/lang/OutOfMemoryError", ""); } } KNI_EndHandles(); KNI_ReturnVoid();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -