Hi, This patch removes setBoundsCallback from Window.java and replaces it with a new method of validating based on a Window resize event. This is more in line with how the JDK handles window resizing and allows both the GTK and Qt peers to handle resizing the same way. I committed this to mainline.
Tom 2005-08-17 Thomas Fitzsimmons <[EMAIL PROTECTED]> * gnu/java/awt/peer/gtk/GtkFileDialogPeer.java (setComponentBounds): Don't post COMPONENT_RESIZED event. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (setBoundsCallbackID): Remove variable. (cp_gtk_window_init_jni): Don't initialize setBoundsCallbackID. (setBoundsCallback): Remove method. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c (setMenuBarPeer): Check if menubar is NULL. (setMenuBarWidth): Likewise. * java/awt/Window.java (dispatchEventImpl): Validate upon receiving a COMPONENT_RESIZED event. (setBoundsCallback): Remove method. * include/gnu_java_awt_peer_gtk_GtkWindowPeer.h: Regenerate. * gnu/java/awt/peer/gtk/GtkWindowPeer.java (setBoundsCallback): Remove method declaration. (postConfigureEvent): Separate handling of resizes and moves. Call setSize and post COMPONENT_RESIZED event. * gnu/java/awt/peer/gtk/GtkFramePeer.java (postConfigureEvent): Separate handling of resizes and moves. Call setSize. * gnu/java/awt/peer/gtk/GtkFileDialogPeer.java (setComponentBounds): Call setSize and post COMPONENT_RESIZED event. * gnu/java/awt/peer/gtk/GtkContainerPeer.java (isValidating): Remove field.
Index: gnu/java/awt/peer/gtk/GtkFileDialogPeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java,v retrieving revision 1.24 diff -u -r1.24 GtkFileDialogPeer.java --- gnu/java/awt/peer/gtk/GtkFileDialogPeer.java 17 Aug 2005 04:24:38 -0000 1.24 +++ gnu/java/awt/peer/gtk/GtkFileDialogPeer.java 17 Aug 2005 04:31:45 -0000 @@ -91,12 +91,7 @@ if (dims[0] != awtComponent.getWidth() || dims[1] != awtComponent.getHeight()) - { - awtComponent.setSize(dims[0], dims[1]); - ComponentEvent e = new ComponentEvent(awtComponent, - ComponentEvent.COMPONENT_RESIZED); - q().postEvent(e); - } + awtComponent.setSize(dims[0], dims[1]); } super.setComponentBounds (); }
Index: gnu/java/awt/peer/gtk/GtkContainerPeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkContainerPeer.java,v retrieving revision 1.30 diff -u -r1.30 GtkContainerPeer.java --- gnu/java/awt/peer/gtk/GtkContainerPeer.java 2 Jul 2005 20:32:12 -0000 1.30 +++ gnu/java/awt/peer/gtk/GtkContainerPeer.java 17 Aug 2005 04:22:38 -0000 @@ -52,7 +52,6 @@ implements ContainerPeer { Container c; - boolean isValidating; public GtkContainerPeer(Container c) { @@ -62,7 +61,6 @@ public void beginValidate () { - isValidating = true; } public void endValidate () @@ -90,8 +88,6 @@ if (!(awtComponent instanceof Window)) setParentAndBounds (); } - - isValidating = false; } public Insets getInsets() Index: gnu/java/awt/peer/gtk/GtkFileDialogPeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java,v retrieving revision 1.23 diff -u -r1.23 GtkFileDialogPeer.java --- gnu/java/awt/peer/gtk/GtkFileDialogPeer.java 2 Jul 2005 20:32:12 -0000 1.23 +++ gnu/java/awt/peer/gtk/GtkFileDialogPeer.java 17 Aug 2005 04:22:38 -0000 @@ -42,6 +42,7 @@ import java.awt.FileDialog; import java.awt.Graphics; import java.awt.Window; +import java.awt.event.ComponentEvent; import java.awt.peer.FileDialogPeer; import java.io.File; import java.io.FilenameFilter; @@ -87,10 +88,15 @@ { int[] dims = new int[2]; gtkWidgetGetPreferredDimensions (dims); - ((GtkFileDialogPeer) this).setBoundsCallback ((Window) awtComponent, - awtComponent.getX (), - awtComponent.getY (), - dims[0], dims[1]); + + if (dims[0] != awtComponent.getWidth() + || dims[1] != awtComponent.getHeight()) + { + awtComponent.setSize(dims[0], dims[1]); + ComponentEvent e = new ComponentEvent(awtComponent, + ComponentEvent.COMPONENT_RESIZED); + q().postEvent(e); + } } super.setComponentBounds (); } Index: gnu/java/awt/peer/gtk/GtkFramePeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java,v retrieving revision 1.37 diff -u -r1.37 GtkFramePeer.java --- gnu/java/awt/peer/gtk/GtkFramePeer.java 2 Jul 2005 20:32:12 -0000 1.37 +++ gnu/java/awt/peer/gtk/GtkFramePeer.java 17 Aug 2005 04:22:38 -0000 @@ -44,6 +44,7 @@ import java.awt.MenuBar; import java.awt.Rectangle; import java.awt.Window; +import java.awt.event.ComponentEvent; import java.awt.event.PaintEvent; import java.awt.image.ColorModel; import java.awt.peer.FramePeer; @@ -192,31 +193,25 @@ protected void postConfigureEvent (int x, int y, int width, int height) { - int frame_x = x - insets.left; - // Since insets.top includes the MenuBar height, we need to add back - // the MenuBar height to the frame's y position. - // If no MenuBar exists in this frame, the MenuBar height will be 0. - int frame_y = y - insets.top + menuBarHeight; int frame_width = width + insets.left + insets.right; - // Ditto as above. Since insets.top already includes the MenuBar's height, - // we need to subtract the MenuBar's height from the top inset. + // Since insets.top already includes the MenuBar's height, we need + // to subtract the MenuBar's height from the top inset. int frame_height = height + insets.top + insets.bottom - menuBarHeight; - if (frame_x != awtComponent.getX() - || frame_y != awtComponent.getY() - || frame_width != awtComponent.getWidth() + + if (frame_width != awtComponent.getWidth() || frame_height != awtComponent.getHeight()) - { - if (frame_width != awtComponent.getWidth() && menuBar != null - && width > 0) - setMenuBarWidth (menuBar, width); - - setBoundsCallback ((Window) awtComponent, - frame_x, - frame_y, - frame_width, - frame_height); + awtComponent.setSize(frame_width, frame_height); - awtComponent.validate(); + int frame_x = x - insets.left; + // Likewise, since insets.top includes the MenuBar height, we need + // to add back the MenuBar height to the frame's y position. If + // no MenuBar exists in this frame, the MenuBar height will be 0. + int frame_y = y - insets.top + menuBarHeight; + + if (frame_x != awtComponent.getX() + || frame_y != awtComponent.getY()) + { + // awtComponent.setLocation(frame_x, frame_y); } } Index: gnu/java/awt/peer/gtk/GtkWindowPeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java,v retrieving revision 1.36 diff -u -r1.36 GtkWindowPeer.java --- gnu/java/awt/peer/gtk/GtkWindowPeer.java 14 Jul 2005 22:07:02 -0000 1.36 +++ gnu/java/awt/peer/gtk/GtkWindowPeer.java 17 Aug 2005 04:22:38 -0000 @@ -41,6 +41,7 @@ import java.awt.Component; import java.awt.Frame; import java.awt.Window; +import java.awt.event.ComponentEvent; import java.awt.event.WindowEvent; import java.awt.peer.WindowPeer; @@ -140,10 +141,6 @@ gtkWindowSetResizable (resizable); } - native void setBoundsCallback (Window window, - int x, int y, - int width, int height); - protected void postInsetsChangedEvent (int top, int left, int bottom, int right) { @@ -155,20 +152,20 @@ protected void postConfigureEvent (int x, int y, int width, int height) { - int frame_x = x - insets.left; - int frame_y = y - insets.top; int frame_width = width + insets.left + insets.right; int frame_height = height + insets.top + insets.bottom; - if (frame_x != awtComponent.getX() - || frame_y != awtComponent.getY() - || frame_width != awtComponent.getWidth() + if (frame_width != awtComponent.getWidth() || frame_height != awtComponent.getHeight()) - { - setBoundsCallback ((Window) awtComponent, - frame_x, frame_y, frame_width, frame_height); + awtComponent.setSize(frame_width, frame_height); - awtComponent.validate(); + int frame_x = x - insets.left; + int frame_y = y - insets.top; + + if (frame_x != awtComponent.getX() + || frame_y != awtComponent.getY()) + { + // awtComponent.setLocation(frame_x, frame_y); } } Index: include/gnu_java_awt_peer_gtk_GtkWindowPeer.h =================================================================== RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h,v retrieving revision 1.15 diff -u -r1.15 gnu_java_awt_peer_gtk_GtkWindowPeer.h --- include/gnu_java_awt_peer_gtk_GtkWindowPeer.h 14 Jul 2005 22:07:02 -0000 1.15 +++ include/gnu_java_awt_peer_gtk_GtkWindowPeer.h 17 Aug 2005 04:22:39 -0000 @@ -20,7 +20,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds (JNIEnv *env, jobject, jint, jint, jint, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize (JNIEnv *env, jobject, jint, jint); -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBoundsCallback (JNIEnv *env, jobject, jobject, jint, jint, jint, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetVisible (JNIEnv *env, jobject, jboolean); #undef gnu_java_awt_peer_gtk_GtkWindowPeer_GDK_WINDOW_TYPE_HINT_NORMAL #define gnu_java_awt_peer_gtk_GtkWindowPeer_GDK_WINDOW_TYPE_HINT_NORMAL 0L Index: java/awt/Window.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/Window.java,v retrieving revision 1.50 diff -u -r1.50 Window.java --- java/awt/Window.java 2 Jul 2005 20:32:26 -0000 1.50 +++ java/awt/Window.java 17 Aug 2005 04:22:39 -0000 @@ -619,6 +619,8 @@ || windowStateListener != null || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) processEvent(e); + else if (e.id == ComponentEvent.COMPONENT_RESIZED) + validate (); else super.dispatchEventImpl(e); } @@ -1068,44 +1070,6 @@ public void setFocusableWindowState (boolean focusableWindowState) { this.focusableWindowState = focusableWindowState; - } - - // setBoundsCallback is needed so that when a user moves a window, - // the Window's location can be updated without calling the peer's - // setBounds method. When a user moves a window the peer window's - // location is updated automatically and the windowing system sends - // a message back to the application informing it of its updated - // dimensions. We must update the AWT Window class with these new - // dimensions. But we don't want to call the peer's setBounds - // method, because the peer's dimensions have already been updated. - // (Under X, having this method prevents Configure event loops when - // moving windows: Component.setBounds -> peer.setBounds -> - // postConfigureEvent -> Component.setBounds -> ... In some cases - // Configure event loops cause windows to jitter back and forth - // continuously). - void setBoundsCallback (int x, int y, int w, int h) - { - if (this.x == x && this.y == y && width == w && height == h) - return; - invalidate(); - boolean resized = width != w || height != h; - boolean moved = this.x != x || this.y != y; - this.x = x; - this.y = y; - width = w; - height = h; - if (resized && isShowing ()) - { - ComponentEvent ce = - new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED); - getToolkit().getSystemEventQueue().postEvent(ce); - } - if (moved && isShowing ()) - { - ComponentEvent ce = - new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED); - getToolkit().getSystemEventQueue().postEvent(ce); - } } /** Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c =================================================================== RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c,v retrieving revision 1.8 diff -u -r1.8 gnu_java_awt_peer_gtk_GtkFramePeer.c --- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c 14 Jul 2005 22:07:02 -0000 1.8 +++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c 17 Aug 2005 04:22:40 -0000 @@ -85,11 +85,15 @@ gdk_threads_enter (); ptr = NSA_GET_PTR (env, obj); - mptr = NSA_GET_PTR (env, menubar); - fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; - gtk_fixed_put (GTK_FIXED (fixed), mptr, 0, 0); - gtk_widget_show (mptr); + if (menubar) + { + mptr = NSA_GET_PTR (env, menubar); + + fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; + gtk_fixed_put (GTK_FIXED (fixed), mptr, 0, 0); + gtk_widget_show (mptr); + } gdk_threads_leave (); } @@ -121,15 +125,18 @@ gdk_threads_enter (); - ptr = NSA_GET_PTR (env, menubar); - - /* Get the menubar's natural size request. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); - gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); - - /* Set the menubar's size request to width by natural_req.height. */ - gtk_widget_set_size_request (GTK_WIDGET (ptr), - width, natural_req.height); + if (menubar) + { + ptr = NSA_GET_PTR (env, menubar); + + /* Get the menubar's natural size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); + gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); + + /* Set the menubar's size request to width by natural_req.height. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), + width, natural_req.height); + } gdk_threads_leave (); } Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c =================================================================== RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c,v retrieving revision 1.51 diff -u -r1.51 gnu_java_awt_peer_gtk_GtkWindowPeer.c --- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 14 Jul 2005 22:07:02 -0000 1.51 +++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 17 Aug 2005 04:22:40 -0000 @@ -260,20 +260,12 @@ static jmethodID postInsetsChangedEventID; static jmethodID windowGetWidthID; static jmethodID windowGetHeightID; -static jmethodID setBoundsCallbackID; void cp_gtk_window_init_jni (void) { - jclass window; jclass gtkwindowpeer; - window = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), "java/awt/Window"); - - setBoundsCallbackID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), window, - "setBoundsCallback", - "(IIII)V"); - gtkwindowpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), "gnu/java/awt/peer/gtk/GtkWindowPeer"); @@ -1346,17 +1338,6 @@ gdk_flush (); gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBoundsCallback - (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), - jobject window, jint x, jint y, jint width, jint height) -{ - /* Circumvent package-private access to call Window's - setBoundsCallback method. */ - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), window, setBoundsCallbackID, - x, y, width, height); } JNIEXPORT void JNICALL
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches