Page.Validate() is called when CausesValidation=true
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Style.cs
index 77201679e6d1a6309b80280ede28f38d379c4ef0..2651bad626acd0c9bd38e50be21dd7bbdb123260 100644 (file)
 //
 //
 
-using System;
 using System.ComponentModel;
 using System.Drawing;
+using System.Security.Permissions;
 
-namespace System.Web.UI.WebControls 
-{
+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,
+               enum Styles 
+               {
+                       BackColor       = 0x00000008,
+                       BorderColor     = 0x00000010,
+                       BorderStyle     = 0x00000040,
+                       BorderWidth     = 0x00000020,
+                       CssClass        = 0x00000002,
+                       Font            = 0x00000001,
+                       ForeColor       = 0x00000004,
                        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;
+               private int styles;
                internal StateBag       viewstate;
                private FontInfo        fontinfo;
                private bool            tracking;
@@ -96,7 +84,9 @@ namespace System.Web.UI.WebControls
                #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))]
@@ -106,7 +96,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.BackColor) == 0
+                               if (!CheckBit ((int) Styles.BackColor)
                                {
                                        return Color.Empty;
                                }
@@ -117,11 +107,13 @@ namespace System.Web.UI.WebControls
                        set 
                        {
                                viewstate["BackColor"] = value;
-                               styles |= Styles.BackColor;
+                               SetBit ((int) Styles.BackColor);
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(typeof (Color), "")]
                [NotifyParentProperty(true)]
                [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
@@ -131,7 +123,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.BorderColor) == 0
+                               if (!CheckBit ((int) Styles.BorderColor)
                                {
                                        return Color.Empty;
                                }
@@ -142,11 +134,13 @@ namespace System.Web.UI.WebControls
                        set 
                        {
                                viewstate["BorderColor"] = value;
-                               styles |= Styles.BorderColor;
+                               SetBit ((int) Styles.BorderColor);
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(BorderStyle.NotSet)]
                [NotifyParentProperty(true)]
                [WebSysDescription ("")]
@@ -155,7 +149,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.BorderStyle) == 0
+                               if (!CheckBit ((int) Styles.BorderStyle)
                                {
                                        return BorderStyle.NotSet;
                                }
@@ -166,11 +160,13 @@ namespace System.Web.UI.WebControls
                        set 
                        {
                                viewstate["BorderStyle"] = value;
-                               styles |= Styles.BorderStyle;
+                               SetBit ((int) Styles.BorderStyle);
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(typeof (Unit), "")]
                [NotifyParentProperty(true)]
                [WebSysDescription ("")]
@@ -179,7 +175,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.BorderWidth) == 0
+                               if (!CheckBit ((int) Styles.BorderWidth)
                                {
                                        return Unit.Empty;
                                }
@@ -195,7 +191,7 @@ namespace System.Web.UI.WebControls
                                }
 
                                viewstate["BorderWidth"] = value;
-                               styles |= Styles.BorderWidth;
+                               SetBit ((int) Styles.BorderWidth);
                        }
                }
 
@@ -207,7 +203,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.CssClass) == 0
+                               if (!CheckBit ((int) Styles.CssClass)
                                {
                                        return string.Empty;
                                }
@@ -218,7 +214,7 @@ namespace System.Web.UI.WebControls
                        set 
                        {
                                viewstate["CssClass"] = value;
-                               styles |= Styles.CssClass;
+                               SetBit ((int) Styles.CssClass);
                        }
                }
 
@@ -238,7 +234,9 @@ namespace System.Web.UI.WebControls
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(typeof (Color), "")]
                [NotifyParentProperty(true)]
                [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
@@ -248,7 +246,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.ForeColor) == 0
+                               if (!CheckBit ((int) Styles.ForeColor)
                                {
                                        return Color.Empty;
                                }
@@ -259,11 +257,13 @@ namespace System.Web.UI.WebControls
                        set 
                        {
                                viewstate["ForeColor"] = value;
-                               styles |= Styles.ForeColor;
+                               SetBit ((int) Styles.ForeColor);
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(typeof (Unit), "")]
                [NotifyParentProperty(true)]
                [WebSysDescription ("")]
@@ -272,7 +272,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.Height) == 0
+                               if (!CheckBit ((int) Styles.Height)
                                {
                                        return Unit.Empty;
                                }
@@ -288,11 +288,13 @@ namespace System.Web.UI.WebControls
                                }
 
                                viewstate["Height"] = value;
-                               styles |= Styles.Height;
+                               SetBit ((int) Styles.Height);
                        }
                }
 
+#if !NET_2_0
                [Bindable(true)]
