Esempio n. 1
0
        CellRange ClipCellRange(CellRange source)
        {
            RowLayoutModel    rowLayoutModel    = OwnPanel.GetRowLayoutModel();
            ColumnLayoutModel columnLayoutModel = GetColumnLayoutModel();
            ICellsSupport     dataContext       = OwnPanel.GetDataContext();
            int row    = Math.Max(rowLayoutModel[0].Row, source.Row);
            int num2   = Math.Min(rowLayoutModel[rowLayoutModel.Count - 1].Row, (source.Row + source.RowCount) - 1);
            int column = Math.Max(columnLayoutModel[0].Column, source.Column);
            int num4   = Math.Min(columnLayoutModel[columnLayoutModel.Count - 1].Column, (source.Column + source.ColumnCount) - 1);

            for (int i = row; i <= num2; i++)
            {
                if (dataContext.Rows[i].ActualHeight > 0.0)
                {
                    row = i;
                    break;
                }
            }
            for (int j = column; j <= num4; j++)
            {
                if (dataContext.Columns[j].ActualWidth > 0.0)
                {
                    column = j;
                    break;
                }
            }
            return(new CellRange(row, column, (num2 - row) + 1, (num4 - column) + 1));
        }
Esempio n. 2
0
        internal Rect GetCellBounds(int p_row, int p_column, bool p_ignoreMerged)
        {
            if (Excel == null)
            {
                return(new Rect());
            }

            // 包含合并情况
            CellLayoutModel model = null;

            if (!p_ignoreMerged)
            {
                model = Excel.GetCellLayoutModel(RowViewportIndex, ColumnViewportIndex, SheetArea.Cells);
            }
            CellLayout layout = (model == null) ? null : model.FindCell(p_row, p_column);

            if (layout != null)
            {
                return(new Rect(layout.X, layout.Y, layout.Width, layout.Height));
            }

            RowLayoutModel    rowLayoutModel    = Excel.GetRowLayoutModel(RowViewportIndex, SheetArea.Cells);
            ColumnLayoutModel columnLayoutModel = Excel.GetColumnLayoutModel(ColumnViewportIndex, SheetArea.Cells);

            if (rowLayoutModel == null || columnLayoutModel == null)
            {
                return(new Rect());
            }

            RowLayout    layout2 = rowLayoutModel.Find(p_row);
            ColumnLayout layout3 = columnLayoutModel.Find(p_column);
            double       x       = -1.0;
            double       y       = -1.0;
            double       width   = 0.0;
            double       height  = 0.0;

            if (layout2 != null)
            {
                y      = layout2.Y;
                height = layout2.Height;
            }
            if (layout3 != null)
            {
                x     = layout3.X;
                width = layout3.Width;
            }
            return(new Rect(x, y, width, height));
        }
Esempio n. 3
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            RowLayoutModel rowLayoutModel = _owner.GetRowLayoutModel();
            double         y        = 0.0;
            double         rowWidth = 0.0;

            foreach (RowLayout layout in rowLayoutModel)
            {
                if (layout.Height <= 0.0)
                {
                    continue;
                }

                if (_rows.TryGetValue(layout.Row, out var rowItem))
                {
                    // 一定按行的最大高度布局,否则当单元格占多行时在uno上只绘一行!
                    rowItem.Arrange(new Rect(0.0, y, finalSize.Width, rowItem.DesiredSize.Height));
                    if (rowWidth == 0.0)
                    {
                        rowWidth = rowItem.RowWidth;
                    }
                }
                y += layout.Height;
            }

            if (_recycledRows.Count > 0)
            {
                foreach (var rowItem in _recycledRows)
                {
                    rowItem.Arrange(_rcEmpty);
                }
            }

            rowWidth = Math.Min(_owner.GetViewportSize().Width, rowWidth);
            Size size = new Size(rowWidth, y);

            Clip = new RectangleGeometry {
                Rect = new Rect(new Point(), size)
            };
            return(size);
        }
