public HeaderPanel(Excel p_excel, SheetArea p_sheetArea) { Area = p_sheetArea; Excel = p_excel; CachedSpanGraph = new SpanGraph(); CellCache = new CellCachePool(GetDataContext()); _rows = new Dictionary <int, HeaderItem>(); _recycledRows = new List <HeaderItem>(); HorizontalAlignment = HorizontalAlignment.Left; VerticalAlignment = VerticalAlignment.Top; }
public CellsPanel(Excel p_excel) { Excel = p_excel; _cachedSelectionLayout = new List <Rect>(); _cachedActiveSelectionLayout = Rect.Empty; _cachedSelectionFrameLayout = new Rect(); _cachedFocusCellLayout = new Rect(); _editorBounds = new Rect(); _cachedDragFillRect = _rcEmpty; _cellCachePool = new CellCachePool(Excel.ActiveSheet); _cachedSpanGraph = new SpanGraph(); //--------------已移除 公式编辑层、图形层、数据校验层------------------- // 1 行数据层 _rowsLayer = new RowsLayer(this); Children.Add(_rowsLayer); // 2 网格层,调整为只用在内容区域,行/列头不再使用 _borderLayer = new BorderLayer(this); Children.Add(_borderLayer); // 3 选择状态层 _selectionLayer = new SelectionLayer(this); Children.Add(_selectionLayer); // 4 拖拽复制层,点击右下角加号复制格内容 _dragFillLayer = CreateDragFillLayer(); Children.Add(_dragFillLayer); // 5 新增修饰层,打印时页面边线 if (p_excel.ShowDecoration) { _decorationLayer = new DecorationLayer(this); Children.Add(_decorationLayer); } // 6 编辑层 _editorLayer = new EditingLayer(this); Children.Add(_editorLayer); // 7 浮动对象层 _floatingLayer = new FloatingObjectLayer(this); Children.Add(_floatingLayer); // 8 浮动对象拖拽移动层 _floatingEditLayer = new FloatingObjectMovingLayer(this); Children.Add(_floatingEditLayer); HorizontalAlignment = HorizontalAlignment.Left; VerticalAlignment = VerticalAlignment.Top; }
//*** 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 }
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); }