2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableItemStyle.cs
1
2 //
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:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
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.
21 //
22 /**\r
23  * Namespace: System.Web.UI.WebControls\r
24  * Class:     TableItemStyle\r
25  *\r
26  * Author:  Gaurav Vaish\r
27  * Maintainer: gvaish@iitk.ac.in\r
28  * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
29  * Implementation: yes\r
30  * Status:  100%\r
31  *\r
32  * (C) Gaurav Vaish (2002)\r
33  */\r
34 \r
35 using System;\r
36 using System.ComponentModel;\r
37 using System.Web;\r
38 using System.Web.UI;\r
39 \r
40 namespace System.Web.UI.WebControls\r
41 {\r
42         public class TableItemStyle: Style\r
43         {\r
44                 private static int H_ALIGN = (0x01 << 16);\r
45                 private static int V_ALIGN = (0x01 << 17);\r
46                 private static int WRAP    = (0x01 << 18);\r
47 \r
48                 public TableItemStyle(): base()\r
49                 {\r
50                 }\r
51 \r
52                 public TableItemStyle(StateBag bag): base(bag)\r
53                 {\r
54                 }\r
55 \r
56                 [Bindable(true)]\r
57                 [DefaultValue(HorizontalAlign.NotSet)]\r
58                 [NotifyParentProperty(true)]\r
59                 [WebCategory("Layout")]\r
60                 [WebSysDescription("TableItemStyle_HorizontalAlign")]\r
61                 public virtual HorizontalAlign HorizontalAlign\r
62                 {\r
63                         get\r
64                         {\r
65                                 if(IsSet(H_ALIGN))\r
66                                         return (HorizontalAlign)ViewState["HorizontalAlign"];\r
67                                 return HorizontalAlign.NotSet;\r
68                         }\r
69                         set\r
70                         {\r
71                                 if(!Enum.IsDefined(typeof(HorizontalAlign), value))\r
72                                 {\r
73                                         throw new ArgumentException();\r
74                                 }\r
75                                 ViewState["HorizontalAlign"] = value;\r
76                                 Set(H_ALIGN);\r
77                         }\r
78                 }\r
79 \r
80                 [Bindable(true)]\r
81                 [DefaultValue(VerticalAlign.NotSet)]\r
82                 [NotifyParentProperty(true)]\r
83                 [WebCategory("Layout")]\r
84                 [WebSysDescription("TableItemStyle_VerticalAlign")]\r
85                 public virtual VerticalAlign VerticalAlign\r
86                 {\r
87                         get\r
88                         {\r
89                                 if(IsSet(V_ALIGN))\r
90                                         return (VerticalAlign)ViewState["VerticalAlign"];\r
91                                 return VerticalAlign.NotSet;\r
92                         }\r
93                         set\r
94                         {\r
95                                 if(!Enum.IsDefined(typeof(VerticalAlign), value))\r
96                                 {\r
97                                         throw new ArgumentException();\r
98                                 }\r
99                                 ViewState["VerticalAlign"] = value;\r
100                                 Set(V_ALIGN);\r
101                         }\r
102                 }\r
103 \r
104                 [Bindable(true)]\r
105                 [DefaultValue(VerticalAlign.NotSet)]\r
106                 [NotifyParentProperty(true)]\r
107                 [WebCategory("Layout")]\r
108                 [WebSysDescription("TableItemStyle_Wrap")]\r
109                 public virtual bool Wrap\r
110                 {\r
111                         get\r
112                         {\r
113                                 if(IsSet(WRAP))\r
114                                         return (bool)ViewState["Wrap"];\r
115                                 return true;\r
116                         }\r
117                         set\r
118                         {\r
119                                 ViewState["Wrap"] = value;\r
120                                 Set(WRAP);\r
121                         }\r
122                 }\r
123 \r
124                 public override void CopyFrom(Style s)\r
125                 {\r
126                         if(s!=null && !s.IsEmpty)\r
127                         {\r
128                                 base.CopyFrom(s);\r
129 \r
130                                 if (!(s is TableItemStyle))\r
131                                         return;\r
132                                 \r
133                                 TableItemStyle from = (TableItemStyle)s;\r
134                                 if(from.IsSet(H_ALIGN))\r
135                                 {\r
136                                         HorizontalAlign = from.HorizontalAlign;\r
137                                 }\r
138                                 if(from.IsSet(V_ALIGN))\r
139                                 {\r
140                                         VerticalAlign = from.VerticalAlign;\r
141                                 }\r
142                                 if(from.IsSet(WRAP))\r
143                                 {\r
144                                         Wrap = from.Wrap;\r
145                                 }\r
146                         }\r
147                 }\r
148 \r
149                 public override void MergeWith(Style s)\r
150                 {\r
151                         if(s!=null && !s.IsEmpty)\r
152                         {\r
153                                 if (IsEmpty) {\r
154                                         CopyFrom (s);\r
155                                         return;\r
156                                 }\r
157                                 base.MergeWith(s);\r
158 \r
159                                 if (!(s is TableItemStyle))\r
160                                         return;\r
161                                 \r
162                                 TableItemStyle with = (TableItemStyle)s;\r
163                                 if(with.IsSet(H_ALIGN) && !IsSet(H_ALIGN))\r
164                                 {\r
165                                         HorizontalAlign = with.HorizontalAlign;\r
166                                 }\r
167                                 if(with.IsSet(V_ALIGN) && !IsSet(V_ALIGN))\r
168                                 {\r
169                                         VerticalAlign = with.VerticalAlign;\r
170                                 }\r
171                                 if(with.IsSet(WRAP) && !IsSet(WRAP))\r
172                                 {\r
173                                         Wrap = with.Wrap;\r
174                                 }\r
175                         }\r
176                 }\r
177 \r
178                 public override void Reset()\r
179                 {\r
180                         if(IsSet(H_ALIGN))\r
181                                 ViewState.Remove("HorizontalAlign");\r
182                         if(IsSet(V_ALIGN))\r
183                                 ViewState.Remove("VerticalAlign");\r
184                         if(IsSet(WRAP))\r
185                                 ViewState.Remove("Wrap");\r
186                         base.Reset();\r
187                 }\r
188 \r
189                 public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)\r
190                 {\r
191                         base.AddAttributesToRender(writer, owner);\r
192                         if(!Wrap)\r
193                         {\r
194                                 writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");\r
195                         }\r
196                         if(HorizontalAlign != HorizontalAlign.NotSet)\r
197                         {\r
198                                 // Temporarily commented out. I'm having problems in cygwin.\r
199                                 //writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));\r
200                                 writer.AddAttribute(HtmlTextWriterAttribute.Align, HorizontalAlign.ToString ());\r
201                         }\r
202                         if(VerticalAlign != VerticalAlign.NotSet)\r
203                         {\r
204                                 // Temporarily commented out. I'm having problems in cygwin.\r
205                                 //writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));\r
206                                 writer.AddAttribute(HtmlTextWriterAttribute.Valign, VerticalAlign.ToString ());\r
207                         }\r
208                 }\r
209         }\r
210 }\r