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)
57 [DefaultValue (HorizontalAlign.NotSet)]
58 [NotifyParentProperty (true)]
59 [WebSysDescription ("")]
60 [WebCategory("Layout")]
61 public virtual HorizontalAlign HorizontalAlign {
63 if (!CheckBit ((int) TableItemStyles.HorizontalAlign))
64 return HorizontalAlign.NotSet;
65 return (HorizontalAlign) ViewState ["HorizontalAlign"];
69 if ((value < HorizontalAlign.NotSet) || (value > HorizontalAlign.Justify)) {
70 // LAMESPEC: documented as ArgumentException
71 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid HorizontalAlign value."));
73 ViewState ["HorizontalAlign"] = value;
74 SetBit ((int) TableItemStyles.HorizontalAlign);
78 [DefaultValue (VerticalAlign.NotSet)]
79 [NotifyParentProperty (true)]
80 [WebSysDescription ("")]
81 [WebCategory("Layout")]
82 public virtual VerticalAlign VerticalAlign {
84 if (!CheckBit ((int) TableItemStyles.VerticalAlign))
85 return VerticalAlign.NotSet;
86 return (VerticalAlign) ViewState ["VerticalAlign"];
90 if ((value < VerticalAlign.NotSet) || (value > VerticalAlign.Bottom)) {
91 // LAMESPEC: documented as ArgumentException
92 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid VerticalAlign value."));
94 ViewState ["VerticalAlign"] = value;
95 SetBit ((int) TableItemStyles.VerticalAlign);
100 [NotifyParentProperty (true)]
101 [WebSysDescription ("")]
102 [WebCategory("Layout")]
103 public virtual bool Wrap {
105 if (!CheckBit ((int) TableItemStyles.Wrap))
107 return (bool) ViewState ["Wrap"];
110 ViewState ["Wrap"] = value;
111 SetBit ((int) TableItemStyles.Wrap);
116 public override void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
118 base.AddAttributesToRender (writer, owner);
122 // note: avoid ToString on the enum
123 switch (HorizontalAlign) {
124 case HorizontalAlign.Left:
125 writer.AddAttribute (HtmlTextWriterAttribute.Align, "left", false);
127 case HorizontalAlign.Center:
128 writer.AddAttribute (HtmlTextWriterAttribute.Align, "center", false);
130 case HorizontalAlign.Right:
131 writer.AddAttribute (HtmlTextWriterAttribute.Align, "right", false);
133 case HorizontalAlign.Justify:
134 writer.AddAttribute (HtmlTextWriterAttribute.Align, "justify", false);
138 // note: avoid ToString on the enum
139 switch (VerticalAlign) {
140 case VerticalAlign.Top:
141 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "top", false);
143 case VerticalAlign.Middle:
144 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "middle", false);
146 case VerticalAlign.Bottom:
147 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "bottom", false);
152 writer.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
156 void Copy (string name, TableItemStyles s, Style source)
158 if (source.CheckBit((int) s)) {
159 object o = source.ViewState [name];
161 ViewState [name] = o;
167 public override void CopyFrom (Style s)
170 if (s != null && !s.IsEmpty) {
171 Copy ("HorizontalAlign", TableItemStyles.HorizontalAlign, s);
172 Copy ("VerticalAlign", TableItemStyles.VerticalAlign, s);
173 Copy ("Wrap", TableItemStyles.Wrap, s);
177 void Merge (string name, TableItemStyles s, Style source)
179 if ((!CheckBit ((int) s)) && (source.CheckBit ((int) s))) {
180 object o = source.ViewState [name];
182 ViewState [name] = o;
188 public override void MergeWith (Style s)
190 // if we're empty then it's like a copy
196 Merge ("HorizontalAlign", TableItemStyles.HorizontalAlign, s);
197 Merge ("VerticalAlign", TableItemStyles.VerticalAlign, s);
198 Merge ("Wrap", TableItemStyles.Wrap, s);
203 public override void Reset ()
205 if (CheckBit ((int) TableItemStyles.HorizontalAlign))
206 ViewState.Remove ("HorizontalAlign");
207 if (CheckBit ((int) TableItemStyles.VerticalAlign))
208 ViewState.Remove ("VerticalAlign");
209 if (CheckBit ((int) TableItemStyles.Wrap))
210 ViewState.Remove ("Wrap");
211 // call base at the end because "styles" will reset there