classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] GTK peer insets fix


From: Thomas Fitzsimmons
Subject: [cp-patches] GTK peer insets fix
Date: Fri, 12 Aug 2005 20:30:36 -0400

Hi,

This patch fixes a bug in our AWT -> GTK co-ordinate conversion code.
We were looking up the Frame insets using Window.getInsets, assuming
that would return the frame border dimensions.  But applications may
override Window.getInsets.  This patch retrieves the correct frame
border directions directly from the peer.

I've also added a toString method to GtkComponentPeer which helps with
debugging.

Tom

2005-08-12  Thomas Fitzsimmons  <address@hidden>

        * gnu/java/awt/peer/gtk/GtkComponentPeer.java (setBounds): Get
        frame insets directly from peer rather than from Window.getInsets.
        (toString): New method.

Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.91
diff -u -r1.91 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 26 Jul 2005 20:41:40 -0000      
1.91
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 13 Aug 2005 00:17:58 -0000
@@ -418,6 +418,9 @@
 
   public void setBounds (int x, int y, int width, int height)
   {
+    int new_x = x;
+    int new_y = y;
+
     Component parent = awtComponent.getParent ();
 
     // Heavyweight components that are children of one or more
@@ -438,8 +441,8 @@
 
        i = ((Container) parent).getInsets ();
 
-       x += parent.getX () + i.left;
-       y += parent.getY () + i.top;
+       new_x += parent.getX () + i.left;
+       new_y += parent.getY () + i.top;
 
        parent = parent.getParent ();
       }
@@ -448,18 +451,22 @@
     // placing a heavyweight component in a Window.
     if (parent instanceof Window && !lightweightChild)
       {
-       Insets insets = ((Window) parent).getInsets ();
         GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer ();
+        // important: we want the window peer's insets here, not the
+        // window's, since user sub-classes of Window can override
+        // getInset and we only want to correct for the frame borders,
+        // not for any user-defined inset values
+        Insets insets = peer.getInsets ();
+
         int menuBarHeight = 0;
         if (peer instanceof GtkFramePeer)
           menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight ();
 
-        // Convert from Java coordinates to GTK coordinates.
-        setNativeBounds (x - insets.left, y - insets.top + menuBarHeight,
-                         width, height);
+        new_x = x - insets.left;
+        new_y = y - insets.top + menuBarHeight;
       }
-    else
-      setNativeBounds (x, y, width, height);
+
+    setNativeBounds (new_x, new_y, width, height);
   }
 
   void setCursor ()
@@ -670,5 +677,10 @@
   public void destroyBuffers ()
   {
     backBuffer.flush();
+  }
+  
+  public String toString ()
+  {
+    return "peer of " + awtComponent.toString();
   }
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]