* support-test-*.cs: Rename from test-*-p2.cs.
[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 #if NET_2_0
40         [ParseChildren (true, "Rows", ChildControlType = typeof(Control))]
41 #else
42         [ParseChildren (true, "Rows")]
43 #endif          
44         public class HtmlTable : HtmlContainerControl {
45
46                 private HtmlTableRowCollection _rows;
47
48
49                 public HtmlTable ()
50                         : base ("table")
51                 {
52                 }
53
54
55                 [DefaultValue ("")]
56                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
57                 [WebSysDescription("")]
58                 [WebCategory("Layout")]
59                 public string Align {
60                         get {
61                                 string s = Attributes ["align"];
62                                 return (s == null) ? String.Empty : s;
63                         }
64                         set {
65                                 if (value == null)
66                                         Attributes.Remove ("align");
67                                 else
68                                         Attributes ["align"] = value;
69                         }
70                 }
71
72                 [DefaultValue ("")]
73                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
74                 [WebSysDescription("")]
75                 [WebCategory("Appearance")]
76                 public string BgColor {
77                         get {
78                                 string s = Attributes ["bgcolor"];
79                                 return (s == null) ? String.Empty : s;
80                         }
81                         set {
82                                 if (value == null)
83                                         Attributes.Remove ("bgcolor");
84                                 else
85                                         Attributes ["bgcolor"] = value;
86                                 }
87                 }
88
89                 [DefaultValue (-1)]
90                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
91                 [WebSysDescription("")]
92                 [WebCategory("Appearance")]
93                 public int Border {
94                         get {
95                                 string s = Attributes ["border"];
96                                 return (s == null) ? -1 : Convert.ToInt32 (s);
97                         }
98                         set {
99                                 if (value == -1)
100                                         Attributes.Remove ("border");
101                                 else
102                                         Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
103                         }
104                 }
105
106                 [DefaultValue ("")]
107                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
108                 [WebSysDescription("")]
109                 [WebCategory("Appearance")]
110                 public string BorderColor {
111                         get {
112                                 string s = Attributes ["bordercolor"];
113                                 return (s == null) ? String.Empty : s;
114                         }
115                         set {
116                                 if (value == null)
117                                         Attributes.Remove ("bordercolor");
118                                 else
119                                         Attributes ["bordercolor"] = value;
120                         }
121                 }
122
123                 [DefaultValue ("")]
124                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
125                 [WebSysDescription("")]
126                 [WebCategory("Appearance")]
127                 public int CellPadding {
128                         get {
129                                 string s = Attributes ["cellpadding"];
130                                 return (s == null) ? -1 : Convert.ToInt32 (s);
131                         }
132                         set {
133                                 if (value == -1)
134                                         Attributes.Remove ("cellpadding");
135                                 else
136                                         Attributes ["cellpadding"] = value.ToString (CultureInfo.InvariantCulture);
137                         }
138                 }
139
140                 [DefaultValue ("")]
141                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
142                 [WebSysDescription("")]
143                 [WebCategory("Appearance")]
144                 public int CellSpacing {
145                         get {
146                                 string s = Attributes ["cellspacing"];
147                                 return (s == null) ? -1 : Convert.ToInt32 (s);
148                         }
149                         set {
150                                 if (value == -1)
151                                         Attributes.Remove ("cellspacing");
152                                 else
153                                         Attributes ["cellspacing"] = value.ToString (CultureInfo.InvariantCulture);
154                         }
155                 }
156
157                 [DefaultValue ("")]
158                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
159                 [WebSysDescription("")]
160                 [WebCategory("Layout")]
161                 public string Height {
162                         get {
163                                 string s = Attributes ["height"];
164                                 return (s == null) ? String.Empty : s;
165                         }
166                         set {
167                                 if (value == null)
168                                         Attributes.Remove ("height");
169                                 else
170                                         Attributes ["height"] = value;
171                         }
172                 }
173
174                 public override string InnerHtml {
175                         get { throw new NotSupportedException (); }
176                         set { throw new NotSupportedException (); }
177                 }
178
179                 public override string InnerText {
180                         get { throw new NotSupportedException (); }
181                         set { throw new NotSupportedException (); }
182                 }
183
184                 [Browsable (false)]
185                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186                 public virtual HtmlTableRowCollection Rows {
187                         get {
188                                 if (_rows == null)
189                                         _rows = new HtmlTableRowCollection (this);
190                                 return _rows;
191                         }
192                 }
193
194                 [DefaultValue ("")]
195                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
196                 [WebSysDescription("")]
197                 [WebCategory("Layout")]
198                 public string Width {
199                         get {
200                                 string s = Attributes ["width"];
201                                 return (s == null) ? String.Empty : s;
202                         }
203                         set {
204                                 if (value == null)
205                                         Attributes.Remove ("width");
206                                 else
207                                         Attributes ["width"] = value;
208                         }
209                 }
210
211
212                 protected override ControlCollection CreateControlCollection ()
213                 {
214                         return new HtmlTableRowControlCollection (this);
215                 }
216
217 #if NET_2_0
218                 protected internal
219 #else           
220                 protected
221 #endif          
222                 override void RenderChildren (HtmlTextWriter writer)
223                 {
224                         if (HasControls ()) {
225                                 writer.Indent++;
226                                 base.RenderChildren (writer);
227                                 writer.Indent--;
228                                 writer.WriteLine ();
229                         }
230                 }
231
232                 protected override void RenderEndTag (HtmlTextWriter writer)
233                 {
234                         writer.WriteLine ();
235                         writer.WriteEndTag (TagName);
236                         writer.WriteLine ();
237                 }
238
239
240                 protected class HtmlTableRowControlCollection : ControlCollection {
241
242                         internal HtmlTableRowControlCollection (HtmlTable owner)
243                                 : base (owner)
244                         {
245                         }
246
247                         public override void Add (Control child)
248                         {
249                                 if (child == null)
250                                         throw new NullReferenceException ("null");
251                                 if (!(child is HtmlTableRow))
252                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
253
254                                 base.Add (child);
255                         }
256
257                         public override void AddAt (int index, Control child)
258                         {
259                                 if (child == null)
260                                         throw new NullReferenceException ("null");
261                                 if (!(child is HtmlTableRow))
262                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
263
264                                 base.AddAt (index, child);
265                         }
266                 }
267         }
268 }