protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (MouseDownWidget != null)
            {
                MouseDownWidget.OnMouseUp(e.Location);
                ConditionalRedrawWidget(MouseDownWidget);
            }

            if ((e.Button & MouseButtons.Left) != 0)
            {
                MouseDownWidget = FindWidget(e.Location);
            }
            else
            {
                MouseDownWidget = null;
            }

            if (MouseDownWidget != null)
            {
                MouseDownWidget.OnMouseDown(e.Location);
                ConditionalRedrawWidget(MouseDownWidget);
            }
        }
 protected void ConditionalLayoutWidget(CustomListViewWidget Widget)
 {
     if (Widget.Item.Tag == Widget)
     {
         Widget.ConditionalLayout(this, Widget.Item.Bounds);
     }
     else
     {
         for (int Idx = 0; Idx < Widget.Item.SubItems.Count; Idx++)
         {
             ListViewItem.ListViewSubItem SubItem = Widget.Item.SubItems[Idx];
             if (SubItem.Tag == Widget)
             {
                 Rectangle Bounds = SubItem.Bounds;
                 for (int EndIdx = Idx + 1; EndIdx < Widget.Item.SubItems.Count && Widget.Item.SubItems[EndIdx].Tag == Widget; EndIdx++)
                 {
                     Rectangle EndBounds = Widget.Item.SubItems[EndIdx].Bounds;
                     Bounds = new Rectangle(Bounds.X, Bounds.Y, EndBounds.Right - Bounds.X, EndBounds.Bottom - Bounds.Y);
                 }
                 Widget.ConditionalLayout(this, Bounds);
                 break;
             }
         }
     }
 }
 protected void ConditionalRedrawWidget(CustomListViewWidget Widget)
 {
     if (Widget.Item.Index != -1 && Widget.RequiresLayout())
     {
         ConditionalLayoutWidget(Widget);
         RedrawItems(Widget.Item.Index, Widget.Item.Index, true);
     }
 }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (MouseDownWidget != null)
            {
                CustomListViewWidget Widget = MouseDownWidget;
                MouseDownWidget = null;

                Widget.OnMouseUp(e.Location);
                ConditionalRedrawWidget(Widget);
            }
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            if (MouseOverWidget != null)
            {
                MouseOverWidget.OnMouseLeave();
                ConditionalRedrawWidget(MouseOverWidget);
                MouseOverWidget = null;
                Invalidate();
            }

            if (HoverItem != -1)
            {
                HoverItem = -1;
                Invalidate();
            }
        }
        public void DrawCustomSubItem(Graphics Graphics, ListViewItem.ListViewSubItem SubItem)
        {
            CustomListViewWidget Widget = SubItem.Tag as CustomListViewWidget;

            if (Widget != null)
            {
                foreach (ListViewItem.ListViewSubItem OtherSubItem in Widget.Item.SubItems)
                {
                    if (OtherSubItem.Tag == Widget)
                    {
                        if (OtherSubItem == SubItem)
                        {
                            ConditionalLayoutWidget(Widget);
                            Widget.Render(Graphics);
                        }
                        break;
                    }
                }
            }
        }
 protected CustomListViewWidget FindWidget(ListViewHitTestInfo HitTest)
 {
     if (HitTest.Item != null)
     {
         CustomListViewWidget Widget = HitTest.Item.Tag as CustomListViewWidget;
         if (Widget != null)
         {
             return(Widget);
         }
     }
     if (HitTest.SubItem != null)
     {
         CustomListViewWidget Widget = HitTest.SubItem.Tag as CustomListViewWidget;
         if (Widget != null)
         {
             return(Widget);
         }
     }
     return(null);
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            ListViewHitTestInfo HitTest = this.HitTest(e.Location);

            CustomListViewWidget NewMouseOverWidget = FindWidget(HitTest);

            if (MouseOverWidget != null && MouseOverWidget != NewMouseOverWidget)
            {
                Cursor = Cursors.Arrow;
                MouseOverWidget.OnMouseLeave();
                ConditionalRedrawWidget(MouseOverWidget);
            }
            MouseOverWidget = NewMouseOverWidget;
            if (MouseOverWidget != null)
            {
                Cursor = MouseOverWidget.Cursor;
                MouseOverWidget.OnMouseMove(e.Location);
                ConditionalRedrawWidget(MouseOverWidget);
            }

            int PrevHoverItem = HoverItem;

            HoverItem = (HitTest.Item == null)? -1 : HitTest.Item.Index;
            if (HoverItem != PrevHoverItem)
            {
                if (HoverItem != -1)
                {
                    RedrawItems(HoverItem, HoverItem, true);
                }
                if (PrevHoverItem != -1 && PrevHoverItem < Items.Count)
                {
                    RedrawItems(PrevHoverItem, PrevHoverItem, true);
                }
            }

            base.OnMouseMove(e);
        }