2 // System.Web.UI.WebControls.TableCell.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.ComponentModel;
30 using System.Globalization;
31 using System.Security.Permissions;
34 namespace System.Web.UI.WebControls {
37 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [ControlBuilder (typeof (TableCellControlBuilder))]
41 [DefaultProperty ("Text")]
42 [ParseChildren (false)]
46 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
48 [PersistChildren (true)]
50 public class TableCell : WebControl {
53 : base (HtmlTextWriterTag.Td)
58 // FIXME: is there a clean way to change the tag's name without using a ctor ?
59 // if not then this truly limits the usefulness of inheritance
60 internal TableCell (HtmlTextWriterTag tag)
69 [TypeConverter (typeof (StringArrayConverter))]
70 public virtual string[] AssociatedHeaderCellID {
72 object o = ViewState ["AssociatedHeaderCellID"];
73 return (o == null) ? new string[0] : (string[]) o;
77 ViewState.Remove ("AssociatedHeaderCellID");
79 ViewState ["AssociatedHeaderCellID"] = value;
88 [WebSysDescription ("")]
89 [WebCategory ("Appearance")]
90 public virtual int ColumnSpan {
92 object o = ViewState ["ColumnSpan"];
93 return (o == null) ? 0 : (int) o;
96 // LAMESPEC: undocumented (but like Table.CellPadding)
98 throw new ArgumentOutOfRangeException ("< 0");
99 ViewState ["ColumnSpan"] = value;
106 [DefaultValue (HorizontalAlign.NotSet)]
107 [WebSysDescription ("")]
108 [WebCategory ("Layout")]
109 public virtual HorizontalAlign HorizontalAlign {
111 if (!ControlStyleCreated)
112 return HorizontalAlign.NotSet; // default value
113 return TableItemStyle.HorizontalAlign;
115 set { TableItemStyle.HorizontalAlign = value; }
122 [WebSysDescription ("")]
123 [WebCategory ("Layout")]
124 public virtual int RowSpan {
126 object o = ViewState ["RowSpan"];
127 return (o == null) ? 0 : (int) o;
130 // LAMESPEC: undocumented (but like Table.CellPadding)
132 throw new ArgumentOutOfRangeException ("< 0");
133 ViewState ["RowSpan"] = value;
139 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
144 [WebSysDescription ("")]
145 [WebCategory ("Appearance")]
146 public virtual string Text {
148 object o = ViewState ["Text"];
149 return (o == null) ? String.Empty : (string) o;
153 ViewState.Remove ("Text");
155 ViewState ["Text"] = value;
165 [DefaultValue (VerticalAlign.NotSet)]
166 [WebSysDescription ("")]
167 [WebCategory ("Layout")]
168 public virtual VerticalAlign VerticalAlign {
170 if (!ControlStyleCreated)
171 return VerticalAlign.NotSet; // default value
172 return TableItemStyle.VerticalAlign;
174 set { TableItemStyle.VerticalAlign = value; }
180 [DefaultValue (true)]
181 [WebSysDescription ("")]
182 [WebCategory ("Layout")]
183 public virtual bool Wrap {
185 if (!ControlStyleCreated)
186 return true; // default value
187 return TableItemStyle.Wrap;
189 set { TableItemStyle.Wrap = value; }
192 private TableItemStyle TableItemStyle {
193 get { return (ControlStyle as TableItemStyle); }
197 protected override void AddAttributesToRender (HtmlTextWriter writer)
199 base.AddAttributesToRender (writer);
205 writer.AddAttribute (HtmlTextWriterAttribute.Colspan, i.ToString (CultureInfo.InvariantCulture), false);
209 writer.AddAttribute (HtmlTextWriterAttribute.Rowspan, i.ToString (CultureInfo.InvariantCulture), false);
211 string[] ahci = AssociatedHeaderCellID;
212 if (ahci.Length > 1) {
213 StringBuilder sb = new StringBuilder ();
214 for (i = 0; i < ahci.Length - 1; i++) {
215 sb.Append (ahci [i]);
218 sb.Append (ahci.Length - 1);
219 writer.AddAttribute (HtmlTextWriterAttribute.Headers, sb.ToString ());
220 } else if (ahci.Length == 1) {
221 // most common case (without a StringBuilder)
222 writer.AddAttribute (HtmlTextWriterAttribute.Headers, ahci [0]);
227 protected override void AddParsedSubObject (object obj)
229 if (HasControls ()) {
230 base.AddParsedSubObject (obj);
234 LiteralControl lc = (obj as LiteralControl);
238 Controls.Add (new LiteralControl (s));
239 // remove from viewstate
242 base.AddParsedSubObject(obj);
244 // this will clear any existing controls
249 protected override Style CreateControlStyle ()
251 return new TableItemStyle (ViewState);
259 override void RenderContents (HtmlTextWriter writer)
261 if (HasControls () || HasRenderMethodDelegate ())
262 base.RenderContents (writer);