X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI.WebControls%2FListItemCollection.cs;h=3fdf3a8cb7c4417b96142e657fe0fd50c2fb8a7a;hb=64c5bf5b672a30208626225787884702122b953b;hp=d8b2829f55ad7b41f6d64f09dc8cf1a01e5f917e;hpb=15ae7bf0337ae8832498fb076e726f2694038ce3;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ListItemCollection.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ListItemCollection.cs index d8b2829f55a..3fdf3a8cb7c 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ListItemCollection.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ListItemCollection.cs @@ -15,22 +15,25 @@ using System; using System.Collections; using System.Web; using System.Web.UI; +using System.ComponentModel; +using System.Reflection; namespace System.Web.UI.WebControls -{ - public class ListItemCollection : IList, ICollection, IEnumerable, IStateManager +{ + [Editor ("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))] + public sealed class ListItemCollection : IList, ICollection, IEnumerable, IStateManager { private ArrayList items; private bool saveAll; private bool marked; - + public ListItemCollection() { items = new ArrayList(); saveAll = false; marked = false; } - + public int Capacity { get @@ -42,7 +45,7 @@ namespace System.Web.UI.WebControls items.Capacity = value; } } - + public int Count { get @@ -50,7 +53,7 @@ namespace System.Web.UI.WebControls return items.Count; } } - + public bool IsReadOnly { get @@ -58,7 +61,7 @@ namespace System.Web.UI.WebControls return items.IsReadOnly; } } - + public bool IsSynchronized { get @@ -66,7 +69,7 @@ namespace System.Web.UI.WebControls return items.IsSynchronized; } } - + public ListItem this[int index] { get @@ -74,14 +77,9 @@ namespace System.Web.UI.WebControls if(index < 0 || index >= Count) return null; return (ListItem)(items[index]); - } - set - { - if(index >= 0 && index < Count) - items[index] = value; - } + } } - + public object SyncRoot { get @@ -89,19 +87,19 @@ namespace System.Web.UI.WebControls return this; } } - + public void Add(ListItem item) { items.Add(item); if(marked) item.Dirty = true; } - + public void Add(string item) { Add(new ListItem(item)); } - + public void AddRange(ListItem[] items) { foreach(ListItem item in items) @@ -110,24 +108,24 @@ namespace System.Web.UI.WebControls Add(item); } } - + public void Clear() { items.Clear(); if(marked) saveAll = true; } - + public bool Contains(ListItem item) { return items.Contains(item); } - + public void CopyTo(Array array, int index) { items.CopyTo(array, index); } - + public ListItem FindByText(string text) { int i=-1; @@ -139,21 +137,19 @@ namespace System.Web.UI.WebControls } return (i==-1 ? null : (ListItem)items[i]); } - + public ListItem FindByValue(string value) { foreach(ListItem current in items) { if(current.Value == value) { - if(current is Disposable) - current.Dispose(); return current; } } return null; } - + internal int FindByValueInternal(string value) { int i = -1; @@ -162,36 +158,34 @@ namespace System.Web.UI.WebControls i++; if(current.Value == value) { - if(current is Disposable) - current.Dispose(); return i; } } return -1; } - + public IEnumerator GetEnumerator() { return items.GetEnumerator(); } - + public int IndexOf(ListItem item) { return items.IndexOf(item); } - + public void Insert(int index, ListItem item) { items.Insert(index, item); if(marked) saveAll = true; } - + public void Insert(int index, string item) { Insert(index, new ListItem(item)); } - + public void RemoveAt(int index) { if(index < 0 || index >= items.Count) @@ -200,87 +194,89 @@ namespace System.Web.UI.WebControls if(marked) saveAll = true; } - + public void Remove(ListItem item) { RemoveAt(IndexOf(item)); } - + public void Remove(string item) { RemoveAt(IndexOf(ListItem.FromString(item))); } - - internal object SaveViewState() - { - if(saveAll) - { - string[] keys = new string[Count]; - string[] vals = new string[Count]; - for(int i=0; i < Count; i++) - { - keys[i] = this[i].Text; - vals[i] = this[i].Value; + + internal object SaveViewState () + { + int count = Count; + if (saveAll) { + string [] keys = new string [count]; + string [] vals = new string [count]; + for(int i = 0; i < count; i++) { + keys[i] = this [i].Text; + vals[i] = this [i].Value; } - return new Triplet(Count, keys, vals); + + return new Triplet (count, keys, vals); } - ArrayList indices = new ArrayList(); - ArrayList states = new ArrayList(); + + ArrayList indices = new ArrayList (); + ArrayList states = new ArrayList (); object o; - for(int i=0; i < Count; i++) - { - o = this[i].SaveViewState(); - if(o!=null) - { - indices.Add(i); - states.Add(o); - } + for(int i = 0; i < count; i++) { + o = this [i].SaveViewState (); + if (o == null) + continue; + + indices.Add (i); + states.Add (o); } - if(indices.Count > 0) - return new Pair(indices, states); + + if (indices.Count > 0) + return new Pair (indices, states); + return null; } - - internal void LoadViewState(object savedState) + + internal void LoadViewState (object savedState) { - if(savedState!=null) - { - if(savedState is Pair) - { - ArrayList indices = (ArrayList)(((Pair)savedState).First); - ArrayList states = (ArrayList)(((Pair)savedState).Second); - for(int i=0; i < indices.Count; i++) - { - if( (int)indices[i] < Count ) - this[i].LoadViewState(states[i]); - else - { - ListItem temp = new ListItem(); - temp.LoadViewState(states[i]); - Add(temp); - } + if (savedState == null) + return; + + int i, end; + if (savedState is Pair) { + Pair pair = (Pair) savedState; + ArrayList indices = (ArrayList) pair.First; + ArrayList states = (ArrayList) pair.Second; + + end = indices.Count; + for (i = 0; i < end; i++) { + if ((int) indices [i] < Count ) { + this [i].LoadViewState (states [i]); + } else { + ListItem temp = new ListItem (); + temp.LoadViewState (states [i]); + Add (temp); } } - if(savedState is Triplet) - { - Triplet t = (Triplet)savedState; - items = new ArrayList((int)t.First); - saveAll = true; - string[] text = (string[])t.Second; - string[] vals = (string[])t.Third; - for(int i=0; i < text.Length; i++) - items.Add(new ListItem(text[i], vals[i])); - } + } else if (savedState is Triplet) { + Triplet t = (Triplet) savedState; + items = new ArrayList ((int) t.First); + saveAll = true; + object [] text = (object []) t.Second; + object [] vals = (object []) t.Third; + end = text.Length; + for(i = 0; i < end; i++) + items.Add (new ListItem (text[i].ToString (), vals[i].ToString ())); } } - + internal void TrackViewState() { marked = true; - foreach(ListItem current in this) + foreach(ListItem current in items) current.TrackViewState(); } - + bool IList.IsFixedSize { get @@ -295,12 +291,12 @@ namespace System.Web.UI.WebControls { return this[index]; } + set { - if(value is ListItem) - { - this[index] = (ListItem)value; - } + if(index >= 0 && index < Count) + if(value is ListItem) + items[index] = (ListItem) value; } } @@ -311,27 +307,27 @@ namespace System.Web.UI.WebControls ((ListItem)item).Dirty = true; return index; } - + bool IList.Contains(object item) { if(item is ListItem) return Contains((ListItem)item); return false; } - + int IList.IndexOf(object item) { if(item is ListItem) return IndexOf((ListItem)item); return -1; } - + void IList.Insert(int index, object item) { if(item is ListItem) Insert(index, (ListItem)item); } - + void IList.Remove(object item) { if(item is string) @@ -339,7 +335,7 @@ namespace System.Web.UI.WebControls if(item is ListItem) Remove((ListItem)item); } - + bool IStateManager.IsTrackingViewState { get @@ -347,17 +343,17 @@ namespace System.Web.UI.WebControls return marked; } } - + void IStateManager.LoadViewState(object state) { LoadViewState(state); } - + object IStateManager.SaveViewState() { return SaveViewState(); } - + void IStateManager.TrackViewState() { TrackViewState();