ChangeLog: Updated.
[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         [DefaultProperty("Text")]\r
42         [ToolboxItem(false)]\r
43         [ControlBuilder(typeof(TableCellControlBuilder))]\r
44         [ParseChildren(false)]\r
45         [PersistChildren(true)]\r
46         public class TableCell: WebControl\r
47         {\r
48                 public TableCell () : base (HtmlTextWriterTag.Td)\r
49                 {\r
50                         PreventAutoID ();\r
51                 }\r
52 \r
53                 internal TableCell (HtmlTextWriterTag tag) : base (tag)\r
54                 {\r
55                         PreventAutoID ();\r
56                 }\r
57
58                 [DefaultValue (0), Bindable (true), WebCategory ("Appearance")]
59                 [WebSysDescription ("The number of columns spanned by this cell.")]\r
60                 public virtual int ColumnSpan\r
61                 {\r
62                         get {\r
63                                 object o = ViewState ["ColumnSpan"];\r
64                                 return (o == null) ? 0 : (int) o;\r
65                         }\r
66 \r
67                         set {
68                                 if (value < 0)
69                                         throw new ArgumentOutOfRangeException ("value", "ColumnSpan value has to be >= 0.");
70                                 ViewState ["ColumnSpan"] = value;
71                         }\r
72                 }\r
73
74                 [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
75                 [WebSysDescription ("The number of rows spanned by this cell.")]\r
76                 public virtual int RowSpan\r
77                 {\r
78                         get {\r
79                                 object o = ViewState ["RowSpan"];\r
80                                 return (o == null) ? 0 : (int) o;\r
81                         }\r
82 \r
83                         set {
84                                 if (value < 0)
85                                         throw new ArgumentOutOfRangeException ("value", "RowSpan value has to be >= 0.");
86                                 ViewState ["RowSpan"] = value;
87                         }\r
88                 }\r
89
90                 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
91                 [WebSysDescription ("The text that is shown in this cell.")]\r
92                 public virtual string Text\r
93                 {\r
94                         get {\r
95                                 object o = ViewState ["Text"];\r
96                                 return (o == null) ? String.Empty : (string) o;\r
97                         }\r
98 \r
99                         set {
100                                 if (HasControls ())
101                                         Controls.Clear ();
102                                 ViewState ["Text"] = value;
103                         }
104                 }\r
105
106                 [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
107                 [WebSysDescription ("The horizontal alignment for this cell.")]\r
108                 public virtual HorizontalAlign HorizontalAlign\r
109                 {\r
110                         get {\r
111                                 if (ControlStyleCreated)\r
112                                         return ((TableItemStyle) ControlStyle).HorizontalAlign;\r
113                                 return HorizontalAlign.NotSet;\r
114                         }\r
115                         set { ((TableItemStyle) ControlStyle).HorizontalAlign = value; }\r
116                 }\r
117
118                 [DefaultValue (typeof (VerticalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
119                 [WebSysDescription ("The horizontal alignment for this cell.")]\r
120                 public virtual VerticalAlign VerticalAlign\r
121                 {\r
122                         get {\r
123                                 if (ControlStyleCreated)\r
124                                         return ((TableItemStyle) ControlStyle).VerticalAlign;\r
125                                 return VerticalAlign.NotSet;\r
126                         }\r
127 \r
128                         set { ((TableItemStyle) ControlStyle).VerticalAlign = value; }\r
129                 }\r
130
131                 [DefaultValue (true), Bindable (true), WebCategory ("Layout")]
132                 [WebSysDescription ("Determines if the text in the cell should be wraped at line-end.")]\r
133                 public virtual bool Wrap\r
134                 {\r
135                         get {\r
136                                 if (ControlStyleCreated)\r
137                                         return ((TableItemStyle) ControlStyle).Wrap;\r
138                                 return true;\r
139                         }\r
140                         set { ((TableItemStyle) ControlStyle).Wrap = value; }\r
141                 }\r
142 \r
143                 protected override void AddAttributesToRender (HtmlTextWriter writer)\r
144                 {\r
145                         base.AddAttributesToRender (writer);\r
146                         if (ColumnSpan > 0)\r
147                                 writer.AddAttribute (HtmlTextWriterAttribute.Colspan,\r
148                                                      ColumnSpan.ToString (NumberFormatInfo.InvariantInfo));\r
149 \r
150                         if (RowSpan > 0)\r
151                                 writer.AddAttribute (HtmlTextWriterAttribute.Rowspan,\r
152                                                      RowSpan.ToString (NumberFormatInfo.InvariantInfo));\r
153                 }\r
154 \r
155                 protected override void AddParsedSubObject (object obj)\r
156                 {\r
157                         if (HasControls ()){\r
158                                 base.AddParsedSubObject (obj);\r
159                                 return;\r
160                         }\r
161 \r
162                         if (obj is LiteralControl){\r
163                                 Text = ((LiteralControl) obj).Text;\r
164                                 return;\r
165                         }\r
166 \r
167                         string text = Text;\r
168                         if (text.Length > 0){\r
169                                 Text = String.Empty;\r
170                                 base.AddParsedSubObject (new LiteralControl (text));\r
171                         }\r
172 \r
173                         base.AddParsedSubObject (obj);\r
174                 }\r
175 \r
176                 protected override Style CreateControlStyle ()\r
177                 {\r
178                         return new TableItemStyle (ViewState);\r
179                 }\r
180 \r
181                 protected override void RenderContents (HtmlTextWriter writer)\r
182                 {\r
183                         if (HasControls ())\r
184                                 base.RenderContents (writer);\r
185                         else\r
186                                 writer.Write (Text);\r
187                 }\r
188         }\r
189 }\r
190 \r