2002-03-05 Gaurav Vaish <gvaish@iitk.ac.in>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Table.cs
1 /**\r
2  * Namespace: System.Web.UI.WebControls\r
3  * Class:     Table\r
4  *\r
5  * Author:  Gaurav Vaish\r
6  * Maintainer: gvaish@iitk.ac.in\r
7  * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
8  * Implementation: yes\r
9  * Status:  100%\r
10  *\r
11  * (C) Gaurav Vaish (2002)\r
12  */\r
13 \r
14 using System;\r
15 using System.Drawing;\r
16 using System.Globalization;\r
17 using System.Web;\r
18 using System.Web.UI;\r
19 \r
20 namespace System.Web.UI.WebControls\r
21 {\r
22         public class Table: WebControl\r
23         {\r
24                 private TableRowCollection rows;\r
25 \r
26                 private class TableRowControlCollection : ControlCollection\r
27                 {\r
28                         public TableRowControlCollection(Control owner): base(owner)\r
29                         {\r
30                         }\r
31 \r
32                         public override void Add(Control child)\r
33                         {\r
34                                 if(child is TableRow)\r
35                                 {\r
36                                         Add(child);\r
37                                         return;\r
38                                 }\r
39                                 throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));\r
40                         }\r
41 \r
42                         public override void AddAt(int index, Control child)\r
43                         {\r
44                                 if(child is TableRow)\r
45                                 {\r
46                                         Add(child);\r
47                                         return;\r
48                                 }\r
49                                 throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));\r
50                         }\r
51                 }\r
52 \r
53                 public Table(): base(HtmlTextWriterTag.Table)\r
54                 {\r
55                 }\r
56 \r
57                 public virtual string BackImageUrl\r
58                 {\r
59                         get\r
60                         {\r
61                                 if(ControlStyleCreated)\r
62                                         return ((TableStyle)ControlStyle).BackImageUrl;\r
63                         }\r
64                         set\r
65                         {\r
66                                 ((TableStyle)ControlStyle).BackImageUrl = value;\r
67                         }\r
68                 }\r
69 \r
70                 public virtual int CellPadding\r
71                 {\r
72                         get\r
73                         {\r
74                                 if(ControlStyleCreated)\r
75                                         return ((TableStyle)ControlStyle).CellPadding;\r
76                         }\r
77                         set\r
78                         {\r
79                                 ((TableStyle)ControlStyle).CellPadding = value;\r
80                         }\r
81                 }\r
82 \r
83                 public virtual int CellSpacing\r
84                 {\r
85                         get\r
86                         {\r
87                                 if(ControlStyleCreated)\r
88                                         return ((TableStyle)ControlStyle).CellSpacing;\r
89                         }\r
90                         set\r
91                         {\r
92                                 ((TableStyle)ControlStyle).CellSpacing = value;\r
93                         }\r
94                 }\r
95 \r
96                 public virtual GridLines GridLines\r
97                 {\r
98                         get\r
99                         {\r
100                                 if(ControlStyleCreated)\r
101                                         return ((TableStyle)ControlStyle).GridLines;\r
102                         }\r
103                         set\r
104                         {\r
105                                 ((TableStyle)ControlStyle).GridLines = value;\r
106                         }\r
107                 }\r
108 \r
109                 public virtual HorizontalAlign HorizontalAlign\r
110                 {\r
111                         get\r
112                         {\r
113                                 if(ControlStyleCreated)\r
114                                         return ((TableStyle)ControlStyle).HorizontalAlign;\r
115                         }\r
116                         set\r
117                         {\r
118                                 ((TableStyle)ControlStyle).HorizontalAlign = value;\r
119                         }\r
120                 }\r
121 \r
122                 public virtual TableRowCollection Rows\r
123                 {\r
124                         get\r
125                         {\r
126                                 if(rows == null)\r
127                                 {\r
128                                         rows = new TableRowCollection(this);\r
129                                 }\r
130                                 return rows;\r
131                         }\r
132                 }\r
133 \r
134                 protected override void AddAttributesToRender(HtmlTextWriter writer)\r
135                 {\r
136                         AddAttributesToRender(writer);\r
137                         if(!BorderColor.IsEmpty)\r
138                         {\r
139                                 writer.AddAttribute(HtmlTextWriterAttribute.Bordercolor, ColorTranslator.ToHtml(BorderColor));\r
140                         }\r
141 \r
142                         Unit bw = BorderWidth;\r
143                         if(GridLines == GridLines.None)\r
144                         {\r
145                                 bw = Unit.Pixel(0);\r
146                         } else if(!bw.IsEmpty && bw.Type == UnitType.Pixel)\r
147                         {\r
148                                 bw = Unit.Pixel(1);\r
149                         }\r
150                         writer.AddAttribute(HtmlTextWriterAttribute.Border, ((int)bw.Value).ToString(NumberFormatInfo.InvariantInfo));\r
151                 }\r
152 \r
153                 protected override ControlCollection CreateControlCollection()\r
154                 {\r
155                         return new TableRowControlCollection(this);\r
156                 }\r
157 \r
158                 protected override Style CreateControlStyle()\r
159                 {\r
160                         return new TableStyle(ViewState);\r
161                 }\r
162 \r
163                 protected override void RenderContents(HtmlTextWriter writer)\r
164                 {\r
165                         foreach(object current in Rows)\r
166                         {\r
167                                 ((TableRow)current).RenderControl(writer);\r
168                         }\r
169                 }\r
170         }\r
171 }