Exemple #1
0
        /*/// <summary>
        /// Stops editing the current Cell and starts editing the next editable Cell
        /// </summary>
        /// <param name="forwards">Specifies whether the editor should traverse
        /// forward when looking for the next editable Cell</param>
        protected internal void EditNextCell(bool forwards)
        {
            if (this.EditingCell == CellPos.Empty)
            {
                return;
            }

            CellPos nextCell = this.FindNextEditableCell(this.FocusedCell, true, forwards, false);

            if (nextCell != CellPos.Empty && nextCell != this.EditingCell)
            {
                this.StopEditing();

                this.EditCell(nextCell);
            }
        }*/
        /// <summary>
        /// Stops editing the current Cell and commits any changes
        /// </summary>
        public void StopEditing()
        {
            // don't bother if we're not editing
            if (this.EditingCell == CellPos.Empty)
            {
                return;
            }

            this.EditingCellEditor.StopEditing();

            this.Invalidate(this.RowRect(this.editingCell.Row));

            this.editingCell = CellPos.Empty;
            this.curentCellEditor = null;
        }
Exemple #2
0
 /// <summary>
 /// Replaces the currently selected Cells with the Cell at the specified CellPos
 /// </summary>
 /// <param name="cellPos">A CellPos thst specifies the row and column indicies of 
 /// the Cell to be selected</param>
 public void SelectCell(CellPos cellPos)
 {
     this.SelectCell(cellPos.Row, cellPos.Column);
 }
Exemple #3
0
 /// <summary>
 /// Replaces the currently selected Cells with the Cells located between the specified 
 /// start and end CellPos
 /// </summary>
 /// <param name="start">A CellPos that specifies the start Cell</param>
 /// <param name="end">A CellPos that specifies the end Cell</param>
 public void SelectCells(CellPos start, CellPos end)
 {
     this.SelectCells(start.Row, start.Column, end.Row, end.Column);
 }
Exemple #4
0
 /// <summary>
 /// Returns whether the Cell at the specified CellPos is currently selected
 /// </summary>
 /// <param name="cellPos">A CellPos the represents the row and column indicies 
 /// of the Cell to check</param>
 /// <returns>true if the Cell at the specified CellPos is currently selected, 
 /// false otherwise</returns>
 public bool IsCellSelected(CellPos cellPos)
 {
     return this.IsCellSelected(cellPos.Row, cellPos.Column);
 }
Exemple #5
0
            /// <summary>
            /// Removes the Cells located between the specified start and end row/column indicies 
            /// from the current selection
            /// </summary>
            /// <param name="startRow">The row index of the start Cell</param>
            /// <param name="startColumn">The column index of the start Cell</param>
            /// <param name="endRow">The row index of the end Cell</param>
            /// <param name="endColumn">The column index of the end Cell</param>
            public void RemoveCells(int startRow, int startColumn, int endRow, int endColumn)
            {
                if (this.rows.Count > 0)
                {
                    int[] oldSelectedIndicies = this.SelectedIndicies;

                    if (this.InternalRemoveCells(startRow, startColumn, endRow, endColumn))
                    {
                        this.owner.OnSelectionChanged(new SelectionEventArgs(this.owner, oldSelectedIndicies, this.SelectedIndicies));
                    }

                    this.shiftSelectStart = new CellPos(startRow, startColumn);
                    this.shiftSelectEnd = new CellPos(endRow, endColumn);
                }
            }
Exemple #6
0
 /// <summary>
 /// Adds the Cells located between the specified start and end CellPos to the
 /// current selection
 /// </summary>
 /// <param name="start">A CellPos that specifies the start Cell</param>
 /// <param name="end">A CellPos that specifies the end Cell</param>
 public void AddCells(CellPos start, CellPos end)
 {
     this.AddCells(start.Row, start.Column, end.Row, end.Column);
 }
Exemple #7
0
 /// <summary>
 /// Adds the Cells between the last selection start Cell and the Cell at the 
 /// specified CellPas to the current selection.  Any Cells that are 
 /// between the last start and end Cells that are not in the new area are 
 /// removed from the current selection
 /// </summary>
 /// <param name="cellPos">A CellPos that specifies the shift selected Cell</param>
 public void AddShiftSelectedCell(CellPos cellPos)
 {
     this.AddShiftSelectedCell(cellPos.Row, cellPos.Column);
 }
