Merge branch 'sgen-android'
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewGroup.cs
index ef870fee24c58787d8a2e40988663a795414ea31..5d757d2c3500c2d5c4d0153d4d32928aebb3cd5a 100644 (file)
@@ -25,8 +25,6 @@
 // Author:
 //     Daniel Nauck            (dna(at)mono-project(dot)de)
 
-#if NET_2_0
-
 using System;
 using System.Text;
 using System.Runtime.Serialization;
@@ -39,42 +37,44 @@ 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 Rectangle bounds = Rectangle.Empty;
+               private Rectangle header_bounds = Rectangle.Empty;
                internal int starting_row;      // At which row the group starts
+               internal int starting_item;     // The first display item in group
+               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
 
-               public ListViewGroup()
+               public ListViewGroup () : this ("ListViewGroup", HorizontalAlignment.Left)
                {
-                       header = "ListViewGroup";
-                       header_alignment = HorizontalAlignment.Left;
                }
 
-               public ListViewGroup(string header)
+               public ListViewGroup (string header) : this (header, HorizontalAlignment.Left)
                {
-                       this.header = header;
-                       header_alignment = HorizontalAlignment.Left;
                }
 
-               public ListViewGroup(string key, string headerText)
+               public ListViewGroup (string key, string headerText) : this (headerText, HorizontalAlignment.Left)
                {
-                       header = headerText;
                        name = key;
-                       header_alignment = HorizontalAlignment.Left;
                }
 
-               public ListViewGroup(string header, HorizontalAlignment headerAlignment)
+               public ListViewGroup (string header, HorizontalAlignment headerAlignment)
                {
                        this.header = header;
                        header_alignment = headerAlignment;
+                       items = new ListView.ListViewItemCollection (list_view_owner, this);
                }
 
                private ListViewGroup(SerializationInfo info, StreamingContext context)
@@ -132,9 +132,6 @@ namespace System.Windows.Forms
                [Browsable(false)]
                public ListView.ListViewItemCollection Items {
                        get {
-                               if (items == null)
-                                       items = new ListView.ListViewItemCollection(list_view_owner);
-
                                return items;
                        }
                }
@@ -149,22 +146,62 @@ namespace System.Windows.Forms
                        get { return list_view_owner; }
                        set { 
                                list_view_owner = value; 
-                               items.Owner = value;
+                               if (!is_default_group)
+                                       items.Owner = value;
                        }
                }
 
-               internal Rectangle Bounds {
+               internal Rectangle HeaderBounds {
                        get {
-                               Rectangle retval = bounds;
+                               Rectangle retval = header_bounds;
                                retval.X -= list_view_owner.h_marker;
                                retval.Y -= list_view_owner.v_marker;
                                return retval;
                        }
                        set { 
-                               list_view_owner.item_control.Invalidate (Bounds);
-                               bounds = value; 
-                               list_view_owner.item_control.Invalidate (Bounds);
+                               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 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;
+                       }
+               }
+
+               internal int GetActualItemCount ()
+               {
+                       if (is_default_group)
+                               return item_count;
+
+                       int count = 0;
+                       for (int i = 0; i < items.Count; i++)
+                               if (items [i].ListView != null) // Ignore.
+                                       count++;
+
+                       return count;
                }
 
                [Browsable(true)]
@@ -211,5 +248,18 @@ 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