2 * Namespace: System.Web.UI.WebControls
\r
5 * Author: Gaurav Vaish
\r
6 * Maintainer: gvaish@iitk.ac.in
\r
7 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
8 * Implementation: yes
\r
11 * (C) Gaurav Vaish (2002)
\r
16 using System.Web.UI;
\r
18 namespace System.Web.UI.WebControls
\r
20 public class TableStyle : Style
\r
22 private static int IMAGE_URL = (0x01 << 16);
\r
23 private static int CELL_PADD = (0x01 << 17);
\r
24 private static int CELL_SPAC = (0x01 << 18);
\r
25 private static int GRID_LINE = (0x01 << 19);
\r
26 private static int HOR_ALIGN = (0x01 << 20);
\r
28 public TableStyle(): base()
\r
32 public TableStyle(StateBag bag): base(bag)
\r
36 public virtual string BackImageUrl
\r
40 if(IsSet(IMAGE_URL))
\r
41 return (string)(ViewState["BackImageUrl"]);
\r
42 return String.Empty;
\r
47 throw new ArgumentNullException("BackImageUrl");
\r
48 ViewState["BackImageUrl"] = value;
\r
53 public virtual int CellPadding
\r
57 if(IsSet(CELL_PADD))
\r
58 return (int)(ViewState["CellPadding"]);
\r
64 throw new ArgumentOutOfRangeException("CellPadding");
\r
65 ViewState["CellPadding"] = value;
\r
70 public virtual int CellSpacing
\r
74 if(IsSet(CELL_SPAC))
\r
75 return (int)(ViewState["CellSpacing"]);
\r
81 throw new ArgumentOutOfRangeException("CellSpacing");
\r
82 ViewState["CellSpacing"] = value;
\r
87 public virtual GridLines GridLines
\r
91 if(IsSet(GRID_LINE))
\r
92 return (string)(ViewState["GridLines"]);
\r
93 return GridLines.Both;
\r
97 if(!Enum.IsDefined(typeof(GridLines), value))
\r
98 throw new ArgumentException();
\r
99 ViewState["GridLines"] = value;
\r
104 public virtual HorizontalAlign HorizontalAlign
\r
108 if(IsSet(HOR_ALIGN))
\r
109 return (string)(ViewState["HorizontalAlign"]);
\r
110 return HorizontalAlign.NotSet;
\r
114 if(!Enum.IsDefined(typeof(HorizontalAlign), value))
\r
115 throw new ArgumentException();
\r
116 ViewState["HorizontalAlign"] = value;
\r
121 public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
\r
123 base.AddAttributesToRender(writer, owner);
\r
124 if(BackImageUrl.Length > 0)
\r
126 writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + ResolveUrl(BackImageUrl) + ")");
\r
128 if(CellSpacing >= 0)
\r
130 writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, CellSpacing.ToString(NumerFormatInfo.InvariantInfo));
\r
132 if(CellPadding >= 0)
\r
134 writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, CellPadding.ToString(NumerFormatInfo.InvariantInfo));
\r
136 if(HorizontalAlign != HorizontalAlign.NotSet)
\r
138 writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(HorizontalAlign), HorizontalAlign, "G"));
\r
143 case GridLines.None: gd = "";
\r
145 case GridLines.Horizontal: gd = "cols";
\r
147 case GridLines.Vertical: gd = "rows";
\r
149 case GridLines.Both: gd = "all";
\r
152 writer.AddAttribute(HtmlTextWriterAttribute.Rules, gd);
\r
155 private static int IMAGE_URL = (0x01 << 16);
\r
156 private static int CELL_PADD = (0x01 << 17);
\r
157 private static int CELL_SPAC = (0x01 << 18);
\r
158 private static int GRID_LINE = (0x01 << 19);
\r
159 private static int HOR_ALIGN = (0x01 << 20);
\r
161 public override void CopyFrom(Style s)
\r
163 if(s != null && s is TableStyle && !s.IsEmpty)
\r
166 TableStyle from = (TableStyle)s;
\r
167 if(from.IsSet(HOR_ALIGN))
\r
169 HorizontalAlign = from.HorizontalAlign;
\r
171 if(from.IsSet(IMAGE_URL))
\r
173 BackImageUrl = from.BackImageUrl;
\r
175 if(from.IsSet(CELL_PADD))
\r
177 CellPadding = from.CellPadding;
\r
179 if(from.IsSet(CELL_SPAC))
\r
181 CellSpacing = from.CellSpacing;
\r
183 if(from.IsSet(GRID_LINE))
\r
185 GridLines = from.GridLines;
\r
190 public override void MergeWith(Style s)
\r
192 if(s != null && s is TableStyle && !s.IsEmpty)
\r
195 TableStyle with = (TableStyle)s;
\r
196 if(from.IsSet(HOR_ALIGN) && IsSet(HOR_ALIGN))
\r
198 HorizontalAlign = with.HorizontalAlign;
\r
200 if(from.IsSet(IMAGE_URL) && IsSet(IMAGE_URL))
\r
202 BackImageUrl = with.BackImageUrl;
\r
204 if(from.IsSet(CELL_PADD) && IsSet(CELLL_PADD))
\r
206 CellPadding = with.CellPadding;
\r
208 if(from.IsSet(CELL_SPAC) && IsSet(CELL_SPAC))
\r
210 CellSpacing = with.CellSpacing;
\r
212 if(from.IsSet(GRID_LINE) && IsSet(GRID_LINE))
\r
214 GridLines = with.GridLines;
\r
219 public override void Reset()
\r
221 if(IsSet(IMAGE_URL))
\r
222 ViewState.Remove("BackImageUrl");
\r
223 if(IsSet(HOR_ALIGN))
\r
224 ViewState.Remove("HorizontalAlign");
\r
225 if(IsSet(CELL_PADD))
\r
226 ViewState.Remove("CellPadding");
\r
227 if(IsSet(CELL_SPAC))
\r
228 ViewState.Remove("CellSpacing");
\r
229 if(IsSet(GRID_LINE))
\r
230 ViewState.Remove("GridLines");
\r