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 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.ComponentModel
;
35 using System
.Globalization
;
39 namespace System
.Web
.UI
.WebControls
41 public class TableStyle
: Style
43 private static int IMAGE_URL
= (0x01 << 16);
44 private static int CELL_PADD
= (0x01 << 17);
45 private static int CELL_SPAC
= (0x01 << 18);
46 private static int GRID_LINE
= (0x01 << 19);
47 private static int HOR_ALIGN
= (0x01 << 20);
49 public TableStyle(): base()
53 public TableStyle(StateBag bag
): base(bag
)
57 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
58 [WebSysDescription ("An Url specifying the background image for the table.")]
59 public virtual string BackImageUrl
64 return (string)(ViewState
["BackImageUrl"]);
70 throw new ArgumentNullException("value");
71 ViewState
["BackImageUrl"] = value;
76 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
77 [WebSysDescription ("The space left around the borders within a cell.")]
78 public virtual int CellPadding
83 return (int)(ViewState
["CellPadding"]);
89 throw new ArgumentOutOfRangeException("value", "CellPadding value has to be -1 for 'not set' or a value >= 0");
90 ViewState
["CellPadding"] = value;
95 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
96 [WebSysDescription ("The space left between cells.")]
97 public virtual int CellSpacing
102 return (int)(ViewState
["CellSpacing"]);
108 throw new ArgumentOutOfRangeException("value"," CellSpacing value has to be -1 for 'not set' or a value >= 0");
109 ViewState
["CellSpacing"] = value;
114 [DefaultValue (typeof (GridLines
), "None"), Bindable (true), WebCategory ("Appearance")]
115 [WebSysDescription ("The type of grid that a table uses.")]
116 public virtual GridLines GridLines
121 return (GridLines
)(ViewState
["GridLines"]);
122 return GridLines
.None
;
126 if(!Enum
.IsDefined(typeof(GridLines
), value))
127 throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");
128 ViewState
["GridLines"] = value;
133 [DefaultValue (typeof (HorizontalAlign
), "NotSet"), Bindable (true), WebCategory ("Layout")]
134 [WebSysDescription ("The horizonal alignment of the table.")]
135 public virtual HorizontalAlign HorizontalAlign
140 return (HorizontalAlign
)(ViewState
["HorizontalAlign"]);
141 return HorizontalAlign
.NotSet
;
145 if(!Enum
.IsDefined(typeof(HorizontalAlign
), value))
146 throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");
147 ViewState
["HorizontalAlign"] = value;
152 public override void AddAttributesToRender(HtmlTextWriter writer
, WebControl owner
)
154 base.AddAttributesToRender(writer
, owner
);
155 if(BackImageUrl
.Length
> 0)
157 writer
.AddStyleAttribute(HtmlTextWriterStyle
.BackgroundImage
, "url(" + owner
.ResolveUrl(BackImageUrl
) + ")");
161 writer
.AddAttribute(HtmlTextWriterAttribute
.Cellspacing
, CellSpacing
.ToString(NumberFormatInfo
.InvariantInfo
));
163 writer
.AddStyleAttribute(HtmlTextWriterStyle
.BorderCollapse
, "collapse");
168 writer
.AddAttribute(HtmlTextWriterAttribute
.Cellpadding
, CellPadding
.ToString(NumberFormatInfo
.InvariantInfo
));
170 if(HorizontalAlign
!= HorizontalAlign
.NotSet
)
172 writer
.AddAttribute(HtmlTextWriterAttribute
.Align
, Enum
.Format(typeof(HorizontalAlign
), HorizontalAlign
, "G"));
177 case GridLines
.None
: break;
178 case GridLines
.Horizontal
: gd
= "rows";
180 case GridLines
.Vertical
: gd
= "cols";
182 case GridLines
.Both
: gd
= "all";
187 writer
.AddAttribute(HtmlTextWriterAttribute
.Rules
, gd
);
190 public override void CopyFrom(Style s
)
192 if (s
== null || s
.IsEmpty
)
196 TableStyle
from = s
as TableStyle
;
200 if (from.IsSet (HOR_ALIGN
))
201 HorizontalAlign
= from.HorizontalAlign
;
203 if (from.IsSet (IMAGE_URL
))
204 BackImageUrl
= from.BackImageUrl
;
206 if (from.IsSet (CELL_PADD
))
207 CellPadding
= from.CellPadding
;
209 if (from.IsSet (CELL_SPAC
))
210 CellSpacing
= from.CellSpacing
;
212 if (from.IsSet (GRID_LINE
))
213 GridLines
= from.GridLines
;
216 public override void MergeWith(Style s
)
218 if(s
!= null && !s
.IsEmpty
)
226 if (!(s
is TableStyle
))
229 TableStyle with
= (TableStyle
)s
;
230 if(with
.IsSet(HOR_ALIGN
) && !IsSet(HOR_ALIGN
))
232 HorizontalAlign
= with
.HorizontalAlign
;
234 if(with
.IsSet(IMAGE_URL
) && !IsSet(IMAGE_URL
))
236 BackImageUrl
= with
.BackImageUrl
;
238 if(with
.IsSet(CELL_PADD
) && !IsSet(CELL_PADD
))
240 CellPadding
= with
.CellPadding
;
242 if(with
.IsSet(CELL_SPAC
) && !IsSet(CELL_SPAC
))
244 CellSpacing
= with
.CellSpacing
;
246 if(with
.IsSet(GRID_LINE
) && !IsSet(GRID_LINE
))
248 GridLines
= with
.GridLines
;
253 public override void Reset()
256 ViewState
.Remove("BackImageUrl");
258 ViewState
.Remove("HorizontalAlign");
260 ViewState
.Remove("CellPadding");
262 ViewState
.Remove("CellSpacing");
264 ViewState
.Remove("GridLines");