📄 nativegui.c
字号:
XFree(BackLight_off_Image); BackLight_off_Image = None; } if (BackLight_on_Image != None) { XFree(BackLight_on_Image); BackLight_on_Image = None; }#ifdef INCLUDE_I18N if (lcWin){ midpFree(lcWin); lcWin=NULL; } if (xic){ XDestroyIC(xic); xic=NULL; } if (xim){ XCloseIM(xim); xim=NULL; }#endif /* * X server-side objects will be disposed of automatically when * the client side connection to the X display server is closed */ if (display != NULL){ XCloseDisplay(display); display = NULL; } /* RFC - some Motif resources remain unclaimed that are buried * in XtOpenDisplay initialization. It may not be possible to * plug all system allocated resources. e.g. cached * conversion tables and interned strings. */}static inttranslateKey(XKeyPressedEvent *ek, KVMEventType *evt){ KeySym sym; Modifiers m; int n; char buf[64]; if (ek->state & Mod3Mask) { /* Num Lock */ int i; for (i = 0; i < 10; ++i) { if (ek->keycode == table[i].code) return table[i].chr; } } XtTranslateKeycode(display, ek->keycode, ek->state, &m, &sym); switch (sym) { /* other keys that return characters */ case XK_BackSpace: evt->type = keyTypedKVMEvent; return 8; case XK_Delete: evt->type = keyTypedKVMEvent; return 127; case XK_space: evt->type = keyTypedKVMEvent; return ' '; /* keypad keys other than 0..9 */ case XK_R3: case XK_KP_Add: return 0; case XK_R4: case XK_KP_Subtract: return 0; case XK_R5: case XK_KP_Divide: return KEY_POUND; case XK_R6: /* num pad * on Sun keyboard */ case XK_KP_Multiply: return KEY_ASTERISK; case XK_KP_Enter: return KEY_SELECT; case XK_Up: return KEY_UP; case XK_Down: return KEY_DOWN; case XK_Left: return KEY_LEFT; case XK_Right: return KEY_RIGHT; case XK_Return: return KEY_SELECT; case XK_F1: return KEY_SOFT1; /* labelled F1 */ case XK_F2: return KEY_SOFT2; /* labelled F2 */ case XK_F6: evt->type = systemKVMEvent; return VK_SUSPEND_ALL; case XK_F7: evt->type = systemKVMEvent; return VK_RESUME_ALL; case XK_F8: evt->type = systemKVMEvent; return VK_SUSPEND_CURRENT; case XK_F9: evt->type = systemKVMEvent; return VK_RESUME_PREVIOUS; case XK_F10: evt->type = systemKVMEvent; return VK_KILL_CURRENT;/* case SunXK_F36: return ; labelled F11 */ /* labelled F12 *//* case SunXK_F37: evt->type = systemKVMEvent; return VK_SHUTDOWN; */ case XK_KP_Decimal: return 0; default: n = XLookupString(ek, buf, sizeof(buf), &sym, NULL); if ((n == 1) && (buf[0] >= ' ')) { evt->type = keyTypedKVMEvent; return buf[0]; } return 0; }}#ifdef INCLUDE_I18Nstatic jbooleanFilterEvent(XEvent *event, KVMEventType *evt) { char *str = NULL; int len = 0; jboolean ret = KNI_FALSE; if (xic == NULL) { return KNI_FALSE; } switch (event->type) { case KeyPress: /* let it go further */ break; case FocusIn: XSetICFocus(xic); return KNI_FALSE; case FocusOut: XUnsetICFocus(xic); return KNI_FALSE; default: return KNI_FALSE; } while (KNI_TRUE) { XKeyPressedEvent *kev = (XKeyPressedEvent *) event; int count; KeySym keysym; Status status; len += 128; str = (char *) midpRealloc(str, len); if (str == NULL) { ret = KNI_FALSE; break; } count = XmbLookupString(xic, kev, str, len, &keysym, &status); if (status == XBufferOverflow) { continue; } else { switch (status) { case XLookupNone: case XLookupKeySym: break; case XLookupBoth: case XLookupChars: { if (count == 1 && isascii(str[0])) { /* let the ascii character handle the main loop. */ break; } if (count > 0) { unicode *ustr = (unicode *) midpMalloc(count * sizeof(unicode)); if (ustr == NULL) { ret = KNI_FALSE; } else { count = nativeToUnicode((const unsigned char *)str, count, ustr, count); evt->type = imeKVMEvent; evt->str = ustr; evt->len = count; ret = KNI_TRUE; } } break; } } /* break the while loop */ break; } } if (str) { midpFree(str); } return ret;}#endif#if USE_KVMvoidGetAndStoreNextKVMEvent(bool_t forever, ulong64 waitUntil) { XEvent event; KVMEventType evt; static int penDown = 0; int i; /* * A timer may come before waitUntil; we don't want to be * blocked for too long, so we have to take them into account. * If there are pending timers, we store the shortened wait value * into the variable "pending," which is used to compute wait time. * * We want (pending == 0) to imply (forever == true), so if * waitUntil is zero and forever is false, we need to use a * nonzero value. */ ulong64 pending = forever ? 0 : ((waitUntil == 0) ? 1 : waitUntil); for (;;) { /* see if we should toggle the network indicator LED */ if ((netIndicatorCount != latestNICount) || isLED_on == KNI_TRUE) { updateNetIndicator(); } /* XtAppPending looks for timers as well as events */ if (pending && !XtAppPending(appContext)) { jlong now = midp_getCurrentTime(); if (waitUntil < now) { return; } else if (pending > now) { int fd = ConnectionNumber(display); ulong64 delta = pending - now; struct timeval timeout; fd_set readfds; /* Set the seconds and microseconds */ timeout.tv_sec = delta / 1000; timeout.tv_usec = (delta % 1000) * 1000; /* Set the single bit in the bit set */ FD_ZERO(&readfds); FD_SET(fd, &readfds); select(fd + 1, &readfds, NULL, NULL, &timeout); } if (!XtAppPending(appContext)) { /* Hmm...no timer or input event waiting yet. */ continue; } } XtAppNextEvent(appContext, &event);#ifdef INCLUDE_I18N if (XFilterEvent(&event, None)) continue; if (FilterEvent(&event, &evt)) { StoreMIDPEvent(&evt); return; }#endif switch (event.type) { case KeyPress: case KeyRelease: { XKeyPressedEvent *ek = (XKeyPressedEvent *)&event; if (event.type == KeyRelease) { XEvent next; evt.type = keyUpKVMEvent; /* with repeating events, you get a release and a press */ /* following it that have exactly the same time. */ if (XCheckTypedEvent(display, KeyPress, &next)) { if ( (next.xkey.time == ek->time) && (next.xkey.keycode == ek->keycode)) { evt.type = keyRepeatKVMEvent; } else { XPutBackEvent(display, &next); } } } else { evt.type = keyDownKVMEvent; } evt.chr = translateKey(ek, &evt); if (evt.chr == 0) { break; } else if ( (evt.type == keyDownKVMEvent) || (evt.type == keyRepeatKVMEvent)) { jboolean tmp = LCDUIpopupMenuInternalEvent(evt.chr, &evt); if (tmp == KNI_FALSE) { tmp = LCDUImenuInternalEvent(evt.chr, &evt); } if (tmp && (evt.type == invalidKVMEvent)) { break; } } else if ( (evt.type == keyTypedKVMEvent) && (event.type == KeyRelease)) { break; } else if ( (evt.type == systemKVMEvent) && (event.type == KeyRelease)) { break; } StoreMIDPEvent(&evt); return; } case MotionNotify: if (lastButton != NULL) { if (INSIDE(event, lastButton->bounds)) { /* we're still inside--do nothing */ break; } else { /* do a release on the old key, then reprocess this event */ evt.chr = lastButton->button; evt.type = keyUpKVMEvent; lastButton = NULL; XPutBackEvent(display, &event); StoreMIDPEvent(&evt); return; } } /* FALL THROUGH */ case ButtonPress: case ButtonRelease: if (event.xbutton.window == paintWindow) { evt.screenX = event.xbutton.x; evt.screenY = event.xbutton.y; if (evt.screenX < 0) { if (!penDown) break; evt.screenX = 0; event.type = ButtonRelease; } else if (evt.screenX >= PAINT_WIDTH) { if (!penDown) break; evt.screenX = PAINT_WIDTH - 1; event.type = ButtonRelease; } if (evt.screenY < 0) { if (!penDown) break; evt.screenY = 0; event.type = ButtonRelease; } else if (evt.screenY >= paintHeight) { if (!penDown) break; evt.screenY = paintHeight - 1; event.type = ButtonRelease; } switch (event.type) { case ButtonPress: penDown = KNI_TRUE; evt.type = penDownKVMEvent; StoreMIDPEvent(&evt); return; case ButtonRelease: if (!penDown) break; penDown = KNI_FALSE; evt.type = penUpKVMEvent; StoreMIDPEvent(&evt); return; case MotionNotify: if (!penDown) break; evt.type = penMoveKVMEvent; StoreMIDPEvent(&evt); return; } /* switch */ } else { int i; for (i = 0; i < XtNumber(keys); i++) { if (INSIDE(event, keys[i].bounds)) {#ifdef SOUND_SUPPORTED if(event.type == ButtonPress) { XBell(display, 0); XFlush(display); }#endif if (keys[i].button == KEY_POWER && event.type == ButtonRelease) { evt.type = systemKVMEvent; evt.chr = VK_SHUTDOWN; StoreMIDPEvent(&evt); return; } else if ((keys[i].button == KEY_SOFT1) || (keys[i].button == KEY_SOFT2)) { lastButton = keys + i; if ((event.type != ButtonRelease) && LCDUIpopupMenuInternalEvent(keys[i].button, &evt)) { StoreMIDPEvent(&evt); return; } else if ((event.type != ButtonRelease) && LCDUImenuInternalEvent(keys[i].button, &evt)) { StoreMIDPEvent(&evt); return; } else { break; } } else if (keys[i].button == KEY_END) { if (event.type == ButtonPress) { /* The RI will manually translate a single press * of the 'end' key into a MIDlet 'kill' system event. * Ports may utilize a special "long press" usage of * the 'end' key to accomplish this and remove this * 'else' block */ LCDUIdismissMenu(); LCDUIdismissPopupMenu(); evt.type = systemKVMEvent; evt.chr = VK_KILL_CURRENT; StoreMIDPEvent(&evt); return; } else { break; } } else { jboolean tmp; evt.chr = keys[i].button; switch (event.type) { case MotionNotify: case ButtonPress: lastButton = keys + i; evt.type = keyDownKVMEvent; tmp = LCDUIpopupMenuInternalEvent(keys[i].button, &evt); if (tmp == KNI_FALSE) { tmp = LCDUImenuInternalEvent(keys[i].button, &evt); } if (tmp && (evt.type == invalidKVMEvent)) { break; } StoreMIDPEvent(&evt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -