This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Checkbox states
On Mon, 2003-12-01 at 14:50, Tom Tromey wrote:
> >>>>> "Kim" == Kim Ho <kho@redhat.com> writes:
>
> Kim> This patch implements a getState function for Checkboxes.
>
> A short digression about the peers...
>
> The peers aren't documented, so we are free to change them as we
> like. And we've already done this in the past.
>
> However, it's best if we don't extend the interfaces too much. One
> problem with doing so is that we have to update all the peers, not
> just the Gtk ones. And as kaffe integrates more with classpath, this
> means the cost goes up.
>
>
> About this particular patch, I know that the Sun CheckboxPeer doesn't
> have a getState method. Is there another way we could implement this?
> If not, that's fine, let's go for it.
>
> Tom
Fixed.
Index: gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java,v
retrieving revision 1.2
diff -u -p -r1.2 GtkCheckboxPeer.java
--- gnu/java/awt/peer/gtk/GtkCheckboxPeer.java 13 Jul 2003 15:09:20 -0000 1.2
+++ gnu/java/awt/peer/gtk/GtkCheckboxPeer.java 4 Dec 2003 14:04:17 -0000
@@ -49,9 +49,10 @@ public class GtkCheckboxPeer extends Gtk
// Group from last time it was set.
public GtkCheckboxGroupPeer old_group;
- public native void nativeCreate (GtkCheckboxGroupPeer group);
+ public native void nativeCreate (GtkCheckboxGroupPeer group, boolean state);
public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
public native void connectHooks ();
+ private boolean currentState;
public GtkCheckboxPeer (Checkbox c)
{
@@ -66,12 +67,14 @@ public class GtkCheckboxPeer extends Gtk
{
CheckboxGroup g = ((Checkbox) awtComponent).getCheckboxGroup ();
old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
- nativeCreate (old_group);
+ currentState = ((Checkbox)awtComponent).getState();
+ nativeCreate (old_group, currentState);
}
public void setState (boolean state)
{
- set ("active", state);
+ if (currentState != state)
+ set ("active", state);
}
public void setLabel (String label)
@@ -103,7 +106,18 @@ public class GtkCheckboxPeer extends Gtk
// need information that we have.
public void postItemEvent (Object item, int stateChange)
{
- super.postItemEvent (awtComponent, stateChange);
+ Checkbox currentCheckBox = ((Checkbox)awtComponent);
+ // A firing of the event is only desired if the state has changed due to a button
+ // press. The currentCheckBox's state must be different from the one that the
+ // stateChange is changing to.
+ // stateChange = 1 if it goes from false -> true
+ // stateChange = 2 if it goes from true -> false
+ if ((!currentCheckBox.getState() && (stateChange==1)) || (currentCheckBox.getState() && (stateChange==2)))
+ {
+ super.postItemEvent (awtComponent, stateChange);
+ currentState = !currentCheckBox.getState();
+ currentCheckBox.setState(currentState);
+ }
}
public void dispose ()
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c,v
retrieving revision 1.1
diff -u -p -r1.1 gnu_java_awt_peer_gtk_GtkCheckboxPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c 31 Jan 2003 17:54:14 -0000 1.1
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c 4 Dec 2003 14:04:22 -0000
@@ -78,7 +78,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt
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;
@@ -97,7 +97,7 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPe
NSA_SET_PTR (env, group, button);
}
}
-
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), state);
gdk_threads_leave ();
NSA_SET_PTR (env, obj, button);