public void DeleteTable() { HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); if (table != null) { try { using (new UndoUnit(Document, "Table delete")) { (table as HtmlDomNode).removeNode(true); } editor._FireCursorMovedEvent(); } catch (Exception ex) { throw new HtmlEditorException("Unable to delete the selected Row", "TableDeleteRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableDeleteRow"); } }
public bool Set(mshtml.IHTMLTableCell cell) { // if user has selected a table extract those properties if (cell == null) { return(false); } try { base.Set(cell.bgColor, cell.borderColor); if (cell.align != null) { this.HorzAlignment = (HorizontalAlignOption)Utils.TryParseEnum(typeof(HorizontalAlignOption), cell.align, HorizontalAlignOption.Default); } if (cell.vAlign != null) { this.VertAlignment = (VerticalAlignOption)Utils.TryParseEnum(typeof(VerticalAlignOption), cell.vAlign, VerticalAlignOption.Default); } this.ColSpan = cell.colSpan; this.RowSpan = cell.rowSpan; this.NoWrap = cell.noWrap; } catch (Exception ex) { // throw an exception indicating table structure change be determined throw new HtmlEditorException("Unable to determine Html Cell properties.", "GetCellProperties", ex); } return(true); }
public void DeleteColumn() { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); // process according to table being defined if (table != null && row != null && cell != null) { try { using (new UndoUnit(Document, "Table column delete")) { foreach (HtmlTableRow r in table.rows) { r.deleteCell(cell.cellIndex); } table.cols--; } editor._FireCursorMovedEvent(); } catch (Exception ex) { throw new HtmlEditorException("Unable to delete the selected Row", "TableDeleteRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableDeleteRow"); } }
// will delete the currently selected row // based on the current user row location public void DeleteRow() { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); // process according to table being defined if (table != null && row != null) { try { using (new UndoUnit(Document, "Table row delete")) { // find the existing row the user is on and perform the deletion int index = row.rowIndex; table.deleteRow(index); } editor._FireCursorMovedEvent(); } catch (Exception ex) { throw new HtmlEditorException("Unable to delete the selected Row", "TableDeleteRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableDeleteRow"); } }
// determine if the current selection is a table // return the table element private void GetTableElement(out HtmlTable table, out HtmlTableRow row, out HtmlTableCell cell) { table = null; row = null; cell = null; HtmlTextRange range = SelectionHelper.GetTextRange(Document); try { // first see if the table element is selected table = SelectionHelper.GetFirstControl(Document) as HtmlTable; // if table not selected then parse up the selection tree if (table == null && range != null) { HtmlElement element = (HtmlElement)range.parentElement(); // parse up the tree until the table element is found while (element != null && table == null) { if (element is HtmlTable) { table = (HtmlTable)element; } else if (element is HtmlTableRow) { row = (HtmlTableRow)element; } else if (element is HtmlTableCell) { cell = (HtmlTableCell)element; } element = (HtmlElement)element.parentElement; } } } catch (Exception) { // have unknown error so set return to null table = null; row = null; cell = null; } } //GetTableElement
public void ColumnMoveRight() { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); if (table != null && row != null && cell != null) { int index = cell.cellIndex; if (index >= row.cells.length - 1) { return; } try { using (new SelectionPreserver(GetMarkupRange())) { using (new UndoUnit(Document, "Table column move right")) { for (int i = 0; i < table.rows.length; i++) { HtmlTableRow r = table.rows.item(i); HtmlDomNode c1 = r.cells.item(index); HtmlDomNode c2 = r.cells.item(index + 1); c1.swapNode(c2); } } } } catch (Exception ex) { throw new HtmlEditorException("Unable to insert a new Row", "TableinsertRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableInsertRow"); } }
// will insert a new row into the table // based on the current user row and insertion after private void InsertRow(bool below = true) { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); // process according to table being defined if (table != null && row != null) { try { using (new SelectionPreserver(GetMarkupRange())) { using (new UndoUnit(Document, "Table row insert")) { // find the existing row the user is on and perform the insertion int index = row.rowIndex + (below ? 1 : 0); HtmlTableRow insertedRow = table.insertRow(index) as HtmlTableRow; // add the new columns to the end of each row int numberCols = row.cells.length; for (int idxCol = 0; idxCol < numberCols; idxCol++) { insertedRow.insertCell(-1); } } } } catch (Exception ex) { throw new HtmlEditorException("Unable to insert a new Row", "TableinsertRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableInsertRow"); } }
private void InsertColumn(bool right = true) { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); // process according to table being defined if (table != null && row != null && cell != null) { try { using (new UndoUnit(Document, "Table column insert")) { // find the existing row the user is on and perform the insertion int index = cell.cellIndex + (right ? 1 : 0); // add the new columns to the end of each row int numberRows = table.rows.length; for (int i = 0; i < numberRows; i++) { HtmlTableRow r = table.rows.item(i) as HtmlTableRow; r.insertCell(index); } table.cols++; } } catch (Exception ex) { throw new HtmlEditorException("Unable to insert a new Row", "TableinsertRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableInsertRow"); } }
public bool Get(ref mshtml.IHTMLTableCell cell) { if (cell == null) { return(false); } object bgColor, borderColor; base.Get(out bgColor, out borderColor); cell.bgColor = bgColor; cell.borderColor = borderColor; if (this.HorzAlignment == HorizontalAlignOption.Default) { cell.align = null; } else { cell.align = this.HorzAlignment.ToString().ToLower(); } if (this.VertAlignment == VerticalAlignOption.Default) { cell.vAlign = null; } else { cell.vAlign = this.VertAlignment.ToString().ToLower(); } cell.colSpan = this.ColSpan; cell.rowSpan = this.RowSpan; cell.noWrap = this.NoWrap; return(true); }
private void SelectCell(HtmlTableCell cell) { HtmlElement cellElement = cell as HtmlElement; MsHtmlWrap.MshtmlMarkupServices markupServices = new MsHtmlWrap.MshtmlMarkupServices((MsHtmlWrap.IMarkupServicesRaw)Document); if (cellElement.document == Document) { System.Diagnostics.Debug.WriteLine("same"); } // move the selection to the beginning of the cell MsHtmlWrap.MarkupRange markupRange = markupServices.CreateMarkupRange(cellElement); // if the cell is empty then collapse the selection if (cellElement.innerHTML == null) { markupRange.End.MoveToPointer(markupRange.Start); } HtmlTextRange textRange = markupRange.ToTextRange(); textRange.select(); }
public void RowMoveDown() { // see if a table selected or insertion point inside a table HtmlTable table = null; HtmlTableRow row = null; HtmlTableCell cell = null; GetTableElement(out table, out row, out cell); if (table != null && row != null && cell != null) { if (row.rowIndex >= table.rows.length - 1) { return; } try { using (new SelectionPreserver(GetMarkupRange())) { using (new UndoUnit(Document, "Table row move down")) { HtmlTableRow rowBelow = table.rows.item(row.rowIndex + 1); (row as HtmlDomNode).swapNode(rowBelow as HtmlDomNode); } } } catch (Exception ex) { throw new HtmlEditorException("Unable to insert a new Row", "TableinsertRow", ex); } } else { throw new HtmlEditorException("Row not currently selected within the table", "TableInsertRow"); } }
public HtmlTableCellProperty(mshtml.IHTMLTableCell cell) : this() { Set(cell); }