2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlControl.cs
index d58f7c8a3ab1a1624cef0fe7fe2e28f3644e93d3..c69c185829b30d1b801c5eb59c3b97d0be18f9ea 100644 (file)
-//
-// System.Web.UI.HtmlControls.HtmlControl.cs
-//
-// Author:
-//   Bob Smith <bob@thestuff.net>
-//
-// (C) Bob Smith
-//
+//\r
+// System.Web.UI.HtmlControls.HtmlControl.cs\r
+//\r
+// Author\r
+//   Bob Smith <bob@thestuff.net>\r
+//\r
+//\r
+// (C) Bob Smith\r
+//\r
+\r
+using System;\r
+using System.ComponentModel;
+using System.ComponentModel.Design;\r
+using System.Globalization;\r
+using System.Web;\r
+using System.Web.UI;\r
+\r
+namespace System.Web.UI.HtmlControls{\r
+       \r
+       [ToolboxItem(false)]
+       [Designer ("System.Web.UI.Design.HtmlIntrinsicControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]\r
+       public abstract class HtmlControl : Control, IAttributeAccessor\r
+       {\r
+               internal string _tagName;\r
+               private AttributeCollection _attributes;\r
 
-using System;
-using System.Web;
-using System.Web.UI;
-
-namespace System.Web.UI.HtmlControls
-{
-        public abstract class HtmlControl : Control, IAttributeAccessor
-        {
-                private string _tagName = "span";
-//TODO: Is this correct, or is the StateBag really the ViewState?
-                private AttributeCollection _attributes = new AttributeCollection(new StateBag(true));
-                private bool _disabled = false;
-                public HtmlControl() {}
-                public HtmlControl(string tag)
-                {
-                        if(tag != null && tag != "") _tagName = tag;
-                }
-                public AttributeCollection Attributes
-                {
-                        get
-                        {
-                                return _attributes;
-                        }
-                }
-                public bool Disabled
-                {
-                        get
-                        {
-                                return _disabled;
-                        }
-                        set
-                        {
-                                _disabled = value;
-                        }
-                }
-                public CssStyleCollection Style
-                {
-                        get
-                        {
-                                return _attributes.CssStyle;
-                        }
-                }
-                public virtual string TagName
-                {
-                        get
-                        {
-                                return _tagName;
-                        }
-                }
-        }
-}
+               \r
+               public HtmlControl() : this ("span") {}\r
+               \r
+               public HtmlControl(string tag)\r
+               {\r
+                       _tagName = tag;\r
+               }\r
+               \r
+               protected override ControlCollection CreateControlCollection ()\r
+               {\r
+                       return new EmptyControlCollection (this);\r
+               }\r
+\r
+               internal static string AttributeToString(int n){\r
+                       if (n != -1)return n.ToString(NumberFormatInfo.InvariantInfo);\r
+                       return null;\r
+               }\r
+               \r
+               internal static string AttributeToString(string s){\r
+                       if (s != null && s.Length != 0) return s;\r
+                       return null;\r
+               }\r
+               \r
+               internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){\r
+                       string attr = Attributes[attribName];\r
+                       if (attr != null){\r
+                               if (attr.Length != 0){\r
+                                       try{\r
+                                               attr = ResolveUrl(attr);\r
+                                       }\r
+                                       catch (Exception) {\r
+                                               throw new HttpException(attribName + " property had malformed url");\r
+                                       }\r
+                                       writer.WriteAttribute(attribName, attr);\r
+                                       Attributes.Remove(attribName);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               string System.Web.UI.IAttributeAccessor.GetAttribute(string name){\r
+                       return Attributes[name];\r
+               }\r
+               \r
+               void System.Web.UI.IAttributeAccessor.SetAttribute(string name, string value){\r
+                       Attributes[name] = value;\r
+               }\r
+               \r
+               protected virtual void RenderBeginTag (HtmlTextWriter writer)\r
+               {\r
+                       writer.WriteBeginTag (TagName);\r
+                       RenderAttributes (writer);\r
+                       writer.Write ('>');\r
+               }\r
+\r
+               protected override void Render (HtmlTextWriter writer)\r
+               {\r
+                       RenderBeginTag (writer);\r
+               }\r
+               \r
+               protected virtual void RenderAttributes(HtmlTextWriter writer){\r
+                       if (ID != null){\r
+                               writer.WriteAttribute("id",ClientID);\r
+                       }\r
+                       Attributes.Render(writer);\r
+               }\r
+               \r
+               [Browsable(false)]\r
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
+               public AttributeCollection Attributes\r
+               {\r
+                       get { \r
+                               if (_attributes == null)\r
+                                       _attributes = new AttributeCollection (ViewState);\r
+                               return _attributes;\r
+                       }\r
+               }\r
+\r
+               [DefaultValue("")]\r
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
+               [WebCategory("Behavior")]\r
+               public bool Disabled\r
+               {\r
+                       get {
+                               string disableAttr = Attributes["disabled"] as string;
+                               return (disableAttr != null);
+                        }\r
+                       set {
+                                if (!value)
+                                        Attributes.Remove ("disabled");
+                                else
+                                        Attributes["disabled"] = "disabled";
+                        }\r
+               }\r
+\r
+               [Browsable(false)]\r
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
+               public CssStyleCollection Style\r
+               {\r
+                       get { return Attributes.CssStyle; }\r
+               }\r
+\r
+               [DefaultValue("")]\r
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
+               [WebCategory("Appearance")]\r
+               public virtual string TagName\r
+               {\r
+                       get { return _tagName; }\r
+               }\r
+\r
+               protected override bool ViewStateIgnoresCase \r
+               {\r
+                       get {\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+}\r