-//
-// System.Web.UI.WebControls.Style.cs
-//
-// Authors:
-// Gaurav Vaish (gvaish@iitk.ac.in)
-// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
-//
-// (C) Gaurav Vaish (2002)
-// (C) 2003 Andreas Nahr
-//
-
-//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Dennis Bartok (pbartok@novell.com)
+//
+//
-using System;
-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
+using System.Drawing;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+ // CAS
+ [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ // attributes
+#if NET_2_0
+// Not until we actually have StyleConverter
+// [TypeConverter(typeof(System.Web.UI.WebControls.StyleConverter))]
+#else
+ [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
+#endif
+ [ToolboxItem("")]
+ public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager
{
- 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;
-
+ [Flags]
+ enum Styles
+ {
+ BackColor = 0x00000008,
+ BorderColor = 0x00000010,
+ BorderStyle = 0x00000040,
+ BorderWidth = 0x00000020,
+ CssClass = 0x00000002,
+ Font = 0x00000001,
+ ForeColor = 0x00000004,
+ Height = 0x00000080,
+ Width = 0x00000100,
+ }
+
+ #region Fields
+ private int styles;
+ internal StateBag viewstate;
+ private FontInfo fontinfo;
+ private bool tracking;
#if NET_2_0
- string regClass;
+ private string registered_class;
#endif
+ #endregion // Fields
- private FontInfo font;
-
- public Style ()
+ #region Public Constructors
+ public Style() : this(new StateBag())
{
- Initialize(null);
- selfStateBag = true;
}
- public Style (StateBag bag)
+ public Style(System.Web.UI.StateBag bag)
{
- Initialize (bag);
- selfStateBag = false;
+ if (bag != null) {
+ viewstate = bag;
+ } else {
+ viewstate = new StateBag();
+ }
+ tracking = false;
}
+ #endregion // Public Constructors
- private void Initialize (StateBag bag)
+ #region Public Instance Properties
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Color), "")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public Color BackColor
{
- 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 ();
+ get
+ {
+ if (!CheckBit ((int) Styles.BackColor))
+ {
+ return Color.Empty;
}
- return viewState;
+
+ return (Color)viewstate["BackColor"];
}
- }
- internal bool IsSet (int bit)
- {
- return ((selectionBits & bit) != 0x00);
+ set
+ {
+ viewstate["BackColor"] = value;
+ SetBit ((int) Styles.BackColor);
+ }
}
- internal virtual void Set (int bit)
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Color), "")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public Color BorderColor
{
- selectionBits |= bit;
- if (IsTrackingViewState)
- selectionBits |= MARKED;
- }
+ get
+ {
+ if (!CheckBit ((int) Styles.BorderColor))
+ {
+ return Color.Empty;
+ }
- [NotifyParentProperty (true)]
- [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
- [TypeConverter (typeof (WebColorConverter))]
- [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);
+ return (Color)viewstate["BorderColor"];
}
- }
- [NotifyParentProperty (true)]
- [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
- [TypeConverter (typeof (WebColorConverter))]
- [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);
+ set
+ {
+ viewstate["BorderColor"] = value;
+ SetBit ((int) Styles.BorderColor);
}
}
- [NotifyParentProperty (true)]
- [DefaultValue (typeof(BorderStyle), "NotSet"), Bindable (true), WebCategory ("Appearance")]
- [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;
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(BorderStyle.NotSet)]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public BorderStyle BorderStyle
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.BorderStyle))
+ {
+ return BorderStyle.NotSet;
+ }
+
+ return (BorderStyle)viewstate["BorderStyle"];
}
- set {
- ViewState ["BorderStyle"] = value;
- Set (BORDERSTYLE);
+
+ set
+ {
+ viewstate["BorderStyle"] = value;
+ SetBit ((int) Styles.BorderStyle);
}
}
- [NotifyParentProperty (true)]
- [DefaultValue (null), Bindable (true), WebCategory ("Appearance")]
- [WebSysDescription ("The width of the border used for the WebControl.")]
- public Unit BorderWidth {
- get {
- if (IsSet (BORDERWIDTH))
- return (Unit) ViewState ["BorderWidth"];
- return Unit.Empty;
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Unit), "")]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public Unit BorderWidth
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.BorderWidth))
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["BorderWidth"];
}
- set {
- ViewState ["BorderWidth"] = value;
- Set (BORDERWIDTH);
+
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
+ }
+
+ viewstate["BorderWidth"] = value;
+ SetBit ((int) Styles.BorderWidth);
}
}
- [NotifyParentProperty (true)]
- [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;
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public string CssClass
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.CssClass))
+ {
+ return string.Empty;
+ }
+
+ return (string)viewstate["CssClass"];
}
- set {
- ViewState ["CssClass"] = value;
- Set (CSSCLASS);
+
+ set
+ {
+ viewstate["CssClass"] = value;
+ SetBit ((int) Styles.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.")]
- public Color ForeColor {
- get {
- if (IsSet (FORECOLOR))
- return (Color) ViewState ["ForeColor"];
- return Color.Empty;
- }
- set {
- ViewState ["ForeColor"] = value;
- Set (FORECOLOR);
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public FontInfo Font
+ {
+ get
+ {
+ if (fontinfo == null)
+ {
+ fontinfo = new FontInfo(this);
+ }
+ return fontinfo;
}
}
- [NotifyParentProperty (true)]
- [DefaultValue (null), Bindable (true), WebCategory ("Layout")]
- [WebSysDescription ("The height of this WebControl.")]
- public Unit Height {
- get {
- if (IsSet (HEIGHT))
- return (Unit) ViewState ["Height"];
- return Unit.Empty;
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Color), "")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public Color ForeColor
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.ForeColor))
+ {
+ return Color.Empty;
+ }
+
+ return (Color)viewstate["ForeColor"];
}
- set {
- ViewState ["Height"] = value;
- Set (HEIGHT);
+
+ set
+ {
+ viewstate["ForeColor"] = value;
+ SetBit ((int) Styles.ForeColor);
}
}
- [NotifyParentProperty (true)]
- [DefaultValue (null), Bindable (true), WebCategory ("Layout")]
- [WebSysDescription ("The width of this WebControl.")]
- public Unit Width {
- get {
- if (IsSet(WIDTH))
- return (Unit) ViewState ["Width"];
- return Unit.Empty;
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Unit), "")]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
+ [WebCategory ("Appearance")]
+ public Unit Height
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.Height))
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["Height"];
}
- set {
- ViewState ["Width"] = value;
- Set (WIDTH);
+
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
+ }
+
+ viewstate["Height"] = value;
+ SetBit ((int) Styles.Height);
}
}
- [NotifyParentProperty (true)]
+#if !NET_2_0
+ [Bindable(true)]
+#endif
+ [DefaultValue(typeof (Unit), "")]
+ [NotifyParentProperty(true)]
+ [WebSysDescription ("")]
[WebCategory ("Appearance")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [WebSysDescription ("The font of this WebControl.")]
- public FontInfo Font {
- get {
- if (font==null)
- font = new FontInfo (this);
- return font;
+ public Unit Width
+ {
+ get
+ {
+ if (!CheckBit ((int) Styles.Width))
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["Width"];
}
- }
- protected internal virtual bool IsEmpty
- {
- get { return (selectionBits == 0); }
- }
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
+ }
- private void AddColor (CssStyleCollection attributes, HtmlTextWriterStyle style, Color color)
- {
- if (!color.IsEmpty)
- attributes.Add (style, ColorTranslator.ToHtml (color));
+ viewstate["Width"] = value;
+ SetBit ((int) Styles.Width);
+ }
}
+ #endregion // Public Instance Properties
- private static string StringArrayToString (string [] array, char separator)
+ #region Protected Instance Properties
+#if NET_2_0
+ [Browsable (false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public virtual bool IsEmpty
+#else
+ protected internal virtual bool IsEmpty
+#endif
{
- 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]);
- }
+ get
+ {
+#if NET_2_0
+ return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty) && RegisteredCssClass.Length == 0);
+#else
+ return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
+#endif
}
- return sb.ToString ();
}
- public void AddAttributesToRender (HtmlTextWriter writer)
+ protected bool IsTrackingViewState
{
- AddAttributesToRender (writer, null);
+ get
+ {
+ return tracking;
+ }
}
- public virtual void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ protected internal StateBag ViewState
{
- if (IsSet (CSSCLASS)) {
- string cssClass = (string) ViewState ["CssClass"];
- if (cssClass.Length > 0)
- writer.AddAttribute (HtmlTextWriterAttribute.Class, cssClass);
+ get
+ {
+ return viewstate;
}
-
- CssStyleCollection ats = new CssStyleCollection ();
-#if NET_2_0
- FillStyleAttributes (ats, owner);
-#else
- FillAttributes (ats);
-#endif
- foreach (string key in ats.Keys)
- writer.AddStyleAttribute (key, ats [key]);
}
+ #endregion // Protected Instance Properties
-#if NET_2_0
- public CssStyleCollection FillStyleAttributes (IUrlResolutionService urlResolver)
+ #region Internal Instance Properties
+ internal bool AlwaysRenderTextDecoration
{
- CssStyleCollection ats = new CssStyleCollection ();
- FillStyleAttributes (ats, urlResolver);
- return ats;
+ get
+ {
+ if (viewstate["AlwaysRenderTextDecoration"] == null)
+ return false;
+ return (bool)viewstate["AlwaysRenderTextDecoration"];
+ }
+
+ set
+ {
+ viewstate["AlwaysRenderTextDecoration"] = value;
+ }
}
- protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
+ #endregion // Internal Instance Properties
+
+ #region Public Instance Methods
+ public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
- FillAttributes (attributes);
+ AddAttributesToRender(writer, null);
}
-#endif
- void FillAttributes (CssStyleCollection attributes)
+ public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
{
- if (IsSet (BACKCOLOR))
- AddColor (attributes, HtmlTextWriterStyle.BackgroundColor, BackColor);
-
- if (IsSet(BORDERCOLOR))
- AddColor (attributes, HtmlTextWriterStyle.BorderColor, BorderColor);
+#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
+ {
+ if (CssClass.Length > 0)
+ writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
+ WriteStyleAttributes (writer);
+ }
+ }
- if (IsSet (FORECOLOR))
- AddColor (attributes, HtmlTextWriterStyle.Color, ForeColor);
+ void WriteStyleAttributes (HtmlTextWriter writer)
+ {
+#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 (CheckBit ((int) Styles.BackColor)) {
+ color = (Color)viewstate["BackColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+ }
- if (!BorderWidth.IsEmpty) {
- attributes.Add (HtmlTextWriterStyle.BorderWidth,
- BorderWidth.ToString (CultureInfo.InvariantCulture));
+ if (CheckBit ((int) Styles.BorderColor)) {
+ color = (Color)viewstate["BorderColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+ }
- if (BorderStyle != BorderStyle.NotSet) {
- attributes.Add (HtmlTextWriterStyle.BorderStyle,
- Enum.Format (typeof (BorderStyle), BorderStyle, "G"));
- } else {
- if (BorderWidth.Value != 0.0)
- attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
+ 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());
}
- } else {
- if (BorderStyle != BorderStyle.NotSet)
- attributes.Add (HtmlTextWriterStyle.BorderStyle,
- Enum.Format (typeof (BorderStyle), BorderStyle, "G"));
}
- if (Font.Names.Length > 0)
- attributes.Add (HtmlTextWriterStyle.FontFamily,
- StringArrayToString (Font.Names, ','));
-
- if (!Font.Size.IsEmpty)
- attributes.Add (HtmlTextWriterStyle.FontSize,
- Font.Size.ToString (CultureInfo.InvariantCulture));
-
- if (Font.Bold)
- attributes.Add (HtmlTextWriterStyle.FontWeight, "bold");
-
- if (Font.Italic)
- attributes.Add (HtmlTextWriterStyle.FontStyle, "italic");
-
- string textDecoration = String.Empty;
- if (Font.Strikeout)
- textDecoration += " line-through";
-
- if (Font.Underline)
- textDecoration += " underline";
-
- if (Font.Overline)
- textDecoration += " overline";
+ 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 (textDecoration.Length > 0)
- attributes.Add (HtmlTextWriterStyle.TextDecoration, textDecoration);
+ if (CheckBit ((int) Styles.ForeColor)) {
+ color = (Color)viewstate["ForeColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+ }
- Unit u = Unit.Empty;
- if (IsSet (HEIGHT)) {
- u = (Unit) ViewState ["Height"];
+ if (CheckBit ((int) Styles.Height)) {
+ u = (Unit)viewstate["Height"];
if (!u.IsEmpty)
- attributes.Add (HtmlTextWriterStyle.Height,
- u.ToString (CultureInfo.InvariantCulture));
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
}
- if (IsSet (WIDTH)) {
- u = (Unit) ViewState ["Width"];
+ if (CheckBit ((int) Styles.Width)) {
+ u = (Unit)viewstate["Width"];
if (!u.IsEmpty)
- attributes.Add (HtmlTextWriterStyle.Width,
- u.ToString (CultureInfo.InvariantCulture));
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
}
- }
-
- 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 (!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];
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
+ }
- if (source.IsSet (WIDTH)&& (source.Width != Unit.Empty))
- Width = source.Width;
+ if (fontinfo.Bold)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
- if (source.IsSet (BORDERCOLOR)&& (source.BorderColor != Color.Empty))
- BorderColor = source.BorderColor;
+ if (fontinfo.Italic)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
- if (source.IsSet (BORDERWIDTH)&& (source.BorderWidth != Unit.Empty))
- BorderWidth = source.BorderWidth;
+ if (!fontinfo.Size.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
- if (source.IsSet (BORDERSTYLE))
- BorderStyle = source.BorderStyle;
+ // These styles are munged into a attribute decoration
+ s = string.Empty;
- if (source.IsSet (BACKCOLOR)&& (source.BackColor != Color.Empty))
- BackColor = source.BackColor;
+ if (fontinfo.Overline)
+ s += "overline ";
- if (source.IsSet (CSSCLASS))
- CssClass = source.CssClass;
+ if (fontinfo.Strikeout)
+ s += "line-through ";
- if (source.IsSet (FORECOLOR)&& (source.ForeColor != Color.Empty))
- ForeColor = source.ForeColor;
+ if (fontinfo.Underline)
+ s += "underline ";
+ s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
+ if (s != "")
+ writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
+ }
+#endif
}
- public virtual void MergeWith (Style with)
+#if NET_2_0
+ void FillStyleAttributes (CssStyleCollection attributes)
{
- if (with == null || with.IsEmpty)
- return;
-
- if (IsEmpty) {
- CopyFrom (with);
- return;
+ Color color;
+ BorderStyle bs;
+ Unit u;
+
+ if (CheckBit ((int) Styles.BackColor))
+ {
+ color = (Color)viewstate["BackColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
}
- 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 (CheckBit ((int) Styles.BorderColor))
+ {
+ color = (Color)viewstate["BorderColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+ }
- if (!IsSet (BORDERCOLOR) && with.BorderColor != Color.Empty)
- BorderColor = with.BorderColor;
+ 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 (!IsSet (BORDERWIDTH) && with.BorderWidth != Unit.Empty)
- BorderWidth = with.BorderWidth;
+ 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 (!IsSet (BORDERSTYLE) && with.BorderStyle != BorderStyle.NotSet)
- BorderStyle = with.BorderStyle;
+ if (CheckBit ((int) Styles.ForeColor))
+ {
+ color = (Color)viewstate["ForeColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+ }
- if (!IsSet (BACKCOLOR) && with.BackColor != Color.Empty)
- BackColor = with.BackColor;
+ if (CheckBit ((int) Styles.Height))
+ {
+ u = (Unit)viewstate["Height"];
+ if (!u.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
+ }
- if (!IsSet (CSSCLASS) && with.CssClass != String.Empty)
- CssClass = with.CssClass;
+ if (CheckBit ((int) Styles.Width))
+ {
+ u = (Unit)viewstate["Width"];
+ if (!u.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
+ }
- if (!IsSet (FORECOLOR) && with.ForeColor != Color.Empty)
- ForeColor = with.ForeColor;
+ Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
}
+#endif
- public virtual void Reset ()
+ public virtual void CopyFrom(Style s)
{
- if (IsSet (BACKCOLOR))
- ViewState.Remove ("BackColor");
+ if ((s == null) || s.IsEmpty)
+ {
+ return;
+ }
- if (IsSet (BORDERCOLOR))
- ViewState.Remove ("BorderColor");
+ if (s.fontinfo != null)
+ {
+ Font.CopyFrom(s.fontinfo);
+ }
- if (IsSet (BORDERSTYLE))
- ViewState.Remove ("BorderStyle");
+ if ((s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
+ {
+ this.BackColor = s.BackColor;
+ }
+ if ((s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
+ {
+ this.BorderColor = s.BorderColor;
+ }
+ if ((s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
+ {
+ this.BorderStyle = s.BorderStyle;
+ }
+ if ((s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
+ {
+ this.BorderWidth = s.BorderWidth;
+ }
+ if ((s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
+ {
+ this.CssClass = s.CssClass;
+ }
+ if ((s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
+ {
+ this.ForeColor = s.ForeColor;
+ }
+ if ((s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
+ {
+ this.Height = s.Height;
+ }
+ if ((s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
+ {
+ this.Width = s.Width;
+ }
+ }
- if (IsSet (BORDERWIDTH))
- ViewState.Remove ("BorderWidth");
+ public virtual void MergeWith(Style s)
+ {
+ if ((s == null) || (s.IsEmpty))
+ {
+ return;
+ }
- if (IsSet (CSSCLASS))
- ViewState.Remove ("CssClass");
+ if (s.fontinfo != null)
+ {
+ Font.MergeWith(s.fontinfo);
+ }
- if (IsSet (FORECOLOR))
- ViewState.Remove ("ForeColor");
+ if ((!CheckBit ((int) Styles.BackColor)) && (s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
+ {
+ this.BackColor = s.BackColor;
+ }
+ if ((!CheckBit ((int) Styles.BorderColor)) && (s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
+ {
+ this.BorderColor = s.BorderColor;
+ }
+ if ((!CheckBit ((int) Styles.BorderStyle)) && (s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
+ {
+ this.BorderStyle = s.BorderStyle;
+ }
+ if ((!CheckBit ((int) Styles.BorderWidth)) && (s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
+ {
+ this.BorderWidth = s.BorderWidth;
+ }
+ if ((!CheckBit ((int) Styles.CssClass)) && (s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
+ {
+ this.CssClass = s.CssClass;
+ }
+ if ((!CheckBit ((int) Styles.ForeColor)) && (s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
+ {
+ this.ForeColor = s.ForeColor;
+ }
+ if ((!CheckBit ((int) Styles.Height)) && (s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
+ {
+ this.Height = s.Height;
+ }
+ if ((!CheckBit ((int) Styles.Width)) && (s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
+ {
+ this.Width = s.Width;
+ }
+ }
- if (IsSet (HEIGHT))
- ViewState.Remove ("Height");
+ /*
+ internal void Print ()
+ {
+ Console.WriteLine ("BackColor: {0}", BackColor);
+ Console.WriteLine ("BorderColor: {0}", BorderColor);
+ Console.WriteLine ("BorderStyle: {0}", BorderStyle);
+ Console.WriteLine ("BorderWidth: {0}", BorderWidth);
+ Console.WriteLine ("CssClass: {0}", CssClass);
+ Console.WriteLine ("ForeColor: {0}", ForeColor);
+ Console.WriteLine ("Height: {0}", Height);
+ Console.WriteLine ("Width: {0}", Width);
+ }
+ */
+
+ public virtual void Reset()
+ {
+ viewstate.Remove("BackColor");
+ viewstate.Remove("BorderColor");
+ viewstate.Remove("BorderStyle");
+ viewstate.Remove("BorderWidth");
+ viewstate.Remove("CssClass");
+ viewstate.Remove("ForeColor");
+ viewstate.Remove("Height");
+ viewstate.Remove("Width");
+ if (fontinfo != null)
+ {
+ fontinfo.Reset();
+ }
+ styles = 0;
+ }
+#if ONLY_1_1
+ public override string ToString()
+ {
+ return string.Empty;
+ }
+#endif
+ #endregion // Public Instance Methods
- if (IsSet (WIDTH))
- ViewState.Remove( "Width");
+ #region Protected Instance Methods
+ protected internal void LoadViewState(object state)
+ {
+ viewstate.LoadViewState(state);
- if (font != null)
- font.Reset ();
+ // Update our style
+ this.styles = 0;
- selectionBits = 0x00;
- }
+ if (viewstate["BackColor"] != null)
+ {
+ styles |= (int) Styles.BackColor;
+ }
+ if (viewstate["BorderColor"] != null)
+ {
+ styles |= (int) Styles.BorderColor;
+ }
+ if (viewstate["BorderStyle"] != null)
+ {
+ styles |= (int) Styles.BorderStyle;
+ }
+ if (viewstate["BorderWidth"] != null)
+ {
+ styles |= (int) Styles.BorderWidth;
+ }
+ if (viewstate["CssClass"] != null)
+ {
+ styles |= (int) Styles.CssClass;
+ }
+ if (viewstate["ForeColor"] != null)
+ {
+ styles |= (int) Styles.ForeColor;
+ }
+ if (viewstate["Height"] != null)
+ {
+ styles |= (int) Styles.Height;
+ }
+ if (viewstate["Width"] != null)
+ {
+ styles |= (int) Styles.Width;
+ }
+ Font.LoadViewState();
- protected bool IsTrackingViewState {
- get { return marked; }
+ LoadViewStateInternal();
}
- protected internal virtual void TrackViewState ()
+ internal virtual void LoadViewStateInternal()
{
- if (selfStateBag)
- ViewState.TrackViewState ();
-
- marked = true;
+ // Override me
}
- protected internal virtual object SaveViewState ()
+ protected internal virtual object SaveViewState ()
{
- if (viewState != null) {
- if (marked && IsSet (MARKED))
- ViewState [selectionBitString] = selectionBits;
-
- if (selfStateBag)
- return ViewState.SaveViewState ();
+ if (styles != 0 || !Font.IsEmpty)
+ {
+ return viewstate.SaveViewState();
}
-
return null;
}
- protected internal void LoadViewState (object state)
+ protected internal virtual void SetBit( int bit )
{
- if (state != null && selfStateBag)
- ViewState.LoadViewState (state);
+ styles |= bit;
+ }
- if (viewState != null) {
- object o = ViewState [selectionBitString];
- if (o != null)
- selectionBits = (int) o;
- }
+ internal bool CheckBit (int bit) {
+ return (styles & bit) != 0;
}
- void IStateManager.LoadViewState(object state)
+ protected internal virtual void TrackViewState ()
{
- LoadViewState(state);
+ tracking = true;
+ viewstate.TrackViewState();
}
+ #endregion // Protected Instance Methods
- object IStateManager.SaveViewState ()
+ #region IStateManager Properties & Methods
+ void IStateManager.LoadViewState(object state)
{
- return SaveViewState ();
+ LoadViewState(state);
}
- void IStateManager.TrackViewState ()
+ object IStateManager.SaveViewState()
{
- TrackViewState ();
+ return SaveViewState();
}
- bool IStateManager.IsTrackingViewState {
- get { return IsTrackingViewState; }
+ void IStateManager.TrackViewState()
+ {
+ TrackViewState();
}
- public override string ToString ()
+ bool IStateManager.IsTrackingViewState
{
- return String.Empty;
+ get
+ {
+ return this.IsTrackingViewState;
+ }
}
+ #endregion // IStateManager Properties & Methods
- protected internal void SetBit (int bit)
+#if NET_2_0
+ protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
{
- Set (bit);
+ FillStyleAttributes (attributes);
}
-
- internal virtual void CopyTextStylesFrom (Style source)
+
+ internal void SetRegisteredCssClass (string name)
{
- if (source.IsSet (FORECOLOR)&& (source.ForeColor != Color.Empty))
- ForeColor = source.ForeColor;
+ registered_class = name;
}
-
-#if NET_2_0
- public void SetDirty ()
+
+ public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
{
- if (selectionBits != 0x00)
- Set (MARKED);
- if (viewState != null)
- viewState.SetDirty ();
+ CssStyleCollection col = new CssStyleCollection (new StateBag ());
+ FillStyleAttributes (col, resolver);
+ return col;
}
-
+
+ [MonoTODO]
+ [EditorBrowsable(EditorBrowsableState.Advanced)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ [Browsable(false)]
public string RegisteredCssClass {
- get { return regClass; }
+ get {
+ if (registered_class == null)
+ registered_class = String.Empty;
+ return registered_class;
+ }
}
-
- internal void SetRegisteredCssClass (string name)
+
+ internal void CopyTextStylesFrom (Style source) {
+ // Used primary for TreeView and Menu
+ if (source.CheckBit ((int) Styles.ForeColor)) {
+ ForeColor = source.ForeColor;
+ }
+ 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 ()
{
- regClass = name;
+ if (viewstate != null)
+ viewstate.SetDirty (true);
}
#endif
}
}
-