+#endif
                [DefaultValue(typeof (Unit), "")]
                [NotifyParentProperty(true)]
                [WebSysDescription ("")]
@@ -301,7 +303,7 @@ namespace System.Web.UI.WebControls
                {
                        get 
                        {
-                               if ((styles & Styles.Width) == 0
+                               if (!CheckBit ((int) Styles.Width)
                                {
                                        return Unit.Empty;
                                }
@@ -317,17 +319,27 @@ namespace System.Web.UI.WebControls
                                }
 
                                viewstate["Width"] = value;
-                               styles |= Styles.Width;
+                               SetBit ((int) 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 
                        {
+#if NET_2_0
+                               return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty) && RegisteredCssClass.Length == 0);
+#else
                                return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
+#endif
                        }
                }
 
@@ -350,6 +362,23 @@ namespace System.Web.UI.WebControls
                }
                #endregion      // Protected Instance Properties
 
+               #region Internal Instance Properties
+               internal bool AlwaysRenderTextDecoration
+               {
+                       get
+                       {
+                               if (viewstate["AlwaysRenderTextDecoration"] == null)
+                                       return false;
+                               return (bool)viewstate["AlwaysRenderTextDecoration"];
+                       }
+                   
+                       set
+                       {
+                               viewstate["AlwaysRenderTextDecoration"] = value;
+                       }
+               }
+               #endregion      // Internal Instance Properties
+               
                #region Public Instance Methods
                public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
                {
@@ -358,66 +387,89 @@ namespace System.Web.UI.WebControls
 
                public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
                {
-                       if ((styles & Styles.CssClass) != 0) 
+#if NET_2_0
+                       if (RegisteredCssClass.Length > 0) {
+                               if (CssClass.Length > 0)
+                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass + " " + RegisteredCssClass);
+                               else
+                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, RegisteredCssClass);
+                       }
+                       else 
+#endif
                        {
-                               string s = (string)viewstate["CssClass"];
-                               if (s != string.Empty)
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
+                               if (CssClass.Length > 0)
+                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
+                               WriteStyleAttributes (writer);
                        }
