Exemplo n.º 1
0
        public bool AddSelectedCell(FastGridCellAddress cell)
        {
            if (!cell.IsCell)
            {
                return(false);
            }

            if (SelectedRealRowCountLimit.HasValue && _selectedRows.Count >= SelectedRealRowCountLimit.Value && !_selectedRows.ContainsKey(cell.Row.Value))
            {
                return(false);
            }
            if (SelectedRealColumnCountLimit.HasValue && _selectedColumns.Count >= SelectedRealColumnCountLimit.Value && !_selectedColumns.ContainsKey(cell.Column.Value))
            {
                return(false);
            }

            if (_selectedCells.Contains(cell))
            {
                return(false);
            }

            _selectedCells.Add(cell);

            if (!_selectedRows.ContainsKey(cell.Row.Value))
            {
                _selectedRows[cell.Row.Value] = 0;
            }
            _selectedRows[cell.Row.Value]++;

            if (!_selectedColumns.ContainsKey(cell.Column.Value))
            {
                _selectedColumns[cell.Column.Value] = 0;
            }
            _selectedColumns[cell.Column.Value]++;

            CheckChangedLimitedSelection();

            return(true);
        }
Exemplo n.º 2
0
 public void InvalidateCell(FastGridCellAddress cell)
 {
     if (cell.IsEmpty)
     {
         return;
     }
     if (cell.IsGridHeader)
     {
         InvalidateGridHeader();
         return;
     }
     if (cell.IsRowHeader)
     {
         InvalidateRowHeader(cell.Row.Value);
         return;
     }
     if (cell.IsColumnHeader)
     {
         InvalidateColumnHeader(cell.Column.Value);
         return;
     }
     InvalidateCell(cell.Row.Value, cell.Column.Value);
 }
Exemplo n.º 3
0
        private void FixCurrentCellAndSetSelectionToCurrentCell()
        {
            int?col = _currentCell.Column;
            int?row = _currentCell.Row;

            if (col.HasValue)
            {
                if (col >= _modelColumnCount)
                {
                    col = _modelColumnCount - 1;
                }
                if (col < 0)
                {
                    col = null;
                }
            }

            if (row.HasValue)
            {
                if (row >= _modelRowCount)
                {
                    row = _modelRowCount - 1;
                }
                if (row < 0)
                {
                    row = null;
                }
            }

            ClearSelectedCells();
            _currentCell = new FastGridCellAddress(row, col);
            if (_currentCell.IsCell)
            {
                AddSelectedCell(_currentCell);
            }
            OnChangeSelectedCells(false);
        }
Exemplo n.º 4
0
        private void imageKeyDown(object sender, KeyEventArgs e)
        {
            if (Model == null)
            {
                return;
            }

            using (var ctx = CreateInvalidationContext())
            {
                if (ShiftPressed)
                {
                    if (!_shiftDragStartCell.IsCell)
                    {
                        _shiftDragStartCell = _currentCell;
                    }
                }
                else
                {
                    _shiftDragStartCell = FastGridCellAddress.Empty;
                }

                bool moved = HandleCursorMove(e);
                if (ShiftPressed && moved)
                {
                    SetSelectedRectangle(_shiftDragStartCell, _currentCell);
                }

                if (e.Key == Key.F2 && _currentCell.IsCell)
                {
                    ShowInlineEditor(_currentCell);
                }
                if (e.Key == Key.A && ControlPressed && AllowSelectAll)
                {
                    SelectAll();
                }
            }
        }
Exemplo n.º 5
0
        public void ScrollIntoView(FastGridCellAddress cell)
        {
            if (cell.Row.HasValue)
            {
                if (cell.Row.Value >= _rowSizes.FrozenCount)
                {
                    int newRow = _rowSizes.ScrollInView(FirstVisibleRowScrollIndex, cell.Row.Value - _rowSizes.FrozenCount, GridScrollAreaHeight);
                    ScrollContent(newRow, FirstVisibleColumnScrollIndex);
                }
            }

            if (cell.Column.HasValue)
            {
                if (cell.Column.Value >= _columnSizes.FrozenCount)
                {
                    int newColumn = _columnSizes.ScrollInView(FirstVisibleColumnScrollIndex, cell.Column.Value - _columnSizes.FrozenCount, GridScrollAreaWidth);
                    ScrollContent(FirstVisibleRowScrollIndex, newColumn);
                }
            }

            AdjustInlineEditorPosition();
            AdjustSelectionMenuPosition();
            AdjustScrollBarPositions();
        }
Exemplo n.º 6
0
 public virtual void HandleCommand(IFastGridView view, FastGridCellAddress address, object commandParameter, ref bool handled)
 {
 }
