diff options
Diffstat (limited to 'gnu/java/awt/peer/gtk/GtkWindowPeer.java')
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkWindowPeer.java | 120 |
1 files changed, 81 insertions, 39 deletions
diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java index 70c6615fa..d15beacb4 100644 --- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java @@ -1,5 +1,5 @@ /* GtkWindowPeer.java -- Implements WindowPeer with GTK - Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2002, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,6 +44,7 @@ import java.awt.Frame; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Window; +import java.awt.event.ComponentEvent; import java.awt.event.PaintEvent; import java.awt.event.WindowEvent; import java.awt.peer.WindowPeer; @@ -63,20 +64,37 @@ public class GtkWindowPeer extends GtkContainerPeer private boolean hasBeenShown = false; private int oldState = Frame.NORMAL; + // Cached awt window component location, width and height. + private int x, y, width, height; + native void gtkWindowSetTitle (String title); native void gtkWindowSetResizable (boolean resizable); native void gtkWindowSetModal (boolean modal); native void realize (); + /** Returns the cached width of the AWT window component. */ + int getX () + { + return x; + } + + /** Returns the cached width of the AWT window component. */ + int getY () + { + return y; + } + + /** Returns the cached width of the AWT window component. */ int getWidth () { - return awtComponent.getWidth(); + return width; } + /** Returns the cached height of the AWT window component. */ int getHeight () { - return awtComponent.getHeight(); + return height; } native void create (int type, boolean decorated, GtkWindowPeer parent); @@ -86,6 +104,10 @@ public class GtkWindowPeer extends GtkContainerPeer Window window = (Window) awtComponent; GtkWindowPeer parent_peer = null; Component parent = awtComponent.getParent(); + x = awtComponent.getX(); + y = awtComponent.getY(); + height = awtComponent.getHeight(); + width = awtComponent.getWidth(); if (!window.isFocusableWindow()) type = GDK_WINDOW_TYPE_HINT_MENU; @@ -130,37 +152,28 @@ public class GtkWindowPeer extends GtkContainerPeer native void nativeSetLocation (int x, int y); native void nativeSetLocationUnlocked (int x, int y); - public void setLocation (int x, int y) + // Called from show. + protected void setLocation (int x, int y) { - // prevent window_configure_cb -> awtComponent.setSize -> - // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock. - if (Thread.currentThread() == GtkToolkit.mainThread) - return; nativeSetLocation (x, y); } - public void setLocationUnlocked (int x, int y) - { - nativeSetLocationUnlocked (x, y); - } - public void setBounds (int x, int y, int width, int height) { - // prevent window_configure_cb -> awtComponent.setSize -> - // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock. - if (Thread.currentThread() == GtkToolkit.mainThread) - return; - - nativeSetBounds (x, y, - width - insets.left - insets.right, - height - insets.top - insets.bottom); - } - - public void setBoundsUnlocked (int x, int y, int width, int height) - { - nativeSetBoundsUnlocked (x, y, - width - insets.left - insets.right, - height - insets.top - insets.bottom); + if (x != getX() + || y != getY() + || width != getWidth() + || height != getHeight()) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + + nativeSetBounds (x, y, + width - insets.left - insets.right, + height - insets.top - insets.bottom); + } } public void setTitle (String title) @@ -168,15 +181,25 @@ public class GtkWindowPeer extends GtkContainerPeer gtkWindowSetTitle (title); } - native void setSize (int width, int height); - + // Called from setResizable + protected native void setSize (int width, int height); + + /** + * Needed by both GtkFramePeer and GtkDialogPeer subclasses, so + * implemented here. But never actually called on a GtkWindowPeer + * itself. + */ public void setResizable (boolean resizable) { // Call setSize; otherwise when resizable is changed from true to // false the window will shrink to the dimensions it had before it // was resizable. - setSize (awtComponent.getWidth() - insets.left - insets.right, - awtComponent.getHeight() - insets.top - insets.bottom); + x = awtComponent.getX(); + y = awtComponent.getY(); + width = awtComponent.getWidth(); + height = awtComponent.getHeight(); + setSize (width - insets.left - insets.right, + height - insets.top - insets.bottom); gtkWindowSetResizable (resizable); } @@ -196,23 +219,35 @@ public class GtkWindowPeer extends GtkContainerPeer int frame_width = width + insets.left + insets.right; int frame_height = height + insets.top + insets.bottom; - if (frame_width != awtComponent.getWidth() - || frame_height != awtComponent.getHeight()) - awtComponent.setSize(frame_width, frame_height); + 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 != awtComponent.getX() - || frame_y != awtComponent.getY()) + if (frame_x != getX() + || frame_y != getY()) { - // awtComponent.setLocation(frame_x, frame_y); + this.x = frame_x; + this.y = frame_y; + q().postEvent(new ComponentEvent(awtComponent, + ComponentEvent.COMPONENT_MOVED)); } } public void show () { - setLocation(awtComponent.getX(), awtComponent.getY()); + x = awtComponent.getX(); + y = awtComponent.getY(); + width = awtComponent.getWidth(); + height = awtComponent.getHeight(); + setLocation(x, y); setVisible (true); } @@ -296,4 +331,11 @@ public class GtkWindowPeer extends GtkContainerPeer x + insets.left, y + insets.top, clickCount, popupTrigger); } + + // We override this to keep it in sync with our internal + // representation. + public Rectangle getBounds() + { + return new Rectangle(x, y, width, height); + } } |