📄 gnu_java_awt_peer_gtk_gdkgraphics.c
字号:
/* gdkgraphics.c Copyright (C) 1999 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */#include "gtkpeer.h"#include "gdkfont.h"#include "gnu_java_awt_peer_gtk_GdkGraphics.h"#include <gdk/gdkprivate.h>#include <gdk/gdkx.h>static jmethodID initComponentGraphicsUnlockedID;voidcp_gtk_graphics_init_jni (void){ jclass gdkgraphics; gdkgraphics = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), "gnu/java/awt/peer/gtk/GdkGraphics"); initComponentGraphicsUnlockedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gdkgraphics, "initComponentGraphicsUnlocked", "()V");}struct state_table *cp_gtk_native_graphics_state_table;static struct state_table *native_graphics_global_ref_table;#define NSA_GLOBAL_G_INIT(env, clazz) \ native_graphics_global_ref_table = cp_gtk_init_state_table (env, clazz)#define NSA_GET_GLOBAL_G_REF(env, obj) \ cp_gtk_get_state (env, obj, native_graphics_global_ref_table)#define NSA_SET_GLOBAL_G_REF(env, obj) \ do {jobject *globRefPtr; \ globRefPtr = (jobject *) malloc (sizeof (jobject)); \ *globRefPtr = (*env)->NewGlobalRef (env, obj); \ cp_gtk_set_state (env, obj, native_graphics_global_ref_table, (void *)globRefPtr);} while (0)#define NSA_DEL_GLOBAL_G_REF(env, obj) \ do {jobject *globRefPtr = cp_gtk_get_state (env, obj, native_graphics_global_ref_table); \ cp_gtk_remove_state_slot (env, obj, native_graphics_global_ref_table); \ (*env)->DeleteGlobalRef (env, *globRefPtr); \ free (globRefPtr);} while (0)JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initStaticState (JNIEnv *env, jclass clazz){ gdk_threads_enter(); NSA_G_INIT (env, clazz); NSA_GLOBAL_G_INIT (env, clazz); gdk_threads_leave();}#define GDK_STABLE_IS_PIXMAP(d) (GDK_IS_PIXMAP(d))static GdkPoint *translate_points (JNIEnv *env, jintArray xpoints, jintArray ypoints, jint npoints, jint x_offset, jint y_offset);static void realize_cb (GtkWidget *widget, jobject jgraphics);JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_copyState (JNIEnv *env, jobject obj, jobject old){ struct graphics *g = NULL; struct graphics *g_old = NULL; gdk_threads_enter (); g = (struct graphics *) g_malloc (sizeof (struct graphics)); g_old = (struct graphics *) NSA_GET_G_PTR (env, old); *g = *g_old; g->gc = gdk_gc_new (g->drawable); gdk_gc_copy (g->gc, g_old->gc); if (GDK_STABLE_IS_PIXMAP (g->drawable)) g_object_ref (g->drawable); else /* GDK_IS_WINDOW (g->drawable) */ g_object_ref (g->drawable); g_object_ref (g->cm); NSA_SET_G_PTR (env, obj, g); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initState__II (JNIEnv *env, jobject obj, jint width, jint height){ struct graphics *g = NULL; gdk_threads_enter (); g = (struct graphics *) g_malloc (sizeof (struct graphics)); g->x_offset = g->y_offset = 0; g->drawable = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, gdk_rgb_get_visual ()->depth); g->cm = gdk_rgb_get_colormap (); g_object_ref (g->cm); g->gc = gdk_gc_new (g->drawable); NSA_SET_G_PTR (env, obj, g); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initFromImage (JNIEnv *env, jobject obj, jobject source){ struct graphics *g = NULL; GdkPixmap *pixmap = NULL; gdk_threads_enter (); pixmap = cp_gtk_image_get_pixmap (env, source); g_assert(pixmap != NULL); g_object_ref (pixmap); g = (struct graphics *) g_malloc (sizeof (struct graphics)); g->x_offset = g->y_offset = 0; g->drawable = (GdkDrawable *)pixmap; g->cm = gdk_drawable_get_colormap (g->drawable); g_object_ref (g->cm); g->gc = gdk_gc_new (g->drawable); NSA_SET_G_PTR (env, obj, g); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initStateUnlocked (JNIEnv *env, jobject obj, jobject peer){ struct graphics *g = NULL; void *ptr = NULL; GtkWidget *widget = NULL; GdkColor color; g = (struct graphics *) g_malloc (sizeof (struct graphics)); ptr = NSA_GET_PTR (env, peer); g->x_offset = 0; g->y_offset = 0; widget = GTK_WIDGET (ptr); g->drawable = (GdkDrawable *) widget->window; g_object_ref (g->drawable); g->cm = gtk_widget_get_colormap (widget); g_object_ref (g->cm); g->gc = gdk_gc_new (g->drawable); gdk_gc_copy (g->gc, widget->style->fg_gc[GTK_STATE_NORMAL]); color = widget->style->fg[GTK_STATE_NORMAL]; NSA_SET_G_PTR (env, obj, g);}/* copy the native state of the peer (GtkWidget *) to the native state of the graphics object */JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2 (JNIEnv *env, jobject obj, jobject peer){ gdk_threads_enter (); Java_gnu_java_awt_peer_gtk_GdkGraphics_initStateUnlocked (env, obj, peer); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_connectSignals (JNIEnv *env, jobject obj, jobject peer){ void *ptr = NULL; jobject *gref = NULL; gdk_threads_enter (); NSA_SET_GLOBAL_G_REF (env, obj); gref = NSA_GET_GLOBAL_G_REF (env, obj); ptr = NSA_GET_PTR (env, peer); g_signal_connect_after (G_OBJECT (ptr), "realize", G_CALLBACK (realize_cb), *gref); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_dispose (JNIEnv *env, jobject obj){ struct graphics *g = NULL; gdk_threads_enter (); g = (struct graphics *) NSA_DEL_G_PTR (env, obj); /* check if dispose has been called already */ if (!g) { gdk_threads_leave (); return; } XFlush (GDK_DISPLAY ()); g_object_unref (g->gc); if (GDK_STABLE_IS_PIXMAP (g->drawable)) g_object_unref (g->drawable); else /* GDK_IS_WINDOW (g->drawable) */ g_object_unref (g->drawable); g_object_unref (g->cm); g_free (g); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_translateNative (JNIEnv *env, jobject obj, jint x, jint y){ struct graphics *g = NULL; gdk_threads_enter (); g = (struct graphics *) NSA_GET_G_PTR (env, obj); g->x_offset += x; g->y_offset += y; gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_drawString (JNIEnv *env, jobject obj, jobject font, jstring str, jint x, jint y){ struct peerfont *pfont = NULL; struct graphics *g = NULL; const char *cstr = NULL; int baseline_y = 0; PangoLayoutIter *iter = NULL; gdk_threads_enter (); g = (struct graphics *) NSA_GET_G_PTR (env, obj); g_assert (g != NULL); pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, font); g_assert (pfont != NULL); cstr = (*env)->GetStringUTFChars (env, str, NULL); pango_layout_set_font_description (pfont->layout, pfont->desc); pango_layout_set_text (pfont->layout, cstr, -1); iter = pango_layout_get_iter (pfont->layout); baseline_y = pango_layout_iter_get_baseline (iter); gdk_draw_layout (g->drawable, g->gc, x + g->x_offset, y + g->y_offset - PANGO_PIXELS (baseline_y), pfont->layout); pango_layout_iter_free (iter); pango_layout_set_text (pfont->layout, "", -1); gdk_flush (); (*env)->ReleaseStringUTFChars (env, str, cstr); gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_drawLine (JNIEnv *env, jobject obj, jint x, jint y, jint x2, jint y2){ struct graphics *g = NULL; gdk_threads_enter (); g = (struct graphics *) NSA_GET_G_PTR (env, obj); gdk_draw_line (g->drawable, g->gc, x + g->x_offset, y + g->y_offset, x2 + g->x_offset, y2 + g->y_offset); gdk_flush ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -