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)
57 // FIXME: is there a clean way to change the tag's name without using a ctor ?
58 // if not then this truly limits the usefulness of inheritance
59 internal TableCell (HtmlTextWriterTag tag)
67 [TypeConverter (typeof (StringArrayConverter))]
68 public virtual string[] AssociatedHeaderCellID {
70 object o = ViewState ["AssociatedHeaderCellID"];
71 return (o == null) ? new string[0] : (string[]) o;
75 ViewState.Remove ("AssociatedHeaderCellID");
77 ViewState ["AssociatedHeaderCellID"] = value;
86 [WebSysDescription ("")]
87 [WebCategory ("Appearance")]
88 public virtual int ColumnSpan {
90 object o = ViewState ["ColumnSpan"];
91 return (o == null) ? 0 : (int) o;
94 // LAMESPEC: undocumented (but like Table.CellPadding)
96 throw new ArgumentOutOfRangeException ("< 0");
97 ViewState ["ColumnSpan"] = value;
104 [DefaultValue (HorizontalAlign.NotSet)]
105 [WebSysDescription ("")]
106 [WebCategory ("Layout")]
107 public virtual HorizontalAlign HorizontalAlign {
109 if (!ControlStyleCreated)
110 return HorizontalAlign.NotSet; // default value
111 return TableItemStyle.HorizontalAlign;
113 set { TableItemStyle.HorizontalAlign = value; }
120 [WebSysDescription ("")]
121 [WebCategory ("Layout")]
122 public virtual int RowSpan {
124 object o = ViewState ["RowSpan"];
125 return (o == null) ? 0 : (int) o;
128 // LAMESPEC: undocumented (but like Table.CellPadding)
130 throw new ArgumentOutOfRangeException ("< 0");
131 ViewState ["RowSpan"] = value;
137 [PersistenceMode (PersistenceMode.EncodedInnerDefaultProperty)]
142 [WebSysDescription ("")]
143 [WebCategory ("Appearance")]
144 public virtual string Text {
146 object o = ViewState ["Text"];
147 return (o == null) ? String.Empty : (string) o;
151 ViewState.Remove ("Text");
153 ViewState ["Text"] = value;
163 [DefaultValue (VerticalAlign.NotSet)]
164 [WebSysDescription ("")]
165 [WebCategory ("Layout")]
166 public virtual VerticalAlign VerticalAlign {
168 if (!ControlStyleCreated)
169 return VerticalAlign.NotSet; // default value
170 return TableItemStyle.VerticalAlign;
172 set { TableItemStyle.VerticalAlign = value; }
178 [DefaultValue (true)]
179 [WebSysDescription ("")]
180 [WebCategory ("Layout")]
181 public virtual bool Wrap {
183 if (!ControlStyleCreated)
184 return true; // default value
185 return TableItemStyle.Wrap;
187 set { TableItemStyle.Wrap = value; }
190 private TableItemStyle TableItemStyle {
191 get { return (ControlStyle as TableItemStyle); }
195 protected override void AddAttributesToRender (HtmlTextWriter writer)
197 base.AddAttributesToRender (writer);
203 writer.AddAttribute (HtmlTextWriterAttribute.Colspan, i.ToString (CultureInfo.InvariantCulture));
207 writer.AddAttribute (HtmlTextWriterAttribute.Rowspan, i.ToString (CultureInfo.InvariantCulture));
209 string[] ahci = AssociatedHeaderCellID;
210 if (ahci.Length > 1) {
211 StringBuilder sb = new StringBuilder ();
212 for (i = 0; i < ahci.Length - 1; i++) {
213 sb.Append (ahci [i]);
216 sb.Append (ahci.Length - 1);
217 writer.AddAttribute (HtmlTextWriterAttribute.Headers, sb.ToString ());
218 } else if (ahci.Length == 1) {
219 // most common case (without a StringBuilder)
220 writer.AddAttribute (HtmlTextWriterAttribute.Headers, ahci [0]);
225 protected override void AddParsedSubObject (object obj)
227 if (HasControls ()) {
228 base.AddParsedSubObject (obj);
232 LiteralControl lc = (obj as LiteralControl);
236 Controls.Add (new LiteralControl (s));
237 // remove from viewstate
240 base.AddParsedSubObject(obj);
242 // this will clear any existing controls
247 protected override Style CreateControlStyle ()
249 return new TableItemStyle (ViewState);
257 override void RenderContents (HtmlTextWriter writer)
259 object o = ViewState ["Text"];
261 writer.Write (o as string);
263 base.RenderContents (writer);