예제 #1
0
파일: RowItem.cs 프로젝트: Daoting/dt
        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));
        }
예제 #2
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (Row == -1 || finalSize.Width == 0 || finalSize.Height == 0)
            {
                if (Children.Count > 0)
                {
                    foreach (UIElement elem in Children)
                    {
                        elem.Arrange(_rcEmpty);
                    }
                }
                return(finalSize);
            }

            ColumnLayoutModel colLayoutModel = GetColumnLayoutModel();
            RowLayout         layout         = Owner.GetRowLayoutModel().FindRow(Row);

            foreach (ColumnLayout colLayout in colLayoutModel)
            {
                if (colLayout.Width <= 0.0)
                {
                    continue;
                }

                HeaderCellItem cell = GetCell(colLayout.Column);
                if (cell != null)
                {
                    double x      = colLayout.X;
                    double y      = layout.Y;
                    double width  = colLayout.Width;
                    double height = layout.Height;
                    int    num5   = 0x2710 + colLayout.Column;

                    CellLayout cellLayout = cell.CellLayout;
                    if (cellLayout != null)
                    {
                        x      = cellLayout.X;
                        y      = cellLayout.Y;
                        width  = cellLayout.Width;
                        height = cellLayout.Height;
                        num5   = 0x4e20 + colLayout.Column;
                    }
                    num5 = num5 % 0x7ffe;
                    Canvas.SetZIndex(cell, num5);
                    cell.Arrange(new Rect(x - Location.X, y - Location.Y, width, height));
                }
            }

            if (_recycledCells.Count > 0)
            {
                foreach (var cell in _recycledCells)
                {
                    cell.Arrange(_rcEmpty);
                }
            }
            return(finalSize);
        }
예제 #3
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (Row == -1 ||
                availableSize.Width == 0.0 ||
                availableSize.Height == 0.0)
            {
                return(new Size());
            }

            ColumnLayoutModel colLayoutModel = GetColumnLayoutModel();
            RowLayout         layout         = Owner.GetRowLayoutModel().FindRow(Row);

            RowWidth = 0.0;
            double height = 0.0;

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

                CellLayout cellLayout = cell.CellLayout;
                if (cellLayout != null)
                {
                    cell.Measure(new Size(cellLayout.Width, cellLayout.Height));
                    if (cellLayout.Height > height)
                    {
                        height = cellLayout.Height;
                    }
                }
                else
                {
                    cell.Measure(new Size(colLayout.Width, layout.Height));
                    if (layout.Height > height)
                    {
                        height = layout.Height;
                    }
                }
            }

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

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

            return(new Size(width, height));
        }
예제 #4
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));
        }
예제 #5
0
파일: RowItem.cs 프로젝트: Daoting/dt
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (Row == -1 || finalSize.Width == 0 || finalSize.Height == 0)
            {
                foreach (UIElement elem in Children)
                {
                    elem.Arrange(_rcEmpty);
                }
                return(finalSize);
            }

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

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

                double left   = colLayout.X;
                double top    = layout.Y;
                double w      = colLayout.Width;
                double h      = layout.Height;
                int    zIndex = _normalCellZIndexBase + colLayout.Column;

                CellLayout cellLayout = cell.CellLayout;
                if (cellLayout != null)
                {
                    left   = cellLayout.X;
                    top    = cellLayout.Y;
                    w      = cellLayout.Width;
                    h      = cellLayout.Height;
                    zIndex = _spanCellZIndexBase + colLayout.Column;
                }

                // Canvas.SetZIndex 对所有继承自 Panel 的面板都有效,z值大的在上层,z值相同时按 Children 的索引,索引大的在上层
                // 但uno中 Canvas.SetZIndex 无效,只按 Children 的索引确定层次!
                if (cell.CellOverflowLayout != null)
                {
                    zIndex = _flowCellZIndexBase + colLayout.Column;
                }
                zIndex = zIndex % 0x7ffe;
                Canvas.SetZIndex(cell, zIndex);

                cell.Arrange(new Rect(left - Location.X, top - Location.Y, w, h));
            }

            if (_recycledCells.Count > 0)
            {
                foreach (var cell in _recycledCells)
                {
                    cell.Arrange(_rcEmpty);
                }
            }

            CellOverflowLayoutModel cellOverflowLayoutModel = OwnPanel.GetCellOverflowLayoutModel(Row);

            if (cellOverflowLayoutModel == null)
            {
                return(finalSize);
            }

            Worksheet worksheet  = OwnPanel.Excel.ActiveSheet;
            float     zoomFactor = OwnPanel.Excel.ZoomFactor;

            if (cellOverflowLayoutModel.HeadingOverflowlayout != null)
            {
                double num7 = Location.X;
                double num8 = layout.Y;
                for (int j = cellOverflowLayoutModel.HeadingOverflowlayout.Column; j < colLayoutModel[0].Column; j++)
                {
                    double actualColumnWidth = worksheet.GetActualColumnWidth(j, SheetArea.Cells);
                    num7 -= actualColumnWidth * zoomFactor;
                }
                double num12 = worksheet.GetActualColumnWidth(cellOverflowLayoutModel.HeadingOverflowlayout.Column, SheetArea.Cells) * zoomFactor;
                Size   size  = new Size(num12, layout.Height);
                Rect   rect  = new Rect(PointToClient(new Point(num7, num8)), size);
                int    num13 = _flowCellZIndexBase + cellOverflowLayoutModel.HeadingOverflowlayout.Column;
                num13 = num13 % 0x7ffe;
                Canvas.SetZIndex(HeadingOverflowCell, num13);
                HeadingOverflowCell.Arrange(rect);
            }
            if (cellOverflowLayoutModel.TrailingOverflowlayout == null)
            {
                return(finalSize);
            }

            ColumnLayout layout4 = colLayoutModel[colLayoutModel.Count - 1];

            if (layout4 == null)
            {
                return(finalSize);
            }

            double x = layout4.X;
            double y = layout.Y;

            for (int i = layout4.Column; i < cellOverflowLayoutModel.TrailingOverflowlayout.Column; i++)
            {
                x += worksheet.GetActualColumnWidth(i, SheetArea.Cells) * zoomFactor;
            }
            double width = worksheet.GetActualColumnWidth(cellOverflowLayoutModel.TrailingOverflowlayout.Column, SheetArea.Cells) * zoomFactor;
            Size   size2 = new Size(width, layout.Height);
            Rect   rect2 = new Rect(PointToClient(new Point(x, y)), size2);
            int    num18 = _flowCellZIndexBase + cellOverflowLayoutModel.TrailingOverflowlayout.Column;

            num18 = num18 % 0x7ffe;
            Canvas.SetZIndex(TrailingOverflowCell, num18);
            TrailingOverflowCell.Arrange(rect2);
            return(finalSize);
        }
