summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog30
-rw-r--r--gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java86
-rw-r--r--gnu/java/awt/peer/gtk/GtkCheckboxPeer.java30
-rw-r--r--gnu/java/awt/peer/gtk/GtkComponentPeer.java2
-rw-r--r--gnu/java/awt/peer/gtk/GtkGenericPeer.java26
-rw-r--r--gnu/java/awt/peer/gtk/Makefile.am1
-rw-r--r--native/jni/classpath/native_state.c1
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c60
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c26
9 files changed, 216 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index abd1886c1..425386cdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2002-11-14 Tom Tromey <tromey@redhat.com>
+
+ * native/jni/classpath/native_state.c (add_node): Set `c_state'
+ field even when moving node.
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c
+ (Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_dispose): New
+ function.
+ (Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_remove): New
+ function.
+ Include GtkComponentPeer header.
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java (dispose): Removed.
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+ (Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose): Renamed.
+ * gnu/java/awt/peer/gtk/Makefile.am (EXTRA_DIST): Added
+ GtkCheckboxGroupPeer.java.
+ * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java (old_group): Now a
+ GtkCheckboxGroupPeer.
+ (nativeCreate): Argument now a GtkCheckboxGroupPeer.
+ (nativeSetCheckboxGroup): Likewise. Removed `old_group'
+ argument.
+ (create): Find the GtkCheckboxGroupPeer.
+ (setCheckboxGroup): Likewise.
+ (dispose): New method.
+ * gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java: New file.
+ * gnu/java/awt/peer/gtk/GtkGenericPeer.java (next_native_state):
+ New global.
+ (getUniqueInteger): New method.
+ (native_state): Use it.
+ (dispose): New native method.
+
2002-11-13 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBuffer.java: Reindented.
diff --git a/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java b/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java
new file mode 100644
index 000000000..9903c3104
--- /dev/null
+++ b/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java
@@ -0,0 +1,86 @@
+/* GtkCheckboxGroupPeer.java - Wrap a CheckboxGroup
+ Copyright (C) 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., 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. */
+
+
+package gnu.java.awt.peer.gtk;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+// Note that there is no peer interface for a CheckboxGroup. We
+// introduce our own in order to make it easier to keep a piece of
+// native state for each one.
+public class GtkCheckboxGroupPeer extends GtkGenericPeer
+{
+ // This maps from a CheckboxGroup to the native peer.
+ private static WeakHashMap map = new WeakHashMap ();
+
+ // Find the native peer corresponding to a CheckboxGroup.
+ public static synchronized GtkCheckboxGroupPeer
+ getCheckboxGroupPeer (CheckboxGroup group)
+ {
+ if (group == null)
+ return null;
+ GtkCheckboxGroupPeer nat = (GtkCheckboxGroupPeer) map.get (group);
+ if (nat == null)
+ {
+ nat = new GtkCheckboxGroupPeer ();
+ map.put (group, nat);
+ }
+ return nat;
+ }
+
+ private GtkCheckboxGroupPeer ()
+ {
+ // We don't need any special state here. Note that we can't store
+ // a reference to the java-side CheckboxGroup. That would mean
+ // they could never be collected.
+ super (null);
+ }
+
+ // Dispose of our native resources.
+ public native void dispose ();
+
+ // Remove a given checkbox from this group.
+ public native void remove (GtkCheckboxPeer box);
+
+ // When collected, clean up the native state.
+ protected void finalize ()
+ {
+ dispose ();
+ }
+}
diff --git a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
index aee2b22a4..48f880400 100644
--- a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
@@ -44,11 +44,10 @@ public class GtkCheckboxPeer extends GtkComponentPeer
implements CheckboxPeer
{
// Group from last time it was set.
- public CheckboxGroup old_group;
+ public GtkCheckboxGroupPeer old_group;
- public native void nativeCreate (CheckboxGroup group);
- public native void nativeSetCheckboxGroup (CheckboxGroup group,
- CheckboxGroup old_group);
+ public native void nativeCreate (GtkCheckboxGroupPeer group);
+ public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
public native void connectHooks ();
public GtkCheckboxPeer (Checkbox c)
@@ -63,7 +62,8 @@ public class GtkCheckboxPeer extends GtkComponentPeer
public void create ()
{
CheckboxGroup g = ((Checkbox) awtComponent).getCheckboxGroup ();
- nativeCreate (g);
+ old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
+ nativeCreate (old_group);
}
public void setState (boolean state)
@@ -78,8 +78,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer
public void setCheckboxGroup (CheckboxGroup group)
{
- nativeSetCheckboxGroup (group, old_group);
- old_group = group;
+ GtkCheckboxGroupPeer gp
+ = GtkCheckboxGroupPeer.getCheckboxGroupPeer (group);
+ if (gp != old_group)
+ {
+ if (old_group != null)
+ old_group.remove (this);
+ nativeSetCheckboxGroup (gp);
+ old_group = gp;
+ }
}
public void getArgs (Component component, GtkArgList args)
@@ -95,4 +102,13 @@ public class GtkCheckboxPeer extends GtkComponentPeer
{
super.postItemEvent (awtComponent, stateChange);
}
+
+ public void dispose ()
+ {
+ // Notify the group so that the native state can be cleaned up
+ // appropriately.
+ if (old_group != null)
+ old_group.remove (this);
+ super.dispose ();
+ }
}
diff --git a/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index 7c97484b9..6e3b25290 100644
--- a/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -121,8 +121,6 @@ public class GtkComponentPeer extends GtkGenericPeer
setEnabled (false);
}
- native public void dispose ();
-
public void enable ()
{
setEnabled (true);
diff --git a/gnu/java/awt/peer/gtk/GtkGenericPeer.java b/gnu/java/awt/peer/gtk/GtkGenericPeer.java
index 0991e6082..464f71157 100644
--- a/gnu/java/awt/peer/gtk/GtkGenericPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkGenericPeer.java
@@ -40,17 +40,22 @@ package gnu.java.awt.peer.gtk;
import java.awt.*;
import java.awt.event.*;
-/* This class will go away with Japhar integration. For use with Sun's JDK
- this may be required, unless another method of associating Java objects
- with GTK objects is used. */
-
public class GtkGenericPeer
{
- // FIXME: this isn't guaranteed to give unique numbers.
- final int native_state = java.lang.System.identityHashCode(this);
+ final int native_state = getUniqueInteger ();
+
+ // Next native state value we will assign.
+ private static int next_native_state = 0;
+
+ // The widget or other java-side object we wrap.
protected Object awtWidget;
+
+ // Global event queue.
protected static EventQueue q = null;
+ // Dispose of our native state.
+ public native void dispose ();
+
protected GtkGenericPeer (Object awtWidget)
{
this.awtWidget = awtWidget;
@@ -67,4 +72,13 @@ public class GtkGenericPeer
q.postEvent (new ActionEvent (awtWidget, ActionEvent.ACTION_PERFORMED,
command, mods));
}
+
+ // Return a unique integer for use in the native state mapping
+ // code. We can't use a hash code since that is not guaranteed to
+ // be unique.
+ private static synchronized int getUniqueInteger ()
+ {
+ // Let's assume this will never wrap.
+ return next_native_state++;
+ }
}
diff --git a/gnu/java/awt/peer/gtk/Makefile.am b/gnu/java/awt/peer/gtk/Makefile.am
index 565d00109..1f95dc721 100644
--- a/gnu/java/awt/peer/gtk/Makefile.am
+++ b/gnu/java/awt/peer/gtk/Makefile.am
@@ -7,6 +7,7 @@ EXTRA_DIST = \
GtkArgList.java \
GtkButtonPeer.java \
GtkCanvasPeer.java \
+ GtkCheckboxGroupPeer.java \
GtkCheckboxMenuItemPeer.java \
GtkCheckboxPeer.java \
GtkChoicePeer.java \
diff --git a/native/jni/classpath/native_state.c b/native/jni/classpath/native_state.c
index c89541f22..c543d0fe6 100644
--- a/native/jni/classpath/native_state.c
+++ b/native/jni/classpath/native_state.c
@@ -161,6 +161,7 @@ add_node (struct state_node **head, jint obj_id, void *state)
/* Insert node at the beginning. */
new_node->next = *head;
+ new_node->c_state = state;
*head = new_node;
}
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 48d6bcc50..09fa7ef21 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
@@ -38,9 +38,44 @@ exception statement from your version. */
#include "gtkpeer.h"
#include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h"
+#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
static void item_toggled (GtkToggleButton *item, jobject peer);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_dispose
+ (JNIEnv *env, jobject obj)
+{
+ /* The actual underlying widget is owned by a different class. So
+ we just clean up the hash table here. */
+ NSA_DEL_PTR (env, obj);
+}
+
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer_remove
+ (JNIEnv *env, jobject obj, jobject checkbox)
+{
+ GtkRadioButton *button;
+ void *ptr;
+ GSList *list;
+
+ ptr = NSA_GET_PTR (env, checkbox);
+ gdk_threads_enter ();
+ button = GTK_RADIO_BUTTON (ptr);
+
+ /* Update the group to point to some other widget in the group. We
+ have to do this because Gtk doesn't have a separate object to
+ represent a radio button's group. */
+ for (list = gtk_radio_button_group (button); list != NULL;
+ list = list->next)
+ {
+ if (list->data != button)
+ break;
+ }
+
+ gdk_threads_leave ();
+
+ NSA_SET_PTR (env, obj, list ? list->data : NULL);
+}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeCreate
(JNIEnv *env, jobject obj, jobject group)
@@ -92,7 +127,7 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectHooks
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
- (JNIEnv *env, jobject obj, jobject group, jobject old_group)
+ (JNIEnv *env, jobject obj, jobject group)
{
GtkRadioButton *button;
void *native_group, *ptr;
@@ -107,23 +142,6 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
button = GTK_RADIO_BUTTON (ptr);
- if (old_group != NULL)
- {
- /* First, update our old group, if one exists, to point to some
- other widget in the group. We have to do this because Gtk
- doesn't have a separate object to represent a radio button's
- group. */
- GSList *list;
- for (list = gtk_radio_button_group (button); list != NULL;
- list = list->next)
- {
- if (list->data != button)
- break;
- }
-
- NSA_SET_PTR (env, old_group, list ? list->data : NULL);
- }
-
native_group = NSA_GET_PTR (env, group);
if (native_group == NULL)
gtk_radio_button_set_group (button, NULL);
@@ -136,7 +154,11 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
/* If the native group wasn't set on the new CheckboxGroup, then set
it now so that the right thing will happen with the next
- radiobutton. */
+ radiobutton. The native state for a CheckboxGroup is a pointer
+ to one of the widgets in the group. We are careful to keep this
+ always pointing at a live widget; whenever a widget is destroyed
+ (or otherwise removed from the group), the CheckboxGroup peer is
+ notified. */
if (native_group == NULL)
NSA_SET_PTR (env, group, native_group);
}
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 c035a3175..5522354e3 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
@@ -56,6 +56,20 @@ exception statement from your version. */
} \
gdk_threads_leave (); \
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose
+ (JNIEnv *env, jobject obj)
+{
+ void *ptr;
+
+ ptr = NSA_DEL_PTR (env, obj);
+
+ /* 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 ();
+}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor
(JNIEnv *env, jobject obj, jint type)
@@ -123,18 +137,6 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor
gdk_threads_leave ();
}
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_dispose
- (JNIEnv *env, jobject obj)
-{
- void *ptr;
-
- ptr = NSA_DEL_PTR (env, obj);
-
- gdk_threads_enter ();
- gtk_widget_destroy (GTK_WIDGET (ptr));
- gdk_threads_leave ();
-}
-
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_requestFocus
(JNIEnv *env, jobject obj)
{