Esempio n. 4
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (_owner.Excel.CanCellOverflow)
            {
                int viewportLeftColumn = _owner.Excel.GetViewportLeftColumn(_owner.ColumnViewportIndex);
                _owner.CellOverflowLayoutBuildEngine.ViewportLeftColumn = viewportLeftColumn;
                int viewportRightColumn = _owner.Excel.GetViewportRightColumn(_owner.ColumnViewportIndex);
                _owner.CellOverflowLayoutBuildEngine.ViewportRightColumn = viewportRightColumn;
            }

            // 频繁增删Children子元素会出现卡顿现象!
            // Children = _rows + _recycledRows
            RowLayoutModel rowLayoutModel = _owner.GetRowLayoutModel();
            int            less           = rowLayoutModel.Count - Children.Count;

            if (less > 0)
            {
                for (int i = 0; i < less; i++)
                {
                    RowItem rowItem = new RowItem(_owner);
                    Children.Add(rowItem);
                    _recycledRows.Add(rowItem);
                }
            }

            // 先回收不可见行
            List <RowItem> rows = _rows.Values.ToList();

            foreach (var rowItem in rows)
            {
                RowLayout layout = rowLayoutModel.FindRow(rowItem.Row);
                if (layout == null || layout.Height <= 0.0)
                {
                    _recycledRows.Add(rowItem);
                    _rows.Remove(rowItem.Row);
                    rowItem.Row = -1;
                    rowItem.CleanUpBeforeDiscard();
                }
            }

            double y    = _owner.Location.Y;
            double left = 0.0;

            foreach (RowLayout layout in rowLayoutModel)
            {
                if (layout.Height <= 0.0)
                {
                    continue;
                }

                bool    updateAllCell = false;
                RowItem rowItem       = null;
                if (!_rows.TryGetValue(layout.Row, out rowItem))
                {
                    // 重新利用回收的行
                    rowItem = _recycledRows[0];
                    _recycledRows.RemoveAt(0);
                    rowItem.Row = layout.Row;
                    _rows.Add(layout.Row, rowItem);
                    updateAllCell = true;
                }
                rowItem.Location = new Point(_owner.Location.X, y);
                rowItem.UpdateChildren(updateAllCell);

                int z = rowItem.ContainsSpanCell ? _spanRowZIndexBase + rowItem.Row : _normalZIndexBase + rowItem.Row;
                z = z % 0x7ffe;
                Canvas.SetZIndex(rowItem, z);

                // 测量尺寸足够大,否则当单元格占多行时在uno上只绘一行!
                rowItem.Measure(availableSize);
                y   += layout.Height;
                left = Math.Max(left, rowItem.DesiredSize.Width);
            }

            // 测量回收的行
            if (_recycledRows.Count > 0)
            {
                foreach (var rowItem in _recycledRows)
                {
                    rowItem.Measure(_szEmpty);
                }
            }
            return(new Size(left + _owner.Location.X, y));
        }
Esempio n. 5
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)));
        }
Esempio n. 6
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)));
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        void ArrangeRowGroups(double buttonSize)
        {
            double num4;
            double y;
            double num3 = Math.Max((double)0.0, (double)((buttonSize - 6.0) / 2.0)) + 2.0;

            _excel.GetSheetLayout();

            RowLayoutModel rowLayoutModel = _excel.GetRowLayoutModel(ViewportIndex, SheetArea.Cells);

            foreach (GroupDotInfo info in _groupDotInfos)
            {
                RowLayout layout = rowLayoutModel.Find(info.Index);
                if ((layout != null) && (layout.Height >= 2.0))
                {
                    num4 = (base.Location.X + (info.Level * buttonSize)) + num3;
                    y    = layout.Y + Math.Max((double)0.0, (double)((layout.Height - 2.0) / 2.0));
                    info.Dot.Arrange(new Rect(base.PointToClient(new Point(num4, y)), _dotSize));
                }
            }
            RangeGroupDirection direction = _excel.ActiveSheet.RowRangeGroup.Direction;

            foreach (GroupLineInfo info2 in _groupLineInfos)
            {
                RowLayout layout2 = rowLayoutModel.FindRow(info2.Start);
                RowLayout layout3 = rowLayoutModel.FindRow(info2.End);
                if ((layout2 != null) && (layout3 != null))
                {
                    Rectangle line = info2.Line;
                    num4 = (base.Location.X + (info2.Level * buttonSize)) + num3;
                    y    = layout2.Y;
                    switch (direction)
                    {
                    case RangeGroupDirection.Forward:
                        y++;
                        break;

                    case RangeGroupDirection.Backward:
                        y--;
                        break;
                    }
                    double num8 = 2.0;
                    double num9 = Math.Max((double)0.0, (double)(((layout3.Y + layout3.Height) - layout2.Y) - 1.0));
                    line.Arrange(new Rect(base.PointToClient(new Point(num4, y)), new Size(num8, num9)));
                    Rectangle startLine = info2.StartLine;
                    if (startLine != null)
                    {
                        double num10 = Math.Min((double)6.0, (double)(buttonSize - 2.0));
                        if (num10 > 0.0)
                        {
                            if (direction == RangeGroupDirection.Backward)
                            {
                                y = (y + num9) - 2.0;
                            }
                            if ((y >= layout2.Y) && (y < (layout3.Y + layout3.Height)))
                            {
                                startLine.Arrange(new Rect(base.PointToClient(new Point(num4, y)), new Size(num10, 2.0)));
                            }
                        }
                    }
                }
            }
            foreach (GroupButtonInfo info3 in _groupButtonInfos)
            {
                RowLayout layout4 = rowLayoutModel.FindRow(info3.Button.Index);
                if (layout4 != null)
                {
                    GroupButton button = info3.Button;
                    double      num11  = Math.Max((double)0.0, (double)((layout4.Height - buttonSize) / 2.0));
                    num4 = (base.Location.X + (button.Level * buttonSize)) + 2.0;
                    y    = layout4.Y + num11;
                    double num12 = buttonSize;
                    double num13 = Math.Min(buttonSize, layout4.Height);
                    button.Arrange(new Rect(base.PointToClient(new Point(num4, y)), new Size(num12, num13)));
                    Rectangle rectangle3 = info3.Line;
                    if ((rectangle3 != null) && (num13 < layout4.Height))
                    {
                        num4 = (base.Location.X + (button.Level * buttonSize)) + num3;
                        y    = layout4.Y;
                        double num14 = 2.0;
                        double num15 = num11;
                        if (info3.LineDirection == RangeGroupDirection.Backward)
                        {
                            y    += num11 + num13;
                            num15 = (layout4.Height - num13) - num11;
                        }
                        rectangle3.Arrange(new Rect(base.PointToClient(new Point(num4, y)), new Size(num14, num15)));
                    }
                }
            }
        }
