private int Compare(CustomListBoxItem item1, CustomListBoxItem item2) { var i1 = item1 as IssueListItem; if(i1 == null) return 0; var i2 = item2 as IssueListItem; if(i2 == null) return 0; return Compare(i1, i2); }
public static int CompareByName(CustomListBoxItem item1, CustomListBoxItem item2) { var i1 = item1 as ITreeItemListItem; if(i1 == null) return 0; var i2 = item2 as ITreeItemListItem; if(i2 == null) return 0; try { return CompareByName(i1, i2); } catch(Exception exc) { if(exc.IsCritical()) { throw; } return 0; } }
private static void _expand_all(CustomListBoxItem item) { item.IsExpanded = true; if(item.Items.Count != 0) { foreach(var i in item.Items) { _expand_all(i); } } }
public abstract void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
public abstract void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
public override void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs) { var state = paintEventArgs.State; if(state == ItemState.None) return; bool isHovered = (state & ItemState.Hovered) == ItemState.Hovered; bool isSelected = (state & ItemState.Selected) == ItemState.Selected; bool isFocused = (state & ItemState.Focused) == ItemState.Focused; Brush brush = null; Pen pen = null; if(isSelected) { if(paintEventArgs.IsHostControlFocused) { if(isHovered) { brush = new SolidBrush(ColorTable.SelectionBackground); } else if(isFocused) { brush = new SolidBrush(ColorTable.SelectionBackground); } else { brush = new SolidBrush(ColorTable.SelectionBackground); } } else { if(isHovered) { brush = new SolidBrush(ColorTable.SelectionBackgroundNoFocus); } else { brush = new SolidBrush(ColorTable.SelectionBackgroundNoFocus); } } } else { if(isHovered) { if(isFocused && paintEventArgs.IsHostControlFocused) { brush = new SolidBrush(ColorTable.HoverBackground); pen = new Pen(ColorTable.FocusBorder); } else { brush = new SolidBrush(ColorTable.HoverBackground); } } else if(isFocused) { if(paintEventArgs.IsHostControlFocused) { pen = new Pen(ColorTable.FocusBorder); } } } if(brush != null) { var itemBounds = Rectangle.Intersect(paintEventArgs.ClipRectangle, paintEventArgs.Bounds); if(itemBounds.Width > 0 && itemBounds.Height > 0) { paintEventArgs.Graphics.FillRectangle(brush, itemBounds); } brush.Dispose(); } if(pen != null) { var rect = paintEventArgs.Bounds; rect.Width -= 1; rect.Height -= 1; paintEventArgs.Graphics.DrawRectangle(pen, rect); pen.Dispose(); } }
public void RemoveItem(CustomListBoxItem item) { _lstRepositoryExplorer.Items.Remove(item); }
public override void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs) { var state = paintEventArgs.State; if(state == ItemState.None) return; bool hovered = (state & ItemState.Hovered) == ItemState.Hovered; bool selected = (state & ItemState.Selected) == ItemState.Selected; bool focused = (state & ItemState.Focused) == ItemState.Focused; IBackgroundStyle background = null; if(selected) { if(paintEventArgs.IsHostControlFocused) { if(hovered) { background = BackgroundStyle.SelectedFocused; } else if(focused) { background = BackgroundStyle.SelectedFocused; } else { background = BackgroundStyle.Selected; } } else { if(hovered) { background = BackgroundStyle.SelectedFocused; } else { background = BackgroundStyle.SelectedNoFocus; } } } else { if(hovered) { if(focused && paintEventArgs.IsHostControlFocused) { background = BackgroundStyle.HoveredFocused; } else { background = BackgroundStyle.Hovered; } } else if(focused) { if(paintEventArgs.IsHostControlFocused) { background = BackgroundStyle.Focused; } } } if(background != null) { background.Draw(paintEventArgs.Graphics, paintEventArgs.Bounds); } }
internal void CollapseItem(CustomListBoxItem item) { Assert.IsNotNull(item); if(item.Items.Count == 0 || !item.IsPresented) return; var itemId = _itemPlainList.IndexOf(item); if(itemId == -1) return; var id = itemId + 1; int pos = id; var level = _itemPlainList[pos].Level; ++pos; while(pos < _itemPlainList.Count && _itemPlainList[pos].Level >= level) ++pos; for(int i = id; i < pos && _selectedItems.Count != 0; ++i) { var s = _selectedItems.IndexOf(_itemPlainList[i]); if(s != -1) _selectedItems.RemoveAt(s); } _itemPlainList.RemoveRange(id, pos - id); if(_itemHover.Index > id) { if(_itemHover.Index < pos) { _itemHover.Drop(); } else { _itemHover.ResetIndex(_itemHover.Index - (pos - id)); } } if(_itemFocus.Index > id) { if(_itemFocus.Index < pos) { _itemFocus.Drop(); } else { _itemFocus.ResetIndex(_itemFocus.Index - (pos - id)); } } if(_lastClickedItemIndex >= id) { if(_lastClickedItemIndex < pos) { _lastClickedItemIndex = -1; } else { _lastClickedItemIndex -= pos - id; } } NotifyContentSizeChanged(); if(_haveAutoSizeColumns) { InvalidateAutoSizeColumns(); } }
/// <summary>Ensures that <paramref name="item"/> is visible to user.</summary> /// <param name="item">Item to display.</param> public void EnsureVisible(CustomListBoxItem item) { Verify.Argument.IsNotNull(item, "item"); Verify.Argument.IsTrue(item.ListBox == this, "item", "This item is not owned by this list box."); var parent = item.Parent; while(parent != null) { parent.IsExpanded = true; parent = parent.Parent; } var id = _itemPlainList.IndexOf(item); EnsureVisible(id); }
private int InsertItem(int index, CustomListBoxItem item) { int id = index; _itemPlainList.Insert(id++, item); if(item.IsSelected) { _selectedItems.Add(item); } if(_itemFocus.Index >= index) { _itemFocus.ResetIndex(_itemFocus.Index + 1); } if(_itemHover.Index >= index) { _itemHover.ResetIndex(_itemHover.Index + 1); } if(item.IsExpanded) { foreach(var i in item.Items) { id = InsertItem(id++, i); } } return id; }
private ItemState GetItemState(CustomListBoxItem item, int index, out int hoveredPart) { var state = ItemState.None; if(item.IsSelected) { state |= ItemState.Selected; } if(_itemFocus.Index == index) { state |= ItemState.Focused; } if(_itemHover.Index == index) { state |= ItemState.Hovered; hoveredPart = _itemHover.PartId; } else { hoveredPart = ItemHitTestResults.Default; } return state; }
private static CustomListBoxItem FindLastVisibleItem(CustomListBoxItem item) { if(item.Items.Count == 0 || !item.IsExpanded) return item; return FindLastVisibleItem(item.Items[item.Items.Count - 1]); }
protected virtual void OnItemCheckedChanged(CustomListBoxItem item) { var handler = (EventHandler<ItemEventArgs>)Events[ItemCheckedChangedEvent]; if(handler != null) handler(this, new ItemEventArgs(item)); }
internal CustomListBoxTextEditor StartTextEditor(CustomListBoxItem item, CustomListBoxColumn column, Font font, string text) { StopTextEditor(); EnsureVisible(item); int id = _itemPlainList.IndexOf(item); int y = _itemsArea.Top + GetItemY1Offset(id); int x = column.Left; int w = column.Width; int h = _itemHeight; var rc = new Rectangle(x, y, w, h); _textEditor = new TextBox() { Font = font, BorderStyle = BorderStyle.FixedSingle, Text = text, BackColor = Style.Colors.Window, ForeColor = Style.Colors.WindowText, MinimumSize = rc.Size, MaximumSize = rc.Size, Bounds = rc, Parent = this, CausesValidation = true, }; _textEditor.Focus(); _textEditor.SelectAll(); return new CustomListBoxTextEditor(this, _textEditor); }
public static int UniversalComparer(CustomListBoxItem item1, CustomListBoxItem item2) { if(item1.GetType() == item2.GetType()) { var branchItem = item1 as BranchListItem; if(branchItem != null) { return BranchListItem.CompareByName(branchItem, (BranchListItem)item2); } var remoeBranchItem = item1 as RemoteBranchListItem; if(remoeBranchItem != null) { return RemoteBranchListItem.CompareByName(branchItem, (RemoteBranchListItem)item2); } var remoteItem = item1 as RemoteListItem; if(remoteItem != null) { return RemoteListItem.CompareByName(remoteItem, (RemoteListItem)item2); } var tagItem = item1 as TagListItem; if(tagItem != null) { return TagListItem.CompareByName(tagItem, (TagListItem)item2); } return 0; } else { var branchItem = item1 as BranchListItem; if(branchItem != null) { return -1; } var remoteBranchItem = item1 as RemoteBranchListItem; if(remoteBranchItem != null) { var branchItem2 = item2 as BranchListItem; if(branchItem2 != null) { return 1; } else { return -1; } } var remoteListItem = item1 as RemoteListItem; if(remoteListItem != null) { var tagItem2 = item2 as TagListItem; if(tagItem2 == null) { return -1; } else { return 1; } } return 1; } }
public override void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs) { var state = paintEventArgs.State; if (state == ItemState.None) { return; } bool hovered = (state & ItemState.Hovered) == ItemState.Hovered; bool selected = (state & ItemState.Selected) == ItemState.Selected; bool focused = (state & ItemState.Focused) == ItemState.Focused; IBackgroundStyle background = null; if (selected) { if (paintEventArgs.IsHostControlFocused) { if (hovered) { background = BackgroundStyle.SelectedFocused; } else if (focused) { background = BackgroundStyle.SelectedFocused; } else { background = BackgroundStyle.Selected; } } else { if (hovered) { background = BackgroundStyle.SelectedFocused; } else { background = BackgroundStyle.SelectedNoFocus; } } } else { if (hovered) { if (focused && paintEventArgs.IsHostControlFocused) { background = BackgroundStyle.HoveredFocused; } else { background = BackgroundStyle.Hovered; } } else if (focused) { if (paintEventArgs.IsHostControlFocused) { background = BackgroundStyle.Focused; } } } if (background != null) { background.Draw(paintEventArgs.Graphics, paintEventArgs.Bounds); } }
internal void ExpandItem(CustomListBoxItem item) { Assert.IsNotNull(item); if(item.Items.Count == 0 || !item.IsPresented) return; var itemId = _itemPlainList.IndexOf(item); if(itemId == -1) return; var id = itemId + 1; foreach(var i in item.Items) { id = InsertItem(id, i); } if(_lastClickedItemIndex > itemId) { _lastClickedItemIndex += id - itemId - 1; } NotifyContentSizeChanged(); if(_haveAutoSizeColumns) { InvalidateAutoSizeColumns(); } }
public void AddItem(CustomListBoxItem item) { _lstRepositoryExplorer.Items.Add(item); }
internal void FocusAndSelectItem(CustomListBoxItem item) { Verify.Argument.IsNotNull(item, "item"); Verify.Argument.IsTrue(item.ListBox == this, "item", "Item is not owned by this ListBox"); item.Present(); FocusAndSelectItem(_itemPlainList.IndexOf(item)); }
public ItemContextMenuRequestEventArgs(CustomListBoxItem item, CustomListBoxColumn column, int columnIndex, int x, int y) : base(column, columnIndex, x, y) { _item = item; }
internal void FocusItem(CustomListBoxItem item) { item.Present(); int index = _itemPlainList.IndexOf(item); FocusItem(index); }
public override void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs) { var graphics = paintEventArgs.Graphics; var rect = paintEventArgs.Bounds; #region clip invisible subitems var clip = paintEventArgs.ClipRectangle; var clipX1 = clip.X; var clipX2 = clip.Right; var columns = item.ListBox.Columns; int columnsCount = columns.Count; int x = rect.X; int firstColumnId; int startColumnId; int endColumnId; int startX; if(clipX1 <= rect.X && clipX2 >= rect.Right) { // all subitems should be painted startColumnId = 0; firstColumnId = 0; endColumnId = columnsCount - 1; startX = x; } else { firstColumnId = -1; startColumnId = -1; endColumnId = -1; startX = -1; // skip clipped subitems int prev = -1; for(int i = 0; i < columnsCount; ++i) { var column = columns[i]; if(column.IsVisible) { if(firstColumnId == -1) { firstColumnId = i; } int x2 = x + column.Width; if(startColumnId == -1 && x2 > clipX1) { if(prev != -1 && columns[prev].ExtendsToRight) { startColumnId = prev; startX = x - columns[prev].Width; } else { startColumnId = i; startX = x; } } if(startColumnId != -1 && endColumnId == -1 && x2 >= clipX2) { endColumnId = i++; for(; i < columnsCount; ++i) { if(columns[i].IsVisible) { if(columns[i].ExtendsToLeft) { endColumnId = i; } break; } } break; } x = x2; prev = i; } } // no visible columns found if(startColumnId == -1) return; if(endColumnId == -1) endColumnId = prev; } #endregion x = startX; bool first = startColumnId == firstColumnId; var subrect = new Rectangle(0, rect.Y, 0, rect.Height); int hoveredPart = paintEventArgs.HoveredPart; for(int i = startColumnId; i <= endColumnId; ++i) { var column = columns[i]; if(column.IsVisible) { int columnWidth = column.Width; if(first) { first = false; var level = item.Level; var listBox = item.ListBox; int offset = level * ListBoxConstants.LevelMargin + ListBoxConstants.RootMargin; int w2 = columnWidth - offset; #region paint plus/minus if(listBox.ShowTreeLines) { if(!listBox.ShowRootTreeLines) { if(level != 0) { offset -= ListBoxConstants.LevelMargin; w2 += ListBoxConstants.LevelMargin; } } if(level != 0 || listBox.ShowRootTreeLines) { if(w2 > ListBoxConstants.SpaceBeforePlusMinus && item.Items.Count != 0) { RenderPlusMinus( graphics, x + offset, subrect.Y + (subrect.Height - ListBoxConstants.PlusMinusImageWidth) / 2, item.IsExpanded, (paintEventArgs.State & ItemState.Selected) == ItemState.Selected, hoveredPart == ItemHitTestResults.PlusMinus, paintEventArgs.IsHostControlFocused); } offset += ListBoxConstants.PlusMinusAreaWidth; w2 -= ListBoxConstants.PlusMinusAreaWidth; } } #endregion #region paint checkbox if(listBox.ShowCheckBoxes && item.CheckedState != CheckedState.Unavailable) { Bitmap checkedStateImage = null; if(hoveredPart == ItemHitTestResults.CheckBox) { ImgCheckedStateHovered.TryGetValue(item.CheckedState, out checkedStateImage); } else { ImgCheckedState.TryGetValue(item.CheckedState, out checkedStateImage); } if(checkedStateImage != null && w2 > ListBoxConstants.SpaceBeforeCheckbox) { Rectangle destRect, srcRect; if(w2 < ListBoxConstants.CheckboxImageWidth + ListBoxConstants.SpaceBeforeCheckbox) { destRect = new Rectangle( x + offset + ListBoxConstants.SpaceBeforeCheckbox, rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2, w2 - ListBoxConstants.SpaceBeforeCheckbox, ListBoxConstants.CheckboxImageWidth); srcRect = new Rectangle( 0, 0, w2 - ListBoxConstants.SpaceBeforeCheckbox, ListBoxConstants.CheckboxImageWidth); } else { destRect = new Rectangle( x + offset + ListBoxConstants.SpaceBeforeCheckbox, rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2, ListBoxConstants.CheckboxImageWidth, ListBoxConstants.CheckboxImageWidth); srcRect = new Rectangle( 0, 0, ListBoxConstants.CheckboxImageWidth, ListBoxConstants.CheckboxImageWidth); } graphics.DrawImage(checkedStateImage, destRect, srcRect, GraphicsUnit.Pixel); } offset += ListBoxConstants.CheckBoxAreaWidth; w2 -= ListBoxConstants.CheckBoxAreaWidth; } #endregion subrect.X = x + offset; subrect.Width = w2; x += columnWidth; if(w2 <= 0) continue; } else { subrect.X = x; subrect.Width = columnWidth; x += columnWidth; } item.PaintSubItem(new SubItemPaintEventArgs(paintEventArgs.Graphics, clip, subrect, paintEventArgs.Index, paintEventArgs.State, hoveredPart, paintEventArgs.IsHostControlFocused, i, column)); } } }
internal void InvalidateItem(CustomListBoxItem item) { int index = _itemPlainList.IndexOf(item); var rc = GetItemDisplayRect(index); Invalidate(rc); }
public abstract void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
internal void InvalidateSubItem(CustomListBoxItem item, int columnId) { int columnIndex = -1; for(int i = 0; i < _columns.Count; ++i) { var column = _columns[i]; if(column.Id == columnId) { if(!column.IsVisible) return; columnIndex = i; break; } } if(columnIndex == -1) return; int itemIndex = _itemPlainList.IndexOf(item); if(itemIndex == -1) return; var itemDisplayRectangle = GetItemDisplayRect(itemIndex); if(itemDisplayRectangle.Width > 0 && itemDisplayRectangle.Height > 0) { var columnContentBounds = GetExtendedColumnContentRectangle(columnIndex); var clipRectangle = Rectangle.Intersect(itemDisplayRectangle, columnContentBounds); if(clipRectangle.Width > 0 && clipRectangle.Height > 0) { Invalidate(clipRectangle); } } }
public abstract void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
internal void NotifyItemActivated(CustomListBoxItem item) { OnItemActivated(item); }
private static void _collapse_all(CustomListBoxItem item) { item.IsExpanded = false; if(item.Items.Count != 0) { foreach(var i in item.Items) { _collapse_all(i); } } }
internal void NotifyItemCheckedChanged(CustomListBoxItem item) { OnItemCheckedChanged(item); }
internal void OnItemsChanged(object sender, NotifyCollectionEventArgs e) { bool plainListChanged = false; var items = (CustomListBoxItemsCollection)sender; var item = items.Parent; switch(e.Event) { case NotifyEvent.Clear: if(_oldItem != null) { InvalidateItem(_oldItem); _oldItem = null; } break; case NotifyEvent.Remove: break; case NotifyEvent.Set: if(_setItemPos != -1) { var newitem = items[e.StartIndex]; _itemPlainList[_setItemPos] = newitem; var y1 = GetItemY1Offset(_setItemPos); int id = _setItemPos + 1; if(_oldItem.IsExpanded && _oldItem.Items.Count != 0) { int level = _oldItem.Level; int end = id + 1; while(end < _itemPlainList.Count && _itemPlainList[end].Level > level) { ++end; } if(_itemFocus.IsTracked) { if(_itemFocus.Index >= id) { if(_itemFocus.Index >= end) { _itemFocus.ResetIndex(_itemFocus.Index - (end - id)); } else { _itemFocus.Drop(); } } } if(_itemHover.IsTracked) { if(_itemHover.Index >= id) { if(_itemHover.Index >= end) { _itemHover.ResetIndex(_itemHover.Index - (end - id)); } else { _itemHover.Drop(); } } } _itemPlainList.RemoveRange(id, end - id); plainListChanged = true; } if(newitem.IsExpanded && newitem.Items.Count != 0) { int end = id; foreach(var i in newitem.Items) { end = InsertItem(id, i); } plainListChanged = true; } NotifyContentSizeChanged(); _setItemPos = -1; _oldItem = null; } break; case NotifyEvent.Insert: { bool noitems = _itemPlainList.Count == 0; if(item == null) { int start = e.StartIndex; int end = e.EndIndex; int id = 0; if(start != 0) { if(end == items.Count - 1) { id = _itemPlainList.Count - (end - start); } else { var sitem = items[start - 1]; while(sitem.Items.Count != 0 && sitem.IsExpanded) { sitem = sitem.Items[sitem.Items.Count - 1]; } id = _itemPlainList.IndexOf(sitem) + 1; } } int startId = id; bool renderAll = id != _itemPlainList.Count; for(int i = start; i <= end; ++i) { id = InsertItem(id, items[i]); } plainListChanged = true; NotifyContentSizeChanged(); } else { if(item.IsPresented) { if(item.IsExpanded) { int start = e.StartIndex; int end = e.EndIndex; int id = 0; if(start == 0) { id = _itemPlainList.IndexOf(item) + 1; } else { var sitem = items[start - 1]; while(sitem.Items.Count != 0 && sitem.IsExpanded) { sitem = sitem.Items[sitem.Items.Count - 1]; } id = _itemPlainList.IndexOf(sitem) + 1; } int startid = id; for(int i = start; i <= end; ++i) { id = InsertItem(id, items[i]); } NotifyContentSizeChanged(); plainListChanged = true; } else { if(items.Count == e.ModifiedItems) { InvalidateItem(item); } } } } if(noitems) Invalidate(_itemsArea); } break; } if(_haveAutoSizeColumns && plainListChanged) { InvalidateAutoSizeColumns(); } }
internal void OnItemsChanging(object sender, NotifyCollectionEventArgs e) { bool plainListChanged = false; var items = (CustomListBoxItemsCollection)sender; var item = items.Parent; switch(e.Event) { case NotifyEvent.Clear: if(item == null) { _lastClickedItemIndex = -1; _itemFocus.Drop(); _itemHover.Drop(); if(_itemPlainList.Count != 0) { plainListChanged = true; _itemPlainList.Clear(); _selectedItems.Clear(); if(Created) { NotifyContentSizeChanged(); } } } else { if(item.IsPresented) { if(items.Count != 0) { if(item.IsExpanded) { RemoveItems(items, 0, items.Count - 1); plainListChanged = true; } else { _oldItem = item; } } } } break; case NotifyEvent.Set: if((item == null) || (item.IsPresented && item.IsExpanded)) { _oldItem = items[e.StartIndex]; _setItemPos = _itemPlainList.IndexOf(_oldItem); } break; case NotifyEvent.Remove: if((item == null) || (item.IsPresented && item.IsExpanded)) { RemoveItems(items, e.StartIndex, e.EndIndex); plainListChanged = true; } if(_itemPlainList.Count == 0) { Invalidate(_itemsArea); } break; } if(_haveAutoSizeColumns && plainListChanged) { InvalidateAutoSizeColumns(); } }
/// <summary>Create <see cref="ItemEventArgs"/>.</summary> /// <param name="item">Related <see cref="CustomListBoxItem"/>.</param> public ItemEventArgs(CustomListBoxItem item) { _item = item; }
private static void EnableCheckboxes(CustomListBoxItem item, bool state) { if(state && item is IRevisionPointerListItem) { item.CheckedState = CheckedState.Unchecked; } else { item.CheckedState = CheckedState.Unavailable; } foreach(var i in item.Items) { EnableCheckboxes(i, state); } }
public override void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs) { var graphics = paintEventArgs.Graphics; var rect = paintEventArgs.Bounds; #region clip invisible subitems var clip = paintEventArgs.ClipRectangle; var clipX1 = clip.X; var clipX2 = clip.Right; var columns = item.ListBox.Columns; int columnsCount = columns.Count; int x = rect.X; int firstColumnId; int startColumnId; int endColumnId; int startX; if (clipX1 <= rect.X && clipX2 >= rect.Right) { // all subitems should be painted startColumnId = 0; firstColumnId = 0; endColumnId = columnsCount - 1; startX = x; } else { firstColumnId = -1; startColumnId = -1; endColumnId = -1; startX = -1; // skip clipped subitems int prev = -1; for (int i = 0; i < columnsCount; ++i) { var column = columns[i]; if (column.IsVisible) { if (firstColumnId == -1) { firstColumnId = i; } int x2 = x + column.Width; if (startColumnId == -1 && x2 > clipX1) { if (prev != -1 && columns[prev].ExtendsToRight) { startColumnId = prev; startX = x - columns[prev].Width; } else { startColumnId = i; startX = x; } } if (startColumnId != -1 && endColumnId == -1 && x2 >= clipX2) { endColumnId = i++; for (; i < columnsCount; ++i) { if (columns[i].IsVisible) { if (columns[i].ExtendsToLeft) { endColumnId = i; } break; } } break; } x = x2; prev = i; } } // no visible columns found if (startColumnId == -1) { return; } if (endColumnId == -1) { endColumnId = prev; } } #endregion x = startX; bool first = startColumnId == firstColumnId; var subrect = new Rectangle(0, rect.Y, 0, rect.Height); int hoveredPart = paintEventArgs.HoveredPart; for (int i = startColumnId; i <= endColumnId; ++i) { var column = columns[i]; if (column.IsVisible) { int columnWidth = column.Width; if (first) { first = false; var level = item.Level; var listBox = item.ListBox; int offset = level * ListBoxConstants.LevelMargin + ListBoxConstants.RootMargin; int w2 = columnWidth - offset; #region paint plus/minus if (listBox.ShowTreeLines) { if (!listBox.ShowRootTreeLines) { if (level != 0) { offset -= ListBoxConstants.LevelMargin; w2 += ListBoxConstants.LevelMargin; } } if (level != 0 || listBox.ShowRootTreeLines) { if (w2 > ListBoxConstants.SpaceBeforePlusMinus && item.Items.Count != 0) { Bitmap image; if (hoveredPart == ItemHitTestResults.PlusMinus) { image = (item.IsExpanded) ? (ImgCollapseHovered) : (ImgExpandHovered); } else { image = (item.IsExpanded) ? (ImgCollapse) : (ImgExpand); } Rectangle destRect, srcRect; if (w2 < ListBoxConstants.PlusMinusImageWidth + ListBoxConstants.SpaceBeforePlusMinus) { destRect = new Rectangle( x + offset, subrect.Y + (subrect.Height - ListBoxConstants.PlusMinusImageWidth) / 2, w2 - ListBoxConstants.SpaceBeforePlusMinus, ListBoxConstants.PlusMinusImageWidth); srcRect = new Rectangle( 0, 0, w2 - ListBoxConstants.SpaceBeforePlusMinus, ListBoxConstants.PlusMinusImageWidth); } else { destRect = new Rectangle( x + offset, subrect.Y + (subrect.Height - ListBoxConstants.PlusMinusImageWidth) / 2, ListBoxConstants.PlusMinusImageWidth, ListBoxConstants.PlusMinusImageWidth); srcRect = new Rectangle( 0, 0, ListBoxConstants.PlusMinusImageWidth, ListBoxConstants.PlusMinusImageWidth); } graphics.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel); } offset += ListBoxConstants.PlusMinusAreaWidth; w2 -= ListBoxConstants.PlusMinusAreaWidth; } } #endregion #region paint checkbox if (listBox.ShowCheckBoxes && item.CheckedState != CheckedState.Unavailable) { Bitmap checkedStateImage; if (hoveredPart == ItemHitTestResults.CheckBox) { ImgCheckedStateHovered.TryGetValue(item.CheckedState, out checkedStateImage); } else { ImgCheckedState.TryGetValue(item.CheckedState, out checkedStateImage); } if (checkedStateImage != null && w2 > ListBoxConstants.SpaceBeforeCheckbox) { Rectangle destRect, srcRect; if (w2 < ListBoxConstants.CheckboxImageWidth + ListBoxConstants.SpaceBeforeCheckbox) { destRect = new Rectangle( x + offset + ListBoxConstants.SpaceBeforeCheckbox, rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2, w2 - ListBoxConstants.SpaceBeforeCheckbox, ListBoxConstants.CheckboxImageWidth); srcRect = new Rectangle( 0, 0, w2 - ListBoxConstants.SpaceBeforeCheckbox, ListBoxConstants.CheckboxImageWidth); } else { destRect = new Rectangle( x + offset + ListBoxConstants.SpaceBeforeCheckbox, rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2, ListBoxConstants.CheckboxImageWidth, ListBoxConstants.CheckboxImageWidth); srcRect = new Rectangle( 0, 0, ListBoxConstants.CheckboxImageWidth, ListBoxConstants.CheckboxImageWidth); } graphics.DrawImage(checkedStateImage, destRect, srcRect, GraphicsUnit.Pixel); } offset += ListBoxConstants.CheckBoxAreaWidth; w2 -= ListBoxConstants.CheckBoxAreaWidth; } #endregion subrect.X = x + offset; subrect.Width = w2; x += columnWidth; if (w2 <= 0) { continue; } } else { subrect.X = x; subrect.Width = columnWidth; x += columnWidth; } item.PaintSubItem(new SubItemPaintEventArgs(paintEventArgs.Graphics, clip, subrect, paintEventArgs.Index, paintEventArgs.State, hoveredPart, paintEventArgs.IsHostControlFocused, i, column)); } } }
/// <summary>Create <see cref="ItemEventArgs"/>.</summary> /// <param name="item">Related <see cref="CustomListBoxItem"/>.</param> public ItemEventArgs(CustomListBoxItem item) { _item = item; }