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