[bcl] Remove ONLY_1_1 defines from class libs
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / Table.cs
blob865c463688d36b2aebcceaf22ded597e2ec1ce44
1 //
2 // System.Web.UI.WebControls.Table.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.
29 using System.ComponentModel;
30 using System.Security.Permissions;
32 namespace System.Web.UI.WebControls {
34 // CAS
35 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 // attributes
38 [DefaultProperty ("Rows")]
39 [Designer ("System.Web.UI.Design.WebControls.TableDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
40 [ParseChildren (true, "Rows")]
41 [SupportsEventValidation]
42 public class Table : WebControl, IPostBackEventHandler
44 TableRowCollection rows;
45 bool generateTableSections;
47 public Table ()
48 : base (HtmlTextWriterTag.Table)
52 internal bool GenerateTableSections {
53 get { return generateTableSections; }
54 set { generateTableSections = value; }
57 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
58 [UrlProperty]
59 [DefaultValue ("")]
60 [WebSysDescription ("")]
61 [WebCategory ("Appearance")]
62 public virtual string BackImageUrl {
63 get {
64 if (!ControlStyleCreated)
65 return String.Empty; // default value
66 return TableStyle.BackImageUrl;
68 set { TableStyle.BackImageUrl = value; }
71 // note: it seems that Caption and CaptionAlign appeared in 1.1 SP1
73 [DefaultValue ("")]
74 [Localizable (true)]
75 [WebSysDescription ("")]
76 [WebCategory ("Accessibility")]
77 public virtual string Caption {
78 get {
79 object o = ViewState ["Caption"];
80 return (o == null) ? String.Empty : (string) o;
82 set {
83 if (value == null)
84 ViewState.Remove ("Caption");
85 else
86 ViewState ["Caption"] = value;
90 [DefaultValue (TableCaptionAlign.NotSet)]
91 [WebCategory ("Accessibility")]
92 public virtual TableCaptionAlign CaptionAlign {
93 get {
94 object o = ViewState ["CaptionAlign"];
95 return (o == null) ? TableCaptionAlign.NotSet : (TableCaptionAlign) o;
97 set {
98 if ((value < TableCaptionAlign.NotSet) || (value > TableCaptionAlign.Right)) {
99 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid TableCaptionAlign value."));
101 ViewState ["CaptionAlign"] = value;
105 [DefaultValue (-1)]
106 [WebSysDescription ("")]
107 [WebCategory ("Appearance")]
108 public virtual int CellPadding {
109 get {
110 if (!ControlStyleCreated)
111 return -1; // default value
112 return TableStyle.CellPadding;
114 set { TableStyle.CellPadding = value; }
117 [DefaultValue (-1)]
118 [WebSysDescription ("")]
119 [WebCategory ("Appearance")]
120 public virtual int CellSpacing {
121 get {
122 if (!ControlStyleCreated)
123 return -1; // default value
124 return TableStyle.CellSpacing;
126 set { TableStyle.CellSpacing = value; }
129 [DefaultValue (GridLines.None)]
130 [WebSysDescription ("")]
131 [WebCategory ("Appearance")]
132 public virtual GridLines GridLines {
133 get {
134 if (!ControlStyleCreated)
135 return GridLines.None; // default value
136 return TableStyle.GridLines;
138 set { TableStyle.GridLines = value; }
141 [DefaultValue (HorizontalAlign.NotSet)]
142 [WebSysDescription ("")]
143 [WebCategory ("Layout")]
144 public virtual HorizontalAlign HorizontalAlign {
145 get {
146 if (!ControlStyleCreated)
147 return HorizontalAlign.NotSet; // default value
148 return TableStyle.HorizontalAlign;
150 set { TableStyle.HorizontalAlign = value; }
153 [MergableProperty (false)]
154 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
155 [WebSysDescription ("")]
156 public virtual TableRowCollection Rows {
157 get {
158 if (rows == null)
159 rows = new TableRowCollection (this);
160 return rows;
164 private TableStyle TableStyle {
165 get { return (ControlStyle as TableStyle); }
167 public override bool SupportsDisabledAttribute {
168 get { return RenderingCompatibilityLessThan40; }
170 protected override void AddAttributesToRender (HtmlTextWriter writer)
172 base.AddAttributesToRender (writer);
175 protected override ControlCollection CreateControlCollection ()
177 return new RowControlCollection (this);
180 protected override Style CreateControlStyle ()
182 return new TableStyle (ViewState);
185 protected internal
186 override void RenderContents (HtmlTextWriter writer)
188 TableRowSection currentTableSection = TableRowSection.TableHeader;
189 TableRowSection rowSection;
190 bool sectionStarted = false;
192 if (Rows.Count > 0) {
193 foreach (TableRow row in Rows) {
194 if (generateTableSections) {
195 rowSection = row.TableSection;
196 if (rowSection < currentTableSection)
197 throw new HttpException ("The table " + ID + " must contain row sections in order of header, body, then footer.");
199 if (currentTableSection != rowSection) {
200 if (sectionStarted) {
201 writer.RenderEndTag ();
202 sectionStarted = false;
205 currentTableSection = rowSection;
208 if (!sectionStarted) {
209 switch (rowSection) {
210 case TableRowSection.TableHeader:
211 writer.RenderBeginTag (HtmlTextWriterTag.Thead);
212 break;
214 case TableRowSection.TableBody:
215 writer.RenderBeginTag (HtmlTextWriterTag.Tbody);
216 break;
218 case TableRowSection.TableFooter:
219 writer.RenderBeginTag (HtmlTextWriterTag.Tfoot);
220 break;
222 sectionStarted = true;
225 if (row != null)
226 row.RenderControl (writer);
229 if (sectionStarted)
230 writer.RenderEndTag ();
235 // new in Fx 1.1 SP1 (to support Caption and CaptionAlign)
237 public override void RenderBeginTag (HtmlTextWriter writer)
239 base.RenderBeginTag (writer);
241 string s = Caption;
242 if (s.Length > 0) {
243 TableCaptionAlign tca = CaptionAlign;
244 if (tca != TableCaptionAlign.NotSet)
245 writer.AddAttribute (HtmlTextWriterAttribute.Align, tca.ToString ());
247 writer.RenderBeginTag (HtmlTextWriterTag.Caption);
248 writer.Write (s);
249 writer.RenderEndTag ();
251 // #if !NET_4_0
252 // else if (HasControls ()) {
253 // writer.Indent++;
254 // }
255 // #endif
258 void IPostBackEventHandler.RaisePostBackEvent (string argument)
260 RaisePostBackEvent (argument);
263 protected virtual void RaisePostBackEvent (string argument)
265 ValidateEvent (UniqueID, argument);
268 // inner class
269 protected class RowControlCollection : ControlCollection {
271 internal RowControlCollection (Table owner)
272 : base (owner)
277 public override void Add (Control child)
279 if (child == null)
280 throw new NullReferenceException ("null");
281 if (!(child is TableRow))
282 throw new ArgumentException ("child", Locale.GetText ("Must be an TableRow instance."));
284 base.Add (child);
287 public override void AddAt (int index, Control child)
289 if (child == null)
290 throw new NullReferenceException ("null");
291 if (!(child is TableRow))
292 throw new ArgumentException ("child", Locale.GetText ("Must be an TableRow instance."));
294 base.AddAt (index, child);