2003/09/16 21:28:43
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:35:39 +0000 (07:35 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:35:39 +0000 (07:35 +0000)
darcs-hash:20040130073539-2ba56-30d105f82648c283fe255206b98359c0a7825944.gz

src/org/xwt/Box.java.pp

index 959deff..b5b8d58 100644 (file)
@@ -7,8 +7,8 @@ package org.xwt;
 // upper-left hand corner of <tt>this</tt>
 
 // FIXME: align
-// FIXME use bitfields
-// FIXME fixedaspect
+// FIXME: use bitfields
+// FIXME: fixedaspect
 // FIXME: reflow before allowing js to read from width/height 
 // FIXME: due to font inheritance, we must dirty and mark all null-font descendents of a node if its font changes
 // FEATURE: fastpath for rows=1/cols=1
@@ -117,9 +117,9 @@ public final class Box extends JS.Scope {
     LENGTH y = 0;
     public LENGTH width = 0;
     public LENGTH height = 0;
-    private int row = 0;  // FIXME short
-    private int col = 0;  // FIXME short
-    private LENGTH contentwidth = 0;             // == max(minwidth, textwidth, sum(child.contentwidth) + pad)
+    private int row = 0;  // FIXME use a short
+    private int col = 0;  // FIXME use a short
+    private LENGTH contentwidth = 0;             // == max(minwidth, textwidth+pad, sum(child.contentwidth) + pad)
     private LENGTH contentheight = 0;
 
 
@@ -136,11 +136,12 @@ public final class Box extends JS.Scope {
     private String cursor = null;                // the cursor for this box
 
     //FIXME make private
-    public boolean invisible = false;           // true iff the Box is invisible
+    public boolean invisible = false;            // true iff the Box is invisible
     private boolean absolute = false;            // If true, the box will be positioned absolutely
     private boolean vshrink = false;             // If true, the box will shrink to the smallest vertical size possible
     private boolean hshrink = false;             // If true, the box will shrink to the smallest horizontal size possible
-    private boolean tile = false; // FIXME: drop this?
+    private boolean tile = false;                // FIXME: drop this?
+
 
     // Instance Methods /////////////////////////////////////////////////////////////////////
 
@@ -205,8 +206,8 @@ public final class Box extends JS.Scope {
     void repack() {
         if (!needs_reflow) return;
         if (numChildren() == 0) {
-           contentwidth = max(textwidth, minwidth);
-           contentheight = max(textheight, minheight);
+           contentwidth = max(textwidth + 2 * hpad, minwidth);
+           contentheight = max(textheight + 2 * vpad, minheight);
            return;
        }
 
@@ -405,7 +406,8 @@ public final class Box extends JS.Scope {
         clipx = max(clipx, globalx + hpad);
         clipy = max(clipy, globaly + vpad);
 
-        for(Box b = getChild(0); b != null; b = b.nextSibling()) b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);   
+        for(Box b = getChild(0); b != null; b = b.nextSibling())
+            b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);   
     }
 
     void renderStretchedImage(int globalx, int globaly, int x, int y, int w, int h, DoubleBuffer buf) {
@@ -450,38 +452,20 @@ public final class Box extends JS.Scope {
     }
 
     void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
-
-       Log.log(this, "rendering text: " + text);
         //buf.setClip(clipx, clipy, clipw, cliph);
 
        try {
-           ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, text);
+           ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, text, false);
            Picture p = Platform.createPicture(id);
-           buf.drawPicture(p, x, y);
+            // FIXME: color
+            // FIXME: underline (dotted?)
+           buf.drawPicture(p, x + hpad, y + vpad);
            buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
        } catch (Exception e) {
            Log.log(this, e);
        }
 
-       /*
-        buf.drawString(font(), text, x + hpad, y + vpad + Platform.getMaxAscent(font()) - 1, textcolor);
         buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
-        int i=0; while(i<font().length() && !Character.isDigit(font().charAt(i))) i++;
-
-        if (font().lastIndexOf('d') > i) {
-            for(int j = x + hpad; j < x + hpad + textdim(0); j += 2)
-                buf.fillRect(j, y + vpad + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2,
-                             j + 1, y + vpad + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
-                             textcolor);
-
-        } else if (font().lastIndexOf('u') > i) {
-            buf.fillRect(x + hpad,
-                        y + vpad + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2,
-                        x + hpad + textdim(0),
-                        y + vpad + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
-                        textcolor);
-        }
-       */
     }
 
 
@@ -962,7 +946,6 @@ public final class Box extends JS.Scope {
                             }
                         else if (SVG.colors.get(s) != null)
                             newcolor = 0xFF000000 | ((Integer)SVG.colors.get(s)).intValue();
-                        // FIXME put named colors back in
                         if (newcolor == b.fillcolor) return;
                         b.fillcolor = newcolor;
                         b.dirty();
@@ -974,6 +957,7 @@ public final class Box extends JS.Scope {
                     public Object get(Box b) { return b.get("fillcolor"); }
                     public void put(Box b, Object value) { b.put("fillcolor", value); }
                 });
+
             specialBoxProperties.put("textcolor", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.get("strokecolor"); }
                     public void put(Box b, Object value) { b.put("strokecolor", value); }
@@ -986,10 +970,12 @@ public final class Box extends JS.Scope {
                         if (t.equals(b.text)) return;
                        b.text = t;
                        if (t == null) {
+                            if (b.textwidth != 0 || b.textheight != 0) MARK_FOR_REFLOW_b;
                            b.textwidth = b.textheight = 0;
                        } else {
                            try {
-                               ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, b.text);
+                               ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, b.text, true);
+                                if (id.getWidth() != b.textwidth || id.getHeight() != b.textheight) MARK_FOR_REFLOW_b;
                                b.textwidth = id.getWidth();
                                b.textheight = id.getHeight();
                            } catch (Exception e) {
@@ -997,13 +983,14 @@ public final class Box extends JS.Scope {
                            }
                        }
                        b.dirty();
-                       MARK_FOR_REFLOW_b;
                     } });
+
             specialBoxProperties.put("font", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.font; }
                     public void put(Box b, Object value) {
                         b.font = value == null ? null : value.toString();
-                        //b.fontChanged();
+                        // FIXME: need a resource stream to hand off to MIPS
+                        // FIXME: MARK_FOR_REFLOW here
                         b.dirty();
                     } });
         
