diff options
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java')
-rw-r--r-- | libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java | 189 |
1 files changed, 125 insertions, 64 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java index 6cc1390ea39..d15beacb4db 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/libjava/classpath/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. @@ -42,7 +42,9 @@ import java.awt.AWTEvent; import java.awt.Component; 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; @@ -62,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); @@ -85,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; @@ -129,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) @@ -167,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); } @@ -195,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); } @@ -244,37 +280,62 @@ public class GtkWindowPeer extends GtkContainerPeer // TODO Auto-generated method stub } + + protected void postExposeEvent (int x, int y, int width, int height) + { + // Translate GTK co-ordinates, which do not include a window + // frame's insets, to AWT co-ordinates, which do include a window + // frame's insets. GtkWindowPeer should always have all-zero + // insets but GtkFramePeer and GtkDialogPeer insets will be + // non-zero. + q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, + new Rectangle (x + insets.left, + y + insets.top, + width, height))); + } + public boolean requestWindowFocus() { // TODO Auto-generated method stub return false; } - public void handleEvent(AWTEvent event) + public Graphics getGraphics () { - int id = event.getID(); - if (id == PaintEvent.UPDATE || id == PaintEvent.PAINT) - { - try - { - Graphics g = getGraphics(); - if (! awtComponent.isShowing() || awtComponent.getWidth() < 1 - || awtComponent.getHeight() < 1 || g == null) - return; - - g.setClip(((PaintEvent) event).getUpdateRect()); - - // Do not want to clear anything before painting. - awtComponent.paint(g); - - g.dispose(); - return; - } - catch (InternalError e) - { - System.err.println(e); - } - } - super.handleEvent(event); + Graphics g = super.getGraphics (); + // Translate AWT co-ordinates, which include a window frame's + // insets, to GTK co-ordinates, which do not include a window + // frame's insets. GtkWindowPeer should always have all-zero + // insets but GtkFramePeer and GtkDialogPeer insets will be + // non-zero. + g.translate (-insets.left, -insets.top); + return g; + } + + protected void updateComponent (PaintEvent event) + { + // Do not clear anything before painting. Sun never calls + // Window.update, only Window.paint. + paintComponent(event); + } + + protected void postMouseEvent(int id, long when, int mods, int x, int y, + int clickCount, boolean popupTrigger) + { + // Translate AWT co-ordinates, which include a window frame's + // insets, to GTK co-ordinates, which do not include a window + // frame's insets. GtkWindowPeer should always have all-zero + // insets but GtkFramePeer and GtkDialogPeer insets will be + // non-zero. + super.postMouseEvent (id, when, mods, + 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); } } |