ControlCollection.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // System.Web.UI.ControlCollection.cs
  3. //
  4. // Duncan Mak ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. //
  8. using System;
  9. using System.Collections;
  10. namespace System.Web.UI {
  11. public class ControlCollection : ICollection, IEnumerable
  12. {
  13. ArrayList list = new ArrayList ();
  14. Control owner;
  15. public ControlCollection (Control owner)
  16. {
  17. if (owner == null)
  18. throw new ArgumentException ();
  19. this.owner = owner;
  20. }
  21. public int Count {
  22. get { return list.Count; }
  23. }
  24. public bool IsReadOnly {
  25. get { return list.IsReadOnly; }
  26. }
  27. public bool IsSynchronized {
  28. get { return list.IsSynchronized; }
  29. }
  30. public virtual Control this [int index] {
  31. get { return list [index] as Control; }
  32. }
  33. protected Control Owner {
  34. get { return owner; }
  35. }
  36. public object SyncRoot {
  37. get { return list.SyncRoot; }
  38. }
  39. public virtual void Add (Control child)
  40. {
  41. if (child == null)
  42. throw new ArgumentNullException ();
  43. if (IsReadOnly)
  44. throw new HttpException ();
  45. list.Add (child);
  46. owner.AddedControl (child, list.Count - 1);
  47. }
  48. public virtual void AddAt (int index, Control child)
  49. {
  50. if (child == null) // maybe we should check for ! (child is Control)?
  51. throw new ArgumentNullException ();
  52. if ((index < -1) || (index > Count))
  53. throw new ArgumentOutOfRangeException ();
  54. if (IsReadOnly)
  55. throw new HttpException ();
  56. if (index == -1){
  57. Add (child);
  58. } else {
  59. list [index] = child;
  60. owner.AddedControl (child, index);
  61. }
  62. }
  63. public virtual void Clear ()
  64. {
  65. list.Clear ();
  66. }
  67. public virtual bool Contains (Control c)
  68. {
  69. return list.Contains (c);
  70. }
  71. public void CopyTo (Array array, int index)
  72. {
  73. list.CopyTo (array, index);
  74. }
  75. public IEnumerator GetEnumerator ()
  76. {
  77. return list.GetEnumerator ();
  78. }
  79. public virtual int IndexOf (Control c)
  80. {
  81. return list.IndexOf (c);
  82. }
  83. public virtual void Remove (Control value)
  84. {
  85. list.Remove (value);
  86. owner.RemovedControl (value);
  87. }
  88. public virtual void RemoveAt (int index)
  89. {
  90. if (IsReadOnly)
  91. throw new HttpException ();
  92. Control value = (Control) list [index];
  93. list.RemoveAt (index);
  94. owner.RemovedControl (value);
  95. }
  96. }
  97. }