2004-06-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Style.cs
index 1d0f2118c4f5039f89f6fc4c167033507c3bc8fa..ad5feeaf8b6f1745e36d65468220ee650185d1e9 100644 (file)
 //
 // (C) Gaurav Vaish (2002)
 // (C) 2003 Andreas Nahr
-//\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
+//
+
+using System;
+using System.Text;
+using System.Collections;
+using System.Drawing;
+using System.Globalization;
+using System.ComponentModel;
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+       [ToolboxItem(false)]
+       [TypeConverter(typeof(ExpandableObjectConverter))]
+       public class Style : Component , IStateManager
+       {
+               internal static int MARKED      = (0x01 << 0);
+               internal static int BACKCOLOR   = (0x01 << 1);
+               internal static int BORDERCOLOR = (0x01 << 2);
+               internal static int BORDERSTYLE = (0x01 << 3);
+               internal static int BORDERWIDTH = (0x01 << 4);
+               internal static int CSSCLASS    = (0x01 << 5);
+               internal static int FORECOLOR   = (0x01 << 6);
+               internal static int HEIGHT      = (0x01 << 7);
+               internal static int WIDTH       = (0x01 << 8);
+               internal static int FONT_BOLD   = (0x01 << 9);
+               internal static int FONT_ITALIC = (0x01 << 10);
+               internal static int FONT_NAMES  = (0x01 << 11);
+               internal static int FONT_SIZE   = (0x01 << 12);
+               internal static int FONT_STRIKE = (0x01 << 13);
+               internal static int FONT_OLINE  = (0x01 << 14);
+               internal static int FONT_ULINE  = (0x01 << 15);
+
+               internal static string selectionBitString = "_SBS";
+
+               StateBag viewState;
+               int  selectionBits;
+               bool selfStateBag;
+               bool marked;
+
+               private FontInfo font;
+
+               public Style ()
+               {
+                       Initialize(null);
+                       selfStateBag = true;
+               }
+
+               public Style (StateBag bag)
+               {
+                       Initialize (bag);
+                       selfStateBag = false;
+               }
+
+               private void Initialize (StateBag bag)
+               {
+                       viewState     = bag;
+                       selectionBits = 0x00;
+               }
+
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               protected internal StateBag ViewState {
+                       get {
+                               if (viewState == null) {
+                                       viewState = new StateBag (false);
+                                       if (IsTrackingViewState)
+                                               viewState.TrackViewState ();
+                               }
+                               return viewState;
+                       }
+               }
+
+               internal bool IsSet (int bit)
+               {
+                       return ((selectionBits & bit) != 0x00);
+               }
+
+               internal virtual void Set (int bit)
+               {
+                       selectionBits |= bit;
+                       if (IsTrackingViewState)
+                               selectionBits |= MARKED;
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
                [TypeConverter (typeof (WebColorConverter))]
-               [WebSysDescription ("The background color for the WebControl.")]\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
+               [WebSysDescription ("The background color for the WebControl.")]
+               public Color BackColor {
+                       get {
+                               if(IsSet(BACKCOLOR))
+                                       return (Color)ViewState["BackColor"];
+                               return Color.Empty;
+                       }
+                       set {
+                               ViewState["BackColor"] = value;
+                               Set(BACKCOLOR);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
                [TypeConverter (typeof (WebColorConverter))]
-               [WebSysDescription ("The border color for the WebControl.")]\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
+               [WebSysDescription ("The border color for the WebControl.")]
+               public Color BorderColor {
+                       get {
+                               if (IsSet (BORDERCOLOR))
+                                       return (Color) ViewState ["BorderColor"];
+                               return Color.Empty;
+                       }
+                       set {
+                               ViewState ["BorderColor"] = value;
+                               Set (BORDERCOLOR);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (typeof(BorderStyle), "NotSet"), Bindable (true), WebCategory ("Appearance")]
-               [WebSysDescription ("The style/type of the border used for the WebControl.")]\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
+               [WebSysDescription ("The style/type of the border used for the WebControl.")]
+               public BorderStyle BorderStyle {
+                       get {
+                               if (IsSet (BORDERSTYLE))
+                                       return (BorderStyle) ViewState ["BorderStyle"];
+                               return BorderStyle.NotSet;
+                       }
+                       set {
+                               ViewState ["BorderStyle"] = value;
+                               Set (BORDERSTYLE);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
-               [WebSysDescription ("The width of the border used for the WebControl.")]\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
+               [WebSysDescription ("The width of the border used for the WebControl.")]
+               public Unit BorderWidth {
+                       get {
+                               if (IsSet (BORDERWIDTH))
+                                       return (Unit) ViewState ["BorderWidth"];
+                               return Unit.Empty;
+                       }
+                       set {
+                               ViewState ["BorderWidth"] = value;
+                               Set (BORDERWIDTH);
+                       }
+               }
 
                [NotifyParentProperty (true)]
-               [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
-               [WebSysDescription ("The cascading stylesheet class that is associated with this WebControl.")]\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
+               [DefaultValue (""), WebCategory ("Appearance")]
+               [WebSysDescription ("The cascading stylesheet class that is associated with this WebControl.")]
+               public string CssClass {
+                       get {
+                               if (IsSet (CSSCLASS))
+                                       return (string) ViewState["CssClass"];
+                               return string.Empty;
+                       }
+                       set {
+                               ViewState ["CssClass"] = value;
+                               Set (CSSCLASS);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
                [TypeConverter (typeof (WebColorConverter))]
-               [WebSysDescription ("The color that is used to paint the primary display of the WebControl.")]\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
+               [WebSysDescription ("The color that is used to paint the primary display of the WebControl.")]
+               public Color ForeColor {
+                       get {
+                               if (IsSet (FORECOLOR))
+                                       return (Color) ViewState ["ForeColor"];
+                               return Color.Empty;
+                       }
+                       set {
+                               ViewState ["ForeColor"] = value;
+                               Set (FORECOLOR);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Layout")]
-               [WebSysDescription ("The height of this WebControl.")]\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
+               [WebSysDescription ("The height of this WebControl.")]
+               public Unit Height {
+                       get {
+                               if (IsSet (HEIGHT))
+                                       return (Unit) ViewState ["Height"];
+                               return Unit.Empty;
+                       }
+                       set {
+                               ViewState ["Height"] = value;
+                               Set (HEIGHT);
+                       }
+               }
 
                [NotifyParentProperty (true)]
                [DefaultValue (null), Bindable (true), WebCategory ("Layout")]
-               [WebSysDescription ("The width of this WebControl.")]\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
+               [WebSysDescription ("The width of this WebControl.")]
+               public Unit Width {
+                       get {
+                               if (IsSet(WIDTH))
+                                       return (Unit) ViewState ["Width"];
+                               return Unit.Empty;
+                       }
+                       set {
+                               ViewState ["Width"] = value;
+                               Set (WIDTH);
+                       }
+               }
 
                [NotifyParentProperty (true)]
-               [DefaultValue (null), WebCategory ("Appearance")]
+               [WebCategory ("Appearance")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               [WebSysDescription ("The font of this WebControl.")]\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
-                               ViewState.LoadViewState(state);\r
-\r
-                       if (viewState != null) {\r
-                               object o = ViewState[selectionBitString];\r
-                               if (o != null)\r
-                                       selectionBits = (int) o;\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
+               [WebSysDescription ("The font of this WebControl.")]
+               public FontInfo Font {
+                       get {
+                               if (font==null)
+                                       font = new FontInfo (this);
+                               return font;
+                       }
+               }
+
+               protected internal virtual bool IsEmpty
+               {
+                       get { return (selectionBits == 0); }
+               }
+
+               private void AddColor (HtmlTextWriter writer, HtmlTextWriterStyle style, Color color)
+               {
+                       if (!color.IsEmpty)
+                               writer.AddStyleAttribute (style, ColorTranslator.ToHtml (color));
+               }
+
+               private static string StringArrayToString (string [] array, char separator)
+               {
+                       if (array.Length == 0)
+                               return String.Empty;
+                       StringBuilder sb = new StringBuilder ();
+                       for (int i = 0; i < array.Length; i++) {
+                               if (i == 0) {
+                                       sb.Append (array [0]);
+                               } else {
+                                       sb.Append (separator);
+                                       sb.Append (array [i]);
+                               }
+                       }
+                       return sb.ToString ();
+               }
+
+               public void AddAttributesToRender (HtmlTextWriter writer)
+               {
+                       AddAttributesToRender (writer, null);
+               }
+
+               public virtual void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
+               {
+                       if (IsSet (BACKCOLOR))
+                               AddColor (writer, HtmlTextWriterStyle.BackgroundColor, BackColor);
+
+                       if (IsSet(BORDERCOLOR))
+                               AddColor (writer, HtmlTextWriterStyle.BorderColor, BorderColor);
+
+                       if (IsSet (FORECOLOR))
+                               AddColor (writer, HtmlTextWriterStyle.Color, ForeColor);
+
+                       if (IsSet (CSSCLASS)) {
+                               string cssClass = (string) ViewState ["CssClass"];
+                               if (cssClass.Length > 0)
+                                       writer.AddAttribute (HtmlTextWriterAttribute.Class, cssClass);
+                       }
+
+                       if (!BorderWidth.IsEmpty) {
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth,
+                                               BorderWidth.ToString (CultureInfo.InvariantCulture));
+
+                               if (BorderStyle != BorderStyle.NotSet) {
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle,
+                                                       Enum.Format (typeof (BorderStyle), BorderStyle, "G"));
+                               } else {
+                                       if (BorderWidth.Value != 0.0)
+                                               writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle,
+                                                                         "solid");
+                               }
+                       } else {
+                               if (BorderStyle != BorderStyle.NotSet)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle,
+                                                       Enum.Format (typeof (BorderStyle), BorderStyle, "G"));
+                       }
+
+                       if (Font.Names.Length > 0)
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily,
+                                                       StringArrayToString (Font.Names, ','));
+
+                       if (!Font.Size.IsEmpty)
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize,
+                                                       Font.Size.ToString (CultureInfo.InvariantCulture));
+
+                       if (Font.Bold)
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
+
+                       if (Font.Italic)
+                               writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
+
+                       string textDecoration = String.Empty;
+                       if (Font.Strikeout)
+                               textDecoration += " line-through";
+
+                       if (Font.Underline)
+                               textDecoration += " underline";
+
+                       if (Font.Overline)
+                               textDecoration += " overline";
+
+                       if (textDecoration.Length > 0)
+                               writer.AddStyleAttribute( HtmlTextWriterStyle.TextDecoration, textDecoration);
+
+                       Unit u = Unit.Empty;
+                       if (IsSet (HEIGHT)) {
+                               u = (Unit) ViewState ["Height"];
+                               if (!u.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.Height,
+                                                               u.ToString (CultureInfo.InvariantCulture));
+                       }
+
+                       if (IsSet (WIDTH)) {
+                               u = (Unit) ViewState ["Width"];
+                               if (!u.IsEmpty)
+                                       writer.AddStyleAttribute (HtmlTextWriterStyle.Width,
+                                                               u.ToString (CultureInfo.InvariantCulture));
+                       }
+               }
+
+               public virtual void CopyFrom (Style source)
+               {
+                       if (source == null || source.IsEmpty)
+                               return;
+
+                       Font.CopyFrom (source.Font);
+                       if (source.IsSet (HEIGHT)&& (source.Height != Unit.Empty))
+                               Height = source.Height;
+
+                       if (source.IsSet (WIDTH)&& (source.Width != Unit.Empty))
+                               Width = source.Width;
+
+                       if (source.IsSet (BORDERCOLOR)&& (source.BorderColor != Color.Empty))
+                               BorderColor = source.BorderColor;
+
+                       if (source.IsSet (BORDERWIDTH)&& (source.BorderWidth != Unit.Empty))
+                               BorderWidth = source.BorderWidth;
+
+                       if (source.IsSet (BORDERSTYLE))
+                               BorderStyle = source.BorderStyle;
+
+                       if (source.IsSet (BACKCOLOR)&& (source.BackColor != Color.Empty))
+                               BackColor = source.BackColor;
+
+                       if (source.IsSet (CSSCLASS))
+                               CssClass = source.CssClass;
+
+                       if (source.IsSet (FORECOLOR)&& (source.ForeColor != Color.Empty))
+                               ForeColor = source.ForeColor;
+
+               }
+
+               public virtual void MergeWith (Style with)
+               {
+                       if (with == null || with.IsEmpty)
+                               return;
+
+                       if (IsEmpty) {
+                               CopyFrom (with);
+                               return;
+                       }
+
+                       Font.MergeWith (with.Font);
+                       if (!IsSet (HEIGHT) && with.Height != Unit.Empty)
+                               Height = with.Height;
+
+                       if (!IsSet(WIDTH) && with.Width != Unit.Empty)
+                               Width = with.Width;
+
+                       if (!IsSet (BORDERCOLOR) && with.BorderColor != Color.Empty)
+                               BorderColor = with.BorderColor;
+
+                       if (!IsSet (BORDERWIDTH) && with.BorderWidth != Unit.Empty)
+                               BorderWidth = with.BorderWidth;
+
+                       if (!IsSet (BORDERSTYLE) && with.BorderStyle != BorderStyle.NotSet)
+                               BorderStyle = with.BorderStyle;
+
+                       if (!IsSet (BACKCOLOR) && with.BackColor != Color.Empty)
+                               BackColor = with.BackColor;
+
+                       if (!IsSet (CSSCLASS) && with.CssClass != String.Empty)
+                               CssClass = with.CssClass;
+
+                       if (!IsSet (FORECOLOR) && with.ForeColor != Color.Empty)
+                               ForeColor = with.ForeColor;
+               }
+
+               public virtual void Reset ()
+               {
+                       if (IsSet (BACKCOLOR))
+                               ViewState.Remove ("BackColor");
+
+                       if (IsSet (BORDERCOLOR))
+                               ViewState.Remove ("BorderColor");
+
+                       if (IsSet (BORDERSTYLE))
+                               ViewState.Remove ("BorderStyle");
+
+                       if (IsSet (BORDERWIDTH))
+                               ViewState.Remove ("BorderWidth");
+
+                       if (IsSet (CSSCLASS))
+                               ViewState.Remove ("CssClass");
+
+                       if (IsSet (FORECOLOR))
+                               ViewState.Remove ("ForeColor");
+
+                       if (IsSet (HEIGHT))
+                               ViewState.Remove ("Height");
+
+                       if (IsSet (WIDTH))
+                               ViewState.Remove( "Width");
+
+                       if (font != null)
+                               font.Reset ();
+
+                       selectionBits = 0x00;
+               }
+
+               protected bool IsTrackingViewState {
+                       get { return marked; }
+               }
+
+               protected internal virtual void TrackViewState ()
+               {
+                       if (selfStateBag)
+                               ViewState.TrackViewState ();
+
+                       marked = true;
+               }
+
+               protected internal virtual object SaveViewState ()
+               {
+                       if (viewState != null) {
+                               if (marked && IsSet (MARKED))
+                                       ViewState [selectionBitString] = selectionBits;
+
+                               if (selfStateBag)
+                                       return ViewState.SaveViewState ();
+                       }
+
+                       return null;
+               }
+
+               protected internal void LoadViewState (object state)
+               {
+                       if (state != null && selfStateBag)
+                               ViewState.LoadViewState (state);
+
+                       if (viewState != null) {
+                               object o = ViewState [selectionBitString];
+                               if (o != null)
+                                       selectionBits = (int) o;
+                       }
+               }
+
+               void IStateManager.LoadViewState(object state)
+               {
+                       LoadViewState(state);
+               }
+
+               object IStateManager.SaveViewState ()
+               {
+                       return SaveViewState ();
+               }
+
+               void IStateManager.TrackViewState ()
+               {
+                       TrackViewState ();
+               }
+
+               bool IStateManager.IsTrackingViewState {
+                       get { return IsTrackingViewState; }
+               }
+
+               public override string ToString ()
+               {
+                       return String.Empty;
+               }
+       }
+}
+