예제 #1
0
        public static IList <SpreadChartBase> GetChartShapeAffectedCellChanged(Worksheet worksheet, int row, int column, int rowCount, int columnCount)
        {
            List <SpreadChartBase> list  = new List <SpreadChartBase>();
            List <SpreadChartBase> list2 = new List <SpreadChartBase>();

            foreach (SpreadChart chart in worksheet.Charts)
            {
                list.Add(chart);
            }
            CellRange range = new CellRange(row, column, rowCount, columnCount);

            foreach (SpreadChartBase base2 in list)
            {
                SheetCellRange[] rangeArray = null;
                if (base2 is SpreadChart)
                {
                    rangeArray = SheetCellRangeUtility.ExtractAllExternalReference(worksheet, (base2 as SpreadChart).Formula);
                }
                if ((rangeArray != null) && (rangeArray != null))
                {
                    foreach (SheetCellRange range2 in rangeArray)
                    {
                        if ((range2.Sheet == worksheet) && range.Intersects(range2.Row, range2.Column, range2.RowCount, range2.ColumnCount))
                        {
                            list2.Add(base2);
                            break;
                        }
                    }
                }
            }
            return((IList <SpreadChartBase>)list2);
        }
 // remove merges that contain a given range
 public void RemoveRange(CellRange sel)
 {
     for (var i = 0; i < _ranges.Count; i++)
     {
         if (sel.Intersects(_ranges[i]))
         {
             _ranges.RemoveAt(i);
             i--;
         }
     }
 }
예제 #3
0
 void Worksheet_RowChanged(object sender, SheetChangedEventArgs e)
 {
     if (this._cachRange != null)
     {
         CellRange range = new CellRange(this._cachRange.Row, -1, this._cachRange.RowCount, -1);
         if (range.Intersects(e.Row, e.Column, e.RowCount, e.ColumnCount) && (e.PropertyName == "IsVisible"))
         {
             this.ClearCache();
             this.OnDataChanged();
         }
     }
 }
예제 #4
0
 void Worksheet_CellChanged(object sender, CellChangedEventArgs e)
 {
     if (((this._cachRange != null) && (e.PropertyName == "Value")) && (this._cachRange != null))
     {
         CellRange range = new CellRange(e.Row, e.Column, e.RowCount, e.ColumnCount);
         if (range.Intersects(this._cachRange.Row, this._cachRange.Column, this._cachRange.RowCount, this._cachRange.ColumnCount))
         {
             this.ClearCache();
             this.OnDataChanged();
         }
     }
 }
예제 #5
0
 public void RemoveMergedRange(CellRange rng)
 {
     for (int i = 0; i < _mergedRanges.Count; i++)
     {
         if (rng.Intersects(_mergedRanges[i]))
         {
             _mergedRanges.RemoveAt(i);
             i--;
         }
     }
     _grid.Invalidate();
 }
예제 #6
0
 CellRange ExpandRange(List <CellRange> spans, CellRange range)
 {
     if ((spans != null) && (spans.Count > 0))
     {
         for (int i = 0; i < spans.Count; i++)
         {
             CellRange range2 = spans[i];
             if (range.Intersects(range2.Row, range2.Column, range2.RowCount, range2.ColumnCount))
             {
                 spans.RemoveAt(i--);
                 return(ExpandRange(spans, CellRangeUnion(range, range2)));
             }
         }
     }
     return(range);
 }
예제 #7
0
 internal bool IntersectsInternal(int row, int column, int rowCount, int columnCount, out int rangeIndex)
 {
     if (this.ranges != null)
     {
         for (int i = 0; i < this.ranges.Length; i++)
         {
             CellRange range = this.ranges[i];
             if ((range != null) && range.Intersects(row, column, rowCount, columnCount))
             {
                 rangeIndex = i;
                 return(true);
             }
         }
     }
     rangeIndex = -1;
     return(false);
 }
