2004-05-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Panel.cs
1 //
2 // System.Web.UI.WebControls.Panel.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 //
11 \r
12 using System;\r
13 using System.ComponentModel;
14 using System.ComponentModel.Design;\r
15 using System.Web;\r
16 using System.Web.UI;\r
17 \r
18 namespace System.Web.UI.WebControls\r
19 {\r
20         [Designer ("System.Web.UI.Design.WebControls.PanelDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]\r
21         [ParseChildren(false)]\r
22         [PersistChildren(true)]\r
23         [ToolboxData("<{0}:Panel runat=\"server\">Panel</{0}:Panel>")]\r
24         public class Panel: WebControl\r
25         {\r
26                 public Panel(): base(HtmlTextWriterTag.Div)\r
27                 {\r
28                 }\r
29
30                 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
31                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
32                 [WebSysDescription ("An Url specifying the background image for the panel.")]\r
33                 public virtual string BackImageUrl\r
34                 {\r
35                         get\r
36                         {\r
37                                 object o = ViewState["BackImageUrl"];\r
38                                 if(o != null)\r
39                                         return (string)o;\r
40                                 return String.Empty;\r
41                         }\r
42                         set\r
43                         {\r
44                                 ViewState["BackImageUrl"] = value;\r
45                         }\r
46                 }\r
47
48                 [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
49                 [WebSysDescription ("The horizonal alignment of the panel.")]\r
50                 public virtual HorizontalAlign HorizontalAlign\r
51                 {\r
52                         get\r
53                         {\r
54                                 object o = ViewState["HorizontalAlign"];\r
55                                 if(o != null)\r
56                                         return (HorizontalAlign)o;\r
57                                 return HorizontalAlign.NotSet;\r
58                         }\r
59                         set\r
60                         {\r
61                                 if(!Enum.IsDefined(typeof(HorizontalAlign), value))\r
62                                 {\r
63                                         throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");\r
64                                 }\r
65                                 ViewState["HorizontalAlign"] = value;\r
66                         }\r
67                 }\r
68
69                 [DefaultValue (true), Bindable (true), WebCategory ("Layout")]
70                 [WebSysDescription ("Determines if the content wraps at line-end.")]\r
71                 public virtual bool Wrap\r
72                 {\r
73                         get\r
74                         {\r
75                                 object o = ViewState["Wrap"];\r
76                                 if(o != null)\r
77                                         return (bool)o;\r
78                                 return true;\r
79                         }\r
80                         set\r
81                         {\r
82                                 ViewState["Wrap"] = value;\r
83                         }\r
84                 }\r
85 \r
86                 protected override void AddAttributesToRender(HtmlTextWriter writer)\r
87                 {\r
88                         base.AddAttributesToRender(writer);\r
89                         if(BackImageUrl.Length > 0)\r
90                         {\r
91                                 writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + ResolveUrl(BackImageUrl) + ")");\r
92                         }\r
93                         if(HorizontalAlign != HorizontalAlign.NotSet)\r
94                         {\r
95                                 writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));\r
96                         }\r
97                         if(!Wrap)\r
98                         {\r
99                                 writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");\r
100                         }\r
101                 }\r
102         }\r
103 }\r