summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjava/ChangeLog13
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java29
-rw-r--r--libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c66
3 files changed, 82 insertions, 26 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index f8eadf92564..25d611abf38 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,16 @@
+2004-01-05 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * 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-05 Sascha Brawer <brawer@dandelis.ch>
Thanks to Brian Gough <bjg@network-theory.com>
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index 6a7c3405f84..0a712a0597c 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -84,8 +84,9 @@ public class GtkComponentPeer extends GtkGenericPeer
native int[] gtkWidgetGetForeground ();
native int[] gtkWidgetGetBackground ();
native void gtkWidgetSetVisible (boolean b);
- native void gtkWidgetGetDimensions(int[] dim);
- native void gtkWidgetGetLocationOnScreen(int[] point);
+ native void gtkWidgetGetDimensions (int[] dim);
+ native void gtkWidgetGetPreferredDimensions (int[] dim);
+ native void gtkWidgetGetLocationOnScreen (int[] point);
native void gtkWidgetSetCursor (int type);
native void gtkWidgetSetBackground (int red, int green, int blue);
native void gtkWidgetSetForeground (int red, int green, int blue);
@@ -196,18 +197,12 @@ public class GtkComponentPeer extends GtkGenericPeer
public Dimension getMinimumSize ()
{
- int dim[]=new int[2];
- gtkWidgetGetDimensions (dim);
- Dimension d = new Dimension (dim[0],dim[1]);
- return (d);
+ return minimumSize ();
}
public Dimension getPreferredSize ()
{
- int dim[]=new int[2];
- gtkWidgetGetDimensions (dim);
- Dimension d = new Dimension (dim[0],dim[1]);
- return (d);
+ return preferredSize ();
}
public Toolkit getToolkit ()
@@ -226,7 +221,11 @@ public class GtkComponentPeer extends GtkGenericPeer
public Dimension minimumSize ()
{
- return getMinimumSize();
+ int dim[] = new int[2];
+
+ gtkWidgetGetPreferredDimensions (dim);
+
+ return new Dimension (dim[0], dim[1]);
}
public void paint (Graphics g)
@@ -234,9 +233,13 @@ public class GtkComponentPeer extends GtkGenericPeer
awtComponent.paint (g);
}
- public Dimension preferredSize()
+ public Dimension preferredSize ()
{
- return getPreferredSize();
+ int dim[] = new int[2];
+
+ gtkWidgetGetPreferredDimensions (dim);
+
+ return new Dimension (dim[0], dim[1]);
}
public boolean prepareImage (Image image, int width, int height,
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
index 6336636ec11..b244fd7d59d 100644
--- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
@@ -169,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 req;
+ 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);
+}
- ptr = NSA_GET_PTR (env, obj);
- dims = (*env)->GetIntArrayElements (env, jdims, 0);
+/*
+ * Find this widget's preferred size.
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetPreferredDimensions
+ (JNIEnv *env, jobject obj, jintArray jdims)
+{
+ void *ptr;
+ jint *dims;
+ GtkRequisition current_req;
+ GtkRequisition natural_req;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ dims = (*env)->GetIntArrayElements (env, jdims, 0);
+ dims[0] = dims[1] = 0;
+
+ gdk_threads_enter ();
+
+ /* Save the widget's current size request. */
+ gtk_widget_size_request (GTK_WIDGET (ptr), &current_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