Exemple #8
0
        /// <summary>
        /// Returns a CellPos that specifies the next Cell that is visible 
        /// and enabled from the specified Cell
        /// </summary>
        /// <param name="start">A CellPos that specifies the Cell to start 
        /// searching from</param>
        /// <param name="wrap">Specifies whether to move to the start of the 
        /// next Row when the end of the current Row is reached</param>
        /// <param name="forward">Specifies whether the search should travel 
        /// in a forward direction (top to bottom, left to right) through the Cells</param>
        /// <param name="includeStart">Indicates whether the specified starting 
        /// Cell is included in the search</param>
        /// <param name="checkOtherCellsInRow">Specifies whether all Cells in 
        /// the Row should be included in the search</param>
        /// <returns>A CellPos that specifies the next Cell that is visible 
        /// and enabled, or CellPos.Empty if there are no Cells that are visible 
        /// and enabled</returns>
        protected CellPos FindNextVisibleEnabledCell(CellPos start, bool wrap, bool forward, bool includeStart, bool checkOtherCellsInRow)
        {
            if (this.ColumnCount == 0 || this.RowCount == 0)
            {
                return CellPos.Empty;
            }

            int startRow = start.Row != -1 ? start.Row : 0;
            int startCol = start.Column != -1 ? start.Column : 0;

            bool first = true;

            if (forward)
            {
                for (int i = startRow; i < this.RowCount; i++)
                {
                    int j = (first || !checkOtherCellsInRow ? startCol : 0);

                    for (; j < this.TableModel.Rows[i].Cells.Count; j++)
                    {
                        if (i == startRow && j == startCol)
                        {
                            if (!first)
                            {
                                return CellPos.Empty;
                            }

                            first = false;

                            if (!includeStart)
                            {
                                if (!checkOtherCellsInRow)
                                {
                                    break;
                                }

                                continue;
                            }
                        }

                        if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Enabled && this.ColumnModel.Columns[j].Enabled && this.ColumnModel.Columns[j].Visible)
                        {
                            return new CellPos(i, j);
                        }

                        if (!checkOtherCellsInRow)
                        {
                            continue;
                        }
                    }

                    if (wrap)
                    {
                        if (i + 1 == this.TableModel.Rows.Count)
                        {
                            i = -1;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = startRow; i >= 0; i--)
                {
                    int j = (first || !checkOtherCellsInRow ? startCol : this.TableModel.Rows[i].Cells.Count);

                    for (; j >= 0; j--)
                    {
                        if (i == startRow && j == startCol)
                        {
                            if (!first)
                            {
                                return CellPos.Empty;
                            }

                            first = false;

                            if (!includeStart)
                            {
                                if (!checkOtherCellsInRow)
                                {
                                    break;
                                }

                                continue;
                            }
                        }

                        if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Enabled && this.ColumnModel.Columns[j].Enabled && this.ColumnModel.Columns[j].Visible)
                        {
                            return new CellPos(i, j);
                        }

                        if (!checkOtherCellsInRow)
                        {
                            continue;
                        }
                    }

                    if (wrap)
                    {
                        if (i - 1 == -1)
                        {
                            i = this.TableModel.Rows.Count;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return CellPos.Empty;
        }
Exemple #9
0
        /// <summary>
        /// Raises the MouseMove event
        /// </summary>
        /// <param name="e">A MouseEventArgs that contains the event data</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // don't go any further if the table is editing
            if (this.TableState == TableState.Editing)
            {
                return;
            }

            #region Left mouse button
            // if the left mouse button is down, check if the LastMouseDownCell
            // references a valid cell.  if it does, send the mouse move message
            // to the cell and then exit (this will stop other cells/headers
            // from getting the mouse move message even if the mouse is over
            // them - this seems consistent with the way windows does it for
            // other controls)
            if (e.Button == MouseButtons.Left)
            {
                if (!this.LastMouseDownCell.IsEmpty)
                {
                    if (this.IsValidCell(this.LastMouseDownCell))
                    {
                        this.RaiseCellMouseMove(this.LastMouseDownCell, e);

                        return;
                    }
                }
            }
            #endregion

            #region Column resizing
            // are we resizing a column?
            if (this.resizingColumnIndex != -1)
            {
                if (this.resizingColumnWidth != -1)
                {
                    this.DrawReversibleLine(this.ColumnRect(this.resizingColumnIndex).Left + this.resizingColumnWidth);
                }

                // calculate the new width for the column
                int width = this.ClientToDisplayRect(e.X, e.Y).X - this.resizingColumnAnchor - this.resizingColumnOffset;

                // make sure the new width isn't smaller than the minimum allowed
                // column width, or larger than the maximum allowed column width
                if (width < Column.MinimumWidth)
                {
                    width = Column.MinimumWidth;
                }
                else if (width > Column.MaximumWidth)
                {
                    width = Column.MaximumWidth;
                }

                this.resizingColumnWidth = width;

                //this.ColumnModel.Columns[this.resizingColumnIndex].Width = width;
                this.DrawReversibleLine(this.ColumnRect(this.resizingColumnIndex).Left + this.resizingColumnWidth);

                return;
            }
            #endregion

            // work out the potential state of play
            this.CalcTableState(e.X, e.Y);

            TableRegion hitTest = this.HitTest(e.X, e.Y);

            #region ColumnHeader

            if (hitTest == TableRegion.ColumnHeader)
            {
                // this next bit is pretty complicated. need to work
                // out which column is displayed as pressed or hot
                // (so we have the same behaviour as a themed ListView
                // in Windows XP)

                int column = this.ColumnIndexAt(e.X, e.Y);

                // if this isn't the current hot column, reset the
                // hot columns state to normal and set this column
                // to be the hot column
                if (this.hotColumn != column)
                {
                    if (this.hotColumn != -1)
                    {
                        this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Normal;

                        this.RaiseHeaderMouseLeave(this.hotColumn);
                    }

                    if (this.TableState != TableState.ColumnResizing)
                    {
                        this.hotColumn = column;

                        if (this.hotColumn != -1 && this.ColumnModel.Columns[column].Enabled)
                        {
                            this.ColumnModel.Columns[column].InternalColumnState = ColumnState.Hot;

                            this.RaiseHeaderMouseEnter(column);
                        }
                    }
                }
                else
                {
                    if (column != -1 && this.ColumnModel.Columns[column].Enabled)
                    {
                        this.RaiseHeaderMouseMove(column, e);
                    }
                }

                // if this isn't the pressed column, then the pressed columns
                // state should be set back to normal
                if (this.pressedColumn != -1 && this.pressedColumn != column)
                {
                    this.ColumnModel.Columns[this.pressedColumn].InternalColumnState = ColumnState.Normal;
                }
                // else if this is the pressed column and its state is not
                // pressed, then we had better set it
                else if (column != -1 && this.pressedColumn == column && this.ColumnModel.Columns[this.pressedColumn].ColumnState != ColumnState.Pressed)
                {
                    this.ColumnModel.Columns[this.pressedColumn].InternalColumnState = ColumnState.Pressed;
                }

                // set the cursor to a resizing cursor if necesary
                if (this.TableState == TableState.ColumnResizing)
                {
                    Rectangle columnRect = this.ColumnModel.ColumnHeaderRect(column);
                    int x = this.ClientToDisplayRect(e.X, e.Y).X;

                    this.Cursor = Cursors.VSplit;

                    // if the left mouse button is down, we don't want
                    // the resizing cursor so set it back to the default
                    if (e.Button == MouseButtons.Left)
                    {
                        this.Cursor = Cursors.Default;
                    }

                    // if the mouse is in the left side of the column,
                    // the first non-hidden column to the left needs to
                    // become the hot column (so the user knows which
                    // column would be resized if a resize action were
                    // to take place
                    if (x < columnRect.Left + Column.ResizePadding)
                    {
                        int col = column;

                        while (col != 0)
                        {
                            col--;

                            if (this.ColumnModel.Columns[col].Visible)
                            {
                                break;
                            }
                        }

                        if (col != -1)
                        {
                            if (this.ColumnModel.Columns[col].Enabled)
                            {
                                if (this.hotColumn != -1)
                                {
                                    this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Normal;
                                }

                                this.hotColumn = col;
                                this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Hot;

                                this.RaiseHeaderMouseEnter(col);
                            }
                            else
                            {
                                this.Cursor = Cursors.Default;
                            }
                        }
                    }
                    else
                    {
                        if (this.ColumnModel.Columns[column].Enabled)
                        {
                            // this mouse is in the right side of the column,
                            // so this column needs to be dsiplayed hot
                            this.hotColumn = column;
                            this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Hot;
                        }
                        else
                        {
                            this.Cursor = Cursors.Default;
                        }
                    }
                }
                else
                {
                    // we're not in a resizing area, so make sure the cursor
                    // is the default cursor (we may have just come from a
                    // resizing area)
                    this.Cursor = Cursors.Default;
                }

                // reset the last cell the mouse was over
                this.ResetLastMouseCell();

                return;
            }

            #endregion

            // we're outside of the header, so if there is a hot column,
            // it need to be reset
            if (this.hotColumn != -1)
            {
                this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Normal;

                this.Cursor = Cursors.Default;

                this.ResetHotColumn();
            }

            // if there is a pressed column, its state need to beset to normal
            if (this.pressedColumn != -1)
            {
                this.ColumnModel.Columns[this.pressedColumn].InternalColumnState = ColumnState.Normal;
            }

            #region Cells

            if (hitTest == TableRegion.Cells)
            {
                // find the cell the mouse is over
                CellPos cellPos = new CellPos(this.RowIndexAt(e.X, e.Y), this.ColumnIndexAt(e.X, e.Y));

                if (!cellPos.IsEmpty)
                {
                    if (cellPos != this.lastMouseCell)
                    {
                        // check if the cell exists (ie is not null)
                        if (this.IsValidCell(cellPos))
                        {
                            CellPos oldLastMouseCell = this.lastMouseCell;

                            if (!oldLastMouseCell.IsEmpty)
                            {
                                this.ResetLastMouseCell();
                            }

                            this.lastMouseCell = cellPos;

                            this.RaiseCellMouseEnter(cellPos);
                        }
                        else
                        {
                            this.ResetLastMouseCell();

                            // make sure the cursor is the default cursor
                            // (we may have just come from a resizing area in the header)
                            this.Cursor = Cursors.Default;
                        }
                    }
                    else
                    {
                        this.RaiseCellMouseMove(cellPos, e);

                        this.Cursor = Cursors.Default;
                    }
                }
                else
                {
                    this.ResetLastMouseCell();

                    if (this.TableModel == null)
                    {
                        this.ResetToolTip();
                    }
                }

                // netus - fix by Kosmokrat Hismoom on 2006-01-29
                // make sure the cursor is the default cursor
                // (we may have just come from a resizing area in the header)
                this.Cursor = Cursors.Default;
                return;
            }
            else
            {
                this.ResetLastMouseCell();

                if (!this.lastMouseDownCell.IsEmpty)
                {
                    this.RaiseCellMouseLeave(this.lastMouseDownCell);
                }

                if (this.TableModel == null)
                {
                    this.ResetToolTip();
                }

                // make sure the cursor is the default cursor
                // (we may have just come from a resizing area in the header)
                this.Cursor = Cursors.Default;
            }

            #endregion
        }
Exemple #10
0
        /// <summary>
        /// Resets the last known cell position that the mouse was over to empty
        /// </summary>
        internal void ResetLastMouseCell()
        {
            if (!this.lastMouseCell.IsEmpty)
            {
                this.ResetMouseEventArgs();

                CellPos oldLastMouseCell = this.lastMouseCell;
                this.lastMouseCell = CellPos.Empty;

                this.RaiseCellMouseLeave(oldLastMouseCell);
            }
        }
Exemple #11
0
        /// <summary>
        /// Returns the position of the actual cell that renders to the given cell pos.
        /// This looks at colspans and returns the cell that colspan overs the given cell (if any)
        /// </summary>
        /// <param name="cellPos"></param>
        /// <returns></returns>
        protected internal CellPos ResolveColspan(CellPos cellPos)
        {
            Row r = this.TableModel.Rows[cellPos.Row];

            CellPos n = new CellPos(cellPos.Row, r.GetRenderedCellIndex(cellPos.Column));

            return n;
        }
Exemple #12
0
        /// <summary>
        /// Raises the CellRemoved event
        /// </summary>
        /// <param name="e">A RowEventArgs that contains the event data</param>
        protected internal virtual void OnCellRemoved(RowEventArgs e)
        {
            if (this.CanRaiseEvents)
            {
                this.InvalidateRow(e.Index);

                if (CellRemoved != null)
                {
                    CellRemoved(this, e);
                }

                if (e.CellFromIndex == -1 && e.CellToIndex == -1)
                {
                    if (this.FocusedCell.Row == e.Index)
                    {
                        this.focusedCell = CellPos.Empty;
                    }
                }
                else
                {
                    for (int i = e.CellFromIndex; i <= e.CellToIndex; i++)
                    {
                        if (this.FocusedCell.Row == e.Index && this.FocusedCell.Column == i)
                        {
                            this.focusedCell = CellPos.Empty;

                            break;
                        }
                    }
                }
            }
        }
Exemple #13
0
 /// <summary>
 /// Returns whether Cell at the specified cell position is not null
 /// </summary>
 /// <param name="cellPos">The position of the cell</param>
 /// <returns>True if the cell at the specified cell position is not 
 /// null, otherwise false</returns>
 protected internal bool IsValidCell(CellPos cellPos)
 {
     return this.IsValidCell(cellPos.Row, cellPos.Column);
 }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the Table class with default settings
        /// </summary>
        public Table()
        {
            // starting setup
            this.init = true;

            // This call is required by the Windows.Forms Form Designer.
            components = new System.ComponentModel.Container();

            //
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true);
            this.TabStop = true;

            this.Size = new Size(150, 150);

            this.BackColor = Color.White;

            //
            this.columnModel = null;
            this.tableModel = null;

            // header
            this.headerStyle = ColumnHeaderStyle.Clickable;
            this.headerFont = this.Font;
            this.headerRenderer = new XPHeaderRenderer();
            //this.headerRenderer = new GradientHeaderRenderer();
            //this.headerRenderer = new FlatHeaderRenderer();
            this.headerRenderer.Font = this.headerFont;
            this.headerContextMenu = new HeaderContextMenu();

            this.columnResizing = true;
            this.resizingColumnIndex = -1;
            this.resizingColumnWidth = -1;
            this.hotColumn = -1;
            this.pressedColumn = -1;
            this.lastSortedColumn = -1;
            this.sortedColumnBackColor = Color.WhiteSmoke;

            // borders
            this.borderStyle = BorderStyle.Fixed3D;
            this.borderColor = Color.Black;
            this.unfocusedBorderColor = Color.Black;

            // scrolling
            this.scrollable = true;

            this.hScrollBar = new HScrollBar();
            this.hScrollBar.Visible = false;
            this.hScrollBar.Location = new Point(this.BorderWidth, this.Height - this.BorderWidth - SystemInformation.HorizontalScrollBarHeight);
            this.hScrollBar.Width = this.Width - (this.BorderWidth * 2) - SystemInformation.VerticalScrollBarWidth;
            this.hScrollBar.Scroll += new ScrollEventHandler(this.OnHorizontalScroll);
            this.Controls.Add(this.hScrollBar);

            this.vScrollBar = new VScrollBar();
            this.vScrollBar.Visible = false;
            this.vScrollBar.Location = new Point(this.Width - this.BorderWidth - SystemInformation.VerticalScrollBarWidth, this.BorderWidth);
            this.vScrollBar.Height = this.Height - (this.BorderWidth * 2) - SystemInformation.HorizontalScrollBarHeight;
            this.vScrollBar.Scroll += new ScrollEventHandler(this.OnVerticalScroll);
            this.Controls.Add(this.vScrollBar);

            //
            this.gridLines = GridLines.None; ;
            this.gridColor = SystemColors.Control;
            this.gridLineStyle = GridLineStyle.Solid;

            this.allowSelection = true;
            this.allowRMBSelection = false;
            this.multiSelect = false;
            this.fullRowSelect = false;
            this.hideSelection = false;
            this.selectionBackColor = SystemColors.Highlight;
            this.selectionForeColor = SystemColors.HighlightText;
            this.unfocusedSelectionBackColor = SystemColors.Control;
            this.unfocusedSelectionForeColor = SystemColors.ControlText;
            this.selectionStyle = SelectionStyle.ListView;
            this.alternatingRowColor = Color.Transparent;
            this.alternatingRowSpan = 1;

            // current table state
            this.tableState = TableState.Normal;

            this.lastMouseCell = new CellPos(-1, -1);
            this.lastMouseDownCell = new CellPos(-1, -1);
            this.focusedCell = new CellPos(-1, -1);
            this.hoverTime = 1000;
            this.trackMouseEvent = null;
            this.ResetMouseEventArgs();

            this.toolTip = new ToolTip(this.components);
            this.toolTip.Active = false;
            this.toolTip.InitialDelay = 1000;

            this.noItemsText = "There are no items in this view";

            this.editingCell = new CellPos(-1, -1);
            this.curentCellEditor = null;
            this.editStartAction = EditStartAction.DoubleClick;
            this.customEditKey = Keys.F5;
            //this.tabMovesEditor = true;

            // showSelectionRectangle defaults to true
            this.showSelectionRectangle = true;

            // for data binding
            listChangedHandler = new ListChangedEventHandler(dataManager_ListChanged);
            positionChangedHandler = new EventHandler(dataManager_PositionChanged);
            dataSourceColumnBinder = new DataSourceColumnBinder();

            // finished setting up
            this.beginUpdateCount = 0;
            this.init = false;
            this.preview = false;
        }
Exemple #15
0
            /// <summary>
            /// Initializes a new instance of the TableModel.Selection class 
            /// that belongs to the specified TableModel
            /// </summary>
            /// <param name="owner">A TableModel representing the tableModel that owns 
            /// the Selection</param>
            public Selection(TableModel owner)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner", "owner cannot be null");
                }

                this.owner = owner;
                this.rows = new ArrayList();

                this.shiftSelectStart = CellPos.Empty;
                this.shiftSelectEnd = CellPos.Empty;
            }
