2003/09/21 10:26:53
[org.ibex.core.git] / src / org / xwt / Box.java.pp
index 245a2c1..eb8c0c0 100644 (file)
@@ -105,6 +105,7 @@ public final class Box extends JS.Scope {
      *  changes.
      */
     static int FONT_CHANGED_FLAG = 0x00000100;
+    static int ISROOT_FLAG       = 0x00000200;
 
     static int ALIGN_FLAG        = 0x00000000;
     static int FIXEDASPECT_FLAG  = 0x00000000;
@@ -477,7 +478,6 @@ public final class Box extends JS.Scope {
             // FIXME: clipping
             char c = text.charAt(i);
             Glyph g = Glyph.getGlyph(font, fontsize, c);
-            System.out.println("rendering glyph for " + c + " as " + g + " @ " + (x+hpad) + ", " + (y+vpad));
            buf.drawPicture(g.p,
                             x + hpad,
                             y + vpad + g.max_ascent - g.baseline,
@@ -512,7 +512,9 @@ public final class Box extends JS.Scope {
                 Template t = Template.buildTemplate(res.getInputStream(), "fromResource");
                 if (ThreadMessage.suspendThread()) try {
                     JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
-                    t.apply(this, null, null, callback, 0, t.numUnits());
+
+                    // FIXME!!! needs to be xwt.apply(template, box)
+                    t.apply(this, null, null, callback, 0, t.numUnits(), null);
                 } finally {
                     ThreadMessage.resumeThread();
                 }
@@ -527,7 +529,8 @@ public final class Box extends JS.Scope {
                 } else {
                     if (ThreadMessage.suspendThread()) try {
                         JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
-                        t.apply(this, null, null, callback, 0, t.numUnits());
+                        // FIXME!!! needs to be xwt.apply(template, box)
+                        t.apply(this, null, null, callback, 0, t.numUnits(), null);
                     } finally {
                         ThreadMessage.resumeThread();
                     }
@@ -649,17 +652,9 @@ public final class Box extends JS.Scope {
         String name = (String)name_;
         if (name.equals("")) return null;
 
-        // See if we're reading back the function value of a trap
-        if (name.charAt(0) == '_') {
-            if (name.charAt(1) == '_') name = name.substring(2);
-            else name = name.substring(1);
-            Trap t = Trap.getTrap(this, name);
-            return t == null ? null : t.f;
-        }
-        
         // See if we're triggering a trap
         Trap t = traps == null || ignoretraps ? null : (Trap)traps.get(name);
-        if (t != null && t.isreadtrap) return t.perform(Trap.emptyargs);
+        if (t != null) return t.perform();
 
         // Check for a special handler
         SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
@@ -677,6 +672,10 @@ public final class Box extends JS.Scope {
         return ret;
     }
 
+    public void addTrap(Object name, Object value) { Trap.addTrap(this, name, ((JS.CompiledFunction)value)); }
+    public void delTrap(Object name, Object value) { Trap.delTrap(this, name, ((JS.CompiledFunction)value)); }
+
+
     /**
      *  Scriptable.put()
      *  @param ignoretraps if set, no traps will be triggered (set when 'cascade' reaches the bottom of the trap stack)
@@ -692,10 +691,7 @@ public final class Box extends JS.Scope {
         if (!ignoretraps && traps != null) {
             Trap t = (Trap)traps.get(name);
             if (t != null) {
-                JS.Array arg = new JS.Array();
-                arg.addElement(value);
-                t.perform(arg);
-                arg.setElementAt(null, 0);
+                t.perform(value);
                 return;
             }
         }
@@ -706,25 +702,6 @@ public final class Box extends JS.Scope {
         SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
         if (gph != null) { gph.put(name, this, value); return; }
 
-        if (name.charAt(0) == '_') {
-            if (value != null && !(value instanceof JS.Callable)) {
-                if (Log.on) Log.logJS(this, "attempt to put a non function value (" + value + ") to " + name);
-            } else if (value != null && !(value instanceof JS.CompiledFunction)) {
-                if (Log.on) Log.logJS(this, "attempt to put a non-compiled function value (" + value + ") to " + name);
-            } else if (name.charAt(1) == '_') {
-                name = name.substring(2).intern();
-                Trap t = Trap.getTrap(this, name);
-                if (t != null) t.delete();
-                if (value != null) Trap.addTrap(this, name, ((JS.CompiledFunction)value), true, rp);
-            } else {
-                name = name.substring(1).intern();
-                Trap t = Trap.getTrap(this, name);
-                if (t != null) t.delete();
-                if (value != null) Trap.addTrap(this, name, ((JS.CompiledFunction)value), false, rp);
-            }
-            return;
-        }
-
         super.put(name, value);
     }
 
@@ -1312,10 +1289,13 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("DoubleClick3", mouseEventHandler);
 
             specialBoxProperties.put("root", new SpecialBoxProperty() {
+                    public void put(Box b, Object value) {
+                        if (stob(value)) b.flags |= ISROOT_FLAG;
+                        else b.flags &= ~ISROOT_FLAG;
+                    }
                     public Object get(Box b) {
-                        if (b.getRoot() == null) return null;
-                        else if (b.parent == null) return b;
-                        else return b.getRoot().getRootProxy();
+                        if (b.parent == null || ((b.flags & ISROOT_FLAG) != 0)) return b;
+                        else return get(b.parent);
                     } });
 
             specialBoxProperties.put("Minimized", new SpecialBoxProperty() {