예제 #8
0
        internal Rect GetRangeBounds(CellRange range, out bool isLeftVisible, out bool isRightVisible, out bool isTopVisible, out bool isBottomVisible)
        {
            isLeftVisible   = true;
            isRightVisible  = true;
            isTopVisible    = true;
            isBottomVisible = true;
            RowLayoutModel    rowLayoutModel            = GetRowLayoutModel();
            ColumnLayoutModel viewportColumnLayoutModel = Excel.GetViewportColumnLayoutModel(ColumnViewportIndex);
            int row    = (rowLayoutModel.Count > 0) ? rowLayoutModel[0].Row : -1;
            int num2   = (rowLayoutModel.Count > 0) ? rowLayoutModel[rowLayoutModel.Count - 1].Row : -1;
            int column = (viewportColumnLayoutModel.Count > 0) ? viewportColumnLayoutModel[0].Column : -1;
            int num4   = (viewportColumnLayoutModel.Count > 0) ? viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].Column : -1;

            if (!range.Intersects(row, column, (num2 - row) + 1, (num4 - column) + 1))
            {
                return(Rect.Empty);
            }
            int          index   = Math.Max(range.Row, row);
            int          num6    = Math.Max(range.Column, column);
            int          num7    = Math.Min((range.Row + range.RowCount) - 1, num2);
            int          num8    = Math.Min((range.Column + range.ColumnCount) - 1, num4);
            RowLayout    layout  = rowLayoutModel.Find(index);
            RowLayout    layout2 = rowLayoutModel.Find(num7);
            ColumnLayout layout3 = viewportColumnLayoutModel.Find(num6);
            ColumnLayout layout4 = viewportColumnLayoutModel.Find(num8);
            double       x       = -1.0;
            double       y       = -1.0;
            double       height  = 0.0;
            double       width   = 0.0;

            if ((layout != null) && (layout2 != null))
            {
                y      = layout.Y;
                height = (layout2.Y + layout2.Height) - layout.Y;
            }
            else if (rowLayoutModel.Count > 0)
            {
                y      = rowLayoutModel[0].Y;
                height = (rowLayoutModel[rowLayoutModel.Count - 1].Y + rowLayoutModel[rowLayoutModel.Count - 1].Height) - y;
            }
            if ((layout3 != null) && (layout4 != null))
            {
                x     = layout3.X;
                width = (layout4.X + layout4.Width) - layout3.X;
            }
            else if (viewportColumnLayoutModel.Count > 0)
            {
                x     = viewportColumnLayoutModel[0].X;
                width = (viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].X + viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].Width) - x;
            }
            if (range.Column < column)
            {
                isLeftVisible = false;
            }
            if (range.Row < row)
            {
                isTopVisible = false;
            }
            if ((num4 != -1) && (((range.Column + range.ColumnCount) - 1) > num4))
            {
                isRightVisible = false;
            }
            if ((num2 != -1) && (((range.Row + range.RowCount) - 1) > num2))
            {
                isBottomVisible = false;
            }
            return(new Rect(PointToClient(new Point(x, y)), new Size(width, height)));
        }
