Пример #1
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (Row == -1 || availableSize.Width == 0.0 || availableSize.Height == 0.0)
            {
                foreach (UIElement elem in Children)
                {
                    elem.Measure(_szEmpty);
                }
                return(_szEmpty);
            }

            ColumnLayoutModel       colLayoutModel          = GetColumnLayoutModel();
            RowLayout               layout                  = OwnPanel.GetRowLayoutModel().FindRow(Row);
            CellOverflowLayoutModel cellOverflowLayoutModel = OwnPanel.GetCellOverflowLayoutModel(Row);

            RowWidth = 0.0;
            double height = 0.0;

            foreach (ColumnLayout colLayout in colLayoutModel)
            {
                RowWidth += colLayout.Width;
                CellItem cell = GetCell(colLayout.Column);
                if (cell == null)
                {
                    continue;
                }

                double w = colLayout.Width;
                double h = layout.Height;
                if (cell.CellLayout != null)
                {
                    w = cell.CellLayout.Width;
                    h = cell.CellLayout.Height;
                }

                cell.CellOverflowLayout = null;
                if (cell.CellLayout == null && cellOverflowLayoutModel != null)
                {
                    var cellOverflowLayout = cellOverflowLayoutModel.GetCellOverflowLayout(colLayout.Column);
                    if ((cellOverflowLayout != null) && (cellOverflowLayout.Column == colLayout.Column))
                    {
                        cell.CellOverflowLayout = cellOverflowLayout;
                    }
                }
                cell.Measure(new Size(w, h));
                if (h > height)
                {
                    height = h;
                }
            }

            if (_recycledCells.Count > 0)
            {
                foreach (var cell in _recycledCells)
                {
                    cell.Measure(_szEmpty);
                }
            }

            double width = Math.Min(RowWidth, OwnPanel.GetViewportSize().Width);

            if (cellOverflowLayoutModel != null)
            {
                Worksheet worksheet  = OwnPanel.Excel.ActiveSheet;
                float     zoomFactor = OwnPanel.Excel.ZoomFactor;
                if (cellOverflowLayoutModel.HeadingOverflowlayout != null)
                {
                    HeadingOverflowCell.CellOverflowLayout = cellOverflowLayoutModel.HeadingOverflowlayout;
                    double num8 = worksheet.GetActualColumnWidth(cellOverflowLayoutModel.HeadingOverflowlayout.Column, SheetArea.Cells) * zoomFactor;
                    Size   size = new Size(num8, layout.Height);
                    HeadingOverflowCell.Measure(size);
                }
                if (cellOverflowLayoutModel.TrailingOverflowlayout != null)
                {
                    TrailingOverflowCell.CellOverflowLayout = cellOverflowLayoutModel.TrailingOverflowlayout;
                    double num9  = worksheet.GetActualColumnWidth(cellOverflowLayoutModel.TrailingOverflowlayout.Column, SheetArea.Cells) * zoomFactor;
                    Size   size2 = new Size(num9, layout.Height);
                    TrailingOverflowCell.Measure(size2);
                }
            }
            return(new Size(width, height));
        }
Пример #2
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)));
        }
Пример #3
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)));
                    }
                }
            }
        }
Пример #4
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)));
        }
Пример #5
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));
        }