Beispiel #1
0
        CellOverflowLayoutModel BuildCellOverflowLayoutModel(int rowIndex)
        {
            if (!Viewport.Excel.CanCellOverflow)
            {
                return(null);
            }

            ColumnLayoutModel viewportColumnLayoutModel = Viewport.Excel.GetViewportColumnLayoutModel(Viewport.ColumnViewportIndex);

            if (viewportColumnLayoutModel == null)
            {
                return(null);
            }
            object    textFormattingMode   = null;
            bool      useLayoutRounding    = Viewport.Excel.UseLayoutRounding;
            SpanGraph cachedSpanGraph      = Viewport.CachedSpanGraph;
            CellOverflowLayoutModel result = new CellOverflowLayoutModel();
            CellOverflowLayout      layout = BuildHeadingCellOverflowLayoutModel(rowIndex, viewportColumnLayoutModel, textFormattingMode, useLayoutRounding);

            result.HeadingOverflowlayout = layout;
            for (int i = 0; i < viewportColumnLayoutModel.Count; i++)
            {
                Cell cachedCell;
                CellOverflowLayout layout3;
                CellOverflowLayout layout5;
                ColumnLayout       layout2 = viewportColumnLayoutModel[i];
                if (layout2.Width > 0.0)
                {
                    cachedCell = Viewport.CellCache.GetCachedCell(rowIndex, layout2.Column);
                    if ((((cachedCell != null) && !string.IsNullOrEmpty(cachedCell.Text)) && (!cachedCell.ActualWordWrap && !cachedCell.ActualShrinkToFit)) && (cachedSpanGraph.GetState(rowIndex, layout2.Column) == 0))
                    {
                        switch (cachedCell.ToHorizontalAlignment())
                        {
                        case HorizontalAlignment.Left:
                        case HorizontalAlignment.Stretch:
                        {
                            int deadColumnIndex     = Enumerable.Last <ColumnLayout>((IEnumerable <ColumnLayout>)viewportColumnLayoutModel).Column + 1;
                            CellOverflowLayout item = BuildCellOverflowLayoutModelForLeft(cachedCell, rowIndex, false, deadColumnIndex, textFormattingMode, useLayoutRounding);
                            if (item != null)
                            {
                                result.Add(item);
                                int index = viewportColumnLayoutModel.IndexOf(viewportColumnLayoutModel.FindColumn(item.EndingColumn));
                                if (index > -1)
                                {
                                    i = index;
                                }
                            }
                            break;
                        }

                        case HorizontalAlignment.Center:
                        {
                            layout3 = new CellOverflowLayout(layout2.Column, 0.0);
                            int num3 = Enumerable.Last <ColumnLayout>((IEnumerable <ColumnLayout>)viewportColumnLayoutModel).Column + 1;
                            CellOverflowLayout layout4 = BuildCellOverflowLayoutModelForLeft(cachedCell, rowIndex, true, num3, textFormattingMode, useLayoutRounding);
                            num3    = viewportColumnLayoutModel[0].Column - 1;
                            layout5 = BuildCellOverflowLayoutModelForRight(cachedCell, rowIndex, result, true, num3, textFormattingMode, useLayoutRounding);
                            if (layout4 == null)
                            {
                                goto Label_01C1;
                            }
                            layout3.EndingColumn         = layout4.EndingColumn;
                            layout3.BackgroundWidth     += layout4.BackgroundWidth;
                            layout3.RightBackgroundWidth = layout4.RightBackgroundWidth;
                            goto Label_01E0;
                        }

                        case HorizontalAlignment.Right:
                        {
                            int num6 = viewportColumnLayoutModel[0].Column - 1;
                            CellOverflowLayout layout7 = BuildCellOverflowLayoutModelForRight(cachedCell, rowIndex, result, false, num6, textFormattingMode, useLayoutRounding);
                            if (layout7 != null)
                            {
                                result.Add(layout7);
                            }
                            break;
                        }
                        }
                    }
                }
                continue;
Label_01C1:
                layout3.BackgroundWidth += layout2.Width / 2.0;
Label_01E0:
                if (layout5 != null)
                {
                    layout3.StartingColumn      = layout5.StartingColumn;
                    layout3.BackgroundWidth    += layout5.BackgroundWidth;
                    layout3.LeftBackgroundWidth = layout5.LeftBackgroundWidth;
                }
                else
                {
                    layout3.BackgroundWidth += layout2.Width / 2.0;
                }
                if (layout3.BackgroundWidth > layout2.Width)
                {
                    Size textSize = MeasureHelper.MeasureTextInCell(cachedCell, new Size(double.PositiveInfinity, double.PositiveInfinity), (double)Viewport.Excel.ZoomFactor, null, textFormattingMode, useLayoutRounding);
                    layout3.ContentWidth = MeasureHelper.ConvertTextSizeToExcelCellSize(textSize, (double)Viewport.Excel.ZoomFactor).Width;
                    result.Add(layout3);
                }
            }
            result.TrailingOverflowlayout = BuildTrailingCellOverflowLayoutModel(rowIndex, viewportColumnLayoutModel, result, textFormattingMode, useLayoutRounding);
            if (((result.Count <= 0) && (result.HeadingOverflowlayout == null)) && (result.TrailingOverflowlayout == null))
            {
                return(null);
            }
            return(result);
        }
