2003/08/10 06:03:02
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:04:16 +0000 (07:04 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:04:16 +0000 (07:04 +0000)
darcs-hash:20040130070416-2ba56-38177033c3d418639a932566ee9d9a5b5327a34e.gz

src/org/xwt/PNG.java
src/org/xwt/Platform.java
src/org/xwt/Proxy.java
src/org/xwt/SpecialBoxProperty.java [deleted file]
src/org/xwt/Surface.java
src/org/xwt/Template.java
src/org/xwt/Trap.java
src/org/xwt/XWF.java [deleted file]
src/org/xwt/XWT.java
src/org/xwt/plat/GCJ.java
src/org/xwt/util/Preprocessor.java [new file with mode: 0644]

index 20979a9..4f5640a 100644 (file)
@@ -21,7 +21,7 @@ import java.util.Enumeration;
 import java.util.zip.*;
 
 /** Converts an InputStream carrying a PNG image into an ARGB int[] */
-public class PNG implements ImageDecoder {
+public class PNG extends ImageDecoder {
 
     // Public Methods ///////////////////////////////////////////////////////////////////////////////
 
index 6ee700e..6f7771f 100644 (file)
@@ -371,20 +371,20 @@ public class Platform {
     public static Surface createSurface(Box b, boolean framed, boolean refreshable) {
         Surface ret = platform._createSurface(b, framed);
         ret.setInvisible(b.invisible);
-        b.set(Box.size, 0, b.size(0) < Surface.scarPicture.getWidth() ? Surface.scarPicture.getWidth() : b.size(0));
-        b.set(Box.size, 1, b.size(1) < Surface.scarPicture.getHeight() ? Surface.scarPicture.getHeight() : b.size(1));
+        b.width = b.height < Surface.scarPicture.getWidth() ? Surface.scarPicture.getWidth() : b.width;
+        b.height = b.height < Surface.scarPicture.getHeight() ? Surface.scarPicture.getHeight() : b.height;
 
         Object titlebar = b.get("titlebar", true);
         if (titlebar != null) ret.setTitleBarText(titlebar.toString());
 
         Object icon = b.get("icon", true);
         if (icon != null && !"".equals(icon)) {
-            Picture pic = Box.getPicture(icon.toString());
+            Picture pic = ImageDecoder.getPicture(icon.toString());
             if (pic != null) ret.setIcon(pic);
             else if (Log.on) Log.log(Platform.class, "unable to load icon " + icon);
         }
 
-        ret.setLimits(b.dmin(0), b.dmin(1), b.dmax(0), b.dmax(1));
+        ret.setLimits(b.minwidth, b.minheight, b.maxwidth, b.maxheight);
 
         if (refreshable) {
             Surface.refreshableSurfaceWasCreated = true;
index 876d35c..def26ca 100644 (file)
@@ -155,7 +155,8 @@ public class Proxy {
             if (Log.on) Log.log(Authorization.class, "displaying proxy authorization dialog");
             MessageQueue.add(new Message() {
                     public void perform() {
-                        Box b = new Box("org.xwt.builtin.proxy_authorization", null);
+                        Box b = new Box();
+                        Template.getTemplate("org.xwt.builtin.proxy_authorization", null).apply(b, null, null, null, 0, 0);
                         b.put("realm", realm);
                         b.put("proxyIP", proxyIP);
                     }
diff --git a/src/org/xwt/SpecialBoxProperty.java b/src/org/xwt/SpecialBoxProperty.java
deleted file mode 100644 (file)
index 56ee209..0000000
+++ /dev/null
@@ -1,716 +0,0 @@
-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
-
-import java.util.*;
-import java.net.*;
-import java.text.*;
-import org.xwt.js.*;
-import org.xwt.util.*;
-
-/** 
- *  A helper class for properties of Box which require special
- *  handling.
- *
- *  To avoid excessive use of String.equals(), the Box.get() and
- *  Box.put() methods employ a Hash keyed on property names that
- *  require special handling. The value stored in the Hash is an
- *  instance of an anonymous subclass of SpecialBoxProperty, which knows
- *  how to handle get()s and put()s for that property name. There
- *  should be one anonymous subclass of SpecialBoxProperty for each
- *  specially-handled property on Box.
- */
-class SpecialBoxProperty {
-
-    SpecialBoxProperty() { }
-    private static final int NUMINTS = Box.NUMINTS;
-    private static final int dmax = Box.dmax;
-    private static final int dmin = Box.dmin;
-    private static final int cmin = Box.cmin;
-    private static final int abs = Box.abs;
-    private static final int pos = Box.pos;
-    private static final int size = Box.size;
-    private static final int oldpos = Box.oldpos;
-    private static final int oldsize = Box.oldsize;
-    private static final int pad = Box.pad;
-
-    /** stores instances of SpecialBoxProperty; keyed on property name */
-    static Hash specialBoxProperties = new Hash(200, 3);
-
-    /** this method defines the behavior when the property is get()ed from b */
-    Object get(Box b) { return null; }
-
-    /** this method defines the behavior when the property is put() to b */
-    void put(Box b, Object value) { }
-
-    /** this method defines the behavior when the property is put() to b, allows a single SpecialBoxProperty to serve multiple properties */
-    void put(String name, Box b, Object value) { put(b, value); }
-
-    // 'ye olde IBM CGA colours', as defined in the XWT reference
-    static final int black = 0xFF000000;
-    static final int blue = 0xFF000088;
-    static final int green = 0xFF008800;
-    static final int cyan = 0xFF008888;
-    static final int red = 0xFF880000;
-    static final int magenta = 0xFF880088;
-    static final int brown = 0xFF888800;
-    static final int lightGray = 0xFFBDBEBD;
-    static final int darkGray = 0xFF242424;
-    static final int brightBlue = 0xFF0000FF;
-    static final int brightGreen = 0xFF00FF00;
-    static final int brightCyan = 0xFF00FFFF;
-    static final int brightRed = 0xFFFF0000;
-    static final int pink = 0xFFFF00FF;
-    static final int yellow = 0xFFFFFF00;
-    static final int white = 0xFFFFFFFF;
-
-    static {
-        specialBoxProperties.put("color", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if ((b.color & 0xFF000000) == 0) return null;
-                    String red = Integer.toHexString((b.color & 0x00FF0000) >> 16);
-                    String green = Integer.toHexString((b.color & 0x0000FF00) >> 8);
-                    String blue = Integer.toHexString(b.color & 0x000000FF);
-                    if (red.length() < 2) red = "0" + red;
-                    if (blue.length() < 2) blue = "0" + blue;
-                    if (green.length() < 2) green = "0" + green;
-                    return "#" + red + green + blue;
-                }
-                public void put(Box b, Object value) {
-                    int newcolor = b.color;
-                    String s = value == null ? null : value.toString();
-                    if (value == null) newcolor = 0x00000000;
-                    else if (s.length() > 0 && s.charAt(0) == '#')
-                        try {
-                            newcolor = 0xFF000000 |
-                                (Integer.parseInt(s.substring(1, 3), 16) << 16) |
-                                (Integer.parseInt(s.substring(3, 5), 16) << 8) |
-                                Integer.parseInt(s.substring(5, 7), 16);
-                        } catch (NumberFormatException e) {
-                            Log.log(this, "invalid color " + s);
-                            return;
-                        }
-                    else if (s.equals("black")) newcolor = black;
-                    else if (s.equals("blue")) newcolor = blue;
-                    else if (s.equals("green")) newcolor = green;
-                    else if (s.equals("cyan")) newcolor = cyan;
-                    else if (s.equals("red")) newcolor = red;
-                    else if (s.equals("magenta")) newcolor = magenta;
-                    else if (s.equals("brown")) newcolor = brown;
-                    else if (s.equals("lightGray")) newcolor = lightGray;
-                    else if (s.equals("darkGray")) newcolor = darkGray;
-                    else if (s.equals("brightBlue")) newcolor = brightBlue;
-                    else if (s.equals("brightGreen")) newcolor = brightGreen;
-                    else if (s.equals("brightCyan")) newcolor = brightCyan;
-                    else if (s.equals("brightRed")) newcolor = brightRed;
-                    else if (s.equals("pink")) newcolor = pink;
-                    else if (s.equals("yellow")) newcolor = yellow;
-                    else if (s.equals("white")) newcolor = white;
-                    else if (Log.on) Log.logJS(this, "invalid color \"" + s + "\"");
-                    if (newcolor == b.color) return;
-                    b.color = newcolor;
-                    b.dirty();
-                } });
-        
-        
-        specialBoxProperties.put("textcolor", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if ((b.textcolor & 0xFF000000) == 0) return null;
-                    String red = Integer.toHexString((b.textcolor & 0x00FF0000) >> 16);
-                    String green = Integer.toHexString((b.textcolor & 0x0000FF00) >> 8);
-                    String blue = Integer.toHexString(b.textcolor & 0x000000FF);
-                    if (red.length() < 2) red = "0" + red;
-                    if (blue.length() < 2) blue = "0" + blue;
-                    if (green.length() < 2) green = "0" + green;
-                    return "#" + red + green + blue;
-                }
-                public void put(Box b, Object value) {
-                    int newtextcolor = b.color;
-                    if (value == null) return;
-                    String s = value.toString();
-                    if (s.length() > 0 && s.charAt(0) == '#')
-                        newtextcolor = 0xFF000000 |
-                            (Integer.parseInt(s.substring(1, 3), 16) << 16) |
-                            (Integer.parseInt(s.substring(3, 5), 16) << 8) |
-                            Integer.parseInt(s.substring(5, 7), 16);
-                    else if (s.equals("black")) newtextcolor = black;
-                    else if (s.equals("blue")) newtextcolor = blue;
-                    else if (s.equals("green")) newtextcolor = green;
-                    else if (s.equals("cyan")) newtextcolor = cyan;
-                    else if (s.equals("red")) newtextcolor = red;
-                    else if (s.equals("magenta")) newtextcolor = magenta;
-                    else if (s.equals("brown")) newtextcolor = brown;
-                    else if (s.equals("lightGray")) newtextcolor = lightGray;
-                    else if (s.equals("darkGray")) newtextcolor = darkGray;
-                    else if (s.equals("brightBlue")) newtextcolor = brightBlue;
-                    else if (s.equals("brightGreen")) newtextcolor = brightGreen;
-                    else if (s.equals("brightCyan")) newtextcolor = brightCyan;
-                    else if (s.equals("brightRed")) newtextcolor = brightRed;
-                    else if (s.equals("pink")) newtextcolor = pink;
-                    else if (s.equals("yellow")) newtextcolor = yellow;
-                    else if (s.equals("white")) newtextcolor = white;
-                    else if (Log.on) Log.logJS(this, "invalid color \"" + s + "\"");
-                    if (newtextcolor == b.textcolor) return;
-                    b.textcolor = newtextcolor;
-                    b.dirty();
-                } });
-        
-        specialBoxProperties.put("text", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.text; }
-                public void put(Box b, Object value) {
-                    String t = value == null ? "null" : value.toString();
-                    if (t.equals(b.text)) return;
-
-                    for(int i=0; i<t.length(); i++)
-                        if (Character.isISOControl(t.charAt(i))) {
-                            if (Log.on) Log.log(this, 
-                                                "ISO Control characters are not permitted in box text strings; offending character is ASCII " +
-                                               ((int)t.charAt(i)));
-                            return;
-                        }
-
-                    // FEATURE: try removing the following line; it appears to be redundant
-                    b.dirty();
-                    b.text = t;
-                    b.textupdate();
-                    b.dirty();
-                } });
-        
-        specialBoxProperties.put("thisbox", new SpecialBoxProperty() {
-                public Object get(Box b) { return b; }
-                public void put(Box b, Object value) {
-                    if (value == null) b.remove();
-                    else if (value.equals("window") || value.equals("frame")) {
-                        if (b.redirect != b && Log.on)
-                            Log.log(this, "WARNING: you have created a surface whose root box's redirect is not itself " +
-                                    "-- this isn't usually a good idea");
-                        Platform.createSurface(b, value.equals("frame"), true);
-                    } else if (Log.on) Log.log(this, "put invalid value to 'thisbox' property: " + value);
-                }
-            });
-
-        specialBoxProperties.put("orient", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.redirect == null) return "horizontal";
-                    else if (b.redirect != b) return get(b.redirect);
-                    else if (b.o == 1) return "vertical";
-                    else return "horizontal";
-                }
-                public void put(Box b, Object value) {
-                    if (value == null) return;
-                    if (b.redirect == null) return;
-                    if (b.redirect != b) {
-                        put(b.redirect, value);
-                        return;
-                    }
-                    if (value.equals("vertical")) {
-                        if (b.o == 1) return;
-                        b.o = 1;
-                        b.xo = 0;
-                    } else if (value.equals("horizontal")) {
-                        if (b.o == 0) return;
-                        b.o = 0;
-                        b.xo = 1;
-                    } else if (Log.on)
-                        Log.log(this, "invalid value put to orient property: " + value);
-                    b.mark_for_prerender();
-                    b.sync_cmin_to_children();
-                } });
-
-        specialBoxProperties.put("static", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    String cfsn = JS.Thread.fromJavaThread(Thread.currentThread()).getCurrentCompiledFunction().getSourceName();
-                    for(int i=0; i<cfsn.length() - 1; i++)
-                        if (cfsn.charAt(i) == '.' && (cfsn.charAt(i+1) == '_' || Character.isDigit(cfsn.charAt(i+1)))) {
-                            cfsn = cfsn.substring(0, i);
-                            break;
-                        }
-                    return Static.getStatic(cfsn);
-                }
-                public void put(Box b, Object value) { }
-            });
-
-        specialBoxProperties.put("sizetoimage", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.sizetoimage ? Boolean.TRUE : Boolean.FALSE; }
-                public void put(Box b, Object value) {
-                    if (stob(value)) {
-                        if (b.sizetoimage) return;
-                        b.sizetoimage = true;
-                        b.syncSizeToImage();
-                    } else {
-                        b.sizetoimage = false;
-                    }
-                } });
-        
-        specialBoxProperties.put("fixedaspect", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.sizetoimage ? Boolean.TRUE : Boolean.FALSE; }
-                public void put(Box b, Object value) {
-                    boolean newval = stob(value);
-                    if (newval == b.fixedaspect) return;
-                    b.fixedaspect = newval;
-                    b.dirty();
-                } });
-        
-        specialBoxProperties.put("shrink", new SpecialBoxProperty() {
-                public Object get(Box b) { return (b.vshrink && b.hshrink) ? Boolean.TRUE : Boolean.FALSE; }
-                public void put(Box b, Object value) {
-                    boolean newshrink = stob(value);
-                    if (b.hshrink == newshrink && b.vshrink == newshrink) return;
-                    b.hshrink = b.vshrink = newshrink;
-                    b.mark_for_prerender();
-                } });
-        
-        specialBoxProperties.put("hshrink", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Boolean(b.hshrink); }
-                public void put(Box b, Object value) {
-                    boolean newshrink = stob(value);
-                    if (b.hshrink == newshrink) return;
-                    b.hshrink = newshrink;
-                    b.mark_for_prerender();
-                }
-            });
-        
-        specialBoxProperties.put("vshrink", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.vshrink ? Boolean.TRUE : Boolean.FALSE; }
-                public void put(Box b, Object value) {
-                    boolean newshrink = stob(value);
-                    if (b.vshrink == newshrink) return;
-                    b.vshrink = newshrink;
-                    b.mark_for_prerender();
-                }
-            });
-        
-        specialBoxProperties.put("x", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.surface == null) return new Integer(0);
-                    if (b.invisible) return new Integer(0);
-                    return new Integer(b.abs(0));
-                }
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && b.surface != null) {
-                        b.surface.setLocation(stoi(value), b.abs(1));
-                        b.surface.centerSurfaceOnRender = false;
-                    }
-                    b.set(abs, 0, stoi(value));
-                }
-            });
-        
-        specialBoxProperties.put("y", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.surface == null) return new Integer(0);
-                    if (b.invisible) return new Integer(0);
-                    return new Integer(b.abs(1));
-                }
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && b.surface != null) {
-                        b.surface.setLocation(b.abs(0), stoi(value));
-                        b.surface.centerSurfaceOnRender = false;
-                    }
-                    b.set(abs, 1, stoi(value));
-                }
-            });
-
-        specialBoxProperties.put("width", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.size(0)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    if (b.getParent() == null && b.surface != null) {
-                        b.set(size, 0, Box.max(Surface.scarPicture.getWidth(), stoi(value)));
-                        b.mark_for_prerender();
-                    } else {
-                        b.set(dmax, 0, stoi(value));
-                        b.set(dmin, 0, stoi(value));
-                    }
-                } });
-        
-        specialBoxProperties.put("height", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.size(1)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    if (b.getParent() == null && b.surface != null) {
-                        b.set(size, 1, Box.max(Surface.scarPicture.getHeight(), stoi(value)));
-                        b.mark_for_prerender();
-                    } else {
-                        b.set(dmax, 1, stoi(value));
-                        b.set(dmin, 1, stoi(value));
-                    }
-                } });
-
-        specialBoxProperties.put("flex", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Double(b.flex); }
-                public void put(Box b, Object value) {
-                    if (value == null) return;
-                    int newflex = stoi(value);
-                    if (newflex == b.flex) return;
-                    b.flex = newflex;
-                    b.mark_for_prerender();
-                } });
-        
-        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;
-                    b.dirty();
-                } });
-        
-        specialBoxProperties.put("align", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.align == -1) return "topleft";
-                    else if (b.align == 1) return "bottomright";
-                    else return "center";
-                }
-                public void put(Box b, Object value) {
-                    String s = value == null ? "" : value.toString();
-                    byte newalign = b.align;
-                    if (s.equals("topleft")) newalign = -1;
-                    else if (s.equals("bottomright")) newalign = 1;
-                    else if (s.equals("center")) newalign = 0;
-                    else if (Log.on) Log.log(this, "invalid value put to align property: " + value);
-                    if (newalign == b.align) return;
-                    b.align = newalign;
-                    if (b.getParent() != null) b.getParent().mark_for_prerender();
-                } });
-        
-        specialBoxProperties.put("invisible", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    for (Box cur = b; cur != null; cur = cur.getParent()) { if (cur.invisible) return Boolean.TRUE; }
-                    return Boolean.FALSE;
-                }
-                public void put(Box b, Object value) {
-                    boolean newinvisible = stob(value);
-                    if (newinvisible == b.invisible) return;
-                    b.invisible = newinvisible;
-                    if (b.getParent() == null) {
-                        if (b.surface != null) b.surface.setInvisible(newinvisible);
-                    } else {
-                        b.dirty();
-                        b.getParent().mark_for_prerender();
-                        b.getParent().sync_cmin_to_children();
-                        b.getParent().dirty(b.pos(0), b.pos(1), b.size(0), b.size(1));
-                        b.getParent().dirty(b.oldpos(0), b.oldpos(1), b.oldsize(0), b.oldsize(1));
-                    }
-                }});
-        
-        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 (b.getParent() != null) {
-                        b.getParent().mark_for_prerender();
-                        b.getParent().sync_cmin_to_children();
-                    }
-                } });
-        
-        specialBoxProperties.put("image", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.image == null ? null : Box.imageToNameMap.get(b.image); }
-                public void put(Box b, Object value) { b.setImage(value == null ? null : value.toString()); }
-            });
-
-        specialBoxProperties.put("border", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.border == null ? null : Box.imageToNameMap.get(b.border); }
-                public void put(Box b, Object value) { b.setBorder(value == null ? null : value.toString()); }
-            });
-
-        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();
-                    b.dirty();
-                } });
-        
-        specialBoxProperties.put("globalx", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.getParent() == null || b.surface == null ? 0 : b.pos(0)); }
-                public void put(Box b, Object value) {
-                    if (b.surface == null || b.getParent() == null) return;
-                    b.put("x", new Integer(stoi(value) - stoi(get(b.getParent()))));
-                }
-            });
-        
-        specialBoxProperties.put("globaly", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.getParent() == null || b.surface == null ? 0 : b.pos(1)); }
-                public void put(Box b, Object value) {
-                    if (b.surface == null || b.getParent() == null) return;
-                    b.put("y", new Integer(stoi(value) - stoi(get(b.getParent()))));
-                }
-            });
-        
-        specialBoxProperties.put("cursor", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.cursor; } 
-                public void put(Box b, Object value) {
-                    b.cursor = (String)value;
-                    if (b.surface == null) return;
-
-                    // see if we need to update the surface cursor
-                    String tempcursor = b.surface.cursor;
-                    b.Move(b.surface.mousex, b.surface.mousey, b.surface.mousex, b.surface.mousey);
-                    if (b.surface.cursor != tempcursor) b.surface.syncCursor();
-                } 
-            });
-        
-        specialBoxProperties.put("mousex", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.surface == null ? 0 : b.surface.mousex - b.pos(0)); }
-            });
-        
-        specialBoxProperties.put("mousey", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.surface == null ? 0 : b.surface.mousey - b.pos(1)); }
-            });
-        
-        specialBoxProperties.put("xwt", new SpecialBoxProperty() {
-                public Object get(Box b) { return XWT.singleton; }
-            });
-        
-        specialBoxProperties.put("mouseinside", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.mouseinside ? Boolean.TRUE : Boolean.FALSE; }
-            });
-        
-        specialBoxProperties.put("numchildren", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.redirect == null) return new Integer(0);
-                    if (b.redirect != b) return get(b.redirect);
-                    return new Integer(b.numChildren());
-                } });
-        
-        SpecialBoxProperty mouseEventHandler = new SpecialBoxProperty() {
-                public void put(String name, Box b, Object value) {
-                    if (b.surface == null) return;
-                    for(Box c = b.prevSibling(); c != null; c = c.prevSibling()) {
-                        Box siblingChild = c.whoIs(c.surface.mousex, c.surface.mousey);
-                        if (siblingChild != null) {
-                            siblingChild.put(name, value);
-                            return;
-                        }
-                    }
-                    if (b.getParent() != null)
-                        b.getParent().put(name, value);
-                }};
-
-        specialBoxProperties.put("Press1", mouseEventHandler);
-        specialBoxProperties.put("Press2", mouseEventHandler);
-        specialBoxProperties.put("Press3", mouseEventHandler);
-        specialBoxProperties.put("Release1", mouseEventHandler);
-        specialBoxProperties.put("Release2", mouseEventHandler);
-        specialBoxProperties.put("Release3", mouseEventHandler);
-        specialBoxProperties.put("Click1", mouseEventHandler);
-        specialBoxProperties.put("Click2", mouseEventHandler);
-        specialBoxProperties.put("Click3", mouseEventHandler);
-        specialBoxProperties.put("DoubleClick1", mouseEventHandler);
-        specialBoxProperties.put("DoubleClick2", mouseEventHandler);
-        specialBoxProperties.put("DoubleClick3", mouseEventHandler);
-
-        specialBoxProperties.put("root", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.surface == null) return null;
-                    else if (b.getRoot() == null) return null;
-                    else if (b.getParent() == null) return b;
-                    else return b.getRoot().getRootProxy();
-                } });
-
-        specialBoxProperties.put("Minimized", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.getParent() == null && b.surface != null) return b.surface.minimized ? Boolean.TRUE : Boolean.FALSE;
-                    else return null;
-                }
-                public void put(Box b, Object value) {
-                    if (b.surface == null) return;
-                    boolean val = stob(value);
-                    if (b.getParent() == null && b.surface.minimized != val) b.surface.setMinimized(val);
-                }
-            });
-
-        specialBoxProperties.put("Maximized", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.getParent() == null && b.surface != null) return b.surface.maximized ? Boolean.TRUE : Boolean.FALSE;
-                    else return null;
-                }
-                public void put(Box b, Object value) {
-                    if (b.surface == null) return;
-                    boolean val = stob(value);
-                    if (b.getParent() == null && b.surface.maximized != val) b.surface.setMaximized(val);
-                }
-            });
-
-        specialBoxProperties.put("toback", new SpecialBoxProperty() {
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && stob(value) && b.surface != null) b.surface.toBack();
-                }
-            });
-
-        specialBoxProperties.put("tofront", new SpecialBoxProperty() {
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && stob(value) && b.surface != null) b.surface.toFront();
-                }
-            });
-
-        specialBoxProperties.put("hscar", new SpecialBoxProperty() {
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && b.surface != null) {
-                        b.surface.hscar = stoi(value);
-                        b.surface.dirty(0, 0, b.surface.width, b.surface.height);
-                        b.surface.Refresh();
-                    }
-                }
-            });
-
-        specialBoxProperties.put("vscar", new SpecialBoxProperty() {
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && b.surface != null) {
-                        b.surface.vscar = stoi(value);
-                        b.surface.dirty(0, 0, b.surface.width, b.surface.height);
-                        b.surface.Refresh();
-                    }
-                }
-            });
-
-        specialBoxProperties.put("Close", new SpecialBoxProperty() {
-                public void put(Box b, Object value) {
-                    if (b.getParent() == null && b.surface != null) b.surface.dispose(true);
-                }
-            });
-
-        // these are all do-nothings; just to prevent space from getting taken up in the params Hash.
-        specialBoxProperties.put("KeyPressed", new SpecialBoxProperty());
-        specialBoxProperties.put("KeyReleased", new SpecialBoxProperty());
-        specialBoxProperties.put("PosChange", new SpecialBoxProperty());
-        specialBoxProperties.put("SizeChange", new SpecialBoxProperty());
-
-        specialBoxProperties.put("hpad", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.redirect == null) return new Integer(0);
-                    if (b.redirect != b) return get(b.redirect);
-                    return new Integer(b.pad(0));
-                }
-                public void put(Box b, Object value) {
-                    if (b.redirect == null) return;
-                    if (b.redirect != b) { put(b.redirect, value); return; }
-                    int newval = stoi(value);
-                    if (newval == b.pad(0)) return;
-                    b.set(pad, 0, newval);
-                }
-            });
-
-        specialBoxProperties.put("vpad", new SpecialBoxProperty() {
-                public Object get(Box b) {
-                    if (b.redirect == null) return new Integer(0);
-                    if (b.redirect != b) return get(b.redirect);
-                    return new Integer(b.pad(1));
-                }
-                public void put(Box b, Object value) {
-                    if (b.redirect == null) return;
-                    if (b.redirect != b) { put(b.redirect, value); return; }
-                    int newval = stoi(value);
-                    if (newval == b.pad(1)) return;
-                    b.set(pad, 1, newval);
-                }
-            });
-
-        specialBoxProperties.put("indexof", new SpecialBoxProperty() {
-                public Object get(Box b) { return b.indexof(); }
-            });
-
-        specialBoxProperties.put("minwidth", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.dmin(0)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    b.set(dmin, 0, stoi(value));
-                }
-            });
-
-        specialBoxProperties.put("maxwidth", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.dmax(0)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    b.set(dmax, 0, stoi(value));
-                }
-            });
-
-        specialBoxProperties.put("minheight", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.dmin(1)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    b.set(dmin, 1, stoi(value));
-                }
-            });
-
-        specialBoxProperties.put("maxheight", new SpecialBoxProperty() {
-                public Object get(Box b) { return new Integer(b.dmax(1)); }
-                public void put(Box b, Object value) {
-                    if (b.sizetoimage) return;
-                    b.set(dmax, 1, stoi(value));
-                }
-            });
-
-        specialBoxProperties.put("redirect", new SpecialBoxProperty() {
-                public void put(Box b, Object value) { }
-                public Object get(Box b) {
-                    if (b.redirect == null) return null;
-                    if (b.redirect == b) return Boolean.TRUE;
-                    return get(b.redirect);
-                }
-            });
-
-        specialBoxProperties.put("apply", new SpecialBoxProperty() {
-                public void put(Box b, Object value) { }
-                public Object get(final Box b) { return new Apply(b); }
-            });
-        
-        specialBoxProperties.put("id", new SpecialBoxProperty() {
-                public void put(Box b, Object value) { }
-                public Object get(Box b) { return b.id; }
-            });
-    }
-
-        
-    /** 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; }
-    }
-        
-    private static class Apply extends JS.Callable {
-        Box b;
-        public Apply(Box b) { this.b = b; }
-        public Object call(JS.Array args) throws JS.Exn {
-            if (args.elementAt(0) instanceof String) {
-                String templatename = (String)args.elementAt(0);
-                Template t = Template.getTemplate(templatename, null);
-                if (t == null) {
-                    if (Log.on) Log.logJS(this, "template " + templatename + " not found");
-                } else {
-                    if (ThreadMessage.suspendThread()) try {
-                        JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
-                        t.apply(b, null, null, callback, 0, t.numUnits());
-                    } finally {
-                        ThreadMessage.resumeThread();
-                    }
-                }
-                
-            } else if (args.elementAt(0) instanceof JS && !(args.elementAt(0) instanceof Box)) {
-                JS s = (JS)args.elementAt(0);
-                Object[] keys = s.keys();
-                for(int j=0; j<keys.length; j++) b.put(keys[j].toString(), s.get(keys[j]));
-            }
-            
-            return b;
-        }
-    }
-}
-
-        
-
index 962a426..28e4819 100644 (file)
@@ -151,10 +151,10 @@ public abstract class Surface {
         else if (button == 2) button2 = true;
         else if (button == 3) button3 = true;
 
-        if (button == 1) new SimpleMessage("Press1", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, root.whoIs(mousex, mousey));
+        if (button == 1) new SimpleMessage("Press1", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
         else if (button == 3) {
-            final Box who = root.whoIs(mousex, mousey);
+            final Box who = Box.whoIs(root, mousex, mousey);
             MessageQueue.add(new Message() { public void perform() {
                 Platform.clipboardReadEnabled = true;
                 root.put("Press3", Boolean.TRUE);
@@ -168,9 +168,9 @@ public abstract class Surface {
         else if (button == 2) button2 = false;
         else if (button == 3) button3 = false;
 
-        if (button == 1) new SimpleMessage("Release1", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 2) new SimpleMessage("Release2", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 3) new SimpleMessage("Release3", Boolean.TRUE, root.whoIs(mousex, mousey));
+        if (button == 1) new SimpleMessage("Release1", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 2) new SimpleMessage("Release2", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 3) new SimpleMessage("Release3", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
 
         if (Platform.needsAutoClick() && Math.abs(last_press_x - mousex) < 5 && Math.abs(last_press_y - mousey) < 5) Click(button);
         last_press_x = Integer.MAX_VALUE;
@@ -178,9 +178,9 @@ public abstract class Surface {
     }
 
     protected final void Click(int button) {
-        if (button == 1) new SimpleMessage("Click1", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 2) new SimpleMessage("Click2", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 3) new SimpleMessage("Click3", Boolean.TRUE, root.whoIs(mousex, mousey));
+        if (button == 1) new SimpleMessage("Click1", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 2) new SimpleMessage("Click2", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 3) new SimpleMessage("Click3", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
         if (Platform.needsAutoDoubleClick()) {
             long now = System.currentTimeMillis();
             if (lastClickButton == button && now - lastClickTime < 350) DoubleClick(button);
@@ -190,9 +190,9 @@ public abstract class Surface {
     }
 
     protected final void DoubleClick(int button) {
-        if (button == 1) new SimpleMessage("DoubleClick1", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 2) new SimpleMessage("DoubleClick2", Boolean.TRUE, root.whoIs(mousex, mousey));
-        else if (button == 3) new SimpleMessage("DoubleClick3", Boolean.TRUE, root.whoIs(mousex, mousey));
+        if (button == 1) new SimpleMessage("DoubleClick1", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 2) new SimpleMessage("DoubleClick2", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
+        else if (button == 3) new SimpleMessage("DoubleClick3", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
     }
 
     /** sends a KeyPressed message; subclasses should not add the C- or A- prefixes, nor should they capitalize alphabet characters */