@@ -1018,6 +1005,7 @@ public final class Box extends JS.Scope {
 
             specialBoxProperties.put("orient", new SpecialBoxProperty() {
                     public Object get(Box b) {
+                        Log.log(this, "warning: the orient property is deprecated");
                         if (b.redirect == null) return "horizontal";
                         else if (b.redirect != b) return get(b.redirect);
                         else if (b.cols == 1) return "vertical";
@@ -1025,6 +1013,7 @@ public final class Box extends JS.Scope {
                         else return "grid";
                     }
                     public void put(Box b, Object value) {
+                        Log.log(this, "warning: the orient property is deprecated");
                         if (value == null) return;
                         if (b.redirect == null) return;
                         if (b.redirect != b) { put(b.redirect, value); return; }
@@ -1083,8 +1072,7 @@ public final class Box extends JS.Scope {
                         b.dirty();
                         b.x = x;
                         if (b.parent == null && b.surface != null) {
-                            // FIXME this gets hosed by the #repeat
-                            //b.surface.setLocation(b.x, b.y);
+                            b.surface.setLocation();
                             b.surface.centerSurfaceOnRender = false;
                         }
                         MARK_FOR_REFLOW_b;
@@ -1102,6 +1090,7 @@ public final class Box extends JS.Scope {
                             b.surface.setSize();
                             MARK_FOR_REFLOW_b;
                         } else {
+                            if (b.minwidth == b.width && b.maxwidth == b.width) return;
                             b.minwidth = b.maxwidth = b.width;
                             MARK_FOR_REFLOW_b;
                         }
@@ -1112,6 +1101,7 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("cols", new SpecialBoxProperty() {
                     public Object get(Box b) { return new Double(b.cols); }
                     public void put(Box b, Object value) {
+                        if (b.cols == stoi(value)) return;
                         b.cols = stoi(value);
                         if (b.cols == 0 && b.rows == 0) b.rows = 1;
                         if (b.cols != 0 && b.rows != 0) b.rows = 0;
@@ -1122,16 +1112,19 @@ public final class Box extends JS.Scope {
             //#repeat colspan/rowspan
             specialBoxProperties.put("colspan", new SpecialBoxProperty() {
                     public Object get(Box b) { return new Double(b.colspan); }
-                    public void put(Box b, Object value) { b.colspan = stoi(value); MARK_FOR_REFLOW_b; }
+                    public void put(Box b, Object value) {
+                        if (b.colspan == stoi(value)) return;
+                        b.colspan = stoi(value);
+                        MARK_FOR_REFLOW_b;
+                    }
                 });
             //#end
         
             specialBoxProperties.put("tile", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.tile ? Boolean.TRUE : Boolean.FALSE; }
                     public void put(Box b, Object value) {
-                        boolean newtile = stob(value);
-                        if (newtile == b.tile) return;
-                        b.tile = newtile;
+                        if (b.tile == stob(value)) return;
+                        b.tile = stob(value);
                         b.dirty();
                     } });
         
@@ -1141,11 +1134,10 @@ public final class Box extends JS.Scope {
                         return Boolean.FALSE;
                     }
                     public void put(Box b, Object value) {
-                        boolean newinvisible = stob(value);
-                        if (newinvisible == b.invisible) return;
-                        b.invisible = newinvisible;
+                        if (stob(value) == b.invisible) return;
+                        b.invisible = stob(value);
                         if (b.parent == null) {
-                            if (b.surface != null) b.surface.setInvisible(newinvisible);
+                            if (b.surface != null) b.surface.setInvisible(b.invisible);
                         } else {
                             b.dirty();
                             MARK_FOR_REFLOW_b_parent;
@@ -1156,9 +1148,8 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("absolute", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.absolute ? Boolean.TRUE : Boolean.FALSE; }
                     public void put(Box b, Object value) {
-                        boolean newabsolute = stob(value);
-                        if (newabsolute == b.absolute) return;
-                        b.absolute = newabsolute;
+                        if (stob(value) == b.absolute) return;
+                        b.absolute = stob(value);
                         if (b.absolute) { b.x = 0; b.y = 0; }
                         if (b.parent != null) MARK_FOR_REFLOW_b_parent;
                     } });
@@ -1398,28 +1389,26 @@ public final class Box extends JS.Scope {
                 });
             */
         }
+    }
 
-        
-        /** helper that converts a String to a boolean according to JavaScript coercion rules */
-        public static boolean stob(Object o) {
-            if (o == null) return false;
-            return Boolean.TRUE.equals(o) || "true".equals(o);
-        }
+    /** helper that converts a String to a boolean according to JavaScript coercion rules */
+    public static boolean stob(Object o) {
+        if (o == null) return false;
+        return Boolean.TRUE.equals(o) || "true".equals(o);
+    }
 
+    /** helper that converts a String to an int according to JavaScript coercion rules */
+    public static int stoi(Object o) {
+        if (o == null) return 0;
+        if (o instanceof Integer) return ((Integer)o).intValue();
         
+        String s;
+        if (!(o instanceof String)) s = o.toString();
+        else s = (String)o;
+        
+        try { return Integer.parseInt(s.indexOf('.') == -1 ? s : s.substring(0, s.indexOf('.'))); }
+        catch (NumberFormatException e) { return 0; }
     }
-        /** helper that converts a String to an int according to JavaScript coercion rules */
-        public static int stoi(Object o) {
-            if (o == null) return 0;
-            if (o instanceof Integer) return ((Integer)o).intValue();
-
-            String s;
-            if (!(o instanceof String)) s = o.toString();
-            else s = (String)o;
-
-            try { return Integer.parseInt(s.indexOf('.') == -1 ? s : s.substring(0, s.indexOf('.'))); }
-            catch (NumberFormatException e) { return 0; }
-        }
 }