📄 gnu_java_awt_peer_gtk_gtkwindowpeer.c
字号:
window_configure_cb (GtkWidget *widget __attribute__((unused)), GdkEventConfigure *event, jobject peer){ (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postConfigureEventID, (jint) event->x, (jint) event->y, (jint) event->width, (jint) event->height); return FALSE;}static gbooleankey_press_cb (GtkWidget *widget __attribute__((unused)), GdkEventKey *event, jobject peer){ jint keycode; jint keylocation; keycode = keysym_to_awt_keycode (event); keylocation = keysym_to_awt_keylocation (event); /* Return immediately if an error occurs translating a hardware keycode to a keyval. */ if (keycode < 0 || keylocation < 0) return TRUE; (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postKeyEventID, (jint) AWT_KEY_PRESSED, (jlong) event->time, keyevent_state_to_awt_mods (event), keycode, keyevent_to_awt_keychar (event), keylocation); /* FIXME: generation of key typed events needs to be moved to GtkComponentPeer.postKeyEvent. If the key in a key press event is not an "action" key (KeyEvent.isActionKey) and is not a modifier key, then it should generate a key typed event. */ return TRUE;}static gbooleankey_release_cb (GtkWidget *widget __attribute__((unused)), GdkEventKey *event, jobject peer){ jint keycode; jint keylocation; keycode = keysym_to_awt_keycode (event); keylocation = keysym_to_awt_keylocation (event); /* Return immediately if an error occurs translating a hardware keycode to a keyval. */ if (keycode < 0 || keylocation < 0) return TRUE; (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postKeyEventID, (jint) AWT_KEY_RELEASED, (jlong) event->time, keyevent_state_to_awt_mods (event), keycode, keyevent_to_awt_keychar (event), keylocation); return TRUE;}/* Union used for type punning. */union extents_union{ guchar **gu_extents; unsigned long **extents;};union atom_list_union{ guchar **gu_extents; Atom **atom_list;};JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_create (JNIEnv *env, jobject obj, jint type, jboolean decorated, jobject parent){ GtkWidget *window_widget; GtkWindow *window; void *window_parent; GtkWidget *fixed; gdk_threads_enter (); NSA_SET_GLOBAL_REF (env, obj); window_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = GTK_WINDOW (window_widget); /* Keep this window in front of its parent, if it has one. */ if (parent) { window_parent = NSA_GET_PTR (env, parent); gtk_window_set_transient_for (window, GTK_WINDOW(window_parent)); } gtk_window_set_decorated (window, decorated); gtk_window_set_type_hint (window, type); gtk_window_group_add_window (cp_gtk_global_window_group, window); fixed = gtk_fixed_new (); gtk_container_add (GTK_CONTAINER (window_widget), fixed); gtk_widget_show (fixed); NSA_SET_PTR (env, obj, window_widget); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetTitle (JNIEnv *env, jobject obj, jstring title){ const char *c_title; void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); c_title = (*env)->GetStringUTFChars (env, title, NULL); gtk_window_set_title (GTK_WINDOW (ptr), c_title); (*env)->ReleaseStringUTFChars (env, title, c_title); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable (JNIEnv *env, jobject obj, jboolean resizable){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gtk_window_set_resizable (GTK_WINDOW (ptr), resizable); g_object_set (G_OBJECT (ptr), "allow-shrink", resizable, NULL); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal (JNIEnv *env, jobject obj, jboolean modal){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gtk_window_set_modal (GTK_WINDOW (ptr), modal); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNative (JNIEnv *env, jobject obj, jboolean visible){ gdk_threads_enter (); Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked (env, obj, visible); gdk_flush (); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked (JNIEnv *env, jobject obj, jboolean visible){ void *ptr; ptr = NSA_GET_PTR (env, obj); if (visible) gtk_widget_show (GTK_WIDGET (ptr)); else gtk_widget_hide (GTK_WIDGET (ptr));}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals (JNIEnv *env, jobject obj){ void *ptr; jobject *gref; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gref = NSA_GET_GLOBAL_REF (env, obj); g_signal_connect (G_OBJECT (ptr), "delete-event", G_CALLBACK (window_delete_cb), *gref); g_signal_connect (G_OBJECT (ptr), "destroy-event", G_CALLBACK (window_destroy_cb), *gref); g_signal_connect (G_OBJECT (ptr), "show", G_CALLBACK (window_show_cb), *gref); g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus", G_CALLBACK (window_focus_state_change_cb), *gref); g_signal_connect (G_OBJECT (ptr), "focus-in-event", G_CALLBACK (window_focus_in_cb), *gref); g_signal_connect (G_OBJECT (ptr), "focus-out-event", G_CALLBACK (window_focus_out_cb), *gref); g_signal_connect (G_OBJECT (ptr), "window-state-event", G_CALLBACK (window_window_state_cb), *gref); g_signal_connect (G_OBJECT (ptr), "property-notify-event", G_CALLBACK (window_property_changed_cb), *gref); g_signal_connect_after (G_OBJECT (ptr), "realize", G_CALLBACK (realize_cb), *gref); g_signal_connect (G_OBJECT (ptr), "key-press-event", G_CALLBACK (key_press_cb), *gref); g_signal_connect (G_OBJECT (ptr), "key-release-event", G_CALLBACK (key_release_cb), *gref); g_signal_connect_after (G_OBJECT (ptr), "window-state-event", G_CALLBACK (window_window_state_cb), *gref); g_signal_connect (G_OBJECT (ptr), "configure-event", G_CALLBACK (window_configure_cb), *gref); cp_gtk_component_connect_expose_signals (ptr, gref); cp_gtk_component_connect_mouse_signals (ptr, gref); /* FIXME: override focus signals here to prevent child fixed repaint? */ gdk_threads_leave ();}/* Realize the window here so that its frame extents are known now. That way Window.pack can operate with the accurate insets returned by the window manager rather than the default estimates. */JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_realize (JNIEnv *env, jobject obj){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gtk_widget_realize (GTK_WIDGET (ptr)); gdk_threads_leave ();}JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toBack (JNIEnv *env, jobject obj){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gdk_window_lower (GTK_WIDGET (ptr)->window); gdk_flush (); gdk_threads_leave ();}JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env, jobject obj){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); gdk_window_raise (GTK_WIDGET (ptr)->window); gdk_flush (); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize (JNIEnv *env, jobject obj, jint width, jint height){ void *ptr; gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); /* Avoid GTK runtime assertion failures. */ width = (width < 1) ? 1 : width; height = (height < 1) ? 1 : height; gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height){ gdk_threads_enter (); Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked (env, obj, x, y, width, height); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height){ void *ptr; ptr = NSA_GET_PTR (env, obj); /* Avoid GTK runtime assertion failures. */ width = (width < 1) ? 1 : width; height = (height < 1) ? 1 : height; gtk_window_move (GTK_WINDOW(ptr), x, y); /* The call to gdk_window_move is needed in addition to the call to gtk_window_move. If gdk_window_move isn't called, then the following set of operations doesn't give the expected results: 1. show a window 2. manually move it to another position on the screen 3. hide the window 4. reposition the window with Component.setLocation 5. show the window Instead of being at the position set by setLocation, the window is reshown at the position to which it was moved manually. */ if (GTK_WIDGET (ptr)->window != NULL) gdk_window_move (GTK_WIDGET (ptr)->window, x, y); /* Need to change the widget's request size. */ gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); /* Also need to call gtk_window_resize. If the resize is requested by the program and the window's "resizable" property is true then the size request will not be honoured. */ gtk_window_resize (GTK_WINDOW (ptr), width, height);}static voidwindow_get_frame_extents (GtkWidget *window, int *top, int *left, int *bottom, int *right){ unsigned long *extents = NULL; union extents_union gu_ex; /* Guess frame extents in case _NET_FRAME_EXTENTS is not supported. */ if (gtk_window_get_decorated (GTK_WINDOW (window))) { *top = 23; *left = 6; *bottom = 6; *right = 6; } else { *top = 0; *left = 0; *bottom = 0; *right = 0; } /* Request that the window manager set window's _NET_FRAME_EXTENTS property. */ request_frame_extents (window); /* Attempt to retrieve window's frame extents. */ gu_ex.extents = &extents; if (gdk_property_get (window->window, gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE), gdk_atom_intern ("CARDINAL", FALSE), 0, sizeof (unsigned long) * 4, FALSE, NULL, NULL, NULL, gu_ex.gu_extents)) { *left = extents [0]; *right = extents [1]; *top = extents [2]; *bottom = extents [3]; }}static Atom extents_atom = 0;/* Requests that the window manager set window's _NET_FRAME_EXTENTS property. */static voidrequest_frame_extents (GtkWidget *window){ const char *request_str = "_NET_REQUEST_FRAME_EXTENTS"; GdkAtom request_extents = gdk_atom_intern (request_str, FALSE); /* Check if the current window manager supports _NET_REQUEST_FRAME_EXTENTS. */ if (gdk_net_wm_supports (request_extents)) { GdkDisplay *display = gtk_widget_get_display (window); Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); GdkWindow *root_window = gdk_get_default_root_window (); Window xroot_window = GDK_WINDOW_XID (root_window); Atom extents_request_atom = gdk_x11_get_xatom_by_name_for_display (display, request_str); XEvent xevent; XEvent notify_xevent; unsigned long window_id = GDK_WINDOW_XID (GDK_DRAWABLE(window->window)); if (!extents_atom) { const char *extents_str = "_NET_FRAME_EXTENTS"; extents_atom = gdk_x11_get_xatom_by_name_for_display (display, extents_str); } xevent.xclient.type = ClientMessage; xevent.xclient.message_type = extents_request_atom; xevent.xclient.display = xdisplay; xevent.xclient.window = window_id; xevent.xclient.format = 32; xevent.xclient.data.l[0] = 0; xevent.xclient.data.l[1] = 0; xevent.xclient.data.l[2] = 0; xevent.xclient.data.l[3] = 0; xevent.xclient.data.l[4] = 0; XSendEvent (xdisplay, xroot_window, False, (SubstructureRedirectMask | SubstructureNotifyMask), &xevent); XIfEvent(xdisplay, ¬ify_xevent, property_notify_predicate, (XPointer) &window_id); }}static Boolproperty_notify_predicate (Display *xdisplay __attribute__((unused)), XEvent *event, XPointer window_id){ unsigned long *window = (unsigned long *) window_id; if (event->xany.type == PropertyNotify && event->xany.window == *window && event->xproperty.atom == extents_atom) return True; else return False;}static gbooleanwindow_delete_cb (GtkWidget *widget __attribute__((unused)), GdkEvent *event __attribute__((unused)), jobject peer){ (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postWindowEventID, (jint) AWT_WINDOW_CLOSING, (jobject) NULL, (jint) 0); /* Prevents that the Window dissappears ("destroy" not being signalled). This is necessary because it should be up to a WindowListener implementation how the AWT Frame responds to close requests. */ return TRUE;}static voidwindow_destroy_cb (GtkWidget *widget __attribute__((unused)), GdkEvent *event __attribute__((unused)), jobject peer){ (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postWindowEventID,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -