Author: jpobst
Date: 2007-07-10 12:11:13 -0400 (Tue, 10 Jul 2007)
New Revision: 81725
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
Log:
2007-07-10 Jonathan Pobst <[EMAIL PROTECTED]>
* ListBox.cs: Add IntegerCollection and Add, Clear, Remove
to existing collections.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-07-10 15:42:49 UTC (rev 81724)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-07-10 16:11:13 UTC (rev 81725)
@@ -1,3 +1,8 @@
+2007-07-10 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * ListBox.cs: Add IntegerCollection and Add, Clear, Remove
+ to existing collections.
+
2007-07-09 Jonathan Pobst <[EMAIL PROTECTED]>
* AccessibleObject.cs, RadioButton.cs: Fix some base classes
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
2007-07-10 15:42:49 UTC (rev 81724)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
2007-07-10 16:11:13 UTC (rev 81725)
@@ -35,6 +35,10 @@
using System.Reflection;
using System.Runtime.InteropServices;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
+
namespace System.Windows.Forms
{
[DefaultProperty("Items")]
@@ -2047,6 +2051,168 @@
#endregion Private Methods
+#if NET_2_0
+ public class IntegerCollection : IList, ICollection, IEnumerable
+ {
+ private ListBox owner;
+ private List<int> list;
+
+ #region Public Constructor
+ public IntegerCollection (ListBox owner)
+ {
+ this.owner = owner;
+ list = new List<int> ();
+ }
+ #endregion
+
+ #region Public Properties
+ [Browsable (false)]
+ public int Count {
+ get { return list.Count; }
+ }
+
+ public int this [int index] {
+ get { return list[index]; }
+ set { list[index] = value; }
+ }
+ #endregion
+
+ #region Public Methods
+ public int Add (int item)
+ {
+ // This collection does not allow duplicates
+ if (!list.Contains (item)) {
+ list.Add (item);
+ list.Sort ();
+ }
+
+ return list.IndexOf (item);
+ }
+
+ public void AddRange (int[] items)
+ {
+ foreach (int i in items)
+ if (!list.Contains (i))
+ list.Add (i);
+
+ list.Sort ();
+ }
+
+ public void AddRange (IntegerCollection value)
+ {
+ foreach (int i in value)
+ if (!list.Contains (i))
+ list.Add (i);
+
+ list.Sort ();
+ }
+
+ public void Clear ()
+ {
+ list.Clear ();
+ }
+
+ public bool Contains (int item)
+ {
+ return list.Contains (item);
+ }
+
+ public void CopyTo (Array destination, int index)
+ {
+ list.CopyTo ((int[])destination, index);
+ }
+
+ public int IndexOf (int item)
+ {
+ return list.IndexOf (item);
+ }
+
+ public void Remove (int item)
+ {
+ list.Remove (item);
+ list.Sort ();
+ }
+
+ public void RemoveAt (int index)
+ {
+ list.RemoveAt (index);
+ list.Sort ();
+ }
+ #endregion
+
+ #region IEnumerable Members
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return list.GetEnumerator ();
+ }
+ #endregion
+
+ #region IList Members
+ int IList.Add (object value)
+ {
+ return Add ((int)value);
+ }
+
+ void IList.Clear ()
+ {
+ Clear ();
+ }
+
+ bool IList.Contains (object value)
+ {
+ return Contains ((int)value);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ return IndexOf ((int)value);
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ throw new Exception ("The method or operation
is not implemented.");
+ }
+
+ bool IList.IsFixedSize
+ {
+ get { return false; }
+ }
+
+ bool IList.IsReadOnly
+ {
+ get { return false; }
+ }
+
+ void IList.Remove (object value)
+ {
+ Remove ((int)value);
+ }
+
+ void IList.RemoveAt (int index)
+ {
+ RemoveAt (index);
+ }
+
+ object IList.this[int index] {
+ get { return this[index]; }
+ set { this[index] = (int)value; }
+ }
+ #endregion
+
+ #region ICollection Members
+ bool ICollection.IsSynchronized
+ {
+ get { throw new Exception ("The method or
operation is not implemented."); }
+ }
+
+ object ICollection.SyncRoot
+ {
+ get { throw new Exception ("The method or
operation is not implemented."); }
+ }
+ #endregion
+ }
+#endif
+
[ListBindable (false)]
public class ObjectCollection : IList, ICollection, IEnumerable
{
@@ -2299,6 +2465,24 @@
#endregion Public Properties
#region Public Methods
+#if NET_2_0
+ public void Add (int index)
+ {
+ object item = owner.items[index];
+
+ if (!owner.selection.Contains (item)) {
+ owner.selection.Add (item);
+ owner.CollectionChanged ();
+ }
+ }
+
+ public void Clear ()
+ {
+ owner.selection.Clear ();
+ owner.CollectionChanged ();
+ }
+#endif
+
public bool Contains (int selectedIndex)
{
foreach (object o in owner.selection)
@@ -2323,6 +2507,19 @@
return indices.GetEnumerator ();
}
+#if NET_2_0
+ public void Remove (int index)
+ {
+ object value = owner.items[index];
+
+ if (value == null)
+ return;
+
+ owner.selection.Remove (value);
+ owner.CollectionChanged ();
+ }
+#endif
+
int IList.Add (object obj)
{
throw new NotSupportedException ();
@@ -2418,6 +2615,22 @@
#endregion Public Properties
#region Public Methods
+#if NET_2_0
+ public void Add (object item)
+ {
+ if (!owner.selection.Contains (item)) {
+ owner.selection.Add (item);
+ owner.CollectionChanged ();
+ }
+ }
+
+ public void Clear ()
+ {
+ owner.selection.Clear ();
+ owner.CollectionChanged ();
+ }
+#endif
+
public bool Contains (object selectedObject)
{
return owner.selection.Contains
(selectedObject);
@@ -2428,6 +2641,17 @@
owner.selection.CopyTo (dest, index);
}
+#if NET_2_0
+ public void Remove (object value)
+ {
+ if (value == null)
+ return;
+
+ owner.selection.Remove (value);
+ owner.CollectionChanged ();
+ }
+#endif
+
int IList.Add (object value)
{
throw new NotSupportedException ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches