2003/11/03 05:28:32
[org.ibex.core.git] / src / org / xwt / Box.java.pp
index c58eebc..473d049 100644 (file)
@@ -112,8 +112,7 @@ public final class Box extends JS.Scope {
     public LENGTH maxwidth = MAX_LENGTH;
     public LENGTH maxheight = MAX_LENGTH;
     private String text = null;
-    private Res font = null;
-    private int fontsize = 10;
+    private Font font = null;
     private LENGTH textwidth = 0;
     private LENGTH textheight = 0;
 
@@ -454,15 +453,15 @@ public final class Box extends JS.Scope {
                 for(int y = globaly; y < clipy + cliph; y += image.getHeight())
                     buf.drawPicture(image, x, y, clipx, clipy, clipx + clipw, clipy + cliph);
 
-       if (text != null && !text.equals(""))
-            Glyph.rasterizeGlyphs(font, fontsize, text, buf, textcolor, globalx, globaly, clipx, clipy, clipw + clipx, clipy + cliph,
-                                  new Callback() { public Object call(Object arg) {
-                                      Box.this.dirty();
-                                      Box b = Box.this;
-                                      MARK_FOR_REFLOW_b;
-                                      b.dirty();
-                                      return null;
-                                  }});
+       if (text != null && !text.equals("") && font != null) // FIXME
+            font.rasterizeGlyphs(text, buf, textcolor,
+                                 globalx, globaly, clipx, clipy, clipw + clipx, clipy + cliph,
+                                 new Scheduler.Task() { public void perform() {
+                                     Box.this.dirty();
+                                     Box b = Box.this;
+                                     MARK_FOR_REFLOW_b;
+                                     b.dirty();
+                                 }});
 
         if (path != null) {
             if (rtransform == null) rpath = null;
@@ -518,27 +517,28 @@ public final class Box extends JS.Scope {
      *  INVARIANT: after completion, getChild(min(i, numChildren())) == newnode
      *  WARNING: O(n) runtime, unless i == numChildren()
      */
-    public void put(int i, Object value) {
-        if (i < 0) return;
+    public Object put(int i, Object value) {
+        if (i < 0) return null;
         Trap t = value == null ? (Trap)get("childremoved", Trap.class) : (Trap)get("childadded", Trap.class);
             
         if (value != null && !(value instanceof Box)) {
             if (Log.on) Log.logJS(this, "attempt to set a numerical property on a box to a non-box");
-            return;
+            return null;
         }
 
         if (redirect == null) {
-            if (t != null) t.perform(value);
+            if (t != null) return t.perform(value);
             else if (Log.on) Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect");
         } else if (redirect != this) {
             Box b = value == null ? (Box)redirect.get(i) : (Box)value;
+            // FIXME: what if both of them want a tailcall?
             redirect.put(i, value);
-            if (t != null) t.perform(value);
+            if (t != null) return t.perform(value);
         } else if (value == null) {
             if (i >= 0 && i < numChildren()) {
                 Box b = getChild(i);
                 b.remove();
-                if (t != null) t.perform(b);
+                if (t != null) return t.perform(b);
             }
         } else {
             Box newnode = (Box)value;
@@ -547,7 +547,7 @@ public final class Box extends JS.Scope {
             for(Box cur = newnode.parent; cur != null; cur = cur.parent)
                 if (cur.redirect == newnode) {
                     if (Log.on) Log.logJS(this, "attempt to move a box that is the target of a redirect");
-                    return;
+                    return null;
                 }
 
             // check for recursive ancestor violation
@@ -555,7 +555,7 @@ public final class Box extends JS.Scope {
                 if (cur == newnode) {
                     if (Log.on) Log.logJS(this, "attempt to make a node a parent of its own ancestor");
                     if (Log.on) Log.log(this, "box == " + this + "  ancestor == " + newnode);
-                    return;
+                    return null;
                 }
 
             if (numKids > 15 && children == null) convert_to_array();
@@ -600,12 +600,13 @@ public final class Box extends JS.Scope {
             MARK_FOR_REFLOW_this;
             
             newnode.dirty();
-            if (t != null) t.perform(b);
+            if (t != null) return t.perform(b);
         }
+        return null;
     }
     
     public Object get(Object key, Object key2) { return super.get(key, key2); }
-    public void put(Object key, Object key2, Object val) { super.put(key, key2, val); }
+    public void put2(Object key, Object key2, Object val) { super.put2(key, key2, val); }
 
     public Object get_(Object name) { return super.get(name); }
     public Object get(Object name) { return get(name, false); }
@@ -618,7 +619,7 @@ public final class Box extends JS.Scope {
 
         // See if we're triggering a trap
         Trap t = ignoretraps ? (Trap)null : (Trap)get(name, Trap.class);
-        if (t != null) return t.perform();
+        if (t != null) { t.perform(); return null; }
 
         // Check for a special handler
         SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
@@ -647,23 +648,20 @@ public final class Box extends JS.Scope {
      *  @param rp if this put is being performed via a root proxy, rp is the root proxy.
      */
     public void put_(Object name, Object value) { super.put(name, value); }
-    public void put(Object name, Object value) { put(name, value, false); }
-    public void put(Object name_, Object value, boolean ignoretraps) {
-        if (name_ instanceof Number) { put(((Number)name_).intValue(), value); return; }
-        if (!(name_ instanceof String)) { super.put(name_,value); return; }
+    public Object put(Object name, Object value) { return put(name, value, false); }
+    public Object put(Object name_, Object value,  boolean ignoretraps) {
+        if (name_ instanceof Number) { return put(((Number)name_).intValue(), value); }
+        if (!(name_ instanceof String)) { return super.put(name_,value); }
         String name = name_.toString();
         if (!ignoretraps) {
             Trap t = (Trap)get(name, Trap.class);
-            if (t != null) {
-                t.perform(value);
-                return;
-            }
+            if (t != null) return t.perform(value);
         }
 
         SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
-        if (gph != null) { gph.put(name, this, value); return; }
+        if (gph != null) { gph.put(name, this, value); return null; }
 
-        super.put(name, value);
+        return super.put(name, value);
     }
 
 
@@ -729,7 +727,9 @@ public final class Box extends JS.Scope {
         // note that JavaScript box[0] will invoke put(int i), not put(String s)
         if (oldparent != null) {
             Trap t = (Trap)oldparent.get("childremoved", Trap.class);
-            if (t != null) t.perform(this);
+
+            // FIXME!!
+            //if (t != null) t.perform(this, tail);
         }
     }
 
@@ -808,16 +808,14 @@ public final class Box extends JS.Scope {
 
     public void recompute_font() {
         if (text == null) { textwidth = textheight = 0; return; }
-        if (font == null) { /* FIXME */ }
-        long widthheight = Glyph.rasterizeGlyphs(font, fontsize, text, null, textcolor, 0, 0, 0, 0, 0, 0,
-                                                 new Callback() { public Object call(Object arg) {
-                                                     Box b = Box.this;
-                                                     recompute_font();
-                                                     MARK_FOR_REFLOW_b;
-                                                     b.dirty();
-                                                     return null;
-                                                 } });
-        if (widthheight == -1) return;
+        if (font == null) { /* FIXME */ return; }
+        long widthheight = font.rasterizeGlyphs(text, null, textcolor, 0, 0, 0, 0, 0, 0,
+                                                new Scheduler.Task() { public void perform() {
+                                                    Box b = Box.this;
+                                                    recompute_font();
+                                                    MARK_FOR_REFLOW_b;
+                                                    b.dirty();
+                                                } });
         textwidth = (int)((widthheight & 0xffff0000) >> 16);
         textheight = (int)(widthheight & 0x0000ffff);
         MARK_FOR_REFLOW_this;
@@ -897,15 +895,18 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("fill", new ColorBoxProperty() {
                     public void put(final Box b, final Object value) {
                         if (value == null || !(value instanceof Res)) super.put(b, value);
-                        else Picture.fromRes((Res)value, new Callback() { public Object call(Object pic) {
-                            if (pic == b.image) return null;
-                            b.image = (Picture)pic;
-                            b.minwidth = b.image.getWidth();
-                            b.minheight = b.image.getHeight();
-                            MARK_FOR_REFLOW_b;
-                            b.dirty();
-                            return null;
-                        } });
+                        else {
+                            Callback callback = new Callback() { public Object call(Object pic) {
+                                b.image = (Picture)pic;
+                                b.minwidth = b.image.getWidth();
+                                b.minheight = b.image.getHeight();
+                                MARK_FOR_REFLOW_b;
+                                b.dirty();
+                                return null;
+                            } };
+                            Picture pic = Picture.fromRes((Res)value, callback);
+                            if (pic != null) callback.call(pic);
+                        }
                     }
                     public int getColor(Box b) { return b.fillcolor; }
                     public void putColor(Box b, int argb) { b.fillcolor = argb; }
@@ -1011,7 +1012,8 @@ public final class Box extends JS.Scope {
                     public Object get(Box b) { return b.font; }
                     public void put(Box b, Object value) {
                         // FIXME: translate value into a resource if it is a string
-                        b.font = value == null ? null : (Res)value;
+                        b.font = value == null ? null :
+                            Font.getFont((Res)value, b.font == null ? 10 : b.font.pointsize); // FIXME
                         MARK_FOR_REFLOW_b;
                         b.flags |= FONT_CHANGED_FLAG;
                         b.dirty();
@@ -1021,8 +1023,9 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("fontsize", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.font; }
                     public void put(Box b, Object value) {
-                        if (b.fontsize == stoi(value)) return;
-                        b.fontsize = stoi(value);
+                        if (b.font != null && b.font.pointsize == stoi(value)) return;
+                        b.font = value == null ? null :
+                            Font.getFont(b.font == null ? null : b.font.res, stoi(value)); // FIXME
                         MARK_FOR_REFLOW_b;
                         b.flags |= FONT_CHANGED_FLAG;
                         b.dirty();