📄 wnd.cc
字号:
return (void*)mw;}void* Java_java_awt_Toolkit_wndCreateWindow(JNIEnv* env, jclass clazz, void* owner, jint x, jint y, jint width, jint height, jint jCursor, jint clrBack ){ fprintf(stderr,"wndCreateWindow\n");/* Window w = createWindow( env, clazz, X->root, (Window)owner, NULL, x, y, width, height, jCursor, clrBack, JNI_TRUE); */ QFrame* mw = new QFrame((QWidget*)owner); mw->setFrameStyle(QFrame::Panel|QFrame::Raised); QPoint p = mw->mapToParent(mw->mapFromGlobal(QPoint(x,y))); x = p.x(); y = p.y(); // Owner AWT_DBG(printf("createWindow( %p, %d,%d,%d,%d,..) -> %p\n", owner,x,y,width,height, mw)); if ( width <= 0 ) width = 1; if ( height <= 0 ) height = 1; mw->setGeometry(x, y, width, height); ((QWidget *)mw)->setCursor (QCursor(getCursor(jCursor))); mw->setBackgroundColor(QCOLOR(clrBack)); //mw->show(); // this should be removed int idx = registerSource( X, (QWidget*)mw, (QWidget*)owner, WND_WINDOW); AWT_DBG(printf("registerSource: mw=%p idx=%d\n",mw,idx)); return (void*)mw;}void* Java_java_awt_Toolkit_wndCreateDialog(JNIEnv* env, jclass clazz, void* owner, jstring jTitle, jint x, jint y, jint width, jint height, jint jCursor, jint clrBack, jboolean isResizable ){/* Window w = createWindow( env, clazz, DefaultRootWindow( X->dsp), (Window)owner, jTitle, x, y, width, height, jCursor, clrBack, isResizable); */ fprintf(stderr,"wndCreateDialog\n"); QFrame* mw = new QFrame(); mw->setFrameStyle(QFrame::Panel|QFrame::Raised); QPoint p = mw->mapToParent(mw->mapFromGlobal(QPoint(x,y))); x = p.x(); y = p.y(); // Owner AWT_DBG( printf("createDialog( %p,%p, %d,%d,%d,%d,..) -> %p\n", owner, jTitle, x, y, width, height, mw)); if ( width <= 0 ) width = 1; if ( height <= 0 ) height = 1; mw->setGeometry(x, y, width, height); ((QWidget *)mw)->setCursor(QCursor( getCursor(jCursor))); mw->setBackgroundColor(QCOLOR(clrBack)); Java_java_awt_Toolkit_wndSetResizable( env, clazz, (void*)mw, isResizable, x, y, width, height); Java_java_awt_Toolkit_wndSetTitle(env, clazz, (void*)mw, jTitle); //mw->show(); // this should be removed int idx = registerSource( X, (QWidget*)mw, (QWidget*)owner, WND_DIALOG); AWT_DBG(printf("registerSource: mw=%p idx=%d\n",mw,idx)); return (void*)mw;}void Java_java_awt_Toolkit_wndDestroyWindow(JNIEnv* env, jclass clazz, void* wnd){ int i = getSourceIdx( X, wnd); AWT_DBG(printf("destroy window: %p (%d)\n", wnd, i)); if ( (i >= 0) && !(X->windows[i].flags & WND_DESTROYED) ) { if ( wnd == X->focusFwd ) { /* * reset focus forwading NOW, we can't do it from a clientMessage, * since any real focusLost notification would be scrubbed by the * subsequent XDestroyWindow */ resetFocusForwarding( X); if ( X->windows[i].owner && (X->windows[i].owner == X->focus) ) { /* * This was a explicit dispose(), and the owner still is the real * focus window. * Let's make it think it got back the focus */ /* forwardFocus( FWD_REVERT, X->windows[i].owner); */ } } X->windows[i].flags |= WND_DESTROYED; X->windows[i].flags &= ~WND_MAPPED; ((QWidget*)wnd)->close(TRUE); // XDestroyWindow( X->dsp, wnd); }}void Java_java_awt_Toolkit_wndRequestFocus(JNIEnv* env, jclass clazz, void* wnd){ int i = getSourceIdx( X, wnd); AWT_DBG( printf("request focus: %lx (%d)\n", wnd, i)); if ( (i < 0) || (X->windows[i].flags & WND_DESTROYED) ) return; ((QWidget*)wnd)->setActiveWindow(); ((QWidget*)wnd)->raise(); ((QWidget*)wnd)->setFocus();#if 0 if ( (X->windows[i].owner) && (X->windows[i].flags & WND_WINDOW) ) { if ( X->focus != X->windows[i].owner ) { /* if our owner doesn't have it yet, make him the focus window */ XSetInputFocus( X->dsp, X->windows[i].owner, RevertToParent, CurrentTime); } /* * This marks the beginning of a focus forward to a owned window * (which isn't allowed to get the real focus because it would * "shade" the titlebar of the owner) */ forwardFocus( FWD_SET, wnd); } else { if ( (X->windows[i].flags & WND_MAPPED) == 0 ){ /* If it's not mapped yet, try again later. Somebody might * have been too fast with requesting the focus of a not yet visible * window, resulting in BadMatch errors */ retryFocus( wnd, X->windows[i].owner, 5); } else if ( (X->focusFwd) && (wnd == X->focus) ) { /* We still have it in real life, but we have to pretend we re-gained * it from our ownee. Reset forwarding here (instead of in the * ClientMessage), because a subsequent destroy of the ownee otherwise * might cause another revert (with the Java keyTgtRequest already * eaten up by this FWD_REVERT) */ resetFocusForwarding( X); forwardFocus( FWD_REVERT, wnd); } else { /* we don't reset X->focusFwd here, that's done in the event handler */ XSetInputFocus( X->dsp, (Window)wnd, RevertToParent, CurrentTime); } }#endif}/* * We shift possible Frame / Dialog deco adaptions back to Java, because (in * order to get more compatible with JDK behavior) we not only have to apply * offsets in wndSetWindowBounds, but also when getting back via ComponentEvents * (ConfigureNotify), and during recursive child painting (to adapt the toplevel Graphics). * Since we don't have the window type info (frame / dialog / window) * in the native lib, this has to be done in the Java layer. In order to do it * all on one side, this means to shift the size adaption out of wndSetWindowBounds, too. * * Therefor Default frame/dialog Insets become the pivotal info, being passed into * the native lib as a (configurable 'Defaults') guess, turned into exact values * (of Frame.frameInsets, Dialog.dialogInsets) by means of native-to-Java callbacks, * computed during initial Frame/Dialog creation */voidJava_java_awt_Toolkit_wndSetFrameInsets ( JNIEnv* env, jclass clazz, jint top, jint left, jint bottom, jint right ){ X->frameInsets.top = top; X->frameInsets.left = left; X->frameInsets.bottom = bottom; X->frameInsets.right = right; X->frameInsets.guess = 1;}voidJava_java_awt_Toolkit_wndSetDialogInsets ( JNIEnv* env, jclass clazz, jint top, jint left, jint bottom, jint right ){ X->dialogInsets.top = top; X->dialogInsets.left = left; X->dialogInsets.bottom = bottom; X->dialogInsets.right = right; X->dialogInsets.guess = 1;}void Java_java_awt_Toolkit_wndSetBounds(JNIEnv* env, jclass clazz, void* wnd, jint x, jint y, jint width, jint height, jboolean isResizable){ AWT_DBG(printf("setBounds: %p %d,%d,%d,%d\n", wnd, x, y, width, height)); if(width < 0) width = 1; if(height < 0) height = 1; ((QWidget*)wnd)->setGeometry(x, y, width, height); /* * Our perspective of 'isResizable' is somewhat relaxed: we just disable * "user-resizing" (like it is stated in the spec), i.e. a program is * allowed to do setBounds on non-resizable Frames/Dialogs. This makes * initial decoration size compensation easy, but it requires that we * update the "lock" after a resize operation */ if ( !isResizable ) { Java_java_awt_Toolkit_wndSetResizable( env, clazz, (void*)wnd, FALSE, x, y, width, height); }}void Java_java_awt_Toolkit_wndRepaint(JNIEnv* env, jclass clazz, void* wnd, jint x, jint y, jint width, jint height ){ AWT_DBG(printf("wndRepaint: %lx %d,%d,%d,%d\n", wnd, x, y, width, height)); ((QWidget*)wnd)->repaint(x, y, width, height); // or use update?}void Java_java_awt_Toolkit_wndSetIcon(JNIEnv* env, jclass clazz, void* wnd, void* img ){}void Java_java_awt_Toolkit_wndSetVisible(JNIEnv* env, jclass clazz, void* wnd, jboolean showIt){ int i = getSourceIdx( X, wnd); void* owner; AWT_DBG( printf("setVisible: %lx (%d) %d\n", wnd, i, showIt)); if ( (i < 0) || (X->windows[i].flags & WND_DESTROYED) ) return; owner = X->windows[i].owner; if ( showIt ){ X->windows[i].flags |= WND_MAPPED; ((QWidget*)wnd)->show(); ((QWidget*)wnd)->setActiveWindow(); ((QWidget*)wnd)->raise(); ((QWidget*)wnd)->repaint();// XMapRaised( X->dsp, wnd);// XSync( X->dsp, False); /* * Don't automatically forward the focus for owned popups, the standard * JDK behavior is NOT to set the focus on them unless explicitly * requested. It would break Swing heavyweight popups (JWindowPopup, * both keyboard input and the famous "first on Solaris" jitter) */ } else { if ( wnd == X->focusFwd ) { forwardFocus( FWD_CLEAR, owner); forwardFocus( FWD_REVERT, owner); } X->windows[i].flags &= ~WND_MAPPED; ((QWidget*)wnd)->hide(); // XUnmapWindow( X->dsp, wnd); // XSync( X->dsp, False); }}void Java_java_awt_Toolkit_wndToBack(JNIEnv* env, jclass clazz, void* wnd){ AWT_DBG(printf("toBack: %p\n", wnd)); ((QWidget*)wnd)->lower();}void Java_java_awt_Toolkit_wndToFront(JNIEnv* env, jclass clazz, void* wnd){ AWT_DBG(printf("toFront: %p\n", wnd)); ((QWidget*)wnd)->raise();}void Java_java_awt_Toolkit_wndSetCursor(JNIEnv* env, jclass clazz, void* wnd, jint jCursor){ AWT_DBG(printf("setCursor: %lx, %d\n", (QWidget *)wnd, jCursor)); ((QWidget*)wnd)->setCursor(QCursor( getCursor(jCursor)));// XDefineCursor( X->dsp, (Window)wnd, getCursor( jCursor));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -