コード例 #1
0
        internal CellItem GetViewportCell(int row, int column, bool containsSpan)
        {
            CellItem cell      = null;
            RowItem  presenter = _rowsLayer.GetRow(row);

            if (presenter != null)
            {
                cell = presenter.GetCell(column);
            }
            if (containsSpan && (cell == null))
            {
                foreach (RowItem presenter2 in _rowsLayer.Rows)
                {
                    if (presenter2 != null)
                    {
                        foreach (CellItem base3 in presenter2.Cells.Values)
                        {
                            if (((base3 != null) && (base3.CellLayout != null)) && ((base3.CellLayout.Row == row) && (base3.CellLayout.Column == column)))
                            {
                                return(base3);
                            }
                        }
                    }
                }
            }
            return(cell);
        }
コード例 #2
0
ファイル: RowItem.cs プロジェクト: Daoting/dt
 void PushRecycledCell(CellItem cell)
 {
     _recycledCells.Add(cell);
     Cells.Remove(cell.Column);
     cell.Column = -1;
     cell.CleanUpBeforeDiscard();
 }
コード例 #3
0
ファイル: EditingLayer.cs プロジェクト: Daoting/dt
        public void ShowEditor(CellItem p_cell, EditorStatus p_status)
        {
            ResetEditorCell(p_cell, p_status);

            // 双击显示光标,IsHitTestVisible为false可控制光标不显示
            // 保证Editor再次点击时不失去焦点
            Editor.IsHitTestVisible = true;
            Editor.Opacity          = 1.0;

            var       cell = _editingCell.BindingCell;
            StyleInfo info = cell.Worksheet.GetActualStyleInfo(cell.Row.Index, cell.Column.Index, cell.SheetArea, true);

            if (info == null)
            {
                return;
            }

            // Enter状态表示因键盘输入触发,不需要给Editor设置Cell原有的Text
            // Edit状态表示双击触发
            bool isFormula = false;

            if (p_status != EditorStatus.Enter)
            {
                isFormula = ApplyEditorText(info);
            }
            ApplyEditorStyle(info, isFormula);
            Editor.Focus(FocusState.Programmatic);

            InvalidateMeasure();
            InvalidateArrange();
        }
コード例 #4
0
ファイル: CellsPanel-Edit.cs プロジェクト: Daoting/dt
        public void PrepareCellEditing(int row, int column)
        {
#if UWP
            CellItem editingCell = GetViewportCell(row, column, true);
            if (editingCell != null)
            {
                _editorLayer.PrepareEditor(editingCell);
            }
#endif
        }
コード例 #5
0
ファイル: EditingLayer.cs プロジェクト: Daoting/dt
        public void PrepareEditor(CellItem p_cell)
        {
            ResetEditorCell(p_cell, EditorStatus.Ready);

            // false可控制光标不显示
            Editor.IsHitTestVisible = false;
            Editor.Opacity          = 0d;
            Editor.Text             = "";

            InvalidateMeasure();
            InvalidateArrange();
        }
コード例 #6
0
ファイル: EditingLayer.cs プロジェクト: Daoting/dt
        public void HideEditor()
        {
            _editingCell       = null;
            EditorDirty        = false;
            EditorStatus       = EditorStatus.Ready;
            EditingColumnIndex = -2;
            EditingRowIndex    = -2;

            Editor.IsHitTestVisible = false;
            Editor.Opacity          = 0d;
            Editor.Text             = "";

            InvalidateMeasure();
            InvalidateArrange();
        }
コード例 #7
0
ファイル: EditingLayer.cs プロジェクト: Daoting/dt
        void ResetEditorCell(CellItem p_cell, EditorStatus p_status)
        {
            _editingCell = p_cell;
            EditorDirty  = false;
            int row    = p_cell.Row;
            int column = p_cell.Column;

            if (p_cell.CellLayout != null)
            {
                row    = p_cell.CellLayout.Row;
                column = p_cell.CellLayout.Column;
            }
            EditingColumnIndex = column;
            EditingRowIndex    = row;
            EditorStatus       = p_status;
        }
コード例 #8
0
ファイル: CellsPanel-Edit.cs プロジェクト: Daoting/dt
        public bool StartTextInput(int row, int column, EditorStatus status, bool canModifyTextBox, bool selectAll = false, string defaultText = null)
        {
            if (IsEditing())
            {
                return(true);
            }

            CellItem cell = GetViewportCell(row, column, true);

            if (cell == null)
            {
                return(false);
            }

            ShowSheetCell(row, column);
            if (Excel.RaiseEditStarting(row, column))
            {
                return(false);
            }

            _editorLayer.ShowEditor(cell, status);
            _editorLayer.EditingChanged += new EventHandler(_editorPanel_EdtingChanged);

            if (canModifyTextBox)
            {
                var editor = _editorLayer.Editor;
                if (defaultText != null)
                {
                    editor.Text = defaultText;
                }

                if (selectAll)
                {
                    editor.SelectAll();
                }
                else
                {
                    editor.SelectionStart = editor.Text.Length;
                }
            }
            return(true);
        }
コード例 #9
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));
        }
コード例 #10
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
        }
コード例 #11
0
ファイル: FilterButton.cs プロジェクト: Daoting/dt
 public FilterButton(CellItem p_cellView)
 {
     DefaultStyleKey  = typeof(FilterButton);
     IsHitTestVisible = false;
     _owner           = p_cellView;
 }