2003/09/19 05:26:46
[org.ibex.core.git] / src / org / xwt / Box.java.pp
index f48835d..4da565a 100644 (file)
@@ -19,7 +19,7 @@ import java.net.*;
 import java.util.*;
 import org.xwt.js.*;
 import org.xwt.util.*;
-import org.xwt.imp.*;
+import org.xwt.translators.*;
 
 /**
  *  <p>
@@ -165,6 +165,7 @@ public final class Box extends JS.Scope {
     /** Adds the intersection of (x,y,w,h) and the node's current actual geometry to the Surface's dirty list */
     public final void dirty() { dirty(0, 0, width, height); }
     public final void dirty(int x, int y, int w, int h) {
+        /*
         for(Box cur = this; cur != null; cur = cur.parent) {
             w = min(x + w, cur.width) - max(x, 0);
             h = min(y + h, cur.height) - max(y, 0);
@@ -175,6 +176,10 @@ public final class Box extends JS.Scope {
             x += cur.x;
             y += cur.y;
         }
+        */
+        Box cur;
+        for(cur = this; cur.parent != null; cur = cur.parent);
+        if (cur.surface != null) cur.surface.dirty(0, 0, cur.width, cur.height);
     }
 
     /**
@@ -352,8 +357,8 @@ public final class Box extends JS.Scope {
         // --- Phase 3 ----------------------------------------------------------------------
         // hand out the slack
         int slack;
-        //#repeat x/y y/x width/height col/row cols/rows colspan/rowspan colWidth/rowHeight maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight numCols/numRows
-        slack = width;
+        //#repeat x/y y/x width/height col/row cols/rows colspan/rowspan colWidth/rowHeight maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight numCols/numRows hpad/vpad
+        slack = width - 2 * hpad;
         for(int i=0; i<numCols; i++) slack -= colWidth[i];
         if (numChildren() > 0)
             while(slack > 0) {  
@@ -435,13 +440,13 @@ public final class Box extends JS.Scope {
             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) {
-        buf.setClip(x, y, w + x, h + y);
+    void renderStretchedImage(int globalx, int globaly, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
+        //buf.setClip(x, y, w + x, h + y);
+        System.out.println("draw " + clipx + " " + clipy + " " + (clipx + clipw) + " " + (clipy + cliph));
         buf.drawPicture(image,
-                        globalx, globaly,
-                        globalx + width, globaly + height,
+                        clipx, clipy, clipx + clipw, clipy + cliph,
                         0, 0, image.getWidth(), image.getHeight());
-        buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
+        //buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
     }
 
     void renderTiledImage(int globalx, int globaly, int x, int y, int w, int h, DoubleBuffer buf) {
@@ -467,8 +472,19 @@ public final class Box extends JS.Scope {
     }
 
     void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
+         /*
+       // hack because (believe it or not) libgcj doesn't support UTF16.
+       byte[] b = new byte[text.length() * 2 + 2];
+       for(int i=0; i<text.length(); i++) {
+           b[i * 2] = (byte)((((short)text.charAt(i)) & 0xff00) >> 8);
+           b[i * 2 + 1] = (byte)(((short)text.charAt(i)) & 0xff);
+       }
+       b[text.length()] = 0;
+       b[text.length() + 1] = 0;
+         */
+            /*
        try {
-           ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, text, false);
+           ImageDecoder id = org.xwt.translators.Font.render(new FileInputStream("COMIC.TTF"), 24, text, false);
            Picture p = Platform.createPicture(id);
             // FIXME: clipping (don't use setClip)
            buf.drawPicture(p,
@@ -479,6 +495,7 @@ public final class Box extends JS.Scope {
        } catch (Exception e) {
            Log.log(this, e);
        }
+            */
     }
 
 
@@ -497,7 +514,17 @@ public final class Box extends JS.Scope {
 
         } else if ("apply".equals(method)) {
             if (checkOnly) return Boolean.TRUE;
-            if (args.elementAt(0) instanceof String) {
+            if (args.elementAt(0) instanceof Res) {
+                Res res = (Res)args.elementAt(0);
+                res = res.addExtension(".xwt");
+                Template t = Template.buildTemplate(res, "fromResource");
+                if (ThreadMessage.suspendThread()) try {
+                    JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
+                    t.apply(this, null, null, callback, 0, t.numUnits());
+                } finally {
+                    ThreadMessage.resumeThread();
+                }
+            } else if (args.elementAt(0) instanceof String) {
                 String templatename = (String)args.elementAt(0);
                 Template t = Template.getTemplate(templatename, null);
                 if (t == null) {
@@ -989,7 +1016,7 @@ public final class Box extends JS.Scope {
                            b.textwidth = b.textheight = 0;
                        } else {
                            try {
-                               ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, b.text, true);
+                               ImageDecoder id = org.xwt.translators.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();
@@ -1182,8 +1209,8 @@ public final class Box extends JS.Scope {
                             if ((b.image = ImageDecoder.getPicture(s)) == null) {
                                 if (Log.on) Log.logJS(Box.class, "unable to load image " + s);
                             } else {
-                                b.minwidth = b.maxwidth = b.image.getWidth();
-                                b.minheight = b.maxheight = b.image.getHeight();
+                                b.minwidth = b.image.getWidth();
+                                b.minheight = b.image.getHeight();
                                 MARK_FOR_REFLOW_b;
                             }
                         }