예제 #9
0
        internal Rect GetRangeBounds(CellRange range, SheetArea area)
        {
            SheetSpanModel spanModel = null;

            if (Excel.ActiveSheet != null)
            {
                switch (area)
                {
                case SheetArea.Cells:
                    spanModel = Excel.ActiveSheet.SpanModel;
                    break;

                case (SheetArea.CornerHeader | SheetArea.RowHeader):
                    spanModel = Excel.ActiveSheet.RowHeaderSpanModel;
                    break;

                case SheetArea.ColumnHeader:
                    spanModel = Excel.ActiveSheet.ColumnHeaderSpanModel;
                    break;
                }
            }
            if (spanModel != null)
            {
                CellRange range2 = spanModel.Find(range.Row, range.Column);
                if (((range2 != null) && (range2.RowCount >= range.RowCount)) && (range2.ColumnCount >= range.ColumnCount))
                {
                    range = range2;
                }
            }
            RowLayoutModel    rowLayoutModel    = Excel.GetRowLayoutModel(RowViewportIndex, area);
            ColumnLayoutModel columnLayoutModel = Excel.GetColumnLayoutModel(ColumnViewportIndex, area);
            int row    = (rowLayoutModel.Count > 0) ? rowLayoutModel[0].Row : -1;
            int num2   = (rowLayoutModel.Count > 0) ? rowLayoutModel[rowLayoutModel.Count - 1].Row : -1;
            int column = (columnLayoutModel.Count > 0) ? columnLayoutModel[0].Column : -1;
            int num4   = (columnLayoutModel.Count > 0) ? columnLayoutModel[columnLayoutModel.Count - 1].Column : -1;

            if (!range.Intersects(row, column, (num2 - row) + 1, (num4 - column) + 1))
            {
                return(Rect.Empty);
            }
            int          index   = Math.Max(range.Row, row);
            int          num6    = Math.Max(range.Column, column);
            int          num7    = Math.Min((range.Row + range.RowCount) - 1, num2);
            int          num8    = Math.Min((range.Column + range.ColumnCount) - 1, num4);
            RowLayout    layout  = rowLayoutModel.Find(index);
            RowLayout    layout2 = rowLayoutModel.Find(num7);
            ColumnLayout layout3 = columnLayoutModel.Find(num6);
            ColumnLayout layout4 = columnLayoutModel.Find(num8);
            double       x       = -1.0;
            double       y       = -1.0;
            double       height  = 0.0;
            double       width   = 0.0;

            if ((layout != null) && (layout2 != null))
            {
                y      = layout.Y;
                height = (layout2.Y + layout2.Height) - layout.Y;
            }
            else if (rowLayoutModel.Count > 0)
            {
                y      = rowLayoutModel[0].Y;
                height = (rowLayoutModel[rowLayoutModel.Count - 1].Y + rowLayoutModel[rowLayoutModel.Count - 1].Height) - y;
            }
            if ((layout3 != null) && (layout4 != null))
            {
                x     = layout3.X;
                width = (layout4.X + layout4.Width) - layout3.X;
            }
            else if (columnLayoutModel.Count > 0)
            {
                x     = columnLayoutModel[0].X;
                width = (columnLayoutModel[columnLayoutModel.Count - 1].X + columnLayoutModel[columnLayoutModel.Count - 1].Width) - x;
            }
            return(new Rect(PointToClient(new Point(x, y)), new Size(width, height)));
        }
