move JS's Hashtable to JS.O
[org.ibex.core.git] / src / org / ibex / core / Box.java
index 4967252..bb8a27b 100644 (file)
@@ -65,8 +65,8 @@ public final class Box extends JSScope implements Task {
     static final int MOUSEINSIDE  = 0x00000001;
     static final int VISIBLE      = 0x00000002;
     static final int PACKED       = 0x00000004;
-    static final int HSHRINK      = 0x00000008;
-    static final int VSHRINK      = 0x00000010;
+    public static final int HSHRINK      = 0x00000008;
+    public static final int VSHRINK      = 0x00000010;
     static final int BLACK        = 0x00000020;  // for red-black code
 
     static final int FIXED        = 0x00000040;
@@ -123,8 +123,8 @@ public final class Box extends JSScope implements Task {
     public int ay = 0;   // FEATURE: roll these into x/y; requires lots of changes; perhaps y()?
     public int width = 0;
     public int height = 0;
-    private int contentwidth = 0;      // == max(minwidth, textwidth, sum(child.contentwidth))
-    private int contentheight = 0;
+    public int contentwidth = 0;      // == max(minwidth, textwidth, sum(child.contentwidth))
+    public int contentheight = 0;
 
     private Path path = null;
     /*
@@ -170,8 +170,14 @@ public final class Box extends JSScope implements Task {
     // Reflow ////////////////////////////////////////////////////////////////////////////////////////
 
     /** should only be invoked on the root box */
-    public void reflow() { pack(); resize(x, y, maxwidth, maxheight); place(); }
-
+    public void reflow() {
+        pack();
+        resize(x, y,
+               test(HSHRINK) ? contentwidth : maxwidth,
+               test(VSHRINK) ? contentheight : maxheight);
+        place();
+    }
+    
     private static Box[] frontier = new Box[65535];
     /** pack the boxes into rows and columns, compute contentwidth */
     public void pack() {
@@ -226,7 +232,7 @@ public final class Box extends JSScope implements Task {
     
     void resize(int x, int y, int width, int height) {
         if (x == this.x && y == this.y && width == this.width && height == this.height) return;
-        boolean sizechange = (this.width != width || this.height != height) && getTrap("SizeChange") != null;
+        boolean sizechange = (this.width != width || this.height != height) && hasTrap("SizeChange");
         int thisx = parent == null ? 0 : this.x;
         int thisy = parent == null ? 0 : this.y;
         Box who = (parent == null ? this : parent);
@@ -442,9 +448,9 @@ public final class Box extends JSScope implements Task {
 
                 case "distanceto":
                     Box b = (Box)a0;
-                    JS ret = new JS();
-                    ret.put("x", N(localToGlobalX(0) - b.localToGlobalX(0)));
-                    ret.put("y", N(localToGlobalY(0) - b.localToGlobalY(0)));
+                    JS ret = new JS.O();
+                    ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0)));
+                    ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0)));
                     return ret;
 
                 //#end
@@ -462,7 +468,13 @@ public final class Box extends JSScope implements Task {
         case "indexof": return METHOD;
         case "distanceto": return METHOD;
         case "text": return text;
-        case "path": throw new JSExn("cannot read from the path property");
+        case "path": 
+            if (path != null) return path.toString();
+            if (text == null) return null;
+            if (font == null) return null;
+            String ret = "";
+            for(int i=0; i<text.length(); i++) ret += font.glyphs[text.charAt(i)].path;
+            return ret;
         case "fill": return Color.colorToString(fillcolor);
         case "strokecolor": return Color.colorToString(strokecolor);
         case "textcolor": return Color.colorToString(strokecolor);
@@ -506,7 +518,7 @@ public final class Box extends JSScope implements Task {
         throw new Error("unreachable"); // unreachable
     }
 
-    private class Mouse extends JS.Cloneable {
+    private class Mouse extends JS implements JS.Cloneable {
         public Object get(Object key) {
             //#switch(key)
             case "x": return N(globalToLocalX(getSurface()._mousex));
@@ -545,7 +557,7 @@ public final class Box extends JSScope implements Task {
         case "shrink":      CHECKSET_FLAG(HSHRINK | VSHRINK); RECONSTRAIN();
         case "hshrink":     CHECKSET_FLAG(HSHRINK); RECONSTRAIN();
         case "vshrink":     CHECKSET_FLAG(VSHRINK); RECONSTRAIN();
-        case "path":        path = Path.parse(toString(value)); dirty();
+        case "path":        path = Path.parse(toString(value)); RECONSTRAIN(); dirty();
         case "width":       setWidth(toInt(value), toInt(value));
         case "height":      setHeight(toInt(value), toInt(value));
         case "maxwidth":    setWidth(minwidth, toInt(value));
@@ -819,7 +831,7 @@ public final class Box extends JSScope implements Task {
     void set(int mask) { flags |= mask; }
     void set(int mask, boolean setclear) { if (setclear) set(mask); else clear(mask); }
     void clear(int mask) { flags &= ~mask; }
-    boolean test(int mask) { return ((flags & mask) == mask); }
+    public boolean test(int mask) { return ((flags & mask) == mask); }
     
 
     // Tree Handling //////////////////////////////////////////////////////////////////////