Esempio n. 9
0
        protected override Size MeasureOverride(Size availableSize)
        {
            BuildSpanGraph();

            // 频繁增删Children子元素会出现卡顿现象!
            // Children = _rows + _recycledRows
            RowLayoutModel rowLayoutModel = GetRowLayoutModel();
            int            less           = rowLayoutModel.Count - Children.Count;

            if (less > 0)
            {
                for (int i = 0; i < less; i++)
                {
                    HeaderItem rowItem = new HeaderItem(this);
                    Children.Add(rowItem);
                    _recycledRows.Add(rowItem);
                }
            }

            // 先回收不可见行
            List <HeaderItem> rows = _rows.Values.ToList();

            foreach (var rowItem in rows)
            {
                RowLayout layout = rowLayoutModel.FindRow(rowItem.Row);
                if (layout == null || layout.Height <= 0.0)
                {
                    _recycledRows.Add(rowItem);
                    _rows.Remove(rowItem.Row);
                    rowItem.Row = -1;
                }
            }

            double x        = Location.X;
            double y        = Location.Y;
            double maxWidth = 0.0;

            foreach (RowLayout layout in rowLayoutModel)
            {
                if (layout.Height <= 0.0)
                {
                    continue;
                }

                bool       updateAllCell = false;
                HeaderItem rowItem       = null;
                if (!_rows.TryGetValue(layout.Row, out rowItem))
                {
                    // 重新利用回收的行
                    rowItem = _recycledRows[0];
                    _recycledRows.RemoveAt(0);
                    rowItem.Row = layout.Row;
                    _rows.Add(layout.Row, rowItem);
                    updateAllCell = true;
                }
                rowItem.UpdateChildren(updateAllCell);

                int z = rowItem.ContainsSpanCell ? _spanRowZIndexBase + rowItem.Row : _normalZIndexBase + rowItem.Row;
                z = z % 0x7ffe;
                Canvas.SetZIndex(rowItem, z);

                rowItem.Location = new Point(x, y);
                // 测量尺寸足够大,否则当单元格占多行时在uno上只绘一行!
                rowItem.Measure(availableSize);
                y       += layout.Height;
                maxWidth = Math.Max(maxWidth, rowItem.DesiredSize.Width);
            }

            // 测量回收的行
            if (_recycledRows.Count > 0)
            {
                foreach (var rowItem in _recycledRows)
                {
                    rowItem.Measure(_szEmpty);
                }
            }
            return(new Size(maxWidth + Location.X, y));
        }