commit-classpath
[Top][All Lists]
Advanced

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

Patch: FYI: fix placing of heavyweights within lightweight containers


From: Thomas Fitzsimmons
Subject: Patch: FYI: fix placing of heavyweights within lightweight containers
Date: Tue, 20 Jan 2004 16:35:31 -0500

Hi,

I committed this patch.

Tom

2004-01-20  Thomas Fitzsimmons  <address@hidden>

        * gnu/java/awt/peer/gtk/GtkComponentPeer.java (setBounds):
        Calculate proper offsets for heavyweight components packed in
        lightweight containers.

Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file:
/cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.13
diff -u -r1.13 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 13 Jan 2004 20:54:46
-0000   1.13
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 16 Jan 2004 03:26:17
-0000
@@ -42,6 +42,7 @@
 import java.awt.BufferCapabilities;
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.Container;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Font;
@@ -292,8 +293,34 @@
   public void setBounds (int x, int y, int width, int height)
   {
     Component parent = awtComponent.getParent ();
-    
-    if (parent instanceof Window)
+
+    // Heavyweight components that are children of one or more
+    // lightweight containers have to be handled specially.  Because
+    // calls to GLightweightPeer.setBounds do nothing, GTK has no
+    // knowledge of the lightweight containers' positions.  So we have
+    // to add the offsets manually when placing a heavyweight
+    // component within a lightweight container.  The lightweight
+    // container may itself be in a lightweight container and so on,
+    // so we need to continue adding offsets until we reach a
+    // container whose position GTK knows -- that is, the first
+    // non-lightweight.
+    boolean lightweightChild = false;
+    Insets i;
+    while (parent.isLightweight ())
+      {
+       lightweightChild = true;
+
+       i = ((Container) parent).getInsets ();
+
+       x += parent.getX () + i.left;
+       y += parent.getY () + i.top;
+
+       parent = parent.getParent ();
+      }
+
+    // We only need to convert from Java to GTK coordinates if we're
+    // placing a heavyweight component in a Window.
+    if (parent instanceof Window && !lightweightChild)
       {
        Insets insets = ((Window) parent).getInsets ();
        // Convert from Java coordinates to GTK coordinates.






reply via email to

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