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

📄 menus.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * @(#)menus.c	1.61 02/09/24 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */#include <kni.h>#include <defaultLCDUI.h>#include <malloc.h>#include <nativeGUI.h>#include <midpMalloc.h>#define BUTTON_NOT_SET        -3#define BUTTON_DISMISSES_MENU -2#define BUTTON_INVOKES_MENU   -1static int buttonCommands[2];static commandStruct *menuList = NULL;/* * Number of commands that  * are displayed outside the menu screen. * In fullscreen mode, this is 0 as all commands * must be displayed on the menu only. */static int inFullScreenMode = KNI_FALSE;static int offMenuCommands = 0;   /* 0 if no negative commands map to the                                     left soft button, 1 otherwise */static int menuLength;  /* number of commands in the menu */static int inMenu = KNI_FALSE;static int menuCurrent; /* index of currently selected menu item */static int scrollPosition; /* index of top menu item on screen ? */static int scrollY;static int itemHeight;static int itemSpace;static int menuHeight;static int boldHeight;static int plainHeight;/* (menuXOffset, menuYOffset) = the upper left corner of system popup menu */ static int menuXOffset;   static int menuYOffset;static int screenWidth, screenHeight;static int blackPixel, whitePixel;static int lightGrayPixel, darkGrayPixel;/* * labels used by the system menu, set by initSystemLabels() in * defaultLCDUI.c  */unicode *_digits_ = NULL;int _digitslen_ = 0;unicode *_menu_ = NULL;int _menulen_ = 0;unicode *_back_ = NULL;int _backlen_ = 0;/* re-initialize all static variables */voidLCDUIinitMenus(){    int ascent, descent, leading;    menuList = NULL;    inMenu = KNI_FALSE;    scrollPosition = scrollY = menuHeight = 0;        /* get the line height of a plain font */    LCDUIgetFontInfo(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,                     &ascent, &descent, &leading);    plainHeight = ascent + descent + leading;        /* get the line height of a bold font */    LCDUIgetFontInfo(FACE_SYSTEM, STYLE_BOLD, SIZE_MEDIUM,                     &ascent, &descent, &leading);    boldHeight = ascent + descent + leading;        /*     * itemHeight is used for the line spacing for the menu items.     * However, each line could have a number, which is drawn in bold      * font, and the menu text is drawn in plain font. So, the line height      * has to be the tallest font on the line.     */    itemHeight = (plainHeight > boldHeight) ? plainHeight : boldHeight;        /* these are the colors used in the topbar image, so we try to      * match them. */    blackPixel = LCDUIgetPixel(0, 0, KNI_FALSE);    whitePixel = LCDUIgetPixel(0xffffff, 0xff, KNI_FALSE);    lightGrayPixel = LCDUIgetPixel(0xafafaf, 0xaf, KNI_FALSE);    darkGrayPixel = LCDUIgetPixel(0x606060, 0x60, KNI_FALSE);    /* TBD by HI */    menuXOffset = 30;    menuYOffset = 61;        setCommandsFullScreenMode(KNI_FALSE);}static voidfreeMenuList() {    int i;        if (menuList != NULL) {        /* Free all of the menu strings */        for (i = 0; i < menuLength; ++i) {            midpFree(menuList[i].chars);	    if (menuList[i].useLongChars == 1) {                midpFree(menuList[i].longChars);	    }        }        midpFree(menuList);        menuList = NULL;    }}voidLCDUIfinalizeMenus() {    freeMenuList();    if (_digits_ != NULL) {        midpFree(_digits_);    }    if (_menu_ != NULL) {        midpFree(_menu_);    }    if (_back_ != NULL) {        midpFree(_back_);    }    if (_cancel_ != NULL) {        midpFree(_cancel_);    }}/* * This function repaints only the screen area that is changed by key  * up/down. curr is the index of the newly hiligthed menu item, and  * prev is the index of the previusly hiligthed menu item. */voidLCDUIpaintMenuPartial(int first, int second){    commandStruct *menu = menuList + offMenuCommands;    /*int curX = 0, curY1 = 0, curY2 = 0;*/    int curX = menuXOffset, curY1 = menuYOffset, curY2 = menuYOffset;    short clip[4];    int bg, fg;        int availableWidth = 0;    int longCharsWidth = 0;        clip[0] = menuXOffset;    clip[1] = menuYOffset;    clip[2] = screenWidth - menuXOffset;    clip[3] = screenHeight - menuYOffset;        /* paint first */    curX += (3 + 8 + LCDUIcharsWidth(FACE_SYSTEM, STYLE_BOLD, SIZE_MEDIUM,				  _digits_, 1));    curY1 += (boldHeight + 6 + (first - scrollPosition)*itemHeight);        if (first == menuCurrent) {	bg = blackPixel;	fg = whitePixel;    } else {	bg = lightGrayPixel;	fg = blackPixel;    }        LCDUIfillRect(bg, clip, NULL, 0,		  curX, curY1, screenWidth - curX, itemHeight);    curX += 2;    availableWidth = screenWidth - curX;        /* decide between short and long label */    if (menu[first].useLongChars == 1) {        longCharsWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,					 menu[first].longChars, 					 menu[first].numLongChars);    }        if ((menu[first].useLongChars == 1) && 	(longCharsWidth <= availableWidth)) {	LCDUIdrawChars(fg, clip, NULL, 0,		       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,		       curX, curY1, LEFT | TOP,		       menu[first].longChars, menu[first].numLongChars);    } else {        LCDUIdrawChars(fg, clip, NULL, 0,		       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,		       curX, curY1, LEFT | TOP,		       menu[first].chars, menu[first].numChars);    }    curX -= 2;    /* paint second */    curY2 = curY1 + itemHeight;        if (second == menuCurrent) {	bg = blackPixel;	fg = whitePixel;    } else {	bg = lightGrayPixel;	fg = blackPixel;    }        LCDUIfillRect(bg, clip, NULL, 0,		  curX, curY2, screenWidth - curX, itemHeight);    curX += 2;    /* decide between short and long label */    if (menu[second].useLongChars == 1) {        longCharsWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,					 menu[second].longChars, 					 menu[second].numLongChars);    }    if ((menu[second].useLongChars == 1) && 	(longCharsWidth <= availableWidth)) {        LCDUIdrawChars(fg, clip, NULL, 0,		       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,		       curX, curY2, LEFT | TOP,		       menu[second].longChars, menu[second].numLongChars);    } else {        LCDUIdrawChars(fg, clip, NULL, 0,		       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,		       curX, curY2, LEFT | TOP,		       menu[second].chars, menu[second].numChars);    }    curX -= 2;    /*      * LCDUIrefresh expects the upper left and lower right corner of the      * rectangle to refresh.     */    LCDUIrefresh(curX, curY1, screenWidth, curY2 + itemHeight);}voidLCDUIpaintMenu(){    int curX = menuXOffset;    int curY = menuYOffset;    int i;    short clip[4];        int availableWidth = 0;    int longCharsWidth = 0;        commandStruct *menu;    int length;        /* we might lop off the first item, because it's mapped to a button */        menu = menuList + offMenuCommands;    length = menuLength - offMenuCommands;        clip[0] = menuXOffset;    clip[1] = menuYOffset;    clip[2] = screenWidth;    clip[3] = screenHeight;        LCDUIfillRect(lightGrayPixel, clip, NULL, 0, 		  menuXOffset, menuYOffset, screenWidth - menuXOffset, 		  screenHeight - menuYOffset);    /* draw top border of menu */    LCDUIdrawLine(darkGrayPixel, clip, NULL, 0, menuXOffset, menuYOffset, 		  screenWidth, menuYOffset);    LCDUIdrawLine(whitePixel, clip, NULL, 0, menuXOffset, menuYOffset + 1, 		  screenWidth, menuYOffset + 1);        /* draw left side border of menu */    LCDUIdrawLine(darkGrayPixel, clip, NULL, 0, menuXOffset, menuYOffset + 1,		  menuXOffset, screenHeight);    LCDUIdrawLine(whitePixel, clip, NULL, 0, menuXOffset + 1, menuYOffset + 1,		  menuXOffset + 1, screenHeight);    curY += 3; /* top border width + 1 extra pixel */    curX += 3; /* left side border width + 1 extra pixel */    curX += (8 + LCDUIcharsWidth(FACE_SYSTEM, STYLE_BOLD, SIZE_MEDIUM,				  _digits_, 1));    /* draw the menu header, bold & centered */    LCDUIdrawChars(blackPixel, clip, NULL, 0,                   FACE_SYSTEM, STYLE_BOLD, SIZE_MEDIUM,                   menuXOffset + ((screenWidth - menuXOffset) / 2), 		   menuYOffset + 2, HCENTER | TOP, _menu_, _menulen_);        curY += boldHeight;        /* draw the title separator lines */    LCDUIdrawLine(darkGrayPixel, clip, NULL, 0, menuXOffset + 2 , curY - 1, 		  screenWidth, curY - 1);    LCDUIdrawLine(whitePixel, clip, NULL, 0, menuXOffset + 2, curY, 		  screenWidth, curY);    curY += 3; /* for title separator line and 1 extra pixel */        /* draw visible commands */    for (i = scrollPosition; (curY - menuYOffset - boldHeight - 6) < 	     itemSpace && i < length; ++i, curY += itemHeight) {        if (length < 10) {            LCDUIdrawChars(blackPixel, clip, NULL, 0,                           FACE_SYSTEM, STYLE_BOLD, SIZE_MEDIUM,                           menuXOffset + 6, curY, LEFT | TOP, _digits_ + i, 1);        }		/* decide between short and long label */	/* First see if the long label fits, if yes use long label */	/* else use short label */	/* labels are clipped if there isn't sufficient space */		if (menu[i].useLongChars == 1) {	    availableWidth = screenWidth - curX;	    	    longCharsWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, 					     SIZE_MEDIUM, menu[i].longChars, 					     menu[i].numLongChars);	}        if (i == menuCurrent) {            LCDUIfillRect(blackPixel, clip, NULL, 0,                          curX, curY, screenWidth, itemHeight);	    curX += 2;	    if ((menu[i].useLongChars == 1) && (longCharsWidth <= 						availableWidth)) {	        LCDUIdrawChars(whitePixel, clip, NULL, 0,			       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,			       curX, curY, LEFT | TOP,			       menu[i].longChars, menu[i].numLongChars);	    } else {	        LCDUIdrawChars(whitePixel, clip, NULL, 0,			       FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM,			       curX, curY, LEFT | TOP,			       menu[i].chars, menu[i].numChars);	    }	    curX -= 2;        } else {	    curX += 2;	    if ((menu[i].useLongChars == 1) && (longCharsWidth <= 

⌨️ 快捷键说明

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