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