Exemple #1
0
 public override void BringCellToVisible(CompositePosition position)
 {
     if ((!position.IsEmpty && (position.Type == DataSheetElementType.Cell)) && (_excel.ActiveSheet != null))
     {
         NavigatorHelper.BringCellToVisible(_excel, position.Row, position.Column);
     }
 }
Exemple #2
0
        CompositePosition GetPreviousCellInRow(CompositePosition startCellPosition, bool includeStartCell, List <int> columnIndexes, out CompositePosition newStartPosition)
        {
            newStartPosition = CompositePosition.Empty;
            int index = columnIndexes.IndexOf(startCellPosition.Column);

            for (int i = includeStartCell ? index : (index - 1); i >= 0; i--)
            {
                CompositePosition position2;
                CompositePosition position = new CompositePosition(startCellPosition.Type, startCellPosition.Row, columnIndexes[i]);
                if (IsMerged(position, out position2))
                {
                    if (position.Column != position2.Column)
                    {
                        continue;
                    }
                    if (CanMoveCurrentTo(position2))
                    {
                        if (position2 == CurrentCell)
                        {
                            continue;
                        }
                        newStartPosition = position;
                        return(position2);
                    }
                }
                if (CanMoveCurrentTo(position))
                {
                    newStartPosition = position;
                    return(position);
                }
            }
            return(CompositePosition.Empty);
        }
Exemple #3
0
        CompositePosition PredictPreviousRowCell(out CompositePosition newStartPosition)
        {
            if (CurrentCell.IsEmpty)
            {
                return(PredictNextRowCell(out newStartPosition));
            }
            newStartPosition = CompositePosition.Empty;
            int column = _startNavigateCellPosition.IsEmpty ? 0 : _startNavigateCellPosition.Column;
            int num2   = _startNavigateCellPosition.IsEmpty ? ContentBounds.StartRow : (_startNavigateCellPosition.Row - 1);

            for (int i = num2; i >= ContentBounds.StartRow; i--)
            {
                CompositePosition position2;
                CompositePosition position = new CompositePosition(DataSheetElementType.Cell, i, column);
                if (IsMerged(position, out position2))
                {
                    position = position2;
                }
                if (CanMoveCurrentTo(position))
                {
                    newStartPosition = position;
                    return(position);
                }
            }
            return(CompositePosition.Empty);
        }
Exemple #4
0
 public void UpdateNavigationStartPosition(CompositePosition currentPosition, CompositePosition startPosition)
 {
     _currentCellPosition = currentPosition;
     if (startPosition.IsEmpty && !currentPosition.IsEmpty)
     {
         _startNavigateCellPosition = currentPosition;
     }
     else
     {
         _startNavigateCellPosition = startPosition;
     }
 }
Exemple #5
0
 public override int GetColumnSpan(CompositePosition position)
 {
     if ((_excel.ActiveSheet != null) && (_excel.ActiveSheet.SpanModel != null))
     {
         CellRange range = _excel.ActiveSheet.SpanModel.Find(position.Row, position.Column);
         if (range != null)
         {
             return(range.ColumnCount);
         }
     }
     return(1);
 }
Exemple #6
0
        public virtual bool MoveCurrent(NavigationDirection direction)
        {
            CompositePosition empty            = CompositePosition.Empty;
            CompositePosition newStartPosition = CompositePosition.Empty;
            int rangeIndex = -1;

            AdjustStartPosition();
            switch (direction)
            {
            case NavigationDirection.Previous:
                empty = PredictPreviousCell(out newStartPosition);
                break;

            case NavigationDirection.Next:
                empty = PredictNextCell(out newStartPosition);
                break;

            case NavigationDirection.PreviousInSelection:
                empty = PredictPreviousCellInSelection(out newStartPosition, out rangeIndex);
                break;

            case NavigationDirection.NextInSelection:
                empty = PredictNextCellInSelection(out newStartPosition, out rangeIndex);
                break;

            case NavigationDirection.FirstRow:
                empty = PredictFirstRowCell(out newStartPosition);
                break;

            case NavigationDirection.LastRow:
                empty = PredictLastRowCell(out newStartPosition);
                break;

            case NavigationDirection.NextRow:
                empty = PredictNextRowCell(out newStartPosition);
                break;

            case NavigationDirection.PreviousRow:
                empty = PredictPreviousRowCell(out newStartPosition);
                break;
            }
            if (empty.IsEmpty || (!(empty != CurrentCell) && (!(empty == CurrentCell) || (_currentRangeIndex == rangeIndex))))
            {
                return(false);
            }
            CurrentCell = empty;
            _startNavigateCellPosition = newStartPosition;
            _currentRangeIndex         = rangeIndex;
            return(true);
        }
