📄 evt.cc
字号:
/** * evt.c - * * Copyright (c) 1998 * Transvirtual Technologies, Inc. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */#ifdef QPE# include <qpe/qpeapplication.h>#else# include <qapplication.h>#endif#include <qevent.h>#include <qqueue.h>#include <qwidget.h>#include "evt.h"#include "toolkit.h"#include "keysyms.h"jclass AWTEvent;jclass ComponentEvent;jclass MouseEvent;jclass FocusEvent;jclass WindowEvent;jclass KeyEvent;jclass PaintEvent;jclass WMEvent;jmethodID getComponentEvent;jmethodID getMouseEvent;jmethodID getFocusEvent;jmethodID getWindowEvent;jmethodID getKeyEvent;jmethodID getPaintEvent;jmethodID getWMEvent;extern void pollJavaClipboard(JNIEnv *env);extern jobject clearJavaClipboard(JNIEnv *env);#define COMPONENT_RESIZED 101#define WINDOW_CLOSING 201#define WINDOW_CLOSED 202#define WINDOW_ICONIFIED 203#define WINDOW_DEICONIFIED 204#define KEY_PRESSED 401#define KEY_RELEASED 402#define MOUSE_PRESSED 501#define MOUSE_RELEASED 502#define MOUSE_MOVED 503#define MOUSE_ENTERED 504#define MOUSE_EXITED 505#define PAINT 800#define UPDATE 801#define FOCUS_GAINED 1004#define FOCUS_LOST 1005#define WM_KILLED 1905class EventPacket {public: EventPacket(QEvent* evt, int idx) { event = evt; srcIdx = idx; } QEvent* getEvent() { return event; } int getIndex() { return srcIdx; }protected: QEvent* event; int srcIdx;};#ifdef QPEextern QPEApplication *qapp;#elseextern QApplication *qapp;#endifQQueue<EventPacket> g_event_queue;EventDispatcher::EventDispatcher(QWidget *parent, const char *name) { if(parent) parent->installEventFilter(this);}bool EventDispatcher::eventFilter(QObject* o, QEvent* e) {// AWT_DBG(printf("event type=%d widget=%p\n", e->type(), o)); QEvent* newEvent = NULL; EventPacket* packet = NULL; bool processed = false;// getSourceIdx(X, o); if(X->srcIdx == 0) return QWidget::eventFilter(o, e); switch(e->type()) { case QEvent::Clipboard: { newEvent = new QEvent(e->type()); processed = true; break; } case QEvent::Destroy: case QEvent::Reparent: { newEvent = new QEvent(e->type()); processed = true; break; } case QEvent::Show: { AWT_DBG(printf("Event Show: srcIdx=%d\n", X->srcIdx));#if (QT_VERSION < 300) newEvent = (QEvent*) new QShowEvent(true);#else QShowEvent* tmpShowEvent = (QShowEvent*)e; newEvent = (QEvent*) new QShowEvent();#endif processed = true; break; } case QEvent::Hide: { AWT_DBG(printf("Event Hid: srcIdx=%d\n", X->srcIdx));#if (QT_VERSION < 300) newEvent = (QEvent*) new QHideEvent(true);#else QHideEvent* tmpHideEvent = (QHideEvent*)e; newEvent = (QEvent*) new QHideEvent();#endif processed = true; break; } case QEvent::FocusIn: case QEvent::FocusOut: { AWT_DBG(printf("Event Focus: srcIdx=%d\n", X->srcIdx)); QFocusEvent* tmpFocusEvent = (QFocusEvent*)e; newEvent = (QEvent*) new QFocusEvent(tmpFocusEvent->type()); ((QFocusEvent*)newEvent)->setReason(tmpFocusEvent->reason()); processed = true; break; } case QEvent::KeyPress: case QEvent::KeyRelease: { AWT_DBG(printf("Event Key: srcIdx=%d\n", X->srcIdx)); QKeyEvent* tmpKeyEvent = (QKeyEvent*)e; newEvent = (QEvent*) new QKeyEvent(tmpKeyEvent->type(),tmpKeyEvent->key(), tmpKeyEvent->ascii(), tmpKeyEvent->state(), tmpKeyEvent->text(), tmpKeyEvent->isAutoRepeat(), tmpKeyEvent->count()); processed = true; break; } case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: { AWT_DBG(printf("Event MouseButton: srcIdx=%d\n", X->srcIdx)); QMouseEvent* tmpMouseEvent = (QMouseEvent*)e; newEvent = (QEvent*) new QMouseEvent(tmpMouseEvent->type(), tmpMouseEvent->pos(), tmpMouseEvent->button(), tmpMouseEvent->state()); processed = true; break; } case QEvent::Paint: { AWT_DBG(printf("Event Paint: srcIdx=%d\n", X->srcIdx)); QPaintEvent* tmpPaintEvent = (QPaintEvent*)e; newEvent = (QEvent*) new QPaintEvent(tmpPaintEvent->rect(), tmpPaintEvent->erased()); processed = true; break; } case QEvent::Move: { AWT_DBG(printf("Event Move: srcIdx=%d\n", X->srcIdx)); QPoint data(((QWidget*)o)->width(), ((QWidget*)o)->height()); QMoveEvent* tmpMoveEvent = (QMoveEvent*)e; // Hide width/height in oldPos of newEvent newEvent = (QEvent*) new QMoveEvent(tmpMoveEvent->pos(), data); processed = true; break; } case QEvent::Resize: { AWT_DBG(printf("Event Resize: srcIdx=%d\n", X->srcIdx)); QSize data(((QWidget*)o)->x(), ((QWidget*)o)->y()); QResizeEvent* tmpResizeEvent = (QResizeEvent*)e; // Hide x/y in oldSize of newEvent newEvent = (QEvent*) new QResizeEvent(tmpResizeEvent->size(), data); processed = true; break; } } if(processed == true) { packet = new EventPacket(newEvent, getSourceIdx(X, o)/*X->srcIdx*/); g_event_queue.enqueue(packet); } return QWidget::eventFilter(o, e);}EventDispatcher* eventDispatcher;void forwardFocus ( int cmd, void* wnd ); /* from wnd.c *//***************************************************************************** * *//* X-to-Java key modifier mapping * altGr : PC * shift - ctrl alt meta : Java * Shift Lock Ctrl Mod1 Mod3 : X symbol * ---------------------------------------------------------- * 1 1 2 8 4 : Java value * 1 2 4 8 32 : X * ShiftButton NA ControlButton AltButton : QT */static inline int keyMod ( int keyState ){ int mod = 0; if ( keyState & Qt::ShiftButton ) mod |= 1; if ( keyState & Qt::ControlButton ) mod |= 2; if ( keyState & Qt::AltButton ) mod |= 8; return mod;}static inline int mapButton( int button ){ if ( button & Qt::LeftButton) return 1; if ( button & Qt::RightButton) return 3; if ( button & Qt::MidButton) return 2; return 1;} #if defined(KAFFE_VMDEBUG)static char *eventStr ( int evtId ){ switch (evtId) { case COMPONENT_RESIZED: return "ComponentResized"; case WINDOW_CLOSING: return "WindowClosing"; case WINDOW_CLOSED: return "WindowClosed"; case WINDOW_ICONIFIED: return "WindowIconified"; case WINDOW_DEICONIFIED: return "WindowDeiconified"; case KEY_PRESSED: return "KeyPressed"; case KEY_RELEASED: return "KeyReleased"; case MOUSE_PRESSED: return "MousePressed"; case MOUSE_RELEASED: return "MouseReleased"; case MOUSE_MOVED: return "MouseMoved"; case MOUSE_ENTERED: return "MouseEntered"; case MOUSE_EXITED: return "MouseExited"; case PAINT: return "Paint"; case UPDATE: return "Update"; case FOCUS_GAINED: return "FocusGained"; case FOCUS_LOST: return "FocusLost"; case WM_KILLED: return "WMKilled"; default: return "<unknown>"; }};#endif#if 0static jobjectkeyNotify ( JNIEnv* env, Toolkit* X ){ KeySym keysym; XComposeStatus ioStatus; int n, keyCode, keyChar, mod, idx; /* * We should eventually support input methods here. * Note that 'keysym' is queried separately (with a standard state), to * ensure the "one physical key -> one keycode" invariant */ n = XLookupString( &X->event.xkey, X->buf, X->nBuf, 0, &ioStatus); keysym = XKeycodeToKeysym( X->dsp, X->event.xkey.keycode, 0); if ( (keysym >= 0xff00) || (n == 0) ) { keyCode = FKeyCode[keysym & 0xff]; /* * There are some "control keys" that should generate KEY_TYPED events * (enter, cancel, backspace, del, tab). This is flagged by a negative keyCode * value and leads to non-zero keyChars */ if ( keyCode < 0 ){ keyChar = keyCode = -keyCode; } else { /* a "pure" function key */ keyChar = 0; } } else { keyChar = (unsigned char)X->buf[0]; keyCode = LKeyCode[keysym & 0xff]; } X->evtId = (X->event.xany.type == KeyPress)? KEY_PRESSED : KEY_RELEASED; mod = keyMod( X->event.xkey.state); if ( X->fwdIdx >= 0 ) { /* * watch out - we still might have key events for a already * unregistered forwardee in the queue (since we fake X, we can't rely on it * to remove key events for a destroyed forwardee) */ if ( !checkSource( X, X->fwdIdx) ) return 0; idx = X->fwdIdx; } else { idx = X->srcIdx; } return env->CallStaticObjectMethod( KeyEvent, getKeyEvent, idx, X->evtId, keyCode, keyChar, mod);}static jobjectbuttonNotify ( JNIEnv* env, Toolkit* X ){ if ( X->event.xany.type == ButtonPress ) { X->evtId = MOUSE_PRESSED; if ( (X->windows[X->srcIdx].w == X->focus) && (X->fwdIdx >= 0) ) forwardFocus( FWD_REVERT, X->event.xany.window); }}static jobjectmouseNotify ( JNIEnv* env, Toolkit* X ){ X->evtId = (X->event.xany.type == EnterNotify) ? MOUSE_ENTERED : MOUSE_EXITED; return env->CallStaticObjectMethod( MouseEvent, getMouseEvent, X->srcIdx, X->evtId, 0, X->event.xcrossing.x, X->event.xcrossing.y);}static jobjectfocusNotify ( JNIEnv* env, Toolkit* X ){ return 0;#if 0 int et = X->event.xany.type; int idx = (X->focusFwd) ? X->fwdIdx : X->srcIdx; /* * get rid of all these fancy intermediate focus events (the real thing should * come last), but be aware of that we might get events for already unregistered windows * (in case the app isn't particulary careful with disposing windows), ending up in * ArrayOutOfBoundsExceptions in the getFocusEvent */ while ( XCheckMaskEvent( X->dsp, FocusChangeMask, &X->event) ){ X->pending--; if ( getSourceIdx( X, X->event.xfocus.window) >= 0 ) { et = X->event.xany.type; idx = (X->focusFwd) ? X->fwdIdx : X->srcIdx; } } if ( et == FocusIn ) { X->evtId = FOCUS_GAINED; X->focus = X->event.xany.window; } else { X->evtId = FOCUS_LOST; X->focus = 0; } /* * No matter what the focus change is - if we get a REAL focus notification, * it means that we will end focus forwarding (which is done on the owner-basis, * not by means of a global grab mode) */ resetFocusForwarding( X); if ( checkSource( X, idx) ){ return env->CallStaticObjectMethod( FocusEvent, getFocusEvent, idx, X->evtId, JNI_FALSE); } else { return 0; }#endif}static jobjectdestroyNotify ( JNIEnv* env, Toolkit* X ){ /* * We should get this just for windows which have been destroyed from an * external client, since removeNotify() calls evtUnregisterSource() (i.e. * removes windows properly from the dispatch table) */ X->windows[X->srcIdx].flags &= ~WND_MAPPED; return env->CallStaticObjectMethod( WMEvent, getWMEvent, X->srcIdx, (X->evtId = WM_KILLED));}static jobjectmapNotify ( JNIEnv* env, Toolkit* X ){ int id = 0; if ( X->event.xany.type == MapNotify ) { if ( (X->windows[X->srcIdx].flags & WND_MAPPED) == 0 ){ id = WINDOW_DEICONIFIED; X->windows[X->srcIdx].flags |= WND_MAPPED; } } else { if ( (X->windows[X->srcIdx].flags & WND_MAPPED) != 0 ){ id = WINDOW_ICONIFIED; X->windows[X->srcIdx].flags &= ~WND_MAPPED; } } if ( id ) { return env->CallStaticObjectMethod( WindowEvent, getWindowEvent, X->srcIdx, id); } else { // we do the ComponentEvent show/hide in Java return 0; }}static jobjectclientMessage ( JNIEnv* env, Toolkit* X ){ return 0;#if 0 if ( X->windows[X->srcIdx].flags & WND_DESTROYED ){ /* we lost him, Jim */ return 0; } if ( X->event.xclient.message_type == WM_PROTOCOLS ) { if ( X->event.xclient.data.l[0] == WM_DELETE_WINDOW ) { return env->CallStaticObjectMethod( WindowEvent, getWindowEvent, X->srcIdx, (X->evtId = WINDOW_CLOSING)); } else if ( X->event.xclient.data.l[0] == WM_TAKE_FOCUS ) { XSetInputFocus( X->dsp, X->event.xany.window, RevertToParent, CurrentTime); } } /* * This is a workaround for the common problem of requesting the focus for not * yet mapped windows (resulting in BadMatch errors) */ else if ( X->event.xclient.message_type == RETRY_FOCUS ) { if ( X->windows[X->srcIdx].flags & WND_MAPPED ) { XSetInputFocus( X->dsp, (Window)X->event.xclient.window, RevertToParent, CurrentTime); if ( X->event.xclient.data.l[1] ) { /* we have a pending forward request, too */ forwardFocus( FWD_SET, X->event.xclient.data.l[1]); } } } /* * This is a workaround for X not having "owned" windows (popups), which do * not "shade" the titlebar of their owner (i.e. don't indicate a change in * the activeWindow). The only way to implement this reliable (w/o playing * around with a window manager) is to not let these popups select on * key events at all. But rather than to expose this to the Java side (like * the JDK does), we hide this in the native layer */ else if ( X->event.xclient.message_type == FORWARD_FOCUS ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -