merge -r 58060:58217
[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                         int n = (_rows == null) ? 0 : _rows.Count;
225                         if (n > 0) {
226                                 writer.Indent++;
227                                 for (int i=0; i < n; i++) {
228                                         writer.WriteLine ();
229                                         _rows [i].RenderControl (writer);
230                                 }
231                                 writer.Indent--;
232                         }
233                 }
234
235                 protected override void RenderEndTag (HtmlTextWriter writer)
236                 {
237                         writer.WriteLine ();
238                         writer.WriteEndTag (TagName);
239                         writer.WriteLine ();
240                 }
241
242
243                 protected class HtmlTableRowControlCollection : ControlCollection {
244
245                         internal HtmlTableRowControlCollection (HtmlTable owner)
246                                 : base (owner)
247                         {
248                         }
249
250                         public override void Add (Control child)
251                         {
252                                 if (child == null)
253                                         throw new NullReferenceException ("null");
254                                 if (!(child is HtmlTableRow))
255                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
256
257                                 base.Add (child);
258                         }
259
260                         public override void AddAt (int index, Control child)
261                         {
262                                 if (child == null)
263                                         throw new NullReferenceException ("null");
264                                 if (!(child is HtmlTableRow))
265                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
266
267                                 base.AddAt (index, child);
268                         }
269                 }
270         }
271 }