New test.
[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         [ToolboxData ("<{0}:Panel runat=server>Panel</{0}:Panel>")]
45         public class Panel : WebControl {
46
47                 public Panel () : base (HtmlTextWriterTag.Div) 
48                 {
49                 }
50                 
51                 protected override void AddAttributesToRender (HtmlTextWriter w)
52                 {
53                         base.AddAttributesToRender (w);
54                         
55                         string image = BackImageUrl;
56                         if (image != "") {
57                                 image = String.Format ("url({0})", image);
58                                 w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
59                         }
60
61                         if (!Wrap) {
62 #if NET_2_0
63                                 w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
64 #else
65                                 w.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
66 #endif
67                         }
68
69                         string align = "";
70
71                         switch (HorizontalAlign) {
72                         case HorizontalAlign.Center: align = "center"; break;
73                         case HorizontalAlign.Justify: align = "justify"; break;
74                         case HorizontalAlign.Left: align = "left"; break;
75                         case HorizontalAlign.Right: align = "right"; break;
76                         }
77
78                         if (align != "")
79                                 w.AddAttribute (HtmlTextWriterAttribute.Align, align);
80                 }
81                 
82                 [Bindable(true)]
83                 [DefaultValue("")]
84                 [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
85                 [WebSysDescription ("")]
86                 [WebCategory ("Appearance")]
87                 public virtual string BackImageUrl {
88                         get {
89                                 return ViewState.GetString ("BackImageUrl", "");
90                         }
91                         
92                         set {
93                                 ViewState ["BackImageUrl"] = value;
94                         }
95                 }
96                 
97                 [Bindable(true)]
98                 [DefaultValue(HorizontalAlign.NotSet)]
99                 [WebSysDescription ("")]
100                 [WebCategory ("Layout")]
101                 public virtual HorizontalAlign HorizontalAlign {
102                         get {
103                                 return (HorizontalAlign) ViewState.GetInt ("HorizontalAlign", (int) HorizontalAlign.NotSet);
104                         }
105                         set {
106                                 ViewState ["HorizontalAlign"] = (int) value;
107                         }
108                 }
109                 
110                 [Bindable(true)]
111                 [DefaultValue(true)]
112                 [WebSysDescription ("")]
113                 [WebCategory ("Layout")]
114                 public virtual bool Wrap {
115                         get {
116                                 return ViewState.GetBool ("Wrap", true);
117                         }
118                         set {
119                                 ViewState ["Wrap"] = value;
120                         }
121                 }
122         }
123 }