[tests] Separate MONO_PATH directories by PLATFORM_PATH_SEPARATOR
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Panel.cs
1 //
2 // System.Web.UI.WebControls.Panel.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@novell.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // TODO: Are we missing something in LoadViewState?
10 // What to do in AddParsedSubObject
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System.ComponentModel;
33 using System.Security.Permissions;
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         [Designer ("System.Web.UI.Design.WebControls.PanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42         [ParseChildren (false)]
43         [PersistChildren (true)]
44         public class Panel : WebControl {
45
46                 public Panel () : base (HtmlTextWriterTag.Div) 
47                 {
48                 }
49                 
50                 protected override void AddAttributesToRender (HtmlTextWriter w)
51                 {
52                         base.AddAttributesToRender (w);
53                         
54                         string image = BackImageUrl;
55                         if (image != "") {
56                                 image = ResolveClientUrl (image);
57                                 w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
58                         }
59
60                         if (!String.IsNullOrEmpty (DefaultButton) && Page != null) {
61                                 Control button = FindControl (DefaultButton);
62                                 if (button == null || !(button is IButtonControl))
63                                         throw new InvalidOperationException (String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.", ID));
64
65                                 Page.ClientScript.RegisterWebFormClientScript ();
66
67                                 w.AddAttribute ("onkeypress",
68                                                 "javascript:return " + Page.WebFormScriptReference + ".WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
69                         }
70
71                         if (Direction != ContentDirection.NotSet) {
72                                 w.AddAttribute (HtmlTextWriterAttribute.Dir, Direction == ContentDirection.RightToLeft ? "rtl" : "ltr", false);
73                         }
74
75                         switch (ScrollBars) {
76                         case ScrollBars.Auto:
77                                 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "auto");
78                                 break;
79                         case ScrollBars.Both:
80                                 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "scroll");
81                                 break;
82                         case ScrollBars.Horizontal:
83                                 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowX, "scroll");
84                                 break;
85                         case ScrollBars.Vertical:
86                                 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowY, "scroll");
87                                 break;
88                         }
89
90
91                         if (!Wrap) {
92                                 w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
93                         }
94
95                         string align = "";
96
97                         switch (HorizontalAlign) {
98                         case HorizontalAlign.Center: align = "center"; break;
99                         case HorizontalAlign.Justify: align = "justify"; break;
100                         case HorizontalAlign.Left: align = "left"; break;
101                         case HorizontalAlign.Right: align = "right"; break;
102                         }
103
104                         if (align != "")
105                                 w.AddStyleAttribute (HtmlTextWriterStyle.TextAlign, align);
106                 }
107                 PanelStyle PanelStyle {
108                         get { return (ControlStyle as PanelStyle); }
109                 }
110
111                 [UrlProperty]
112                 [DefaultValue ("")]
113                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
114                 [WebSysDescription ("")]
115                 [WebCategory ("Appearance")]
116                 public virtual string BackImageUrl {
117                         get {
118                                 if (ControlStyleCreated) {
119                                         if (PanelStyle != null)
120                                                 return PanelStyle.BackImageUrl;
121                                         else
122                                                 return ViewState.GetString ("BackImageUrl", String.Empty);
123                                 }
124                                 return String.Empty;
125                         }
126                         set {
127                                 if(PanelStyle!=null)
128                                         PanelStyle.BackImageUrl = value;
129                                 else
130                                         ViewState ["BackImageUrl"] = value;
131                         }
132                 }
133
134                 [DefaultValue (HorizontalAlign.NotSet)]
135                 [WebSysDescription ("")]
136                 [WebCategory ("Layout")]
137                 public virtual HorizontalAlign HorizontalAlign {
138                         get {
139                                 if (ControlStyleCreated) {
140                                         if (PanelStyle != null)
141                                                 return PanelStyle.HorizontalAlign;
142                                         else
143                                                 return ViewState ["HorizontalAlign"] != null ? (HorizontalAlign) ViewState ["HorizontalAlign"] : HorizontalAlign.NotSet;
144                                 }
145                                 return HorizontalAlign.NotSet;
146                         }
147                         set {
148                                 if (PanelStyle != null)
149                                         PanelStyle.HorizontalAlign = value;
150                                 else
151                                         ViewState ["HorizontalAlign"] = value;
152                         }
153                 }
154
155                 [DefaultValue (true)]
156                 [WebSysDescription ("")]
157                 [WebCategory ("Layout")]
158                 public virtual bool Wrap {
159                         get {
160                                 if (ControlStyleCreated) {
161                                         if (PanelStyle != null)
162                                                 return PanelStyle.Wrap;
163                                         else
164                                                 return ViewState.GetBool ("Wrap", true);
165                                 }
166                                 return true;
167                         }
168                         set {
169                                 if (PanelStyle != null)
170                                         PanelStyle.Wrap = value;
171                                 else
172                                         ViewState ["Wrap"] = value;
173                         }
174                 }
175                 
176                 [ThemeableAttribute (false)]
177                 [DefaultValue ("")]
178                 public virtual string DefaultButton {
179                         get {
180                                 return ViewState.GetString ("DefaultButton", String.Empty);
181                         }
182                         set {
183                                 ViewState ["DefaultButton"] = value;
184                         }
185                 }
186
187                 [DefaultValue (ContentDirection.NotSet)]
188                 public virtual ContentDirection Direction {
189                         get {
190                                 if (ControlStyleCreated) {
191                                         if (PanelStyle != null)
192                                                 return PanelStyle.Direction;
193                                         else
194                                                 return ViewState ["Direction"] != null ? (ContentDirection) ViewState ["Direction"] : ContentDirection.NotSet;
195                                 }
196                                 return ContentDirection.NotSet;
197                         }
198                         set {
199                                 if (PanelStyle != null)
200                                         PanelStyle.Direction = value;
201                                 else
202                                         ViewState ["Direction"] = value;
203                         }
204                 }
205
206                 [LocalizableAttribute (true)]
207                 [DefaultValue ("")]
208                 public virtual string GroupingText {
209                         get {
210                                 return ViewState.GetString ("GroupingText", String.Empty);
211                         }
212                         set {
213                                 ViewState ["GroupingText"] = value;
214                         }
215                 }
216
217                 [DefaultValue (ScrollBars.None)]
218                 public virtual ScrollBars ScrollBars {
219                         get {
220                                 if (ControlStyleCreated) {
221                                         if (PanelStyle != null)
222                                                 return PanelStyle.ScrollBars;
223                                         else
224                                                 return ViewState ["ScrollBars"] != null ? (ScrollBars) ViewState ["Direction"] : ScrollBars.None;
225                                 }
226                                 return ScrollBars.None;
227                         }
228                         set {
229                                 if (PanelStyle != null)
230                                         PanelStyle.ScrollBars = value;
231                                 else
232                                         ViewState ["ScrollBars"] = value;
233                         }
234                 }
235                 public override bool SupportsDisabledAttribute {
236                         get { return RenderingCompatibilityLessThan40; }
237                 }
238                 protected override Style CreateControlStyle ()
239                 {
240                         return new PanelStyle (ViewState);
241                 }
242
243                 public override void RenderBeginTag (HtmlTextWriter writer)
244                 {
245                         base.RenderBeginTag (writer);
246                         if (!String.IsNullOrEmpty (GroupingText)) {
247                                 writer.RenderBeginTag (HtmlTextWriterTag.Fieldset);
248                                 writer.RenderBeginTag (HtmlTextWriterTag.Legend);
249                                 writer.Write (GroupingText);
250                                 writer.RenderEndTag ();
251                         }
252                 }
253
254                 public override void RenderEndTag (HtmlTextWriter writer)
255                 {
256                         if (!String.IsNullOrEmpty (GroupingText)) {
257                                 writer.RenderEndTag (); // Fieldset
258                         }
259                         base.RenderEndTag (writer);
260                 }
261         }
262 }