internal GridItemBase FindItemFromPoint(Point point, out Point p) { int width = LeftOffset; int skipping = 0; foreach (string col in GridView.HeaderRow.Columns) { GridItemBase item = GetItem(col); if (item is GridEmptyItem && skipping > 0) { skipping--; continue; } skipping = item.RowSpan - 1; int itwidth = GridView.GetColumnWidth(col, item.RowSpan); if (point.X >= width && point.X < width + itwidth) { p = new Point(point.X - width, point.Y); return(item); } width += itwidth; } p = new Point(); return(null); }
/* * Asserts are here to ensure these events happen in order. * That order being OnEnter, OnMouseMove, OnLeave. */ internal void OnEnter(Point point) { System.Diagnostics.Trace.Assert(LastSubRow == null); System.Diagnostics.Trace.Assert(LastItem == null); Point p; if (point.Y > RowHeight) { LastSubRow = FindRowFromPoint(point, out p); if (LastSubRow == null) { return; } LastSubRow.OnEnter(p); } else { LastItem = FindItemFromPoint(point, out p); if (LastItem == null) { return; } LastItem.OnEnter(p); } }
public override int CompareTo(GridItemBase other) { GridVerticalArrayItem otherArrayItem = other as GridVerticalArrayItem; if (otherArrayItem == null) { return(-1); } for (int i = 0; i < items.Length; i++) { if (i >= otherArrayItem.items.Length) { return(1); } int comp = items[i].CompareTo(otherArrayItem.items[i]); if (comp != 0) { return(comp); } } return(items.Length == otherArrayItem.items.Length ? 0 : -1); }
internal int ItemColumnSpan(GridItemBase item, string col) { if (GridView == null || GridView.HeaderRow == null) { return(1); } int colindex = GridView.HeaderRow.Columns.IndexOf(col); int span = 1; for (int i = colindex + 1; i < colindex + item.RowSpan; i++) { if (GridView.HeaderRow.Columns.Count <= i) { break; } string name = GridView.HeaderRow.Columns[i]; if (!Items.ContainsKey(name)) { span++; continue; } if (Items[name].Empty) { span++; } else { break; } } return(span); }
public override void OnMouseMove(Point point) { Point subItemPoint; GridItemBase subItem = CurrentItem(point, out subItemPoint); if (mouseTrackedItem != subItem) { if (mouseTrackedItem != null) { mouseTrackedItem.OnLeave(); } mouseTrackedItem = subItem; if (subItem != null) { subItem.OnEnter(subItemPoint); } } if (mouseTrackedItem != null) { mouseTrackedItem.OnMouseMove(subItemPoint); } }
private void FitColumnWidthToHeaderAndContents(GridRow currentRow, Point p) { GridHeaderItem headerItem = (GridHeaderItem)currentRow.FindItemFromPoint(new Point(p.X - GridHeaderItem.ResizeGutter, p.Y), out ResizeColumnsInitialMouseLocation); ResizeColumnsInitialMouseLocation.X += GridHeaderItem.ResizeGutter; ActiveColumn = headerItem.ColumnName; if (HeaderRow.Items.ContainsKey(ActiveColumn)) { int maxWidth = headerItem.MinimumWidth; foreach (GridRow row in RowsAndChildren) { GridItemBase _item = row.GetItem(ActiveColumn); int itemWidth = _item.GetGridItemWidth(ActiveColumn); if (itemWidth > maxWidth) { maxWidth = itemWidth; } } headerItem.Width = maxWidth; Refresh(); } }
public void OnPaint(RowPaintArgs e) { if (GridView == null || GridView.HeaderRow == null) { return; } if (HasLeftExpander) { // paint background using (Brush brush = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(brush, e.Rectangle); } if (BorderPen != null) { e.Graphics.DrawRectangle(BorderPen, e.Rectangle); } Image im = Expanded ? ExpandedImage : ShrunkenImage; e.Graphics.DrawImage(im, e.Rectangle.X + im.Width, e.Rectangle.Y + im.Height, im.Width, im.Height); } // paint this row int totalHeight = RowHeight; int left = e.Rectangle.Left + LeftOffset; int top = e.Rectangle.Top; foreach (string col in GridView.HeaderRow.Columns) { GridItemBase item = GetItem(col); int itemwidth = GridView.GetColumnWidth(col, ItemColumnSpan(item, col)); if (left >= e.ClipRectangle.Left - itemwidth && left <= e.ClipRectangle.Right + itemwidth) { item.OnPaint(new ItemPaintArgs(e.Graphics, new Rectangle(left, top, itemwidth, totalHeight), Selected ? ItemState.Selected : ItemState.Normal)); } left += GridView.GetColumnWidth(col, 1); } // paint subrows if (HasVisibleChildren) { top += RowHeight + RowSeparation; foreach (GridRow row in Rows) { int rowheight = row.RowAndChildrenHeight; if (top >= e.ClipRectangle.Top - rowheight && top <= e.ClipRectangle.Bottom + rowheight) { row.OnPaint(new RowPaintArgs(e.Graphics, e.ClipRectangle, new Rectangle(e.Rectangle.Left, top, e.Rectangle.Width, rowheight))); } top += rowheight + row.SpaceAfter; } } }
public override void OnLeave() { if (mouseTrackedItem == null) { return; } mouseTrackedItem.OnLeave(); mouseTrackedItem = null; }
public override int CompareTo(GridItemBase other) { GridImageItem imageItem = other as GridImageItem; if (imageItem == null) { return(-1); } return(StringUtility.NaturalCompare(rankObject.ToString(), imageItem.rankObject.ToString())); }
public override void OnMouseButtonAction(Point point, MouseButtonAction type) { Point subItemPoint; GridItemBase subItem = CurrentItem(point, out subItemPoint); if (subItem != null) { subItem.OnMouseButtonAction(subItemPoint, type); } else { base.OnMouseButtonAction(point, type); } }
public override void OnEnter(Point point) { if (mouseTrackedItem != null) { OnLeave(); } Point subItemPoint; mouseTrackedItem = CurrentItem(point, out subItemPoint); if (mouseTrackedItem != null) { mouseTrackedItem.OnEnter(subItemPoint); } }
internal void OnLeave() { // Make sure only one is valid System.Diagnostics.Trace.Assert(LastItem == null || LastSubRow == null); if (LastItem != null) { LastItem.OnLeave(); LastItem = null; } if (LastSubRow != null) { LastSubRow.OnLeave(); LastSubRow = null; } }
public override int CompareTo(GridItemBase gridItem) { GridStringItem other = gridItem as GridStringItem; Object otherdata = other == null ? null : other.sortdata; if (sortdata == null) { return(otherdata == null ? 0 : 1); } if (otherdata == null) { return(-1); } return(StringUtility.NaturalCompare(sortdata.ToString(), other.sortdata.ToString())); }
public override void AddItem(string col, GridItemBase item) { GridHeaderItem headerItem = item as GridHeaderItem; if (headerItem == null) { return; } if (headerItem.IsDefaultSortColumn) { DefaultSortColumn = headerItem; } Columns.Add(col); headerItem.ColumnName = col; base.AddItem(col, item); }
internal void OnMouseButtonAction(Point point, MouseButtonAction type) { if (HasLeftExpander) { Image image = Expanded ? ExpandedImage : ShrunkenImage; Size s = new Size(image.Width * 3, image.Height * 3); Rectangle r = new Rectangle(new Point(), s); if (r.Contains(point)) { if (type == MouseButtonAction.MouseDown) { Expanded = !Expanded; GridView.Refresh(); } else { return; } } } if (point.Y < RowHeight) // user has clicked on the row { Point p; GridItemBase item = FindItemFromPoint(point, out p); if (item == null) { return; } item.OnMouseButtonAction(p, type); return; } else // user has clicked on a sub row of the row { Point p; GridRow row = FindRowFromPoint(point, out p); if (row == null) { return; } row.OnMouseButtonAction(p, type); } }
internal void OnMouseMove(Point point) { if (HasLeftExpander) { Image image = Expanded ? ExpandedImage : ShrunkenImage; Rectangle r = new Rectangle(image.Width, image.Height, image.Width, image.Height); Cursor = r.Contains(point) ? Cursors.Hand : Cursors.Default; } // Make sure only one is valid System.Diagnostics.Trace.Assert(LastItem == null || LastSubRow == null); Point p; if (point.Y > RowHeight) { if (LastItem != null) { LastItem.OnLeave(); LastItem = null; } GridRow row = FindRowFromPoint(point, out p); if (row != null && LastSubRow == row) { LastSubRow.OnMouseMove(p); return; } if (LastSubRow != null) { LastSubRow.OnLeave(); } LastSubRow = row; if (LastSubRow != null) { LastSubRow.OnEnter(p); } } else { if (LastSubRow != null) { LastSubRow.OnLeave(); LastSubRow = null; } GridItemBase item = FindItemFromPoint(point, out p); if (item != null && LastItem == item) { LastItem.OnMouseMove(p); return; } if (LastItem != null) { LastItem.OnLeave(); } LastItem = item; if (LastItem != null) { LastItem.OnEnter(p); } } }
public virtual void AddItem(string colname, GridItemBase item) { Items[colname] = item; item.Row = this; }