HtmlTable.cs 6.8 KB

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