Exemple #16
0
        /// <summary>
        /// Raises the MouseUp event
        /// </summary>
        /// <param name="e">A MouseEventArgs that contains the event data</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (!this.CanRaiseEvents)
            {
                return;
            }

            // work out the current state of  play
            this.CalcTableState(e.X, e.Y);

            // right mouse up. for context menu
            if (this.AllowRMBSelection && e.Button == MouseButtons.Right)
            {
                if (!this.LastMouseDownCell.IsEmpty)
                {
                    if (this.IsValidCell(this.LastMouseDownCell))
                    {
                        this.RaiseCellMouseUp(this.LastMouseDownCell, e);
                    }

                    // reset the lastMouseDownCell
                    this.lastMouseDownCell = CellPos.Empty;
                }
                return;
            }

            TableRegion region = this.HitTest(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                // if the left mouse button was down for a cell,
                // Raise a mouse up for that cell
                if (!this.LastMouseDownCell.IsEmpty)
                {
                    if (this.IsValidCell(this.LastMouseDownCell))
                    {
                        this.RaiseCellMouseUp(this.LastMouseDownCell, e);
                    }

                    // reset the lastMouseDownCell
                    this.lastMouseDownCell = CellPos.Empty;
                }

                // if we have just finished resizing, it might
                // be a good idea to relayout the table
                if (this.resizingColumnIndex != -1)
                {
                    if (this.resizingColumnWidth != -1)
                    {
                        this.DrawReversibleLine(this.ColumnRect(this.resizingColumnIndex).Left + this.resizingColumnWidth);
                        this.ColumnModel.Columns[this.resizingColumnIndex].Width = this.resizingColumnWidth;
                    }

                    this.resizingColumnIndex = -1;
                    this.resizingColumnWidth = -1;

                    this.UpdateScrollBars();
                    this.Invalidate(this.PseudoClientRect, true);
                }

                // check if the mouse was released in a column header
                if (region == TableRegion.ColumnHeader)
                {
                    int column = this.ColumnIndexAt(e.X, e.Y);

                    // if we are in the header, check if we are in the pressed column
                    if (this.pressedColumn != -1)
                    {
                        if (this.pressedColumn == column)
                        {
                            if (this.hotColumn != -1 && this.hotColumn != column)
                            {
                                this.ColumnModel.Columns[this.hotColumn].InternalColumnState = ColumnState.Normal;
                            }

                            this.ColumnModel.Columns[this.pressedColumn].InternalColumnState = ColumnState.Hot;

                            this.RaiseHeaderMouseUp(column, e);
                        }

                        this.pressedColumn = -1;

                        // only sort the column if we have rows to sort
                        if ((this.IsValidColumn(column)) && (this.ColumnModel.Columns[column].Sortable))
                        {
                            if (this.TableModel != null && this.TableModel.Rows.Count > 0)
                            {
                                this.Sort(column);
                            }
                        }

                        this.Invalidate(this.HeaderRectangle, false);
                    }

                    return;
                }

                // the mouse wasn't released in a column header, so if we
                // have a pressed column then we need to make it unpressed
                if (this.pressedColumn != -1)
                {
                    this.pressedColumn = -1;

                    this.Invalidate(this.HeaderRectangle, false);
                }
            }
        }