Exemple #7
0
        int GetCurrentPageIndex(CompositePosition position)
        {
            IList <CompositeRange> selections = Selections;

            for (int i = selections.Count - 1; i >= 0; i--)
            {
                CompositeRange fixedRange = GetFixedRange(selections[i]);
                if (((position.Column >= fixedRange.Column) && (position.Column <= fixedRange.EndColumn)) && ((position.Row >= fixedRange.Row) && (position.Row <= fixedRange.EndRow)))
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemple #8
0
 public override bool IsMerged(CompositePosition position, out CompositePosition topLeftPosition)
 {
     topLeftPosition = position;
     if ((_excel.ActiveSheet != null) && (_excel.ActiveSheet.SpanModel != null))
     {
         CellRange range = _excel.ActiveSheet.SpanModel.Find(position.Row, position.Column);
         if (range != null)
         {
             topLeftPosition = new CompositePosition(DataSheetElementType.Cell, range.Row, range.Column);
             return(true);
         }
     }
     return(false);
 }
Exemple #9
0
 CompositePosition GetNextCellInRow(int rowDataIndex, List <int> columnIndexes, int startColumnDataIndex, out CompositePosition newStartPosition)
 {
     newStartPosition = CompositePosition.Empty;
     for (int i = columnIndexes.IndexOf(startColumnDataIndex) + 1; i < columnIndexes.Count; i++)
     {
         CompositePosition position2;
         CompositePosition position = new CompositePosition(CurrentCell.Type, rowDataIndex, columnIndexes[i]);
         if ((!IsMerged(position, out position2) || ((position.Row == position2.Row) && (position.Column == position2.Column))) && CanMoveCurrentTo(position))
         {
             newStartPosition = position;
             return(position);
         }
     }
     return(CompositePosition.Empty);
 }
Exemple #10
0
        CompositePosition PredictPreviousCellInSelection(out CompositePosition newStartPosition, out int rangeIndex)
        {
            rangeIndex = _currentRangeIndex;
            if (rangeIndex == -1)
            {
                rangeIndex = GetCurrentPageIndex(CurrentCell);
            }
            if (rangeIndex < 0)
            {
                newStartPosition = CurrentCell;
                return(CompositePosition.Empty);
            }
            List <CompositeRange> list = new List <CompositeRange>();

            for (int i = 0; i < Selections.Count; i++)
            {
                list.Add(GetFixedRange(Selections[i]));
            }
            CompositePosition empty         = CompositePosition.Empty;
            List <int>        columnIndexes = GetColumnIndexes(list[rangeIndex]);

            empty = GetPreviousCellInRange(list[rangeIndex], CurrentCell.Row, columnIndexes, CurrentCell.Column, out newStartPosition);
            if (empty.IsEmpty)
            {
                for (int j = rangeIndex - 1; j >= 0; j--)
                {
                    columnIndexes = GetColumnIndexes(list[j]);
                    empty         = GetPreviousCellInRange(list[j], list[j].EndRow, columnIndexes, list[j].EndColumn + 1, out newStartPosition);
                    if (!empty.IsEmpty)
                    {
                        rangeIndex = j;
                        return(empty);
                    }
                }
                for (int k = list.Count - 1; k >= 0; k--)
                {
                    columnIndexes = GetColumnIndexes(list[k]);
                    empty         = GetPreviousCellInRange(list[k], list[k].EndRow, columnIndexes, list[k].EndColumn + 1, out newStartPosition);
                    if (!empty.IsEmpty)
                    {
                        rangeIndex = k;
                        return(empty);
                    }
                }
            }
            return(empty);
        }
Exemple #11
0
        CompositePosition GetNextCellInRange(CompositeRange range, int rowDataIndex, List <int> columnIndexes, int startColumnDataIndex, out CompositePosition newStartPosition)
        {
            CompositePosition position = GetNextCellInRow(rowDataIndex, columnIndexes, startColumnDataIndex, out newStartPosition);

            if (position.IsEmpty)
            {
                for (int i = rowDataIndex + 1; i <= range.EndRow; i++)
                {
                    position = GetNextCellInRow(i, columnIndexes, -1, out newStartPosition);
                    if (!position.IsEmpty)
                    {
                        return(position);
                    }
                }
            }
            return(position);
        }
Exemple #12
0
 public virtual bool ShouldNavigateInSelection()
 {
     if (Selections.Count == 0)
     {
         return(false);
     }
     if (Selections.Count <= 1)
     {
         CompositeRange    fixedRange = GetFixedRange(Selections[0]);
         CompositePosition topLeft    = GetTopLeft(fixedRange);
         if (fixedRange.RowCount <= GetRowSpan(topLeft))
         {
             return(fixedRange.ColumnCount > GetColumnSpan(topLeft));
         }
     }
     return(true);
 }
Exemple #13
0
        CompositePosition GetPreviousCellInRange(CompositeRange range, int rowDataIndex, List <int> columnIndexes, int startColumnDataIndex, out CompositePosition newStartPosition)
        {
            CompositePosition position = GetPreviousCellInRow(rowDataIndex, columnIndexes, startColumnDataIndex, out newStartPosition);

            if (position.IsEmpty)
            {
                for (int i = rowDataIndex - 1; i >= range.Row; i--)
                {
                    position = GetPreviousCellInRow(i, columnIndexes, CompositeColumnCount, out newStartPosition);
                    if (!position.IsEmpty)
                    {
                        return(position);
                    }
                }
            }
            return(position);
        }
Exemple #14
0
        public override bool CanMoveCurrentTo(CompositePosition cellPosition)
        {
            var worksheet = _excel.ActiveSheet;

            if ((cellPosition.Type == DataSheetElementType.Cell) && (worksheet != null))
            {
                if (!worksheet.GetActualRowVisible(cellPosition.Row, SheetArea.Cells) || !worksheet.GetActualColumnVisible(cellPosition.Column, SheetArea.Cells))
                {
                    return(false);
                }
                StyleInfo info = worksheet.GetActualStyleInfo(cellPosition.Row, cellPosition.Column, SheetArea.Cells);
                if (info != null)
                {
                    return(info.TabStop && info.Focusable);
                }
            }
            return(base.CanMoveCurrentTo(cellPosition));
        }
Exemple #15
0
        CompositePosition GetPreviousCellInRow(int rowDataIndex, List <int> columnIndexes, int startColumnDataIndex, out CompositePosition newStartPosition)
        {
            newStartPosition = CompositePosition.Empty;
            int index = columnIndexes.IndexOf(startColumnDataIndex);

            if (index == -1)
            {
                index = columnIndexes.Count;
            }
            for (int i = index - 1; i >= 0; i--)
            {
                CompositePosition position2;
                CompositePosition position = new CompositePosition(CurrentCell.Type, rowDataIndex, columnIndexes[i]);
                if ((!IsMerged(position, out position2) || ((position.Row == position2.Row) && (position.Column == position2.Column))) && CanMoveCurrentTo(position))
                {
                    newStartPosition = position;
                    return(position);
                }
            }
            return(CompositePosition.Empty);
        }
Exemple #16
0
        CompositePosition PredictLastRowCell(out CompositePosition newStartPosition)
        {
            newStartPosition = CompositePosition.Empty;
            int column = _startNavigateCellPosition.IsEmpty ? 0 : _startNavigateCellPosition.Column;
            int num2   = _startNavigateCellPosition.IsEmpty ? (ContentBounds.StartRow - 1) : _startNavigateCellPosition.Row;

            for (int i = ContentBounds.EndRow; i > num2; i--)
            {
                CompositePosition position2;
                CompositePosition position = new CompositePosition(DataSheetElementType.Cell, i, column);
                if (IsMerged(position, out position2))
                {
                    position = position2;
                }
                if (CanMoveCurrentTo(position))
                {
                    newStartPosition = position;
                    return(position);
                }
            }
            return(CompositePosition.Empty);
        }
Exemple #17
0
 void AdjustStartPosition()
 {
     if (_currentCellPosition.IsEmpty)
     {
         _startNavigateCellPosition = CompositePosition.Empty;
     }
     else
     {
         CompositePosition position;
         if (IsMerged(_currentCellPosition, out position))
         {
             if (((_startNavigateCellPosition.Column < position.Column) || (_startNavigateCellPosition.Column > (position.Column + GetColumnSpan(position)))) || ((_startNavigateCellPosition.Row < position.Row) || (_startNavigateCellPosition.Row > (position.Row + GetRowSpan(position)))))
             {
                 _startNavigateCellPosition = _currentCellPosition;
             }
         }
         else if (_startNavigateCellPosition != _currentCellPosition)
         {
             _startNavigateCellPosition = _currentCellPosition;
         }
     }
 }
Exemple #18
0
        CompositePosition PredictPreviousCell(out CompositePosition newStartPosition)
        {
            if (CurrentCell.IsEmpty)
            {
                return(PredictNextCell(out newStartPosition));
            }
            List <int>        columnIndexes     = GetColumnIndexes();
            CompositePosition startCellPosition = _startNavigateCellPosition;
            CompositePosition position2         = GetPreviousCellInRow(startCellPosition, false, columnIndexes, out newStartPosition);

            if (position2.IsEmpty)
            {
                for (int i = startCellPosition.Row - 1; i >= 0; i--)
                {
                    position2 = GetPreviousCellInRow(new CompositePosition(startCellPosition.Type, i, columnIndexes[columnIndexes.Count - 1]), true, columnIndexes, out newStartPosition);
                    if (!position2.IsEmpty)
                    {
                        return(position2);
                    }
                }
            }
            return(position2);
        }
Exemple #19
0
        public virtual CompositePosition PredictMoveCurrent(NavigationDirection direction)
        {
            if ((CompositeColumnCount != 0) && (CompositeRowCount != 0))
            {
                AdjustStartPosition();
                CompositePosition empty = CompositePosition.Empty;
                int rangeIndex          = -1;
                switch (direction)
                {
                case NavigationDirection.Previous:
                    return(PredictPreviousCell(out empty));

                case NavigationDirection.Next:
                    return(PredictNextCell(out empty));

                case NavigationDirection.PreviousInSelection:
                    return(PredictPreviousCellInSelection(out empty, out rangeIndex));

                case NavigationDirection.NextInSelection:
                    return(PredictNextCellInSelection(out empty, out rangeIndex));

                case NavigationDirection.FirstRow:
                    return(PredictFirstRowCell(out empty));

                case NavigationDirection.LastRow:
                    return(PredictLastRowCell(out empty));

                case NavigationDirection.NextRow:
                    return(PredictNextRowCell(out empty));

                case NavigationDirection.PreviousRow:
                    return(PredictPreviousRowCell(out empty));
                }
            }
            return(CompositePosition.Empty);
        }
Exemple #20
0
        CompositePosition PredictNextCell(out CompositePosition newStartPosition)
        {
            CompositePosition startCellPosition = _startNavigateCellPosition;

            if (CurrentCell.IsEmpty)
            {
                startCellPosition = new CompositePosition(DataSheetElementType.Cell, 0, 0);
            }
            List <int>        columnIndexes = GetColumnIndexes();
            CompositePosition position2     = GetNextCellInRow(startCellPosition, false, columnIndexes, out newStartPosition);

            if (position2.IsEmpty)
            {
                for (int i = startCellPosition.Row + 1; i < CompositeRowCount; i++)
                {
                    position2 = GetNextCellInRow(new CompositePosition(startCellPosition.Type, i, columnIndexes[0]), true, columnIndexes, out newStartPosition);
                    if (!position2.IsEmpty)
                    {
                        return(position2);
                    }
                }
            }
            return(position2);
        }
Exemple #21
0
 public abstract int GetRowSpan(CompositePosition position);
Exemple #22
0
 public abstract bool IsMerged(CompositePosition position, out CompositePosition topLeftPosition);
Exemple #23
0
 public abstract int GetColumnSpan(CompositePosition position);
Exemple #24
0
 public virtual bool CanMoveCurrentTo(CompositePosition cellPosition)
 {
     return(true);
 }
Exemple #25
0
 public abstract void BringCellToVisible(CompositePosition position);