win32app_export.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,259 行 · 第 1/3 页
C
1,259 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. *//** * @file * Additional porting API for Java Widgets based port of abstract * command manager. */#include <stdio.h>#include <windows.h>#include <math.h>#include <kni.h>#include <midp_logging.h>#include <win32app_export.h>#include <gx_graphics.h>#include <midpServices.h>#include <midp_properties_port.h>#include <midp_constants_data.h>#include <keymap_input.h>#include <midpMalloc.h>#include <midpString.h>#include <anc_indicators.h>#include <gxj_putpixel.h>#include <midp_foreground_id.h>/*#include "staticGraphics.h" */#include "midpStubsKeymapping.h"#define NUMBEROF(x) (sizeof(x)/sizeof(x[0]))/* * This (x,y) coordinate pair refers to the offset of the upper * left corner of the display screen within the MIDP phone handset * graphic window */#define X_SCREEN_OFFSET 60#define Y_SCREEN_OFFSET 76#define TOP_BAR_HEIGHT 0/* * Defines Java code paintable region */#define DISPLAY_WIDTH CHAM_WIDTH#define DISPLAY_HEIGHT CHAM_FULLHEIGHT#define DISPLAY_X X_SCREEN_OFFSET#define DISPLAY_Y (Y_SCREEN_OFFSET + TOP_BAR_HEIGHT)#define UNTRANSLATED_SCREEN_BITMAP (void*)0xffffffff#define CHECK_RETURN(expr) (expr) ? (void)0 : (void)fprintf(stderr, "%s returned error (%s:%d)\n", #expr, __FILE__, __LINE__)#define ASSERT(expr) (expr) ? (void)0 : (void)fprintf(stderr, \ "%s:%d: (%s)is NOT true\n", __FILE__, __LINE__, #expr)#define KEYMAP_MD_KEY_HOME (KEYMAP_KEY_MACHINE_DEP)#define KEYMAP_MD_KEY_SWITCH_APP (KEYMAP_KEY_MACHINE_DEP - 1)static HBITMAP getBitmapDCtmp = NULL;typedef unsigned short unicode;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 INSIDE(_x, _y, _r) \ ((_x >= (_r).x) && (_x < ((_r).x + (_r).width)) && \ (_y >= (_r).y) && (_y < ((_r).y + (_r).height)))static jboolean reverse_orientation = KNI_FALSE;static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);static void releaseBitmapDC(HDC hdcMem);static void DrawBitmap(HDC hdc, HBITMAP hBitmap, int x, int y, int rop);static HDC getBitmapDC(void *imageData);static HPEN setPen(HDC hdc, int pixel, int dotted);static void CreateBacklight(HDC hdc);static void CreateEmulatorWindow();static void resizeScreenBuffer();static void invalidateLCDScreen(int x1, int y1, int x2, int y2);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;/* This is logical LCDUI putpixel screen buffer. */gxj_screen_buffer gxj_system_screen_buffer;static jboolean initialized = KNI_FALSE;static jboolean inFullScreenMode = KNI_FALSE;static jboolean bkliteImageCreated = KNI_FALSE;static jboolean isBklite_on = KNI_FALSE;static int backgroundColor = RGB(182, 182, 170); /* This a win32 color value */static int foregroundColor = RGB(0,0,0); /* This a win32 color value */static void* lastImage = (void*)0xfffffffe;static HWND hMainWindow = NULL;static HDC hMemDC = NULL;static TEXTMETRIC fixed_tm, tm;static HFONT fonts[3][3][8];/* The phone images */static HBITMAP hPhoneBitmap;static HBITMAP hPhoneLightBitmap;void win32app_init() { CreateEmulatorWindow();}/** * Utility function to request logical screen to be painted * to the physical screen when screen is in normal mode. * @param x1 top-left x coordinate of the area to refresh * @param y1 top-left y coordinate of the area to refresh * @param x2 bottom-right x coordinate of the area to refresh * @param y2 bottom-right y coordinate of the area to refresh */static void win32app_refresh_normal(int x1, int y1, int x2, int y2) { int x; int y; int width; int height; gxj_pixel_type* pixels = gxj_system_screen_buffer.pixelData; int i; int j; gxj_pixel_type pixel; int r; int g; int b; unsigned char *destBits; unsigned char *destPtr; HDC hdcMem; HBITMAP destHBmp; BITMAPINFO bi; HGDIOBJ oobj; HDC hdc; REPORT_CALL_TRACE4(LC_HIGHUI, "LF:STUB:win32app_refresh(%3d, %3d, %3d, %3d )\n", x1, y1, x2, y2); if (x1 < 0) { x1 = 0; } if (y1 < 0) { y1 = 0; } if (x2 <= x1 || y2 <= y1) { return; } if (x2 > gxj_system_screen_buffer.width) { x2 = gxj_system_screen_buffer.width; } if (y2 > gxj_system_screen_buffer.height) { y2 = gxj_system_screen_buffer.height; } x = x1; y = y1; width = x2 - x1; height = y2 - y1; bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biWidth = width; bi.bmiHeader.biHeight = -height; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = sizeof (long) * 8; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = width * height * sizeof (long); bi.bmiHeader.biXPelsPerMeter = 0; bi.bmiHeader.biYPelsPerMeter = 0; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; hdc = getBitmapDC(NULL); hdcMem = CreateCompatibleDC(hdc); destHBmp = CreateDIBSection (hdcMem, &bi, DIB_RGB_COLORS, &destBits, NULL, 0); if (destBits != NULL) { oobj = SelectObject(hdcMem, destHBmp); SelectObject(hdcMem, oobj); for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { pixel = pixels[((y + j) * gxj_system_screen_buffer.width) + x + i]; r = GXJ_GET_RED_FROM_PIXEL(pixel); g = GXJ_GET_GREEN_FROM_PIXEL(pixel); b = GXJ_GET_BLUE_FROM_PIXEL(pixel); destPtr = destBits + ((j * width + i) * sizeof (long)); *destPtr++ = b; /* dest pixels seem to be in BGRA order */ *destPtr++ = g; *destPtr++ = r; } } SetDIBitsToDevice(hdc, x, y, width, height, 0, 0, 0, height, destBits, &bi, DIB_RGB_COLORS); } DeleteObject(oobj); DeleteObject(destHBmp); DeleteDC(hdcMem); releaseBitmapDC(hdc); invalidateLCDScreen(x1, y1, x2, y2);}/** * Utility function to request logical screen to be painted * to the physical screen when screen is in rotated mode. * @param x1 top-left x coordinate of the area to refresh * @param y1 top-left y coordinate of the area to refresh * @param x2 bottom-right x coordinate of the area to refresh * @param y2 bottom-right y coordinate of the area to refresh */static void win32app_refresh_rotate(int x1, int y1, int x2, int y2) { int x; int y; int width; int height; gxj_pixel_type* pixels = gxj_system_screen_buffer.pixelData; gxj_pixel_type pixel; int r; int g; int b; unsigned char *destBits; unsigned char *destPtr; HDC hdcMem; HBITMAP destHBmp; BITMAPINFO bi; HGDIOBJ oobj; HDC hdc; REPORT_CALL_TRACE4(LC_HIGHUI, "LF:STUB:win32app_refresh(%3d, %3d, %3d, %3d )\n", x1, y1, x2, y2); if (x1 < 0) { x1 = 0; } if (y1 < 0) { y1 = 0; } if (x2 <= x1 || y2 <= y1) { return; } if (x2 > gxj_system_screen_buffer.width) { x2 = gxj_system_screen_buffer.width; } if (y2 > gxj_system_screen_buffer.height) { y2 = gxj_system_screen_buffer.height; } x = x1; y = y1; width = x2 - x1; height = y2 - y1; bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biWidth = height; /* width; */ bi.bmiHeader.biHeight = -width; /* -height; */ bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = sizeof (long) * 8; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = width * height * sizeof (long); bi.bmiHeader.biXPelsPerMeter = 0; bi.bmiHeader.biYPelsPerMeter = 0; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; hdc = getBitmapDC(NULL); hdcMem = CreateCompatibleDC(hdc); destHBmp = CreateDIBSection (hdcMem, &bi, DIB_RGB_COLORS, &destBits, NULL, 0); if (destBits != NULL) { oobj = SelectObject(hdcMem, destHBmp); SelectObject(hdcMem, oobj); destPtr = destBits; pixels += x2-1 + y1 * win32app_get_screen_width(); for (x = x2; x > x1; x--) { int y; for (y = y1; y < y2; y++) { r = GXJ_GET_RED_FROM_PIXEL(*pixels); g = GXJ_GET_GREEN_FROM_PIXEL(*pixels); b = GXJ_GET_BLUE_FROM_PIXEL(*pixels); *destPtr++ = b; *destPtr++ = g; *destPtr++ = r; destPtr += sizeof(long) - 3*sizeof(*destPtr); pixels += win32app_get_screen_width(); } pixels += -1 - height * win32app_get_screen_width(); } SetDIBitsToDevice(hdc, y, win32app_get_screen_width() - width - x, height, width, 0, 0, 0, width, destBits, &bi, DIB_RGB_COLORS);} DeleteObject(oobj); DeleteObject(destHBmp); DeleteDC(hdcMem); releaseBitmapDC(hdc); invalidateLCDScreen(x1, y1, x1 + height, y1 + width);}/** * Bridge function to request logical screen to be painted * to the physical screen. * <p> * On win32 there are 3 bitmap buffers, putpixel screen buffer, the phone * bitmap that includes an LCD screen area, and the actual window buffer. * Paint the screen buffer on the LCD screen area of the phone bitmap. * On a real win32 (or high level window API) device the phone bitmap would * not be needed and this function would just invalidate the window and * when the system call back to paint the window, then the putpixel buffer * would be painted to the window. * * @param x1 top-left x coordinate of the area to refresh * @param y1 top-left y coordinate of the area to refresh * @param x2 bottom-right x coordinate of the area to refresh * @param y2 bottom-right y coordinate of the area to refresh */void win32app_refresh(int x1, int y1, int x2, int y2) { if (reverse_orientation) { win32app_refresh_rotate(x1, y1, x2, y2); } else { win32app_refresh_normal(x1, y1, x2, y2); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?