Exemple #17
0
 /// <summary>
 /// Adds the Cell at the specified row and column indicies to the current selection
 /// </summary>
 /// <param name="cellPos">A CellPos that specifies the Cell to add to the selection</param>
 public void AddCell(CellPos cellPos)
 {
     this.AddCell(cellPos.Row, cellPos.Column);
 }
Exemple #18
0
        /// <summary>
        /// Raises the LostFocus event for the Cell at the specified position
        /// </summary>
        /// <param name="cellPos">The position of the Cell that lost focus</param>
        protected void RaiseCellLostFocus(CellPos cellPos)
        {
            if (!this.IsValidCell(cellPos))
            {
                return;
            }

            ICellRenderer renderer = this.ColumnModel.GetCellRenderer(cellPos.Column);

            if (renderer != null)
            {
                Cell cell = null;

                if (cellPos.Column < this.TableModel.Rows[cellPos.Row].Cells.Count)
                {
                    cell = this.TableModel[cellPos.Row, cellPos.Column];
                }

                CellFocusEventArgs cfea = new CellFocusEventArgs(cell, this, cellPos.Row, cellPos.Column, this.CellRect(cellPos.Row, cellPos.Column));

                this.OnCellLostFocus(cfea);
            }
        }
Exemple #19
0
            /// <summary>
            /// Adds the Cells between the last selection start Cell and the Cell at the 
            /// specified row/column indicies to the current selection.  Any Cells that are 
            /// between the last start and end Cells that are not in the new area are 
            /// removed from the current selection
            /// </summary>
            /// <param name="row">The row index of the shift selected Cell</param>
            /// <param name="column">The column index of the shift selected Cell</param>
            public void AddShiftSelectedCell(int row, int column)
            {
                int[] oldSelectedIndicies = this.SelectedIndicies;

                if (this.shiftSelectStart == CellPos.Empty)
                {
                    this.shiftSelectStart = new CellPos(0, 0);
                }

                bool changed = false;

                if (this.shiftSelectEnd != CellPos.Empty)
                {
                    changed = this.InternalRemoveCells(this.shiftSelectStart, this.shiftSelectEnd);
                    changed |= this.InternalAddCells(this.shiftSelectStart, new CellPos(row, column));
                }
                else
                {
                    changed = this.InternalAddCells(0, 0, row, column);
                }

                if (changed)
                {
                    this.owner.OnSelectionChanged(new SelectionEventArgs(this.owner, oldSelectedIndicies, this.SelectedIndicies));
                }

                this.shiftSelectEnd = new CellPos(row, column);
            }
