public virtual Object StartDrag(ObjectListView olv, MouseButtons button, OLVListItem item) {
            // We only drag on left mouse
            if (button != MouseButtons.Left)
                return null;

            return this.CreateDataObject(olv);
        }
 static private void ReplaceColumns(ObjectListView olv, IList<OLVColumn> columns) {
     olv.Clear();
     olv.AllColumns.Clear();
     if (columns.Count > 0) {
         olv.AllColumns.AddRange(columns);
         olv.RebuildColumns();
     }
 }
        static public void GenerateColumns(ObjectListView olv, IEnumerable enumerable) {
            // Generate columns based on the type of the first model in the collection and then quit
            foreach (object model in enumerable) {
                Generator.GenerateColumns(olv, model.GetType());
                return;
            }

            // If we reach here, the collection was empty, so we clear the list
            Generator.ReplaceColumns(olv, new List<OLVColumn>());
        }
        public OLVDataObject(ObjectListView olv) : this(olv, olv.SelectedObjects) {

        }
 public TextMatchFilter(ObjectListView olv, string text, StringComparison comparison) {
     this.ListView = olv;
     this.Text = text;
     this.StringComparison = comparison;
 }
 public TextMatchFilter(ObjectListView olv) {
     this.ListView = olv;
 }
        /// <summary>
        /// Draw this overlay
        /// </summary>
        /// <param name="olv">The ObjectListView being decorated</param>
        /// <param name="g">The Graphics used for drawing</param>
        /// <param name="r">The bounds of the rendering</param>
        public override void Draw(ObjectListView olv, Graphics g, Rectangle r) {
            if (String.IsNullOrEmpty(this.Text))
                return;

            // Calculate the bounds of the text, and then move it to where it should be
            Rectangle textRect = this.CalculateTextBounds(g, r, this.Text);
            textRect.Location = this.Location;

            // Make sure the billboard is within the bounds of the List, as far as is possible
            if (textRect.Right > r.Width)
                textRect.X = Math.Max(r.Left, r.Width - textRect.Width);
            if (textRect.Bottom > r.Height)
                textRect.Y = Math.Max(r.Top, r.Height - textRect.Height);

            this.DrawBorderedText(g, textRect, this.Text, 255);
        }
 public static int SetGroupImageList(ObjectListView olv, ImageList il) {
     const int LVSIL_GROUPHEADER = 3;
     IntPtr handle = IntPtr.Zero;
     if (il != null)
         handle = il.Handle;
     return (int)NativeMethods.SendMessage(olv.Handle, LVM_SETIMAGELIST, LVSIL_GROUPHEADER, handle);
 }
 public static int SetGroupInfo(ObjectListView olv, int groupId, LVGROUP2 group) {
     return (int)NativeMethods.SendMessage(olv.Handle, LVM_SETGROUPINFO, groupId, ref group);
 }
 public static GroupState GetGroupState(ObjectListView olv, int groupId, GroupState mask) {
     return (GroupState)NativeMethods.SendMessage(olv.Handle, LVM_GETGROUPSTATE, groupId, (int)mask);
 }
 public override void Draw(ObjectListView olv, Graphics g, Rectangle r) {
     Rectangle bounds = this.CalculateBounds();
     if (!bounds.IsEmpty)
         this.DrawFilledBorder(g, bounds);
 }
        public override void Draw(ObjectListView olv, Graphics g, Rectangle r) {

            // This overlay only works when:
            // - the list is in Details view
            // - there is at least one row
            // - there is a selected column
            if (olv.View != System.Windows.Forms.View.Details)
                return;

            if (olv.GetItemCount() == 0)
                return;

            OLVColumn column = this.ColumnToTint ?? olv.SelectedColumn;
            if (column == null)
                return;

            Point sides = NativeMethods.GetScrolledColumnSides(olv, column.Index);
            if (sides.X == -1)
                return;

            Rectangle columnBounds = new Rectangle(sides.X, r.Top, sides.Y - sides.X, r.Bottom);

            // Find the bottom of the last item. The tinting should extend only to there.
            OLVListItem lastItem = olv.GetLastItemInDisplayOrder();
            if (lastItem != null) {
                Rectangle lastItemBounds = lastItem.Bounds;
                if (!lastItemBounds.IsEmpty && lastItemBounds.Bottom < columnBounds.Bottom)
                    columnBounds.Height = lastItemBounds.Bottom - columnBounds.Top;
            }
            g.FillRectangle(this.tintBrush, columnBounds);
        }
        public AutoCompleteCellEditor(ObjectListView lv, OLVColumn column) {
            this.DropDownStyle = ComboBoxStyle.DropDown;

            Dictionary<String, bool> alreadySeen = new Dictionary<string, bool>();
            for (int i = 0; i < Math.Min(lv.GetItemCount(), 1000); i++) {
                String str = column.GetStringValue(lv.GetModelObject(i));
                if (!alreadySeen.ContainsKey(str)) {
                    this.Items.Add(str);
                    alreadySeen[str] = true;
                }
            }

            this.Sorted = true;
            this.AutoCompleteSource = AutoCompleteSource.ListItems;
            this.AutoCompleteMode = AutoCompleteMode.Append;
        }
 public virtual Object StartDrag(ObjectListView olv, MouseButtons button, OLVListItem item) {
     return null;
 }
 public OLVDataObject(ObjectListView olv, IList modelObjects) {
     this.objectListView = olv;
     this.modelObjects = modelObjects;
 }
        /// <summary>
        /// Return the edges of the given column.
        /// </summary>
        /// <param name="lv"></param>
        /// <param name="columnIndex"></param>
        /// <returns>A Point holding the left and right co-ords of the column.
        /// -1 means that the sides could not be retrieved.</returns>
        public static Point GetColumnSides(ObjectListView lv, int columnIndex) {
            Point sides = new Point(-1, -1);
            IntPtr hdr = NativeMethods.GetHeaderControl(lv);
            if (hdr == IntPtr.Zero)
                return new Point(-1, -1);

            RECT r = new RECT();
            NativeMethods.SendMessageRECT(hdr, HDM_GETITEMRECT, columnIndex, ref r);
            return new Point(r.left, r.right);
        }
        public override void Draw(ObjectListView olv, Graphics g, Rectangle r) {
            if (!r.Contains(olv.PointToClient(Cursor.Position)))
                return;

            Rectangle bounds = this.RowBounds;
            if (bounds.IsEmpty)
                return;

            using (Region newClip = new Region(r)) {
                bounds.Inflate(this.BoundsPadding);
                newClip.Exclude(this.GetRoundedRect(bounds, this.CornerRounding));
                Region originalClip = g.Clip;
                g.Clip = newClip;
                g.FillRectangle(this.FillBrush, r);
                g.Clip = originalClip;
            }
        }
 public static int InsertGroup(ObjectListView olv, LVGROUP2 group) {
     return (int)NativeMethods.SendMessage(olv.Handle, LVM_INSERTGROUP, -1, ref group);
 }
 /// <summary>
 /// Draw this overlay
 /// </summary>
 /// <param name="olv">The ObjectListView being decorated</param>
 /// <param name="g">The Graphics used for drawing</param>
 /// <param name="r">The bounds of the rendering</param>
 public virtual void Draw(ObjectListView olv, Graphics g, Rectangle r) {
     this.DrawText(g, this.CalculateItemBounds(this.ListItem, this.SubItem));
 }
 public static int SetGroupMetrics(ObjectListView olv, int groupId, LVGROUPMETRICS metrics) {
     return (int)NativeMethods.SendMessage(olv.Handle, LVM_SETGROUPMETRICS, groupId, ref metrics);
 }
 public HeaderControl(ObjectListView olv) {
     this.ListView = olv;
     this.AssignHandle(NativeMethods.GetHeaderControl(olv));
 }
 /// <summary>
 /// Draw this overlay
 /// </summary>
 /// <param name="olv">The ObjectListView being decorated</param>
 /// <param name="g">The Graphics used for drawing</param>
 /// <param name="r">The bounds of the rendering</param>
 public virtual void Draw(ObjectListView olv, Graphics g, Rectangle r) {
     Rectangle insetRect = r;
     insetRect.Inflate(-this.InsetX, -this.InsetY);
     // We hard code a transparency of 255 here since transparency is handled by the glass panel
     this.DrawText(g, insetRect, this.Text, 255);
 }
 /// <summary>
 /// Insert a native group into the underlying Windows control,
 /// *without* using a ListViewGroup
 /// </summary>
 /// <param name="olv"></param>
 /// <remarks>This is used when creating virtual groups</remarks>
 public void InsertGroupNewStyle(ObjectListView olv) {
     this.ListView = olv;
     NativeMethods.InsertGroup(olv, this.AsNativeGroup(true));
     this.SetGroupSpacing();
 }
 /// <summary>
 /// Draw this overlay
 /// </summary>
 /// <param name="olv">The ObjectListView that is being overlaid</param>
 /// <param name="g">The Graphics onto the given OLV</param>
 /// <param name="r">The content area of the OLV</param>
 public virtual void Draw(ObjectListView olv, Graphics g, Rectangle r) {
 }
        /// <summary>
        /// Insert a native group into the underlying control via a ListViewGroup
        /// </summary>
        /// <param name="olv"></param>
        public void InsertGroupOldStyle(ObjectListView olv) {
            this.ListView = olv;
            if (this.ListViewGroup == null)
                this.ListViewGroup = new ListViewGroup();
            this.ListViewGroup.Header = this.Header;
            this.ListViewGroup.HeaderAlignment = this.HeaderAlignment;
            this.ListViewGroup.Name = this.Name;
            this.ListViewGroup.Tag = this.Tag;
            olv.Groups.Add(this.ListViewGroup);

            // Add any extra information
            NativeMethods.SetGroupInfo(olv, this.GroupId, this.AsNativeGroup(false));
            this.SetGroupSpacing();
        }
 public TextMatchFilter(ObjectListView olv, string text) {
     this.ListView = olv;
     this.Text = text;
 }
 static public void GenerateColumns(ObjectListView olv, Type type) {
     IList<OLVColumn> columns = Generator.GenerateColumns(type);
     Generator.ReplaceColumns(olv, columns);
 }
        /// <summary>
        /// Attach this form to the given ObjectListView
        /// </summary>        
        public void Bind(ObjectListView olv, IOverlay overlay) {
            if (this.objectListView != null)
                this.Unbind();

            this.objectListView = olv;
            this.Overlay = overlay;
            this.mdiClient = null;
            this.mdiOwner = null;

            // NOTE: If you listen to any events here, you *must* stop listening in Unbind()
            this.objectListView.Disposed += new EventHandler(objectListView_Disposed);
            this.objectListView.LocationChanged += new EventHandler(objectListView_LocationChanged);
            this.objectListView.SizeChanged += new EventHandler(objectListView_SizeChanged);
            this.objectListView.VisibleChanged += new EventHandler(objectListView_VisibleChanged);
            this.objectListView.ParentChanged += new EventHandler(objectListView_ParentChanged);

            Control parent = this.objectListView.Parent;
            while (parent != null) {
                parent.ParentChanged += new EventHandler(objectListView_ParentChanged);
                TabControl tabControl = parent as TabControl;
                if (tabControl != null) {
                    tabControl.Selected += new TabControlEventHandler(tabControl_Selected);
                }
                parent = parent.Parent;
            }
            this.Owner = this.objectListView.FindForm();
            this.myOwner = this.Owner;
            if (this.Owner != null) {
                this.Owner.LocationChanged += new EventHandler(Owner_LocationChanged);
                this.Owner.SizeChanged += new EventHandler(Owner_SizeChanged);
                this.Owner.ResizeBegin += new EventHandler(Owner_ResizeBegin);
                this.Owner.ResizeEnd += new EventHandler(Owner_ResizeEnd);
                if (this.Owner.TopMost) {
                    // We can't do this.TopMost = true; since that will activate the panel,
                    // taking focus away from the owner of the listview
                    NativeMethods.MakeTopMost(this);
                }

                // We need special code to handle MDI
                this.mdiOwner = this.Owner.MdiParent;
                if (this.mdiOwner != null) {
                    this.mdiOwner.LocationChanged += new EventHandler(Owner_LocationChanged);
                    this.mdiOwner.SizeChanged += new EventHandler(Owner_SizeChanged);
                    this.mdiOwner.ResizeBegin += new EventHandler(Owner_ResizeBegin);
                    this.mdiOwner.ResizeEnd += new EventHandler(Owner_ResizeEnd);

                    // Find the MDIClient control, which houses all MDI children
                    foreach (Control c in this.mdiOwner.Controls) {
                        this.mdiClient = c as MdiClient;
                        if (this.mdiClient != null) {
                            break;
                        }
                    }
                    if (this.mdiClient != null) {
                        this.mdiClient.ClientSizeChanged += new EventHandler(myMdiClient_ClientSizeChanged);
                    }
                }
            }

            this.UpdateTransparency();
        }
 /// <summary>
 /// Create a data object that will be used to as the data object
 /// for the drag operation.
 /// </summary>
 /// <remarks>
 /// Subclasses can override this method add new formats to the data object.
 /// </remarks>
 /// <param name="olv">The ObjectListView that is the source of the drag</param>
 /// <returns>A data object for the drag</returns>
 protected virtual object CreateDataObject(ObjectListView olv) {
     OLVDataObject data = new OLVDataObject(olv);
     data.CreateTextFormats();
     return data;
 }