public void FullCollapse(GridCell branch) { Expand(_rootCell, false, branch); MeasureCells(); UpdateScrollRange(); Refresh(); }
public GridCell ForwardCell(GridCell cell) { GridCell curr = cell; while (curr.Parent != null) if (curr.Col < curr.Owner.Width - 1) return FrontCell(curr.Owner[curr.Col + 1, curr.Row]); else curr = curr.Parent; return null; }
public GridCell FrontCell(GridCell cell) { if (cell != null && cell.IsGroup) { GridCellGroup group = (GridCellGroup)cell; if (group.Overlaped) return FrontCell(group.FirstChild()); } return cell; }
private void DrawCell(Graphics g, int x, int y, GridCell cell, int pixelWidth, int pixelHeight, bool isSelected) { Rectangle cellRect = Rectangle.FromLTRB(x + 1, y + 1, x + pixelWidth, y + pixelHeight); Brush brush; if (cell is GridHeadLabel) { brush = new LinearGradientBrush(cellRect, Color.White, SystemColors.ButtonFace, LinearGradientMode.Vertical); } else { Color color; if (cell == _focusedCell) { if (Focused) color = Color.FromArgb(0xA6, 0xCA, 0xF0); else color = SystemColors.InactiveCaption; } else if (isSelected) if (cell is GridRowLabel || cell is GridColumnLabel) color = Color.FromArgb(0x00, 0x00, 0xFF); else if (Focused) color = Color.FromArgb(0x31, 0x6A, 0xC5); else if (String.IsNullOrEmpty(cell.Text)) color = Color.White; else color = Color.FromArgb(0xF4, 0xF7, 0xFC); else if (cell is GridRowLabel || cell is GridColumnLabel) color = Color.FromArgb(0xFF, 0xFF, 0xC0); else if (String.IsNullOrEmpty(cell.Text)) color = Color.FromArgb(0xF0, 0xF0, 0xF0); else color = BackColor; brush = new SolidBrush(color); } Brush textBrush = new SolidBrush(ForeColor); g.FillRectangle(brush, cellRect); if (cell == _focusedCell) ControlPaint.DrawFocusRectangle(g, cellRect); if (cell.ImageIndex != -1) { if (cell.ImageIndex <= 1) g.DrawImage(_images.Images[cell.ImageIndex], x + 5, y + 3); else g.DrawImage(_images.Images[cell.ImageIndex], x + 2, y + 2); cellRect.X += _images.ImageSize.Width +1; cellRect.Width -= _images.ImageSize.Width + 1; } cellRect.Offset(0, -1); cellRect.Inflate(-3, -1); StringFormat sf = cell.GetStringFormat(); if (cell is GridRowLabel || cell is GridColumnLabel) { Font font = new Font(Font, FontStyle.Bold); if (cell is GridRowLabel) sf.Alignment = StringAlignment.Far; g.DrawString(cell.Text, font, textBrush, cellRect, sf); } else if (cell.Text != null) cell.DrawCellText(this, g, Font, textBrush, sf, _drawInfo, cellRect); }
public Rectangle FindCellRect(GridCell cell) { Rectangle cellRect = new Rectangle(0, 0, _drawInfo.iMaxWidth, _drawInfo.iHeight); Rectangle rc = FindCellRect(_rootCell, cellRect, cell); return rc; }
public void MakeCellVisible(Graphics g, GridCell cell, bool fullVisible) { ExpandParentCell(cell); Rectangle rcClient = GetClientRect(); Rectangle rcWindow = GetWindowRect(); Rectangle rc = FindCellRect(cell); if (rc.IsEmpty) return; int X = -1; if (rc.Left < rcWindow.Left || GetCellRight(g, cell, rc, fullVisible) > rcWindow.Right) if (rc.Width < rcClient.Right) { X = 0; for (int i = 0; i < _columnsWidth.Length; i++) { if (X <= rc.Left && rc.Right <= X + rcClient.Right) { int dist = Math.Abs(X - rcWindow.Left); for (int k = i + 1; k < _columnsWidth.Length; k++) { int v = X + _columnsWidth[k]; if (!(v <= rc.Left && rc.Right <= v + rcClient.Right) || (dist < Math.Abs(v - rcWindow.Left))) break; X = v; dist = Math.Abs(v - rcWindow.Left); } break; } X += _columnsWidth[i]; } } else X = rc.Left; int Y = -1; if (GetCellBottom(g, cell, rc, fullVisible) > rcWindow.Bottom || rc.Top < rcWindow.Top) if (rc.Height < rcClient.Bottom) { Y = 0; for (int i = 0; i < _rowHeight.Length; i++) { if (Y <= rc.Top && rc.Bottom <= Y + rcClient.Bottom) { int dist = Math.Abs(Y - rcWindow.Top); for (int s = i + 1; s < _rowHeight.Length; s++) { int v = Y + _rowHeight[s]; if (ShowColumnHeader) { if (!(v < rc.Top && rc.Bottom <= v + rcClient.Height) || (dist < Math.Abs(v - rcWindow.Top))) break; } else { if (!(v <= rc.Top && rc.Bottom <= v + rcClient.Height) || (dist < Math.Abs(v - rcWindow.Top))) break; } Y = v; dist = Math.Abs(Y - rcWindow.Top); } break; } Y += _rowHeight[i]; } } else if (rc.Top + _drawInfo.cyChar <= rcWindow.Top) Y = rc.Top; if (X != -1) X = X / _drawInfo.cxChar; if (Y != -1) Y = Y / _drawInfo.cyChar; ScrollTo(X, Y); }
public GridCell PriorCell(GridCell cell) { if (cell != null) { if (cell.Row == 0) { if (cell.Parent != _rootCell) if (cell.Parent.Overlaped) return BottomCell(PriorCell(cell.Parent)); else return cell.Parent; else return null; } else if (ShowColumnHeader && cell.Parent == _rootCell && cell.Row == 1) return null; else return BottomCell(cell.Owner[cell.Col, cell.Row - 1]); } else return null; }
private void SetFocusedCell(GridCell cell) { GridCell target = null; if (cell != null && cell.Parent != null && cell.Index == 0 && cell is GridRowLabel) target = cell.Parent; else target = cell; if (target != _focusedCell) { if (target == _rootCell) _focusedCell = null; else _focusedCell = target; Invalidate(); } }
public GridCell BackwardCell(GridCell cell) { if (cell.Col > 0) return FrontCell(cell.Owner[cell.Col - 1, cell.Row]); else { GridCell res = cell; while (res.Parent != _rootCell && res.Parent != null && res.Parent.Overlaped) res = res.Parent; return res; } }
private int GetCellRight(Graphics g, GridCell cell, Rectangle cellRect, bool fullVisible) { if (fullVisible) return cellRect.Right; else return cellRect.Left + Math.Max(cell.GetTextWidth(this, g, Font, _drawInfo), _rowNumWidth); }
private GridCell GetRootCell(GridCell cell) { while (cell.Parent != _rootCell) cell = cell.Parent; return cell; }
private int GetCellBottom(Graphics g, GridCell cell, Rectangle cellRect, bool fullVisible) { if (fullVisible || !cell.IsGroup) return cellRect.Bottom; else return cellRect.Top + _drawInfo.cyChar; }
private Rectangle FindCellRect(GridCellGroup cell, Rectangle cellRect, GridCell dest) { if (cell.Expanded) { int rcLeft = cellRect.Right - cell.TableWidth - cell.TablePadding; for (int k = 0; k < cell.Table.Width; k++) { int rcRight = rcLeft + cell.Table.ColumnsWidth[k]; int rcTop = cellRect.Bottom - cell.TableHeight; for (int s = 0; s < cell.Table.Height; s++) { int rcBottom = rcTop + cell.Table.RowHeight[s]; Rectangle rc = Rectangle.FromLTRB(rcLeft, rcTop, rcRight, rcBottom); if (cell.Table[k, s] == dest) return rc; else if (cell.Table[k, s].IsGroup) { rc = FindCellRect((GridCellGroup)cell.Table[k, s], rc, dest); if (!rc.IsEmpty) return rc; } rcTop = rcBottom; } rcLeft = rcRight; } } return Rectangle.Empty; }
private void Expand(GridCellGroup cell, bool expand, GridCell stopCell) { for (int k = 0; k < cell.Table.Width; k++) for (int s = 0; s < cell.Table.Height; s++) if (cell.Table[k, s].IsGroup && stopCell != cell.Table[k, s]) { GridCellGroup child = (GridCellGroup)cell.Table[k, s]; if (!child.Overlaped) if (expand) { child.BeforeExpand(); child.Flags = child.Flags | GroupFlags.Expanded; } else child.Flags = child.Flags & ~GroupFlags.Expanded; Expand(child, expand, stopCell); } }
public HitTest GetHitTest(Point p, out GridCell cell) { Rectangle cellRect = new Rectangle(); cell = FindCellByPoint(p, ref cellRect); if (cell != null) { Rectangle rc; if (cell.ImageIndex != -1) { rc = new Rectangle(cellRect.Left + 2, cellRect.Top + 2, _images.ImageSize.Width, _images.ImageSize.Height); if (rc.Contains(p)) return HitTest.Icon; } rc = cellRect; rc.X++; rc.Offset(0, 0); rc.Inflate(-3, 0); if (rc.Contains(p)) return HitTest.Text; else return HitTest.Cell; } else return HitTest.Nothing; }
public GridCell BottomCell(GridCell cell) { if (cell != null && cell.IsGroup) { GridCellGroup group = (GridCellGroup)cell; if (group.Expanded) if (group.Overlaped) return BottomCell(group.LastChild()); else return FrontCell(group); } return cell; }
public void HighlightCell(GridCell cell, bool collapse) { if (collapse) FullCollapse(cell); ExpandParentCell(cell); using (Graphics g = CreateGraphics()) MakeCellVisible(g, cell, false); _focusedCell = cell; }
public void Clear() { _focusedCell = null; _rootCell = null; UpdateTextMetrics(); MeasureCells(); UpdateScrollRange(); Invalidate(); }
public GridCell NextCell(GridCell cell, bool canEnter) { if (cell != null) { if (cell.IsGroup) { GridCellGroup group = (GridCellGroup)cell; if (group.Expanded && canEnter) return FrontCell(group.FirstChild()); } if (cell.Row == cell.Owner.Height - 1) { if (cell.Parent != _rootCell) return NextCell(cell.Parent, false); else return null; } else return FrontCell(cell.Owner[cell.Col, cell.Row + 1]); } else return null; }
public void ExpandParentCell(GridCell cell) { bool needMeasure = false; GridCellGroup parent = cell.Parent; while (parent != null) { if (!parent.Expanded) { parent.Flags = parent.Flags | GroupFlags.Expanded; needMeasure = true; } parent = parent.Parent; } if (needMeasure) { MeasureCells(); UpdateScrollRange(); } }
private int CountCellColumns(GridCell cell) { if (cell.IsGroup) { GridCellGroup group = (GridCellGroup)cell; if (group.Expanded) { GridCellTable table = group.Table; int res = 0; for (int k = 0; k < table.Width; k++) { int cols = 1; for (int s = 0; s < table.Height; s++) cols = Math.Max(cols, CountCellColumns(table[k, s])); res += cols; } if (! (group.TableView || group.Overlaped)) res++; return res; } } return 1; }
private int CountCellRows(GridCell cell) { if (cell.IsGroup) { GridCellGroup group = (GridCellGroup)cell; if (group.Expanded) { GridCellTable table = group.Table; int res = 0; for (int s = 0; s < table.Height; s++) { int rows = 1; for (int k = 0; k < table.Width; k++) rows = Math.Max(rows, CountCellRows(table[k, s])); res += rows; } if (!group.Overlaped) res++; return res; } } return 1; }