SetCellRect() private method

private SetCellRect ( Rectangle cellRect ) : void
cellRect System.Drawing.Rectangle
return void
示例#1
0
文件: Table.cs 项目: zhuangyy/Motion
        /// <summary>
        /// Paints the Cell at the specified row and column indexes
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data</param>
        /// <param name="row">The index of the row that contains the cell to be painted</param>
        /// <param name="column">The index of the column that contains the cell to be painted</param>
        /// <param name="cellRect">The bounding Rectangle of the Cell</param>
        protected void OnPaintCell(PaintEventArgs e, int row, int column, Rectangle cellRect)
        {
            if (row == 0 && column == 1)
            {
                column = 1;
            }

            // get the renderer for the cells column
            ICellRenderer renderer = this.ColumnModel.Columns[column].Renderer;
            if (renderer == null)
            {
                // get the default renderer for the column
                renderer = this.ColumnModel.GetCellRenderer(this.ColumnModel.Columns[column].GetDefaultRendererName());
            }

            // if the renderer is still null (which it shouldn't)
            // the get out of here
            if (renderer == null)
            {
                return;
            }

            ////////////
            // Adjust the rectangle for this cell to include any cells that it colspans over
            Rectangle realRect = cellRect;
            Cell thisCell = this.TableModel[row, column];
            if (thisCell != null && thisCell.ColSpan > 1)
            {
                int width = this.GetColumnWidth(column, thisCell);
                realRect = new Rectangle(cellRect.X, cellRect.Y, width, cellRect.Height);
            }
            ////////////

            PaintCellEventArgs pcea = new PaintCellEventArgs(e.Graphics, realRect);
            pcea.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle, realRect));

            if (column < this.TableModel.Rows[row].Cells.Count)
            {
                // is the cell selected
                bool selected = false;

                if (this.FullRowSelect)
                {
                    selected = this.TableModel.Selections.IsRowSelected(row);
                }
                else
                {
                    if (this.SelectionStyle == SelectionStyle.ListView)
                    {
                        if (this.TableModel.Selections.IsRowSelected(row) && this.ColumnModel.PreviousVisibleColumn(column) == -1)
                        {
                            selected = true;
                        }
                    }
                    else if (this.SelectionStyle == SelectionStyle.Grid)
                    {
                        if (this.TableModel.Selections.IsCellSelected(row, column))
                        {
                            selected = true;
                        }
                    }
                }

                //
                bool editable = this.TableModel[row, column].Editable && this.TableModel.Rows[row].Editable && this.ColumnModel.Columns[column].Editable;
                bool enabled = this.TableModel[row, column].Enabled && this.TableModel.Rows[row].Enabled && this.ColumnModel.Columns[column].Enabled;

                // draw the cell
                pcea.SetCell(this.TableModel[row, column]);
                pcea.SetRow(row);
                pcea.SetColumn(column);
                pcea.SetTable(this);
                pcea.SetSelected(selected);
                pcea.SetFocused(this.Focused && this.FocusedCell.Row == row && this.FocusedCell.Column == column);
                pcea.SetSorted(column == this.lastSortedColumn);
                pcea.SetEditable(editable);
                pcea.SetEnabled(enabled);
                pcea.SetCellRect(realRect);
            }
            else
            {
                // there isn't a cell for this column, so send a
                // null value for the cell and the renderer will
                // take care of the rest (it should draw an empty cell)

                pcea.SetCell(null);
                pcea.SetRow(row);
                pcea.SetColumn(column);
                pcea.SetTable(this);
                pcea.SetSelected(false);
                pcea.SetFocused(false);
                pcea.SetSorted(false);
                pcea.SetEditable(false);
                pcea.SetEnabled(false);
                pcea.SetCellRect(realRect);
            }

            // let the user get the first crack at painting the cell
            this.OnBeforePaintCell(pcea);

            // only send to the renderer if the user hasn't
            // set the handled property
            if (!pcea.Handled)
            {
                renderer.OnPaintCell(pcea);
            }

            // let the user have another go
            this.OnAfterPaintCell(pcea);
        }