Exemple #20
0
        /// <summary>
        /// Raises a MouseUp event for the Cell at the specified cell position
        /// </summary>
        /// <param name="cellPos">The position of the Cell</param>
        /// <param name="e">A MouseEventArgs that contains the event data</param>
        protected void RaiseCellMouseUp(CellPos cellPos, MouseEventArgs e)
        {
            if (!this.IsValidCell(cellPos))
            {
                return;
            }

            if (!this.TableModel[cellPos].Enabled)
            {
                return;
            }

            if (this.ColumnModel.GetCellRenderer(cellPos.Column) != null)
            {
                Cell cell = null;

                if (cellPos.Column < this.TableModel.Rows[cellPos.Row].Cells.Count)
                {
                    cell = this.TableModel.Rows[cellPos.Row].Cells[cellPos.Column];
                }

                CellMouseEventArgs mcea = new CellMouseEventArgs(cell, this, cellPos.Row, cellPos.Column, this.CellRect(cellPos.Row, cellPos.Column), e);

                this.OnCellMouseUp(mcea);
            }
        }
Exemple #21
0
            /// <summary>
            /// Removes all selected Rows and Cells from the selection
            /// </summary>
            public void Clear()
            {
                if (this.rows.Count > 0)
                {
                    int[] oldSelectedIndicies = this.SelectedIndicies;

                    this.InternalClear();

                    this.shiftSelectStart = CellPos.Empty;
                    this.shiftSelectEnd = CellPos.Empty;

                    this.owner.OnSelectionChanged(new SelectionEventArgs(this.owner, oldSelectedIndicies, this.SelectedIndicies));
                }
            }
