// Author:
// Daniel Nauck (dna(at)mono-project(dot)de)
-#if NET_2_0
-
using System;
using System.Text;
using System.Runtime.Serialization;
[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)
[Browsable(false)]
public ListView.ListViewItemCollection Items {
get {
- if (items == null)
- items = new ListView.ListViewItemCollection(list_view_owner);
-
return items;
}
}
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)]
#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