TabularPosition PredictHomeCell(TabularPosition startPosition, int leftmostColumn, out TabularPosition newStartPosition) { TabularRange range; newStartPosition = TabularPosition.Empty; int column = startPosition.Column; if (column < leftmostColumn) { column = ContentBounds.LastColumn; } for (int i = leftmostColumn; i < column; i += range.ColumnCount) { TabularPosition topLeft = new TabularPosition(startPosition.Area, startPosition.Row, i); if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(startPosition.Area, startPosition.Row, topLeft.Column); return(topLeft); } } return(TabularPosition.Empty); }
TabularPosition PredictTopCell(out TabularPosition newStartPosition) { TabularRange range; newStartPosition = TabularPosition.Empty; TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, TotalRowCount - 1, 0); } int row = ContentBounds.Row; int lastRow = position.Row; if (lastRow < row) { lastRow = ContentBounds.LastRow; } for (int i = row; i < lastRow; i += range.RowCount) { TabularPosition topLeft = new TabularPosition(position.Area, i, position.Column); if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(position.Area, topLeft.Row, position.Column); return(topLeft); } } return(TabularPosition.Empty); }
TabularPosition PredictLastCell(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; for (int i = ContentBounds.LastRow; i >= ContentBounds.Row; i--) { if (GetRowIsVisible(i)) { for (int j = ContentBounds.LastColumn; j >= ContentBounds.Column; j--) { if (GetColumnIsVisible(j)) { TabularRange range; TabularPosition topLeft = new TabularPosition(_currentCellPosition.Area, i, j); if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = topLeft; return(topLeft); } } } } } return(TabularPosition.Empty); }
public override void BringCellToVisible(TabularPosition position) { if ((!position.IsEmpty && (position.Area == SheetArea.Cells)) && (_excel.ActiveSheet != null)) { NavigatorHelper.BringCellToVisible(_excel, position.Row, position.Column); } }
public virtual bool MoveCurrent(NavigationDirection direction) { AdjustStartPosition(); if (((direction == NavigationDirection.PageUp) || (direction == NavigationDirection.PageDown)) || ((direction == NavigationDirection.PageLeft) || (direction == NavigationDirection.PageRight))) { if (CanMoveCurrent(direction)) { TabularPosition empty = TabularPosition.Empty; TabularPosition position2 = MoveCellByPage(direction, out empty); if (!position2.IsEmpty && (position2 != CurrentCell)) { CurrentCell = position2; _startNavigateCellPosition = empty; } return(true); } } else { TabularPosition newStartPosition = TabularPosition.Empty; TabularPosition position4 = PredictCell(direction, out newStartPosition); if (!position4.IsEmpty && (position4 != CurrentCell)) { CurrentCell = position4; _startNavigateCellPosition = newStartPosition; return(true); } } return(false); }
public TabularPosition(SheetArea area, int row, int column) { this = new TabularPosition(); _isNotEmpty = true; _area = area; _row = row; _column = column; }
static CellRange TabularPositionUnion(TabularPosition startPosition, TabularPosition endPosition) { int row = Math.Min(startPosition.Row, endPosition.Row); int column = Math.Min(startPosition.Column, endPosition.Column); int rowCount = Math.Abs((int)(startPosition.Row - endPosition.Row)) + 1; return(new CellRange(row, column, rowCount, Math.Abs((int)(startPosition.Column - endPosition.Column)) + 1)); }
public virtual bool MoveCurrentTo(TabularPosition cellPosition) { if (CanMoveCurrentTo(cellPosition)) { CurrentCell = cellPosition; return(true); } return(false); }
TabularPosition PredictEndCell(out TabularPosition newStartPosition) { TabularPosition startPosition = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { startPosition = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } return(PredictEndCell(startPosition, ContentBounds.LastColumn, out newStartPosition)); }
public override bool Equals(object obj) { if (!(obj is TabularPosition)) { return(false); } TabularPosition other = (TabularPosition)obj; return(Equals(other)); }
TabularPosition PredictHomeCell(out TabularPosition newStartPosition) { TabularPosition startPosition = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { startPosition = new TabularPosition(_startNavigateCellPosition.Area, 0, TotalColumnCount - 1); } return(PredictHomeCell(startPosition, ContentBounds.Column, out newStartPosition)); }
public override bool IsMerged(TabularPosition position, out TabularRange range) { range = new TabularRange(position, 1, 1); if ((_excel.ActiveSheet != null) && (_excel.ActiveSheet.SpanModel != null)) { CellRange range2 = _excel.ActiveSheet.SpanModel.Find(position.Row, position.Column); if (range2 != null) { range = new TabularRange(position.Area, range2.Row, range2.Column, range2.RowCount, range2.ColumnCount); return(true); } } return(false); }
TabularPosition PredictUpCell(out TabularPosition newStartPosition) { if (CurrentCell.IsEmpty) { return(PredictFirstCell(out newStartPosition)); } newStartPosition = TabularPosition.Empty; int row = _startNavigateCellPosition.Row; TabularPosition topLeft = _startNavigateCellPosition; while (row > 0) { TabularRange range; if (IsMerged(topLeft, out range)) { row = range.Row - 1; if (row < 0) { break; } } else { row--; } topLeft = new TabularPosition(_startNavigateCellPosition.Area, row, _startNavigateCellPosition.Column); if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; for (int i = 0; i < range.RowCount; i++) { row = range.LastRow - i; if (GetRowIsVisible(row)) { break; } } } if (GetRowIsVisible(row) && CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(_startNavigateCellPosition.Area, row, _startNavigateCellPosition.Column); return(topLeft); } } return(TabularPosition.Empty); }
TabularPosition PredictLeftCell(out TabularPosition newStartPosition) { if (CurrentCell.IsEmpty) { return(PredictFirstCell(out newStartPosition)); } newStartPosition = TabularPosition.Empty; int column = _startNavigateCellPosition.Column; TabularPosition topLeft = _startNavigateCellPosition; while (column > 0) { TabularRange range; if (IsMerged(topLeft, out range)) { column = range.Column - 1; if (column < 0) { break; } } else { column--; } topLeft = new TabularPosition(_startNavigateCellPosition.Area, _startNavigateCellPosition.Row, column); if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; for (int i = 0; i < range.ColumnCount; i++) { column = range.LastColumn - i; if (GetColumnIsVisible(column)) { break; } } } if (GetColumnIsVisible(column) && CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(_startNavigateCellPosition.Area, _startNavigateCellPosition.Row, column); return(topLeft); } } return(TabularPosition.Empty); }
TabularPosition PredictCell(NavigationDirection direction, out TabularPosition newStartPosition) { if (((direction == NavigationDirection.PageUp) || (direction == NavigationDirection.PageDown)) || ((direction == NavigationDirection.PageLeft) || (direction == NavigationDirection.PageRight))) { throw new NotSupportedException("Not support"); } AdjustStartPosition(); newStartPosition = TabularPosition.Empty; if ((TotalColumnCount != 0) && (TotalRowCount != 0)) { switch (direction) { case NavigationDirection.Left: return(PredictLeftCell(out newStartPosition)); case NavigationDirection.Right: return(PredictRightCell(out newStartPosition)); case NavigationDirection.Up: return(PredictUpCell(out newStartPosition)); case NavigationDirection.Down: return(PredictDownCell(out newStartPosition)); case NavigationDirection.Home: return(PredictHomeCell(out newStartPosition)); case NavigationDirection.End: return(PredictEndCell(out newStartPosition)); case NavigationDirection.Top: return(PredictTopCell(out newStartPosition)); case NavigationDirection.Bottom: return(PredictBottomCell(out newStartPosition)); case NavigationDirection.First: return(PredictFirstCell(out newStartPosition)); case NavigationDirection.Last: return(PredictLastCell(out newStartPosition)); } } return(TabularPosition.Empty); }
TabularPosition PredictDownCell(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } int row = position.Row; TabularPosition topLeft = position; while (row < (TotalRowCount - 1)) { TabularRange range; if (IsMerged(topLeft, out range)) { row = range.Row + range.RowCount; if (row > (TotalRowCount - 1)) { break; } } else { row++; } topLeft = new TabularPosition(position.Area, row, position.Column); if (GetRowIsVisible(row)) { if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(position.Area, row, position.Column); return(topLeft); } } } return(TabularPosition.Empty); }
TabularPosition PredictRightCell(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } int column = position.Column; TabularPosition topLeft = position; while (column < (TotalColumnCount - 1)) { TabularRange range; if (IsMerged(topLeft, out range)) { column = range.Column + range.ColumnCount; if (column > (TotalColumnCount - 1)) { break; } } else { column++; } topLeft = new TabularPosition(position.Area, position.Row, column); if (GetColumnIsVisible(column)) { if (IsMerged(topLeft, out range)) { topLeft = range.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(position.Area, position.Row, column); return(topLeft); } } } return(TabularPosition.Empty); }
TabularPosition MoveLeftByPage(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; if (CanHorizontalScroll(false)) { TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } TabularRange currentViewport = CurrentViewport; bool flag = IsColumnInViewport(currentViewport, position); ScrollToPreviousPageOfColumns(); TabularRange viewPort = CurrentViewport; if (IsColumnInViewport(viewPort, position)) { return(CurrentCell); } int column = flag ? (position.Column - currentViewport.ColumnCount) : viewPort.Column; if (column < ContentBounds.Column) { column = ContentBounds.Column; } int num2 = flag ? position.Column : viewPort.LastColumn; while (column < num2) { TabularRange range3; TabularPosition topLeft = new TabularPosition(_startNavigateCellPosition.Area, position.Row, column); if (IsMerged(topLeft, out range3)) { topLeft = range3.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(_startNavigateCellPosition.Area, position.Row, column); return(topLeft); } column += range3.ColumnCount; } } return(TabularPosition.Empty); }
TabularPosition MoveUpByPage(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; if (CanVerticalScroll(false)) { TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } TabularRange currentViewport = CurrentViewport; bool flag = IsRowInViewport(currentViewport, position); ScrollToPreviousPageOfRows(); TabularRange viewPort = CurrentViewport; if (IsRowInViewport(viewPort, position)) { return(CurrentCell); } int row = flag ? (position.Row - currentViewport.RowCount) : viewPort.Row; int num2 = flag ? position.Row : viewPort.LastRow; if (row < ContentBounds.Row) { row = ContentBounds.Row; } while (row < num2) { TabularRange range3; TabularPosition topLeft = new TabularPosition(_startNavigateCellPosition.Area, row, position.Column); if (IsMerged(topLeft, out range3)) { topLeft = range3.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(_startNavigateCellPosition.Area, row, position.Column); return(topLeft); } row += range3.RowCount; } } return(TabularPosition.Empty); }
TabularPosition MoveCellByPage(NavigationDirection direction, out TabularPosition newStartPosition) { if (direction == NavigationDirection.PageUp) { return(MoveUpByPage(out newStartPosition)); } if (direction == NavigationDirection.PageDown) { return(MoveDownByPage(out newStartPosition)); } if (direction == NavigationDirection.PageLeft) { return(MoveLeftByPage(out newStartPosition)); } if (direction != NavigationDirection.PageRight) { throw new ArgumentException("the direction must be PageDown, PageUp, PageLeft, PageRight"); } return(MoveRightByPage(out newStartPosition)); }
void AdjustStartPosition() { if (_currentCellPosition.IsEmpty) { _startNavigateCellPosition = TabularPosition.Empty; } else { TabularRange range; if (IsMerged(_currentCellPosition, out range)) { if (!range.IsContains(new TabularRange(_startNavigateCellPosition, 1, 1))) { _startNavigateCellPosition = _currentCellPosition; } } else if (_startNavigateCellPosition != _currentCellPosition) { _startNavigateCellPosition = _currentCellPosition; } } }
public TabularRange(TabularPosition position, int rowCount = 1, int columnCount = 1) : this(position.Area, position.Row, position.Column, rowCount, columnCount) { }
static TabularPosition() { Empty = new TabularPosition(); }
TabularPosition MoveRightByPage(out TabularPosition newStartPosition) { newStartPosition = TabularPosition.Empty; if (CanHorizontalScroll(true)) { TabularPosition position = _startNavigateCellPosition; if (CurrentCell.IsEmpty) { position = new TabularPosition(_startNavigateCellPosition.Area, 0, 0); } TabularRange currentViewport = CurrentViewport; bool flag = IsColumnInViewport(currentViewport, _startNavigateCellPosition); ScrollToNextPageOfColumns(); TabularRange viewPort = CurrentViewport; if (IsColumnInViewport(viewPort, position)) { return(CurrentCell); } if (flag) { int column = position.Column + currentViewport.ColumnCount; if (column > ContentBounds.LastColumn) { column = ContentBounds.LastColumn; } while (column > position.Column) { TabularRange range3; TabularPosition topLeft = new TabularPosition(position.Area, position.Row, column); if (IsMerged(topLeft, out range3)) { topLeft = range3.TopLeft; } if (CanMoveCurrentTo(topLeft)) { newStartPosition = new TabularPosition(position.Area, position.Row, column); return(topLeft); } column -= range3.ColumnCount; } } else { TabularRange range4; for (int i = viewPort.Column; i < viewPort.LastColumn; i += range4.ColumnCount) { TabularPosition position3 = new TabularPosition(position.Area, position.Row, i); if (IsMerged(position3, out range4)) { position3 = range4.TopLeft; } if (CanMoveCurrentTo(position3)) { newStartPosition = new TabularPosition(position.Area, position.Row, i); return(position3); } } } } return(TabularPosition.Empty); }
public bool Equals(TabularPosition other) { return((((_isNotEmpty == other._isNotEmpty) && (_area == other._area)) && (_row == other._row)) && (_column == other._column)); }
public virtual bool CanMoveCurrentTo(TabularPosition cellPosition) { return(true); }
public virtual TabularPosition PredictMoveCurrent(NavigationDirection direction) { TabularPosition empty = TabularPosition.Empty; return(PredictCell(direction, out empty)); }
public override bool CanMoveCurrentTo(TabularPosition cellPosition) { return(((((_excel.ActiveSheet != null) && (cellPosition.Row >= 0)) && ((cellPosition.Row < _excel.ActiveSheet.RowCount) && (cellPosition.Column >= 0))) && (((cellPosition.Column < _excel.ActiveSheet.ColumnCount) && _excel.ActiveSheet.Cells[cellPosition.Row, cellPosition.Column].ActualFocusable) && GetRowIsVisible(cellPosition.Row))) && GetColumnIsVisible(cellPosition.Column)); }
public void UpdateNavigationStartPosition(TabularPosition currentPosition, TabularPosition startPosition) { _currentCellPosition = currentPosition; _startNavigateCellPosition = startPosition; }
public abstract void BringCellToVisible(TabularPosition position);