Author: calberto
Date: 2007-06-11 18:43:38 -0400 (Mon, 11 Jun 2007)
New Revision: 79215
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewItem.cs
Log:
2007-06-11 Carlos Alberto Cortez <[EMAIL PROTECTED]>
* ListView.cs:
* ListViewItem.cs: In VirtualMode the selection information
resides in the ListView, rather than in the Items. Also, throw
InvalidOperationExceptions when VirtualMode is being used and
CheckedItemCollection is accessed.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-06-11 22:08:59 UTC (rev 79214)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-06-11 22:43:38 UTC (rev 79215)
@@ -1,3 +1,11 @@
+2007-06-11 Carlos Alberto Cortez <[EMAIL PROTECTED]>
+
+ * ListView.cs:
+ * ListViewItem.cs: In VirtualMode the selection information
+ resides in the ListView, rather than in the Items. Also, throw
+ InvalidOperationExceptions when VirtualMode is being used and
+ CheckedItemCollection is accessed.
+
2007-06-08 Jonathan Pobst <[EMAIL PROTECTED]>
* ComboBox.cs: Add ScaleControl.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
2007-06-11 22:08:59 UTC (rev 79214)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
2007-06-11 22:43:38 UTC (rev 79215)
@@ -1866,7 +1866,7 @@
}
BoxSelect box_select_mode = BoxSelect.None;
- ArrayList prev_selection;
+ IList prev_selection;
Point box_select_start;
Rectangle box_select_rect;
@@ -2087,7 +2087,7 @@
else
box_select_mode =
BoxSelect.Normal;
box_select_start = pt;
- prev_selection =
owner.SelectedIndices.List;
+ prev_selection =
owner.SelectedIndices.List.Clone () as IList;
}
}
@@ -3481,6 +3481,10 @@
public ListViewItem this [int index] {
get {
+#if NET_2_0
+ if (owner.VirtualMode)
+ throw new
InvalidOperationException ();
+#endif
ArrayList checked_items = List;
if (index < 0 || index >=
checked_items.Count)
throw new
ArgumentOutOfRangeException ("index");
@@ -3532,6 +3536,10 @@
public void CopyTo (Array dest, int index)
{
+#if NET_2_0
+ if (owner.VirtualMode)
+ throw new InvalidOperationException ();
+#endif
if (!owner.CheckBoxes)
return;
List.CopyTo (dest, index);
@@ -3539,6 +3547,10 @@
public IEnumerator GetEnumerator ()
{
+#if NET_2_0
+ if (owner.VirtualMode)
+ throw new InvalidOperationException ();
+#endif
if (!owner.CheckBoxes)
return (new ListViewItem
[0]).GetEnumerator ();
return List.GetEnumerator ();
@@ -3585,6 +3597,10 @@
public int IndexOf (ListViewItem item)
{
+#if NET_2_0
+ if (owner.VirtualMode)
+ throw new InvalidOperationException ();
+#endif
if (!owner.CheckBoxes)
return -1;
return List.IndexOf (item);
@@ -3593,6 +3609,10 @@
#if NET_2_0
public virtual int IndexOfKey (string key)
{
+#if NET_2_0
+ if (owner.VirtualMode)
+ throw new InvalidOperationException ();
+#endif
if (key == null || key.Length == 0)
return -1;
@@ -4417,6 +4437,12 @@
}
} // ListViewItemCollection
+
+ // In normal mode, the selection information resides in the
Items,
+ // making SelectedIndexCollection.List read-only
+ //
+ // In virtual mode, SelectedIndexCollection directly saves the
selection
+ // information, instead of getting it from Items, making List
read-and-write
public class SelectedIndexCollection : IList, ICollection,
IEnumerable
{
private readonly ListView owner;
@@ -4491,7 +4517,11 @@
if (itemIndex < 0 || itemIndex >=
owner.Items.Count)
throw new ArgumentOutOfRangeException
("index");
+ if (owner.virtual_mode &&
!owner.IsHandleCreated)
+ return -1;
+
owner.Items [itemIndex].Selected = true;
+
if (!owner.IsHandleCreated)
return 0;
@@ -4509,7 +4539,8 @@
if (!owner.IsHandleCreated)
return;
- foreach (int index in List)
+ int [] indexes = (int []) List.ToArray (typeof
(int));
+ foreach (int index in indexes)
owner.Items [index].Selected = false;
}
@@ -4569,6 +4600,9 @@
public int IndexOf (int selectedIndex)
{
+ if (!owner.IsHandleCreated)
+ return -1;
+
return List.IndexOf (selectedIndex);
}
@@ -4587,12 +4621,14 @@
get {
if (list == null) {
list = new ArrayList ();
+#if NET_2_0
+ if (!owner.VirtualMode)
+#endif
for (int i = 0; i <
owner.Items.Count; i++) {
if (owner.Items
[i].Selected)
list.Add (i);
}
}
-
return list;
}
}
@@ -4600,6 +4636,9 @@
internal void Reset ()
{
// force re-population of list
+#if NET_2_0
+ if (!owner.VirtualMode)
+#endif
list = null;
}
@@ -4608,6 +4647,36 @@
Reset ();
}
+#if NET_2_0
+ internal void RemoveIndex (int index)
+ {
+ int idx = List.BinarySearch (index);
+ if (idx != -1)
+ List.RemoveAt (idx);
+ }
+
+ // actually store index in the collection
+ // also, keep the collection sorted, as .Net does
+ internal void InsertIndex (int index)
+ {
+ int iMin = 0;
+ int iMax = List.Count - 1;
+ while (iMin <= iMax) {
+ int iMid = (iMin + iMax) / 2;
+ int current_index = (int) List [iMid];
+
+ if (current_index == index)
+ return; // Already added
+ if (current_index > index)
+ iMax = iMid - 1;
+ else
+ iMin = iMid + 1;
+ }
+
+ List.Insert (iMin, index);
+ }
+#endif
+
} // SelectedIndexCollection
public class SelectedListViewItemCollection : IList,
ICollection, IEnumerable
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewItem.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewItem.cs
2007-06-11 22:08:59 UTC (rev 79214)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewItem.cs
2007-06-11 22:43:38 UTC (rev 79215)
@@ -411,23 +411,42 @@
}
#endif
+ // When ListView uses VirtualMode, selection state info
+ // lives in the ListView, not in the item
[Browsable (false)]
[DesignerSerializationVisibility
(DesignerSerializationVisibility.Hidden)]
public bool Selected {
get {
+#if NET_2_0
+ if (owner != null && owner.VirtualMode)
+ return owner.SelectedIndices.Contains
(Index);
+#endif
+
return selected;
}
set {
+#if NET_2_0
+ if (selected == value && owner != null &&
!owner.VirtualMode)
+#else
if (selected == value)
+#endif
return;
if (owner != null) {
if (value && !owner.MultiSelect)
- owner.SelectedItems.Clear ();
- selected = value;
+ owner.SelectedIndices.Clear ();
+#if NET_2_0
+ if (owner.VirtualMode)
+ if (value)
+
owner.SelectedIndices.InsertIndex (Index);
+ else
+
owner.SelectedIndices.RemoveIndex (Index);
+ else
+#endif
+ selected = value;
+
// force re-population of list
owner.SelectedIndices.Reset ();
- Layout ();
owner.OnSelectedIndexChanged ();
} else {
selected = value;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches