Page.Validate() is called when CausesValidation=true
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Style.cs
index 738f584376fea27c270b3809b65f8690800769ab..2651bad626acd0c9bd38e50be21dd7bbdb123260 100644 (file)
@@ -44,42 +44,21 @@ namespace System.Web.UI.WebControls {
        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;
@@ -117,7 +96,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.BackColor) == 0
+                               if (!CheckBit ((int) Styles.BackColor)
                                {
                                        return Color.Empty;
                                }
@@ -128,7 +107,7 @@ namespace System.Web.UI.WebControls {
                        set 
                        {
                                viewstate["BackColor"] = value;
-                               styles |= Styles.BackColor;
+                               SetBit ((int) Styles.BackColor);
                        }
                }
 
@@ -144,7 +123,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.BorderColor) == 0
+                               if (!CheckBit ((int) Styles.BorderColor)
                                {
                                        return Color.Empty;
                                }
@@ -155,7 +134,7 @@ namespace System.Web.UI.WebControls {
                        set 
                        {
                                viewstate["BorderColor"] = value;
-                               styles |= Styles.BorderColor;
+                               SetBit ((int) Styles.BorderColor);
                        }
                }
 
@@ -170,7 +149,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.BorderStyle) == 0
+                               if (!CheckBit ((int) Styles.BorderStyle)
                                {
                                        return BorderStyle.NotSet;
                                }
@@ -181,7 +160,7 @@ namespace System.Web.UI.WebControls {
                        set 
                        {
                                viewstate["BorderStyle"] = value;
-                               styles |= Styles.BorderStyle;
+                               SetBit ((int) Styles.BorderStyle);
                        }
                }
 
@@ -196,7 +175,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.BorderWidth) == 0
+                               if (!CheckBit ((int) Styles.BorderWidth)
                                {
                                        return Unit.Empty;
                                }
@@ -212,7 +191,7 @@ namespace System.Web.UI.WebControls {
                                }
 
                                viewstate["BorderWidth"] = value;
-                               styles |= Styles.BorderWidth;
+                               SetBit ((int) Styles.BorderWidth);
                        }
                }
 
@@ -224,7 +203,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.CssClass) == 0
+                               if (!CheckBit ((int) Styles.CssClass)
                                {
                                        return string.Empty;
                                }
@@ -235,7 +214,7 @@ namespace System.Web.UI.WebControls {
                        set 
                        {
                                viewstate["CssClass"] = value;
-                               styles |= Styles.CssClass;
+                               SetBit ((int) Styles.CssClass);
                        }
                }
 
@@ -267,7 +246,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.ForeColor) == 0
+                               if (!CheckBit ((int) Styles.ForeColor)
                                {
                                        return Color.Empty;
                                }
@@ -278,7 +257,7 @@ namespace System.Web.UI.WebControls {
                        set 
                        {
                                viewstate["ForeColor"] = value;
-                               styles |= Styles.ForeColor;
+                               SetBit ((int) Styles.ForeColor);
                        }
                }
 
@@ -293,7 +272,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.Height) == 0
+                               if (!CheckBit ((int) Styles.Height)
                                {
                                        return Unit.Empty;
                                }
@@ -309,7 +288,7 @@ namespace System.Web.UI.WebControls {
                                }
 
                                viewstate["Height"] = value;
-                               styles |= Styles.Height;
+                               SetBit ((int) Styles.Height);
                        }
                }
 
@@ -324,7 +303,7 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
-                               if ((styles & Styles.Width) == 0
+                               if (!CheckBit ((int) Styles.Width)
                                {
                                        return Unit.Empty;
                                }
@@ -340,7 +319,7 @@ namespace System.Web.UI.WebControls {
                                }
 
                                viewstate["Width"] = value;
-                               styles |= Styles.Width;
+                               SetBit ((int) Styles.Width);
                        }
                }
                #endregion      // Public Instance Properties
@@ -356,7 +335,11 @@ namespace System.Web.UI.WebControls {
                {
                        get 
                        {
+#if NET_2_0
+                               return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty) && RegisteredCssClass.Length == 0);
+#else
                                return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
+#endif
                        }
                }
 
@@ -379,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) 
                {
@@ -387,37 +387,50 @@ 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));
                        }
 
                        bool have_width = false;
-                       if ((styles & Styles.BorderWidth) != 0) {
+                       if (CheckBit ((int) Styles.BorderWidth)) {
                                u = (Unit)viewstate["BorderWidth"];
                                if (!u.IsEmpty) {
                                        if (u.Value > 0)
@@ -426,31 +439,31 @@ namespace System.Web.UI.WebControls {
                                }
                        }
 
-                       if ((styles & Styles.BorderStyle) != 0) {
+                       if (CheckBit ((int) Styles.BorderStyle)) {
                                bs = (BorderStyle)viewstate["BorderStyle"];
                                if (bs != BorderStyle.NotSet) 
                                        writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
                                else {
-                                       if ((styles & Styles.BorderWidth) != 0)
+                                       if (CheckBit ((int) Styles.BorderWidth))
                                                writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
                                }
                        } else if (have_width) {
                                writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
                        }
 
-                       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());
@@ -486,116 +499,79 @@ namespace System.Web.UI.WebControls {
                                if (fontinfo.Underline)
                                        s += "underline ";
 
-                               s = (s != "") ? s : "none";
-                               writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
+                               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 (!Font.IsEmpty) {
-                               // 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 ";
-                               }
-
-                               s = (s != "") ? s : "none";
-                               attributes.Add (HtmlTextWriterStyle.TextDecoration, s);
-                       }
+                       Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
                }
+#endif
 
                public virtual void CopyFrom(Style s) 
                {
@@ -609,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.IsEmpty))
+                       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.IsEmpty))
+                       if ((s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
                        {
                                this.Height = s.Height;
                        }
-                       if (((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
+                       if ((s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
                        {
                                this.Width = s.Width;
                        }
@@ -655,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.IsEmpty)) 
+                       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.IsEmpty)) 
+                       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.IsEmpty)) 
+                       if ((!CheckBit ((int) Styles.Width)) && (s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
                        {
                                this.Width = s.Width;
                        }
@@ -717,7 +693,7 @@ namespace System.Web.UI.WebControls {
                        {
                                fontinfo.Reset();
                        }
-                       styles = Styles.None;
+                       styles = 0;
                }
 #if ONLY_1_1
                public override string ToString() 
@@ -733,39 +709,39 @@ 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;
+                               styles |= (int) Styles.Width;
                        }
                        Font.LoadViewState();
 
@@ -779,20 +755,23 @@ namespace System.Web.UI.WebControls {
 
                protected internal virtual object SaveViewState () 
                {
-                       if (styles != Styles.None || !Font.IsEmpty) 
+                       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();
@@ -854,17 +833,25 @@ namespace System.Web.UI.WebControls {
                        }
                }
 
-               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);
                        }
                }
 
+               internal void AddCssClass (string cssClass) {
+                       if (String.IsNullOrEmpty (cssClass))
+                               return;
+
+                       if (CssClass.Length > 0)
+                               CssClass += " ";
+                       CssClass += cssClass;
+               }
+
                public void SetDirty ()
                {
                        if (viewstate != null)