// FIXME
-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.ibex;
// FEATURE: reflow before allowing js to read from width/height
//#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;
-
- void mark_for_repack() { MARK_REPACK; }
+ //#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;
"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 //////////////////////////////////////////////////////////////////////
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;
/** 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()); }
}
- public Box getRoot() { return parent == null ? this : parent.getRoot(); }
- public Surface getSurface() { return Surface.fromBox(getRoot()); }
-
// FEATURE: use cx2/cy2 format
/** Adds the intersection of (x,y,w,h) and the node's current actual geometry to the Surface's dirty list */
public void dirty() { dirty(0, 0, width, height); }
// Reflow ////////////////////////////////////////////////////////////////////////////////////////
- // static stuff so we don't have to keep reallocating
- private static int[] numRowsInCol = new int[65535];
-
- Box nextPackedSibling() { Box b = nextSibling(); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
- Box firstPackedChild() { Box b = getChild(0); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
-
- /** pack the boxes into rows and columns; also computes contentwidth */
- void repack() {
- for(Box child = getChild(0); child != null; child = child.nextSibling()) child.repack();
-
- //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan
+ 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 (test(FIXED) == COLS) {
- short r = 0;
- for(Box child = firstPackedChild(); child != null; r++) {
- for(short c=0, numclear=0; child != null && c < cols; c++) {
- if (numRowsInCol[c] > r) { numclear = 0; continue; }
- if (c != 0 && c + min(cols, child.colspan) - numclear > cols) break;
- if (++numclear < min(cols, child.colspan)) continue;
- for(int i=c - numclear + 1; i <= c; i++) numRowsInCol[i] += child.rowspan;
- child.col = (short)(c - numclear + 1); child.row = r;
- rows = (short)max(rows, child.row + child.rowspan);
- child = child.nextPackedSibling();
- numclear = 0;
- }
+ 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++; }
+ for(int i=0; i<frontier_size; i++)
+ if (frontier[i].row + frontier[i].rowspan <= child.row) {
+ frontier[i--] = frontier[--frontier_size]; frontier[frontier_size] = null;
+ } else if (frontier[i].col<child.col+min(cols,child.colspan)&&frontier[i].col+frontier[i].colspan>child.col) {
+ child.col = (short)(frontier[i].col + frontier[i].colspan);
+ if (child.col + min(cols,child.colspan) > cols) {
+ child.row = (short)(frontier[i].row + frontier[i].rowspan);
+ for(i--; i>0; i--) child.row = (short)min(row, frontier[i].row + frontier[i].rowspan);
+ child.col = (short)0;
+ }
+ i = -1;
+ } else break;
+ frontier[frontier_size++] = child;
}
- for(int i=0; i<cols; i++) numRowsInCol[i] = 0;
+ for(int i=0; i<frontier_size; i++){ rows=(short)max(rows, frontier[i].row + frontier[i].rowspan); frontier[i] = null; }
}
//#end
-
- //#repeat contentwidth/contentheight colWidth/rowHeight colspan/rowspan col/row cols/rows minwidth/minheight \
- // textwidth/textheight maxwidth/maxheight cols/rows
- contentwidth = 0;
- int[] colWidth = new int[cols];
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling())
- colWidth[child.col] = max(colWidth[child.col], child.contentwidth / child.colspan);
- for(int i=0; i<cols; i++) contentwidth += colWidth[i];
- contentwidth = bound(minwidth, max(font == null || text == null ? 0 : font.textwidth(text), contentwidth), maxwidth);
- //#end
+ solve(true);
+ //#repeat contentwidth/contentheight contentheight/contentwidth minwidth/minheight row/col col/row \
+ // textwidth/textheight maxwidth/maxheight cols/rows rows/cols colspan/rowspan rowspan/colspan
+ contentwidth = bound(minwidth,
+ max(contentwidth, font == null || text == null ? 0 : font.textwidth(text)),
+ maxwidth);
+ //#end
}
void resize(LENGTH x, LENGTH y, LENGTH width, LENGTH height) {
- if (x != this.x || y != this.y || width != this.width || height != this.height) {
- boolean sizechange = (this.width != width || this.height != height) && getTrap("SizeChange") != null;
- boolean poschange = (this.x != x || this.y != y) && getTrap("PosChange") != null;
- //do {
- int thisx = parent == null ? 0 : this.x;
- int thisy = parent == null ? 0 : this.y;
-
- // we can't reenable this until we track
- // surface-relative sizes; imagine the case of a clear
- // surface with nonclear children
-
- /*
- if (texture == null && (text == null || text.equals(""))) {
- if ((fillcolor & 0xff000000) == 0) break;
- // FEATURE: more optimizations here
- if (this.x == x && this.y == y) {
- Box who = (parent == null ? this : parent);
- who.dirty(thisx+min(this.width,width), thisy, Math.abs(width-this.width), max(this.height, height));
- who.dirty(thisx, thisy+min(this.height,height), min(this.width, width), Math.abs(height-this.height));
- break;
- }
+ if (x == this.x && y == this.y && width == this.width && height == this.height) return;
+ boolean sizechange = (this.width != width || this.height != height) && getTrap("SizeChange") != null;
+ try {
+ int thisx = parent == null ? 0 : this.x;
+ int thisy = parent == null ? 0 : this.y;
+ if (this.x != x || this.y != y) set(MOVED);
+ if (texture == null && (text == null || text.equals("")) && !test(MOVED)) {
+ if ((fillcolor & 0xff000000) != 0) {
+ Box who = (parent == null ? this : parent);
+ who.dirty(thisx+min(this.width,width), thisy, Math.abs(width-this.width), max(this.height, height));
+ who.dirty(thisx, thisy+min(this.height,height), min(this.width, width), Math.abs(height-this.height));
}
- */
- (parent == null ? this : parent).dirty(thisx, thisy, this.width, this.height);
- this.width = width; this.height = height; this.x = x; this.y = y;
- dirty();
- //} while (false);
- //this.width = width; this.height = height; this.x = x; this.y = y;
+ //return;
+ }
+ (parent == null ? this : parent).dirty(thisx, thisy, this.width, this.height);
+ this.width = width; this.height = height; this.x = x; this.y = y;
+ dirty();
+ } finally {
+ this.width = width; this.height = height; this.x = x; this.y = y;
if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T);
- if (poschange) putAndTriggerTrapsAndCatchExceptions("PosChange", T);
}
}
private static float[] coeff = null;
- void place_children() {
+ private static Simplex lp_h = new Simplex(65535, 65535, 65535);
+ private static Simplex lp = new Simplex(65535, 65535, 65535);
+
+ private static int[] regions = new int[65535];
+ private static int[] regions_v = new int[65535];
+ private static int numregions = 0;
+ private static int numregions_v = 0;
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
+ // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v \
+ // computeRegions/computeRegions_v
+ private void computeRegions() {
+ numregions = 0;
+ for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) {
+ regions[numregions++] = c.col;
+ regions[numregions++] = min(cols, c.col+c.colspan);
+ }
+ Vec.sortInts(regions, 0, numregions);
+ int j = 0;
+ int newnumregions = numregions;
+ for(int i=1; i<numregions; i++) {
+ if (regions[j] != regions[i]) j++;
+ else newnumregions--;
+ regions[j] = regions[i];
+ }
+ numregions = newnumregions;
+ if (regions[numregions-1] == cols) numregions--;
+ else regions[numregions] = cols;
+ }
+ //#end
+
+ void solve(boolean findMinimum) {
int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
- int nc = numkids * 2 + cols * 3 + 1 + 2;
- if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
- LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex();
- LinearProgramming.Problem lpr_h = new LinearProgramming.Problem(nc, nc);
- LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex();
- LinearProgramming.Problem lpr_v = new LinearProgramming.Problem(nc, nc);
-
- //#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \
- // HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight x_slack/y_slack lp_h/lp_v lpr_h/lpr_v
- do {
- // objective function
- coeff[cols*2+numkids] = coeff[cols*2+numkids+1] = (float)-10000.0; // attempt to make sum of columns equal to parent width
- for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)100.0; // second priority: try to honor maxwidths
- for(int i=cols; i<cols*2; i++) coeff[i] = (float)(-1.0); // third priority: try to make all columns similar size
- lp_h.set_obj_fn(lpr_h, coeff);
- lp_h.set_maxim(lpr_h);
-
- // top priority: try to match the parent's width
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- coeff[cols*2+numkids] = (float)-1.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.LE, (float)width);
-
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- coeff[cols*2+numkids+1] = (float)1.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.GE, (float)width);
-
- // obey minwidth, second priority: try to obey maxwidth (if relevant)
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
+ // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v \
+ // computeRegions/computeRegions_v
+ if (numkids > 0) do {
+ computeRegions();
+ int nc = numregions * 3 + numkids * 2 + 3;
+ if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
+ lp_h.init(nc);
+
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ if (!findMinimum) {
+ coeff[numregions*2+numkids] = (float)10000.0; // priority 1: sum of columns no greater than parent
+ for(int i=numregions*2; i<numregions*2+numkids; i++) coeff[i] = (float)100.0; // priority 2: honor maxwidths
+ for(int i=numregions; i<numregions*2; i++) coeff[i] = (float)(0.1); // priority 3: equalize columns
+ } else {
+ coeff[numregions*2+numkids] = (float)1.0;
+ }
+ lp_h.setObjective(coeff, false);
+
+ // priority 1: sum of columns as close to parent's width as possible
+ for(int i=0; i<coeff.length; i++) coeff[i] = (i<numregions) ? (float)(regions[i+1] - regions[i]) : (float)0.0;
+ coeff[numregions*2+numkids] = (float)-1.0;
+ if (!findMinimum) lp_h.add_constraint(coeff, Simplex.EQ, (float)width);
+ else lp_h.add_constraint(coeff, Simplex.LE, (float)0);
+
int childnum = 0;
for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling()) {
- for(int i=0; i<coeff.length; i++) coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.GE, (float)child.minwidth);
- if (child.maxwidth < Integer.MAX_VALUE) {
- for(int i=0; i<coeff.length; i++)
- coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
- coeff[cols*2+childnum] = (float)1.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.EQ, (float)child.maxwidth);
+
+ // invariant: honor minwidths
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ for(int r=0; r<numregions; r++)
+ if (regions[r] >= child.col && regions[r+1] <= min(child.col+child.colspan,cols))
+ coeff[r] = (float)(regions[r+1] - regions[r]);
+ lp_h.add_constraint(coeff, Simplex.GE, (float)child.contentwidth);
+ if (!findMinimum) {
+ // priority 2: honor maxwidths
+ int child_maxwidth = child.test(HSHRINK) ? min(child.maxwidth, child.contentwidth) : child.maxwidth;
+ if (child_maxwidth < Integer.MAX_VALUE) {
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ for(int r=0; r<numregions; r++)
+ if (regions[r] >= child.col && regions[r+1] <= min(child.col+child.colspan,cols))
+ coeff[r] = (float)(regions[r+1] - regions[r]);
+ coeff[numregions*2+childnum] = (float)-1.0;
+ lp_h.add_constraint(coeff, Simplex.LE, (float)child_maxwidth);
+ }
}
- for(int j=0; j<coeff.length; j++) coeff[j] = (float)0.0;
childnum++;
}
- // third priority: try to make columns similar size
- for(int i=0 ; i<cols; i++) {
- lp_h.set_lowbo(lpr_h, i+1, (float)0.0);
- lp_h.bound_difference(lpr_h, i, cols+i, ((float)width)/((float)cols), LinearProgramming.LE, coeff);
- lp_h.bound_sum( lpr_h, i, cols+i, ((float)width)/((float)cols), LinearProgramming.GE, coeff);
+ if (!findMinimum) {
+ // priority 3: equalize columns
+ float avg = ((float)width)/((float)numregions);
+ for(int r=0; r<numregions; r++) {
+ float weight = (float)(regions[r+1] - regions[r]);
+ for(int k=0; k<coeff.length; k++) coeff[k] = (float)(k==r?weight:k==(numregions+r)?-1.0:0.0);
+ lp_h.add_constraint(coeff, Simplex.LE, avg * weight);
+ for(int k=0; k<coeff.length; k++) coeff[k] = (float)(k==r?weight:k==(numregions+r)?1.0:0.0);
+ lp_h.add_constraint(coeff, Simplex.GE, avg * weight);
+ }
+ }
+
+ try { switch(lp_h.solve()) {
+ case Simplex.UNBOUNDED: Log.warn(this, "simplex claims unboundedness; this should never happen"); break;
+ case Simplex.INFEASIBLE: Log.debug(this, "simplex claims infeasibility; this should never happen"); break;
+ case Simplex.MILP_FAIL: Log.warn(this, "simplex claims MILP_FAIL; this should never happen"); break;
+ case Simplex.RUNNING: Log.warn(this, "simplex still RUNNING; this should never happen"); break;
+ case Simplex.FAILURE: Log.warn(this, "simplex claims FAILURE; this should never happen"); break;
+ } } catch (Error e) {
+ Log.warn(this, "got an Error in simplex solver; not sure why this happens");
+ return;
}
- lp_h.solve(lpr_h);
+ if (findMinimum) contentwidth = Math.round(lp_h.solution[lp_h.rows + (2*numregions + numkids + 1)]);
} while(false);
//#end
-
+ }
+
+ void place() {
+ solve(false);
for(Box child = getChild(0); child != null; child = child.nextSibling()) {
if (!child.test(VISIBLE)) continue;
int child_width, child_height, child_x, child_y;
child_x = child.ax + (child.test(ALIGN_RIGHT) ? gap_x : !child.test(ALIGN_LEFT) ? gap_x / 2 : 0);
child_y = child.ay + (child.test(ALIGN_BOTTOM) ? gap_y : !child.test(ALIGN_TOP) ? gap_y / 2 : 0);
} else {
+ int diff;
//#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight \
// child_x/child_y x/y HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight x_slack/y_slack \
- // colWidth/rowHeight child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP lpr_h/lpr_v
+ // child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP lp_h/lp \
+ // numregions/numregions_v regions/regions_v
child_width = 0;
child_x = 0;
- for(int i=0; i < child.col; i++) child_x += Math.round(lpr_h.solution[lpr_h.rows+i+1]);
- for(int i = child.col; i < child.col + child.colspan; i++) child_width += Math.round(lpr_h.solution[lpr_h.rows+i+1]);
- child_x += (child_width - min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth)) / 2;
- child_width = min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth);
+ if (cols == 1) {
+ child_x = 0;
+ child_width = width;
+ } else {
+ for(int r=0; r<numregions; r++)
+ if (regions[r] >= child.col && regions[r+1] <= min(child.col+child.colspan,cols))
+ child_width += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r]));
+ else if (regions[r+1] <= child.col)
+ child_x += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r]));
+ }
+ diff = (child_width - (child.test(HSHRINK) ? child.contentwidth : min(child_width, child.maxwidth)));
+ child_x += (child.test(ALIGN_RIGHT) ? diff : child.test(ALIGN_LEFT) ? 0 : diff / 2);
+ child_width -= diff;
//#end
}
+ if (test(MOVED)) child.set(MOVED);
child.resize(child_x, child_y, child_width, child_height);
}
+ clear(MOVED);
for(Box child = getChild(0); child != null; child = child.nextSibling())
if (child.test(VISIBLE) && child.treeSize() > 0)
- child.place_children();
+ child.place();
}
int gap_y = height - font.textheight(text);
int text_x = globalx + (test(ALIGN_RIGHT) ? gap_x : !test(ALIGN_LEFT) ? gap_x/2 : 0);
int text_y = globaly + (test(ALIGN_BOTTOM) ? gap_y : !test(ALIGN_TOP) ? gap_y/2 : 0);
- if (font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, null) == -1)
- font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, this);
+ font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2);
}
for(Box b = getChild(0); b != null; b = b.nextSibling())
// Methods to implement org.ibex.js.JS //////////////////////////////////////
- public int globalToLocalX(int x) { return parent == null ? x : parent.globalToLocalX(x - this.x); }
- public int globalToLocalY(int y) { return parent == null ? y : parent.globalToLocalY(y - this.y); }
- public int localToGlobalX(int x) { return parent == null ? x : parent.globalToLocalX(x + this.x); }
- public int localToGlobalY(int y) { return parent == null ? y : parent.globalToLocalY(y + this.y); }
-
+
public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
switch (nargs) {
case 1: {
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
- public Enumeration keys() { throw new Error("you cannot apply for..in to a " + this.getClass().getName()); }
-
protected boolean isTrappable(Object key, boolean isRead) {
if (key == null) return false;
else if (key instanceof String) {
case "hshrink": return B(test(HSHRINK));
case "vshrink": return B(test(VSHRINK));
case "aspect": return N(aspect);
- case "x": return (parent == null || !test(VISIBLE)) ? N(0) : N(x);
- case "y": return (parent == null || !test(VISIBLE)) ? N(0) : N(y);
+ case "x": return (parent == null || !test(VISIBLE)) ? N(0) : test(PACKED) ? N(x) : N(ax);
+ case "y": return (parent == null || !test(VISIBLE)) ? N(0) : test(PACKED) ? N(y) : N(ay);
case "cols": return test(FIXED) == COLS ? N(cols) : N(0);
case "rows": return test(FIXED) == ROWS ? N(rows) : N(0);
case "colspan": return N(colspan);
}
}
- void setMaxWidth(Object value) {
+ 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;
+ if (parent == null && getSurface() != null) getSurface().pendingWidth = maxwidth;
}
- void setMaxHeight(Object value) {
+ public void setMaxHeight(Object value) {
do { CHECKSET_INT(maxheight); MARK_RESIZE; } while(false);
if (parent == null && getSurface() != null) getSurface().pendingHeight = maxheight;
}
case "minheight": CHECKSET_INT(minheight); MARK_RESIZE;
if (parent == null && getSurface() != null)
getSurface().setMinimumSize(minwidth, minheight, minwidth != maxwidth || minheight != maxheight);
- case "colspan": CHECKSET_SHORT(colspan); MARK_REPACK_parent;
- case "rowspan": CHECKSET_SHORT(rowspan); MARK_REPACK_parent;
+ case "colspan": if (toInt(value) <= 0) return; CHECKSET_SHORT(colspan); MARK_REPACK_parent;
+ case "rowspan": if (toInt(value) <= 0) return; CHECKSET_SHORT(rowspan); MARK_REPACK_parent;
case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); MARK_REPACK;
case "cols": CHECKSET_SHORT(cols); if (cols==0){set(FIXED, ROWS);if(rows==0)rows=1;} else set(FIXED, COLS); MARK_REPACK;
case "clip": CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty();
case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = toBoolean(value); // FEATURE
case "Close": if (parent == null && getSurface() != null) getSurface().dispose(true);
case "redirect":
+ if (value == null) { redirect = null; return; }
for(Box cur = (Box)value; cur != null; cur = cur.parent)
if (cur == redirect) {
redirect = (Box)value;
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;
fillcolor = newfillcolor;
} else if(value instanceof JS) {
texture = Picture.load((JS)value, this);
+ if (texture != null && texture.isLoaded) perform();
} else {
throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass());
}
}
if (!obscured && !found)
- if ("_Move".equals(name) || wasinside)
+ if ("_Move".equals(name) || name.startsWith("_Release") || wasinside)
if (name != null)
putAndTriggerTrapsAndCatchExceptions(name.substring(1), value);
}
// Trivial Helper Methods (should be inlined) /////////////////////////////////////////
+ void mark_for_repack() { MARK_REPACK; }
+ public Enumeration keys() { throw new Error("you cannot apply for..in to a " + this.getClass().getName()); }
+ public Box getRoot() { return parent == null ? this : parent.getRoot(); }
+ public Surface getSurface() { return Surface.fromBox(getRoot()); }
+ Box nextPackedSibling() { Box b = nextSibling(); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
+ Box firstPackedChild() { Box b = getChild(0); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
+ public int globalToLocalX(int x) { return parent == null ? x : parent.globalToLocalX(x - this.x); }
+ public int globalToLocalY(int y) { return parent == null ? y : parent.globalToLocalY(y - this.y); }
+ public int localToGlobalX(int x) { return parent == null ? x : parent.globalToLocalX(x + this.x); }
+ public int localToGlobalY(int y) { return parent == null ? y : parent.globalToLocalY(y + this.y); }
+
static short min(short a, short b) { if (a<b) return a; else return b; }
static int min(int a, int b) { if (a<b) return a; else return b; }
static float min(float a, float b) { if (a<b) return a; else return b; }
deleteNode(i);
b.parent = null;
MARK_REFLOW;
- putAndTriggerTrapsAndCatchExceptions("childremoved", b);
+ putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
}
public void put(int i, Object value) throws JSExn {
}
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;
MARK_REFLOW;
b.dirty();
- putAndTriggerTrapsAndCatchExceptions("childadded", b);
+ putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
}
}