public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid) { Rectangle rect_header; Rectangle icon_bounds = new Rectangle (); Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor); /* paint the header if it's visible and intersects the clip */ if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { rect_header = row_rect; rect_header.Width = grid.RowHeaderWidth; row_rect.X += grid.RowHeaderWidth; if (clip.IntersectsWith (rect_header)) { DataGridPaintRowHeader (g, rect_header, row, grid); } icon_bounds = rect_header; icon_bounds.X += icon_bounds.Width / 2; icon_bounds.Y += 3; icon_bounds.Width = 8; icon_bounds.Height = 8; g.DrawRectangle (pen, icon_bounds); /* the - part of the icon */ g.DrawLine (pen, icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2, icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2); if (!grid.IsExpanded (row)) { /* the | part of the icon */ g.DrawLine (pen, icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2, icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2); } } Rectangle nested_rect = row_rect; if (grid.DataGridRows[row].IsExpanded) nested_rect.Height -= grid.DataGridRows[row].RelationHeight; DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid); if (grid.DataGridRows[row].IsExpanded) { // XXX we should create this in the // datagrid and cache it for use by // the theme instead of doing it each // time through here string[] relations = grid.CurrentTableStyle.Relations; StringBuilder relation_builder = new StringBuilder (""); for (int i = 0; i < relations.Length; i ++) { if (i > 0) relation_builder.Append ("\n"); relation_builder.Append (relations[i]); } string relation_text = relation_builder.ToString (); StringFormat string_format = new StringFormat (); string_format.FormatFlags |= StringFormatFlags.NoWrap; //Region prev_clip = g.Clip; //Region current_clip; Rectangle rect_cell = row_rect; rect_cell.X = nested_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset; rect_cell.Y += nested_rect.Height; rect_cell.Height = grid.DataGridRows[row].RelationHeight; rect_cell.Width = 0; int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) continue; rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width; } rect_cell.Width = Math.Max (rect_cell.Width, grid.DataGridRows[row].relation_area.Width); g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor), rect_cell); /* draw the line leading from the +/- to the relation area */ Rectangle outline = grid.DataGridRows[row].relation_area; outline.Y = rect_cell.Y; outline.Height --; g.DrawLine (pen, icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height, icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2); g.DrawLine (pen, icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2, outline.X, outline.Y + outline.Height / 2); g.DrawRectangle (pen, outline); g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor), outline, string_format); if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) { Rectangle not_usedarea = new Rectangle (); not_usedarea.X = rect_cell.X + rect_cell.Width; not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width; not_usedarea.Y = row_rect.Y; not_usedarea.Height = row_rect.Height; if (clip.IntersectsWith (not_usedarea)) g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea); } } }
public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid) { Rectangle rect_cell = new Rectangle (); int col_pixel; Color backcolor, forecolor; Brush backBrush, foreBrush; Rectangle not_usedarea = Rectangle.Empty; rect_cell.Y = row_rect.Y; rect_cell.Height = row_rect.Height; if (grid.IsSelected (row)) { backcolor = grid.SelectionBackColor; forecolor = grid.SelectionForeColor; } else { if (row % 2 == 0) { backcolor = grid.BackColor; } else { backcolor = grid.AlternatingBackColor; } forecolor = grid.ForeColor; } backBrush = ResPool.GetSolidBrush (backcolor); foreBrush = ResPool.GetSolidBrush (forecolor); // PaintCells at row, column int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; DataGridCell current_cell = grid.CurrentCell; if (column_cnt > 0) { Region prev_clip = g.Clip; Region current_clip; for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) continue; col_pixel = grid.GetColumnStartingPixel (column); rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset; rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width; if (clip.IntersectsWith (rect_cell)) { current_clip = new Region (rect_cell); current_clip.Intersect (row_rect); current_clip.Intersect (prev_clip); g.Clip = current_clip; Brush colBackBrush = backBrush; Brush colForeBrush = foreBrush; // If we are in the precise cell we are editing, then use the normal colors // even if we are selected. if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) { colBackBrush = ResPool.GetSolidBrush (grid.BackColor); colForeBrush = ResPool.GetSolidBrush (grid.ForeColor); } if (is_newrow) { grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, colBackBrush, colForeBrush); } else { grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row, colBackBrush, colForeBrush, grid.RightToLeft == RightToLeft.Yes); } current_clip.Dispose (); } } g.Clip = prev_clip; if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) { not_usedarea.X = rect_cell.X + rect_cell.Width; not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width; not_usedarea.Y = row_rect.Y; not_usedarea.Height = row_rect.Height; } } else { not_usedarea = row_rect; } if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea)) g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea); }
public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid) { if (!grid.CurrentTableStyle.ColumnHeadersVisible) return; Rectangle columns_area = grid.column_headers_area; // Paint corner shared between row and column header if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { Rectangle rect_bloc = grid.column_headers_area; rect_bloc.Width = grid.RowHeaderWidth; if (clip.IntersectsWith (rect_bloc)) { if (grid.FlatMode) g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc); else CPDrawBorder3D (g, rect_bloc, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Middle, grid.CurrentTableStyle.CurrentHeaderBackColor); } columns_area.X += grid.RowHeaderWidth; columns_area.Width -= grid.RowHeaderWidth; } // Set column painting Rectangle rect_columnhdr = new Rectangle (); int col_pixel; Region current_clip; Region prev_clip = g.Clip; rect_columnhdr.Y = columns_area.Y; rect_columnhdr.Height = columns_area.Height; int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) continue; col_pixel = grid.GetColumnStartingPixel (column); rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset; rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width; if (clip.IntersectsWith (rect_columnhdr) == false) continue; current_clip = new Region (rect_columnhdr); current_clip.Intersect (columns_area); current_clip.Intersect (prev_clip); g.Clip = current_clip; DataGridPaintColumnHeader (g, rect_columnhdr, grid, column); current_clip.Dispose (); } g.Clip = prev_clip; Rectangle not_usedarea = grid.column_headers_area; not_usedarea.X = (column_cnt == 0) ? grid.RowHeaderWidth : rect_columnhdr.X + rect_columnhdr.Width; not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - not_usedarea.X; g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea); }