Exemplo n.º 7
0
        protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            _showCellEditorIfMouseUp = FastGridCellAddress.Empty;

            var pt = e.GetPosition(image);

            pt.X *= DpiDetector.DpiXKoef;
            pt.Y *= DpiDetector.DpiYKoef;
            var cell = GetCellAddress(pt);

            var currentRegion = CurrentCellActiveRegions.FirstOrDefault(x => x.Rect.Contains(pt));

            if (currentRegion != null)
            {
                HandleCommand(cell, currentRegion.CommandParameter);
                return;
            }

            using (var ctx = CreateInvalidationContext())
            {
                int?resizingColumn = GetResizingColumn(pt);
                if (resizingColumn != null)
                {
                    Cursor                   = Cursors.SizeWE;
                    _resizingColumn          = resizingColumn;
                    _resizingColumnOrigin    = pt;
                    _resizingColumnStartSize = _columnSizes.GetSizeByRealIndex(_resizingColumn.Value);
                    CaptureMouse();
                }

                bool isHeaderClickHandled = false;
                if (_resizingColumn == null && cell.IsColumnHeader)
                {
                    if (IsTransposed)
                    {
                        isHeaderClickHandled = OnModelRowClick(_columnSizes.RealToModel(cell.Column.Value));
                    }
                    else
                    {
                        isHeaderClickHandled = OnModelColumnClick(_columnSizes.RealToModel(cell.Column.Value));
                    }
                }
                if (cell.IsRowHeader)
                {
                    if (IsTransposed)
                    {
                        isHeaderClickHandled = OnModelColumnClick(_rowSizes.RealToModel(cell.Row.Value));
                    }
                    else
                    {
                        isHeaderClickHandled = OnModelRowClick(_rowSizes.RealToModel(cell.Row.Value));
                    }
                }

                if (!isHeaderClickHandled && ((_resizingColumn == null && cell.IsColumnHeader) || cell.IsRowHeader) &&
                    (_lastDblClickResize == null || DateTime.Now - _lastDblClickResize.Value > TimeSpan.FromSeconds(1)))
                {
                    HideInlineEditor();

                    if (ControlPressed)
                    {
                        foreach (var rangeCell in GetCellRange(cell, cell))
                        {
                            if (_selectedCells.Contains(rangeCell))
                            {
                                RemoveSelectedCell(rangeCell);
                            }
                            else
                            {
                                AddSelectedCell(rangeCell);
                            }
                            InvalidateCell(rangeCell);
                        }
                    }
                    else if (ShiftPressed)
                    {
                        _selectedCells.ToList().ForEach(InvalidateCell);
                        ClearSelectedCells();

                        foreach (var rangeCell in GetCellRange(cell, _currentCell))
                        {
                            AddSelectedCell(rangeCell);
                            InvalidateCell(rangeCell);
                        }
                    }
                    else
                    {
                        _selectedCells.ToList().ForEach(InvalidateCell);
                        ClearSelectedCells();
                        if (_currentCell.IsCell)
                        {
                            SetCurrentCell(cell);
                        }
                        foreach (var rangeCell in GetCellRange(cell, cell))
                        {
                            AddSelectedCell(rangeCell);
                            InvalidateCell(rangeCell);
                        }
                        _dragStartCell       = cell;
                        _dragTimer.IsEnabled = true;
                        CaptureMouse();
                    }
                    OnChangeSelectedCells(true);
                }

                if (cell.IsCell)
                {
                    if (ControlPressed)
                    {
                        HideInlineEditor();
                        if (_selectedCells.Contains(cell))
                        {
                            RemoveSelectedCell(cell);
                        }
                        else
                        {
                            AddSelectedCell(cell);
                        }
                        InvalidateCell(cell);
                    }
                    else if (ShiftPressed)
                    {
                        _selectedCells.ToList().ForEach(InvalidateCell);
                        ClearSelectedCells();

                        HideInlineEditor();
                        foreach (var cellItem in GetCellRange(_currentCell, cell))
                        {
                            AddSelectedCell(cellItem);
                            InvalidateCell(cellItem);
                        }
                    }
                    else
                    {
                        _selectedCells.ToList().ForEach(InvalidateCell);
                        ClearSelectedCells();
                        if (_currentCell == cell)
                        {
                            _showCellEditorIfMouseUp = _currentCell;
                        }
                        else
                        {
                            HideInlineEditor();
                            SetCurrentCell(cell);
                        }
                        AddSelectedCell(cell);
                        _dragStartCell       = cell;
                        _dragTimer.IsEnabled = true;
                        CaptureMouse();
                    }
                    OnChangeSelectedCells(true);
                }
            }

            //if (cell.IsCell) ShowTextEditor(
            //    GetCellRect(cell.Row.Value, cell.Column.Value),
            //    Model.GetCell(cell.Row.Value, cell.Column.Value).GetEditText());
        }
Exemplo n.º 8
0
 public void ScrollModelIntoView(FastGridCellAddress cell)
 {
     ScrollIntoView(ModelToReal(cell));
 }
Exemplo n.º 9
0
 public bool Equals(FastGridCellAddress other)
 {
     return(Row == other.Row && Column == other.Column);
 }
