2 // System.Web.UI.WebControls.TableStyle.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.ComponentModel;
\r
14 using System.Globalization;
\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 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
37 [WebSysDescription ("An Url specifying the background image for the table.")]
\r
38 public virtual string BackImageUrl
\r
42 if(IsSet(IMAGE_URL))
\r
43 return (string)(ViewState["BackImageUrl"]);
\r
44 return String.Empty;
\r
49 throw new ArgumentNullException("value");
\r
50 ViewState["BackImageUrl"] = value;
\r
55 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
56 [WebSysDescription ("The space left around the borders within a cell.")]
\r
57 public virtual int CellPadding
\r
61 if(IsSet(CELL_PADD))
\r
62 return (int)(ViewState["CellPadding"]);
\r
68 throw new ArgumentOutOfRangeException("value", "CellPadding value has to be -1 for 'not set' or a value >= 0");
\r
69 ViewState["CellPadding"] = value;
\r
74 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
75 [WebSysDescription ("The space left between cells.")]
\r
76 public virtual int CellSpacing
\r
80 if(IsSet(CELL_SPAC))
\r
81 return (int)(ViewState["CellSpacing"]);
\r
87 throw new ArgumentOutOfRangeException("value"," CellSpacing value has to be -1 for 'not set' or a value >= 0");
\r
88 ViewState["CellSpacing"] = value;
\r
93 [DefaultValue (typeof (GridLines), "None"), Bindable (true), WebCategory ("Appearance")]
94 [WebSysDescription ("The type of grid that a table uses.")]
\r
95 public virtual GridLines GridLines
\r
99 if(IsSet(GRID_LINE))
\r
100 return (GridLines)(ViewState["GridLines"]);
\r
101 return GridLines.None;
\r
105 if(!Enum.IsDefined(typeof(GridLines), value))
\r
106 throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");
\r
107 ViewState["GridLines"] = value;
\r
112 [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
113 [WebSysDescription ("The horizonal alignment of the table.")]
\r
114 public virtual HorizontalAlign HorizontalAlign
\r
118 if(IsSet(HOR_ALIGN))
\r
119 return (HorizontalAlign)(ViewState["HorizontalAlign"]);
\r
120 return HorizontalAlign.NotSet;
\r
124 if(!Enum.IsDefined(typeof(HorizontalAlign), value))
\r
125 throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");
\r
126 ViewState["HorizontalAlign"] = value;
\r
131 public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
\r
133 base.AddAttributesToRender(writer, owner);
\r
134 if(BackImageUrl.Length > 0)
\r
136 writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + owner.ResolveUrl(BackImageUrl) + ")");
\r
138 if(CellSpacing >= 0)
\r
140 writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, CellSpacing.ToString(NumberFormatInfo.InvariantInfo));
\r
142 writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse");
145 if(CellPadding >= 0)
\r
147 writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, CellPadding.ToString(NumberFormatInfo.InvariantInfo));
\r
149 if(HorizontalAlign != HorizontalAlign.NotSet)
\r
151 writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(HorizontalAlign), HorizontalAlign, "G"));
\r
153 string gd = String.Empty;
156 case GridLines.None: break;
157 case GridLines.Horizontal: gd = "rows";
\r
159 case GridLines.Vertical: gd = "cols";
\r
161 case GridLines.Both: gd = "all";
\r
164 writer.AddAttribute(HtmlTextWriterAttribute.Rules, gd);
167 public override void CopyFrom(Style s)
169 if (s == null || s.IsEmpty)
173 TableStyle from = s as TableStyle;
177 if (from.IsSet (HOR_ALIGN))
178 HorizontalAlign = from.HorizontalAlign;
180 if (from.IsSet (IMAGE_URL))
181 BackImageUrl = from.BackImageUrl;
183 if (from.IsSet (CELL_PADD))
184 CellPadding = from.CellPadding;
186 if (from.IsSet (CELL_SPAC))
187 CellSpacing = from.CellSpacing;
189 if (from.IsSet (GRID_LINE))
190 GridLines = from.GridLines;
193 public override void MergeWith(Style s)
\r
195 if(s != null && !s.IsEmpty)
\r
203 if (!(s is TableStyle))
206 TableStyle with = (TableStyle)s;
\r
207 if(with.IsSet(HOR_ALIGN) && !IsSet(HOR_ALIGN))
\r
209 HorizontalAlign = with.HorizontalAlign;
\r
211 if(with.IsSet(IMAGE_URL) && !IsSet(IMAGE_URL))
\r
213 BackImageUrl = with.BackImageUrl;
\r
215 if(with.IsSet(CELL_PADD) && !IsSet(CELL_PADD))
\r
217 CellPadding = with.CellPadding;
\r
219 if(with.IsSet(CELL_SPAC) && !IsSet(CELL_SPAC))
\r
221 CellSpacing = with.CellSpacing;
\r
223 if(with.IsSet(GRID_LINE) && !IsSet(GRID_LINE))
\r
225 GridLines = with.GridLines;
\r
230 public override void Reset()
\r
232 if(IsSet(IMAGE_URL))
\r
233 ViewState.Remove("BackImageUrl");
\r
234 if(IsSet(HOR_ALIGN))
\r
235 ViewState.Remove("HorizontalAlign");
\r
236 if(IsSet(CELL_PADD))
\r
237 ViewState.Remove("CellPadding");
\r
238 if(IsSet(CELL_SPAC))
\r
239 ViewState.Remove("CellSpacing");
\r
240 if(IsSet(GRID_LINE))
\r
241 ViewState.Remove("GridLines");
\r