[bcl] Remove ONLY_1_1 defines from class libs
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableItemStyle.cs
blob165b09b09e5881699302d08813e7a639b64c65fb
1 //
2 // System.Web.UI.WebControls.TableItemStyle.cs
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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;
32 using System.Web.UI;
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 [Flags]
41 enum TableItemStyles
43 HorizontalAlign = 0x00010000,
44 VerticalAlign = 0x00020000,
45 Wrap = 0x00040000,
48 public TableItemStyle ()
52 public TableItemStyle (StateBag bag)
53 : base (bag)
57 [DefaultValue (HorizontalAlign.NotSet)]
58 [NotifyParentProperty (true)]
59 [WebSysDescription ("")]
60 [WebCategory("Layout")]
61 public virtual HorizontalAlign HorizontalAlign {
62 get {
63 if (!CheckBit ((int) TableItemStyles.HorizontalAlign))
64 return HorizontalAlign.NotSet;
65 return (HorizontalAlign) ViewState ["HorizontalAlign"];
67 set {
68 // avoid reflection
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 {
83 get {
84 if (!CheckBit ((int) TableItemStyles.VerticalAlign))
85 return VerticalAlign.NotSet;
86 return (VerticalAlign) ViewState ["VerticalAlign"];
88 set {
89 // avoid reflection
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);
99 [DefaultValue (true)]
100 [NotifyParentProperty (true)]
101 [WebSysDescription ("")]
102 [WebCategory("Layout")]
103 public virtual bool Wrap {
104 get {
105 if (!CheckBit ((int) TableItemStyles.Wrap))
106 return true;
107 return (bool) ViewState ["Wrap"];
109 set {
110 ViewState ["Wrap"] = value;
111 SetBit ((int) TableItemStyles.Wrap);
116 public override void AddAttributesToRender (HtmlTextWriter writer, WebControl owner)
118 base.AddAttributesToRender (writer, owner);
119 if (writer == null)
120 return;
122 // note: avoid ToString on the enum
123 switch (HorizontalAlign) {
124 case HorizontalAlign.Left:
125 writer.AddAttribute (HtmlTextWriterAttribute.Align, "left", false);
126 break;
127 case HorizontalAlign.Center:
128 writer.AddAttribute (HtmlTextWriterAttribute.Align, "center", false);
129 break;
130 case HorizontalAlign.Right:
131 writer.AddAttribute (HtmlTextWriterAttribute.Align, "right", false);
132 break;
133 case HorizontalAlign.Justify:
134 writer.AddAttribute (HtmlTextWriterAttribute.Align, "justify", false);
135 break;
138 // note: avoid ToString on the enum
139 switch (VerticalAlign) {
140 case VerticalAlign.Top:
141 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "top", false);
142 break;
143 case VerticalAlign.Middle:
144 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "middle", false);
145 break;
146 case VerticalAlign.Bottom:
147 writer.AddAttribute (HtmlTextWriterAttribute.Valign, "bottom", false);
148 break;
151 if (!Wrap) {
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];
160 if (o != null) {
161 ViewState [name] = o;
162 SetBit ((int) s);
167 public override void CopyFrom (Style s)
169 base.CopyFrom (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];
181 if (o != null) {
182 ViewState [name] = o;
183 SetBit ((int) s);
188 public override void MergeWith (Style s)
190 // if we're empty then it's like a copy
191 if (IsEmpty) {
192 CopyFrom (s);
193 } else {
194 base.MergeWith (s);
195 if (s != null) {
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
212 base.Reset ();