Almost eliminate wrong use of Constants.WsaNamespace.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableCell.cs
1 //
2 // System.Web.UI.WebControls.TableCell.cs
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
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
29 using System.ComponentModel;
30 using System.Globalization;
31 using System.Security.Permissions;
32 using System.Text;
33 using System.Web.Util;
34
35 namespace System.Web.UI.WebControls {
36
37         // CAS
38         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40         // attributes
41         [ControlBuilder (typeof (TableCellControlBuilder))]
42         [DefaultProperty ("Text")]
43         [ParseChildren (false)]
44         [ToolboxItem ("")]
45 #if NET_2_0
46         [Bindable (false)]
47         [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
48 #else
49         [PersistChildren (true)]
50 #endif
51         public class TableCell : WebControl {
52
53                 public TableCell ()
54                         : base (HtmlTextWriterTag.Td)
55                 {
56                         AutoID = false;
57                 }
58
59                 // FIXME: is there a clean way to change the tag's name without using a ctor ?
60                 // if not then this truly limits the usefulness of inheritance
61                 internal TableCell (HtmlTextWriterTag tag)
62                         : base (tag)
63                 {
64                         AutoID = false;
65                 }
66
67
68 #if NET_2_0
69                 [DefaultValue (null)]
70                 [TypeConverter (typeof (StringArrayConverter))]
71                 public virtual string[] AssociatedHeaderCellID {
72                         get {
73                                 object o = ViewState ["AssociatedHeaderCellID"];
74                                 return (o == null) ? new string[0] : (string[]) o;
75                         }
76                         set {
77                                 if (value == null)
78                                         ViewState.Remove ("AssociatedHeaderCellID");
79                                 else
80                                         ViewState ["AssociatedHeaderCellID"] = value;
81                         }
82                 }
83 #endif
84
85 #if ONLY_1_1
86                 [Bindable (true)]
87 #endif
88                 [DefaultValue (0)]
89                 [WebSysDescription ("")]
90                 [WebCategory ("Appearance")]
91                 public virtual int ColumnSpan {
92                         get {
93                                 object o = ViewState ["ColumnSpan"];
94                                 return (o == null) ? 0 : (int) o;
95                         }
96                         set {
97                                 // LAMESPEC: undocumented (but like Table.CellPadding)
98                                 if (value < 0)
99                                         throw new ArgumentOutOfRangeException ("< 0");
100                                 ViewState ["ColumnSpan"] = value;
101                         }
102                 }
103
104 #if ONLY_1_1
105                 [Bindable (true)]
106 #endif
107                 [DefaultValue (HorizontalAlign.NotSet)]
108                 [WebSysDescription ("")]
109                 [WebCategory ("Layout")]
110                 public virtual HorizontalAlign HorizontalAlign {
111                         get {
112                                 if (!ControlStyleCreated)
113                                         return HorizontalAlign.NotSet; // default value
114                                 return TableItemStyle.HorizontalAlign;
115                         }
116                         set { TableItemStyle.HorizontalAlign = value; }
117                 }
118
119 #if ONLY_1_1
120                 [Bindable (true)]
121 #endif
122                 [DefaultValue (0)]
123                 [WebSysDescription ("")]
124                 [WebCategory ("Layout")]
125                 public virtual int RowSpan {
126                         get {
127                                 object o = ViewState ["RowSpan"];
128                                 return (o == null) ? 0 : (int) o;
129                         }
130                         set {
131                                 // LAMESPEC: undocumented (but like Table.CellPadding)
132                                 if (value < 0)
133                                         throw new ArgumentOutOfRangeException ("< 0");
134                                 ViewState ["RowSpan"] = value;
135                         }
136                 }
137
138 #if NET_2_0
139                 [Localizable (true)]
140                 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
141 #else
142                 [Bindable (true)]
143 #endif
144                 [DefaultValue ("")]
145                 [WebSysDescription ("")]
146                 [WebCategory ("Appearance")]
147                 public virtual string Text {
148                         get {
149                                 object o = ViewState ["Text"];
150                                 return (o == null) ? String.Empty : (string) o;
151                         }
152                         set {
153                                 if (value == null)
154                                         ViewState.Remove ("Text");
155                                 else {
156                                         ViewState ["Text"] = value;
157                                         if (HasControls ())
158                                                 Controls.Clear ();
159                                 }
160                         }
161                 }
162
163 #if ONLY_1_1
164                 [Bindable (true)]
165 #endif
166                 [DefaultValue (VerticalAlign.NotSet)]
167                 [WebSysDescription ("")]
168                 [WebCategory ("Layout")]
169                 public virtual VerticalAlign VerticalAlign {
170                         get {
171                                 if (!ControlStyleCreated)
172                                         return VerticalAlign.NotSet; // default value
173                                 return TableItemStyle.VerticalAlign;
174                         }
175                         set { TableItemStyle.VerticalAlign = value; }
176                 }
177
178 #if ONLY_1_1
179                 [Bindable (true)]
180 #endif
181                 [DefaultValue (true)]
182                 [WebSysDescription ("")]
183                 [WebCategory ("Layout")]
184                 public virtual bool Wrap {
185                         get {
186                                 if (!ControlStyleCreated)
187                                         return true; // default value
188                                 return TableItemStyle.Wrap;
189                         }
190                         set { TableItemStyle.Wrap = value; }
191                 }
192 #if NET_4_0
193                 public override bool SupportsDisabledAttribute {
194                         get { return RenderingCompatibilityLessThan40; }
195                 }
196 #endif
197                 TableItemStyle TableItemStyle {
198                         get { return (ControlStyle as TableItemStyle); }
199                 }
200
201                 protected override void AddAttributesToRender (HtmlTextWriter writer)
202                 {
203                         base.AddAttributesToRender (writer);
204                         if (writer == null)
205                                 return;
206
207                         int i = ColumnSpan;
208                         if (i > 0)
209                                 writer.AddAttribute (HtmlTextWriterAttribute.Colspan, i.ToString (Helpers.InvariantCulture), false);
210
211                         i = RowSpan;
212                         if (i > 0)
213                                 writer.AddAttribute (HtmlTextWriterAttribute.Rowspan, i.ToString (Helpers.InvariantCulture), false);
214 #if NET_2_0
215                         string[] ahci = AssociatedHeaderCellID;
216                         if (ahci.Length > 1) {
217                                 StringBuilder sb = new StringBuilder ();
218                                 for (i = 0; i < ahci.Length - 1; i++) {
219                                         sb.Append (ahci [i]);
220                                         sb.Append (",");
221                                 }
222                                 sb.Append (ahci.Length - 1);
223                                 writer.AddAttribute (HtmlTextWriterAttribute.Headers, sb.ToString ());
224                         } else if (ahci.Length == 1) {
225                                 // most common case (without a StringBuilder)
226                                 writer.AddAttribute (HtmlTextWriterAttribute.Headers, ahci [0]);
227                         }
228 #endif
229                 }
230
231                 protected override void AddParsedSubObject (object obj)
232                 {
233                         if (HasControls ()) {
234                                 base.AddParsedSubObject (obj);
235                                 return;
236                         }
237                         
238                         LiteralControl lc = (obj as LiteralControl);
239                         if (lc == null) {
240                                 string s = Text;
241                                 if (s.Length > 0) {
242                                         Controls.Add (new LiteralControl (s));
243                                         // remove from viewstate
244                                         Text = null;
245                                 }
246                                 base.AddParsedSubObject(obj);
247                         } else {
248                                 // this will clear any existing controls
249                                 Text = lc.Text;
250                         }
251                 }
252
253                 protected override Style CreateControlStyle ()
254                 {
255                         return new TableItemStyle (ViewState);
256                 }
257
258 #if NET_2_0
259                 protected internal
260 #else           
261                 protected
262 #endif          
263                 override void RenderContents (HtmlTextWriter writer)
264                 {
265                         if (HasControls () || HasRenderMethodDelegate ())
266                                 base.RenderContents (writer);
267                         else
268                                 writer.Write (Text);
269                 }
270         }
271 }
272