📄 style.cs
字号:
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Drawing;
using System.Text;
using System.Globalization;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for Style.
/// </summary>
public class Style : Component,IStateManager
{
internal const int MARKED = 1;
internal const int PROP_CSSCLASS = 2;
internal const int PROP_FORECOLOR = 4;
internal const int PROP_BACKCOLOR = 8;
internal const int PROP_BORDERCOLOR = 16;
internal const int PROP_BORDERWIDTH = 32;
internal const int PROP_BORDERSTYLE = 64;
internal const int PROP_HEIGHT = 128;
internal const int PROP_WIDTH = 256;
internal const int PROP_FONT_NAMES = 512;
internal const int PROP_FONT_SIZE = 1024;
internal const int PROP_FONT_BOLD = 2048;
internal const int PROP_FONT_ITALIC = 4096;
internal const int PROP_FONT_UNDERLINE = 8192;
internal const int PROP_FONT_OVERLINE = 16384;
internal const int PROP_FONT_STRIKEOUT = 32768;
internal const string SetBitsKey = "_!SB";
private System.Web.UI.StateBag statebag;
private System.Web.UI.WebControls.FontInfo fontInfo;
private bool ownStateBag;
private bool marked;
private int setBits;
public Style(StateBag bag) : base()
{
this.statebag = bag;
this.marked = false;
this.setBits = 0;
}
public Style()
{
// this = new System.Web.UI.WebControls.Style(null);
this.ownStateBag = true;
}
public void AddAttributesToRender(HtmlTextWriter writer)
{
this.AddAttributesToRender(writer, null);
}
public void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
{
// StateBag local0;
// string local1;
// Color local2;
// Unit local3;
// BorderStyle local4;
// Unit local5;
// FontInfo local6;
// string[] local7;
// FontUnit local8;
// bool local9;
// bool local10;
// bool local11;
// bool local12;
// bool local13;
// string local14;
//
// local0 = this.ViewState;
// if (this.IsSet(2))
// {
// local1 = (String) local0["CssClass"];
// if (local1.Length > 0)
// writer.AddAttribute(HtmlTextWriterAttribute.Class, local1);
// }
// if (this.IsSet(4))
// {
// local2 = (Color) local0["ForeColor"];
// if (!(local2.IsEmpty))
// writer.AddStyleAttribute(6, System.Drawing.ColorTranslator.ToHtml(local2));
// }
// if (this.IsSet(8))
// {
// local2 = (Color) local0["BackColor"];
// if (!(local2.IsEmpty))
// writer.AddStyleAttribute(0, System.Drawing.ColorTranslator.ToHtml(local2));
// }
// if (this.IsSet(16))
// {
// local2 = (Color) local0["BorderColor"];
// if (!(local2.IsEmpty))
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Background, System.Drawing.ColorTranslator.ToHtml(local2));
// }
// local4 = this.BorderStyle;
// local5 = this.BorderWidth;
// if (!(local5.IsEmpty))
// {
// writer.AddStyleAttribute(5, local5.ToString(CultureInfo.InvariantCulture));
// if (local4 == 0)
// {
// if (local5.Value == 0)
// goto i0;
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Bgcolor, "solid");
// goto i0;
// }
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Bgcolor, System.Enum.Format(typeof(BorderStyle), local4, "G"));
// }
// else if (local4 != 0)
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Bgcolor, System.Enum.Format(typeof(BorderStyle), local4, "G"));
// i0: local6 = this.Font;
// local7 = local6.Names;
// if ((int) local7.Length > 0)
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Cellpadding, Style.FormatStringArray(local7, ','));
// local8 = local6.Size;
// if (!(local8.IsEmpty))
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Cellspacing, local8.ToString(CultureInfo.InvariantCulture));
// local9 = local6.Bold;
// if (local9)
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Class, "bold");
// local10 = local6.Italic;
// if (local10)
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Checked, "italic");
// local11 = local6.Underline;
// local12 = local6.Overline;
// local13 = local6.Strikeout;
// local14 = System.String.Empty;
// if (local11)
// local14 = "underline";
// if (local12)
// local14 = local14 + " overline";
// if (local13)
// local14 = local14 + " line-through";
// if (local14.Length > 0)
// writer.AddStyleAttribute(HtmlTextWriterAttribute.Colspan, local14);
// if (this.IsSet(128))
// {
// local3 = (Unit) local0["Height"];
// if (!(local3.IsEmpty))
// writer.AddStyleAttribute(11, local3.ToString(CultureInfo.InvariantCulture));
// }
// if (this.IsSet(256))
// {
// local3 = (Unit) local0["Width"];
// if (!(local3.IsEmpty))
// writer.AddStyleAttribute(13, local3.ToString(CultureInfo.InvariantCulture));
// }
throw new Exception("");
}
public void CopyFrom(Style s)
{
if (s != null && !(s.IsEmpty))
{
this.Font.CopyFrom(s.Font);
if (s.IsSet(2))
this.CssClass = s.CssClass;
if (s.IsSet(8) && (s.BackColor!= System.Drawing.Color.Empty))
this.BackColor = s.BackColor;
if (s.IsSet(4) && (s.ForeColor!= System.Drawing.Color.Empty))
this.ForeColor = s.ForeColor;
if (s.IsSet(16) && (s.BorderColor!= System.Drawing.Color.Empty))
this.BorderColor = s.BorderColor;
if (s.IsSet(32) && System.Web.UI.WebControls.Unit.op_Inequality(s.BorderWidth, System.Web.UI.WebControls.Unit.Empty))
this.BorderWidth = s.BorderWidth;
if (s.IsSet(64))
this.BorderStyle = s.BorderStyle;
if (s.IsSet(128) && System.Web.UI.WebControls.Unit.op_Inequality(s.Height, System.Web.UI.WebControls.Unit.Empty))
this.Height = s.Height;
if (s.IsSet(256) && System.Web.UI.WebControls.Unit.op_Inequality(s.Width, System.Web.UI.WebControls.Unit.Empty))
this.Width = s.Width;
}
}
private static string FormatStringArray(string[] array, char delimiter)
{
int local0;
string local1;
StringBuilder local2;
string local3;
int local4;
local0 = (int) array.Length;
local1 = System.String.Empty;
if (local0 == 1)
return array[0];
if (local0 != 0)
{
local2 = new StringBuilder(local0 * array[0].Length);
local4 = 0;
while (local4 < local0)
{
local3 = array[local4].ToString();
if (local4 > 0)
local2.Append(delimiter);
local2.Append(local3);
local4++;
}
local1 = local2.ToString();
}
return local1;
}
internal bool IsSet(int propKey)
{
return (this.setBits & propKey) != 0 ;
}
public void LoadViewState(object state)
{
object local0;
if (state != null && this.ownStateBag)
this.ViewState.LoadViewState(state);
if (this.statebag != null)
{
local0 = this.ViewState["_!SB"];
if (local0 != null)
this.setBits = (Int32) local0;
}
}
public void MergeWith(Style s)
{
if (s == null || s.IsEmpty)
return;
if (this.IsEmpty)
{
this.CopyFrom(s);
return;
}
this.Font.MergeWith(s.Font);
if (s.IsSet(2) && !(this.IsSet(2)))
this.CssClass = s.CssClass;
if (s.IsSet(8) && !(this.IsSet(8)) || this.BackColor== System.Drawing.Color.Empty)
this.BackColor = s.BackColor;
if (s.IsSet(4) && !(this.IsSet(4)) || this.ForeColor== System.Drawing.Color.Empty)
this.ForeColor = s.ForeColor;
if (s.IsSet(16) && !(this.IsSet(16)) || this.BorderColor== System.Drawing.Color.Empty)
this.BorderColor = s.BorderColor;
if (s.IsSet(32) && !(this.IsSet(32)) || System.Web.UI.WebControls.Unit.op_Equality(this.BorderWidth, System.Web.UI.WebControls.Unit.Empty))
this.BorderWidth = s.BorderWidth;
if (s.IsSet(64) && !(this.IsSet(64)))
this.BorderStyle = s.BorderStyle;
if (s.IsSet(128) && !(this.IsSet(128)) || System.Web.UI.WebControls.Unit.op_Equality(this.Height, System.Web.UI.WebControls.Unit.Empty))
this.Height = s.Height;
if (s.IsSet(256) && !(this.IsSet(256)) || System.Web.UI.WebControls.Unit.op_Equality(this.Width, System.Web.UI.WebControls.Unit.Empty))
this.Width = s.Width;
}
public void Reset()
{
if (this.statebag != null)
{
if (this.IsSet(2))
this.ViewState.Remove("CssClass");
if (this.IsSet(8))
this.ViewState.Remove("BackColor");
if (this.IsSet(4))
this.ViewState.Remove("ForeColor");
if (this.IsSet(16))
this.ViewState.Remove("BorderColor");
if (this.IsSet(32))
this.ViewState.Remove("BorderWidth");
if (this.IsSet(64))
this.ViewState.Remove("BorderStyle");
if (this.IsSet(128))
this.ViewState.Remove("Height");
if (this.IsSet(256))
this.ViewState.Remove("Width");
this.Font.Reset();
}
this.setBits = 0;
}
public object SaveViewState()
{
if (this.statebag != null)
{
if (this.IsSet(1))
this.ViewState["_!SB"]= this.setBits;
if (this.ownStateBag)
return this.ViewState.SaveViewState();
}
return null;
}
public void SetBit(int bit)
{
this.setBits = this.setBits | bit;
if (this.IsTrackingViewState)
this.setBits = this.setBits | 1;
}
bool System.Web.UI.IStateManager.IsTrackingViewState
{
get
{
return this.IsTrackingViewState;
}
}
void System.Web.UI.IStateManager.LoadViewState(object state)
{
this.LoadViewState(state);
}
object System.Web.UI.IStateManager.SaveViewState()
{
return this.SaveViewState();
}
void System.Web.UI.IStateManager.TrackViewState()
{
this.TrackViewState();
}
public string ToString()
{
return System.String.Empty;
}
public void TrackViewState()
{
if (this.ownStateBag)
this.ViewState.TrackViewState();
this.marked = true;
}
public Color BackColor
{
get
{
if (this.IsSet(8))
return (Color) this.ViewState["BackColor"];
return System.Drawing.Color.Empty;
}
set
{
this.ViewState["BackColor"]= value;
this.SetBit(8);
}
}
public Color BorderColor
{
get
{
if (this.IsSet(16))
return (Color) this.ViewState["BorderColor"];
return System.Drawing.Color.Empty;
}
set
{
this.ViewState["BorderColor"]= value;
this.SetBit(16);
}
}
public BorderStyle BorderStyle
{
get
{
if (this.IsSet(64))
return (BorderStyle) this.ViewState["BorderStyle"];
return 0;
}
set
{
if (value < (BorderStyle)0 || value > (BorderStyle)9)
throw new ArgumentOutOfRangeException("value");
this.ViewState["BorderStyle"]= value;
this.SetBit(64);
}
}
public Unit BorderWidth
{
get
{
if (this.IsSet(32))
return (Unit) this.ViewState["BorderWidth"];
return System.Web.UI.WebControls.Unit.Empty;
}
set
{
// if (value.Type == 7 || value.Value < 0)
// throw new ArgumentOutOfRangeException("value");
// this.ViewState["BorderWidth"]= value;
// this.SetBit(32);
}
}
public string CssClass
{
get
{
if (this.IsSet(2))
return (String) this.ViewState["CssClass"];
return System.String.Empty;
}
set
{
if (value == null)
throw new ArgumentOutOfRangeException("value");
this.ViewState["CssClass"]= value;
this.SetBit(2);
}
}
public FontInfo Font
{
get
{
if (this.fontInfo == null)
this.fontInfo = new FontInfo(this);
return this.fontInfo;
}
}
public Color ForeColor
{
get
{
if (this.IsSet(4))
return (Color) this.ViewState["ForeColor"];
return System.Drawing.Color.Empty;
}
set
{
this.ViewState["ForeColor"]= value;
this.SetBit(4);
}
}
public Unit Height
{
get
{
if (this.IsSet(128))
return (Unit) this.ViewState["Height"];
return System.Web.UI.WebControls.Unit.Empty;
}
set
{
if (value.Value < 0)
throw new ArgumentOutOfRangeException("value");
this.ViewState["Height"]= value;
this.SetBit(128);
}
}
public bool IsEmpty
{
get
{
return this.setBits == 0;
}
}
protected bool IsTrackingViewState
{
get
{
return this.marked;
}
}
public StateBag ViewState
{
get
{
if (this.statebag == null)
{
this.statebag = new StateBag(false);
if (this.IsTrackingViewState)
this.statebag.TrackViewState();
}
return this.statebag;
}
}
public Unit Width
{
get
{
if (this.IsSet(256))
return (Unit) this.ViewState["Width"];
return System.Web.UI.WebControls.Unit.Empty;
}
set
{
if (value.Value < 0)
throw new ArgumentOutOfRangeException("value");
this.ViewState["Width"]= value;
this.SetBit(256);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -