diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 01:27:14 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 01:27:14 +0000 |
commit | a63c2657c94913d72b3cd388730d61edcb09fc69 (patch) | |
tree | 8762d1f992e2f725a6bde1ff966ed6f1e5f4f823 /libjava/jni/gtk-peer | |
parent | 6484dceb0094998183c2f8d3c8c27c6f4e53b8a9 (diff) | |
download | gcc-a63c2657c94913d72b3cd388730d61edcb09fc69.tar.gz |
Major merge with Classpath.
Removed many duplicate files.
* HACKING: Updated.x
* classpath: Imported new directory.
* standard.omit: New file.
* Makefile.in, aclocal.m4, configure: Rebuilt.
* sources.am: New file.
* configure.ac: Run Classpath configure script. Moved code around
to support. Disable xlib AWT peers (temporarily).
* Makefile.am (SUBDIRS): Added 'classpath'
(JAVAC): Removed.
(AM_CPPFLAGS): Added more -I options.
(BOOTCLASSPATH): Simplified.
Completely redid how sources are built.
Include sources.am.
* include/Makefile.am (tool_include__HEADERS): Removed jni.h.
* include/jni.h: Removed (in Classpath).
* scripts/classes.pl: Updated to look at built classes.
* scripts/makemake.tcl: New file.
* testsuite/libjava.jni/jni.exp (gcj_jni_compile_c_to_so): Added
-I options.
(gcj_jni_invocation_compile_c_to_binary): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102082 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/jni/gtk-peer')
43 files changed, 0 insertions, 15667 deletions
diff --git a/libjava/jni/gtk-peer/gdkfont.h b/libjava/jni/gtk-peer/gdkfont.h deleted file mode 100644 index 1ed08582f45..00000000000 --- a/libjava/jni/gtk-peer/gdkfont.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef __GDKFONT_H__ -#define __GDKFONT_H__ - -/* gdkfont.h -- Some global stuff related to fonts and glyphs - Copyright (C) 2003 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gtkpeer.h" - -#include <pango/pango.h> -#include <pango/pango-context.h> -#include <pango/pango-fontmap.h> -#include <pango/pangoft2.h> - -extern struct state_table *native_font_state_table; -extern struct state_table *native_glyphvector_state_table; -extern struct state_table *native_text_layout_state_table; - -#define NSA_FONT_INIT(env, clazz) \ - native_font_state_table = init_state_table (env, clazz) - -#define NSA_GET_FONT_PTR(env, obj) \ - get_state (env, obj, native_font_state_table) - -#define NSA_SET_FONT_PTR(env, obj, ptr) \ - set_state (env, obj, native_font_state_table, (void *)ptr) - -#define NSA_DEL_FONT_PTR(env, obj) \ - remove_state_slot (env, obj, native_font_state_table) - - -#define NSA_GV_INIT(env, clazz) \ - native_glyphvector_state_table = init_state_table (env, clazz) - -#define NSA_GET_GV_PTR(env, obj) \ - get_state (env, obj, native_glyphvector_state_table) - -#define NSA_SET_GV_PTR(env, obj, ptr) \ - set_state (env, obj, native_glyphvector_state_table, (void *)ptr) - -#define NSA_DEL_GV_PTR(env, obj) \ - remove_state_slot (env, obj, native_glyphvector_state_table) - - -#define NSA_TEXT_LAYOUT_INIT(env, clazz) \ - native_text_layout_state_table = init_state_table (env, clazz) - -#define NSA_GET_TEXT_LAYOUT_PTR(env, obj) \ - get_state (env, obj, native_text_layout_state_table) - -#define NSA_SET_TEXT_LAYOUT_PTR(env, obj, ptr) \ - set_state (env, obj, native_text_layout_state_table, (void *)ptr) - -#define NSA_DEL_TEXT_LAYOUT_PTR(env, obj) \ - remove_state_slot (env, obj, native_text_layout_state_table) - -#define FONT_METRICS_ASCENT 0 -#define FONT_METRICS_MAX_ASCENT 1 -#define FONT_METRICS_DESCENT 2 -#define FONT_METRICS_MAX_DESCENT 3 -#define FONT_METRICS_MAX_ADVANCE 4 -#define NUM_FONT_METRICS 5 - -#define TEXT_METRICS_X_BEARING 0 -#define TEXT_METRICS_Y_BEARING 1 -#define TEXT_METRICS_WIDTH 2 -#define TEXT_METRICS_HEIGHT 3 -#define TEXT_METRICS_X_ADVANCE 4 -#define TEXT_METRICS_Y_ADVANCE 5 -#define NUM_TEXT_METRICS 6 - -#define NUM_GLYPH_METRICS 10 - -#define GLYPH_LOG_X(i) (NUM_GLYPH_METRICS * (i) ) -#define GLYPH_LOG_Y(i) (NUM_GLYPH_METRICS * (i) + 1) -#define GLYPH_LOG_WIDTH(i) (NUM_GLYPH_METRICS * (i) + 2) -#define GLYPH_LOG_HEIGHT(i) (NUM_GLYPH_METRICS * (i) + 3) - -#define GLYPH_INK_X(i) (NUM_GLYPH_METRICS * (i) + 4) -#define GLYPH_INK_Y(i) (NUM_GLYPH_METRICS * (i) + 5) -#define GLYPH_INK_WIDTH(i) (NUM_GLYPH_METRICS * (i) + 6) -#define GLYPH_INK_HEIGHT(i) (NUM_GLYPH_METRICS * (i) + 7) - -#define GLYPH_POS_X(i) (NUM_GLYPH_METRICS * (i) + 8) -#define GLYPH_POS_Y(i) (NUM_GLYPH_METRICS * (i) + 9) - -struct peerfont -{ - PangoFont *font; - PangoFontDescription *desc; - PangoContext *ctx; - PangoLayout *layout; - /* - * The GdkGraphics2D (using cairo) may store a pointer to a - * cairo_font_t here; since we want to work equally well with - * the GdkGraphics class (using GDK) we do not explicitly mention - * cairo types here; it is up to the higher level driver routine - * in GdkClasspathFontPeer.java to decide which backend functions - * to invoke. - */ - void *graphics_resource; -}; - -struct textlayout -{ - PangoLayout *pango_layout; -}; - -#endif /* __GDKFONT_H__ */ diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.c deleted file mode 100644 index 595c1a28a6e..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Native implementation of functions in GThreadNativeMethodRunner - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.h" -#include "gthread-jni.h" - -/* - * Class: GThreadNativeMethodRunner - * Method: nativeRun - * Signature: (J)V - * - * Purpose: Run the C function whose function pointer is - * - */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_nativeRun - (JNIEnv *env __attribute__((unused)), - jobject lcl_obj __attribute__((unused)), - jlong funcAddr, jlong funcArg) -{ - /* Convert the function's address back into a pointer to a C function. */ - void *(*funcPtr)(void *) = (void *(*)(void *)) (size_t)funcAddr; - - /* We do not need to worry about the return value from funcPtr(); it's - just thrown away. That is part of the g_threads spec, so no reason - to worry about returning it. */ - (void) funcPtr((void *) (size_t)funcArg); - /* Fall off the end and terminate the thread of control. */ -} - -/* Local Variables: */ -/* c-file-style: "gnu" */ -/* End: */ - - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c deleted file mode 100644 index 55a20e8bb7c..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c +++ /dev/null @@ -1,401 +0,0 @@ -/* gnu_java_awt_GdkFont.c - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gdkfont.h" -#include "gnu_java_awt_peer_gtk_GdkFontPeer.h" - -struct state_table *native_font_state_table; - -enum java_awt_font_style { - java_awt_font_PLAIN = 0, - java_awt_font_BOLD = 1, - java_awt_font_ITALIC = 2 -}; - -enum java_awt_font_baseline { - java_awt_font_ROMAN_BASELINE = 0, - java_awt_font_CENTER_BASELINE = 1, - java_awt_font_HANGING_BASELINE = 2 -}; - -static jmethodID glyphVector_ctor; -static jclass glyphVector_class; -static PangoAttrList *attrs = NULL; - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_initStaticState - (JNIEnv *env, jclass clazz) -{ - NSA_FONT_INIT (env, clazz); - - glyphVector_class = (*env)->FindClass - (env, "gnu/java/awt/peer/gtk/GdkGlyphVector"); - - glyphVector_ctor = (*env)->GetMethodID - (env, glyphVector_class, "<init>", - "([D[ILjava/awt/Font;Ljava/awt/font/FontRenderContext;)V"); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_initState - (JNIEnv *env, jobject self) -{ - struct peerfont *pfont = NULL; - gdk_threads_enter (); - g_assert (self != NULL); - pfont = (struct peerfont *) g_malloc0 (sizeof (struct peerfont)); - g_assert (pfont != NULL); - NSA_SET_FONT_PTR (env, self, pfont); - gdk_threads_leave (); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_dispose - (JNIEnv *env, jobject self) -{ - struct peerfont *pfont = NULL; - - gdk_threads_enter (); - pfont = (struct peerfont *)NSA_DEL_FONT_PTR (env, self); - g_assert (pfont != NULL); - if (pfont->layout != NULL) - g_object_unref (pfont->font); - if (pfont->font != NULL) - g_object_unref (pfont->font); - if (pfont->ctx != NULL) - g_object_unref (pfont->ctx); - if (pfont->desc != NULL) - pango_font_description_free (pfont->desc); - g_free (pfont); - gdk_threads_leave (); -} - - -JNIEXPORT jobject JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_getGlyphVector - (JNIEnv *env, jobject self, - jstring chars, - jobject font, - jobject fontRenderContext) -{ - struct peerfont *pfont = NULL; - GList *items = NULL, *i = NULL; - gchar *str = NULL; - int len, j; - double *native_extents; - int *native_codes; - jintArray java_codes = NULL; - jdoubleArray java_extents = NULL; - - gdk_threads_enter (); - - pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self); - g_assert (pfont != NULL); - - len = (*gdk_env())->GetStringUTFLength (env, chars); - str = (gchar *)(*env)->GetStringUTFChars (env, chars, NULL); - g_assert (str != NULL); - - if (attrs == NULL) - attrs = pango_attr_list_new (); - - if (len > 0 && str[len-1] == '\0') - len--; - - items = pango_itemize (pfont->ctx, str, 0, len, attrs, NULL); - - i = g_list_first (items); - - if (i == NULL) - { - java_extents = (*env)->NewDoubleArray (env, 0); - java_codes = (*env)->NewIntArray (env, 0); - } - else - { - PangoGlyphString *glyphs; - PangoItem *item = (PangoItem *)i->data; - - pango_context_set_font_description (pfont->ctx, pfont->desc); - pango_context_set_language (pfont->ctx, gtk_get_default_language()); - pango_context_load_font (pfont->ctx, pfont->desc); - - glyphs = pango_glyph_string_new (); - g_assert (glyphs != NULL); - - pango_shape (str + item->offset, item->length, - &(item->analysis), glyphs); - - if (glyphs->num_glyphs > 0) - { - int x = 0; - double scale = ((double) PANGO_SCALE); - - java_extents = (*env)->NewDoubleArray (env, glyphs->num_glyphs * NUM_GLYPH_METRICS); - java_codes = (*env)->NewIntArray (env, glyphs->num_glyphs); - native_extents = (*env)->GetDoubleArrayElements (env, java_extents, NULL); - native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL); - - for (j = 0; j < glyphs->num_glyphs; ++j) - { - PangoRectangle ink; - PangoRectangle logical; - PangoGlyphGeometry *geom = &glyphs->glyphs[j].geometry; - - pango_font_get_glyph_extents (pfont->font, - glyphs->glyphs[j].glyph, - &ink, &logical); - - native_codes[j] = glyphs->glyphs[j].glyph; - - native_extents[ GLYPH_LOG_X(j) ] = (logical.x) / scale; - native_extents[ GLYPH_LOG_Y(j) ] = (- logical.y) / scale; - native_extents[ GLYPH_LOG_WIDTH(j) ] = (logical.width) / scale; - native_extents[ GLYPH_LOG_HEIGHT(j) ] = (logical.height) / scale; - - native_extents[ GLYPH_INK_X(j) ] = (ink.x) / scale; - native_extents[ GLYPH_INK_Y(j) ] = (- ink.y) / scale; - native_extents[ GLYPH_INK_WIDTH(j) ] = (ink.width) / scale; - native_extents[ GLYPH_INK_HEIGHT(j) ] = (ink.height) / scale; - - native_extents[ GLYPH_POS_X(j) ] = (x + geom->x_offset) / scale; - native_extents[ GLYPH_POS_Y(j) ] = ( - geom->y_offset) / scale; - - x += geom->width; - } - (*env)->ReleaseDoubleArrayElements (env, java_extents, native_extents, 0); - (*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0); - } - - pango_glyph_string_free (glyphs); - } - - (*env)->ReleaseStringUTFChars (env, chars, str); - - for (i = g_list_first (items); i != NULL; i = g_list_next (i)) - g_free (i->data); - - g_list_free (items); - - gdk_threads_leave (); - - return (*env)->NewObject (env, - glyphVector_class, - glyphVector_ctor, - java_extents, java_codes, - font, fontRenderContext); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics - (JNIEnv *env, jobject java_font, jdoubleArray java_metrics) -{ - struct peerfont *pfont = NULL; - jdouble *native_metrics = NULL; - PangoFontMetrics *pango_metrics; - - gdk_threads_enter(); - - pfont = (struct peerfont *) NSA_GET_FONT_PTR (env, java_font); - g_assert (pfont != NULL); - - pango_metrics - = pango_context_get_metrics (pfont->ctx, pfont->desc, - gtk_get_default_language ()); - - native_metrics - = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); - - g_assert (native_metrics != NULL); - - native_metrics[FONT_METRICS_ASCENT] - = PANGO_PIXELS (pango_font_metrics_get_ascent (pango_metrics)); - - native_metrics[FONT_METRICS_MAX_ASCENT] - = native_metrics[FONT_METRICS_ASCENT]; - - native_metrics[FONT_METRICS_DESCENT] - = PANGO_PIXELS (pango_font_metrics_get_descent (pango_metrics)); - - if (native_metrics[FONT_METRICS_DESCENT] < 0) - native_metrics[FONT_METRICS_DESCENT] - = - native_metrics[FONT_METRICS_DESCENT]; - - native_metrics[FONT_METRICS_MAX_DESCENT] - = native_metrics[FONT_METRICS_DESCENT]; - - native_metrics[FONT_METRICS_MAX_ADVANCE] - = PANGO_PIXELS (pango_font_metrics_get_approximate_char_width - (pango_metrics)); - - (*env)->ReleaseDoubleArrayElements (env, - java_metrics, - native_metrics, 0); - - pango_font_metrics_unref (pango_metrics); - - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics - (JNIEnv *env, jobject java_font, jstring str, jdoubleArray java_metrics) -{ - struct peerfont *pfont = NULL; - const char *cstr = NULL; - jdouble *native_metrics = NULL; - PangoRectangle log; - - gdk_threads_enter(); - - pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, java_font); - g_assert (pfont != NULL); - - cstr = (*env)->GetStringUTFChars (env, str, NULL); - g_assert(cstr != NULL); - - pango_layout_set_text (pfont->layout, cstr, -1); - pango_layout_get_extents (pfont->layout, NULL, &log); - - (*env)->ReleaseStringUTFChars (env, str, cstr); - pango_layout_set_text (pfont->layout, "", -1); - - native_metrics = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); - g_assert (native_metrics != NULL); - - native_metrics[TEXT_METRICS_X_BEARING] - = PANGO_PIXELS( ((double)log.x) ); - - native_metrics[TEXT_METRICS_Y_BEARING] - = PANGO_PIXELS( ((double)log.y) ); - - native_metrics[TEXT_METRICS_WIDTH] - = PANGO_PIXELS( ((double)log.width) ); - - native_metrics[TEXT_METRICS_HEIGHT] - = PANGO_PIXELS( ((double)log.height) ); - - native_metrics[TEXT_METRICS_X_ADVANCE] - = PANGO_PIXELS( ((double) (log.x + log.width)) ); - - native_metrics[TEXT_METRICS_Y_ADVANCE] - = PANGO_PIXELS( ((double) (log.y + log.height)) ); - - (*env)->ReleaseDoubleArrayElements (env, java_metrics, native_metrics, 0); - - gdk_threads_leave(); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont - (JNIEnv *env, jobject self, jstring family_name_str, jint style_int, jint size, jboolean useGraphics2D) -{ - struct peerfont *pfont = NULL; - char const *family_name = NULL; - enum java_awt_font_style style; - PangoFT2FontMap *ft2_map; - - gdk_threads_enter (); - style = (enum java_awt_font_style) style_int; - - g_assert (self != NULL); - pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self); - g_assert (pfont != NULL); - - if (pfont->ctx != NULL) - g_object_unref (pfont->ctx); - if (pfont->font != NULL) - g_object_unref (pfont->font); - if (pfont->desc != NULL) - pango_font_description_free (pfont->desc); - - pfont->desc = pango_font_description_new (); - g_assert (pfont->desc != NULL); - - family_name = (*env)->GetStringUTFChars(env, family_name_str, 0); - g_assert (family_name != NULL); - pango_font_description_set_family (pfont->desc, family_name); - (*env)->ReleaseStringUTFChars(env, family_name_str, family_name); - - - if (style & java_awt_font_BOLD) - pango_font_description_set_weight (pfont->desc, PANGO_WEIGHT_BOLD); - - if (style & java_awt_font_ITALIC) - pango_font_description_set_style (pfont->desc, PANGO_STYLE_ITALIC); - - if (useGraphics2D) - { - pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); - if (pfont->ctx == NULL) - { - ft2_map = PANGO_FT2_FONT_MAP(pango_ft2_font_map_for_display ()); - pfont->ctx = pango_ft2_font_map_create_context (ft2_map); - } - } - else - { - /* GDK uses a slightly different DPI setting. */ - pango_font_description_set_size (pfont->desc, - size * dpi_conversion_factor); - if (pfont->ctx == NULL) - pfont->ctx = gdk_pango_context_get(); - } - - g_assert (pfont->ctx != NULL); - - if (pfont->font != NULL) - { - g_object_unref (pfont->font); - pfont->font = NULL; - } - - pango_context_set_font_description (pfont->ctx, pfont->desc); - pango_context_set_language (pfont->ctx, gtk_get_default_language()); - pfont->font = pango_context_load_font (pfont->ctx, pfont->desc); - g_assert (pfont->font != NULL); - - if (pfont->layout == NULL) - pfont->layout = pango_layout_new (pfont->ctx); - g_assert (pfont->layout != NULL); - - gdk_threads_leave (); -} - - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c deleted file mode 100644 index 26e2230a7da..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c +++ /dev/null @@ -1,692 +0,0 @@ -/* 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception 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> - -#define GDK_STABLE_IS_PIXMAP(d) (GDK_IS_PIXMAP(d)) - -GdkPoint * -translate_points (JNIEnv *env, jintArray xpoints, jintArray ypoints, - jint npoints, jint x_offset, jint y_offset); -static void realize_cb (GtkWidget *widget, jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_copyState - (JNIEnv *env, jobject obj, jobject old) -{ - struct graphics *g, *g_old; - - g = (struct graphics *) malloc (sizeof (struct graphics)); - g_old = (struct graphics *) NSA_GET_PTR (env, old); - - *g = *g_old; - - gdk_threads_enter (); - - g->gc = gdk_gc_new (g->drawable); - gdk_gc_copy (g->gc, g_old->gc); - - if (GDK_STABLE_IS_PIXMAP (g->drawable)) - gdk_pixmap_ref (g->drawable); - else /* GDK_IS_WINDOW (g->drawable) */ - gdk_window_ref (g->drawable); - - gdk_colormap_ref (g->cm); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, g); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_initState__II - (JNIEnv *env, jobject obj, jint width, jint height) -{ - struct graphics *g; - - g = (struct graphics *) malloc (sizeof (struct graphics)); - g->x_offset = g->y_offset = 0; - - gdk_threads_enter (); - g->drawable = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, - gdk_rgb_get_visual ()->depth); - g->cm = gdk_rgb_get_cmap (); - gdk_colormap_ref (g->cm); - g->gc = gdk_gc_new (g->drawable); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, g); -} - -/* copy the native state of the peer (GtkWidget *) to the native state - of the graphics object */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2 - (JNIEnv *env, jobject obj, jobject peer) -{ - struct graphics *g = (struct graphics *) malloc (sizeof (struct graphics)); - void *ptr; - GtkWidget *widget; - GdkColor color; - - ptr = NSA_GET_PTR (env, peer); - g->x_offset = g->y_offset = 0; - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - g->drawable = (GdkDrawable *) widget->window; - - gdk_window_ref (g->drawable); - g->cm = gtk_widget_get_colormap (widget); - gdk_colormap_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]; - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, g); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_connectSignals - (JNIEnv *env, jobject obj, jobject peer) -{ - void *ptr; - jobject *gref; - - NSA_SET_GLOBAL_REF (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - ptr = NSA_GET_PTR (env, peer); - - gdk_threads_enter (); - - g_signal_connect_after (G_OBJECT (ptr), "realize", - G_CALLBACK (realize_cb), *gref); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_dispose - (JNIEnv *env, jobject obj) -{ - struct graphics *g; - - - g = (struct graphics *) NSA_DEL_PTR (env, obj); - - if (!g) return; /* dispose has been called more than once */ - - gdk_threads_enter (); - XFlush (GDK_DISPLAY ()); - - gdk_gc_destroy (g->gc); - - if (GDK_STABLE_IS_PIXMAP (g->drawable)) - gdk_pixmap_unref (g->drawable); - else /* GDK_IS_WINDOW (g->drawable) */ - gdk_window_unref (g->drawable); - - gdk_colormap_unref (g->cm); - - gdk_threads_leave (); - - - free (g); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_translateNative - (JNIEnv *env, jobject obj, jint x, jint y) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - g->x_offset += x; - g->y_offset += y; - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_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; - const char *cstr; - int baseline_y; - PangoLayoutIter *iter; - - g = (struct graphics *) NSA_GET_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); - - gdk_threads_enter (); - - 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 (); - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, str, cstr); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawLine - (JNIEnv *env, jobject obj, jint x, jint y, jint x2, jint y2) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - 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 (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_fillRect - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gdk_draw_rectangle (g->drawable, g->gc, TRUE, - x + g->x_offset, y + g->y_offset, width, height); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawRect - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_draw_rectangle (g->drawable, g->gc, FALSE, - x + g->x_offset, y + g->y_offset, width, height); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_copyArea - (JNIEnv *env, jobject obj, jint x, jint y, - jint width, jint height, jint dx, jint dy) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_window_copy_area ((GdkWindow *)g->drawable, - g->gc, - x + g->x_offset + dx, y + g->y_offset + dy, - (GdkWindow *)g->drawable, - x + g->x_offset, y + g->y_offset, - width, height); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_copyPixmap - (JNIEnv *env, jobject obj, jobject offscreen, - jint x, jint y, jint width, jint height) -{ - struct graphics *g1, *g2; - - g1 = (struct graphics *) NSA_GET_PTR (env, obj); - g2 = (struct graphics *) NSA_GET_PTR (env, offscreen); - - gdk_threads_enter (); - gdk_window_copy_area ((GdkWindow *)g1->drawable, - g1->gc, - x + g1->x_offset, y + g1->y_offset, - (GdkWindow *)g2->drawable, - 0 + g2->x_offset, 0 + g2->y_offset, - width, height); - gdk_flush (); - gdk_threads_leave (); -} - -static void flip_pixbuf (GdkPixbuf *pixbuf, - jboolean flip_x, - jboolean flip_y, - jint width, - jint height) -{ - gint src_rs; - guchar *src_pix; - - src_rs = gdk_pixbuf_get_rowstride (pixbuf); - src_pix = gdk_pixbuf_get_pixels (pixbuf); - - if (flip_x) - { - gint i, channels; - guchar buf[4]; - - channels = gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3; - - for (i = 0; i < height; i++) - { - guchar *left = src_pix + i * src_rs; - guchar *right = left + channels * (width - 1); - while (left < right) - { - g_memmove (buf, left, channels); - g_memmove (left, right, channels); - g_memmove (right, buf, channels); - left += channels; - right -= channels; - } - } - } - - if (flip_y) - { - guchar *top = src_pix; - guchar *bottom = top + (height - 1) * src_rs; - gpointer buf = g_malloc (src_rs); - - while (top < bottom) - { - g_memmove (buf, top, src_rs); - g_memmove (top, bottom, src_rs); - g_memmove (bottom, buf, src_rs); - top += src_rs; - bottom -= src_rs; - } - - g_free (buf); - } -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_copyAndScalePixmap - (JNIEnv *env, jobject obj, jobject offscreen, jboolean flip_x, jboolean flip_y, - jint src_x, jint src_y, jint src_width, jint src_height, - jint dest_x, jint dest_y, jint dest_width, jint dest_height) -{ - struct graphics *g1, *g2; - GdkPixbuf *buf_src, *buf_dest; - - g1 = (struct graphics *) NSA_GET_PTR (env, obj); - g2 = (struct graphics *) NSA_GET_PTR (env, offscreen); - - gdk_threads_enter (); - - buf_src = gdk_pixbuf_get_from_drawable (NULL, - g2->drawable, - g2->cm, - src_x, - src_y, - 0, - 0, - src_width, - src_height); - - buf_dest = gdk_pixbuf_scale_simple (buf_src, - dest_width, - dest_height, - GDK_INTERP_BILINEAR); - - if (flip_x || flip_y) - { - flip_pixbuf (buf_dest, flip_x, flip_y, dest_width, dest_height); - } - - gdk_pixbuf_render_to_drawable (buf_dest, - g1->drawable, - g1->gc, - 0, - 0, - dest_x, - dest_y, - dest_width, - dest_height, - GDK_RGB_DITHER_NORMAL, - 0, - 0); - - g_object_unref (G_OBJECT (buf_src)); - g_object_unref (G_OBJECT (buf_dest)); - - gdk_threads_leave (); -} - - - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_clearRect - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - GdkGCValues saved; - GtkWidget *widget; - union widget_union w; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (!g) - { - gdk_threads_leave (); - return; - } - if (GDK_IS_WINDOW (g->drawable)) - { - w.widget = &widget; - gdk_window_get_user_data (GDK_WINDOW (g->drawable), w.void_widget); - if (widget == NULL || !GTK_IS_EVENT_BOX (widget)) - gdk_window_clear_area ((GdkWindow *) g->drawable, - x + g->x_offset, y + g->y_offset, - width, height); - } - else - { - gdk_gc_get_values (g->gc, &saved); - gdk_gc_set_foreground (g->gc, &(saved.background)); - gdk_draw_rectangle (g->drawable, g->gc, TRUE, - x + g->x_offset, y + g->y_offset, width, height); - gdk_gc_set_foreground (g->gc, &(saved.foreground)); - } - - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_setFunction - (JNIEnv *env, jobject obj, jint func) -{ - struct graphics *g; - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_gc_set_function (g->gc, func); - gdk_threads_leave (); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_setFGColor - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor color; - struct graphics *g; - - color.red = red << 8; - color.green = green << 8; - color.blue = blue << 8; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_color_alloc (g->cm, &color); - gdk_gc_set_foreground (g->gc, &color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawArc - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height, - jint angle1, jint angle2) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_draw_arc (g->drawable, g->gc, FALSE, - x + g->x_offset, y + g->y_offset, - width, height, angle1 << 6, angle2 << 6); - gdk_flush (); - gdk_threads_leave (); -} - -GdkPoint * -translate_points (JNIEnv *env, jintArray xpoints, jintArray ypoints, - jint npoints, jint x_offset, jint y_offset) -{ - GdkPoint *points; - jint *x, *y; - int i; - - /* allocate one more point than necessary, in case we need to tack - on an extra due to the semantics of Java polygons. */ - points = g_malloc (sizeof (GdkPoint) * (npoints + 1)); - - x = (*env)->GetIntArrayElements (env, xpoints, NULL); - y = (*env)->GetIntArrayElements (env, ypoints, NULL); - - for (i = 0; i < npoints; i++) - { - points[i].x = x[i] + x_offset; - points[i].y = y[i] + y_offset; - } - - (*env)->ReleaseIntArrayElements (env, xpoints, x, JNI_ABORT); - (*env)->ReleaseIntArrayElements (env, ypoints, y, JNI_ABORT); - - return points; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolyline - (JNIEnv *env, jobject obj, jintArray xpoints, jintArray ypoints, - jint npoints) -{ - struct graphics *g; - GdkPoint *points; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - points = translate_points (env, xpoints, ypoints, npoints, - g->x_offset, g->y_offset); - - gdk_threads_enter (); - gdk_draw_lines (g->drawable, g->gc, points, npoints); - gdk_flush (); - gdk_threads_leave (); - - g_free (points); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolygon - (JNIEnv *env, jobject obj, jintArray xpoints, jintArray ypoints, - jint npoints) -{ - struct graphics *g; - GdkPoint *points; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - points = translate_points (env, xpoints, ypoints, npoints, - g->x_offset, g->y_offset); - - /* make sure the polygon is closed, per Java semantics. - if it's not, we close it. */ - if (points[0].x != points[npoints-1].x || points[0].y != points[npoints-1].y) - points[npoints++] = points[0]; - - gdk_threads_enter (); - gdk_draw_lines (g->drawable, g->gc, points, npoints); - gdk_flush (); - gdk_threads_leave (); - - g_free (points); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_fillPolygon - (JNIEnv *env, jobject obj, jintArray xpoints, jintArray ypoints, - jint npoints) -{ - struct graphics *g; - GdkPoint *points; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - points = translate_points (env, xpoints, ypoints, npoints, - g->x_offset, g->y_offset); - gdk_threads_enter (); - gdk_draw_polygon (g->drawable, g->gc, TRUE, points, npoints); - gdk_flush (); - gdk_threads_leave (); - - g_free (points); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_fillArc - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height, - jint angle1, jint angle2) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_draw_arc (g->drawable, g->gc, TRUE, - x + g->x_offset, y + g->y_offset, - width, height, angle1 << 6, angle2 << 6); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_drawOval - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_draw_arc (g->drawable, g->gc, FALSE, - x + g->x_offset, y + g->y_offset, - width, height, 0, 23040); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_fillOval - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gdk_draw_arc (g->drawable, g->gc, TRUE, - x + g->x_offset, y + g->y_offset, - width, height, 0, 23040); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics_setClipRectangle - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - struct graphics *g; - GdkRectangle rectangle; - - g = (struct graphics *) NSA_GET_PTR (env, obj); - - rectangle.x = x + g->x_offset; - rectangle.y = y + g->y_offset; - rectangle.width = width; - rectangle.height = height; - - gdk_threads_enter (); - gdk_gc_set_clip_rectangle (g->gc, &rectangle); - gdk_threads_leave (); -} - -static void realize_cb (GtkWidget *widget __attribute__ ((unused)), - jobject peer) -{ - gdk_threads_leave (); - - (*gdk_env())->CallVoidMethod (gdk_env(), peer, initComponentGraphicsID); - - NSA_DEL_GLOBAL_REF (gdk_env(), peer); - - gdk_threads_enter (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c deleted file mode 100644 index 97787387708..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c +++ /dev/null @@ -1,1621 +0,0 @@ -/* gnu_java_awt_peer_gtk_GdkGraphics2d.c - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gtkcairopeer.h" -#include "gdkfont.h" -#include "gnu_java_awt_peer_gtk_GdkGraphics2D.h" -#include <gdk/gdktypes.h> -#include <gdk/gdkprivate.h> -#include <gdk/gdkx.h> - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gdk-pixbuf/gdk-pixdata.h> - -#include <cairo-ft.h> -#include <cairo-xlib.h> - -#include <stdio.h> -#include <stdlib.h> - -struct state_table *native_graphics2d_state_table; - -#define NSA_G2D_INIT(env, clazz) \ - native_graphics2d_state_table = init_state_table (env, clazz) - -#define NSA_GET_G2D_PTR(env, obj) \ - get_state (env, obj, native_graphics2d_state_table) - -#define NSA_SET_G2D_PTR(env, obj, ptr) \ - set_state (env, obj, native_graphics2d_state_table, (void *)ptr) - -#define NSA_DEL_G2D_PTR(env, obj) \ - remove_state_slot (env, obj, native_graphics2d_state_table) - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initStaticState - (JNIEnv *env, jclass clazz) -{ - gdk_threads_enter(); - NSA_G2D_INIT (env, clazz); - gdk_threads_leave(); -} - -/* these public final constants are part of the java2d public API, so we - write them explicitly here to save fetching them from the constant pool - all the time. */ - -#ifndef min -#define min(x,y) ((x) < (y) ? (x) : (y)) -#endif - -enum java_awt_alpha_composite_rule - { - java_awt_alpha_composite_CLEAR = 1, - java_awt_alpha_composite_SRC = 2, - java_awt_alpha_composite_SRC_OVER = 3, - java_awt_alpha_composite_DST_OVER = 4, - java_awt_alpha_composite_SRC_IN = 5, - java_awt_alpha_composite_DST_IN = 6, - java_awt_alpha_composite_SRC_OUT = 7, - java_awt_alpha_composite_DST_OUT = 8, - java_awt_alpha_composite_DST = 9, - java_awt_alpha_composite_SRC_ATOP = 10, - java_awt_alpha_composite_DST_ATOP = 11, - java_awt_alpha_composite_XOR = 12 - }; - -enum java_awt_basic_stroke_join_rule - { - java_awt_basic_stroke_JOIN_MITER = 0, - java_awt_basic_stroke_JOIN_ROUND = 1, - java_awt_basic_stroke_JOIN_BEVEL = 2 - }; - -enum java_awt_basic_stroke_cap_rule - { - java_awt_basic_stroke_CAP_BUTT = 0, - java_awt_basic_stroke_CAP_ROUND = 1, - java_awt_basic_stroke_CAP_SQUARE = 2 - }; - -enum java_awt_geom_path_iterator_winding_rule - { - java_awt_geom_path_iterator_WIND_EVEN_ODD = 0, - java_awt_geom_path_iterator_WIND_NON_ZERO = 1 - }; - -enum java_awt_rendering_hints_filter - { - java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR = 0, - java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR = 1, - java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED = 2, - java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY = 3, - java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT = 4 - - }; - -static int -peer_is_disposed(JNIEnv *env, jobject obj) -{ - static jfieldID fid = NULL; - jclass cls; - jobject peer; - - return 0; - - if (fid == NULL) - { - cls = (*env)->GetObjectClass(env, obj); - fid = (*env)->GetFieldID(env, cls, "component", - "Lgnu/java/awt/peer/gtk/GtkComponentPeer;"); - } - g_assert(fid != NULL); - peer = (*env)->GetObjectField(env, obj, fid); - if (peer == NULL || NSA_GET_PTR (env, peer) != NULL) - return 0; - else - { - return 1; - } -} - - -static void -grab_current_drawable (GtkWidget *widget, GdkDrawable **draw, GdkWindow **win) -{ - g_assert (widget != NULL); - g_assert (draw != NULL); - g_assert (win != NULL); - - *win = widget->window; - - *draw = *win; - gdk_window_get_internal_paint_info (*win, draw, 0, 0); - g_object_ref (*draw); -} - - -static int -x_server_has_render_extension (void) -{ - int ev = 0, err = 0; - return (int) XRenderQueryExtension (GDK_DISPLAY (), &ev, &err); -} - -static void -init_graphics2d_as_pixbuf (struct graphics2d *gr) -{ - gint width, height; - gint bits_per_sample = 8; - gint total_channels = 4; - gboolean has_alpha = TRUE; - - g_assert (gr != NULL); - g_assert (gr->drawable != NULL); - - if (gr->debug) printf ("initializing graphics2d as pixbuf\n"); - gdk_drawable_get_size (gr->drawable, &width, &height); - gr->drawbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - has_alpha, bits_per_sample, - width, height); - g_assert (gr->drawbuf != NULL); - g_assert (gdk_pixbuf_get_bits_per_sample (gr->drawbuf) == bits_per_sample); - g_assert (gdk_pixbuf_get_n_channels (gr->drawbuf) == total_channels); - - gr->surface = cairo_surface_create_for_image ((char *) gdk_pixbuf_get_pixels (gr->drawbuf), - CAIRO_FORMAT_ARGB32, - gdk_pixbuf_get_width (gr->drawbuf), - gdk_pixbuf_get_height (gr->drawbuf), - gdk_pixbuf_get_rowstride (gr->drawbuf)); - g_assert (gr->surface != NULL); - g_assert (gr->cr != NULL); - gr->mode = MODE_DRAWABLE_NO_RENDER; - cairo_set_target_surface (gr->cr, gr->surface); -} - -static void -init_graphics2d_as_renderable (struct graphics2d *gr) -{ - Drawable draw; - Display * dpy; - Visual * vis; - - g_assert (gr != NULL); - g_assert (gr->drawable != NULL); - - gr->drawbuf = NULL; - - if (gr->debug) printf ("initializing graphics2d as renderable\n"); - draw = gdk_x11_drawable_get_xid (gr->drawable); - - dpy = gdk_x11_drawable_get_xdisplay (gr->drawable); - g_assert (dpy != NULL); - - vis = gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (gr->drawable)); - g_assert (vis != NULL); - - gr->surface = cairo_xlib_surface_create (dpy, draw, vis, - CAIRO_FORMAT_ARGB32, - DefaultColormap (dpy, DefaultScreen (dpy))); - g_assert (gr->surface != NULL); - g_assert (gr->cr != NULL); - gr->mode = MODE_DRAWABLE_WITH_RENDER; - cairo_set_target_surface (gr->cr, gr->surface); -} - -static void -begin_drawing_operation (JNIEnv *env, struct graphics2d * gr) -{ - g_assert(cairo_status (gr->cr) == CAIRO_STATUS_SUCCESS); - - switch (gr->mode) - { - case MODE_DRAWABLE_WITH_RENDER: - break; - - case MODE_DRAWABLE_NO_RENDER: - { - - gint drawable_width, drawable_height; - gint pixbuf_width, pixbuf_height; - gint width, height; - - gdk_drawable_get_size (gr->drawable, &drawable_width, &drawable_height); - pixbuf_width = gdk_pixbuf_get_width (gr->drawbuf); - pixbuf_height = gdk_pixbuf_get_height (gr->drawbuf); - width = min (drawable_width, pixbuf_width); - height = min (drawable_height, pixbuf_height); - - gdk_pixbuf_get_from_drawable (gr->drawbuf, /* destination pixbuf */ - gr->drawable, - NULL, /* colormap */ - 0, 0, 0, 0, - width, height); - - if (gr->debug) printf ("copied (%d, %d) pixels from GDK drawable to pixbuf\n", - width, height); - } - break; - - case MODE_JAVA_ARRAY: - gr->javabuf = (*env)->GetIntArrayElements (env, gr->jarray, &gr->isCopy); - gr->surface = cairo_surface_create_for_image ((char *) gr->javabuf, - CAIRO_FORMAT_ARGB32, - gr->width, - gr->height, - gr->width * 4); - g_assert(gr->surface != NULL); - g_assert(gr->cr != NULL); - cairo_set_target_surface (gr->cr, gr->surface); - break; - } -} - -static void -end_drawing_operation (JNIEnv *env, struct graphics2d * gr) -{ - g_assert(cairo_status (gr->cr) == CAIRO_STATUS_SUCCESS); - - switch (gr->mode) - { - case MODE_DRAWABLE_WITH_RENDER: - break; - - case MODE_DRAWABLE_NO_RENDER: - { - - gint drawable_width, drawable_height; - gint pixbuf_width, pixbuf_height; - gint width, height; - - gdk_drawable_get_size (gr->drawable, &drawable_width, &drawable_height); - pixbuf_width = gdk_pixbuf_get_width (gr->drawbuf); - pixbuf_height = gdk_pixbuf_get_height (gr->drawbuf); - width = min (drawable_width, pixbuf_width); - height = min (drawable_height, pixbuf_height); - - gdk_draw_pixbuf (gr->drawable, NULL, gr->drawbuf, - 0, 0, 0, 0, - width, height, - GDK_RGB_DITHER_NORMAL, 0, 0); - - if (gr->debug) printf ("copied (%d, %d) pixels from pixbuf to GDK drawable\n", - width, height); - } - break; - - case MODE_JAVA_ARRAY: - /* - * FIXME: Perhaps this should use the isCopy flag to try to avoid - * tearing down the cairo surface. - */ - cairo_surface_destroy (gr->surface); - gr->surface = NULL; - (*env)->ReleaseIntArrayElements (env, gr->jarray, gr->javabuf, JNI_COMMIT); - } -} - - -static void -update_pattern_transform (struct graphics2d *gr) -{ - double a, b, c, d, tx, ty; - cairo_matrix_t *mat = NULL; - - g_assert (gr != NULL); - if (gr->pattern == NULL) - return; - - return; - /* temporarily disabled: ambiguous behavior */ - /* cairo_get_matrix (gr->cr, &a, &b, &c, &d, &tx, &ty); */ - mat = cairo_matrix_create (); - g_assert (mat != NULL); - cairo_matrix_set_affine (mat, a, b, c, d, tx, ty); - cairo_pattern_set_matrix (gr->pattern, mat); - cairo_matrix_destroy (mat); -} - -static void -check_for_debug (struct graphics2d *gr) -{ - gr->debug = (gboolean)(getenv("DEBUGJ2D") != NULL); -} - -static void -realize_cb (GtkWidget *widget __attribute__ ((unused)), jobject peer) -{ - gdk_threads_leave (); - - (*gdk_env())->CallVoidMethod (gdk_env(), peer, initComponentGraphics2DID); - - gdk_threads_enter (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_copyState - (JNIEnv *env, jobject obj, jobject old) -{ - struct graphics2d *g = NULL, *g_old = NULL; - - gdk_threads_enter(); - g = (struct graphics2d *) malloc (sizeof (struct graphics2d)); - g_assert (g != NULL); - memset (g, 0, sizeof(struct graphics2d)); - - g_old = (struct graphics2d *) NSA_GET_G2D_PTR (env, old); - g_assert (g_old != NULL); - - if (g_old->debug) printf ("copying state from existing graphics2d\n"); - - g->debug = g_old->debug; - g->mode = g_old->mode; - - if (g_old->mode == MODE_JAVA_ARRAY) - { - g->width = g_old->width; - g->height = g_old->height; - g->jarray = (*env)->NewGlobalRef(env, g_old->jarray); - } - else - { - g->drawable = g_old->drawable; - - g_object_ref (g->drawable); - - g->cr = cairo_create(); - g_assert (g->cr != NULL); - - if (x_server_has_render_extension ()) - init_graphics2d_as_renderable (g); - else - init_graphics2d_as_pixbuf (g); - } - - cairo_surface_set_filter (g->surface, CAIRO_FILTER_FAST); - - NSA_SET_G2D_PTR (env, obj, g); - gdk_threads_leave(); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initState___3III -(JNIEnv *env, jobject obj, jintArray jarr, jint width, jint height) -{ - struct graphics2d *gr; - - gdk_threads_enter(); - gr = (struct graphics2d *) malloc (sizeof (struct graphics2d)); - g_assert (gr != NULL); - memset (gr, 0, sizeof(struct graphics2d)); - - check_for_debug (gr); - - if (gr->debug) printf ("constructing java-backed image of size (%d,%d)\n", - width, height); - - gr->cr = cairo_create(); - g_assert (gr->cr != NULL); - - gr->width = width; - gr->height = height; - gr->jarray = (*env)->NewGlobalRef(env, jarr); - gr->mode = MODE_JAVA_ARRAY; - - if (gr->debug) printf ("constructed java-backed image of size (%d,%d)\n", - width, height); - - NSA_SET_G2D_PTR (env, obj, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initState__II - (JNIEnv *env, jobject obj, jint width, jint height) -{ - struct graphics2d *gr; - - gdk_threads_enter(); - gr = (struct graphics2d *) malloc (sizeof (struct graphics2d)); - g_assert (gr != NULL); - memset (gr, 0, sizeof(struct graphics2d)); - - check_for_debug (gr); - - if (gr->debug) printf ("constructing offscreen drawable of size (%d,%d)\n", - width, height); - - gr->drawable = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, - gdk_rgb_get_visual ()->depth); - g_assert (gr->drawable != NULL); - - gr->cr = cairo_create(); - g_assert (gr->cr != NULL); - - if (x_server_has_render_extension ()) - init_graphics2d_as_renderable (gr); - else - init_graphics2d_as_pixbuf (gr); - - if (gr->debug) printf ("constructed offscreen drawable of size (%d,%d)\n", - width, height); - NSA_SET_G2D_PTR (env, obj, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable - (JNIEnv *env, jobject self, jobject other, jint x, jint y) -{ - struct graphics2d *src = NULL, *dst = NULL; - gint s_height, s_width, d_height, d_width, height, width; - cairo_matrix_t *matrix; - cairo_operator_t tmp_op; - - gdk_threads_enter(); - if (peer_is_disposed(env, self)) { gdk_threads_leave(); return; } - src = (struct graphics2d *)NSA_GET_G2D_PTR (env, other); - dst = (struct graphics2d *)NSA_GET_G2D_PTR (env, self); - g_assert (src != NULL); - g_assert (dst != NULL); - - if (src->debug) printf ("copying from offscreen drawable\n"); - - begin_drawing_operation(env, dst); - - /* gdk_flush(); */ - - gdk_drawable_get_size (src->drawable, &s_width, &s_height); - gdk_drawable_get_size (dst->drawable, &d_width, &d_height); - width = min (s_width, d_width); - height = min (s_height, d_height); - - matrix = cairo_matrix_create (); - cairo_surface_get_matrix (src->surface, matrix); - cairo_matrix_translate (matrix, (double)-x, (double)-y); - cairo_surface_set_matrix (src->surface, matrix); - - tmp_op = cairo_current_operator (dst->cr); - cairo_set_operator(dst->cr, CAIRO_OPERATOR_SRC); - cairo_show_surface (dst->cr, src->surface, width, height); - cairo_set_operator(dst->cr, tmp_op); - - cairo_matrix_translate (matrix, (double)x, (double)y); - cairo_surface_set_matrix (src->surface, matrix); - cairo_matrix_destroy (matrix); - - gdk_flush(); - - end_drawing_operation(env, dst); - - if (src->debug) printf ("copied %d x %d pixels from offscreen drawable\n", width, height); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2 - (JNIEnv *env, jobject obj, jobject peer) -{ - struct graphics2d *gr = NULL; - GtkWidget *widget = NULL; - void *ptr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - ptr = NSA_GET_PTR (env, peer); - g_assert (ptr != NULL); - - gr = (struct graphics2d *) malloc (sizeof (struct graphics2d)); - g_assert (gr != NULL); - memset (gr, 0, sizeof(struct graphics2d)); - - check_for_debug (gr); - - gr->cr = cairo_create(); - g_assert (gr->cr != NULL); - - widget = GTK_WIDGET (ptr); - g_assert (widget != NULL); - - grab_current_drawable (widget, &(gr->drawable), &(gr->win)); - g_assert (gr->drawable != NULL); - - if (x_server_has_render_extension ()) - init_graphics2d_as_renderable (gr); - else - init_graphics2d_as_pixbuf (gr); - - NSA_SET_G2D_PTR (env, obj, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_connectSignals - (JNIEnv *env, jobject obj, jobject peer) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, peer); - - gdk_threads_enter (); - - g_signal_connect_after (G_OBJECT (ptr), "realize", - G_CALLBACK (realize_cb), obj); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_dispose - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - gr = (struct graphics2d *) NSA_DEL_G2D_PTR (env, obj); - if (gr == NULL) - { - gdk_threads_leave(); - return; /* dispose has been called more than once */ - } - - if (gr->surface) - cairo_surface_destroy (gr->surface); - - cairo_destroy (gr->cr); - - if (gr->drawbuf) - g_object_unref (gr->drawbuf); - - g_object_unref (gr->drawable); - - if (gr->pattern) - cairo_pattern_destroy (gr->pattern); - - if (gr->pattern_surface) - cairo_surface_destroy (gr->pattern_surface); - - if (gr->pattern_pixels) - free (gr->pattern_pixels); - - if (gr->mode == MODE_JAVA_ARRAY) - (*env)->DeleteGlobalRef(env, gr->jarray); - - if (gr->debug) printf ("disposed of graphics2d\n"); - - free (gr); - gdk_threads_leave(); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_setGradient - (JNIEnv *env, jobject obj, - jdouble x1, jdouble y1, - jdouble x2, jdouble y2, - jint r1, jint g1, jint b1, jint a1, - jint r2, jint g2, jint b2, jint a2, - jboolean cyclic) -{ - struct graphics2d *gr = NULL; - cairo_surface_t *surf = NULL; - cairo_matrix_t *mat = NULL; - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - if (gr->debug) printf ("setGradient (%f,%f) -> (%f,%f); (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n", - x1, y1, - x2, y2, - r1, g1, b1, a1, - r2, g2, b2, a2); - - cairo_save (gr->cr); - - if (cyclic) - surf = cairo_surface_create_similar (gr->surface, CAIRO_FORMAT_ARGB32, 3, 2); - else - surf = cairo_surface_create_similar (gr->surface, CAIRO_FORMAT_ARGB32, 2, 2); - g_assert (surf != NULL); - - cairo_set_target_surface (gr->cr, surf); - - cairo_identity_matrix (gr->cr); - - cairo_set_rgb_color (gr->cr, r1 / 255.0, g1 / 255.0, b1 / 255.0); - cairo_set_alpha (gr->cr, a1 / 255.0); - cairo_rectangle (gr->cr, 0, 0, 1, 2); - cairo_fill (gr->cr); - - cairo_set_rgb_color (gr->cr, r2 / 255.0, g2 / 255.0, b2 / 255.0); - cairo_set_alpha (gr->cr, a2 / 255.0); - cairo_rectangle (gr->cr, 1, 0, 1, 2); - cairo_fill (gr->cr); - - if (cyclic) - { - cairo_set_rgb_color (gr->cr, r1 / 255.0, g1 / 255.0, b1 / 255.0); - cairo_set_alpha (gr->cr, a1 / 255.0); - cairo_rectangle (gr->cr, 2, 0, 1, 2); - cairo_fill (gr->cr); - } - - mat = cairo_matrix_create (); - g_assert (mat != NULL); - - /* - consider the vector [x2 - x1, y2 - y1] = [p,q] - - this is a line in space starting at an 'origin' x1, y1. - - it can also be thought of as a "transformed" unit vector in either the - x or y directions. we have just *drawn* our gradient as a unit vector - (well, a 2-3x unit vector) in the x dimension. so what we want to know - is which transformation turns our existing unit vector into [p,q]. - - which means solving for M in - - [p,q] = M[1,0] - - [p,q] = |a b| [1,0] - |c d| - - [p,q] = [a,c], with b = d = 0. - - what does this mean? it means that our gradient is 1-dimensional; as - you move through the x axis of our 2 or 3 pixel gradient from logical - x positions 0 to 1, the transformation of your x coordinate under the - matrix M causes you to accumulate both x and y values in fill - space. the y value of a gradient coordinate is ignored, since the - gradient is one dimensional. which is correct. - - unfortunately we want the opposite transformation, it seems, because of - the way cairo is going to use this transformation. I'm a bit confused by - that, but it seems to work right, so we take reciprocals of values and - negate offsets. oh well. - - */ - { - double a = (x2 - x1 == 0.) ? 0. : ((cyclic ? 3.0 : 2.0) / (x2 - x1)); - double c = (y2 - y1 == 0.) ? 0. : (1. / (y2 - y1)); - double dx = (x1 == 0.) ? 0. : 1. / x1; - double dy = (y1 == 0.) ? 0. : 1. / y1; - - cairo_matrix_set_affine (mat, - a, 0., - c, 0., - dx, dy); - - cairo_surface_set_matrix (surf, mat); - cairo_matrix_destroy (mat); - cairo_surface_set_filter (surf, CAIRO_FILTER_BILINEAR); - } - - /* FIXME: repeating gradients (not to mention hold gradients) don't seem to work. */ - /* cairo_surface_set_repeat (surf, cyclic ? 1 : 0); */ - - if (gr->pattern) - cairo_pattern_destroy (gr->pattern); - - if (gr->pattern_surface) - cairo_surface_destroy (gr->pattern_surface); - - if (gr->pattern_pixels) - free (gr->pattern_pixels); - - gr->pattern_pixels = NULL; - gr->pattern_surface = surf; - gr->pattern = cairo_pattern_create_for_surface(surf); - - cairo_restore (gr->cr); - cairo_set_pattern (gr->cr, gr->pattern); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_setTexturePixels - (JNIEnv *env, jobject obj, jintArray jarr, jint w, jint h, jint stride) -{ - struct graphics2d *gr = NULL; - jint *jpixels = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - - if (gr->debug) printf ("setTexturePixels (%d pixels, %dx%d, stride: %d)\n", - (*env)->GetArrayLength (env, jarr), w, h, stride); - - if (gr->pattern) - cairo_pattern_destroy (gr->pattern); - - if (gr->pattern_surface) - cairo_surface_destroy (gr->pattern_surface); - - if (gr->pattern_pixels) - free (gr->pattern_pixels); - - gr->pattern = NULL; - gr->pattern_surface = NULL; - gr->pattern_pixels = NULL; - - gr->pattern_pixels = (char *) malloc (h * stride * 4); - g_assert (gr->pattern_pixels != NULL); - - jpixels = (*env)->GetIntArrayElements (env, jarr, NULL); - g_assert (jpixels != NULL); - memcpy (gr->pattern_pixels, jpixels, h * stride * 4); - (*env)->ReleaseIntArrayElements (env, jarr, jpixels, 0); - - gr->pattern_surface = cairo_surface_create_for_image (gr->pattern_pixels, - CAIRO_FORMAT_ARGB32, - w, h, stride * 4); - g_assert (gr->pattern_surface != NULL); - cairo_surface_set_repeat (gr->pattern_surface, 1); - gr->pattern = cairo_pattern_create_for_surface (gr->pattern_surface); - g_assert (gr->pattern != NULL); - cairo_set_pattern (gr->cr, gr->pattern); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_drawPixels - (JNIEnv *env, jobject obj, jintArray java_pixels, - jint w, jint h, jint stride, jdoubleArray java_matrix) -{ - struct graphics2d *gr = NULL; - jint *native_pixels = NULL; - jdouble *native_matrix = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - - if (gr->debug) printf ("drawPixels (%d pixels, %dx%d, stride: %d)\n", - (*env)->GetArrayLength (env, java_pixels), w, h, stride); - - native_pixels = (*env)->GetIntArrayElements (env, java_pixels, NULL); - native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); - g_assert (native_pixels != NULL); - g_assert (native_matrix != NULL); - g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); - - begin_drawing_operation (env, gr); - - { - cairo_matrix_t *mat = NULL; - cairo_surface_t *surf = cairo_surface_create_for_image ((char *)native_pixels, - CAIRO_FORMAT_ARGB32, - w, h, stride * 4); - mat = cairo_matrix_create (); - cairo_matrix_set_affine (mat, - native_matrix[0], native_matrix[1], - native_matrix[2], native_matrix[3], - native_matrix[4], native_matrix[5]); - cairo_surface_set_matrix (surf, mat); - cairo_surface_set_filter (surf, cairo_surface_get_filter(gr->surface)); - cairo_show_surface (gr->cr, surf, w, h); - cairo_matrix_destroy (mat); - cairo_surface_destroy (surf); - } - - end_drawing_operation (env, gr); - - (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0); - (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); - - gdk_threads_leave(); -} - -/* passthrough methods to cairo */ - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSave - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_save\n"); - cairo_save (gr->cr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_restore\n"); - cairo_restore (gr->cr); - update_pattern_transform (gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMatrix - (JNIEnv *env, jobject obj, jdoubleArray java_matrix) -{ - struct graphics2d *gr = NULL; - jdouble *native_matrix = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - /* cairoSetMatrix was called before this graphics object's component - was realized. */ - if (gr == NULL) { gdk_threads_leave (); return; } - - native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); - g_assert (native_matrix != NULL); - g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); - - if (gr->debug) printf ("cairo_set_matrix [ %f, %f, %f, %f, %f, %f ]\n", - native_matrix[0], native_matrix[1], - native_matrix[2], native_matrix[3], - native_matrix[4], native_matrix[5]); - - { - cairo_matrix_t * mat = cairo_matrix_create (); - cairo_matrix_set_affine (mat, - native_matrix[0], native_matrix[1], - native_matrix[2], native_matrix[3], - native_matrix[4], native_matrix[5]); - cairo_set_matrix (gr->cr, mat); - cairo_matrix_destroy (mat); - } - - (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); - update_pattern_transform (gr); - gdk_threads_leave(); -} - -static void -install_font_peer(cairo_t *cr, - struct peerfont *pfont, - int debug) -{ - cairo_font_t *ft; - FT_Face face = NULL; - - g_assert(cr != NULL); - g_assert(pfont != NULL); - - if (pfont->graphics_resource == NULL) - { - face = pango_ft2_font_get_face (pfont->font); - g_assert (face != NULL); - - ft = cairo_ft_font_create_for_ft_face (face); - g_assert (ft != NULL); - - if (debug) printf ("install_font_peer made new cairo font for '%s' at %f\n", - face->family_name, - (pango_font_description_get_size (pfont->desc) / - (double)PANGO_SCALE)); - - cairo_set_font (cr, ft); - cairo_font_destroy (ft); - cairo_scale_font (cr, - (pango_font_description_get_size (pfont->desc) / - (double)PANGO_SCALE)); - ft = cairo_current_font (cr); - pfont->graphics_resource = ft; - } - else - { - if (debug) printf ("install_font_peer reused existing font resource\n"); - ft = (cairo_font_t *) pfont->graphics_resource; - cairo_set_font (cr, ft); - } -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_releasePeerGraphicsResource - (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject java_font) -{ - struct peerfont *pfont = NULL; - - g_assert(java_font != NULL); - - gdk_threads_enter(); - pfont = (struct peerfont *) NSA_GET_FONT_PTR (env, java_font); - g_assert (pfont != NULL); - if (pfont->graphics_resource != NULL) - { - cairo_font_destroy ((cairo_font_t *) pfont->graphics_resource); - pfont->graphics_resource = NULL; - } - gdk_threads_leave(); -} - -static void -paint_glyph_run(JNIEnv *env, - struct graphics2d *gr, - cairo_glyph_t **glyphs, - gint *n_glyphs, - PangoLayoutRun *run) -{ - gint i = 0; - gint x = 0, y = 0; - - g_assert (gr != NULL); - g_assert (glyphs != NULL); - g_assert (n_glyphs != NULL); - g_assert (run != NULL); - - if (run->glyphs != NULL && run->glyphs->num_glyphs > 0) - { - if (*n_glyphs < run->glyphs->num_glyphs) - { - *glyphs = g_realloc(*glyphs, - (sizeof(cairo_glyph_t) - * run->glyphs->num_glyphs)); - *n_glyphs = run->glyphs->num_glyphs; - } - - g_assert (*glyphs != NULL); - - if (gr->debug) printf ("painting %d glyphs: ", run->glyphs->num_glyphs); - - for (i = 0; i < run->glyphs->num_glyphs; ++i) - { - (*glyphs)[i].index = run->glyphs->glyphs[i].glyph; - - (*glyphs)[i].x = - ((double) (x + run->glyphs->glyphs[i].geometry.x_offset)) - / ((double) PANGO_SCALE); - - (*glyphs)[i].y = - ((double) (y + run->glyphs->glyphs[i].geometry.y_offset)) - / ((double) PANGO_SCALE); - - if (gr->debug) printf(" (%ld @ %f,%f)", - (*glyphs)[i].index, - (*glyphs)[i].x, - (*glyphs)[i].y); - - x += run->glyphs->glyphs[i].geometry.width; - } - - if (gr->debug) printf("\n"); - begin_drawing_operation (env, gr); - cairo_show_glyphs (gr->cr, *glyphs, run->glyphs->num_glyphs); - end_drawing_operation (env, gr); - } -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoDrawGlyphVector - (JNIEnv *env, jobject self, - jobject font, - jfloat x, jfloat y, jint n, - jintArray java_codes, - jfloatArray java_positions) -{ - - struct graphics2d *gr = NULL; - struct peerfont *pfont = NULL; - cairo_glyph_t *glyphs = NULL; - int *native_codes; - float *native_positions; - jint i = 0; - - g_assert (self != NULL); - g_assert (java_codes != NULL); - g_assert (java_positions != NULL); - - gdk_threads_enter (); - if (peer_is_disposed(env, self)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *)NSA_GET_G2D_PTR (env, self); - g_assert (gr != NULL); - - pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, font); - g_assert (pfont != NULL); - - install_font_peer(gr->cr, pfont, gr->debug); - - glyphs = malloc( sizeof(cairo_glyph_t) * n); - g_assert (glyphs != NULL); - - native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL); - native_positions = (*env)->GetFloatArrayElements (env, java_positions, NULL); - - for (i = 0; i < n; ++i) - { - glyphs[i].index = native_codes[i]; - glyphs[i].x = x + native_positions[ 2*i ]; - glyphs[i].y = y + native_positions[ 2*i + 1]; - } - - (*env)->ReleaseFloatArrayElements (env, java_positions, native_positions, 0); - (*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0); - - begin_drawing_operation (env, gr); - cairo_show_glyphs (gr->cr, glyphs, n); - end_drawing_operation (env, gr); - - gdk_threads_leave (); - free(glyphs); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoDrawGdkTextLayout - (JNIEnv *env, jobject self, jobject java_layout, jfloat x, jfloat y) -{ - /* - * FIXME: Some day we expect either cairo or pango will know how to make - * a pango layout paint to a cairo surface. that day is not yet here. - */ - - struct graphics2d *gr = NULL; - struct textlayout *tl = NULL; - PangoLayoutIter *i = NULL; - PangoLayoutRun *run = NULL; - cairo_glyph_t *glyphs = NULL; - gint n_glyphs = 0; - - g_assert (self != NULL); - g_assert (java_layout != NULL); - - gr = (struct graphics2d *)NSA_GET_G2D_PTR (env, self); - tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, java_layout); - - g_assert (gr != NULL); - g_assert (tl != NULL); - g_assert (tl->pango_layout != NULL); - - if (gr->debug) printf ("painting pango layout\n"); - - gdk_threads_enter (); - if (peer_is_disposed(env, self)) { gdk_threads_leave(); return; } - - i = pango_layout_get_iter (tl->pango_layout); - g_assert (i != NULL); - - cairo_translate (gr->cr, x, y); - - do - { - run = pango_layout_iter_get_run (i); - if (run != NULL) - paint_glyph_run (env, gr, &glyphs, &n_glyphs, run); - } - while (pango_layout_iter_next_run (i)); - - if (glyphs != NULL) - g_free (glyphs); - - cairo_translate (gr->cr, -x, -y); - - pango_layout_iter_free (i); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetOperator - (JNIEnv *env, jobject obj, jint op) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_operator %d\n", op); - switch ((enum java_awt_alpha_composite_rule) op) - { - case java_awt_alpha_composite_CLEAR: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_CLEAR); - break; - - case java_awt_alpha_composite_SRC: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_SRC); - break; - - case java_awt_alpha_composite_SRC_OVER: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_OVER); - break; - - case java_awt_alpha_composite_DST_OVER: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_OVER_REVERSE); - break; - - case java_awt_alpha_composite_SRC_IN: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_IN); - break; - - case java_awt_alpha_composite_DST_IN: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_IN_REVERSE); - break; - - case java_awt_alpha_composite_SRC_OUT: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_OUT); - break; - - case java_awt_alpha_composite_DST_OUT: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_OUT_REVERSE); - break; - - case java_awt_alpha_composite_DST: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_DST); - break; - - case java_awt_alpha_composite_SRC_ATOP: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_ATOP); - break; - - case java_awt_alpha_composite_DST_ATOP: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_ATOP_REVERSE); - break; - - case java_awt_alpha_composite_XOR: - cairo_set_operator (gr->cr, CAIRO_OPERATOR_XOR); - break; - } - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetRGBColor - (JNIEnv *env, jobject obj, jdouble r, jdouble g, jdouble b) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - - /* this is a very weird fact: GDK Pixbufs and RENDER drawables consider - colors in opposite pixel order. I have no idea why. thus when you - draw to a PixBuf, you must exchange the R and B components of your - color. */ - - if (gr->debug) printf ("cairo_set_rgb_color (%f, %f, %f)\n", r, g, b); - - if (gr->drawbuf) - cairo_set_rgb_color (gr->cr, b, g, r); - else - cairo_set_rgb_color (gr->cr, r, g, b); - - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetAlpha - (JNIEnv *env, jobject obj, jdouble a) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_alpha %f\n", a); - cairo_set_alpha (gr->cr, a); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetFillRule - (JNIEnv *env, jobject obj, jint rule) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - if (gr->debug) printf ("cairo_set_fill_rule %d\n", rule); - g_assert (gr != NULL); - switch ((enum java_awt_geom_path_iterator_winding_rule) rule) - { - case java_awt_geom_path_iterator_WIND_NON_ZERO: - cairo_set_fill_rule (gr->cr, CAIRO_FILL_RULE_WINDING); - break; - case java_awt_geom_path_iterator_WIND_EVEN_ODD: - cairo_set_fill_rule (gr->cr, CAIRO_FILL_RULE_EVEN_ODD); - break; - } - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetLineWidth - (JNIEnv *env, jobject obj, jdouble width) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_line_width %f\n", width); - cairo_set_line_width (gr->cr, width); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetLineCap - (JNIEnv *env, jobject obj, jint cap) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_line_cap %d\n", cap); - switch ((enum java_awt_basic_stroke_cap_rule) cap) - { - case java_awt_basic_stroke_CAP_BUTT: - cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_BUTT); - break; - - case java_awt_basic_stroke_CAP_ROUND: - cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_ROUND); - break; - - case java_awt_basic_stroke_CAP_SQUARE: - cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_SQUARE); - break; - } - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetLineJoin - (JNIEnv *env, jobject obj, jint join) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_line_join %d\n", join); - switch ((enum java_awt_basic_stroke_join_rule) join) - { - case java_awt_basic_stroke_JOIN_MITER: - cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_MITER); - break; - - case java_awt_basic_stroke_JOIN_ROUND: - cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_ROUND); - break; - - case java_awt_basic_stroke_JOIN_BEVEL: - cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_BEVEL); - break; - } - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetDash - (JNIEnv *env, jobject obj, jdoubleArray dashes, jint ndash, jdouble offset) -{ - struct graphics2d *gr = NULL; - jdouble *dasharr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_dash\n"); - dasharr = (*env)->GetDoubleArrayElements (env, dashes, NULL); - g_assert (dasharr != NULL); - cairo_set_dash (gr->cr, dasharr, ndash, offset); - (*env)->ReleaseDoubleArrayElements (env, dashes, dasharr, 0); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMiterLimit - (JNIEnv *env, jobject obj, jdouble miter) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_set_miter_limit %f\n", miter); - cairo_set_miter_limit (gr->cr, miter); - gdk_threads_leave(); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoNewPath - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - if (gr == NULL) { gdk_threads_leave (); return; } - if (gr->debug) printf ("cairo_new_path\n"); - cairo_new_path (gr->cr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoMoveTo - (JNIEnv *env, jobject obj, jdouble x, jdouble y) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_move_to (%f, %f)\n", x, y); - cairo_move_to (gr->cr, x, y); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoLineTo - (JNIEnv *env, jobject obj, jdouble x, jdouble y) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_line_to (%f, %f)\n", x, y); - cairo_line_to (gr->cr, x, y); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoCurveTo - (JNIEnv *env, jobject obj, jdouble x1, jdouble y1, jdouble x2, jdouble y2, jdouble x3, jdouble y3) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_curve_to (%f, %f), (%f, %f), (%f, %f)\n", x1, y1, x2, y2, x3, y3); - cairo_curve_to (gr->cr, x1, y1, x2, y2, x3, y3); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRelMoveTo - (JNIEnv *env, jobject obj, jdouble dx, jdouble dy) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_rel_move_to (%f, %f)\n", dx, dy); - cairo_rel_move_to (gr->cr, dx, dy); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRelLineTo - (JNIEnv *env, jobject obj, jdouble dx, jdouble dy) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_rel_line_to (%f, %f)\n", dx, dy); - cairo_rel_line_to (gr->cr, dx, dy); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRelCurveTo - (JNIEnv *env, jobject obj, jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2, jdouble dx3, jdouble dy3) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_rel_curve_to (%f, %f), (%f, %f), (%f, %f)\n", dx1, dy1, dx2, dy2, dx3, dy3); - cairo_rel_curve_to (gr->cr, dx1, dy1, dx2, dy2, dx3, dy3); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRectangle - (JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble width, jdouble height) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - if (gr == NULL) { gdk_threads_leave (); return; } - if (gr->debug) printf ("cairo_rectangle (%f, %f) (%f, %f)\n", x, y, width, height); - cairo_rectangle (gr->cr, x, y, width, height); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClosePath - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_close_path\n"); - cairo_close_path (gr->cr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoStroke - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_stroke\n"); - begin_drawing_operation (env, gr); - cairo_stroke (gr->cr); - end_drawing_operation (env, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoFill - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_fill\n"); - begin_drawing_operation (env, gr); - cairo_fill (gr->cr); - end_drawing_operation (env, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip - (JNIEnv *env, jobject obj) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - if (gr == NULL) { gdk_threads_leave (); return; } - if (gr->debug) printf ("cairo_clip\n"); - begin_drawing_operation (env, gr); - cairo_init_clip (gr->cr); - cairo_clip (gr->cr); - end_drawing_operation (env, gr); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSurfaceSetFilter - (JNIEnv *env, jobject obj, jint filter) -{ - struct graphics2d *gr = NULL; - - gdk_threads_enter(); - if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; } - - gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); - g_assert (gr != NULL); - if (gr->debug) printf ("cairo_surface_set_filter %d\n", filter); - switch ((enum java_awt_rendering_hints_filter) filter) - { - case java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR: - cairo_surface_set_filter (gr->surface, CAIRO_FILTER_NEAREST); - break; - case java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR: - cairo_surface_set_filter (gr->surface, CAIRO_FILTER_BILINEAR); - break; - case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED: - cairo_surface_set_filter (gr->surface, CAIRO_FILTER_FAST); - break; - case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT: - cairo_surface_set_filter (gr->surface, CAIRO_FILTER_NEAREST); - break; - case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY: - cairo_surface_set_filter (gr->surface, CAIRO_FILTER_BEST); - break; - } - gdk_threads_leave(); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c deleted file mode 100644 index ca9d5642eec..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c +++ /dev/null @@ -1,99 +0,0 @@ -/* gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c - Copyright (C) 2004 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gdkfont.h" -#include "gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h" - - -static gint -cmp_families (const void *a, const void *b) -{ - const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); - const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); - - return g_utf8_collate (a_name, b_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetFontFamilies -(JNIEnv *env, jobject self __attribute__((unused)), jobjectArray family_name) -{ - PangoContext *context; - PangoFontFamily **families; - int n_families, idx; - - gdk_threads_enter (); - - context = gdk_pango_context_get(); - g_assert (context != NULL); - - pango_context_list_families (context, &families, &n_families); - - qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); - - for (idx = 0; idx < n_families; idx++) - { - const char *name_tmp = pango_font_family_get_name (families[idx]); - jstring name = (*env)->NewStringUTF (env, name_tmp); - (*env)->SetObjectArrayElement (env, family_name, idx, name); - } - g_free (families); - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetNumFontFamilies -(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - PangoContext *context; - PangoFontFamily **families; - gint n_families; - jint num; - - gdk_threads_enter (); - - context = gdk_pango_context_get(); - g_assert (context != NULL); - - pango_context_list_families (context, &families, &n_families); - - num = n_families; - g_free (families); - gdk_threads_leave (); - - return num; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c deleted file mode 100644 index 6af4815622f..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c +++ /dev/null @@ -1,445 +0,0 @@ -/* gdkpixbufdecoder.c - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include <gtkpeer.h> -#include <gdk/gdk.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gdk-pixbuf/gdk-pixbuf-loader.h> - -#include <jni.h> -#include "native_state.h" -#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h" - -#include <string.h> -#include <stdlib.h> - -struct state_table *native_pixbufdecoder_state_table; - -/* Union used for type punning. */ -union env_union -{ - void **void_env; - JNIEnv **jni_env; -}; - -static JavaVM *vm; - -static jmethodID areaPreparedID; -static jmethodID areaUpdatedID; -static jmethodID dataOutputWriteID; -static jmethodID registerFormatID; - -static void -area_prepared (GdkPixbufLoader *loader, - jobject *decoder) -{ - JNIEnv *env; - union env_union e; - jint width, height; - - GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); - if (pixbuf == NULL) - return; - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - - gdk_threads_leave (); - - g_assert (decoder != NULL); - - e.jni_env = &env; - (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); - (*env)->CallVoidMethod (env, - *decoder, - areaPreparedID, - width, height); - - gdk_threads_enter (); -} - -static void -area_updated (GdkPixbufLoader *loader, - gint x, gint y, - gint width, gint height, - jobject *decoder) -{ - JNIEnv *env; - union env_union e; - jint stride_bytes, stride_pixels, n_channels, n_pixels; - jintArray jpixels; - jint *java_pixels; - guchar *gdk_pixels; - - GdkPixbuf *pixbuf_no_alpha = NULL; - GdkPixbuf *pixbuf = NULL; - -#ifndef WORDS_BIGENDIAN - int i; -#endif - - pixbuf_no_alpha = gdk_pixbuf_loader_get_pixbuf (loader); - if (pixbuf_no_alpha == NULL) - return; - - pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0); - g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); - - stride_bytes = gdk_pixbuf_get_rowstride (pixbuf); - n_channels = gdk_pixbuf_get_n_channels (pixbuf); - stride_pixels = stride_bytes / n_channels; - n_pixels = height * stride_pixels; - gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); - - e.jni_env = &env; - (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); - jpixels = (*env)->NewIntArray (env, n_pixels); - java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL); - - memcpy (java_pixels, - gdk_pixels + (y * stride_bytes), - (height * stride_bytes)); - -#ifndef WORDS_BIGENDIAN - /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ - for (i = 0; i < n_pixels; ++i) - { - java_pixels[i] = SWAPU32 ((unsigned)java_pixels[i]); - } -#endif - - g_object_unref (pixbuf); - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); - (*env)->CallVoidMethod (env, - *decoder, - areaUpdatedID, - (jint) x, (jint) y, - (jint) width, (jint) height, - jpixels, - stride_pixels); - gdk_threads_enter (); -} - -static void -closed (GdkPixbufLoader *loader __attribute__((unused)), jobject *decoder) -{ - JNIEnv *env; - union env_union e; - e.jni_env = &env; - (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); - - gdk_threads_leave (); - (*env)->DeleteGlobalRef (env, *decoder); - free (decoder); - gdk_threads_enter (); -} - - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initState - (JNIEnv *env, jobject obj) -{ - GdkPixbufLoader *loader = NULL; - jobject *decoder = NULL; - - decoder = (jobject *) malloc (sizeof (jobject)); - g_assert (decoder != NULL); - *decoder = (*env)->NewGlobalRef (env, obj); - - gdk_threads_enter (); - loader = gdk_pixbuf_loader_new (); - g_assert (loader != NULL); - g_signal_connect (loader, "area-prepared", G_CALLBACK (area_prepared), decoder); - g_signal_connect (loader, "area-updated", G_CALLBACK (area_updated), decoder); - g_signal_connect (loader, "closed", G_CALLBACK (closed), decoder); - gdk_threads_leave (); - - NSA_SET_PB_PTR (env, obj, loader); -} - -static void -query_formats (JNIEnv *env, jclass clazz) -{ - jobject jformat; - GSList *formats, *f; - GdkPixbufFormat *format; - char **ch, *name; - - jclass formatClass; - jmethodID addExtensionID; - jmethodID addMimeTypeID; - jobject string; - - formatClass = (*env)->FindClass - (env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder$ImageFormatSpec"); - - g_assert(formatClass != NULL); - - addExtensionID = (*env)->GetMethodID (env, formatClass, - "addExtension", - "(Ljava/lang/String;)V"); - - addMimeTypeID = (*env)->GetMethodID (env, formatClass, - "addMimeType", - "(Ljava/lang/String;)V"); - - formats = gdk_pixbuf_get_formats (); - - for (f = formats; f; f = f->next) - { - format = (GdkPixbufFormat *) f->data; - name = gdk_pixbuf_format_get_name(format); - - string = (*env)->NewStringUTF(env, name); - g_assert(string != NULL); - - jformat = (*env)->CallStaticObjectMethod - (env, clazz, registerFormatID, string, - (jboolean) gdk_pixbuf_format_is_writable(format)); - (*env)->DeleteLocalRef(env, string); - - g_assert(jformat != NULL); - - ch = gdk_pixbuf_format_get_extensions(format); - while (*ch) - { - string = (*env)->NewStringUTF(env, *ch); - g_assert(string != NULL); - (*env)->CallVoidMethod (env, jformat, addExtensionID, string); - (*env)->DeleteLocalRef(env, string); - ++ch; - } - - ch = gdk_pixbuf_format_get_mime_types(format); - while (*ch) - { - string = (*env)->NewStringUTF(env, *ch); - g_assert(string != NULL); - (*env)->CallVoidMethod (env, jformat, addMimeTypeID, string); - (*env)->DeleteLocalRef(env, string); - ++ch; - } - } - - g_slist_free(formats); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState - (JNIEnv *env, jclass clazz) -{ - jclass dataOutputClass; - - (*env)->GetJavaVM(env, &vm); - - areaPreparedID = (*env)->GetMethodID (env, clazz, - "areaPrepared", - "(II)V"); - - areaUpdatedID = (*env)->GetMethodID (env, clazz, - "areaUpdated", - "(IIII[II)V"); - - registerFormatID = (*env)->GetStaticMethodID - (env, clazz, - "registerFormat", - "(Ljava/lang/String;Z)" - "Lgnu/java/awt/peer/gtk/GdkPixbufDecoder$ImageFormatSpec;"); - - - dataOutputClass = (*env)->FindClass(env, "java/io/DataOutput"); - dataOutputWriteID = (*env)->GetMethodID (env, dataOutputClass, - "write", "([B)V"); - - query_formats (env, clazz); - - NSA_PB_INIT (env, clazz); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish - (JNIEnv *env, jobject obj) -{ - GdkPixbufLoader *loader = NULL; - - loader = (GdkPixbufLoader *)NSA_DEL_PB_PTR (env, obj); - if (loader == NULL) - return; - - gdk_threads_enter (); - gdk_pixbuf_loader_close (loader, NULL); - g_object_unref (loader); - gdk_threads_leave (); -} - -struct stream_save_request -{ - JNIEnv *env; - jobject *stream; -}; - -static gboolean -save_to_stream(const gchar *buf, - gsize count, - GError **error __attribute__((unused)), - gpointer data) -{ - struct stream_save_request *ssr = (struct stream_save_request *)data; - - jbyteArray jbuf; - jbyte *cbuf; - - gdk_threads_leave (); - jbuf = (*(ssr->env))->NewByteArray ((ssr->env), count); - cbuf = (*(ssr->env))->GetByteArrayElements ((ssr->env), jbuf, NULL); - memcpy (cbuf, buf, count); - (*(ssr->env))->ReleaseByteArrayElements ((ssr->env), jbuf, cbuf, 0); - (*(ssr->env))->CallVoidMethod ((ssr->env), *(ssr->stream), - dataOutputWriteID, jbuf); - gdk_threads_enter (); - return TRUE; -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_streamImage -(JNIEnv *env, jclass clazz __attribute__((unused)), - jintArray jarr, jstring jenctype, jint width, jint height, - jboolean hasAlpha, jobject stream) -{ - GdkPixbuf* pixbuf; - jint *ints; - guchar a, r, g, b, *pix, *p; - GError *err = NULL; - const char *enctype; - int i; - - struct stream_save_request ssr; - ssr.stream = &stream; - ssr.env = env; - - ints = (*env)->GetIntArrayElements (env, jarr, NULL); - pix = g_malloc(width * height * (hasAlpha ? 4 : 3)); - - enctype = (*env)->GetStringUTFChars (env, jenctype, NULL); - g_assert(enctype != NULL); - - g_assert (pix != NULL); - g_assert (ints != NULL); - - p = pix; - for (i = 0; i < width*height; ++i) - { - /* - * Java encodes pixels as integers in a predictable arithmetic order: - * 0xAARRGGBB. Since these are jints, JNI has already byte-swapped - * them for us if necessary, so they're in "our" endianness, whatever - * that is. It uses 4 bytes per pixel whether or not there's an alpha - * channel. - */ - - a = 0xff & (ints[i] >> 24); - r = 0xff & (ints[i] >> 16); - g = 0xff & (ints[i] >> 8); - b = 0xff & ints[i]; - - /* - * GDK-pixbuf has a very different storage model: - * - * - A different alpha order (alpha after colors). - * - A different packing model (no alpha -> 3-bytes-per-pixel). - * - A different "RGB" order (host memory order, not endian-neutral). - */ - - *p++ = r; - *p++ = g; - *p++ = b; - if (hasAlpha) - *p++ = a; - } - - gdk_threads_enter (); - pixbuf = gdk_pixbuf_new_from_data (pix, - GDK_COLORSPACE_RGB, - (gboolean) hasAlpha, - 8, width, height, - width * (hasAlpha ? 4 : 3), /* rowstride */ - NULL, NULL); - g_assert (pixbuf != NULL); - - g_assert(gdk_pixbuf_save_to_callback (pixbuf, - &save_to_stream, - &ssr, - enctype, - &err, NULL)); - - g_object_unref (pixbuf); - - gdk_threads_leave (); - g_free(pix); - - (*env)->ReleaseStringUTFChars (env, jenctype, enctype); - (*env)->ReleaseIntArrayElements (env, jarr, ints, 0); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpBytes - (JNIEnv *env, jobject obj, jbyteArray jarr, jint len) -{ - GdkPixbufLoader *loader = NULL; - jbyte *bytes = NULL; - - if (len < 1) - return; - - bytes = (*env)->GetByteArrayElements (env, jarr, NULL); - g_assert (bytes != NULL); - loader = (GdkPixbufLoader *)NSA_GET_PB_PTR (env, obj); - g_assert (loader != NULL); - - gdk_threads_enter (); - gdk_pixbuf_loader_write (loader, (const guchar *) bytes, len, NULL); - gdk_threads_leave (); - - (*env)->ReleaseByteArrayElements (env, jarr, bytes, 0); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c deleted file mode 100644 index e884004cb26..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c +++ /dev/null @@ -1,328 +0,0 @@ -/* gdkrobotpeer.c - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GdkRobotPeer.h" -#include <gdk/gdkx.h> -#include <X11/extensions/XTest.h> - -static int -awt_button_mask_to_num (int buttons) -{ - switch (buttons) - { - case AWT_BUTTON1_MASK: - return 1; - case AWT_BUTTON2_MASK: - return 2; - case AWT_BUTTON3_MASK: - return 3; - } - - return 0; -} - -JNIEXPORT jboolean JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_initXTest - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - GdkDisplay *display; - Display *xdisplay; - int event_basep; - int error_basep; - int majorp; - int minorp; - jboolean result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - result = XTestQueryExtension (xdisplay, - &event_basep, - &error_basep, - &majorp, - &minorp); - - gdk_threads_leave (); - - return result; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseMove - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint x, jint y) -{ - GdkDisplay *display; - Display *xdisplay; - int result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - result = XTestFakeMotionEvent (xdisplay, - -1, - x, y, CurrentTime); - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mousePress - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) -{ - GdkDisplay *display; - Display *xdisplay; - int result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - result = XTestFakeButtonEvent (xdisplay, - awt_button_mask_to_num (buttons), - True, CurrentTime); - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseRelease - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) -{ - GdkDisplay *display; - Display *xdisplay; - int result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - result = XTestFakeButtonEvent (xdisplay, - awt_button_mask_to_num (buttons), - False, CurrentTime); - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseWheel - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint wheelAmt) -{ - GdkDisplay *display; - Display *xdisplay; - int i = 0; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - if (wheelAmt < 0) - for (i = 0; i < -wheelAmt; i++) - { - XTestFakeButtonEvent (xdisplay, - 4, - True, CurrentTime); - XTestFakeButtonEvent (xdisplay, - 4, - False, CurrentTime); - } - else - for (i = 0; i < wheelAmt; i++) - { - XTestFakeButtonEvent (xdisplay, - 5, - True, CurrentTime); - XTestFakeButtonEvent (xdisplay, - 5, - False, CurrentTime); - } - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyPress - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) -{ - GdkDisplay *display; - Display *xdisplay; - GdkKeymapKey *keymap_keys = NULL; - gint n_keys = 0; - guint lookup_keyval = 0; - int result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - lookup_keyval = awt_keycode_to_keysym (keycode, AWT_KEY_LOCATION_LEFT); - - if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), - lookup_keyval, - &keymap_keys, - &n_keys)) - { - /* No matching keymap entry was found. */ - g_printerr ("No matching keymap entries were found\n"); - gdk_threads_leave (); - return; - } - - /* If n_keys > 1 then there are multiple hardware keycodes that - translate to lookup_keyval. We arbitrarily choose the first - hardware keycode from the list returned by - gdk_keymap_get_entries_for_keyval. */ - result = XTestFakeKeyEvent (xdisplay, - keymap_keys[0].keycode, - True, CurrentTime); - - g_free (keymap_keys); - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyRelease - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) -{ - GdkDisplay *display; - Display *xdisplay; - GdkKeymapKey *keymap_keys = NULL; - gint n_keys = 0; - guint lookup_keyval = 0; - int result; - - gdk_threads_enter (); - - display = gdk_display_get_default (); - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - lookup_keyval = awt_keycode_to_keysym (keycode, AWT_KEY_LOCATION_LEFT); - - if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), - lookup_keyval, - &keymap_keys, - &n_keys)) - { - /* No matching keymap entry was found. */ - g_printerr ("No matching keymap entries were found\n"); - gdk_threads_leave (); - return; - } - - /* If n_keys > 1 then there are multiple hardware keycodes that - translate to lookup_keyval. We arbitrarily choose the first - hardware keycode from the list returned by - gdk_keymap_get_entries_for_keyval. */ - result = XTestFakeKeyEvent (xdisplay, - keymap_keys[0].keycode, - False, CurrentTime); - - g_free (keymap_keys); - - XFlush (xdisplay); - gdk_threads_leave (); -} - -JNIEXPORT jintArray JNICALL -Java_gnu_java_awt_peer_gtk_GdkRobotPeer_nativeGetRGBPixels - (JNIEnv *env, jobject obj __attribute__((unused)), jint x, jint y, - jint width, jint height) -{ - jint stride_bytes, stride_pixels, n_channels, n_pixels; - jintArray jpixels; - jint *java_pixels; - guchar *gdk_pixels; - GdkPixbuf *pixbuf_no_alpha = NULL; - GdkPixbuf *pixbuf = NULL; - -#ifndef WORDS_BIGENDIAN - int i; -#endif - - gdk_threads_enter (); - - pixbuf_no_alpha = gdk_pixbuf_get_from_drawable (NULL, - gdk_get_default_root_window (), - NULL, x, y, 0, 0, - width, height); - - pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0); - g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); - - stride_bytes = gdk_pixbuf_get_rowstride (pixbuf); - n_channels = gdk_pixbuf_get_n_channels (pixbuf); - stride_pixels = stride_bytes / n_channels; - n_pixels = height * stride_pixels; - gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); - - jpixels = (*env)->NewIntArray (env, n_pixels); - java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL); - - memcpy (java_pixels, - gdk_pixels, - (height * stride_bytes)); - -#ifndef WORDS_BIGENDIAN - /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ - for (i = 0; i < n_pixels; ++i) - { - java_pixels[i] = SWAPU32 ((unsigned)java_pixels[i]); - } -#endif - - g_object_unref (pixbuf); - - (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); - - gdk_threads_leave (); - - return jpixels; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c deleted file mode 100644 index a86bb09db95..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c +++ /dev/null @@ -1,183 +0,0 @@ -/* gnu_java_awt_GdkTextLayout.c - Copyright (C) 2004 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - - -#include <jni.h> -#include <gtk/gtk.h> -#include "native_state.h" -#include "gdkfont.h" -#include "gnu_java_awt_peer_gtk_GdkTextLayout.h" - -struct state_table *native_text_layout_state_table; - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_initStaticState - (JNIEnv *env, jclass clazz) -{ - NSA_TEXT_LAYOUT_INIT (env, clazz); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_initState - (JNIEnv *env, jobject self) -{ - struct textlayout *tl; - - gdk_threads_enter (); - g_assert(self != NULL); - tl = g_malloc0 (sizeof (struct textlayout)); - g_assert(tl != NULL); - tl->pango_layout = pango_layout_new(gdk_pango_context_get()); - g_assert(tl->pango_layout != NULL); - NSA_SET_TEXT_LAYOUT_PTR (env, self, tl); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_setText - (JNIEnv *env, jobject self, jstring text) -{ - struct textlayout *tl; - gchar *str = NULL; - gint len = 0; - - gdk_threads_enter (); - g_assert(self != NULL); - g_assert(text != NULL); - - tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, self); - g_assert(tl != NULL); - g_assert(tl->pango_layout != NULL); - - len = (*env)->GetStringUTFLength (env, text); - str = (gchar *)(*env)->GetStringUTFChars (env, text, NULL); - g_assert (str != NULL); - - pango_layout_set_text (tl->pango_layout, text, len); - - (*env)->ReleaseStringUTFChars (env, text, str); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_indexToPos - (JNIEnv *env, jobject self, jint idx, jdoubleArray javaPos) -{ - struct textlayout *tl; - PangoRectangle pangoPos; - jdouble *nativePos; - - gdk_threads_enter (); - g_assert(self != NULL); - g_assert(javaPos != NULL); - - tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, self); - g_assert(tl != NULL); - g_assert(tl->pango_layout != NULL); - - g_assert((*env)->GetArrayLength (env, javaPos) == 4); - - nativePos = (*env)->GetDoubleArrayElements (env, javaPos, NULL); - - pango_layout_index_to_pos (tl->pango_layout, idx, &pangoPos); - - nativePos[0] = (jdouble) pangoPos.x; - nativePos[1] = (jdouble) pangoPos.y; - nativePos[2] = (jdouble) pangoPos.width; - nativePos[3] = (jdouble) pangoPos.height; - - (*env)->ReleaseDoubleArrayElements (env, javaPos, nativePos, 0); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_getExtents - (JNIEnv *env, jobject self, jdoubleArray javaInkExtents, jdoubleArray javaLogExtents) -{ - struct textlayout *tl; - PangoRectangle pangoInkExtents, pangoLogExtents; - jdouble *nativeInkExtents, *nativeLogExtents; - - gdk_threads_enter (); - g_assert(self != NULL); - g_assert(javaInkExtents != NULL); - g_assert(javaLogExtents != NULL); - - tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, self); - g_assert(tl != NULL); - g_assert(tl->pango_layout != NULL); - - g_assert((*env)->GetArrayLength (env, javaInkExtents) == 4); - g_assert((*env)->GetArrayLength (env, javaLogExtents) == 4); - - nativeInkExtents = (*env)->GetDoubleArrayElements (env, javaInkExtents, NULL); - nativeLogExtents = (*env)->GetDoubleArrayElements (env, javaLogExtents, NULL); - - pango_layout_get_extents (tl->pango_layout, - &pangoInkExtents, &pangoLogExtents); - - nativeInkExtents[0] = (jdouble) pangoInkExtents.x; - nativeInkExtents[1] = (jdouble) pangoInkExtents.y; - nativeInkExtents[2] = (jdouble) pangoInkExtents.width; - nativeInkExtents[3] = (jdouble) pangoInkExtents.height; - - nativeLogExtents[0] = (jdouble) pangoLogExtents.x; - nativeLogExtents[1] = (jdouble) pangoLogExtents.y; - nativeLogExtents[2] = (jdouble) pangoLogExtents.width; - nativeLogExtents[3] = (jdouble) pangoLogExtents.height; - - (*env)->ReleaseDoubleArrayElements (env, javaInkExtents, nativeInkExtents, 0); - (*env)->ReleaseDoubleArrayElements (env, javaLogExtents, nativeLogExtents, 0); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GdkTextLayout_dispose - (JNIEnv *env, jobject self) -{ - struct textlayout *tl; - - gdk_threads_enter (); - g_assert(self != NULL); - tl = (struct textlayout *) NSA_DEL_TEXT_LAYOUT_PTR (env, self); - g_assert(tl != NULL); - if (tl->pango_layout != NULL) - g_object_unref (tl->pango_layout); - g_free(tl); - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c deleted file mode 100644 index 07574ed7d96..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c +++ /dev/null @@ -1,355 +0,0 @@ -/* gtkbuttonpeer.c -- Native implementation of GtkButtonPeer - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkButtonPeer.h" - -static gboolean focus_in_cb (GtkWidget *widget, - GdkEventFocus *event, - jobject peer); -static gboolean focus_out_cb (GtkWidget *widget, - GdkEventFocus *event, - jobject peer); - -static void block_expose_events_cb (GtkWidget *widget, - jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create - (JNIEnv *env, jobject obj, jstring label) -{ - const char *c_label; - GtkWidget *eventbox; - GtkWidget *button; - - NSA_SET_GLOBAL_REF (env, obj); - - c_label = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - eventbox = gtk_event_box_new (); - button = gtk_button_new_with_label (c_label); - gtk_container_add (GTK_CONTAINER (eventbox), button); - gtk_widget_show (button); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, c_label); - NSA_SET_PTR (env, obj, eventbox); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr; - jobject *gref; - GtkWidget *button; - - ptr = NSA_GET_PTR (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - - g_signal_connect (G_OBJECT (ptr), "event", - G_CALLBACK (pre_event_handler), *gref); - - g_signal_connect (G_OBJECT (button), "event", - G_CALLBACK (pre_event_handler), *gref); - - g_signal_connect (G_OBJECT (button), "focus-in-event", - G_CALLBACK (focus_in_cb), *gref); - - g_signal_connect (G_OBJECT (button), "focus-out-event", - G_CALLBACK (focus_out_cb), *gref); - - g_signal_connect_after (G_OBJECT (button), "pressed", - G_CALLBACK (block_expose_events_cb), *gref); - - g_signal_connect_after (G_OBJECT (button), "released", - G_CALLBACK (block_expose_events_cb), *gref); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetLabel - (JNIEnv *env, jobject obj, jstring jtext) -{ - const char *text; - GtkWidget *button; - GtkWidget *label; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - text = (*env)->GetStringUTFChars (env, jtext, NULL); - - gdk_threads_enter (); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - label = gtk_bin_get_child (GTK_BIN (button)); - gtk_label_set_text (GTK_LABEL (label), text); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, jtext, text); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *button; - GtkWidget *label; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - label = gtk_bin_get_child (GTK_BIN (button)); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET(label), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetBackground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor normal_color; - GdkColor prelight_color; - GdkColor active_color; - int prelight_red; - int prelight_blue; - int prelight_green; - GtkWidget *button; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - normal_color.red = (red / 255.0) * 65535; - normal_color.green = (green / 255.0) * 65535; - normal_color.blue = (blue / 255.0) * 65535; - - /* This calculation only approximate the active color produced by - Sun's AWT. */ - active_color.red = 0.85 * (red / 255.0) * 65535; - active_color.green = 0.85 * (green / 255.0) * 65535; - active_color.blue = 0.85 * (blue / 255.0) * 65535; - - /* There is no separate prelight color in Motif. */ - prelight_red = 1.15 * (red / 255.0) * 65535; - prelight_green = 1.15 * (green / 255.0) * 65535; - prelight_blue = 1.15 * (blue / 255.0) * 65535; - - prelight_color.red = prelight_red > 65535 ? 65535 : prelight_red; - prelight_color.green = prelight_green > 65535 ? 65535 : prelight_green; - prelight_color.blue = prelight_blue > 65535 ? 65535 : prelight_blue; - - gdk_threads_enter (); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - - gtk_widget_modify_bg (button, GTK_STATE_NORMAL, &normal_color); - gtk_widget_modify_bg (button, GTK_STATE_ACTIVE, &active_color); - gtk_widget_modify_bg (button, GTK_STATE_PRELIGHT, &prelight_color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetForeground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor color; - GtkWidget *button; - GtkWidget *label; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - color.red = (red / 255.0) * 65535; - color.green = (green / 255.0) * 65535; - color.blue = (blue / 255.0) * 65535; - - gdk_threads_enter (); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - label = gtk_bin_get_child (GTK_BIN (button)); - - gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color); - gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, &color); - gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkActivate - (JNIEnv *env, jobject obj) -{ - GtkWidget *button; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - button = gtk_bin_get_child (GTK_BIN (ptr)); - gtk_widget_activate (GTK_WIDGET (button)); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetRequestFocus - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkWidget *button; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - button = gtk_bin_get_child (GTK_BIN (ptr)); - gtk_widget_grab_focus (button); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkButtonPeer_setNativeBounds - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - GtkWidget *widget, *child; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - /* We assume that -1 is a width or height and not a request for the - widget's natural size. */ - width = width < 0 ? 0 : width; - height = height < 0 ? 0 : height; - child = gtk_bin_get_child (GTK_BIN (widget)); - - if (!(width == 0 && height == 0)) - { - /* Set the event box's size request... */ - gtk_widget_set_size_request (widget, width, height); - /* ...and the button's size request... */ - gtk_widget_set_size_request (child, width, height); - /* ...and the label's size request. */ - gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (child)), width, - height); - if (widget->parent != NULL) - gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); - } - - gdk_threads_leave (); -} - -static gboolean -focus_in_cb (GtkWidget *widget __attribute((unused)), - GdkEventFocus *event __attribute((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postFocusEventID, - AWT_FOCUS_GAINED, - JNI_FALSE); - gdk_threads_enter (); - return FALSE; -} - -static gboolean -focus_out_cb (GtkWidget *widget __attribute((unused)), - GdkEventFocus *event __attribute((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postFocusEventID, - AWT_FOCUS_LOST, - JNI_FALSE); - gdk_threads_enter (); - return FALSE; -} - -static void -block_expose_events_cb (GtkWidget *widget, jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - beginNativeRepaintID); - gdk_threads_enter (); - - gdk_window_process_updates (widget->window, TRUE); - - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - endNativeRepaintID); - gdk_threads_enter (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c deleted file mode 100644 index 592cd02bb4f..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c +++ /dev/null @@ -1,60 +0,0 @@ -/* gtkcanvaspeer.c -- Native implementation of GtkCanvasPeer - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkCanvasPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCanvasPeer_create - (JNIEnv *env, jobject obj) -{ - gpointer widget; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - widget = gtk_type_new (gtk_drawing_area_get_type ()); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, widget); -} - - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.c deleted file mode 100644 index 93fab16c030..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.c +++ /dev/null @@ -1,77 +0,0 @@ -/* gtkcheckboxgrouppeer.c -- Native implementation of GtkCheckboxGroupPeer - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_dispose - (JNIEnv *env, jobject obj) -{ - /* The actual underlying widget is owned by a different class. So - we just clean up the hash table here. */ - NSA_DEL_PTR (env, obj); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_remove - (JNIEnv *env, jobject obj, jobject checkbox) -{ - GtkRadioButton *button; - void *ptr; - GSList *list; - - ptr = NSA_GET_PTR (env, checkbox); - gdk_threads_enter (); - button = GTK_RADIO_BUTTON (ptr); - - /* Update the group to point to some other widget in the group. We - have to do this because Gtk doesn't have a separate object to - represent a radio button's group. */ - for (list = gtk_radio_button_group (button); list != NULL; - list = list->next) - { - if (list->data != button) - break; - } - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, list ? list->data : NULL); -} - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c deleted file mode 100644 index 87803a7df71..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c +++ /dev/null @@ -1,76 +0,0 @@ -/* gtkmenuitempeer.c -- Native implementation of GtkMenuItemPeer - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_create - (JNIEnv *env, jobject obj, jstring label) -{ - GtkWidget *widget; - const char *str; - - NSA_SET_GLOBAL_REF (env, obj); - - str = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - widget = gtk_check_menu_item_new_with_label (str); - gtk_widget_show (widget); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, str); - - NSA_SET_PTR (env, obj, widget); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_setState - (JNIEnv *env, jobject obj, jboolean state) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (ptr), state); - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c deleted file mode 100644 index b37f3c1df57..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c +++ /dev/null @@ -1,217 +0,0 @@ -/* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer - Copyright (C) 1998, 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" - -static void item_toggled (GtkToggleButton *item, jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_create - (JNIEnv *env, jobject obj, jobject group) -{ - GtkWidget *button; - - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - if (group == NULL) - button = gtk_check_button_new_with_label (""); - else - { - void *native_group = NSA_GET_PTR (env, group); - button = gtk_radio_button_new_with_label_from_widget (native_group, ""); - if (native_group == NULL) - { - /* Set the native group so we can use the correct value the - next time around. FIXME: this doesn't work! */ - NSA_SET_PTR (env, group, button); - } - } - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, button); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr = NSA_GET_PTR (env, obj); - jobject *gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); - - gdk_threads_enter (); - - g_signal_connect (G_OBJECT (ptr), "toggled", - GTK_SIGNAL_FUNC (item_toggled), *gref); - - gdk_threads_leave (); - - /* Connect the superclass signals. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup - (JNIEnv *env, jobject obj, jobject group) -{ - GtkRadioButton *button; - void *native_group, *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - /* FIXME: we can't yet switch between a checkbutton and a - radiobutton. However, AWT requires this. For now we just - crash. */ - - button = GTK_RADIO_BUTTON (ptr); - - native_group = NSA_GET_PTR (env, group); - if (native_group == NULL) - gtk_radio_button_set_group (button, NULL); - else - gtk_radio_button_set_group (button, - gtk_radio_button_group - (GTK_RADIO_BUTTON (native_group))); - - gdk_threads_leave (); - - /* If the native group wasn't set on the new CheckboxGroup, then set - it now so that the right thing will happen with the next - radiobutton. The native state for a CheckboxGroup is a pointer - to one of the widgets in the group. We are careful to keep this - always pointing at a live widget; whenever a widget is destroyed - (or otherwise removed from the group), the CheckboxGroup peer is - notified. */ - if (native_group == NULL) - NSA_SET_PTR (env, group, native_group); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive - (JNIEnv *env, jobject obj, jboolean is_active) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ptr), is_active); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *button; - GtkWidget *label; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - button = GTK_WIDGET (ptr); - label = gtk_bin_get_child (GTK_BIN(button)); - - if (!label) - return; - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET(label), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel - (JNIEnv *env, jobject obj, jstring label) -{ - const char *c_label; - GtkWidget *label_widget; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - c_label = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - label_widget = gtk_bin_get_child (GTK_BIN (ptr)); - gtk_label_set_text (GTK_LABEL (label_widget), c_label); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, c_label); -} - -static void -item_toggled (GtkToggleButton *item, jobject peer) -{ - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postItemEventID, - peer, - item->active ? - (jint) AWT_ITEM_SELECTED : - (jint) AWT_ITEM_DESELECTED); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c deleted file mode 100644 index 030cb73d09f..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c +++ /dev/null @@ -1,207 +0,0 @@ -/* gtkchoicepeer.c -- Native implementation of GtkChoicePeer - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkChoicePeer.h" - -static void selection_changed (GtkComboBox *combobox, jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create - (JNIEnv *env, jobject obj) -{ - GtkWidget *combobox; - jobject *gref; - - NSA_SET_GLOBAL_REF (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - combobox = gtk_combo_box_new_text (); - - g_signal_connect (combobox, "changed", - G_CALLBACK (selection_changed), *gref); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, combobox); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append - (JNIEnv *env, jobject obj, jobjectArray items) -{ - gpointer ptr; - jsize count, i; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - count = (*env)->GetArrayLength (env, items); - - for (i = 0; i < count; i++) - { - jobject item; - const char *label; - - item = (*env)->GetObjectArrayElement (env, items, i); - label = (*env)->GetStringUTFChars (env, item, NULL); - - gtk_combo_box_append_text (GTK_COMBO_BOX (ptr), label); - - (*env)->ReleaseStringUTFChars (env, item, label); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd - (JNIEnv *env, jobject obj, jstring item, jint index) -{ - void *ptr; - const char *label; - - ptr = NSA_GET_PTR (env, obj); - - label = (*env)->GetStringUTFChars (env, item, 0); - - gdk_threads_enter (); - gtk_combo_box_insert_text (GTK_COMBO_BOX (ptr), index, label); - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, item, label); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), index); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkTreeModel *model; - gint count, i; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (ptr)); - count = gtk_tree_model_iter_n_children (model, NULL); - - /* First, unselect everything, to avoid problems when removing items. */ - gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), -1); - - for (i = count - 1; i >= 0; i--) { - gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), i); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_select - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), index); - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected - (JNIEnv *env, jobject obj) -{ - void *ptr; - int index; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - index = gtk_combo_box_get_active (GTK_COMBO_BOX (ptr)); - gdk_threads_leave (); - - return index; -} - -static void selection_changed (GtkComboBox *combobox, jobject peer) -{ - jstring label; - GtkTreeModel *model; - GtkTreeIter iter; - gchar *selected; - gint index; - - index = gtk_combo_box_get_active(combobox); - - if (index >= 0) - { - model = gtk_combo_box_get_model (combobox); - - gtk_combo_box_get_active_iter (combobox, &iter); - - gtk_tree_model_get (model, &iter, 0, &selected, -1); - - gdk_threads_leave (); - - label = (*gdk_env())->NewStringUTF (gdk_env(), selected); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - choicePostItemEventID, - label, - (jint) AWT_ITEM_SELECTED); - gdk_threads_enter (); - } -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c deleted file mode 100644 index b2717e8d122..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c +++ /dev/null @@ -1,183 +0,0 @@ -/* gtkclipboard.c - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkClipboard.h" - -jmethodID stringSelectionReceivedID; -jmethodID stringSelectionHandlerID; -jmethodID selectionClearID; - -void selection_received (GtkWidget *, GtkSelectionData *, guint, gpointer); -void selection_get (GtkWidget *, GtkSelectionData *, guint, guint, gpointer); -gint selection_clear (GtkWidget *, GdkEventSelection *); - -GtkWidget *clipboard; -jobject cb_obj; - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState (JNIEnv *env, - jobject obj) -{ - if (!stringSelectionReceivedID) - { - jclass gtkclipboard; - - gtkclipboard = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkClipboard"); - stringSelectionReceivedID = (*env)->GetMethodID (env, gtkclipboard, - "stringSelectionReceived", - "(Ljava/lang/String;)V"); - stringSelectionHandlerID = (*env)->GetMethodID (env, gtkclipboard, - "stringSelectionHandler", - "()Ljava/lang/String;"); - selectionClearID = (*env)->GetMethodID (env, gtkclipboard, - "selectionClear", "()V"); - } - - cb_obj = (*env)->NewGlobalRef (env, obj); - - gdk_threads_enter (); - clipboard = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - g_signal_connect (G_OBJECT(clipboard), "selection_received", - GTK_SIGNAL_FUNC (selection_received), NULL); - - g_signal_connect (G_OBJECT(clipboard), "selection_clear_event", - GTK_SIGNAL_FUNC (selection_clear), NULL); - - gtk_selection_add_target (clipboard, GDK_SELECTION_PRIMARY, - GDK_TARGET_STRING, 0); - - g_signal_connect (G_OBJECT(clipboard), "selection_get", - GTK_SIGNAL_FUNC (selection_get), NULL); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkClipboard_requestStringConversion - (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused))) -{ - gdk_threads_enter (); - gtk_selection_convert (clipboard, GDK_SELECTION_PRIMARY, - GDK_TARGET_STRING, GDK_CURRENT_TIME); - gdk_threads_leave (); -} - -void -selection_received (GtkWidget *widget __attribute__((unused)), - GtkSelectionData *selection_data __attribute__((unused)), - guint time __attribute__((unused)), - gpointer data __attribute__((unused))) -{ - /* Check to see if retrieval succeeded */ - if (selection_data->length < 0 - || selection_data->type != GDK_SELECTION_TYPE_STRING) - { - (*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, stringSelectionReceivedID, - NULL); - } - else - { - char *str = (char *) selection_data->data; - - (*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, stringSelectionReceivedID, - (*gdk_env())->NewStringUTF (gdk_env(), str)); - } - - return; -} - -void -selection_get (GtkWidget *widget __attribute__((unused)), - GtkSelectionData *selection_data, - guint info __attribute__((unused)), - guint time __attribute__((unused)), - gpointer data __attribute__((unused))) -{ - jstring jstr; - const char *utf; - jsize utflen; - - jstr = (*gdk_env())->CallObjectMethod (gdk_env(), cb_obj, - stringSelectionHandlerID); - - if (!jstr) - { - gtk_selection_data_set (selection_data, - GDK_TARGET_STRING, 8, NULL, 0); - return; - } - - utflen = (*gdk_env())->GetStringUTFLength (gdk_env(), jstr); - utf = (*gdk_env())->GetStringUTFChars (gdk_env(), jstr, NULL); - - gtk_selection_data_set (selection_data, GDK_TARGET_STRING, 8, - (const unsigned char*)utf, utflen); - - (*gdk_env())->ReleaseStringUTFChars (gdk_env(), jstr, utf); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkClipboard_selectionGet - (JNIEnv *env, jclass clazz __attribute__((unused))) -{ - GdkWindow *owner; - - gdk_threads_enter (); - - /* if we already own the clipboard, we need to tell the old data object - that we're no longer going to be using him */ - owner = gdk_selection_owner_get (GDK_SELECTION_PRIMARY); - if (owner && owner == clipboard->window) - (*env)->CallVoidMethod (env, cb_obj, selectionClearID); - - gtk_selection_owner_set (clipboard, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); - - gdk_threads_leave (); -} - -gint -selection_clear (GtkWidget *widget __attribute__((unused)), - GdkEventSelection *event __attribute__((unused))) -{ - (*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, selectionClearID); - - return TRUE; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c deleted file mode 100644 index 2b932d14bdf..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c +++ /dev/null @@ -1,1078 +0,0 @@ -/* gtkcomponentpeer.c -- Native implementation of GtkComponentPeer - Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -#include <gtk/gtkprivate.h> -#include <gdk/gdkkeysyms.h> - -static GtkWidget *find_fg_color_widget (GtkWidget *widget); -static GtkWidget *find_bg_color_widget (GtkWidget *widget); -static gboolean focus_in_cb (GtkWidget *widget, - GdkEventFocus *event, - jobject peer); -static gboolean focus_out_cb (GtkWidget *widget, - GdkEventFocus *event, - jobject peer); - -/* - * This method returns a GDK keyval that corresponds to one of the - * keysyms in the X keymap table. The return value is only used to - * determine the keyval's corresponding hardware keycode, and doesn't - * reflect an accurate translation of a Java virtual key value to a - * GDK keyval. - */ -#ifdef __GNUC__ -__inline -#endif -guint -awt_keycode_to_keysym (jint keyCode, jint keyLocation) -{ - /* GDK_A through GDK_Z */ - if (keyCode >= VK_A && keyCode <= VK_Z) - return gdk_keyval_to_lower (keyCode); - - /* GDK_0 through GDK_9 */ - if (keyCode >= VK_0 && keyCode <= VK_9) - return keyCode; - - switch (keyCode) - { - case VK_ENTER: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Enter : GDK_Return; - case VK_BACK_SPACE: - return GDK_BackSpace; - case VK_TAB: - return GDK_Tab; - case VK_CANCEL: - return GDK_Cancel; - case VK_CLEAR: - return GDK_Clear; - case VK_SHIFT: - return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Shift_L : GDK_Shift_R; - case VK_CONTROL: - return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Control_L : GDK_Control_R; - case VK_ALT: - return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Alt_L : GDK_Alt_R; - case VK_PAUSE: - return GDK_Pause; - case VK_CAPS_LOCK: - return GDK_Caps_Lock; - case VK_ESCAPE: - return GDK_Escape; - case VK_SPACE: - return GDK_space; - case VK_PAGE_UP: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Page_Up : GDK_Page_Up; - case VK_PAGE_DOWN: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Page_Down : GDK_Page_Down; - case VK_END: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_End : GDK_End; - case VK_HOME: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Home : GDK_Home; - case VK_LEFT: - return GDK_Left; - case VK_UP: - return GDK_Up; - case VK_RIGHT: - return GDK_Right; - case VK_DOWN: - return GDK_Down; - case VK_COMMA: - return GDK_comma; - case VK_MINUS: - return GDK_minus; - case VK_PERIOD: - return GDK_period; - case VK_SLASH: - return GDK_slash; - /* - case VK_0: - case VK_1: - case VK_2: - case VK_3: - case VK_4: - case VK_5: - case VK_6: - case VK_7: - case VK_8: - case VK_9: - */ - case VK_SEMICOLON: - return GDK_semicolon; - case VK_EQUALS: - return GDK_equal; - /* - case VK_A: - case VK_B: - case VK_C: - case VK_D: - case VK_E: - case VK_F: - case VK_G: - case VK_H: - case VK_I: - case VK_J: - case VK_K: - case VK_L: - case VK_M: - case VK_N: - case VK_O: - case VK_P: - case VK_Q: - case VK_R: - case VK_S: - case VK_T: - case VK_U: - case VK_V: - case VK_W: - case VK_X: - case VK_Y: - case VK_Z: - */ - case VK_OPEN_BRACKET: - return GDK_bracketleft; - case VK_BACK_SLASH: - return GDK_backslash; - case VK_CLOSE_BRACKET: - return GDK_bracketright; - case VK_NUMPAD0: - return GDK_KP_0; - case VK_NUMPAD1: - return GDK_KP_1; - case VK_NUMPAD2: - return GDK_KP_2; - case VK_NUMPAD3: - return GDK_KP_3; - case VK_NUMPAD4: - return GDK_KP_4; - case VK_NUMPAD5: - return GDK_KP_5; - case VK_NUMPAD6: - return GDK_KP_6; - case VK_NUMPAD7: - return GDK_KP_7; - case VK_NUMPAD8: - return GDK_KP_8; - case VK_NUMPAD9: - return GDK_KP_9; - case VK_MULTIPLY: - return GDK_KP_Multiply; - case VK_ADD: - return GDK_KP_Add; - /* - case VK_SEPARATER: - */ - case VK_SEPARATOR: - return GDK_KP_Separator; - case VK_SUBTRACT: - return GDK_KP_Subtract; - case VK_DECIMAL: - return GDK_KP_Decimal; - case VK_DIVIDE: - return GDK_KP_Divide; - case VK_DELETE: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Delete : GDK_Delete; - case VK_NUM_LOCK: - return GDK_Num_Lock; - case VK_SCROLL_LOCK: - return GDK_Scroll_Lock; - case VK_F1: - return GDK_F1; - case VK_F2: - return GDK_F2; - case VK_F3: - return GDK_F3; - case VK_F4: - return GDK_F4; - case VK_F5: - return GDK_F5; - case VK_F6: - return GDK_F6; - case VK_F7: - return GDK_F7; - case VK_F8: - return GDK_F8; - case VK_F9: - return GDK_F9; - case VK_F10: - return GDK_F10; - case VK_F11: - return GDK_F11; - case VK_F12: - return GDK_F12; - case VK_F13: - return GDK_F13; - case VK_F14: - return GDK_F14; - case VK_F15: - return GDK_F15; - case VK_F16: - return GDK_F16; - case VK_F17: - return GDK_F17; - case VK_F18: - return GDK_F18; - case VK_F19: - return GDK_F19; - case VK_F20: - return GDK_F20; - case VK_F21: - return GDK_F21; - case VK_F22: - return GDK_F22; - case VK_F23: - return GDK_F23; - case VK_F24: - return GDK_F24; - case VK_PRINTSCREEN: - return GDK_Print; - case VK_INSERT: - return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Insert : GDK_Insert; - case VK_HELP: - return GDK_Help; - case VK_META: - return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Meta_L : GDK_Meta_R; - case VK_BACK_QUOTE: - return GDK_grave; - case VK_QUOTE: - return GDK_apostrophe; - case VK_KP_UP: - return GDK_KP_Up; - case VK_KP_DOWN: - return GDK_KP_Down; - case VK_KP_LEFT: - return GDK_KP_Left; - case VK_KP_RIGHT: - return GDK_KP_Right; - case VK_DEAD_GRAVE: - return GDK_dead_grave; - case VK_DEAD_ACUTE: - return GDK_dead_acute; - case VK_DEAD_CIRCUMFLEX: - return GDK_dead_circumflex; - case VK_DEAD_TILDE: - return GDK_dead_tilde; - case VK_DEAD_MACRON: - return GDK_dead_macron; - case VK_DEAD_BREVE: - return GDK_dead_breve; - case VK_DEAD_ABOVEDOT: - return GDK_dead_abovedot; - case VK_DEAD_DIAERESIS: - return GDK_dead_diaeresis; - case VK_DEAD_ABOVERING: - return GDK_dead_abovering; - case VK_DEAD_DOUBLEACUTE: - return GDK_dead_doubleacute; - case VK_DEAD_CARON: - return GDK_dead_caron; - case VK_DEAD_CEDILLA: - return GDK_dead_cedilla; - case VK_DEAD_OGONEK: - return GDK_dead_ogonek; - case VK_DEAD_IOTA: - return GDK_dead_iota; - case VK_DEAD_VOICED_SOUND: - return GDK_dead_voiced_sound; - case VK_DEAD_SEMIVOICED_SOUND: - return GDK_dead_semivoiced_sound; - case VK_AMPERSAND: - return GDK_ampersand; - case VK_ASTERISK: - return GDK_asterisk; - case VK_QUOTEDBL: - return GDK_quotedbl; - case VK_LESS: - return GDK_less; - case VK_GREATER: - return GDK_greater; - case VK_BRACELEFT: - return GDK_braceleft; - case VK_BRACERIGHT: - return GDK_braceright; - case VK_AT: - return GDK_at; - case VK_COLON: - return GDK_colon; - case VK_CIRCUMFLEX: - return GDK_asciicircum; - case VK_DOLLAR: - return GDK_dollar; - case VK_EURO_SIGN: - return GDK_EuroSign; - case VK_EXCLAMATION_MARK: - return GDK_exclam; - case VK_INVERTED_EXCLAMATION_MARK: - return GDK_exclamdown; - case VK_LEFT_PARENTHESIS: - return GDK_parenleft; - case VK_NUMBER_SIGN: - return GDK_numbersign; - case VK_PLUS: - return GDK_plus; - case VK_RIGHT_PARENTHESIS: - return GDK_parenright; - case VK_UNDERSCORE: - return GDK_underscore; - /* - case VK_FINAL: - case VK_CONVERT: - case VK_NONCONVERT: - case VK_ACCEPT: - */ - case VK_MODECHANGE: - return GDK_Mode_switch; - /* - case VK_KANA: - */ - case VK_KANJI: - return GDK_Kanji; - /* - case VK_ALPHANUMERIC: - */ - case VK_KATAKANA: - return GDK_Katakana; - case VK_HIRAGANA: - return GDK_Hiragana; - /* - case VK_FULL_WIDTH: - case VK_HALF_WIDTH: - case VK_ROMAN_CHARACTERS: - case VK_ALL_CANDIDATES: - */ - case VK_PREVIOUS_CANDIDATE: - return GDK_PreviousCandidate; - case VK_CODE_INPUT: - return GDK_Codeinput; - /* - case VK_JAPANESE_KATAKANA: - case VK_JAPANESE_HIRAGANA: - case VK_JAPANESE_ROMAN: - */ - case VK_KANA_LOCK: - return GDK_Kana_Lock; - /* - case VK_INPUT_METHOD_ON_OFF: - case VK_CUT: - case VK_COPY: - case VK_PASTE: - case VK_UNDO: - case VK_AGAIN: - case VK_FIND: - case VK_PROPS: - case VK_STOP: - case VK_COMPOSE: - case VK_ALT_GRAPH: - */ - default: - return GDK_VoidSymbol; - } -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor - (JNIEnv *env, jobject obj, jint type) -{ - void *ptr; - GtkWidget *widget; - GdkCursorType gdk_cursor_type; - GdkCursor *gdk_cursor; - - ptr = NSA_GET_PTR (env, obj); - - switch (type) - { - case AWT_CROSSHAIR_CURSOR: - gdk_cursor_type = GDK_CROSSHAIR; - break; - case AWT_TEXT_CURSOR: - gdk_cursor_type = GDK_XTERM; - break; - case AWT_WAIT_CURSOR: - gdk_cursor_type = GDK_WATCH; - break; - case AWT_SW_RESIZE_CURSOR: - gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER; - break; - case AWT_SE_RESIZE_CURSOR: - gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER; - break; - case AWT_NW_RESIZE_CURSOR: - gdk_cursor_type = GDK_TOP_LEFT_CORNER; - break; - case AWT_NE_RESIZE_CURSOR: - gdk_cursor_type = GDK_TOP_RIGHT_CORNER; - break; - case AWT_N_RESIZE_CURSOR: - gdk_cursor_type = GDK_TOP_SIDE; - break; - case AWT_S_RESIZE_CURSOR: - gdk_cursor_type = GDK_BOTTOM_SIDE; - break; - case AWT_W_RESIZE_CURSOR: - gdk_cursor_type = GDK_LEFT_SIDE; - break; - case AWT_E_RESIZE_CURSOR: - gdk_cursor_type = GDK_RIGHT_SIDE; - break; - case AWT_HAND_CURSOR: - gdk_cursor_type = GDK_HAND2; - break; - case AWT_MOVE_CURSOR: - gdk_cursor_type = GDK_FLEUR; - break; - default: - gdk_cursor_type = GDK_LEFT_PTR; - } - - gdk_threads_enter (); - - widget = GTK_WIDGET(ptr); - - gdk_cursor = gdk_cursor_new (gdk_cursor_type); - gdk_window_set_cursor (widget->window, gdk_cursor); - gdk_cursor_destroy (gdk_cursor); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetParent - (JNIEnv *env, jobject obj, jobject parent) -{ - void *ptr; - void *parent_ptr; - GtkWidget *widget; - GtkWidget *parent_widget; - - ptr = NSA_GET_PTR (env, obj); - parent_ptr = NSA_GET_PTR (env, parent); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - parent_widget = GTK_WIDGET (parent_ptr); - - if (widget->parent == NULL) - { - if (GTK_IS_WINDOW (parent_widget)) - { - GList *children = gtk_container_children - (GTK_CONTAINER (parent_widget)); - - if (GTK_IS_MENU_BAR (children->data)) - gtk_fixed_put (GTK_FIXED (children->next->data), widget, 0, 0); - else - gtk_fixed_put (GTK_FIXED (children->data), widget, 0, 0); - } - else - if (GTK_IS_SCROLLED_WINDOW (parent_widget)) - { - gtk_scrolled_window_add_with_viewport - (GTK_SCROLLED_WINDOW (parent_widget), widget); - gtk_viewport_set_shadow_type (GTK_VIEWPORT (widget->parent), - GTK_SHADOW_NONE); - - } - else - { - if (widget->parent == NULL) - gtk_fixed_put (GTK_FIXED (parent_widget), widget, 0, 0); - } - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetSensitive - (JNIEnv *env, jobject obj, jboolean sensitive) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gtk_widget_set_sensitive (GTK_WIDGET (ptr), sensitive); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetRequestFocus - (JNIEnv *env, jobject obj) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gtk_widget_grab_focus (GTK_WIDGET (ptr)); - gdk_threads_leave (); -} - -/* - * Translate a Java KeyEvent object into a GdkEventKey event, then - * pass it to the GTK main loop for processing. - */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetDispatchKeyEvent - (JNIEnv *env, jobject obj, jint id, jlong when, jint mods, - jint keyCode, jint keyLocation) -{ - void *ptr; - GdkEvent *event = NULL; - GdkKeymapKey *keymap_keys = NULL; - gint n_keys = 0; - guint lookup_keyval = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (id == AWT_KEY_PRESSED) - event = gdk_event_new (GDK_KEY_PRESS); - else if (id == AWT_KEY_RELEASED) - event = gdk_event_new (GDK_KEY_RELEASE); - else - { - gdk_threads_leave (); - /* Don't send AWT KEY_TYPED events to GTK. */ - return; - } - - if (GTK_IS_BUTTON (ptr)) - event->key.window = GTK_BUTTON (ptr)->event_window; - else if (GTK_IS_SCROLLED_WINDOW (ptr)) - event->key.window = GTK_WIDGET (GTK_SCROLLED_WINDOW (ptr)->container.child)->window; - else - event->key.window = GTK_WIDGET (ptr)->window; - - event->key.send_event = 0; - event->key.time = (guint32) when; - - if (mods & AWT_SHIFT_DOWN_MASK) - event->key.state |= GDK_SHIFT_MASK; - if (mods & AWT_CTRL_DOWN_MASK) - event->key.state |= GDK_CONTROL_MASK; - if (mods & AWT_ALT_DOWN_MASK) - event->key.state |= GDK_MOD1_MASK; - - /* This hack is needed because the AWT has no notion of num lock. - It infers numlock state from the only Java virtual keys that are - affected by it. */ - if (keyCode == VK_NUMPAD9 - || keyCode == VK_NUMPAD8 - || keyCode == VK_NUMPAD7 - || keyCode == VK_NUMPAD6 - || keyCode == VK_NUMPAD5 - || keyCode == VK_NUMPAD4 - || keyCode == VK_NUMPAD3 - || keyCode == VK_NUMPAD2 - || keyCode == VK_NUMPAD1 - || keyCode == VK_NUMPAD0 - || keyCode == VK_DECIMAL) - event->key.state |= GDK_MOD2_MASK; - - /* These values don't need to be filled in since GTK doesn't use - them. */ - event->key.length = 0; - event->key.string = NULL; - - lookup_keyval = awt_keycode_to_keysym (keyCode, keyLocation); - - if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), - lookup_keyval, - &keymap_keys, - &n_keys)) - { - /* No matching keymap entry was found. */ - g_printerr ("No matching keymap entries were found\n"); - gdk_threads_leave (); - return; - } - - /* Note: if n_keys > 1 then there are multiple hardware keycodes - that translate to lookup_keyval. We arbitrarily choose the first - hardware keycode from the list returned by - gdk_keymap_get_entries_for_keyval. */ - - event->key.hardware_keycode = keymap_keys[0].keycode; - event->key.group = keymap_keys[0].group; - - g_free (keymap_keys); - - if (!gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), - event->key.hardware_keycode, - event->key.state, - event->key.group, - &event->key.keyval, - NULL, NULL, NULL)) - { - /* No matching keyval was found. */ - g_printerr ("No matching keyval was found\n"); - gdk_threads_leave (); - return; - } - - /* keyevent = (GdkEventKey *) event; */ - /* g_printerr ("generated event: sent: %d time: %d state: %d keyval: %d length: %d string: %s hardware_keycode: %d group: %d\n", keyevent->send_event, keyevent->time, keyevent->state, keyevent->keyval, keyevent->length, keyevent->string, keyevent->hardware_keycode, keyevent->group); */ - - /* We already received the original key event on the window itself, - so we don't want to resend it. */ - if (!GTK_IS_WINDOW (ptr)) - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - gtk_widget_event (GTK_WIDGET (GTK_SCROLLED_WINDOW (ptr)->container.child), event); - else - gtk_widget_event (GTK_WIDGET (ptr), event); - } - - gdk_threads_leave (); -} - -/* - * Find the origin of a widget's window. - */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreen - (JNIEnv * env, jobject obj, jintArray jpoint) -{ - void *ptr; - jint *point; - - ptr = NSA_GET_PTR (env, obj); - point = (*env)->GetIntArrayElements (env, jpoint, 0); - - gdk_threads_enter (); - - gdk_window_get_origin (GTK_WIDGET (ptr)->window, point, point+1); - - if (!GTK_IS_CONTAINER (ptr)) - { - *point += GTK_WIDGET(ptr)->allocation.x; - *(point+1) += GTK_WIDGET(ptr)->allocation.y; - } - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements(env, jpoint, point, 0); -} - -/* - * Find this widget's current size. - */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetDimensions - (JNIEnv *env, jobject obj, jintArray jdims) -{ - void *ptr; - jint *dims; - GtkRequisition requisition; - - ptr = NSA_GET_PTR (env, obj); - - dims = (*env)->GetIntArrayElements (env, jdims, 0); - dims[0] = dims[1] = 0; - - gdk_threads_enter (); - - gtk_widget_size_request (GTK_WIDGET (ptr), &requisition); - - dims[0] = requisition.width; - dims[1] = requisition.height; - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); -} - -/* - * Find this widget's preferred size. - */ -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetPreferredDimensions - (JNIEnv *env, jobject obj, jintArray jdims) -{ - void *ptr; - jint *dims; - GtkRequisition current_req; - GtkRequisition natural_req; - - ptr = NSA_GET_PTR (env, obj); - - dims = (*env)->GetIntArrayElements (env, jdims, 0); - dims[0] = dims[1] = 0; - - gdk_threads_enter (); - - /* Widgets that extend GtkWindow such as GtkFileChooserDialog may have - a default size. These values seem more useful then the natural - requisition values, particularly for GtkFileChooserDialog. */ - if (GTK_IS_WINDOW (ptr)) - { - gint width, height; - gtk_window_get_default_size (GTK_WINDOW (ptr), &width, &height); - - dims[0] = width; - dims[1] = height; - } - else - { - /* Save the widget's current size request. */ - gtk_widget_size_request (GTK_WIDGET (ptr), ¤t_req); - - /* Get the widget's "natural" size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); - gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); - - /* Reset the widget's size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), - current_req.width, current_req.height); - - dims[0] = natural_req.width; - dims[1] = natural_req.height; - } - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeBounds - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - GtkWidget *widget; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - /* We assume that -1 is a width or height and not a request for the - widget's natural size. */ - width = width < 0 ? 0 : width; - height = height < 0 ? 0 : height; - - if (GTK_IS_VIEWPORT (widget->parent)) - gtk_widget_set_size_request (widget, width, height); - else - { - if (!(width == 0 && height == 0)) - { - gtk_widget_set_size_request (widget, width, height); - if (widget->parent != NULL) - gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); - } - } - - gdk_threads_leave (); -} - -JNIEXPORT jintArray JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetBackground - (JNIEnv *env, jobject obj) -{ - void *ptr; - jintArray array; - int *rgb; - GdkColor bg; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - bg = GTK_WIDGET (ptr)->style->bg[GTK_STATE_NORMAL]; - gdk_threads_leave (); - - array = (*env)->NewIntArray (env, 3); - rgb = (*env)->GetIntArrayElements (env, array, NULL); - /* convert color data from 16 bit values down to 8 bit values */ - rgb[0] = bg.red >> 8; - rgb[1] = bg.green >> 8; - rgb[2] = bg.blue >> 8; - (*env)->ReleaseIntArrayElements (env, array, rgb, 0); - - return array; -} - -JNIEXPORT jintArray JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetForeground - (JNIEnv *env, jobject obj) -{ - void *ptr; - jintArray array; - jint *rgb; - GdkColor fg; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - fg = GTK_WIDGET (ptr)->style->fg[GTK_STATE_NORMAL]; - gdk_threads_leave (); - - array = (*env)->NewIntArray (env, 3); - rgb = (*env)->GetIntArrayElements (env, array, NULL); - /* convert color data from 16 bit values down to 8 bit values */ - rgb[0] = fg.red >> 8; - rgb[1] = fg.green >> 8; - rgb[2] = fg.blue >> 8; - (*env)->ReleaseIntArrayElements (env, array, rgb, 0); - - return array; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetBackground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor normal_color; - GdkColor active_color; - GtkWidget *widget; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - normal_color.red = (red / 255.0) * 65535; - normal_color.green = (green / 255.0) * 65535; - normal_color.blue = (blue / 255.0) * 65535; - - /* This calculation only approximates the active colors produced by - Sun's AWT. */ - active_color.red = 0.85 * (red / 255.0) * 65535; - active_color.green = 0.85 * (green / 255.0) * 65535; - active_color.blue = 0.85 * (blue / 255.0) * 65535; - - gdk_threads_enter (); - - widget = find_bg_color_widget (GTK_WIDGET (ptr)); - - gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &normal_color); - gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &active_color); - gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &normal_color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetForeground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor color; - GtkWidget *widget; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - color.red = (red / 255.0) * 65535; - color.green = (green / 255.0) * 65535; - color.blue = (blue / 255.0) * 65535; - - gdk_threads_enter (); - - widget = find_fg_color_widget (GTK_WIDGET (ptr)); - - gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &color); - gtk_widget_modify_fg (widget, GTK_STATE_ACTIVE, &color); - gtk_widget_modify_fg (widget, GTK_STATE_PRELIGHT, &color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_show - (JNIEnv *env, jobject obj) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter(); - gtk_widget_show (GTK_WIDGET (ptr)); - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_hide - (JNIEnv *env, jobject obj) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter(); - gtk_widget_hide (GTK_WIDGET (ptr)); - gdk_threads_leave(); -} - -JNIEXPORT jboolean JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_isEnabled - (JNIEnv *env, jobject obj) -{ - void *ptr; - jboolean ret_val; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - ret_val = GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (ptr)); - gdk_threads_leave (); - - return ret_val; -} - -JNIEXPORT jboolean JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_isRealized - (JNIEnv *env, jobject obj) -{ - void *ptr; - jboolean ret_val; - - ptr = NSA_GET_PTR (env, obj); - - if (ptr == NULL) - return FALSE; - - gdk_threads_enter (); - ret_val = GTK_WIDGET_REALIZED (GTK_WIDGET (ptr)); - gdk_threads_leave (); - - return ret_val; -} - -JNIEXPORT jboolean JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_modalHasGrab - (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused))) -{ - GtkWidget *widget; - jboolean retval; - - gdk_threads_enter (); - widget = gtk_grab_get_current (); - retval = (widget && GTK_IS_WINDOW (widget) && GTK_WINDOW (widget)->modal); - gdk_threads_leave (); - - return retval; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr; - jobject *gref; - - ptr = NSA_GET_PTR (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - /* Connect EVENT signal, which happens _before_ any specific signal. */ - - g_signal_connect (GTK_OBJECT (ptr), "event", - G_CALLBACK (pre_event_handler), *gref); - - g_signal_connect (G_OBJECT (ptr), "focus-in-event", - G_CALLBACK (focus_in_cb), *gref); - - g_signal_connect (G_OBJECT (ptr), "focus-out-event", - G_CALLBACK (focus_out_cb), *gref); - - g_signal_connect_after (G_OBJECT (ptr), "realize", - G_CALLBACK (connect_awt_hook_cb), *gref); - - gdk_threads_leave (); -} - -static GtkWidget * -find_fg_color_widget (GtkWidget *widget) -{ - GtkWidget *fg_color_widget; - - if (GTK_IS_EVENT_BOX (widget) - || (GTK_IS_BUTTON (widget) - && !GTK_IS_OPTION_MENU (widget))) - fg_color_widget = gtk_bin_get_child (GTK_BIN(widget)); - else - fg_color_widget = widget; - - return fg_color_widget; -} - -static GtkWidget * -find_bg_color_widget (GtkWidget *widget) -{ - GtkWidget *bg_color_widget; - - bg_color_widget = widget; - - return bg_color_widget; -} - -static gboolean -focus_in_cb (GtkWidget *widget __attribute((unused)), - GdkEventFocus *event __attribute((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postFocusEventID, - AWT_FOCUS_GAINED, - JNI_FALSE); - gdk_threads_enter (); - return FALSE; -} - -static gboolean -focus_out_cb (GtkWidget *widget __attribute((unused)), - GdkEventFocus *event __attribute((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postFocusEventID, - AWT_FOCUS_LOST, - JNI_FALSE); - gdk_threads_enter (); - return FALSE; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c deleted file mode 100644 index 3fa0c21e6c6..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c +++ /dev/null @@ -1,82 +0,0 @@ -/* gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c -- Native - implementation of GtkEmbeddedWindowPeer - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_create - (JNIEnv *env, jobject obj, jlong socket_id) -{ - GtkWidget *window; - GtkWidget *fixed; - - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - window = gtk_plug_new ((GdkNativeWindow) socket_id); - - fixed = gtk_fixed_new (); - gtk_container_add (GTK_CONTAINER (window), fixed); - - gtk_widget_show (fixed); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, window); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_construct - (JNIEnv *env, jobject obj, jlong socket_id) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_WIDGET_REALIZED (GTK_WIDGET (ptr))) - g_printerr ("ERROR: GtkPlug is already realized\n"); - - gtk_plug_construct (GTK_PLUG (ptr), (GdkNativeWindow) socket_id); - - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c deleted file mode 100644 index c45c672fec0..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c +++ /dev/null @@ -1,1176 +0,0 @@ -/* gtkevents.c -- GDK/GTK event handlers - Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include <X11/Xlib.h> -#include <gdk/gdkkeysyms.h> -#include <stdarg.h> -#include <assert.h> - -/* A widget can be composed of multipled windows, so we need to hook - events on all of them. */ -struct event_hook_info -{ - jobject *peer_obj; - int nwindows; - /* array of pointers to (GdkWindow *) */ - GdkWindow ***windows; -}; - -static jint -button_to_awt_mods (int button) -{ - switch (button) - { - case 1: - return AWT_BUTTON1_MASK; - case 2: - return AWT_BUTTON2_MASK; - case 3: - return AWT_BUTTON3_MASK; - } - - return 0; -} - -static jint -state_to_awt_mods (guint state) -{ - jint result = 0; - - if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; - if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; - if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; - - return result; -} - -static jint -state_to_awt_mods_with_button_states (guint state) -{ - jint result = 0; - - if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; - if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; - if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; - if (state & GDK_BUTTON1_MASK) - result |= AWT_BUTTON1_DOWN_MASK; - if (state & GDK_BUTTON2_MASK) - result |= AWT_BUTTON2_DOWN_MASK; - if (state & GDK_BUTTON3_MASK) - result |= AWT_BUTTON3_DOWN_MASK; - - return result; -} - -/* Modifier key events need special treatment. In Sun's peer - implementation, when a modifier key is pressed, the KEY_PRESSED - event has that modifier in its modifiers list. The corresponding - KEY_RELEASED event's modifier list does not contain the modifier. - For example, pressing and releasing the shift key will produce a - key press event with modifiers=Shift, and a key release event with - no modifiers. GDK's key events behave in the exact opposite way, - so this translation code is needed. */ -jint -keyevent_state_to_awt_mods (GdkEvent *event) -{ - jint result = 0; - guint state; - - if (event->type == GDK_KEY_PRESS) - { - state = event->key.state; - - if (event->key.keyval == GDK_Shift_L - || event->key.keyval == GDK_Shift_R) - result |= AWT_SHIFT_DOWN_MASK; - else - { - if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; - } - - if (event->key.keyval == GDK_Control_L - || event->key.keyval == GDK_Control_R) - result |= AWT_CTRL_DOWN_MASK; - else - { - if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; - } - - if (event->key.keyval == GDK_Alt_L - || event->key.keyval == GDK_Alt_R) - result |= AWT_ALT_DOWN_MASK; - else - { - if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; - } - } - else if (event->type == GDK_KEY_RELEASE) - { - state = event->key.state; - - if (event->key.keyval != GDK_Shift_L - && event->key.keyval != GDK_Shift_R) - { - if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; - } - if (event->key.keyval != GDK_Control_L - && event->key.keyval != GDK_Control_R) - { - if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; - } - - if (event->key.keyval != GDK_Alt_L - && event->key.keyval != GDK_Alt_R) - { - if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; - } - } - - return result; -} - -/* Get the first keyval in the keymap for this event's keycode. The - first keyval corresponds roughly to Java's notion of a virtual - key. Returns the uppercase version of the first keyval. */ -static guint -get_first_keyval_from_keymap (GdkEvent *event) -{ - guint keyval; - guint *keyvals; - gint n_entries; - - if (!gdk_keymap_get_entries_for_keycode (NULL, - event->key.hardware_keycode, - NULL, - &keyvals, - &n_entries)) - { - g_warning ("No keyval found for hardware keycode %d\n", - event->key.hardware_keycode); - /* Try to recover by using the keyval in the event structure. */ - keyvals = &(event->key.keyval); - } - keyval = keyvals[0]; - g_free (keyvals); - - return gdk_keyval_to_upper (keyval); -} - -#ifdef __GNUC__ -__inline -#endif -static jint -keysym_to_awt_keycode (GdkEvent *event) -{ - guint ukeyval; - guint state; - - ukeyval = get_first_keyval_from_keymap (event); - state = event->key.state; - - /* VK_A through VK_Z */ - if (ukeyval >= GDK_A && ukeyval <= GDK_Z) - return ukeyval; - - /* VK_0 through VK_9 */ - if (ukeyval >= GDK_0 && ukeyval <= GDK_9) - return ukeyval; - - switch (ukeyval) - { - case GDK_Return: - case GDK_KP_Enter: - return VK_ENTER; - case GDK_BackSpace: - return VK_BACK_SPACE; - case GDK_Tab: - return VK_TAB; - case GDK_Cancel: - return VK_CANCEL; - case GDK_Clear: - return VK_CLEAR; - case GDK_Shift_L: - case GDK_Shift_R: - return VK_SHIFT; - case GDK_Control_L: - case GDK_Control_R: - return VK_CONTROL; - case GDK_Alt_L: - case GDK_Alt_R: - return VK_ALT; - case GDK_Pause: - return VK_PAUSE; - case GDK_Caps_Lock: - return VK_CAPS_LOCK; - case GDK_Escape: - return VK_ESCAPE; - case GDK_space: - return VK_SPACE; - case GDK_KP_Page_Up: - /* For keys on the numeric keypad, the JVM produces one of two - virtual keys, depending on the num lock state. */ - if (state & GDK_MOD2_MASK) - return VK_NUMPAD9; - else - return VK_PAGE_UP; - case GDK_Page_Up: - return VK_PAGE_UP; - case GDK_KP_Page_Down: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD3; - else - return VK_PAGE_DOWN; - case GDK_Page_Down: - return VK_PAGE_DOWN; - case GDK_KP_End: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD1; - else - return VK_END; - case GDK_End: - return VK_END; - case GDK_KP_Home: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD7; - else - return VK_HOME; - case GDK_Home: - return VK_HOME; - case GDK_KP_Begin: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD5; - else - return VK_UNDEFINED; - case GDK_Left: - return VK_LEFT; - case GDK_Up: - return VK_UP; - case GDK_Right: - return VK_RIGHT; - case GDK_Down: - return VK_DOWN; - case GDK_comma: - return VK_COMMA; - case GDK_minus: - return VK_MINUS; - case GDK_period: - return VK_PERIOD; - case GDK_slash: - return VK_SLASH; - /* - return VK_0; - return VK_1; - return VK_2; - return VK_3; - return VK_4; - return VK_5; - return VK_6; - return VK_7; - return VK_8; - return VK_9; - */ - case GDK_semicolon: - return VK_SEMICOLON; - case GDK_equal: - return VK_EQUALS; - /* - return VK_A; - return VK_B; - return VK_C; - return VK_D; - return VK_E; - return VK_F; - return VK_G; - return VK_H; - return VK_I; - return VK_J; - return VK_K; - return VK_L; - return VK_M; - return VK_N; - return VK_O; - return VK_P; - return VK_Q; - return VK_R; - return VK_S; - return VK_T; - return VK_U; - return VK_V; - return VK_W; - return VK_X; - return VK_Y; - return VK_Z; - */ - case GDK_bracketleft: - return VK_OPEN_BRACKET; - case GDK_backslash: - return VK_BACK_SLASH; - case GDK_bracketright: - return VK_CLOSE_BRACKET; - case GDK_KP_0: - return VK_NUMPAD0; - case GDK_KP_1: - return VK_NUMPAD1; - case GDK_KP_2: - return VK_NUMPAD2; - case GDK_KP_3: - return VK_NUMPAD3; - case GDK_KP_4: - return VK_NUMPAD4; - case GDK_KP_5: - return VK_NUMPAD5; - case GDK_KP_6: - return VK_NUMPAD6; - case GDK_KP_7: - return VK_NUMPAD7; - case GDK_KP_8: - return VK_NUMPAD8; - case GDK_KP_9: - return VK_NUMPAD9; - case GDK_KP_Multiply: - return VK_MULTIPLY; - case GDK_KP_Add: - return VK_ADD; - /* - return VK_SEPARATER; - */ - case GDK_KP_Separator: - return VK_SEPARATOR; - case GDK_KP_Subtract: - return VK_SUBTRACT; - case GDK_KP_Decimal: - return VK_DECIMAL; - case GDK_KP_Divide: - return VK_DIVIDE; - case GDK_KP_Delete: - if (state & GDK_MOD2_MASK) - return VK_DECIMAL; - else - return VK_DELETE; - case GDK_Delete: - return VK_DELETE; - case GDK_Num_Lock: - return VK_NUM_LOCK; - case GDK_Scroll_Lock: - return VK_SCROLL_LOCK; - case GDK_F1: - return VK_F1; - case GDK_F2: - return VK_F2; - case GDK_F3: - return VK_F3; - case GDK_F4: - return VK_F4; - case GDK_F5: - return VK_F5; - case GDK_F6: - return VK_F6; - case GDK_F7: - return VK_F7; - case GDK_F8: - return VK_F8; - case GDK_F9: - return VK_F9; - case GDK_F10: - return VK_F10; - case GDK_F11: - return VK_F11; - case GDK_F12: - return VK_F12; - case GDK_F13: - return VK_F13; - case GDK_F14: - return VK_F14; - case GDK_F15: - return VK_F15; - case GDK_F16: - return VK_F16; - case GDK_F17: - return VK_F17; - case GDK_F18: - return VK_F18; - case GDK_F19: - return VK_F19; - case GDK_F20: - return VK_F20; - case GDK_F21: - return VK_F21; - case GDK_F22: - return VK_F22; - case GDK_F23: - return VK_F23; - case GDK_F24: - return VK_F24; - case GDK_Print: - return VK_PRINTSCREEN; - case GDK_KP_Insert: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD0; - else - return VK_INSERT; - case GDK_Insert: - return VK_INSERT; - case GDK_Help: - return VK_HELP; - case GDK_Meta_L: - case GDK_Meta_R: - return VK_META; - case GDK_grave: - return VK_BACK_QUOTE; - case GDK_apostrophe: - return VK_QUOTE; - case GDK_KP_Up: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD8; - else - return VK_KP_UP; - case GDK_KP_Down: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD2; - else - return VK_KP_DOWN; - case GDK_KP_Left: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD4; - else - return VK_KP_LEFT; - case GDK_KP_Right: - if (state & GDK_MOD2_MASK) - return VK_NUMPAD6; - else - return VK_KP_RIGHT; - case GDK_dead_grave: - return VK_DEAD_GRAVE; - case GDK_dead_acute: - return VK_DEAD_ACUTE; - case GDK_dead_circumflex: - return VK_DEAD_CIRCUMFLEX; - case GDK_dead_tilde: - return VK_DEAD_TILDE; - case GDK_dead_macron: - return VK_DEAD_MACRON; - case GDK_dead_breve: - return VK_DEAD_BREVE; - case GDK_dead_abovedot: - return VK_DEAD_ABOVEDOT; - case GDK_dead_diaeresis: - return VK_DEAD_DIAERESIS; - case GDK_dead_abovering: - return VK_DEAD_ABOVERING; - case GDK_dead_doubleacute: - return VK_DEAD_DOUBLEACUTE; - case GDK_dead_caron: - return VK_DEAD_CARON; - case GDK_dead_cedilla: - return VK_DEAD_CEDILLA; - case GDK_dead_ogonek: - return VK_DEAD_OGONEK; - case GDK_dead_iota: - return VK_DEAD_IOTA; - case GDK_dead_voiced_sound: - return VK_DEAD_VOICED_SOUND; - case GDK_dead_semivoiced_sound: - return VK_DEAD_SEMIVOICED_SOUND; - case GDK_ampersand: - return VK_AMPERSAND; - case GDK_asterisk: - return VK_ASTERISK; - case GDK_quotedbl: - return VK_QUOTEDBL; - case GDK_less: - return VK_LESS; - case GDK_greater: - return VK_GREATER; - case GDK_braceleft: - return VK_BRACELEFT; - case GDK_braceright: - return VK_BRACERIGHT; - case GDK_at: - return VK_AT; - case GDK_colon: - return VK_COLON; - case GDK_asciicircum: - return VK_CIRCUMFLEX; - case GDK_dollar: - return VK_DOLLAR; - case GDK_EuroSign: - return VK_EURO_SIGN; - case GDK_exclam: - return VK_EXCLAMATION_MARK; - case GDK_exclamdown: - return VK_INVERTED_EXCLAMATION_MARK; - case GDK_parenleft: - return VK_LEFT_PARENTHESIS; - case GDK_numbersign: - return VK_NUMBER_SIGN; - case GDK_plus: - return VK_PLUS; - case GDK_parenright: - return VK_RIGHT_PARENTHESIS; - case GDK_underscore: - return VK_UNDERSCORE; - /* - return VK_FINAL; - return VK_CONVERT; - return VK_NONCONVERT; - return VK_ACCEPT; - */ - case GDK_Mode_switch: - return VK_MODECHANGE; - /* - return VK_KANA; - */ - case GDK_Kanji: - return VK_KANJI; - /* - return VK_ALPHANUMERIC; - */ - case GDK_Katakana: - return VK_KATAKANA; - case GDK_Hiragana: - return VK_HIRAGANA; - /* - return VK_FULL_WIDTH; - return VK_HALF_WIDTH; - return VK_ROMAN_CHARACTERS; - return VK_ALL_CANDIDATES; - */ - case GDK_PreviousCandidate: - return VK_PREVIOUS_CANDIDATE; - case GDK_Codeinput: - return VK_CODE_INPUT; - /* - return VK_JAPANESE_KATAKANA; - return VK_JAPANESE_HIRAGANA; - return VK_JAPANESE_ROMAN; - */ - case GDK_Kana_Lock: - return VK_KANA_LOCK; - /* - return VK_INPUT_METHOD_ON_OFF; - return VK_CUT; - return VK_COPY; - return VK_PASTE; - return VK_UNDO; - return VK_AGAIN; - return VK_FIND; - return VK_PROPS; - return VK_STOP; - return VK_COMPOSE; - return VK_ALT_GRAPH; - */ - default: - return VK_UNDEFINED; - } -} - -static jint -keysym_to_awt_keylocation (GdkEvent *event) -{ - guint ukeyval; - - ukeyval = get_first_keyval_from_keymap (event); - - /* VK_A through VK_Z */ - if (ukeyval >= GDK_A && ukeyval <= GDK_Z) - return AWT_KEY_LOCATION_STANDARD; - - /* VK_0 through VK_9 */ - if (ukeyval >= GDK_0 && ukeyval <= GDK_9) - return AWT_KEY_LOCATION_STANDARD; - - switch (ukeyval) - { - case GDK_Shift_L: - case GDK_Control_L: - case GDK_Alt_L: - case GDK_Meta_L: - return AWT_KEY_LOCATION_LEFT; - - case GDK_Shift_R: - case GDK_Control_R: - case GDK_Alt_R: - case GDK_Meta_R: - return AWT_KEY_LOCATION_RIGHT; - - case GDK_Return: - case GDK_BackSpace: - case GDK_Tab: - case GDK_Cancel: - case GDK_Clear: - case GDK_Pause: - case GDK_Caps_Lock: - case GDK_Escape: - case GDK_space: - case GDK_Page_Up: - case GDK_Page_Down: - case GDK_End: - case GDK_Home: - case GDK_Left: - case GDK_Up: - case GDK_Right: - case GDK_Down: - case GDK_comma: - case GDK_minus: - case GDK_period: - case GDK_slash: - case GDK_semicolon: - case GDK_equal: - case GDK_bracketleft: - case GDK_backslash: - case GDK_bracketright: - case GDK_Delete: - case GDK_Scroll_Lock: - case GDK_F1: - case GDK_F2: - case GDK_F3: - case GDK_F4: - case GDK_F5: - case GDK_F6: - case GDK_F7: - case GDK_F8: - case GDK_F9: - case GDK_F10: - case GDK_F11: - case GDK_F12: - case GDK_F13: - case GDK_F14: - case GDK_F15: - case GDK_F16: - case GDK_F17: - case GDK_F18: - case GDK_F19: - case GDK_F20: - case GDK_F21: - case GDK_F22: - case GDK_F23: - case GDK_F24: - case GDK_Print: - case GDK_Insert: - case GDK_Help: - case GDK_grave: - case GDK_apostrophe: - case GDK_dead_grave: - case GDK_dead_acute: - case GDK_dead_circumflex: - case GDK_dead_tilde: - case GDK_dead_macron: - case GDK_dead_breve: - case GDK_dead_abovedot: - case GDK_dead_diaeresis: - case GDK_dead_abovering: - case GDK_dead_doubleacute: - case GDK_dead_caron: - case GDK_dead_cedilla: - case GDK_dead_ogonek: - case GDK_dead_iota: - case GDK_dead_voiced_sound: - case GDK_dead_semivoiced_sound: - case GDK_ampersand: - case GDK_asterisk: - case GDK_quotedbl: - case GDK_less: - case GDK_greater: - case GDK_braceleft: - case GDK_braceright: - case GDK_at: - case GDK_colon: - case GDK_asciicircum: - case GDK_dollar: - case GDK_EuroSign: - case GDK_exclam: - case GDK_exclamdown: - case GDK_parenleft: - case GDK_numbersign: - case GDK_plus: - case GDK_parenright: - case GDK_underscore: - case GDK_Mode_switch: - case GDK_Kanji: - case GDK_Katakana: - case GDK_Hiragana: - case GDK_PreviousCandidate: - case GDK_Codeinput: - case GDK_Kana_Lock: - return AWT_KEY_LOCATION_STANDARD; - - case GDK_KP_Enter: - case GDK_KP_Page_Up: - case GDK_KP_Page_Down: - case GDK_KP_End: - case GDK_KP_Home: - case GDK_KP_Begin: - case GDK_KP_0: - case GDK_KP_1: - case GDK_KP_2: - case GDK_KP_3: - case GDK_KP_4: - case GDK_KP_5: - case GDK_KP_6: - case GDK_KP_7: - case GDK_KP_8: - case GDK_KP_9: - case GDK_KP_Multiply: - case GDK_KP_Add: - case GDK_KP_Separator: - case GDK_KP_Subtract: - case GDK_KP_Decimal: - case GDK_KP_Divide: - case GDK_KP_Delete: - case GDK_Num_Lock: - case GDK_KP_Insert: - case GDK_KP_Up: - case GDK_KP_Down: - case GDK_KP_Left: - case GDK_KP_Right: - return AWT_KEY_LOCATION_NUMPAD; - - default: - return AWT_KEY_LOCATION_UNKNOWN; - } -} - -static jchar -keyevent_to_awt_keychar (GdkEvent *event) -{ - if (event->key.length > 0) - { - /* Translate GDK carriage return to Java linefeed. */ - if (event->key.string[0] == 13) - return VK_ENTER; - else - return event->key.string[0]; - } - else - { - switch (event->key.keyval) - { - case GDK_BackSpace: - return VK_BACK_SPACE; - case GDK_Tab: - return VK_TAB; - case GDK_Delete: - case GDK_KP_Delete: - return VK_DELETE; - default: - return AWT_KEY_CHAR_UNDEFINED; - } - } -} - -void -awt_event_handler (GdkEvent *event) -{ - /* keep synthetic AWT events from being processed recursively */ - if (event->type & SYNTHETIC_EVENT_MASK && event->type != GDK_NOTHING) - { - event->type ^= SYNTHETIC_EVENT_MASK; - } - - gtk_main_do_event (event); -} - -gboolean -pre_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer) -{ - GtkWidget *event_widget; - static guint32 button_click_time = 0; - static GdkWindow *button_window = NULL; - static guint button_number = -1; - static jint click_count = 1; - static int hasBeenDragged; - union widget_union w; - - /* If it is not a focus change event, the widget must be realized already. - If not, ignore the event (Gtk+ will do the same). */ - if (!(event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))) - return FALSE; - - /* Do not handle propagated events. AWT has its own propagation rules */ - w.widget = &event_widget; - gdk_window_get_user_data (event->any.window, w.void_widget); - if (event_widget != widget) - return FALSE; - - /* We only care about input events */ - if (!(event->type == GDK_BUTTON_PRESS - || event->type == GDK_BUTTON_RELEASE - || event->type == GDK_ENTER_NOTIFY - || event->type == GDK_LEAVE_NOTIFY - || event->type == GDK_CONFIGURE - || event->type == GDK_EXPOSE - || event->type == GDK_KEY_PRESS - || event->type == GDK_KEY_RELEASE - || event->type == GDK_FOCUS_CHANGE - || event->type == GDK_MOTION_NOTIFY)) - { - return FALSE; - } - /* g_print("event %u widget %s peer %p\n", - event->type, gtk_widget_get_name (widget), peer); */ - - /* If it has no jobject associated we can send no AWT event */ - if (!peer) - return FALSE; - - /* for all input events, which have a window with a jobject attached, - send the AWT input event corresponding to the Gtk event off to Java */ - - /* keep track of clickCount ourselves, since the AWT allows more - than a triple click to occur */ - if (event->type == GDK_BUTTON_PRESS) - { - if ((event->button.time < (button_click_time + MULTI_CLICK_TIME)) - && (event->button.window == button_window) - && (event->button.button == button_number)) - click_count++; - else - click_count = 1; - - button_click_time = event->button.time; - button_window = event->button.window; - button_number = event->button.button; - } - - switch (event->type) - { - case GDK_BUTTON_PRESS: - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postMouseEventID, - AWT_MOUSE_PRESSED, - (jlong)event->button.time, - state_to_awt_mods (event->button.state) - | button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, - (event->button.button == 3) ? JNI_TRUE : - JNI_FALSE); - gdk_threads_enter (); - hasBeenDragged = FALSE; - break; - case GDK_BUTTON_RELEASE: - { - int width, height; - - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postMouseEventID, - AWT_MOUSE_RELEASED, - (jlong)event->button.time, - state_to_awt_mods (event->button.state) - | button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, - JNI_FALSE); - gdk_threads_enter (); - - /* Generate an AWT click event only if the release occured in the - window it was pressed in, and the mouse has not been dragged since - the last time it was pressed. */ - gdk_window_get_size (event->any.window, &width, &height); - if (! hasBeenDragged - && event->button.x >= 0 - && event->button.y >= 0 - && event->button.x <= width - && event->button.y <= height) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postMouseEventID, - AWT_MOUSE_CLICKED, - (jlong)event->button.time, - state_to_awt_mods (event->button.state) - | button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, - JNI_FALSE); - gdk_threads_enter (); - } - } - break; - case GDK_MOTION_NOTIFY: - if (event->motion.state & (GDK_BUTTON1_MASK - | GDK_BUTTON2_MASK - | GDK_BUTTON3_MASK - | GDK_BUTTON4_MASK - | GDK_BUTTON5_MASK)) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postMouseEventID, - AWT_MOUSE_DRAGGED, - (jlong)event->motion.time, - state_to_awt_mods_with_button_states (event->motion.state), - (jint)event->motion.x, - (jint)event->motion.y, - 0, - JNI_FALSE); - gdk_threads_enter (); - hasBeenDragged = TRUE; - } - else - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, postMouseEventID, - AWT_MOUSE_MOVED, - (jlong)event->motion.time, - state_to_awt_mods (event->motion.state), - (jint)event->motion.x, - (jint)event->motion.y, - 0, - JNI_FALSE); - gdk_threads_enter (); - } - - break; - case GDK_ENTER_NOTIFY: - /* We are not interested in enter events that are due to - grab/ungrab and not to actually crossing boundaries */ - if (event->crossing.mode == GDK_CROSSING_NORMAL) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, postMouseEventID, - AWT_MOUSE_ENTERED, - (jlong)event->crossing.time, - state_to_awt_mods_with_button_states (event->crossing.state), - (jint)event->crossing.x, - (jint)event->crossing.y, - 0, - JNI_FALSE); - gdk_threads_enter (); - } - break; - case GDK_LEAVE_NOTIFY: - /* We are not interested in leave events that are due to - grab/ungrab and not to actually crossing boundaries */ - if (event->crossing.mode == GDK_CROSSING_NORMAL) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postMouseEventID, - AWT_MOUSE_EXITED, - (jlong)event->crossing.time, - state_to_awt_mods_with_button_states (event->crossing.state), - (jint)event->crossing.x, - (jint)event->crossing.y, - 0, - JNI_FALSE); - gdk_threads_enter (); - } - break; - case GDK_CONFIGURE: - { - /* Only send configure events to visible top-level windows. */ - if (widget && GTK_WIDGET_TOPLEVEL (widget) - && GTK_WIDGET_VISIBLE (widget)) - { - /* Configure events are not posted to the AWT event - queue, and as such, the gdk/gtk peer functions will - be called back before postConfigureEvent - returns. */ - gdk_threads_leave (); - - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postConfigureEventID, - (jint) event->configure.x, - (jint) event->configure.y, - (jint) event->configure.width, - (jint) event->configure.height); - gdk_threads_enter (); - } - } - break; - case GDK_EXPOSE: - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postExposeEventID, - (jint)event->expose.area.x, - (jint)event->expose.area.y, - (jint)event->expose.area.width, - (jint)event->expose.area.height); - gdk_threads_enter (); - break; - - case GDK_FOCUS_CHANGE: - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postFocusEventID, - (jint) (event->focus_change.in) ? - AWT_FOCUS_GAINED : AWT_FOCUS_LOST, - JNI_FALSE); - gdk_threads_enter (); - break; - case GDK_KEY_PRESS: - if (GTK_IS_WINDOW (widget)) - { - /* GdkEventKey *keyevent = (GdkEventKey *) event; */ - /* g_printerr ("key press event: sent: %d time: %d state: %d keyval: %d length: %d string: %s hardware_keycode: %d group: %d\n", keyevent->send_event, keyevent->time, keyevent->state, keyevent->keyval, keyevent->length, keyevent->string, keyevent->hardware_keycode, keyevent->group); */ - - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postKeyEventID, - (jint) AWT_KEY_PRESSED, - (jlong) event->key.time, - keyevent_state_to_awt_mods (event), - keysym_to_awt_keycode (event), - keyevent_to_awt_keychar (event), - keysym_to_awt_keylocation (event)); - gdk_threads_enter (); - /* 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; - } - else - return FALSE; - break; - case GDK_KEY_RELEASE: - if (GTK_IS_WINDOW (widget)) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postKeyEventID, - (jint) AWT_KEY_RELEASED, - (jlong) event->key.time, - keyevent_state_to_awt_mods (event), - keysym_to_awt_keycode (event), - keyevent_to_awt_keychar (event), - keysym_to_awt_keylocation (event)); - gdk_threads_enter (); - return TRUE; - } - else - return FALSE; - break; - default: - break; - } - - return FALSE; -} - -static void -attach_jobject (GdkWindow *window, jobject *obj) -{ - GdkAtom addr_atom = gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE); - GdkAtom type_atom = gdk_atom_intern ("CARDINAL", FALSE); - - gdk_window_set_events (window, - gdk_window_get_events (window) - | GDK_POINTER_MOTION_MASK - | GDK_BUTTON_MOTION_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_KEY_PRESS_MASK - | GDK_KEY_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK - | GDK_LEAVE_NOTIFY_MASK - | GDK_STRUCTURE_MASK - | GDK_KEY_PRESS_MASK - | GDK_FOCUS_CHANGE_MASK); - - gdk_property_change (window, - addr_atom, - type_atom, - 8, - GDK_PROP_MODE_REPLACE, - (guchar *)obj, - sizeof (jobject)); -} - -void -connect_awt_hook (JNIEnv *env, jobject peer_obj, int nwindows, ...) -{ - va_list ap; - jobject *obj; - - obj = NSA_GET_GLOBAL_REF (env, peer_obj); - g_assert (obj); - - va_start (ap, nwindows); - { - int i; - for (i = 0; i < nwindows; i++) - { - GdkWindow* attach = (va_arg (ap, GdkWindow *)); - attach_jobject(attach, obj); - } - } - va_end (ap); -} - -/* - * Attach a Java object that is backed by widget. This callback is - * called after the widget's window has been realized. That way, we - * can be sure that widget->window is non-NULL, and so can have data - * connected to it. - */ -void connect_awt_hook_cb (GtkWidget *widget __attribute__((unused)), - jobject peer) -{ - void *ptr; - - ptr = NSA_GET_PTR (gdk_env(), peer); - - connect_awt_hook (gdk_env(), peer, 1, GTK_WIDGET (ptr)->window); - - gdk_threads_leave (); - - (*gdk_env())->CallVoidMethod (gdk_env(), peer, setCursorID); - - gdk_threads_enter (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c deleted file mode 100644 index 85fe3dd6cbf..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c +++ /dev/null @@ -1,274 +0,0 @@ -/* gtkfiledialogpeer.c -- Native implementation of GtkFileDialogPeer - Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -#include "gnu_java_awt_peer_gtk_GtkFileDialogPeer.h" - -static void handle_response (GtkDialog *dialog, - gint responseId, - jobject peer_obj); - -/* - * Make a new file selection dialog - */ - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create - (JNIEnv *env, jobject obj, jobject parent) -{ - void *parentp; - gpointer widget; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - parentp = NSA_GET_PTR(env, parent); - - gdk_threads_enter (); - - /* FIXME: we should be using the default gnome-vfs backend but it is - not currently thread-safe. See: - http://bugzilla.gnome.org/show_bug.cgi?id=166852 */ - widget = gtk_file_chooser_dialog_new_with_backend - ("Open File", - GTK_WINDOW(parentp), - GTK_FILE_CHOOSER_ACTION_OPEN, - "gtk+", - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - /* GtkFileSelect is not modal by default */ - gtk_window_set_modal (GTK_WINDOW (widget), TRUE); - - /* We must add this window to the group so input in the others are - disable while it is being shown */ - gtk_window_group_add_window (global_gtk_window_group, GTK_WINDOW (widget)); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, widget); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr = NSA_GET_PTR (env, obj); - jobject *gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); - - gdk_threads_enter (); - - g_signal_connect (G_OBJECT (GTK_DIALOG (ptr)), - "response", - GTK_SIGNAL_FUNC (handle_response), *gref); - - gdk_threads_leave (); - - /* Connect the superclass signals. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); -} - -JNIEXPORT jstring JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeGetDirectory - (JNIEnv *env, jobject obj) -{ - void *ptr; - const char *str; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - str = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(ptr)); - - gdk_threads_leave (); - - return (*env)->NewStringUTF(env, str); -} - - -/* This function interfaces with the Java callback method of the same name. - This function extracts the filename from the GtkFileFilterInfo object, - and passes it to the Java method. The Java method will call the filter's - accept() method and will give back the return value. */ -static gboolean filenameFilterCallback (const GtkFileFilterInfo *filter_info, - gpointer obj) -{ - jclass cx; - jmethodID id; - jstring *filename; - gboolean accepted; - - cx = (*gdk_env())->GetObjectClass (gdk_env(), (jobject) obj); - id = (*gdk_env())->GetMethodID (gdk_env(), cx, "filenameFilterCallback", - "(Ljava/lang/String;)Z"); - - filename = (*gdk_env())->NewStringUTF(gdk_env(), filter_info->filename); - - gdk_threads_leave(); - accepted = (*gdk_env())->CallBooleanMethod(gdk_env(), obj, id, filename); - gdk_threads_enter(); - - return accepted; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFilenameFilter - (JNIEnv *env, jobject obj, jobject filter_obj __attribute__((unused))) -{ - void *ptr; - GtkFileFilter *filter; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - filter = gtk_file_filter_new(); - gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, - filenameFilterCallback, obj, NULL); - - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(ptr), filter); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetDirectory - (JNIEnv *env, jobject obj, jstring directory) -{ - void *ptr; - const char *str; - - ptr = NSA_GET_PTR (env, obj); - - str = (*env)->GetStringUTFChars (env, directory, 0); - - gdk_threads_enter (); - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(ptr), str); - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, directory, str); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile - (JNIEnv *env, jobject obj, jstring filename) -{ - void *ptr; - const char *str; - - ptr = NSA_GET_PTR (env, obj); - - str = (*env)->GetStringUTFChars (env, filename, 0); - - gdk_threads_enter (); - gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (ptr), str); - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, filename, str); -} - -static void -handle_response (GtkDialog *dialog __attribute__((unused)), - gint responseId, - jobject peer_obj) -{ - static int isDisposeIDSet = 0; - static int isIDSet = 0; - static jmethodID gtkSetFilenameID; - static jmethodID hideID; - static jmethodID disposeID; - void *ptr; - G_CONST_RETURN gchar *fileName; - jstring str_fileName = NULL; - - /* We only need this for the case when the user closed the window, - or clicked ok or cancel. */ - if (responseId != GTK_RESPONSE_DELETE_EVENT - && responseId != GTK_RESPONSE_ACCEPT - && responseId != GTK_RESPONSE_CANCEL) - return; - - ptr = NSA_GET_PTR (gdk_env(), peer_obj); - - if (responseId == GTK_RESPONSE_DELETE_EVENT) - { - if (!isDisposeIDSet) - { - jclass cx = (*gdk_env())->GetObjectClass (gdk_env(), peer_obj); - disposeID = (*gdk_env())->GetMethodID (gdk_env(), cx, "gtkDisposeFileDialog", "()V"); - isDisposeIDSet = 1; - } - - gdk_threads_leave (); - - /* We can dispose of the dialog now (and unblock show) */ - (*gdk_env())->CallVoidMethod (gdk_env(), peer_obj, disposeID); - - gdk_threads_enter (); - return; - } - - if (responseId == GTK_RESPONSE_ACCEPT) { - fileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (GTK_WIDGET (ptr))); - str_fileName = (*gdk_env())->NewStringUTF (gdk_env(), fileName); - } - - if (!isIDSet) - { - jclass cx = (*gdk_env())->GetObjectClass (gdk_env(), peer_obj); - hideID = (*gdk_env())->GetMethodID (gdk_env(), cx, "gtkHideFileDialog", "()V"); - gtkSetFilenameID = (*gdk_env())->GetMethodID (gdk_env(), cx, - "gtkSetFilename", "(Ljava/lang/String;)V"); - isIDSet = 1; - } - - gdk_threads_leave (); - - /* Set the Java object field 'file' with this value. */ - (*gdk_env())->CallVoidMethod (gdk_env(), peer_obj, gtkSetFilenameID, str_fileName); - - /* We can hide the dialog now (and unblock show) */ - (*gdk_env())->CallVoidMethod (gdk_env(), peer_obj, hideID); - - gdk_threads_enter (); -} - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c deleted file mode 100644 index 9253312f0f6..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c +++ /dev/null @@ -1,223 +0,0 @@ -/* gtkframepeer.c -- Native implementation of GtkFramePeer - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkFramePeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer - (JNIEnv *env, jobject obj) -{ - void *ptr; - void *mptr; - void *fixed; - GList* children; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; - children = gtk_container_get_children (GTK_CONTAINER (fixed)); - - while (children != NULL && !GTK_IS_MENU_SHELL (children->data)) - { - children = children->next; - } - - /* If there's a menu bar, remove it. */ - if (children != NULL) - { - mptr = children->data; - - /* This will actually destroy the MenuBar. By removing it from - its parent, the reference count for the MenuBar widget will - decrement to 0. The widget will be automatically destroyed by - GTK. */ - gtk_container_remove (GTK_CONTAINER (fixed), GTK_WIDGET (mptr)); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer - (JNIEnv *env, jobject obj, jobject menubar) -{ - void *ptr; - void *mptr; - void *fixed; - - ptr = NSA_GET_PTR (env, obj); - mptr = NSA_GET_PTR (env, menubar); - - gdk_threads_enter (); - - fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; - gtk_fixed_put (GTK_FIXED (fixed), mptr, 0, 0); - gtk_widget_show (mptr); - - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_getMenuBarHeight - (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar) -{ - GtkWidget *ptr; - GtkRequisition requisition; - - ptr = NSA_GET_PTR (env, menubar); - - gdk_threads_enter (); - - gtk_widget_size_request (ptr, &requisition); - - gdk_threads_leave (); - - return requisition.height; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidth - (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar, jint width) -{ - GtkWidget *ptr; - GtkRequisition natural_req; - - ptr = NSA_GET_PTR (env, menubar); - - gdk_threads_enter (); - - /* Get the menubar's natural size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); - gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); - - /* Set the menubar's size request to width by natural_req.height. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), - width, natural_req.height); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkFixedSetVisible - (JNIEnv *env, jobject obj, jboolean visible) -{ - void *ptr; - void *fixed; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; - - if (visible) - gtk_widget_show (GTK_WIDGET (fixed)); - else - gtk_widget_hide (GTK_WIDGET (fixed)); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImageFromDecoder - (JNIEnv *env, jobject obj, jobject decoder) -{ - void *ptr; - GdkPixbufLoader *loader = NULL; - GdkPixbuf *pixbuf = NULL; - - ptr = NSA_GET_PTR (env, obj); - - loader = NSA_GET_PB_PTR (env, decoder); - g_assert (loader != NULL); - - gdk_threads_enter (); - - pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); - g_assert (pixbuf != NULL); - - gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf); - - gdk_threads_leave (); -} - -static void -free_pixbuf_data (guchar *pixels, gpointer data __attribute__((unused))) -{ - free(pixels); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImageFromData - (JNIEnv *env, jobject obj, jintArray pixelArray, jint width, jint height) -{ - void *ptr; - GdkPixbuf *pixbuf; - jint *pixels; - int pixels_length, i; - guchar *data; - - ptr = NSA_GET_PTR (env, obj); - - pixels = (*env)->GetIntArrayElements (env, pixelArray, 0); - pixels_length = (*env)->GetArrayLength (env, pixelArray); - - data = malloc (sizeof (guchar) * pixels_length); - for (i = 0; i < pixels_length; i++) - data[i] = (guchar) pixels[i]; - - gdk_threads_enter (); - - pixbuf = gdk_pixbuf_new_from_data (data, - GDK_COLORSPACE_RGB, - TRUE, - 8, - width, - height, - width*4, - free_pixbuf_data, - NULL); - - gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf); - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements(env, pixelArray, pixels, 0); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c deleted file mode 100644 index 7e8a07a7df7..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c +++ /dev/null @@ -1,100 +0,0 @@ -/* gtkgenericpeer.c -- Native implementation of GtkGenericPeer - Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkGenericPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose - (JNIEnv *env, jobject obj) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - /* For now the native state for any object must be a widget. - However, a subclass could override dispose() if required. */ - gtk_widget_destroy (GTK_WIDGET (ptr)); - - gdk_threads_leave (); - - /* Remove entries from state tables */ - NSA_DEL_GLOBAL_REF (env, obj); - NSA_DEL_PTR (env, obj); - - /* - * Wake up the main thread, to make sure it re-checks the window - * destruction condition. - */ - - g_main_context_wakeup (NULL); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkGenericPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET(ptr), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImagePainter.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImagePainter.c deleted file mode 100644 index c7c3b8e5a2e..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImagePainter.c +++ /dev/null @@ -1,168 +0,0 @@ -/* gtkimagepainter.c - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkImagePainter.h" -#include <libart_lgpl/art_misc.h> -#include <libart_lgpl/art_rgb_affine.h> - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkImagePainter_drawPixels - (JNIEnv *env, jobject obj __attribute__((unused)), jobject gc_obj, - jint bg_red, jint bg_green, jint bg_blue, jint x, jint y, jint width, - jint height, jintArray jpixels, jint offset, jint scansize, - jdoubleArray jaffine) -{ - struct graphics *g; - jint *pixels, *elems; - guchar *packed; - int i; - jsize num_pixels; - guchar *j_rgba, *c_rgb; - - g = (struct graphics *) NSA_GET_PTR (env, gc_obj); - - if (!jpixels) - return; - - elems = (*env)->GetIntArrayElements (env, jpixels, NULL); - num_pixels = (*env)->GetArrayLength (env, jpixels); - - /* get a copy of the pixel data so we can modify it */ - pixels = malloc (sizeof (jint) * num_pixels); - memcpy (pixels, elems, sizeof (jint) * num_pixels); - - (*env)->ReleaseIntArrayElements (env, jpixels, elems, 0); - -#ifndef WORDS_BIGENDIAN - /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ - for (i = 0; i < num_pixels; i++) - pixels[i] = SWAPU32 ((unsigned)pixels[i]); -#endif - - packed = (guchar *) malloc (sizeof (guchar) * 3 * num_pixels); - j_rgba = (guchar *) pixels; - c_rgb = packed; - - /* copy over pixels in DirectColorModel format to 24 bit RGB image data, - and process the alpha channel */ - for (i = 0; i < num_pixels; i++) - { - jint ialpha = *j_rgba++; - - switch (ialpha) - { - case 0: /* full transparency */ - *c_rgb++ = bg_red; - *c_rgb++ = bg_green; - *c_rgb++ = bg_blue; - j_rgba += 3; - break; - case 255: /* opaque */ - *c_rgb++ = *j_rgba++; - *c_rgb++ = *j_rgba++; - *c_rgb++ = *j_rgba++; - break; - default: /* compositing required */ - { - jfloat alpha = ialpha / 255.0; - jfloat comp_alpha = 1.0 - alpha; - - *c_rgb++ = *j_rgba++ * alpha + bg_red * comp_alpha; - *c_rgb++ = *j_rgba++ * alpha + bg_green * comp_alpha; - *c_rgb++ = *j_rgba++ * alpha + bg_blue * comp_alpha; - } - break; - } - } - - if (jaffine) - { - jdouble *affine; - ArtAlphaGamma *alphagamma = NULL; - art_u8 *dst; - int new_width, new_height; - - affine = (*env)->GetDoubleArrayElements (env, jaffine, NULL); - - new_width = abs (width * affine[0]); - new_height = abs (height * affine[3]); - - dst = (art_u8 *) malloc (sizeof (art_u8) * 3 * (new_width * new_height)); - - art_rgb_affine (dst, - 0, 0, - new_width, new_height, - new_width * 3, - (art_u8 *) packed + offset * 3, - width, height, - scansize * 3, - affine, - ART_FILTER_NEAREST, - alphagamma); - - (*env)->ReleaseDoubleArrayElements (env, jaffine, affine, JNI_ABORT); - - free (packed); - packed = (guchar *) dst; - - width = scansize = new_width; - height = new_height; - offset = 0; - } - - gdk_threads_enter (); - - if (!g || !GDK_IS_DRAWABLE (g->drawable)) - { - gdk_threads_leave (); - return; - } - - gdk_draw_rgb_image (g->drawable, - g->gc, - x + g->x_offset, - y + g->y_offset, - width, height, GDK_RGB_DITHER_NORMAL, - packed + offset * 3, scansize * 3); - - gdk_threads_leave (); - - free (pixels); - free (packed); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c deleted file mode 100644 index befa265488b..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c +++ /dev/null @@ -1,179 +0,0 @@ -/* gtklabelpeer.c -- Native implementation of GtkLabelPeer - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkLabelPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create - (JNIEnv *env, jobject obj, jstring text, jfloat xalign) -{ - GtkWidget *label; - GtkWidget *eventbox; - const char *str; - - NSA_SET_GLOBAL_REF (env, obj); - - str = (*env)->GetStringUTFChars (env, text, 0); - - gdk_threads_enter (); - - eventbox = gtk_event_box_new (); - label = gtk_label_new (str); - gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5); - gtk_container_add (GTK_CONTAINER (eventbox), label); - gtk_widget_show (label); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, text, str); - - NSA_SET_PTR (env, obj, eventbox); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *label; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter (); - - label = gtk_bin_get_child (GTK_BIN (ptr)); - - if (!label) - return; - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET (label), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText - (JNIEnv *env, jobject obj, jstring text) -{ - const char *str; - void *ptr; - GtkWidget *label; - - ptr = NSA_GET_PTR (env, obj); - - str = (*env)->GetStringUTFChars (env, text, 0); - - gdk_threads_enter (); - - label = gtk_bin_get_child (GTK_BIN (ptr)); - - gtk_label_set_label (GTK_LABEL (label), str); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, text, str); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment - (JNIEnv *env, jobject obj, jfloat xalign) -{ - void *ptr; - GtkWidget *label; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - label = gtk_bin_get_child (GTK_BIN(ptr)); - - gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - GtkWidget *widget; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - /* We assume that -1 is a width or height and not a request for the - widget's natural size. */ - width = width < 0 ? 0 : width; - height = height < 0 ? 0 : height; - - if (!(width == 0 && height == 0)) - { - /* Set the event box's size request... */ - gtk_widget_set_size_request (widget, width, height); - /* ...and the label's size request. */ - gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget)), - width, height); - - if (widget->parent != NULL) - gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); - } - - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c deleted file mode 100644 index 1483147dc99..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c +++ /dev/null @@ -1,513 +0,0 @@ -/* GtkListPeer.c -- implements GtkListPeer's native methods - Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkListPeer.h" - -enum - { - COLUMN_STRING, - N_COLUMNS - }; - -gboolean item_highlighted (GtkTreeSelection *selection, - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - jobject peer); - - -#define TREE_VIEW_FROM_SW(obj) \ - (GTK_TREE_VIEW (GTK_SCROLLED_WINDOW (obj)->container.child)) - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_create - (JNIEnv *env, jobject obj, jint rows) -{ - GtkWidget *sw; - GtkWidget *list; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkListStore *list_store; - GtkTreeIter iter; - GtkRequisition req; - gint i; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING); - /* Add the number of rows so that we can calculate the tree view's - size request. */ - for (i = 0; i < rows; i++) - { - gtk_list_store_append (list_store, &iter); - gtk_list_store_set (list_store, &iter, - COLUMN_STRING, "", - -1); - } - list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (NULL, - renderer, - "text", - COLUMN_STRING, - NULL); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - gtk_tree_view_append_column (GTK_TREE_VIEW (list), column); - - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE); - - gtk_widget_size_request (GTK_WIDGET (list), &req); - - gtk_widget_set_size_request (GTK_WIDGET (list), req.width, req.height); - - gtk_container_add (GTK_CONTAINER (sw), list); - - /* Remove the blank rows. */ - gtk_list_store_clear (list_store); - - gtk_widget_show (list); - gtk_widget_show (sw); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, sw); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr; - jobject *gref; - GtkTreeView *list; - GtkTreeSelection *selection; - - ptr = NSA_GET_PTR (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - g_assert (gref); - - list = TREE_VIEW_FROM_SW (ptr); - - g_signal_connect (G_OBJECT (list), "event", - G_CALLBACK (pre_event_handler), *gref); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); - gtk_tree_selection_set_select_function (selection, item_highlighted, - *gref, NULL); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *list; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter(); - - list = GTK_WIDGET (TREE_VIEW_FROM_SW (ptr)); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET (list), font_desc); - - pango_font_description_free (font_desc); - - (*env)->ReleaseStringUTFChars (env, name, font_name); - - gdk_threads_leave(); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_gtkWidgetRequestFocus - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkWidget *list; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = GTK_WIDGET (TREE_VIEW_FROM_SW (ptr)); - gtk_widget_grab_focus (list); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_append - (JNIEnv *env, jobject obj, jobjectArray items) -{ - void *ptr; - GtkTreeView *list; - GtkTreeIter iter; - GtkTreeModel *list_store; - jint count; - jint i; - - ptr = NSA_GET_PTR (env, obj); - - count = (*env)->GetArrayLength (env, items); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - list_store = gtk_tree_view_get_model (list); - - for (i = 0; i < count; i++) - { - const char *text; - jobject item; - - item = (*env)->GetObjectArrayElement (env, items, i); - - text = (*env)->GetStringUTFChars (env, item, NULL); - gtk_list_store_append (GTK_LIST_STORE (list_store), &iter); - gtk_list_store_set (GTK_LIST_STORE (list_store), &iter, - COLUMN_STRING, text, - -1); - (*env)->ReleaseStringUTFChars (env, item, text); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_add - (JNIEnv *env, jobject obj, jstring text, jint index) -{ - void *ptr; - const char *str; - GtkTreeView *list; - GtkTreeIter iter; - GtkTreeModel *list_store; - - ptr = NSA_GET_PTR (env, obj); - str = (*env)->GetStringUTFChars (env, text, NULL); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - list_store = gtk_tree_view_get_model (list); - - if (index == -1) - gtk_list_store_append (GTK_LIST_STORE (list_store), &iter); - else - gtk_list_store_insert (GTK_LIST_STORE (list_store), &iter, index); - - gtk_list_store_set (GTK_LIST_STORE (list_store), &iter, - COLUMN_STRING, str, -1); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, text, str); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_delItems - (JNIEnv *env, jobject obj, jint start, jint end) -{ - void *ptr; - GtkTreeView *list; - GtkTreeIter iter; - GtkTreeModel *list_store; - jint i; - jint num_items; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - list_store = gtk_tree_view_get_model (list); - - /* Special case: remove all rows. */ - if (end == -1) - gtk_list_store_clear (GTK_LIST_STORE (list_store)); - else - { - i = 0; - num_items = end - start + 1; - gtk_tree_model_iter_nth_child (list_store, &iter, NULL, start); - while (i < num_items) - { - gtk_list_store_remove (GTK_LIST_STORE (list_store), &iter); - i++; - } - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_select - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - GtkTreeView *list; - GtkTreePath *path; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - path = gtk_tree_path_new_from_indices (index, -1); - gtk_tree_view_set_cursor (list, path, NULL, FALSE); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_deselect - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - GtkTreeView *list; - GtkTreeSelection *selection; - GtkTreePath *path; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - selection = gtk_tree_view_get_selection (list); - path = gtk_tree_path_new_from_indices (index, -1); - gtk_tree_selection_unselect_path (selection, path); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_getSize - (JNIEnv *env, jobject obj, jint rows, jint visible_rows, jintArray jdims) -{ - void *ptr; - jint *dims; - GtkRequisition current_req; - GtkRequisition natural_req; - - dims = (*env)->GetIntArrayElements (env, jdims, NULL); - dims[0] = dims[1] = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - /* Save the widget's current size request. */ - gtk_widget_size_request (GTK_WIDGET (ptr), ¤t_req); - - /* Get the widget's "natural" size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); - gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); - - /* Reset the widget's size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), - current_req.width, current_req.height); - - dims[0] = natural_req.width; - - /* Calculate the final height, by comparing the number of rows - in the list to the number of rows requested by the caller. - FIXME: Is there a GTK method that counts the number of rows - in the list? If so, we don't need to bring visible_rows from - the Java peer. */ - if (rows == visible_rows) - dims[1] = natural_req.height; - else - dims[1] = natural_req.height / visible_rows * rows; - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); -} - - -JNIEXPORT jintArray JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_getSelectedIndexes - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkTreeView *list; - GtkTreeSelection *selection; - jintArray result_array; - jint *result_array_iter; - GList *current_row; - GList *rows; - gint *indices; - jint count; - jint i; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - selection = gtk_tree_view_get_selection (list); - count = gtk_tree_selection_count_selected_rows (selection); - if (count > 0) - { - current_row = rows = gtk_tree_selection_get_selected_rows (selection, NULL); - - result_array = (*env)->NewIntArray (env, count); - result_array_iter = (*env)->GetIntArrayElements (env, result_array, NULL); - - for (i = 0; i < count; i++) - { - indices = gtk_tree_path_get_indices (current_row->data); - result_array_iter[i] = indices ? indices[0] : -1; - current_row = g_list_next (current_row); - } - - if (rows) - { - g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL); - g_list_free (rows); - } - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements (env, result_array, result_array_iter, 0); - - return result_array; - } - else - gdk_threads_leave (); - - return (jintArray) NULL; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_makeVisible - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - GtkTreeView *list; - GtkTreePath *path; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - path = gtk_tree_path_new_from_indices (index, -1); - gtk_tree_view_scroll_to_cell (list, path, NULL, FALSE, 0.0, 0.0); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_setMultipleMode - (JNIEnv *env, jobject obj, jboolean mode) -{ - void *ptr; - GtkTreeView *list; - GtkTreeSelection *selection; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - list = TREE_VIEW_FROM_SW (ptr); - selection = gtk_tree_view_get_selection (list); - gtk_tree_selection_set_mode (selection, - mode ? GTK_SELECTION_MULTIPLE - : GTK_SELECTION_SINGLE); - - gdk_threads_leave (); -} - -gboolean -item_highlighted (GtkTreeSelection *selection __attribute__((unused)), - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - jobject peer) -{ - GtkTreeIter iter; - jint row; - gint *indices; - - if (gtk_tree_model_get_iter (model, &iter, path)) - { - indices = gtk_tree_path_get_indices (path); - row = indices ? indices[0] : -1; - - if (!path_currently_selected) - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postListItemEventID, - row, - (jint) AWT_ITEM_SELECTED); - else - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postListItemEventID, - row, - (jint) AWT_ITEM_DESELECTED); - } - - return TRUE; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c deleted file mode 100644 index 0a88f645bd2..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c +++ /dev/null @@ -1,112 +0,0 @@ -/* gtkmenubarpeer.c -- Native implementation of GtkMenuBarPeer - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkMenuBarPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_create - (JNIEnv *env, jobject obj) -{ - GtkWidget *widget; - - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - widget = gtk_menu_bar_new (); - gtk_widget_show (widget); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, widget); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu - (JNIEnv *env, jobject obj, jobject menupeer) -{ - void *mbar, *menu; - - mbar = NSA_GET_PTR (env, obj); - menu = NSA_GET_PTR (env, menupeer); - - gdk_threads_enter (); - gtk_menu_shell_append (GTK_MENU_SHELL (mbar), GTK_WIDGET (menu)); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_nativeSetHelpMenu - (JNIEnv *env, jobject obj, jobject menupeer) -{ - static void *helpmenu; - void *mbar, *menu; - GList *list; - - mbar = NSA_GET_PTR (env, obj); - menu = NSA_GET_PTR (env, menupeer); - - gdk_threads_enter (); - if (helpmenu != NULL) - { - list = gtk_container_children (GTK_CONTAINER (mbar)); - while (list != NULL && list->data != helpmenu) - list = list->next; - if (list != NULL && list->data == helpmenu) - gtk_container_remove (GTK_CONTAINER (mbar), GTK_WIDGET (list->data)); - } - helpmenu = menu; - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_delMenu - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - GList *list; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - list = gtk_container_children (GTK_CONTAINER (ptr)); - list = g_list_nth (list, index); - gtk_container_remove (GTK_CONTAINER (ptr), GTK_WIDGET (list->data)); - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c deleted file mode 100644 index 01b74e46c57..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c +++ /dev/null @@ -1,56 +0,0 @@ -/* gtkmenucomponentpeer.c -- Native implementation of GtkMenuComponentPeer - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkMenuComponentPeer.h" - -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose - (JNIEnv *env, jobject obj) -{ - /* For MenuComponents and its subclasses, the widgets are - automatically destroyed by Gtk when the parent MenuBar - is removed from the Frame. So we avoid the widget - destruction in GtkGenericPeer dispose() by overriding - it here. */ - - /* However, references to the Java objects still exist in the - state tables, so we still have to remove those. */ - - NSA_DEL_GLOBAL_REF (env, obj); - NSA_DEL_PTR (env, obj); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c deleted file mode 100644 index 76850c8143c..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c +++ /dev/null @@ -1,170 +0,0 @@ -/* gtkmenuitempeer.c -- Native implementation of GtkMenuItemPeer - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkMenuItemPeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" - -static void item_activate (GtkMenuItem *item __attribute__((unused)), - jobject peer_obj); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create - (JNIEnv *env, jobject obj, jstring label) -{ - GtkWidget *widget; - const char *str; - - NSA_SET_GLOBAL_REF (env, obj); - - str = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - /* "-" signals that we need a separator. */ - if (strcmp (str, "-") == 0) - widget = gtk_menu_item_new (); - else - widget = gtk_menu_item_new_with_label (str); - - gtk_widget_show (widget); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, str); - - NSA_SET_PTR (env, obj, widget); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr = NSA_GET_PTR (env, obj); - jobject *gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); - - gdk_threads_enter (); - - g_signal_connect (G_OBJECT (ptr), "activate", - G_CALLBACK (item_activate), *gref); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *label; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - label = gtk_bin_get_child (GTK_BIN (ptr)); - - if (label) - { - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET(label), font_desc); - - pango_font_description_free (font_desc); - } - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setEnabled - (JNIEnv *env, jobject obj, jboolean enabled) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - gtk_widget_set_sensitive (GTK_WIDGET (ptr), enabled); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel - (JNIEnv *env, jobject obj, jstring label) -{ - void *ptr; - const char *str; - GtkAccelLabel *accel_label; - - ptr = NSA_GET_PTR (env, obj); - - str = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - accel_label = GTK_ACCEL_LABEL (GTK_BIN (ptr)->child); - - gtk_label_set_text (GTK_LABEL (accel_label), str); - gtk_accel_label_refetch (accel_label); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, str); -} - -static void -item_activate (GtkMenuItem *item __attribute__((unused)), jobject peer_obj) -{ - (*gdk_env())->CallVoidMethod (gdk_env(), peer_obj, - postMenuActionEventID); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c deleted file mode 100644 index 21c738ca5d2..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c +++ /dev/null @@ -1,172 +0,0 @@ -/* gtkmenupeer.c -- Native implementation of GtkMenuPeer - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkMenuPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup - (JNIEnv *env, jobject obj, jobject parent) -{ - void *ptr1, *ptr2; - - ptr1 = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - if (!parent) - { - gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), - gtk_accel_group_new ()); - } - else - { - GtkAccelGroup *parent_accel; - - ptr2 = NSA_GET_PTR (env, parent); - parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu)); - - gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), - parent_accel); - } - - gdk_threads_leave (); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create - (JNIEnv *env, jobject obj, jstring label) -{ - GtkWidget *menu_title, *menu, *toplevel; - const char *str; - - NSA_SET_GLOBAL_REF (env, obj); - - str = (*env)->GetStringUTFChars (env, label, NULL); - - gdk_threads_enter (); - - menu = gtk_menu_new (); - - if (str != NULL) - menu_title = gtk_menu_item_new_with_label (str); - else - menu_title = gtk_menu_item_new(); - - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu); - - /* Allow this menu to grab the pointer. */ - toplevel = gtk_widget_get_toplevel (menu); - if (GTK_IS_WINDOW (toplevel)) - { - gtk_window_group_add_window (global_gtk_window_group, - GTK_WINDOW(toplevel)); - } - - gtk_widget_show (menu_title); - - NSA_SET_PTR (env, obj, menu_title); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, label, str); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addTearOff - (JNIEnv *env, jobject obj) -{ - void *ptr1; - GtkWidget *menu, *item; - - ptr1 = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (ptr1)); - item = gtk_tearoff_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - gtk_widget_show (item); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem - (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift) -{ - void *ptr1, *ptr2; - GtkWidget *menu; - - ptr1 = NSA_GET_PTR (env, obj); - ptr2 = NSA_GET_PTR (env, menuitempeer); - - gdk_threads_enter (); - - menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1)); - gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2)); - - if (key) - { - gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate", - gtk_menu_get_accel_group (GTK_MENU (menu)), key, - (GDK_CONTROL_MASK - | ((shift) ? GDK_SHIFT_MASK : 0)), - GTK_ACCEL_VISIBLE); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMenuPeer_delItem - (JNIEnv *env, jobject obj, jint index) -{ - void *ptr; - GList *list; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - list = gtk_container_children (GTK_CONTAINER (ptr)); - list = g_list_nth (list, index); - gtk_container_remove (GTK_CONTAINER (ptr), GTK_WIDGET (list->data)); - gdk_threads_leave (); -} - - diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c deleted file mode 100644 index 63ead82036d..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c +++ /dev/null @@ -1,62 +0,0 @@ -/* gtkpanelpeer.c -- Native implementation of GtkPanelPeer - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -#include "gnu_java_awt_peer_gtk_GtkPanelPeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create - (JNIEnv *env, jobject obj) -{ - GtkWidget *widget; - - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - widget = gtk_fixed_new (); - - gtk_fixed_set_has_window (GTK_FIXED (widget), TRUE); - - GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, widget); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c deleted file mode 100644 index 70ebbb796ad..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c +++ /dev/null @@ -1,101 +0,0 @@ -/* gtkpopupmenupeer.c -- Native implementation of GtkPopupMenuPeer - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkPopupMenuPeer.h" - -struct pos -{ - gint x; - gint y; -}; - -static void -menu_pos (GtkMenu *menu __attribute__((unused)), - gint *x, gint *y, - gboolean *push_in, - gpointer user_data) -{ - struct pos *p = (struct pos *) user_data; - - *x = p->x; - *y = p->y; - *push_in = TRUE; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show - (JNIEnv *env, jobject obj, jint x, jint y, jlong time) -{ - void *ptr; - struct pos *p; - - ptr = NSA_GET_PTR (env, obj); - - p = g_malloc (sizeof (struct pos)); - p->x = x; - p->y = y; - - gdk_threads_enter (); - gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu), - NULL, NULL, menu_pos, p, 0, time); - gdk_threads_leave (); - - g_free (p); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup - (JNIEnv *env, jobject obj, jobject parent) -{ - void *ptr1, *ptr2; - GtkMenu *menu; - - ptr1 = NSA_GET_PTR (env, obj); - ptr2 = NSA_GET_PTR (env, parent); - - gdk_threads_enter (); - menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu); - gtk_menu_set_accel_group (menu, gtk_accel_group_new ()); - /* FIXME: update this to use GTK-2.4 GtkActions. */ -#if 0 - _gtk_accel_group_attach (gtk_menu_get_accel_group (menu), - G_OBJECT (gtk_widget_get_toplevel (ptr2))); -#endif - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c deleted file mode 100644 index 372458360d0..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c +++ /dev/null @@ -1,165 +0,0 @@ -/* gtkscrollbarpeer.c -- Native implementation of GtkScrollbarPeer - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -#include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h" - -static void post_change_event (GtkRange *range, jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create -(JNIEnv *env, jobject obj, jint orientation, jint value, - jint min, jint max, jint step_incr, jint page_incr, jint visible_amount) -{ - GtkWidget *scrollbar; - GtkObject *adj; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - adj = gtk_adjustment_new ((gdouble) value, - (gdouble) min, - (gdouble) max, - (gdouble) step_incr, - (gdouble) page_incr, - (gdouble) visible_amount); - - scrollbar = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) : - gtk_hscrollbar_new (GTK_ADJUSTMENT (adj)); - - GTK_RANGE (scrollbar)->round_digits = 0; - /* These calls seem redundant but they are not. They clamp values - so that the slider's entirety is always between the two - steppers. */ - gtk_range_set_range (GTK_RANGE (scrollbar), (gdouble) min, (gdouble) max); - gtk_range_set_value (GTK_RANGE (scrollbar), (gdouble) value); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, scrollbar); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr = NSA_GET_PTR (env, obj); - jobject *gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); - - gdk_threads_enter (); - - g_signal_connect (G_OBJECT (ptr), "value-changed", - G_CALLBACK (post_change_event), *gref); - - gdk_threads_leave (); - - /* Connect the superclass signals. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setLineIncrement - (JNIEnv *env, jobject obj, jint amount) -{ - void *ptr; - GtkAdjustment *adj; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - adj = gtk_range_get_adjustment (GTK_RANGE (ptr)); - adj->step_increment = (gdouble) amount; - gtk_adjustment_changed (adj); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setPageIncrement - (JNIEnv *env, jobject obj, jint amount) -{ - void *ptr; - GtkAdjustment *adj; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - adj = gtk_range_get_adjustment (GTK_RANGE (ptr)); - adj->page_increment = (gdouble) amount; - gtk_adjustment_changed (adj); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setValues - (JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max) -{ - void *ptr; - GtkAdjustment *adj; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - adj = gtk_range_get_adjustment (GTK_RANGE (ptr)); - adj->page_size = (gdouble) visible; - - gtk_range_set_range (GTK_RANGE (ptr), (gdouble) min, (gdouble) max); - gtk_range_set_value (GTK_RANGE (ptr), (gdouble) value); - - gtk_adjustment_changed (adj); - - gdk_threads_leave (); -} - -static void -post_change_event (GtkRange *range, jobject peer) -{ - GtkAdjustment *adj; - adj = gtk_range_get_adjustment (range); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, postAdjustmentEventID, - AWT_ADJUSTMENT_TRACK, (jint) adj->value); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c deleted file mode 100644 index 474d334d91f..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c +++ /dev/null @@ -1,193 +0,0 @@ -/* gtkscrollpanepeer.c -- Native implementation of GtkScrollPanePeer - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkScrollPanePeer.h" - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_create - (JNIEnv *env, jobject obj, int width, int height) -{ - GtkWidget *sw; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - sw = gtk_scrolled_window_new (NULL, NULL); - - gtk_widget_set_size_request (sw, width, height); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, sw); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_setScrollPosition - (JNIEnv *env, jobject obj, jint x, jint y) -{ - GtkAdjustment *hadj, *vadj; - GtkScrolledWindow *sw; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW (ptr); - - hadj = gtk_scrolled_window_get_hadjustment (sw); - vadj = gtk_scrolled_window_get_vadjustment (sw); - - gtk_adjustment_set_value (hadj, x); - gtk_adjustment_set_value (vadj, y); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_gtkScrolledWindowSetHScrollIncrement - (JNIEnv *env, jobject obj, jint u) -{ - GtkAdjustment *hadj; - GtkScrolledWindow *sw; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW(ptr); - - hadj = gtk_scrolled_window_get_hadjustment (sw); - hadj->step_increment = u; - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_gtkScrolledWindowSetVScrollIncrement - (JNIEnv *env, jobject obj, jint u) -{ - GtkAdjustment *vadj; - GtkScrolledWindow *sw; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW(ptr); - - vadj = gtk_scrolled_window_get_hadjustment (sw); - vadj->step_increment = u; - - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getHScrollbarHeight - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkScrolledWindow *sw; - GtkRequisition requisition; - jint height = 0; - jint spacing = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW (ptr); - - gtk_widget_size_request (sw->hscrollbar, &requisition); - gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); - height = requisition.height + spacing; - - gdk_threads_leave (); - - return height; -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getVScrollbarWidth - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkScrolledWindow *sw; - GtkRequisition requisition; - jint width = 0; - jint spacing = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW (ptr); - - gtk_widget_size_request (sw->vscrollbar, &requisition); - gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); - width = requisition.width + spacing; - - gdk_threads_leave (); - - return width; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_setPolicy - (JNIEnv *env, jobject obj, jint policy) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - switch (policy) - { - case AWT_SCROLLPANE_SCROLLBARS_AS_NEEDED: - policy = GTK_POLICY_AUTOMATIC; - break; - case AWT_SCROLLPANE_SCROLLBARS_ALWAYS: - policy = GTK_POLICY_ALWAYS; - break; - case AWT_SCROLLPANE_SCROLLBARS_NEVER: - policy = GTK_POLICY_NEVER; - break; - } - - gdk_threads_enter (); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ptr), policy, policy); - gdk_threads_leave (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c deleted file mode 100644 index 002a7a8c24d..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c +++ /dev/null @@ -1,248 +0,0 @@ -/* gtktextareapeer.c -- Native implementation of GtkTextAreaPeer - Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkTextAreaPeer.h" - -#define TEXT_FROM_SW(obj) (GTK_TEXT_VIEW(GTK_SCROLLED_WINDOW (obj)->container.child)) -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create - (JNIEnv *env, jobject obj, - jint textview_width, jint textview_height, jint scroll) -{ - GtkWidget *text, *sw; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - text = gtk_text_view_new (); - gtk_widget_set_size_request (text, textview_width, textview_height); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (text), TRUE); - - gtk_widget_show (text); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (sw), text); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - /* horizontal scrollbar */ - (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH - || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) ? - GTK_POLICY_ALWAYS : GTK_POLICY_NEVER, - /* vertical scrollbar */ - (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH - || scroll == AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY) ? - GTK_POLICY_ALWAYS : GTK_POLICY_NEVER); - - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), - (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH - || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) - ? GTK_WRAP_NONE : GTK_WRAP_WORD); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, sw); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_insert - (JNIEnv *env, jobject obj, jstring contents, jint position) -{ - GtkTextBuffer *buf; - GtkTextIter iter; - GtkWidget *text; - void *ptr; - const char *str; - int pos=position; - - ptr = NSA_GET_PTR (env, obj); - str = (*env)->GetStringUTFChars (env, contents, NULL); - - gdk_threads_enter (); - - text = GTK_WIDGET (TEXT_FROM_SW (ptr)); - - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); - gtk_text_buffer_insert (buf, &iter, str, strlen (str)); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, contents, str); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_replaceRange - (JNIEnv *env, jobject obj, jstring contents, jint start, jint end) -{ - GtkWidget *text; - GtkTextBuffer *buf; - GtkTextIter iter, startIter, endIter; - void *ptr; - const char *str; - int mystart = start; - int myend = end; - - ptr = NSA_GET_PTR (env, obj); - str = (*env)->GetStringUTFChars (env, contents, NULL); - - gdk_threads_enter (); - - text = GTK_WIDGET (TEXT_FROM_SW (ptr)); - - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - - gtk_text_buffer_get_iter_at_offset (buf, &startIter, mystart); - gtk_text_buffer_get_iter_at_offset (buf, &endIter, myend); - gtk_text_buffer_delete (buf, &startIter, &endIter); - - gtk_text_buffer_get_iter_at_offset (buf, &iter, mystart); - gtk_text_buffer_insert(buf, &iter, str, strlen (str)); - - gdk_threads_leave (); - (*env)->ReleaseStringUTFChars (env, contents, str); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *text; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - text = GTK_WIDGET (TEXT_FROM_SW (ptr)); - - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET (text), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetRequestFocus - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkWidget *text; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - text = GTK_WIDGET (TEXT_FROM_SW (ptr)); - - gtk_widget_grab_focus (text); - - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getHScrollbarHeight - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkScrolledWindow *sw; - GtkRequisition requisition; - jint height = 0; - jint spacing = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW (ptr); - - if (sw) - { - gtk_widget_size_request (sw->hscrollbar, &requisition); - gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); - height = requisition.height + spacing; - } - - gdk_threads_leave (); - - return height; -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getVScrollbarWidth - (JNIEnv *env, jobject obj) -{ - void *ptr; - GtkScrolledWindow *sw; - GtkRequisition requisition; - jint width = 0; - jint spacing = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - sw = GTK_SCROLLED_WINDOW (ptr); - - if (sw) - { - gtk_widget_size_request (sw->vscrollbar, &requisition); - gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); - width = requisition.width + spacing; - } - - gdk_threads_leave (); - - return width; -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c deleted file mode 100644 index a6d0a612445..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c +++ /dev/null @@ -1,498 +0,0 @@ -/* gtktextcomponentpeer.c -- Native implementation of GtkTextComponentPeer - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -#include "gnu_java_awt_peer_gtk_GtkTextComponentPeer.h" - -static void textcomponent_changed_cb (GtkEditable *editable, - jobject peer); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - GtkTextView *text = NULL; - GtkTextBuffer *buf; - void *ptr = NSA_GET_PTR (env, obj); - jobject *gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); - - gdk_threads_enter (); - - if (GTK_IS_ENTRY(ptr)) - { - g_signal_connect (GTK_EDITABLE (ptr), "changed", - G_CALLBACK (textcomponent_changed_cb), *gref); - - gdk_threads_leave (); - - /* Connect the superclass signals. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, *gref); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_TEXT_VIEW (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (text); - if (buf) - g_signal_connect (buf, "changed", - G_CALLBACK (textcomponent_changed_cb), *gref); - - /* Connect the superclass signals. */ - /* FIXME: Cannot do that here or it will get the sw and not the list. - We must a generic way of doing this. */ - /* Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, - obj); */ - g_signal_connect (GTK_OBJECT (text), "event", - G_CALLBACK (pre_event_handler), *gref); - - gdk_threads_leave (); - } - } -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getCaretPosition - (JNIEnv *env, jobject obj) -{ - void *ptr; - int pos = 0; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextMark *mark; - GtkTextIter iter; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - pos = gtk_editable_get_position (editable); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - mark = gtk_text_buffer_get_insert (buf); - gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); - pos = gtk_text_iter_get_offset (&iter); - } - } - - gdk_threads_leave (); - - return pos; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_setCaretPosition - (JNIEnv *env, jobject obj, jint pos) -{ - void *ptr; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextIter iter; - GtkTextMark *oldmark; - GtkTextIter olditer; - int oldpos; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - gtk_editable_set_position (editable, pos); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - - /* Save old position. */ - oldmark = gtk_text_buffer_get_insert (buf); - gtk_text_buffer_get_iter_at_mark (buf, &olditer, oldmark); - oldpos = gtk_text_iter_get_offset (&olditer); - - /* Move to new position. */ - gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); - gtk_text_buffer_place_cursor (buf, &iter); - - /* Scroll to new position. Alignment is determined - comparing the new position to the old position. */ - if (oldpos > pos) - gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), - &iter, 0, TRUE, 0, 0); - else if (oldpos < pos) - gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), - &iter, 0, TRUE, 1, 1); - } - } - - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionStart - (JNIEnv *env, jobject obj) -{ - void *ptr; - int pos = 0; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextIter start; - GtkTextIter end; - int starti, endi; - GtkTextMark *mark; - GtkTextIter iter; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - if (gtk_editable_get_selection_bounds (editable, &starti, &endi)) - pos = starti; - else - pos = gtk_editable_get_position (editable); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - if (gtk_text_buffer_get_selection_bounds(buf, &start, &end)) - pos = gtk_text_iter_get_offset (&start); - else - { - mark = gtk_text_buffer_get_insert (buf); - gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); - pos = gtk_text_iter_get_offset (&iter); - } - } - } - - gdk_threads_leave (); - - return pos; -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionEnd - (JNIEnv *env, jobject obj) -{ - void *ptr; - int pos = 0; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextIter start; - GtkTextIter end; - int starti, endi; - GtkTextMark *mark; - GtkTextIter iter; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - if (gtk_editable_get_selection_bounds (editable, &starti, &endi)) - pos = endi; - else - pos = gtk_editable_get_position (editable); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - if (gtk_text_buffer_get_selection_bounds(buf, &start, &end)) - pos = gtk_text_iter_get_offset (&end); - else - { - mark = gtk_text_buffer_get_insert (buf); - gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); - pos = gtk_text_iter_get_offset (&iter); - } - } - } - - gdk_threads_leave (); - - return pos; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_select - (JNIEnv *env, jobject obj, jint start, jint end) -{ - void *ptr; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextIter iter; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - gtk_editable_select_region (editable, start, end); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - gtk_text_buffer_get_iter_at_offset (buf, &iter, start); - /* quickly move both 'insert' and 'selection_bound' to the - same position */ - gtk_text_buffer_place_cursor (buf, &iter); - gtk_text_buffer_get_iter_at_offset (buf, &iter, end); - gtk_text_buffer_move_mark_by_name (buf, "selection_bound", &iter); - } - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_setEditable - (JNIEnv *env, jobject obj, jboolean state) -{ - void *ptr; - GtkEditable *editable; - GtkWidget *text = NULL; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - gtk_editable_set_editable (editable, state); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - gtk_text_view_set_editable (GTK_TEXT_VIEW (text), state); - } - } - - gdk_threads_leave (); -} - -JNIEXPORT jstring JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getText - (JNIEnv *env, jobject obj) -{ - void *ptr; - char *contents = NULL; - jstring jcontents; - GtkEditable *editable; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - GtkTextIter start, end; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - editable = GTK_EDITABLE (ptr); - contents = gtk_editable_get_chars (editable, 0, -1); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - gtk_text_buffer_get_start_iter (buf, &start); - gtk_text_buffer_get_end_iter (buf, &end); - contents = gtk_text_buffer_get_text (buf, &start, &end, FALSE); - } - } - - gdk_threads_leave (); - - jcontents = (*env)->NewStringUTF (env, contents); - g_free (contents); - - return jcontents; -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_setText - (JNIEnv *env, jobject obj, jstring contents) -{ - void *ptr; - const char *str; - GtkWidget *text = NULL; - GtkTextBuffer *buf; - - ptr = NSA_GET_PTR (env, obj); - str = (*env)->GetStringUTFChars (env, contents, NULL); - - gdk_threads_enter (); - - if (GTK_IS_EDITABLE (ptr)) - { - gtk_entry_set_text (GTK_ENTRY (ptr), str); - } - else - { - if (GTK_IS_SCROLLED_WINDOW (ptr)) - { - text = GTK_WIDGET (GTK_TEXT_VIEW (GTK_SCROLLED_WINDOW (ptr)->container.child)); - } - else if (GTK_IS_TEXT_VIEW (ptr)) - { - text = GTK_WIDGET (ptr); - } - - if (text) - { - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); - gtk_text_buffer_set_text (buf, str, strlen (str)); - } - } - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, contents, str); -} - -static void -textcomponent_changed_cb (GtkEditable *editable __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, postTextEventID); - gdk_threads_enter (); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c deleted file mode 100644 index b7e4a1677a7..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c +++ /dev/null @@ -1,209 +0,0 @@ -/* gtktextfieldpeer.c -- Native implementation of GtkTextFieldPeer - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkTextFieldPeer.h" - -static jint -get_border_width (GtkWidget *entry); - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_create - (JNIEnv *env, jobject obj, jint text_width) -{ - GtkWidget *entry; - - /* Create global reference and save it for future use */ - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - entry = gtk_entry_new (); - gtk_widget_set_size_request (entry, - text_width + 2 * get_border_width (entry), -1); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, entry); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkWidgetSetBackground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor color; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - color.red = (red / 255.0) * 65535; - color.green = (green / 255.0) * 65535; - color.blue = (blue / 255.0) * 65535; - - gdk_threads_enter (); - - gtk_widget_modify_base (GTK_WIDGET (ptr), GTK_STATE_NORMAL, &color); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkWidgetSetForeground - (JNIEnv *env, jobject obj, jint red, jint green, jint blue) -{ - GdkColor color; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - color.red = (red / 255.0) * 65535; - color.green = (green / 255.0) * 65535; - color.blue = (blue / 255.0) * 65535; - - gdk_threads_enter (); - - gtk_widget_modify_text (GTK_WIDGET (ptr), GTK_STATE_NORMAL, &color); - gtk_widget_modify_base (GTK_WIDGET (ptr), GTK_STATE_SELECTED, &color); - - gdk_threads_leave (); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkEntryGetBorderWidth - (JNIEnv *env, jobject obj) -{ - void *ptr; - int border_width = 0; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - border_width = get_border_width (GTK_WIDGET (ptr)); - - gdk_threads_leave (); - - return border_width; -} - -/* GTK hard-codes this value. It is the space between a GtkEntry's - frame and its text. */ -#define INNER_BORDER 2 - -static jint -get_border_width (GtkWidget *entry) -{ - gint focus_width; - gboolean interior_focus; - int x_border_width = INNER_BORDER; - - gtk_widget_style_get (entry, - "interior-focus", &interior_focus, - "focus-line-width", &focus_width, - NULL); - - if (GTK_ENTRY (entry)->has_frame) - x_border_width += entry->style->xthickness; - - if (!interior_focus) - x_border_width += focus_width; - - return x_border_width; -} - -#undef INNER_BORDER - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setEchoChar - (JNIEnv *env, jobject obj, jchar c) -{ - void *ptr; - GtkEntry *entry; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - entry = GTK_ENTRY (ptr); - - if (c != 0) - { - /* FIXME: use gtk_entry_set_invisible_char (GtkEntry *entry, - gunichar ch) here. That means we must convert from jchar - (utf16) to gunichar (ucs4). */ - gtk_entry_set_visibility (entry, FALSE); - } - else - gtk_entry_set_visibility (entry, TRUE); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkWidgetModifyFont - (JNIEnv *env, jobject obj, jstring name, jint style, jint size) -{ - const char *font_name; - void *ptr; - GtkWidget *entry; - PangoFontDescription *font_desc; - - ptr = NSA_GET_PTR (env, obj); - - entry = GTK_WIDGET (ptr); - font_name = (*env)->GetStringUTFChars (env, name, NULL); - - gdk_threads_enter(); - - font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * dpi_conversion_factor); - - if (style & AWT_STYLE_BOLD) - pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); - - if (style & AWT_STYLE_ITALIC) - pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - - gtk_widget_modify_font (GTK_WIDGET(entry), font_desc); - - pango_font_description_free (font_desc); - - gdk_threads_leave(); - - (*env)->ReleaseStringUTFChars (env, name, font_name); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c deleted file mode 100644 index e831bc4c458..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c +++ /dev/null @@ -1,537 +0,0 @@ -/* gtktoolkit.c -- Native portion of GtkToolkit - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkToolkit.h" -#include "gthread-jni.h" - -#include <sys/time.h> - -#ifdef JVM_SUN - struct state_table *native_state_table; - struct state_table *native_global_ref_table; -#endif - -jmethodID setBoundsCallbackID; - -jmethodID postActionEventID; -jmethodID postMenuActionEventID; -jmethodID postMouseEventID; -jmethodID postConfigureEventID; -jmethodID postExposeEventID; -jmethodID postKeyEventID; -jmethodID postFocusEventID; -jmethodID postAdjustmentEventID; -jmethodID postItemEventID; -jmethodID choicePostItemEventID; -jmethodID postListItemEventID; -jmethodID postTextEventID; -jmethodID postWindowEventID; -jmethodID postInsetsChangedEventID; -jmethodID windowGetWidthID; -jmethodID windowGetHeightID; - -jmethodID beginNativeRepaintID; -jmethodID endNativeRepaintID; - -jmethodID initComponentGraphicsID; -jmethodID initComponentGraphics2DID; -jmethodID setCursorID; - -JavaVM *java_vm; - -union env_union -{ - void *void_env; - JNIEnv *jni_env; -}; - -JNIEnv * -gdk_env() -{ - union env_union tmp; - g_assert((*java_vm)->GetEnv(java_vm, &tmp.void_env, JNI_VERSION_1_2) == JNI_OK); - return tmp.jni_env; -} - - -GtkWindowGroup *global_gtk_window_group; - -static void init_glib_threads(JNIEnv *, jint); - -double dpi_conversion_factor; - -static void init_dpi_conversion_factor (void); -static void dpi_changed_cb (GtkSettings *settings, - GParamSpec *pspec); - -/* - * Call gtk_init. It is very important that this happen before any other - * gtk calls. - * - * The portableNativeSync argument may have the values: - * 1 if the Java property gnu.classpath.awt.gtk.portable.native.sync - * is set to "true". - * 0 if it is set to "false" - * -1 if unset. - */ - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, - jclass clazz __attribute__((unused)), - jint portableNativeSync) -{ - int argc = 1; - char **argv; - char *homedir, *rcpath = NULL; - - jclass gtkgenericpeer, gtkcomponentpeer, gtkchoicepeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer, - gtkmenuitempeer, gtktextcomponentpeer, window, gdkgraphics, gdkgraphics2d; - - gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer"); - - NSA_INIT (env, gtkgenericpeer); - - g_assert((*env)->GetJavaVM(env, &java_vm) == 0); - - /* GTK requires a program's argc and argv variables, and requires that they - be valid. Set it up. */ - argv = (char **) g_malloc (sizeof (char *) * 2); - argv[0] = (char *) g_malloc(1); -#if 1 - strcpy(argv[0], ""); -#else /* The following is a more efficient alternative, but less intuitively - * expresses what we are trying to do. This code is only run once, so - * I'm going for intuitive. */ - argv[0][0] = '\0'; -#endif - argv[1] = NULL; - - init_glib_threads(env, portableNativeSync); - - /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */ - gdk_threads_init(); - - gtk_init (&argc, &argv); - - gdk_rgb_init (); - gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); - gtk_widget_set_default_visual (gdk_rgb_get_visual ()); - - /* Make sure queued calls don't get sent to GTK/GDK while - we're shutting down. */ - atexit (gdk_threads_enter); - - gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL); - - if ((homedir = getenv ("HOME"))) - { - rcpath = (char *) g_malloc (strlen (homedir) + strlen (RC_FILE) + 2); - sprintf (rcpath, "%s/%s", homedir, RC_FILE); - } - - gtk_rc_parse ((rcpath) ? rcpath : RC_FILE); - - g_free (rcpath); - g_free (argv[0]); - g_free (argv); - - /* setup cached IDs for posting GTK events to Java */ - - window = (*env)->FindClass (env, "java/awt/Window"); - - gtkcomponentpeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkComponentPeer"); - gtkchoicepeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkChoicePeer"); - gtkwindowpeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkWindowPeer"); - gtkscrollbarpeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkScrollbarPeer"); - gtklistpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkListPeer"); - gtkmenuitempeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkMenuItemPeer"); - gtktextcomponentpeer = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GtkTextComponentPeer"); - gdkgraphics = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GdkGraphics"); - gdkgraphics2d = (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GdkGraphics2D"); - setBoundsCallbackID = (*env)->GetMethodID (env, window, - "setBoundsCallback", - "(IIII)V"); - - postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer, - "postMenuActionEvent", - "()V"); - postMouseEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postMouseEvent", "(IJIIIIZ)V"); - setCursorID = (*env)->GetMethodID (env, gtkcomponentpeer, - "setCursor", "()V"); - beginNativeRepaintID = (*env)->GetMethodID (env, gtkcomponentpeer, - "beginNativeRepaint", "()V"); - - endNativeRepaintID = (*env)->GetMethodID (env, gtkcomponentpeer, - "endNativeRepaint", "()V"); - - postConfigureEventID = (*env)->GetMethodID (env, gtkwindowpeer, - "postConfigureEvent", "(IIII)V"); - postWindowEventID = (*env)->GetMethodID (env, gtkwindowpeer, - "postWindowEvent", - "(ILjava/awt/Window;I)V"); - postInsetsChangedEventID = (*env)->GetMethodID (env, gtkwindowpeer, - "postInsetsChangedEvent", - "(IIII)V"); - windowGetWidthID = (*env)->GetMethodID (env, gtkwindowpeer, - "getWidth", "()I"); - windowGetHeightID = (*env)->GetMethodID (env, gtkwindowpeer, - "getHeight", "()I"); - - postExposeEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postExposeEvent", "(IIII)V"); - postKeyEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postKeyEvent", "(IJIICI)V"); - postFocusEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postFocusEvent", "(IZ)V"); - postAdjustmentEventID = (*env)->GetMethodID (env, gtkscrollbarpeer, - "postAdjustmentEvent", - "(II)V"); - postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postItemEvent", - "(Ljava/lang/Object;I)V"); - choicePostItemEventID = (*env)->GetMethodID (env, gtkchoicepeer, - "choicePostItemEvent", - "(Ljava/lang/String;I)V"); - postListItemEventID = (*env)->GetMethodID (env, gtklistpeer, - "postItemEvent", - "(II)V"); - postTextEventID = (*env)->GetMethodID (env, gtktextcomponentpeer, - "postTextEvent", - "()V"); - initComponentGraphicsID = (*env)->GetMethodID (env, gdkgraphics, - "initComponentGraphics", - "()V"); - initComponentGraphics2DID = (*env)->GetMethodID (env, gdkgraphics2d, - "initComponentGraphics2D", - "()V"); - global_gtk_window_group = gtk_window_group_new (); - - init_dpi_conversion_factor (); -} - - -/** Initialize GLIB's threads properly, based on the value of the - gnu.classpath.awt.gtk.portable.native.sync Java system property. If - that's unset, use the PORTABLE_NATIVE_SYNC config.h macro. (TODO: - In some release following 0.10, that config.h macro will go away.) - */ -static void -init_glib_threads(JNIEnv *env, jint portableNativeSync) -{ - if (portableNativeSync < 0) - { -#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system - property */ - portableNativeSync = 1; -#else - portableNativeSync = 0; -#endif - } - - (*env)->GetJavaVM( env, &the_vm ); - if (!g_thread_supported ()) - { - if (portableNativeSync) - g_thread_init ( &portable_native_sync_jni_functions ); - else - g_thread_init ( NULL ); - } - else - { - /* Warn if portable native sync is desired but the threading - system is already initialized. In that case we can't - override the threading implementation with our portable - native sync functions. */ - if (portableNativeSync) - g_printerr ("peer warning: portable native sync disabled.\n"); - } - - /* Debugging progress message; uncomment if needed: */ - /* printf("called gthread init\n"); */ -} - - -/* This is a big hack, needed until this pango bug is resolved: - http://bugzilla.gnome.org/show_bug.cgi?id=119081. - See: http://mail.gnome.org/archives/gtk-i18n-list/2003-August/msg00001.html - for details. */ -static void -init_dpi_conversion_factor () -{ - GtkSettings *settings = gtk_settings_get_default (); - GObjectClass *klass; - - klass = G_OBJECT_CLASS (GTK_SETTINGS_GET_CLASS (settings)); - if (g_object_class_find_property (klass, "gtk-xft-dpi")) - { - int int_dpi; - g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); - /* If int_dpi == -1 gtk-xft-dpi returns the default value. So we - have to do approximate calculation here. */ - if (int_dpi < 0) - dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; - else - dpi_conversion_factor = PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); - - g_signal_connect (settings, "notify::gtk-xft-dpi", - G_CALLBACK (dpi_changed_cb), NULL); - } - else - /* Approximate. */ - dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; -} - -static void -dpi_changed_cb (GtkSettings *settings, - GParamSpec *pspec __attribute__((unused))) -{ - int int_dpi; - g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); - if (int_dpi < 0) - dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; - else - dpi_conversion_factor = PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); -} - -static int -within_human_latency_tolerance(struct timeval *init) -{ - struct timeval curr; - unsigned long milliseconds_elapsed; - - gettimeofday(&curr, NULL); - - milliseconds_elapsed = (((curr.tv_sec * 1000) + (curr.tv_usec / 1000)) - - ((init->tv_sec * 1000) + (init->tv_usec / 1000))); - - return milliseconds_elapsed < 100; -} - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_iterateNativeQueue -(JNIEnv *env, - jobject self __attribute__((unused)), - jobject lockedQueue, - jboolean block) -{ - /* We're holding an EventQueue lock, and we're about to acquire the GDK - * lock before dropping the EventQueue lock. This can deadlock if someone - * holds the GDK lock and wants to acquire the EventQueue lock; however - * all callbacks from GTK happen with the GDK lock released, so this - * would only happen in an odd case such as some JNI helper code - * acquiring the GDK lock and calling back into - * EventQueue.getNextEvent(). - */ - - struct timeval init; - gettimeofday(&init, NULL); - - gdk_threads_enter (); - (*env)->MonitorExit (env, lockedQueue); - - if (block) - { - - /* If we're blocking-when-empty, we want a do .. while loop. */ - do - gtk_main_iteration (); - while (within_human_latency_tolerance (&init) - && gtk_events_pending ()); - } - else - { - /* If we're not blocking-when-empty, we want a while loop. */ - while (within_human_latency_tolerance (&init) - && gtk_events_pending ()) - gtk_main_iteration (); - } - - (*env)->MonitorEnter (env, lockedQueue); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_wakeNativeQueue - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - g_main_context_wakeup (NULL); -} - -JNIEXPORT jboolean JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_nativeQueueEmpty - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - jboolean empty = FALSE; - gdk_threads_enter (); - empty = ! gtk_events_pending(); - gdk_threads_leave (); - return empty; -} - - -static jint gdk_color_to_java_color (GdkColor color); - - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_beep - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - gdk_threads_enter (); - gdk_beep (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_sync - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - gdk_threads_enter (); - gdk_flush (); - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), - jintArray jdims) -{ - jint *dims = (*env)->GetIntArrayElements (env, jdims, 0); - - gdk_threads_enter (); - - dims[0] = gdk_screen_width (); - dims[1] = gdk_screen_height (); - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements(env, jdims, dims, 0); -} - -JNIEXPORT jint JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) -{ - jint res; - - gdk_threads_enter (); - - res = gdk_screen_width () / (gdk_screen_width_mm () / 25.4); - - gdk_threads_leave (); - return res; -} - -#define CONVERT(type, state) \ - gdk_color_to_java_color (style->type[GTK_STATE_ ## state]) - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors - (JNIEnv *env, jobject obj __attribute__((unused)), - jintArray jcolors) -{ - jint *colors; - GtkStyle *style; - - colors = (*env)->GetIntArrayElements (env, jcolors, 0); - - gdk_threads_enter (); - - style = gtk_widget_get_default_style (); - - colors[AWT_DESKTOP] = CONVERT (bg, SELECTED); - colors[AWT_ACTIVE_CAPTION] = CONVERT (bg, SELECTED); - colors[AWT_ACTIVE_CAPTION_TEXT] = CONVERT (text, SELECTED); - colors[AWT_ACTIVE_CAPTION_BORDER] = CONVERT (fg, NORMAL); - colors[AWT_INACTIVE_CAPTION] = CONVERT (base, INSENSITIVE); - colors[AWT_INACTIVE_CAPTION_TEXT] = CONVERT (fg, INSENSITIVE); - colors[AWT_INACTIVE_CAPTION_BORDER] = CONVERT (fg, INSENSITIVE); - colors[AWT_WINDOW] = CONVERT (bg, NORMAL); - colors[AWT_WINDOW_BORDER] = CONVERT (fg, NORMAL); - colors[AWT_WINDOW_TEXT] = CONVERT (fg, NORMAL); - colors[AWT_MENU] = CONVERT (bg, NORMAL); - colors[AWT_MENU_TEXT] = CONVERT (fg, NORMAL); - colors[AWT_TEXT] = CONVERT (bg, NORMAL); - colors[AWT_TEXT_TEXT] = CONVERT (fg, NORMAL); - colors[AWT_TEXT_HIGHLIGHT] = CONVERT (bg, SELECTED); - colors[AWT_TEXT_HIGHLIGHT_TEXT] = CONVERT (fg, SELECTED); - colors[AWT_TEXT_INACTIVE_TEXT] = CONVERT (bg, INSENSITIVE); - colors[AWT_CONTROL] = CONVERT (bg, NORMAL); - colors[AWT_CONTROL_TEXT] = CONVERT (fg, NORMAL); - colors[AWT_CONTROL_HIGHLIGHT] = CONVERT (base, ACTIVE); - colors[AWT_CONTROL_LT_HIGHLIGHT] = CONVERT (bg, PRELIGHT); - colors[AWT_CONTROL_SHADOW] = CONVERT (bg, ACTIVE); - colors[AWT_CONTROL_DK_SHADOW] = CONVERT (fg, INSENSITIVE); - colors[AWT_SCROLLBAR] = CONVERT (base, INSENSITIVE); - colors[AWT_INFO] = CONVERT (bg, NORMAL); - colors[AWT_INFO_TEXT] = CONVERT (fg, NORMAL); - - gdk_threads_leave (); - - (*env)->ReleaseIntArrayElements(env, jcolors, colors, 0); -} - -#undef CONVERT - -static jint -gdk_color_to_java_color (GdkColor gdk_color) -{ - guchar red; - guchar green; - guchar blue; - float factor; - - factor = 255.0 / 65535.0; - - red = (float) gdk_color.red * factor; - green = (float) gdk_color.green * factor; - blue = (float) gdk_color.blue * factor; - - return (jint) (0xff000000 | (red << 16) | (green << 8) | blue); -} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c deleted file mode 100644 index 8136416d6a5..00000000000 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ /dev/null @@ -1,744 +0,0 @@ -/* gtkwindowpeer.c -- Native implementation of GtkWindowPeer - Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "gtkpeer.h" -#include "gnu_java_awt_peer_gtk_GtkWindowPeer.h" -#include <gdk/gdkprivate.h> -#include <gdk/gdkx.h> -#include <X11/Xatom.h> - -/* FIXME: we're currently seeing the double-activation that occurs - with metacity and GTK. See - http://bugzilla.gnome.org/show_bug.cgi?id=140977 for details. */ - -static void window_get_frame_extents (GtkWidget *window, - int *top, int *left, - int *bottom, int *right); - -static void request_frame_extents (GtkWidget *window); - -static Bool property_notify_predicate (Display *display, - XEvent *xevent, - XPointer arg); - -static gboolean window_delete_cb (GtkWidget *widget, GdkEvent *event, - jobject peer); -static void window_destroy_cb (GtkWidget *widget, GdkEvent *event, - jobject peer); -static void window_show_cb (GtkWidget *widget, jobject peer); -static void window_active_state_change_cb (GtkWidget *widget, - GParamSpec *pspec, - jobject peer); -static void window_focus_state_change_cb (GtkWidget *widget, - GParamSpec *pspec, - jobject peer); -static gboolean window_focus_in_cb (GtkWidget * widget, - GdkEventFocus *event, - jobject peer); -static gboolean window_focus_out_cb (GtkWidget * widget, - GdkEventFocus *event, - jobject peer); -static gboolean window_window_state_cb (GtkWidget *widget, - GdkEvent *event, - jobject peer); -static jint window_get_new_state (GtkWidget *widget); -static gboolean window_property_changed_cb (GtkWidget *widget, - GdkEventProperty *event, - jobject peer); -static void realize_cb (GtkWidget *widget, jobject peer); - -/* 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 JNICALL -Java_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; - - NSA_SET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - 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 (global_gtk_window_group, window); - - fixed = gtk_fixed_new (); - gtk_container_add (GTK_CONTAINER (window_widget), fixed); - - gtk_widget_show (fixed); - - gdk_threads_leave (); - - NSA_SET_PTR (env, obj, window_widget); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetTitle - (JNIEnv *env, jobject obj, jstring title) -{ - const char *c_title; - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - c_title = (*env)->GetStringUTFChars (env, title, NULL); - - gdk_threads_enter (); - - gtk_window_set_title (GTK_WINDOW (ptr), c_title); - - gdk_threads_leave (); - - (*env)->ReleaseStringUTFChars (env, title, c_title); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable - (JNIEnv *env, jobject obj, jboolean resizable) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gtk_window_set_policy (GTK_WINDOW (ptr), resizable, resizable, FALSE); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal - (JNIEnv *env, jobject obj, jboolean modal) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gtk_window_set_modal (GTK_WINDOW (ptr), modal); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetVisible - (JNIEnv *env, jobject obj, jboolean visible) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - if (visible) - gtk_widget_show (GTK_WIDGET (ptr)); - else - gtk_widget_hide (GTK_WIDGET (ptr)); - - XFlush (GDK_DISPLAY ()); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals - (JNIEnv *env, jobject obj) -{ - void *ptr; - jobject *gref; - - ptr = NSA_GET_PTR (env, obj); - gref = NSA_GET_GLOBAL_REF (env, obj); - - gdk_threads_enter (); - - g_signal_connect (G_OBJECT (ptr), "event", - G_CALLBACK (pre_event_handler), *gref); - - 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::is-active", - G_CALLBACK (window_active_state_change_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_after (G_OBJECT (ptr), "realize", - G_CALLBACK (connect_awt_hook_cb), *gref); - - - /* 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. */ - 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; - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - 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; - ptr = NSA_GET_PTR (env, obj); - - gdk_threads_enter (); - - gdk_window_raise (GTK_WIDGET (ptr)->window); - gdk_flush (); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBoundsCallback - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), - jobject window, jint x, jint y, jint width, jint height) -{ - /* Circumvent package-private access to call Window's - setBoundsCallback method. */ - (*gdk_env())->CallVoidMethod (gdk_env(), window, setBoundsCallbackID, - x, y, width, height); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize - (JNIEnv *env, jobject obj, jint width, jint height) -{ - void *ptr = NSA_GET_PTR (env, obj); - - /* Avoid GTK runtime assertion failures. */ - width = (width < 1) ? 1 : width; - height = (height < 1) ? 1 : height; - - gdk_threads_enter (); - - gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds - (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) -{ - void *ptr = NSA_GET_PTR (env, obj); - - /* Avoid GTK runtime assertion failures. */ - width = (width < 1) ? 1 : width; - height = (height < 1) ? 1 : height; - - gdk_threads_enter (); - - 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); - gdk_threads_leave (); -} - -static void -window_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. */ - *top = 23; - *left = 6; - *bottom = 6; - *right = 6; - - /* 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 void -request_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 Bool -property_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 gboolean -window_delete_cb (GtkWidget *widget __attribute__((unused)), - GdkEvent *event __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_CLOSING, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); - - /* 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 void -window_destroy_cb (GtkWidget *widget __attribute__((unused)), - GdkEvent *event __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_CLOSED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); -} - -static void -window_show_cb (GtkWidget *widget __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_OPENED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); -} - -static void -window_active_state_change_cb (GtkWidget *widget __attribute__((unused)), - GParamSpec *pspec __attribute__((unused)), - jobject peer __attribute__((unused))) -{ - /* FIXME: not sure if this is needed or not. */ - /* Remove the unused attributes if you fix the below. */ -#if 0 - gdk_threads_leave (); - if (GTK_WINDOW (widget)->is_active) - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_GAINED_FOCUS, - (jobject) NULL, (jint) 0); - else - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_DEACTIVATED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); -#endif -} - -static void -window_focus_state_change_cb (GtkWidget *widget, - GParamSpec *pspec __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - if (GTK_WINDOW (widget)->has_toplevel_focus) - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_ACTIVATED, - (jobject) NULL, (jint) 0); - else - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_DEACTIVATED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); -} - -static gboolean -window_focus_in_cb (GtkWidget * widget __attribute__((unused)), - GdkEventFocus *event __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_GAINED_FOCUS, - (jobject) NULL, (jint) 0); - /* FIXME: somewhere after this is handled, the child window is - getting an expose event. */ - gdk_threads_enter (); - return FALSE; -} - -static gboolean -window_focus_out_cb (GtkWidget * widget __attribute__((unused)), - GdkEventFocus *event __attribute__((unused)), - jobject peer) -{ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_LOST_FOCUS, - (jobject) NULL, (jint) 0); - /* FIXME: somewhere after this is handled, the child window is - getting an expose event. */ - gdk_threads_enter (); - return FALSE; -} - -static gboolean -window_window_state_cb (GtkWidget *widget, - GdkEvent *event, - jobject peer) -{ - jint new_state; - - /* Handle WINDOW_ICONIFIED and WINDOW_DEICONIFIED events. */ - if (event->window_state.changed_mask & GDK_WINDOW_STATE_ICONIFIED) - { - /* We've either been iconified or deiconified. */ - if (event->window_state.new_window_state & GDK_WINDOW_STATE_ICONIFIED) - { - /* We've been iconified. */ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_ICONIFIED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); - } - else - { - /* We've been deiconified. */ - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_DEICONIFIED, - (jobject) NULL, (jint) 0); - gdk_threads_enter (); - } - } - - /* Post a WINDOW_STATE_CHANGED event, passing the new frame state to - GtkWindowPeer. */ - new_state = AWT_FRAME_STATE_NORMAL; - - if (event->window_state.new_window_state & GDK_WINDOW_STATE_ICONIFIED) - new_state |= AWT_FRAME_STATE_ICONIFIED; - - new_state |= window_get_new_state (widget); - - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_STATE_CHANGED, - (jobject) NULL, new_state); - gdk_threads_enter (); - return TRUE; -} - -static jint -window_get_new_state (GtkWidget *widget) -{ - GdkDisplay *display = gtk_widget_get_display(widget); - jint new_state = AWT_FRAME_STATE_NORMAL; - Atom type; - gint format; - gulong atom_count; - gulong bytes_after; - Atom *atom_list = NULL; - union atom_list_union alu; - gulong i; - - alu.atom_list = &atom_list; - XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XID (widget->window), - gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"), - 0, G_MAXLONG, False, XA_ATOM, &type, &format, &atom_count, - &bytes_after, alu.gu_extents); - - if (type != None) - { - Atom maxvert = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT"); - Atom maxhorz = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ"); - - i = 0; - while (i < atom_count) - { - if (atom_list[i] == maxhorz) - new_state |= AWT_FRAME_STATE_MAXIMIZED_HORIZ; - else if (atom_list[i] == maxvert) - new_state |= AWT_FRAME_STATE_MAXIMIZED_VERT; - - ++i; - } - - XFree (atom_list); - } - return new_state; -} - -static gboolean -window_property_changed_cb (GtkWidget *widget __attribute__((unused)), - GdkEventProperty *event, - jobject peer) -{ - unsigned long *extents; - union extents_union gu_ex; - - gu_ex.extents = &extents; - if (gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE) == event->atom - && gdk_property_get (event->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)) - { - gdk_threads_leave (); - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postInsetsChangedEventID, - (jint) extents[2], /* top */ - (jint) extents[0], /* left */ - (jint) extents[3], /* bottom */ - (jint) extents[1]); /* right */ - gdk_threads_enter (); - } - - - return FALSE; -} - -static void -realize_cb (GtkWidget *widget, jobject peer) -{ - jint top = 0; - jint left = 0; - jint bottom = 0; - jint right = 0; - jint width = 0; - jint height = 0; - - width = (*gdk_env())->CallIntMethod (gdk_env(), peer, windowGetWidthID); - height = (*gdk_env())->CallIntMethod (gdk_env(), peer, windowGetHeightID); - - window_get_frame_extents (widget, &top, &left, &bottom, &right); - - (*gdk_env())->CallVoidMethod (gdk_env(), peer, - postInsetsChangedEventID, - top, left, bottom, right); - - gtk_window_set_default_size (GTK_WINDOW (widget), - MAX (1, width - left - right), - MAX (1, height - top - bottom)); - - /* set the size like we do in nativeSetBounds */ - gtk_widget_set_size_request (widget, - MAX (1, width - left - right), - MAX (1, height - top - bottom)); - - gtk_window_resize (GTK_WINDOW (widget), - MAX (1, width - left - right), - MAX (1, height - top - bottom)); -} diff --git a/libjava/jni/gtk-peer/gthread-jni.c b/libjava/jni/gtk-peer/gthread-jni.c deleted file mode 100644 index be822cefd12..00000000000 --- a/libjava/jni/gtk-peer/gthread-jni.c +++ /dev/null @@ -1,2592 +0,0 @@ -/* gthread-jni.c -- JNI threading routines for GLIB - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -/************************************************************************/ -/* Header */ -/************************************************************************/ - -/* - * @author Julian Dolby (dolby@us.ibm.com) - * @date February 7, 2003 implemented for GLIB v.1 - * - * - * @author Steven Augart - * <steve+classpath at augart dot com>, <augart at watson dot ibm dot com> - * @date April 30, 2004 -- May 10 2004: Support new functions for Glib v.2, - * fix cond_wait to free and re-acquire the mutex, - * replaced trylock stub implementation with a full one. - * - * This code implements the GThreadFunctions interface for GLIB using - * Java threading primitives. All of the locking and conditional variable - * functionality required by GThreadFunctions is implemented using the - * monitor and wait/notify functionality of Java objects. The thread- - * local functionality uses the java.lang.ThreadLocal class. - * - * Classpath's AWT support uses GTK+ peers. GTK+ uses GLIB. GLIB by default - * uses the platform's native threading model -- pthreads in most cases. If - * the Java runtime doesn't use the native threading model, then it needs this - * code in order to use Classpath's (GTK+-based) AWT routines. - * - * This code should be portable; I believe it makes no assumptions - * about the underlying VM beyond that it implements the JNI functionality - * that this code uses. - * - * Currently, use of this code is governed by the configuration option - * --enable-portable-native-sync. We will soon add a VM hook so the VM can - * select which threading model it wants to use at run time; at that point, - * the configuration option will go away. - * - * The code in this file uses only JNI 1.1, except for one JNI 1.2 function: - * GetEnv, in the JNI Invocation API. (There seems to be no way around using - * GetEnv). - * - * ACKNOWLEDGEMENT: - * - * I would like to thank Mark Wielaard for his kindness in spending at least - * six hours of his own time in reviewing this code and correcting my GNU - * coding and commenting style. --Steve Augart - * - * - * NOTES: - * - * This code has been tested with Jikes RVM and with Kaffe. - * - * This code should have proper automated unit tests. I manually tested it - * by running an application that uses AWT. --Steven Augart - * - * MINOR NIT: - * - * - Using a jboolean in the arglist to "throw()" and "rethrow()" - * triggers many warnings from GCC's -Wconversion operation, because that - * is not the same as the conversion (upcast to an int) that would occur in - * the absence of a prototype. - * - * It would be very slightly more efficient to just pass the jboolean, but - * is not worth the clutter of messages. The right solution would be to - * turn off the -Wconversion warning for just this file, *except* that - * -Wconversion also warns you against constructs such as: - * unsigned u = -1; - * and that is a useful warning. So I went from a "jboolean" to a - * "gboolean" (-Wconversion is not enabled by default for GNU Classpath, - * but it is in my own CFLAGS, which, for gcc 3.3.3, read: -pipe -ggdb3 -W - * -Wall -Wbad-function-cast -Wcast-align -Wpointer-arith -Wcast-qual - * -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations - * -fkeep-static-consts -fkeep-inline-functions -Wundef -Wwrite-strings - * -Wno-aggregate-return -Wmissing-noreturn -Wnested-externs -Wtrigraphs - * -Wconversion -Wsign-compare -Wno-float-equal -Wmissing-format-attribute - * -Wno-unreachable-code -Wdisabled-optimization ) - */ - -#include <config.h> - -/************************************************************************/ -/* Configuration */ -/************************************************************************/ - -/** Tracing and Reporting **/ -#define TRACE_API_CALLS 0 /* announce entry and exit into each method, - by printing to stderr. */ - -#define TRACE_MONITORS 0 /* Every enterMonitor() and exitMonitor() goes - to stderr. */ - -/** Trouble handling. There is a discussion below of this. **/ -#define EXPLAIN_TROUBLE 1 /* Describe any unexpected trouble that - happens. This is a superset - of EXPLAIN_BROKEN, and if set trumps an - unset EXPLAIN_BROKEN. It is not a strict - superset, since at the moment there is no - TROUBLE that is not also BROKEN. - - Use criticalMsg() to describe the problem. - */ - -#define EXPLAIN_BROKEN 1 /* Describe trouble that is serious enough to - be BROKEN. (Right now all trouble is at - least BROKEN.) */ - -/* There is no EXPLAIN_BADLY_BROKEN definition. We always explain - BADLY_BROKEN trouble, since there is no other way to report it. */ - - -/** Error Handling **/ -#define DIE_IF_BROKEN 1 /* Dies if serious trouble happens. There is - really no non-serious trouble, except - possibly problems that arise during - pthread_create, which are reported by a - GError. - - If you do not set DIE_IF_BROKEN, then - trouble will raise a Java RuntimeException. - We probably do want to die right away, - since anything that's BROKEN really - indicates a programming error or a - system-wide error, and that's what the glib - documentation says you should do in case of - that kind of error in a glib-style - function. But it does work to turn this - off. */ - -#if DIE_IF_BROKEN -#define DIE_IF_BADLY_BROKEN 1 /* DIE_IF_BROKEN implies DIE_IF_BADLY_BROKEN */ -#else -#define DIE_IF_BADLY_BROKEN 1 /* Die if the system is badly broken -- - that is, if we have further trouble while - attempting to throw an exception - upwards, or if we are unable to generate - one of the classes we'll need in order to - throw wrapped exceptions upward. - - If unset, we will print a warning message, - and limp along anyway. Not that the system - is likely to work. */ -#endif - -/** Performance tuning parameters **/ - -#define ENABLE_EXPENSIVE_ASSERTIONS 0 /* Enable expensive assertions? */ - -#define DELETE_LOCAL_REFS 1 /* Whether to delete local references. - - JNI only guarantees that there wil be 16 - available. (Jikes RVM provides an number - only limited by VM memory.) - - Jikes RVM will probably perform faster if - this is turned off, but other VMs may need - this to be turned on in order to perform at - all, or might need it if things change. - - Remember, we don't know how many of those - local refs might have already been used up - by higher layers of JNI code that end up - calling g_thread_self(), - g_thread_set_private(), and so on. - - We set this to 1 for GNU Classpath, since - one of our principles is "always go for the - most robust implementation" */ - -#define HAVE_JNI_VERSION_1_2 0 /* Assume we don't. We could - dynamically check for this. We will - assume JNI 1.2 in later versions of - Classpath. - - As it stands, the code in this file - already needs one JNI 1.2 function: - GetEnv, in the JNI Invocation API. - - TODO This code hasn't been tested yet. - And really hasn't been implemented yet. - */ - -/************************************************************************/ -/* Global data */ -/************************************************************************/ - -#if defined HAVE_STDINT_H -#include <stdint.h> /* provides intptr_t */ -#elif defined HAVE_INTTYPES_H -#include <inttypes.h> -#endif -#include <stdarg.h> /* va_list */ -#include <glib.h> -#include "gthread-jni.h" -#include <assert.h> /* assert() */ - -/* For Java thread priority constants. */ -#include <gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.h> - -/* Since not all JNI header generators actually define constants we - define them here explicitly. */ -#ifndef gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MIN_PRIORITY -#define gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MIN_PRIORITY 1 -#endif -#ifndef gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_NORM_PRIORITY -#define gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_NORM_PRIORITY 5 -#endif -#ifndef gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MAX_PRIORITY -#define gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MAX_PRIORITY 10 -#endif - -/* The VM handle. This is set in - Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit */ -JavaVM *the_vm; - -/* Unions used for type punning. */ -union env_union -{ - void **void_env; - JNIEnv **jni_env; -}; - -union func_union -{ - void *void_func; - GThreadFunc g_func; -}; - -/* Forward Declarations for Functions */ -static int threadObj_set_priority (JNIEnv * env, jobject threadObj, - GThreadPriority gpriority); -static void fatalMsg (const char fmt[], ...) - __attribute__ ((format (printf, 1, 2))) - __attribute__ ((noreturn)); - -static void criticalMsg (const char fmt[], ...) - __attribute__ ((format (printf, 1, 2))); - -static void tracing (const char fmt[], ...) - __attribute__ ((format (printf, 1, 2))); - -static jint javaPriorityLevel (GThreadPriority priority) - __attribute__ ((const)); - -/************************************************************************/ -/* Trouble-handling, including utilities to reflect exceptions */ -/* back to the VM. Also some status reporting. */ -/************************************************************************/ - -/* How are we going to handle problems? - - There are several approaches: - - 1) Report them with the GError mechanism. - - (*thread_create)() is the only one of these functions that takes a - GError pointer. And the only G_THREAD error defined maps onto EAGAIN. - We don't have any errors in our (*thread_create)() implementation that - can be mapped to EAGAIN. So this idea is a non-starter. - - 2) Reflect the exception back to the VM, wrapped in a RuntimeException. - This will fail sometimes, if we're so broken (BADLY_BROKEN) that we - fail to throw the exception. - - 3) Abort execution. This is what the glib functions themselves do for - errors that they can't report via GError. - - Enable DIE_IF_BROKEN and/or DIE_IF_BADLY_BROKEN to - make this the default for BROKEN and/or BADLY_BROKEN trouble. - - 4) Display messages to stderr. We always do this for BADLY_BROKEN - trouble. The glib functions do that for errors they can't report via - GError. - - There are some complications. - - When I attempted to report a problem in g_thread_self() using g_critical (a - macro around g_log(), I found that g_log in turn looks for thread-private - data and calls g_thread_self() again. - - We got a segfault, probably due to stack overflow. So, this code doesn't - use the g_critical() and g_error() functions any more. Nor do we use - g_assert(); we use the C library's assert() instead. -*/ - - -#define WHERE __FILE__ ":" G_STRINGIFY(__LINE__) ": " - -/* This is portable to older compilers that lack variable-argument macros. - This used to be just g_critical(), but then we ran into the error reporting - problem discussed above. -*/ -static void -fatalMsg (const char fmt[], ...) -{ - va_list ap; - va_start (ap, fmt); - vfprintf (stderr, fmt, ap); - va_end (ap); - fputs ("\nAborting execution\n", stderr); - abort (); -} - - -static void -criticalMsg (const char fmt[], ...) -{ - va_list ap; - va_start (ap, fmt); - vfprintf (stderr, fmt, ap); - va_end (ap); - putc ('\n', stderr); -} - -/* Unlike the other two, this one does not append a newline. This is only - used if one of the TRACE_ macros is defined. */ -static void -tracing (const char fmt[], ...) -{ - va_list ap; - va_start (ap, fmt); - vfprintf (stderr, fmt, ap); - va_end (ap); -} - -#define assert_not_reached() \ - do \ - { \ - fputs(WHERE "You should never get here. Aborting execution.\n", \ - stderr); \ - abort(); \ - } \ - while(0) - - -#if DIE_IF_BADLY_BROKEN -#define BADLY_BROKEN fatalMsg -#else -#define BADLY_BROKEN criticalMsg -/* So, the user may still attempt to recover, even though we do not advise - this. */ -#endif - -/* I find it so depressing to have to use C without varargs macros. */ -#define BADLY_BROKEN_MSG WHERE "Something fundamental" \ - " to GNU Classpath's AWT JNI broke while we were trying to pass up a Java error message" - -#define BADLY_BROKEN0() \ - BADLY_BROKEN(BADLY_BROKEN_MSG); -#define BADLY_BROKEN1(msg) \ - BADLY_BROKEN(BADLY_BROKEN_MSG ": " msg) -#define BADLY_BROKEN2(msg, arg) \ - BADLY_BROKEN(BADLY_BROKEN_MSG ": " msg, arg) -#define BADLY_BROKEN3(msg, arg, arg2) \ - BADLY_BROKEN(BADLY_BROKEN_MSG ": " msg, arg1, arg2) -#define BADLY_BROKEN4(msg, arg, arg2, arg3) \ - BADLY_BROKEN(BADLY_BROKEN_MSG ": " msg, arg1, arg2, arg3) - -#define DELETE_LOCAL_REF(env, ref) \ - do \ - { \ - if ( DELETE_LOCAL_REFS ) \ - { \ - (*env)->DeleteLocalRef (env, ref); \ - (ref) = NULL; \ - } \ - } \ - while(0) - -/* Cached info for Exception-wrapping */ - -jclass runtimeException_class; /* java.lang.RuntimeException */ -jmethodID runtimeException_ctor; /* constructor for it */ - - -/* Throw a new RuntimeException. It may wrap around an existing exception. - 1 if we did rethrow, -1 if we had trouble while rethrowing. - isBroken is always true in this case. */ -static int -throw (JNIEnv * env, jthrowable cause, const char *message, - gboolean isBroken, const char *file, int line) -{ - jstring jmessage; - gboolean describedException = FALSE; /* Did we already describe the - exception to stderr or the - equivalent? */ - jthrowable wrapper; - - /* allocate local message in Java */ - const char fmt[] = "In AWT JNI, %s (at %s:%d)"; - size_t len = strlen (message) + strlen (file) + sizeof fmt + 25; - char *buf; - - if (EXPLAIN_TROUBLE || (isBroken && EXPLAIN_BROKEN)) - { - criticalMsg ("%s:%d: AWT JNI failure%s: %s\n", file, line, - isBroken ? " (BROKEN)" : "", message); - if (cause) - { - jthrowable currentException = (*env)->ExceptionOccurred (env); - - if (cause == currentException) - { - criticalMsg ("Description follows to System.err:"); - (*env)->ExceptionDescribe (env); - /* ExceptionDescribe has the side-effect of clearing the pending - exception; relaunch it. */ - describedException = TRUE; - - if ((*env)->Throw (env, cause)) - { - BADLY_BROKEN1 - ("Relaunching an exception with Throw failed."); - return -1; - } - } - else - { - DELETE_LOCAL_REF (env, currentException); - criticalMsg (WHERE - "currentException != cause; something else happened" - " while handling an exception."); - } - } - } /* if (EXPLAIN_TROUBLE) */ - - if (isBroken && DIE_IF_BROKEN) - fatalMsg ("%s:%d: Aborting execution; BROKEN: %s\n", file, line, message); - - if ((buf = malloc (len))) - { - memset (buf, 0, len); - g_snprintf (buf, len, fmt, message, file, line); - jmessage = (*env)->NewStringUTF (env, buf); - free (buf); - } - else - { - jmessage = NULL; - } - - /* Create the RuntimeException wrapper object and throw it. It is OK for - CAUSE to be NULL. */ - wrapper = (jthrowable) (*env)->NewObject - (env, runtimeException_class, runtimeException_ctor, jmessage, cause); - DELETE_LOCAL_REF (env, jmessage); - - if (!wrapper) - { - /* I think this should only happen: - - if there are bugs in my JNI code, or - - if the VM is broken, or - - if we run out of memory. - */ - if (EXPLAIN_TROUBLE) - { - criticalMsg (WHERE "GNU Classpath: JNI NewObject() could not create" - " a new java.lang.RuntimeException."); - criticalMsg ("We were trying to warn about the following" - " previous failure:"); - criticalMsg ("%s:%d: %s", file, line, message); - criticalMsg ("The latest (NewObject()) exception's description" - " follows, to System.err:"); - (*env)->ExceptionDescribe (env); - } - BADLY_BROKEN1 ("Failure of JNI NewObject()" - " to make a java.lang.RuntimeException"); - return -1; - } - - - /* throw it */ - if ((*env)->Throw (env, wrapper)) - { - /* Throw() should just never fail, unless we're in such severe trouble - that we might as well die. */ - BADLY_BROKEN1 - ("GNU Classpath: Failure of JNI Throw to report an Exception"); - return -1; - } - - DELETE_LOCAL_REF (env, wrapper); - return 1; -} - - - -/* Rethrow an exception we received, wrapping it with a RuntimeException. 1 - if we did rethrow, -1 if we had trouble while rethrowing. - CAUSE should be identical to the most recent exception that happened, so - that ExceptionDescribe will work. (Otherwise nix.) */ -static int -rethrow (JNIEnv * env, jthrowable cause, const char *message, - gboolean isBroken, const char *file, int line) -{ - assert (cause); - return throw (env, cause, message, isBroken, file, line); -} - - -/* This function checks for a pending exception, and rethrows it with - * a wrapper RuntimeException to deal with possible type problems (in - * case some calling piece of code does not expect the exception being - * thrown) and to include the given extra message. - * - * Returns 0 if no problems found (so no exception thrown), 1 if we rethrew an - * exception. Returns -1 on failure. - */ -static int -maybe_rethrow (JNIEnv * env, const char *message, gboolean isBroken, - const char *file, int line) -{ - jthrowable cause = (*env)->ExceptionOccurred (env); - int ret = 0; - - /* rethrow if an exception happened */ - if (cause) - { - ret = rethrow (env, cause, message, isBroken, file, line); - DELETE_LOCAL_REF (env, cause); - } - - return 0; -} - -/* MAYBE_TROUBLE() is used to include a source location in the exception - message. Once we have run maybe_rethrow, if there WAS trouble, - return TRUE, else FALSE. - - MAYBE_TROUBLE() is actually never used; all problems that throw exceptions - are BROKEN, at least. Nothing is recoverable :(. See the discussion of - possible errors at thread_create_jni_impl(). */ -#define MAYBE_TROUBLE(_env, _message) \ - maybe_rethrow(_env, _message, FALSE, __FILE__, __LINE__) - -/* MAYBE_TROUBLE(), but something would be BROKEN if it were true. */ -#define MAYBE_BROKEN(_env, _message) \ - maybe_rethrow(_env, _message, TRUE, __FILE__, __LINE__) - -/* Like MAYBE_TROUBLE(), TROUBLE() is never used. */ -#define TROUBLE(_env, _message) \ - rethrow(_env, (*env)->ExceptionOccurred (env), _message, FALSE, \ - __FILE__, __LINE__) - -#define BROKEN(_env, _message) \ - rethrow (_env, (*env)->ExceptionOccurred (env), _message, TRUE, \ - __FILE__, __LINE__) - -/* Like MAYBE_TROUBLE(), NEW_TROUBLE() is never used. */ -#define NEW_TROUBLE(_env, _message) \ - throw (_env, NULL, _message, FALSE, __FILE__, __LINE__) - -#define NEW_BROKEN(_env, _message) \ - throw (_env, NULL, _message, TRUE, __FILE__, __LINE__) - -/* Like MAYBE_TROUBLE(), RETHROW_CAUSE() is never used. */ -#define RETHROW_CAUSE(_env, _cause, _message) \ - rethrow (_env, _cause, _message, FALSE, __FILE__, __LINE__) - -#define BROKEN_CAUSE(_env, _cause, _message) \ - rethrow (_env, _cause, _message, TRUE, __FILE__, __LINE__) - -/* Macros to handle the possibility that someone might have called one of the - GThreadFunctions API functions with a Java exception pending. It is - generally discouraged to continue to use JNI after a Java exception has - been raised. Sun's JNI book advises that one trap JNI errors immediately - and not continue with an exception pending. - - These are #if'd out for these reasons: - - 1) They do not work in the C '89 subset that Classpath is currently - (2004 May 10) sticking to; HIDE_OLD_TROUBLE() includes a declaration - that should be in scope for the rest of the function, so it needs a - language version that lets you mix declarations and statements. (This - could be worked around if it were important.) - - 2) They chew up more time and resources. - - 3) There does not ever seem to be old trouble -- the assertion in - HIDE_OLD_TROUBLE never goes off. - - You will want to re-enable them if this code needs to be used in a context - where old exceptions might be pending when the GThread functions are - called. - - The implementations in this file are responsible for skipping around calls - to SHOW_OLD_TROUBLE() if they've raised exceptions during the call. So, if - we reach SHOW_OLD_TROUBLE, we are guaranteed that there are no exceptions - pending. */ -#if 1 -#define HIDE_OLD_TROUBLE(env) \ - assert ( NULL == (*env)->ExceptionOccurred (env) ) - -#define SHOW_OLD_TROUBLE() \ - assert ( NULL == (*env)->ExceptionOccurred (env) ) -#else /* 0 */ -#define HIDE_OLD_TROUBLE(env) \ - jthrowable savedTrouble = (*env)->ExceptionOccurred (env); \ - (*env)->ExceptionClear (env); - -#define SHOW_OLD_TROUBLE() do \ -{ \ - assert ( NULL == (*env)->ExceptionOccurred (env) ) \ - if (savedTrouble) \ - { \ - if ((*env)->Throw (env, savedTrouble)) \ - BADLY_BROKEN ("ReThrowing the savedTrouble failed"); \ - } \ - DELETE_LOCAL_REF (env, savedTrouble); \ -} while(0) - -#endif /* 0 */ - -/* Set up the cache of jclass and jmethodID primitives we need - in order to throw new exceptions and rethrow exceptions. We do this - independently of the other caching. We need to have this cache set up - first, so that we can then report errors properly. - - If any errors while setting up the error cache, the world is BADLY_BROKEN. - - May be called more than once. - - Returns -1 if the cache was not initialized properly, 1 if it was. -*/ -static int -setup_exception_cache (JNIEnv * env) -{ - static int exception_cache_initialized = 0; /* -1 for trouble, 1 for proper - init. */ - - jclass lcl_class; /* a class used for local refs */ - - if (exception_cache_initialized) - return exception_cache_initialized; - lcl_class = (*env)->FindClass (env, "java/lang/RuntimeException"); - if ( ! lcl_class ) - { - BADLY_BROKEN1 ("Broken Class library or VM?" - " Couldn't find java/lang/RuntimeException"); - return exception_cache_initialized = -1; - } - /* Pin it down. */ - runtimeException_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!runtimeException_class) - { - BADLY_BROKEN1 ("Serious trouble: could not turn" - " java.lang.RuntimeException into a global reference"); - return exception_cache_initialized = -1; - } - - runtimeException_ctor = - (*env)->GetMethodID (env, runtimeException_class, "<init>", - "(Ljava/lang/String;Ljava/lang/Throwable;)V"); - if ( ! runtimeException_ctor ) - { - BADLY_BROKEN1 ("Serious trouble: classpath couldn't find a" - " two-arg constructor for java/lang/RuntimeException"); - return exception_cache_initialized = -1; - } - - return exception_cache_initialized = 1; -} - - -/**********************************************************/ -/***** The main cache *************************************/ -/**********************************************************/ - -/** This is a cache of all classes, methods, and field IDs that we use during - the run. We maintain a permanent global reference to each of the classes - we cache, since otherwise the (local) jclass that refers to that class - would go out of scope and possibly be reused in further calls. - - The permanent global reference also achieves the secondary goal of - protecting the validity of the methods and field IDs in case the classes - were otherwise unloaded and then later loaded again. Obviously, this will - never happen to classes such as java.lang.Thread and java.lang.Object, but - the primary reason for maintaining permanent global refs is sitll valid. - - The code in jnilink.c has a similar objective. TODO: Consider using that - code instead. - - --Steven Augart -*/ - -/* All of these are cached classes and method IDs: */ -/* java.lang.Object */ -static jclass obj_class; /* java.lang.Object */ -static jmethodID obj_ctor; /* no-arg Constructor for java.lang.Object */ -static jmethodID obj_notify_mth; /* java.lang.Object.notify() */ -static jmethodID obj_notifyall_mth; /* java.lang.Object.notifyall() */ -static jmethodID obj_wait_mth; /* java.lang.Object.wait() */ -static jmethodID obj_wait_nanotime_mth; /* java.lang.Object.wait(JI) */ - -/* GThreadMutex and its methods */ -static jclass mutex_class; -static jmethodID mutex_ctor; -static jfieldID mutex_lockForPotentialLockers_fld; -static jfieldID mutex_potentialLockers_fld; - -/* java.lang.Thread and its methods*/ -static jclass thread_class; /* java.lang.Thread */ -static jmethodID thread_current_mth; /* Thread.currentThread() */ -static jmethodID thread_equals_mth; /* Thread.equals() */ -static jmethodID thread_join_mth; /* Thread.join() */ -static jmethodID thread_setPriority_mth; /* Thread.setPriority() */ -static jmethodID thread_stop_mth; /* Thread.stop() */ -static jmethodID thread_yield_mth; /* Thread.yield() */ - -/* java.lang.ThreadLocal and its methods */ -static jclass threadlocal_class; /* java.lang.ThreadLocal */ -static jmethodID threadlocal_ctor; /* Its constructor */ -static jmethodID threadlocal_set_mth; /* ThreadLocal.set() */ -static jmethodID threadlocal_get_mth; /* ThreadLocal.get() */ - -/* java.lang.Long and its methods */ -static jclass long_class; /* java.lang.Long */ -static jmethodID long_ctor; /* constructor for it: (J) */ -static jmethodID long_longValue_mth; /* longValue()J */ - - -/* GThreadNativeMethodRunner */ -static jclass runner_class; -static jmethodID runner_ctor; -static jmethodID runner_threadToThreadID_mth; -static jmethodID runner_threadIDToThread_mth; -static jmethodID runner_deRegisterJoinable_mth; -static jmethodID runner_start_mth; /* Inherited Thread.start() */ - - -/* java.lang.InterruptedException */ -static jclass interrupted_exception_class; - - - - -/* Returns a negative value if there was trouble during initialization. - Returns a positive value of the cache was initialized correctly. - Never returns zero. */ -static int -setup_cache (JNIEnv * env) -{ - jclass lcl_class; - static int initialized = 0; /* 1 means initialized, 0 means uninitialized, - -1 means mis-initialized */ - - if (initialized) - return initialized; - - /* make sure we can report on trouble */ - if (setup_exception_cache (env) < 0) - return initialized = -1; - -#ifdef JNI_VERSION_1_2 - if (HAVE_JNI_VERSION_1_2) - assert ( ! (*env)->ExceptionCheck (env)); - else -#endif - assert ( ! (*env)->ExceptionOccurred (env)); - - /* java.lang.Object and its methods */ - lcl_class = (*env)->FindClass (env, "java/lang/Object"); - if (!lcl_class) - { - BROKEN (env, "cannot find java.lang.Object"); - return initialized = -1; - } - - /* Pin it down. */ - obj_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!obj_class) - { - BROKEN (env, "Cannot get a global reference to java.lang.Object"); - return initialized = -1; - } - - obj_ctor = (*env)->GetMethodID (env, obj_class, "<init>", "()V"); - if (!obj_ctor) - { - BROKEN (env, "cannot find constructor for java.lang.Object"); - return initialized = -1; - } - - obj_notify_mth = (*env)->GetMethodID (env, obj_class, "notify", "()V"); - if ( ! obj_notify_mth ) - { - BROKEN (env, "cannot find java.lang.Object.notify()V"); - return initialized = -1; - } - - obj_notifyall_mth = - (*env)->GetMethodID (env, obj_class, "notifyAll", "()V"); - if ( ! obj_notifyall_mth) - { - BROKEN (env, "cannot find java.lang.Object.notifyall()V"); - return initialized = -1; - } - - obj_wait_mth = (*env)->GetMethodID (env, obj_class, "wait", "()V"); - if ( ! obj_wait_mth ) - { - BROKEN (env, "cannot find Object.<wait()V>"); - return initialized = -1; - } - - obj_wait_nanotime_mth = - (*env)->GetMethodID (env, obj_class, "wait", "(JI)V"); - if ( ! obj_wait_nanotime_mth ) - { - BROKEN (env, "cannot find Object.<wait(JI)V>"); - return initialized = -1; - } - - /* GThreadMutex and its methods */ - lcl_class = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GThreadMutex"); - if ( ! lcl_class) - { - BROKEN (env, "cannot find gnu.java.awt.peer.gtk.GThreadMutex"); - return initialized = -1; - } - /* Pin it down. */ - mutex_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if ( ! mutex_class) - { - BROKEN (env, "Cannot get a global reference to GThreadMutex"); - return initialized = -1; - } - - mutex_ctor = (*env)->GetMethodID (env, mutex_class, "<init>", "()V"); - if ( ! mutex_ctor) - { - BROKEN (env, "cannot find zero-arg constructor for GThreadMutex"); - return initialized = -1; - } - - mutex_potentialLockers_fld = (*env)->GetFieldID - (env, mutex_class, "potentialLockers", "I"); - if ( ! mutex_class ) - { - BROKEN (env, "cannot find GThreadMutex.potentialLockers"); - return initialized = -1; - } - - if (! (mutex_lockForPotentialLockers_fld = (*env)->GetFieldID - (env, mutex_class, "lockForPotentialLockers", "Ljava/lang/Object;"))) - { - BROKEN (env, "cannot find GThreadMutex.lockForPotentialLockers"); - return initialized = -1; - } - - - /* java.lang.Thread */ - if (! (lcl_class = (*env)->FindClass (env, "java/lang/Thread"))) - { - BROKEN (env, "cannot find java.lang.Thread"); - return initialized = -1; - } - - /* Pin it down. */ - thread_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!thread_class) - { - BROKEN (env, "Cannot get a global reference to java.lang.Thread"); - return initialized = -1; - } - - thread_current_mth = - (*env)->GetStaticMethodID (env, thread_class, "currentThread", - "()Ljava/lang/Thread;"); - if (!thread_current_mth) - { - BROKEN (env, "cannot find Thread.currentThread() method"); - return initialized = -1; - } - - thread_equals_mth = - (*env)->GetMethodID (env, thread_class, "equals", "(Ljava/lang/Object;)Z"); - if (!thread_equals_mth) - { - BROKEN (env, "cannot find Thread.equals() method"); - return initialized = -1; - } - - thread_join_mth = (*env)->GetMethodID (env, thread_class, "join", "()V"); - if (!thread_join_mth) - { - BROKEN (env, "cannot find Thread.join() method"); - return initialized = -1; - } - - thread_stop_mth = (*env)->GetMethodID (env, thread_class, "stop", "()V"); - if ( ! thread_stop_mth ) - { - BROKEN (env, "cannot find Thread.stop() method"); - return initialized = -1; - } - - thread_setPriority_mth = - (*env)->GetMethodID (env, thread_class, "setPriority", "(I)V"); - if ( ! thread_setPriority_mth ) - { - BROKEN (env, "cannot find Thread.setPriority() method"); - return initialized = -1; - } - - thread_yield_mth = - (*env)->GetStaticMethodID (env, thread_class, "yield", "()V"); - if ( ! thread_yield_mth ) - { - BROKEN (env, "cannot find Thread.yield() method"); - return initialized = -1; - } - - /* java.lang.ThreadLocal */ - lcl_class = (*env)->FindClass (env, "java/lang/ThreadLocal"); - if ( ! lcl_class ) - { - BROKEN (env, "cannot find class java.lang.ThreadLocal"); - return initialized = -1; - } - - /* Pin it down. */ - threadlocal_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if ( ! threadlocal_class ) - { - BROKEN (env, "Cannot get a global reference to java.lang.ThreadLocal"); - return initialized = -1; - } - - threadlocal_ctor = (*env)->GetMethodID (env, threadlocal_class, - "<init>", "()V"); - if ( ! threadlocal_ctor ) - { - BROKEN (env, "cannot find ThreadLocal.<init>()V"); - return initialized = -1; - } - - threadlocal_get_mth = (*env)->GetMethodID (env, threadlocal_class, - "get", "()Ljava/lang/Object;"); - if ( ! threadlocal_get_mth ) - { - BROKEN (env, "cannot find java.lang.ThreadLocal.get()Object"); - return initialized = -1; - } - - threadlocal_set_mth = (*env)->GetMethodID (env, threadlocal_class, - "set", "(Ljava/lang/Object;)V"); - if ( ! threadlocal_set_mth ) - { - BROKEN (env, "cannot find ThreadLocal.set(Object)V"); - return initialized = -1; - } - - /* java.lang.Long */ - lcl_class = (*env)->FindClass (env, "java/lang/Long"); - if ( ! lcl_class ) - { - BROKEN (env, "cannot find class java.lang.Long"); - return initialized = -1; - } - - /* Pin it down. */ - long_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!long_class) - { - BROKEN (env, "Cannot get a global reference to java.lang.Long"); - return initialized = -1; - } - - long_ctor = (*env)->GetMethodID (env, long_class, "<init>", "(J)V"); - if (!long_ctor) - { - BROKEN (env, "cannot find method java.lang.Long.<init>(J)V"); - return initialized = -1; - } - - long_longValue_mth = - (*env)->GetMethodID (env, long_class, "longValue", "()J"); - if (!long_longValue_mth) - { - BROKEN (env, "cannot find method java.lang.Long.longValue()J"); - return initialized = -1; - } - - - /* GThreadNativeMethodRunner */ - lcl_class = - (*env)->FindClass (env, - "gnu/java/awt/peer/gtk/GThreadNativeMethodRunner"); - if ( ! lcl_class ) - { - BROKEN (env, - "cannot find gnu.java.awt.peer.gtk.GThreadNativeMethodRunner"); - return initialized = -1; - } - - /* Pin it down. */ - runner_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!runner_class) - { - BROKEN (env, - "Cannot get a global reference to the class GThreadNativeMethodRunner"); - return initialized = -1; - } - - runner_ctor = (*env)->GetMethodID (env, runner_class, "<init>", "(JJZ)V"); - if ( ! runner_ctor ) - { - BROKEN (env, - "cannot find method GThreadNativeMethodRunner.<init>(JJZ)"); - return initialized = -1; - } - - runner_start_mth = (*env)->GetMethodID (env, runner_class, "start", "()V"); - if ( ! runner_start_mth ) - { - BROKEN (env, "cannot find method GThreadNativeMethodRunner.start()V"); - return initialized = -1; - } - - - runner_threadToThreadID_mth = - (*env)->GetStaticMethodID (env, runner_class, - "threadToThreadID", "(Ljava/lang/Thread;)I"); - if ( ! runner_threadToThreadID_mth ) - { - BROKEN (env, - "cannot find method GThreadNativeMethodRunner.threadToThreadID(java.lang.Thread)I"); - return initialized = -1; - } - - - runner_threadIDToThread_mth = - (*env)->GetStaticMethodID (env, runner_class, - "threadIDToThread", "(I)Ljava/lang/Thread;"); - if ( ! runner_threadIDToThread_mth ) - { - BROKEN (env, - "cannot find method GThreadNativeMethodRunner.threadIDToThread(I)java.lang.Thread"); - return initialized = -1; - } - - - runner_deRegisterJoinable_mth = - (*env)->GetStaticMethodID (env, runner_class, "deRegisterJoinable", - "(Ljava/lang/Thread;)V"); - if (!runner_deRegisterJoinable_mth) - { - BROKEN (env, - "cannot find method GThreadNativeMethodRunner.deRegisterJoinable(java.lang.Thread)V"); - return initialized = -1; - } - - - /* java.lang.InterruptedException */ - lcl_class = (*env)->FindClass (env, "java/lang/InterruptedException"); - if ( ! lcl_class ) - { - BROKEN (env, "cannot find class java.lang.InterruptedException"); - return initialized = -1; - } - - /* Pin it down. */ - interrupted_exception_class = (jclass) (*env)->NewGlobalRef (env, lcl_class); - DELETE_LOCAL_REF (env, lcl_class); - if (!interrupted_exception_class) - { - BROKEN (env, "Cannot make a global reference" - " to java.lang.InterruptedException"); - return initialized = -1; - } - -#ifdef JNI_VERSION_1_2 - if (HAVE_JNI_VERSION_1_2) - assert ( ! (*env)->ExceptionCheck (env)); - else -#endif - assert ( ! (*env)->ExceptionOccurred (env)); - - - return initialized = 1; -} - - - - - -/************************************************************************/ -/* Utilities to allocate and free java.lang.Objects */ -/************************************************************************/ - -/* The condition variables are java.lang.Object objects, - * which this method allocates and returns a global ref. Note that global - * refs must be explicitly freed (isn't C fun?). - */ -static jobject -allocatePlainObject (JNIEnv * env) -{ - jobject lcl_obj, global_obj; - - lcl_obj = (*env)->NewObject (env, obj_class, obj_ctor); - if (!lcl_obj) - { - BROKEN (env, "cannot allocate object"); - return NULL; - } - - global_obj = (*env)->NewGlobalRef (env, lcl_obj); - DELETE_LOCAL_REF (env, lcl_obj); - if (!global_obj) - { - NEW_BROKEN (env, "cannot make global ref for a new plain Java object"); - /* Deliberate fall-through */ - } - - return global_obj; -} - -/* Frees any Java object given a global ref (isn't C fun?) */ -static void -freeObject (JNIEnv * env, jobject obj) -{ - if (obj) - { - (*env)->DeleteGlobalRef (env, obj); - /* DeleteGlobalRef can never fail */ - } -} - - -/************************************************************************/ -/* Utilities to allocate and free Java mutexes */ -/************************************************************************/ - -/* The mutexes are gnu.java.awt.peer.gtk.GThreadMutex objects, - * which this method allocates and returns a global ref. Note that global - * refs must be explicitly freed (isn't C fun?). - * - * Free this with freeObject() - */ -static jobject -allocateMutexObject (JNIEnv * env) -{ - jobject lcl_obj, global_obj; - - lcl_obj = (*env)->NewObject (env, mutex_class, mutex_ctor); - if (!lcl_obj) - { - BROKEN (env, "cannot allocate a GThreadMutex"); - return NULL; - } - - global_obj = (*env)->NewGlobalRef (env, lcl_obj); - DELETE_LOCAL_REF (env, lcl_obj); - if (!global_obj) - { - NEW_BROKEN (env, "cannot make global ref"); - /* Deliberate fallthrough */ - } - - return global_obj; -} - - -/************************************************************************/ -/* Locking code */ -/************************************************************************/ - -/* Lock a Java object */ -#define ENTER_MONITOR(env, m) \ - enterMonitor(env, m, G_STRINGIFY(m)) - -/* Return -1 on failure, 0 on success. */ -static int -enterMonitor (JNIEnv * env, jobject monitorObj, const char monName[]) -{ - if (TRACE_MONITORS) - tracing (" <MonitorEnter(%s)>", monName); - assert (monitorObj); - if ((*env)->MonitorEnter (env, monitorObj) < 0) - { - BROKEN (env, "cannot enter monitor"); - return -1; - } - return 0; -} - - -/* Unlock a Java object */ -#define EXIT_MONITOR(env, m) \ - exitMonitor(env, m, G_STRINGIFY(m)) - -static int -exitMonitor (JNIEnv * env, jobject mutexObj, const char monName[]) -{ - if (TRACE_MONITORS) - tracing (" <MonitorExit(%s)>", monName); - assert (mutexObj); - if ((*env)->MonitorExit (env, mutexObj) < 0) - { - BROKEN (env, "cannot exit monitor "); - return -1; - } - return 0; -} - - -/************************************************************************/ -/* Miscellaneous utilities */ -/************************************************************************/ - -/* Get the Java Thread object that corresponds to a particular thread ID. - A negative thread Id gives us a null object. - - Returns a local reference. -*/ -static jobject -getThreadFromThreadID (JNIEnv * env, gpointer gThreadID) -{ - jint threadNum = (jint) gThreadID; - jobject thread; - - if (threadNum < 0) - { - NEW_BROKEN (env, "getThreadFromThreadID asked to look up" - " a negative thread index"); - return NULL; - } - - thread = (*env)->CallStaticObjectMethod - (env, runner_class, runner_threadIDToThread_mth, threadNum); - - if (MAYBE_BROKEN (env, "cannot get Thread for threadID ")) - return NULL; - - return thread; -} - -/** Return the unique threadID of THREAD. - - Error handling: Return (gpointer) -1 on all failures, - and propagate an exception. -*/ -static gpointer -getThreadIDFromThread (JNIEnv * env, jobject thread) -{ - jint threadNum; - - if (ENABLE_EXPENSIVE_ASSERTIONS) - assert ((*env)->IsInstanceOf (env, thread, thread_class)); - - HIDE_OLD_TROUBLE (env); - - threadNum = (*env)->CallStaticIntMethod - (env, runner_class, runner_threadToThreadID_mth, thread); - - if (MAYBE_BROKEN (env, "cannot get ThreadID for a Thread ")) - { - threadNum = -1; - goto done; - } - - - SHOW_OLD_TROUBLE (); - -done: - return (gpointer) threadNum; -} - - -/************************************************************************/ -/* The Actual JNI functions that we pass to the function vector. */ -/************************************************************************/ - - -/************************************************************************/ -/* Mutex Functions */ -/************************************************************************/ - -/*** Mutex Utilities ****/ -struct mutexObj_cache -{ - jobject lockForPotentialLockersObj; /* Lock for the potentialLockers - field. Local reference. */ - jobject lockObj; /* The real lock we use. This is a GLOBAL - reference and must not be freed. */ -}; - -/* Initialize the cache of sub-locks for a particular mutex object. - - -1 on error, 0 on success. The caller is not responsible for freeing the - partially-populated cache in case of failure (but in practice does anyway) - (This actually never fails, though, since GetObjectField allegedly never - fails.) - - Guaranteed to leave all fields of the cache initialized, even if only to - zero. -*/ -static int -populate_mutexObj_cache (JNIEnv * env, jobject mutexObj, - struct mutexObj_cache *mcache) -{ - mcache->lockObj = mutexObj; /* the mutexObj is its own lock. */ - assert (mcache->lockObj); - - mcache->lockForPotentialLockersObj = (*env)->GetObjectField - (env, mutexObj, mutex_lockForPotentialLockers_fld); - /* GetObjectField can never fail. */ - - /* Retrieving a NULL object could only happen if we somehow got a - a mutex object that was not properly intialized. */ - assert (mcache->lockForPotentialLockersObj); - - return 0; -} - - -/* Clean out the mutexObj_cache, even if it was never populated. */ -static void -clean_mutexObj_cache (JNIEnv * env, struct mutexObj_cache *mcache) -{ - /* OK to pass NULL refs to DELETE_LOCAL_REF */ - DELETE_LOCAL_REF (env, mcache->lockForPotentialLockersObj); - /* mcache->lockObj is a GLOBAL reference. */ - mcache->lockObj = NULL; -} - -/* -1 on failure, 0 on success. - The mutexObj_cache is already populated for this particular object. */ -static int -mutexObj_lock (JNIEnv * env, jobject mutexObj, struct mutexObj_cache *mcache) -{ - jint potentialLockers; - - if (ENTER_MONITOR (env, mcache->lockForPotentialLockersObj)) - return -1; - - assert(mutexObj); - potentialLockers = - (*env)->GetIntField (env, mutexObj, mutex_potentialLockers_fld); - /* GetIntField() never fails. */ - - ++potentialLockers; - - (*env)->SetIntField - (env, mutexObj, mutex_potentialLockers_fld, potentialLockers); - - if (EXIT_MONITOR (env, mcache->lockForPotentialLockersObj)) - return -1; - - if (ENTER_MONITOR (env, mcache->lockObj)) - return -1; - - SHOW_OLD_TROUBLE (); - - return 0; -} - -/* Unlock a GMutex, once we're already in JNI and have already gotten the - mutexObj for it. This skips the messages that TRACE_API_CALLS would - print. - - Returns -1 on error, 0 on success. */ -static int -mutexObj_unlock (JNIEnv * env, jobject mutexObj, - struct mutexObj_cache *mcache) -{ - jint potentialLockers; - int ret = -1; /* assume failure until we suceed. */ - - /* Free the lock first, so that someone waiting for the lock can get it - ASAP. */ - /* This is guaranteed not to block. */ - if (EXIT_MONITOR (env, mcache->lockObj) < 0) - goto done; - - /* Kick down potentialLockers by one. We do this AFTER we free the lock, so - that we hold it no longer than necessary. */ - if (ENTER_MONITOR (env, mcache->lockForPotentialLockersObj) < 0) - goto done; - - potentialLockers = (*env)->GetIntField - (env, mutexObj, mutex_potentialLockers_fld); - /* GetIntField never fails */ - - assert (potentialLockers >= 1); - --potentialLockers; - - (*env)->SetIntField - (env, mutexObj, mutex_potentialLockers_fld, potentialLockers); - /* Never fails, so the JNI book says. */ - - /* Clean up. */ - if (EXIT_MONITOR (env, mcache->lockForPotentialLockersObj) < 0) - goto done; - ret = 0; - -done: - return ret; -} - -/*** Mutex Implementations ****/ - -/* Create a mutex, which is a java.lang.Object for us. - In case of failure, we'll return NULL. Which will implicitly - cause future calls to fail. */ -static GMutex * -mutex_new_jni_impl (void) -{ - jobject mutexObj; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("mutex_new_jni_impl()"); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - if (setup_cache (env) < 0) - { - mutexObj = NULL; - goto done; - } - - mutexObj = allocateMutexObject (env); - -done: - if (TRACE_API_CALLS) - tracing (" ==> %p \n", mutexObj); - - return (GMutex *) mutexObj; - -} - -/* Lock a mutex. */ -static void -mutex_lock_jni_impl (GMutex * mutex) -{ - struct mutexObj_cache mcache; - jobject mutexObj = (jobject) mutex; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("mutex_lock_jni_impl( mutexObj = %p )", mutexObj); - - assert (mutexObj); - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - if (setup_cache (env) < 0) - goto done; - - HIDE_OLD_TROUBLE (env); - - if (populate_mutexObj_cache (env, mutexObj, &mcache) < 0) - goto done; - - mutexObj_lock (env, mutexObj, &mcache); - /* No need to error check; we've already reported it in any case. */ - -done: - clean_mutexObj_cache (env, &mcache); - if (TRACE_API_CALLS) - tracing (" ==> VOID \n"); -} - - -/* Try to lock a mutex. Return TRUE if we succeed, FALSE if we fail. - FALSE on error. */ -static gboolean -mutex_trylock_jni_impl (GMutex * gmutex) -{ - jobject mutexObj = (jobject) gmutex; - jint potentialLockers; - gboolean ret = FALSE; - JNIEnv *env; - union env_union e; - struct mutexObj_cache mcache; - - if (TRACE_API_CALLS) - tracing ("mutex_trylock_jni_impl(mutexObj=%p)", mutexObj); - - assert (mutexObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - if (populate_mutexObj_cache (env, mutexObj, &mcache) < 0) - goto done; - - if (ENTER_MONITOR (env, mcache.lockForPotentialLockersObj)) - goto done; - - potentialLockers = (*env)->GetIntField - (env, mutexObj, mutex_potentialLockers_fld); - - assert (potentialLockers >= 0); - - if (potentialLockers) - { - /* Already locked. Clean up and leave. */ - EXIT_MONITOR (env, mcache.lockForPotentialLockersObj); - /* Ignore any error code from EXIT_MONITOR; there's nothing we could do - at this level, in any case. */ - goto done; - } - - /* Guaranteed not to block. */ - if (ENTER_MONITOR (env, mcache.lockObj)) - { - /* Clean up the existing lock. */ - EXIT_MONITOR (env, mcache.lockForPotentialLockersObj); - /* Ignore any error code from EXIT_MONITOR; there's nothing we could do - at this level, in any case. */ - goto done; - } - - - /* We have the monitor. Record that fact. */ - potentialLockers = 1; - (*env)->SetIntField - (env, mutexObj, mutex_potentialLockers_fld, potentialLockers); - /* Set*Field() never fails */ - - ret = TRUE; /* We have the lock. */ - - /* Clean up. */ - if (EXIT_MONITOR (env, mcache.lockForPotentialLockersObj)) - goto done; /* If we fail at this point, still keep the - main lock. */ - - SHOW_OLD_TROUBLE (); -done: - clean_mutexObj_cache (env, &mcache); - if (TRACE_API_CALLS) - tracing (" ==> %s\n", ret ? "TRUE" : "FALSE"); - return ret; -} - - -/* Unlock a mutex. */ -static void -mutex_unlock_jni_impl (GMutex * gmutex) -{ - jobject mutexObj = (jobject) gmutex; - struct mutexObj_cache mcache; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("mutex_unlock_jni_impl(mutexObj=%p)", mutexObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - assert (mutexObj); - - if ( populate_mutexObj_cache (env, mutexObj, &mcache) < 0) - goto done; - - (void) mutexObj_unlock (env, mutexObj, &mcache); - - SHOW_OLD_TROUBLE (); - -done: - clean_mutexObj_cache (env, &mcache); - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - - -/* Free a mutex (isn't C fun?). OK this time for it to be NULL. - No failure conditions, for a change. */ -static void -mutex_free_jni_impl (GMutex * mutex) -{ - jobject mutexObj = (jobject) mutex; - JNIEnv *env; - union env_union e; - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - if (TRACE_API_CALLS) - tracing ("mutex_free_jni_impl(%p)", mutexObj); - - freeObject (env, mutexObj); - - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - - - -/************************************************************************/ -/* Condition variable code */ -/************************************************************************/ - -/* Create a new condition variable. This is a java.lang.Object for us. */ -static GCond * -cond_new_jni_impl (void) -{ - jobject condObj; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("mutex_free_jni_impl()"); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - condObj = allocatePlainObject (env); - - if (TRACE_API_CALLS) - tracing (" ==> %p\n", condObj); - - return (GCond *) condObj; -} - -/* Signal on a condition variable. This is simply calling Object.notify - * for us. - */ -static void -cond_signal_jni_impl (GCond * gcond) -{ - JNIEnv *env; - union env_union e; - jobject condObj = (jobject) gcond; - - if (TRACE_API_CALLS) - tracing ("cond_signal_jni_impl(condObj = %p)", condObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - assert (condObj); - - /* Must have locked an object to call notify */ - if (ENTER_MONITOR (env, condObj)) - goto done; - - (*env)->CallVoidMethod (env, condObj, obj_notify_mth); - if (MAYBE_BROKEN (env, "cannot signal mutex with Object.notify()")) - { - if (EXIT_MONITOR (env, condObj)) - BADLY_BROKEN1 ("Failed to unlock a monitor; the VM may deadlock."); - goto done; - } - - EXIT_MONITOR (env, condObj); - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - -/* Broadcast to all waiting on a condition variable. This is simply - * calling Object.notifyAll for us. - */ -static void -cond_broadcast_jni_impl (GCond * gcond) -{ - jobject condObj = (jobject) gcond; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("cond_broadcast_jni_impl(condObj=%p)", condObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - assert (condObj); - /* Must have locked an object to call notifyAll */ - if (ENTER_MONITOR (env, condObj)) - goto done; - - (*env)->CallVoidMethod (env, condObj, obj_notifyall_mth); - if (MAYBE_BROKEN (env, "cannot broadcast to mutex with Object.notify()")) - { - EXIT_MONITOR (env, condObj); - goto done; - } - - EXIT_MONITOR (env, condObj); - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -/* Wait on a condition variable. For us, this simply means calling - * Object.wait. - * - * Throws a Java exception on trouble; may leave the mutexes set arbitrarily. - * XXX TODO: Further improve error recovery. - */ -static void -cond_wait_jni_impl (GCond * gcond, GMutex * gmutex) -{ - struct mutexObj_cache cache; - jobject condObj = (jobject) gcond; - jobject mutexObj = (jobject) gmutex; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("cond_wait_jni_impl(condObj=%p, mutexObj=%p)", - condObj, mutexObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - assert (condObj); - assert (mutexObj); - /* Must have locked a Java object to call wait on it */ - if (ENTER_MONITOR (env, condObj) < 0) - goto done; - - /* Our atomicity is now guaranteed; we're protected by the Java monitor on - condObj. Unlock the GMutex. */ - if (mutexObj_unlock (env, mutexObj, &cache)) - goto done; - - (*env)->CallVoidMethod (env, condObj, obj_wait_mth); - if (MAYBE_BROKEN (env, "cannot wait on condObj")) - { - EXIT_MONITOR (env, condObj); /* ignore err checking */ - goto done; - } - - /* Re-acquire the lock on the GMutex. Do this while we're protected by the - Java monitor on condObj. */ - if (mutexObj_lock (env, mutexObj, &cache)) - goto done; - - EXIT_MONITOR (env, condObj); - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -/** Wait on a condition variable until a timeout. This is a little tricky - * for us. We first call Object.wait(J) giving it the appropriate timeout - * value. On return, we check whether an InterruptedException happened. If - * so, that is Java-speak for wait timing out. - * - * We return FALSE if we timed out. Return TRUE if the condition was - * signalled first, before we timed out. - * - * In case of trouble we throw a Java exception. Whether we return FALSE or - * TRUE depends upon whether the condition was raised before the trouble - * happened. - * - * I believe that this function goes to the proper lengths to try to unlock - * all of the locked mutexes and monitors, as appropriate, and that it further - * tries to make sure that the thrown exception is the current one, not any - * future cascaded one from something like a failure to unlock the monitors. - */ -static gboolean -cond_timed_wait_jni_impl (GCond * gcond, GMutex * gmutex, GTimeVal * end_time) -{ - JNIEnv *env; - union env_union e; - jlong time_millisec; - jint time_nanosec; - jthrowable cause; - jobject condObj = (jobject) gcond; - jobject mutexObj = (jobject) gmutex; - gboolean condRaised = FALSE; /* Condition has not been raised yet. */ - struct mutexObj_cache cache; - gboolean interrupted; - - if (TRACE_API_CALLS) - { - tracing ("cond_timed_wait_jni_impl(cond=%p, mutex=%p," - " end_time=< sec=%lu, usec=%lu >)", condObj, mutexObj, - (unsigned long) end_time->tv_sec, - (unsigned long) end_time->tv_usec); - } - - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - time_millisec = end_time->tv_sec * 1000 + end_time->tv_usec / 1000; - time_nanosec = 1000 * (end_time->tv_usec % 1000); - - /* Must have locked an object to call wait */ - if (ENTER_MONITOR (env, condObj) < 0) - goto done; - - if (mutexObj_unlock (env, mutexObj, &cache) < 0) - { - if (EXIT_MONITOR (env, condObj) < 0) - criticalMsg - ("Unable to unlock an existing lock on a condition; your proram may deadlock"); - goto done; - } - - - (*env)->CallVoidMethod (env, condObj, obj_wait_nanotime_mth, - time_millisec, time_nanosec); - - /* If there was trouble, save that fact, and the reason for the trouble. We - want to respond to this condition as fast as possible. */ - cause = (*env)->ExceptionOccurred (env); - - if ( ! cause ) - { - condRaised = TRUE; /* condition was signalled */ - } - else if ((*env)->IsInstanceOf (env, cause, interrupted_exception_class)) - { - condRaised = FALSE; /* Condition was not raised before timeout. - (This is redundant with the initialization - of condRaised above) */ - (*env)->ExceptionClear (env); /* Clear the InterruptedException. */ - cause = NULL; /* no pending cause now. */ - } - else - { - interrupted = FALSE; /* Trouble, but not because of - InterruptedException. Assume the condition - was not raised. */ - /* Leave condRaised set to FALSE */ - } - - /* Irrespective of whether there is a pending problem to report, go ahead - and try to clean up. This may end up throwing an exception that is - different from the one that was thrown by the call to Object.wait(). - So we will override it with the first exception (don't want to have - cascading problems). */ - if (mutexObj_lock (env, mutexObj, &cache) && !cause) - { - cause = (*env)->ExceptionOccurred (env); - assert (cause); - } - - if (EXIT_MONITOR (env, condObj) && !cause) - { - cause = (*env)->ExceptionOccurred (env); - assert (cause); - } - - if (cause) /* Raise the first cause. */ - { - BROKEN_CAUSE (env, cause, "error in timed wait or during its cleanup"); - goto done; - } - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> condRaised = %s\n", condRaised ? "TRUE" : "FALSE"); - return condRaised; -} - - -/* Free a condition variable. (isn't C fun?). Can not fail. */ -static void -cond_free_jni_impl (GCond * cond) -{ - jobject condObj = (jobject) cond; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("cond_free_jni_impl(condObj = %p)", condObj); - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - freeObject (env, condObj); - - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -/************************************************************************/ -/* Thread-local data code */ -/************************************************************************/ - -/* Create a new thread-local key. We use java.lang.ThreadLocal objects - * for this. This returns the pointer representation of a Java global - * reference. - * - * We will throw a Java exception and return NULL in case of failure. - */ -static GPrivate * -private_new_jni_impl (GDestroyNotify notify __attribute__ ((unused))) -{ - JNIEnv *env; - union env_union e; - jobject lcl_key; - jobject global_key; - GPrivate *gkey = NULL; /* Error return code */ - - if (TRACE_API_CALLS) - tracing ("private_new_jni_impl()"); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - lcl_key = (*env)->NewObject (env, threadlocal_class, threadlocal_ctor); - if ( ! lcl_key ) - { - BROKEN (env, "cannot allocate a ThreadLocal"); - goto done; - } - - global_key = ((*env)->NewGlobalRef (env, lcl_key)); - DELETE_LOCAL_REF (env, lcl_key); - if ( ! global_key) - { - NEW_BROKEN (env, "cannot create a GlobalRef to a new ThreadLocal"); - goto done; - } - - gkey = (GPrivate *) global_key; - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> %p\n", (void *) gkey); - - return gkey; -} - -/* Get this thread's value for a thread-local key. This is simply - * ThreadLocal.get for us. Return NULL if no value. (I can't think of - * anything else to do.) - */ -static gpointer -private_get_jni_impl (GPrivate * gkey) -{ - JNIEnv *env; - union env_union e; - jobject val_wrapper; - jobject keyObj = (jobject) gkey; - gpointer thread_specific_data = NULL; /* Init to the error-return value */ - - jlong val; - - if (TRACE_API_CALLS) - tracing ("private_get_jni_impl(keyObj=%p)", keyObj); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - val_wrapper = (*env)->CallObjectMethod (env, keyObj, threadlocal_get_mth); - if (MAYBE_BROKEN (env, "cannot find thread-local object")) - goto done; - - if (! val_wrapper ) - { - /* It's Java's "null" object. No ref found. This is OK; we must never - have set a value in this thread. Note that this next statement is - not necessary, strictly speaking, since we're already initialized to - NULL. A good optimizing C compiler will detect that and optimize out - this statement. */ - thread_specific_data = NULL; - goto done; - } - - val = (*env)->CallLongMethod (env, val_wrapper, long_longValue_mth); - - if (MAYBE_BROKEN (env, "cannot get thread local value")) - goto done; - - thread_specific_data = (gpointer) (intptr_t) val; - - /* Only re-raise the old pending exception if a new one hasn't come along to - supersede it. */ - SHOW_OLD_TROUBLE (); - -done: - - if (TRACE_API_CALLS) - tracing (" ==> %p\n", thread_specific_data); - - return thread_specific_data; -} - -/* Set this thread's value for a thread-local key. This is simply - * ThreadLocal.set() for us. - */ -static void -private_set_jni_impl (GPrivate * gkey, gpointer thread_specific_data) -{ - JNIEnv *env; - union env_union e; - jobject val_wrapper; - jobject keyObj = (jobject) gkey; - - - if (TRACE_API_CALLS) - tracing ("private_set_jni_impl(keyObj=%p, thread_specific_data=%p)", - keyObj, thread_specific_data); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - /* We are just going to always use a Java long to represent a C pointer. - Otherwise all of the code would end up being conditionalized for various - pointer sizes, and that seems like too much of a hassle, in order to save - a paltry few bytes, especially given the horrendous overhead of JNI in - any case. - */ - - val_wrapper = (*env)->NewObject (env, long_class, long_ctor, - (jlong) (intptr_t) thread_specific_data); - if ( ! val_wrapper ) - { - BROKEN (env, "cannot create a java.lang.Long"); - goto done; - } - - /* At this point, we now have set lcl_obj as a numeric class that wraps - around the thread-specific data we were given. */ - (*env)->CallVoidMethod (env, keyObj, threadlocal_set_mth, val_wrapper); - if (MAYBE_BROKEN (env, "cannot set thread local value")) - goto done; - - SHOW_OLD_TROUBLE (); -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -/** Create an object of type gnu.java.awt.peer.gtk.GThreadNativeMethodRunner. - Run it. - - We need to create joinable threads. We handle the notion of a joinable - thread by determining whether or not we are going to maintain a permanent - hard reference to it until it croaks. - - Posix does not appear to have a Java-like concept of daemon threads, where - the JVM will exit when there are only daemon threads running. - - Error handling: - - To quote from the glib guide: - "GError should only be used to report recoverable runtime errors, never - to report programming errors." - - So how do we consider the failure to create a thread? Well, each of the - failure cases in this function are discussed, and none of them are really - recoverable. - - The glib library is really designed so that you should fail - catastrophically in case of "programming errors". The only error defined - for the GThread functions is G_THREAD_ERROR_AGAIN, and that for - thread_create. - - Most of these GThread functions could fail if we run out of memory, for - example, but the only one capable of reporting that fact is - thread_create. */ -static void -thread_create_jni_impl (GThreadFunc func, - gpointer data, - gulong stack_size __attribute__((unused)), - gboolean joinable, - gboolean bound __attribute__((unused)), - GThreadPriority gpriority, - /* This prototype is horrible. threadIDp is actually - a gpointer to the thread's thread-ID. Which is, - of course, itself a gpointer-typed value. Ouch. */ - gpointer threadIDp, - /* Do not touch the GError stuff unless you have - RECOVERABLE trouble. There is no recoverable - trouble in this implementation. */ - GError **errorp __attribute__((unused))) -{ - JNIEnv *env; - union env_union e; - union func_union f; - jboolean jjoinable = joinable; - jobject newThreadObj; - gpointer threadID; /* to be filled in */ - - if (TRACE_API_CALLS) - { - f.g_func = func; - tracing ("thread_create_jni_impl(func=%p, data=%p, joinable=%s," - " threadIDp=%p, *(int *) threadIDp = %d)", - f.void_func, data, joinable ? "TRUE" : "FALSE", - threadIDp, *(int *) threadIDp); - } - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - { - /* The failed call to setup the cache is certainly not recoverable; - not appropriate for G_THREAD_ERROR_AGAIN. */ - *(gpointer *) threadIDp = NULL; - goto done; - } - HIDE_OLD_TROUBLE (env); - - /* If a thread is joinable, then notify its constructor. The constructor - will enter a hard reference for it, and the hard ref. won't go away until - the thread has been joined. */ - newThreadObj = - (*env)->NewObject (env, runner_class, runner_ctor, - (jlong) (intptr_t) func, (jlong) (intptr_t) data, - jjoinable); - if ( ! newThreadObj ) - { - BROKEN (env, "creating a new thread failed in the constructor"); - *(gpointer *) threadIDp = NULL; - /* The failed call to the constructor does not throw any errors such - that G_THREAD_ERROR_AGAIN is appropriate. No other recoverable - errors defined. Once again, we go back to the VM. */ - goto done; - } - - if (threadObj_set_priority (env, newThreadObj, gpriority) < 0) - { - *(gpointer *) threadIDp = NULL; - /* None of these possible exceptions from Thread.setPriority() are - recoverable, so they are not appropriate for EAGAIN. So we should - fail. */ - goto done; - } - - (*env)->CallVoidMethod (env, runner_class, runner_start_mth); - - if (MAYBE_BROKEN (env, "starting a new thread failed")) - { - *(gpointer *) threadIDp = NULL; - /* The only exception Thread.start() throws is - IllegalStateException. And that would indicate a programming error. - - So there are no situations such that G_THREAD_ERROR_AGAIN would be - OK. - - So, we don't use g_set_error() here to perform any error reporting. - */ - goto done; - } - - threadID = getThreadIDFromThread (env, newThreadObj); - - *(gpointer *) threadIDp = threadID; - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> (threadID = %p) \n", threadID); -} - - -/* Wraps a call to g_thread_yield. */ -static void -thread_yield_jni_impl (void) -{ - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("thread_yield_jni_impl()"); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - (*env)->CallStaticVoidMethod (env, thread_class, thread_yield_mth); - if (MAYBE_BROKEN (env, "Thread.yield() failed")) - goto done; - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -static void -thread_join_jni_impl (gpointer threadID) -{ - JNIEnv *env; - union env_union e; - jobject threadObj = NULL; - - if ( TRACE_API_CALLS ) - tracing ("thread_join_jni_impl(threadID=%p) ", threadID); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - HIDE_OLD_TROUBLE (env); - - threadObj = getThreadFromThreadID (env, threadID); - if ( ! threadObj ) /* Already reported with BROKEN */ - goto done; - - (*env)->CallVoidMethod (env, threadObj, thread_join_mth); - if (MAYBE_BROKEN (env, "Thread.join() failed")) - goto done; - - - (*env)->CallStaticVoidMethod - (env, runner_class, runner_deRegisterJoinable_mth, threadObj); - if (MAYBE_BROKEN (env, "Thread.deRegisterJoinableThread() failed")) - goto done; - - SHOW_OLD_TROUBLE (); - -done: - DELETE_LOCAL_REF (env, threadObj); - if (TRACE_API_CALLS) - tracing (" ==> VOID \n"); -} - -/* Terminate the current thread. Unlike pthread_exit(), here we do not need - to bother with a return value or exit value for the thread which is about - to croak. (The gthreads abstraction doesn't use it.) However, we *do* - need to bail immediately. We handle this with Thread.stop(), which is - a deprecated method. - - It's deprecated since we might leave objects protected by monitors in - half-constructed states on the way out -- Thread.stop() throws a - ThreadDeath exception, which is usually unchecked. There is no good - solution that I can see. */ -static void -thread_exit_jni_impl (void) -{ - JNIEnv *env; - union env_union e; - jobject this_thread; - - if (TRACE_API_CALLS) - tracing ("thread_exit_jni_impl() "); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - goto done; - - HIDE_OLD_TROUBLE (env); - - this_thread = (*env)-> - CallStaticObjectMethod (env, thread_class, thread_current_mth); - - if ( ! this_thread ) - { - BROKEN (env, "cannot get current thread"); - goto done; - } - - (*env)->CallVoidMethod (env, this_thread, thread_stop_mth); - if (MAYBE_BROKEN (env, "cannot call Thread.stop() on current thread")) - goto done; - - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> VOID \n"); -} - - -/* Translate a GThreadPriority to a Java priority level. */ -static jint -javaPriorityLevel (GThreadPriority priority) -{ - /* We have these fields in java.lang.Thread to play with: - - static int MIN_PRIORITY The minimum priority that a thread can have. - static int NORM_PRIORITY The default priority that is assigned to a - thread. - static int MAX_PRIORITY The maximum priority that a thread can have. - - We get these from the header file generated by javah, even though they're - documented as being 1, 5, and 10. - */ - static const jint minJPri = - gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MIN_PRIORITY; - static const jint normJPri = - gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_NORM_PRIORITY; - static const jint maxJPri = - gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_MAX_PRIORITY; - - switch (priority) - { - case G_THREAD_PRIORITY_LOW: - return minJPri; - break; - - default: - assert_not_reached (); - /* Deliberate fall-through if assertions are turned off; also shuts up - GCC warnings if they're turned on. */ - case G_THREAD_PRIORITY_NORMAL: - return normJPri; - break; - - case G_THREAD_PRIORITY_HIGH: - return (normJPri + maxJPri) / 2; - break; - - case G_THREAD_PRIORITY_URGENT: - return maxJPri; - break; - } -} - - -/** It would be safe not to implement this, according to the JNI docs, since - not all platforms do thread priorities. However, we might as well - provide the hint for those who want it. -*/ -static void -thread_set_priority_jni_impl (gpointer gThreadID, GThreadPriority gpriority) -{ - jobject threadObj = NULL; - JNIEnv *env; - union env_union e; - - if (TRACE_API_CALLS) - tracing ("thread_set_priority_jni_impl(gThreadID=%p, gpriority = %u) ", - gThreadID, gpriority); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - if (setup_cache (env) < 0) - goto done; - - HIDE_OLD_TROUBLE (env); - - - threadObj = getThreadFromThreadID (env, gThreadID); - if ( ! threadObj) /* Reported with BROKEN already. */ - goto done; - - if (threadObj_set_priority (env, threadObj, gpriority)) - goto done; - - SHOW_OLD_TROUBLE (); - -done: - DELETE_LOCAL_REF (env, threadObj); - - if (TRACE_API_CALLS) - tracing (" ==> VOID\n"); -} - - -/** It would be safe not to implement this, according to the JNI docs, since - not all platforms do thread priorities. However, we might as well - provide the hint for those who want it. - - -1 on failure, 0 on success. */ -static int -threadObj_set_priority (JNIEnv * env, jobject threadObj, - GThreadPriority gpriority) -{ - jint javaPriority = javaPriorityLevel (gpriority); - (*env)->CallVoidMethod (env, threadObj, thread_setPriority_mth, - javaPriority); - return MAYBE_BROKEN (env, "Thread.setPriority() failed"); -} - - -/** Return the result of Thread.currentThread(), a static method. */ -static void -thread_self_jni_impl (/* Another confusing glib prototype. This is - actually a gpointer to the thread's thread-ID. - Which is, of course, a gpointer. */ - gpointer my_thread_IDp) -{ - JNIEnv *env; - union env_union e; - jobject this_thread; - gpointer my_threadID; - - if (TRACE_API_CALLS) - tracing ("thread_self_jni_impl(my_thread_IDp=%p)", my_thread_IDp); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - - if (setup_cache (env) < 0) - return; - - HIDE_OLD_TROUBLE (env); - - this_thread = (*env)-> - CallStaticObjectMethod (env, thread_class, thread_current_mth); - if (! this_thread ) - { - BROKEN (env, "cannot get current thread"); - my_threadID = NULL; - goto done; - } - - my_threadID = getThreadIDFromThread (env, this_thread); - SHOW_OLD_TROUBLE (); - -done: - if (TRACE_API_CALLS) - tracing (" ==> (my_threadID = %p) \n", my_threadID); - - *(gpointer *) my_thread_IDp = my_threadID; -} - - -static gboolean -thread_equal_jni_impl (gpointer thread1, gpointer thread2) -{ - JNIEnv *env; - union env_union e; - - gpointer threadID1 = *(gpointer *) thread1; - gpointer threadID2 = *(gpointer *) thread2; - - jobject thread1_obj = NULL; - jobject thread2_obj = NULL; - gboolean ret; - - if (TRACE_API_CALLS) - tracing ("thread_equal_jni_impl(threadID1=%p, threadID2=%p)", - threadID1, threadID2); - - e.jni_env = &env; - (*the_vm)->GetEnv (the_vm, e.void_env, JNI_VERSION_1_1); - if (setup_cache (env) < 0) - { - ret = FALSE; /* what is safer? We really don't ever want - to return from here. */ - goto done; - } - - HIDE_OLD_TROUBLE (env); - thread1_obj = getThreadFromThreadID (env, threadID1); - thread2_obj = getThreadFromThreadID (env, threadID2); - - ret = (*env)->CallBooleanMethod (env, thread1_obj, - thread_equals_mth, thread2_obj); - - if (MAYBE_BROKEN (env, "Thread.equals() failed")) - { - ret = FALSE; - goto done; - } - - SHOW_OLD_TROUBLE (); - - -done: - DELETE_LOCAL_REF (env, thread1_obj); - DELETE_LOCAL_REF (env, thread2_obj); - - if (TRACE_API_CALLS) - tracing (" ==> %s\n", ret ? "TRUE" : "FALSE"); - - return ret; -} - - - - -/************************************************************************/ -/* GLIB interface */ -/************************************************************************/ - -/* set of function pointers to give to glib. */ -GThreadFunctions portable_native_sync_jni_functions = { - mutex_new_jni_impl, /* mutex_new */ - mutex_lock_jni_impl, /* mutex_lock */ - mutex_trylock_jni_impl, /* mutex_trylock */ - mutex_unlock_jni_impl, /* mutex_unlock */ - mutex_free_jni_impl, /* mutex_free */ - cond_new_jni_impl, /* cond_new */ - cond_signal_jni_impl, /* cond_signal */ - cond_broadcast_jni_impl, /* cond_broadcast */ - cond_wait_jni_impl, /* cond_wait */ - cond_timed_wait_jni_impl, /* cond_timed_wait */ - cond_free_jni_impl, /* cond_free */ - private_new_jni_impl, /* private_new */ - private_get_jni_impl, /* private_get */ - private_set_jni_impl, /* private_set */ - thread_create_jni_impl, /* thread_create */ - thread_yield_jni_impl, /* thread_yield */ - thread_join_jni_impl, /* thread_join */ - thread_exit_jni_impl, /* thread_exit */ - thread_set_priority_jni_impl, /* thread_set_priority */ - thread_self_jni_impl, /* thread_self */ - thread_equal_jni_impl, /* thread_equal */ -}; - - -/* Keep c-font-lock-extra-types in alphabetical order. */ -/* Local Variables: */ -/* c-file-style: "gnu" */ -/* c-font-lock-extra-types: ("\\sw+_t" "gboolean" "GError" "gpointer" - "GPrivate" "GThreadFunc" "GThreadFunctions" "GThreadPriority" - "gulong" - "JNIEnv" - "jboolean" "jclass" "jfieldID" "jint" "jlong" "jmethodID" "jobject" "jstring" "jthrowable" ) */ -/* End: */ diff --git a/libjava/jni/gtk-peer/gthread-jni.h b/libjava/jni/gtk-peer/gthread-jni.h deleted file mode 100644 index e7b33a61153..00000000000 --- a/libjava/jni/gtk-peer/gthread-jni.h +++ /dev/null @@ -1,48 +0,0 @@ -/* gthread-jni.h - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -#ifndef __GTHREADJNI_H__ -#define __GTHREADJNI_H__ - -#include <jni.h> -#include <glib.h> -#include "gtkpeer.h" - -extern GThreadFunctions portable_native_sync_jni_functions; -extern JavaVM *the_vm; - -#endif /* __GTHREADJNI_H__ */ diff --git a/libjava/jni/gtk-peer/gtk_jawt.c b/libjava/jni/gtk-peer/gtk_jawt.c deleted file mode 100644 index c63f07d0a23..00000000000 --- a/libjava/jni/gtk-peer/gtk_jawt.c +++ /dev/null @@ -1,197 +0,0 @@ -/* gtk_jawt.c -- GTK implementation of classpath_jawt.h - Copyright (C) 2005 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - - -#include "gtkpeer.h" -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include "classpath_jawt.h" - -jint -classpath_jawt_get_awt_version () -{ - return CLASSPATH_JAWT_VERSION; -} - -Display* -classpath_jawt_get_default_display (JNIEnv* env, jobject canvas) -{ - GdkDisplay *display; - Display *xdisplay; - GtkWidget *widget; - void *ptr; - jobject peer; - jclass class_id; - jmethodID method_id; - - /* retrieve peer object */ - class_id = (*env)->GetObjectClass (env, canvas); - - method_id = (*env)->GetMethodID (env, class_id, - "getPeer", - "()Ljava/awt/peer/ComponentPeer;"); - - peer = (*env)->CallObjectMethod (env, canvas, method_id); - - ptr = NSA_GET_PTR (env, peer); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - /* widget should be realized before Canvas.paint is called. */ - g_assert (GTK_WIDGET_REALIZED (widget)); - - display = gtk_widget_get_display (widget); - - xdisplay = GDK_DISPLAY_XDISPLAY (display); - - gdk_threads_leave (); - - return xdisplay; -} - -VisualID -classpath_jawt_get_visualID (JNIEnv* env, jobject canvas) -{ - GtkWidget *widget; - Visual *visual; - void *ptr; - jobject peer; - jclass class_id; - jmethodID method_id; - - class_id = (*env)->GetObjectClass (env, canvas); - - method_id = (*env)->GetMethodID (env, class_id, - "getPeer", - "()Ljava/awt/peer/ComponentPeer;"); - - peer = (*env)->CallObjectMethod (env, canvas, method_id); - - ptr = NSA_GET_PTR (env, peer); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - g_assert (GTK_WIDGET_REALIZED (widget)); - - visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget)); - g_assert (visual != NULL); - - gdk_threads_leave (); - - return visual->visualid; -} - -Drawable -classpath_jawt_get_drawable (JNIEnv* env, jobject canvas) -{ - GtkWidget *widget; - int drawable; - void *ptr; - jobject peer; - jclass class_id; - jmethodID method_id; - - class_id = (*env)->GetObjectClass (env, canvas); - - method_id = (*env)->GetMethodID (env, class_id, - "getPeer", - "()Ljava/awt/peer/ComponentPeer;"); - - peer = (*env)->CallObjectMethod (env, canvas, method_id); - - ptr = NSA_GET_PTR (env, peer); - - gdk_threads_enter (); - - widget = GTK_WIDGET (ptr); - - g_assert (GTK_WIDGET_REALIZED (widget)); - - drawable = GDK_DRAWABLE_XID (widget->window); - - gdk_threads_leave (); - - return drawable; -} - -jint -classpath_jawt_object_lock (jobject lock) -{ - JNIEnv *env = gdk_env(); - (*env)->MonitorEnter (env, lock); - return 0; -} - -void -classpath_jawt_object_unlock (jobject lock) -{ - JNIEnv *env = gdk_env(); - (*env)->MonitorExit (env, lock); -} - -jint -classpath_jawt_lock () -{ - gdk_threads_enter (); - return 0; -} - -void -classpath_jawt_unlock () -{ - gdk_threads_leave (); -} - -jobject -classpath_jawt_create_lock () -{ - JNIEnv *env = gdk_env (); - jobject lock = (*env)->NewStringUTF (env, "jawt-lock"); - NSA_SET_GLOBAL_REF (env, lock); - return lock; -} - -void -classpath_jawt_destroy_lock (jobject lock) -{ - JNIEnv *env = gdk_env (); - NSA_DEL_GLOBAL_REF (env, lock); -} diff --git a/libjava/jni/gtk-peer/gtkcairopeer.h b/libjava/jni/gtk-peer/gtkcairopeer.h deleted file mode 100644 index c4b1eb6a917..00000000000 --- a/libjava/jni/gtk-peer/gtkcairopeer.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef __GTKCAIROPEER_H__ -#define __GTKCAIROPEER_H__ - -/* gtkcairopeer.h -- Some global variables and #defines - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -#include "gtkpeer.h" -#include <cairo.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -/* - A graphics2d struct is both simpler and uglier than a graphics - struct. - - Most of the graphics2d drawing state is held in the referenced cairo_t - and corresponding cairo_surface_t, so we can ignore it. - - In addition to the cairo_t, we need to hold an extra reference to the - underlying GdkDrawable so its refcount matches the lifecycle of the java - Graphics object which is peering with us; also a reference to a byte - buffer and cairo_surface_t which contain the pattern you're drawing from - (if it exists). - - Finally, it is possible that we are using a non-RENDER capable X server, - therefore we will be drawing to an cairo_surface_t which is actually a - pixbuf. When this is the case, the pointer to a GdkPixbuf will be - non-NULL and any drawing operation needs to be bracketed by pixbuf - load/save operations. If the GdkPixbuf pointer is NULL, we will treat - the cairo_surface_t as RENDER-capable. - */ - -struct graphics2d -{ - cairo_t *cr; - cairo_surface_t *surface; - GdkDrawable *drawable; - GdkWindow *win; - GdkPixbuf *drawbuf; - char *pattern_pixels; - cairo_surface_t *pattern_surface; - cairo_pattern_t *pattern; - gboolean debug; - enum - { - MODE_DRAWABLE_WITH_RENDER, - MODE_DRAWABLE_NO_RENDER, - MODE_JAVA_ARRAY - } - mode; - - /* Support for MODE_JAVA_ARRAY */ - jintArray jarray; - jint width, height; - jint *javabuf; - jboolean isCopy; -}; - -#endif /* __GTKCAIROPEER_H */ diff --git a/libjava/jni/gtk-peer/gtkpeer.h b/libjava/jni/gtk-peer/gtkpeer.h deleted file mode 100644 index 914de570f85..00000000000 --- a/libjava/jni/gtk-peer/gtkpeer.h +++ /dev/null @@ -1,522 +0,0 @@ -/* gtkpeer.h -- Some global variables and #defines - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include <gtk/gtk.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <config.h> -#include "native_state.h" - -#include <jni.h> - -#define RC_FILE ".classpath-gtkrc" -#define JVM_SUN -/* - #define JVM_JAPHAR -*/ - -#ifndef __GTKPEER_H__ -#define __GTKPEER_H__ - -#ifndef __GNUC__ -#define __attribute__(x) /* nothing */ -#endif - -#ifdef JVM_SUN - -extern struct state_table *native_state_table; -extern struct state_table *native_global_ref_table; - -#define NSA_INIT(env, clazz) \ - do {native_state_table = init_state_table (env, clazz); \ - native_global_ref_table = init_state_table (env, clazz);} while (0) - -#define NSA_GET_PTR(env, obj) \ - get_state (env, obj, native_state_table) - -#define NSA_SET_PTR(env, obj, ptr) \ - set_state (env, obj, native_state_table, (void *)ptr) - -#define NSA_DEL_PTR(env, obj) \ - remove_state_slot (env, obj, native_state_table) - -#define NSA_GET_GLOBAL_REF(env, obj) \ - get_state (env, obj, native_global_ref_table) - -#define NSA_SET_GLOBAL_REF(env, obj) \ - do {jobject *globRefPtr; \ - globRefPtr = (jobject *) malloc (sizeof (jobject)); \ - *globRefPtr = (*env)->NewGlobalRef (env, obj); \ - set_state (env, obj, native_global_ref_table, (void *)globRefPtr);} while (0) - -#define NSA_DEL_GLOBAL_REF(env, obj) \ - do {jobject *globRefPtr = get_state (env, obj, native_global_ref_table); \ - remove_state_slot (env, obj, native_global_ref_table); \ - (*env)->DeleteGlobalRef (env, *globRefPtr); \ - free (globRefPtr);} while (0) - -extern struct state_table *native_pixbufdecoder_state_table; - -#define NSA_PB_INIT(env, clazz) \ - native_pixbufdecoder_state_table = init_state_table (env, clazz) - -#define NSA_GET_PB_PTR(env, obj) \ - get_state (env, obj, native_pixbufdecoder_state_table) - -#define NSA_SET_PB_PTR(env, obj, ptr) \ - set_state (env, obj, native_pixbufdecoder_state_table, (void *)ptr) - -#define NSA_DEL_PB_PTR(env, obj) \ - remove_state_slot (env, obj, native_pixbufdecoder_state_table) - -#endif /* JVM_SUN */ - -#define SWAPU32(w) \ - (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24)) - -struct graphics -{ - GdkDrawable *drawable; - GdkGC *gc; - GdkColormap *cm; - PangoFontDescription *pango_font; - PangoContext *pango_context; - PangoLayout *pango_layout; - jint x_offset, y_offset; -}; - -#define AWT_DEFAULT_CURSOR 0 -#define AWT_CROSSHAIR_CURSOR 1 -#define AWT_TEXT_CURSOR 2 -#define AWT_WAIT_CURSOR 3 -#define AWT_SW_RESIZE_CURSOR 4 -#define AWT_SE_RESIZE_CURSOR 5 -#define AWT_NW_RESIZE_CURSOR 6 -#define AWT_NE_RESIZE_CURSOR 7 -#define AWT_N_RESIZE_CURSOR 8 -#define AWT_S_RESIZE_CURSOR 9 -#define AWT_W_RESIZE_CURSOR 10 -#define AWT_E_RESIZE_CURSOR 11 -#define AWT_HAND_CURSOR 12 -#define AWT_MOVE_CURSOR 13 - -#define SYNTHETIC_EVENT_MASK (1 << 10) - -#define AWT_SHIFT_DOWN_MASK (1 << 6) -#define AWT_CTRL_DOWN_MASK (1 << 7) -#define AWT_META_DOWN_MASK (1 << 8) -#define AWT_ALT_DOWN_MASK (1 << 9) - -#define AWT_BUTTON1_DOWN_MASK (1 << 10) -#define AWT_BUTTON2_DOWN_MASK (1 << 11) -#define AWT_BUTTON3_DOWN_MASK (1 << 12) - -#define AWT_BUTTON1_MASK (1 << 4) -#define AWT_BUTTON2_MASK (1 << 3) -#define AWT_BUTTON3_MASK (1 << 2) - -#define MULTI_CLICK_TIME 250 -/* as opposed to a MULTI_PASS_TIME :) */ - -#define AWT_MOUSE_CLICKED 500 -#define AWT_MOUSE_PRESSED 501 -#define AWT_MOUSE_RELEASED 502 -#define AWT_MOUSE_MOVED 503 -#define AWT_MOUSE_ENTERED 504 -#define AWT_MOUSE_EXITED 505 -#define AWT_MOUSE_DRAGGED 506 - -#define AWT_ADJUSTMENT_UNIT_INCREMENT 1 -#define AWT_ADJUSTMENT_UNIT_DECREMENT 2 -#define AWT_ADJUSTMENT_BLOCK_DECREMENT 3 -#define AWT_ADJUSTMENT_BLOCK_INCREMENT 4 -#define AWT_ADJUSTMENT_TRACK 5 - -#define AWT_SCROLLPANE_SCROLLBARS_AS_NEEDED 0 -#define AWT_SCROLLPANE_SCROLLBARS_ALWAYS 1 -#define AWT_SCROLLPANE_SCROLLBARS_NEVER 2 - -#define AWT_LABEL_LEFT 0 -#define AWT_LABEL_CENTER 1 -#define AWT_LABEL_RIGHT 2 - -#define AWT_TEXTAREA_SCROLLBARS_BOTH 0 -#define AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY 1 -#define AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY 2 - -#define AWT_ITEM_SELECTED 1 -#define AWT_ITEM_DESELECTED 2 - -#define AWT_KEY_TYPED 400 -#define AWT_KEY_PRESSED 401 -#define AWT_KEY_RELEASED 402 - -#define AWT_KEY_CHAR_UNDEFINED 0 - -#define AWT_KEY_LOCATION_UNKNOWN 0 -#define AWT_KEY_LOCATION_STANDARD 1 -#define AWT_KEY_LOCATION_LEFT 2 -#define AWT_KEY_LOCATION_RIGHT 3 -#define AWT_KEY_LOCATION_NUMPAD 4 - -/* Virtual Keys */ -/* This list should be kept in the same order as the VK_ field - declarations in KeyEvent.java. */ -#define VK_ENTER '\n' -#define VK_BACK_SPACE '\b' -#define VK_TAB '\t' -#define VK_CANCEL 3 -#define VK_CLEAR 12 -#define VK_SHIFT 16 -#define VK_CONTROL 17 -#define VK_ALT 18 -#define VK_PAUSE 19 -#define VK_CAPS_LOCK 20 -#define VK_ESCAPE 27 -#define VK_SPACE ' ' -#define VK_PAGE_UP 33 -#define VK_PAGE_DOWN 34 -#define VK_END 35 -#define VK_HOME 36 -#define VK_LEFT 37 -#define VK_UP 38 -#define VK_RIGHT 39 -#define VK_DOWN 40 -#define VK_COMMA ',' -#define VK_MINUS '-' -#define VK_PERIOD '.' -#define VK_SLASH '/' -#define VK_0 '0' -#define VK_1 '1' -#define VK_2 '2' -#define VK_3 '3' -#define VK_4 '4' -#define VK_5 '5' -#define VK_6 '6' -#define VK_7 '7' -#define VK_8 '8' -#define VK_9 '9' -#define VK_SEMICOLON ';' -#define VK_EQUALS '=' -#define VK_A 'A' -#define VK_B 'B' -#define VK_C 'C' -#define VK_D 'D' -#define VK_E 'E' -#define VK_F 'F' -#define VK_G 'G' -#define VK_H 'H' -#define VK_I 'I' -#define VK_J 'J' -#define VK_K 'K' -#define VK_L 'L' -#define VK_M 'M' -#define VK_N 'N' -#define VK_O 'O' -#define VK_P 'P' -#define VK_Q 'Q' -#define VK_R 'R' -#define VK_S 'S' -#define VK_T 'T' -#define VK_U 'U' -#define VK_V 'V' -#define VK_W 'W' -#define VK_X 'X' -#define VK_Y 'Y' -#define VK_Z 'Z' -#define VK_OPEN_BRACKET '[' -#define VK_BACK_SLASH '\\' -#define VK_CLOSE_BRACKET ']' -#define VK_NUMPAD0 96 -#define VK_NUMPAD1 97 -#define VK_NUMPAD2 98 -#define VK_NUMPAD3 99 -#define VK_NUMPAD4 100 -#define VK_NUMPAD5 101 -#define VK_NUMPAD6 102 -#define VK_NUMPAD7 103 -#define VK_NUMPAD8 104 -#define VK_NUMPAD9 105 -#define VK_MULTIPLY 106 -#define VK_ADD 107 -#define VK_SEPARATER 108 -#define VK_SEPARATOR 108 -#define VK_SUBTRACT 109 -#define VK_DECIMAL 110 -#define VK_DIVIDE 111 -#define VK_DELETE 127 -#define VK_NUM_LOCK 144 -#define VK_SCROLL_LOCK 145 -#define VK_F1 112 -#define VK_F2 113 -#define VK_F3 114 -#define VK_F4 115 -#define VK_F5 116 -#define VK_F6 117 -#define VK_F7 118 -#define VK_F8 119 -#define VK_F9 120 -#define VK_F10 121 -#define VK_F11 122 -#define VK_F12 123 -#define VK_F13 61440 -#define VK_F14 61441 -#define VK_F15 61442 -#define VK_F16 61443 -#define VK_F17 61444 -#define VK_F18 61445 -#define VK_F19 61446 -#define VK_F20 61447 -#define VK_F21 61448 -#define VK_F22 61449 -#define VK_F23 61450 -#define VK_F24 61451 -#define VK_PRINTSCREEN 154 -#define VK_INSERT 155 -#define VK_HELP 156 -#define VK_META 157 -#define VK_BACK_QUOTE 192 -#define VK_QUOTE 222 -#define VK_KP_UP 224 -#define VK_KP_DOWN 225 -#define VK_KP_LEFT 226 -#define VK_KP_RIGHT 227 -#define VK_DEAD_GRAVE 128 -#define VK_DEAD_ACUTE 129 -#define VK_DEAD_CIRCUMFLEX 130 -#define VK_DEAD_TILDE 131 -#define VK_DEAD_MACRON 132 -#define VK_DEAD_BREVE 133 -#define VK_DEAD_ABOVEDOT 134 -#define VK_DEAD_DIAERESIS 135 -#define VK_DEAD_ABOVERING 136 -#define VK_DEAD_DOUBLEACUTE 137 -#define VK_DEAD_CARON 138 -#define VK_DEAD_CEDILLA 139 -#define VK_DEAD_OGONEK 140 -#define VK_DEAD_IOTA 141 -#define VK_DEAD_VOICED_SOUND 142 -#define VK_DEAD_SEMIVOICED_SOUND 143 -#define VK_AMPERSAND 150 -#define VK_ASTERISK 151 -#define VK_QUOTEDBL 152 -#define VK_LESS 153 -#define VK_GREATER 160 -#define VK_BRACELEFT 161 -#define VK_BRACERIGHT 162 -#define VK_AT 512 -#define VK_COLON 513 -#define VK_CIRCUMFLEX 514 -#define VK_DOLLAR 515 -#define VK_EURO_SIGN 516 -#define VK_EXCLAMATION_MARK 517 -#define VK_INVERTED_EXCLAMATION_MARK 518 -#define VK_LEFT_PARENTHESIS 519 -#define VK_NUMBER_SIGN 520 -#define VK_PLUS 521 -#define VK_RIGHT_PARENTHESIS 522 -#define VK_UNDERSCORE 523 -#define VK_FINAL 24 -#define VK_CONVERT 28 -#define VK_NONCONVERT 29 -#define VK_ACCEPT 30 -#define VK_MODECHANGE 31 -#define VK_KANA 21 -#define VK_KANJI 25 -#define VK_ALPHANUMERIC 240 -#define VK_KATAKANA 241 -#define VK_HIRAGANA 242 -#define VK_FULL_WIDTH 243 -#define VK_HALF_WIDTH 244 -#define VK_ROMAN_CHARACTERS 245 -#define VK_ALL_CANDIDATES 256 -#define VK_PREVIOUS_CANDIDATE 257 -#define VK_CODE_INPUT 258 -#define VK_JAPANESE_KATAKANA 259 -#define VK_JAPANESE_HIRAGANA 260 -#define VK_JAPANESE_ROMAN 261 -#define VK_KANA_LOCK 262 -#define VK_INPUT_METHOD_ON_OFF 263 -#define VK_CUT 65489 -#define VK_COPY 65485 -#define VK_PASTE 65487 -#define VK_UNDO 65483 -#define VK_AGAIN 65481 -#define VK_FIND 65488 -#define VK_PROPS 65482 -#define VK_STOP 65480 -#define VK_COMPOSE 65312 -#define VK_ALT_GRAPH 65406 -#define VK_UNDEFINED 0 - -#define AWT_FOCUS_GAINED 1004 -#define AWT_FOCUS_LOST 1005 - -#define AWT_WINDOW_OPENED 200 -#define AWT_WINDOW_CLOSING 201 -#define AWT_WINDOW_CLOSED 202 -#define AWT_WINDOW_ICONIFIED 203 -#define AWT_WINDOW_DEICONIFIED 204 -#define AWT_WINDOW_ACTIVATED 205 -#define AWT_WINDOW_DEACTIVATED 206 -#define AWT_WINDOW_GAINED_FOCUS 207 -#define AWT_WINDOW_LOST_FOCUS 208 -#define AWT_WINDOW_STATE_CHANGED 209 - -#define AWT_FRAME_STATE_NORMAL 0 -#define AWT_FRAME_STATE_ICONIFIED 1 -#define AWT_FRAME_STATE_MAXIMIZED_HORIZ 2 -#define AWT_FRAME_STATE_MAXIMIZED_VERT 4 -#define AWT_FRAME_STATE_MAXIMIZED_BOTH 6 - -#define AWT_STYLE_PLAIN 0 -#define AWT_STYLE_BOLD 1 -#define AWT_STYLE_ITALIC 2 - -/* From java.awt.SystemColor */ -#define AWT_DESKTOP 0 -#define AWT_ACTIVE_CAPTION 1 -#define AWT_ACTIVE_CAPTION_TEXT 2 -#define AWT_ACTIVE_CAPTION_BORDER 3 -#define AWT_INACTIVE_CAPTION 4 -#define AWT_INACTIVE_CAPTION_TEXT 5 -#define AWT_INACTIVE_CAPTION_BORDER 6 -#define AWT_WINDOW 7 -#define AWT_WINDOW_BORDER 8 -#define AWT_WINDOW_TEXT 9 -#define AWT_MENU 10 -#define AWT_MENU_TEXT 11 -#define AWT_TEXT 12 -#define AWT_TEXT_TEXT 13 -#define AWT_TEXT_HIGHLIGHT 14 -#define AWT_TEXT_HIGHLIGHT_TEXT 15 -#define AWT_TEXT_INACTIVE_TEXT 16 -#define AWT_CONTROL 17 -#define AWT_CONTROL_TEXT 18 -#define AWT_CONTROL_HIGHLIGHT 19 -#define AWT_CONTROL_LT_HIGHLIGHT 20 -#define AWT_CONTROL_SHADOW 21 -#define AWT_CONTROL_DK_SHADOW 22 -#define AWT_SCROLLBAR 23 -#define AWT_INFO 24 -#define AWT_INFO_TEXT 25 -#define AWT_NUM_COLORS 26 - -extern jmethodID setBoundsCallbackID; - -extern jmethodID postActionEventID; -extern jmethodID postMenuActionEventID; -extern jmethodID postMouseEventID; -extern jmethodID postConfigureEventID; -extern jmethodID postExposeEventID; -extern jmethodID postKeyEventID; -extern jmethodID postFocusEventID; -extern jmethodID postAdjustmentEventID; -extern jmethodID choicePostItemEventID; -extern jmethodID postItemEventID; -extern jmethodID postListItemEventID; -extern jmethodID postTextEventID; -extern jmethodID postWindowEventID; - -extern jmethodID beginNativeRepaintID; -extern jmethodID endNativeRepaintID; - -extern jmethodID initComponentGraphicsID; -extern jmethodID initComponentGraphics2DID; -extern jmethodID setCursorID; - -extern jmethodID syncAttrsID; -extern jclass gdkColor; -extern jmethodID gdkColorID; - -extern jmethodID postInsetsChangedEventID; -extern jmethodID windowGetWidthID; -extern jmethodID windowGetHeightID; - -JNIEnv *gdk_env(void); - -extern double dpi_conversion_factor; - -extern GtkWindowGroup *global_gtk_window_group; - -void awt_event_handler (GdkEvent *event); - -gboolean pre_event_handler (GtkWidget *widget, - GdkEvent *event, - jobject peer); - -void connect_awt_hook (JNIEnv *env, jobject peer_obj, int nwindows, ...); -void connect_awt_hook_cb (GtkWidget *widget, jobject peer); - -void set_visible (GtkWidget *widget, jboolean visible); -void set_parent (GtkWidget *widget, GtkContainer *parent); - -jint keyevent_state_to_awt_mods (GdkEvent *event); - -guint awt_keycode_to_keysym (jint keyCode, jint keyLocation); - -struct item_event_hook_info -{ - jobject peer_obj; - const char *label; -}; - -/* Union used for type punning. */ -union widget_union -{ - void **void_widget; - GtkWidget **widget; -}; - -#define DEBUG_LOCKING 0 - -#if DEBUG_LOCKING -#define gdk_threads_enter() \ -{ \ - g_print ("lock: %s, %d\n", __FILE__, __LINE__); \ - gdk_threads_enter (); \ -} -#define gdk_threads_leave() \ -{ \ - g_print ("unlock: %s, %d\n", __FILE__, __LINE__); \ - gdk_threads_leave (); \ -} -#endif - -#endif /* __GTKPEER_H */ |