Somehow the peer->AWT component bounds update has been broken, resulting
in:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29448
Some testing shows that the bounds is not updated via:
- Component.reshape() calls (this could induce loops)
- Some event via the EventQueue
What remains is:
- Private callback methods called from JNI or via reflection
- Magic
and the way that I did it:
- Directly dispatch a special event to the (final)
Component.dispatchEvent() to carry the new bounds to the AWT.
This is not really testable, because that method is final. However, this
impossibility to test seems to indicate that this also can't be a
compatibility issue.
2006-10-13 Roman Kennke <[EMAIL PROTECTED]>
PR 29448
* java/awt/Component.java
(dispatchEventImpl): Special handle ComponentReshapeEvents to
update the AWT's knowledge about a component's size.
* gnu/java/awt/ComponentReshapeEvent.java: New class.
* gnu/java/awt/peer/gtk/GtkWindowPeer.java
(postConfigureEvent): Directly dispatch a ComponentReshapeEvent
to update the AWT's knowledge about the component bounds.
/Roman
Index: gnu/java/awt/ComponentReshapeEvent.java
===================================================================
RCS file: gnu/java/awt/ComponentReshapeEvent.java
diff -N gnu/java/awt/ComponentReshapeEvent.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/awt/ComponentReshapeEvent.java 13 Oct 2006 15:14:09 -0000
@@ -0,0 +1,85 @@
+/* WindowResizeEvent.java -- Used to synchronize the AWT and peer sizes
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt;
+
+import java.awt.AWTEvent;
+import java.awt.Component;
+
+/**
+ * This is used to update the AWT's knowledge about a Window's size when
+ * the user changes the window bounds.
+ *
+ * This event is _not_ posted to the eventqueue, but rather dispatched directly
+ * via Window.dispatchEvent(). It is the cleanest way we could find to update
+ * the AWT's knowledge of the window size. Small testprograms showed the
+ * following:
+ * - Component.reshape() and its derivatives are _not_ called. This makes sense
+ * as it could end up in loops,because this calls back into the peers.
+ * - Intercepting event dispatching for any events in
+ * EventQueue.dispatchEvent() showed that the size is still updated. So it
+ * is not done via an event dispatched over the eventqueue.
+ *
+ * Possible other candidates for implementation would have been:
+ * - Call a (private) callback method in Window/Component from the native
+ * side.
+ * - Call a (private) callback method in Window/Component via reflection.
+ *
+ * Both is uglier than sending this event directly. Note however that this
+ * is impossible to test, as Component.dispatchEvent() is final and can't be
+ * intercepted from outside code. But this impossibility to test the issue from
+ * outside code also means that this shouldn't raise any compatibility issues.
+ */
+public class ComponentReshapeEvent
+ extends AWTEvent
+{
+
+ public int x;
+ public int y;
+ public int width;
+ public int height;
+
+ public ComponentReshapeEvent(Component c, int x, int y, int width, int height)
+ {
+ super(c, 1999);
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+}
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.149
diff -u -1 -5 -r1.149 Component.java
--- java/awt/Component.java 22 Sep 2006 12:27:11 -0000 1.149
+++ java/awt/Component.java 13 Oct 2006 15:14:11 -0000
@@ -29,30 +29,32 @@
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt;
//import gnu.java.awt.dnd.peer.gtk.GtkDropTargetContextPeer;
+import gnu.java.awt.ComponentReshapeEvent;
+
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.AdjustmentEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputEvent;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
@@ -5686,30 +5688,45 @@
return translated;
}
/**
* Implementation of dispatchEvent. Allows trusted package classes
* to dispatch additional events first. This implementation first
* translates <code>e</code> to an AWT 1.0 event and sends the
* result to [EMAIL PROTECTED] #postEvent}. If the AWT 1.0 event is not
* handled, and events of type <code>e</code> are enabled for this
* component, e is passed on to [EMAIL PROTECTED] #processEvent}.
*
* @param e the event to dispatch
*/
void dispatchEventImpl(AWTEvent e)
{
+ // Update the component's knowledge about the size.
+ // Important: Please look at the big comment in ComponentReshapeEvent
+ // to learn why we did it this way. If you change this code, make
+ // sure that the peer->AWT bounds update still works.
+ // (for instance: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29448 )
+ if (e instanceof ComponentReshapeEvent)
+ {
+ ComponentReshapeEvent reshape = (ComponentReshapeEvent) e;
+ x = reshape.x;
+ y = reshape.y;
+ width = reshape.width;
+ height = reshape.height;
+ return;
+ }
+
// Retarget focus events before dispatching it to the KeyboardFocusManager
// in order to handle lightweight components properly.
boolean dispatched = false;
if (! e.isFocusManagerEvent)
{
e = KeyboardFocusManager.retargetFocusEvent(e);
dispatched = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.dispatchEvent(e);
}
if (! dispatched)
{
// Give toolkit a chance to dispatch the event
// to globally registered listeners.
Toolkit.getDefaultToolkit().globalDispatchEvent(e);
Index: gnu/java/awt/peer/gtk/GtkWindowPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java,v
retrieving revision 1.53
diff -u -1 -5 -r1.53 GtkWindowPeer.java
--- gnu/java/awt/peer/gtk/GtkWindowPeer.java 8 Aug 2006 22:23:36 -0000 1.53
+++ gnu/java/awt/peer/gtk/GtkWindowPeer.java 13 Oct 2006 15:14:12 -0000
@@ -26,30 +26,32 @@
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.awt.peer.gtk;
+import gnu.java.awt.ComponentReshapeEvent;
+
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.PaintEvent;
import java.awt.event.WindowEvent;
import java.awt.peer.WindowPeer;
public class GtkWindowPeer extends GtkContainerPeer
implements WindowPeer
{
@@ -212,53 +214,73 @@
}
protected void postInsetsChangedEvent (int top, int left,
int bottom, int right)
{
insets.top = top;
insets.left = left;
insets.bottom = bottom;
insets.right = right;
}
// called back by native side: window_configure_cb
// only called from GTK thread
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;
+ // Update the component's knowledge about the size.
+ // Important: Please look at the big comment in ComponentReshapeEvent
+ // to learn why we did it this way. If you change this code, make
+ // sure that the peer->AWT bounds update still works.
+ // (for instance: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29448 )
+
+ // We do this befor we post the ComponentEvent, because (in Window)
+ // we invalidate() / revalidate() when a ComponentEvent is seen,
+ // and the AWT must already know about the new size then.
+ if (frame_x != this.x || frame_y != this.y || frame_width != this.width
+ || frame_height != this.height)
+ {
+ ComponentReshapeEvent ev = new ComponentReshapeEvent(awtComponent,
+ frame_x,
+ frame_y,
+ frame_width,
+ frame_height);
+ awtComponent.dispatchEvent(ev);
+ }
+
if (frame_width != getWidth()
|| frame_height != getHeight())
{
this.width = frame_width;
this.height = frame_height;
q().postEvent(new ComponentEvent(awtComponent,
ComponentEvent.COMPONENT_RESIZED));
}
- int frame_x = x - insets.left;
- int frame_y = y - insets.top;
-
if (frame_x != getX()
|| frame_y != getY())
{
this.x = frame_x;
this.y = frame_y;
q().postEvent(new ComponentEvent(awtComponent,
ComponentEvent.COMPONENT_MOVED));
}
+
}
public void show ()
{
x = awtComponent.getX();
y = awtComponent.getY();
width = awtComponent.getWidth();
height = awtComponent.getHeight();
setLocation(x, y);
setVisible (true);
}
void postWindowEvent (int id, Window opposite, int newState)
{
if (id == WindowEvent.WINDOW_OPENED)