2003-12-04 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                         }\r
100                 }\r
101 \r
102                 public override void CopyFrom(Style s)\r
103                 {\r
104                         if(s!=null && !s.IsEmpty)\r
105                         {\r
106                                 base.CopyFrom(s);\r
107 \r
108                                 if (!(s is TableItemStyle))\r
109                                         return;\r
110                                 \r
111                                 TableItemStyle from = (TableItemStyle)s;\r
112                                 if(from.IsSet(H_ALIGN))\r
113                                 {\r
114                                         HorizontalAlign = from.HorizontalAlign;\r
115                                 }\r
116                                 if(from.IsSet(V_ALIGN))\r
117                                 {\r
118                                         VerticalAlign = from.VerticalAlign;\r
119                                 }\r
120                                 if(from.IsSet(WRAP))\r
121                                 {\r
122                                         Wrap = from.Wrap;\r
123                                 }\r
124                         }\r
125                 }\r
126 \r
127                 public override void MergeWith(Style s)\r
128                 {\r
129                         if(s!=null && !s.IsEmpty)\r
130                         {\r
131                                 if (IsEmpty) {\r
132                                         CopyFrom (s);\r
133                                         return;\r
134                                 }\r
135                                 base.MergeWith(s);\r
136 \r
137                                 if (!(s is TableItemStyle))\r
138                                         return;\r
139                                 \r
140                                 TableItemStyle with = (TableItemStyle)s;\r
141                                 if(with.IsSet(H_ALIGN) && !IsSet(H_ALIGN))\r
142                                 {\r
143                                         HorizontalAlign = with.HorizontalAlign;\r
144                                 }\r
145                                 if(with.IsSet(V_ALIGN) && !IsSet(V_ALIGN))\r
146                                 {\r
147                                         VerticalAlign = with.VerticalAlign;\r
148                                 }\r
149                                 if(with.IsSet(WRAP) && !IsSet(WRAP))\r
150                                 {\r
151                                         Wrap = with.Wrap;\r
152                                 }\r
153                         }\r
154                 }\r
155 \r
156                 public override void Reset()\r
157                 {\r
158                         if(IsSet(H_ALIGN))\r
159                                 ViewState.Remove("HorizontalAlign");\r
160                         if(IsSet(V_ALIGN))\r
161                                 ViewState.Remove("VerticalAlign");\r
162                         if(IsSet(WRAP))\r
163                                 ViewState.Remove("Wrap");\r
164                         base.Reset();\r
165                 }\r
166 \r
167                 public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)\r
168                 {\r
169                         base.AddAttributesToRender(writer, owner);\r
170                         if(!Wrap)\r
171                         {\r
172                                 writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");\r
173                         }\r
174                         if(HorizontalAlign != HorizontalAlign.NotSet)\r
175                         {\r
176                                 // Temporarily commented out. I'm having problems in cygwin.\r
177                                 //writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));\r
178                                 writer.AddAttribute(HtmlTextWriterAttribute.Align, HorizontalAlign.ToString ());\r
179                         }\r
180                         if(VerticalAlign != VerticalAlign.NotSet)\r
181                         {\r
182                                 // Temporarily commented out. I'm having problems in cygwin.\r
183                                 //writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));\r
184                                 writer.AddAttribute(HtmlTextWriterAttribute.Valign, VerticalAlign.ToString ());\r
185                         }\r
186                 }\r
187         }\r
188 }\r