-
-                       WriteStyleAttributes (writer);
                }
 
                void WriteStyleAttributes (HtmlTextWriter writer) 
                {
-                       string          s;
+#if NET_2_0
+                       CssStyleCollection col = new CssStyleCollection (new StateBag ());
+                       FillStyleAttributes (col, null);
+                       foreach (string key in col.Keys) {
+                               writer.AddStyleAttribute (key, col [key]);
+                       }
+#else
+                       string s;
                        Color           color;
                        BorderStyle     bs;
                        Unit            u;
 
-                       if ((styles & Styles.BackColor) != 0) {
+                       if (CheckBit ((int) Styles.BackColor)) {
                                color = (Color)viewstate["BackColor"];
                                if (!color.IsEmpty)
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
                        }
 
-                       if ((styles & Styles.BorderColor) != 0) {
+                       if (CheckBit ((int) Styles.BorderColor)) {
                                color = (Color)viewstate["BorderColor"];
                                if (!color.IsEmpty)
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
                        }
 
-                       if ((styles & Styles.BorderStyle) != 0) {
+                       bool have_width = false;
+                       if (CheckBit ((int) Styles.BorderWidth)) {
+                               u = (Unit)viewstate["BorderWidth"];
+                               if (!u.IsEmpty) {
+                                       if (u.Value > 0)
+                                               have_width = true;
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
+                               }
+                       }
+
+                       if (CheckBit ((int) Styles.BorderStyle)) {
                                bs = (BorderStyle)viewstate["BorderStyle"];
                                if (bs != BorderStyle.NotSet) 
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
+                               else {
+                                       if (CheckBit ((int) Styles.BorderWidth))
+                                               writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
+                               }
+                       } else if (have_width) {
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
                        }
 
-                       if ((styles & Styles.BorderWidth) != 0) {
-                               u = (Unit)viewstate["BorderWidth"];
-                               if (!u.IsEmpty)
-                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
-                       }
-
-                       if ((styles & Styles.ForeColor) != 0) {
+                       if (CheckBit ((int) Styles.ForeColor)) {
                                color = (Color)viewstate["ForeColor"];
                                if (!color.IsEmpty)
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
                        }
 
-                       if ((styles & Styles.Height) != 0) {
+                       if (CheckBit ((int) Styles.Height)) {
                                u = (Unit)viewstate["Height"];
                                if (!u.IsEmpty)
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
                        }
 
-                       if ((styles & Styles.Width) != 0) {
+                       if (CheckBit ((int) Styles.Width)) {
                                u = (Unit)viewstate["Width"];
                                if (!u.IsEmpty)
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
                        }
 
-                       if (fontinfo != null) {
+                       if (!Font.IsEmpty) {
                                // Fonts are a bit weird
                                if (fontinfo.Name != string.Empty) {
                                        s = fontinfo.Names[0];
@@ -447,118 +499,79 @@ namespace System.Web.UI.WebControls
                                if (fontinfo.Underline)
                                        s += "underline ";
 
-                               if (s != string.Empty)
+                               s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
+                               if (s != "")
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
                        }
+#endif
                }
 
+#if NET_2_0
                void FillStyleAttributes (CssStyleCollection attributes) 
                {
-                       string          s;
                        Color           color;
                        BorderStyle     bs;
                        Unit            u;
 
-                       if ((styles & Styles.BackColor) != 0)
+                       if (CheckBit ((int) Styles.BackColor))
                        {
                                color = (Color)viewstate["BackColor"];
                                if (!color.IsEmpty)
                                        attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
                        }
 
-                       if ((styles & Styles.BorderColor) != 0
+                       if (CheckBit ((int) Styles.BorderColor)
                        {
                                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());
+                       bool have_width = false;
+                       if (CheckBit ((int) Styles.BorderWidth)) {
+                               u = (Unit) viewstate ["BorderWidth"];
+                               if (!u.IsEmpty) {
+                                       if (u.Value > 0)
+                                               have_width = true;
+                                       attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
+                               }
                        }
 
-                       if ((styles & Styles.BorderWidth) != 0) 
-                       {
-                               u = (Unit)viewstate["BorderWidth"];
-                               if (!u.IsEmpty)
-                                       attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString());
+                       if (CheckBit ((int) Styles.BorderStyle)) {
+                               bs = (BorderStyle) viewstate ["BorderStyle"];
+                               if (bs != BorderStyle.NotSet)
+                                       attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
+                               else if (have_width)
+                                               attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
+                       }
+                       else if (have_width) {
+                               attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
                        }
 
-                       if ((styles & Styles.ForeColor) != 0
+                       if (CheckBit ((int) Styles.ForeColor)
                        {
                                color = (Color)viewstate["ForeColor"];
                                if (!color.IsEmpty)
                                        attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
                        }
 
-                       if ((styles & Styles.Height) != 0
+                       if (CheckBit ((int) Styles.Height)
                        {
                                u = (Unit)viewstate["Height"];
                                if (!u.IsEmpty)
                                        attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
                        }
 
-                       if ((styles & Styles.Width) != 0
+                       if (CheckBit ((int) Styles.Width)
                        {
                                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);
-                               }
-                       }
+                       Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
                }
+#endif
 
                public virtual void CopyFrom(Style s) 
                {
@@ -572,35 +585,35 @@ namespace System.Web.UI.WebControls
                                Font.CopyFrom(s.fontinfo);
                        }
 
-                       if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+                       if ((s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
                        {
                                this.BackColor = s.BackColor;
                        }
-                       if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
+                       if ((s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
                        {
                                this.BorderColor = s.BorderColor;
                        }
-                       if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
+                       if ((s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
                        {
                                this.BorderStyle = s.BorderStyle;
                        }
-                       if (((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty))
+                       if ((s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
                        {
                                this.BorderWidth = s.BorderWidth;
                        }
-                       if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
+                       if ((s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
                        {
                                this.CssClass = s.CssClass;
                        }
-                       if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
+                       if ((s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
                        {
                                this.ForeColor = s.ForeColor;
                        }
-                       if (((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty))
+                       if ((s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
                        {
                                this.Height = s.Height;
                        }
-                       if (((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty))
+                       if ((s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
                        {
                                this.Width = s.Width;
                        }
@@ -618,35 +631,35 @@ namespace System.Web.UI.WebControls
                                Font.MergeWith(s.fontinfo);
                        }
 
-                       if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+                       if ((!CheckBit ((int) Styles.BackColor)) && (s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
                        {
                                this.BackColor = s.BackColor;
                        }
-                       if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty)) 
+                       if ((!CheckBit ((int) Styles.BorderColor)) && (s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty)) 
                        {
                                this.BorderColor = s.BorderColor;
                        }
-                       if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet)) 
+                       if ((!CheckBit ((int) Styles.BorderStyle)) && (s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
                        {
                                this.BorderStyle = s.BorderStyle;
                        }
-                       if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty)) 
+                       if ((!CheckBit ((int) Styles.BorderWidth)) && (s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
                        {
                                this.BorderWidth = s.BorderWidth;
                        }
-                       if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty)) 
+                       if ((!CheckBit ((int) Styles.CssClass)) && (s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
                        {
                                this.CssClass = s.CssClass;
                        }
-                       if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty)) 
+                       if ((!CheckBit ((int) Styles.ForeColor)) && (s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
                        {
                                this.ForeColor = s.ForeColor;
                        }
-                       if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty)) 
+                       if ((!CheckBit ((int) Styles.Height)) && (s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
                        {
                                this.Height = s.Height;
                        }
-                       if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty)) 
+                       if ((!CheckBit ((int) Styles.Width)) && (s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
                        {
                                this.Width = s.Width;
                        }
@@ -680,13 +693,14 @@ namespace System.Web.UI.WebControls
                        {
                                fontinfo.Reset();
                        }
-                       styles = Styles.None;
+                       styles = 0;
                }
-
+#if ONLY_1_1
                public override string ToString() 
                {
                        return string.Empty;
                }
+#endif
                #endregion      // Public Instance Methods
 
                #region Protected Instance Methods
@@ -695,43 +709,41 @@ namespace System.Web.UI.WebControls
                        viewstate.LoadViewState(state);
 
                        // Update our style
-                       this.styles = Styles.None;
+                       this.styles = 0;
 
                        if (viewstate["BackColor"] != null) 
                        {
-                               styles |= Styles.BackColor;
+                               styles |= (int) Styles.BackColor;
                        }
                        if (viewstate["BorderColor"] != null) 
                        {
-                               styles |= Styles.BorderColor;
+                               styles |= (int) Styles.BorderColor;
                        }
                        if (viewstate["BorderStyle"] != null) 
                        {
-                               styles |= Styles.BorderStyle;
+                               styles |= (int) Styles.BorderStyle;
                        }
                        if (viewstate["BorderWidth"] != null) 
                        {
-                               styles |= Styles.BorderWidth;
+                               styles |= (int) Styles.BorderWidth;
                        }
                        if (viewstate["CssClass"] != null) 
                        {
-                               styles |= Styles.CssClass;
+                               styles |= (int) Styles.CssClass;
                        }
                        if (viewstate["ForeColor"] != null) 
                        {
-                               styles |= Styles.ForeColor;
+                               styles |= (int) Styles.ForeColor;
                        }
                        if (viewstate["Height"] != null) 
                        {
-                               styles |= Styles.Height;
+                               styles |= (int) Styles.Height;
                        }
                        if (viewstate["Width"] != null) 
                        {
-                               styles |= Styles.Width;
-                       }
-                       if (fontinfo != null) {
-                               fontinfo.LoadViewState();
+                               styles |= (int) Styles.Width;
                        }
+                       Font.LoadViewState();
 
                        LoadViewStateInternal();
                }
@@ -743,20 +755,23 @@ namespace System.Web.UI.WebControls
 
                protected internal virtual object SaveViewState () 
                {
-                       if (styles != Styles.None
+                       if (styles != 0 || !Font.IsEmpty
                        {
                                return viewstate.SaveViewState();
                        }
                        return null;
                }
 
-               [MonoTODO]
                protected internal virtual void SetBit( int bit ) 
                {
-                       throw new NotImplementedException();
+                       styles |= bit;
                }
 
-               protected internal virtual void TrackViewState() 
+               internal bool CheckBit (int bit) {
+                       return (styles & bit) != 0;
+               }
+
+               protected internal virtual void TrackViewState () 
                {
                        tracking = true;
                        viewstate.TrackViewState();
@@ -807,36 +822,41 @@ namespace System.Web.UI.WebControls
                }
 
                [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) {
+               internal void CopyTextStylesFrom (Style source) {
+                       // Used primary for TreeView and Menu
+                       if (source.CheckBit ((int) Styles.ForeColor)) {
                                ForeColor = source.ForeColor;
                        }
-                       if ((styles & Styles.BackColor) != 0) {
-                               BackColor = source.BackColor;
+                       if (!source.Font.IsEmpty) {
+                               Font.CopyFrom (source.Font);
                        }
                }
 
-               public void SetDirty ()
-               {
-                       if (viewstate != null)
-                               viewstate.SetDirty ();
+               internal void AddCssClass (string cssClass) {
+                       if (String.IsNullOrEmpty (cssClass))
+                               return;
+
+                       if (CssClass.Length > 0)
+                               CssClass += " ";
+                       CssClass += cssClass;
                }
 
-               public static bool IsStyleEmpty (Style s)
+               public void SetDirty ()
                {
-                       if (s == null)
-                               return true;
-                       return s.IsEmpty;
+                       if (viewstate != null)
+                               viewstate.SetDirty (true);
                }
-
 #endif
        }
 }