From 5518e5d03a513174d17bfa82a177ecceeb116272 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:04:20 +0000 Subject: [PATCH] 2003/08/10 07:40:09 darcs-hash:20040130070420-2ba56-f2fd1c2b44bbc7ed6fd74170fc37c6e74ba24c09.gz --- src/org/xwt/Box.java.pp | 78 ++++++++++++++++++++++++++++----------------- src/org/xwt/Surface.java | 12 +++---- src/org/xwt/plat/AWT.java | 5 ++- 3 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/org/xwt/Box.java.pp b/src/org/xwt/Box.java.pp index 7b9dfef..affcbb0 100644 --- a/src/org/xwt/Box.java.pp +++ b/src/org/xwt/Box.java.pp @@ -39,8 +39,8 @@ import org.xwt.util.*; * *
  • resizing: width/height and x/y positions of children * are assigned. If a PosChange or SizeChange is triggered, - * abort will be set and the resizing process will - * abort. + * Surface.abort will be set and the resizing process will + * Surface.abort. * *
  • repainting: children draw their content onto the * buffer. @@ -49,8 +49,8 @@ import org.xwt.util.*; * The first two passes together are called the reflow phase. * * Reflowing is done in a seperate pass since PosChanges and - * SizeChanges trigger an abort; if rendering were done in the same - * pass, rendering work done prior to the abort would be wasted. + * SizeChanges trigger an Surface.abort; if rendering were done in the same + * pass, rendering work done prior to the Surface.abort would be wasted. * * Repacking is seperate from resizing since a box's size depends on * both the box's parent's size (so the traversal must be preorder) @@ -68,7 +68,6 @@ public final class Box extends JS.Scope { // Misc instance data //////////////////////////////////////////////////////////////// - public static boolean abort = false; private static int sizePosChangesSinceLastRender = 0; @@ -194,7 +193,7 @@ public final class Box extends JS.Scope { void reflow() { repack(); - if (abort) return; + if (Surface.abort) return; resize(x, y, width, height); } @@ -205,12 +204,13 @@ public final class Box extends JS.Scope { // --- Phase 0 ---------------------------------------------------------------------- // recurse for(Box child = getChild(0); child != null; child = child.nextSibling()) { - child.reflow(); - if (abort) { MARK_FOR_REFLOW_this; return; } + child.repack(); + if (Surface.abort) { MARK_FOR_REFLOW_this; return; } } // --- Phase 1 ---------------------------------------------------------------------- // assign children to their row/column positions (assuming constrained columns) + if ((rows == 0 && cols == 0) || (rows != 0 && cols != 0)) throw new Error("rows == " + rows + " cols == " + cols); //#repeat x/y y/x width/height col/row row/col cols/rows colspan/rowspan colWidth/rowHeight numRowsInCol/numColsInRow INNER/INNER2 maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight OUTER/OUTER2 INNER/INNER2 if (rows == 0) { int[] numRowsInCol = new int[cols]; // the number of cells occupied in each column @@ -227,6 +227,7 @@ public final class Box extends JS.Scope { if (col + child.colspan >= cols) break; for(int i=col; i < col + child.colspan; i++) numRowsInCol[i] += child.rowspan; child.col = col; + child.row = row; col += child.colspan; for(child = child.nextSibling(); child != null && (child.absolute || child.invisible); child = child.nextSibling()); } @@ -238,9 +239,10 @@ public final class Box extends JS.Scope { // compute the min/max sizes of the columns and rows and set our contentwidth //#repeat x/y y/x width/height col/row cols/rows colspan/rowspan colWidth/rowHeight maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight contentwidth = 0; - LENGTH[] colWidth = new LENGTH[cols]; + LENGTH[] colWidth = new LENGTH[(cols == 0 ? (getChild(numChildren() - 1).col + 1) : cols)]; for(Box child = getChild(0); child != null; child = child.nextSibling()) - colWidth[child.col] = max(colWidth[child.col], child.contentwidth / child.colspan); + if (!(child.absolute || child.invisible)) + colWidth[child.col] = max(colWidth[child.col], child.contentwidth / child.colspan); for(int col=0; col 0) { - // FEATURE: inefficient - int startslack = slack; - int increment = max(1, slack / cols); - for(int col=0; col < cols && slack > 0; col++) { - slack += colWidth[col]; - colWidth[col] = min(colMaxWidth[col], colWidth[col] + increment); - slack -= colWidth[col]; - } - if (slack == startslack) break; - } + if (numChildren() > 0) + while(slack > 0) { + // FEATURE: inefficient + int startslack = slack; + int increment = max(1, slack / (cols == 0 ? (getChild(numChildren() - 1).col + 1) : cols)); + for(int col=0; col < (cols == 0 ? (getChild(numChildren() - 1).col + 1) : cols) && slack > 0; col++) { + slack += colWidth[col]; + colWidth[col] = min(colMaxWidth[col], colWidth[col] + increment); + slack -= colWidth[col]; + } + if (slack == startslack) break; + } //#end // --- Phase 4 ---------------------------------------------------------------------- // assign children's new sizes and positions and recurse for(Box child = getChild(0); child != null; child = child.nextSibling()) { + if (child.absolute || child.invisible) continue; int diff; - //#repeat x/y y/x width/height col/row cols/rows colspan/rowspan colWidth/rowHeight maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight hshrink/vshrink + //#repeat x/y y/x width/height col/row cols/rows colspan/rowspan colWidth/rowHeight maxwidth/maxheight minwidth/minheight contentwidth/contentheight colMaxWidth/rowMaxHeight hshrink/vshrink marginWidth/marginHeight child.width = 0; for(int i=child.col; i