New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlTable.cs
1 //
2 // System.Web.UI.HtmlControls.HtmlTable.cs
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.ComponentModel;
30 using System.Globalization;
31 using System.Security.Permissions;
32
33 namespace System.Web.UI.HtmlControls {
34
35         // CAS
36         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38         // attributes
39         [ParseChildren (true, "Rows")]  
40         public class HtmlTable : HtmlContainerControl {
41
42                 private HtmlTableRowCollection _rows;
43
44
45                 public HtmlTable ()
46                         : base ("table")
47                 {
48                 }
49
50
51                 [DefaultValue ("")]
52                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
53                 [WebSysDescription("")]
54                 [WebCategory("Layout")]
55                 public string Align {
56                         get {
57                                 string s = Attributes ["align"];
58                                 return (s == null) ? String.Empty : s;
59                         }
60                         set {
61                                 if (value == null)
62                                         Attributes.Remove ("align");
63                                 else
64                                         Attributes ["align"] = value;
65                         }
66                 }
67
68                 [DefaultValue ("")]
69                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
70                 [WebSysDescription("")]
71                 [WebCategory("Appearance")]
72                 public string BgColor {
73                         get {
74                                 string s = Attributes ["bgcolor"];
75                                 return (s == null) ? String.Empty : s;
76                         }
77                         set {
78                                 if (value == null)
79                                         Attributes.Remove ("bgcolor");
80                                 else
81                                         Attributes ["bgcolor"] = value;
82                                 }
83                 }
84
85                 [DefaultValue (-1)]
86                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
87                 [WebSysDescription("")]
88                 [WebCategory("Appearance")]
89                 public int Border {
90                         get {
91                                 string s = Attributes ["border"];
92                                 return (s == null) ? -1 : Convert.ToInt32 (s);
93                         }
94                         set {
95                                 if (value == -1)
96                                         Attributes.Remove ("border");
97                                 else
98                                         Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
99                         }
100                 }
101
102                 [DefaultValue ("")]
103                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
104                 [WebSysDescription("")]
105                 [WebCategory("Appearance")]
106                 public string BorderColor {
107                         get {
108                                 string s = Attributes ["bordercolor"];
109                                 return (s == null) ? String.Empty : s;
110                         }
111                         set {
112                                 if (value == null)
113                                         Attributes.Remove ("bordercolor");
114                                 else
115                                         Attributes ["bordercolor"] = value;
116                         }
117                 }
118
119                 [DefaultValue ("")]
120                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
121                 [WebSysDescription("")]
122                 [WebCategory("Appearance")]
123                 public int CellPadding {
124                         get {
125                                 string s = Attributes ["cellpadding"];
126                                 return (s == null) ? -1 : Convert.ToInt32 (s);
127                         }
128                         set {
129                                 if (value == -1)
130                                         Attributes.Remove ("cellpadding");
131                                 else
132                                         Attributes ["cellpadding"] = value.ToString (CultureInfo.InvariantCulture);
133                         }
134                 }
135
136                 [DefaultValue ("")]
137                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
138                 [WebSysDescription("")]
139                 [WebCategory("Appearance")]
140                 public int CellSpacing {
141                         get {
142                                 string s = Attributes ["cellspacing"];
143                                 return (s == null) ? -1 : Convert.ToInt32 (s);
144                         }
145                         set {
146                                 if (value == -1)
147                                         Attributes.Remove ("cellspacing");
148                                 else
149                                         Attributes ["cellspacing"] = value.ToString (CultureInfo.InvariantCulture);
150                         }
151                 }
152
153                 [DefaultValue ("")]
154                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
155                 [WebSysDescription("")]
156                 [WebCategory("Layout")]
157                 public string Height {
158                         get {
159                                 string s = Attributes ["height"];
160                                 return (s == null) ? String.Empty : s;
161                         }
162                         set {
163                                 if (value == null)
164                                         Attributes.Remove ("height");
165                                 else
166                                         Attributes ["height"] = value;
167                         }
168                 }
169
170                 public override string InnerHtml {
171                         get { throw new NotSupportedException (); }
172                         set { throw new NotSupportedException (); }
173                 }
174
175                 public override string InnerText {
176                         get { throw new NotSupportedException (); }
177                         set { throw new NotSupportedException (); }
178                 }
179
180                 [Browsable (false)]
181                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
182                 public virtual HtmlTableRowCollection Rows {
183                         get {
184                                 if (_rows == null)
185                                         _rows = new HtmlTableRowCollection (this);
186                                 return _rows;
187                         }
188                 }
189
190                 [DefaultValue ("")]
191                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
192                 [WebSysDescription("")]
193                 [WebCategory("Layout")]
194                 public string Width {
195                         get {
196                                 string s = Attributes ["width"];
197                                 return (s == null) ? String.Empty : s;
198                         }
199                         set {
200                                 if (value == null)
201                                         Attributes.Remove ("width");
202                                 else
203                                         Attributes ["width"] = value;
204                         }
205                 }
206
207
208                 protected override ControlCollection CreateControlCollection ()
209                 {
210                         return new HtmlTableRowControlCollection (this);
211                 }
212
213 #if NET_2_0
214                 protected internal
215 #else           
216                 protected
217 #endif          
218                 override void RenderChildren (HtmlTextWriter writer)
219                 {
220                         if (HasControls ()) {
221                                 writer.Indent++;
222                                 base.RenderChildren (writer);
223                                 writer.Indent--;
224                                 writer.WriteLine ();
225                         }
226                 }
227
228                 protected override void RenderEndTag (HtmlTextWriter writer)
229                 {
230                         writer.WriteLine ();
231                         writer.WriteEndTag (TagName);
232                         writer.WriteLine ();
233                 }
234
235
236                 protected class HtmlTableRowControlCollection : ControlCollection {
237
238                         internal HtmlTableRowControlCollection (HtmlTable owner)
239                                 : base (owner)
240                         {
241                         }
242
243                         public override void Add (Control child)
244                         {
245                                 if (child == null)
246                                         throw new NullReferenceException ("null");
247                                 if (!(child is HtmlTableRow))
248                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
249
250                                 base.Add (child);
251                         }
252
253                         public override void AddAt (int index, Control child)
254                         {
255                                 if (child == null)
256                                         throw new NullReferenceException ("null");
257                                 if (!(child is HtmlTableRow))
258                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
259
260                                 base.AddAt (index, child);
261                         }
262                 }
263         }
264 }