X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fibex%2FBox.java;h=9dcb020148e37f162e14ac3d2ef9c407bc927758;hb=31019e2c41b5fab3cac37d0583fd0a2e5bd18adf;hp=49808b332be3806d35af070508477e3653419456;hpb=3e1c990ae2a4476b51aa3474163cbd81b22aed61;p=org.ibex.core.git diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 49808b3..9dcb020 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -54,11 +54,11 @@ public final class Box extends JSScope implements Scheduler.Task { //#define CHECKSET_INT(prop) int nu = toInt(value); if (nu == prop) break; prop = nu; //#define CHECKSET_FLAG(flag) boolean nu = toBoolean(value); if (nu == test(flag)) break; if (nu) set(flag); else clear(flag); //#define CHECKSET_BOOLEAN(prop) boolean nu = toBoolean(value); if (nu == prop) break; prop = nu; - //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&value.equals(prop))) break; prop=(String)value; + //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JS.toString(value).equals(prop))) break; prop=JS.toString(value); protected Box() { super(null); } - static Hash boxToCursor = new Hash(500, 3); + static Hash boxToCursor = new Hash(500, 3); // FIXME memory leak public static final int MAX_LENGTH = Integer.MAX_VALUE; static final Font DEFAULT_FONT; @@ -85,11 +85,9 @@ public final class Box extends JSScope implements Scheduler.Task { "Release1", "Release2", "Release3", "Click1", "Click2", "Click3", "DoubleClick1", "DoubleClick2", "DoubleClick3", - "Enter", "Leave", "Move", - "KeyPressed", "KeyReleased", "PosChange", "SizeChange", - "childadded", "childremoved", - "Focused", "Maximized", "Minimized", "Close", - "icon", "titlebar", "toback", "tofront" + "Enter", "Leave", "Move", "ChildChange", + "KeyPressed", "KeyReleased", "SizeChange", + "Focused", "Maximized", "Minimized", "Close" }; // Flags ////////////////////////////////////////////////////////////////////// @@ -118,13 +116,14 @@ public final class Box extends JSScope implements Scheduler.Task { static final int CURSOR = 0x00010000; // if true, this box has a cursor in the cursor hash; FEATURE: GC issues? static final int CLIP = 0x00020000; static final int STOP_UPWARD_PROPAGATION = 0x00040000; + static final int MOVED = 0x00080000; // Instance Data ////////////////////////////////////////////////////////////////////// Box parent = null; Box redirect = this; - int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */ | STOP_UPWARD_PROPAGATION | CLIP; + int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */ | STOP_UPWARD_PROPAGATION | CLIP | MOVED; private String text = null; private Font font = DEFAULT_FONT; @@ -170,19 +169,9 @@ public final class Box extends JSScope implements Scheduler.Task { /** invoked when a resource needed to render ourselves finishes loading */ public void perform() throws JSExn { - - // FIXME; we can't assume that just because we were performed the image is loaded. - // as external events have occured, check the state of box - if (texture != null) { - if (texture.isLoaded) { minwidth = min(texture.width, maxwidth); minheight = min(texture.height, maxheight); } - else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); } - } else { - Log.warn(Box.class, "perform() called with null texture"); - } - MARK_REPACK; - MARK_REFLOW; - MARK_RESIZE; - dirty(); + if (texture == null) { Log.warn(Box.class, "perform() called with null texture"); return; } + if (texture.isLoaded) { setMinWidth(max(texture.width, maxwidth)); setMinHeight(max(texture.height, maxheight)); } + else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); } } // FEATURE: use cx2/cy2 format @@ -207,20 +196,18 @@ public final class Box extends JSScope implements Scheduler.Task { // Reflow //////////////////////////////////////////////////////////////////////////////////////// - // worst case runtime = O(numboxes * numboxes_in_widest_row) - - private static Box[] frontier = new Box[65535]; // FIXME: GC hazard - - /** pack the boxes into rows and columns; also computes contentwidth */ + private static Box[] frontier = new Box[65535]; + /** pack the boxes into rows and columns, compute contentwidth */ void pack() { for(Box child = getChild(0); child != null; child = child.nextSibling()) child.pack(); int frontier_size = 0; contentwidth = 0; contentheight = 0; //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan \ // contentheight/contentwidth contentwidth/contentheight - if (treeSize() > 0 && test(FIXED) == COLS) { + if (test(FIXED) == COLS) { rows = 0; for(Box child = getChild(0); child != null; child = child.nextSibling()) { if (!child.test(PACKED) || !child.test(VISIBLE)) continue; + if (cols == 1) { child.row = rows; rows += child.rowspan; child.col = 0; continue; } child.col = (short)(frontier_size <= 0 ? 0 : (frontier[frontier_size-1].col + frontier[frontier_size-1].colspan)); child.row = (short)(frontier_size <= 0 ? 0 : frontier[frontier_size-1].row); if (child.col + min(cols,child.colspan) > cols) { child.col = 0; child.row++; } @@ -238,39 +225,37 @@ public final class Box extends JSScope implements Scheduler.Task { } else break; frontier[frontier_size++] = child; } - for(int i=0; i 0) @@ -578,6 +565,14 @@ public final class Box extends JSScope implements Scheduler.Task { } } + public void setMinWidth(int minwidth) { + if (this.minwidth == minwidth) return; + MARK_RESIZE; MARK_REFLOW; MARK_REPACK; this.minwidth = minwidth; + } + public void setMinHeight(int minheight) { + if (this.minheight == minheight) return; + MARK_RESIZE; MARK_REFLOW; MARK_REPACK; this.minheight = minheight; + } public void setMaxWidth(Object value) { do { CHECKSET_INT(maxwidth); MARK_RESIZE; } while(false); if (parent == null && getSurface() != null) getSurface().pendingWidth = maxwidth; @@ -702,10 +697,8 @@ public final class Box extends JSScope implements Scheduler.Task { case "_HScroll": propagateDownward(name, value, false); case "_VScroll": propagateDownward(name, value, false); - case "PosChange": return; case "SizeChange": return; - case "childadded": return; - case "childremoved": return; + case "ChildChange": return; case "Enter": return; case "Leave": return; @@ -823,7 +816,7 @@ public final class Box extends JSScope implements Scheduler.Task { } if (!obscured && !found) - if ("_Move".equals(name) || wasinside) + if ("_Move".equals(name) || name.startsWith("_Release") || wasinside) if (name != null) putAndTriggerTrapsAndCatchExceptions(name.substring(1), value); } @@ -944,7 +937,7 @@ public final class Box extends JSScope implements Scheduler.Task { deleteNode(i); b.parent = null; MARK_REFLOW; - putAndTriggerTrapsAndCatchExceptions("childremoved", b); + putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } public void put(int i, Object value) throws JSExn { @@ -956,22 +949,22 @@ public final class Box extends JSScope implements Scheduler.Task { } if (redirect == null) { - if (value == null) putAndTriggerTrapsAndCatchExceptions("childremoved", getChild(i)); + if (value == null) putAndTriggerTrapsAndCatchExceptions("ChildChange", getChild(i)); else JS.warn("attempt to add/remove children to/from a node with a null redirect"); } else if (redirect != this) { - if (value != null) putAndTriggerTrapsAndCatchExceptions("childadded", value); + if (value != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", value); redirect.put(i, value); if (value == null) { Box b = (Box)redirect.get(new Integer(i)); - if (b != null) putAndTriggerTrapsAndCatchExceptions("childremoved", b); + if (b != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } } else if (value == null) { if (i < 0 || i > treeSize()) return; Box b = getChild(i); removeChild(i); - putAndTriggerTrapsAndCatchExceptions("childremoved", b); + putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } else { Box b = (Box)value; @@ -1000,7 +993,7 @@ public final class Box extends JSScope implements Scheduler.Task { MARK_REFLOW; b.dirty(); - putAndTriggerTrapsAndCatchExceptions("childadded", b); + putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } }