public void ContinueSizing(int clientX) { // calculate offset int offset = clientX - _lastClientX; // no-op for zero offset if (offset == 0) { return; } if (!_cellWidthsFixed) { // do fixups once during each size operation // This actually causes the cells to change size in many cases, which is incredibly annoying. // TableHelper.SynchronizeCellWidthsForEditing(_table); _cellWidthsFixed = true; } // check for abort condition if (AbortOnMinimumColumnWidth(offset)) { return; } // perform the sizing (middle of the table mode) if (_rightColumn != null) { _leftColumn.Width = Math.Max(_leftColumn.Width + offset, MINIMUM_COLUMN_WIDTH); _rightColumn.Width = Math.Max(_rightColumn.Width - offset, MINIMUM_COLUMN_WIDTH); } // perform the sizing (end of the table mode) else { // change left column _leftColumn.Width = Math.Max(_leftColumn.Width + offset, MINIMUM_COLUMN_WIDTH); // set the table width to prevent table wierdness TableHelper.SynchronizeTableWidthForEditing(_table); } // update last client x _lastClientX = clientX; // make sure we continue showing the sizing cursor ShowSizingCursor(); }
private IHTMLElement GetTargetCell(Point clientPoint) { // maximum amount of scanning buffer is based on cell spacing int maxScanningRange = Math.Max(TableHelper.GetAttributeAsInteger(_table.cellSpacing), 2); // copy client point so we can modify the x-coordinate while scanning Point targetPoint = new Point(clientPoint.X, clientPoint.Y); // if we go past the end of the table allow the cell closest to the cursor // to become the target cell (necessary for sizing the table larger) Point xTargetPoint = new Point(targetPoint.X, targetPoint.Y); IHTMLTableCell targetCell = null; while (targetCell == null && xTargetPoint.X >= (targetPoint.X - maxScanningRange)) // 0 ) { // determine the cell we are over targetCell = _editorContext.ElementFromClientPoint(xTargetPoint) as IHTMLTableCell; // screen cells that don't belong to us if (!HTMLElementHelper.ElementsAreEqual(_table as IHTMLElement, TableHelper.GetContainingTableElement(targetCell as IHTMLElement) as IHTMLElement)) { targetCell = null; } xTargetPoint.X--; } // if we got a target cell then ensure that the point is over the document area if (targetCell != null) { if (_editorContext.PointIsOverDocumentArea(clientPoint)) { return(targetCell as IHTMLElement); } else { return(null); } } else { return(null); } }
public void ProcessCell(IHTMLTableCell cell) { // for the first cell processed, note its color if (!_firstCellProcessed) { _backgroundColor.Color = TableHelper.GetColorForHtmlColor(cell.bgColor); _firstCellProcessed = true; } // for subsequent cells, if any of them differ from the first cell // then the background color is mixed else if (!_backgroundColor.IsMixed) { if (_backgroundColor.Color != TableHelper.GetColorForHtmlColor(cell.bgColor)) { _backgroundColor.IsMixed = true; } } }
public void ProcessCell(IHTMLTableCell cell) { // for the first cell processed, note its alignment if (!_firstCellProcessed) { _verticalAlignment = TableHelper.GetVAlignmentForHtmlAlignment(cell.vAlign); _firstCellProcessed = true; } // for subsequent cells, if any of them differ from the first cell // then the alignment is mixed else if (_verticalAlignment != VerticalAlignment.Mixed) // optimize { if (_verticalAlignment != TableHelper.GetVAlignmentForHtmlAlignment(cell.vAlign)) { _verticalAlignment = VerticalAlignment.Mixed; } } }
public void ProcessCell(IHTMLTableCell cell) { // for the first cell processed, note its alignment if (!_firstCellProcessed) { _horizontalAlignment = TableHelper.GetAlignmentForHtmlAlignment(cell.align); _firstCellProcessed = true; } // for subsequent cells, if any of them differ from the first cell // then the alignment is mixed else if (_horizontalAlignment != HorizontalAlignment.Mixed) { if (_horizontalAlignment != TableHelper.GetAlignmentForHtmlAlignment(cell.align)) { _horizontalAlignment = HorizontalAlignment.Mixed; } } }
public TableSelection(MarkupRange markupRange) { // calculate the begin and end cells IHTMLTableCell beginCell; IHTMLTableCell endCell; ArrayList selectedCells; FindCellRange(markupRange, out selectedCells, out beginCell, out endCell); // see if the two cells have a single containing table IHTMLTable table = GetSelectedTable(beginCell, endCell, markupRange) as IHTMLTable; // if we have a table then calculate the rest of our states if (table != null) { // validate the table selection if (ValidateTableSelection(table, markupRange, out _entireTableSelected)) { _table = table; _beginCell = beginCell; _endCell = endCell; // filter selected cells to only include direct descendents of this table (no // cells from nested tables) _selectedCells = new ArrayList(); foreach (IHTMLElement cell in selectedCells) { if (HTMLElementHelper.ElementsAreEqual(TableHelper.GetContainingTableElement(cell) as IHTMLElement, _table as IHTMLElement)) { _selectedCells.Add(cell); } } _hasContiguousSelection = !HTMLElementHelper.ElementsAreEqual(_beginCell as IHTMLElement, _endCell as IHTMLElement); _beginRow = GetContainingRowForCell(beginCell); _endRow = GetContainingRowForCell(endCell); _beginColumn = new HTMLTableColumn(_table, beginCell); _endColumn = new HTMLTableColumn(_table, endCell); } } }
protected override void OnElementAttached() { // call base base.OnElementAttached(); // determine whether the cell is editable _cellIsEditable = TableHelper.TableElementIsEditable(HTMLElement, ElementRange); // if editable then do our thing if (_cellIsEditable) { // add ourselves to the list of cell element behaviors TableEditingContext.AddCellBehavior(this); // if the table has no borders then set a runtime style that lets the user see the borders TableHelper.UpdateDesignTimeBorders( TableHelper.GetContainingTableElement(HTMLElement), HTMLElement as IHTMLElement2); } }
private static bool TableElementIsContainedInUnselectableTable(IHTMLElement element) { IHTMLTable table = TableHelper.GetContainingTableElement(element); if (table != null) { object unselectable = (table as IHTMLElement).getAttribute("unselectable", 0); if (unselectable != null) { return(unselectable.ToString() == "on"); } else { return(false); } } else { return(false); } }
private IHTMLElement GetSelectedTable(IHTMLTableCell beginCell, IHTMLTableCell endCell, MarkupRange selectionMarkupRange) { // screen null cases if (beginCell == null || endCell == null) { return(null); } // get containing tables IHTMLTable beginTable = TableHelper.GetContainingTableElement(beginCell as IHTMLElement); IHTMLTable endTable = TableHelper.GetContainingTableElement(endCell as IHTMLElement); // see if they are from the same table if (HTMLElementHelper.ElementsAreEqual(beginTable as IHTMLElement, endTable as IHTMLElement)) { return(beginTable as IHTMLElement); } else { return(null); } }
private void InitializeSizingContext(IHTMLTableCell targetCell) { IHTMLTableRow row = TableHelper.GetContainingRowElement(targetCell as IHTMLTableCell); IHTMLTableCell leftCell = row.cells.item(_pendingLeftColumnIndex, _pendingLeftColumnIndex) as IHTMLTableCell; _leftColumn = new HTMLTableColumn(_table, leftCell); if (_pendingRightColumnIndex != -1) { IHTMLTableCell rightCell = row.cells.item(_pendingRightColumnIndex, _pendingRightColumnIndex) as IHTMLTableCell; _rightColumn = new HTMLTableColumn(_table, rightCell); } else { _rightColumn = null; } // force a fixup of cell widths on the next call to ContinueSizing // (we do this during ContinueSizing so that table column borders don't // visible "jump" on MouseDown) _cellWidthsFixed = false; }
private bool ValidateTableSelection(IHTMLTable table, MarkupRange selectionMarkupRange, out bool tableFullySelected) { // assume table is not fully selected tableFullySelected = false; // first check to see that this is a "Writer" editable table if (!TableHelper.TableElementContainsWriterEditingMark(table as IHTMLElement)) { return(false); } // get elemental objects we need to analyze the table IHTMLElement tableElement = table as IHTMLElement; MarkupRange tableMarkupRange = selectionMarkupRange.Clone(); tableMarkupRange.MoveToElement(table as IHTMLElement, true); // analyze selection bool selectionAtTableStart = tableMarkupRange.Start.IsEqualTo(selectionMarkupRange.Start); bool selectionAtTableEnd = tableMarkupRange.End.IsEqualTo(selectionMarkupRange.End); // is the table fully selected? if (selectionAtTableStart && selectionAtTableEnd) { tableFullySelected = true; return(true); } else { MarkupRange selectionMarkupRange2 = selectionMarkupRange.Clone(); // is the selection bounded by the table IHTMLElement beginParentTable = selectionMarkupRange2.Start.SeekElementLeft(ElementFilters.CreateEqualFilter(tableElement)); IHTMLElement endParentTable = selectionMarkupRange2.End.SeekElementRight(ElementFilters.CreateEqualFilter(tableElement)); return(beginParentTable != null && endParentTable != null); } }
private void HandleMouseMove(TableColumnMouseEventArgs ea) { // cell element we are over IHTMLElement targetCell = GetTargetCell(ea.ClientPoint); // if there is no element then we are done if (targetCell == null) { // reset state _sizingOperation.EndSizing(); return; } // get the cell and row IHTMLTableCell cell = targetCell as IHTMLTableCell; IHTMLTableRow row = TableHelper.GetContainingRowElement(cell); // convert the client point to cell-local coordinates & calcualte our comparison x values TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(targetCell); if (cellBehavior == null) { _sizingOperation.ClearPending(); return; } Point cellLocalMousePt = cellBehavior.TransformGlobalToLocal(ea.ClientPoint); int cellSpacing = TableHelper.GetAttributeAsInteger(_table.cellSpacing); int cellSpacingOffset = cellSpacing / 2; int compareX = cellLocalMousePt.X; int cellStartX = 0 - cellSpacingOffset; int cellEndX = targetCell.offsetWidth + cellSpacingOffset; // if the mouse is near the edge of the cell then update the pending sizing action // (unless the mouse is near the edge of the first cell where no sizing is supported) if (MouseNearCellEdge(compareX, cellStartX, cellSpacing) || MouseNearCellEdge(compareX, cellEndX, cellSpacing)) { if (MouseNearCellEdge(compareX, cellStartX, cellSpacing)) { if (cell.cellIndex > 0) { int leftIndex = cell.cellIndex - 1; int rightIndex = cell.cellIndex; _sizingOperation.TrackPending(ea.ClientPoint.X, leftIndex, rightIndex); ea.Handled = true; } else { _sizingOperation.ClearPending(); } } else if (MouseNearCellEdge(compareX, cellEndX, cellSpacing)) { int leftIndex = cell.cellIndex; int rightIndex = cell.cellIndex < (row.cells.length - 1) ? cell.cellIndex + 1 : -1; _sizingOperation.TrackPending(ea.ClientPoint.X, leftIndex, rightIndex); ea.Handled = true; } } else // mouse is not near the edge of the cell, reset pending action { _sizingOperation.ClearPending(); } }