Merge branch 'sgen-android'
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewGroup.cs
index 5b42ba371c1e9ffbd26bdde2c950bc6158dfcc09..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,6 +37,7 @@ namespace System.Windows.Forms
        [ToolboxItem(false)]
        [DesignTimeVisible(false)]
        [DefaultProperty("Header")]
+       [TypeConverter (typeof (ListViewGroupConverter))]
        public sealed class ListViewGroup : ISerializable
        {
                internal string header = string.Empty;
@@ -49,6 +48,8 @@ namespace System.Windows.Forms
                private object tag = null;
                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;
@@ -56,29 +57,24 @@ namespace System.Windows.Forms
 
                #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)
@@ -136,9 +132,6 @@ namespace System.Windows.Forms
                [Browsable(false)]
                public ListView.ListViewItemCollection Items {
                        get {
-                               if (items == null)
-                                       items = new ListView.ListViewItemCollection (list_view_owner, this);
-
                                return items;
                        }
                }
@@ -198,6 +191,19 @@ namespace System.Windows.Forms
                        }
                }
 
+               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)]
                [DefaultValue("")]
                public string Name {
@@ -242,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