2 // System.Web.UI.WebControls.TableItemStyle.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
30 using System.Globalization;
31 using System.Security.Permissions;
34 namespace System.Web.UI.WebControls {
36 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 public class TableItemStyle : Style {
40 public TableItemStyle ()
44 public TableItemStyle (StateBag bag)
52 [DefaultValue (HorizontalAlign.NotSet)]
53 [NotifyParentProperty (true)]
54 [WebSysDescription ("")]
55 [WebCategory("Layout")]
56 public virtual HorizontalAlign HorizontalAlign {
58 if ((styles & Styles.HorizontalAlign) == 0)
59 return HorizontalAlign.NotSet;
60 return (HorizontalAlign) ViewState ["HorizontalAlign"];
64 if ((value < HorizontalAlign.NotSet) || (value > HorizontalAlign.Justify)) {
65 // LAMESPEC: documented as ArgumentException
66 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid HorizontalAlign value."));
68 ViewState ["HorizontalAlign"] = value;
69 styles |= Styles.HorizontalAlign;
76 [DefaultValue (VerticalAlign.NotSet)]
77 [NotifyParentProperty (true)]
78 [WebSysDescription ("")]
79 [WebCategory("Layout")]
80 public virtual VerticalAlign VerticalAlign {
82 if ((styles & Styles.VerticalAlign) == 0)
83 return VerticalAlign.NotSet;
84 return (VerticalAlign) ViewState ["VerticalAlign"];
88 if ((value < VerticalAlign.NotSet) || (value > VerticalAlign.Bottom)) {
89 // LAMESPEC: documented as ArgumentException
90 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid VerticalAlign value."));
92 ViewState ["VerticalAlign"] = value;
93 styles |= Styles.VerticalAlign;
100 [DefaultValue (true)]
101 [NotifyParentProperty (true)]
102 [WebSysDescription ("")]
103 [WebCategory("Layout")]
104 public virtual bool Wrap {
106 if ((styles & Styles.Wrap) == 0)
108 return (bool) ViewState ["Wrap"];
111 ViewState ["Wrap"] = value;
112 styles |= Styles.Wrap;
117 public override void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
119 base.AddAttributesToRender (writer, owner);
123 // note: avoid ToString on the enum
124 switch (HorizontalAlign) {
125 case HorizontalAlign.Left:
126 writer.AddAttribute (HtmlTextWriterAttribute.Align, "left");
128 case HorizontalAlign.Center:
129 writer.AddAttribute (HtmlTextWriterAttribute.Align, "center");
131 case HorizontalAlign.Right:
132 writer.AddAttribute (HtmlTextWriterAttribute.Align, "right");
134 case HorizontalAlign.Justify:
135 writer.AddAttribute (HtmlTextWriterAttribute.Align, "justify");
139 // note: avoid ToString on the enum
140 switch (VerticalAlign) {
141 case VerticalAlign.Top:
142 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "top");
144 case VerticalAlign.Middle:
145 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "middle");
147 case VerticalAlign.Bottom:
148 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "bottom");
154 writer.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
156 writer.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
161 private void Copy (string name, Styles s, Style source)
163 if ((source.styles & s) != 0) {
164 object o = source.ViewState [name];
166 ViewState [name] = o;
172 public override void CopyFrom (Style s)
175 if (s != null && !s.IsEmpty) {
176 Copy ("HorizontalAlign", Styles.HorizontalAlign, s);
177 Copy ("VerticalAlign", Styles.VerticalAlign, s);
178 Copy ("Wrap", Styles.Wrap, s);
182 private void Merge (string name, Styles s, Style source)
184 if ((styles & s) == 0 && (source.styles & s) != 0) {
185 object o = source.ViewState [name];
187 ViewState [name] = o;
193 public override void MergeWith (Style s)
195 // if we're empty then it's like a copy
201 Merge ("HorizontalAlign", Styles.HorizontalAlign, s);
202 Merge ("VerticalAlign", Styles.VerticalAlign, s);
203 Merge ("Wrap", Styles.Wrap, s);
208 public override void Reset ()
210 if ((styles & Styles.HorizontalAlign) != 0)
211 ViewState.Remove ("HorizontalAlign");
212 if ((styles & Styles.VerticalAlign) != 0)
213 ViewState.Remove ("VerticalAlign");
214 if ((styles & Styles.Wrap) != 0)
215 ViewState.Remove ("Wrap");
216 // call base at the end because "styles" will reset there
220 internal override void LoadViewStateInternal()
222 if (viewstate["VerticalAlign"] != null) {
223 styles |= Styles.VerticalAlign;
225 if (viewstate["Wrap"] != null) {
226 styles |= Styles.Wrap;
229 base.LoadViewStateInternal();