예제 #10
0
        void BuildSelection()
        {
            _cachedSelectionLayout.Clear();
            _cachedFocusCellLayout       = _rcEmpty;
            _cachedSelectionFrameLayout  = _rcEmpty;
            _cachedActiveSelectionLayout = _rcEmpty;
            _cachedActiveSelection       = null;
            _activeRow = Excel.ActiveSheet.ActiveRowIndex;
            _activeCol = Excel.ActiveSheet.ActiveColumnIndex;
            _selectionLayer.IsAnchorCellInSelection = false;

            var               indicator      = _selectionLayer.FocusIndicator;
            RowLayoutModel    rowLayoutModel = GetRowLayoutModel();
            ColumnLayoutModel colLayoutModel = Excel.GetViewportColumnLayoutModel(ColumnViewportIndex);

            if (rowLayoutModel == null ||
                rowLayoutModel.Count == 0 ||
                colLayoutModel == null ||
                colLayoutModel.Count == 0)
            {
                indicator.HideAll();
                return;
            }

            CellRange        activeCellRange = GetActiveCellRange();
            List <CellRange> ranges          = new List <CellRange>((IEnumerable <CellRange>)Excel.ActiveSheet.Selections);

            if (ranges.Count == 0)
            {
                ranges.Add(activeCellRange);
            }

            int  rangeCount   = ranges.Count;
            Size viewportSize = GetViewportSize();
            Rect rectViewport = new Rect(0.0, 0.0, viewportSize.Width, viewportSize.Height);

            int topRow    = rowLayoutModel[0].Row;
            int bottomRow = rowLayoutModel[rowLayoutModel.Count - 1].Row;
            int leftCol   = colLayoutModel[0].Column;
            int rightCol  = colLayoutModel[colLayoutModel.Count - 1].Column;

            for (int i = 0; i < rangeCount; i++)
            {
                CellRange range = ranges[i];
                if (range.Contains(_activeRow, _activeCol))
                {
                    _selectionLayer.IsAnchorCellInSelection = true;
                }

                int num7        = (range.Row < 0) ? 0 : range.Row;
                int num8        = (range.Column < 0) ? 0 : range.Column;
                int rowCount    = (range.RowCount < 0) ? Excel.ActiveSheet.RowCount : range.RowCount;
                int columnCount = (range.ColumnCount < 0) ? Excel.ActiveSheet.ColumnCount : range.ColumnCount;
                range = new CellRange(num7, num8, rowCount, columnCount);

                Rect rect2 = GetRangeBounds(range);
                rect2.Intersect(rectViewport);
                if (rect2.IsEmpty)
                {
                    continue;
                }

                _cachedSelectionLayout.Add(new Rect(rect2.Left + 1.0, rect2.Top + 1.0, Math.Max((double)0.0, (double)(rect2.Width - 3.0)), Math.Max((double)0.0, (double)(rect2.Height - 3.0))));
                if (range.Contains(activeCellRange))
                {
                    Rect rect3 = new Rect(rect2.Left + 1.0, rect2.Top + 1.0, Math.Max((double)0.0, (double)(rect2.Width - 3.0)), Math.Max((double)0.0, (double)(rect2.Height - 3.0)));
                    if (_cachedActiveSelectionLayout.IsEmpty || (rangeCount == 1))
                    {
                        _cachedActiveSelectionLayout = rect3;
                        _cachedActiveSelection       = range;
                    }
                    else
                    {
                        Rect rect4 = new Rect(rect3.Left, rect3.Top, rect3.Width, rect3.Height);
                        rect4.Intersect(_cachedActiveSelectionLayout);
                        if (rect4.IsEmpty)
                        {
                            _cachedActiveSelectionLayout = rect3;
                            _cachedActiveSelection       = range;
                        }
                        else if (ContainsRect(rect3, _cachedActiveSelectionLayout))
                        {
                            _cachedActiveSelectionLayout = rect3;
                            _cachedActiveSelection       = range;
                        }
                    }
                }
            }

            Rect rangeBounds = GetRangeBounds(activeCellRange);

            if (!rangeBounds.IsEmpty)
            {
                rangeBounds = new Rect(rangeBounds.Left + 1.0, rangeBounds.Top + 1.0, Math.Max((double)0.0, (double)(rangeBounds.Width - 3.0)), Math.Max((double)0.0, (double)(rangeBounds.Height - 3.0)));
            }
            _cachedFocusCellLayout = rangeBounds;

            // 只一个选择区域
            if (rangeCount == 1)
            {
                CellRange range = ranges[0];
                if (!_selectionLayer.IsAnchorCellInSelection)
                {
                    range = activeCellRange;
                }
                Rect bounds = GetRangeBounds(range);
                bounds.Intersect(rectViewport);
                if (bounds.IsEmpty)
                {
                    indicator.HideAll();
                    return;
                }

                if ((range.Row == -1) && (range.Column == -1))
                {
                    // 全选
                    indicator.Thickness         = 1.0;
                    _cachedSelectionFrameLayout = bounds;
                }
                else if (!_selectionLayer.IsAnchorCellInSelection)
                {
                    indicator.Thickness         = 1.0;
                    _cachedSelectionFrameLayout = new Rect(bounds.Left, bounds.Top, bounds.Width, bounds.Height);
                }
                else
                {
                    indicator.Thickness         = 3.0;
                    _cachedSelectionFrameLayout = new Rect(bounds.Left - 2.0, bounds.Top - 2.0, bounds.Width + 3.0, bounds.Height + 3.0);
                }

                if (!Excel.IsDraggingFill && range.Intersects(topRow, leftCol, rowLayoutModel.Count, colLayoutModel.Count))
                {
                    if (range.Row == -1)
                    {
                        indicator.IsTopVisible    = topRow == 0;
                        indicator.IsBottomVisible = bottomRow == (Excel.ActiveSheet.RowCount - 1);
                    }
                    else
                    {
                        indicator.IsTopVisible = (range.Row >= topRow) && (range.Row <= bottomRow);
                        int num11 = (range.Row + range.RowCount) - 1;
                        indicator.IsBottomVisible = (num11 >= topRow) && (num11 <= bottomRow);
                    }

                    if (range.Column == -1)
                    {
                        indicator.IsLeftVisible  = leftCol == 0;
                        indicator.IsRightVisible = rightCol == (Excel.ActiveSheet.ColumnCount - 1);
                    }
                    else
                    {
                        indicator.IsLeftVisible = (range.Column >= leftCol) && (range.Column <= rightCol);
                        int num12 = (range.Column + range.ColumnCount) - 1;
                        indicator.IsRightVisible = (num12 >= leftCol) && (num12 <= rightCol);
                    }
                }
                else
                {
                    indicator.IsTopVisible    = false;
                    indicator.IsBottomVisible = false;
                    indicator.IsLeftVisible   = false;
                    indicator.IsRightVisible  = false;
                }

                if (Excel.CanUserDragFill)
                {
                    if (!Excel.IsDraggingFill)
                    {
                        if (((bounds.Width == 0.0) || (bounds.Height == 0.0)) || (indicator.Thickness == 1.0))
                        {
                            indicator.IsFillIndicatorVisible = false;
                        }
                        else if ((range.Row != -1) && (range.Column != -1))
                        {
                            bool flag = indicator.IsRightVisible && indicator.IsBottomVisible;
                            if (Excel.InputDeviceType == InputDeviceType.Touch)
                            {
                                flag = false;
                            }
                            indicator.IsFillIndicatorVisible = flag;
                            if (flag)
                            {
                                indicator.FillIndicatorPosition = FillIndicatorPosition.BottomRight;
                            }
                        }
                        else if ((range.Row != -1) && (range.Column == -1))
                        {
                            ViewportInfo viewportInfo = Excel.GetViewportInfo();
                            bool         flag2;
                            if (Excel.ActiveSheet.FrozenColumnCount == 0)
                            {
                                flag2 = (ColumnViewportIndex >= 0) && (ColumnViewportIndex < viewportInfo.ColumnViewportCount);
                            }
                            else
                            {
                                flag2 = (ColumnViewportIndex == -1) || ((ColumnViewportIndex >= 1) && (ColumnViewportIndex < viewportInfo.ColumnViewportCount));
                            }
                            flag2 = flag2 && indicator.IsBottomVisible;
                            if (Excel.InputDeviceType == InputDeviceType.Touch)
                            {
                                flag2 = false;
                            }
                            indicator.IsFillIndicatorVisible = flag2;
                            if (flag2)
                            {
                                indicator.FillIndicatorPosition = FillIndicatorPosition.BottomLeft;
                            }
                        }
                        else if ((range.Column != -1) && (range.Row == -1))
                        {
                            ViewportInfo info2 = Excel.GetViewportInfo();
                            bool         flag3;
                            if (Excel.ActiveSheet.FrozenRowCount == 0)
                            {
                                flag3 = (RowViewportIndex >= 0) && (RowViewportIndex < info2.RowViewportCount);
                            }
                            else
                            {
                                flag3 = (RowViewportIndex == -1) || ((RowViewportIndex >= 1) && (RowViewportIndex < info2.RowViewportCount));
                            }
                            flag3 = flag3 && indicator.IsRightVisible;
                            if (Excel.InputDeviceType == InputDeviceType.Touch)
                            {
                                flag3 = false;
                            }
                            indicator.IsFillIndicatorVisible = flag3;
                            if (flag3)
                            {
                                indicator.FillIndicatorPosition = FillIndicatorPosition.TopRight;
                            }
                        }
                        else
                        {
                            indicator.IsFillIndicatorVisible = false;
                        }
                    }
                }
                else
                {
                    indicator.IsFillIndicatorVisible = false;
                }
                return;
            }

            // 多个选择区域
            Rect rect7 = GetRangeBounds(activeCellRange);

            if (!rect7.IsEmpty)
            {
                indicator.Thickness                = 1.0;
                _cachedSelectionFrameLayout        = rect7;
                _cachedSelectionFrameLayout.Width  = Math.Max((double)0.0, (double)(_cachedSelectionFrameLayout.Width - 1.0));
                _cachedSelectionFrameLayout.Height = Math.Max((double)0.0, (double)(_cachedSelectionFrameLayout.Height - 1.0));
                int num13 = 0;
                int num14 = 0;
                int num15 = 0;
                int num16 = 0;
                for (int j = 0; j < rangeCount; j++)
                {
                    CellRange range4 = ranges[j];
                    if (range4 != null)
                    {
                        if (activeCellRange.Row == range4.Row)
                        {
                            num14 = 1;
                        }
                        if (activeCellRange.Column == range4.Column)
                        {
                            num13 = 1;
                        }
                        if (activeCellRange.Row == ((range4.Row + range4.RowCount) - 1))
                        {
                            num16 = 1;
                        }
                        if (activeCellRange.Column == ((range4.Column + range4.ColumnCount) - 1))
                        {
                            num15 = 1;
                        }
                    }
                }
                _cachedSelectionFrameLayout.Y     += num14;
                _cachedSelectionFrameLayout.Height = Math.Max((double)0.0, (double)(_cachedSelectionFrameLayout.Height - (num14 + num16)));
                _cachedSelectionFrameLayout.X     += num13;
                _cachedSelectionFrameLayout.Width  = Math.Max((double)0.0, (double)(_cachedSelectionFrameLayout.Width - (num13 + num15)));
            }
            indicator.IsBottomVisible        = true;
            indicator.IsTopVisible           = true;
            indicator.IsLeftVisible          = true;
            indicator.IsRightVisible         = true;
            indicator.IsFillIndicatorVisible = false;
        }
