2 // System.Web.UI.WebControls.Panel.cs
5 // Ben Maurer (bmaurer@novell.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
9 // TODO: Are we missing something in LoadViewState?
10 // What to do in AddParsedSubObject
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
32 using System.ComponentModel;
33 using System.Security.Permissions;
35 namespace System.Web.UI.WebControls {
38 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
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 {
46 public Panel () : base (HtmlTextWriterTag.Div)
50 protected override void AddAttributesToRender (HtmlTextWriter w)
52 base.AddAttributesToRender (w);
54 string image = BackImageUrl;
56 image = ResolveClientUrl (image);
57 w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
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));
65 Page.ClientScript.RegisterWebFormClientScript ();
67 w.AddAttribute ("onkeypress",
68 "javascript:return " + Page.WebFormScriptReference + ".WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
71 if (Direction != ContentDirection.NotSet) {
72 w.AddAttribute (HtmlTextWriterAttribute.Dir, Direction == ContentDirection.RightToLeft ? "rtl" : "ltr", false);
77 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "auto");
80 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "scroll");
82 case ScrollBars.Horizontal:
83 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowX, "scroll");
85 case ScrollBars.Vertical:
86 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowY, "scroll");
92 w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
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;
105 w.AddStyleAttribute (HtmlTextWriterStyle.TextAlign, align);
107 PanelStyle PanelStyle {
108 get { return (ControlStyle as PanelStyle); }
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 {
118 if (ControlStyleCreated) {
119 if (PanelStyle != null)
120 return PanelStyle.BackImageUrl;
122 return ViewState.GetString ("BackImageUrl", String.Empty);
128 PanelStyle.BackImageUrl = value;
130 ViewState ["BackImageUrl"] = value;
134 [DefaultValue (HorizontalAlign.NotSet)]
135 [WebSysDescription ("")]
136 [WebCategory ("Layout")]
137 public virtual HorizontalAlign HorizontalAlign {
139 if (ControlStyleCreated) {
140 if (PanelStyle != null)
141 return PanelStyle.HorizontalAlign;
143 return ViewState ["HorizontalAlign"] != null ? (HorizontalAlign) ViewState ["HorizontalAlign"] : HorizontalAlign.NotSet;
145 return HorizontalAlign.NotSet;
148 if (PanelStyle != null)
149 PanelStyle.HorizontalAlign = value;
151 ViewState ["HorizontalAlign"] = value;
155 [DefaultValue (true)]
156 [WebSysDescription ("")]
157 [WebCategory ("Layout")]
158 public virtual bool Wrap {
160 if (ControlStyleCreated) {
161 if (PanelStyle != null)
162 return PanelStyle.Wrap;
164 return ViewState.GetBool ("Wrap", true);
169 if (PanelStyle != null)
170 PanelStyle.Wrap = value;
172 ViewState ["Wrap"] = value;
176 [ThemeableAttribute (false)]
178 public virtual string DefaultButton {
180 return ViewState.GetString ("DefaultButton", String.Empty);
183 ViewState ["DefaultButton"] = value;
187 [DefaultValue (ContentDirection.NotSet)]
188 public virtual ContentDirection Direction {
190 if (ControlStyleCreated) {
191 if (PanelStyle != null)
192 return PanelStyle.Direction;
194 return ViewState ["Direction"] != null ? (ContentDirection) ViewState ["Direction"] : ContentDirection.NotSet;
196 return ContentDirection.NotSet;
199 if (PanelStyle != null)
200 PanelStyle.Direction = value;
202 ViewState ["Direction"] = value;
206 [LocalizableAttribute (true)]
208 public virtual string GroupingText {
210 return ViewState.GetString ("GroupingText", String.Empty);
213 ViewState ["GroupingText"] = value;
217 [DefaultValue (ScrollBars.None)]
218 public virtual ScrollBars ScrollBars {
220 if (ControlStyleCreated) {
221 if (PanelStyle != null)
222 return PanelStyle.ScrollBars;
224 return ViewState ["ScrollBars"] != null ? (ScrollBars) ViewState ["Direction"] : ScrollBars.None;
226 return ScrollBars.None;
229 if (PanelStyle != null)
230 PanelStyle.ScrollBars = value;
232 ViewState ["ScrollBars"] = value;
235 public override bool SupportsDisabledAttribute {
236 get { return RenderingCompatibilityLessThan40; }
238 protected override Style CreateControlStyle ()
240 return new PanelStyle (ViewState);
243 public override void RenderBeginTag (HtmlTextWriter writer)
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 ();
254 public override void RenderEndTag (HtmlTextWriter writer)
256 if (!String.IsNullOrEmpty (GroupingText)) {
257 writer.RenderEndTag (); // Fieldset
259 base.RenderEndTag (writer);