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 [ToolboxData ("<{0}:Panel runat=server>Panel</{0}:Panel>")]
45 public class Panel : WebControl {
47 public Panel () : base (HtmlTextWriterTag.Div)
51 protected override void AddAttributesToRender (HtmlTextWriter w)
53 base.AddAttributesToRender (w);
55 string image = BackImageUrl;
57 image = ResolveClientUrl (image);
58 #if !NET_2_0 // see HtmlTextWriter.WriteStyleAttribute(string, string, bool)
59 image = String.Concat ("url(", image, ")");
61 w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
65 if (!String.IsNullOrEmpty (DefaultButton) && Page != null) {
66 Control button = FindControl (DefaultButton);
67 if (button == null || !(button is IButtonControl))
68 throw new InvalidOperationException (String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.", ID));
70 Page.ClientScript.RegisterWebFormClientScript ();
72 w.AddAttribute ("onkeypress",
73 "javascript:return " + Page.WebFormScriptReference + ".WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
76 if (Direction != ContentDirection.NotSet) {
77 w.AddAttribute (HtmlTextWriterAttribute.Dir, Direction == ContentDirection.RightToLeft ? "rtl" : "ltr", false);
82 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "auto");
85 w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "scroll");
87 case ScrollBars.Horizontal:
88 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowX, "scroll");
90 case ScrollBars.Vertical:
91 w.AddStyleAttribute (HtmlTextWriterStyle.OverflowY, "scroll");
99 w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
101 w.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
107 switch (HorizontalAlign) {
108 case HorizontalAlign.Center: align = "center"; break;
109 case HorizontalAlign.Justify: align = "justify"; break;
110 case HorizontalAlign.Left: align = "left"; break;
111 case HorizontalAlign.Right: align = "right"; break;
116 w.AddStyleAttribute (HtmlTextWriterStyle.TextAlign, align);
118 w.AddAttribute (HtmlTextWriterAttribute.Align, align);
125 [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
126 [WebSysDescription ("")]
127 [WebCategory ("Appearance")]
128 public virtual string BackImageUrl {
130 return ViewState.GetString ("BackImageUrl", "");
134 ViewState ["BackImageUrl"] = value;
139 [DefaultValue(HorizontalAlign.NotSet)]
140 [WebSysDescription ("")]
141 [WebCategory ("Layout")]
142 public virtual HorizontalAlign HorizontalAlign {
144 return (HorizontalAlign) ViewState.GetInt ("HorizontalAlign", (int) HorizontalAlign.NotSet);
147 ViewState ["HorizontalAlign"] = (int) value;
153 [WebSysDescription ("")]
154 [WebCategory ("Layout")]
155 public virtual bool Wrap {
157 return ViewState.GetBool ("Wrap", true);
160 ViewState ["Wrap"] = value;
166 PanelStyle PanelStyle {
167 get { return (ControlStyle as PanelStyle); }
172 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
173 [WebSysDescription ("")]
174 [WebCategory ("Appearance")]
175 public virtual string BackImageUrl {
177 if (ControlStyleCreated) {
178 if (PanelStyle != null)
179 return PanelStyle.BackImageUrl;
181 return ViewState.GetString ("BackImageUrl", String.Empty);
187 PanelStyle.BackImageUrl = value;
189 ViewState ["BackImageUrl"] = value;
194 [DefaultValue (HorizontalAlign.NotSet)]
195 [WebSysDescription ("")]
196 [WebCategory ("Layout")]
197 public virtual HorizontalAlign HorizontalAlign {
199 if (ControlStyleCreated) {
200 if (PanelStyle != null)
201 return PanelStyle.HorizontalAlign;
203 return ViewState ["HorizontalAlign"] != null ? (HorizontalAlign) ViewState ["HorizontalAlign"] : HorizontalAlign.NotSet;
205 return HorizontalAlign.NotSet;
208 if (PanelStyle != null)
209 PanelStyle.HorizontalAlign = value;
211 ViewState ["HorizontalAlign"] = value;
216 [DefaultValue (true)]
217 [WebSysDescription ("")]
218 [WebCategory ("Layout")]
219 public virtual bool Wrap {
221 if (ControlStyleCreated) {
222 if (PanelStyle != null)
223 return PanelStyle.Wrap;
225 return ViewState.GetBool ("Wrap", true);
230 if (PanelStyle != null)
231 PanelStyle.Wrap = value;
233 ViewState ["Wrap"] = value;
237 [ThemeableAttribute (false)]
238 public virtual string DefaultButton {
240 return ViewState.GetString ("DefaultButton", String.Empty);
243 ViewState ["DefaultButton"] = value;
247 public virtual ContentDirection Direction {
249 if (ControlStyleCreated) {
250 if (PanelStyle != null)
251 return PanelStyle.Direction;
253 return ViewState ["Direction"] != null ? (ContentDirection) ViewState ["Direction"] : ContentDirection.NotSet;
255 return ContentDirection.NotSet;
258 if (PanelStyle != null)
259 PanelStyle.Direction = value;
261 ViewState ["Direction"] = value;
265 [LocalizableAttribute (true)]
266 public virtual string GroupingText {
268 return ViewState.GetString ("GroupingText", String.Empty);
271 ViewState ["GroupingText"] = value;
275 public virtual ScrollBars ScrollBars {
277 if (ControlStyleCreated) {
278 if (PanelStyle != null)
279 return PanelStyle.ScrollBars;
281 return ViewState ["ScrollBars"] != null ? (ScrollBars) ViewState ["Direction"] : ScrollBars.None;
283 return ScrollBars.None;
286 if (PanelStyle != null)
287 PanelStyle.ScrollBars = value;
289 ViewState ["ScrollBars"] = value;
293 protected override Style CreateControlStyle ()
295 return new PanelStyle (ViewState);
298 public override void RenderBeginTag (HtmlTextWriter writer)
300 base.RenderBeginTag (writer);
301 if (!String.IsNullOrEmpty (GroupingText)) {
302 writer.RenderBeginTag (HtmlTextWriterTag.Fieldset);
303 writer.RenderBeginTag (HtmlTextWriterTag.Legend);
304 writer.Write (GroupingText);
305 writer.RenderEndTag ();
309 public override void RenderEndTag (HtmlTextWriter writer)
311 if (!String.IsNullOrEmpty (GroupingText)) {
312 writer.RenderEndTag (); // Fieldset
314 base.RenderEndTag (writer);