예제 #11
0
        void UpdateActiveSelectionLayouts()
        {
            Rect      rcSelection = _owner._cachedActiveSelectionLayout;
            Rect      rcFocus     = _owner._cachedFocusCellLayout;
            CellRange range       = null;

            _activeSelectionLayouts.Clear();
            CellRange viewportRange = GetViewportRange();

            if (_owner.IsActived && (_owner.Excel.ActiveSheet.ActiveCell != null))
            {
                Worksheet ws = _owner.Excel.ActiveSheet;
                range = new CellRange(ws.ActiveRowIndex, ws.ActiveColumnIndex, 1, 1);
                CellRange range3 = ws.SpanModel.Find(range.Row, range.Column);
                if ((range3 != null) && viewportRange.Intersects(range3.Row, range3.Column, range3.RowCount, range3.ColumnCount))
                {
                    range = CellRange.GetIntersect(viewportRange, range3, viewportRange.RowCount, viewportRange.ColumnCount);
                }
            }

            if (_owner.IsActived)
            {
                if ((viewportRange.RowCount == 0) || (viewportRange.ColumnCount == 0))
                {
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                }
                else if ((range != null) && !viewportRange.Contains(range))
                {
                    _activeSelectionLayouts.Add(rcSelection);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                }
                else if (_owner._cachedActiveSelection != null &&
                         range != null &&
                         IsActiveCellBoundsValid &&
                         _owner._cachedActiveSelection != range &&
                         _owner._cachedActiveSelection.Contains(range))
                {
                    Rect   rect3 = new Rect(rcSelection.X, rcSelection.Y, rcSelection.Width, rcFocus.Y - rcSelection.Y);
                    Rect   rect4 = new Rect(rcSelection.X, rcFocus.Y, rcFocus.X - rcSelection.X, rcFocus.Height);
                    double width = rcSelection.Right - rcFocus.Right;
                    if (width < 0.0)
                    {
                        width = 0.0;
                    }
                    Rect   rect5  = new Rect(rcFocus.Right, rcFocus.Y, width, rcFocus.Height);
                    double height = rcSelection.Bottom - rcFocus.Bottom;
                    if (height < 0.0)
                    {
                        height = 0.0;
                    }
                    Rect rect6 = new Rect(rcSelection.X, rcFocus.Bottom, rcSelection.Width, height);
                    _activeSelectionLayouts.Add(rect3);
                    _activeSelectionLayouts.Add(rect4);
                    _activeSelectionLayouts.Add(rect5);
                    _activeSelectionLayouts.Add(rect6);
                }
                else
                {
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                    _activeSelectionLayouts.Add(Rect.Empty);
                }
            }
            else if ((viewportRange.RowCount == 0) || (viewportRange.ColumnCount == 0))
            {
                _activeSelectionLayouts.Add(Rect.Empty);
                _activeSelectionLayouts.Add(Rect.Empty);
                _activeSelectionLayouts.Add(Rect.Empty);
                _activeSelectionLayouts.Add(Rect.Empty);
            }
            else
            {
                _activeSelectionLayouts.Add(rcSelection);
                _activeSelectionLayouts.Add(Rect.Empty);
                _activeSelectionLayouts.Add(Rect.Empty);
                _activeSelectionLayouts.Add(Rect.Empty);
            }
        }