Exemple #22
0
 /// <summary>
 /// Records the Cell that is currently being edited and the 
 /// ICellEditor used to edit the Cell
 /// </summary>
 /// <param name="cellPos">The Cell that is currently being edited</param>
 /// <param name="editor">The ICellEditor used to edit the Cell</param>
 private void SetEditingCell(CellPos cellPos, ICellEditor editor)
 {
     this.editingCell = cellPos;
     this.curentCellEditor = editor;
 }
Exemple #23
0
 /// <summary>
 /// Removes the Cell at the specified row and column indicies from the current selection
 /// </summary>
 /// <param name="cellPos">A CellPos that specifies the Cell to remove from the selection</param>
 public void RemoveCell(CellPos cellPos)
 {
     this.RemoveCell(cellPos.Row, cellPos.Column);
 }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of the CellKeyEventArgs class with 
 /// the specified source Cell, table, row index, column index and 
 /// cell bounds
 /// </summary>
 /// <param name="cell">The Cell that Raised the event</param>
 /// <param name="table">The Table the Cell belongs to</param>
 /// <param name="cellPos"></param>
 /// <param name="cellRect">The Cell's bounding rectangle</param>
 /// <param name="kea"></param>
 public CellKeyEventArgs(Cell cell, Table table, CellPos cellPos, Rectangle cellRect, KeyEventArgs kea)
     : base(kea.KeyData)
 {
     this.cell = cell;
     this.table = table;
     this.row = cellPos.Row;
     this.column = cellPos.Column;
     this.cellRect = cellRect;
 }