@@ -266,7 +266,7 @@ public abstract class Surface {
                 cursor = "default";
 
                 // Root gets motion events outside itself (if trapped, of course)
-                if (root.is_trapped("Move") && !root.inside(oldmousex, oldmousey) && !root.inside(mousex, mousey) && (button1 || button2 || button3))
+                if (!root.inside(oldmousex, oldmousey) && !root.inside(mousex, mousey) && (button1 || button2 || button3))
                     root.put("Move", Boolean.TRUE);
 
                 root.Move(oldmousex, oldmousey, mousex, mousey);
@@ -286,8 +286,8 @@ public abstract class Surface {
     }
 
     protected final void PosChange(int x, int y) {
-        root.set(Box.abs, 0, x);
-        root.set(Box.abs, 1, y);
+        if (x != root.x) root.put("x", new Integer(x));
+        if (y != root.y) root.put("y", new Integer(y));
         new SimpleMessage("PosChange", Boolean.TRUE, root);
     }
 
@@ -361,7 +361,7 @@ public abstract class Surface {
             width = Math.max(width, scarPicture.getWidth());
             height = Math.max(height, scarPicture.getHeight());
             dirty(hscar,
-                  root.size(1) - vscar - scarPicture.getHeight(),
+                  root.height - vscar - scarPicture.getHeight(),
                   scarPicture.getWidth(), scarPicture.getHeight());
         }
         setSize(width, height);
@@ -401,18 +401,17 @@ public abstract class Surface {
         } else {
             root.remove();
         }
-        root.setSurface(this);
+        root.surface = this;
 
         // make sure the root is properly sized
-        while (root.needs_prerender || abort) {
-            abort = false;
-            root.prerender();
-        }
+        do {
+            Box.abort = false;
+            root.reflow();
+        } while(Box.abort);
 
         // this is a bit dangerous since we're passing ourselves to another method before subclasses' ctors have run...        
         backbuffer = Platform.createDoubleBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
 
-        root.mark_for_prerender();
         root.dirty();
         Refresh();
     }
