public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!(obj is FastGridLocation))
            {
                return(false);
            }

            FastGridLocation loc = (FastGridLocation)obj;

            if (loc.RowIndex != RowIndex)
            {
                return(false);
            }
            if (loc.ColumnIndex != ColumnIndex)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Ensure that the cell as specified in the loc parameter is shown
        /// in the grid.
        /// </summary>
        /// <param name="loc">The location of the cell to show</param>
        private void EnsureCellIsShown(FastGridLocation loc)
        {
            bool needInvalidate = true;
            bool needScroll     = false;

            // Handle moving the row so the row is shown
            if (loc.RowIndex < _firstDisplayedRowIndex || loc.RowIndex >= _firstDisplayedRowIndex + _rows.Count)
            {
                if (loc.RowIndex < RowsCount && loc.RowIndex >= 0)
                {
                    _firstDisplayedRowIndex = loc.RowIndex;
                    FetchRows();
                    needScroll = true;
                }
            }

            try
            {
                Rectangle cell = _cellRectangles[loc.RowIndex - _firstDisplayedRowIndex, loc.ColumnIndex];
                if (cell.X >= _content.X + _startX && cell.Right <= _content.Right + _startX)
                {
                    needInvalidate = false;
                    return;
                }
                else
                {
                    // Move to the start of the column
                    if (cell.Left >= _content.Right + _startX)
                    {
                        _startX = cell.Right - _content.Width;
                    }
                    else if (cell.Left < _content.X + _startX)
                    {
                        int width = cell.Width;
                        _startX -= width;
                        if (_startX > cell.Left)
                        {
                            _startX = cell.Left;
                        }
                    }
                    else if (cell.Right > _content.Right + _startX)
                    {
                        if (cell.Width < _content.Width)
                        {
                            _startX += cell.Right - (_content.Right + _startX);
                        }
                        else
                        {
                            _startX = cell.Left;
                        }
                    }

                    if (_startX < 0)
                    {
                        _startX = 0;
                    }

                    needScroll = true;
                }
            }
            finally
            {
                if (needScroll)
                {
                    // Notify about the scroll
                    if (Scroll != null)
                    {
                        Scroll(this, EventArgs.Empty);
                    }
                }

                if (needInvalidate)
                {
                    Invalidate();
                }
            } // finally
        }
Exemple #3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (!_valid)
            {
                return;
            }

            this.Focus();

            FastGridLocation loc = PointToLocation(e.Location);

            if (loc == FastGridLocation.Empty)
            {
                return;
            }

            if (_viewResizeHint)
            {
                // Enter resize mode
                _resizeColumnsMode = true;

                // Mark the point where the resize begun
                _resizeColumnsPoint = e.Location;
            }
            else
            {
                if (e.Button == MouseButtons.Left)
                {
                    _mouseLeftPressed = true;
                }

                // Ignore column cells
                if (loc.RowIndex < 0)
                {
                }
                else if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
                {
                    long rowid = loc.RowIndex;
                    switch (_selectionMode)
                    {
                    case SelectionMode.None:
                        _selection.SetSelection(rowid, rowid);
                        _currentRowId = rowid;
                        _startRowId   = rowid;
                        break;

                    case SelectionMode.SingleSelection:
                        if (_selection.IsRowSelected(rowid))
                        {
                            _selection.DelSelection(rowid, rowid);
                        }
                        else
                        {
                            _selection.AddSelection(rowid, rowid);
                        }
                        _currentRowId = rowid;
                        _startRowId   = rowid;
                        break;

                    case SelectionMode.RangeSelection:
                        _selection.SetSelection(_startRowId, rowid);
                        break;

                    default:
                        throw new InvalidOperationException("illegal selection mode encountered");
                    } // switch

                    // Move the selected cell to the clicked cell
                    _selectedCellLocation = loc;

                    Invalidate();
                } // else
            }     // else
        }
Exemple #4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!_valid)
            {
                return;
            }

            if (_resizeColumnsMode)
            {
                // Measure X distance from the location where the resize was started
                int delta = _resizeColumnsPoint.X - e.Location.X;
                if (delta != 0)
                {
                    _resizeColumnsPoint = e.Location;

                    // Apply the difference to the column's width
                    _columns[_resizedColumnIndex].Width -= delta;
                    if (_columns[_resizedColumnIndex].Width < 10)
                    {
                        _columns[_resizedColumnIndex].Width = 10;
                    }

                    // Notify about this resize
                    if (ColumnResized != null)
                    {
                        ColumnResized(this, new ColumnResizedEventArgs(_resizedColumnIndex, _columns[_resizedColumnIndex].Width));
                    }

                    DoLayout();

                    Refresh();
                }
            }
            else
            {
                FastGridLocation loc = PointToLocation(e.Location);
                if (loc == FastGridLocation.Empty)
                {
                    if (_viewResizeHint)
                    {
                        _viewResizeHint = false;
                        Cursor          = Cursors.Default;
                    }
                    return;
                }

                if (loc.RowIndex < 0)
                {
                    // We need to track the mouse location when it hovers above
                    // column cells in order to be able to change the cursor so that
                    // the user can resize the columns.
                    if ((e.X + _startX - _columnRectangles[loc.ColumnIndex].Left < 5 ||
                         _columnRectangles[loc.ColumnIndex].Right - e.X - _startX < 5))
                    {
                        if (e.X + _startX - _columnRectangles[loc.ColumnIndex].Left < 5)
                        {
                            _resizedColumnIndex = loc.ColumnIndex - 1;
                        }
                        else
                        {
                            _resizedColumnIndex = loc.ColumnIndex;
                        }

                        if (_resizedColumnIndex < 0)
                        {
                            _viewResizeHint = false;
                            Cursor          = Cursors.Default;
                        }
                        else
                        {
                            _viewResizeHint = true;
                            if (Cursor == Cursors.Default)
                            {
                                Cursor = Cursors.VSplit;
                            }
                        } // else
                    }
                    else if (_viewResizeHint)
                    {
                        _viewResizeHint = false;
                        Cursor          = Cursors.Default;
                    }
                }
                else
                {
                    if (_viewResizeHint)
                    {
                        _viewResizeHint = false;
                        Cursor          = Cursors.Default;
                    }

                    if (_mouseLeftPressed && _selectionMode == SelectionMode.None)
                    {
                        _selectionMode = SelectionMode.RangeSelection;
                    }

                    if (e.Button == MouseButtons.Left && _selectionMode == SelectionMode.RangeSelection)
                    {
                        long rowid = loc.RowIndex;
                        _currentRowId = rowid;

                        _selection.SetSelection(_startRowId, _currentRowId);

                        Invalidate();
                    }
                } // else
            }     // else
        }