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

📄 nativegui.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    for (i = 0; i < NUM_FONTS; ++i) {        if (fonts[i] && (fonts[i]->fid == font)) {            return fonts[i];        }    }    return NULL;}void LCDUIrefresh(int x1, int y1, int x2, int y2){    XClearArea(display, paintWindow, x1, y1, x2-x1, y2-y1, 0);    XFlush(display);}void LCDUIgetDisplayParams(int *width, int *height, int *adornedHeight,                           int *eraseColor, int *depth, int *flags, int *alphaLevels){    *width  = PAINT_WIDTH;    *height = DISPLAY_HEIGHT - topbar_height;    *adornedHeight = DISPLAY_HEIGHT - (topbar_height + BOTTOM_BAR_HEIGHT);    *eraseColor = 0x00ffffff;    *depth  = (numColors == 16) ? 4 : (numColors == 256) ? 8 : numColors / 2;    *flags  = ((numColors >= 256 ) ? SUPPORTS_COLOR : 0)         | SUPPORTS_POINTER         | SUPPORTS_MOTION         | (doubleBuffer ? SUPPORTS_DOUBLEBUFFER : 0);    *alphaLevels = numColors;}void LCDUIsetSoftButton(int index, const unicode *label, int numChars){    /* X_OFFSET is the offset from the left of the drawbale*/    #define X_OFFSET 0    int x = X_OFFSET, y = topBarHeight + paintHeight;    int width, ascent, descent;    XTextItem16 *items, itemBuf[4];    XChar2b charBuf[80];    int numItems;    XRectangle r;    /* Check to see that we are being called in full screen mode.       In such a case we should return without doing anything.       Ideally we shouldn't be being called at all. However,       there is at least one place in the code (in menus.c)       where we are called from within a code block       that is executed if we are in fullscreen mode.     */    if (KNI_TRUE == inFullScreenMode) {       return;    }    if ((index < 0) || (index > 1)) return;    if (index == 0) {        /* clear rectangle */        XFillRectangle(display, backgroundDrawable, gcErase,                        x, y,                       (PAINT_WIDTH - ARROWS_WIDTH)/2,                       ARROWS_HEIGHT);    } else {        /* clear rectangle */        XFillRectangle(display, backgroundDrawable, gcErase,                       x + (PAINT_WIDTH + ARROWS_WIDTH)/2, y,                       (PAINT_WIDTH - ARROWS_WIDTH)/2,                       ARROWS_HEIGHT);    }    if (label == NULL) {        refreshBottomBar();        return;    }        /* we must convert all of the text in order to get correct width */    /* This makes malloc() unavoidable if the string is long or has  */    /* many changes of font.  We try to avoid it by providing some   */    /* data space and using malloc only when the space isn't enough. */    convertText(FACE_SYSTEM, STYLE_UNDERLINED, SIZE_MEDIUM,                label, numChars, &items, &numItems, itemBuf, 4, charBuf, 80);    getTextBounds(items, numItems, &width, &ascent, &descent);    if (index == 0) {        x = X_OFFSET + 2;       /* left justified */        r.x = x;    } else {        x = X_OFFSET + PAINT_WIDTH - width - 2; /* right justified */        r.x = X_OFFSET + (PAINT_WIDTH + ARROWS_WIDTH) / 2;        if (x < r.x) x = r.x; /* clip away the last chars, not the first */    }    r.y = y;     r.width = (PAINT_WIDTH - ARROWS_WIDTH) / 2 - 1;    r.height = ARROWS_HEIGHT;    XSetClipRectangles(display, gcNormal, 0, 0, &r, 1, YXBanded);    y += ARROWS_HEIGHT - (descent + 1);    XDrawText16(display, backgroundDrawable, gcNormal, x, y, items, numItems);    freeText(items, numItems, itemBuf, charBuf, 80);    XSetClipMask(display, gcNormal, None);    refreshBottomBar();}#define VERT_X   ((PAINT_WIDTH/2) - 3)#define HORIZ_Y  (y_screen + paintHeight + 6)#define LEFT_X   (X_SCREEN + (PAINT_WIDTH/2) - 10)#define RIGHT_X  (X_SCREEN + (PAINT_WIDTH/2) + 3)#define UP_Y     (DISPLAY_HEIGHT - BOTTOM_BAR_HEIGHT + 1)#define DOWN_Y   (DISPLAY_HEIGHT - BOTTOM_BAR_HEIGHT + 11)static XImage         *upArrow, *downArrow;static voidpaintVerticalScroll(    int scrollPosition,    int scrollProportion,    Drawable drawable){    if (KNI_TRUE == inFullScreenMode) {      return;    }    if (upArrow == NULL) {	upArrow    = loadImage(up_bits, arrow_width, arrow_height);	upArrow->bitmap_bit_order = LSBFirst;	downArrow  = loadImage(down_bits,  arrow_width, arrow_height);	downArrow->bitmap_bit_order = LSBFirst;    }    /* If the scrollable is 100% the proportion of the viewport,    */    /* there's no need for any scrolling, clear the arrows and      */    /* return.                                                      */    if (scrollProportion >= 100 || scrollProportion == 0) {	XFillRectangle(display, drawable, gcErase,		       VERT_X, UP_Y, arrow_width, arrow_height);	XFillRectangle(display, drawable, gcErase,		       VERT_X, DOWN_Y, arrow_width, arrow_height);        XFlush(display);        return;    }        /* If we're somewhere between the top and bottom,   */    /* add both scroll arrows                           */    if (scrollPosition > 0 && scrollPosition < 100) {	XPutImage(display, drawable, gcNormal, upArrow,		  0, 0, VERT_X, UP_Y, arrow_width, arrow_height);	XPutImage(display, drawable, gcNormal, downArrow,		  0, 0, VERT_X, DOWN_Y, arrow_width, arrow_height);	/* If we're at the top, add the down arrow, clear the   */	/* up arrow                                             */    } else if (scrollPosition == 0) {	XPutImage(display, drawable, gcNormal, downArrow,		  0, 0, VERT_X, DOWN_Y, arrow_width, arrow_height);	XFillRectangle(display, drawable, gcErase,		       VERT_X, UP_Y, arrow_width, arrow_height);	/* We're at the bottom, add the up arrow, clear the     */	/* down arrow                                           */    } else {	XPutImage(display, drawable, gcNormal, upArrow,		  0, 0, VERT_X, UP_Y, arrow_width, arrow_height);	XFillRectangle(display, drawable, gcErase,		       VERT_X, DOWN_Y, arrow_width, arrow_height);    }        XFlush(display);}static int vScrollPosition, vScrollProportion;intLCDUIsetVerticalScroll(int scrollPosition, int scrollProportion){    int tmp1 = vScrollPosition;    vScrollPosition = scrollPosition;    vScrollProportion = scrollProportion;    paintVerticalScroll(scrollPosition, scrollProportion, backgroundDrawable);    refreshBottomBar();    return tmp1;}jboolean LCDUIplaySound(int soundType){    if (   (soundType == ALERT_WARNING)         || (soundType == ALERT_ERROR)        || (soundType == ALERT_ALARM)   ) {        XBell(display, 0);        XFlush(display);        return KNI_TRUE;    } else {        return KNI_FALSE;    }}/* * Draw the BackLight. * If 'active' is KNI_TRUE, the BackLight is drawn. * If 'active' is KNI_FALSE, the BackLight is erased. */void drawBackLight(jboolean active) {    if (active == KNI_TRUE) {        XPutImage(display, BackLightDrawable, gcNormal, BackLight_on_Image, 0, 0,	      0, 0, Bklite_width, Bklite_height);	refreshBackLightArea();    } else {        XPutImage(display, BackLightDrawable, gcNormal, BackLight_off_Image, 0, 0,	      0, 0, Bklite_width, Bklite_height);	refreshBackLightArea();    }    }/* * Requests a flashing effect for the device's backlight.  */ jboolean LCDUIshowBacklight(jboolean mode){     drawBackLight(mode);     return KNI_TRUE;}voidLCDUIsetInputMode(int mode){#include "inputmodes.xbm"    static XImage *ABCMode, *abcMode, *numMode, *SYMMode;#ifdef INCLUDE_I18N#include "inputmodes_ja.xbm"    static XImage *hiraMode, *kanaMode;#endif    static int x, y;    XImage *icon = NULL;    if (ABCMode == NULL) {	ABCMode = loadImage(ABC_bits, inputmode_width, inputmode_height);	ABCMode->bitmap_bit_order = LSBFirst;	abcMode = loadImage(abc_bits, inputmode_width, inputmode_height);	abcMode->bitmap_bit_order = LSBFirst;	numMode = loadImage(num_bits, inputmode_width, inputmode_height);	numMode->bitmap_bit_order = LSBFirst;	SYMMode = loadImage(SYM_bits, inputmode_width, inputmode_height);	SYMMode->bitmap_bit_order = LSBFirst;#ifdef INCLUDE_I18N	hiraMode = loadImage(hira_bits, inputmode_width, inputmode_height);	hiraMode->bitmap_bit_order = LSBFirst;	kanaMode = loadImage(kana_bits, inputmode_width, inputmode_height);	kanaMode->bitmap_bit_order = LSBFirst;#endif	x = (PAINT_WIDTH - inputmode_width)/2;	y = (topbar_height - inputmode_height) / 2;    }        XFillRectangle(display, backgroundDrawable, gcErase, x, y, 		   inputmode_width, inputmode_height);        switch (mode) {    case 1:	icon = ABCMode;	break;    case 2:	icon = abcMode;	break;    case 3:	icon = numMode;	break;    case 4:	icon = SYMMode;	break;#ifdef INCLUDE_I18N    case 5:	icon = hiraMode;	break;    case 6:	icon = kanaMode;	break;#endif    case 0:    default:        break;    }    if (icon != NULL) {	XPutImage(display, backgroundDrawable, gcNormal, icon,		  0, 0, x, y, inputmode_width, inputmode_height);    }    refreshTopBar();}typedef struct _kte {    unsigned int code;    unsigned int chr;} keytable_entry;static keytable_entry *table;voidInitializeWindowSystem() {    static unsigned char data33[] = {        0xdb, 0x6d, 0xb6,        0x6d, 0xb6, 0xdb,        0xb6, 0xdb, 0x6d    };    static unsigned char data50[] = {        0x55,        0xaa,    };    static unsigned char data66[] = {        0x24, 0x92, 0x49,        0x92, 0x49, 0x24,        0x49, 0x24, 0x92    };    int i;    memset(fonts, 0, sizeof(fonts));    /* Initialize multi-thread mode in X11 */    if (XInitThreads() == 0) {        fprintf(stderr, "WARNING: Unable to initialize X11 threading\n");    }    /* set up the offsets for non-full screen mode*/    setUpOffsets(KNI_FALSE);    inFullScreenMode = KNI_FALSE;    requestedFullScreenMode = KNI_FALSE;    drawTrustedMIDletIcon = KNI_FALSE;    createEmulatorWindow();    LCDUIinitMenus();    LCDUIinitPopupMenu();    LCDUIinitPhoneSim();    stipple33 =         XCreatePixmapFromBitmapData(display, paintDrawable,                                    (char*)data33, 24, 3, 0, 1, 1);    stipple50 =         XCreatePixmapFromBitmapData(display, paintDrawable,                                    (char*)data50, 8, 2, 0, 1, 1);    stipple66 =         XCreatePixmapFromBitmapData(display, paintDrawable,                                    (char*)data66, 24, 3, 0, 1, 1);    /* enough to handle the keypad keys 0..9 */    table = midpCalloc(10, sizeof(keytable_entry));    if (table == NULL) {        fprintf(stderr, "No memory for table\n");        exit(1);    }     for (i = 0; i < 10; ++i) {        KeySym sym = i + XK_KP_0;  /* contiguous */        table[i].chr  = KEY_0 + i; /* contiguous */        table[i].code = XKeysymToKeycode(display, sym);    }}/*  * Finalize the use of the window system by returning all allocated * graphics data structures to the free list. e.g. close, destroy or free * X, Xt and xpm library resources. */voidFinalizeWindowSystem() {    int i;    if (!initialized) {	return;    }    LCDUIfinalizeMenus();    LCDUIfinalizePopupMenu();    if (table) {	midpFree(table);	table = NULL;    }    if(visualInfo) {	XFree(visualInfo);	visualInfo = NULL;    }    if(gc) {	XFreeGC(display,gc);	gc = NULL;    }    if(gcErase) {	XFreeGC(display,gcErase);	gcErase = NULL;    }    if(gcNormal) {	XFreeGC(display,gcNormal);	gcNormal = NULL;    }    if (systemFontInfo){	XFreeFont(display,systemFontInfo);	systemFontInfo = NULL;    }    for (i = 0; i < NUM_FONTS; ++i) {        if (fonts[i]) {            XFreeFont(display, fonts[i]);	    fonts[i] = 0;        }	    }    if (pixmap != None) {	XFreePixmap(display, pixmap);	XpmFreeAttributes(&case_attributes);	pixmap = None;    }    if (display != NULL) {        XrmDestroyDatabase(XrmGetDatabase(display));    }    if (topbar != None) {	XFree(topbar);	topbar = None;    }    if (LED_on_Image != None) {	XFree(LED_on_Image);	LED_on_Image = None;    }    if (LED_off_Image != None) {	XFree(LED_off_Image);	LED_off_Image = None;    }    if (BackLight_off_Image != None) {

⌨️ 快捷键说明

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