Exemple #25
0
 /// <summary>
 /// Removes the Cells located between the specified start and end CellPos from the
 /// current selection
 /// </summary>
 /// <param name="start">A CellPos that specifies the start Cell</param>
 /// <param name="end">A CellPos that specifies the end Cell</param>
 public void RemoveCells(CellPos start, CellPos end)
 {
     this.RemoveCells(start.Row, start.Column, end.Row, end.Column);
 }
Exemple #26
0
 /// <summary>
 /// Removes the Cells located between the specified start and end CellPos from the
 /// current selection without raising an event
 /// </summary>
 /// <param name="start">A CellPos that specifies the start Cell</param>
 /// <param name="end">A CellPos that specifies the end Cell</param>
 /// <returns>true if any Cells were added, false otherwise</returns>
 private bool InternalRemoveCells(CellPos start, CellPos end)
 {
     return this.InternalRemoveCells(start.Row, start.Column, end.Row, end.Column);
 }
Exemple #27
0
            /// <summary>
            /// Replaces the currently selected Cells with the Cells located between the specified 
            /// start and end row/column indicies
            /// </summary>
            /// <param name="startRow">The row index of the start Cell</param>
            /// <param name="startColumn">The column index of the start Cell</param>
            /// <param name="endRow">The row index of the end Cell</param>
            /// <param name="endColumn">The column index of the end Cell</param>
            public void SelectCells(int startRow, int startColumn, int endRow, int endColumn)
            {
                int[] oldSelectedIndicies = this.SelectedIndicies;

                this.InternalClear();

                if (this.InternalAddCells(startRow, startColumn, endRow, endColumn))
                {
                    this.owner.OnSelectionChanged(new SelectionEventArgs(this.owner, oldSelectedIndicies, this.SelectedIndicies));
                }

                this.shiftSelectStart = new CellPos(startRow, startColumn);
                this.shiftSelectEnd = new CellPos(endRow, endColumn);
            }