예제 #12
0
        /// <summary>
        /// Returns an ordered array of CellRange objects, from largest to smallest, that contain the selected cells
        /// with minimal overlap between the ranges.
        /// </summary>
        /// <param name="rowCount">The number of rows in the sheet in which to look.</param>
        /// <param name="columnCount">The number of columns in the sheet in which to look.</param>
        /// <returns>Returns an ordered array of CellRange objects, from largest to smallest, that contain the selected cells with minimal overlap between the ranges.</returns>
        public CellRange[] GetSelections(int rowCount, int columnCount)
        {
            List <CellRange> items = new List <CellRange>((IEnumerable <CellRange>) this.items);
            List <CellRange> list2 = new List <CellRange>();

            while (items.Count > 0)
            {
                CellRange range;
                long      num  = 0L;
                int       num2 = -1;
                for (int i = 0; i < items.Count; i++)
                {
                    long num3;
                    range = items[i];
                    if (range.ColumnCount == -1)
                    {
                        if (range.Column == -1)
                        {
                            num3 = columnCount;
                        }
                        else
                        {
                            num3 = columnCount - range.Column;
                        }
                    }
                    else
                    {
                        num3 = range.ColumnCount;
                    }
                    if (range.RowCount == -1)
                    {
                        if (range.Row == -1)
                        {
                            num3 *= rowCount;
                        }
                        else
                        {
                            num3 *= rowCount - range.Row;
                        }
                    }
                    else
                    {
                        num3 *= range.RowCount;
                    }
                    if (num3 > num)
                    {
                        num2 = i;
                        num  = num3;
                    }
                }
                if (num2 < 0)
                {
                    num2 = items.Count - 1;
                }
                range = items[num2];
                CellRange original = new CellRange(range.Row, range.Column, range.RowCount, range.ColumnCount);
                list2.Add(original);
                items.RemoveAt(num2);
                int num5 = 0;
                int num6 = items.Count;
                while (num5 < num6)
                {
                    range = items[num5];
                    if (original.Intersects(range.Row, range.Column, range.RowCount, range.ColumnCount))
                    {
                        CellRange split = new CellRange(range.Row, range.Column, range.RowCount, range.ColumnCount);
                        items.RemoveAt(num5);
                        this.Split(items, original, split);
                        num6--;
                    }
                    else
                    {
                        num5++;
                    }
                }
            }
            CellRange[] rangeArray = new CellRange[list2.Count];
            if (list2.Count > 0)
            {
                list2.CopyTo(rangeArray);
            }
            return(rangeArray);
        }