| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- //
- // System.Web.UI.WebControls.Panel.cs
- //
- // Authors:
- // Ben Maurer ([email protected])
- //
- // (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // TODO: Are we missing something in LoadViewState?
- // What to do in AddParsedSubObject
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System.ComponentModel;
- using System.Security.Permissions;
- namespace System.Web.UI.WebControls {
- // CAS
- [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- // attributes
- [Designer ("System.Web.UI.Design.WebControls.PanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- [ParseChildren (false)]
- [PersistChildren (true)]
- public class Panel : WebControl {
- public Panel () : base (HtmlTextWriterTag.Div)
- {
- }
-
- protected override void AddAttributesToRender (HtmlTextWriter w)
- {
- base.AddAttributesToRender (w);
-
- string image = BackImageUrl;
- if (image != "") {
- image = ResolveClientUrl (image);
- #if !NET_2_0 // see HtmlTextWriter.WriteStyleAttribute(string, string, bool)
- image = String.Concat ("url(", image, ")");
- #endif
- w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
- }
- #if NET_2_0
- if (!String.IsNullOrEmpty (DefaultButton) && Page != null) {
- Control button = FindControl (DefaultButton);
- if (button == null || !(button is IButtonControl))
- throw new InvalidOperationException (String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.", ID));
- Page.ClientScript.RegisterWebFormClientScript ();
- w.AddAttribute ("onkeypress",
- "javascript:return " + Page.WebFormScriptReference + ".WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
- }
- if (Direction != ContentDirection.NotSet) {
- w.AddAttribute (HtmlTextWriterAttribute.Dir, Direction == ContentDirection.RightToLeft ? "rtl" : "ltr", false);
- }
- switch (ScrollBars) {
- case ScrollBars.Auto:
- w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "auto");
- break;
- case ScrollBars.Both:
- w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "scroll");
- break;
- case ScrollBars.Horizontal:
- w.AddStyleAttribute (HtmlTextWriterStyle.OverflowX, "scroll");
- break;
- case ScrollBars.Vertical:
- w.AddStyleAttribute (HtmlTextWriterStyle.OverflowY, "scroll");
- break;
- }
- #endif
- if (!Wrap) {
- #if NET_2_0
- w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
- #else
- w.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
- #endif
- }
- string align = "";
- switch (HorizontalAlign) {
- case HorizontalAlign.Center: align = "center"; break;
- case HorizontalAlign.Justify: align = "justify"; break;
- case HorizontalAlign.Left: align = "left"; break;
- case HorizontalAlign.Right: align = "right"; break;
- }
- if (align != "")
- #if NET_2_0
- w.AddStyleAttribute (HtmlTextWriterStyle.TextAlign, align);
- #else
- w.AddAttribute (HtmlTextWriterAttribute.Align, align);
- #endif
- }
- #if NET_2_0
- PanelStyle PanelStyle {
- get { return (ControlStyle as PanelStyle); }
- }
- [UrlProperty]
- [DefaultValue ("")]
- [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- [WebSysDescription ("")]
- [WebCategory ("Appearance")]
- public virtual string BackImageUrl {
- get {
- if (ControlStyleCreated) {
- if (PanelStyle != null)
- return PanelStyle.BackImageUrl;
- else
- return ViewState.GetString ("BackImageUrl", String.Empty);
- }
- return String.Empty;
- }
- set {
- if(PanelStyle!=null)
- PanelStyle.BackImageUrl = value;
- else
- ViewState ["BackImageUrl"] = value;
- }
- }
- [DefaultValue (HorizontalAlign.NotSet)]
- [WebSysDescription ("")]
- [WebCategory ("Layout")]
- public virtual HorizontalAlign HorizontalAlign {
- get {
- if (ControlStyleCreated) {
- if (PanelStyle != null)
- return PanelStyle.HorizontalAlign;
- else
- return ViewState ["HorizontalAlign"] != null ? (HorizontalAlign) ViewState ["HorizontalAlign"] : HorizontalAlign.NotSet;
- }
- return HorizontalAlign.NotSet;
- }
- set {
- if (PanelStyle != null)
- PanelStyle.HorizontalAlign = value;
- else
- ViewState ["HorizontalAlign"] = value;
- }
- }
- [DefaultValue (true)]
- [WebSysDescription ("")]
- [WebCategory ("Layout")]
- public virtual bool Wrap {
- get {
- if (ControlStyleCreated) {
- if (PanelStyle != null)
- return PanelStyle.Wrap;
- else
- return ViewState.GetBool ("Wrap", true);
- }
- return true;
- }
- set {
- if (PanelStyle != null)
- PanelStyle.Wrap = value;
- else
- ViewState ["Wrap"] = value;
- }
- }
-
- [ThemeableAttribute (false)]
- [DefaultValue ("")]
- public virtual string DefaultButton {
- get {
- return ViewState.GetString ("DefaultButton", String.Empty);
- }
- set {
- ViewState ["DefaultButton"] = value;
- }
- }
- [DefaultValue (ContentDirection.NotSet)]
- public virtual ContentDirection Direction {
- get {
- if (ControlStyleCreated) {
- if (PanelStyle != null)
- return PanelStyle.Direction;
- else
- return ViewState ["Direction"] != null ? (ContentDirection) ViewState ["Direction"] : ContentDirection.NotSet;
- }
- return ContentDirection.NotSet;
- }
- set {
- if (PanelStyle != null)
- PanelStyle.Direction = value;
- else
- ViewState ["Direction"] = value;
- }
- }
- [LocalizableAttribute (true)]
- [DefaultValue ("")]
- public virtual string GroupingText {
- get {
- return ViewState.GetString ("GroupingText", String.Empty);
- }
- set {
- ViewState ["GroupingText"] = value;
- }
- }
- [DefaultValue (ScrollBars.None)]
- public virtual ScrollBars ScrollBars {
- get {
- if (ControlStyleCreated) {
- if (PanelStyle != null)
- return PanelStyle.ScrollBars;
- else
- return ViewState ["ScrollBars"] != null ? (ScrollBars) ViewState ["Direction"] : ScrollBars.None;
- }
- return ScrollBars.None;
- }
- set {
- if (PanelStyle != null)
- PanelStyle.ScrollBars = value;
- else
- ViewState ["ScrollBars"] = value;
- }
- }
- #if NET_4_0
- public override bool SupportsDisabledAttribute {
- get { return RenderingCompatibilityLessThan40; }
- }
- #endif
- protected override Style CreateControlStyle ()
- {
- return new PanelStyle (ViewState);
- }
- public override void RenderBeginTag (HtmlTextWriter writer)
- {
- base.RenderBeginTag (writer);
- if (!String.IsNullOrEmpty (GroupingText)) {
- writer.RenderBeginTag (HtmlTextWriterTag.Fieldset);
- writer.RenderBeginTag (HtmlTextWriterTag.Legend);
- writer.Write (GroupingText);
- writer.RenderEndTag ();
- }
- }
- public override void RenderEndTag (HtmlTextWriter writer)
- {
- if (!String.IsNullOrEmpty (GroupingText)) {
- writer.RenderEndTag (); // Fieldset
- }
- base.RenderEndTag (writer);
- }
- #endif
- }
- }
|