2008-03-06 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewGroup.cs
index 7f7450da3efed754bd8e11ba9e011e42d3779c2e..e60057f9d5170a641673cbacb5c9fbaea322c4d0 100644 (file)
@@ -39,15 +39,22 @@ namespace System.Windows.Forms
        [ToolboxItem(false)]
        [DesignTimeVisible(false)]
        [DefaultProperty("Header")]
+       [TypeConverter (typeof (ListViewGroupConverter))]
        public sealed class ListViewGroup : ISerializable
        {
-               private string header = string.Empty;
+               internal string header = string.Empty;
                private string name = null;
                private HorizontalAlignment header_alignment = HorizontalAlignment.Left;
                private ListView list_view_owner = null;
                private ListView.ListViewItemCollection items = null;
                private object tag = null;
-               private Point location = Point.Empty;
+               private Rectangle header_bounds = Rectangle.Empty;
+               internal int starting_row;      // At which row the group starts
+               internal int rows;
+               internal int current_item;      // Current item when doing layout
+               internal Point items_area_location;
+               bool is_default_group;
+               int item_count; // Used by default group to store item count
 
                #region ListViewGroup constructors
 
@@ -132,7 +139,7 @@ namespace System.Windows.Forms
                public ListView.ListViewItemCollection Items {
                        get {
                                if (items == null)
-                                       items = new ListView.ListViewItemCollection(list_view_owner);
+                                       items = new ListView.ListViewItemCollection (list_view_owner, this);
 
                                return items;
                        }
@@ -146,12 +153,51 @@ namespace System.Windows.Forms
 
                internal ListView ListViewOwner {
                        get { return list_view_owner; }
-                       set { list_view_owner = value; }
+                       set { 
+                               list_view_owner = value; 
+                               if (!is_default_group)
+                                       items.Owner = value;
+                       }
+               }
+
+               internal Rectangle HeaderBounds {
+                       get {
+                               Rectangle retval = header_bounds;
+                               retval.X -= list_view_owner.h_marker;
+                               retval.Y -= list_view_owner.v_marker;
+                               return retval;
+                       }
+                       set { 
+                               if (list_view_owner != null)
+                                       list_view_owner.item_control.Invalidate (HeaderBounds);
+
+                               header_bounds = value; 
+
+                               if (list_view_owner != null)
+                                       list_view_owner.item_control.Invalidate (HeaderBounds);
+
+                       }
+               }
+
+               internal bool IsDefault {
+                       get {
+                               return is_default_group;
+                       }
+                       set {
+                               is_default_group = value;
+                       }
                }
 
-               internal Point Location {
-                       get { return location; }
-                       set { location = value; }
+               internal int ItemCount {
+                       get {
+                               return is_default_group ? item_count : items.Count;
+                       }
+                       set {
+                               if (!is_default_group)
+                                       throw new InvalidOperationException ("ItemCount cannot be set for non-default groups.");
+
+                               item_count = value;
+                       }
                }
 
                [Browsable(true)]
@@ -179,7 +225,7 @@ namespace System.Windows.Forms
 
                #region ISerializable Members
 
-               public void GetObjectData(SerializationInfo info, StreamingContext context)
+               void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
                {
                        info.AddValue("Header", header);
                        info.AddValue("Name", name);
@@ -198,5 +244,19 @@ namespace System.Windows.Forms
 
                #endregion
        }
+
+       internal class ListViewGroupConverter : TypeConverter
+       {
+               public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
+               {
+                       return true;
+               }
+
+               // Weird
+               public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
+               {
+                       return new StandardValuesCollection (new object [] {});
+               }
+       }
 }
 #endif