2005-10-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Style.cs
index 7ded5926fb213dd56ee7906a0e17434f52f83397..91861f5733369d93f70853f51e4c50619287e94c 100644 (file)
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class:     Style\r
- *\r
- * Author:  Gaurav Vaish\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
- * Implementation: yes\r
- * Status:  100%\r
- *\r
- * (C) Gaurav Vaish (2001)\r
- */\r
-\r
-using System;\r
-using System.Text;\r
-using System.Collections;\r
-using System.Drawing;\r
-using System.Globalization;\r
-using System.ComponentModel;\r
-using System.Web;\r
-using System.Web.UI;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
-       [ToolboxItem(false)]\r
-       [TypeConverter(typeof(ExpandableObjectConverter))]\r
-       public class Style : Component , IStateManager\r
-       {\r
-               internal static int MARKED      = (0x01 << 0);\r
-               internal static int BACKCOLOR   = (0x01 << 1);\r
-               internal static int BORDERCOLOR = (0x01 << 2);\r
-               internal static int BORDERSTYLE = (0x01 << 3);\r
-               internal static int BORDERWIDTH = (0x01 << 4);\r
-               internal static int CSSCLASS    = (0x01 << 5);\r
-               internal static int FORECOLOR   = (0x01 << 6);\r
-               internal static int HEIGHT      = (0x01 << 7);\r
-               internal static int WIDTH       = (0x01 << 8);\r
-               internal static int FONT_BOLD   = (0x01 << 9);\r
-               internal static int FONT_ITALIC = (0x01 << 10);\r
-               internal static int FONT_NAMES  = (0x01 << 11);\r
-               internal static int FONT_SIZE   = (0x01 << 12);\r
-               internal static int FONT_STRIKE = (0x01 << 13);\r
-               internal static int FONT_OLINE  = (0x01 << 14);\r
-               internal static int FONT_ULINE  = (0x01 << 15);\r
-\r
-               internal static string selectionBitString = "_SystemWebUIWebControlsStyle_SBS";\r
-\r
-               private StateBag viewState;\r
-               private int      selectionBits;\r
-               private bool     selfStateBag;\r
-\r
-               private FontInfo font;\r
-\r
-               public Style()\r
-               {\r
-                       Initialize(null);\r
-                       selfStateBag = true;\r
-               }\r
-\r
-               public Style(StateBag bag): base()\r
-               {\r
-                       Initialize(bag);\r
-                       selfStateBag = false;\r
-               }\r
-\r
-               private void Initialize(StateBag bag)\r
-               {\r
-                       viewState     = bag;\r
-                       selectionBits = 0x00;\r
-               }\r
-\r
-               protected internal StateBag ViewState\r
-               {\r
-                       get\r
-                       {\r
-                               if(viewState == null)\r
-                               {\r
-                                       viewState = new StateBag(false);\r
-                                       if(IsTrackingViewState)\r
-                                               viewState.TrackViewState();\r
-                               }\r
-                               return viewState;\r
-                       }\r
-               }\r
-\r
-               internal bool IsSet(int bit)\r
-               {\r
-                       return ( (selectionBits & bit) != 0x00);\r
-               }\r
-\r
-               internal virtual void Set(int bit)\r
-               {\r
-                       selectionBits |= bit;\r
-                       if(IsTrackingViewState)\r
-                               selectionBits |= MARKED;\r
-               }\r
-\r
-               public Color BackColor\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(BACKCOLOR))\r
-                                       return (Color)ViewState["BackColor"];\r
-                               return Color.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["BackColor"] = value;\r
-                               Set(BACKCOLOR);\r
-                       }\r
-               }\r
-\r
-               public Color BorderColor\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(BORDERCOLOR))\r
-                                       return (Color)ViewState["BorderColor"];\r
-                               return Color.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["BorderColor"] = value;\r
-                               Set(BORDERCOLOR);\r
-                       }\r
-               }\r
-\r
-               public BorderStyle BorderStyle\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(BORDERSTYLE))\r
-                                       return (BorderStyle)ViewState["BorderStyle"];\r
-                               return BorderStyle.NotSet;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["BorderStyle"] = value;\r
-                               Set(BORDERSTYLE);\r
-                       }\r
-               }\r
-\r
-               public Unit BorderWidth\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(BORDERWIDTH))\r
-                                       return (Unit)ViewState["BorderWidth"];\r
-                               return Unit.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["BorderWidth"] = value;\r
-                               Set(BORDERWIDTH);\r
-                       }\r
-               }\r
-\r
-               public string CssClass\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(CSSCLASS))\r
-                                       return (string)ViewState["CssClass"];\r
-                               return string.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["CssClass"] = value;\r
-                               Set(CSSCLASS);\r
-                       }\r
-               }\r
-\r
-               public Color ForeColor\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(FORECOLOR))\r
-                                       return (Color)ViewState["ForeColor"];\r
-                               return Color.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["ForeColor"] = value;\r
-                               Set(FORECOLOR);\r
-                       }\r
-               }\r
-\r
-               public Unit Height\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(HEIGHT))\r
-                                       return (Unit)ViewState["Height"];\r
-                               return Unit.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["Height"] = value;\r
-                               Set(HEIGHT);\r
-                       }\r
-               }\r
-\r
-               public Unit Width\r
-               {\r
-                       get\r
-                       {\r
-                               if(IsSet(WIDTH))\r
-                                       return (Unit)ViewState["Width"];\r
-                               return Unit.Empty;\r
-                       }\r
-                       set\r
-                       {\r
-                               ViewState["Width"] = value;\r
-                               Set(WIDTH);\r
-                       }\r
-               }\r
-\r
-               public FontInfo Font\r
-               {\r
-                       get\r
-                       {\r
-                               if(font==null)\r
-                                       font = new FontInfo(this);\r
-                               return font;\r
-                       }\r
-               }\r
-\r
-               protected internal virtual bool IsEmpty\r
-               {\r
-                       get { return (selectionBits == 0); }\r
-               }\r
-\r
-               private void AddColor(HtmlTextWriter writer, HtmlTextWriterStyle style, Color color)\r
-               {\r
-                       if(!color.IsEmpty)\r
-                               writer.AddStyleAttribute(style, ColorTranslator.ToHtml(color));\r
-               }\r
-\r
-               private static string StringArrayToString(string[] array, char separator)\r
-               {\r
-                       if(array.Length == 0)\r
-                               return String.Empty;\r
-                       StringBuilder sb = new StringBuilder();\r
-                       for(int i=0; i < array.Length; i++)\r
-                       {\r
-                               if(i==0)\r
-                               {\r
-                                       sb.Append(array[0]);\r
-                               } else\r
-                               {\r
-                                       sb.Append(separator);\r
-                                       sb.Append(array[i]);\r
-                               }\r
-                       }\r
-                       return sb.ToString();\r
-               }\r
-\r
-               public void AddAttributesToRender(HtmlTextWriter writer)\r
-               {\r
-                       AddAttributesToRender(writer, null);\r
-               }\r
-\r
-               public virtual void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)\r
-               {\r
-                       if(IsSet(BACKCOLOR))\r
-                       {\r
-                               AddColor(writer, HtmlTextWriterStyle.BackgroundColor, (Color)ViewState["BackColor"]);\r
-                       }\r
-\r
-                       if(IsSet(BORDERCOLOR))\r
-                       {\r
-                               AddColor(writer, HtmlTextWriterStyle.BorderColor, (Color)ViewState["BorderColor"]);\r
-                       }\r
-\r
-                       if(IsSet(FORECOLOR))\r
-                       {\r
-                               AddColor(writer, HtmlTextWriterStyle.Color, (Color)ViewState["ForeColor"]);\r
-                       }\r
-\r
-                       if(IsSet(CSSCLASS))\r
-                       {\r
-                               string cssClass = (string)ViewState["CssClass"];\r
-                               if(cssClass.Length > 0)\r
-                                       writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);\r
-                       }\r
-\r
-                       if(!BorderWidth.IsEmpty)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, BorderWidth.ToString(CultureInfo.InvariantCulture));\r
-                               if(BorderStyle!=BorderStyle.NotSet)\r
-                               {\r
-                                       writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), BorderStyle, "G"));\r
-                               } else\r
-                               {\r
-                                       if(BorderWidth.Value != 0.0)\r
-                                       {\r
-                                               writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");\r
-                                       }\r
-                               }\r
-                       } else\r
-                       {\r
-                               if(BorderStyle!=BorderStyle.NotSet)\r
-                               {\r
-                                       writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), BorderStyle, "G"));\r
-                               }\r
-                       }\r
-\r
-                       if(Font.Names.Length > 0)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, StringArrayToString(Font.Names,','));\r
-                       }\r
-\r
-                       if(!Font.Size.IsEmpty)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, Font.Size.ToString(CultureInfo.InvariantCulture));\r
-                       }\r
-\r
-                       if(Font.Bold)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold");\r
-                       }\r
-\r
-                       if(Font.Italic)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.FontStyle, "italic");\r
-                       }\r
-\r
-                       string textDecoration = String.Empty;\r
-                       if(Font.Strikeout)\r
-                       {\r
-                               textDecoration += " strikeout";\r
-                       }\r
-                       if(Font.Underline)\r
-                       {\r
-                               textDecoration += " underline";\r
-                       }\r
-                       if(Font.Overline)\r
-                       {\r
-                               textDecoration += " overline";\r
-                       }\r
-                       if(textDecoration.Length > 0)\r
-                       {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, textDecoration);\r
-                       }\r
-\r
-                       Unit u = Unit.Empty;\r
-                       if(IsSet(HEIGHT))\r
-                       {\r
-                               u = (Unit)ViewState["Height"];\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));\r
-                       }\r
-                       if(IsSet(WIDTH))\r
-                       {\r
-                               u = (Unit)ViewState["Width"];\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));\r
-                       }\r
-               }\r
-\r
-               public virtual void CopyFrom(Style source)\r
-               {\r
-                       if(source!=null && !source.IsEmpty)\r
-                       {\r
-                               Font.CopyFrom(source.Font);\r
-                               if(source.Height!=Unit.Empty)\r
-                               {\r
-                                       Height = source.Height;\r
-                               }\r
-                               if(source.Width!=Unit.Empty)\r
-                               {\r
-                                       Width = source.Width;\r
-                               }\r
-                               if(source.BorderColor!=Color.Empty)\r
-                               {\r
-                                       BorderColor = source.BorderColor;\r
-                               }\r
-                               if(source.BorderWidth!=Unit.Empty)\r
-                               {\r
-                                       BorderWidth = source.BorderWidth;\r
-                               }\r
-                               if(source.BorderStyle!=BorderStyle.NotSet)\r
-                               {\r
-                                       BorderStyle = source.BorderStyle;\r
-                               }\r
-                               if(source.BackColor!=Color.Empty)\r
-                               {\r
-                                       BackColor = source.BackColor;\r
-                               }\r
-                               if(source.CssClass!=String.Empty)\r
-                               {\r
-                                       CssClass = source.CssClass;\r
-                               }\r
-                               if(source.ForeColor!=Color.Empty)\r
-                               {\r
-                                       ForeColor = source.ForeColor;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public virtual void MergeWith(Style with)\r
-               {\r
-                       if(with!=null && !with.IsEmpty)\r
-                       {\r
-                               if(IsEmpty)\r
-                               {\r
-                                       CopyFrom(with);\r
-                                       return;\r
-                               }\r
-\r
-                               Font.MergeWith(with.Font);\r
-                               if(!IsSet(HEIGHT) && with.Height!=Unit.Empty)\r
-                               {\r
-                                       Height = with.Height;\r
-                               }\r
-                               if(!IsSet(WIDTH) && with.Width!=Unit.Empty)\r
-                               {\r
-                                       Width = with.Width;\r
-                               }\r
-                               if(!IsSet(BORDERCOLOR) && with.BorderColor!=Color.Empty)\r
-                               {\r
-                                       BorderColor = with.BorderColor;\r
-                               }\r
-                               if(!IsSet(BORDERWIDTH) && with.BorderWidth!=Unit.Empty)\r
-                               {\r
-                                       BorderWidth = with.BorderWidth;\r
-                               }\r
-                               if(!IsSet(BORDERSTYLE) && with.BorderStyle!=BorderStyle.NotSet)\r
-                               {\r
-                                       BorderStyle = with.BorderStyle;\r
-                               }\r
-                               if(!IsSet(BACKCOLOR) && with.BackColor!=Color.Empty)\r
-                               {\r
-                                       BackColor = with.BackColor;\r
-                               }\r
-                               if(!IsSet(CSSCLASS) && with.CssClass!=String.Empty)\r
-                               {\r
-                                       CssClass = with.CssClass;\r
-                               }\r
-                               if(!IsSet(FORECOLOR) && with.ForeColor!=Color.Empty)\r
-                               {\r
-                                       ForeColor = with.ForeColor;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public virtual void Reset()\r
-               {\r
-                       if(IsSet(BACKCOLOR))\r
-                               ViewState.Remove("BackColor");\r
-                       if(IsSet(BORDERCOLOR))\r
-                               ViewState.Remove("BorderColor");\r
-                       if(IsSet(BORDERSTYLE))\r
-                               ViewState.Remove("BorderStyle");\r
-                       if(IsSet(BORDERWIDTH))\r
-                               ViewState.Remove("BorderWidth");\r
-                       if(IsSet(CSSCLASS))\r
-                               ViewState.Remove("CssClass");\r
-                       if(IsSet(FORECOLOR))\r
-                               ViewState.Remove("ForeColor");\r
-                       if(IsSet(HEIGHT))\r
-                               ViewState.Remove("Height");\r
-                       if(IsSet(WIDTH))\r
-                               ViewState.Remove("Width");\r
-                       if(font!=null)\r
-                               font.Reset();\r
-                       selectionBits = 0x00;\r
-               }\r
-\r
-               protected bool IsTrackingViewState\r
-               {\r
-                       get\r
-                       {\r
-                               return ( (selectionBits & MARKED) != 0x00 );\r
-                       }\r
-               }\r
-\r
-               protected internal virtual void TrackViewState()\r
-               {\r
-                       if(viewState!=null)\r
-                               ViewState.TrackViewState();\r
-                       Set(MARKED);\r
-               }\r
-\r
-               protected internal virtual object SaveViewState()\r
-               {\r
-                       if(viewState != null)\r
-                       {\r
-                               if(IsSet(MARKED))\r
-                               {\r
-                                       ViewState[selectionBitString] = selectionBits;\r
-                               }\r
-                               if(selfStateBag)\r
-                               {\r
-                                       return ViewState.SaveViewState();\r
-                               }\r
-                       }\r
-                       return null;\r
-               }\r
-\r
-               protected internal void LoadViewState(object state)\r
-               {\r
-                       if(state!=null && selfStateBag)\r
-                       {\r
-                               ViewState.LoadViewState(state);\r
-                       }\r
-                       if(viewState!=null)\r
-                       {\r
-                               selectionBits = (int)ViewState[selectionBitString];\r
-                       }\r
-               }\r
-\r
-               void IStateManager.LoadViewState(object state)\r
-               {\r
-                       LoadViewState(state);\r
-               }\r
-\r
-               object IStateManager.SaveViewState()\r
-               {\r
-                       return SaveViewState();\r
-               }\r
-\r
-               void IStateManager.TrackViewState()\r
-               {\r
-                       TrackViewState();\r
-               }\r
-\r
-               bool IStateManager.IsTrackingViewState\r
-               {\r
-                       get\r
-                       {\r
-                               return IsTrackingViewState;\r
-                       }\r
-               }\r
-\r
-               public override string ToString()\r
-               {\r
-                       return String.Empty;\r
-               }\r
-       }\r
-}\r
+// 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.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Peter Dennis Bartok     (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+using System.Drawing;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+       // CAS
+       [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       // attributes
+#if NET_2_0
+// Not until we actually have StyleConverter
+//     [TypeConverter(typeof(System.Web.UI.WebControls.StyleConverter))]
+#else
+       [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
+#endif
+       [ToolboxItem("")]
+       public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager 
+       {
+               [Flags]
+               internal enum Styles 
+               {
+                       None            = 0,
+                       BackColor       = 0x00000001,
+                       BorderColor     = 0x00000002,
+                       BorderStyle     = 0x00000004,
+                       BorderWidth     = 0x00000008,
+                       CssClass        = 0x00000010,
+                       Font            = 0x00000020,
+                       ForeColor       = 0x00000040,
+                       Height          = 0x00000080,
+                       Width           = 0x00000100,
+
+                       // from TableStyle (which doesn't override IsEmpty)
+                       BackImageUrl    = 0x00000200,
+                       CellPadding     = 0x00000400,
+                       CellSpacing     = 0x00000800,
+                       GridLines       = 0x00001000,
+                       HorizontalAlign = 0x00002000,
+
+                       // from TableItemStyle (which doesn't override IsEmpty neither)
+                       VerticalAlign   = 0x00004000,
+                       Wrap            = 0x00008000,
+
+                       // from DataGridPagerStyle (and, once again, no IsEmpty override)
+                       Mode            = 0x00010000,
+                       NextPageText    = 0x00020000,
+                       PageButtonCount = 0x00040000,
+                       Position        = 0x00080000,
+                       PrevPageText    = 0x00100000,
+                       Visible         = 0x00200000
+                       
+               }
+
+               #region Fields
+               internal Styles         styles;
+               internal StateBag       viewstate;
+               private FontInfo        fontinfo;
+               private bool            tracking;
+#if NET_2_0
+               private string          registered_class;
+#endif
+               #endregion      // Fields
+
+               #region Public Constructors
+               public Style() : this(new StateBag()) 
+               {
+               }
+
+               public Style(System.Web.UI.StateBag bag) 
+               {
+                       if (bag != null) {
+                               viewstate = bag;
+                       } else {
+                               viewstate = new StateBag();
+                       }
+                       tracking = false;
+               }
+               #endregion      // Public Constructors
+
+               #region Public Instance Properties
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Color), "")]
+               [NotifyParentProperty(true)]
+               [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Color BackColor 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.BackColor) == 0) 
+                               {
+                                       return Color.Empty;
+                               }
+
+                               return (Color)viewstate["BackColor"];
+                       }
+
+                       set 
+                       {
+                               viewstate["BackColor"] = value;
+                               styles |= Styles.BackColor;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Color), "")]
+               [NotifyParentProperty(true)]
+               [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Color BorderColor 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.BorderColor) == 0) 
+                               {
+                                       return Color.Empty;
+                               }
+
+                               return (Color)viewstate["BorderColor"];
+                       }
+
+                       set 
+                       {
+                               viewstate["BorderColor"] = value;
+                               styles |= Styles.BorderColor;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(BorderStyle.NotSet)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public BorderStyle BorderStyle 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.BorderStyle) == 0) 
+                               {
+                                       return BorderStyle.NotSet;
+                               }
+
+                               return (BorderStyle)viewstate["BorderStyle"];
+                       }
+
+                       set 
+                       {
+                               viewstate["BorderStyle"] = value;
+                               styles |= Styles.BorderStyle;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Unit), "")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Unit BorderWidth 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.BorderWidth) == 0) 
+                               {
+                                       return Unit.Empty;
+                               }
+
+                               return (Unit)viewstate["BorderWidth"];
+                       }
+
+                       set 
+                       {
+                               if (value.Value < 0) 
+                               {
+                                       throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
+                               }
+
+                               viewstate["BorderWidth"] = value;
+                               styles |= Styles.BorderWidth;
+                       }
+               }
+
+               [DefaultValue("")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public string CssClass 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.CssClass) == 0) 
+                               {
+                                       return string.Empty;
+                               }
+
+                               return (string)viewstate["CssClass"];
+                       }
+
+                       set 
+                       {
+                               viewstate["CssClass"] = value;
+                               styles |= Styles.CssClass;
+                       }
+               }
+
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public FontInfo Font 
+               {
+                       get 
+                       {
+                               if (fontinfo == null) 
+                               {
+                                       fontinfo = new FontInfo(this);
+                               }
+                               return fontinfo;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Color), "")]
+               [NotifyParentProperty(true)]
+               [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Color ForeColor 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.ForeColor) == 0) 
+                               {
+                                       return Color.Empty;
+                               }
+
+                               return (Color)viewstate["ForeColor"];
+                       }
+
+                       set 
+                       {
+                               viewstate["ForeColor"] = value;
+                               styles |= Styles.ForeColor;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Unit), "")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Unit Height 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.Height) == 0) 
+                               {
+                                       return Unit.Empty;
+                               }
+
+                               return (Unit)viewstate["Height"];
+                       }
+
+                       set 
+                       {
+                               if (value.Value < 0) 
+                               {
+                                       throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
+                               }
+
+                               viewstate["Height"] = value;
+                               styles |= Styles.Height;
+                       }
+               }
+
+#if !NET_2_0
+               [Bindable(true)]
+#endif
+               [DefaultValue(typeof (Unit), "")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
+               public Unit Width 
+               {
+                       get 
+                       {
+                               if ((styles & Styles.Width) == 0) 
+                               {
+                                       return Unit.Empty;
+                               }
+
+                               return (Unit)viewstate["Width"];
+                       }
+
+                       set 
+                       {
+                               if (value.Value < 0) 
+                               {
+                                       throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
+                               }
+
+                               viewstate["Width"] = value;
+                               styles |= Styles.Width;
+                       }
+               }
+               #endregion      // Public Instance Properties
+
+               #region Protected Instance Properties
+#if NET_2_0
+               [Browsable (false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public virtual bool IsEmpty 
+#else
+               protected internal virtual bool IsEmpty 
+#endif
+               {
+                       get 
+                       {
+                               return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
+                       }
+               }
+
+               protected bool IsTrackingViewState 
+               {
+                       get 
+                       {
+                               return tracking;
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               protected internal StateBag ViewState 
+               {
+                       get 
+                       {
+                               return viewstate;
+                       }
+               }
+               #endregion      // Protected Instance Properties
+
+               #region Public Instance Methods
+               public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
+               {
+                       AddAttributesToRender(writer, null);
+               }
+
+               public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
+               {
+                       if ((styles & Styles.CssClass) != 0) 
+                       {
+                               string s = (string)viewstate["CssClass"];
+                               if (s != string.Empty)
+                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
+                       }
+
+                       WriteStyleAttributes (writer);
+               }
+
+               void WriteStyleAttributes (HtmlTextWriter writer) 
+               {
+                       string          s;
+                       Color           color;
+                       BorderStyle     bs;
+                       Unit            u;
+
+                       if ((styles & Styles.BackColor) != 0) {
+                               color = (Color)viewstate["BackColor"];
+                               if (!color.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.BorderColor) != 0) {
+                               color = (Color)viewstate["BorderColor"];
+                               if (!color.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.BorderStyle) != 0) {
+                               bs = (BorderStyle)viewstate["BorderStyle"];
+                               if (bs != BorderStyle.NotSet) 
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
+                       }
+
+                       if ((styles & Styles.BorderWidth) != 0) {
+                               u = (Unit)viewstate["BorderWidth"];
+                               if (!u.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
+                       }
+
+                       if ((styles & Styles.ForeColor) != 0) {
+                               color = (Color)viewstate["ForeColor"];
+                               if (!color.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.Height) != 0) {
+                               u = (Unit)viewstate["Height"];
+                               if (!u.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
+                       }
+
+                       if ((styles & Styles.Width) != 0) {
+                               u = (Unit)viewstate["Width"];
+                               if (!u.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
+                       }
+
+                       if (fontinfo != null) {
+                               // Fonts are a bit weird
+                               if (fontinfo.Name != string.Empty) {
+                                       s = fontinfo.Names[0];
+                                       for (int i = 1; i < fontinfo.Names.Length; i++)
+                                               s += "," + fontinfo.Names[i];
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
+                               }
+
+                               if (fontinfo.Bold)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
+
+                               if (fontinfo.Italic)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
+
+                               if (!fontinfo.Size.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
+
+                               // These styles are munged into a attribute decoration
+                               s = string.Empty;
+
+                               if (fontinfo.Overline)
+                                       s += "overline ";
+
+                               if (fontinfo.Strikeout)
+                                       s += "line-through ";
+
+                               if (fontinfo.Underline)
+                                       s += "underline ";
+
+                               if (s != string.Empty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
+                       }
+               }
+
+               void FillStyleAttributes (CssStyleCollection attributes) 
+               {
+                       string          s;
+                       Color           color;
+                       BorderStyle     bs;
+                       Unit            u;
+
+                       if ((styles & Styles.BackColor) != 0)
+                       {
+                               color = (Color)viewstate["BackColor"];
+                               if (!color.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.BorderColor) != 0) 
+                       {
+                               color = (Color)viewstate["BorderColor"];
+                               if (!color.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.BorderStyle) != 0) 
+                       {
+                               bs = (BorderStyle)viewstate["BorderStyle"];
+                               if (bs != BorderStyle.NotSet) 
+                                       attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString());
+                       }
+
+                       if ((styles & Styles.BorderWidth) != 0) 
+                       {
+                               u = (Unit)viewstate["BorderWidth"];
+                               if (!u.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString());
+                       }
+
+                       if ((styles & Styles.ForeColor) != 0) 
+                       {
+                               color = (Color)viewstate["ForeColor"];
+                               if (!color.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+                       }
+
+                       if ((styles & Styles.Height) != 0) 
+                       {
+                               u = (Unit)viewstate["Height"];
+                               if (!u.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
+                       }
+
+                       if ((styles & Styles.Width) != 0) 
+                       {
+                               u = (Unit)viewstate["Width"];
+                               if (!u.IsEmpty)
+                                       attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
+                       }
+
+                       if (fontinfo != null) {
+                               // Fonts are a bit weird
+                               if (fontinfo.Name != string.Empty) 
+                               {
+                                       s = fontinfo.Names[0];
+                                       for (int i = 1; i < fontinfo.Names.Length; i++) 
+                                       {
+                                               s += "," + fontinfo.Names[i];
+                                       }
+                                       attributes.Add (HtmlTextWriterStyle.FontFamily, s);
+                               }
+
+                               if (fontinfo.Bold) 
+                               {
+                                       attributes.Add (HtmlTextWriterStyle.FontWeight, "bold");
+                               }
+
+                               if (fontinfo.Italic) 
+                               {
+                                       attributes.Add (HtmlTextWriterStyle.FontStyle, "italic");
+                               }
+
+                               if (!fontinfo.Size.IsEmpty) 
+                               {
+                                       attributes.Add (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
+                               }
+
+                               // These styles are munged into a attribute decoration
+                               s = string.Empty;
+
+                               if (fontinfo.Overline) 
+                               {
+                                       s += "overline ";
+                               }
+
+                               if (fontinfo.Strikeout) 
+                               {
+                                       s += "line-through ";
+                               }
+
+                               if (fontinfo.Underline) 
+                               {
+                                       s += "underline ";
+                               }
+
+                               if (s != string.Empty) 
+                               {
+                                       attributes.Add (HtmlTextWriterStyle.TextDecoration, s);
+                               }
+                       }
+               }
+
+               public virtual void CopyFrom(Style s) 
+               {
+                       if ((s == null) || s.IsEmpty) 
+                       {
+                               return;
+                       }
+
+                       if (s.fontinfo != null) 
+                       {
+                               Font.CopyFrom(s.fontinfo);
+                       }
+
+                       if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+                       {
+                               this.BackColor = s.BackColor;
+                       }
+                       if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
+                       {
+                               this.BorderColor = s.BorderColor;
+                       }
+                       if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
+                       {
+                               this.BorderStyle = s.BorderStyle;
+                       }
+                       if (((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty))
+                       {
+                               this.BorderWidth = s.BorderWidth;
+                       }
+                       if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
+                       {
+                               this.CssClass = s.CssClass;
+                       }
+                       if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
+                       {
+                               this.ForeColor = s.ForeColor;
+                       }
+                       if (((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty))
+                       {
+                               this.Height = s.Height;
+                       }
+                       if (((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty))
+                       {
+                               this.Width = s.Width;
+                       }
+               }
+
+               public virtual void MergeWith(Style s) 
+               {
+                       if ((s == null) || (s.IsEmpty))
+                       {
+                               return;
+                       }
+
+                       if (s.fontinfo != null) 
+                       {
+                               Font.MergeWith(s.fontinfo);
+                       }
+
+                       if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+                       {
+                               this.BackColor = s.BackColor;
+                       }
+                       if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty)) 
+                       {
+                               this.BorderColor = s.BorderColor;
+                       }
+                       if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet)) 
+                       {
+                               this.BorderStyle = s.BorderStyle;
+                       }
+                       if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty)) 
+                       {
+                               this.BorderWidth = s.BorderWidth;
+                       }
+                       if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty)) 
+                       {
+                               this.CssClass = s.CssClass;
+                       }
+                       if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty)) 
+                       {
+                               this.ForeColor = s.ForeColor;
+                       }
+                       if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty)) 
+                       {
+                               this.Height = s.Height;
+                       }
+                       if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty)) 
+                       {
+                               this.Width = s.Width;
+                       }
+               }
+
+               /*
+               internal void Print ()
+               {
+                       Console.WriteLine ("BackColor: {0}", BackColor);
+                       Console.WriteLine ("BorderColor: {0}", BorderColor);
+                       Console.WriteLine ("BorderStyle: {0}", BorderStyle);
+                       Console.WriteLine ("BorderWidth: {0}", BorderWidth);
+                       Console.WriteLine ("CssClass: {0}", CssClass);
+                       Console.WriteLine ("ForeColor: {0}", ForeColor);
+                       Console.WriteLine ("Height: {0}", Height);
+                       Console.WriteLine ("Width: {0}", Width);
+               }
+               */
+
+               public virtual void Reset() 
+               {
+                       viewstate.Remove("BackColor");
+                       viewstate.Remove("BorderColor");
+                       viewstate.Remove("BorderStyle");
+                       viewstate.Remove("BorderWidth");
+                       viewstate.Remove("CssClass");
+                       viewstate.Remove("ForeColor");
+                       viewstate.Remove("Height");
+                       viewstate.Remove("Width");
+                       if (fontinfo != null) 
+                       {
+                               fontinfo.Reset();
+                       }
+                       styles = Styles.None;
+               }
+#if ONLY_1_1
+               public override string ToString() 
+               {
+                       return string.Empty;
+               }
+#endif
+               #endregion      // Public Instance Methods
+
+               #region Protected Instance Methods
+               protected internal void LoadViewState(object state) 
+               {
+                       viewstate.LoadViewState(state);
+
+                       // Update our style
+                       this.styles = Styles.None;
+
+                       if (viewstate["BackColor"] != null) 
+                       {
+                               styles |= Styles.BackColor;
+                       }
+                       if (viewstate["BorderColor"] != null) 
+                       {
+                               styles |= Styles.BorderColor;
+                       }
+                       if (viewstate["BorderStyle"] != null) 
+                       {
+                               styles |= Styles.BorderStyle;
+                       }
+                       if (viewstate["BorderWidth"] != null) 
+                       {
+                               styles |= Styles.BorderWidth;
+                       }
+                       if (viewstate["CssClass"] != null) 
+                       {
+                               styles |= Styles.CssClass;
+                       }
+                       if (viewstate["ForeColor"] != null) 
+                       {
+                               styles |= Styles.ForeColor;
+                       }
+                       if (viewstate["Height"] != null) 
+                       {
+                               styles |= Styles.Height;
+                       }
+                       if (viewstate["Width"] != null) 
+                       {
+                               styles |= Styles.Width;
+                       }
+                       if (fontinfo != null) {
+                               fontinfo.LoadViewState();
+                       }
+
+                       LoadViewStateInternal();
+               }
+
+               internal virtual void LoadViewStateInternal()
+               {
+                       // Override me
+               }
+
+               protected internal virtual object SaveViewState () 
+               {
+                       if (styles != Styles.None) 
+                       {
+                               return viewstate.SaveViewState();
+                       }
+                       return null;
+               }
+
+               [MonoTODO]
+               protected internal virtual void SetBit( int bit ) 
+               {
+                       throw new NotImplementedException();
+               }
+
+               protected internal virtual void TrackViewState() 
+               {
+                       tracking = true;
+                       viewstate.TrackViewState();
+               }
+               #endregion      // Protected Instance Methods
+
+               #region IStateManager Properties & Methods
+               void IStateManager.LoadViewState(object state) 
+               {
+                       LoadViewState(state);
+               }
+
+               object IStateManager.SaveViewState() 
+               {
+                       return SaveViewState();
+               }
+
+               void IStateManager.TrackViewState() 
+               {
+                       TrackViewState();
+               }
+
+               bool IStateManager.IsTrackingViewState 
+               {
+                       get 
+                       {
+                               return this.IsTrackingViewState;
+                       }
+               }
+               #endregion      // IStateManager Properties & Methods
+
+#if NET_2_0
+               protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
+               {
+                       FillStyleAttributes (attributes);
+               }
+
+               internal void SetRegisteredCssClass (string name)
+               {
+                       registered_class = name;
+               }
+
+               public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
+               {
+                       CssStyleCollection col = new CssStyleCollection (new StateBag ());
+                       FillStyleAttributes (col, resolver);
+                       return col;
+               }
+
+               [MonoTODO]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               [Browsable(false)]
+               public string RegisteredCssClass {
+                       get {
+                               if (registered_class == null)
+                                       registered_class = String.Empty;
+                               return registered_class;
+                       }
+               }
+
+               internal virtual void CopyTextStylesFrom (Style source)
+               {
+                       // Need to ask lluis if we need fonts, too
+                       if ((styles & Styles.ForeColor) != 0) {
+                               ForeColor = source.ForeColor;
+                       }
+                       if ((styles & Styles.BackColor) != 0) {
+                               BackColor = source.BackColor;
+                       }
+               }
+
+               public void SetDirty ()
+               {
+                       if (viewstate != null)
+                               viewstate.SetDirty (true);
+               }
+#endif
+       }
+}