예제 #6
0
파일: RowItem.cs 프로젝트: Daoting/dt
        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));
        }
예제 #7
0
파일: RowItem.cs 프로젝트: Daoting/dt
        //*** 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
        }
예제 #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
        CellOverflowLayout BuildTrailingCellOverflowLayoutModel(int rowIndex, ColumnLayoutModel columnLayoutModel, CellOverflowLayoutModel existed, object textFormattingMode, bool useLayoutRounding)
        {
            ColumnLayout layout = Enumerable.LastOrDefault <ColumnLayout>(columnLayoutModel, delegate(ColumnLayout clm)
            {
                return(clm.Width > 0.0);
            });

            if (layout == null)
            {
                if (columnLayoutModel.Count == 0)
                {
                    return(null);
                }
                layout = columnLayoutModel[0];
            }
            if (!existed.Contains(layout.Column))
            {
                CellOverflowLayout layout2     = new CellOverflowLayout(layout.Column, 0.0);
                ICellsSupport      dataContext = Viewport.GetDataContext();
                SheetSpanModelBase spanModel   = Viewport.GetSpanModel();
                for (int i = 1; i < _maxCellOverflowDistance; i++)
                {
                    int column = layout.Column + i;
                    if (column >= dataContext.Columns.Count)
                    {
                        return(null);
                    }
                    if (dataContext.Columns[column].ActualWidth > 0.0)
                    {
                        if ((spanModel != null) && (spanModel.Find(rowIndex, column) != null))
                        {
                            return(null);
                        }
                        Cell cachedCell = Viewport.CellCache.GetCachedCell(rowIndex, column);
                        if (!string.IsNullOrEmpty(cachedCell.Text))
                        {
                            if (cachedCell.ActualWordWrap)
                            {
                                return(null);
                            }
                            if (cachedCell.ActualShrinkToFit)
                            {
                                return(null);
                            }
                            switch (cachedCell.ToHorizontalAlignment())
                            {
                            case HorizontalAlignment.Left:
                            case HorizontalAlignment.Stretch:
                                return(null);

                            case HorizontalAlignment.Center:
                            {
                                int deadColumnIndex = columnLayoutModel[0].Column - 1;
                                layout2 = BuildCellOverflowLayoutModelForRight(cachedCell, rowIndex, existed, true, deadColumnIndex, textFormattingMode, useLayoutRounding);
                                if ((layout2 == null) || (layout2.StartingColumn > ViewportRightColumn))
                                {
                                    return(null);
                                }
                                layout2.BackgroundWidth += (dataContext.Columns[column].ActualWidth * Viewport.Excel.ZoomFactor) / 2.0;
                                return(layout2);
                            }

                            case HorizontalAlignment.Right:
                            {
                                int num5 = columnLayoutModel[0].Column - 1;
                                layout2 = BuildCellOverflowLayoutModelForRight(cachedCell, rowIndex, existed, false, num5, textFormattingMode, useLayoutRounding);
                                if ((layout2 == null) || (layout2.StartingColumn > ViewportRightColumn))
                                {
                                    return(null);
                                }
                                return(layout2);
                            }
                            }
                            break;
                        }
                    }
                }
            }
            return(null);
        }
예제 #12
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);
        }
예제 #13
0
파일: GcRangeGroup.cs 프로젝트: Daoting/dt
        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)));
                    }
                }
            }
        }