protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // get the table and its cells IHTMLTable sourceTable = GetSourceTable(DataMeister); IHTMLElementCollection cells = (sourceTable as IHTMLElement2).getElementsByTagName("td"); // single-cell tables just get the innerHTML of the cell pasted at the selection if (cells.length == 1) { IHTMLElement cell = cells.item(0, 0) as IHTMLElement; EditorContext.InsertHtml(begin, end, cell.innerHTML, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } else { // if we are inside a table TableSelection tableSelection = new TableSelection(EditorContext.MarkupServices.CreateMarkupRange(begin, end)); if (tableSelection.Table != null) { // paste the source cells into the table PasteCellsIntoTable(sourceTable, tableSelection); } else { // get table html (make sure width matches # of rows selected) TableHelper.SynchronizeTableWidthForEditing(sourceTable); string html = (sourceTable as IHTMLElement).outerHTML; // insert the html (nests within an undo unit) EditorContext.InsertHtml(begin, end, html, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } } return(true); }
/// <summary> /// Method to present to the user the table properties dialog /// Uses all the default properties for the table based on an insert operation /// </summary> private void ProcessTablePrompt(IHTMLTable table) { HtmlTableProperty tableProperties = GetTableProperties(table); var res = Application.Current.Dispatcher.Invoke(() => { var wdw = new TablePropertyWdw(tableProperties); wdw.ShowDialog(); return(wdw); }); if (!res.Confirmed) { return; } tableProperties = res.Value; if (table.IsNull()) { TableInsert(tableProperties); } else { ProcessTable(table, tableProperties); } }
public static PixelPercent GetTableLogicalEditingWidth(IHTMLTable table) { // If percentage, then just keep that var width = GetTableWidth(table); if (width.Units == PixelPercentUnits.Percentage || width.Units == PixelPercentUnits.Undefined) { return(width); } // value to return (default to zero) int logicalWidth = 0; // calculate the "logical" width of the table if (table.rows.length > 0) { // save value of cellSpacing int cellSpacing = GetAttributeAsInteger(table.cellSpacing); // use the first row as a proxy for the width of the table IHTMLTableRow firstRow = table.rows.item(0, 0) as IHTMLTableRow; foreach (IHTMLTableCell cell in firstRow.cells) { logicalWidth += GetCellWidth(cell) + cellSpacing; } // total width + extra cellspacing @ end + size of borders return(logicalWidth + cellSpacing + GetTableBorderEditingOffset(table)); } // return width return(logicalWidth); }
public static IHTMLTableRow AddTableRowsAfterRow( IHTMLTable table, int afterRowIndex, int count) { var columnCount = CountTableColumns(table); IHTMLTableRow lastRow = null; // Add rows. for (var j = 0; j < count; ++j) { var row = (IHTMLTableRow)table.insertRow(afterRowIndex); lastRow = row; // Add columns in the newly added row. while (row.cells.length < columnCount) { var cell = (IHTMLTableCell)row.insertCell(); var element = (IHTMLElement)cell; element.innerHTML = @" "; } } return(lastRow); }
public static IHTMLTableRow AddTableRowsAfterRow( IHTMLTable table, int afterRowIndex, int count) { var columnCount = CountTableColumns(table); IHTMLTableRow lastRow = null; // Add rows. for (var j = 0; j < count; ++j) { var row = (IHTMLTableRow)table.insertRow(afterRowIndex); lastRow = row; // Add columns in the newly added row. while (row.cells.length < columnCount) { var cell = (IHTMLTableCell)row.insertCell(); var element = (IHTMLElement)cell; element.innerHTML = @" "; } } return lastRow; }
/// <summary> /// Gets the IHTMLTable object of the selected table /// </summary> /// <returns>The selected table as IHTMLTable</returns> public IHTMLTable GetSelectedTableElement() { IHTMLTable selectedTable = this.GetSelectedElement().parentElement.parentElement.parentElement as IHTMLTable; return(selectedTable); }
public void InsertTable() { var helper = noteGlue.Editor.TableEditor; IHTMLTable table = helper.GetSelectedTable(); if (table != null) //modify selected table { using (var dialog = new TablePropertyForm()) { dialog.UpdateTable = true; dialog.TableProperties = helper.GetTableProperties(table); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { helper.TableModify(table, dialog.TableProperties); } } } else //insert new table { using (var dialog = new TablePropertyForm()) { if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { helper.TableInsert(dialog.TableProperties); } } } }
public void Initialize( IHTMLTable table, int columnIndex) { Text = Resources.Str_UIHtml_ColumnProperties; var rows = table.rows; if (rows != null) { for (var i = 0; i < rows.length; ++i) { var row = (IHTMLTableRow)rows.item(i, i); var cells = row.cells; if (cells != null) { for (int j = 0; j < cells.length; ++j) { if (j == columnIndex) { _cells.Add(cells.item(j, j) as IHTMLTableCell); break; } } } } } }
/// <summary> /// Deletes a given rowindex in a given table /// zero based /// If the table has no rows after deletion anymore /// we delete it compeletely /// </summary> /// <param name="table"></param> /// <param name="rowindex"></param> public void DeleteRow(IHTMLTable table, int rowindex) { table.deleteRow(rowindex); if (GetRowCount(table) == 0) { RemoveNode(table as IHTMLElement, true); } }
public static IHTMLTable AttachToDocument(this DataTable table) { IHTMLTable table2 = table; table2.AttachToDocument(); return(table2); }
public static IHTMLTableRow AddTableRowsAtBottom( IHTMLTable table, int count) { return(AddTableRowsAfterRow( table, -1, count)); }
public static void AddTableColumnsAtRight( IHTMLTable table, int count) { AddTableColumnsAfterColumn( table, -1, count); }
private void tablePropertiesToolStripMenuItem_Click(object sender, EventArgs e) { try { IHTMLTable selectedElement = builder.GetSelectedTableElement(); Table selectedTable = builder.GetSelectedTable(); TablePropertiesDialog dlgTableProperties = new TablePropertiesDialog(); if (selectedTable.BackgroundColor != null) { dlgTableProperties.TableBackgroundColor = ConvertRgbToColor(selectedTable.BackgroundColor); } if (selectedTable.BorderColor != null) { dlgTableProperties.TableBorderColor = ConvertRgbToColor(selectedTable.BorderColor); } if (selectedTable.BorderSize != null) { dlgTableProperties.TableBorderSize = selectedTable.BorderSize; } if (selectedTable.Width != null) { dlgTableProperties.TableWidth = selectedTable.Width; } if (selectedTable.Height != null) { dlgTableProperties.TableHeight = selectedTable.Height; } if (selectedTable.CellSpacing != null) { dlgTableProperties.TableCellSpacing = selectedTable.CellSpacing; } dlgTableProperties.ShowDialog(); if (dlgTableProperties.DialogResult == DialogResult.OK) { builder.ChangeTableProperty(selectedElement, TableProperties.BackgroundColor, ConvertColorToRgb(dlgTableProperties.TableBackgroundColor)); builder.ChangeTableProperty(selectedElement, TableProperties.BorderColor, ConvertColorToRgb(dlgTableProperties.TableBorderColor)); builder.ChangeTableProperty(selectedElement, TableProperties.BorderSize, dlgTableProperties.TableBorderSize.ToString()); builder.ChangeTableProperty(selectedElement, TableProperties.Height, dlgTableProperties.TableHeight.ToString()); builder.ChangeTableProperty(selectedElement, TableProperties.Width, dlgTableProperties.TableWidth.ToString()); builder.ChangeTableProperty(selectedElement, TableProperties.CellSpacing, dlgTableProperties.TableCellSpacing.ToString()); modifiedDocument = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private static void RemoveDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement) { IHTMLElement element = tableElement as IHTMLElement; tableElement.runtimeStyle.borderWidth = element.style.borderWidth; tableElement.runtimeStyle.borderColor = element.style.borderColor; tableElement.runtimeStyle.borderStyle = element.style.borderStyle; (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = (element.style as IHTMLStyle2).borderCollapse; }
public int GetRowCount(IHTMLTable table) { IHTMLElementCollection rows = table.rows; if (rows != null) { return(rows.length); } return(0); }
/// <summary> /// Method to present to the user the table properties dialog /// Ensure a table is currently selected or insertion point is within a table /// </summary> public void TableModifyPrompt() { // define the Html Table element IHTMLTable table = GetTableElement(); // if a table has been selected then process if (!table.IsNull()) { ProcessTablePrompt(table); } }
static void DualDump(object left, object right) { var t = new IHTMLTable(); var b = t.AddBody(); var r = b.AddRow(); Dump(left, r.AddColumn(), right); Dump(right, r.AddColumn(), left); t.AttachToDocument(); }
public static void SynchronizeCellWidthsForEditing(IHTMLTable table) { // resize the cells in the table to match their actual width foreach (IHTMLTableCell cell in (table as IHTMLElement2).getElementsByTagName("th")) { SynchronizeCellWidthForEditing(cell); } foreach (IHTMLTableCell cell in (table as IHTMLElement2).getElementsByTagName("td")) { SynchronizeCellWidthForEditing(cell); } }
/// <summary> /// Gets the selected table /// </summary> /// <returns>The selected table as Table object</returns> public Table GetSelectedTable() { if (this.GetSelectedElement() != null) { if (this.GetElementType(this.GetSelectedTableElement() as IHTMLElement) != "TABLE") { return(null); } IHTMLTable selectedTable = GetSelectedTableElement(); Table table = new Table(); if (selectedTable != null) { table.BackgroundColor = selectedTable.bgColor; table.BorderColor = selectedTable.borderColor; table.BorderSize = Int32.Parse(selectedTable.border); if (string.IsNullOrEmpty(selectedTable.width)) { table.Width = null; } else { table.Width = Int32.Parse(selectedTable.width); } if (string.IsNullOrEmpty(selectedTable.height)) { table.Height = null; } else { table.Height = Int32.Parse(selectedTable.height); } if (string.IsNullOrEmpty(selectedTable.cellSpacing)) { table.CellSpacing = null; } else { table.CellSpacing = Int32.Parse(selectedTable.cellSpacing); } } return(table); } else { return(null); } }
/// <summary> /// Zero based /// </summary> /// <param name="table"></param> /// <param name="rowindex"></param> /// <returns></returns> public IHTMLTableRow GetRow(IHTMLTable table, int rowindex) { IHTMLElementCollection rows = table.rows; if (rows == null) { return(null); } object obj = rowindex; return(rows.item(obj, obj) as IHTMLTableRow); }
public void Row_DeleteCol(IHTMLTableRow row, int index) { int col = 0; int span = 0; IHTMLTableCell cell = Row_GetCell(row, 0); IHTMLElement elem = null; while (true) { if (cell == null) { return; } span = cell.colSpan; //cell.cellIndex if (span == 1) { if (col == index) { RemoveNode(cell as IHTMLElement, true); if (Row_GetCellCount(row) == 0) { IHTMLTable table = GetParentTable(row as IHTMLElement) as IHTMLTable; if (table != null) { RemoveNode(table as IHTMLElement, true); } break; } } } else if (span > 1)// cell spans about multiple columns { if (index >= col && index < col + span) { cell.colSpan = span - 1; // reduce cellspan break; } } col += span; //Get next sibiling elem = NextSibiling(cell as IHTMLDOMNode); if (elem != null) { cell = elem as IHTMLTableCell; } else { cell = null; } } }
public static void SynchronizeTableWidthForEditing(IHTMLTable table) { int logicalWidth = TableHelper.GetTableLogicalEditingWidth(table); if (logicalWidth > 0) { table.width = logicalWidth; } else { (table as IHTMLElement).removeAttribute("width", 0); } }
private void FillTable(IHTMLTable table) { foreach (var r in table.rows) { IHTMLTableRow row = r as IHTMLTableRow; foreach (var c in row.cells) { IHTMLTableCell cell = c as IHTMLTableCell; IHTMLElement elem = c as IHTMLElement; elem.innerText = "r" + row.rowIndex + "c" + cell.cellIndex; } } }
public static void SynchronizeTableWidthForEditing(IHTMLTable table) { var logicalWidth = TableHelper.GetTableLogicalEditingWidth(table); if (logicalWidth > 0 && logicalWidth.Units != PixelPercentUnits.Undefined) { table.width = logicalWidth.ToString(); } else { (table as IHTMLElement).removeAttribute("width", 0); } }
public static void UpdateDesignTimeBorders(IHTMLTable table) { // update the table's borders UpdateDesignTimeBorders(table, table as IHTMLElement2); // update the contained cell borders foreach (IHTMLTableRow row in table.rows) { foreach (IHTMLTableCell cell in row.cells) { UpdateDesignTimeBorders(table, cell as IHTMLElement2); } } }
/// <summary> /// Method to modify a tables properties /// Ensure a table is currently selected or insertion point is within a table /// </summary> public bool TableModify(HtmlTableProperty tableProperties) { // define the Html Table element IHTMLTable table = GetTableElement(); // if a table has been selected then process if (!table.IsNull()) { LogTo.Debug("Modifying the HTML table."); ProcessTable(table, tableProperties); return(true); } return(false); }
public bool ShowTableContextMenuForElement(IHTMLElement element) { IHTMLTable tableElement = TableHelper.GetContainingTableElement(element); if (tableElement != null) { MarkupRange tableMarkupRange = _editorContext.MarkupServices.CreateMarkupRange(tableElement as IHTMLElement); return(TableHelper.TableElementIsEditable(tableElement as IHTMLElement, tableMarkupRange)); } else { return(false); } }
public void InsertCol(IHTMLTable table, int index) { for (int j = 0; true; j++) { IHTMLTableRow row = GetRow(table, j); if (row == null) { return; } if (Row_InsertCol(row, index) == null) { return; } } }
public static void MakeTableWriterEditableIfRectangular(IHTMLTable table) { try { // no-op for null table if (table == null) { return; } // no-op if we are already unselectable IHTMLElement tableElement = table as IHTMLElement; if (TableElementContainsWriterEditingMark(tableElement)) { return; } // check for rectangular structure int tableColumnCount = -1; foreach (IHTMLTableRow row in table.rows) { int columnCount = row.cells.length; if (tableColumnCount == -1) { // initialize table column count if this is the first pass tableColumnCount = columnCount; } else { // compare this rows column count with the table column // count -- if they are not equal then exit function if (columnCount != tableColumnCount) { return; } } } // if we made it this far then the table is rectangular, so // mark it with our "editable" sentinel tableElement.setAttribute("unselectable", "on", 0); } catch (Exception ex) { Trace.Fail("Unexpected error in MakeTableWriterEditableIfRectangular: " + ex.ToString()); } }
/// <summary> /// Method to return a table defintion based on the user selection /// If table selected (or insertion point within table) returns these values /// </summary> public void GetTableDefinition(out HtmlTableProperty table, out bool tableFound) { // see if a table selected or insertion point inside a table IHTMLTable htmlTable = GetTableElement(); // process according to table being defined if (htmlTable.IsNull()) { table = new HtmlTableProperty(true); tableFound = false; } else { table = GetTableProperties(htmlTable); tableFound = true; } }
private static void AttachDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement) { // attach design time border tableElement.runtimeStyle.borderWidth = "1"; tableElement.runtimeStyle.borderColor = "#BCBCBC"; tableElement.runtimeStyle.borderStyle = "dotted"; // collapse cells if there is no cellspacing if ((table.cellSpacing == null) || table.cellSpacing.ToString() != "0") { (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "separate"; } else { (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "collapse"; } }
public TableColumnSizeEditor(IHTMLTable table, IHtmlEditorComponentContext editorContext, IHTMLPaintSiteRaw paintSite) { Debug.Assert(((IHTMLElement)table).offsetHeight > 0 && ((IHTMLElement)table).offsetWidth > 0, "TableColumnSizeEditor unexpectedly attached to a table with no height and/or width!"); // save references _table = table; _editorContext = editorContext; _paintSite = paintSite; // initialize sizing _sizingOperation = new SizingOperation(_editorContext, _table); // initialize table editing context _tableEditingContext = new TableEditingContext(editorContext); // subscribe to events _editorContext.PreHandleEvent += new OpenLiveWriter.Mshtml.HtmlEditDesignerEventHandler(_editorContext_PreHandleEvent); }
public static void AddTableColumnsAfterColumn( IHTMLTable table, int afterColumnIndex, int count) { // Add columns in each row. for (var i = 0; i < table.rows.length; ++i) { var row = (IHTMLTableRow)table.rows.item(i, i); for (var j = 0; j < count; ++j) { var cell = (IHTMLTableCell)row.insertCell(afterColumnIndex); var element = (IHTMLElement)cell; element.innerHTML = @" "; } } }
public static PixelPercent GetTableWidth(IHTMLTable table) { if (table.width != null) { try { return new PixelPercent(table.width.ToString(), CultureInfo.InvariantCulture); } catch { return new PixelPercent(); } } else { return new PixelPercent(); } }
public static void SynchronizeTableWidthForEditing(IHTMLTable table) { var logicalWidth = TableHelper.GetTableLogicalEditingWidth(table); if (logicalWidth > 0 && logicalWidth.Units != PixelPercentUnits.Undefined) table.width = logicalWidth.ToString(); else (table as IHTMLElement).removeAttribute("width", 0); }
private void PasteCellsIntoTable(IHTMLTable sourceTable, TableSelection tableSelection) { // collect up the top level cells we are pasting ArrayList cellsToPaste = new ArrayList(); foreach (IHTMLTableRow row in sourceTable.rows) foreach (IHTMLElement cell in row.cells) cellsToPaste.Add(cell); // get the list of cells we are pasting into int appendRows = 0; int cellsPerRow = 0; ArrayList targetCells; if (tableSelection.SelectedCells.Count > 1) { targetCells = tableSelection.SelectedCells; } else { targetCells = new ArrayList(); bool accumulatingCells = false; foreach (IHTMLTableRow row in tableSelection.Table.rows) { cellsPerRow = row.cells.length; foreach (IHTMLElement cell in row.cells) { if (!accumulatingCells && HTMLElementHelper.ElementsAreEqual(cell, tableSelection.BeginCell as IHTMLElement)) accumulatingCells = true; if (accumulatingCells) targetCells.Add(cell); } } // if the target cells aren't enough to paste all of the cells, then // calculate the number of rows we need to append to fit all of the // cells being pasted int cellGap = cellsToPaste.Count - targetCells.Count; if (cellGap > 0 && cellsPerRow > 0) { appendRows = cellGap / cellsPerRow + (cellGap % cellsPerRow == 0 ? 0 : 1); } } // perform the paste using (IUndoUnit undoUnit = EditorContext.CreateUndoUnit()) { // append rows if needed if (appendRows > 0) { // see if we can cast our editor context to the one required // by the table editor IHtmlEditorComponentContext editorContext = EditorContext as IHtmlEditorComponentContext; if (editorContext != null) { // markup range based on last target cell IHTMLElement lastCell = targetCells[targetCells.Count - 1] as IHTMLElement; MarkupRange lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(lastCell); for (int i = 0; i < appendRows; i++) { IHTMLTableRow row = TableEditor.InsertRowBelow(editorContext, lastCellRange); foreach (IHTMLElement cell in row.cells) targetCells.Add(cell); lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(row as IHTMLElement); } } else { Debug.Fail("Couldn't cast EditorContext!"); } } // do the paste for (int i = 0; i < cellsToPaste.Count && i < targetCells.Count; i++) { (targetCells[i] as IHTMLElement).innerHTML = (cellsToPaste[i] as IHTMLElement).innerHTML; } undoUnit.Commit(); } }
public void InsertRow(IHTMLTable table, int index, int numberofcells) { IHTMLTableRow row = table.insertRow(index) as IHTMLTableRow; if (row == null) return; CalculateCellWidths(numberofcells); for (int j = 0; j < numberofcells; j++) { if ((j + 1) == numberofcells) Row_InsertCell(row, -1, m_lastcellwidth); else Row_InsertCell(row, -1, m_cellwidth); } }
public int GetRowCount(IHTMLTable table) { IHTMLElementCollection rows = table.rows; if (rows != null) return rows.length; return 0; }
/// <summary> /// Gets the column count of row(rowindex) /// Accounts for colSpan property /// </summary> /// <param name="table"></param> /// <param name="colindex"></param> /// <returns></returns> public int GetColCount(IHTMLTable table, int rowindex) { IHTMLTableRow row = GetRow(table, rowindex); if (row == null) return 0; int counter = 0; int cols = 0; while (true) { IHTMLTableCell cell = Row_GetCell(row, counter); if (cell == null) break; cols += cell.colSpan; counter++; } return cols; }
/// <summary> /// Changes a single property of a table /// </summary> /// <param name="table">The table to modify</param> /// <param name="propertyName">The property to change</param> /// <param name="newValue">The new value of the property</param> public void ChangeTableProperty(IHTMLTable table, TableProperties propertyName, string newValue) { if (table != null) { IHTMLElement tableElement = table as IHTMLElement; switch (propertyName) { case TableProperties.BackgroundColor: tableElement.style.backgroundColor = newValue; break; case TableProperties.BorderColor: tableElement.style.borderColor = newValue; break; case TableProperties.BorderSize: if (newValue != null) { tableElement.style.borderWidth = newValue; } break; case TableProperties.Height: if (newValue != null) { tableElement.style.height = newValue; } break; case TableProperties.Width: if (newValue != null) { tableElement.style.width = newValue; } break; case TableProperties.CellSpacing: if (newValue != null) { table.cellSpacing = newValue; } break; } } }
public static PixelPercent GetTableLogicalEditingWidth(IHTMLTable table) { // If percentage, then just keep that var width = GetTableWidth(table); if (width.Units == PixelPercentUnits.Percentage || width.Units == PixelPercentUnits.Undefined) return width; // value to return (default to zero) int logicalWidth = 0; // calculate the "logical" width of the table if (table.rows.length > 0) { // save value of cellSpacing int cellSpacing = GetAttributeAsInteger(table.cellSpacing); // use the first row as a proxy for the width of the table IHTMLTableRow firstRow = table.rows.item(0, 0) as IHTMLTableRow; foreach (IHTMLTableCell cell in firstRow.cells) logicalWidth += GetCellWidth(cell) + cellSpacing; // total width + extra cellspacing @ end + size of borders return logicalWidth + cellSpacing + GetTableBorderEditingOffset(table); } // return width return logicalWidth; }
private static void RemoveDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement) { IHTMLElement element = tableElement as IHTMLElement; tableElement.runtimeStyle.borderWidth = element.style.borderWidth; tableElement.runtimeStyle.borderColor = element.style.borderColor; tableElement.runtimeStyle.borderStyle = element.style.borderStyle; (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = (element.style as IHTMLStyle2).borderCollapse; }
private static void AttachDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement) { // attach design time border tableElement.runtimeStyle.borderWidth = "1"; tableElement.runtimeStyle.borderColor = "#BCBCBC"; tableElement.runtimeStyle.borderStyle = "dotted"; // collapse cells if there is no cellspacing if ((table.cellSpacing == null) || table.cellSpacing.ToString() != "0") (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "separate"; else (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "collapse"; }
public static void UpdateDesignTimeBorders(IHTMLTable table, IHTMLElement2 tableElement) { // don't do anything if there is a css-based border on this element if ((tableElement as IHTMLElement).style.borderStyle != null) return; // don't attach if is there a standard table border if (table.border != null && table.border.ToString() != "0") { RemoveDesignTimeBorder(table, tableElement); } else { AttachDesignTimeBorder(table, tableElement); } }
public static void UpdateDesignTimeBorders(IHTMLTable table) { // update the table's borders UpdateDesignTimeBorders(table, table as IHTMLElement2); // update the contained cell borders foreach (IHTMLTableRow row in table.rows) foreach (IHTMLTableCell cell in row.cells) UpdateDesignTimeBorders(table, cell as IHTMLElement2); }
public void DeleteCol(IHTMLTable table, int colindex) { for (int i = 0; true; i++) { IHTMLTableRow row = GetRow(table, i); if (row == null) break; IHTMLTableCell cell = Row_GetCell(row, colindex); if (cell == null) continue; RemoveNode(cell as IHTMLElement, true); if (Row_GetCellCount(row) == 0) { RemoveNode(table as IHTMLElement, true); break; } //Accounts for colspan //Row_DeleteCol(row, colindex); IHTMLElementCollection cells = row.cells; CalculateCellWidths(cells.length); for (int j = 0; j < cells.length; j++) { object obj = j; IHTMLTableCell cella = cells.item(obj, obj) as IHTMLTableCell; if (cella != null) { if ((j + 1) == cells.length) cella.width = m_lastcellwidth; else cella.width = m_cellwidth; } } } }
/// <summary> /// Deletes a given rowindex in a given table /// zero based /// If the table has no rows after deletion anymore /// we delete it compeletely /// </summary> /// <param name="table"></param> /// <param name="rowindex"></param> public void DeleteRow(IHTMLTable table, int rowindex) { table.deleteRow(rowindex); if (GetRowCount(table) == 0) RemoveNode(table as IHTMLElement, true); }
public SizingOperation(IHtmlEditorComponentContext editorContext, IHTMLTable table) { _editorContext = editorContext; _table = table; }
/// <summary> /// Zero based /// </summary> /// <param name="table"></param> /// <param name="rowindex"></param> /// <returns></returns> public IHTMLTableRow GetRow(IHTMLTable table, int rowindex) { IHTMLElementCollection rows = table.rows; if (rows == null) return null; object obj = rowindex; return rows.item(obj, obj) as IHTMLTableRow; }
public static IHTMLTableRow AddTableRowsAtBottom( IHTMLTable table, int count) { return AddTableRowsAfterRow( table, -1, count); }
public void InsertCol(IHTMLTable table, int index) { for (int j = 0; true; j++) { IHTMLTableRow row = GetRow(table, j); if (row == null) return; if (Row_InsertCol(row, index) == null) return; } }
public HTMLTableColumn(IHTMLTable table, IHTMLTableCell baseCell) { _table = table; _baseCell = baseCell; _index = _baseCell.cellIndex; }
public void Initialize( IHTMLTable table, int columnIndex) { Text = Resources.Str_UIHtml_ColumnProperties; var rows = table.rows; if (rows != null) { for (var i = 0; i < rows.length; ++i) { var row = (IHTMLTableRow)rows.item(i, i); var cells = row.cells; if (cells != null) { for (int j = 0; j < cells.length; ++j) { if (j == columnIndex) { _cells.Add(cells.item(j, j) as IHTMLTableCell); break; } } } } } }
public bool changeTable(IHTMLTable table, int height, int colnum, int rownum, int bordersize, string alignment, int cellpadding, int cellspacing, string widthpercentage, int widthpixel, string backcolor, string bordercolor, string lightbordercolor, string darkbordercolor) { if (m_pDoc2 == null) return false; IHTMLTable t = table; //set the cols t.cols = colnum; t.border = bordersize; if (!string.IsNullOrEmpty(alignment)) t.align = alignment; //"center" t.cellPadding = cellpadding; //1 t.cellSpacing = cellspacing; //2 if (!string.IsNullOrEmpty(widthpercentage)) t.width = widthpercentage; //"50%"; else if (widthpixel > 0) t.width = widthpixel; //80; if (!string.IsNullOrEmpty(backcolor)) t.bgColor = backcolor; if (!string.IsNullOrEmpty(bordercolor)) t.borderColor = bordercolor; if (!string.IsNullOrEmpty(lightbordercolor)) t.borderColorLight = lightbordercolor; if (!string.IsNullOrEmpty(darkbordercolor)) t.borderColorDark = darkbordercolor; //Insert rows and fill them with space int cells = colnum - 1; int rows = rownum - 1; System.Collections.IEnumerator ee = table.rows.GetEnumerator(); while (ee.MoveNext() && ee.Current != null) { IHTMLTableRow row = (IHTMLTableRow)ee.Current; int index = row.rowIndex; t.deleteRow(index); } CalculateCellWidths(colnum); for (int i = 0; i <= rows; i++) { IHTMLTableRow tr = (IHTMLTableRow)t.insertRow(-1); for (int j = 0; j <= cells; j++) { IHTMLElement c = tr.insertCell(-1) as IHTMLElement; if (c != null) { c.innerHTML = HtmlSpace; IHTMLTableCell tcell = c as IHTMLTableCell; if (tcell != null) { //set width so as user enters text //the cell width would not adjust if (j == cells) //last cell tcell.width = m_lastcellwidth; else tcell.width = m_cellwidth; } } } } //Append to body DOM collection IHTMLDOMNode nd = (IHTMLDOMNode)t; IHTMLAttributeCollection iac = nd.attributes; IHTMLElement ele = (IHTMLElement)t; ele.setAttribute("ghm", "chenjian", 0); //ele.innerHTML += "<demoTag id=\"ddeo\">hello</demoTag>"; //nd.appendChild((IHTMLDOMNode)div); IHTMLSelectionObject sel = m_pDoc2.selection as IHTMLSelectionObject; if (sel == null) return false; IHTMLTxtRange range = sel.createRange() as IHTMLTxtRange; string eventtype = sel.EventType; System.Type type = sel.GetType(); //string html = range.htmlText; //range.compareEndPoints IHTMLDOMNode body = (IHTMLDOMNode)m_pDoc2.body; IHTMLDOMChildrenCollection childreCollection = body.childNodes; for (int i = 0; i < childreCollection.length; i++) { IHTMLElement eleChild = childreCollection.item(i) as IHTMLElement; } return true; }
public static void AddTableColumnsAtRight( IHTMLTable table, int count) { AddTableColumnsAfterColumn( table, -1, count); }
public static void SynchronizeCellWidthsForEditing(IHTMLTable table) { // resize the cells in the table to match their actual width foreach (IHTMLTableCell cell in (table as IHTMLElement2).getElementsByTagName("th")) SynchronizeCellWidthForEditing(cell); foreach (IHTMLTableCell cell in (table as IHTMLElement2).getElementsByTagName("td")) SynchronizeCellWidthForEditing(cell); }
private static int CountTableColumns( IHTMLTable table) { int cols = 0; for (int i = 0; i < table.rows.length; ++i) { int c = CountTableRowColumns( table.rows.item(i, i) as IHTMLTableRow); if (c > cols) { cols = c; } } return cols; }
public static int GetTableBorderEditingOffset(IHTMLTable table) { int borderOffset = GetAttributeAsInteger(table.border) * 2; if (borderOffset == 0) { // respect css border width IHTMLElement tableElement = table as IHTMLElement; borderOffset = GetAttributeAsInteger(tableElement.style.borderWidth) * 2; // if no css border width, we know the total border width is 2 (b/c we // add a one pixel border for editing) if (borderOffset == 0) borderOffset = 2; } // return width return borderOffset; }
public static void SynchronizeCellAndTableWidthsForEditing(IHTMLTable table) { SynchronizeCellWidthsForEditing(table); SynchronizeTableWidthForEditing(table); }
public static void MakeTableWriterEditableIfRectangular(IHTMLTable table) { try { // no-op for null table if (table == null) return; // no-op if we are already unselectable IHTMLElement tableElement = table as IHTMLElement; if (TableElementContainsWriterEditingMark(tableElement)) return; // check for rectangular structure int tableColumnCount = -1; foreach (IHTMLTableRow row in table.rows) { int columnCount = row.cells.length; if (tableColumnCount == -1) { // initilize table column count if this is the first pass tableColumnCount = columnCount; } else { // compare this rows column count with the table column // count -- if they are not equal then exit function if (columnCount != tableColumnCount) return; } } // if we made it this far then the table is rectangular, so // mark it with our "editable" sentinel tableElement.setAttribute("unselectable", "on", 0); } catch (Exception ex) { Trace.Fail("Unexpected error in MakeTableWriterEditableIfRectangular: " + ex.ToString()); } }