HtmlTable.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // System.Web.UI.HtmlControls.HtmlTable.cs
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  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. using System.ComponentModel;
  29. using System.Globalization;
  30. using System.Security.Permissions;
  31. using System.Web.Util;
  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, "Rows")]
  39. public class HtmlTable : HtmlContainerControl
  40. {
  41. HtmlTableRowCollection _rows;
  42. public HtmlTable ()
  43. : base ("table")
  44. {
  45. }
  46. [DefaultValue ("")]
  47. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  48. [WebSysDescription("")]
  49. [WebCategory("Layout")]
  50. public string Align {
  51. get {
  52. string s = Attributes ["align"];
  53. return (s == null) ? String.Empty : s;
  54. }
  55. set {
  56. if (value == null)
  57. Attributes.Remove ("align");
  58. else
  59. Attributes ["align"] = value;
  60. }
  61. }
  62. [DefaultValue ("")]
  63. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  64. [WebSysDescription("")]
  65. [WebCategory("Appearance")]
  66. public string BgColor {
  67. get {
  68. string s = Attributes ["bgcolor"];
  69. return (s == null) ? String.Empty : s;
  70. }
  71. set {
  72. if (value == null)
  73. Attributes.Remove ("bgcolor");
  74. else
  75. Attributes ["bgcolor"] = value;
  76. }
  77. }
  78. [DefaultValue (-1)]
  79. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  80. [WebSysDescription("")]
  81. [WebCategory("Appearance")]
  82. public int Border {
  83. get {
  84. string s = Attributes ["border"];
  85. return (s == null) ? -1 : Convert.ToInt32 (s);
  86. }
  87. set {
  88. if (value == -1)
  89. Attributes.Remove ("border");
  90. else
  91. Attributes ["border"] = value.ToString (Helpers.InvariantCulture);
  92. }
  93. }
  94. [DefaultValue ("")]
  95. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  96. [WebSysDescription("")]
  97. [WebCategory("Appearance")]
  98. public string BorderColor {
  99. get {
  100. string s = Attributes ["bordercolor"];
  101. return (s == null) ? String.Empty : s;
  102. }
  103. set {
  104. if (value == null)
  105. Attributes.Remove ("bordercolor");
  106. else
  107. Attributes ["bordercolor"] = value;
  108. }
  109. }
  110. [DefaultValue ("")]
  111. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  112. [WebSysDescription("")]
  113. [WebCategory("Appearance")]
  114. public int CellPadding {
  115. get {
  116. string s = Attributes ["cellpadding"];
  117. return (s == null) ? -1 : Convert.ToInt32 (s);
  118. }
  119. set {
  120. if (value == -1)
  121. Attributes.Remove ("cellpadding");
  122. else
  123. Attributes ["cellpadding"] = value.ToString (Helpers.InvariantCulture);
  124. }
  125. }
  126. [DefaultValue ("")]
  127. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  128. [WebSysDescription("")]
  129. [WebCategory("Appearance")]
  130. public int CellSpacing {
  131. get {
  132. string s = Attributes ["cellspacing"];
  133. return (s == null) ? -1 : Convert.ToInt32 (s);
  134. }
  135. set {
  136. if (value == -1)
  137. Attributes.Remove ("cellspacing");
  138. else
  139. Attributes ["cellspacing"] = value.ToString (Helpers.InvariantCulture);
  140. }
  141. }
  142. [DefaultValue ("")]
  143. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  144. [WebSysDescription("")]
  145. [WebCategory("Layout")]
  146. public string Height {
  147. get {
  148. string s = Attributes ["height"];
  149. return (s == null) ? String.Empty : s;
  150. }
  151. set {
  152. if (value == null)
  153. Attributes.Remove ("height");
  154. else
  155. Attributes ["height"] = value;
  156. }
  157. }
  158. public override string InnerHtml {
  159. get { throw new NotSupportedException (); }
  160. set { throw new NotSupportedException (); }
  161. }
  162. public override string InnerText {
  163. get { throw new NotSupportedException (); }
  164. set { throw new NotSupportedException (); }
  165. }
  166. [Browsable (false)]
  167. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  168. public virtual HtmlTableRowCollection Rows {
  169. get {
  170. if (_rows == null)
  171. _rows = new HtmlTableRowCollection (this);
  172. return _rows;
  173. }
  174. }
  175. [DefaultValue ("")]
  176. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  177. [WebSysDescription("")]
  178. [WebCategory("Layout")]
  179. public string Width {
  180. get {
  181. string s = Attributes ["width"];
  182. return (s == null) ? String.Empty : s;
  183. }
  184. set {
  185. if (value == null)
  186. Attributes.Remove ("width");
  187. else
  188. Attributes ["width"] = value;
  189. }
  190. }
  191. protected override ControlCollection CreateControlCollection ()
  192. {
  193. return new HtmlTableRowControlCollection (this);
  194. }
  195. protected internal override void RenderChildren (HtmlTextWriter writer)
  196. {
  197. if (HasControls ()) {
  198. writer.Indent++;
  199. base.RenderChildren (writer);
  200. writer.Indent--;
  201. writer.WriteLine ();
  202. }
  203. }
  204. protected override void RenderEndTag (HtmlTextWriter writer)
  205. {
  206. writer.WriteLine ();
  207. writer.WriteEndTag (TagName);
  208. writer.WriteLine ();
  209. }
  210. protected class HtmlTableRowControlCollection : ControlCollection {
  211. internal HtmlTableRowControlCollection (HtmlTable owner)
  212. : base (owner)
  213. {
  214. }
  215. public override void Add (Control child)
  216. {
  217. if (child == null)
  218. throw new NullReferenceException ("null");
  219. if (!(child is HtmlTableRow))
  220. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
  221. base.Add (child);
  222. }
  223. public override void AddAt (int index, Control child)
  224. {
  225. if (child == null)
  226. throw new NullReferenceException ("null");
  227. if (!(child is HtmlTableRow))
  228. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableRow instance."));
  229. base.AddAt (index, child);
  230. }
  231. }
  232. }
  233. }