diff options
Diffstat (limited to 'libjava/jni')
-rw-r--r-- | libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c | 66 |
1 files changed, 53 insertions, 13 deletions
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), ¤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 |