New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlTableRow.cs
1 //
2 // System.Web.UI.HtmlControls.HtmlTableRow.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.Security.Permissions;
31
32 namespace System.Web.UI.HtmlControls {
33
34         // CAS
35         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37         // attributes
38         [ParseChildren (true, "Cells")] 
39         public class HtmlTableRow : HtmlContainerControl {
40
41                 private HtmlTableCellCollection _cells;
42
43
44                 public HtmlTableRow ()
45                         : base ("tr")
46                 {
47                 }
48
49
50                 [DefaultValue ("")]
51                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
52                 [WebSysDescription("")]
53                 [WebCategory("Layout")]
54                 public string Align {
55                         get {
56                                 string s = Attributes ["align"];
57                                 return (s == null) ? String.Empty : s;
58                         }
59                         set {
60                                 if (value == null)
61                                         Attributes.Remove ("align");
62                                 else
63                                         Attributes ["align"] = value;
64                         }
65                 }
66
67                 [DefaultValue ("")]
68                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
69                 [WebSysDescription("")]
70                 [WebCategory("Appearance")]
71                 public string BgColor {
72                         get {
73                                 string s = Attributes ["bgcolor"];
74                                 return (s == null) ? String.Empty : s;
75                         }
76                         set {
77                                 if (value == null)
78                                         Attributes.Remove ("bgcolor");
79                                 else
80                                         Attributes ["bgcolor"] = value;
81                         }
82                 }
83
84                 [DefaultValue ("")]
85                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
86                 [WebSysDescription("")]
87                 [WebCategory("Appearance")]
88                 public string BorderColor {
89                         get {
90                                 string s = Attributes ["bordercolor"];
91                                 return (s == null) ? String.Empty : s;
92                         }
93                         set {
94                                 if (value == null)
95                                         Attributes.Remove ("bordercolor");
96                                 else
97                                         Attributes ["bordercolor"] = value;
98                         }
99                 }
100
101                 [Browsable (false)]
102                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
103                 public virtual HtmlTableCellCollection Cells {
104                         get {
105                                 if (_cells == null)
106                                         _cells = new HtmlTableCellCollection (this);
107                                 return _cells;
108                         }
109                 }
110
111                 [DefaultValue ("")]
112                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
113                 [WebSysDescription("")]
114                 [WebCategory("Layout")]
115                 public string Height {
116                         get {
117                                 string s = Attributes ["height"];
118                                 return (s == null) ? String.Empty : s;
119                         }
120                         set {
121                                 if (value == null)
122                                         Attributes.Remove ("height");
123                                 else
124                                         Attributes ["height"] = value;
125                         }
126                 }
127
128                 public override string InnerHtml {
129                         get { throw new NotSupportedException (); }
130                         set { throw new NotSupportedException (); }
131                 }
132
133                 public override string InnerText {
134                         get { throw new NotSupportedException (); }
135                         set { throw new NotSupportedException (); }
136                 }
137
138                 [DefaultValue ("")]
139                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
140                 [WebSysDescription("")]
141                 [WebCategory("Layout")]
142                 public string VAlign {
143                         get {
144                                 string s = Attributes ["valign"];
145                                 return (s == null) ? String.Empty : s;
146                         }
147                         set {
148                                 if (value == null)
149                                         Attributes.Remove ("valign");
150                                 else
151                                         Attributes ["valign"] = value;
152                         }
153                 }
154
155                 private int Count {
156                         get { return (_cells == null) ? 0 : _cells.Count; }
157                 }
158
159
160                 protected override ControlCollection CreateControlCollection ()
161                 {
162                         return new HtmlTableCellControlCollection (this);
163                 }
164
165 #if NET_2_0
166                 protected internal
167 #else           
168                 protected
169 #endif          
170                 override void RenderChildren (HtmlTextWriter writer)
171                 {
172                         if (HasControls ()) {
173                                 writer.Indent++;
174                                 base.RenderChildren (writer);
175                                 writer.Indent--;
176                                 writer.WriteLine ();
177                         }
178                 }
179
180                 protected override void RenderEndTag (HtmlTextWriter writer)
181                 {
182                         if (Count == 0)
183                                 writer.WriteLine ();
184                         writer.WriteEndTag (TagName);
185                         if (writer.Indent == 0)
186                                 writer.WriteLine ();
187                 }
188
189
190                 protected class HtmlTableCellControlCollection : ControlCollection {
191
192                         internal HtmlTableCellControlCollection (HtmlTableRow owner)
193                                 : base (owner)
194                         {
195                         }
196
197                         public override void Add (Control child)
198                         {
199                                 if (child == null)
200                                         throw new NullReferenceException ("null");
201                                 if (!(child is HtmlTableCell))
202                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
203
204                                 base.Add (child);
205                         }
206
207                         public override void AddAt (int index, Control child)
208                         {
209                                 if (child == null)
210                                         throw new NullReferenceException ("null");
211                                 if (!(child is HtmlTableCell))
212                                         throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
213
214                                 base.AddAt (index, child);
215                         }
216                 }
217         }
218 }