Exemplo n.º 10
0
        private void RenderCell(IFastGridCell cell, IntRect rect, Color?selectedTextColor, Color bgColor, FastGridCellAddress cellAddr)
        {
            bool isHoverCell = !cellAddr.IsEmpty && cellAddr == _mouseOverCell;

            if (isHoverCell)
            {
                _mouseOverCellIsTrimmed = false;
                CurrentCellActiveRegions.Clear();
                CurrentHoverRegion = null;
            }

            if (cell == null)
            {
                return;
            }
            var rectContent = GetContentRect(rect);

            _drawBuffer.DrawRectangle(rect, GridLineColor);
            _drawBuffer.FillRectangle(rect.GrowSymmetrical(-1, -1), bgColor);

            int count      = cell.BlockCount;
            int rightCount = cell.RightAlignBlockCount;
            int leftCount  = count - rightCount;
            int leftPos    = rectContent.Left;
            int rightPos   = rectContent.Right;

            for (int i = count - 1; i >= count - rightCount; i--)
            {
                var block = cell.GetBlock(i);
                if (block == null)
                {
                    continue;
                }
                if (i < count - 1)
                {
                    rightPos -= BlockPadding;
                }
                int blockWi = RenderBlock(leftPos, rightPos, selectedTextColor, bgColor, rectContent, block, cellAddr, false, isHoverCell);
                rightPos -= blockWi;
            }

            for (int i = 0; i < leftCount && leftPos < rightPos; i++)
            {
                var block = cell.GetBlock(i);
                if (block == null)
                {
                    continue;
                }
                if (i > 0)
                {
                    leftPos += BlockPadding;
                }
                int blockWi = RenderBlock(leftPos, rightPos, selectedTextColor, bgColor, rectContent, block, cellAddr, true, isHoverCell);
                leftPos += blockWi;
            }
            switch (cell.Decoration)
            {
            case CellDecoration.StrikeOutHorizontal:
                _drawBuffer.DrawLine(rect.Left, rect.Top + rect.Height / 2, rect.Right, rect.Top + rect.Height / 2, cell.DecorationColor ?? Colors.Black);
                break;
            }
            if (isHoverCell)
            {
                _mouseOverCellIsTrimmed = leftPos > rightPos;
            }
        }
Exemplo n.º 11
0
        private int RenderBlock(int leftPos, int rightPos, Color?selectedTextColor, Color bgColor, IntRect rectContent, IFastGridCellBlock block, FastGridCellAddress cellAddr, bool leftAlign, bool isHoverCell)
        {
            bool renderBlock = true;

            if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideWhenMouseOut && !isHoverCell)
            {
                renderBlock = false;
            }

            int width = 0, top = 0, height = 0;

            switch (block.BlockType)
            {
            case FastGridBlockType.Text:
                var font       = GetFont(block.IsBold, block.IsItalic);
                int textHeight = font.GetTextHeight(block.TextData);
                width  = font.GetTextWidth(block.TextData, _columnSizes.MaxSize);
                height = textHeight;
                top    = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - textHeight / 2.0);
                break;

            case FastGridBlockType.Image:
                top    = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - block.ImageHeight / 2.0);
                height = block.ImageHeight;
                width  = block.ImageWidth;
                break;
            }

            if (renderBlock && block.CommandParameter != null)
            {
                var activeRect = new IntRect(new IntPoint(leftAlign ? leftPos : rightPos - width, top), new IntSize(width, height)).GrowSymmetrical(1, 1);
                var region     = new ActiveRegion
                {
                    CommandParameter = block.CommandParameter,
                    Rect             = activeRect,
                    Tooltip          = block.ToolTip,
                };
                CurrentCellActiveRegions.Add(region);
                if (_mouseCursorPoint.HasValue && activeRect.Contains(_mouseCursorPoint.Value))
                {
                    _drawBuffer.FillRectangle(activeRect, ActiveRegionHoverFillColor);
                    CurrentHoverRegion = region;
                }

                bool renderRectangle = true;
                if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideButtonWhenMouseOut && !isHoverCell)
                {
                    renderRectangle = false;
                }

                if (renderRectangle)
                {
                    _drawBuffer.DrawRectangle(activeRect, ActiveRegionFrameColor);
                }
            }

            switch (block.BlockType)
            {
            case FastGridBlockType.Text:
                if (renderBlock)
                {
                    var textOrigin = new IntPoint(leftAlign ? leftPos : rightPos - width, top);
                    var font       = GetFont(block.IsBold, block.IsItalic);
                    _drawBuffer.DrawString(textOrigin.X, textOrigin.Y, rectContent, selectedTextColor ?? block.FontColor ?? CellFontColor, UseClearType ? bgColor : (Color?)null,
                                           font,
                                           block.TextData);
                }
                break;

            case FastGridBlockType.Image:
                if (renderBlock)
                {
                    var imgOrigin = new IntPoint(leftAlign ? leftPos : rightPos - block.ImageWidth, top);
                    var image     = GetImage(block.ImageSource);
                    _drawBuffer.Blit(new Point(imgOrigin.X, imgOrigin.Y), image.Bitmap, new Rect(0, 0, block.ImageWidth, block.ImageHeight),
                                     image.KeyColor, image.BlendMode);
                }
                break;
            }

            return(width);
        }
Exemplo n.º 12
0
 public HoverRowChangedEventArgs(FastGridCellAddress cell)
 {
     Cell = cell;
 }