1 // 2 // System.Web.UI.HtmlControls.HtmlTable.cs 3 // 4 // Author: 5 // Sebastien Pouliot <sebastien@ximian.com> 6 // 7 // Copyright (C) 2005-2010 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 using System.Web.Util; 33 34 namespace System.Web.UI.HtmlControls 35 { 36 // CAS 37 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] 38 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] 39 // attributes 40 [ParseChildren (true, "Rows")] 41 public class HtmlTable : HtmlContainerControl 42 { 43 HtmlTableRowCollection _rows; 44 HtmlTable()45 public HtmlTable () 46 : base ("table") 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 (-1)] 85 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 86 [WebSysDescription("")] 87 [WebCategory("Appearance")] 88 public int Border { 89 get { 90 string s = Attributes ["border"]; 91 return (s == null) ? -1 : Convert.ToInt32 (s); 92 } 93 set { 94 if (value == -1) 95 Attributes.Remove ("border"); 96 else 97 Attributes ["border"] = value.ToString (Helpers.InvariantCulture); 98 } 99 } 100 101 [DefaultValue ("")] 102 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 103 [WebSysDescription("")] 104 [WebCategory("Appearance")] 105 public string BorderColor { 106 get { 107 string s = Attributes ["bordercolor"]; 108 return (s == null) ? String.Empty : s; 109 } 110 set { 111 if (value == null) 112 Attributes.Remove ("bordercolor"); 113 else 114 Attributes ["bordercolor"] = value; 115 } 116 } 117 118 [DefaultValue ("")] 119 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 120 [WebSysDescription("")] 121 [WebCategory("Appearance")] 122 public int CellPadding { 123 get { 124 string s = Attributes ["cellpadding"]; 125 return (s == null) ? -1 : Convert.ToInt32 (s); 126 } 127 set { 128 if (value == -1) 129 Attributes.Remove ("cellpadding"); 130 else 131 Attributes ["cellpadding"] = value.ToString (Helpers.InvariantCulture); 132 } 133 } 134 135 [DefaultValue ("")] 136 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 137 [WebSysDescription("")] 138 [WebCategory("Appearance")] 139 public int CellSpacing { 140 get { 141 string s = Attributes ["cellspacing"]; 142 return (s == null) ? -1 : Convert.ToInt32 (s); 143 } 144 set { 145 if (value == -1) 146 Attributes.Remove ("cellspacing"); 147 else 148 Attributes ["cellspacing"] = value.ToString (Helpers.InvariantCulture); 149 } 150 } 151 152 [DefaultValue ("")] 153 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 154 [WebSysDescription("")] 155 [WebCategory("Layout")] 156 public string Height { 157 get { 158 string s = Attributes ["height"]; 159 return (s == null) ? String.Empty : s; 160 } 161 set { 162 if (value == null) 163 Attributes.Remove ("height"); 164 else 165 Attributes ["height"] = value; 166 } 167 } 168 169 public override string InnerHtml { 170 get { throw new NotSupportedException (); } 171 set { throw new NotSupportedException (); } 172 } 173 174 public override string InnerText { 175 get { throw new NotSupportedException (); } 176 set { throw new NotSupportedException (); } 177 } 178 179 [Browsable (false)] 180 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 181 public virtual HtmlTableRowCollection Rows { 182 get { 183 if (_rows == null) 184 _rows = new HtmlTableRowCollection (this); 185 return _rows; 186 } 187 } 188 189 [DefaultValue ("")] 190 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] 191 [WebSysDescription("")] 192 [WebCategory("Layout")] 193 public string Width { 194 get { 195 string s = Attributes ["width"]; 196 return (s == null) ? String.Empty : s; 197 } 198 set { 199 if (value == null) 200 Attributes.Remove ("width"); 201 else 202 Attributes ["width"] = value; 203 } 204 } 205 206 CreateControlCollection()207 protected override ControlCollection CreateControlCollection () 208 { 209 return new HtmlTableRowControlCollection (this); 210 } 211 RenderChildren(HtmlTextWriter writer)212 protected internal override void RenderChildren (HtmlTextWriter writer) 213 { 214 if (HasControls ()) { 215 writer.Indent++; 216 base.RenderChildren (writer); 217 writer.Indent--; 218 writer.WriteLine (); 219 } 220 } 221 RenderEndTag(HtmlTextWriter writer)222 protected override void RenderEndTag (HtmlTextWriter writer) 223 { 224 writer.WriteLine (); 225 writer.WriteEndTag (TagName); 226 writer.WriteLine (); 227 } 228 229 230 protected class HtmlTableRowControlCollection : ControlCollection { 231 HtmlTableRowControlCollection(HtmlTable owner)232 internal HtmlTableRowControlCollection (HtmlTable owner) 233 : base (owner) 234 { 235 } 236 Add(Control child)237 public override void Add (Control child) 238 { 239 if (child == null) 240 throw new NullReferenceException ("null"); 241 if (!(child is HtmlTableRow)) 242 throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance.")); 243 244 base.Add (child); 245 } 246 AddAt(int index, Control child)247 public override void AddAt (int index, Control child) 248 { 249 if (child == null) 250 throw new NullReferenceException ("null"); 251 if (!(child is HtmlTableRow)) 252 throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance.")); 253 254 base.AddAt (index, child); 255 } 256 } 257 } 258 } 259