Exemple #28
0
 public Cell this[CellPos cellPos]
 {
     get
     {
         return this[cellPos.Row, cellPos.Column];
     }
 }
Exemple #29
0
        /// <summary>
        /// Prepares the CellEditor to edit the specified Cell
        /// </summary>
        /// <param name="cell">The Cell to be edited</param>
        /// <param name="table">The Table that contains the Cell</param>
        /// <param name="cellPos">A CellPos representing the position of the Cell</param>
        /// <param name="cellRect">The Rectangle that represents the Cells location and size</param>
        /// <param name="userSetEditorValues">Specifies whether the ICellEditors 
        /// starting value has already been set by the user</param>
        /// <returns>true if the ICellEditor can continue editing the Cell, false otherwise</returns>
        public override bool PrepareForEditing(Cell cell, Table table, CellPos cellPos, Rectangle cellRect, bool userSetEditorValues)
        {
            //
            if (!(table.ColumnModel.Columns[cellPos.Column] is NumberColumn))
            {
                throw new InvalidOperationException("Cannot edit Cell as NumberCellEditor can only be used with a NumberColumn");
            }

            if (!(table.ColumnModel.GetCellRenderer(cellPos.Column) is NumberCellRenderer))
            {
                throw new InvalidOperationException("Cannot edit Cell as NumberCellEditor can only be used with a NumberColumn that uses a NumberCellRenderer");
            }

            this.Minimum = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Minimum;
            this.Maximum = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Maximum;
            this.Increment = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Increment;

            return base.PrepareForEditing (cell, table, cellPos, cellRect, userSetEditorValues);
        }
Exemple #30
0
        /// <summary>
        /// Returns whether the Cell at the specified CellPos is able 
        /// to respond to user interaction
        /// </summary>
        /// <param name="cellpos">A CellPos that specifies the Cell to check</param>
        /// <returns>True if the Cell at the specified CellPos is able 
        /// to respond to user interaction, false otherwise</returns>
        public bool IsCellEnabled(CellPos cellpos)
        {
            // don't bother if the cell doesn't exists or the cell's
            // column is not visible
            if (!this.IsValidCell(cellpos) || !this.ColumnModel.Columns[cellpos.Column].Visible)
            {
                return false;
            }

            return (this.TableModel[cellpos].Enabled &&
                this.ColumnModel.Columns[cellpos.Column].Enabled);
        }