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