Exemple #1
0
        public override Status Layout(Area area)
        {
            if (this.marker == MarkerBreakAfter)
            {
                return new Status(Status.OK);
            }

            if (this.marker == MarkerStart)
            {
                if (!setup)
                {
                    DoSetup(area);
                }

                if (cellArray == null)
                {
                    InitCellArray();
                    area.getIDReferences().CreateID(id);
                }

                this.marker = 0;
                int breakStatus = propMgr.CheckBreakBefore(area);
                if (breakStatus != Status.OK)
                {
                    return new Status(breakStatus);
                }
            }

            if (marker == 0)
            {
                area.getIDReferences().ConfigureID(id, area);
            }

            int spaceLeft = area.spaceLeft();

            this.areaContainer =
                new AreaContainer(propMgr.GetFontState(area.getFontInfo()), 0, 0,
                                  area.getContentWidth(), spaceLeft,
                                  Position.RELATIVE);
            areaContainer.foCreator = this;
            areaContainer.setPage(area.getPage());
            areaContainer.setParent(area);

            areaContainer.setBackground(propMgr.GetBackgroundProps());
            areaContainer.start();

            areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
            areaContainer.setIDReferences(area.getIDReferences());

            largestCellHeight = minHeight;

            bool someCellDidNotLayoutCompletely = false;

            int offset = 0;
            int iColIndex = 0;

            foreach (TableColumn tcol in columns)
            {
                TableCell cell;
                ++iColIndex;
                int colWidth = tcol.GetColumnWidth();
                if (cellArray.GetCellType(iColIndex) == CellArray.CELLSTART)
                {
                    cell = cellArray.GetCell(iColIndex);
                }
                else
                {
                    if (rowSpanMgr.IsInLastRow(iColIndex))
                    {
                        int h = rowSpanMgr.GetRemainingHeight(iColIndex);
                        if (h > largestCellHeight)
                        {
                            largestCellHeight = h;
                        }
                    }
                    offset += colWidth;
                    continue;
                }
                cell.SetStartOffset(offset);
                offset += colWidth;

                int rowSpan = cell.GetNumRowsSpanned();
                Status status;
                if ((status = cell.Layout(areaContainer)).isIncomplete())
                {
                    if ((keepTogether.GetKeepType() == KeepValue.KEEP_WITH_ALWAYS)
                        || (status.getCode() == Status.AREA_FULL_NONE)
                        || rowSpan > 1)
                    {
                        this.ResetMarker();
                        this.RemoveID(area.getIDReferences());
                        return new Status(Status.AREA_FULL_NONE);
                    }
                    else if (status.getCode() == Status.AREA_FULL_SOME)
                    {
                        someCellDidNotLayoutCompletely = true;
                    }
                }
                int hi = cell.GetHeight();
                if (rowSpan > 1)
                {
                    rowSpanMgr.AddRowSpan(cell, iColIndex,
                                          cell.GetNumColumnsSpanned(), hi,
                                          rowSpan);
                }
                else if (hi > largestCellHeight)
                {
                    largestCellHeight = hi;
                }
            }

            area.setMaxHeight(area.getMaxHeight() - spaceLeft
                + this.areaContainer.getMaxHeight());

            for (int iCol = 1; iCol <= columns.Count; iCol++)
            {
                if (cellArray.GetCellType(iCol) == CellArray.CELLSTART
                    && rowSpanMgr.IsSpanned(iCol) == false)
                {
                    cellArray.GetCell(iCol).SetRowHeight(largestCellHeight);
                }
            }

            rowSpanMgr.FinishRow(largestCellHeight);

            area.addChild(areaContainer);
            areaContainer.SetHeight(largestCellHeight);
            areaAdded = true;
            areaContainer.end();

            area.addDisplaySpace(largestCellHeight
                + areaContainer.getPaddingTop()
                + areaContainer.getBorderTopWidth()
                + areaContainer.getPaddingBottom()
                + areaContainer.getBorderBottomWidth());

            if (someCellDidNotLayoutCompletely)
            {
                return new Status(Status.AREA_FULL_SOME);
            }
            else
            {
                if (rowSpanMgr.HasUnfinishedSpans())
                {
                    return new Status(Status.KEEP_WITH_NEXT);
                }
                if (breakAfter == BreakAfter.PAGE)
                {
                    this.marker = MarkerBreakAfter;
                    return new Status(Status.FORCE_PAGE_BREAK);
                }

                if (breakAfter == BreakAfter.ODD_PAGE)
                {
                    this.marker = MarkerBreakAfter;
                    return new Status(Status.FORCE_PAGE_BREAK_ODD);
                }

                if (breakAfter == BreakAfter.EVEN_PAGE)
                {
                    this.marker = MarkerBreakAfter;
                    return new Status(Status.FORCE_PAGE_BREAK_EVEN);
                }

                if (breakAfter == BreakAfter.COLUMN)
                {
                    this.marker = MarkerBreakAfter;
                    return new Status(Status.FORCE_COLUMN_BREAK);
                }
                if (keepWithNext.GetKeepType() != KeepValue.KEEP_WITH_AUTO)
                {
                    return new Status(Status.KEEP_WITH_NEXT);
                }
                return new Status(Status.OK);
            }

        }