Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 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);
 }
Exemple #4
0
 public override void BringCellToVisible(TabularPosition position)
 {
     if ((!position.IsEmpty && (position.Area == SheetArea.Cells)) && (_excel.ActiveSheet != null))
     {
         NavigatorHelper.BringCellToVisible(_excel, position.Row, position.Column);
     }
 }
Exemple #5
0
 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);
 }
Exemple #6
0
 public TabularPosition(SheetArea area, int row, int column)
 {
     this        = new TabularPosition();
     _isNotEmpty = true;
     _area       = area;
     _row        = row;
     _column     = column;
 }
Exemple #7
0
        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));
        }
Exemple #8
0
 public virtual bool MoveCurrentTo(TabularPosition cellPosition)
 {
     if (CanMoveCurrentTo(cellPosition))
     {
         CurrentCell = cellPosition;
         return(true);
     }
     return(false);
 }
Exemple #9
0
        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));
        }
Exemple #10
0
        public override bool Equals(object obj)
        {
            if (!(obj is TabularPosition))
            {
                return(false);
            }
            TabularPosition other = (TabularPosition)obj;

            return(Equals(other));
        }
Exemple #11
0
        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));
        }
Exemple #12
0
 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);
 }
Exemple #13
0
        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);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
 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);
 }
Exemple #19
0
 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);
 }
Exemple #20
0
 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));
 }
Exemple #21
0
 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;
         }
     }
 }
Exemple #22
0
 public TabularRange(TabularPosition position, int rowCount = 1, int columnCount = 1) : this(position.Area, position.Row, position.Column, rowCount, columnCount)
 {
 }
Exemple #23
0
 static TabularPosition()
 {
     Empty = new TabularPosition();
 }
Exemple #24
0
 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);
 }
Exemple #25
0
 public bool Equals(TabularPosition other)
 {
     return((((_isNotEmpty == other._isNotEmpty) && (_area == other._area)) && (_row == other._row)) && (_column == other._column));
 }
Exemple #26
0
 public virtual bool CanMoveCurrentTo(TabularPosition cellPosition)
 {
     return(true);
 }
Exemple #27
0
        public virtual TabularPosition PredictMoveCurrent(NavigationDirection direction)
        {
            TabularPosition empty = TabularPosition.Empty;

            return(PredictCell(direction, out empty));
        }
Exemple #28
0
 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));
 }
Exemple #29
0
 public void UpdateNavigationStartPosition(TabularPosition currentPosition, TabularPosition startPosition)
 {
     _currentCellPosition       = currentPosition;
     _startNavigateCellPosition = startPosition;
 }
Exemple #30
0
 public abstract void BringCellToVisible(TabularPosition position);