2 // System.Web.UI.ControlCollection.cs
4 // Duncan Mak (duncan@ximian.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
33 namespace System.Web.UI {
35 public class ControlCollection : ICollection, IEnumerable
40 public ControlCollection (Control owner)
43 throw new ArgumentException ();
45 list = new ArrayList ();
49 internal ControlCollection (Control owner, bool shortList)
52 throw new ArgumentException ();
54 list = new ArrayList (shortList ? 1 : 0);
59 get { return list.Count; }
62 public bool IsReadOnly {
63 get { return list.IsReadOnly; }
66 public bool IsSynchronized {
67 get { return list.IsSynchronized; }
70 public virtual Control this [int index] {
71 get { return list [index] as Control; }
74 protected Control Owner {
78 public object SyncRoot {
79 get { return list.SyncRoot; }
82 public virtual void Add (Control child)
85 throw new ArgumentNullException ();
87 throw new HttpException ();
90 owner.AddedControl (child, list.Count - 1);
93 public virtual void AddAt (int index, Control child)
95 if (child == null) // maybe we should check for ! (child is Control)?
96 throw new ArgumentNullException ();
98 if ((index < -1) || (index > Count))
99 throw new ArgumentOutOfRangeException ();
102 throw new HttpException ();
107 list.Insert (index, child);
108 owner.AddedControl (child, index);
112 public virtual void Clear ()
116 owner.ResetChildNames ();
119 public virtual bool Contains (Control c)
121 return list.Contains (c);
124 public void CopyTo (Array array, int index)
126 list.CopyTo (array, index);
129 public IEnumerator GetEnumerator ()
131 return list.GetEnumerator ();
134 public virtual int IndexOf (Control c)
136 return list.IndexOf (c);
139 public virtual void Remove (Control value)
142 owner.RemovedControl (value);
145 public virtual void RemoveAt (int index)
148 throw new HttpException ();
150 Control value = (Control) list [index];
151 list.RemoveAt (index);
152 owner.RemovedControl (value);