HtmlTableRow.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // System.Web.UI.HtmlControls.HtmlTableRow.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.Security.Permissions;
  30. namespace System.Web.UI.HtmlControls {
  31. // CAS
  32. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  33. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  34. // attributes
  35. #if NET_2_0
  36. [ParseChildren (true, "Cells", ChildControlType = typeof(Control))]
  37. #else
  38. [ParseChildren (true, "Cells")]
  39. #endif
  40. public class HtmlTableRow : HtmlContainerControl {
  41. private HtmlTableCellCollection _cells;
  42. public HtmlTableRow ()
  43. : base ("tr")
  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 ("")]
  79. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  80. [WebSysDescription("")]
  81. [WebCategory("Appearance")]
  82. public string BorderColor {
  83. get {
  84. string s = Attributes ["bordercolor"];
  85. return (s == null) ? String.Empty : s;
  86. }
  87. set {
  88. if (value == null)
  89. Attributes.Remove ("bordercolor");
  90. else
  91. Attributes ["bordercolor"] = value;
  92. }
  93. }
  94. [Browsable (false)]
  95. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  96. #if NET_2_0
  97. public virtual
  98. #else
  99. public
  100. #endif
  101. HtmlTableCellCollection Cells {
  102. get {
  103. if (_cells == null)
  104. _cells = new HtmlTableCellCollection (this);
  105. return _cells;
  106. }
  107. }
  108. [DefaultValue ("")]
  109. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  110. [WebSysDescription("")]
  111. [WebCategory("Layout")]
  112. public string Height {
  113. get {
  114. string s = Attributes ["height"];
  115. return (s == null) ? String.Empty : s;
  116. }
  117. set {
  118. if (value == null)
  119. Attributes.Remove ("height");
  120. else
  121. Attributes ["height"] = value;
  122. }
  123. }
  124. public override string InnerHtml {
  125. get { throw new NotSupportedException (); }
  126. set { throw new NotSupportedException (); }
  127. }
  128. public override string InnerText {
  129. get { throw new NotSupportedException (); }
  130. set { throw new NotSupportedException (); }
  131. }
  132. [DefaultValue ("")]
  133. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  134. [WebSysDescription("")]
  135. [WebCategory("Layout")]
  136. public string VAlign {
  137. get {
  138. string s = Attributes ["valign"];
  139. return (s == null) ? String.Empty : s;
  140. }
  141. set {
  142. if (value == null)
  143. Attributes.Remove ("valign");
  144. else
  145. Attributes ["valign"] = value;
  146. }
  147. }
  148. private int Count {
  149. get { return (_cells == null) ? 0 : _cells.Count; }
  150. }
  151. protected override ControlCollection CreateControlCollection ()
  152. {
  153. return new HtmlTableCellControlCollection (this);
  154. }
  155. #if NET_2_0
  156. protected internal
  157. #else
  158. protected
  159. #endif
  160. override void RenderChildren (HtmlTextWriter writer)
  161. {
  162. int n = Count;
  163. if (n > 0) {
  164. writer.Indent++;
  165. for (int i=0; i < n; i++) {
  166. writer.WriteLine ();
  167. _cells [i].RenderControl (writer);
  168. }
  169. writer.Indent--;
  170. writer.WriteLine ();
  171. }
  172. }
  173. protected override void RenderEndTag (HtmlTextWriter writer)
  174. {
  175. if (Count == 0)
  176. writer.WriteLine ();
  177. writer.WriteEndTag (TagName);
  178. if (writer.Indent == 0)
  179. writer.WriteLine ();
  180. }
  181. protected class HtmlTableCellControlCollection : ControlCollection {
  182. internal HtmlTableCellControlCollection (HtmlTableRow owner)
  183. : base (owner)
  184. {
  185. }
  186. public override void Add (Control child)
  187. {
  188. if (child == null)
  189. throw new NullReferenceException ("null");
  190. if (!(child is HtmlTableCell))
  191. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
  192. base.Add (child);
  193. }
  194. public override void AddAt (int index, Control child)
  195. {
  196. if (child == null)
  197. throw new NullReferenceException ("null");
  198. if (!(child is HtmlTableCell))
  199. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
  200. base.AddAt (index, child);
  201. }
  202. }
  203. }
  204. }