refactoring
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableRow.cs
1 //
2 // System.Web.UI.WebControls.TableRow.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.Security.Permissions;
31
32 namespace System.Web.UI.WebControls {
33
34         // CAS
35         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37         // attributes
38         [DefaultProperty ("Cells")]
39         [ParseChildren (true, "Cells")]
40         [ToolboxItem ("")]
41 #if NET_2_0
42         [Bindable (false)]
43         [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
44 #endif
45         public class TableRow : WebControl {
46
47                 private TableCellCollection cells;
48
49
50                 public TableRow ()
51                         : base (HtmlTextWriterTag.Tr)
52                 {
53                         AutoID = false;
54                 }
55
56
57                 [MergableProperty (false)]
58                 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
59                 [WebSysDescription ("")]
60                 [WebCategory("Layout")]
61                 public virtual TableCellCollection Cells {
62                         get {
63                                 if (cells == null)
64                                         cells = new TableCellCollection (this);
65                                 return cells;
66                         }
67                 }
68
69 #if ONLY_1_1
70                 [Bindable (true)]
71 #endif
72                 [DefaultValue (HorizontalAlign.NotSet)]
73                 [WebSysDescription ("")]
74                 [WebCategory ("Layout")]
75                 public virtual HorizontalAlign HorizontalAlign {
76                         get {
77                                 if (!ControlStyleCreated)
78                                         return HorizontalAlign.NotSet; // default value
79                                 return TableItemStyle.HorizontalAlign;
80                         }
81                         set { TableItemStyle.HorizontalAlign = value; }
82                 }
83
84 #if ONLY_1_1
85                 [Bindable (true)]
86 #endif
87                 [DefaultValue (VerticalAlign.NotSet)]
88                 [WebSysDescription ("")]
89                 [WebCategory ("Layout")]
90                 public virtual VerticalAlign VerticalAlign {
91                         get {
92                                 if (!ControlStyleCreated)
93                                         return VerticalAlign.NotSet; // default value
94                                 return TableItemStyle.VerticalAlign;
95                         }
96                         set { TableItemStyle.VerticalAlign = value; }
97                 }
98
99                 private TableItemStyle TableItemStyle {
100                         get { return (ControlStyle as TableItemStyle); }
101                 }
102
103
104                 protected override ControlCollection CreateControlCollection ()
105                 {
106                         return new CellControlCollection (this);
107                 }
108
109                 protected override Style CreateControlStyle ()
110                 {
111                         return new TableItemStyle (ViewState);
112                 }
113 #if NET_2_0
114                 [DefaultValue (TableRowSection.TableBody)]
115                 public virtual TableRowSection TableSection {
116                         get {
117                                 object o = ViewState ["TableSection"];
118                                 return (o == null) ? TableRowSection.TableBody : (TableRowSection) o;
119                         }
120                         set {
121                                 if ((value < TableRowSection.TableHeader) || (value > TableRowSection.TableFooter))
122                                         throw new ArgumentOutOfRangeException ("TableSection");
123                                 ViewState ["TableSection"] = (int) value;
124                         }
125                 }
126 #endif
127                 // inner class
128                 protected class CellControlCollection : ControlCollection {
129
130                         internal CellControlCollection (TableRow owner)
131                                 : base (owner)
132                         {
133                         }
134
135
136                         public override void Add (Control child)
137                         {
138                                 if (child == null)
139                                         throw new NullReferenceException ("null");
140                                 if (!(child is TableCell))
141                                         throw new ArgumentException ("child", Locale.GetText ("Must be an TableCell instance."));
142
143                                 base.Add (child);
144                         }
145
146                         public override void AddAt (int index, Control child)
147                         {
148                                 if (child == null)
149                                         throw new NullReferenceException ("null");
150                                 if (!(child is TableCell))
151                                         throw new ArgumentException ("child", Locale.GetText ("Must be an TableCell instance."));
152
153                                 base.AddAt (index, child);
154                         }
155                 }
156         }
157 }