internal static void DrawRow( Table table, RowSetup rowSetup, List <CellPlaceholder> rowPlaceholder, List <ColumnSetup> columnSetups, bool tableIsColumnPrimary) { var row = new TableRow(); rowSetup.UnderlyingTableRow = row; table.Rows.Add(row); row.CssClass = rowSetup.CssClass; if (rowSetup.ClickScript != null) { rowSetup.ClickScript.SetUpClickableControl(row); } for (var i = 0; i < rowPlaceholder.Count; i++) { if (rowPlaceholder[i] is EwfTableCell) { row.Cells.Add(buildCell(rowPlaceholder[i] as EwfTableCell, rowSetup, columnSetups[i], tableIsColumnPrimary)); } } if ((!rowSetup.ToolTip.IsNullOrWhiteSpace() || rowSetup.ToolTipControl != null) && row.Cells.Count > 0) { // NOTE: This comment is no longer accurate. // It is very important that we add the tool tip to the cell so that the tool tip is hidden if the row is hidden. // We cannot add the tool tip to the row because rows can't have children of that type. new ToolTip(rowSetup.ToolTipControl ?? ToolTip.GetToolTipTextControl(rowSetup.ToolTip), row); } }
private static TableCell buildCell(EwfTableCell ewfCell, RowSetup rowSetup, ColumnSetup columnSetup, bool tableIsColumnPrimary) { var colSpan = tableIsColumnPrimary ? ewfCell.ItemSpan : ewfCell.FieldSpan; var rowSpan = tableIsColumnPrimary ? ewfCell.FieldSpan : ewfCell.ItemSpan; var underlyingCell = (rowSetup.IsHeader || columnSetup.IsHeader) ? new TableHeaderCell() : new TableCell(); underlyingCell.AddControlsReturnThis(ewfCell.Controls); if (colSpan == 1) { underlyingCell.Width = columnSetup.Width; } underlyingCell.CssClass = StringTools.ConcatenateWithDelimiter( " ", EwfTable.CssElementCreator.AllCellAlignmentsClass, columnSetup.CssClassOnAllCells, ewfCell.CssClass); if (ewfCell.ClickScript != null) { ewfCell.ClickScript.SetUpClickableControl(underlyingCell); } if (!ewfCell.ToolTip.IsNullOrWhiteSpace() || ewfCell.ToolTipControl != null || !columnSetup.ToolTipOnCells.IsNullOrWhiteSpace()) { var toolTipControl = ewfCell.ToolTipControl ?? ToolTip.GetToolTipTextControl(!ewfCell.ToolTip.IsNullOrWhiteSpace() ? ewfCell.ToolTip : columnSetup.ToolTipOnCells); // NOTE: This comment is no longer accurate. // It is very important that we add the tool tip to the cell so that the tool tip is hidden if the row/cell is hidden. new ToolTip(toolTipControl, underlyingCell); } if (colSpan != 1) { underlyingCell.ColumnSpan = colSpan; } if (rowSpan != 1) { underlyingCell.RowSpan = rowSpan; } return(underlyingCell); }
/// <summary> /// Adds a row to this table. /// </summary> public void AddRow(RowSetup rowSetup, params EwfTableCell[] cells) { // If SetUpColumns was never called, implicitly set up the columns based on this first row. if (columnSetups == null) { columnSetups = cells.Select(c => new ColumnSetup()).ToList(); } rowSetups.Add(rowSetup); if (!rowSetup.IsHeader) { dataRowCount++; } var defaultCsvLine = cells.Select(cell => (cell as CellPlaceholder).SimpleText).ToList(); if (rowSetup.CsvLine == null) { rowSetup.CsvLine = defaultCsvLine; } // Verify that this row has the right number of cells. try { if (cells.Sum(c => c.FieldSpan) + previousRowColumnSpans.Sum(rcSpan => rcSpan.ColumnSpan) != columnSetups.Count) { throw new ApplicationException("Row to be added has the wrong number of cells."); } // Despite that it would make no sense to do this and all latest browsers will draw tables incorrectly when this happens, I cannot find official documentation // saying that it is wrong. NOTE: This check isn't as good as the logic we are going to add to EwfTableItemRemainingData (to ensure that the item has at // least one cell) because it doesn't catch a case like two cells that each have a row span greater than one and together span all columns. if (cells.Any(c => c.ItemSpan > 1 && c.FieldSpan == columnSetups.Count)) { throw new ApplicationException("Cell may not take up all columns and span multiple rows."); } } catch (ApplicationException e) { if (!AppTools.IsDevelopmentInstallation) { TelemetryStatics.ReportError(e); } else { throw; } } foreach (var rowColumnSpanPair in previousRowColumnSpans) { rowColumnSpanPair.RowSpan--; } previousRowColumnSpans = (previousRowColumnSpans.Where(rowSpan => rowSpan.RowSpan > 0) .Concat( cells.Where(c => c.ItemSpan != 1) .Select(rowSpanCell => new RowColumnSpanPair { RowSpan = rowSpanCell.ItemSpan - 1, ColumnSpan = rowSpanCell.FieldSpan }))).ToList(); var cellPlaceHolders = new List <CellPlaceholder>(cells); TableOps.DrawRow(table, rowSetup, cellPlaceHolders, columnSetups, false); }
/// <summary> /// Adds a row of controls to this table. /// </summary> public void AddRow(RowSetup rowSetup, params Control[] controls) { AddRow(rowSetup, controls.Select(c => (EwfTableCell)c).ToArray()); }
/// <summary> /// Adds a text-only row to this table. /// </summary> public void AddTextRow(RowSetup rowSetup, params string[] cellText) { AddRow(rowSetup, cellText.Select(ct => (EwfTableCell)ct).ToArray()); }