📄 nativegui.c
字号:
/* * @(#)nativeGUI.c 1.155 02/10/17 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. *//*========================================================================= * Include files *=======================================================================*/#define STRICT#include <kni.h>#include <defaultLCDUI.h>#include <nativeGUI.h>#include <imageDecode.h>#include <midpMalloc.h>#include <stdio.h>#include <windows.h>#include <ctype.h>#include <math.h>#ifdef INCLUDE_I18N#include <imm.h>#endif#include <configuration.h>#include "staticGraphics.h"#ifndef M_PI#define M_PI 3.14159265358979323846#endif#define MAX_SOFTBUTTON_CHARS 12#define EMULATOR_WIDTH (241 + 8)#define EMULATOR_HEIGHT (635 + 24)#define TOP_BAR_HEIGHT 11 #define BOTTOM_BAR_HEIGHT 19#define MENUBAR_BORDER_HEIGHT 2#define ARROWS_WIDTH 7#define PAINT_WIDTH DISPLAY_WIDTH#define UNTRANSLATED_SCREEN_BITMAP (void*)0xffffffff#define NUMBEROF(x) (sizeof(x)/sizeof(x[0]))#define MIN(a,b) ((a)<(b)?(a):(b))void DrawBitmap(HDC hdc, HBITMAP hBitmap, int x, int y, int rop);static jboolean FilterEvent(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam, KVMEventType *kvmEvent, int *gotEvent, int *retval);static void DrawMenuBarBorder(HDC hdc);static jboolean bkliteImageCreated = KNI_FALSE;void CreateBacklight(HDC hdc);#define INSIDE(_x, _y, _r) \ ((_x >= (_r).x) && (_x < ((_r).x + (_r).width)) && \ (_y >= (_r).y) && (_y < ((_r).y + (_r).height)))typedef struct _Rectangle { int x; int y; int width; int height;} XRectangle;typedef struct { KeyType button; XRectangle bounds; char *name;} Key;static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;/* thread safety */static int tlsId;jboolean doubleBuffer = KNI_TRUE;#ifdef SKINS_MENU_SUPPORTED/* support for changing the device "skin"...this is for user testing only */#define NUM_SKINS_SUPPORTED 16static int numSkins = 0;static char *skins[16];#endif#define REFRESHBOTTOMBAR() \do { \ RECT r; \ r.left = x_offset; \ r.top = y_offset; \ r.right = x_offset + PAINT_WIDTH; \ r.bottom = y_offset + paintHeight + bottomBarHeight; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \} while (0)#define REFRESHTOPBAR() \{ \ RECT r; \ r.left = x_offset; \ r.top = Y_SCREEN_OFFSET; \ r.right = x_offset + PAINT_WIDTH; \ r.bottom = y_offset; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \} /* refresh the Top backlight bar */#define REFRESH_BACKLIGHT_TOPBAR() \{ \ RECT r; \ r.left = BkliteTop_xposition; \ r.top = BkliteTop_yposition; \ r.right = BkliteTop_xposition + BkliteTop_width; \ r.bottom = BkliteTop_yposition + BkliteTop_height; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \}/* refresh the bottom backlight bar */#define REFRESH_BACKLIGHT_BOTTOMBAR() \{ \ RECT r; \ r.left = BkliteBottom_xposition; \ r.top = BkliteBottom_yposition; \ r.right = BkliteBottom_xposition + BkliteBottom_width; \ r.bottom = BkliteBottom_yposition + BkliteBottom_height; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \}/* refresh the left backlight bar */#define REFRESH_BACKLIGHT_LEFTBAR() \{ \ RECT r; \ r.left = BkliteLeft_xposition; \ r.top = BkliteLeft_yposition; \ r.right = BkliteLeft_xposition + BkliteLeft_width; \ r.bottom = BkliteLeft_yposition + BkliteLeft_height; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \}/* refresh the right backlight bar */#define REFRESH_BACKLIGHT_RIGHTBAR() \{ \ RECT r; \ r.left = BkliteRight_xposition; \ r.top = BkliteRight_yposition; \ r.right = BkliteRight_xposition + BkliteRight_width; \ r.bottom = BkliteRight_yposition + BkliteRight_height; \ InvalidateRect(hMainWindow, &r, KNI_TRUE); \}const static Key Keys[] = {#ifdef NO_POWER_BUTTON /* * Add -DNO_POWER_BUTTON to the Makefile if you want to disable * the power button during user testing. */ {KEY_POWER, {-10, -10, 1, 1}, "POWER"},#else {KEY_POWER, {160, 59, 24, 24}, "POWER"},#endif {KEY_SOFT1, {32, 347, 36, 27}, "SOFT1"}, {KEY_SOFT2, {174, 347, 36, 27}, "SOFT2"}, {KEY_UP, {105, 343, 30, 25}, "UP"}, {KEY_DOWN, {105, 399, 30, 25}, "DOWN"}, {KEY_LEFT, {72, 370, 25, 25}, "LEFT"}, {KEY_RIGHT, {148, 370, 25, 25}, "RIGHT"}, {KEY_SELECT, {110, 371, 24, 24}, "SELECT"}, {KEY_SEND, {27, 387, 31, 36}, "SEND"}, {KEY_END, {187, 387, 31, 36}, "END"}, {KEY_CLEAR, {93, 427, 56, 29}, "CLEAR"}, {KEY_1, {36, 462, 39, 31}, "1"}, {KEY_2, {101, 466, 44, 28}, "2"}, {KEY_3, {170, 462, 39, 31}, "3"}, {KEY_4, {40, 499, 39, 31}, "4"}, {KEY_5, {101, 505, 44, 28}, "5"}, {KEY_6, {166, 500, 39, 31}, "6"}, {KEY_7, {46, 539, 39, 31}, "7"}, {KEY_8, {101, 543, 44, 28}, "8"}, {KEY_9, {158, 539, 39, 31}, "9"}, {KEY_ASTERISK, {50, 582, 41, 23}, "*"}, {KEY_0, {101, 580, 44, 28}, "0"}, {KEY_POUND, {153, 582, 41, 23}, "#"},} ;static const Key *lastButton = NULL;int numColors = 4;int backgroundColor = RGB(182, 182, 170);static int foregroundColor = RGB(0,0,0);static HBITMAP hScreenBitmap;static HBITMAP topbar_Image;/* The bits of the BackLight images */static HBITMAP bklite_Top_Image;static HBITMAP bklite_Bottom_Image;static HBITMAP bklite_Left_Image;static HBITMAP bklite_Right_Image;/* The bits of the Network Indicator images */static HBITMAP LED_on_Image;static HBITMAP LED_off_Image;/* The bits of the trusted MIDlet icon image */static HBITMAP TrustIcon_Image;HWND hMainWindow;KVMEventType kvmEvent;int gotEvent;static int x_offset = X_SCREEN_OFFSET;static int y_offset;static int initialized = 0;static jboolean inFullScreenMode;static jboolean requestedFullScreenMode;static jboolean drawTrustedMIDletIcon;int blackPixel;int whitePixel;int lightGrayPixel;int darkGrayPixel;HBRUSH darkGrayBrush;HPEN whitePen;HPEN darkGrayPen;HBRUSH whiteBrush;HBRUSH BACKGROUND_BRUSH, FOREGROUND_BRUSH;HPEN BACKGROUND_PEN, FOREGROUND_PEN;static TEXTMETRIC fixed_tm, tm;static HFONT fonts[3][3][8];static int timerPending = 0;/* these are gamma corrected for a monitor with gamma = 2.5 */static int grayTable4[4] = { RGB(0x00,0x00,0x00), RGB(0x6F,0x7B,0x6F), RGB(0x94,0xA3,0x94), RGB(0xAE,0xC0,0xAE)};/* these are gamma corrected for a monitor with gamma = 2.5 */static int grayTable16[16] = { RGB(0X00,0X00,0X00), RGB(0X3A,0X40,0X3A), RGB(0X4D,0X54,0X4D), RGB(0X5B,0X64,0X5B), RGB(0X66,0X71,0X66), RGB(0X70,0X7B,0X70), RGB(0X78,0X85,0X78), RGB(0X80,0X8D,0X80), RGB(0X87,0X95,0X87), RGB(0X8D,0X9C,0X8D), RGB(0X93,0XA3,0X93), RGB(0X99,0XA9,0X99), RGB(0X9F,0XAF,0X9F), RGB(0XA4,0XB5,0XA4), RGB(0XA9,0XBA,0XA9), RGB(0XAE,0XC0,0XAE)};/* these are not gamma corrected */static int rgtable[8] = { 0, 36, 73, 109, 146, 182, 219, 255};/* these are not gamma corrected */static int btable[4] = { 0, 85, 170, 255};#define CHECK_RETURN(expr) (expr) ? (void)0 : (void)fprintf(stderr, "%s returned error (%s:%d)\n", #expr, __FILE__, __LINE__)static HBITMAP getBitmapDCtmp = NULL;typedef struct { int num; unicode label[MAX_SOFTBUTTON_CHARS];} SoftButtonLabel;static SoftButtonLabel llabel;static SoftButtonLabel rlabel;typedef struct _mbs { HBITMAP bitmap; HBITMAP mask; int width; int height; int mutable; unsigned char *image; unsigned char *imageMask; char prop;} myBitmapStruct;/* Network Indicator position parameters */#define LED_xposition 17#define LED_yposition 82#define LED_width 20#define LED_height 20#define NET_INDICATOR_DELAY 2500 /* 2.5 seconds *//* Network Indicator status info */int latestNICount = 0;jboolean isLED_on = KNI_FALSE;jlong latestNITime = 0;/* Trusted MIDlet icon info */#define TrustIcon_width 12#define TrustIcon_height 12#define TrustIcon_xposition (X_SCREEN_OFFSET + PAINT_WIDTH - 17 - 10 - TrustIcon_width)#define TrustIcon_yposition (Y_SCREEN_OFFSET)/* NOTE : * trusted midlet icon x position is = * right corner (screenoffset+paintwidth) * - widht of battery (17 pixels) * - space between battery and right edge of icon (10 pixels) * - the width of the trusted icon *//* BackLight top bar position parameters */#define BkliteTop_xposition 0#define BkliteTop_yposition 113#define BkliteTop_width 241#define BkliteTop_height 18/* BackLight bottom bar position parameters */#define BkliteBottom_xposition 0#define BkliteBottom_yposition 339#define BkliteBottom_width 241#define BkliteBottom_height 6/* BackLight left bar position parameters */#define BkliteLeft_xposition 0#define BkliteLeft_yposition 131#define BkliteLeft_width 30#define BkliteLeft_height 208/* BackLight right bar position parameters */#define BkliteRight_xposition 210#define BkliteRight_yposition 131#define BkliteRight_width 31#define BkliteRight_height 208jboolean isBklite_on = KNI_FALSE;static int topBarHeight;static int bottomBarHeight;static int paintHeight;void setUpOffsets(int fullscreen) { switch (fullscreen) { case 1: topBarHeight = TOP_BAR_HEIGHT; bottomBarHeight = 0; break; case 0: topBarHeight = TOP_BAR_HEIGHT; bottomBarHeight = BOTTOM_BAR_HEIGHT; break; } paintHeight = (DISPLAY_HEIGHT - (topBarHeight + bottomBarHeight)); y_offset = Y_SCREEN_OFFSET + topBarHeight;}/* * Draw BackLight. * If 'active' is KNI_TRUE, the BackLight is drawn. * If 'active' is KNI_FALSE, the BackLight is erased. */void drawBackLight(jboolean active) { HDC hdc = GetDC(hMainWindow); CreateBacklight(hdc); if (active == KNI_TRUE) { isBklite_on = KNI_TRUE; DrawBitmap(hdc, bklite_Top_Image, BkliteTop_xposition, BkliteTop_yposition, SRCCOPY); DrawBitmap(hdc, bklite_Bottom_Image, BkliteBottom_xposition, BkliteBottom_yposition, SRCCOPY); DrawBitmap(hdc, bklite_Left_Image, BkliteLeft_xposition, BkliteLeft_yposition, SRCCOPY); DrawBitmap(hdc, bklite_Right_Image, BkliteRight_xposition, BkliteRight_yposition, SRCCOPY); }else { if (isBklite_on) { isBklite_on = KNI_FALSE; REFRESH_BACKLIGHT_TOPBAR(); REFRESH_BACKLIGHT_BOTTOMBAR(); REFRESH_BACKLIGHT_LEFTBAR(); REFRESH_BACKLIGHT_RIGHTBAR(); } } ReleaseDC(hMainWindow, hdc);}/* * Draw the LED indicating network activity. * If 'active' is KNI_TRUE, a lit green LED is drawn. * If 'active' is KNI_FALSE, a dim gray LED is drawn. */void drawNetIndicator(jboolean activity) { HDC hdc = GetDC(hMainWindow); if (activity == KNI_TRUE) { DrawBitmap(hdc, LED_on_Image, LED_xposition, LED_yposition, SRCCOPY); } else { DrawBitmap(hdc, LED_off_Image, LED_xposition, LED_yposition, SRCCOPY); } ReleaseDC(hMainWindow, hdc);}/* * Check for recent network activity, and update the * network indicator LED accordingly. */void updateNetIndicator() { if (netIndicatorCount != latestNICount){ if (!isLED_on){ drawNetIndicator(KNI_TRUE); isLED_on = KNI_TRUE; } latestNITime = midp_getCurrentTime(); latestNICount = netIndicatorCount; } else { if (isLED_on){ jlong now = midp_getCurrentTime(); if ((now - latestNITime) > NET_INDICATOR_DELAY) { drawNetIndicator(KNI_FALSE); isLED_on = KNI_FALSE; } } }}void drawEmulatorScreen(jboolean fullscreen) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -