2002/07/25 23:30:51
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:49:27 +0000 (06:49 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:49:27 +0000 (06:49 +0000)
darcs-hash:20040130064927-2ba56-48feacbbb743189cccf9363e2f3de0b0de90869b.gz

src/org/xwt/Box.java

index e7d63cb..c60552c 100644 (file)
@@ -1072,34 +1072,40 @@ public final class Box extends JSObject {
      *  WARNING: O(n) runtime, unless i == numChildren()
      */
     public void put(int i, Scriptable start, Object value) {
-        if (value == null) {
-            if (i >= 0 && i < numChildren()) getChild(i).remove();
-            return;
-        }
-        if (value instanceof RootProxy) {
-            if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
-                                Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-            return;
-        } else if (!(value instanceof Box)) {
+
+        if (value != null && !(value instanceof Box)) {
             if (Log.on) Log.log(this, "attempt to set a numerical property on a box to anything other than a box at " +
                                 Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-            return;
-        }
-        Box newnode = (Box)value;
 
-        for(Box cur = this; cur != null; cur = cur.getParent())
-            if (cur == newnode) {
-                if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " + 
-                                    Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-                return;
+        } else if (redirect == null) {
+            if (Log.on) Log.log(this, "attempt to add/remove children to/from a node with a null redirect at " + 
+                                Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
+
+        } else if (redirect != this) {
+            Box b = value == null ? (Box)redirect.get(i, null) : (Box)value;
+            redirect.put(i, null, value);
+            put("0", null, b);
+
+        } else if (value == null) {
+            if (i >= 0 && i < numChildren()) {
+                Box b = getChild(i);
+                b.remove();
+                put("0", null, b);
             }
 
-        if (redirect == null) {
-            if (Log.on) Log.log(this, "attempt to add a child to a node with a null redirect at " + 
+        } else if (value instanceof RootProxy) {
+            if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
                                 Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-            return;
-        } else if (redirect != this) redirect.put(i, null, newnode);
-        else {
+
+        } else {
+            Box newnode = (Box)value;
+            for(Box cur = this; cur != null; cur = cur.getParent())
+                if (cur == newnode) {
+                    if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " + 
+                                        Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
+                    return;
+                }
+
             if (numKids > 15 && children == null) convert_to_array();
             if (newnode.parent != null) newnode.remove();
             newnode.parent = this;
@@ -1136,17 +1142,17 @@ public final class Box extends JSObject {
                 }
             }
             newnode.setSurface(surface);
-
+            
             // need both of these in case child was already uncalc'ed
             newnode.mark_for_prerender();
             mark_for_prerender(); 
-
+            
             newnode.dirty();
             sync_cmin_to_children();
-        }
 
-        // note that JavaScript box[0] will invoke put(int i), not put(String s)
-        put("0", null, newnode);
+            // note that JavaScript box[0] will invoke put(int i), not put(String s)
+            put("0", null, newnode);
+        }
     }
     
     public Object get(String name, Scriptable start) { return get(name, start, false); }