diff options
| author | Dan Albert <danalbert@google.com> | 2016-01-14 16:43:34 -0800 |
|---|---|---|
| committer | Dan Albert <danalbert@google.com> | 2016-01-22 14:51:24 -0800 |
| commit | 3186be22b6598fbd467b126347d1c7f48ccb7f71 (patch) | |
| tree | 2b176d3ce027fa5340160978effeb88ec9054aaa /gcc-4.8.1/libjava/classpath/native/jni/gtk-peer | |
| parent | a45222a0e5951558bd896b0513bf638eb376e086 (diff) | |
| download | toolchain_gcc-3186be22b6598fbd467b126347d1c7f48ccb7f71.tar.gz toolchain_gcc-3186be22b6598fbd467b126347d1c7f48ccb7f71.tar.bz2 toolchain_gcc-3186be22b6598fbd467b126347d1c7f48ccb7f71.zip | |
Check in a pristine copy of GCC 4.8.1.
The copy of GCC that we use for Android is still not working for
mingw. Rather than finding all the differences that have crept into
our GCC, just check in a copy from
ftp://ftp.gnu.org/gnu/gcc/gcc-4.9.3/gcc-4.8.1.tar.bz2.
GCC 4.8.1 was chosen because it is what we have been using for mingw
thus far, and the emulator doesn't yet work when upgrading to 4.9.
Bug: http://b/26523949
Change-Id: Iedc0f05243d4332cc27ccd46b8a4b203c88dcaa3
Diffstat (limited to 'gcc-4.8.1/libjava/classpath/native/jni/gtk-peer')
48 files changed, 16864 insertions, 0 deletions
diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/.cvsignore b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c new file mode 100644 index 000000000..b8f1ba5b2 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c @@ -0,0 +1,325 @@ +/* gtkdragsourcecontextpeer.c -- Native implementation of GtkDragSourceContextPeer + Copyright (C) 2006 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_dnd_peer_gtk_GtkDragSourceContextPeer.h" + +#include <jni.h> +#include <gtk/gtk.h> + +static GtkWidget * get_widget (GtkWidget *widget); +static void connect_signals_for_widget (GtkWidget *widget); + +#define ACTION_COPY 1 +#define ACTION_MOVE 2 +#define ACTION_COPY_OR_MOVE 3 +#define ACTION_LINK 1073741824 + +#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 + +static jmethodID dragEnterID; +static jmethodID dragExitID; +static jmethodID dragDropEndID; +static jmethodID dragMouseMovedID; +static jmethodID dragOverID; +static jmethodID dragActionChangedID; +static jmethodID acceptDragID; +static jmethodID rejectDragID; +static jmethodID acceptDropID; +static jmethodID rejectDropID; +static jmethodID dropCompleteID; + +GtkWidget *widget; +GtkWidget *tgt; +jobject gref; +jobject javaObj; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create + (JNIEnv *env, jobject obj, jobject comp) +{ + gdk_threads_enter (); + + javaObj = obj; + gtkpeer_set_global_ref (env, obj); + gtkpeer_set_global_ref (env, comp); + + gref = gtkpeer_get_widget (env, comp); + widget = get_widget (GTK_WIDGET (gref)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeSetCursor + (JNIEnv *env __attribute__((unused)), jobject obj, jint type) +{ + GdkWindow *win; + GdkCursorType gdk_cursor_type; + GdkCursor *gdk_cursor; + + gdk_threads_enter (); + + javaObj = 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; + } + + win = widget->window; + if ((widget->window) == NULL) + win = widget->window; + + gdk_cursor = gdk_cursor_new (gdk_cursor_type); + + gdk_window_set_cursor (win, gdk_cursor); + gdk_cursor_unref (gdk_cursor); + + gdk_flush(); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_connectSignals + (JNIEnv *env, jobject obj, jobject comp) +{ + jclass gtkdragsourcecontextpeer; + jclass gtkdroptargetcontextpeer; + + gdk_threads_enter (); + + javaObj = obj; + gref = gtkpeer_get_global_ref (env, comp); + + connect_signals_for_widget (widget); + + gtkdragsourcecontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer"); + + dragEnterID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragEnter", "(II)V"); + dragExitID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragExit", "(III)V"); + dragDropEndID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragDropEnd", "(IZII)V"); + dragMouseMovedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragMouseMoved", "(II)V"); + dragOverID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragOver", "(II)V"); + dragActionChangedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragActionChanged", "(II)V"); + + + gtkdroptargetcontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer"); + + acceptDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "acceptDrag", "(I)V"); + rejectDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "rejectDrag", "()V"); + acceptDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "acceptDrop", "(I)V"); + rejectDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "rejectDrop", "()V"); + dropCompleteID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "dropComplete", "(Z)V"); + + gdk_threads_leave (); +} + +static void +connect_signals_for_widget (GtkWidget *w __attribute__((unused))) +{ + /* FIXME: Not implemented. */ +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_setTarget + (JNIEnv *env, jobject obj, jobject target) +{ + void *ptr; + + gdk_threads_enter (); + + javaObj = obj; + ptr = gtkpeer_get_widget (env, target); + tgt = get_widget (GTK_WIDGET (ptr)); + connect_signals_for_widget (tgt); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeStartDrag + (JNIEnv *env, jobject obj, jobject img, jint x, jint y, jint act, + jstring target) +{ + const gchar *data; + GtkTargetEntry tar[1]; + GdkEvent *event; + GdkPixbuf *image = NULL; + GdkDragContext *context = NULL; + GdkDragAction action = GDK_ACTION_DEFAULT; + + gdk_threads_enter (); + + javaObj = obj; + + data = (*env)->GetStringUTFChars (env, target, NULL); + tar[0].target = (gchar *) data; + event = gdk_event_new (GDK_ALL_EVENTS_MASK); + + switch (act) + { + case ACTION_COPY: + action = GDK_ACTION_COPY; + break; + case ACTION_MOVE: + action = GDK_ACTION_MOVE; + break; + case ACTION_COPY_OR_MOVE: + action = GDK_ACTION_COPY | GDK_ACTION_MOVE; + break; + case ACTION_LINK: + action = GDK_ACTION_LINK; + break; + default: + action = GDK_ACTION_DEFAULT; + } + + gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, tar, + sizeof (tar) / sizeof (GtkTargetEntry), + action); + context = gtk_drag_begin (widget, + gtk_target_list_new (tar, sizeof (tar) / sizeof (GtkTargetEntry)), + action, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, event); + + if (img != NULL) + { + image = cp_gtk_image_get_pixbuf (env, img); + gtk_drag_set_icon_pixbuf (context, image, x, y); + } + + if (tgt != NULL) + gtk_drag_dest_set (tgt, GTK_DEST_DEFAULT_ALL, tar, + sizeof (tar) / sizeof (GtkTargetEntry), + action); + + gdk_event_free (event); + (*env)->ReleaseStringUTFChars (env, target, data); + + gdk_threads_leave (); +} + +static GtkWidget * +get_widget (GtkWidget *widget) +{ + GtkWidget *w; + + if (GTK_IS_EVENT_BOX (widget) || GTK_IS_CONTAINER (widget)) + w = gtk_bin_get_child (GTK_BIN(widget)); + else + w = widget; + + return w; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.am b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.am new file mode 100644 index 000000000..6ab32636b --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.am @@ -0,0 +1,61 @@ +nativeexeclib_LTLIBRARIES = libgtkpeer.la + +# GTK JNI sources. +libgtkpeer_la_SOURCES = gnu_java_awt_peer_gtk_CairoSurface.c \ + gnu_java_awt_peer_gtk_CairoGraphics2D.c \ + gnu_java_awt_peer_gtk_ComponentGraphics.c \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.c \ + gnu_java_awt_peer_gtk_GdkFontPeer.c \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.c \ + gnu_java_awt_peer_gtk_GdkRobotPeer.c \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c \ + gnu_java_awt_peer_gtk_GtkButtonPeer.c \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.c \ + gnu_java_awt_peer_gtk_GtkChoicePeer.c \ + gnu_java_awt_peer_gtk_GtkClipboard.c \ + gnu_java_awt_peer_gtk_GtkComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.c \ + gnu_java_awt_peer_gtk_GtkFramePeer.c \ + gnu_java_awt_peer_gtk_GtkGenericPeer.c \ + gnu_java_awt_peer_gtk_GtkImage.c \ + gnu_java_awt_peer_gtk_GtkLabelPeer.c \ + gnu_java_awt_peer_gtk_GtkListPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkPanelPeer.c \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.c \ + gnu_java_awt_peer_gtk_GtkSelection.c \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.c \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.c \ + gnu_java_awt_peer_gtk_GtkToolkit.c \ + gnu_java_awt_peer_gtk_GtkWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkVolatileImage.c \ + GtkDragSourceContextPeer.c \ + cairographics2d.h \ + gdkdisplay.h \ + gdkfont.h \ + gtk_jawt.c \ + gtkpeer.c \ + gtkpeer.h + +libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgtkpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @FREETYPE2_LIBS@ \ + @PANGOFT2_LIBS@ @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @XTEST_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @FREETYPE2_CFLAGS@ @PANGOFT2_CFLAGS@ \ + @X_CFLAGS@ @EXTRA_CFLAGS@ diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.in b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.in new file mode 100644 index 000000000..4ca363c7e --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/Makefile.in @@ -0,0 +1,743 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/gtk-peer +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgtkpeer_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libgtkpeer_la_OBJECTS = gnu_java_awt_peer_gtk_CairoSurface.lo \ + gnu_java_awt_peer_gtk_CairoGraphics2D.lo \ + gnu_java_awt_peer_gtk_ComponentGraphics.lo \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.lo \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.lo \ + gnu_java_awt_peer_gtk_GdkFontPeer.lo \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.lo \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.lo \ + gnu_java_awt_peer_gtk_GdkRobotPeer.lo \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.lo \ + gnu_java_awt_peer_gtk_GtkButtonPeer.lo \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.lo \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.lo \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.lo \ + gnu_java_awt_peer_gtk_GtkChoicePeer.lo \ + gnu_java_awt_peer_gtk_GtkClipboard.lo \ + gnu_java_awt_peer_gtk_GtkComponentPeer.lo \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.lo \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.lo \ + gnu_java_awt_peer_gtk_GtkFramePeer.lo \ + gnu_java_awt_peer_gtk_GtkGenericPeer.lo \ + gnu_java_awt_peer_gtk_GtkImage.lo \ + gnu_java_awt_peer_gtk_GtkLabelPeer.lo \ + gnu_java_awt_peer_gtk_GtkListPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuPeer.lo \ + gnu_java_awt_peer_gtk_GtkPanelPeer.lo \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.lo \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.lo \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.lo \ + gnu_java_awt_peer_gtk_GtkSelection.lo \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.lo \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.lo \ + gnu_java_awt_peer_gtk_GtkToolkit.lo \ + gnu_java_awt_peer_gtk_GtkWindowPeer.lo \ + gnu_java_awt_peer_gtk_GtkVolatileImage.lo \ + GtkDragSourceContextPeer.lo gtk_jawt.lo gtkpeer.lo +libgtkpeer_la_OBJECTS = $(am_libgtkpeer_la_OBJECTS) +libgtkpeer_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgtkpeer_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgtkpeer_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOC4 = @MOC4@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgtkpeer.la + +# GTK JNI sources. +libgtkpeer_la_SOURCES = gnu_java_awt_peer_gtk_CairoSurface.c \ + gnu_java_awt_peer_gtk_CairoGraphics2D.c \ + gnu_java_awt_peer_gtk_ComponentGraphics.c \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.c \ + gnu_java_awt_peer_gtk_GdkFontPeer.c \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.c \ + gnu_java_awt_peer_gtk_GdkRobotPeer.c \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c \ + gnu_java_awt_peer_gtk_GtkButtonPeer.c \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.c \ + gnu_java_awt_peer_gtk_GtkChoicePeer.c \ + gnu_java_awt_peer_gtk_GtkClipboard.c \ + gnu_java_awt_peer_gtk_GtkComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.c \ + gnu_java_awt_peer_gtk_GtkFramePeer.c \ + gnu_java_awt_peer_gtk_GtkGenericPeer.c \ + gnu_java_awt_peer_gtk_GtkImage.c \ + gnu_java_awt_peer_gtk_GtkLabelPeer.c \ + gnu_java_awt_peer_gtk_GtkListPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkPanelPeer.c \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.c \ + gnu_java_awt_peer_gtk_GtkSelection.c \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.c \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.c \ + gnu_java_awt_peer_gtk_GtkToolkit.c \ + gnu_java_awt_peer_gtk_GtkWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkVolatileImage.c \ + GtkDragSourceContextPeer.c \ + cairographics2d.h \ + gdkdisplay.h \ + gdkfont.h \ + gtk_jawt.c \ + gtkpeer.c \ + gtkpeer.h + +libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgtkpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @FREETYPE2_LIBS@ \ + @PANGOFT2_LIBS@ @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @XTEST_LIBS@ + +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @FREETYPE2_CFLAGS@ @PANGOFT2_CFLAGS@ \ + @X_CFLAGS@ @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/gtk-peer/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/gtk-peer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgtkpeer.la: $(libgtkpeer_la_OBJECTS) $(libgtkpeer_la_DEPENDENCIES) + $(libgtkpeer_la_LINK) -rpath $(nativeexeclibdir) $(libgtkpeer_la_OBJECTS) $(libgtkpeer_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GtkDragSourceContextPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_CairoGraphics2D.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_CairoSurface.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_ComponentGraphics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_FreetypeGlyphVector.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkFontPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkPixbufDecoder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkRobotPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkButtonPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCanvasPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCheckboxPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkChoicePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkClipboard.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkComponentPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkFileDialogPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkFramePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkGenericPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkImage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkLabelPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkListPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuBarPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuItemPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkPanelPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkScrollPanePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkScrollbarPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkSelection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkTextAreaPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkTextFieldPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkToolkit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkVolatileImage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkWindowPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtk_jawt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtkpeer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/cairographics2d.h b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/cairographics2d.h new file mode 100644 index 000000000..d5611bff6 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/cairographics2d.h @@ -0,0 +1,116 @@ +/* cairographics2d.h -- + Copyright (C) 2006 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 CAIROGRAPHICS2D_H +#define CAIROGRAPHICS2D_H + + +#include <cairo.h> +#include <gtk/gtk.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <config.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + +#include <jni.h> + +/* + * 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. + */ +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, + java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC = 5 + + }; + +/** + * A structure which basically contains the cairo_t pointer. + * The rest is for gradient and texture fills. + */ +struct cairographics2d +{ + cairo_t *cr; + cairo_surface_t *pattern_surface; + cairo_pattern_t *pattern; + char *pattern_pixels; +}; + +#endif diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h new file mode 100644 index 000000000..e15f08e69 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h @@ -0,0 +1,43 @@ +#ifndef __GDKDISPLAY_H__ +#define __GDKDISPLAY_H__ + +/* gdkdisplay.h -- Some global stuff related to displays & screens + Copyright (C) 2006 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" + +#endif /* __GDKDISPLAY_H__ */ diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkfont.h b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkfont.h new file mode 100644 index 000000000..241a05f7d --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gdkfont.h @@ -0,0 +1,105 @@ +#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" + +#define PANGO_ENABLE_ENGINE +#include <pango/pango.h> +#include <pango/pango-context.h> +#include <pango/pango-fontmap.h> +#include <pango/pangoft2.h> + +#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 FONT_METRICS_HEIGHT 5 +#define FONT_METRICS_UNDERLINE_OFFSET 6 +#define FONT_METRICS_UNDERLINE_THICKNESS 7 +#define NUM_FONT_METRICS 8 + +#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; + PangoFontset *set; + 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/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c new file mode 100644 index 000000000..58f003e86 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c @@ -0,0 +1,749 @@ +/* gnu_java_awt_peer_gtk_CairoGraphics2d.c + Copyright (C) 2006, 2008 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 "jcl.h" +#include "gdkfont.h" +#include "cairographics2d.h" +#include "gnu_java_awt_peer_gtk_CairoGraphics2D.h" +#include <gdk/gdktypes.h> +#include <gdk/gdkprivate.h> + +#include <cairo-ft.h> + +#include <stdio.h> +#include <stdlib.h> + +static void update_pattern_transform (struct cairographics2d *gr); + +/** + * Allocates the cairographics2d structure. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_init + (JNIEnv *env __attribute__ ((unused)), + jobject obj __attribute__ ((unused)), + jlong cairo_t_pointer) +{ + struct cairographics2d *g = NULL; + cairo_t *cr = JLONG_TO_PTR(cairo_t, cairo_t_pointer); + g_assert(cr != NULL); + + g = (struct cairographics2d *) g_malloc (sizeof (struct cairographics2d)); + + g_assert (g != NULL); + memset (g, 0, sizeof(struct cairographics2d)); + g->cr = cr; + + return PTR_TO_JLONG(g); +} + +/** + * Disposes of the cairographics2d structure. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_disposeNative + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + if (gr == NULL) + return; + + if (gr->cr) + { + gdk_threads_enter(); + cairo_destroy (gr->cr); + gdk_threads_leave(); + } + + if (gr->pattern) + cairo_pattern_destroy (gr->pattern); + gr->pattern = NULL; + + if (gr->pattern_surface) + cairo_surface_destroy (gr->pattern_surface); + gr->pattern_surface = NULL; + + if (gr->pattern_pixels) + g_free(gr->pattern_pixels); + gr->pattern_pixels = NULL; + + g_free( gr ); +} + +/** + * Set the gradient. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setGradient + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, + 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 cairographics2d *gr = NULL; + cairo_pattern_t* pattern; + cairo_extend_t extend; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert( gr != NULL ); + + pattern = cairo_pattern_create_linear(x1, y1, x2, y2); + g_assert( pattern != NULL ); + + cairo_pattern_add_color_stop_rgba(pattern, 0.0, r1 / 255.0, g1 / 255.0, + b1 / 255.0, a1 / 255.0); + + cairo_pattern_add_color_stop_rgba(pattern, 1.0, r2 / 255.0, g2 / 255.0, + b2 / 255.0, a2 / 255.0); + + #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0) + extend = (cyclic == JNI_TRUE) ? CAIRO_EXTEND_REFLECT : CAIRO_EXTEND_PAD; + #else + extend = (cyclic == JNI_TRUE) ? CAIRO_EXTEND_REFLECT : CAIRO_EXTEND_NONE; + #endif + + cairo_pattern_set_extend( pattern, extend ); + + gr->pattern = pattern; + cairo_set_source(gr->cr, gr->pattern); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setPaintPixels + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jintArray jarr, jint w, jint h, jint stride, jboolean repeat, + jint x, jint y) +{ + struct cairographics2d *gr = NULL; + jint *jpixels = NULL; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (gr->pattern) + cairo_pattern_destroy (gr->pattern); + + if (gr->pattern_surface) + cairo_surface_destroy (gr->pattern_surface); + + if (gr->pattern_pixels) + g_free (gr->pattern_pixels); + + gr->pattern = NULL; + gr->pattern_surface = NULL; + gr->pattern_pixels = NULL; + + gr->pattern_pixels = (char *) g_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_image_surface_create_for_data ((unsigned char *)gr->pattern_pixels, + CAIRO_FORMAT_ARGB32, + w, h, stride * 4); + g_assert (gr->pattern_surface != NULL); + gr->pattern = cairo_pattern_create_for_surface (gr->pattern_surface); + g_assert (gr->pattern != NULL); + + cairo_set_source_surface(gr->cr, gr->pattern_surface, x, y); + + if (repeat) + cairo_pattern_set_extend(cairo_get_source(gr->cr), CAIRO_EXTEND_REPEAT); + else + cairo_pattern_set_extend(cairo_get_source(gr->cr), CAIRO_EXTEND_NONE); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_drawPixels +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jintArray java_pixels, + jint w, jint h, jint stride, jdoubleArray java_matrix, jdouble alpha, + jint interpolation) +{ + jint *native_pixels = NULL; + jdouble *native_matrix = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + 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); + + { + cairo_matrix_t mat; + cairo_pattern_t *p; + cairo_surface_t *surf = cairo_image_surface_create_for_data ((unsigned char *)native_pixels, + CAIRO_FORMAT_ARGB32, + w, h, stride * 4); + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + + p = cairo_pattern_create_for_surface (surf); + cairo_pattern_set_matrix (p, &mat); + switch ((enum java_awt_rendering_hints_filter) interpolation) + { + case java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR: + cairo_pattern_set_filter (p, CAIRO_FILTER_BILINEAR); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC: + cairo_pattern_set_filter (p, CAIRO_FILTER_GAUSSIAN); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED: + cairo_pattern_set_filter (p, CAIRO_FILTER_FAST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY: + cairo_pattern_set_filter (p, CAIRO_FILTER_BEST); + break; + } + + cairo_set_source (gr->cr, p); + if (alpha == 1.) + cairo_paint (gr->cr); + else + cairo_paint_with_alpha(gr->cr, alpha); + + cairo_pattern_destroy (p); + cairo_surface_destroy (surf); + } + + (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0); + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetMatrix +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdoubleArray java_matrix) +{ + jdouble *native_matrix = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); + g_assert (native_matrix != NULL); + g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); + + { + cairo_matrix_t mat; + + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + g_assert (gr != NULL); + cairo_set_matrix (gr->cr, &mat); + } + + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); + update_pattern_transform (gr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoScale +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_scale (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector +(JNIEnv *env, jobject obj __attribute__((unused)), jlong pointer, + jobject font, + jfloat x, jfloat y, jint n, + jintArray java_codes, + jfloatArray java_positions, jlongArray java_fontset) +{ + struct cairographics2d *gr = NULL; + struct peerfont *pfont = NULL; + cairo_glyph_t *glyphs = NULL; + int *native_codes; + float *native_positions; + jint i = 0; + + g_assert (java_codes != NULL); + g_assert (java_positions != NULL); + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, font); + g_assert (pfont != NULL); + + glyphs = g_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); + + /* Set up glyphs and layout */ + 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); + + /* Iterate through glyphs and draw */ + jlong* fonts = (*env)->GetLongArrayElements (env, java_fontset, NULL); + gdk_threads_enter(); + for (i = 0; i < n; i++) + { + PangoFcFont *font = JLONG_TO_PTR(PangoFcFont, fonts[i]); + + /* Draw as many glyphs as possible with the current font */ + int length = 0; + while (i < n-1 && fonts[i] == fonts[i+1]) + { + length++; + i++; + } + + FT_Face face = pango_fc_font_lock_face( font ); + cairo_font_face_t *ft = cairo_ft_font_face_create_for_ft_face (face, 0); + g_assert (ft != NULL); + + cairo_set_font_face (gr->cr, ft); + cairo_show_glyphs (gr->cr, &glyphs[i-length], length+1); + + cairo_font_face_destroy (ft); + pango_fc_font_unlock_face(font); + } + gdk_threads_leave(); + + (*env)->ReleaseLongArrayElements (env, java_fontset, fonts, 0); + g_free(glyphs); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetFont +(JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong pointer, jobject font) +{ + struct cairographics2d *gr = NULL; + struct peerfont *pfont = NULL; + FT_Face face = NULL; + cairo_font_face_t *ft = NULL; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, font); + g_assert (pfont != NULL); + + gdk_threads_enter(); + face = pango_fc_font_lock_face( (PangoFcFont *)pfont->font ); + g_assert (face != NULL); + + ft = cairo_ft_font_face_create_for_ft_face (face, 0); + g_assert (ft != NULL); + + cairo_set_font_face (gr->cr, ft); + cairo_set_font_size (gr->cr, + (pango_font_description_get_size (pfont->desc) / + (double)PANGO_SCALE)); + + cairo_font_face_destroy (ft); + pango_fc_font_unlock_face((PangoFcFont *)pfont->font); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetOperator +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint op) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + 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_SOURCE); + 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_DEST_OVER); + 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_DEST_IN); + 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_DEST_OUT); + break; + + case java_awt_alpha_composite_DST: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST); + 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_DEST_ATOP); + break; + + case java_awt_alpha_composite_XOR: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_XOR); + break; + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetRGBAColor +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble r, jdouble g, jdouble b, jdouble a) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_set_source_rgba (gr->cr, r, g, b, a); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetFillRule +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint rule) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + 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; + } +} + +/** + * Set the line style, except for dashes. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetLine +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble width, jint cap, jint join, jdouble miterLimit) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + /* set width */ + cairo_set_line_width (gr->cr, width); + + /* set 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; + } + + /* set 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; + } + + /* set miter */ + cairo_set_miter_limit (gr->cr, miterLimit); +} + +/** + * Set the line dashes + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetDash +(JNIEnv *env, jobject obj __attribute__((unused)), + jlong pointer, jdoubleArray dashes, jint ndash, jdouble offset) +{ + jdouble *dasharr = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + dasharr = (*env)->GetDoubleArrayElements (env, dashes, NULL); + g_assert (dasharr != NULL); + + cairo_set_dash (gr->cr, dasharr, ndash, offset); + + (*env)->ReleaseDoubleArrayElements (env, dashes, dasharr, 0); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSave +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_save (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRestore +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_restore (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoNewPath +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_new_path (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoMoveTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_move_to (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoLineTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_line_to (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoCurveTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x1, jdouble y1, + jdouble x2, jdouble y2, jdouble x3, jdouble y3) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + cairo_curve_to (gr->cr, x1, y1, x2, y2, x3, y3); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRectangle +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y, jdouble width, jdouble height) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + cairo_rectangle (gr->cr, x, y, width, height); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoArc +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y, jdouble radius, jdouble angle1, + jdouble angle2) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + cairo_arc (gr->cr, x, y, radius, angle1, angle2); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClosePath +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_close_path (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoStroke +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_stroke (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble alpha) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (alpha == 1.0) + cairo_fill (gr->cr); + else + { + cairo_save(gr->cr); + cairo_clip(gr->cr); + cairo_paint_with_alpha(gr->cr, alpha); + cairo_restore(gr->cr); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert( gr != NULL ); + + cairo_clip( gr->cr ); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoResetClip +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_reset_clip( gr->cr ); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetAntialias +(JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong pointer, jboolean aa) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (aa) + cairo_set_antialias(gr->cr, CAIRO_ANTIALIAS_GRAY); + else + cairo_set_antialias(gr->cr, CAIRO_ANTIALIAS_NONE); +} + +static void +update_pattern_transform (struct cairographics2d *gr) +{ + cairo_matrix_t mat; + + g_assert (gr != NULL); + if (gr->pattern == NULL) + return; + + cairo_get_matrix (gr->cr, &mat); + cairo_pattern_set_matrix (gr->pattern, &mat); +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c new file mode 100644 index 000000000..23340fb5b --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c @@ -0,0 +1,333 @@ +/* gnu_java_awt_peer_gtk_CairoSurface.c + Copyright (C) 2006 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 "jcl.h" +#include "gtkpeer.h" + +#include "gnu_java_awt_peer_gtk_CairoSurface.h" +#include "cairographics2d.h" + +/** + * Field names in CairoSurface.java + */ +#define SURFACE "surfacePointer" +#define SHARED "sharedBuffer" + +/* prototypes */ +static void setNativeObject( JNIEnv *env, jobject obj, void *ptr, const char *pointer ); + +/** + * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_create +(JNIEnv *env, jobject obj, jint width, jint height, jint stride, + jintArray buf ) +{ + cairo_surface_t* surface; + jboolean isCopy; + + /* Retrieve java-created data array */ + void *data = (*env)->GetIntArrayElements (env, buf, &isCopy); + + /* Set sharedBuffer variable */ + jclass cls = (*env)->GetObjectClass (env, obj); + jfieldID field = (*env)->GetFieldID (env, cls, SHARED, "Z"); + g_assert (field != 0); + + if (isCopy == JNI_TRUE) + { + (*env)->SetBooleanField (env, obj, field, JNI_FALSE); + void* temp = g_malloc(stride * height * 4); + memcpy(temp, data, stride * height * 4); + (*env)->ReleaseIntArrayElements (env, buf, data, 0); + data = temp; + } + else + (*env)->SetBooleanField (env, obj, field, JNI_TRUE); + + /* Create the cairo surface and set the java pointer */ + surface = cairo_image_surface_create_for_data + (data, CAIRO_FORMAT_ARGB32, width, height, stride * 4); + + setNativeObject(env, obj, surface, SURFACE); +} + +/** + * Destroy the surface + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_destroy +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buf) +{ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + void *data = cairo_image_surface_get_data(surface); + if( surface != NULL ) + { + /* Release or free the data buffer as appropriate */ + jclass cls = (*env)->GetObjectClass (env, obj); + jfieldID field = (*env)->GetFieldID (env, cls, SHARED, "Z"); + g_assert (field != 0); + jboolean sharedBuffer = (*env)->GetBooleanField (env, obj, field); + + if (sharedBuffer == JNI_TRUE) + (*env)->ReleaseIntArrayElements (env, buf, data, 0); + else + g_free(data); + + /* Destroy the cairo surface itself */ + cairo_surface_destroy(surface); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_nativeDrawSurface +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jlong context, jdoubleArray java_matrix, double alpha, + jint interpolation) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, context); + cairo_t *cr = gr->cr; + jdouble *native_matrix = NULL; + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + g_assert(cr != NULL); + + native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); + g_assert (native_matrix != NULL); + g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); + + { + cairo_matrix_t mat; + cairo_pattern_t *p; + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + + p = cairo_pattern_create_for_surface (surface); + cairo_pattern_set_matrix (p, &mat); + switch ((enum java_awt_rendering_hints_filter) interpolation) + { + case java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR: + cairo_pattern_set_filter (p, CAIRO_FILTER_BILINEAR); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC: + cairo_pattern_set_filter (p, CAIRO_FILTER_GAUSSIAN); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED: + cairo_pattern_set_filter (p, CAIRO_FILTER_FAST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY: + cairo_pattern_set_filter (p, CAIRO_FILTER_BEST); + break; + } + + cairo_set_source(cr, p); + if (alpha == 1.0) + cairo_paint(cr); + else + cairo_paint_with_alpha(cr, alpha); + + cairo_pattern_destroy(p); + } + + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer) +{ + cairo_surface_t* surface; + jint *src; + jint *dst; + int i, t, width, height; + jclass cls; + jfieldID field; + + /* Retrieve pointer to cairo data buffer */ + surface = JLONG_TO_PTR(void, surfacePointer); + src = (jint*)cairo_image_surface_get_data(surface); + + /* Retrieve dimensions of surface, from java fields */ + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + /* Create destination array */ + g_assert( src != NULL ); + dst = g_malloc( width * height * sizeof( jint ) ); + + /* Copy data into destination array, reversing sample order of each pixel */ + for(i = 0; i < (height * width); i++ ) + { + t = (src[i] & 0x0000FF) << 16; + dst[i] = (src[i] & 0x00FF0000) >> 16; + dst[i] |= (src[i] & 0xFF00FF00); + dst[i] |= t; + } + + return PTR_TO_JLONG(dst); +} + +/** + * Create and return a cairo context for drawing to the surface. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_nativeNewCairoContext +(JNIEnv *env __attribute((unused)), jobject obj __attribute((unused)), + jlong surfacePointer) +{ + cairo_surface_t* surface = JLONG_TO_PTR(cairo_surface_t, surfacePointer); + cairo_t *ptr; + g_assert(surface != NULL); + ptr = cairo_create(surface); + g_assert(ptr != NULL); + + return PTR_TO_JLONG(ptr); +} + +/** + * copyArea. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_copyAreaNative2 +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, + jint x, jint y, jint w, jint h, jint dx, jint dy, jint stride) +{ + int row; + int srcOffset, dstOffset; + jint *temp; + + /* Retrieve pointer to cairo data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + jint *pixeldata = (jint*)cairo_image_surface_get_data(surface); + g_assert( pixeldata != NULL ); + + /* Create temporary buffer and calculate offsets */ + temp = g_malloc( h * w * 4 ); + g_assert( temp != NULL ); + + srcOffset = x + (y * stride); + dstOffset = (x + dx) + ((y + dy) * stride); + + /* Copy desired region into temporary buffer */ + for( row = 0; row < h; row++ ) + memcpy( temp + (w * row), pixeldata + srcOffset + (stride * row), w * 4 ); + + /* Copy out of buffer and to destination */ + for( row = 0; row < h; row++ ) + memcpy( pixeldata + dstOffset + (stride * row), temp + (w * row), w * 4 ); + + g_free( temp ); +} + +/* + * Synchronizes the java and native data buffers, copying any changes made in + * the java array into the native array. + * This method should only be called if (sharedBuffer == false). + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_syncJavaToNative +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buffer) +{ + /* Get size of java array */ + int size = (*env)->GetArrayLength(env, buffer); + + /* Get native data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + void* nativeBuffer = cairo_image_surface_get_data(surface); + + /* Sync buffers */ + (*env)->GetIntArrayRegion(env, buffer, 0, size, nativeBuffer); +} + +/* + * Synchronizes the java and native data buffers, copying any changes made in + * the native array into the java array. + * This method should only be called if (sharedBuffer == false). + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_syncNativeToJava +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buffer) +{ + /* Get size of java array */ + int size = (*env)->GetArrayLength(env, buffer); + + /* Get native data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + void* nativeBuffer = cairo_image_surface_get_data(surface); + + /* Sync buffers */ + (*env)->SetIntArrayRegion(env, buffer, 0, size, nativeBuffer); +} + +/* + * Sets the native object field. + */ +static void +setNativeObject( JNIEnv *env, jobject obj, void *ptr, const char *pointer ) +{ + jclass cls; + jlong value; + jfieldID nofid; + cls = (*env)->GetObjectClass( env, obj ); + value = PTR_TO_JLONG(ptr); + nofid = (*env)->GetFieldID( env, cls, pointer, "J" ); + (*env)->SetLongField( env, obj, nofid, value ); + (*env)->DeleteLocalRef( env, cls ); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c new file mode 100644 index 000000000..31bab77d4 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c @@ -0,0 +1,291 @@ +/* gnu_java_awt_peer_gtk_ComponentGraphics.c + Copyright (C) 2006, 2007 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 "jcl.h" +#include "gtkpeer.h" +#include <gdk/gdktypes.h> +#include <gdk/gdkprivate.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdk-pixbuf/gdk-pixdata.h> + +#include <cairo-ft.h> + +#include <stdio.h> +#include <stdlib.h> + +#if HAVE_XRENDER +#include <gdk/gdkx.h> +#include <X11/extensions/Xrender.h> +#endif + +#include "gnu_java_awt_peer_gtk_ComponentGraphics.h" + +#include "cairographics2d.h" + +static short flush_scheduled = 0; + +static gboolean flush (gpointer data __attribute__((unused))) +{ + gdk_threads_enter (); + + gdk_display_flush (gdk_display_get_default ()); + flush_scheduled = 0; + + gdk_threads_leave (); + + return FALSE; +} + +/* The minimum time period between calls to XFlush, in + milliseconds. */ +#define MINIMUM_FLUSH_PERIOD 20 + +/* schedule_flush must be called with the GDK lock held. */ +static void +schedule_flush () +{ + if (!flush_scheduled) + { + g_timeout_add (MINIMUM_FLUSH_PERIOD, flush, NULL); + flush_scheduled = 1; + } +} + +void cp_gtk_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); +} + +/** + * Returns whether the XRender extension is supported + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender + (JNIEnv *env __attribute__ ((unused)), jclass cls __attribute__ ((unused))) +{ +#if HAVE_XRENDER + int ev = 0, err = 0; + if( XRenderQueryExtension (GDK_DISPLAY(), &ev, &err) ) + return JNI_TRUE; +#endif + return JNI_FALSE; +} + + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_initState + (JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer) +{ + GdkDrawable *drawable; + GtkWidget *widget; + cairo_t *cr; + void *ptr; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + drawable = widget->window; + g_assert (drawable != NULL); + + cr = gdk_cairo_create(drawable); + + g_assert(cr != NULL); + + gdk_threads_leave(); + + return PTR_TO_JLONG(cr); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong ptr) +{ + GdkDrawable *drawable; + cairo_t *cr; + + gdk_threads_enter(); + + drawable = JLONG_TO_PTR(GdkDrawable, ptr); + g_assert (drawable != NULL); + + cr = gdk_cairo_create (drawable); + g_assert(cr != NULL); + + gdk_threads_leave(); + + return PTR_TO_JLONG(cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused))) +{ + gdk_threads_enter(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused))) +{ + schedule_flush (); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative + (JNIEnv *env, jobject obj __attribute__((unused)), jobject peer, + jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, x, y, 0, 0, w, h ); + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, x + dx, y + dy, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_nativeGrab +(JNIEnv *env, jclass cls __attribute__((unused)), jobject peer ) +{ + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + gint w,h; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + gdk_drawable_get_size ( drawable, &w, &h ); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, 0, 0, 0, 0, w, h ); + g_object_ref( pixbuf ); + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, 0, 0, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); + + return JCL_NewRawDataObject (env, pixbuf); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile +(JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer, + jlong img, jint x, jint y, jint w, jint h, jint cx, jint cy, jint cw, jint ch) +{ + GdkPixmap *pixmap; + GtkWidget *widget = NULL; + GdkGC *gc; + GdkRectangle clip; + void *ptr; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + pixmap = JLONG_TO_PTR(GdkPixmap, img); + + gc = gdk_gc_new(widget->window); + + clip.x = cx; + clip.y = cy; + clip.width = cw; + clip.height = ch; + gdk_gc_set_clip_rectangle(gc, &clip); + + gdk_draw_drawable(widget->window, + gc, + pixmap, + 0, 0, + x, y, + w, h); + + g_object_unref( gc ); + + schedule_flush (); + + gdk_threads_leave(); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c new file mode 100644 index 000000000..df700f559 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c @@ -0,0 +1,129 @@ +/* gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c + Copyright (C) 2006 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 "jcl.h" +#include "gtkpeer.h" +#include <gdk/gdktypes.h> +#include <gdk/gdkprivate.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdk-pixbuf/gdk-pixdata.h> + +#include <cairo-ft.h> + +#include <stdio.h> +#include <stdlib.h> + +#include "gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphicsCopy_getPixbuf + (JNIEnv *env, jobject obj __attribute__((unused)), + jobject peer, jobject image) +{ + gint width, height; + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = cp_gtk_image_get_pixbuf( env, image ); + g_assert( pixbuf != NULL); + + width = gdk_pixbuf_get_width( pixbuf ); + height = gdk_pixbuf_get_height( pixbuf ); + + gdk_pixbuf_get_from_drawable( pixbuf, /* destination pixbuf */ + drawable, + NULL, /* colormap */ + 0, 0, 0, 0, + width, height ); + gdk_threads_leave(); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphicsCopy_copyPixbuf + (JNIEnv *env, jobject obj __attribute__((unused)), + jobject peer, jobject image, + jint x __attribute__((unused)), jint y __attribute__((unused)), + jint width __attribute__((unused)), jint height __attribute__((unused))) +{ + gint pwidth, pheight; + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = cp_gtk_image_get_pixbuf( env, image ); + g_assert( pixbuf != NULL); + + pwidth = gdk_pixbuf_get_width( pixbuf ); + pheight = gdk_pixbuf_get_height( pixbuf ); + + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, 0, 0, + pwidth, pheight, + GDK_RGB_DITHER_NORMAL, 0, 0); + + gdk_threads_leave(); +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c new file mode 100644 index 000000000..cb7bf43dc --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c @@ -0,0 +1,449 @@ +/* gnu_java_awt_FreetypeGlyphVector.c + Copyright (C) 2006 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. */ + +#define PANGO_ENABLE_ENGINE +#include <jni.h> +#include <gtk/gtk.h> +#include <string.h> +#include <pango/pango.h> +#include <pango/pangoft2.h> +#include <pango/pangofc-font.h> +#include <freetype/ftglyph.h> +#include <freetype/ftoutln.h> +#include "jcl.h" +#include "gdkfont.h" +#include "gnu_java_awt_peer_gtk_FreetypeGlyphVector.h" +#include "cairographics2d.h" + +typedef struct gp +{ + JNIEnv *env; + jobject obj; + double px; + double py; + double sx; + double sy; +} generalpath ; + +static PangoFcFont * +getFont(JNIEnv *env, jobject obj) +{ + jfieldID fid; + jobject data; + jclass cls; + struct peerfont *pfont; + + cls = (*env)->GetObjectClass (env, obj); + fid = (*env)->GetFieldID (env, cls, "peer", + "Lgnu/java/awt/peer/gtk/GdkFontPeer;"); + g_assert (fid != 0); + + data = (*env)->GetObjectField (env, obj, fid); + g_assert (data != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, data); + g_assert (pfont != NULL); + g_assert (pfont->font != NULL); + + return (PangoFcFont *)pfont->font; +} + +static PangoFontset * +getFontSet(JNIEnv *env, jobject obj) +{ + jfieldID fid; + jobject data; + jclass cls; + struct peerfont *pfont; + + cls = (*env)->GetObjectClass (env, obj); + fid = (*env)->GetFieldID (env, cls, "peer", + "Lgnu/java/awt/peer/gtk/GdkFontPeer;"); + g_assert (fid != 0); + + data = (*env)->GetObjectField (env, obj, fid); + g_assert (data != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font (env, data); + g_assert (pfont != NULL); + g_assert (pfont->font != NULL); + + return (PangoFontset *)pfont->set; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs + (JNIEnv *env, jobject obj, jintArray codepoints, jintArray glyphs, + jlongArray fonts) +{ + PangoFcFont *default_font, *current_font; + PangoFontset *pfs; + jint *cpvals; + jint length; + int i; + + /* Set up default font and fontset */ + default_font = getFont(env, obj); + current_font = default_font; + pfs = getFontSet(env, obj); + + /* Retrieve string information */ + length = (*env)->GetArrayLength (env, codepoints); + cpvals = (*env)->GetIntArrayElements (env, codepoints, NULL); + + jint *glyphArray = (*env)->GetIntArrayElements (env, glyphs, NULL); + jlong *fontArray = (*env)->GetLongArrayElements (env, fonts, NULL); + + /* A design goal of Pango is to be threadsafe, but it's admitted that it is + * not actually threadsafe at the moment. Using gdk locking here to be safe, + * but I don't know if if actually helps at all... */ + gdk_threads_enter(); + + for( i = 0; i < length; i++ ) + { + /* Ensure the current font has the requested character; if it doesn't, + * try the default font before pulling a new font out of the fontset. + * Once chosen, a font will be used until a character not in the font is + * encountered. */ + if (!pango_fc_font_has_char(current_font, cpvals[i])) + { + if (pango_fc_font_has_char(default_font, cpvals[i])) + { + current_font = default_font; + g_object_ref(current_font); + } + else + { + current_font = (PangoFcFont*)pango_fontset_get_font(pfs, cpvals[i]); + } + } + else + { + g_object_ref(current_font); + } + + /* Get glyph, and store both glyph and pointer to font */ + glyphArray[i] = (int)pango_fc_font_get_glyph(current_font, + (gunichar)cpvals[i]); + fontArray[i] = PTR_TO_JLONG(current_font); + } + + gdk_threads_leave(); + + (*env)->ReleaseIntArrayElements (env, glyphs, glyphArray, 0); + (*env)->ReleaseIntArrayElements (env, codepoints, cpvals, 0); + (*env)->ReleaseLongArrayElements (env, fonts, fontArray, 0); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getKerning + (JNIEnv *env, jobject obj __attribute__((unused)), jint rightGlyph, + jint leftGlyph, jlong fnt, jfloatArray p) +{ + FT_Face ft_face; + FT_Vector kern; + PangoFcFont *font; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + g_assert (ft_face != NULL); + FT_Get_Kerning( ft_face, rightGlyph, leftGlyph, FT_KERNING_DEFAULT, &kern ); + + pango_fc_font_unlock_face( font ); + + jfloat *pelements = (*env)->GetPrimitiveArrayCritical(env, p, NULL); + pelements[0] = (jfloat)kern.x/64.0; + pelements[1] = (jfloat)kern.y/64.0; + (*env)->ReleasePrimitiveArrayCritical (env, p, pelements, 0); +} + +JNIEXPORT jdoubleArray JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getMetricsNative +(JNIEnv *env, jobject obj __attribute__((unused)), jint glyphIndex, jlong fnt) +{ + FT_Face ft_face; + jdouble *values; + jdoubleArray retArray = NULL; + PangoFcFont *font; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + + g_assert (ft_face != NULL); + + FT_Set_Transform( ft_face, NULL, NULL ); + + if( FT_Load_Glyph( ft_face, glyphIndex, FT_LOAD_NO_BITMAP ) != 0 ) + { + pango_fc_font_unlock_face( font ); + printf("Couldn't load glyph %i\n", glyphIndex); + return NULL; + } + + retArray = (*env)->NewDoubleArray (env, 8); + values = (*env)->GetDoubleArrayElements (env, retArray, NULL); + + values[0] = 0; + values[1] = (jdouble)ft_face->glyph->advance.x/64.0; + values[2] = (jdouble)ft_face->glyph->advance.y/64.0; + values[3] = (jdouble)ft_face->glyph->metrics.horiBearingX/64.0; + values[4] = -(jdouble)ft_face->glyph->metrics.horiBearingY/64.0; + values[5] = (jdouble)ft_face->glyph->metrics.width/64.0; + values[6] = (jdouble)ft_face->glyph->metrics.height/64.0; + values[7] = 0; + + (*env)->ReleaseDoubleArrayElements (env, retArray, values, 0); + pango_fc_font_unlock_face( font ); + + return retArray; +} + +/* GetOutline code follows ****************************/ +/********* Freetype callback functions *****************************/ + +static int _moveTo( const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[2]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + + values[0].f = (jfloat)(to->x * path->sx + path->px); + values[1].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "moveTo", "(FF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _lineTo( const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[2]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(to->x * path->sx + path->px); + values[1].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "lineTo", "(FF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _quadTo( const FT_Vector* cp, + const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[4]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(cp->x * path->sx + path->px); + values[1].f = (jfloat)(cp->y * path->sy + path->py); + values[2].f = (jfloat)(to->x * path->sx + path->px); + values[3].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "quadTo", "(FFFF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _curveTo( const FT_Vector* cp1, + const FT_Vector* cp2, + const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[6]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(cp1->x * path->sx + path->px); + values[1].f = (jfloat)(cp1->y * path->sy + path->py); + values[2].f = (jfloat)(cp2->x * path->sx + path->px); + values[3].f = (jfloat)(cp2->y * path->sy + path->py); + values[4].f = (jfloat)(to->x * path->sx + path->px); + values[5].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "curveTo", "(FFFFFF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphOutlineNative + (JNIEnv *env, jobject obj __attribute__((unused)), jint glyphIndex, jlong fnt) +{ + generalpath *path; + jobject gp; + FT_Outline_Funcs ftCallbacks = + { + (FT_Outline_MoveToFunc) _moveTo, + (FT_Outline_LineToFunc) _lineTo, + (FT_Outline_ConicToFunc) _quadTo, + (FT_Outline_CubicToFunc) _curveTo, + 0, + 0 + }; + PangoFcFont *font; + FT_Face ft_face; + FT_Glyph glyph; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + + g_assert (ft_face != NULL); + + path = g_malloc0 (sizeof (generalpath)); + g_assert(path != NULL); + path->env = env; + + path->px = path->py = 0.0; + path->sx = 1.0/64.0; + path->sy = -1.0/64.0; + + { /* create a GeneralPath instance */ + jclass cls; + jmethodID method; + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "<init>", "()V"); + gp = path->obj = (*env)->NewObject (env, cls, method); + } + + if(FT_Load_Glyph(ft_face, + (FT_UInt)(glyphIndex), + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP) != 0) + { + pango_fc_font_unlock_face( font ); + g_free(path); + return NULL; + } + + FT_Get_Glyph( ft_face->glyph, &glyph ); + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) + { + FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline), + &ftCallbacks, path); + } + else + { + char format[5]; + + format[0] = (glyph->format & 0xFF000000) >> 24; + format[1] = (glyph->format & 0x00FF0000) >> 16; + format[2] = (glyph->format & 0x0000FF00) >> 8; + format[3] = (glyph->format & 0x000000FF); + format[4] = '\0'; + printf("WARNING: Unable to create outline for font %s %s of format %s\n", + ft_face->family_name, ft_face->style_name, format); + } + FT_Done_Glyph( glyph ); + + pango_fc_font_unlock_face( font ); + + g_free(path); + + return gp; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_dispose + (JNIEnv *env, jobject obj __attribute__((unused)), jlongArray fontset) +{ + PangoFcFont *font; + jlong *fontArray; + int i, length; + + length = (*env)->GetArrayLength (env, fontset); + fontArray = (*env)->GetLongArrayElements (env, fontset, NULL); + + gdk_threads_enter(); + + for( i = 0; i < length; i++ ) + { + font = JLONG_TO_PTR(PangoFcFont, fontArray[i]); + g_object_unref(font); + } + + gdk_threads_leave(); + + (*env)->ReleaseLongArrayElements (env, fontset, fontArray, 0); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer + (JNIEnv *env, jobject obj, jint n) +{ + int i; + PangoFcFont *font = getFont(env, obj); + + for (i = 0; i < n; i++) + g_object_ref(font); + + return PTR_TO_JLONG(font); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c new file mode 100644 index 000000000..771b23e37 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c @@ -0,0 +1,370 @@ +/* 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. */ + +#define PANGO_ENABLE_ENGINE +#include <pango/pango.h> +#include <pango/pangoft2.h> +#include <pango/pangofc-font.h> +#include <freetype/ftglyph.h> +#include <freetype/ftoutln.h> +#include <freetype/fttypes.h> +#include <freetype/tttables.h> +#include "gdkfont.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GdkFontPeer.h" + +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 PangoFontMap *font_map = NULL; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_initStaticState + (JNIEnv *env, jclass clazz __attribute__((unused))) +{ + gtkpeer_init_font_IDs(env); + font_map = pango_ft2_font_map_new(); +} + +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); + gtkpeer_set_font (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 *) gtkpeer_get_font (env, self); + g_assert (pfont != NULL); + if (pfont->layout != NULL) + g_object_unref (pfont->layout); + if (pfont->font != NULL) + g_object_unref (pfont->font); + if (pfont->set != NULL) + g_object_unref (pfont->set); + 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 void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_releasePeerGraphicsResource + (JNIEnv *env, jobject java_font) +{ + struct peerfont *pfont = NULL; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font (env, java_font); + g_assert (pfont != NULL); + if (pfont->graphics_resource != NULL) + { + cairo_font_face_destroy ((cairo_font_face_t *) pfont->graphics_resource); + pfont->graphics_resource = NULL; + } + + gdk_threads_leave(); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics +(JNIEnv *env, jobject java_font, jdoubleArray java_metrics) +{ + FT_Face face; + struct peerfont *pfont = NULL; + jdouble *native_metrics = NULL; + short x_ppem; + short y_ppem; + short units_per_em; + double factorx; + double factory; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font (env, java_font); + g_assert (pfont != NULL); + face = pango_fc_font_lock_face ((PangoFcFont *)pfont->font); + + native_metrics + = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); + + g_assert (native_metrics != NULL); + + x_ppem = face->size->metrics.x_ppem; + y_ppem = face->size->metrics.y_ppem; + units_per_em = face->units_per_EM; + factorx = units_per_em / x_ppem; + factory = units_per_em / y_ppem; + native_metrics[FONT_METRICS_ASCENT] = face->ascender / factory; + native_metrics[FONT_METRICS_MAX_ASCENT] = face->bbox.yMax / factory; + native_metrics[FONT_METRICS_DESCENT] = - face->descender / factory; + native_metrics[FONT_METRICS_MAX_DESCENT] = - face->bbox.yMin / factory; + native_metrics[FONT_METRICS_MAX_ADVANCE] = face->max_advance_width / factorx; + native_metrics[FONT_METRICS_HEIGHT] = face->height / factory; + native_metrics[FONT_METRICS_UNDERLINE_OFFSET] = + face->underline_position / factory; + native_metrics[FONT_METRICS_UNDERLINE_THICKNESS] = + face->underline_thickness / factory; + + pango_fc_font_unlock_face((PangoFcFont *)pfont->font); + + (*env)->ReleaseDoubleArrayElements (env, + java_metrics, + native_metrics, 0); + + 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; + PangoRectangle log2; + int line_count = 0; + int i = 0; + int width = 0; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font(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); + + line_count = pango_layout_get_line_count (pfont->layout); + for (i = 0; i < line_count; i++) + { + pango_layout_line_get_extents (pango_layout_get_line (pfont->layout, i), + NULL, &log2); + width += log2.width; + } + + (*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_HEIGHT] + = PANGO_PIXELS( ((double)log.height) ); + + native_metrics[TEXT_METRICS_WIDTH] + = PANGO_PIXELS( ((double)width) ); + + 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) +{ + struct peerfont *pfont = NULL; + char const *family_name = NULL; + enum java_awt_font_style style; + + gdk_threads_enter (); + + style = (enum java_awt_font_style) style_int; + + g_assert (self != NULL); + pfont = (struct peerfont *) gtkpeer_get_font(env, self); + g_assert (pfont != NULL); + + /* Clear old font information */ + if (pfont->ctx != NULL) + g_object_unref (pfont->ctx); + if (pfont->font != NULL) + g_object_unref (pfont->font); + if (pfont->set != NULL) + g_object_unref (pfont->set); + if (pfont->desc != NULL) + pango_font_description_free (pfont->desc); + + /* Set new description information */ + 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); + + pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); + + /* Create new context */ + pfont->ctx = pango_font_map_create_context (font_map); + g_assert (pfont->ctx != NULL); + + pango_context_set_font_description (pfont->ctx, pfont->desc); + pango_context_set_language (pfont->ctx, gtk_get_default_language()); + + /* Create new fontset and default font */ + pfont->set = pango_context_load_fontset(pfont->ctx, pfont->desc, + 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 (); +} + + +JNIEXPORT jbyteArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable + (JNIEnv *env, jobject self, jbyte n, jbyte a, jbyte m, jbyte e) +{ + struct peerfont *pfont = NULL; + FT_Face face; + FT_ULong length = 0; + FT_ULong tag; + int error; + FT_Byte *buffer; + jbyteArray result_array; + jbyte *rbuf; + + pfont = (struct peerfont *) gtkpeer_get_font(env, self); + if(pfont == NULL) + return NULL; + + gdk_threads_enter (); + face = pango_fc_font_lock_face ((PangoFcFont *)pfont->font); + tag = FT_MAKE_TAG( n, a, m, e ); + + /* Get the length of the table requested */ + error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length ); + if ( error ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + return NULL; + } + + buffer = (FT_Byte *)g_malloc0( length ); + if ( buffer == NULL ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + return NULL; + } + /* get the table data */ + error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length ); + if ( error ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + g_free(buffer); + gdk_threads_leave (); + return NULL; + } + + /* copy to a jbytearray */ + result_array = (*env)->NewByteArray (env, length); + + rbuf = (*env)->GetByteArrayElements (env, result_array, NULL); + memcpy(rbuf, buffer, length); + (*env)->ReleaseByteArrayElements (env, result_array, rbuf, 0); + + g_free(buffer); + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + + /* done */ + return result_array; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c new file mode 100644 index 000000000..6066a6bb2 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c @@ -0,0 +1,299 @@ +/* gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c + Copyright (C) 2004, 2006 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 <glib.h> +#include <gdk/gdk.h> + +#include "gdkfont.h" +#include "gdkdisplay.h" +#include "gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h" + +jclass gdkGraphicsEnvironment_class; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_initIDs +(JNIEnv *env, jclass klazz __attribute__((unused))) +{ + gtkpeer_init_display_IDs(env); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeInitState +(JNIEnv *env, jobject obj) +{ + GdkDisplay *defaultDisplay; + + gdk_threads_enter(); + + /* Retrieve the default display. */ + defaultDisplay = gdk_display_get_default(); + + gdk_threads_leave(); + + /* Store display pointer in GdkGraphicsEnvironment instance. */ + gtkpeer_set_display(env, obj, (void *) defaultDisplay); +} + +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 = NULL; + PangoFontFamily **families = NULL; + int n_families = 0; + int idx = 0; + + 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); + (*env)->DeleteLocalRef(env, 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 = NULL; + PangoFontFamily **families = NULL; + gint n_families = 0; + gint num = 0; + + 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; +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetScreenDevices +(JNIEnv *env, jobject obj) +{ + jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init; + jclass gdkScreenGraphicsDevice_class; + int numScreens = 0, i = 0; + GdkDisplay *display; + jobjectArray array; + jobject instance; + + gdkScreenGraphicsDevice_class = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + + gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "<init>", + "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V"); + + gdkScreenGraphicsDevice_init = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "init", "()V"); + + display = (GdkDisplay *) gtkpeer_get_display(env, obj); + + gdk_threads_enter(); + + numScreens = gdk_display_get_n_screens(display); + + + /* Create a suitably sized array. */ + array = (*env)->NewObjectArray(env, + numScreens, + gdkScreenGraphicsDevice_class, + NULL); + + /* Create GdkScreenGraphicsDevice instances, store the native pointer to + * the GScreen object with them, run a 2nd initialization phase and + * put the new instance into the result array. + */ + for ( ; i < numScreens ; i++) + { + instance = (*env)->NewObject (env, + gdkScreenGraphicsDevice_class, + gdkScreenGraphicsDevice_ctor, + obj); + + gtkpeer_set_screen(env, instance, gdk_display_get_screen(display, i)); + + gdk_threads_leave(); + (*env)->CallVoidMethod(env, + instance, + gdkScreenGraphicsDevice_init); + gdk_threads_enter(); + + (*env)->SetObjectArrayElement(env, array, i, instance); + } + + gdk_threads_leave(); + + return array; +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetDefaultScreenDevice +(JNIEnv *env, jobject obj) +{ + jclass gdkScreenGraphicsDevice_class; + jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init; + jobject defaultDevice; + GdkScreen *defaultScreen; + + gdkScreenGraphicsDevice_class = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + + gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "<init>", + "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V"); + gdkScreenGraphicsDevice_init = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "init", "()V"); + + /* Create the GdkScreenGraphicsDevice instance. */ + defaultDevice = (*env)->NewObject(env, gdkScreenGraphicsDevice_class, + gdkScreenGraphicsDevice_ctor, obj); + + gdk_threads_enter(); + + defaultScreen = gdk_screen_get_default(); + + gdk_threads_leave(); + + /* Class initialization will have set up the native_state storage + * mechanism for GdkScreenGraphicsDevice. + */ + gtkpeer_set_screen(env, defaultDevice, defaultScreen); + + (*env)->CallVoidMethod(env, + defaultDevice, + gdkScreenGraphicsDevice_init); + + return defaultDevice; +} + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_getMouseCoordinates +(JNIEnv *env, jobject obj) +{ + jintArray retArray; + jint *values; + GdkDisplay *display; + gint x, y, screenIndex; + GdkScreen *screen; + + display = (GdkDisplay *) gtkpeer_get_display(env, obj); + g_assert (display != NULL); + + gdk_threads_enter (); + + gdk_display_get_pointer (display, &screen, &x, &y, NULL); + screenIndex = gdk_screen_get_number( screen ); + + gdk_threads_leave (); + + retArray = (*env)->NewIntArray (env, 3); + values = (*env)->GetIntArrayElements (env, retArray, NULL); + + values[0] = screenIndex; + values[1] = x; + values[2] = y; + + (*env)->ReleaseIntArrayElements (env, retArray, values, 0); + + return retArray; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_isWindowUnderMouse +(JNIEnv *env, jobject obj, jobject windowPeer) +{ + GdkDisplay *display = NULL; + gint x = 0; + gint y = 0; + GtkWidget *windowToTest = NULL; + GdkWindow *windowAtPointer = NULL; + jboolean retVal = JNI_FALSE; + + display = (GdkDisplay *) gtkpeer_get_display (env, obj); + g_assert (display != NULL); + + windowToTest = (GtkWidget *) gtkpeer_get_widget (env, windowPeer); + + gdk_threads_enter (); + + windowAtPointer = gdk_display_get_window_at_pointer (display, &x, &y); + + while (windowAtPointer + && windowAtPointer != windowToTest->window) + windowAtPointer = gdk_window_get_parent (windowAtPointer); + + gdk_threads_leave (); + + if (windowAtPointer) + retVal = JNI_TRUE; + else + retVal = JNI_FALSE; + + return retVal; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c new file mode 100644 index 000000000..5ed39521a --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c @@ -0,0 +1,470 @@ +/* gdkpixbufdecoder.c + Copyright (C) 1999, 2003, 2004, 2005, 2006 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 <jcl.h> +#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h" + +#include <string.h> +#include <stdlib.h> + +/* 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_cb (GdkPixbufLoader *loader, + jobject *decoder) +{ + JNIEnv *env = NULL; + union env_union e; + jint width = 0; + jint height = 0; + GdkPixbuf *pixbuf = NULL; + + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + g_assert (pixbuf != NULL); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + 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); +} + +static void +area_updated_cb (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); + + (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); + + (*env)->CallVoidMethod (env, + *decoder, + areaUpdatedID, + (jint) x, (jint) y, + (jint) width, (jint) height, + jpixels, + stride_pixels); + + (*env)->DeleteLocalRef(env, jpixels); +} + +static void +closed_cb (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); + + (*env)->DeleteGlobalRef (env, *decoder); + g_free (decoder); +} + + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initState + (JNIEnv *env, jobject obj) +{ + GdkPixbufLoader *loader = NULL; + jobject *decoder = NULL; + + decoder = (jobject *) g_malloc (sizeof (jobject)); + g_assert (decoder != NULL); + *decoder = (*env)->NewGlobalRef (env, obj); + + loader = gdk_pixbuf_loader_new (); + g_assert (loader != NULL); + g_signal_connect (loader, "area-prepared", G_CALLBACK (area_prepared_cb), decoder); + g_signal_connect (loader, "area-updated", G_CALLBACK (area_updated_cb), decoder); + g_signal_connect (loader, "closed", G_CALLBACK (closed_cb), decoder); + + gtkpeer_set_pixbuf_loader (env, obj, loader); +} + +static void +query_formats (JNIEnv *env, jclass clazz) +{ + jobject jformat; + GSList *formats, *f; + GdkPixbufFormat *format; + gchar **ch, *name; + gint count; + + 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_free(name); + + g_assert(jformat != NULL); + + ch = gdk_pixbuf_format_get_extensions(format); + count = 0; + while (*ch) + { + string = (*env)->NewStringUTF(env, *ch); + g_assert(string != NULL); + (*env)->CallVoidMethod (env, jformat, addExtensionID, string); + (*env)->DeleteLocalRef(env, string); + ++ch; + ++count; + } + g_strfreev(ch - count); + + ch = gdk_pixbuf_format_get_mime_types(format); + count = 0; + while (*ch) + { + string = (*env)->NewStringUTF(env, *ch); + g_assert(string != NULL); + (*env)->CallVoidMethod (env, jformat, addMimeTypeID, string); + (*env)->DeleteLocalRef(env, string); + ++ch; + ++count; + } + g_strfreev(ch - count); + (*env)->DeleteLocalRef(env, jformat); + } + + g_slist_free(formats); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState + (JNIEnv *env, jclass clazz) +{ + jclass writerClass; + + (*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;"); + + writerClass = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder$GdkPixbufWriter"); + dataOutputWriteID = (*env)->GetMethodID (env, writerClass, + "write", "([B)V"); + + query_formats (env, clazz); + + gtkpeer_init_pixbuf_IDs (env); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish +(JNIEnv *env, jobject obj, jboolean needs_close) +{ + GdkPixbufLoader *loader = NULL; + + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader(env, obj); + if (loader == NULL) + return; + + if (needs_close) + gdk_pixbuf_loader_close (loader, NULL); + g_object_unref (loader); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpDone +(JNIEnv *env, jobject obj) +{ + GError *err = NULL; + GdkPixbufLoader *loader = NULL; + + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader (env, obj); + g_assert (loader != NULL); + + gdk_pixbuf_loader_close (loader, &err); + + if (err != NULL) + { + JCL_ThrowException (env, "java/io/IOException", err->message); + g_error_free (err); + } +} + +struct stream_save_request +{ + JNIEnv *env; + jobject *writer; +}; + +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; + + 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->writer), + dataOutputWriteID, jbuf); + (*(ssr->env))->DeleteLocalRef((ssr->env), jbuf); + + 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 writer) +{ + 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.writer = &writer; + 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; + } + + 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); + + 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; + GError *err = NULL; + + g_assert (len >= 1); + g_assert (jarr != NULL); + + bytes = (*env)->GetByteArrayElements (env, jarr, NULL); + g_assert (bytes != NULL); + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader (env, obj); + g_assert (loader != NULL); + + gdk_pixbuf_loader_write (loader, (const guchar *) bytes, len, &err); + + (*env)->ReleaseByteArrayElements (env, jarr, bytes, 0); + + if (err != NULL) + { + JCL_ThrowException (env, "java/io/IOException", err->message); + g_error_free (err); + } +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c new file mode 100644 index 000000000..ea9c1d6e8 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c @@ -0,0 +1,440 @@ +/* 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" + +#ifdef HAVE_XTEST +#include <gdk/gdkx.h> +#include <X11/extensions/XTest.h> +#endif + +#ifdef HAVE_XTEST + +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; +} + +#endif + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_initXTest + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + +#ifdef HAVE_XTEST + + 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; + +#else + + return JNI_FALSE; + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseMove + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint x, jint y) +{ + +#ifdef HAVE_XTEST + + 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); + if (result) + g_warning("XTestFakeMotionEvent returned %d\n", result); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) x; // Unused. + (void) y; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mousePress + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) +{ + +#ifdef HAVE_XTEST + + 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); + if (result) + g_warning("XTestFakeButtonEvent returned %d\n", result); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) buttons; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseRelease + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) +{ + +#ifdef HAVE_XTEST + + 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); + if (result) + g_warning("XTestFakeButtonEvent returned %d\n", result); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) buttons; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseWheel + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint wheelAmt) +{ + +#ifdef HAVE_XTEST + + 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 (); + +#else + + (void) wheelAmt; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyPress + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) +{ + +#ifdef HAVE_XTEST + + 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 = cp_gtk_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_message ("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); + if (result) + g_warning("XTestFakeKeyEvent returned %d\n", result); + + g_free (keymap_keys); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) keycode; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyRelease + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) +{ + +#ifdef HAVE_XTEST + + 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 = cp_gtk_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_message ("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); + if (result) + g_warning("XTestFakeKeyEvent returned %d\n", result); + + g_free (keymap_keys); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) keycode; // Unused. + +#endif + +} + +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) +{ + +#ifdef HAVE_XTEST + + 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; + +#else + + (void) env; + (void) x; + (void) y; + (void) width; + (void) height; + return NULL; + +#endif + +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c new file mode 100644 index 000000000..14ba2a123 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c @@ -0,0 +1,351 @@ +/* gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c + Copyright (C) 2006 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 <jcl.h> + +#include <gdk/gdk.h> +#include <gdk/gdkx.h> + +#ifdef HAVE_XRANDR +#include <X11/Xlib.h> +#include <X11/extensions/Xrandr.h> +#endif + +#include "gdkdisplay.h" + +#include "gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h" + +struct state_table *cp_gtk_native_screen_state_table; + +jclass gdkScreenGraphicsDevice_class; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_initIDs +(JNIEnv *env, jclass klazz __attribute__((unused))) +{ + gtkpeer_init_screen_IDs(env); +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetFixedDisplayMode +(JNIEnv *env, jobject obj, jobject gdkGraphicsEnv __attribute__((unused))) +{ + jclass displayMode_class; + jmethodID displayMode_ctor; + GdkScreen *screen; + jobject fixedDisplayMode = NULL; +#ifdef HAVE_XRANDR + int temp1, temp2; + GdkDisplay *display; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + if (!XRRQueryExtension(GDK_DISPLAY_XDISPLAY(display), &temp1, &temp2)) + { + displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode"); + displayMode_ctor = (*env)->GetMethodID(env, + displayMode_class, + "<init>", + "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + fixedDisplayMode = (*env)->NewObject(env, + displayMode_class, + displayMode_ctor, + gdk_screen_get_width(screen), + gdk_screen_get_height(screen), + -1, + 0); + } + + gdk_threads_leave(); + +#else + + displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode"); + displayMode_ctor = (*env)->GetMethodID(env, + displayMode_class, + "<init>", + "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + fixedDisplayMode = (*env)->NewObject(env, + displayMode_class, + displayMode_ctor, + gdk_screen_get_width(screen), + gdk_screen_get_height(screen), + -1, + 0); + +#endif + return fixedDisplayMode; +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetIDString +(JNIEnv *env, jobject obj) +{ + GdkScreen *screen; + gchar* displayName; + jstring string; + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + gdk_threads_enter(); + + displayName = gdk_screen_make_display_name(screen); + + gdk_threads_leave(); + + string = (*env)->NewStringUTF(env, displayName); + + g_free(displayName); + + return string; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + + GdkDisplay *display; + XRRScreenConfiguration *config; + int rate; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + rate = (int) XRRConfigCurrentRate (config); + + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return rate; +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return -1; +#endif +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + + GdkDisplay *display; + XRRScreenConfiguration *config; + SizeID index; + Rotation rotation; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + index = XRRConfigCurrentConfiguration (config, &rotation); + + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return (int) index; + +#else + + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return -1; + +#endif +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + GdkDisplay *display; + XRRScreenConfiguration *config; + XRRScreenSize *screenSizes; + int nsizes = 0, nrates = 0, i = 0; + jclass x11DisplayMode_class; + jmethodID x11DisplayMode_ctor; + jobjectArray array; + jobject instance; + short *rates; + jshortArray shortArray; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + screenSizes = XRRConfigSizes(config, &nsizes); + + x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode"); + + x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "<init>", "(II[S)V"); + + array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL); + + for (; i < nsizes ; i++) + { + /* Retrieves refresh rate information. */ + rates = XRRConfigRates(config, i, &nrates); + + /* Create a Java short array and put them in. */ + shortArray = (*env)->NewShortArray(env, nrates); + (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates); + + /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */ + instance = (*env)->NewObject(env, + x11DisplayMode_class, + x11DisplayMode_ctor, + screenSizes[i].width, + screenSizes[i].height, + shortArray); + + /* Put it into the result array. */ + (*env)->SetObjectArrayElement(env, array, i, instance); + } + + /* Free everything acquired by xlib. */ + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return array; +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return NULL; + +#endif +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + GdkDisplay *display; + XRRScreenConfiguration *config; + Rotation rotation; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + /* The rotation is not exposed to the Java API. So we retrieve its current + * value and set it to the same when switching resolution. + */ + XRRConfigCurrentConfiguration (config, &rotation); + + XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display), + config, + GDK_ROOT_WINDOW(), + index, + rotation, + rate, + CurrentTime); + + XRRFreeScreenConfigInfo(config); + + gdk_threads_leave(); + +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); +#endif +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetBounds +(JNIEnv *env, jobject obj) +{ + jclass rectangle_class; + jmethodID rectangle_ctor; + GdkScreen *screen; + GdkWindow *window; + int x, y, w, h; + jobject instance; + + rectangle_class = (*env)->FindClass(env, "java/awt/Rectangle"); + + rectangle_ctor = (*env)->GetMethodID + (env, rectangle_class, "<init>", "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + gdk_threads_enter(); + + window = gdk_screen_get_root_window(screen); + + gdk_window_get_geometry(window, &x, &y, &w, &h, NULL); + + gdk_threads_leave(); + + instance = (*env)->NewObject(env, + rectangle_class, + rectangle_ctor, + x, y, w, h); + + return instance; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c new file mode 100644 index 000000000..3e39b0ee2 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c @@ -0,0 +1,376 @@ +/* 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 jmethodID postActionEventID; + +void +cp_gtk_button_init_jni (JNIEnv* env) +{ + jclass gtkbuttonpeer; + + gtkbuttonpeer = (*env)->FindClass (env, + "gnu/java/awt/peer/gtk/GtkButtonPeer"); + + postActionEventID = (*env)->GetMethodID (cp_gtk_gdk_env(), gtkbuttonpeer, + "postActionEvent", "(I)V"); +} + +static void clicked_cb (GtkButton *button, + 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + c_label = (*env)->GetStringUTFChars (env, label, NULL); + + eventbox = gtk_event_box_new (); + button = gtk_button_new_with_label (c_label); + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + (*env)->ReleaseStringUTFChars (env, label, c_label); + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkWidget *button; + GtkWidget *label; + GtkRequisition current_req; + GtkRequisition current_label_req; + GtkRequisition natural_req; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* Save the button's current size request. */ + gtk_widget_size_request (GTK_WIDGET (button), ¤t_req); + + /* Save the label's current size request. */ + gtk_widget_size_request (GTK_WIDGET (label), ¤t_label_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1); + gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1); + + gtk_widget_size_request (GTK_WIDGET (button), &natural_req); + + /* Reset the button's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (button), + current_req.width, current_req.height); + + /* Reset the label's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), + current_label_req.width, current_label_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + GtkWidget *widget; + jobject gref; + GtkWidget *button; + + gdk_threads_enter (); + + widget = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + button = gtk_bin_get_child (GTK_BIN (widget)); + + /* Button signals */ + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (clicked_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (button), 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = (*env)->GetStringUTFChars (env, jtext, NULL); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + gtk_label_set_text (GTK_LABEL (label), text); + + (*env)->ReleaseStringUTFChars (env, jtext, text); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + 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 * cp_gtk_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); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (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; + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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_IS_FIXED (widget->parent)) + gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); + } + + gdk_threads_leave (); +} + +static void +clicked_cb (GtkButton* button __attribute__((unused)), + jobject peer) +{ + GdkEventButton* event; + + event = (GdkEventButton*) gtk_get_current_event (); + g_assert (event); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postActionEventID, + cp_gtk_state_to_awt_mods (event->state)); + + gdk_event_free ((GdkEvent*) event); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c new file mode 100644 index 000000000..600b61a33 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c @@ -0,0 +1,58 @@ +/* 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; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + widget = gtk_drawing_area_new (); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c new file mode 100644 index 000000000..a30eba449 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c @@ -0,0 +1,78 @@ +/* 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + widget = gtk_check_menu_item_new_with_label (str); + gtk_widget_show (widget); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_setState + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (ptr), state); + + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c new file mode 100644 index 000000000..96230aadf --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c @@ -0,0 +1,407 @@ +/* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer + Copyright (C) 1998, 1999, 2002, 2003, 2004, 2006 + 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" +#include "jcl.h" + +static jmethodID postItemEventID; +static jmethodID addToGroupMapID; +static GtkWidget *checkbox_get_widget (GtkWidget *widget); +static void item_toggled_cb (GtkToggleButton *item, jobject peer); + +void +cp_gtk_checkbox_init_jni (void) +{ + jclass gtkcheckboxpeer; + + gtkcheckboxpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkCheckboxPeer"); + + postItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer, + "postItemEvent", + "(Ljava/lang/Object;Z)V"); + + addToGroupMapID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer, + "addToGroupMap", + "(J)V"); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + bin = checkbox_get_widget (GTK_WIDGET (ptr)); + + /* Checkbox signals */ + g_signal_connect (G_OBJECT (bin), "toggled", + G_CALLBACK (item_toggled_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (bin), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive + (JNIEnv *env, jobject obj, jboolean is_active) +{ + void *ptr; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = checkbox_get_widget (GTK_WIDGET (ptr)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin), 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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + button = checkbox_get_widget (GTK_WIDGET (ptr)); + label = gtk_bin_get_child (GTK_BIN(button)); + + if (!label) + return; + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_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); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + c_label = (*env)->GetStringUTFChars (env, label, NULL); + + label_widget = gtk_bin_get_child (GTK_BIN (checkbox_get_widget (GTK_WIDGET (ptr)))); + gtk_label_set_text (GTK_LABEL (label_widget), c_label); + + (*env)->ReleaseStringUTFChars (env, label, c_label); + + gdk_threads_leave (); +} + +/* A check button is created if we are not part of + a group. + This function is called when initially creating the + button, so an eventbox is created. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createCheckButton + (JNIEnv *env, jobject obj) +{ + GtkWidget *button; + GtkWidget *eventbox; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + eventbox = gtk_event_box_new (); + + button = gtk_check_button_new_with_label (""); + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +/* A radio button is created if we are part of a group. + groupPointer points to the corresponding group. If 0, + a new group is created. + This function is called when initially creating the + button, so an eventbox is created. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createRadioButton + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + GtkWidget *button; + GtkWidget *eventbox; + GSList *native_group = NULL; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + eventbox = gtk_event_box_new (); + + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + button = gtk_radio_button_new_with_label (native_group, ""); + + if (native_group == NULL) + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (button)); + GTK_RADIO_BUTTON(button)->group = native_group; + } + + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + gtkpeer_set_widget (env, obj, eventbox); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Add the object to the group pointed to by groupPointer. + If groupPointer is 0, create a new group and create + a radio button. Otherwise, creating a radio button in an + existing group. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_addToGroup + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + void *ptr; + GtkWidget *container; + GtkWidget *check_button; + GtkWidget *radio_button; + const gchar *label; + GSList *native_group = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + container = GTK_WIDGET (ptr); + check_button = checkbox_get_widget (container); + label = gtk_label_get_text (GTK_LABEL (gtk_bin_get_child + (GTK_BIN (check_button)))); + + /* Need to remove the check_button, and replace it with + a radio button in a group. + */ + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + + radio_button = gtk_radio_button_new_with_label (native_group, label); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button))); + + if (native_group == NULL) + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (radio_button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = native_group; + } + + gtk_container_remove (GTK_CONTAINER (container), check_button); + gtk_container_add (GTK_CONTAINER (container), radio_button); + gtk_widget_show (radio_button); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Remove the object from the group pointed to by groupPointer. + We are removing the radio button and creating a check button. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_removeFromGroup + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *container; + GtkWidget *check_button; + GtkWidget *radio_button; + GSList *native_group; + const gchar *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + container = GTK_WIDGET (ptr); + radio_button = checkbox_get_widget (container); + label = gtk_label_get_text (GTK_LABEL (gtk_bin_get_child + (GTK_BIN (radio_button)))); + + /* Need to remove the radio_button, and replace it with + a check button. + */ + check_button = gtk_check_button_new_with_label (label); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_button))); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + native_group = g_slist_remove (native_group, GTK_RADIO_BUTTON (radio_button)); + + if (native_group && ! GTK_IS_RADIO_BUTTON (native_group->data)) + native_group = NULL; + + GTK_RADIO_BUTTON(radio_button)->group = NULL; + + gtk_container_remove (GTK_CONTAINER (container), radio_button); + gtk_container_add (GTK_CONTAINER (container), check_button); + gtk_widget_show (check_button); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Move the radio button to a new group. If groupPointer is + 0, create a new group. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_switchToGroup + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + void *ptr; + GtkWidget *radio_button; + GSList *native_group = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + radio_button = checkbox_get_widget (GTK_WIDGET (ptr)); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + native_group = g_slist_remove (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = NULL; + + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), native_group); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (radio_button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = native_group; + } + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +static void +item_toggled_cb (GtkToggleButton *item, jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postItemEventID, + peer, + item->active); +} + +static GtkWidget * +checkbox_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c new file mode 100644 index 000000000..6f3d9c0e1 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c @@ -0,0 +1,237 @@ +/* gtkchoicepeer.c -- Native implementation of GtkChoicePeer + Copyright (C) 1998, 1999, 2006 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 jmethodID postChoiceItemEventID; +static GtkWidget *choice_get_widget (GtkWidget *widget); + +void +cp_gtk_choice_init_jni (void) +{ + jclass gtkchoicepeer; + + gtkchoicepeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkChoicePeer"); + + postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer, + "postChoiceItemEvent", + "(I)V"); +} + +static void selection_changed_cb (GtkComboBox *combobox, jobject peer); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create + (JNIEnv *env, jobject obj) +{ + GtkWidget *combobox; + GtkWidget *eventbox; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + eventbox = gtk_event_box_new (); + combobox = gtk_combo_box_new_text (); + gtk_container_add (GTK_CONTAINER (eventbox), combobox); + gtk_widget_show (combobox); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NULL; + jobject gref; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + bin = choice_get_widget (GTK_WIDGET (ptr)); + + /* Choice signals */ + g_signal_connect (G_OBJECT (bin), "changed", + G_CALLBACK (selection_changed_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (bin), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add + (JNIEnv *env, jobject obj, jstring item, jint index) +{ + void *ptr; + const char *label; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + label = (*env)->GetStringUTFChars (env, item, 0); + + gtk_combo_box_insert_text (GTK_COMBO_BOX (bin), index, label); + + (*env)->ReleaseStringUTFChars (env, item, label); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + /* First, unselect everything, to avoid problems when removing items. */ + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1); + gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), index); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkTreeModel *model; + GtkWidget *bin; + gint count, i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (bin)); + 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 (bin), -1); + + for (i = count - 1; i >= 0; i--) { + gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), i); + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNative + (JNIEnv *env, jobject obj, jint index) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked + (env, obj, index); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *bin; + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), (gint)index); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected + (JNIEnv *env, jobject obj) +{ + void *ptr; + int index; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + index = gtk_combo_box_get_active (GTK_COMBO_BOX (bin)); + + gdk_threads_leave (); + + return index; +} + +static void +selection_changed_cb (GtkComboBox *combobox, jobject peer) +{ + gint index = gtk_combo_box_get_active(combobox); + + if (index >= 0) + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postChoiceItemEventID, (jint)index ); +} + +static GtkWidget * +choice_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c new file mode 100644 index 000000000..0b076f864 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c @@ -0,0 +1,422 @@ +/* gtkclipboard.c + Copyright (C) 1998, 1999, 2005, 2006 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 "jcl.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkClipboard.h" + +#define OBJECT_TARGET 1 +#define TEXT_TARGET 2 +#define IMAGE_TARGET 3 +#define URI_TARGET 4 + +/* The clipboard and selection plus corresponding GtkClipboard objects. */ +GtkClipboard *cp_gtk_clipboard; +GtkClipboard *cp_gtk_selection; + +jobject cp_gtk_clipboard_instance; +jobject cp_gtk_selection_instance; + +/* Standard (string targets) shared with GtkSelection. */ +jstring cp_gtk_stringTarget; +jstring cp_gtk_imageTarget; +jstring cp_gtk_filesTarget; + +static jclass gtk_clipboard_class; + +static jmethodID setSystemContentsID; +static jmethodID provideContentID; +static jmethodID provideTextID; +static jmethodID provideImageID; +static jmethodID provideURIsID; + +/* Called when clipboard owner changes. Used to update available targets. */ +#if GTK_MINOR_VERSION > 4 +static void +clipboard_owner_change_cb (GtkClipboard *clipboard, + GdkEvent *event __attribute__((unused)), + gpointer user_data __attribute__((unused))) +{ + JNIEnv *env = cp_gtk_gdk_env (); + if (clipboard == cp_gtk_clipboard) + (*env)->CallVoidMethod (env, cp_gtk_clipboard_instance, + setSystemContentsID, JNI_FALSE); + else + (*env)->CallVoidMethod (env, cp_gtk_selection_instance, + setSystemContentsID, JNI_FALSE); + +} +#endif + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState (JNIEnv *env, + jclass clz, + jobject gtkclipboard, + jobject gtkselection, + jstring string, + jstring image, + jstring files) +{ + GdkDisplay* display; + jboolean can_cache; + + gtk_clipboard_class = clz; + setSystemContentsID = (*env)->GetMethodID (env, gtk_clipboard_class, + "setSystemContents", + "(Z)V"); + if (setSystemContentsID == NULL) + return JNI_FALSE; + + provideContentID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideContent", + "(Ljava/lang/String;)[B"); + if (provideContentID == NULL) + return JNI_FALSE; + + provideTextID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideText", + "()Ljava/lang/String;"); + if (provideTextID == NULL) + return JNI_FALSE; + + provideImageID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideImage", + "()Lgnu/java/awt/peer/gtk/GtkImage;"); + if (provideImageID == NULL) + return JNI_FALSE; + + provideURIsID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideURIs", + "()[Ljava/lang/String;"); + if (provideURIsID == NULL) + return JNI_FALSE; + + cp_gtk_clipboard_instance = (*env)->NewGlobalRef(env, gtkclipboard); + cp_gtk_selection_instance = (*env)->NewGlobalRef(env, gtkselection); + + cp_gtk_stringTarget = (*env)->NewGlobalRef(env, string); + cp_gtk_imageTarget = (*env)->NewGlobalRef(env, image); + cp_gtk_filesTarget = (*env)->NewGlobalRef(env, files); + + gdk_threads_enter (); + cp_gtk_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + cp_gtk_selection = gtk_clipboard_get (GDK_SELECTION_PRIMARY); + + display = gtk_clipboard_get_display (cp_gtk_clipboard); + /* Check for support for clipboard owner changes. */ +#if GTK_MINOR_VERSION > 4 + if (gdk_display_supports_selection_notification (display)) + { + g_signal_connect (cp_gtk_clipboard, "owner-change", + G_CALLBACK (clipboard_owner_change_cb), NULL); + g_signal_connect (cp_gtk_selection, "owner-change", + G_CALLBACK (clipboard_owner_change_cb), NULL); + gdk_display_request_selection_notification (display, + GDK_SELECTION_CLIPBOARD); + gdk_display_request_selection_notification (display, + GDK_SELECTION_PRIMARY); + can_cache = JNI_TRUE; + } + else +#endif + can_cache = JNI_FALSE; + + gdk_threads_leave (); + + return can_cache; +} + +static void +clipboard_get_func (GtkClipboard *clipboard, + GtkSelectionData *selection, + guint info, + gpointer user_data __attribute__((unused))) +{ + jobject gtk_clipboard_instance; + JNIEnv *env = cp_gtk_gdk_env (); + + if (clipboard == cp_gtk_clipboard) + gtk_clipboard_instance = cp_gtk_clipboard_instance; + else + gtk_clipboard_instance = cp_gtk_selection_instance; + + if (info == OBJECT_TARGET) + { + const gchar *target_name; + jstring target_string; + jbyteArray bytes; + jint len; + jbyte *barray; + + target_name = gdk_atom_name (selection->target); + if (target_name == NULL) + return; + target_string = (*env)->NewStringUTF (env, target_name); + if (target_string == NULL) + return; + bytes = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideContentID, + target_string); + (*env)->DeleteLocalRef(env, target_string); + if (bytes == NULL) + return; + len = (*env)->GetArrayLength(env, bytes); + if (len <= 0) + return; + barray = (*env)->GetByteArrayElements(env, bytes, NULL); + if (barray == NULL) + return; + gtk_selection_data_set (selection, selection->target, 8, + (guchar *) barray, len); + + (*env)->ReleaseByteArrayElements(env, bytes, barray, 0); + + } + else if (info == TEXT_TARGET) + { + jstring string; + const gchar *text; + int len; + string = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideTextID); + if (string == NULL) + return; + len = (*env)->GetStringUTFLength (env, string); + if (len == -1) + return; + text = (*env)->GetStringUTFChars (env, string, NULL); + if (text == NULL) + return; + + gtk_selection_data_set_text (selection, text, len); + (*env)->ReleaseStringUTFChars (env, string, text); + } + /* Images and URIs/Files support only available with gtk+2.6 or higher. */ +#if GTK_MINOR_VERSION > 4 + else if (info == IMAGE_TARGET) + { + jobject gtkimage; + GdkPixbuf *pixbuf = NULL; + + gtkimage = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideImageID); + if (gtkimage == NULL) + return; + + pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage); + if (pixbuf != NULL) + gtk_selection_data_set_pixbuf (selection, pixbuf); + } + else if (info == URI_TARGET) + { + jobjectArray uris; + jint count; + int i; + gchar **list; + + uris = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideURIsID); + if (uris == NULL) + return; + count = (*env)->GetArrayLength (env, uris); + if (count <= 0) + return; + + list = (gchar **) JCL_malloc (env, (count + 1) * sizeof (gchar *)); + for (i = 0; i < count; i++) + { + const char *text; + jstring uri; + + /* Mark NULL in so case of some error we can find the end. */ + list[i] = NULL; + uri = (*env)->GetObjectArrayElement (env, uris, i); + if (uri == NULL) + break; + text = (*env)->GetStringUTFChars (env, uri, NULL); + if (text == NULL) + { + (*env)->DeleteLocalRef(env, uri); + break; + } + list[i] = strdup (text); + (*env)->ReleaseStringUTFChars (env, uri, text); + (*env)->DeleteLocalRef(env, uri); + } + + if (i == count) + { + list[count] = NULL; + gtk_selection_data_set_uris (selection, list); + } + + for (i = 0; list[i] != NULL; i++) + free (list[i]); + JCL_free (env, list); + } +#endif +} + +static void +clipboard_clear_func (GtkClipboard *clipboard, + gpointer user_data __attribute__((unused))) +{ + JNIEnv *env = cp_gtk_gdk_env(); + if (clipboard == cp_gtk_clipboard) + (*env)->CallVoidMethod (env, cp_gtk_clipboard_instance, + setSystemContentsID, JNI_TRUE); + else + (*env)->CallVoidMethod (env, cp_gtk_selection_instance, + setSystemContentsID, JNI_TRUE); + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkClipboard_advertiseContent +(JNIEnv *env, + jobject instance, + jobjectArray mime_array, +#if GTK_MINOR_VERSION > 4 + jboolean add_text, jboolean add_images, jboolean add_uris) +#else + jboolean add_text __attribute__((unused)), + jboolean add_images __attribute__((unused)), + jboolean add_uris __attribute__((unused))) +#endif +{ + GtkTargetList *target_list; + GList *list; + GtkTargetEntry *targets; + gint n, i; + + gdk_threads_enter (); + target_list = gtk_target_list_new (NULL, 0); + + if (mime_array != NULL) + { + n = (*env)->GetArrayLength (env, mime_array); + for (i = 0; i < n; i++) + { + const char *text; + jstring target; + GdkAtom atom; + + target = (*env)->GetObjectArrayElement (env, mime_array, i); + if (target == NULL) + break; + text = (*env)->GetStringUTFChars (env, target, NULL); + if (text == NULL) + break; + + atom = gdk_atom_intern (text, FALSE); + gtk_target_list_add (target_list, atom, 0, OBJECT_TARGET); + + (*env)->ReleaseStringUTFChars (env, target, text); + } + } + + /* Add extra targets that gtk+ can provide/translate for us. */ +#if GTK_MINOR_VERSION > 4 + if (add_text) + gtk_target_list_add_text_targets (target_list, TEXT_TARGET); + if (add_images) + gtk_target_list_add_image_targets (target_list, IMAGE_TARGET, TRUE); + if (add_uris) + gtk_target_list_add_uri_targets (target_list, URI_TARGET); +#else + if (add_text) + gtk_target_list_add (target_list, + gdk_atom_intern ("STRING", FALSE), + 0, TEXT_TARGET); +#endif + + + /* Turn list into a target table. */ + n = g_list_length (target_list->list); + if (n > 0) + { + targets = g_new (GtkTargetEntry, n); + for (list = target_list->list, i = 0; + list != NULL; + list = list->next, i++) + { + GtkTargetPair *pair = (GtkTargetPair *) list->data; + targets[i].target = gdk_atom_name (pair->target); + targets[i].flags = pair->flags; + targets[i].info = pair->info; + } + + /* Set the targets plus callback functions and ask for the clipboard + to be stored when the application exists if supported. */ + if ((*env)->IsSameObject(env, instance, cp_gtk_clipboard_instance)) + { + if (gtk_clipboard_set_with_data (cp_gtk_clipboard, targets, n, + clipboard_get_func, + clipboard_clear_func, + NULL)) + { +#if GTK_MINOR_VERSION > 4 + gtk_clipboard_set_can_store (cp_gtk_clipboard, NULL, 0); +#endif + } + } + else + { + if (gtk_clipboard_set_with_data (cp_gtk_selection, targets, n, + clipboard_get_func, + clipboard_clear_func, + NULL)) + { +#if GTK_MINOR_VERSION > 4 + gtk_clipboard_set_can_store (cp_gtk_selection, NULL, 0); +#endif + } + } + + for (i = 0; i < n; i++) + g_free (targets[i].target); + g_free (targets); + } + + gtk_target_list_unref (target_list); + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c new file mode 100644 index 000000000..5de5d82a6 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c @@ -0,0 +1,1260 @@ +/* gtkcomponentpeer.c -- Native implementation of GtkComponentPeer + Copyright (C) 1998, 1999, 2002, 2004, 2006 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> + +#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 + +/* FIXME: use gtk-double-click-time, gtk-double-click-distance */ +#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_MOUSE_WHEEL 507 + +#define AWT_WHEEL_UNIT_SCROLL 0 + +#define AWT_FOCUS_GAINED 1004 +#define AWT_FOCUS_LOST 1005 + +static GtkWidget *find_fg_color_widget (GtkWidget *widget); +static GtkWidget *find_bg_color_widget (GtkWidget *widget); +static GtkWidget *get_widget (GtkWidget *widget); + +static jmethodID postMouseEventID; +static jmethodID postMouseWheelEventID; +static jmethodID postExposeEventID; +static jmethodID postFocusEventID; + +void +cp_gtk_component_init_jni (void) + { + jclass gtkcomponentpeer; + + gtkcomponentpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkComponentPeer"); + + postMouseEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postMouseEvent", "(IJIIIIZ)V"); + + postMouseWheelEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkcomponentpeer, + "postMouseWheelEvent", + "(IJIIIIZIII)V"); + + postExposeEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postExposeEvent", "(IIII)V"); + + postFocusEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postFocusEvent", "(IZ)V"); +} + +static gboolean component_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + jobject peer); +static gboolean component_button_release_cb (GtkWidget *widget, + GdkEventButton *event, + jobject peer); +static gboolean component_motion_notify_cb (GtkWidget *widget, + GdkEventMotion *event, + jobject peer); +static gboolean component_scroll_cb (GtkWidget *widget, + GdkEventScroll *event, + jobject peer); +static gboolean component_enter_notify_cb (GtkWidget *widget, + GdkEventCrossing *event, + jobject peer); +static gboolean component_leave_notify_cb (GtkWidget *widget, + GdkEventCrossing *event, + jobject peer); +static gboolean component_expose_cb (GtkWidget *widget, + GdkEventExpose *event, + jobject peer); +static gboolean component_focus_in_cb (GtkWidget *widget, + GdkEventFocus *event, + jobject peer); +static gboolean component_focus_out_cb (GtkWidget *widget, + GdkEventFocus *event, + jobject peer); + +static jint +button_to_awt_mods (int button) +{ + switch (button) + { + case 1: + return AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; + case 2: + return AWT_BUTTON2_DOWN_MASK | AWT_BUTTON2_MASK; + case 3: + return AWT_BUTTON3_DOWN_MASK | AWT_BUTTON3_MASK; + } + + return 0; +} + +jint +cp_gtk_state_to_awt_mods (guint state) +{ + jint result = 0; + + if (state & GDK_SHIFT_MASK) + result |= (AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK); + if (state & GDK_CONTROL_MASK) + result |= (AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK); + if (state & GDK_MOD1_MASK) + result |= (AWT_ALT_DOWN_MASK | AWT_ALT_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 | AWT_SHIFT_MASK; + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + if (state & GDK_BUTTON1_MASK) + result |= AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; + if (state & GDK_BUTTON2_MASK) + result |= AWT_BUTTON2_DOWN_MASK; + if (state & GDK_BUTTON3_MASK) + result |= AWT_BUTTON3_DOWN_MASK; + + return result; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor + (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked + (env, obj, type, image, x, y); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked + (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) +{ + void *ptr; + GtkWidget *widget; + GdkWindow *win; + GdkCursorType gdk_cursor_type; + GdkCursor *gdk_cursor; + + ptr = gtkpeer_get_widget (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; + } + + widget = get_widget(GTK_WIDGET(ptr)); + + win = widget->window; + if ((widget->window) == NULL) + win = GTK_WIDGET(ptr)->window; + + if (image == NULL) + gdk_cursor = gdk_cursor_new (gdk_cursor_type); + else + gdk_cursor + = gdk_cursor_new_from_pixbuf (gdk_drawable_get_display (win), + cp_gtk_image_get_pixbuf (env, image), + x, y); + + gdk_window_set_cursor (win, gdk_cursor); + gdk_cursor_unref (gdk_cursor); + + /* Make sure the cursor is replaced on screen. */ + gdk_flush(); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + parent_ptr = gtkpeer_get_widget (env, parent); + + widget = GTK_WIDGET (ptr); + parent_widget = get_widget(GTK_WIDGET (parent_ptr)); + + if (widget->parent == NULL) + { + if (GTK_IS_WINDOW (parent_widget)) + { + GList *children = gtk_container_get_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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_set_sensitive (get_widget(GTK_WIDGET (ptr)), sensitive); + + gdk_threads_leave (); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetHasFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = GTK_WIDGET_HAS_FOCUS((GTK_WIDGET (ptr))); + + gdk_threads_leave (); + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetCanFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = GTK_WIDGET_CAN_FOCUS((GTK_WIDGET (ptr))); + + gdk_threads_leave (); + + return retval; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_grab_focus (get_widget(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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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 (get_widget(GTK_WIDGET (ptr)))->event_window; + else if (GTK_IS_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))) + event->key.window = GTK_WIDGET (GTK_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))->container.child)->window; + else + event->key.window = get_widget(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 = cp_gtk_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 (get_widget(GTK_WIDGET (ptr)))) + gtk_widget_event (GTK_WIDGET (GTK_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))->container.child), event); + else + gtk_widget_event (get_widget(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_gtkWindowGetLocationOnScreen + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWindowGetLocationOnScreenUnlocked + (env, obj, jpoint); + + gdk_threads_leave(); + +} +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWindowGetLocationOnScreenUnlocked + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + void *ptr; + jint *point; + + ptr = gtkpeer_get_widget (env, obj); + point = (*env)->GetIntArrayElements (env, jpoint, 0); + + gdk_window_get_root_origin (get_widget(GTK_WIDGET (ptr))->window, point, point+1); + + (*env)->ReleaseIntArrayElements(env, jpoint, point, 0); +} + +/* + * Find the origin of a widget + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreen + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreenUnlocked + (env, obj, jpoint); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreenUnlocked + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + void *ptr; + jint *point; + GtkWidget *widget; + + ptr = gtkpeer_get_widget (env, obj); + point = (*env)->GetIntArrayElements (env, jpoint, 0); + + widget = get_widget(GTK_WIDGET (ptr)); + while(gtk_widget_get_parent(widget) != NULL) + widget = gtk_widget_get_parent(widget); + gdk_window_get_position (GTK_WIDGET(widget)->window, point, point+1); + + *point += GTK_WIDGET(ptr)->allocation.x; + *(point+1) += GTK_WIDGET(ptr)->allocation.y; + + (*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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), &requisition); + + dims[0] = requisition.width; + dims[1] = requisition.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +/* + * 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* 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 (get_widget(GTK_WIDGET (ptr)))) + { + gint width, height; + gtk_window_get_default_size (GTK_WINDOW (get_widget(GTK_WIDGET (ptr))), &width, &height); + + dims[0] = width; + dims[1] = height; + } + else + { + /* Save the widget's current size request. */ + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (get_widget(GTK_WIDGET (ptr)), -1, -1); + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (get_widget(GTK_WIDGET (ptr)), + current_req.width, current_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + } + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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)) + { + gtk_widget_set_size_request (widget, width, height); + /* The GTK_IS_FIXED check here prevents gtk_fixed_move being + called when our parent is a GtkScrolledWindow. In that + case though, moving the child widget is invalid since a + ScrollPane only has one child and that child is always + located at (0, 0) in viewport coordinates. */ + if (widget->parent != NULL && GTK_IS_FIXED (widget->parent)) + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bg = GTK_WIDGET (ptr)->style->bg[GTK_STATE_NORMAL]; + + 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); + + gdk_threads_leave (); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + fg = get_widget(GTK_WIDGET (ptr))->style->fg[GTK_STATE_NORMAL]; + + 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); + + gdk_threads_leave (); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (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; + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + 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_realize (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNative + (JNIEnv *env, jobject obj, jboolean visible) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNativeUnlocked + (env, obj, visible); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNativeUnlocked + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + if (visible) + gtk_widget_show (GTK_WIDGET (ptr)); + else + gtk_widget_hide (GTK_WIDGET (ptr)); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_isEnabled + (JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean ret_val; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + ret_val = GTK_WIDGET_IS_SENSITIVE (get_widget(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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + cp_gtk_component_connect_signals (ptr, gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeEventMask + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_add_events (get_widget(GTK_WIDGET (ptr)), + 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_threads_leave (); +} + +static GtkWidget * +get_widget (GtkWidget *widget) +{ + GtkWidget *w; + + if (GTK_IS_EVENT_BOX (widget)) + w = gtk_bin_get_child (GTK_BIN(widget)); + else + w = widget; + + return w; +} + +/* FIXME: these functions should be implemented by overridding the + appropriate GtkComponentPeer methods. */ +static GtkWidget * +find_fg_color_widget (GtkWidget *widget) +{ + GtkWidget *fg_color_widget; + + if (GTK_IS_EVENT_BOX (widget) + || (GTK_IS_BUTTON (widget) + && !GTK_IS_COMBO_BOX (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; +} + +void +cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "expose-event", + G_CALLBACK (component_expose_cb), gref); +} + +void +cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (component_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (component_focus_out_cb), gref); +} + +void +cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "button-press-event", + G_CALLBACK (component_button_press_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "button-release-event", + G_CALLBACK (component_button_release_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "enter-notify-event", + G_CALLBACK (component_enter_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "leave-notify-event", + G_CALLBACK (component_leave_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "motion-notify-event", + G_CALLBACK (component_motion_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "scroll-event", + G_CALLBACK (component_scroll_cb), gref); +} + +void +cp_gtk_component_connect_signals (GObject *ptr, jobject gref) +{ + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_focus_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); +} + +/* These variables are used to keep track of click counts. The AWT + allows more than a triple click to occur but GTK doesn't report + more-than-triple clicks. Also used for keeping track of scroll events.*/ +static jint click_count = 1; +static guint32 button_click_time = 0; +static GdkWindow *button_window = NULL; +static guint button_number_direction = -1; +static int hasBeenDragged; + +static gboolean +component_button_press_cb (GtkWidget *widget __attribute__((unused)), + GdkEventButton *event, + jobject peer) +{ + /* Ignore double and triple click events. */ + if (event->type == GDK_2BUTTON_PRESS + || event->type == GDK_3BUTTON_PRESS) + return FALSE; + + if ((event->time < (button_click_time + MULTI_CLICK_TIME)) + && (event->window == button_window) + && (event->button == button_number_direction)) + click_count++; + else + click_count = 1; + + button_click_time = event->time; + button_window = event->window; + button_number_direction = event->button; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_PRESSED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + (event->button == 3) ? JNI_TRUE : + JNI_FALSE); + + hasBeenDragged = FALSE; + + return FALSE; +} + +static gboolean +component_button_release_cb (GtkWidget *widget __attribute__((unused)), + GdkEventButton *event, + jobject peer) +{ + int width, height; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_RELEASED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE); + + /* 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_drawable_get_size (event->window, &width, &height); + if (! hasBeenDragged + && event->x >= 0 + && event->y >= 0 + && event->x <= width + && event->y <= height) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_CLICKED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_motion_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventMotion *event, + jobject peer) +{ + if (event->state & (GDK_BUTTON1_MASK + | GDK_BUTTON2_MASK + | GDK_BUTTON3_MASK + | GDK_BUTTON4_MASK + | GDK_BUTTON5_MASK)) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_DRAGGED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + + hasBeenDragged = TRUE; + } + else + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postMouseEventID, + AWT_MOUSE_MOVED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_scroll_cb (GtkWidget *widget __attribute__((unused)), + GdkEventScroll *event, + jobject peer) +{ + int rotation; + /** Record click count for specific direction. */ + if ((event->time < (button_click_time + MULTI_CLICK_TIME)) + && (event->window == button_window) + && (event->direction == button_number_direction)) + click_count++; + else + click_count = 1; + + button_click_time = event->time; + button_window = event->window; + button_number_direction = event->direction; + + if (event->direction == GDK_SCROLL_UP + || event->direction == GDK_SCROLL_LEFT) + rotation = -1; + else + rotation = 1; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseWheelEventID, + AWT_MOUSE_WHEEL, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE, + AWT_WHEEL_UNIT_SCROLL, + 1 /* amount */, + rotation); + return FALSE; +} + +static gboolean +component_enter_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventCrossing *event, + jobject peer) +{ + /* We are not interested in enter events that are due to + grab/ungrab and not to actually crossing boundaries */ + if (event->mode == GDK_CROSSING_NORMAL) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postMouseEventID, + AWT_MOUSE_ENTERED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_leave_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventCrossing *event, + jobject peer) +{ + /* We are not interested in leave events that are due to + grab/ungrab and not to actually crossing boundaries */ + if (event->mode == GDK_CROSSING_NORMAL) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_EXITED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_expose_cb (GtkWidget *widget __attribute__((unused)), + GdkEventExpose *event, + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postExposeEventID, + (jint)event->area.x, + (jint)event->area.y, + (jint)event->area.width, + (jint)event->area.height); + + return FALSE; +} + +static gboolean +component_focus_in_cb (GtkWidget *widget __attribute((unused)), + GdkEventFocus *event __attribute((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postFocusEventID, + AWT_FOCUS_GAINED, + JNI_FALSE); + + return FALSE; +} + +static gboolean +component_focus_out_cb (GtkWidget *widget __attribute((unused)), + GdkEventFocus *event __attribute((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postFocusEventID, + AWT_FOCUS_LOST, + JNI_FALSE); + + return FALSE; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c new file mode 100644 index 000000000..fabadc8ca --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c @@ -0,0 +1,84 @@ +/* gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c -- Native + implementation of GtkEmbeddedWindowPeer + Copyright (C) 2003, 2006 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + window = gtk_plug_new ((GdkNativeWindow) socket_id); + + gtk_window_set_decorated (GTK_WINDOW (window), FALSE); + + fixed = gtk_fixed_new (); + gtk_container_add (GTK_CONTAINER (window), fixed); + + gtk_widget_show (fixed); + + gtkpeer_set_widget (env, obj, window); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_construct + (JNIEnv *env, jobject obj, jlong socket_id) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c new file mode 100644 index 000000000..10f512f29 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c @@ -0,0 +1,302 @@ +/* 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" + +#define AWT_FILEDIALOG_LOAD 0 +#define AWT_FILEDIALOG_SAVE 1 + +static void handle_response_cb (GtkDialog *dialog, + gint responseId, + jobject peer_obj); + +static jmethodID gtkSetFilenameID; +static jmethodID gtkHideFileDialogID; +static jmethodID gtkDisposeFileDialogID; +static jmethodID filenameFilterCallbackID; + +void +cp_gtk_filedialog_init_jni (void) +{ + jclass gtkfiledialogpeer; + + gtkfiledialogpeer = + (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkFileDialogPeer"); + + gtkDisposeFileDialogID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkDisposeFileDialog", "()V"); + + gtkHideFileDialogID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkHideFileDialog", "()V"); + + gtkSetFilenameID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkSetFilename", + "(Ljava/lang/String;)V"); + + filenameFilterCallbackID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "filenameFilterCallback", + "(Ljava/lang/String;)Z"); +} + +/* + * Make a new file selection dialog + */ + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create + (JNIEnv *env, jobject obj, jobject parent, jint mode) +{ + void *parentp; + gpointer widget; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + parentp = gtkpeer_get_widget(env, parent); + + if (mode == AWT_FILEDIALOG_LOAD) + widget = gtk_file_chooser_dialog_new + ("Open File", + GTK_WINDOW(parentp), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + else + { + widget = gtk_file_chooser_dialog_new + ("Save File", + GTK_WINDOW(parentp), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); +#if GTK_MINOR_VERSION >= 8 + gtk_file_chooser_set_do_overwrite_confirmation + (GTK_FILE_CHOOSER (widget), TRUE); +#endif + } + + + /* GtkFileChooserDialog 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 (cp_gtk_global_window_group, + GTK_WINDOW (widget)); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NULL; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* FileDialog signals */ + g_signal_connect (G_OBJECT (ptr), "response", + G_CALLBACK (handle_response_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (ptr), gref); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeGetDirectory + (JNIEnv *env, jobject obj) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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 filename_filter_cb (const GtkFileFilterInfo *filter_info, + gpointer obj) +{ + jstring *filename; + gboolean accepted; + + filename = (*cp_gtk_gdk_env())->NewStringUTF(cp_gtk_gdk_env(), filter_info->filename); + + accepted = (*cp_gtk_gdk_env())->CallBooleanMethod(cp_gtk_gdk_env(), obj, + filenameFilterCallbackID, + filename); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + filter = gtk_file_filter_new(); + gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, + filename_filter_cb, 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, directory, 0); + + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(ptr), str); + + (*env)->ReleaseStringUTFChars (env, directory, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile + (JNIEnv *env, jobject obj, jstring filename) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, filename, 0); + + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (ptr), str); + + (*env)->ReleaseStringUTFChars (env, filename, str); + + gdk_threads_leave (); +} + +static void +handle_response_cb (GtkDialog *dialog __attribute__((unused)), + gint responseId, + jobject peer_obj) +{ + 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 = gtkpeer_get_widget (cp_gtk_gdk_env(), peer_obj); + + if (responseId == GTK_RESPONSE_DELETE_EVENT) + { + /* We can dispose of the dialog now (and unblock show) */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkDisposeFileDialogID); + + return; + } + + if (responseId == GTK_RESPONSE_ACCEPT) + { + fileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (GTK_WIDGET (ptr))); + str_fileName = (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), fileName); + } + + /* Set the Java object field 'file' with this value. */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkSetFilenameID, str_fileName); + + /* We can hide the dialog now (and unblock show) */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkHideFileDialogID); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c new file mode 100644 index 000000000..ef7df0f03 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c @@ -0,0 +1,234 @@ +/* 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (menubar) + { + mptr = gtkpeer_get_widget (env, menubar); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, menubar); + + 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, jobject menubar, jint width) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidthUnlocked + (env, obj, menubar, width); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidthUnlocked + (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar, jint width) +{ + GtkWidget *ptr; + GtkRequisition natural_req; + + if (menubar) + { + ptr = gtkpeer_get_widget (env, menubar); + + /* 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); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkFixedSetVisible + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + void *fixed; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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_nativeSetIconImage + (JNIEnv *env, jobject obj, jobject gtkimage) +{ + void *ptr; + GdkPixbuf *pixbuf = NULL; + + gdk_threads_enter (); + + pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage); + g_assert (pixbuf != NULL); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_maximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_maximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_unmaximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_unmaximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_iconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_iconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_deiconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_deiconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c new file mode 100644 index 000000000..e0ba50849 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c @@ -0,0 +1,100 @@ +/* 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_initIDs +(JNIEnv *env, jclass clz __attribute__((unused))) +{ + gtkpeer_init_widget_IDs(env); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + /* 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)); + + /* Delete global reference. */ + gtkpeer_del_global_ref(env, obj); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_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); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c new file mode 100644 index 000000000..0b0dbec4b --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c @@ -0,0 +1,434 @@ +/* gtkimage.c + Copyright (C) 2005, 2006, 2007 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 "jcl.h" +#include "gtkpeer.h" + +#include "gnu_java_awt_peer_gtk_GtkImage.h" + +/* The constant fields in java.awt.Image */ +#define SCALE_DEFAULT 1 +#define SCALE_FAST 2 +#define SCALE_SMOOTH 4 +#define SCALE_REPLICATE 8 +#define SCALE_AREA_AVERAGING 16 + +/* local stuff */ +static GdkInterpType mapHints(jint hints); +static void createRawData (JNIEnv * env, jobject obj, void *ptr); +static void setWidthHeight (JNIEnv * env, jobject obj, int width, int height); + +/** + * Loads a pixbuf from a file. + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_loadPixbuf + (JNIEnv *env, jobject obj, jstring name) +{ + const char *filename; + int width, height; + GdkPixbuf *pixbuf; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + + if (filename == NULL) + return JNI_FALSE; + + pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + if (pixbuf == NULL) + { + (*env)->ReleaseStringUTFChars (env, name, filename); + return JNI_FALSE; + } + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + createRawData (env, obj, pixbuf); + setWidthHeight(env, obj, width, height); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return JNI_TRUE; +} + +/* + * Creates the image from an array of java bytes. + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_loadImageFromData + (JNIEnv *env, jobject obj, jbyteArray data) +{ + jbyte *src; + GdkPixbuf* pixbuf; + GdkPixbufLoader* loader; + int len; + int width; + int height; + + src = (*env)->GetByteArrayElements (env, data, NULL); + len = (*env)->GetArrayLength (env, data); + + loader = gdk_pixbuf_loader_new (); + + gdk_pixbuf_loader_write (loader, (guchar *)src, len, NULL); + gdk_pixbuf_loader_close (loader, NULL); + + (*env)->ReleaseByteArrayElements (env, data, src, 0); + + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + + if (pixbuf == NULL) + { + g_object_unref (loader); + createRawData (env, obj, NULL); + return JNI_FALSE; + } + + g_object_ref (pixbuf); + g_object_unref (loader); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + createRawData (env, obj, pixbuf); + setWidthHeight(env, obj, width, height); + + return JNI_TRUE; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createFromPixbuf +(JNIEnv *env, jobject obj) +{ + int width, heigth; + GdkPixbuf *pixbuf = cp_gtk_image_get_pixbuf (env, obj); + width = gdk_pixbuf_get_width (pixbuf); + heigth = gdk_pixbuf_get_height (pixbuf); + setWidthHeight(env, obj, width, heigth); +} + +/** + * Returns a copy of the pixel data as a java array. + */ +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_getPixels(JNIEnv *env, jobject obj) +{ + GdkPixbuf *pixbuf; + int width, height, rowstride; + guchar *pixeldata; + jintArray result_array; + jint *result_array_iter, *dst; + int i,j; + + gdk_threads_enter (); + + pixbuf = cp_gtk_image_get_pixbuf (env, obj); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + result_array = (*env)->NewIntArray (env, (width * height)); + if (result_array == NULL) + { + gdk_threads_leave (); + return NULL; + } + + dst = result_array_iter = + (*env)->GetIntArrayElements (env, result_array, NULL); + + + pixeldata = gdk_pixbuf_get_pixels (pixbuf); + + g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); + + if (gdk_pixbuf_get_has_alpha (pixbuf)) + { + for(i = 0 ; i < height; i++) + { + memcpy(dst, (void *)pixeldata, width * 4); + dst += width; + pixeldata += rowstride; + } + } else { + + /* Add a default alpha value of 0xFF to the pixeldata without alpha + information and keep it in the same format as the pixeldata with alpha + information. On Little Endian systems: AABBGGRR and on Big Endian + systems: RRGGBBAA. */ + + for(i = 0; i < height; i++) + { + for(j = 0; j < width; j++) + +#ifndef WORDS_BIGENDIAN + dst[j] = 0xFF000000 + | (pixeldata[j*3 + 2] & 0xFF) << 16 + | (pixeldata[j*3 + 1] & 0xFF) << 8 + | (pixeldata[j*3] & 0xFF); +#else + dst[j] = (pixeldata[j*3] & 0xFF) << 24 + | (pixeldata[j*3 + 1] & 0xFF) << 16 + | (pixeldata[j*3 + 2] & 0xFF) << 8 + | 0xFF; +#endif + dst += width; + pixeldata += rowstride; + } + } + + (*env)->ReleaseIntArrayElements (env, result_array, result_array_iter, 0); + + gdk_threads_leave (); + return result_array; +} + +/** + * Returns a copy of the pixel data as a java array. + * (GdkPixbuf only) + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_setPixels(JNIEnv *env, jobject obj, + jintArray pixels) +{ + GdkPixbuf *pixbuf = cp_gtk_image_get_pixbuf (env, obj); + int width, height, rowstride; + guchar *pixeldata; + jint *src_array_iter, *src; + int i; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + src = src_array_iter = + (*env)->GetIntArrayElements (env, pixels, NULL); + + pixeldata = gdk_pixbuf_get_pixels (pixbuf); + for(i = 0 ; i < height; i++) + { + memcpy((void *)pixeldata, (void *)src, width * 4); + src += width; + pixeldata += rowstride; + } + + (*env)->ReleaseIntArrayElements (env, pixels, src_array_iter, 0); +} + +/** + * Allocates a Gtk Pixbuf + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createPixbuf(JNIEnv *env, jobject obj) +{ + int width, height; + jclass cls; + jfieldID field; + + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + createRawData (env, obj, gdk_pixbuf_new (GDK_COLORSPACE_RGB, + TRUE, + 8, + width, + height)); +} + +/** + * Allocates a Gtk Pixbuf + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_initFromBuffer(JNIEnv *env, jobject obj, + jlong bufferPointer) +{ + int width, height; + jclass cls; + jfieldID field; + GdkPixbuf *pixbuf; + const guchar *bp = JLONG_TO_PTR(const guchar, bufferPointer); + + g_assert(bp != NULL); + cls = (*env)->GetObjectClass( env, obj ); + field = (*env)->GetFieldID( env, cls, "width", "I" ); + g_assert( field != 0 ); + width = (*env)->GetIntField( env, obj, field ); + + field = (*env)->GetFieldID( env, cls, "height", "I" ); + g_assert( field != 0 ); + height = (*env)->GetIntField( env, obj, field ); + + pixbuf = gdk_pixbuf_new_from_data( bp, + GDK_COLORSPACE_RGB, TRUE, 8, + width, height, width * 4, NULL, NULL ); + g_assert( pixbuf != NULL ); + createRawData( env, obj, pixbuf ); +} + +/** + * Frees the Gtk Pixbuf. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_freePixbuf(JNIEnv *env, jobject obj) +{ + g_object_unref (cp_gtk_image_get_pixbuf (env, obj)); +} + +/** + * Sets this to a scaled version of the original pixbuf + * width and height of the destination GtkImage must be set. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createScaledPixbuf(JNIEnv *env, + jobject destination, + jobject source, + jint hints) +{ + GdkPixbuf* dst; + int width, height; + jclass cls; + jfieldID field; + + GdkPixbuf *pixbuf; + + cls = (*env)->GetObjectClass (env, destination); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, destination, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, destination, field); + + pixbuf = cp_gtk_image_get_pixbuf (env, source); + + dst = gdk_pixbuf_scale_simple(pixbuf, + width, height, + mapHints(hints)); + + createRawData (env, destination, (void *)dst); +} + +/** + * Used by GtkFramePeer + */ +GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj) +{ + jclass cls; + jfieldID data_fid; + jobject data; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "pixbuf", + "Lgnu/classpath/Pointer;"); + g_assert (data_fid != 0); + data = (*env)->GetObjectField (env, obj, data_fid); + + if (data == NULL) + return NULL; + + return (GdkPixbuf *)JCL_GetRawData (env, data); +} + +/** + * Maps java.awt.Image scaling hints to the native GDK ones. + */ +static GdkInterpType mapHints(jint hints) +{ + switch ( hints ) + { + /* For FAST, we use the nearest-neighbor. Fastest and lowest quality. */ + case SCALE_FAST: + case SCALE_REPLICATE: + return GDK_INTERP_NEAREST; + + /* Hyperbolic for smooth. Slowest too. */ + case SCALE_SMOOTH: + return GDK_INTERP_HYPER; + + /* the inbetweenish method */ + case SCALE_AREA_AVERAGING: + return GDK_INTERP_TILES; + + /* default to bilinear */ + } + return GDK_INTERP_BILINEAR; +} + +/* Sets the width and height fields of a GtkImage object. */ +static void setWidthHeight (JNIEnv * env, jobject obj, int width, int height) +{ + jclass cls; + jfieldID field; + + cls = (*env)->GetObjectClass (env, obj); + g_assert (cls != 0); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + (*env)->SetIntField (env, obj, field, (jint)width); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + (*env)->SetIntField (env, obj, field, (jint)height); +} + +/* Store and get the pixbuf pointer */ +static void +createRawData (JNIEnv * env, jobject obj, void *ptr) +{ + jclass cls; + jobject data; + jfieldID data_fid; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "pixbuf", + "Lgnu/classpath/Pointer;"); + g_assert (data_fid != 0); + + data = JCL_NewRawDataObject (env, ptr); + + (*env)->SetObjectField (env, obj, data_fid, data); +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c new file mode 100644 index 000000000..3703858fe --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c @@ -0,0 +1,221 @@ +/* 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, text, 0); + + 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); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkWidget *label; + GtkRequisition current_req; + GtkRequisition natural_req; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* Save the widget's current size request. */ + gtk_widget_size_request (GTK_WIDGET (label), ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1); + gtk_widget_size_request (GTK_WIDGET (label), &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), + current_req.width, current_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + if (!label) + { + gdk_threads_leave (); + return; + } + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_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); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText + (JNIEnv *env, jobject obj, jstring text) +{ + const char *str; + void *ptr; + GtkWidget *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, text, 0); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + gtk_label_set_label (GTK_LABEL (label), str); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment + (JNIEnv *env, jobject obj, jfloat xalign) +{ + void *ptr; + GtkWidget *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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_IS_FIXED (widget->parent)) + gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); + } + + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c new file mode 100644 index 000000000..4b7b63e6d --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c @@ -0,0 +1,549 @@ +/* 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" + +static jmethodID postListItemEventID; +static GtkWidget *list_get_widget (GtkWidget *widget); + +void +cp_gtk_list_init_jni (void) +{ + jclass gtklistpeer; + + gtklistpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkListPeer"); + + postListItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtklistpeer, + "postItemEvent", + "(II)V"); +} + +enum + { + COLUMN_STRING, + N_COLUMNS + }; + +static gboolean item_highlighted_cb (GtkTreeSelection *selection, + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + jobject peer); + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_create + (JNIEnv *env, jobject obj, jint rows) +{ + GtkWidget *sw; + GtkWidget *list; + GtkWidget *eventbox; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkListStore *list_store; + GtkTreeIter iter; + GtkRequisition req; + gint i; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + 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); + + eventbox = gtk_event_box_new (); + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + + 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); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + GtkWidget *list; + GtkTreeSelection *selection; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + gtk_tree_selection_set_select_function (selection, item_highlighted_cb, + gref, NULL); + + cp_gtk_component_connect_signals (G_OBJECT (list), gref); + + 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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (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 * cp_gtk_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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (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; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + jint count; + jint i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + count = (*env)->GetArrayLength (env, items); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (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); + (*env)->DeleteLocalRef(env, item); + } + + 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; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, text, NULL); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (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); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gdk_threads_leave (); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_delItems + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + jint i; + jint num_items; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (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; + GtkWidget *list; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + path = gtk_tree_path_new_from_indices (index, -1); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (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; + GtkWidget *list; + GtkTreeSelection *selection; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (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; + GtkWidget* bin; + + gdk_threads_enter (); + + dims = (*env)->GetIntArrayElements (env, jdims, NULL); + dims[0] = dims[1] = 0; + + ptr = gtkpeer_get_widget (env, obj); + bin = list_get_widget (GTK_WIDGET (ptr)); + + /* Save the widget's current size request. */ + gtk_widget_size_request (bin, ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); + gtk_widget_size_request (bin, &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (bin, + 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; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_getSelectedIndexes + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *list; + GtkTreeSelection *selection; + jintArray result_array; + jint *result_array_iter; + GList *current_row; + GList *rows; + gint *indices; + jint count; + jint i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (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); + } + + (*env)->ReleaseIntArrayElements (env, result_array, result_array_iter, 0); + } + else + result_array = NULL; + + gdk_threads_leave (); + + return result_array; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_makeVisible + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *list; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + path = gtk_tree_path_new_from_indices (index, -1); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (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; + GtkWidget *list; + GtkTreeSelection *selection; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + gtk_tree_selection_set_mode (selection, + mode ? GTK_SELECTION_MULTIPLE + : GTK_SELECTION_SINGLE); + + gdk_threads_leave (); +} + +static gboolean +item_highlighted_cb (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) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postListItemEventID, + row, + (jint) AWT_ITEM_SELECTED); + } + else + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postListItemEventID, + row, + (jint) AWT_ITEM_DESELECTED); + } + } + + return TRUE; +} + +static GtkWidget * +list_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + + wid = gtk_bin_get_child (GTK_BIN (widget)); + g_assert (GTK_IS_SCROLLED_WINDOW (wid)); + + wid = gtk_bin_get_child (GTK_BIN (wid)); + + return wid; +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c new file mode 100644 index 000000000..ac3fab78b --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c @@ -0,0 +1,92 @@ +/* gtkmenubarpeer.c -- Native implementation of GtkMenuBarPeer + Copyright (C) 1999, 2006 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + widget = gtk_menu_bar_new (); + gtk_widget_show (widget); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu + (JNIEnv *env, jobject obj, jobject menupeer) +{ + void *mbar, *menu; + + gdk_threads_enter (); + + mbar = gtkpeer_get_widget (env, obj); + menu = gtkpeer_get_widget (env, menupeer); + + gtk_menu_shell_append (GTK_MENU_SHELL (mbar), GTK_WIDGET (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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = gtk_container_get_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/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c new file mode 100644 index 000000000..6da949488 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c @@ -0,0 +1,55 @@ +/* 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. */ + + gtkpeer_del_global_ref (env, obj); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c new file mode 100644 index 000000000..965435545 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c @@ -0,0 +1,191 @@ +/* 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 jmethodID postMenuActionEventID; + +void +cp_gtk_menuitem_init_jni (void) +{ + jclass gtkmenuitempeer; + + gtkmenuitempeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkMenuItemPeer"); + + postMenuActionEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkmenuitempeer, + "postMenuActionEvent", + "()V"); +} + +static void item_activate_cb (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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + /* "-" 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); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + g_signal_connect (G_OBJECT (ptr), "activate", + G_CALLBACK (item_activate_cb), 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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + 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 * cp_gtk_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); + } + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setEnabled + (JNIEnv *env, jobject obj, jboolean enabled) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + accel_label = GTK_ACCEL_LABEL (GTK_BIN (ptr)->child); + + gtk_label_set_text (GTK_LABEL (accel_label), str); + gtk_accel_label_refetch (accel_label); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gdk_threads_leave (); +} + +static void +item_activate_cb (GtkMenuItem *item __attribute__((unused)), jobject peer_obj) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + postMenuActionEventID); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c new file mode 100644 index 000000000..1081de253 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c @@ -0,0 +1,176 @@ +/* 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; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + + if (!parent) + { + gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), + gtk_accel_group_new ()); + } + else + { + GtkAccelGroup *parent_accel; + + ptr2 = gtkpeer_get_widget (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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + 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 (cp_gtk_global_window_group, + GTK_WINDOW(toplevel)); + } + + gtk_widget_show (menu_title); + + gtkpeer_set_widget (env, obj, menu_title); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addTearOff + (JNIEnv *env, jobject obj) +{ + void *ptr1; + GtkWidget *menu, *item; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + ptr2 = gtkpeer_get_widget (env, menuitempeer); + + 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; + GtkWidget *menu; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr)); + + list = gtk_container_get_children (GTK_CONTAINER (menu)); + list = g_list_nth (list, index); + gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (list->data)); + + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c new file mode 100644 index 000000000..e52e6de51 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c @@ -0,0 +1,112 @@ +/* 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" + +static gboolean panel_focus_in_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); +static gboolean panel_focus_out_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create + (JNIEnv *env, jobject obj) +{ + GtkWidget *widget; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + widget = gtk_fixed_new (); + + gtk_fixed_set_has_window (GTK_FIXED (widget), TRUE); + + GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* Panel signals. These callbacks prevent expose events being + delivered to the panel when it is focused. */ + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (panel_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (panel_focus_out_cb), gref); + + /* Component signals. Exclude focus signals. */ + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); + + gdk_threads_leave (); +} + +static gboolean +panel_focus_in_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer __attribute__((unused))) +{ + return TRUE; +} + +static gboolean +panel_focus_out_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer __attribute__((unused))) +{ + return TRUE; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c new file mode 100644 index 000000000..0511c051a --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c @@ -0,0 +1,110 @@ +/* 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + p = g_malloc (sizeof (struct pos)); + p->x = x; + p->y = y; + + gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu), + NULL, NULL, menu_pos, p, 0, time); + + g_free (p); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup + (JNIEnv *env, jobject obj, jobject parent __attribute__((unused))) +{ + void *ptr1; + GtkMenu *menu; +#if 0 + void *ptr2; +#endif + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + + 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. */ + // FIXME: _gtk_accel_group_attach is a GTK-private function, so + // we'll need a different approach here +#if 0 + ptr2 = gtkpeer_get_widget (env, parent); + _gtk_accel_group_attach (gtk_menu_get_accel_group (menu), + G_OBJECT (gtk_widget_get_toplevel (ptr2))); +#endif + + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c new file mode 100644 index 000000000..0d67b0b78 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c @@ -0,0 +1,222 @@ +/* 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" + +#define AWT_SCROLLPANE_SCROLLBARS_AS_NEEDED 0 +#define AWT_SCROLLPANE_SCROLLBARS_ALWAYS 1 +#define AWT_SCROLLPANE_SCROLLBARS_NEVER 2 + +static GtkWidget *scrollpane_get_widget (GtkWidget *widget); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_create + (JNIEnv *env, jobject obj, int width, int height) +{ + GtkWidget *sw; + GtkWidget *eventbox; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_set_size_request (sw, width, height); + eventbox = gtk_event_box_new (); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + gtk_widget_show (sw); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (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; + GtkWidget *sw; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (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; + } + + sw = scrollpane_get_widget (GTK_WIDGET (ptr)); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), policy, policy); + + gdk_threads_leave (); +} + +static GtkWidget * +scrollpane_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c new file mode 100644 index 000000000..64d91d2b2 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c @@ -0,0 +1,296 @@ +/* gtkscrollbarpeer.c -- Native implementation of GtkScrollbarPeer + Copyright (C) 1998, 1999, 2006 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 <math.h> +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" +#include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h" + +#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 + +static jmethodID postAdjustmentEventID; +static GtkWidget *scrollbar_get_widget (GtkWidget *widget); + +void +cp_gtk_scrollbar_init_jni (void) +{ + jclass gtkscrollbarpeer; + + gtkscrollbarpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkScrollbarPeer"); + + postAdjustmentEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkscrollbarpeer, + "postAdjustmentEvent", + "(II)V"); +} + +#if GTK_MINOR_VERSION > 4 +static gboolean slider_moved_cb (GtkRange *range, + GtkScrollType scroll, + gdouble value, + jobject obj); +#else +static void post_change_event_cb (GtkRange *range, + jobject peer); +#endif + +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; + GtkWidget *eventbox; + GtkObject *adj; + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + gdk_threads_enter (); + + /* A little hack because gtk_range_set_range() doesn't allow min == max. */ + if (min == max) + { + if (visible_amount == 0) + visible_amount = 1; + max++; + } + + 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)); + eventbox = gtk_event_box_new (); + gtk_container_add (GTK_CONTAINER (eventbox), scrollbar); + gtk_widget_show (scrollbar); + + 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 (); + + gtkpeer_set_widget (env, obj, eventbox); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = gtkpeer_get_widget (env, obj); + GtkWidget *wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + jobject gref = gtkpeer_get_global_ref (env, obj); + g_assert (gref); + + gdk_threads_enter (); + + /* Scrollbar signals */ +#if GTK_MINOR_VERSION > 4 + g_signal_connect (G_OBJECT (wid), "change-value", + G_CALLBACK (slider_moved_cb), gref); +#else + g_signal_connect (G_OBJECT (wid), "value-changed", + G_CALLBACK (post_change_event_cb), gref); +#endif + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (wid), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setLineIncrement + (JNIEnv *env, jobject obj, jint amount) +{ + void *ptr; + GtkAdjustment *adj; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + 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; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + adj->page_increment = (gdouble) amount; + gtk_adjustment_changed (adj); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setBarValues + (JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max) +{ + void *ptr; + GtkAdjustment *adj; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + /* A little hack because gtk_range_set_range() doesn't allow min == max. */ + if (min == max) + { + if (visible == 0) + visible = 1; + max++; + } + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + adj->page_size = (gdouble) visible; + + gtk_range_set_range (GTK_RANGE (wid), (gdouble) min, (gdouble) max); + gtk_range_set_value (GTK_RANGE (wid), (gdouble) value); + + gdk_threads_leave (); +} + +#if GTK_MINOR_VERSION > 4 +static gboolean +slider_moved_cb (GtkRange *range, + GtkScrollType scroll, + gdouble value, + jobject obj) +{ + GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range)); + + value = CLAMP (value, adj->lower, + (adj->upper - adj->page_size)); + + if (range->round_digits >= 0) + { + gdouble power; + gint i; + + i = range->round_digits; + power = 1; + while (i--) + power *= 10; + + value = floor ((value * power) + 0.5) / power; + } + + switch (scroll) + { + case GTK_SCROLL_STEP_BACKWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_UNIT_DECREMENT, + (jint) value); + break; + case GTK_SCROLL_STEP_FORWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_UNIT_INCREMENT, + (jint) value); + break; + case GTK_SCROLL_PAGE_BACKWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_BLOCK_DECREMENT, + (jint) value); + break; + case GTK_SCROLL_PAGE_FORWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_BLOCK_INCREMENT, + (jint) value); + break; + default: + /* GTK_SCROLL_JUMP: */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_TRACK, + (jint) value); + break; + } + return FALSE; +} +#else +static void +post_change_event_cb (GtkRange *range, jobject peer) +{ + GtkAdjustment *adj; + adj = gtk_range_get_adjustment (range); + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postAdjustmentEventID, + AWT_ADJUSTMENT_TRACK, (jint) adj->value); +} +#endif + +static GtkWidget * +scrollbar_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c new file mode 100644 index 000000000..e5ba4c7b1 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c @@ -0,0 +1,489 @@ +/* gtkselection.c -- Native C functions for GtkSelection class using gtk+. + Copyright (C) 2005, 2006 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 "jcl.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkSelection.h" + +static jmethodID mimeTypesAvailableID; + +/* Note this is actually just a GtkClipboardReceivedFunc, not a real + GtkClipboardTargetsReceivedFunc, see requestMimeTypes. */ +static void +clipboard_targets_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *target_data, + gpointer selection) +{ + GdkAtom *targets = NULL; + gint targets_len = 0; + gchar **target_strings = NULL; + jobjectArray strings = NULL; + int strings_len = 0; + gboolean include_text = FALSE; + gboolean include_image = FALSE; + gboolean include_uris = FALSE; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (target_data != NULL && target_data->length > 0) + { + include_text = gtk_selection_data_targets_include_text (target_data); + +#if GTK_MINOR_VERSION > 4 + include_image = gtk_selection_data_targets_include_image (target_data, + TRUE); +#endif + if (gtk_selection_data_get_targets (target_data, &targets, &targets_len)) + { + int i; + GdkAtom uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE); + target_strings = g_new (gchar*, targets_len); + if (target_strings != NULL) + for (i = 0; i < targets_len; i++) + { + gchar *name = gdk_atom_name (targets[i]); + if (strchr (name, '/') != NULL) + { + target_strings[i] = name; + strings_len++; + if (! include_uris && targets[i] == uri_list_atom) + include_uris = TRUE; + } + else + target_strings[i] = NULL; + } + } + + if (target_strings != NULL) + { + int i = 0, j = 0; + jclass stringClass; + + if (include_text) + strings_len++; + if (include_image) + strings_len++; + if (include_uris) + strings_len++; + + stringClass = (*env)->FindClass (env, "java/lang/String"); + strings = (*env)->NewObjectArray (env, strings_len, stringClass, + NULL); + (*env)->DeleteLocalRef(env, stringClass); + + if (strings != NULL) + { + if (include_text) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_stringTarget); + if (include_image) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_imageTarget); + if (include_uris) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_filesTarget); + + while(i < strings_len) + { + if (target_strings[j] == NULL) + j++; + else + { + jstring string; + string = (*env)->NewStringUTF (env, + target_strings[j++]); + if (string == NULL) + break; + (*env)->SetObjectArrayElement (env, strings, i++, + string); + (*env)->DeleteLocalRef (env, string); + } + } + + (*env)->DeleteLocalRef(env, strings); + } + + for (i = 0; i < targets_len; i++) + g_free (target_strings[i]); + g_free (target_strings); + } + } + + (*env)->CallVoidMethod (env, selection_obj, + mimeTypesAvailableID, + strings); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestMimeTypes +(JNIEnv *env, jobject selection, jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, selection); + if (selection_obj == NULL) + return; + + if (mimeTypesAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + mimeTypesAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "mimeTypesAvailable", + "([Ljava/lang/String;)V"); + if (mimeTypesAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + /* We would have liked to call gtk_clipboard_request_targets () + since that is more general. But the result of that, an array of + GdkAtoms, cannot be used with the + gtk_selection_data_targets_include_<x> functions (despite what + the name suggests). */ + gdk_threads_enter (); + gtk_clipboard_request_contents (gtk_clipboard, + gdk_atom_intern ("TARGETS", FALSE), + clipboard_targets_received, + (gpointer) selection_obj); + gdk_threads_leave (); +} + + +static jmethodID textAvailableID; + +static void +clipboard_text_received (GtkClipboard *clipboard + __attribute__((unused)), + const gchar *text, + gpointer selection) +{ + jstring string; + jobject selection_obj = (jobject) selection; + + JNIEnv *env = cp_gtk_gdk_env (); + if (text != NULL) + string = (*env)->NewStringUTF (env, text); + else + string = NULL; + + (*env)->CallVoidMethod (env, selection_obj, + textAvailableID, + string); + (*env)->DeleteGlobalRef (env, selection_obj); + + if (string != NULL) + (*env)->DeleteLocalRef (env, string); + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestText +(JNIEnv *env, jobject selection, jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, selection); + if (selection_obj == NULL) + return; + + if (textAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + textAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "textAvailable", + "(Ljava/lang/String;)V"); + if (textAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + gdk_threads_enter (); + gtk_clipboard_request_text (gtk_clipboard, + clipboard_text_received, + (gpointer) selection_obj); + gdk_threads_leave (); +} + +static jmethodID imageAvailableID; + +static void +clipboard_image_received (GtkClipboard *clipboard + __attribute__((unused)), + GdkPixbuf *pixbuf, + gpointer selection) +{ + jobject pointer = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (pixbuf != NULL) + { + g_object_ref (pixbuf); + pointer = JCL_NewRawDataObject (env, (void *) pixbuf); + } + + (*env)->CallVoidMethod (env, selection_obj, + imageAvailableID, + pointer); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestImage (JNIEnv *env, + jobject obj, + jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (imageAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + imageAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "imageAvailable", + "(Lgnu/classpath/Pointer;)V"); + if (imageAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + +#if GTK_MINOR_VERSION > 4 + gdk_threads_enter (); + gtk_clipboard_request_image (gtk_clipboard, + clipboard_image_received, + (gpointer) selection_obj); + gdk_threads_leave (); +#else + clipboard_image_received (gtk_clipboard, NULL, (gpointer) selection_obj); +#endif +} + +static jmethodID urisAvailableID; + +static void +clipboard_uris_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *uri_data, + gpointer selection) +{ + gchar **uris = NULL; + jobjectArray strings = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + +#if GTK_MINOR_VERSION > 4 + if (uri_data != NULL) + uris = gtk_selection_data_get_uris (uri_data); +#else + if (uri_data != NULL) + uris = NULL; +#endif + + if (uris != NULL) + { + int len, i; + gchar **count = uris; + jclass stringClass = (*env)->FindClass (env, "java/lang/String"); + + len = 0; + while (count[len]) + len++; + + strings = (*env)->NewObjectArray (env, len, stringClass, NULL); + (*env)->DeleteLocalRef(env, stringClass); + + if (strings != NULL) + { + for (i = 0; i < len; i++) + { + jstring string = (*env)->NewStringUTF (env, uris[i]); + if (string == NULL) + break; + (*env)->SetObjectArrayElement (env, strings, i, string); + (*env)->DeleteLocalRef (env, string); + } + + (*env)->DeleteLocalRef(env, strings); + } + g_strfreev (uris); + } + + (*env)->CallVoidMethod (env, selection_obj, + urisAvailableID, + strings); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestURIs (JNIEnv *env, + jobject obj, + jboolean clipboard) +{ +#if GTK_MINOR_VERSION > 4 + GdkAtom uri_atom; +#endif + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (urisAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + urisAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "urisAvailable", + "([Ljava/lang/String;)V"); + if (urisAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + +#if GTK_MINOR_VERSION > 4 + /* There is no real request_uris so we have to make one ourselves. */ + gdk_threads_enter (); + uri_atom = gdk_atom_intern ("text/uri-list", FALSE); + gtk_clipboard_request_contents (gtk_clipboard, + uri_atom, + clipboard_uris_received, + (gpointer) selection_obj); + gdk_threads_leave (); +#else + clipboard_uris_received (gtk_clipboard, NULL, (gpointer) selection_obj); +#endif +} + +static jmethodID bytesAvailableID; + +static void +clipboard_bytes_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *selection_data, + gpointer selection) +{ + jbyteArray bytes = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (selection_data != NULL && selection_data->length > 0) + { + bytes = (*env)->NewByteArray (env, selection_data->length); + if (bytes != NULL) + (*env)->SetByteArrayRegion(env, bytes, 0, selection_data->length, + (jbyte *) selection_data->data); + } + + (*env)->CallVoidMethod (env, selection_obj, + bytesAvailableID, + bytes); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestBytes (JNIEnv *env, + jobject obj, + jboolean clipboard, + jstring target_string) +{ + int len; + const gchar *target_text; + GdkAtom target_atom; + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (bytesAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + bytesAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "bytesAvailable", + "([B)V"); + if (bytesAvailableID == NULL) + return; + } + + len = (*env)->GetStringUTFLength (env, target_string); + if (len == -1) + return; + target_text = (*env)->GetStringUTFChars (env, target_string, NULL); + if (target_text == NULL) + return; + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + gdk_threads_enter (); + target_atom = gdk_atom_intern (target_text, FALSE); + gtk_clipboard_request_contents (gtk_clipboard, + target_atom, + clipboard_bytes_received, + (gpointer) selection_obj); + gdk_threads_leave (); + + (*env)->ReleaseStringUTFChars (env, target_string, target_text); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c new file mode 100644 index 000000000..4d768fa33 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c @@ -0,0 +1,547 @@ +/* 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 AWT_TEXTAREA_SCROLLBARS_BOTH 0 +#define AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY 1 +#define AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY 2 + +static GtkWidget *textarea_get_widget (GtkWidget *widget); + +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; + GtkWidget *sw; + GtkWidget *eventbox; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + 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); + + eventbox = gtk_event_box_new (); + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (sw), text); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + gtk_widget_show (sw); + + 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); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + GtkWidget *text = NULL; + GtkTextBuffer *buf; + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* Unwrap the text view from the scrolled window */ + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + /* TextComponent signals */ + cp_gtk_textcomponent_connect_signals (G_OBJECT (buf), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (text), gref); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_get_iter_at_offset (buf, &iter, position); + gtk_text_buffer_insert (buf, &iter, str, strlen (str)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (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)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (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 * cp_gtk_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); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *text; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (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; + GtkWidget *bin; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint height = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bin = gtk_bin_get_child (GTK_BIN (ptr)); + sw = GTK_SCROLLED_WINDOW (bin); + + 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; + GtkWidget *bin; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint width = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bin = gtk_bin_get_child (GTK_BIN (ptr)); + sw = GTK_SCROLLED_WINDOW (bin); + + 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; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getCaretPosition + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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_GtkTextAreaPeer_setCaretPosition + (JNIEnv *env, jobject obj, jint pos) +{ + void *ptr; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter iter; + GtkTextMark *oldmark; + GtkTextIter olditer; + int oldpos; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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_GtkTextAreaPeer_getSelectionStart + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start; + GtkTextIter end; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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_GtkTextAreaPeer_getSelectionEnd + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start; + GtkTextIter end; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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_GtkTextAreaPeer_select + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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_GtkTextAreaPeer_setEditable + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + GtkWidget *text = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + gtk_text_view_set_editable (GTK_TEXT_VIEW (text), state); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getText + (JNIEnv *env, jobject obj) +{ + void *ptr; + char *contents = NULL; + jstring jcontents; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start, end; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + 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); + + jcontents = (*env)->NewStringUTF (env, contents); + g_free (contents); + + gdk_threads_leave (); + + return jcontents; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_setText + (JNIEnv *env, jobject obj, jstring contents) +{ + void *ptr; + const char *str; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_set_text (buf, str, strlen (str)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +static GtkWidget * +textarea_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + + wid = gtk_bin_get_child (GTK_BIN (widget)); + g_assert (GTK_IS_SCROLLED_WINDOW (wid)); + + wid = gtk_bin_get_child (GTK_BIN (wid)); + + return wid; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c new file mode 100644 index 000000000..df82ff091 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c @@ -0,0 +1,388 @@ +/* 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" + +/* the color used for highlighting when the foreground is black, + since black highlights aren't a Good Idea. */ +#define BB_RED 16962 +#define BB_GREEN 26985 +#define BB_BLUE 31611 + +static jmethodID postTextEventID; + +void +cp_gtk_textcomponent_init_jni (void) +{ + jclass gtkcomponentpeer; + + gtkcomponentpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkComponentPeer"); + + postTextEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postTextEvent", + "()V"); +} + +static void textcomponent_changed_cb (GtkEditable *editable, jobject peer); + +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; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + entry = gtk_entry_new (); + gtk_widget_set_size_request (entry, + text_width + 2 * get_border_width (entry), -1); + + gtkpeer_set_widget (env, obj, entry); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* TextComponent signals */ + cp_gtk_textcomponent_connect_signals (G_OBJECT (ptr), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (ptr), gref); + + gdk_threads_leave (); +} + +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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + gtk_widget_modify_text (GTK_WIDGET (ptr), GTK_STATE_NORMAL, &color); + + if ( red == 0 && green == 0 && blue == 0) + { + color.red = BB_RED; + color.green = BB_GREEN; + color.blue = BB_BLUE; + } + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + 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 jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getCaretPosition + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setCaretPosition + (JNIEnv *env, jobject obj, jint pos) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_set_position (GTK_EDITABLE (ptr), pos); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getSelectionStart + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + int starti, endi; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (gtk_editable_get_selection_bounds (GTK_EDITABLE (ptr), &starti, &endi)) + pos = starti; + else + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getSelectionEnd + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + int starti, endi; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (gtk_editable_get_selection_bounds (GTK_EDITABLE (ptr), &starti, &endi)) + pos = endi; + else + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_select + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_select_region (GTK_EDITABLE (ptr), start, end); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setEditable + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_set_editable (GTK_EDITABLE (ptr), state); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getText + (JNIEnv *env, jobject obj) +{ + void *ptr; + char *contents = NULL; + jstring jcontents; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + contents = gtk_editable_get_chars (GTK_EDITABLE (ptr), 0, -1); + + jcontents = (*env)->NewStringUTF (env, contents); + + g_free (contents); + + gdk_threads_leave (); + + return jcontents; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setText + (JNIEnv *env, jobject obj, jstring contents) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + gtk_entry_set_text (GTK_ENTRY (ptr), str); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +void +cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT(ptr), "changed", + G_CALLBACK (textcomponent_changed_cb), gref); +} + +static void +textcomponent_changed_cb (GtkEditable *editable __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postTextEventID); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c new file mode 100644 index 000000000..ad996641f --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c @@ -0,0 +1,627 @@ + +/* gtktoolkit.c -- Native portion of GtkToolkit + Copyright (C) 1998, 1999, 2005, 2007, 2010 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 "jcl.h" + +#define RC_FILE ".classpath-gtkrc" + +/* 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 + +#define VK_SHIFT 16 +#define VK_CONTROL 17 +#define VK_ALT 18 +#define VK_CAPS_LOCK 20 +#define VK_META 157 + +static jclass gtkgenericpeer; +static jclass gtktoolkit; +static JavaVM *java_vm; +static jmethodID printCurrentThreadID; +static jmethodID setRunningID; + +/** + * The global AWT lock object. + */ +static jobject global_lock; + +union env_union +{ + void *void_env; + JNIEnv *jni_env; +}; + +JNIEnv * +cp_gtk_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 *cp_gtk_global_window_group; +double cp_gtk_dpi_conversion_factor; + +static void jni_lock_cb(); +static void jni_unlock_cb(); +static void init_glib_threads(JNIEnv*, jint, jobject); +static gboolean post_set_running_flag (gpointer); +static gboolean set_running_flag (gpointer); +static gboolean clear_running_flag (gpointer); +static void init_dpi_conversion_factor (void); +static void dpi_changed_cb (GtkSettings *settings, + GParamSpec *pspec); + +#if GTK_MINOR_VERSION > 4 +static GLogFunc old_glog_func; +static void glog_func (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data); +#endif + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_initIDs +(JNIEnv *env, jclass cls __attribute__((unused))) +{ + gtkpeer_init_pointer_IDs(env); +} + +/* + * 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, + jobject lock) +{ + int argc = 1; + char **argv; + char *homedir, *rcpath = NULL; + + gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer"); + + gtkgenericpeer = (*env)->NewGlobalRef(env, gtkgenericpeer); + + printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer, + "printCurrentThread", "()V"); + + 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); + argv[0][0] = '\0'; + argv[1] = NULL; + + init_glib_threads(env, portableNativeSync, lock); + + /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */ + gdk_threads_init(); + + gtk_init (&argc, &argv); + +#if SYNCHRONIZE_GDK + XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True); +#endif + + gtk_widget_set_default_colormap (gdk_rgb_get_colormap ()); + + 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); + + /* On errors or warning print a whole stacktrace. */ +#if GTK_MINOR_VERSION > 4 + old_glog_func = g_log_set_default_handler (&glog_func, NULL); +#endif + + cp_gtk_button_init_jni (env); + cp_gtk_checkbox_init_jni (); + cp_gtk_choice_init_jni (); + cp_gtk_component_init_jni (); + cp_gtk_filedialog_init_jni (); + cp_gtk_list_init_jni (); + cp_gtk_menuitem_init_jni (); + cp_gtk_scrollbar_init_jni (); + cp_gtk_textcomponent_init_jni (); + cp_gtk_window_init_jni (); + + cp_gtk_global_window_group = gtk_window_group_new (); + + init_dpi_conversion_factor (); + + gtktoolkit = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkMainThread"); + gtktoolkit = (*env)->NewGlobalRef(env, gtktoolkit); /* bug fix #40889 */ + setRunningID = (*env)->GetStaticMethodID (env, gtktoolkit, + "setRunning", "(Z)V"); +} + +/** + * A callback function that implements gdk_threads_enter(). This is + * implemented to wrap the JNI MonitorEnter() function. + */ +static void jni_lock_cb() +{ + JNIEnv * env = cp_gtk_gdk_env(); + if ((*env)->MonitorEnter(env, global_lock) != JNI_OK) + { + printf("failure while entering GTK monitor\n"); + } +} + +/** + * A callback function that implements gdk_threads_leave(). This is + * implemented to wrap the JNI MonitorExit() function. + */ +static void jni_unlock_cb() +{ + + JNIEnv * env = cp_gtk_gdk_env(); + if ((*env)->MonitorExit(env, global_lock)) + { + printf("failure while exiting GTK monitor\n"); + } +} + +/** 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, jobject lock) +{ + if (portableNativeSync < 0) + { +#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system + property */ + portableNativeSync = 1; +#else + portableNativeSync = 0; +#endif + } + + if (!g_thread_supported ()) + { + if (portableNativeSync) + { + global_lock = (*env)->NewGlobalRef(env, lock); + gdk_threads_set_lock_functions(&jni_lock_cb, &jni_unlock_cb); + } + 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"); */ +} + +void +cp_gtk_print_current_thread (void) +{ + (*cp_gtk_gdk_env())->CallStaticVoidMethod (cp_gtk_gdk_env(), gtkgenericpeer, printCurrentThreadID); +} + +/* 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) + cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; + else + cp_gtk_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. */ + cp_gtk_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) + cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; + else + cp_gtk_dpi_conversion_factor = + PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); +} + +#if GTK_MINOR_VERSION > 4 +static void +glog_func (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + old_glog_func (log_domain, log_level, message, user_data); + if (log_level & (G_LOG_LEVEL_ERROR + | G_LOG_LEVEL_CRITICAL + | G_LOG_LEVEL_WARNING)) + { + JNIEnv *env = cp_gtk_gdk_env (); + jthrowable *exc = (*env)->ExceptionOccurred(env); + gchar *detail = g_strconcat (log_domain, ": ", message, NULL); + JCL_ThrowException (env, "java/lang/InternalError", detail); + g_free (detail); + (*env)->ExceptionDescribe (env); + if (exc != NULL) + (*env)->Throw (env, exc); + else + (*env)->ExceptionClear (env); + } +} +#endif + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter(); + + gtk_init_add (post_set_running_flag, NULL); + gtk_quit_add (gtk_main_level (), clear_running_flag, NULL); + + gtk_main (); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter (); + + gtk_main_quit (); + + gdk_threads_leave (); +} + + +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; +} + +/** + * Report the number of mouse buttons + * Returns the number of buttons of the first mouse found, or -1 if no mouse + * seems to be connected. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + jint res = -1; + GList *devices; + GdkDevice *d; + + gdk_threads_enter (); + + /* FIXME: Why doesn't this return the correct number? */ + devices = gdk_devices_list(); + + while( res == -1 && devices != NULL ) + { + d = GDK_DEVICE( devices->data ); + if( d->source == GDK_SOURCE_MOUSE ) + res = d->num_keys; + devices = devices->next; + } + + 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; + + /* FIXME: this was deadlocking so assume it is thread-safe for now; + we need to replace this call with a .properties file anyway. */ +#if 0 + gdk_threads_enter (); +#endif + + colors = (*env)->GetIntArrayElements (env, jcolors, 0); + + 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); + + (*env)->ReleaseIntArrayElements(env, jcolors, colors, 0); + +#if 0 + gdk_threads_leave (); +#endif +} + +#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); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getLockState + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jint key) +{ + gint coord; + GdkModifierType state, mask; + GdkWindow *root_window; + + gdk_threads_enter (); + + root_window = gdk_get_default_root_window (); + gdk_window_get_pointer (root_window, &coord, &coord, &state); + + switch (key) + { + case VK_SHIFT: + mask = GDK_SHIFT_MASK; + break; + case VK_CONTROL: + mask = GDK_CONTROL_MASK; + break; + case VK_ALT: + /* This is dubious, since MOD1 could have been mapped to something + other than ALT. */ + mask = GDK_MOD1_MASK; + break; +#if GTK_CHECK_VERSION(2, 10, 0) + case VK_META: + mask = GDK_META_MASK; + break; +#endif + case VK_CAPS_LOCK: + mask = GDK_LOCK_MASK; + break; + default: + mask = 0; + } + + gdk_threads_leave (); + + if (mask == 0) + return -1; + + return state & mask ? 1 : 0; +} + +static gboolean +post_set_running_flag (gpointer data __attribute__((unused))) +{ + g_idle_add (set_running_flag, NULL); + return FALSE; +} + +static gboolean +set_running_flag (gpointer data __attribute__((unused))) +{ + (*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (), + gtktoolkit, + setRunningID, TRUE); + return FALSE; +} + +static gboolean +clear_running_flag (gpointer data __attribute__((unused))) +{ + (*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (), + gtktoolkit, + setRunningID, FALSE); + return FALSE; +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c new file mode 100644 index 000000000..af0868cc2 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c @@ -0,0 +1,202 @@ +/* gnu_java_awt_peer_gtk_VolatileImage.c + Copyright (C) 2006 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 "jcl.h" +#include "gtkpeer.h" +#include <gdk/gdktypes.h> +#include <gdk/gdkprivate.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdk-pixbuf/gdk-pixdata.h> + +#include "gnu_java_awt_peer_gtk_GtkVolatileImage.h" +#include "cairographics2d.h" + + +/** + * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env, + jobject obj __attribute__ ((__unused__)), + jobject peer, + jint width, jint height) +{ + GtkWidget *widget = NULL; + GdkPixmap* pixmap; + void *ptr = NULL; + + gdk_threads_enter(); + + if( peer != NULL ) + { + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + pixmap = gdk_pixmap_new( widget->window, width, height, -1 ); + } + else + pixmap = gdk_pixmap_new( NULL, width, height, + gdk_rgb_get_visual()->depth ); + + gdk_threads_leave(); + + g_assert( pixmap != NULL ); + + return PTR_TO_JLONG( pixmap ); +} + +/** + * Destroy the surface + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_destroy +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + if( pixmap != NULL ) + { + gdk_threads_enter(); + g_object_unref( pixmap ); + gdk_threads_leave(); + } +} + +/** + * Gets all pixels in an array + */ +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeGetPixels +(JNIEnv *env, jobject obj, jlong pointer) +{ + /* jint *pixeldata, *jpixdata; */ + jint *jpixdata; + GdkPixmap *pixmap; + GdkPixbuf *pixbuf; + jintArray jpixels; + int width, height, size; + jclass cls; + jfieldID field; + guchar *pixels; + + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + g_assert(pixmap != NULL); + + gdk_threads_enter(); + + size = width * height; + jpixels = (*env)->NewIntArray ( env, size ); + jpixdata = (*env)->GetIntArrayElements (env, jpixels, NULL); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, width, height ); + gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, 0, 0, 0, 0, width, height ); + + if (pixbuf != NULL) + { + pixels = gdk_pixbuf_get_pixels(pixbuf); + memcpy (jpixdata, pixels, size * sizeof(jint)); + } + + (*env)->ReleaseIntArrayElements (env, jpixels, jpixdata, 0); + + gdk_threads_leave(); + + return jpixels; +} + +/** + * Copy area + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeCopyArea +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + GdkPixbuf *pixbuf; + GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + + g_assert (pixmap != NULL); + + gdk_threads_enter(); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, x, y, 0, 0, w, h ); + gdk_draw_pixbuf (pixmap, NULL, pixbuf, + 0, 0, x + dx, y + dy, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeDrawVolatile +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jlong srcptr, jint x, jint y, jint w, jint h) +{ + GdkPixmap *dst, *src; + GdkGC *gc; + + src = JLONG_TO_PTR(GdkPixmap, srcptr); + dst = JLONG_TO_PTR(GdkPixmap, pointer); + g_assert (src != NULL); + g_assert (dst != NULL); + + gdk_threads_enter(); + + gc = gdk_gc_new( dst ); + gdk_draw_drawable(dst, + gc, + src, + 0, 0, + x, y, + w, h); + g_object_unref( gc ); + + gdk_threads_leave(); +} + diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c new file mode 100644 index 000000000..6ba8d4767 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -0,0 +1,2164 @@ +/* gtkwindowpeer.c -- Native implementation of GtkWindowPeer + Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006 + 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> +#include <gdk/gdkkeysyms.h> + +#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_NORMAL 0 +#define AWT_FRAME_ICONIFIED 1 +#define AWT_FRAME_MAXIMIZED_BOTH 6 + +/* 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 ']' +/* See gtkpeer.h */ +/* #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 +/* See gtkpeer.h */ +/* #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 VK_BEGIN 65368 +#define VK_CONTEXT_MENU 525 +#define VK_WINDOWS 524 + + +#define AWT_KEY_CHAR_UNDEFINED 0 + +#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 + +static jmethodID postKeyEventID; +static jmethodID postWindowEventID; +static jmethodID postConfigureEventID; +static jmethodID postInsetsChangedEventID; +static jmethodID windowGetWidthID; +static jmethodID windowGetHeightID; + +void +cp_gtk_window_init_jni (void) +{ + jclass gtkwindowpeer; + + gtkwindowpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkWindowPeer"); + + postKeyEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postKeyEvent", "(IJIICI)V"); + + postWindowEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postWindowEvent", + "(ILjava/awt/Window;I)V"); + + postConfigureEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postConfigureEvent", "(IIII)V"); + + postInsetsChangedEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postInsetsChangedEvent", + "(IIII)V"); + + windowGetWidthID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "getWidth", "()I"); + + windowGetHeightID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "getHeight", "()I"); + + gtkwindowpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkWindowPeer"); +} + +/* 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 or -1 if no + keyval was found for the given hardware keycode. */ +static gint +get_first_keyval_from_keymap (GdkEventKey *event) +{ + guint keyval; + guint *keyvals; + gint n_entries; + + if (!gdk_keymap_get_entries_for_keycode (NULL, + event->hardware_keycode, + NULL, + &keyvals, + &n_entries)) + { + /* No keyval found for hardware keycode */ + return -1; + } + keyval = keyvals[0]; + g_free (keyvals); + + return gdk_keyval_to_upper (keyval); +} + +/* Return the AWT key code for the given keysym or -1 if no keyval was + found for the given hardware keycode. */ +#ifdef __GNUC__ +__inline +#endif +static jint +keysym_to_awt_keycode (GdkEventKey *event) +{ + gint ukeyval; + guint state; + + ukeyval = get_first_keyval_from_keymap (event); + + if (ukeyval < 0) + return -1; + + state = event->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; + */ + case GDK_Undo: + return VK_UNDO; + case GDK_Redo: + return VK_AGAIN; + /* + return VK_FIND; + return VK_PROPS; + return VK_STOP; + return VK_COMPOSE; + */ + case GDK_ISO_Level3_Shift: + return VK_ALT_GRAPH; + /* + case VK_BEGIN: + */ + case GDK_Menu: + return VK_CONTEXT_MENU; + case GDK_Super_L: + case GDK_Super_R: + return VK_WINDOWS; + + default: + return VK_UNDEFINED; + } +} + +/* Return the AWT key location code for the given keysym or -1 if no + keyval was found for the given hardware keycode. */ +static jint +keysym_to_awt_keylocation (GdkEventKey *event) +{ + gint ukeyval; + + ukeyval = get_first_keyval_from_keymap (event); + + if (ukeyval < 0) + return -1; + + /* 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 (GdkEventKey *event) +{ + if (event->length > 0) + { + /* Translate GDK carriage return to Java linefeed. */ + if (event->string[0] == 13) + return VK_ENTER; + else + return event->string[0]; + } + else + { + switch (event->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; + } + } +} + +/* 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. */ +static jint +keyevent_state_to_awt_mods (GdkEventKey *event) +{ + jint result = 0; + guint state; + + if (event->type == GDK_KEY_PRESS) + { + state = event->state; + + if (event->keyval == GDK_Shift_L + || event->keyval == GDK_Shift_R) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + else + { + if (state & GDK_SHIFT_MASK) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + } + + if (event->keyval == GDK_Control_L + || event->keyval == GDK_Control_R) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + else + { + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + } + + if (event->keyval == GDK_Alt_L + || event->keyval == GDK_Alt_R) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + else + { + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + } + } + else if (event->type == GDK_KEY_RELEASE) + { + state = event->state; + + if (event->keyval != GDK_Shift_L + && event->keyval != GDK_Shift_R) + { + if (state & GDK_SHIFT_MASK) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + } + if (event->keyval != GDK_Control_L + && event->keyval != GDK_Control_R) + { + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + } + + if (event->keyval != GDK_Alt_L + && event->keyval != GDK_Alt_R) + { + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + } + } + + return result; +} + +static gboolean window_configure_cb (GtkWidget *widget, + GdkEventConfigure *event, + jobject peer); + +/* 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_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 gboolean window_property_changed_cb (GtkWidget *widget, + GdkEventProperty *event, + jobject peer); +static void realize_cb (GtkWidget *widget, jobject peer); + +static gboolean +window_configure_cb (GtkWidget *widget __attribute__((unused)), + GdkEventConfigure *event, + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postConfigureEventID, + (jint) event->x, + (jint) event->y, + (jint) event->width, + (jint) event->height); + + return FALSE; +} + +static gboolean +key_press_cb (GtkWidget *widget __attribute__((unused)), + GdkEventKey *event, + jobject peer) +{ + jint keycode; + jint keylocation; + + keycode = keysym_to_awt_keycode (event); + keylocation = keysym_to_awt_keylocation (event); + + /* Return immediately if an error occurs translating a hardware + keycode to a keyval. */ + if (keycode < 0 || keylocation < 0) + return TRUE; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postKeyEventID, + (jint) AWT_KEY_PRESSED, + (jlong) event->time, + keyevent_state_to_awt_mods (event), + keycode, + keyevent_to_awt_keychar (event), + keylocation); + + /* FIXME: generation of key typed events needs to be moved + to GtkComponentPeer.postKeyEvent. If the key in a key + press event is not an "action" key + (KeyEvent.isActionKey) and is not a modifier key, then + it should generate a key typed event. */ + return TRUE; +} + + +static gboolean +key_release_cb (GtkWidget *widget __attribute__((unused)), + GdkEventKey *event, + jobject peer) +{ + jint keycode; + jint keylocation; + + keycode = keysym_to_awt_keycode (event); + keylocation = keysym_to_awt_keylocation (event); + + /* Return immediately if an error occurs translating a hardware + keycode to a keyval. */ + if (keycode < 0 || keylocation < 0) + return TRUE; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postKeyEventID, + (jint) AWT_KEY_RELEASED, + (jlong) event->time, + keyevent_state_to_awt_mods (event), + keycode, + keyevent_to_awt_keychar (event), + keylocation); + + return TRUE; +} + +/* Union used for type punning. */ +union extents_union +{ + guchar **gu_extents; + unsigned long **extents; +}; + +union atom_list_union +{ + guchar **gu_extents; + Atom **atom_list; +}; + +JNIEXPORT void 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; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + window_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = GTK_WINDOW (window_widget); + + /* Keep this window in front of its parent, if it has one. */ + if (parent) + { + window_parent = gtkpeer_get_widget (env, parent); + gtk_window_set_transient_for (window, GTK_WINDOW(window_parent)); + } + + gtk_window_set_decorated (window, decorated); + + gtk_window_set_type_hint (window, type); + + gtk_window_group_add_window (cp_gtk_global_window_group, window); + + fixed = gtk_fixed_new (); + + gtk_container_add (GTK_CONTAINER (window_widget), fixed); + + gtk_widget_show (fixed); + + gtkpeer_set_widget (env, obj, window_widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetTitle + (JNIEnv *env, jobject obj, jstring title) +{ + const char *c_title; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + c_title = (*env)->GetStringUTFChars (env, title, NULL); + + gtk_window_set_title (GTK_WINDOW (ptr), c_title); + + (*env)->ReleaseStringUTFChars (env, title, c_title); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable + (JNIEnv *env, jobject obj, jboolean resizable) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gtk_window_set_resizable (GTK_WINDOW (ptr), resizable); + g_object_set (G_OBJECT (ptr), "allow-shrink", resizable, NULL); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal + (JNIEnv *env, jobject obj, jboolean modal) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_modal (GTK_WINDOW (ptr), modal); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetAlwaysOnTop + (JNIEnv *env, jobject obj, jboolean alwaysOnTop) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_keep_above (GTK_WINDOW (ptr), alwaysOnTop); + + gdk_threads_leave (); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowHasFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = gtk_window_has_toplevel_focus (GTK_WINDOW (ptr)); + + gdk_threads_leave (); + return retval; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNative + (JNIEnv *env, jobject obj, jboolean visible) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked + (env, obj, visible); + + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + if (visible) + gtk_widget_show (GTK_WIDGET (ptr)); + else + gtk_widget_hide (GTK_WIDGET (ptr)); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = (jobject) gtkpeer_get_global_ref (env, obj); + + g_signal_connect (G_OBJECT (ptr), "delete-event", + G_CALLBACK (window_delete_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "destroy-event", + G_CALLBACK (window_destroy_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus", + G_CALLBACK (window_focus_state_change_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (window_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (window_focus_out_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "window-state-event", + G_CALLBACK (window_window_state_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "property-notify-event", + G_CALLBACK (window_property_changed_cb), gref); + + g_signal_connect_after (G_OBJECT (ptr), "realize", + G_CALLBACK (realize_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "key-press-event", + G_CALLBACK (key_press_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "key-release-event", + G_CALLBACK (key_release_cb), gref); + + g_signal_connect_after (G_OBJECT (ptr), "window-state-event", + G_CALLBACK (window_window_state_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "configure-event", + G_CALLBACK (window_configure_cb), gref); + + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); + + /* FIXME: override focus signals here to prevent child fixed repaint? */ + + gdk_threads_leave (); +} + +/* Realize the window here so that its frame extents are known now. + That way Window.pack can operate with the accurate insets returned + by the window manager rather than the default estimates. */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_realize (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toBack (JNIEnv *env, + jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gdk_window_lower (GTK_WIDGET (ptr)->window); + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env, + jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gdk_window_raise (GTK_WIDGET (ptr)->window); + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize + (JNIEnv *env, jobject obj, jint width, jint height) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + /* Avoid GTK runtime assertion failures. */ + width = (width < 1) ? 1 : width; + height = (height < 1) ? 1 : height; + + gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked + (env, obj, x, y, width, height); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocationUnlocked + (JNIEnv *env, jobject obj, jint x, jint y) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_move (GTK_WINDOW(ptr), x, y); + + if (GTK_WIDGET (ptr)->window != NULL) + gdk_window_move (GTK_WIDGET (ptr)->window, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocation + (JNIEnv *env, jobject obj, jint x, jint y) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocationUnlocked + (env, obj, x, y); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + void *ptr; + gint current_width; + gint current_height; + + ptr = gtkpeer_get_widget (env, obj); + + /* Avoid GTK runtime assertion failures. */ + width = (width < 1) ? 1 : width; + height = (height < 1) ? 1 : height; + + gtk_window_move (GTK_WINDOW(ptr), x, y); + /* The call to gdk_window_move is needed in addition to the call to + gtk_window_move. If gdk_window_move isn't called, then the + following set of operations doesn't give the expected results: + + 1. show a window + 2. manually move it to another position on the screen + 3. hide the window + 4. reposition the window with Component.setLocation + 5. show the window + + Instead of being at the position set by setLocation, the window + is reshown at the position to which it was moved manually. */ + if (GTK_WIDGET (ptr)->window != NULL) + gdk_window_move (GTK_WIDGET (ptr)->window, x, y); + + /* Only request resizing if the actual width or height change, otherwise + * we get unnecessary flickers because resizing causes GTK to clear the + * window content, even if the actual size doesn't change. */ + gtk_window_get_size(GTK_WINDOW(ptr), ¤t_width, ¤t_height); + if (current_width != width || current_height != height) + { + /* Need to change the widget's request size. */ + gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); + /* Also need to call gtk_window_resize. If the resize is requested + by the program and the window's "resizable" property is true then + the size request will not be honoured. */ + gtk_window_resize (GTK_WINDOW (ptr), width, height); + } +} + +static 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. */ + if (!gtk_window_get_decorated (GTK_WINDOW (window))) + { + *top = 0; + *left = 0; + *bottom = 0; + *right = 0; + + return; + } + + *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) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_CLOSING, + (jobject) NULL, (jint) 0); + + /* Prevents that the Window dissappears ("destroy" + not being signalled). This is necessary because it + should be up to a WindowListener implementation + how the AWT Frame responds to close requests. */ + return TRUE; +} + +static void +window_destroy_cb (GtkWidget *widget __attribute__((unused)), + GdkEvent *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_CLOSED, + (jobject) NULL, (jint) 0); +} + +static void +window_focus_state_change_cb (GtkWidget *widget, + GParamSpec *pspec __attribute__((unused)), + jobject peer) +{ + if (GTK_WINDOW (widget)->has_toplevel_focus) + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_ACTIVATED, + (jobject) NULL, (jint) 0); + else + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_DEACTIVATED, + (jobject) NULL, (jint) 0); +} + +static gboolean +window_focus_in_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_GAINED_FOCUS, + (jobject) NULL, (jint) 0); + + return FALSE; +} + +static gboolean +window_focus_out_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_LOST_FOCUS, + (jobject) NULL, (jint) 0); + + return FALSE; +} + +static gboolean +window_window_state_cb (GtkWidget *widget __attribute__((unused)), + GdkEvent *event, + jobject peer) +{ + jint new_java_state = 0; + /* Put together the new state and let the java side figure out what + * to post */ + GdkWindowState new_state = event->window_state.new_window_state; + /* The window can be either iconfified, maximized, iconified + maximized + * or normal. */ + if ((new_state & GDK_WINDOW_STATE_ICONIFIED) != 0) + new_java_state |= AWT_FRAME_ICONIFIED; + if ((new_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) + new_java_state |= AWT_FRAME_MAXIMIZED_BOTH; + if ((new_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_ICONIFIED)) + == 0) + new_java_state = AWT_FRAME_NORMAL; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_STATE_CHANGED, + (jobject) NULL, new_java_state); + + return TRUE; +} + +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)) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postInsetsChangedEventID, + (jint) extents[2], /* top */ + (jint) extents[0], /* left */ + (jint) extents[3], /* bottom */ + (jint) extents[1]); /* right */ + } + + + 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 = (*cp_gtk_gdk_env())->CallIntMethod (cp_gtk_gdk_env(), peer, windowGetWidthID); + height = (*cp_gtk_gdk_env())->CallIntMethod (cp_gtk_gdk_env(), peer, windowGetHeightID); + + window_get_frame_extents (widget, &top, &left, &bottom, &right); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_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)); +} + +/* + * 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 +cp_gtk_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: + return GDK_Undo; + case VK_AGAIN: + return GDK_Redo; + /* + case VK_FIND: + case VK_PROPS: + case VK_STOP: + case VK_COMPOSE: + */ + case VK_ALT_GRAPH: + return GDK_ISO_Level3_Shift; + /* + case VK_BEGIN: + */ + case VK_CONTEXT_MENU: + return GDK_Menu; + case VK_WINDOWS: + return GDK_Super_R; + + default: + return GDK_VoidSymbol; + } +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c new file mode 100644 index 000000000..72130376f --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c @@ -0,0 +1,203 @@ +/* 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; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +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 = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + display = gtk_widget_get_display (widget); + + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + return xdisplay; + } + else + return NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +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 = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget)); + g_assert (visual != NULL); + + return visual->visualid; + } + else + return (VisualID) NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +int +classpath_jawt_get_depth (JNIEnv* env, jobject canvas) +{ + GtkWidget *widget; + GdkVisual *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 = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + visual = gtk_widget_get_visual (widget); + g_assert (visual != NULL); + + return visual->depth; + } + else + return (VisualID) NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +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 = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + drawable = GDK_DRAWABLE_XID (widget->window); + + return drawable; + } + else + return (Drawable) NULL; +} + +jint +classpath_jawt_lock () +{ + gdk_threads_enter (); + return 0; +} + +void +classpath_jawt_unlock () +{ + gdk_threads_leave (); +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.c b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.c new file mode 100644 index 000000000..b57626e94 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.c @@ -0,0 +1,586 @@ +/* gtkpeer.c -- Some GTK peer specific helper functions + Copyright (C) 2007 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 "jni.h" + +/** + * The Pointer class. + */ +static jclass pointerClass; + +/** + * The Pointer constructor. + */ +static jmethodID pointerConstructorMID; + +/** + * The field ID of the data field in the Pointer class. + */ +static jfieldID pointerDataFID; + +/** + * The field ID of the widget field in the GtkGenericPeer class. + */ +static jfieldID widgetFID; + +/** + * The field ID of the globalRef field in the GtkGenericPeer class. + */ +static jfieldID globalRefFID; + +/** + * The field ID of the display field in the GdkGraphicsEnvironment class. + */ +static jfieldID displayFID; + +/** + * The field ID of the screen field in the GdkScreenGraphicsDevice class. + */ +static jfieldID screenFID; + +/** + * The field ID of the nativeFont field in GdkFontPeer. + */ +static jfieldID fontFID; + +/** + * The field ID of the nativeDecoder field in GdkPixbufDecoder. + */ +static jfieldID pixbufLoaderFID; + +/** + * Initializes the IDs of the Pointer* classes. + * + * @param env the JNI environment + */ +void gtkpeer_init_pointer_IDs(JNIEnv* env) +{ +#if SIZEOF_VOID_P == 8 + pointerClass = (*env)->FindClass (env, "gnu/classpath/Pointer64"); + if (pointerClass != NULL) + { + pointerClass = (*env)->NewGlobalRef (env, pointerClass); + pointerDataFID = (*env)->GetFieldID (env, pointerClass, "data", "J"); + pointerConstructorMID = (*env)->GetMethodID (env, pointerClass, "<init>", + "(J)V"); + } +#else +#if SIZEOF_VOID_P == 4 + pointerClass = (*env)->FindClass(env, "gnu/classpath/Pointer32"); + if (pointerClass != NULL) + { + pointerClass = (*env)->NewGlobalRef (env, pointerClass); + pointerDataFID = (*env)->GetFieldID (env, pointerClass, "data", "I"); + pointerConstructorMID = (*env)->GetMethodID (env, pointerClass, "<init>", + "(I)V"); + } +#else +#error "Pointer size is not supported." +#endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ +} + +/** + * Initializes the field IDs for the widget reference. + * + * @param env the JNI environment + */ +void gtkpeer_init_widget_IDs(JNIEnv *env) +{ + jclass cls; + + /* Find the widget field ID in GtkGenericPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer"); + widgetFID = (*env)->GetFieldID(env, cls, "widget", + "Lgnu/classpath/Pointer;"); + + /* Find the globalRef field in GtkGenericPeer. */ + globalRefFID = (*env)->GetFieldID(env, cls, "globalRef", + "Lgnu/classpath/Pointer;"); +} + +/** + * Stores the GTK widget reference in the GtkGenericPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * @param widget the widget reference to store + */ +void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget) +{ + jobject obj; + + /* Fetch the widget field object. */ + obj = (*env)->GetObjectField(env, peer, widgetFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) widget); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) widget); +#endif + (*env)->SetObjectField(env, peer, widgetFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) widget); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) widget); +#endif + } +} + +/** + * Retrieves the GTK widget reference from a GtkGenericPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * + * @return the widget reference + */ +void* gtkpeer_get_widget(JNIEnv *env, jobject peer) +{ + jobject obj; + void *widget; + + /* Fetch the widget field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, widgetFID); + + /* Fetch actual widget pointer. */ +#if SIZEOF_VOID_P == 8 + widget = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + widget = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return widget; +} + + +/** + * Stores the global JNI reference of a peer inside the peer. + * + * @param env the JNI environment + * @param peer the peer object + */ +void gtkpeer_set_global_ref(JNIEnv *env, jobject peer) +{ + jobject obj; + void* globalRef; + + /* Create global reference. */ + globalRef = (*env)->NewGlobalRef(env, peer); + + /* Fetch the globalRef field object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) globalRef); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) globalRef); +#endif + (*env)->SetObjectField(env, peer, globalRefFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) globalRef); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) globalRef); +#endif + } +} + +/** + * Retrieves the global reference from a peer. + * + * @param env the JNI environment + * @param peer the peer object + * + * @return the global reference + */ +void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer) +{ + jobject obj; + void *globalRef; + + /* Fetch the globalRef field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + + /* Fetch actual globalRef pointer. */ +#if SIZEOF_VOID_P == 8 + globalRef = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + globalRef = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return globalRef; +} + +/** + * Deletes the global reference of a peer. This is necessary in order to + * allow the peer to be garbage collected. + * + * @param env the JNI environment + * @param peer the peer object. + */ +void gtkpeer_del_global_ref(JNIEnv* env, jobject peer) +{ + jobject obj; + void *globalRef; + + /* Fetch the globalRef field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + + /* Fetch actual globalRef pointer. */ +#if SIZEOF_VOID_P == 8 + globalRef = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + globalRef = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + (*env)->DeleteGlobalRef(env, globalRef); +} + +/** + * Initializes the fieldIDs for the display and screen fields. + * + * @param env the JNI environment + */ +void gtkpeer_init_display_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the display field ID in GdkGraphicsEnvironment. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkGraphicsEnvironment"); + displayFID = (*env)->GetFieldID(env, cls, "display", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native display pointer in the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * @param display the native display pointer + */ +void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display) +{ + jobject obj; + + /* Fetch the display field object. */ + obj = (*env)->GetObjectField(env, graphicsenv, displayFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) display); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) display); +#endif + (*env)->SetObjectField(env, graphicsenv, displayFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) display); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) display); +#endif + } +} + +/** + * Fetches the native display pointer from the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * + * @return the native display pointer + */ +void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv) +{ + jobject obj; + void *display; + + /* Fetch the display field from the peer object. */ + obj = (*env)->GetObjectField(env, graphicsenv, displayFID); + + /* Fetch actual display pointer. */ +#if SIZEOF_VOID_P == 8 + display = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + display = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return display; +} + +/** + * Initializes the fieldIDs for the screen field. + * + * @param env the JNI environment + */ +void gtkpeer_init_screen_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the display field ID in GdkScreenGraphicsDevice. */ + cls = (*env)->FindClass(env, + "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + screenFID = (*env)->GetFieldID(env, cls, "screen", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native screen in the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * @param ptr the native screen pointer + */ +void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device, + void* ptr) +{ + jobject obj; + + /* Fetch the screen field object. */ + obj = (*env)->GetObjectField(env, screen_graphics_device, screenFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) ptr); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) ptr); +#endif + (*env)->SetObjectField(env, screen_graphics_device, screenFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) ptr); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) ptr); +#endif + } +} + +/** + * Fetches the native screen pointer from the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * + * @return the native screen pointer + */ +void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device) +{ + jobject obj; + void *screen; + + /* Fetch the display field from the peer object. */ + obj = (*env)->GetObjectField(env, screen_graphics_device, screenFID); + + /* Fetch actual display pointer. */ +#if SIZEOF_VOID_P == 8 + screen = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + screen = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return screen; +} + +/** + * Initializes the field IDs for fonts. + * + * @param env the JNI environment + */ +void gtkpeer_init_font_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the nativeFont field ID in GdkFontPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkFontPeer"); + fontFID = (*env)->GetFieldID(env, cls, "nativeFont", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param font_peer the font peer object + * @param font the actual native font reference + */ +void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font) +{ + jobject obj; + + /* Fetch the nativeFont field object. */ + obj = (*env)->GetObjectField(env, font_peer, fontFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) font); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) font); +#endif + (*env)->SetObjectField(env, font_peer, fontFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) font); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) font); +#endif + } +} + +/** + * Fetches the native font reference from the GdkFontPeer object. + * + * @param env the JNI environment + * @param font_peer the font peer object + * + * @return the native font structure + */ +void* gtkpeer_get_font(JNIEnv* env, jobject font_peer) +{ + jobject obj; + void *font; + + /* Fetch the nativeFont field from the peer object. */ + obj = (*env)->GetObjectField(env, font_peer, fontFID); + + /* Fetch actual font pointer. */ +#if SIZEOF_VOID_P == 8 + font = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + font = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return font; +} + +/** + * Initializes the field IDs for pixbuf decoder. + * + * @param env the JNI environment + */ +void gtkpeer_init_pixbuf_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the nativeFont field ID in GdkFontPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder"); + pixbufLoaderFID = (*env)->GetFieldID(env, cls, "nativeDecoder", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * @param pixbuf_loader the native pixbuf loader + */ +void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec, + void* pixbuf_loader) +{ + jobject obj; + + /* Fetch the nativeDecoder field object. */ + obj = (*env)->GetObjectField(env, pixbuf_dec, pixbufLoaderFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) pixbuf_loader); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) pixbuf_loader); +#endif + (*env)->SetObjectField(env, pixbuf_dec, pixbufLoaderFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) pixbuf_loader); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) pixbuf_loader); +#endif + } +} + +/** + * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * + * @return the native pixbuf loader + */ +void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec) +{ + jobject obj; + void *loader; + + /* Fetch the nativeFont field from the peer object. */ + obj = (*env)->GetObjectField(env, pixbuf_dec, pixbufLoaderFID); + + /* Fetch actual font pointer. */ +#if SIZEOF_VOID_P == 8 + loader = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + loader = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return loader; +} diff --git a/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.h b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.h new file mode 100644 index 000000000..8b677aff7 --- /dev/null +++ b/gcc-4.8.1/libjava/classpath/native/jni/gtk-peer/gtkpeer.h @@ -0,0 +1,360 @@ +/* gtkpeer.h -- Some global variables and #defines + Copyright (C) 1998, 1999, 2004, 2005, 2006 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 <cairo.h> +#include <gtk/gtk.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <config.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + +#include <jni.h> + +#ifndef __GTKPEER_H__ +#define __GTKPEER_H__ + +#ifndef __GNUC__ +#define __attribute__(x) /* nothing */ +#endif + +/** + * Initializes the IDs of the Pointer* classes. + * + * @param env the JNI environment + */ +void gtkpeer_init_pointer_IDs(JNIEnv* env); + +/** + * Initializes the field IDs for the widget reference. + * + * @param env the JNI environment + */ +void gtkpeer_init_widget_IDs(JNIEnv *env); + +/** + * Stores the GTK widget reference in the GtkComponentPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * @param widget the widget reference to store + */ +void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget); + +/** + * Retrieves the GTK widget reference from a GtkComponentPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * + * @return the widget reference + */ +void* gtkpeer_get_widget(JNIEnv *env, jobject peer); + +/** + * Stores the global JNI reference of a peer inside the peer. + * + * @param env the JNI environment + * @param peer the peer object + */ +void gtkpeer_set_global_ref(JNIEnv *env, jobject peer); + +/** + * Retrieves the global reference from a peer. + * + * @param env the JNI environment + * @param peer the peer object + * + * @return the global reference + */ +void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer); + +/** + * Deletes the global reference of a peer. This is necessary in order to + * allow the peer to be garbage collected. + * + * @param env the JNI environment + * @param peer the peer object. + */ +void gtkpeer_del_global_ref(JNIEnv* env, jobject peer); + + +/** + * Initializes the fieldIDs for the display and screen fields. + * + * @param env the JNI environment + */ +void gtkpeer_init_display_IDs(JNIEnv* env); + +/** + * Sets the native display pointer in the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * @param display the native display pointer + */ +void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display); + +/** + * Fetches the native display pointer from the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * + * @return the native display pointer + */ +void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv); + +/** + * Initializes the fieldIDs for the screen field. + * + * @param env the JNI environment + */ +void gtkpeer_init_screen_IDs(JNIEnv* env); + +/** + * Sets the native screen in the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * @param ptr the native screen pointer + */ +void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device, + void* ptr); + +/** + * Fetches the native screen pointer from the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * + * @return the native screen pointer + */ +void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device); + +/** + * Initializes the field IDs for fonts. + * + * @param env the JNI environment + */ +void gtkpeer_init_font_IDs(JNIEnv* env); + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param font_peer the font peer object + * @param font the actual native font reference + */ +void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font); + +/** + * Fetches the native font reference from the GdkFontPeer object. + * + * @param env the JNI environment + * @param font_peer the font peer object + * + * @return the native font structure + */ +void* gtkpeer_get_font(JNIEnv* env, jobject font_peer); + +/** + * Initializes the field IDs for pixbuf decoder. + * + * @param env the JNI environment + */ +void gtkpeer_init_pixbuf_IDs(JNIEnv* env); + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * @param pixbuf_loader the native pixbuf loader + */ +void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec, + void* pixbuf_loader); + +/** + * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * + * @return the native pixbuf loader + */ +void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec); + + +#define SWAPU32(w) \ + (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24)) + +/* New-style event masks. */ +#define AWT_BUTTON1_DOWN_MASK (1 << 10) +#define AWT_BUTTON2_DOWN_MASK (1 << 11) +#define AWT_BUTTON3_DOWN_MASK (1 << 12) + +#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) + +/* Old-style event masks. */ +#define AWT_BUTTON1_MASK (1 << 4) +#define AWT_BUTTON2_MASK (1 << 3) +#define AWT_BUTTON3_MASK (1 << 2) + +#define AWT_SHIFT_MASK (1 << 0) +#define AWT_CTRL_MASK (1 << 1) +#define AWT_META_MASK (1 << 2) +#define AWT_ALT_MASK (1 << 3) + +#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_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 + +#define AWT_STYLE_PLAIN 0 +#define AWT_STYLE_BOLD 1 +#define AWT_STYLE_ITALIC 2 + +/* Used in GtkComponentPeer and GtkWindowPeer */ +#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_DECIMAL 110 + +JNIEnv *cp_gtk_gdk_env(void); + +/* Global variables */ +extern double cp_gtk_dpi_conversion_factor; +extern GtkWindowGroup *cp_gtk_global_window_group; + +/* Shared global clipboard and selection for GtkClipboard and GtkSelection. */ +extern GtkClipboard *cp_gtk_clipboard; +extern GtkClipboard *cp_gtk_selection; + +extern jobject cp_gtk_clipboard_instance; +extern jobject cp_gtk_selection_instance; + +/* Standard target (strings) for GtkClipboard and GtkSelection. */ +extern jstring cp_gtk_stringTarget; +extern jstring cp_gtk_imageTarget; +extern jstring cp_gtk_filesTarget; + +/* Union used for type punning. */ +union widget_union +{ + void **void_widget; + GtkWidget **widget; +}; + +/* Constant conversion helpers */ +guint cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation); +jint cp_gtk_state_to_awt_mods (guint state); + +/* Image helpers */ +GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj); + +/* Component Graphics helpers */ +void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw, + GdkWindow **win); + +/* JNI initialization functions */ +void cp_gtk_button_init_jni (JNIEnv*); +void cp_gtk_checkbox_init_jni (void); +void cp_gtk_choice_init_jni (void); +void cp_gtk_component_init_jni (void); +void cp_gtk_filedialog_init_jni (void); +void cp_gtk_list_init_jni (void); +void cp_gtk_menuitem_init_jni (void); +void cp_gtk_scrollbar_init_jni (void); +void cp_gtk_textcomponent_init_jni (void); +void cp_gtk_window_init_jni (void); + +/* Signal connection convience functions */ +void cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_signals (GObject *ptr, jobject gref); +void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref); + +/* Debugging */ +void cp_gtk_print_current_thread (void); + +GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj); + +#define SYNCHRONIZE_GDK 0 + +#define DEBUG_LOCKING 0 + +#if DEBUG_LOCKING +#define gdk_threads_enter() \ +{ \ + g_print ("locking: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ + gdk_threads_enter (); \ + g_print ("locked: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ +} +#define gdk_threads_leave() \ +{ \ + g_print ("unlocking: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ + gdk_threads_leave (); \ + g_print ("unlocked: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ +} +#endif + +#endif /* __GTKPEER_H */ |
