2
0

HtmlTable.cs 6.8 KB

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