// this method is called when we load the table public void AttachCell(TableCell cell) { if (FCell != null) { FCell.CellData = null; FCell.Dispose(); } Text = cell.Text; ColSpan = cell.ColSpan; RowSpan = cell.RowSpan; FObjects = cell.Objects; FStyle = null; FCell = cell; cell.CellData = this; }
/// <summary> /// Attaches the specified table cell. /// </summary> /// <param name="cell">The table cell instance.</param> /// <remarks>This method is called when we load the table.</remarks> public void AttachCell(TableCell cell) { if (this.cell != null) { this.cell.CellData = null; this.cell.Dispose(); } Text = cell.Text; ColSpan = cell.ColSpan; RowSpan = cell.RowSpan; objects = cell.Objects; style = null; this.cell = cell; cell.CellData = this; }
/// <inheritdoc/> public void AddChild(Base child) { if (child is ReportComponentBase) { if (Objects == null) { objects = new ReportComponentCollection(this); if (CellData != null) { CellData.Objects = objects; } } Objects.Add(child as ReportComponentBase); } }
/// <summary> /// Assigns another <see cref="TableCellData"/> instance at run time. /// </summary> /// <param name="cell">The table cell data that used as a source.</param> /// <param name="copyChildren">This flag shows should children be copied or not.</param> /// <remarks>This method is called when we print a table. We should create a copy of the cell and set the style.</remarks> public void RunTimeAssign(TableCell cell, bool copyChildren) { Text = cell.Text; Value = cell.Value; HyperlinkValue = cell.Hyperlink.Value; // don't copy ColSpan, RowSpan - they will be handled in the TableHelper. //ColSpan = cell.ColSpan; //RowSpan = cell.RowSpan; // clone objects objects = null; if (cell.Objects != null && copyChildren) { objects = new ReportComponentCollection(); foreach (ReportComponentBase obj in cell.Objects) { if (obj.Visible) { ReportComponentBase cloneObj = Activator.CreateInstance(obj.GetType()) as ReportComponentBase; cloneObj.AssignAll(obj); cloneObj.Name = obj.Name; objects.Add(cloneObj); } } } // add the cell to the style list. If the list contains such style, // return the existing style; in other case, create new style based // on the given cell. SetStyle(cell); // FCell is used to reference the original cell. It is necessary to use Alias, OriginalComponent this.cell = cell; // reset object's location as if we set ColSpan and RowSpan to 1. // It is nesessary when printing spanned cells because the span of such cells will be corrected // when print new rows/columns and thus will move cell objects. if (objects != null) { UpdateLayout(Width, Height, Width - cell.CellData.Width, Height - cell.CellData.Height); } }
/// <summary> /// Calculates height of the table cell. /// </summary> /// <param name="width">The width of the table cell.</param> /// <returns>The value of the table cell height.</returns> public float CalcHeight(float width) { TableCell cell = Cell; cell.SetReport(Table.Report); cell.Width = width; float cellHeight = cell.CalcHeight(); if (objects != null) { // pasted from BandBase.cs // sort objects by Top ReportComponentCollection sortedObjects = objects.SortByTop(); // calc height of each object float[] heights = new float[sortedObjects.Count]; for (int i = 0; i < sortedObjects.Count; i++) { ReportComponentBase obj = sortedObjects[i]; float height = obj.Height; if (obj.CanGrow || obj.CanShrink) { float height1 = obj.CalcHeight(); if ((obj.CanGrow && height1 > height) || (obj.CanShrink && height1 < height)) { height = height1; } } heights[i] = height; } // calc shift amounts float[] shifts = new float[sortedObjects.Count]; for (int i = 0; i < sortedObjects.Count; i++) { ReportComponentBase parent = sortedObjects[i]; float shift = heights[i] - parent.Height; if (shift == 0) { continue; } for (int j = i + 1; j < sortedObjects.Count; j++) { ReportComponentBase child = sortedObjects[j]; if (child.ShiftMode == ShiftMode.Never) { continue; } if (child.Top >= parent.Bottom - 1e-4) { if (child.ShiftMode == ShiftMode.WhenOverlapped && (child.Left > parent.Right - 1e-4 || parent.Left > child.Right - 1e-4)) { continue; } float parentShift = shifts[i]; float childShift = shifts[j]; if (shift > 0) { childShift = Math.Max(shift + parentShift, childShift); } else { childShift = Math.Min(shift + parentShift, childShift); } shifts[j] = childShift; } } } // update location and size of each component, calc max height float maxHeight = 0; for (int i = 0; i < sortedObjects.Count; i++) { ReportComponentBase obj = sortedObjects[i]; obj.Height = heights[i]; obj.Top += shifts[i]; if (obj.Bottom > maxHeight) { maxHeight = obj.Bottom; } } if (cellHeight < maxHeight) { cellHeight = maxHeight; } // perform grow to bottom foreach (ReportComponentBase obj in objects) { if (obj.GrowToBottom) { obj.Height = cellHeight - obj.Top; } } // ----------------------- } return(cellHeight); }