3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Namespace: System.Web.UI.WebControls
24 * Class: TableItemStyle
26 * Author: Gaurav Vaish
27 * Maintainer: gvaish@iitk.ac.in
28 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
32 * (C) Gaurav Vaish (2002)
36 using System
.ComponentModel
;
40 namespace System
.Web
.UI
.WebControls
42 public class TableItemStyle
: Style
44 private static int H_ALIGN
= (0x01 << 16);
45 private static int V_ALIGN
= (0x01 << 17);
46 private static int WRAP
= (0x01 << 18);
48 public TableItemStyle(): base()
52 public TableItemStyle(StateBag bag
): base(bag
)
57 [DefaultValue(HorizontalAlign
.NotSet
)]
58 [NotifyParentProperty(true)]
59 [WebCategory("Layout")]
60 [WebSysDescription("TableItemStyle_HorizontalAlign")]
61 public virtual HorizontalAlign HorizontalAlign
66 return (HorizontalAlign
)ViewState
["HorizontalAlign"];
67 return HorizontalAlign
.NotSet
;
71 if(!Enum
.IsDefined(typeof(HorizontalAlign
), value))
73 throw new ArgumentException();
75 ViewState
["HorizontalAlign"] = value;
81 [DefaultValue(VerticalAlign
.NotSet
)]
82 [NotifyParentProperty(true)]
83 [WebCategory("Layout")]
84 [WebSysDescription("TableItemStyle_VerticalAlign")]
85 public virtual VerticalAlign VerticalAlign
90 return (VerticalAlign
)ViewState
["VerticalAlign"];
91 return VerticalAlign
.NotSet
;
95 if(!Enum
.IsDefined(typeof(VerticalAlign
), value))
97 throw new ArgumentException();
99 ViewState
["VerticalAlign"] = value;
105 [DefaultValue(VerticalAlign
.NotSet
)]
106 [NotifyParentProperty(true)]
107 [WebCategory("Layout")]
108 [WebSysDescription("TableItemStyle_Wrap")]
109 public virtual bool Wrap
114 return (bool)ViewState
["Wrap"];
119 ViewState
["Wrap"] = value;
124 public override void CopyFrom(Style s
)
126 if(s
!=null && !s
.IsEmpty
)
130 if (!(s
is TableItemStyle
))
133 TableItemStyle
from = (TableItemStyle
)s
;
134 if(from.IsSet(H_ALIGN
))
136 HorizontalAlign
= from.HorizontalAlign
;
138 if(from.IsSet(V_ALIGN
))
140 VerticalAlign
= from.VerticalAlign
;
149 public override void MergeWith(Style s
)
151 if(s
!=null && !s
.IsEmpty
)
159 if (!(s
is TableItemStyle
))
162 TableItemStyle with
= (TableItemStyle
)s
;
163 if(with
.IsSet(H_ALIGN
) && !IsSet(H_ALIGN
))
165 HorizontalAlign
= with
.HorizontalAlign
;
167 if(with
.IsSet(V_ALIGN
) && !IsSet(V_ALIGN
))
169 VerticalAlign
= with
.VerticalAlign
;
171 if(with
.IsSet(WRAP
) && !IsSet(WRAP
))
178 public override void Reset()
181 ViewState
.Remove("HorizontalAlign");
183 ViewState
.Remove("VerticalAlign");
185 ViewState
.Remove("Wrap");
189 public override void AddAttributesToRender(HtmlTextWriter writer
, WebControl owner
)
191 base.AddAttributesToRender(writer
, owner
);
194 writer
.AddAttribute(HtmlTextWriterAttribute
.Nowrap
, "nowrap");
196 if(HorizontalAlign
!= HorizontalAlign
.NotSet
)
198 // Temporarily commented out. I'm having problems in cygwin.
199 //writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));
200 writer
.AddAttribute(HtmlTextWriterAttribute
.Align
, HorizontalAlign
.ToString ());
202 if(VerticalAlign
!= VerticalAlign
.NotSet
)
204 // Temporarily commented out. I'm having problems in cygwin.
205 //writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));
206 writer
.AddAttribute(HtmlTextWriterAttribute
.Valign
, VerticalAlign
.ToString ());