1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
//------------------------------------------------------------------------------
// <copyright file="TableCell.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Util;
/// <devdoc>
/// <para>Interacts with the parser to build a <see cref='System.Web.UI.WebControls.TableCell'/> control.</para>
/// </devdoc>
public class TableCellControlBuilder : ControlBuilder {
/// <internalonly/>
/// <devdoc>
/// Specifies whether white space literals are allowed.
/// </devdoc>
public override bool AllowWhitespaceLiterals() {
return false;
}
}
/// <devdoc>
/// <para>Encapsulates a cell within a table.</para>
/// </devdoc>
[
Bindable(false),
ControlBuilderAttribute(typeof(TableCellControlBuilder)),
DefaultProperty("Text"),
ParseChildren(false),
ToolboxItem(false)
]
[Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + AssemblyRef.SystemDesign)]
public class TableCell : WebControl {
private bool _textSetByAddParsedSubObject = false;
/// <devdoc>
/// <para>
/// Initializes a new instance of the <see cref='System.Web.UI.WebControls.TableCell'/> class.
/// </para>
/// </devdoc>
public TableCell() : this(HtmlTextWriterTag.Td) {
}
/// <devdoc>
/// </devdoc>
internal TableCell(HtmlTextWriterTag tagKey) : base(tagKey) {
PreventAutoID();
}
/// <devdoc>
/// <para>
/// Contains a list of categories associated with the table header (read by screen readers). The categories can be any string values. The categories are rendered as a comma delimited list using the HTML axis attribute.
/// </para>
/// </devdoc>
[
DefaultValue(null),
TypeConverterAttribute(typeof(StringArrayConverter)),
WebCategory("Accessibility"),
WebSysDescription(SR.TableCell_AssociatedHeaderCellID)
]
public virtual string[] AssociatedHeaderCellID {
get {
object x = ViewState["AssociatedHeaderCellID"];
return (x != null) ? (string[])((string[])x).Clone() : new string[0];
}
set {
if (value != null) {
ViewState["AssociatedHeaderCellID"] = (string[])value.Clone();
}
else {
ViewState["AssociatedHeaderCellID"] = null;
}
}
}
/// <devdoc>
/// <para>Gets or sets the number
/// of columns this table cell stretches horizontally.</para>
/// </devdoc>
[
WebCategory("Appearance"),
DefaultValue(0),
WebSysDescription(SR.TableCell_ColumnSpan)
]
public virtual int ColumnSpan {
get {
object o = ViewState["ColumnSpan"];
return((o == null) ? 0 : (int)o);
}
set {
if (value < 0) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["ColumnSpan"] = value;
}
}
/// <devdoc>
/// <para>Gets or sets
/// the horizontal alignment of the content within the cell.</para>
/// </devdoc>
[
WebCategory("Layout"),
DefaultValue(HorizontalAlign.NotSet),
WebSysDescription(SR.TableItem_HorizontalAlign)
]
public virtual HorizontalAlign HorizontalAlign {
get {
if (ControlStyleCreated == false) {
return HorizontalAlign.NotSet;
}
return ((TableItemStyle)ControlStyle).HorizontalAlign;
}
set {
((TableItemStyle)ControlStyle).HorizontalAlign = value;
}
}
public override bool SupportsDisabledAttribute {
get {
return RenderingCompatibility < VersionUtil.Framework40;
}
}
/// <devdoc>
/// <para>Gets or sets the
/// number of rows this table cell stretches vertically.</para>
/// </devdoc>
[
WebCategory("Layout"),
DefaultValue(0),
WebSysDescription(SR.TableCell_RowSpan)
]
public virtual int RowSpan {
get {
object o = ViewState["RowSpan"];
return((o == null) ? 0 : (int)o);
}
set {
if (value < 0) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["RowSpan"] = value;
}
}
/// <devdoc>
/// <para>Gets
/// or sets the text contained in the cell.</para>
/// </devdoc>
[
Localizable(true),
WebCategory("Appearance"),
DefaultValue(""),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
WebSysDescription(SR.TableCell_Text)
]
public virtual string Text {
get {
object o = ViewState["Text"];
return((o == null) ? String.Empty : (string)o);
}
set {
if (HasControls()) {
Controls.Clear();
}
ViewState["Text"] = value;
}
}
/// <devdoc>
/// <para>Gets or sets the vertical alignment of the content within the cell.</para>
/// </devdoc>
[
WebCategory("Layout"),
DefaultValue(VerticalAlign.NotSet),
WebSysDescription(SR.TableItem_VerticalAlign)
]
public virtual VerticalAlign VerticalAlign {
get {
if (ControlStyleCreated == false) {
return VerticalAlign.NotSet;
}
return ((TableItemStyle)ControlStyle).VerticalAlign;
}
set {
((TableItemStyle)ControlStyle).VerticalAlign = value;
}
}
/// <devdoc>
/// <para>
/// Gets or sets
/// whether the cell content wraps within the cell.
/// </para>
/// </devdoc>
[
WebCategory("Layout"),
DefaultValue(true),
WebSysDescription(SR.TableCell_Wrap)
]
public virtual bool Wrap {
get {
if (ControlStyleCreated == false) {
return true;
}
return ((TableItemStyle)ControlStyle).Wrap;
}
set {
((TableItemStyle)ControlStyle).Wrap = value;
}
}
/// <internalonly/>
/// <devdoc>
/// <para>A protected method. Adds information about the column
/// span and row span to the list of attributes to render.</para>
/// </devdoc>
protected override void AddAttributesToRender(HtmlTextWriter writer) {
base.AddAttributesToRender(writer);
int span = ColumnSpan;
if (span > 0)
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, span.ToString(NumberFormatInfo.InvariantInfo));
span = RowSpan;
if (span > 0)
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, span.ToString(NumberFormatInfo.InvariantInfo));
string[] arr = AssociatedHeaderCellID;
if (arr.Length > 0) {
bool first = true;
StringBuilder builder = new StringBuilder();
Control namingContainer = NamingContainer;
foreach (string id in arr) {
TableHeaderCell headerCell = namingContainer.FindControl(id) as TableHeaderCell;
if (headerCell == null) {
throw new HttpException(SR.GetString(SR.TableCell_AssociatedHeaderCellNotFound, id));
}
if (first) {
first = false;
}
else {
// AssociatedHeaderCellID was seperated by "," instead of " ". (DevDiv Bugs 159670)
builder.Append(" ");
}
builder.Append(headerCell.ClientID);
}
string val = builder.ToString();
if (!String.IsNullOrEmpty(val)) {
writer.AddAttribute(HtmlTextWriterAttribute.Headers, val);
}
}
}
/// <devdoc>
/// </devdoc>
protected override void AddParsedSubObject(object obj) {
if (HasControls()) {
base.AddParsedSubObject(obj);
}
else {
if (obj is LiteralControl) {
// If we have multiple LiteralControls added here (as would happen if there were a code block
// at design time) we don't want to overwrite Text with the last LiteralControl's Text. Just
// concatenate their content. However, if Text was set by the property or was in ViewState,
// we want to overwrite it.
if (_textSetByAddParsedSubObject) {
Text += ((LiteralControl)obj).Text;
}
else {
Text = ((LiteralControl)obj).Text;
}
_textSetByAddParsedSubObject = true;
}
else {
string currentText = Text;
if (currentText.Length != 0) {
Text = String.Empty;
base.AddParsedSubObject(new LiteralControl(currentText));
}
base.AddParsedSubObject(obj);
}
}
}
/// <internalonly/>
/// <devdoc>
/// <para>A protected
/// method. Creates a table item control
/// style.</para>
/// </devdoc>
protected override Style CreateControlStyle() {
return new TableItemStyle(ViewState);
}
/// <internalonly/>
/// <devdoc>
/// <para>A protected method.</para>
/// </devdoc>
protected internal override void RenderContents(HtmlTextWriter writer) {
// We can't use HasControls() here, because we may have a compiled render method (ASURT 94127)
if (HasRenderingData()) {
base.RenderContents(writer);
}
else {
writer.Write(Text);
}
}
}
}
|