HtmlTable.cs 7.0 KB

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