⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultlcdui.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*========================================================================= * FUNCTION:      getPopupSelection()I * CLASS:         javax.microedition.lcdui.ChoiceGroup * TYPE:          virtual native function * OVERVIEW:      Return the selected choice from a popup choice group * INTERFACE  *   parameters:  <none> *   returns:     index of the selected popup element, or -1 if popup *                choice group was canceled *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_javax_microedition_lcdui_ChoiceGroup_getPopupSelection(){    int rv = LCDUIgetCurrentPopupSelection();    KNI_ReturnInt(rv);}/*========================================================================= * FUNCTION:      initSystemLabels([java.lang.String])V * CLASS:         com.sun.midp.main.Main * TYPE:          virtual native function * OVERVIEW:      Pass localized strings to native system menu and  *                popup choice group for use * INTERFACE  *   parameters:  labels[] array of localized strings in this order: *                [1234567890, Menu, Back, Cancel] *   returns:     <none> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_Main_initSystemLabels() {    int i;    int slen;    unicode *ustr;        KNI_StartHandles(2);        KNI_DeclareHandle(labels);    KNI_DeclareHandle(label);        KNI_GetParameterAsObject(1, labels);    /*      * Currently there are 4 translated labels:      * '1234567890', 'Menu', 'Back', & 'Cancel'     */    for (i = 0; i < 4; i++) {	KNI_GetObjectArrayElement(labels, i, label);	slen = KNI_GetStringLength(label);	slen = (slen > 12) ? 12 : slen; /* 12 = maximum label length */	ustr = (unicode*) midpCalloc(slen, sizeof(unicode));	if (ustr != NULL) {	    KNI_GetStringRegion(label, 0, slen, ustr);            switch(i) {            case 0: /* "digits" */                _digitslen_ = slen;                if (_digits_ != NULL) {                    midpFree(_digits_);                }                _digits_ = ustr;                break;            case 1: /* Menu */                _menulen_ = slen;                if (_menu_ != NULL) {                    midpFree(_menu_);                }                _menu_ = ustr;                break;            case 2: /* Back */                _backlen_ = slen;                if (_back_ != NULL) {                    midpFree(_back_);                }                _back_ = ustr;                break;            case 3: /* Cancel */                _cancellen_ = slen;                if (_cancel_ != NULL) {                    midpFree(_cancel_);                }                _cancel_ = ustr;                break;            }	}    }    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      updateCommandSet([Ljavax/microedition/lcdui/Command;I *                                 [Ljavax/microedition/lcdui/Command;I)V * CLASS:         com.sun.midp.lcdui.DefaultEventHandler * TYPE:          virtual native function * OVERVIEW:      Set the current set of active Abstract Commands. * INTERFACE (operand stack manipulation): *   parameters:  itemCommands    The list of Item Commands that  *                                should be active *                numItemCommands The number of commands in the list  *                                of Item Commands *                commands        The list of Commands that should be active *                numCommands     The number of commands in the list of  *                                Commands *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_lcdui_DefaultEventHandler_updateCommandSet() {    int numItemCmds = KNI_GetParameterAsInt(2);    int numCmds     = KNI_GetParameterAsInt(4);    KNI_StartHandles(2);    KNI_DeclareHandle(itemCmds);    KNI_DeclareHandle(cmds);    KNI_GetParameterAsObject(1, itemCmds);    KNI_GetParameterAsObject(3, cmds);    if (numItemCmds == 0 && numCmds == 0) {        LCDUIupdateCommandSet(NULL, 0);    } else {        commandStruct *menuList = getSortedCommands(itemCmds, numItemCmds,						    cmds, numCmds);        if (menuList != NULL ) {            LCDUIupdateCommandSet(menuList, numItemCmds + numCmds);        } else {            LCDUIupdateCommandSet(NULL, 0);            KNI_ThrowNew("java/lang/OutOfMemoryError", "");        }    }    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      menuKeyEvent(II)Z * CLASS:         com.sun.midp.lcdui.DefaultEventHandler * TYPE:          virtual native function * OVERVIEW:      Handle the key event when the menu is the current *                 display. * INTERFACE (operand stack manipulation): *   parameters:  type   One of PRESSED, RELEASED, or REPEATED *                code   The key code of the key event *   returns:     true if the event is the current display is the *                 menu screen. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_BOOLEANJava_com_sun_midp_lcdui_DefaultEventHandler_menuKeyEvent() {    int code = KNI_GetParameterAsInt(2);    int type = KNI_GetParameterAsInt(1);    enum KVMEventTypes etype = stopKVMEvent;    switch (type) {    case 1: etype = keyDownKVMEvent;   break;    case 2: etype = keyUpKVMEvent;     break;    case 3: etype = keyRepeatKVMEvent; break;    }    KNI_ReturnBoolean(LCDUIhandleMenuEvent(etype, code, 0));}/*========================================================================= * FUNCTION:      menuPointerEvent(III)Z * CLASS:         com.sun.midp.lcdui.DefaultEventHandler * TYPE:          virtual native function * OVERVIEW:      Handle the pointer event when the menu is the current *                 display. * INTERFACE (operand stack manipulation): *   parameters:  type   one of PRESSED, RELEASE, or DRAGGED *                x      the x co-ordinate of the pointer event *                y      the y co-ordinate of the pointer event *   returns:     true if the event is the current display is the menu *                 screen. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_BOOLEANJava_com_sun_midp_lcdui_DefaultEventHandler_menuPointerEvent() {    int    y = KNI_GetParameterAsInt(3);    int    x = KNI_GetParameterAsInt(2);    int type = KNI_GetParameterAsInt(1);    enum KVMEventTypes etype = stopKVMEvent;    switch (type) {    case 1: etype = penDownKVMEvent; break;    case 2: etype = penUpKVMEvent;   break;    case 3: etype = penMoveKVMEvent; break;    }    KNI_ReturnBoolean(LCDUIhandleMenuEvent(etype, x, y));}/*========================================================================= * FUNCTION:      paintMenu()V * CLASS:         com.sun.midp.lcdui.DefaultEventHandler * TYPE:          virtual native function * OVERVIEW:      Native method to draw the command menu on the screen * INTERFACE (operand stack manipulation): *   parameters:  <none> *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_lcdui_DefaultEventHandler_paintMenu() {    LCDUIpaintMenu();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      dismissMenu()V * CLASS:         com.sun.midp.lcdui.DefaultEventHandler * TYPE:          virtual native function * OVERVIEW:      Dismiss the current menu in the case of setCurrent() *                 being called while the Display is suspended by a *                 system screen. * INTERFACE (operand stack manipulation): *   parameters:  <none> *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_lcdui_DefaultEventHandler_dismissMenu() {    LCDUIdismissMenu();    LCDUIdismissPopupMenu();    KNI_ReturnVoid();}static int checkAnchor(int anchor, int illegal_vpos) {    int OK;    if (anchor == 0) return KNI_TRUE; /* special case: 0 is ok */    OK =   (anchor > 0) && (anchor < (BASELINE << 1))        && ((anchor & illegal_vpos) == 0);    if (OK) {        int n = anchor & (TOP | BOTTOM | BASELINE | VCENTER);        OK = (n != 0) && ((n & (n-1)) == 0); /* exactly one bit set */    }    if (OK) {        int n = anchor & (LEFT | RIGHT | HCENTER);        OK = (n != 0) && ((n & (n-1)) == 0); /* exactly one bit set */    }    return OK;}/*========================================================================= * FUNCTION:      drawLine(IIII)V * CLASS:         javax.microedition.lcdui.Graphics * TYPE:          virtual native function * OVERVIEW:      Draws a line between the coordinates (x1,y1) and *                (x2,y2) using the current color and stroke style. * INTERFACE (operand stack manipulation): *   parameters:  x1   the x coordinate of the start of the line *                y1   the y coordinate of the start of the line *                x2   the x coordinate of the end of the line *                y2   the y coordinate of the end of the line *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_Graphics_drawLine() {    int y2 = KNI_GetParameterAsInt(4);    int x2 = KNI_GetParameterAsInt(3);    int y1 = KNI_GetParameterAsInt(2);    int x1 = KNI_GetParameterAsInt(1);    jshort myClip[4]; /* Defined in Graphics.java as 4 shorts */    KNI_StartHandles(4);    KNI_DeclareHandle(thisClass);    KNI_DeclareHandle(gHandle);    KNI_DeclareHandle(cHandle);    KNI_DeclareHandle(iHandle);    KNI_GetParameterAsObject(0, thisClass);    KNI_GetObjectClass(thisClass, gHandle);    KNI_TRANSLATE(thisClass, x1, y1, gHandle);    KNI_TRANSLATE(thisClass, x2, y2, gHandle);    LCDUIdrawLine(KNI_PIXEL(thisClass, gHandle), 		  KNI_CLIP(thisClass, gHandle, myClip, cHandle), 		  KNI_IMAGEDST(thisClass, gHandle, iHandle, NULL), 		  KNI_LINESTYLE(thisClass, gHandle), 		  x1, y1, x2, y2);    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      drawRect(IIII)V * CLASS:         javax.microedition.lcdui.Graphics * TYPE:          virtual native function * OVERVIEW:      Draws the outline of the specified rectangle using *                 the current color and stroke style. * INTERFACE (operand stack manipulation): *   parameters:  x       the x coordinate of the rectangle to be drawn *                y       the y coordinate of the rectangle to be drawn *                width   the width of the rectangle to be drawn *                height  the height of the rectangle to be drawn *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_Graphics_drawRect() {    int h = KNI_GetParameterAsInt(4);    int w = KNI_GetParameterAsInt(3);    int y = KNI_GetParameterAsInt(2);    int x = KNI_GetParameterAsInt(1);    jshort myClip[4]; /* Defined in Graphics.java as 4 shorts */    KNI_StartHandles(4);    KNI_DeclareHandle(thisClass);    KNI_DeclareHandle(gHandle);    KNI_DeclareHandle(cHandle);    KNI_DeclareHandle(iHandle);    KNI_GetParameterAsObject(0, thisClass);    KNI_GetObjectClass(thisClass, gHandle);    KNI_TRANSLATE(thisClass, x, y, gHandle);    LCDUIdrawRect(KNI_PIXEL(thisClass, gHandle),		  KNI_CLIP(thisClass, gHandle, myClip, cHandle),		  KNI_IMAGEDST(thisClass, gHandle, iHandle, NULL), 		  KNI_LINESTYLE(thisClass, gHandle),		  x, y, w, h);    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      fillRect(IIII)V * CLASS:         javax.microedition.lcdui.Graphics * TYPE:          virtual native function * OVERVIEW:      Fills the specified rectangle with the current color. * INTERFACE (operand stack manipulation): *   parameters:  x       the x coordinate of the rectangle to be filled *                y       the y coordinate of the rectangle to be filled *                width   the width of the rectangle to be filled *                height  the height of the rectangle to be filled *   returns:     <nothing> *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_Graphics_fillRect() {    int h = KNI_GetParameterAsInt(4);    int w = KNI_GetParameterAsInt(3);    int y = KNI_GetParameterAsInt(2);    int x = KNI_GetParameterAsInt(1);    jshort myClip[4]; /* Defined in Graphics.java as 4 shorts */    KNI_StartHandles(4);    KNI_DeclareHandle(thisClass);    KNI_DeclareHandle(gHandle);    KNI_DeclareHandle(cHandle);    KNI_DeclareHandle(iHandle);    KNI_GetParameterAsObject(0, thisClass);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -