2002-03-17 Gaurav Vaish <gvaish@iitk.ac.in>
[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                 public virtual HorizontalAlign HorizontalAlign\r
36                 {\r
37                         get\r
38                         {\r
39                                 if(IsSet(H_ALIGN))\r
40                                         return (HorizontalAlign)ViewState["HorizontalAlign"];\r
41                                 return HorizontalAlign.NotSet;\r
42                         }\r
43                         set\r
44                         {\r
45                                 if(!Enum.IsDefined(typeof(HorizontalAlign), value))\r
46                                 {\r
47                                         throw new ArgumentException();\r
48                                 }\r
49                                 ViewState["HorizontalAlign"] = value;\r
50                                 Set(H_ALIGN);\r
51                         }\r
52                 }\r
53 \r
54                 public virtual VerticalAlign VerticalAlign\r
55                 {\r
56                         get\r
57                         {\r
58                                 if(IsSet(V_ALIGN))\r
59                                         return (VerticalAlign)ViewState["VerticalAlign"];\r
60                                 return VerticalAlign.NotSet;\r
61                         }\r
62                         set\r
63                         {\r
64                                 if(!Enum.IsDefined(typeof(VerticalAlign), value))\r
65                                 {\r
66                                         throw new ArgumentException();\r
67                                 }\r
68                                 ViewState["VerticalAlign"] = value;\r
69                                 Set(V_ALIGN);\r
70                         }\r
71                 }\r
72 \r
73                 public virtual bool Wrap\r
74                 {\r
75                         get\r
76                         {\r
77                                 if(IsSet(WRAP))\r
78                                         return (bool)ViewState["Wrap"];\r
79                                 return true;\r
80                         }\r
81                         set\r
82                         {\r
83                                 ViewState["Wrap"] = value;\r
84                         }\r
85                 }\r
86 \r
87                 public override void CopyFrom(Style s)\r
88                 {\r
89                         if(s!=null && s is TableItemStyle && !s.IsEmpty)\r
90                         {\r
91                                 base.CopyFrom(s);\r
92                                 TableItemStyle from = (TableItemStyle)s;\r
93                                 if(from.IsSet(H_ALIGN))\r
94                                 {\r
95                                         HorizontalAlign = from.HorizontalAlign;\r
96                                 }\r
97                                 if(from.IsSet(V_ALIGN))\r
98                                 {\r
99                                         VerticalAlign = from.VerticalAlign;\r
100                                 }\r
101                                 if(from.IsSet(WRAP))\r
102                                 {\r
103                                         Wrap = from.Wrap;\r
104                                 }\r
105                         }\r
106                 }\r
107 \r
108                 public override void MergeWith(Style s)\r
109                 {\r
110                         if(s!=null && s is TableItemStyle && !s.IsEmpty)\r
111                         {\r
112                                 base.MergeWith(s);\r
113                                 TableItemStyle with = (TableItemStyle)s;\r
114                                 if(with.IsSet(H_ALIGN) && !IsSet(H_ALIGN))\r
115                                 {\r
116                                         HorizontalAlign = with.HorizontalAlign;\r
117                                 }\r
118                                 if(with.IsSet(V_ALIGN) && !IsSet(V_ALIGN))\r
119                                 {\r
120                                         VerticalAlign = with.VerticalAlign;\r
121                                 }\r
122                                 if(with.IsSet(WRAP) && !IsSet(WRAP))\r
123                                 {\r
124                                         Wrap = with.Wrap;\r
125                                 }\r
126                         }\r
127                 }\r
128 \r
129                 public override void Reset()\r
130                 {\r
131                         if(IsSet(H_ALIGN))\r
132                                 ViewState.Remove("HorizontalAlign");\r
133                         if(IsSet(V_ALIGN))\r
134                                 ViewState.Remove("VerticalAlign");\r
135                         if(IsSet(WRAP))\r
136                                 ViewState.Remove("Wrap");\r
137                         base.Reset();\r
138                 }\r
139 \r
140                 public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)\r
141                 {\r
142                         base.AddAttributesToRender(writer, owner);\r
143                         if(!Wrap)\r
144                         {\r
145                                 writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");\r
146                         }\r
147                         if(HorizontalAlign != HorizontalAlign.NotSet)\r
148                         {\r
149                                 writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));\r
150                         }\r
151                         if(VerticalAlign != VerticalAlign.NotSet)\r
152                         {\r
153                                 writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));\r
154                         }\r
155                 }\r
156         }\r
157 }\r