HtmlTable.cs 6.3 KB

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