aboutsummaryrefslogtreecommitdiff
path: root/libjava/jni
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2003-10-02 18:34:56 +0000
committerThomas Fitzsimmons <fitzsim@gcc.gnu.org>2003-10-02 18:34:56 +0000
commitb59b5081384b68e33c1a50ef4d047f95e171c05d (patch)
treead4d3237b7756c048c153b6523f2ac2e1afded13 /libjava/jni
parent01d28c3ff91870a620f7a5a699e509e103afb8b9 (diff)
downloadgcc-b59b5081384b68e33c1a50ef4d047f95e171c05d.zip
gcc-b59b5081384b68e33c1a50ef4d047f95e171c05d.tar.gz
gcc-b59b5081384b68e33c1a50ef4d047f95e171c05d.tar.bz2
GtkComponentPeer.java (insets): New field.
2003-10-02 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (insets): New field. (initializeInsets): New method. (GtkComponentPeer): Call initializeInsets. Call setCursor and setBounds unconditionally. (setBounds): Convert coordinates if parent is a Window. * gnu/java/awt/peer/gtk/GtkContainerPeer.java (insets): Move field to GtkComponentPeer. (GtkContainerPeer): Don't initialize insets. * gnu/java/awt/peer/gtk/GtkDialogPeer.java (initializeInsets): New method. (create): Call new GtkWindowPeer create method. * gnu/java/awt/peer/gtk/GtkFramePeer.java (initializeInsets): New method. (create): Call new GtkWindowPeer create method. (setBounds): Remove method. (postConfigureEvent): Likewise. * gnu/java/awt/peer/gtk/GtkWindowPeer.java: Replace GTK window type constants with GDK window type constants. (create(int,boolean,int,int,GtkWindowPeer)): New method. (create(int,boolean)): Likewise. (create()): Call create(int,boolean). (nativeSetBounds): New native method declaration. (setBounds): Call native method declaration. (setSize): New native method declaration. (setBoundsCallback): Likewise. (postConfigureEvent): Handle change in insets. Call setSize and setBoundsCallback methods. * java/awt/Window.java (Window): Set visible to false. (setBoundsCallback): New method. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (gtkWidgetGetLocationOnScreen): If this component is not a container, adjust the location returned based on the peer's allocation. (set(String,boolean)): Revert change from 2003-09-19. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (awt_event_handler): Fix inset calculation. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c: Add JNI glue for Window.setBoundsCallback. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (create): Set up stacking order, window decorations and window manager hints. (setBoundsCallback): New method. (setSize): New method. (nativeSetBounds): New method. * jni/gtk-peer/gtkpeer.h: Declare setBoundsCallbackID. From-SVN: r72043
Diffstat (limited to 'libjava/jni')
-rw-r--r--libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c14
-rw-r--r--libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c51
-rw-r--r--libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c11
-rw-r--r--libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c67
-rw-r--r--libjava/jni/gtk-peer/gtkpeer.h2
5 files changed, 103 insertions, 42 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 ed94b7d..455af68 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
@@ -172,7 +172,15 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreen
point = (*env)->GetIntArrayElements (env, jpoint, 0);
gdk_threads_enter ();
+
gdk_window_get_origin (GTK_WIDGET (ptr)->window, point, point+1);
+
+ if (!GTK_IS_CONTAINER (ptr))
+ {
+ *point += GTK_WIDGET(ptr)->allocation.x;
+ *(point+1) += GTK_WIDGET(ptr)->allocation.y;
+ }
+
gdk_threads_leave ();
(*env)->ReleaseIntArrayElements(env, jpoint, point, 0);
@@ -508,18 +516,14 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_set__Ljava_lang_String_2Ljava_lang_S
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_set__Ljava_lang_String_2Z
- (JNIEnv *env, jobject obj, jstring jname, jboolean jvalue)
+ (JNIEnv *env, jobject obj, jstring jname, jboolean value)
{
const char *name;
- gboolean value;
void *ptr;
ptr = NSA_GET_PTR (env, obj);
name = (*env)->GetStringUTFChars (env, jname, NULL);
- /* Apparently a jboolean can have a value greater than 1. gboolean
- variables may only contain the value TRUE or FALSE. */
- value = jvalue ? TRUE : FALSE;
gdk_threads_enter();
g_object_set(ptr, name, value, NULL);
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
index cdcd72e..481fadf 100644
--- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
+++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
@@ -981,31 +981,40 @@ awt_event_handler (GdkEvent *event)
if (widget && GTK_WIDGET_TOPLEVEL (widget))
{
gint top, left, right, bottom;
- gint x, y, w, h, wb, d;
+ gint x, y, w, h, d;
+ GdkRectangle r;
- /* calculate our insets */
- gdk_window_get_root_geometry (event->any.window,
- &x, &y, &w, &h, &wb, &d);
+ /* 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 ();
- /* We used to compute these based on the configure
- event's fields. However, that gives strange and
- apparently incorrect results. */
- top = left = bottom = right = 0;
+ /* Calculate our insets. */
- /* configure events are not posted to the AWT event queue,
- and as such, gdk/gtk will be called back before
- postConfigureEvent returns */
- gdk_threads_leave ();
- (*gdk_env)->CallVoidMethod (gdk_env, *obj_ptr,
+ /* When called from within the gdk_threads critical
+ section these functions seem to return strange
+ results, so we call them after
+ gdk_threads_leave. */
+ gdk_window_get_geometry (event->any.window,
+ &x, &y, &w, &h, &d);
+ gdk_window_get_frame_extents (event->any.window, &r);
+
+ top = y;
+ left = x;
+ bottom = r.height - h - y;
+ right = r.width - w - x;
+
+ (*gdk_env)->CallVoidMethod (gdk_env, *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);
+ (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 ();
}
}
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
index f67845a..03566f2 100644
--- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
+++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
@@ -44,6 +44,8 @@ exception statement from your version. */
struct state_table *native_state_table;
#endif
+jmethodID setBoundsCallbackID;
+
jmethodID postActionEventID;
jmethodID postMenuActionEventID;
jmethodID postMouseEventID;
@@ -74,7 +76,7 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
char *homedir, *rcpath = NULL;
/* jclass gtkgenericpeer; */
jclass gtkcomponentpeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer,
- gtkmenuitempeer, gtktextcomponentpeer;
+ gtkmenuitempeer, gtktextcomponentpeer, window;
NSA_INIT (env, clazz);
@@ -127,6 +129,9 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
/* setup cached IDs for posting GTK events to Java */
/* gtkgenericpeer = (*env)->FindClass (env, */
/* "gnu/java/awt/peer/gtk/GtkGenericPeer"); */
+
+ window = (*env)->FindClass (env, "java/awt/Window");
+
gtkcomponentpeer = (*env)->FindClass (env,
"gnu/java/awt/peer/gtk/GtkComponentPeer");
gtkwindowpeer = (*env)->FindClass (env,
@@ -145,6 +150,10 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
/* "postActionEvent", */
/* "(Ljava/lang/String;I)V"); */
+ setBoundsCallbackID = (*env)->GetMethodID (env, window,
+ "setBoundsCallback",
+ "(IIII)V");
+
postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer,
"postMenuActionEvent",
"()V");
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
index 982a5cb..692c50e 100644
--- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
@@ -43,20 +43,24 @@ exception statement from your version. */
#include <gdk/gdkx.h>
/*
- * Make a new window (any type)
+ * Make a new window.
*/
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create
- (JNIEnv *env, jobject obj, jint type, jint width, jint height)
+ (JNIEnv *env, jobject obj, jint type, jboolean decorated,
+ jint width, jint height, jobject parent)
{
- GtkWidget *window;
+ GtkWidget *window_widget;
+ GtkWindow *window;
+ void *window_parent;
GtkWidget *vbox, *layout;
gdk_threads_enter ();
- window = gtk_window_new (type);
+ window_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ window = GTK_WINDOW (window_widget);
- gtk_window_set_default_size (GTK_WINDOW(window), width, height);
+ gtk_window_set_default_size (window, width, height);
/* We must set this window's size requisition. Otherwise when a
resize is queued (when gtk_widget_queue_resize is called) the
@@ -65,17 +69,28 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create
when their resizable property changes. */
gtk_widget_set_size_request (window, width, height);
+ /* Keep this window in front of its parent, if it has one. */
+ if (parent)
+ {
+ window_parent = NSA_GET_PTR (env, parent);
+ gtk_window_set_transient_for (window, GTK_WINDOW(window_parent));
+ }
+
+ gtk_window_set_decorated (window, decorated);
+
+ gtk_window_set_type_hint (window, type);
+
vbox = gtk_vbox_new (0, 0);
layout = gtk_layout_new (NULL, NULL);
gtk_box_pack_end (GTK_BOX (vbox), layout, 1, 1, 0);
- gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_container_add (GTK_CONTAINER (window_widget), vbox);
gtk_widget_show (layout);
gtk_widget_show (vbox);
gdk_threads_leave ();
- NSA_SET_PTR (env, obj, window);
+ NSA_SET_PTR (env, obj, window_widget);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisible
@@ -218,20 +233,42 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env,
gdk_threads_leave ();
}
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBounds
- (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBoundsCallback
+ (JNIEnv *env, jobject obj, jobject window,
+ jint x, jint y, jint width, jint height)
{
- void *ptr;
- GtkWidget *widget;
+ /* Circumvent package-private access to call Window's
+ setBoundsCallback method. */
+ (*gdk_env)->CallVoidMethod (gdk_env, window, setBoundsCallbackID,
+ x, y, width, height);
+}
- ptr = NSA_GET_PTR (env, obj);
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize
+ (JNIEnv *env, jobject obj, jint width, jint height)
+{
+ void *ptr = NSA_GET_PTR (env, obj);
gdk_threads_enter ();
+ gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height);
+ gdk_threads_leave ();
+}
- widget = GTK_WIDGET (ptr);
- gtk_widget_set_size_request (widget, width, height);
- gtk_window_resize (GTK_WINDOW(widget), width, height);
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds
+ (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
+{
+ void *ptr = NSA_GET_PTR (env, obj);
+ gdk_threads_enter ();
+ gtk_window_move (GTK_WINDOW(ptr), x, y);
+ /* Need to change the widget's request size. */
+ gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height);
+ /* Also need to call gtk_window_resize. If the resize is requested
+ by the program and the window's "resizable" property is true then
+ the size request will not be honoured. */
+ gtk_window_resize (GTK_WINDOW (ptr), width, height);
gdk_threads_leave ();
}
diff --git a/libjava/jni/gtk-peer/gtkpeer.h b/libjava/jni/gtk-peer/gtkpeer.h
index 2aa7109..8f38953 100644
--- a/libjava/jni/gtk-peer/gtkpeer.h
+++ b/libjava/jni/gtk-peer/gtkpeer.h
@@ -343,6 +343,8 @@ struct graphics
#define AWT_FOCUS_LOST 1004
#define AWT_FOCUS_GAINED 1005
+extern jmethodID setBoundsCallbackID;
+
extern jmethodID postActionEventID;
extern jmethodID postMenuActionEventID;
extern jmethodID postMouseEventID;