TableCell.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // System.Web.UI.WebControls.TableCell.cs
  3. //
  4. // Authors:
  5. // Gaurav Vaish ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Gaurav Vaish (2002)
  9. // (C) 2003 Andreas Nahr
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Globalization;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.ComponentModel;
  36. namespace System.Web.UI.WebControls
  37. {
  38. [DefaultProperty("Text")]
  39. [ToolboxItem(false)]
  40. [ControlBuilder(typeof(TableCellControlBuilder))]
  41. [ParseChildren(false)]
  42. [PersistChildren(true)]
  43. public class TableCell: WebControl
  44. {
  45. public TableCell () : base (HtmlTextWriterTag.Td)
  46. {
  47. PreventAutoID ();
  48. }
  49. internal TableCell (HtmlTextWriterTag tag) : base (tag)
  50. {
  51. PreventAutoID ();
  52. }
  53. [DefaultValue (0), Bindable (true), WebCategory ("Appearance")]
  54. [WebSysDescription ("The number of columns spanned by this cell.")]
  55. public virtual int ColumnSpan
  56. {
  57. get {
  58. object o = ViewState ["ColumnSpan"];
  59. return (o == null) ? 0 : (int) o;
  60. }
  61. set {
  62. if (value < 0)
  63. throw new ArgumentOutOfRangeException ("value", "ColumnSpan value has to be >= 0.");
  64. ViewState ["ColumnSpan"] = value;
  65. }
  66. }
  67. [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
  68. [WebSysDescription ("The number of rows spanned by this cell.")]
  69. public virtual int RowSpan
  70. {
  71. get {
  72. object o = ViewState ["RowSpan"];
  73. return (o == null) ? 0 : (int) o;
  74. }
  75. set {
  76. if (value < 0)
  77. throw new ArgumentOutOfRangeException ("value", "RowSpan value has to be >= 0.");
  78. ViewState ["RowSpan"] = value;
  79. }
  80. }
  81. [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
  82. [WebSysDescription ("The text that is shown in this cell.")]
  83. public virtual string Text
  84. {
  85. get {
  86. object o = ViewState ["Text"];
  87. return (o == null) ? String.Empty : (string) o;
  88. }
  89. set {
  90. if (HasControls ())
  91. Controls.Clear ();
  92. ViewState ["Text"] = value;
  93. }
  94. }
  95. [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
  96. [WebSysDescription ("The horizontal alignment for this cell.")]
  97. public virtual HorizontalAlign HorizontalAlign
  98. {
  99. get {
  100. if (ControlStyleCreated)
  101. return ((TableItemStyle) ControlStyle).HorizontalAlign;
  102. return HorizontalAlign.NotSet;
  103. }
  104. set { ((TableItemStyle) ControlStyle).HorizontalAlign = value; }
  105. }
  106. [DefaultValue (typeof (VerticalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
  107. [WebSysDescription ("The horizontal alignment for this cell.")]
  108. public virtual VerticalAlign VerticalAlign
  109. {
  110. get {
  111. if (ControlStyleCreated)
  112. return ((TableItemStyle) ControlStyle).VerticalAlign;
  113. return VerticalAlign.NotSet;
  114. }
  115. set { ((TableItemStyle) ControlStyle).VerticalAlign = value; }
  116. }
  117. [DefaultValue (true), Bindable (true), WebCategory ("Layout")]
  118. [WebSysDescription ("Determines if the text in the cell should be wraped at line-end.")]
  119. public virtual bool Wrap
  120. {
  121. get {
  122. if (ControlStyleCreated)
  123. return ((TableItemStyle) ControlStyle).Wrap;
  124. return true;
  125. }
  126. set { ((TableItemStyle) ControlStyle).Wrap = value; }
  127. }
  128. protected override void AddAttributesToRender (HtmlTextWriter writer)
  129. {
  130. base.AddAttributesToRender (writer);
  131. if (ColumnSpan > 0)
  132. writer.AddAttribute (HtmlTextWriterAttribute.Colspan,
  133. ColumnSpan.ToString (NumberFormatInfo.InvariantInfo));
  134. if (RowSpan > 0)
  135. writer.AddAttribute (HtmlTextWriterAttribute.Rowspan,
  136. RowSpan.ToString (NumberFormatInfo.InvariantInfo));
  137. }
  138. protected override void AddParsedSubObject (object obj)
  139. {
  140. if (HasControls ()){
  141. base.AddParsedSubObject (obj);
  142. return;
  143. }
  144. if (obj is LiteralControl){
  145. Text = ((LiteralControl) obj).Text;
  146. return;
  147. }
  148. string text = Text;
  149. if (text.Length > 0){
  150. Text = String.Empty;
  151. base.AddParsedSubObject (new LiteralControl (text));
  152. }
  153. base.AddParsedSubObject (obj);
  154. }
  155. protected override Style CreateControlStyle ()
  156. {
  157. return new TableItemStyle (ViewState);
  158. }
  159. protected override void RenderContents (HtmlTextWriter writer)
  160. {
  161. if (HasControls ())
  162. base.RenderContents (writer);
  163. else
  164. writer.Write (Text);
  165. }
  166. }
  167. }