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