Flush pending changes I got from a contributor that did not put his name in
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlTable.cs
1 /*      System.Web.UI.HtmlControls
2 *       Authors
3 *               Leen Toelen (toelen@hotmail.com)
4 */
5
6 using System;
7 using System.Web;
8 using System.Web.UI;
9 using System.Globalization;
10
11 namespace System.Web.UI.HtmlControls{
12         
13         public class HtmlTable : HtmlContainerControl {
14                 private HtmlTableRowCollection _rows;
15                 
16                 public HtmlTable():base("table"){}
17                 
18                 protected override ControlCollection CreateControlCollection(){
19                         return new HtmlTableRowControlCollection(this);
20                 }
21                 
22                 protected override void RenderChildren(HtmlTextWriter writer){
23                         writer.WriteLine();
24                         writer.Indent = writer.Indent + 1;
25                         base.RenderChildren(writer);
26                         writer.Indent = writer.Indent - 1;
27                 }
28                 
29                 protected new void RenderEndTag(HtmlTextWriter writer){
30                         base.RenderEndTag(writer);
31                         writer.WriteLine();
32                 }
33                 
34                 public string Align {
35                         get{
36                                 string attr = Attributes["align"];
37                                 if (attr != null) return attr;
38                                 return "";
39                         }
40                         set{
41                                 Attributes["align"] = AttributeToString(value);
42                         }
43                 }
44                 
45                 public string BgColor {
46                         get{
47                                 string attr = Attributes["bgcolor"];
48                                 if (attr != null) return attr;
49                                 return "";
50                         }
51                         set{
52                                 Attributes["bgcolor"] = AttributeToString(value);
53                         }
54                 }
55                 
56                 public int Border {
57                         get{
58                                 string attr = Attributes["border"];
59                                 if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
60                                 return -1;
61                         }
62                         set{
63                                 Attributes["border"] = AttributeToString(value);
64                         }
65                 }
66                 
67                 public string BorderColor {
68                         get{
69                                 string attr = Attributes["bordercolor"];
70                                 if (attr != null) return attr;
71                                 return "";
72                         }
73                         set{
74                                 Attributes["bordercolor"] = AttributeToString(value);
75                         }
76                 }
77                 
78                 public int CellPadding {
79                         get{
80                                 string attr = Attributes["cellpadding"];
81                                 if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
82                                 return -1;
83                         }
84                         set{
85                                 Attributes["cellpadding"] = AttributeToString(value);
86                         }
87                 }
88                 
89                 public int CellSpacing {
90                         get{
91                                 string attr = Attributes["cellspacing"];
92                                 if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
93                                 return -1;
94                         }
95                         set{
96                                 Attributes["cellspacing"] = AttributeToString(value);
97                         }
98                 }
99                 
100                 public string Height {
101                         get{
102                                 string attr = Attributes["height"];
103                                 if (attr != null) return attr;
104                                 return "";
105                         }
106                         set{
107                                 Attributes["height"] = AttributeToString(value);
108                         }
109                 }
110                 
111                 public override string InnerHtml {
112                         get{
113                                 throw new NotSupportedException("InnerHtml property not supported by HtmlTable");
114                         }
115                         set{
116                                 throw new NotSupportedException("InnerHtml property not supported by HtmlTable");
117                         }
118                 }
119                 
120                 public override string InnerText {
121                         get{
122                                 throw new NotSupportedException("InnerText property not supported by HtmlTable");
123                         }
124                         set{
125                                 throw new NotSupportedException("InnerText property not supported by HtmlTable");
126                         }
127                 }
128                 
129                 public virtual HtmlTableRowCollection Rows {
130                         get{
131                                 if (_rows == null) _rows = new HtmlTableRowCollection(this);
132                                 return _rows;
133                         }
134                 }
135                 
136                 public string Width {
137                         get{
138                                 string attr = Attributes["width"];
139                                 if (attr != null) return attr;
140                                 return "";
141                         }
142                         set{
143                                 Attributes["width"] = AttributeToString(value);
144                         }
145                 }
146                 
147                 protected class HtmlTableRowControlCollection : ControlCollection {
148                         
149                         internal HtmlTableRowControlCollection(Control owner): base(owner){}
150                         
151                         public override void Add(Control child){
152                                 if ((child as HtmlTableCell) != null){
153                                         base.Add(child);
154                                 }
155                                 else{
156                                         throw new ArgumentException("HtmlTableRow cannot have children of type" + child.GetType().Name);
157                                 }
158                         }
159                         
160                         public override void AddAt(int index, Control child){
161                                 if ((child as HtmlTableCell) != null){
162                                         base.AddAt(index,child);
163                                 }
164                                 else{
165                                         throw new ArgumentException("HtmlTableRow cannot have children of type" + child.GetType().Name);
166                                 }
167                         }
168                 } // end of HtmlTableRowControlCollection
169         }
170         // end of System.Web.UI.HtmlControl
171 }