//
//
-using System;
using System.ComponentModel;
using System.Drawing;
+using System.Security.Permissions;
-namespace System.Web.UI.WebControls
-{
+namespace System.Web.UI.WebControls {
+
+ // CAS
+ [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ // attributes
+#if NET_2_0
+// Not until we actually have StyleConverter
+// [TypeConverter(typeof(System.Web.UI.WebControls.StyleConverter))]
+#else
[TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
+#endif
[ToolboxItem("")]
public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager
{
#endregion // Public Constructors
#region Public Instance Properties
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Color), "")]
[NotifyParentProperty(true)]
[TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Color), "")]
[NotifyParentProperty(true)]
[TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(BorderStyle.NotSet)]
[NotifyParentProperty(true)]
[WebSysDescription ("")]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Unit), "")]
[NotifyParentProperty(true)]
[WebSysDescription ("")]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Color), "")]
[NotifyParentProperty(true)]
[TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Unit), "")]
[NotifyParentProperty(true)]
[WebSysDescription ("")]
}
}
+#if !NET_2_0
[Bindable(true)]
+#endif
[DefaultValue(typeof (Unit), "")]
[NotifyParentProperty(true)]
[WebSysDescription ("")]
#endregion // Public Instance Properties
#region Protected Instance Properties
+#if NET_2_0
+ [Browsable (false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public virtual bool IsEmpty
+#else
protected internal virtual bool IsEmpty
+#endif
{
get
{
writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
}
- CssStyleCollection attributes = new CssStyleCollection ();
- FillStyleAttributes (attributes);
- foreach (string attr in attributes.Keys)
- writer.AddStyleAttribute (attr, attributes [attr]);
+ WriteStyleAttributes (writer);
+ }
+
+ void WriteStyleAttributes (HtmlTextWriter writer)
+ {
+ string s;
+ Color color;
+ BorderStyle bs;
+ Unit u;
+
+ if ((styles & Styles.BackColor) != 0) {
+ color = (Color)viewstate["BackColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderColor) != 0) {
+ color = (Color)viewstate["BorderColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderStyle) != 0) {
+ bs = (BorderStyle)viewstate["BorderStyle"];
+ if (bs != BorderStyle.NotSet)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
+ }
+
+ if ((styles & Styles.BorderWidth) != 0) {
+ u = (Unit)viewstate["BorderWidth"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
+ }
+
+ if ((styles & Styles.ForeColor) != 0) {
+ color = (Color)viewstate["ForeColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.Height) != 0) {
+ u = (Unit)viewstate["Height"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
+ }
+
+ if ((styles & Styles.Width) != 0) {
+ u = (Unit)viewstate["Width"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
+ }
+
+ if (fontinfo != null) {
+ // Fonts are a bit weird
+ if (fontinfo.Name != string.Empty) {
+ s = fontinfo.Names[0];
+ for (int i = 1; i < fontinfo.Names.Length; i++)
+ s += "," + fontinfo.Names[i];
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
+ }
+
+ if (fontinfo.Bold)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
+
+ if (fontinfo.Italic)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
+
+ if (!fontinfo.Size.IsEmpty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
+
+ // These styles are munged into a attribute decoration
+ s = string.Empty;
+
+ if (fontinfo.Overline)
+ s += "overline ";
+
+ if (fontinfo.Strikeout)
+ s += "line-through ";
+
+ if (fontinfo.Underline)
+ s += "underline ";
+
+ if (s != string.Empty)
+ writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
+ }
}
-
+
void FillStyleAttributes (CssStyleCollection attributes)
{
string s;
}
}
+ /*
+ 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");
}
styles = Styles.None;
}
-
+#if ONLY_1_1
public override string ToString()
{
return string.Empty;
}
+#endif
#endregion // Public Instance Methods
#region Protected Instance Methods
public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
{
- CssStyleCollection col = new CssStyleCollection ();
+ CssStyleCollection col = new CssStyleCollection (new StateBag ());
FillStyleAttributes (col, resolver);
return col;
}
[MonoTODO]
+ [EditorBrowsable(EditorBrowsableState.Advanced)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ [Browsable(false)]
public string RegisteredCssClass {
get {
+ if (registered_class == null)
+ registered_class = String.Empty;
return registered_class;
}
}
public void SetDirty ()
{
if (viewstate != null)
- viewstate.SetDirty ();
+ viewstate.SetDirty (true);
}
-
- public static bool IsStyleEmpty (Style s)
- {
- if (s == null)
- return true;
- return s.IsEmpty;
- }
-
#endif
}
}