diff options
author | Thomas Fitzsimmons <fitzsim@redhat.com> | 2004-01-07 02:23:37 +0000 |
---|---|---|
committer | Thomas Fitzsimmons <fitzsim@redhat.com> | 2004-01-07 02:23:37 +0000 |
commit | 3134fa889725dd24cde1667279eda76d175e1295 (patch) | |
tree | aa913073f7042b1307315ba17f200ec55a790935 /native/jni | |
parent | 27d82386067d73298bb6245ab819a588485a3973 (diff) | |
download | classpath-3134fa889725dd24cde1667279eda76d175e1295.tar.gz |
2004-01-06 Graydon Hoare <graydon@redhat.com>
* configure.in: Add --enable-gtk-cairo check.
* configure: Regenerate.
* Makefile.am: Conditionally link against cairo.
* Makefile.in: Regenerate.
* acinclude.m4: Include PKG_CHECK_MODULES.
* aclocal.m4: Regenerate.
* gnu/java/awt/peer/gtk/GtkToolkit.java (useGraphics2D): New method.
(getFontMetrics, getClasspathFontPeer):
* gnu/java/awt/peer/gtk/GtkCanvasPeer.java (getGraphics):
* gnu/java/awt/peer/gtk/GtkComponentPeer.java (createImage):
* gnu/java/awt/peer/gtk/GtkContainerPeer.java (getGraphics):
* gnu/java/awt/peer/gtk/GtkFramePeer.java (getGraphics):
Switch behavior depending on GtkToolkit.useGraphics2D().
* gnu/java/awt/peer/gtk/GtkFontPeer.java: Extend ClasspathFontPeer.
* java/awt/Font.java: Switch to peer model.
* jni/gtk-peer/gtkcairopeer.h: Definitions of cairo stuff.
* jni/gtk-peer/gdkfont.h: Include gtkcairopeer.h.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c: Include gtkcairopeer.h.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c: Un-include gtkpeer.h.
2004-01-06 Fernando Nasser <fnasser@redhat.com>
* gnu/java/awt/peer/gtk/GtkListPeer.java (handleEvent): Fix generation
of ActionEvents for mouse double-clicks.
2004-01-06 Fernando Nasser <fnasser@redhat.com>
* java/awt/Choice.java (add): Leave posting of ItemEvents to peer.
(insert): Ditto.
(remove): Ditto. Also, Check for valid argument.
(removeAll): Use peer interface method.
* gnu/java/awt/peer/gtk/GtkChoicePeer.java (nativeAdd): New name for
native add function.
(nativeRemove): New name for native remove function.
(getHistory): New native function.
(constructor): Generate ItemEvent.
(add): Ditto, if selection is changed.
(remove): Ditto, ditto.
(removeAll): Add implementation.
(handleEvent): Remove. Dead code.
(choicePostItemEvent): Add comment.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append): Add comments.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add): Rename to...
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd): New name. Add
comments and fix condition to change selection.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_remove): Rename to...
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove): New name. Add
remove all capability.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_getHistory): New function.
(item_activate): Add cast to remove compiler warning.
2004-01-06 Thomas Fitzsimmons <fitzsim@redhat.com>
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
(pre_event_handler): Set all insets to 0 when a Configure event
is received for a GtkPlug.
* gnu/java/awt/peer/gtk/GtkScrollPanePeer.java,
jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c
(create(int, int)): New method.
(create): Call new create method.
(gtkScrolledWindowNew, gtkScrolledWindowSetSize): Remove
methods.
(childResized): Remove native implementation. Implement in
Java.
(getHScrollbarHeight, getVScrollbarWidth): Call
gtk_widget_size_request to get scrollbar dimensions.
* java/awt/ScrollPane.java (getViewportSize): Reimplement. Only
call getVScrollbarWidth and getHScrollbarHeight when vertical
and horizontal scrollbars respectively are needed.
(doLayout): Enlarge child if it is smaller than the viewport.
* gnu/java/awt/peer/gtk/GtkComponentPeer.java,
jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
(getPreferredSize): Call preferredSize.
(preferredSize): Call gtkWidgetGetPreferredDimensions.
(getMinimumSize): Call minimumSize.
(minimumSize): Call gtkWidgetGetPreferredDimensions.
(gtkWidgetGetDimensions): Return the peer widget's current size
request.
(gtkWidgetGetPreferredDimensions): Return the peer widget's
natural size request.
2004-01-06 Fernando Nasser <fnasser@redhat.com>
* gnu/java/awt/peer/gtk/GtkChoicePeer.java (postItemEvent): Rename to...
(choicePostItemEvent): Change signature to more specific String object.
* java/awt/Choice.java (add): Generate ItemEvent for the first item
added.
(insert): Generate ItemEvent if insertion caused
selection to change.
(remove): Generate ItemEvent if removal cause selection to change.
(removeAll): Change algorithm to prevent generation of ItemEvents.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
(connect_choice_item_selectable_hook): Change argument type.
Fix argument value.
Make sure resources are feed by registering callback.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append): Adjust call to the
above function.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add): Ditto.
(item_activate): Ditto.
(Java_gnu_java_awt_peer_gtk_GtkChoicePeer_remove): Destroy removed
menuitem.
(item_removed): New function. Free resources.
* jni/gtk-peer/gtkpeer.h (item_event_hook_info): Change member type and
name.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
(Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit): Obtain MethodID for
choicePostItemEvent.
2004-01-06 Kim Ho <kho@redhat.com>
Fix for Checkbox states.
* gnu/java/awt/peer/gtk/GtkCheckboxPeer.java:
(currentState): New field.
(nativeCreate): Add initial state parameter.
(create): Changed to reflect new parameter.
(setState): Fire only on changed states.
(postItemEvent): Fire only on changed states. Also change the
Java Checkbox to reflect new state.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c:
(nativeCreate): Add parameter and set active state.
2004-01-06 Fernando Nasser <fnasser@redhat.com>
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (awt_event_handler):
Most coded moved to pre_event_handler, with the modifications
mentioned below.
(pre_event_handler): New function. Called on the Gtk "event" signal.
Do not retrieve the jobject from the window property as it is already
available as user data in the signal.
Do not try and find the grab widget as it is already done by Gtk at
this point.
Do not search for Window ancestor as Gtk already sends the signal to it.
Do not meddle with the activation state of peer widgets on each
key press or release.
Add CList to the special handling when looking for the focused widget.
* jni/gtk-peer/gtkpeer.h: Add declaration for pre_event_handler.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c (connectJObject):
New function.
(connectSignals): New function.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c (connectHooks):
Rename to...
(connectSignals): New name. Get rid of NewGlobalRef call.
Use g_signal_connect instead of deprecated gtk_signal_connect.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
(connect_choice_item_selectable_hook): Use g_signal_connect instead of
deprecated gtk_signal_connect.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c
(Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState): Ditto.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks): Remove
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectJObject): New
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals): New
function.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks): Remove
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectJObject): New
function.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks): Remove
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectJObject): New
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals): New
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_old_create): Remove dead
code.
(item_select): Remove indirection.
(item_unselect): Ditto.
(connect_selectable_hook): Folded into connectSignals.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks): Remove
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectJObject): New
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals): New
function.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c: Ditto.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks): Remove
function.
(Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals): New
function.
* gnu/java/awt/peer/gtk/GtkComponentPeer.java: Declare and call
connectJObject and connectSignals instead of connectHooks.
* gnu/java/awt/peer/gtk/GtkButtonPeer.java: Declare connectJObject and
connectSignals.
* gnu/java/awt/peer/gtk/GtkCheckboxPeer.java: Declare connectSignals
and not connectHooks.
* gnu/java/awt/peer/gtk/GtkTextComponentPeer.java: Ditto.
* gnu/java/awt/peer/gtk/GtkFileDialogPeer.java: Declare connectJObject
and not connectHooks.
* gnu/java/awt/peer/gtk/GtkListPeer.java: Declare connectJObject and
connectSignals instead of connectHooks.
* gnu/java/awt/peer/gtk/GtkPanelPeer.java: Ditto.
* gnu/java/awt/peer/gtk/GtkScrollbarPeer.java: Ditto.
* gnu/java/awt/peer/gtk/GtkWindowPeer.java: Ditto.
Diffstat (limited to 'native/jni')
28 files changed, 952 insertions, 539 deletions
diff --git a/native/jni/gtk-peer/gdkfont.h b/native/jni/gtk-peer/gdkfont.h new file mode 100644 index 000000000..f2ee86a2d --- /dev/null +++ b/native/jni/gtk-peer/gdkfont.h @@ -0,0 +1,93 @@ +#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., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include "gtkcairopeer.h" + +#include <pango/pango.h> +#include <pango/pango-context.h> +#include <pango/pango-fontmap.h> +#include <pango/pangoft2.h> + +extern struct state_table *native_font_state_table; +extern struct state_table *native_glyphvector_state_table; + +#define NSA_FONT_INIT(env, clazz) \ + native_font_state_table = init_state_table (env, clazz) + +#define NSA_GET_FONT_PTR(env, obj) \ + get_state (env, obj, native_font_state_table) + +#define NSA_SET_FONT_PTR(env, obj, ptr) \ + set_state (env, obj, native_font_state_table, (void *)ptr) + +#define NSA_DEL_FONT_PTR(env, obj) \ + remove_state_slot (env, obj, native_font_state_table) + + +#define NSA_GV_INIT(env, clazz) \ + native_glyphvector_state_table = init_state_table (env, clazz) + +#define NSA_GET_GV_PTR(env, obj) \ + get_state (env, obj, native_glyphvector_state_table) + +#define NSA_SET_GV_PTR(env, obj, ptr) \ + set_state (env, obj, native_glyphvector_state_table, (void *)ptr) + +#define NSA_DEL_GV_PTR(env, obj) \ + remove_state_slot (env, obj, native_glyphvector_state_table) + +struct peerfont +{ + PangoFont *font; + PangoFontDescription *desc; + PangoContext *ctx; +}; + +struct glyphvec +{ + /* the GList is list of PangoGlyphItems, each of which is a pair of 1 + PangoItem and 1 PangoGlyphString. */ + GList *glyphitems; + PangoFontDescription *desc; + PangoFont *font; + PangoContext *ctx; +}; + +#endif /* __GDKFONT_H__ */ diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c index 0f0b42446..86139db52 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c @@ -37,7 +37,6 @@ #include <math.h> -#include "gtkpeer.h" #include "gdkfont.h" #include "gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.h" diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c index 76305cae0..581cb82cf 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c @@ -35,7 +35,7 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -#include "gtkpeer.h" +#include "gtkcairopeer.h" #include "gdkfont.h" #include "gnu_java_awt_peer_gtk_GdkGraphics2D.h" #include <gdk/gdktypes.h> @@ -46,7 +46,6 @@ #include <gdk-pixbuf/gdk-pixdata.h> #include <cairo.h> -#include <cairo-xlib.h> #include <stdio.h> #include <stdlib.h> @@ -385,6 +384,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable gdk_draw_drawable(dst->drawable, gc, src->drawable, 0, 0, x, y, width, height); + gdk_flush (); g_object_unref (gc); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c index 0d7557216..222c7cede 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c @@ -153,7 +153,7 @@ area_updated (GdkPixbufLoader *loader, } static void -closed (GdkPixbufLoader *loader, jobject *decoder) +closed (GdkPixbufLoader *loader __attribute__((unused)), jobject *decoder) { gdk_threads_leave (); (*gdk_env)->DeleteGlobalRef (gdk_env, *decoder); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c index a52f54ce3..e16b2d457 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c @@ -37,20 +37,56 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkButtonPeer.h" -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create (JNIEnv *env, jobject obj) { GtkWidget *button; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + button = gtk_button_new(); gtk_widget_show (button); + gdk_threads_leave (); + NSA_SET_PTR (env, obj, button); } +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectJObject + (JNIEnv *env, jobject obj) +{ + void *ptr; + + ptr = NSA_GET_PTR (env, obj); + + gdk_threads_enter (); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + connect_awt_hook (env, obj, 1, GTK_BUTTON(ptr)->event_window); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + /* FIXME: Do we need to connect any signals here? Otherwise just do not + override parent method. */ + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); +} + JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetFont (JNIEnv *env, jobject obj, jstring name, jint style, jint size) diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c index 6559c5baf..6a1a90ce1 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c @@ -44,8 +44,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCanvasPeer_create { gpointer widget; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + widget = gtk_type_new (gtk_drawing_area_get_type ()); + gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c index 94b136667..71600c082 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c @@ -46,12 +46,17 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_create GtkWidget *widget; const char *str; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + str = (*env)->GetStringUTFChars (env, label, NULL); gdk_threads_enter (); + widget = gtk_check_menu_item_new_with_label (str); gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), 1); gtk_widget_show (widget); + gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, label, str); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c index 09fa7ef21..26a878d46 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c @@ -1,5 +1,5 @@ /* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -78,10 +78,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_remove JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeCreate - (JNIEnv *env, jobject obj, jobject group) + (JNIEnv *env, jobject obj, jobject group, jboolean state) { GtkWidget *button; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); if (group == NULL) @@ -97,6 +100,7 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeCreate NSA_SET_PTR (env, group, button); } } + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), state); gdk_threads_leave (); @@ -104,25 +108,22 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeCreate } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals (JNIEnv *env, jobject obj) { void *ptr = NSA_GET_PTR (env, obj); - jobject peer; + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); gdk_threads_enter (); - peer = (*env)->NewGlobalRef (env, obj); - - /* FIXME: when the widget goes away, we should get rid of the global - reference. */ - gtk_signal_connect (GTK_OBJECT (ptr), "toggled", - GTK_SIGNAL_FUNC (item_toggled), peer); + g_signal_connect (G_OBJECT (ptr), "toggled", + GTK_SIGNAL_FUNC (item_toggled), *gref); gdk_threads_leave (); - /* Connect the superclass hooks. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks (env, obj); + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); } JNIEXPORT void JNICALL diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c index b0130408c..068cf1e42 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c @@ -41,8 +41,9 @@ exception statement from your version. */ static void connect_choice_item_selectable_hook (JNIEnv *env, jobject peer_obj, - GtkItem *item, - jobject item_obj); + GtkItem *menuitem, + const char *label); + JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create (JNIEnv *env, jobject obj) @@ -51,7 +52,11 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create GtkOptionMenu *option_menu; GtkRequisition child_requisition; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + option_menu = GTK_OPTION_MENU (gtk_option_menu_new ()); menu = gtk_menu_new (); gtk_widget_show (menu); @@ -97,14 +102,13 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append label = (*env)->GetStringUTFChars (env, item, NULL); menuitem = gtk_menu_item_new_with_label (label); - - (*env)->ReleaseStringUTFChars (env, item, label); - gtk_menu_append (menu, menuitem); gtk_widget_show (menuitem); connect_choice_item_selectable_hook (env, obj, - GTK_ITEM (menuitem), item); + GTK_ITEM (menuitem), label); + + (*env)->ReleaseStringUTFChars (env, item, label); } if (need_set_history) @@ -135,7 +139,8 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add menuitem = gtk_menu_item_new_with_label (label); gtk_menu_insert (GTK_MENU (menu), menuitem, index); gtk_widget_show (menuitem); - connect_choice_item_selectable_hook (env, obj, GTK_ITEM (menuitem), item); + + connect_choice_item_selectable_hook (env, obj, GTK_ITEM (menuitem), label); if (need_set_history) gtk_option_menu_set_history (GTK_OPTION_MENU (ptr), 0); @@ -151,14 +156,19 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_remove { void *ptr; GtkContainer *menu; + GtkWidget *menuitem; GList *children; ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); + menu = GTK_CONTAINER (gtk_option_menu_get_menu (GTK_OPTION_MENU (ptr))); children = gtk_container_children (menu); - gtk_container_remove (menu, GTK_WIDGET (g_list_nth (children, index)->data)); + menuitem = GTK_WIDGET (g_list_nth (children, index)->data); + gtk_container_remove (menu, menuitem); + gtk_widget_destroy (menuitem); + gdk_threads_leave (); } @@ -175,31 +185,49 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_select gdk_threads_leave (); } - static void item_activate (GtkItem *item __attribute__((unused)), struct item_event_hook_info *ie) { gdk_threads_leave (); + + jstring label = (*gdk_env)->NewStringUTF (gdk_env, ie->label); (*gdk_env)->CallVoidMethod (gdk_env, ie->peer_obj, - postItemEventID, - ie->item_obj, + choicePostItemEventID, + label, (jint) AWT_ITEM_SELECTED); gdk_threads_enter (); } static void -connect_choice_item_selectable_hook (JNIEnv *env, jobject peer_obj, - GtkItem *item, jobject item_obj) +item_removed (gpointer data, + GClosure gc __attribute__((unused))) +{ + struct item_event_hook_info *ie = data; + + free (ie->label); + free (ie); +} + +static void +connect_choice_item_selectable_hook (JNIEnv *env, + jobject peer_obj, + GtkItem *menuitem, + const char *label) { struct item_event_hook_info *ie; + jobject *peer_objGlobPtr; ie = (struct item_event_hook_info *) malloc (sizeof (struct item_event_hook_info)); - ie->peer_obj = (*env)->NewGlobalRef (env, peer_obj); - ie->item_obj = (*env)->NewGlobalRef (env, item_obj); + peer_objGlobPtr = NSA_GET_GLOBAL_REF (env, peer_obj); + g_assert (peer_objGlobPtr); + + ie->peer_obj = *peer_objGlobPtr; + ie->label = strdup (label); - gtk_signal_connect (GTK_OBJECT (item), "activate", - GTK_SIGNAL_FUNC (item_activate), ie); + g_signal_connect_data (G_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (item_activate), ie, + (GClosureNotify) item_removed, 0); } diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c index cf197115a..a13274003 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c @@ -75,16 +75,16 @@ Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState (JNIEnv *env, gdk_threads_enter (); clipboard = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_signal_connect (GTK_OBJECT(clipboard), "selection_received", + g_signal_connect (G_OBJECT(clipboard), "selection_received", GTK_SIGNAL_FUNC (selection_received), NULL); - gtk_signal_connect (GTK_OBJECT(clipboard), "selection_clear_event", + g_signal_connect (G_OBJECT(clipboard), "selection_clear_event", GTK_SIGNAL_FUNC (selection_clear), NULL); gtk_selection_add_target (clipboard, GDK_SELECTION_PRIMARY, GDK_TARGET_STRING, 0); - gtk_signal_connect (GTK_OBJECT(clipboard), "selection_get", + g_signal_connect (G_OBJECT(clipboard), "selection_get", GTK_SIGNAL_FUNC (selection_get), NULL); gdk_threads_leave (); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c index 70aabf0ca..b244fd7d5 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c @@ -48,12 +48,16 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose { void *ptr; + /* Remove entries from state tables */ + NSA_DEL_GLOBAL_REF (env, obj); ptr = NSA_DEL_PTR (env, obj); + gdk_threads_enter (); + /* For now the native state for any object must be a widget. However, a subclass could override dispose() if required. */ - gdk_threads_enter (); gtk_widget_destroy (GTK_WIDGET (ptr)); + gdk_threads_leave (); } @@ -165,29 +169,69 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreen } /* - * Find the preferred size of a widget. + * Find this widget's current size. */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetDimensions - (JNIEnv *env, jobject obj, jintArray jdims) + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkRequisition requisition; + + ptr = NSA_GET_PTR (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + gdk_threads_enter (); + + gtk_widget_size_request (GTK_WIDGET (ptr), &requisition); + + dims[0] = requisition.width; + dims[1] = requisition.height; + + gdk_threads_leave (); + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); +} + +/* + * Find this widget's preferred size. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) { - void *ptr; - jint *dims; - GtkRequisition req; + void *ptr; + jint *dims; + GtkRequisition current_req; + GtkRequisition natural_req; - ptr = NSA_GET_PTR (env, obj); - dims = (*env)->GetIntArrayElements (env, jdims, 0); + ptr = NSA_GET_PTR (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + gdk_threads_enter (); + + /* Save the widget's current size request. */ + gtk_widget_size_request (GTK_WIDGET (ptr), ¤t_req); - gdk_threads_enter (); + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); + gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); - gtk_signal_emit_by_name (GTK_OBJECT (ptr), "size_request", &req); + /* Reset the widget's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), + current_req.width, current_req.height); - dims[0] = req.width; - dims[1] = req.height; + dims[0] = natural_req.width; + dims[1] = natural_req.height; - gdk_threads_leave (); + gdk_threads_leave (); - (*env)->ReleaseIntArrayElements(env, jdims, dims, 0); + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); } JNIEXPORT void JNICALL @@ -531,7 +575,7 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_set__Ljava_lang_String_2Ljava_lang_O (*env)->ReleaseStringUTFChars (env, jname, name); } -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr; @@ -539,12 +583,36 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); + gtk_widget_realize (GTK_WIDGET (ptr)); - if(GTK_IS_BUTTON(ptr)) - connect_awt_hook (env, obj, 1, GTK_BUTTON(ptr)->event_window); - else - connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window); + connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); + + gdk_threads_enter (); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + /* FIXME: We could check here if this is a scrolled window with a + single child that does not have an associated jobject. This + means that it is one of our wrapped widgets like List or TextArea + and thus we could connect the signal to the child without having + to specialize this method. */ + + /* Connect EVENT signal, which happens _before_ any specific signal. */ + + g_signal_connect (GTK_OBJECT (ptr), "event", + G_CALLBACK (pre_event_handler), *gref); + gdk_threads_leave (); } diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c index 74939f8ec..e8b8702ef 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c @@ -813,19 +813,57 @@ generates_key_typed_event (GdkEvent *event, GtkWidget *source) void awt_event_handler (GdkEvent *event) { - jobject *event_obj_ptr; + /* keep synthetic AWT events from being processed recursively */ + if (event->type & SYNTHETIC_EVENT_MASK && event->type != GDK_NOTHING) + { + event->type ^= SYNTHETIC_EVENT_MASK; + } + + gtk_main_do_event (event); +} + +gboolean +pre_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer) +{ + GtkWidget *event_widget; static guint32 button_click_time = 0; static GdkWindow *button_window = NULL; static guint button_number = -1; static jint click_count = 1; - /* keep synthetic AWT events from being processed recursively */ - if (event->type & SYNTHETIC_EVENT_MASK && event->type != GDK_NOTHING) + /* If it is not a focus change event, the widget must be realized already. + If not, ignore the event (Gtk+ will do the same). */ + if (!(event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))) + return FALSE; + + /* Do not handle propagated events. AWT has its own propagation rules */ + gdk_window_get_user_data (event->any.window, (void **) &event_widget); + if (event_widget != widget) + return FALSE; + + /* We only care about input events */ + if (!(event->type == GDK_BUTTON_PRESS + || event->type == GDK_BUTTON_RELEASE + || event->type == GDK_ENTER_NOTIFY + || event->type == GDK_LEAVE_NOTIFY + || event->type == GDK_CONFIGURE + || event->type == GDK_EXPOSE + || event->type == GDK_KEY_PRESS + || event->type == GDK_KEY_RELEASE + || event->type == GDK_FOCUS_CHANGE + || event->type == GDK_MOTION_NOTIFY)) { - event->type ^= SYNTHETIC_EVENT_MASK; - gtk_main_do_event (event); - return; + return FALSE; } + /* g_print("event %u widget %s peer %p\n", + event->type, gtk_widget_get_name (widget), peer); */ + + /* If it has no jobject associated we can send no AWT event */ + if (!peer) + return FALSE; + + /* for all input events, which have a window with a jobject attached, + send the AWT input event corresponding to the Gtk event off to Java */ /* keep track of clickCount ourselves, since the AWT allows more than a triple click to occur */ @@ -843,341 +881,266 @@ awt_event_handler (GdkEvent *event) button_number = event->button.button; } - /* for all input events, which have a window with a jobject attached, - send the input event off to Java before GTK has a chance to process - the event */ - if ((event->type == GDK_BUTTON_PRESS - || event->type == GDK_BUTTON_RELEASE - || event->type == GDK_ENTER_NOTIFY - || event->type == GDK_LEAVE_NOTIFY - || event->type == GDK_CONFIGURE - || event->type == GDK_EXPOSE - || event->type == GDK_KEY_PRESS - || event->type == GDK_KEY_RELEASE - || event->type == GDK_FOCUS_CHANGE - || event->type == GDK_MOTION_NOTIFY) - && gdk_property_get (event->any.window, - gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), - 0, - sizeof (jobject), - FALSE, - NULL, - NULL, - NULL, - (guchar **)&event_obj_ptr)) + switch (event->type) { - GtkWidget *event_widget; - GtkWidget *grab_widget; - jobject *grab_obj_ptr = NULL; - void *ptr; - - /* Implement modality using GTK grabs. */ - g_assert (global_gtk_window_group); - if (global_gtk_window_group->grabs) - { - grab_widget = global_gtk_window_group->grabs->data; - g_assert (grab_widget); - - gdk_property_get (grab_widget->window, - gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), - 0, - sizeof (jobject), - FALSE, - NULL, - NULL, - NULL, - (guchar **)&grab_obj_ptr); - - ptr = NSA_GET_PTR (gdk_env, *event_obj_ptr); - event_widget = GTK_WIDGET(ptr); - - if (GTK_WIDGET_IS_SENSITIVE (event_widget) && - gtk_widget_is_ancestor (event_widget, grab_widget)) - { - g_free (grab_obj_ptr); - - grab_obj_ptr = event_obj_ptr; - } - } - else - grab_obj_ptr = event_obj_ptr; - - switch (event->type) - { - case GDK_BUTTON_PRESS: - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, postMouseEventID, - AWT_MOUSE_PRESSED, - (jlong)event->button.time, - state_to_awt_mods (event->button.state) | - button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, - (event->button.button == 3) ? JNI_TRUE : - JNI_FALSE); - - /* grab_counter++; - gdk_pointer_grab (event->any.window, - FALSE, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK, - NULL, - NULL, - event->button.time);*/ - break; - case GDK_BUTTON_RELEASE: - { - int width, height; - - /* only ungrab if no other buttons are pressed down */ - /* if (--grab_counter == 0) - gdk_pointer_ungrab (event->button.time); - */ - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postMouseEventID, - AWT_MOUSE_RELEASED, - (jlong)event->button.time, + case GDK_BUTTON_PRESS: + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postMouseEventID, + AWT_MOUSE_PRESSED, + (jlong)event->button.time, + state_to_awt_mods (event->button.state) | + button_to_awt_mods (event->button.button), + (jint)event->button.x, + (jint)event->button.y, + click_count, + (event->button.button == 3) ? JNI_TRUE : + JNI_FALSE); + break; + case GDK_BUTTON_RELEASE: + { + int width, height; + + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postMouseEventID, + AWT_MOUSE_RELEASED, + (jlong)event->button.time, state_to_awt_mods (event->button.state) | button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, JNI_FALSE); - - /* check to see if the release occured in the window it was pressed - in, and if so, generate an AWT click event */ - gdk_window_get_size (event->any.window, &width, &height); - if (event->button.x >= 0 - && event->button.y >= 0 - && event->button.x <= width - && event->button.y <= height) - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postMouseEventID, - AWT_MOUSE_CLICKED, - (jlong)event->button.time, - state_to_awt_mods (event->button.state) | - button_to_awt_mods (event->button.button), - (jint)event->button.x, - (jint)event->button.y, - click_count, JNI_FALSE); - - } - break; - case GDK_MOTION_NOTIFY: - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, postMouseEventID, - AWT_MOUSE_MOVED, + (jint)event->button.x, + (jint)event->button.y, + click_count, + JNI_FALSE); + + /* check to see if the release occured in the window it was pressed + in, and if so, generate an AWT click event */ + gdk_window_get_size (event->any.window, &width, &height); + if (event->button.x >= 0 + && event->button.y >= 0 + && event->button.x <= width + && event->button.y <= height) + { + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postMouseEventID, + AWT_MOUSE_CLICKED, + (jlong)event->button.time, + state_to_awt_mods (event->button.state) | + button_to_awt_mods (event->button.button), + (jint)event->button.x, + (jint)event->button.y, + click_count, + JNI_FALSE); + } + } + break; + case GDK_MOTION_NOTIFY: + (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, + AWT_MOUSE_MOVED, + (jlong)event->motion.time, + state_to_awt_mods (event->motion.state), + (jint)event->motion.x, + (jint)event->motion.y, + 0, + JNI_FALSE); + + if (event->motion.state & (GDK_BUTTON1_MASK + | GDK_BUTTON2_MASK + | GDK_BUTTON3_MASK + | GDK_BUTTON4_MASK + | GDK_BUTTON5_MASK)) + { + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postMouseEventID, + AWT_MOUSE_DRAGGED, (jlong)event->motion.time, state_to_awt_mods (event->motion.state), (jint)event->motion.x, (jint)event->motion.y, - 0, JNI_FALSE); - - if (event->motion.state & (GDK_BUTTON1_MASK - | GDK_BUTTON2_MASK - | GDK_BUTTON3_MASK - | GDK_BUTTON4_MASK - | GDK_BUTTON5_MASK)) - { - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postMouseEventID, - AWT_MOUSE_DRAGGED, - (jlong)event->motion.time, - state_to_awt_mods (event->motion.state), - (jint)event->motion.x, - (jint)event->motion.y, - 0, JNI_FALSE); - } - break; - case GDK_ENTER_NOTIFY: - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, postMouseEventID, - AWT_MOUSE_ENTERED, - (jlong)event->crossing.time, - state_to_awt_mods (event->crossing.state), - (jint)event->crossing.x, - (jint)event->crossing.y, - 0, JNI_FALSE); - break; - case GDK_LEAVE_NOTIFY: - if (event->crossing.mode == GDK_CROSSING_NORMAL) - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postMouseEventID, - AWT_MOUSE_EXITED, - (jlong)event->crossing.time, + 0, + JNI_FALSE); + } + break; + case GDK_ENTER_NOTIFY: + (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, + AWT_MOUSE_ENTERED, + (jlong)event->crossing.time, + state_to_awt_mods (event->crossing.state), + (jint)event->crossing.x, + (jint)event->crossing.y, + 0, + JNI_FALSE); + break; + case GDK_LEAVE_NOTIFY: + if (event->crossing.mode == GDK_CROSSING_NORMAL) + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postMouseEventID, + AWT_MOUSE_EXITED, + (jlong)event->crossing.time, state_to_awt_mods (event->crossing.state), - (jint)event->crossing.x, - (jint)event->crossing.y, - 0, JNI_FALSE); - break; - case GDK_CONFIGURE: - { - GtkWidget *widget; - - gdk_window_get_user_data (event->any.window, (void **) &widget); + (jint)event->crossing.x, + (jint)event->crossing.y, + 0, + JNI_FALSE); + break; + case GDK_CONFIGURE: + { + /* GtkWidget *widget; + + gdk_window_get_user_data (event->any.window, (void **) &widget); */ - if (widget && GTK_WIDGET_TOPLEVEL (widget)) - { - gint top, left, right, bottom; + if (widget && GTK_WIDGET_TOPLEVEL (widget)) + { + gint top, left, right, bottom; - /* Configure events are not posted to the AWT event - queue, and as such, the gdk/gtk peer functions will - be called back before postConfigureEvent - returns. */ - gdk_threads_leave (); + /* Configure events are not posted to the AWT event + queue, and as such, the gdk/gtk peer functions will + be called back before postConfigureEvent + returns. */ + gdk_threads_leave (); - /* FIXME: hard-code these values for now. */ + /* FIXME: hard-code these values for now. */ + if (GTK_IS_PLUG (widget)) + { + top = 0; + left = 0; + bottom = 0; + right = 0; + } + else + { top = 20; left = 6; bottom = 6; right = 6; - - (*gdk_env)->CallVoidMethod (gdk_env, *event_obj_ptr, - postConfigureEventID, - (jint) event->configure.x, - (jint) event->configure.y, - (jint) event->configure.width, - (jint) event->configure.height, - (jint) top, - (jint) left, - (jint) bottom, - (jint) right); - gdk_threads_enter (); } - } - break; - case GDK_EXPOSE: - { - (*gdk_env)->CallVoidMethod (gdk_env, *event_obj_ptr, - postExposeEventID, - (jint)event->expose.area.x, - (jint)event->expose.area.y, - (jint)event->expose.area.width, - (jint)event->expose.area.height); - } - break; - case GDK_KEY_PRESS: - { - GtkWidget *widget; - GtkWindow *window; - /* The window to which the Java peer is attached. */ - GdkWindow *obj_window; - - gdk_window_get_user_data (event->any.window, (void **) &widget); - - window = GTK_WINDOW (gtk_widget_get_ancestor (widget, - GTK_TYPE_WINDOW)); - if (window - && GTK_WIDGET_IS_SENSITIVE (window) - && window->focus_widget - && GTK_WIDGET_IS_SENSITIVE (window->focus_widget) - && window->focus_widget->window) - { - gtk_widget_activate (window->focus_widget); - - /* TextArea peers are attached to the scrolled window - that contains the GtkTextView, not to the text view - itself. */ - if (GTK_IS_TEXT_VIEW (window->focus_widget)) - obj_window = gtk_widget_get_parent (window->focus_widget)->window; - else - obj_window = window->focus_widget->window; - - gdk_property_get (obj_window, - gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), - 0, - sizeof (jobject), - FALSE, - NULL, - NULL, - NULL, - (guchar **)&grab_obj_ptr); - - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postKeyEventID, - (jint) AWT_KEY_PRESSED, - (jlong) event->key.time, - keyevent_state_to_awt_mods (event), - keysym_to_awt_keycode (event), - keyevent_to_awt_keychar (event), - keysym_to_awt_keylocation (event)); - - if (generates_key_typed_event (event, window->focus_widget)) - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postKeyEventID, - (jint) AWT_KEY_TYPED, - (jlong) event->key.time, - state_to_awt_mods (event->key.state), - VK_UNDEFINED, - keyevent_to_awt_keychar (event), - AWT_KEY_LOCATION_UNKNOWN); - } + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postConfigureEventID, + (jint) event->configure.x, + (jint) event->configure.y, + (jint) event->configure.width, + (jint) event->configure.height, + (jint) top, + (jint) left, + (jint) bottom, + (jint) right); + gdk_threads_enter (); } - break; - case GDK_KEY_RELEASE: + } + break; + case GDK_EXPOSE: + { + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postExposeEventID, + (jint)event->expose.area.x, + (jint)event->expose.area.y, + (jint)event->expose.area.width, + (jint)event->expose.area.height); + } + break; + case GDK_FOCUS_CHANGE: + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postFocusEventID, + (jint) (event->focus_change.in) ? + AWT_FOCUS_GAINED : AWT_FOCUS_LOST, + JNI_FALSE); + break; + case GDK_KEY_PRESS: + case GDK_KEY_RELEASE: + { + GdkWindow *obj_window; + jobject *focus_obj_ptr = NULL; + int generates_key_typed = 0; + + /* A widget with a grab will get key events */ + if (!GTK_IS_WINDOW (widget)) + focus_obj_ptr = &peer; + else { - GtkWidget *widget; - GtkWindow *window; - GdkWindow *obj_window; - - gdk_window_get_user_data (event->any.window, (void **) &widget); - - window = GTK_WINDOW (gtk_widget_get_ancestor (widget, - GTK_TYPE_WINDOW)); - if (window - && GTK_WIDGET_IS_SENSITIVE (window) - && window->focus_widget - && GTK_WIDGET_IS_SENSITIVE (window->focus_widget) - && window->focus_widget->window) - { - gtk_widget_activate (window->focus_widget); - - if (GTK_IS_TEXT_VIEW (window->focus_widget)) - obj_window = gtk_widget_get_parent (window->focus_widget)->window; - else - obj_window = window->focus_widget->window; - - gdk_property_get (obj_window, - gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), - 0, - sizeof (jobject), - FALSE, - NULL, - NULL, - NULL, - (guchar **)&grab_obj_ptr); - - (*gdk_env)->CallVoidMethod (gdk_env, *grab_obj_ptr, - postKeyEventID, - (jint) AWT_KEY_RELEASED, - (jlong) event->key.time, - keyevent_state_to_awt_mods (event), - keysym_to_awt_keycode (event), - keyevent_to_awt_keychar (event), - keysym_to_awt_keylocation (event)); + GtkWindow *window; + + /* Check if we have an enabled focused widget in this window. + If not don't handle the event. */ + window = GTK_WINDOW (widget); + if (!window->focus_widget + || !GTK_WIDGET_IS_SENSITIVE (window->focus_widget) + || !window->focus_widget->window) + return FALSE; + + /* TextArea peers are attached to the scrolled window + that contains the GtkTextView, not to the text view + itself. Same for List. */ + if (GTK_IS_TEXT_VIEW (window->focus_widget) + || GTK_IS_CLIST (window->focus_widget)) + { + obj_window = gtk_widget_get_parent (window->focus_widget)->window; + } + else if (GTK_IS_BUTTON (window->focus_widget)) + /* GtkButton events go to the "event_window" and this is what + we registered when the button was created. */ + obj_window = GTK_BUTTON (window->focus_widget)->event_window; + else + obj_window = window->focus_widget->window; + + gdk_property_get (obj_window, + gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), + gdk_atom_intern ("CARDINAL", FALSE), + 0, + sizeof (jobject), + FALSE, + NULL, + NULL, + NULL, + (guchar **)&focus_obj_ptr); + + /* If the window has no jobject attached we can't send anything */ + if (!focus_obj_ptr) + return FALSE; + + /* Should we generate an AWT_KEY_TYPED event? */ + generates_key_typed = generates_key_typed_event (event, window->focus_widget); + } + + if (event->type == GDK_KEY_PRESS) + { + (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, + postKeyEventID, + (jint) AWT_KEY_PRESSED, + (jlong) event->key.time, + keyevent_state_to_awt_mods (event), + keysym_to_awt_keycode (event), + keyevent_to_awt_keychar (event), + keysym_to_awt_keylocation (event)); + + if (generates_key_typed) + { + (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, + postKeyEventID, + (jint) AWT_KEY_TYPED, + (jlong) event->key.time, + state_to_awt_mods (event->key.state), + VK_UNDEFINED, + keyevent_to_awt_keychar (event), + AWT_KEY_LOCATION_UNKNOWN); } } - break; - case GDK_FOCUS_CHANGE: - (*gdk_env)->CallVoidMethod (gdk_env, *event_obj_ptr, - postFocusEventID, - (jint) (event->focus_change.in) ? - AWT_FOCUS_GAINED : AWT_FOCUS_LOST, - JNI_FALSE); - break; - default: - break; - } - g_free (event_obj_ptr); + else /* GDK_KEY_RELEASE */ + { + (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, + postKeyEventID, + (jint) AWT_KEY_RELEASED, + (jlong) event->key.time, + keyevent_state_to_awt_mods (event), + keysym_to_awt_keycode (event), + keyevent_to_awt_keychar (event), + keysym_to_awt_keylocation (event)); + } + } + break; + default: + break; } - - gtk_main_do_event (event); + + return FALSE; } static void @@ -1215,10 +1178,11 @@ connect_awt_hook (JNIEnv *env, jobject peer_obj, int nwindows, ...) { va_list ap; jobject *obj; + //void *ptr = NSA_GET_PTR (env, peer_obj); - obj = (jobject *) malloc (sizeof (jobject)); - *obj = (*env)->NewGlobalRef (env, peer_obj); - //g_print("Connection obj %p\n", peer_obj); + obj = NSA_GET_GLOBAL_REF (env, peer_obj); + //g_print("Connection obj %s\n", gtk_widget_get_name (GTK_WIDGET (ptr))); + g_assert (obj); va_start (ap, nwindows); { @@ -1226,9 +1190,9 @@ connect_awt_hook (JNIEnv *env, jobject peer_obj, int nwindows, ...) for (i = 0; i < nwindows; i++) { GdkWindow* attach = (va_arg (ap, GdkWindow *)); - //g_print("attach peer obj %p and %p\n", peer_obj, attach); attach_jobject(attach, obj); } } va_end (ap); } + diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c index 2308d1100..47a08ae8e 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c @@ -49,23 +49,28 @@ Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create { gpointer widget; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + widget = gtk_type_new (gtk_file_selection_get_type ()); + gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); - /* NOTE: we don't call the superclass connect method here. */ gtk_widget_realize (GTK_WIDGET (ptr)); + connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window); gdk_threads_leave (); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c index 38a45d8e2..0865f6316 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c @@ -48,10 +48,13 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create GtkContainer *ebox_container; const char *str; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + str = (*env)->GetStringUTFChars (env, text, 0); gdk_threads_enter (); - + ebox = gtk_event_box_new (); ebox_container = GTK_CONTAINER (ebox); label = gtk_label_new (str); @@ -90,7 +93,7 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setAlignment +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment (JNIEnv *env, jobject obj, jfloat xalign) { void *ptr; diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c index 6c37aeb82..ac6f389f8 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c @@ -37,10 +37,18 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkListPeer.h" -static void -connect_selectable_hook (JNIEnv *env, jobject peer_obj, GtkCList *list); +static void item_select (GtkCList *list __attribute__((unused)), + int row, int col __attribute__((unused)), + GdkEventButton *event __attribute__((unused)), + jobject peer_obj); +static void item_unselect (GtkCList *list __attribute__((unused)), + int row, + int col __attribute__((unused)), + GdkEventButton *event __attribute__((unused)), + jobject peer_obj); #define CLIST_FROM_SW(obj) (GTK_CLIST(GTK_SCROLLED_WINDOW (obj)->container.child)) @@ -50,7 +58,11 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_create { GtkWidget *list, *sw; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + list = gtk_clist_new (1); gtk_widget_show (list); sw = gtk_scrolled_window_new (NULL, NULL); @@ -58,13 +70,14 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_create GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), list); + gdk_threads_leave (); NSA_SET_PTR (env, obj, sw); } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkListPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr; @@ -72,76 +85,61 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_connectHooks ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); + gtk_widget_realize (GTK_WIDGET (ptr)); - connect_selectable_hook (env, obj, CLIST_FROM_SW (ptr)); + connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window); + gdk_threads_leave (); } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_append - (JNIEnv *env, jobject obj, jobjectArray items) +Java_gnu_java_awt_peer_gtk_GtkListPeer_connectSignals + (JNIEnv *env, jobject obj) { - void *ptr; GtkCList *list; - jint count, i; + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); - ptr = NSA_GET_PTR (env, obj); + gdk_threads_enter (); - count = (*env)->GetArrayLength (env, items); + gtk_widget_realize (GTK_WIDGET (ptr)); - gdk_threads_enter (); + /* connect selectable hook */ + list = CLIST_FROM_SW (ptr); - for (i = 0; i < count; i++) - { - const char *text; - jobject item; - item = (*env)->GetObjectArrayElement (env, items, i); + g_signal_connect (G_OBJECT (list), "select_row", + GTK_SIGNAL_FUNC (item_select), *gref); - text = (*env)->GetStringUTFChars (env, item, NULL); - gtk_clist_append (list, (char **)&text); - (*env)->ReleaseStringUTFChars (env, item, text); - } + g_signal_connect (G_OBJECT (list), "unselect_row", + GTK_SIGNAL_FUNC (item_unselect), *gref); + + /* Connect the superclass signals. */ + /* FIXME: Cannot do that here or it will get the sw and not the list. + We must a generic way of doing this. */ + /* Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, peer_obj); */ + g_signal_connect (GTK_OBJECT (list), "event", + G_CALLBACK (pre_event_handler), *gref); - gtk_clist_columns_autosize (list); gdk_threads_leave (); } - JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkListPeer_old_create - (JNIEnv *env, jobject obj, jobject parent_obj, - jobjectArray items, jboolean mode) +Java_gnu_java_awt_peer_gtk_GtkListPeer_append + (JNIEnv *env, jobject obj, jobjectArray items) { - GtkWidget *list, *sw, *parent; - jsize count, i; + void *ptr; + GtkCList *list; + jint count, i; - parent = NSA_GET_PTR (env, parent_obj); + ptr = NSA_GET_PTR (env, obj); count = (*env)->GetArrayLength (env, items); gdk_threads_enter (); - - list = gtk_clist_new (1); - gtk_widget_show (list); - - sw = gtk_scrolled_window_new (NULL, NULL); - set_parent (sw, GTK_CONTAINER (parent)); - gtk_widget_realize (sw); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (sw), list); - - connect_selectable_hook (env, obj, GTK_CLIST (list)); - connect_awt_hook (env, obj, 1, list->window); - - gtk_clist_set_selection_mode (GTK_CLIST (list), - mode ? GTK_SELECTION_MULTIPLE : - GTK_SELECTION_SINGLE); - + list = CLIST_FROM_SW (ptr); for (i = 0; i < count; i++) { const char *text; @@ -150,14 +148,12 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_old_create item = (*env)->GetObjectArrayElement (env, items, i); text = (*env)->GetStringUTFChars (env, item, NULL); - gtk_clist_append (GTK_CLIST (list), (char **)&text); + gtk_clist_append (list, (char **)&text); (*env)->ReleaseStringUTFChars (env, item, text); } - gtk_clist_columns_autosize (GTK_CLIST (list)); + gtk_clist_columns_autosize (list); gdk_threads_leave (); - - NSA_SET_PTR (env, obj, sw); } JNIEXPORT void JNICALL @@ -192,12 +188,14 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_delItems list = CLIST_FROM_SW (ptr); if (end == -1) /* special case for removing all rows */ - end = list->rows; - - gtk_clist_freeze (list); - for (i = start; i < end; i++) - gtk_clist_remove (list, i); - gtk_clist_thaw (list); + gtk_clist_clear (list); + else + { + gtk_clist_freeze (list); + for (i = end; i >= start; i--) + gtk_clist_remove (list, i); + gtk_clist_thaw (list); + } gdk_threads_leave (); } @@ -324,9 +322,10 @@ static void item_select (GtkCList *list __attribute__((unused)), int row, int col __attribute__((unused)), GdkEventButton *event __attribute__((unused)), - jobject *peer_obj) + jobject peer_obj) { - (*gdk_env)->CallVoidMethod (gdk_env, *peer_obj, + //g_print ("select_row\n"); + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, postListItemEventID, row, (jint) AWT_ITEM_SELECTED); @@ -337,25 +336,12 @@ item_unselect (GtkCList *list __attribute__((unused)), int row, int col __attribute__((unused)), GdkEventButton *event __attribute__((unused)), - jobject *peer_obj) + jobject peer_obj) { - (*gdk_env)->CallVoidMethod (gdk_env, *peer_obj, + //g_print ("unselect_row\n"); + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, postListItemEventID, row, (jint) AWT_ITEM_DESELECTED); } -static void -connect_selectable_hook (JNIEnv *env, jobject peer_obj, GtkCList *list) -{ - jobject *obj; - - obj = (jobject *) malloc (sizeof (jobject)); - *obj = (*env)->NewGlobalRef (env, peer_obj); - - gtk_signal_connect (GTK_OBJECT (list), "select_row", - GTK_SIGNAL_FUNC (item_select), obj); - - gtk_signal_connect (GTK_OBJECT (list), "unselect_row", - GTK_SIGNAL_FUNC (item_unselect), obj); -} diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c index 5d144f8ec..bad4a5168 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c @@ -42,6 +42,7 @@ exception statement from your version. */ #ifdef JVM_SUN struct state_table *native_state_table; + struct state_table *native_global_ref_table; #endif jmethodID setBoundsCallbackID; @@ -55,6 +56,7 @@ jmethodID postKeyEventID; jmethodID postFocusEventID; jmethodID postAdjustmentEventID; jmethodID postItemEventID; +jmethodID choicePostItemEventID; jmethodID postListItemEventID; jmethodID postTextEventID; jmethodID postWindowEventID; @@ -79,7 +81,7 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) char **argv; char *homedir, *rcpath = NULL; /* jclass gtkgenericpeer; */ - jclass gtkcomponentpeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer, + jclass gtkcomponentpeer, gtkchoicepeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer, gtkmenuitempeer, gtktextcomponentpeer, window; NSA_INIT (env, clazz); @@ -138,6 +140,8 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) gtkcomponentpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkComponentPeer"); + gtkchoicepeer = (*env)->FindClass (env, + "gnu/java/awt/peer/gtk/GtkChoicePeer"); gtkwindowpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkWindowPeer"); gtkscrollbarpeer = (*env)->FindClass (env, @@ -180,6 +184,9 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer, "postItemEvent", "(Ljava/lang/Object;I)V"); + choicePostItemEventID = (*env)->GetMethodID (env, gtkchoicepeer, + "choicePostItemEvent", + "(Ljava/lang/String;I)V"); postListItemEventID = (*env)->GetMethodID (env, gtklistpeer, "postItemEvent", "(II)V"); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c index 89818e05f..48509a5d3 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c @@ -44,9 +44,14 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_create { GtkWidget *widget; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + widget = gtk_menu_bar_new (); gtk_widget_show (widget); + gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c index 10c9e4cab..4984760f9 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c @@ -40,26 +40,35 @@ exception statement from your version. */ #include "gnu_java_awt_peer_gtk_GtkMenuItemPeer.h" #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" -static void -connect_activate_hook (JNIEnv *, jobject, GtkMenuItem *); +static void item_activate (GtkMenuItem *item __attribute__((unused)), + jobject *peer_obj); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create (JNIEnv *env, jobject obj, jstring label) { GtkWidget *widget; const char *str; + jobject *gref; + + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gref = NSA_GET_GLOBAL_REF (env, obj); str = (*env)->GetStringUTFChars (env, label, NULL); gdk_threads_enter (); - + if (strcmp (str, "-") == 0) /* "-" signals that we need a separator */ widget = gtk_menu_item_new (); else widget = gtk_menu_item_new_with_label (str); - connect_activate_hook (env, obj, GTK_MENU_ITEM (widget)); + /* Connect activate hook */ + g_signal_connect (G_OBJECT (widget), "activate", + GTK_SIGNAL_FUNC (item_activate), *gref); + gtk_widget_show (widget); + gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, label, str); @@ -101,14 +110,3 @@ item_activate (GtkMenuItem *item __attribute__((unused)), jobject *peer_obj) postMenuActionEventID); } -static void -connect_activate_hook (JNIEnv *env, jobject peer_obj, GtkMenuItem *item) -{ - jobject *obj; - - obj = (jobject *) malloc (sizeof (jobject)); - *obj = (*env)->NewGlobalRef (env, peer_obj); - - gtk_signal_connect (GTK_OBJECT (item), "activate", - GTK_SIGNAL_FUNC (item_activate), obj); -} diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c index e8cd78cb1..63e6a7401 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c @@ -66,7 +66,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup if (GTK_WIDGET_REALIZED (GTK_WIDGET (ptr1))) accel_attach (GTK_MENU_ITEM (ptr1), NULL); else - gtk_signal_connect (GTK_OBJECT (ptr1), + g_signal_connect (G_OBJECT (ptr1), "realize", GTK_SIGNAL_FUNC (accel_attach), NULL); @@ -92,9 +92,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create GtkWidget *menu_title, *menu; const char *str; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + str = (*env)->GetStringUTFChars (env, label, NULL); gdk_threads_enter (); + menu = gtk_menu_new (); menu_title = gtk_menu_item_new_with_label (str); @@ -104,6 +108,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create gtk_widget_show (menu_title); NSA_SET_PTR (env, obj, menu_title); + gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, label, str); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c index 5d3898954..62fff4d8a 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c @@ -37,6 +37,7 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkPanelPeer.h" JNIEXPORT void JNICALL @@ -45,8 +46,13 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create { gpointer widget; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + widget = gtk_layout_new (NULL, NULL); + gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); @@ -61,7 +67,7 @@ struct _GtkLayoutChild { }; JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr; @@ -72,11 +78,31 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectHooks gtk_widget_realize (GTK_WIDGET (ptr)); connect_awt_hook (env, obj, 1, GTK_LAYOUT (ptr)->bin_window); -/* gtk_signal_connect (GTK_OBJECT (ptr), "size_request", GTK_SIGNAL_FUNC (sr), */ + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); + + gdk_threads_enter (); + gtk_widget_realize (GTK_WIDGET (ptr)); + + /* FIXME: If we don't need this then remove this method. */ +/* g_signal_connect (G_OBJECT (ptr), "size_request", GTK_SIGNAL_FUNC (sr), */ /* NULL); */ gdk_threads_leave (); + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); } +/* FIXME: The following doesn't seem to be used. + Is not declared as a native function in GtkPanelPeer.java */ /* * Make a new panel. */ @@ -87,19 +113,26 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_gtkPanelNew GtkWidget *layout; void *parent; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + parent = NSA_GET_PTR (env, parent_obj); gdk_threads_enter (); + layout = gtk_layout_new (NULL, NULL); set_parent (layout, GTK_CONTAINER (parent)); gtk_widget_realize (layout); + connect_awt_hook (env, obj, 1, GTK_LAYOUT (layout)->bin_window); + set_visible (layout, 1); - NSA_SET_PTR (env, obj, layout); gdk_threads_leave (); + + NSA_SET_PTR (env, obj, layout); } diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c index 2bd3df8cf..be7e2d0a4 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c @@ -37,6 +37,7 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h" struct range_scrollbar @@ -107,46 +108,70 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create GtkWidget *sb; GtkObject *adj; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + adj = gtk_adjustment_new (value, min, max, step_incr, page_incr, visible_amount); sb = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) : gtk_hscrollbar_new (GTK_ADJUSTMENT (adj)); + gdk_threads_leave (); NSA_SET_PTR (env, obj, sb); } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr; + + ptr = NSA_GET_PTR (env, obj); + + gdk_threads_enter (); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + connect_awt_hook (env, obj, 1, GTK_SCROLLBAR (ptr)->range); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals + (JNIEnv *env, jobject obj) +{ struct range_scrollbar *rs; + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); rs = (struct range_scrollbar *) malloc (sizeof (struct range_scrollbar)); - ptr = NSA_GET_PTR (env, obj); - gdk_threads_enter (); + gtk_widget_realize (GTK_WIDGET (ptr)); rs->range = GTK_RANGE (ptr); - rs->scrollbar = (jobject *) malloc (sizeof (jobject)); - *(rs->scrollbar) = (*env)->NewGlobalRef (env, obj); - gtk_signal_connect (GTK_OBJECT (GTK_RANGE (ptr)), + rs->scrollbar = gref; + + g_signal_connect (G_OBJECT (GTK_RANGE (ptr)), "move-slider", GTK_SIGNAL_FUNC (post_adjustment_event), rs); - gtk_signal_connect (GTK_OBJECT (GTK_RANGE (ptr)), + g_signal_connect (G_OBJECT (GTK_RANGE (ptr)), "value-changed", GTK_SIGNAL_FUNC (post_change_event), rs); - - connect_awt_hook (env, obj, 1, GTK_SCROLLBAR (ptr)->range); gdk_threads_leave (); + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); } diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c index 08ae7e5cf..79e5082bb 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c @@ -41,15 +41,22 @@ exception statement from your version. */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_create - (JNIEnv *env, jobject obj) + (JNIEnv *env, jobject obj, int width, int height) { - gpointer window; + GtkWidget *sw; + + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); gdk_threads_enter (); - window = gtk_scrolled_window_new (NULL, NULL); + + sw = gtk_scrolled_window_new (NULL, NULL); + + gtk_widget_set_size_request (sw, width, height); + gdk_threads_leave (); - NSA_SET_PTR (env, obj, window); + NSA_SET_PTR (env, obj, sw); } JNIEXPORT void JNICALL @@ -111,34 +118,25 @@ Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_gtkScrolledWindowSetVScrollIncremen gdk_threads_leave (); } -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_childResized - (JNIEnv *env, jobject obj, jint width, jint height) -{ - void *ptr; - - ptr = NSA_GET_PTR (env, obj); - - return; - - gdk_threads_enter (); - gtk_widget_set_usize (GTK_BIN (ptr)->child, width, height); - gdk_threads_leave (); -} - JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getHScrollbarHeight (JNIEnv *env, jobject obj) { void *ptr; GtkScrolledWindow *sw; - jint height; + GtkRequisition requisition; + jint height = 0; + jint spacing = 0; ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); sw = GTK_SCROLLED_WINDOW (ptr); - height = (sw->hscrollbar_visible) ? sw->hscrollbar->allocation.height : 0; + + 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; @@ -150,13 +148,19 @@ Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getVScrollbarWidth { void *ptr; GtkScrolledWindow *sw; - jint width; + GtkRequisition requisition; + jint width = 0; + jint spacing = 0; ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); sw = GTK_SCROLLED_WINDOW (ptr); - width = (sw->vscrollbar_visible) ? sw->vscrollbar->allocation.width : 0; + + gtk_widget_size_request (sw->vscrollbar, &requisition); + gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); + width = requisition.width + spacing; + gdk_threads_leave (); return width; diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c index c6d97d576..71a789ed3 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c @@ -46,8 +46,11 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create { GtkWidget *text, *sw; - gdk_threads_enter (); + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + text = gtk_text_view_new (); gtk_widget_show (text); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c index 7e6d02f17..2ec87f012 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c @@ -48,24 +48,29 @@ static void textcomponent_changed_cb (GtkEditable *editable, jobject peer); JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_connectHooks +Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_connectSignals (JNIEnv *env, jobject obj) { - void *ptr; GtkTextView *text = NULL; GtkTextBuffer *buf; - - ptr = NSA_GET_PTR (env, obj); + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); gdk_threads_enter (); if (GTK_IS_ENTRY(ptr)) { g_signal_connect (GTK_ENTRY (ptr)->im_context, "commit", - G_CALLBACK (textcomponent_commit_cb), obj); + G_CALLBACK (textcomponent_commit_cb), *gref); g_signal_connect (GTK_EDITABLE (ptr), "changed", - G_CALLBACK (textcomponent_changed_cb), obj); + G_CALLBACK (textcomponent_changed_cb), *gref); + + gdk_threads_leave (); + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, *gref); } else { @@ -81,19 +86,24 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_connectHooks if (text) { g_signal_connect (text->im_context, "commit", - G_CALLBACK (textcomponent_commit_cb), obj); + G_CALLBACK (textcomponent_commit_cb), *gref); buf = gtk_text_view_get_buffer (text); if (buf) g_signal_connect (buf, "changed", - G_CALLBACK (textcomponent_changed_cb), obj); - } - } + G_CALLBACK (textcomponent_changed_cb), *gref); - gdk_threads_leave (); + /* Connect the superclass signals. */ + /* FIXME: Cannot do that here or it will get the sw and not the list. + We must a generic way of doing this. */ + /* Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, + obj); */ + g_signal_connect (GTK_OBJECT (text), "event", + G_CALLBACK (pre_event_handler), *gref); - /* Connect the superclass hooks. */ - Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectHooks (env, obj); + gdk_threads_leave (); + } + } } JNIEXPORT jint JNICALL @@ -101,7 +111,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getCaretPosition (JNIEnv *env, jobject obj) { void *ptr; - int pos; + int pos = 0; GtkEditable *editable; // type of GtkEntry (TextField) GtkWidget *text = NULL; // type of GtkTextView (TextArea) GtkTextBuffer *buf; @@ -187,7 +197,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionStart (JNIEnv *env, jobject obj) { void *ptr; - int pos; + int pos = 0; GtkEditable *editable; // type of GtkEntry (TextField) GtkWidget *text = NULL; // type of GtkTextView (TextArea) GtkTextBuffer *buf; @@ -244,7 +254,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getSelectionEnd (JNIEnv *env, jobject obj) { void *ptr; - int pos; + int pos = 0; GtkEditable *editable; // type of GtkEntry (TextField) GtkWidget *text = NULL; // type of GtkTextView (TextArea) GtkTextBuffer *buf; @@ -384,7 +394,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextComponentPeer_getText (JNIEnv *env, jobject obj) { void *ptr; - char *contents; + char *contents = NULL; jstring jcontents; GtkEditable *editable; // type of GtkEntry (TextField) GtkWidget *text = NULL; // type of GtkTextView (TextArea) diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c index a7bbb02f8..5379635b8 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c @@ -45,8 +45,13 @@ Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_create { GtkWidget *widget; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + widget = gtk_entry_new (); + gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c index d71f36a42..022677b06 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -37,6 +37,7 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkWindowPeer.h" #include "gnu_java_awt_peer_gtk_GtkFramePeer.h" #include <gdk/gdkprivate.h> @@ -73,7 +74,11 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create void *window_parent; GtkWidget *vbox, *layout; + /* Create global reference and save it for future use */ + NSA_SET_GLOBAL_REF (env, obj); + gdk_threads_enter (); + window_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = GTK_WINDOW (window_widget); @@ -116,7 +121,8 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create NSA_SET_PTR (env, obj, window_widget); } -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetVisible +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetVisible (JNIEnv *env, jobject obj, jboolean visible) { void *ptr; @@ -135,7 +141,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetVisible gdk_threads_leave (); } -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectHooks +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectJObject (JNIEnv *env, jobject obj) { void *ptr; @@ -169,26 +176,44 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectHooks connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); + + gdk_threads_enter (); + + gtk_widget_realize (ptr); + /* Connect signals for window event support. */ g_signal_connect (G_OBJECT (ptr), "delete-event", - G_CALLBACK (window_delete_cb), obj); + G_CALLBACK (window_delete_cb), *gref); g_signal_connect (G_OBJECT (ptr), "destroy-event", - G_CALLBACK (window_destroy_cb), obj); + G_CALLBACK (window_destroy_cb), *gref); g_signal_connect (G_OBJECT (ptr), "show", - G_CALLBACK (window_show_cb), obj); + G_CALLBACK (window_show_cb), *gref); g_signal_connect (G_OBJECT (ptr), "focus-in-event", - G_CALLBACK (window_focus_in_cb), obj); + G_CALLBACK (window_focus_in_cb), *gref); g_signal_connect (G_OBJECT (ptr), "focus-out-event", - G_CALLBACK (window_focus_out_cb), obj); + G_CALLBACK (window_focus_out_cb), *gref); g_signal_connect (G_OBJECT (ptr), "window-state-event", - G_CALLBACK (window_window_state_cb), obj); + G_CALLBACK (window_window_state_cb), *gref); gdk_threads_leave (); + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); } /* diff --git a/native/jni/gtk-peer/gtkcairopeer.h b/native/jni/gtk-peer/gtkcairopeer.h new file mode 100644 index 000000000..90a148fa9 --- /dev/null +++ b/native/jni/gtk-peer/gtkcairopeer.h @@ -0,0 +1,78 @@ +#ifndef __GTKCAIROPEER_H__ +#define __GTKCAIROPEER_H__ + +/* gtkcairopeer.h -- Some global variables and #defines + Copyright (C) 1998, 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gtkpeer.h" +#include <cairo.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + +/* + A graphics2d struct is both simpler and uglier than a graphics + struct. + + Most of the graphics2d drawing state is held in the referenced cairo_t + and corresponding cairo_surface_t, so we can ignore it. + + In addition to the cairo_t, we need to hold an extra reference to the + underlying GdkDrawable so its refcount matches the lifecycle of the java + Graphics object which is peering with us; also a reference to a byte + buffer and cairo_surface_t which contain the pattern you're drawing from + (if it exists). + + Finally, it is possible that we are using a non-RENDER capable X server, + therefore we will be drawing to an cairo_surface_t which is actually a + pixbuf. When this is the case, the pointer to a GdkPixbuf will be + non-NULL and any drawing operation needs to be bracketed by pixbuf + load/save operations. If the GdkPixbuf pointer is NULL, we will treat + the cairo_surface_t as RENDER-capable. + */ + +struct graphics2d +{ + cairo_t *cr; + cairo_surface_t *surface; + GdkDrawable *drawable; + GdkWindow *win; + GdkPixbuf *drawbuf; + char *pattern_pixels; + cairo_surface_t *pattern; + gboolean debug; +}; + +#endif /* __GTKCAIROPEER_H */ diff --git a/native/jni/gtk-peer/gtkpeer.h b/native/jni/gtk-peer/gtkpeer.h index 8f8ec40c0..d552e687c 100644 --- a/native/jni/gtk-peer/gtkpeer.h +++ b/native/jni/gtk-peer/gtkpeer.h @@ -61,9 +61,11 @@ exception statement from your version. */ #ifdef JVM_SUN extern struct state_table *native_state_table; +extern struct state_table *native_global_ref_table; #define NSA_INIT(env, clazz) \ - native_state_table = init_state_table (env, clazz) + do {native_state_table = init_state_table (env, clazz); \ + native_global_ref_table = init_state_table (env, clazz);} while (0) #define NSA_GET_PTR(env, obj) \ get_state (env, obj, native_state_table) @@ -74,6 +76,21 @@ extern struct state_table *native_state_table; #define NSA_DEL_PTR(env, obj) \ remove_state_slot (env, obj, native_state_table) +#define NSA_GET_GLOBAL_REF(env, obj) \ + get_state (env, obj, native_global_ref_table) + +#define NSA_SET_GLOBAL_REF(env, obj) \ + do {jobject *globRefPtr; \ + globRefPtr = (jobject *) malloc (sizeof (jobject)); \ + *globRefPtr = (*env)->NewGlobalRef (env, obj); \ + set_state (env, obj, native_global_ref_table, (void *)globRefPtr);} while (0) + +#define NSA_DEL_GLOBAL_REF(env, obj) \ + do {jobject *globRefPtr = get_state (env, obj, native_global_ref_table); \ + remove_state_slot (env, obj, native_global_ref_table); \ + (*env)->DeleteGlobalRef (env, *globRefPtr); \ + free (globRefPtr);} while (0) + #endif /* JVM_SUN */ struct graphics @@ -378,6 +395,7 @@ extern jmethodID postExposeEventID; extern jmethodID postKeyEventID; extern jmethodID postFocusEventID; extern jmethodID postAdjustmentEventID; +extern jmethodID choicePostItemEventID; extern jmethodID postItemEventID; extern jmethodID postListItemEventID; extern jmethodID postTextEventID; @@ -392,6 +410,10 @@ extern GtkWindowGroup *global_gtk_window_group; void awt_event_handler (GdkEvent *event); +gboolean pre_event_handler (GtkWidget *widget, + GdkEvent *event, + jobject peer); + void connect_awt_hook (JNIEnv *env, jobject peer_obj, int nwindows, ...); void set_visible (GtkWidget *widget, jboolean visible); @@ -403,7 +425,7 @@ jint keyevent_state_to_awt_mods (GdkEvent *event); struct item_event_hook_info { jobject peer_obj; - jobject item_obj; + const char *label; }; #endif /* __GTKPEER_H */ |