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 {
43 HorizontalAlign = 0x00010000,
44 VerticalAlign = 0x00020000,
48 public TableItemStyle ()
52 public TableItemStyle (StateBag bag)
60 [DefaultValue (HorizontalAlign.NotSet)]
61 [NotifyParentProperty (true)]
62 [WebSysDescription ("")]
63 [WebCategory("Layout")]
64 public virtual HorizontalAlign HorizontalAlign {
66 if (!CheckBit ((int) TableItemStyles.HorizontalAlign))
67 return HorizontalAlign.NotSet;
68 return (HorizontalAlign) ViewState ["HorizontalAlign"];
72 if ((value < HorizontalAlign.NotSet) || (value > HorizontalAlign.Justify)) {
73 // LAMESPEC: documented as ArgumentException
74 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid HorizontalAlign value."));
76 ViewState ["HorizontalAlign"] = value;
77 SetBit ((int) TableItemStyles.HorizontalAlign);
84 [DefaultValue (VerticalAlign.NotSet)]
85 [NotifyParentProperty (true)]
86 [WebSysDescription ("")]
87 [WebCategory("Layout")]
88 public virtual VerticalAlign VerticalAlign {
90 if (!CheckBit ((int) TableItemStyles.VerticalAlign))
91 return VerticalAlign.NotSet;
92 return (VerticalAlign) ViewState ["VerticalAlign"];
96 if ((value < VerticalAlign.NotSet) || (value > VerticalAlign.Bottom)) {
97 // LAMESPEC: documented as ArgumentException
98 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid VerticalAlign value."));
100 ViewState ["VerticalAlign"] = value;
101 SetBit ((int) TableItemStyles.VerticalAlign);
108 [DefaultValue (true)]
109 [NotifyParentProperty (true)]
110 [WebSysDescription ("")]
111 [WebCategory("Layout")]
112 public virtual bool Wrap {
114 if (!CheckBit ((int) TableItemStyles.Wrap))
116 return (bool) ViewState ["Wrap"];
119 ViewState ["Wrap"] = value;
120 SetBit ((int) TableItemStyles.Wrap);
125 public override void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
127 base.AddAttributesToRender (writer, owner);
131 // note: avoid ToString on the enum
132 switch (HorizontalAlign) {
133 case HorizontalAlign.Left:
134 writer.AddAttribute (HtmlTextWriterAttribute.Align, "left", false);
136 case HorizontalAlign.Center:
137 writer.AddAttribute (HtmlTextWriterAttribute.Align, "center", false);
139 case HorizontalAlign.Right:
140 writer.AddAttribute (HtmlTextWriterAttribute.Align, "right", false);
142 case HorizontalAlign.Justify:
143 writer.AddAttribute (HtmlTextWriterAttribute.Align, "justify", false);
147 // note: avoid ToString on the enum
148 switch (VerticalAlign) {
149 case VerticalAlign.Top:
150 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "top", false);
152 case VerticalAlign.Middle:
153 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "middle", false);
155 case VerticalAlign.Bottom:
156 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "bottom", false);
162 writer.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
164 writer.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
169 private void Copy (string name, TableItemStyles s, Style source)
171 if (source.CheckBit((int) s)) {
172 object o = source.ViewState [name];
174 ViewState [name] = o;
180 public override void CopyFrom (Style s)
183 if (s != null && !s.IsEmpty) {
184 Copy ("HorizontalAlign", TableItemStyles.HorizontalAlign, s);
185 Copy ("VerticalAlign", TableItemStyles.VerticalAlign, s);
186 Copy ("Wrap", TableItemStyles.Wrap, s);
190 private void Merge (string name, TableItemStyles s, Style source)
192 if ((!CheckBit ((int) s)) && (source.CheckBit ((int) s))) {
193 object o = source.ViewState [name];
195 ViewState [name] = o;
201 public override void MergeWith (Style s)
203 // if we're empty then it's like a copy
209 Merge ("HorizontalAlign", TableItemStyles.HorizontalAlign, s);
210 Merge ("VerticalAlign", TableItemStyles.VerticalAlign, s);
211 Merge ("Wrap", TableItemStyles.Wrap, s);
216 public override void Reset ()
218 if (CheckBit ((int) TableItemStyles.HorizontalAlign))
219 ViewState.Remove ("HorizontalAlign");
220 if (CheckBit ((int) TableItemStyles.VerticalAlign))
221 ViewState.Remove ("VerticalAlign");
222 if (CheckBit ((int) TableItemStyles.Wrap))
223 ViewState.Remove ("Wrap");
224 // call base at the end because "styles" will reset there