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

📄 defaultlcdui.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * @(#)defaultLCDUI.c	1.176 02/10/22 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */#include <kni.h>#include <stdlib.h>#include <property.h>#include <defaultLCDUI.h>#include <imageDecode.h>#include <nativeGUI.h>#include <midpMalloc.h>#include <storage.h>#include <vibrate.h>#include <images.h>#ifdef INCLUDE_I18N#include "localeMethod.h"#endif/* Forward declarations */static void decodeImage(char *buffer, const int length,			const jobject thisClass, const jobject clazz);/* cached field ids for Graphics class */static jfieldID _g_transx_cache      = NULL;static jfieldID _g_transy_cache      = NULL;static jfieldID _g_linestyle_cache   = NULL;static jfieldID _g_pixel_cache       = NULL;static jfieldID _g_clip_cache        = NULL;static jfieldID _g_destination_cache = NULL;static jfieldID _g_currentFont_cache = NULL;static jfieldID _g_face_cache        = NULL;static jfieldID _g_style_cache       = NULL;static jfieldID _g_size_cache        = NULL;static jfieldID _g_maxwidth_cache    = NULL;static jfieldID _g_maxheight_cache   = NULL;/* cached field ids for Image class */static jfieldID _i_imgData_cache     = NULL;static jfieldID _i_height_cache      = NULL;static jfieldID _i_width_cache       = NULL;/* cached field ids for Command class */static jfieldID _c_longlabel_cache   = NULL;static jfieldID _c_shortlabel_cache  = NULL;static jfieldID _c_id_cache          = NULL;static jfieldID _c_priority_cache    = NULL;static jfieldID _c_commandType_cache = NULL;/* a flag indicating if a vibration is playing */static char vibrationPlaying = 0;#define _CACHE_FIELDID(HANDLE, name, type, cache) \    ((cache)==NULL?((cache)=KNI_GetFieldID((HANDLE), (name), (type))):(cache))#define KNI_TRANSLATE(G, x, y, GHAND)                                    \    (x) += KNI_GetIntField((G), _CACHE_FIELDID((GHAND), "transX", "I", _g_transx_cache)), \    (y) += KNI_GetIntField((G), _CACHE_FIELDID((GHAND), "transY", "I", _g_transy_cache))  \#define KNI_LINESTYLE(G, GHAND)  \    (KNI_GetIntField((G), _CACHE_FIELDID((GHAND), "style", "I", _g_linestyle_cache)))#define KNI_PIXEL(G, GHAND)      \    (KNI_GetIntField((G), _CACHE_FIELDID((GHAND), "pixel", "I", _g_pixel_cache)))#define KNI_CLIP(G, GHAND, ARRAY, CHAND) \    (KNI_GetObjectField((G), \    _CACHE_FIELDID((GHAND), "clip", "[S", _g_clip_cache), (CHAND)), \    KNI_GetRawArrayRegion((CHAND), 0, 8, (jbyte*)(ARRAY)), (ARRAY))#define KNI_IMAGE(G, GHAND, IHAND) \    (KNI_GetObjectField((G), _CACHE_FIELDID((GHAND), "destination", \    "Ljavax/microedition/lcdui/Image;",_g_destination_cache), (IHAND)))#define KNI_IMAGEDST(G, GHAND, IHAND, alt) \    (KNI_GetObjectField((G), _CACHE_FIELDID((GHAND), "destination", \     "Ljavax/microedition/lcdui/Image;",_g_destination_cache), (IHAND)), \     getImageData((IHAND), alt))#define KNI_FONT(G, GHAND, F)          \    KNI_GetObjectField((G), _CACHE_FIELDID((GHAND), "currentFont", \    "Ljavax/microedition/lcdui/Font;", _g_currentFont_cache), (F))#define DECLARE_KNI_FONT_PARAMS(F, FHAND)  \    face  = KNI_GetIntField((F), \            _CACHE_FIELDID((FHAND), "face", "I", _g_face_cache));  \    style = KNI_GetIntField((F), \            _CACHE_FIELDID((FHAND), "style", "I", _g_style_cache)); \    size  = KNI_GetIntField((F), \            _CACHE_FIELDID((FHAND), "size", "I", _g_size_cache))/* * Used with adjustToViewableRegion */#define NO_IMAGE       0#define COMPLETE_IMAGE 1#define PARTIAL_IMAGE  2/* For Image.createIcon the default icon to return if a resource file * is not found. */static const unsigned char defaultIcon[] = {            0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,            0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,            0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b,            0x02, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0xf4,            0x8b, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c, 0x54,            0x45, 0xff, 0xff, 0xff, 0xbb, 0xbb, 0xbb, 0xc7,            0x4b, 0xdf, 0xf8, 0x00, 0x00, 0x00, 0x1e, 0x49,            0x44, 0x41, 0x54, 0x78, 0xda, 0x63, 0x60, 0x60,            0x60, 0x60, 0x0c, 0x65, 0xf8, 0xcd, 0xe0, 0xc0,            0x20, 0xc0, 0xc4, 0xc0, 0xc0, 0x80, 0x0b, 0x33,            0x86, 0x32, 0xfc, 0x06, 0x00, 0x3f, 0x74, 0x03,            0x01, 0x35, 0x94, 0x27, 0xe6, 0x00, 0x00, 0x00,            0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,            0x82 };static voiddestroyImageData(jobject image) {    void *imagePtr;    KNI_StartHandles(1);    KNI_DeclareHandle(clazz);    KNI_GetObjectClass(image, clazz);    imagePtr =       (void*)KNI_GetIntField(image, _CACHE_FIELDID(clazz, "imgData", "I", _i_imgData_cache));    KNI_EndHandles();    if(imagePtr != NULL) {        LCDUIdestroyNativeImage(imagePtr);    }}/*========================================================================= * FUNCTION:      getImageData * OVERVIEW:      retrieves a pointer to the raw image data * INTERFACE: *   parameters:  INSTANCE img: the Image object to get the data from *                void* alt: default image data if img is null *   returns:     a pointer into the raw data associated with the image's *                BYTEARRAY * * COMMENTS:      One should be very careful with this function. We are *                returning a pointer to the inside of an object. If the *                GC moves the object, this pointer will be invalid. *                Great care must be taken to not allow a GC to happen *                after calling this function. *=======================================================================*/static void *getImageData(jobject img, void *alt) {    if (KNI_IsNullHandle(img) == KNI_TRUE) {        return alt;    } else {	int    result;	KNI_StartHandles(1);	KNI_DeclareHandle(clazz);	KNI_GetObjectClass(img, clazz);        result =           KNI_GetIntField(img, _CACHE_FIELDID(clazz, "imgData", "I", _i_imgData_cache));		KNI_EndHandles();	return (void*)result;    }}static intcompare(const commandStruct  *a, const commandStruct *b, const char table[]) {    if (a->type == b->type) {        return a->priority - b->priority;    } else {        int aPos =            ((a->type < 1) || (a->type > 8)) ? 127 : table[a->type];        int bPos =            ((b->type < 1) || (b->type > 8)) ? 127 : table[b->type];        return aPos - bPos;    }}static intcompareForButton(const void *first, const void *second) {    /*     * According to latest HI specification, the precedence     * and mapping for 2 buttons are     *     *    left button             right button     *  -------------------+--------------------     *       BACK                     ITEM     *       EXIT                    SCREEN     *      CANCEL                     OK     *       STOP                     HELP     *      <none>                    BACK     *                                EXIT     *                               CANCEL     *                                STOP     *     * To get the right effect, we need to (arbitrarily) place     * the items with one button above another.  Because the     * system menu goes on the right button, we      * put left button items higher, which gives us the ordering     *     *    5 BACK     *    6 EXIT     *    7 CANCEL     *    8 STOP     *    127 ITEM   (invalid for the left button)     *    127 SCREEN (          ""               )     *    127 OK     (          ""               )     *    127 HELP   (          ""               )     *     *     * as reproduced in the (inverted) sorting-order table below.     *     * The left soft button is labeled with the highest priority     * negative command (e.g. BACK, EXIT, CANCEL, or STOP).  In the case     * that none of these commands is present in the command list the left     * soft button label is blank and the button is incactive.     *     * June 25 2001     */    static char table[10] = {        127,    /* invalid */        127,    /* SCREEN */        5,      /* BACK */        7,      /* CANCEL */        127,    /* OK */        127,    /* HELP */        8,      /* STOP */        6,      /* EXIT */        127,    /* ITEM */    };    return compare((commandStruct *)first, (commandStruct *)second, table);}static intcompareForMenu(const void *first, const void *second) {    /*     * When there are more than 2 commands, or 2 commands which     * are not negative (BACK, EXIT, CANCEL, STOP), the Left button      * should be choosen according to the rules mentioned above while     * the commands that are left should be sorted in the menu     * according to the following order:     *     *    1 ITEM           *    2 SCREEN     *    3 OK     *    4 HELP     *    5 BACK     *    6 EXIT     *    7 CANCEL     *    8 STOP     */    static char table[10] = {        127,    /* invalid */        2,      /* SCREEN */        5,      /* BACK */        7,      /* CANCEL */        3,      /* OK */        4,      /* HELP */        8,      /* STOP */        6,      /* EXIT */        1,      /* ITEM */    };    return compare((commandStruct *)first, (commandStruct *)second, table);}/*========================================================================= * FUNCTION:      getSortedCommands * OVERVIEW:      Sort the given commands based upon a set of HI rules. * INTERFACE: *   parameters:  ARRAY inItemCmds: the Item Commands to sort *                int numItemCommands: the number of Item Commands to sort *                ARRAY inCmds: the rest of the commands to sort *                int numCommands: the number of the rest of the commands  *                                 to sort *   returns:     a sorted list of commands. NULL if we are unable to  *                allocate enough memory for the structure. *=======================================================================*/static commandStruct *getSortedCommands(jobject inItemCmds, int numItemCommands,		  jobject inCmds, int numCommands) {    /* for some reason, we need to allocate an extra command in order    */    /* to avoid a memory smash.  I've looked but haven't found the cause.*/    int nc = numItemCommands + numCommands;    commandStruct *c = (commandStruct*)midpCalloc(nc + 1, 					          sizeof(commandStruct));    jobjectArray  itemCmds = (jobjectArray)inItemCmds;    jobjectArray  cmds = (jobjectArray)inCmds;    int              j;    int highestCmdIndx = -1;    int        chrsLen;    char       undoAllocs = 0;    if (c == NULL) {        return NULL;    }    KNI_StartHandles(4);    KNI_DeclareHandle(i);    KNI_DeclareHandle(str);    KNI_DeclareHandle(longstring);    KNI_DeclareHandle(clazz);    KNI_FindClass("javax/microedition/lcdui/Command", clazz);    /*     * WARNING: 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.     */    for (j = 0; j < nc; ++j) {	/* First fill c array with Item commands from itemCmds (inItemCmds)	 * then fill it with screen commands from cmds (inCmds)	 * Later all these commands will be sorted together	 */	if (j < numItemCommands) {	    KNI_GetObjectArrayElement(itemCmds, j, i);	} else {	    KNI_GetObjectArrayElement(cmds, j - numItemCommands, i);	}	KNI_GetObjectField(i, _CACHE_FIELDID(clazz, "shortLabel", 					     "Ljava/lang/String;", _c_shortlabel_cache), str);	chrsLen = KNI_GetStringLength(str);        c[j].id       = KNI_GetIntField(i,             _CACHE_FIELDID(clazz, "id", "I", _c_id_cache));        c[j].priority = KNI_GetIntField(i,             _CACHE_FIELDID(clazz, "priority", "I", _c_priority_cache));        c[j].type     = KNI_GetIntField(i,             _CACHE_FIELDID(clazz, "commandType", "I", _c_commandType_cache));        c[j].numChars = (chrsLen > MAX_MENU_COMMAND_LENGTH)                       ? MAX_MENU_COMMAND_LENGTH                       : chrsLen;        c[j].chars    = (unicode*) midpCalloc(c[j].numChars, sizeof(unicode));        if (c[j].chars == NULL) {            undoAllocs = 1;

⌨️ 快捷键说明

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