Beispiel #2
0
        //*** CellsPanel.Measure -> RowsLayer.Measure -> RowItem.UpdateChildren -> 行列改变时 CellItem.UpdateChildren -> RowItem.Measure -> CellItem.Measure ***//

        public void UpdateChildren(bool p_updateAllCell)
        {
            // 频繁增删Children子元素会出现卡顿现象!
            // Children = Cells + _recycledCells
            ColumnLayoutModel colLayoutModel = GetColumnLayoutModel();
            int less = colLayoutModel.Count - Children.Count + (_headingOverflowCell == null ? 0 : 1) + (_trailingOverflowCell == null ? 0 : 1);

            if (less > 0)
            {
                for (int i = 0; i < less; i++)
                {
                    var cell = new CellItem(this);
                    Children.Add(cell);
                    _recycledCells.Add(cell);
                }
            }

            // 先回收不可见格
            var cols = Cells.Values.ToList();

            foreach (var cell in cols)
            {
                ColumnLayout layout = colLayoutModel.FindColumn(cell.Column);
                if (layout == null || layout.Width <= 0.0)
                {
                    PushRecycledCell(cell);
                }
            }

            int updateCells = 0;

            ContainsSpanCell = false;
            SpanGraph cachedSpanGraph = OwnPanel.CachedSpanGraph;

            for (int i = 0; i < colLayoutModel.Count; i++)
            {
                ColumnLayout colLayout = colLayoutModel[i];
                if (colLayout.Width <= 0.0)
                {
                    continue;
                }

                byte       state  = cachedSpanGraph.GetState(Row, colLayout.Column);
                CellLayout layout = null;
                if (state > 0)
                {
                    CellLayoutModel cellLayoutModel = OwnPanel.GetCellLayoutModel();
                    if (cellLayoutModel != null)
                    {
                        layout = cellLayoutModel.FindCell(Row, colLayout.Column);
                        if (layout != null)
                        {
                            ContainsSpanCell = true;
                        }
                    }
                }

                CellItem cell         = GetCell(colLayout.Column);
                bool     rangeChanged = false;
                if (layout != null && layout.Width > 0.0 && layout.Height > 0.0)
                {
                    CellRange range = ClipCellRange(layout.GetCellRange());
                    rangeChanged = (Row != range.Row) || (range.Column != colLayout.Column);

                    // 跨多列
                    if (layout.ColumnCount > 1)
                    {
                        // 移除跨度区域内的所有格
                        int maxCol = (layout.Column + layout.ColumnCount) - 1;
                        for (int j = i + 1; j < colLayoutModel.Count; j++)
                        {
                            int curCol = colLayoutModel[j].Column;
                            if (curCol > maxCol)
                            {
                                break;
                            }

                            i = j;
                            CellItem ci = GetCell(curCol);
                            if (ci != null)
                            {
                                PushRecycledCell(ci);
                            }
                        }
                    }
                }

                // 跨度不同不显示
                if (rangeChanged)
                {
                    if (cell != null)
                    {
                        PushRecycledCell(cell);
                    }
                    continue;
                }

                bool updated = false;
                if (cell == null)
                {
                    // 重新利用回收的格
                    cell = _recycledCells[0];
                    _recycledCells.RemoveAt(0);
                    cell.Column = colLayout.Column;
                    Cells.Add(colLayout.Column, cell);
                    updated = true;
                }
                cell.CellLayout = layout;

                if (p_updateAllCell || updated)
                {
                    cell.UpdateChildren();
                    updateCells++;
                }
            }

            CellOverflowLayoutModel cellOverflowLayoutModel = OwnPanel.GetCellOverflowLayoutModel(Row);

            if ((cellOverflowLayoutModel != null) && !cellOverflowLayoutModel.IsEmpty)
            {
                if (cellOverflowLayoutModel.HeadingOverflowlayout != null)
                {
                    if (HeadingOverflowCell == null)
                    {
                        HeadingOverflowCell = new CellItem(this);
                    }
                    if (HeadingOverflowCell.Column != cellOverflowLayoutModel.HeadingOverflowlayout.Column)
                    {
                        HeadingOverflowCell.Column = cellOverflowLayoutModel.HeadingOverflowlayout.Column;
                        HeadingOverflowCell.UpdateChildren();
                        updateCells++;
                    }
                }
                else
                {
                    HeadingOverflowCell = null;
                }

                if (cellOverflowLayoutModel.TrailingOverflowlayout != null)
                {
                    if (TrailingOverflowCell == null)
                    {
                        TrailingOverflowCell = new CellItem(this);
                    }
                    if (TrailingOverflowCell.Column != cellOverflowLayoutModel.TrailingOverflowlayout.Column)
                    {
                        TrailingOverflowCell.Column = cellOverflowLayoutModel.TrailingOverflowlayout.Column;
                        TrailingOverflowCell.UpdateChildren();
                        updateCells++;
                    }
                }
                else
                {
                    TrailingOverflowCell = null;
                }
            }
            else
            {
                HeadingOverflowCell  = null;
                TrailingOverflowCell = null;
            }

#if !IOS
            // iOS在 MeasureOverride 内部调用子元素的 InvalidateMeasure 会造成死循环!
            // 不重新测量会造成如:迷你图忽大忽小的情况
            if (updateCells > 0)
            {
                InvalidateMeasure();
            }
#endif
        }
