- if (sizechange) putAndTriggerTrapsAndCatchExceptions(SIZECHANGE, JSU.T);
- }
-
- private float targetColumnSize = (float)0.0;
- private float targetRowSize = (float)0.0;
- private static float[] sizes = new float[65535];
- private static float[] sizes_v = new float[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;
-
- void solve(boolean findMinimum) {
- int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
- //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
- // maxwidth/maxheight cols/rows minwidth/minheight regions/regions_v targetColumnSize/targetRowSize sizes/sizes_v \
- // HSHRINK/VSHRINK
- if (numkids == 0) {
- if (findMinimum) contentwidth = 0;
- else targetColumnSize = 0;
- } else if (cols == 1) {
- if (findMinimum) {
- contentwidth = 0;
- for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling())
- contentwidth = max(contentwidth, c.contentwidth);
- } else {
- targetColumnSize = width;
- }
- } else if (cols > 1) do {
-
- // FIXME: cache these?
- // compute regions
- 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;
-
- int target = findMinimum ? 0 : Math.max(width, contentwidth);
- // priority 0: (inviolable) honor minwidths
- // priority 1: sum of columns no greater than parent
- // priority 2: honor maxwidths
- // priority 3: equalize columns
- float targetColumnSize = target == 0 ? 0 : this.targetColumnSize;
- float last_columnsize = 0;
- float last_total = 0;
- float total;
- boolean first = true;
- while(true) {
- total = (float)0.0;
- for(int r=0; r<numregions; r++) total += (sizes[r] = (float)(targetColumnSize * (regions[r+1]-regions[r])));
- int minregion = 0;
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling())
- for(int r=(child.col==0?0:minregion); r<numregions; r++) {
- if (regions[r+1] < child.col) continue;
- if (regions[r] >= min(child.col+child.colspan,cols)) { minregion = r; break; }
- total -= sizes[r];
- int child_maxwidth = child.test(HSHRINK)?child.contentwidth:child.maxwidth;
- if (sizes[r] <= (float)(targetColumnSize*(regions[r+1]-regions[r])))
- if ((child.colspan * targetColumnSize) > (child_maxwidth + (float)0.5))
- sizes[r] = (float)Math.min(sizes[r], (regions[r+1]-regions[r])*(child_maxwidth/child.colspan));
- if ((child.colspan * targetColumnSize) < (child.contentwidth - (float)0.5))
- sizes[r] = (float)Math.max(sizes[r], (regions[r+1]-regions[r])*(child.contentwidth/child.colspan));
- total += sizes[r];
- }
- float save = targetColumnSize;
- if (Math.abs(total - target) <= (float)1.0) break;
- if (!first) {
- if (Math.abs(total - last_total) <= (float)1.0) break;
- } else {
- last_columnsize = ((total - target) / (float)cols) + targetColumnSize;
- }
- if (total < target) targetColumnSize += Math.abs((last_columnsize - targetColumnSize) / (float)1.1);
- else if (total > target) targetColumnSize -= Math.abs((last_columnsize - targetColumnSize) / (float)1.1);
- last_columnsize = save;
- last_total = total;
- first = false;