@@ -421,39 +420,39 @@ public abstract class Surface {
     public synchronized void render() {
 
         // if the window size changed as a result of a user action, we have to update the root box's size
-        if (root.size(0) != width || root.size(1) != height) {
+        if (root.width != width || root.width != height) {
 
             // since the scar will be moving, dirty the place it used to be
             if (scarred) dirty(hscar,
-                               root.size(1) - vscar - scarPicture.getHeight(),
+                               root.height - vscar - scarPicture.getHeight(),
                                scarPicture.getWidth(), scarPicture.getHeight());
 
             // sort of ugly; we can't use set() here because it will cause an infinite mutual recursion
-            root._size_0 = (int)width;
-            root._size_1 = (int)height;
+            root.width = (int)width;
+            root.height = (int)height;
 
-            root.mark_for_prerender();
+            root.needs_reflow = true;
             root.put("SizeChange", Boolean.TRUE);
         }
 
-        while (root.needs_prerender || abort) {
-            abort = false;
-            root.prerender();
-
+        // make sure the root is properly sized
+        do {
+            Box.abort = false;
+            root.reflow();
             // update mouseinside and trigger Enter/Leave as a result of box size/position changes
             String oldcursor = cursor;
             cursor = "default";
             root.Move(mousex, mousey, mousex, mousey);
             if (!cursor.equals(oldcursor)) syncCursor();
-        }
+        } while(Box.abort);
 
         if (centerSurfaceOnRender) {
             centerSurfaceOnRender = false;
             int x = (Platform.getScreenWidth() - width) / 2;
             int y = (Platform.getScreenHeight() - height) / 2;
             setLocation(x, y);
-            root.set(Box.abs, 0, x);
-            root.set(Box.abs, 1, y);
+            root.x = x;
+            root.y = y;
         }
 
         sizePosChangesSinceLastRender = 0;
@@ -530,8 +529,8 @@ public abstract class Surface {
             int h = dirt[i][3];
             if (x < 0) x = 0;
             if (y < 0) y = 0;
-            if (x+w > root.size(0)) w = root.size(0) - x;
-            if (y+h > root.size(1)) h = root.size(1) - y;
+            if (x+w > root.width) w = root.width - x;
+            if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
             // if any part of this region falls within the "bad region", just skip it
index 2f14040..1bf8b2b 100644 (file)
@@ -197,7 +197,9 @@ public class Template {
             }
 
         for (int i=0; children != null && i<children.length; i++) {
-            b.put(Integer.MAX_VALUE, new Box(children[i], pboxes, ptemplates, callback, numerator, denominator));
+            Box newkid = new Box();
+            children[i].apply(newkid, pboxes, ptemplates, callback, numerator, denominator);
+            b.put(Integer.MAX_VALUE, newkid);
             numerator += children[i].numUnits();
         }
 
@@ -269,6 +271,7 @@ public class Template {
 
     /** adds a theme mapping, retemplatizing as needed */
     public static void retheme(JS.Callable callback) {
+        /*
         XWF.flushXWFs();
 
         // clear changed marker and relink
@@ -295,6 +298,7 @@ public class Template {
             } catch (JS.Exn ex) {
                 if (Log.on) Log.log(Template.class, "WARNING: uncaught ecmascript exception: " + ex.getMessage());
             }
+        */
     }
 
     /** template reapplication procedure */
index 7966047..8d78fd1 100644 (file)
@@ -24,7 +24,7 @@ public class Trap {
     static {
         String[] p = new String[] {
             "sizetoimage", "shrink", "hshrink", "vshrink", "x", "y", "width", "height",
-            "flex", "align", "invisible", "absolute", "globalx", "globaly",
+            "flex", "hflex", "vflex", "cols", "rows", "align", "invisible", "absolute", "globalx", "globaly",
             "minwidth", "minheight", "height", "width", "maxwidth", "maxheight", 
             "numchildren", "hpad", "vpad", "doublebuffered", "cursor",
             "mousex", "mousey", "xwt", "static", "mouseinside", "root", "thisbox", "indexof", "svg"
@@ -122,9 +122,13 @@ public class Trap {
 
     private Trap() { allTraps.put(myWeak, dummy); }
 
+    /** the empty object, used for get-traps */
+    public static JS.Array emptyargs = new JS.Array();
+
     /** perform this trap -- arg.length == 0 if this is a get; otherwise it contains a single element to be put */
     public Object perform(JS.Array jsArrayArgs) throws JS.Exn {
         // TrapContext tc = TrapContext.get();
+        if (jsArrayArgs == null) jsArrayArgs = emptyargs;
         TrapArgs args = new TrapArgs(this,jsArrayArgs);
 
         // invoke the trap function
@@ -168,8 +172,10 @@ public class Trap {
             else if (cur.next == null) trapee.traps.remove(name);
             else trapee.traps.put(name, cur.next);
         }
+        /* FIXME
         if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
             trapee.surface.keywatchers.removeElement(trapee);
+        */
         allTraps.remove(myWeak);
     }
     
diff --git a/src/org/xwt/XWF.java b/src/org/xwt/XWF.java
deleted file mode 100644 (file)
index da6f57b..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
-
-import java.io.*;
-import java.util.*;
-import org.xwt.util.*;
-
-/** encapsulates a single XWF font */
-public class XWF {
-
-    /** all instances of XWF */
-    private static Hash xwtfonts = new Hash();
-
-    /** the int array comprising the XWF */
-    int[] data = null;
-
-    /** the width of the XWF's PNG */
-    int w = 0;
-
-    /** the height of the XWF's PNG */
-    int h = 0;
-
-    /** the full resource name of this font */
-    String name = null;
-
-    /** minimum descent of all glyphs */
-    int maxascent = 0;
-
-    /** maximum descent of all glyphs */
-    int maxdescent = 0;
-
-    /** hash containing all Picture instances created, keyed on an Integer object containing the argb color of the font */
-    Hash pictures = new Hash();
-
-    /** each element corresponds to a single glyph; <br>
-     *  metrics[glyphnum][0] == x position of left edge of glyph<br>
-     *  metrics[glyphnum][1] == x position of right edge of glyph<br>
-     *  metrics[glyphnum][2] == y position of top edge of glyph<br>
-     *  metrics[glyphnum][3] == y position of bottom edge of glyph<br>
-     *  metrics[glyphnum][4] == advance amount<br>
-     *  metrics[glyphnum][5] == baseline
-     */
-    int[][] metrics = null;
-
-    /** drop all cached fonts when the theme mapping changes */
-    public static void flushXWFs() { xwtfonts.clear(); }
-
-    /** retrieve an XWF instance, creating it if needed */
-    public static XWF getXWF(String resourcename) {
-        XWF ret = (XWF)xwtfonts.get(resourcename);
-        if (ret != null) return ret;
-
-        String resolved = Resources.resolve(resourcename + ".xwf", null);
-        byte[] bytes = Resources.getResource(resolved);
-        if (bytes != null) {
-            PNG png = PNG.decode(new ByteArrayInputStream(bytes), resourcename);
-            if (png != null) return new XWF(resourcename, png);
-        }
-        return null;
-    }
-
-    public int getMaxAscent() { return maxascent; }
-    public int getMaxDescent() { return maxdescent; }
-
-    /** draws <tt>text</tt> on <tt>buf</tt> in this font, with color <tt>argb</tt> */
-    public void drawString(DoubleBuffer buf, String text, int x, int y, int argb) {
-
-        Integer color = new Integer(argb | 0xFF000000);
-        Picture pg = (Picture)pictures.get(color);
-        if (pg == null) {
-            int[] data2 = new int[data.length];
-            for(int i=0; i<data.length; i++)
-                data2[i] = (data[i] & 0xFF000000) | (argb & 0x00FFFFFF);
-            pg = Platform.createPicture(data2, w, h);
-            pictures.put(color, pg);
-        }
-
-        int left = x;
-        for(int i=0; i<text.length(); i++) {
-            int c = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".indexOf(text.charAt(i));
-            if (c == -1 || metrics[c] == null) {
-        left += metrics[64] != null ? metrics[64][4] : 10;
-        continue;
-        }
-            buf.drawPicture(pg,
-                            left,
-                            y - (metrics[c][5] - metrics[c][2]),
-                            left + metrics[c][1] - metrics[c][0],
-                            y - (metrics[c][5] - metrics[c][2]) + metrics[c][3] - metrics[c][2],
-                            metrics[c][0], metrics[c][2], metrics[c][1], metrics[c][3]);
-            
-            left += metrics[c][4];
-        }
-    }
-
-    /** returns the width of <tt>text</tt> when rendered in this font */
-    public int stringWidth(String text) {
-        int ret = 0;
-        for(int i=0; i<text.length(); i++) {
-            // what a hack...
-            int c = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".indexOf(text.charAt(i));
-            if (c == -1 || metrics[c] == null) { ret += metrics[64][4]; continue; }
-            ret += metrics[c][4];
-        }
-        return ret;
-    }
-
-    private XWF(String name, PNG png) {
-        this.name = name;
-        xwtfonts.put(name, this);
-
-        data = png.getData();
-        w = png.getWidth();
-        h = png.getHeight();
-
-        int x, y, y1;
-        boolean breakout;
-
-        int start_x, start_y, end_x, end_y, advance;
-
-        int[] rows = new int[120];
-
-        int baseline = 0;
-
-        metrics = new int[96][];
-        int numglyphs = 0;
-
-        for(y=0; y<h; y++) {
-
-            // search for the next non-empty row
-            for(breakout = false; y<h && !breakout; y++)
-                for(x = 0; x<w; x++)
-                    if ((data[x + y * w] & 0x00FFFFFF) != 0x00FFFFFF) breakout = true;
-
-            start_y = y - 2;
-
-            // search for the next empty row
-            for(breakout = false; y<h && !breakout; y++)
-                for(x = 0, breakout = true; x<w; x++)
-                    if ((data[x + y * w] & 0x00FFFFFF) != 0x00FFFFFF) breakout = false;
-
-            end_y = y;
-
-            if (start_y == end_y) continue;
-
-            for(x=0; x<w; x++) {
-
-                // search for the next column with a non-grayscale pixel in it
-                for(breakout = false; x<w && !breakout; x++)
-                    for(y1 = start_y; y1<end_y; y1++)
-                        if (Math.abs(((data[x + y1 * w] & 0x00FF0000) >> 16) - ((data[x + y1 * w] & 0x0000FF00) >> 8)) > 10 ||
-                            Math.abs(((data[x + y1 * w] & 0x0000FF00) >> 8) - ((data[x + y1 * w] & 0x000000FF))) > 10) {
-                            breakout = true;
-                            baseline = y1;
-                        }
-                
-                // search for the next column without a non-grayscale pixel in it
-                for(breakout = false; x<w && !breakout; x++)
-                    for(y1 = start_y, breakout = true; y1<end_y; y1++)
-                        if (Math.abs(((data[x + y1 * w] & 0x00FF0000) >> 16) - ((data[x + y1 * w] & 0x0000FF00) >> 8)) > 10 ||
-                            Math.abs(((data[x + y1 * w] & 0x0000FF00) >> 8) - ((data[x + y1 * w] & 0x000000FF))) > 10) {
-                            breakout = false;
-                        }
-
-                x--;
-                start_x = x;
-
-                // search for the next column with a non-grayscale pixel in it
-                for(breakout = false; x<w && !breakout; x++)
-                    for(y1 = start_y; y1<end_y; y1++)
-                        if (Math.abs(((data[x + y1 * w] & 0x00FF0000) >> 16) - ((data[x + y1 * w] & 0x0000FF00) >> 8)) > 10 ||
-                            Math.abs(((data[x + y1 * w] & 0x0000FF00) >> 8) - ((data[x + y1 * w] & 0x000000FF))) > 10) {
-                            breakout = true;
-                            baseline = y1;
-                        }
-                
-                x--;
-                advance = x - start_x;
-
-                // search for the next column without a grayscale pixel in it
-                for(breakout = false; x<w && !breakout; x++)
-                    for(y1 = start_y, breakout = true; y1<end_y; y1++)
-                        if (Math.abs(((data[x + y1 * w] & 0x00FF0000) >> 16) - ((data[x + y1 * w] & 0x0000FF00) >> 8)) > 10 ||
-                            Math.abs(((data[x + y1 * w] & 0x0000FF00) >> 8) - ((data[x + y1 * w] & 0x000000FF))) > 10) {
-                            breakout = false;
-                        }
-
-                x--;
-                end_x = x;
-
-                if (start_x == end_x) break;
-
-                metrics[numglyphs] = new int[6];
-                metrics[numglyphs][0] = start_x;
-                metrics[numglyphs][1] = end_x;
-                metrics[numglyphs][2] = start_y;
-                metrics[numglyphs][3] = end_y;
-                metrics[numglyphs][4] = advance;
-                metrics[numglyphs][5] = baseline;
-                numglyphs++;
-
-                if (numglyphs >= metrics.length) break;
-
-            }
-
-            if (numglyphs >= metrics.length) break;
-        }
-
-        for(int i=0; i<data.length; i++)
-            if (Math.abs(((data[i] & 0x00FF0000) >> 16) - ((data[i] & 0x0000FF00) >> 8)) > 10 ||
-                Math.abs(((data[i] & 0x0000FF00) >> 8) - ((data[i] & 0x000000FF))) > 10)
-                data[i] = 0x00;
-            else
-                data[i] = (0xFF - (data[i] & 0xFF)) << 24;
-
-        for(int i=33; i<=126; i++)
-            if (metrics[i - 33] != null)
-                maxascent = Math.max(maxascent, metrics[i - 33][5] - metrics[i - 33][2]);
-
-        for(int i=33; i<=126; i++)
-            if (metrics[i - 33] != null)
-                maxdescent = Math.max(maxdescent, metrics[i - 33][3] - metrics[i - 33][5]);
-       
-    }
-
-}
index 6055a2d..33950f1 100644 (file)
@@ -130,18 +130,14 @@ public final class XWT extends JS.Obj {
             if (args.elementAt(0) == null || (args.length() == 2 && args.elementAt(1) == null)) return null;
             String font = args.length() == 1 ? Platform.getDefaultFont() : args.elementAt(0).toString();
             String text = args.length() == 1 ? args.elementAt(0).toString() : args.elementAt(1).toString();
-            XWF xwf = XWF.getXWF(font);
-            if (xwf == null) return new Integer(Platform.stringWidth(font, text));
-            else return new Integer(xwf.stringWidth(text));
+            return new Integer(Platform.stringWidth(font, text));
         }});
 
         super.put("textheight", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
             if (args.length() > 1) return null;
             if (args.length() == 1 && args.elementAt(0) == null) return null;
             String font = args.length() == 0 || args.elementAt(0) == null ? Platform.getDefaultFont() : args.elementAt(0).toString();
-            XWF xwf = XWF.getXWF(font);
-            if (xwf == null) return new Integer(Platform.getMaxAscent(font) + Platform.getMaxDescent(font));
-            else return new Integer(xwf.getMaxAscent() + xwf.getMaxDescent());
+            return new Integer(Platform.getMaxAscent(font) + Platform.getMaxDescent(font));
         }});
         
         super.put("newBox", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
@@ -150,8 +146,10 @@ public final class XWT extends JS.Obj {
             for(int i=1; i<args.length(); i++)
                 if (args.elementAt(i) instanceof JS.Callable && callback == null)
                     callback = (JS.Callable)args.elementAt(i);
-            Box ret = new Box(args.length() == 0 || args.elementAt(0) == null ? "box" : args.elementAt(0).toString(),
-                              Template.defaultImportList, callback);
+            Box ret = new Box();
+            if (!(args.length() == 0 || args.elementAt(0) == null))
+                Template.getTemplate(args.elementAt(0).toString(),
+                                     Template.defaultImportList).apply(ret, null, null, callback, 0, 1);
             for(int i=1; i<args.length(); i++)
                 if (args.elementAt(i) instanceof Box)
                     ret.put(ret.numChildren(), (Box)args.elementAt(i));
@@ -166,7 +164,7 @@ public final class XWT extends JS.Obj {
 
         super.put("sleep", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
             if (args != null && (args.length() != 1 || args.elementAt(0) == null)) return null;
-            int i = args == null ? 0 : SpecialBoxProperty.stoi(args.elementAt(0).toString());
+            int i = args == null ? 0 : Box.stoi(args.elementAt(0).toString());
             sleep(i);
             return null;
         }});
@@ -302,8 +300,8 @@ public final class XWT extends JS.Obj {
 
     super.put("prefetchImage", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
         if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;
-        Box.getImage(args.elementAt(0).toString(),
-                     args.length() > 1 && args.elementAt(1) instanceof JS.Callable ? (JS.Callable)args.elementAt(1) : null);
+        ImageDecoder.getImageDecoder(args.elementAt(0).toString(),
+                                     args.length() > 1 && args.elementAt(1) instanceof JS.Callable ? (JS.Callable)args.elementAt(1) : null);
         return null;
     }});
     }
index 5814bbc..aec30f8 100644 (file)
@@ -38,7 +38,7 @@ public abstract class GCJ extends Platform {
     }
 
     /** Converts an InputStream carrying a JPEG image into an ARGB int[] */
-    private static class JPEG implements ImageDecoder {
+    private static class JPEG extends ImageDecoder {
         int[] data;
         byte[] buffer;
         int width, height;
diff --git a/src/org/xwt/util/Preprocessor.java b/src/org/xwt/util/Preprocessor.java
new file mode 100644 (file)
index 0000000..b653c46
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+package org.xwt.util;
+
+import java.util.*;
+import java.io.*;
+
+/**
+ *   A VERY crude, inefficient Java preprocessor
+ *
+ *   //#define FOO bar baz       -- replace all instances of token FOO with "bar baz"
+ *   //#replace foo/bar baz/bop  -- DUPLICATE everything between here and //#end,
+ *                                  replacing foo with bar and baz with bop in the *second* copy
+ *
+ *   Replacements are done on a token basis.  Tokens are defined as a
+ *   sequence of characters which all belong to a single class.  The
+ *   two character classes are:
+ *
+ *     - [a-zA-Z0-9_]
+ *     - all other non-whitespace characters
+ */
+public class Preprocessor {
+
+    static Hashtable replace = new Hashtable();
+    static Hashtable savereplace = replace;
+    static Vector sinceLastRepeat = null;
+
+    public static void main(String[] args) throws IOException {
+        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+        String s = null;
+
+        while((s = br.readLine()) != null) {
+            if (sinceLastRepeat != null) sinceLastRepeat.addElement(s);
+            String trimmed = s.trim();
+            if (trimmed.startsWith("//#define ")) {
+                trimmed = trimmed.substring(10).trim();
+                String key = trimmed.substring(0, trimmed.indexOf(' '));
+                String val = trimmed.substring(trimmed.indexOf(' ')).trim();
+                replace.put(key, val);
+                
+            } else if (trimmed.startsWith("//#repeat ")) {
+                StringTokenizer st = new StringTokenizer(trimmed.substring(9), " ");
+                savereplace = replace;
+                replace = (Hashtable)replace.clone();
+                while (st.hasMoreTokens()) {
+                    String tok = st.nextToken().trim();
+                    String key = tok.substring(0, tok.indexOf('/'));
+                    String val = tok.substring(tok.indexOf('/') + 1);
+                    replace.put(key, val);
+                }
+                sinceLastRepeat = new Vector();
+
+            } else if (trimmed.startsWith("//#end")) {
+                replace = savereplace;
+                System.out.println();
+                for(int i=0; i<sinceLastRepeat.size(); i++) processLine((String)sinceLastRepeat.elementAt(i));
+                sinceLastRepeat = null;
+
+            } else {
+                processLine(s);
+            }
+           
+        }
+
+    }
+
+    static void processLine(String s) throws IOException {
+        for(int i=0; i<s.length(); i++) {
+            char c = s.charAt(i);
+            if (!Character.isLetter(c) && !Character.isDigit(c) && c != '_') {
+                System.out.print(c);
+                continue;
+            }
+            int j;
+            for(j = i; j < s.length(); j++) {
+                c = s.charAt(j);
+                if (!Character.isLetter(c) && !Character.isDigit(c) && c != '_') break;
+            }
+            String tok = s.substring(i, j);
+            String val = (String)replace.get(tok);
+            if (val != null) System.out.print(val);
+            else System.out.print(tok);
+            i = j - 1;
+        }
+        System.out.println();
+    }
+}
+