Beispiel #3
0
        void ArrangeColumnGroups(double buttonSize)
        {
            double            x;
            double            num5;
            double            num3 = Math.Max((double)0.0, (double)((buttonSize - 6.0) / 2.0)) + 2.0;
            ColumnLayoutModel columnLayoutModel = _excel.GetColumnLayoutModel(ViewportIndex, SheetArea.Cells);

            foreach (GroupDotInfo info in _groupDotInfos)
            {
                ColumnLayout layout = columnLayoutModel.FindColumn(info.Index);
                if ((layout != null) && (layout.Width >= 2.0))
                {
                    x    = layout.X + Math.Max((double)0.0, (double)((layout.Width - 2.0) / 2.0));
                    num5 = (Location.Y + (info.Level * buttonSize)) + num3;
                    info.Dot.Arrange(new Rect(PointToClient(new Point(x, num5)), _dotSize));
                }
            }

            RangeGroupDirection direction = _excel.ActiveSheet.ColumnRangeGroup.Direction;

            foreach (GroupLineInfo info2 in _groupLineInfos)
            {
                ColumnLayout layout2 = columnLayoutModel.FindColumn(info2.Start);
                ColumnLayout layout3 = columnLayoutModel.FindColumn(info2.End);
                if ((layout2 != null) && (layout3 != null))
                {
                    Rectangle line = info2.Line;
                    x = layout2.X;
                    switch (direction)
                    {
                    case RangeGroupDirection.Forward:
                        x++;
                        break;

                    case RangeGroupDirection.Backward:
                        x--;
                        break;
                    }
                    num5 = (base.Location.Y + (info2.Level * buttonSize)) + num3;
                    double num8 = Math.Max((double)0.0, (double)(((layout3.X + layout3.Width) - layout2.X) - 1.0));
                    double num9 = 2.0;
                    line.Arrange(new Rect(base.PointToClient(new Point(x, num5)), 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)
                            {
                                x = (x + num8) - 2.0;
                            }
                            if ((x >= layout2.X) && (x < (layout3.X + layout3.Width)))
                            {
                                startLine.Arrange(new Rect(base.PointToClient(new Point(x, num5)), new Size(2.0, num10)));
                            }
                        }
                    }
                }
            }

            foreach (GroupButtonInfo info3 in _groupButtonInfos)
            {
                GroupButton  button  = info3.Button;
                ColumnLayout layout4 = columnLayoutModel.FindColumn(button.Index);
                if (layout4 != null)
                {
                    double num11 = Math.Max((double)0.0, (double)((layout4.Width - buttonSize) / 2.0));
                    x    = layout4.X + num11;
                    num5 = (base.Location.Y + (button.Level * buttonSize)) + 2.0;
                    double num12 = Math.Min(buttonSize, layout4.Width);
                    double num13 = buttonSize;
                    button.Arrange(new Rect(base.PointToClient(new Point(x, num5)), new Size(num12, num13)));
                    Rectangle rectangle3 = info3.Line;
                    if ((rectangle3 != null) && (num12 < layout4.Width))
                    {
                        x    = layout4.X;
                        num5 = (base.Location.Y + (button.Level * buttonSize)) + num3;
                        double num14 = num11;
                        double num15 = 2.0;
                        if (info3.LineDirection == RangeGroupDirection.Backward)
                        {
                            x    += num11 + num12;
                            num14 = (layout4.Width - num12) - num11;
                        }
                        rectangle3.Arrange(new Rect(base.PointToClient(new Point(x, num5)), new Size(num14, num15)));
                    }
                }
            }
        }