2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableCellCollection.cs
1
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 /**\r
23  * Namespace: System.Web.UI.WebControls\r
24  * Class:     TableCellCollection\r
25  *\r
26  * Author:  Gaurav Vaish\r
27  * Maintainer: gvaish@iitk.ac.in\r
28  * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
29  * Implementation: yes\r
30  * Status:  100%\r
31  *\r
32  * (C) Gaurav Vaish (2002)\r
33  */\r
34 \r
35 using System;\r
36 using System.Collections;\r
37 using System.Web;\r
38 using System.Web.UI;\r
39 using System.ComponentModel;\r
40 \r
41 namespace System.Web.UI.WebControls\r
42 {\r
43         [Editor ("System.Web.UI.Design.WebControls.TableCellsCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]\r
44         public sealed class TableCellCollection: IList, ICollection, IEnumerable\r
45         {\r
46                 private TableRow owner;\r
47 \r
48                 internal TableCellCollection(TableRow owner)\r
49                 {\r
50                         if(owner == null)\r
51                         {\r
52                                 throw new ArgumentNullException();\r
53                         }\r
54                         this.owner = owner;\r
55                 }\r
56 \r
57                 public int Count\r
58                 {\r
59                         get\r
60                         {\r
61                                 return owner.Controls.Count;\r
62                         }\r
63                 }\r
64 \r
65                 public bool IsReadOnly\r
66                 {\r
67                         get\r
68                         {\r
69                                 return false;\r
70                         }\r
71                 }\r
72 \r
73                 public bool IsSynchronized\r
74                 {\r
75                         get\r
76                         {\r
77                                 return false;\r
78                         }\r
79                 }\r
80 \r
81                 public TableCell this[int index]\r
82                 {\r
83                         get\r
84                         {\r
85                                 return (TableCell)owner.Controls[index];\r
86                         }\r
87                 }\r
88 \r
89                 public object SyncRoot\r
90                 {\r
91                         get\r
92                         {\r
93                                 return this;\r
94                         }\r
95                 }\r
96 \r
97                 public int Add(TableCell cell)\r
98                 {\r
99                         AddAt(-1, cell);\r
100                         return owner.Controls.Count - 1;\r
101                 }\r
102 \r
103                 public void AddAt(int index, TableCell cell)\r
104                 {\r
105                         owner.Controls.AddAt(index, cell);\r
106                 }\r
107 \r
108                 public void AddRange(TableCell[] cells)\r
109                 {\r
110                         foreach(TableCell cell in cells)\r
111                         {\r
112                                 Add(cell);\r
113                         }\r
114                 }\r
115 \r
116                 public void Clear()\r
117                 {\r
118                         if(owner.HasControls())\r
119                         {\r
120                                 owner.Controls.Clear();\r
121                         }\r
122                 }\r
123 \r
124                 public void CopyTo(Array array, int index)\r
125                 {\r
126                         foreach(object cell in this)\r
127                         {\r
128                                 array.SetValue(cell, index++);\r
129                         }\r
130                 }\r
131 \r
132                 public int GetCellIndex(TableCell cell)\r
133                 {\r
134                         if(!owner.HasControls())\r
135                         {\r
136                                 return -1;\r
137                         }\r
138                         return owner.Controls.IndexOf(cell);\r
139                 }\r
140 \r
141                 public IEnumerator GetEnumerator()\r
142                 {\r
143                         return owner.Controls.GetEnumerator();\r
144                 }\r
145 \r
146                 public void Remove(TableCell cell)\r
147                 {\r
148                         owner.Controls.Remove(cell);\r
149                 }\r
150 \r
151                 public void RemoveAt(int index)\r
152                 {\r
153                         owner.Controls.RemoveAt(index);\r
154                 }\r
155 \r
156                 int IList.Add(object o)\r
157                 {\r
158                         return Add((TableCell)o);\r
159                 }\r
160 \r
161                 bool IList.Contains(object o)\r
162                 {\r
163                         return owner.Controls.Contains((TableCell)o);\r
164                 }\r
165 \r
166                 int IList.IndexOf(object o)\r
167                 {\r
168                         return owner.Controls.IndexOf((TableCell)o);\r
169                 }\r
170 \r
171                 void IList.Insert(int index, object o)\r
172                 {\r
173                         owner.Controls.AddAt(index, (TableCell)o);\r
174                 }\r
175 \r
176                 void IList.Remove(object o)\r
177                 {\r
178                         owner.Controls.Remove((TableCell)o);\r
179                 }\r
180 \r
181                 bool IList.IsFixedSize\r
182                 {\r
183                         get\r
184                         {\r
185                                 return false;\r
186                         }\r
187                 }\r
188 \r
189                 object IList.this[int index]\r
190                 {\r
191                         get\r
192                         {\r
193                                 return this[index];\r
194                         }\r
195                         set\r
196                         {\r
197                                 RemoveAt(index);\r
198                                 AddAt(index, (TableCell)value);\r
199                         }\r
200                 }\r
201         }\r
202 }\r