More files from Toelen
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlTextArea.cs
1 /*      System.Web.UI.HtmlControls
2 *       Authors
3 *               Leen Toelen (toelen@hotmail.com)
4 */
5
6 using System;
7 using System.Web;
8 using System.Web.UI;
9 using System.ComponentModel;
10 using System.Globalization;
11 using System.Collections.Specialized;
12
13 namespace System.Web.UI.HtmlControls{
14         
15         public class HtmlTextArea : HtmlContainerControl, IPostBackDataHandler{
16                 
17                 private static readonly object EventServerChange;
18                 
19                 public HtmlTextArea(): base("textarea"){}
20                 
21                 public int Cols{
22                         get{
23                                 string attr = Attributes["cols"];
24                                 if (attr != null){
25                                         return Int32.Parse(attr, CultureInfo.InvariantCulture);
26                                 }
27                                 return -1;
28                         }
29                         set{
30                                 //MapIntegerAttributeToString(value) accessible constraint is "assembly"
31                                 Attributes["cols"] = MapIntegerAttributeToString(value);
32                         }
33                 }
34                 
35                 public int Rows{
36                         get{
37                                 string attr = Attributes["rows"];
38                                 if (attr != null){
39                                         return Int32.Parse(attr, CultureInfo.InvariantCulture);;
40                                 }
41                                 return -1;
42                         }
43                         set{
44                                 //MapIntegerAttributeToString(value) accessible constraint is "assembly"
45                                 Attributes["rows"] = MapIntegerAttributeToString(value);
46                         }
47                 }
48                 
49                 public string Value{
50                         get{
51                                 return InnerHtml;
52                         }
53                         set{
54                                 InnerHtml = value;
55                         }
56                 }
57                 
58                 protected string RenderedNameAttribute{
59                         get{
60                                 return Name;
61                         }
62                 }
63                 
64                 public virtual string Name{
65                         get{
66                                 if (UniqueID != null){
67                                         return UniqueID;
68                                 }
69                                 return String.Empty;
70                         }
71                         set{}
72                 }
73                 
74                 public event EventHandler ServerChange{
75                         add{
76                                 Events.AddHandler(EventServerChange, value);
77                         }
78                         remove{
79                                 Events.RemoveHandler(EventServerChange, value);
80                         }
81                 }
82                 
83                 protected virtual void OnServerChange(EventArgs e){
84                         EventHandler handler;
85                         handler = (EventHandler) Events[EventServerChange];
86                         if(handler != null){
87                                 handler.Invoke(this, e);
88                         }
89                 }
90                 
91                 //FIXME: not sure about the accessor
92                 public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
93                         string currentValue = Value;
94                         string postedValue = postCollection[postDataKey];
95                         if (!currentValue.Equals(postedValue) && currentValue != null){
96                                 Value = HttpUtility.HtmlEncode(postedValue);
97                                 return true;
98                         }
99                         return false;
100                         
101                 }
102                 
103                 protected override void RenderAttributes(HtmlTextWriter writer){
104                         writer.WriteAttribute("name", RenderedNameAttribute);
105                         base.Attributes.Remove("name");
106                         base.RenderAttributes(writer);
107                 }
108                 
109                 //FIXME: not sure about the accessor
110                 public void RaisePostDataChangedEvent(){
111                         OnServerChange(EventArgs.Empty);
112                 }
113                 
114                 protected override void OnPreRender(EventArgs e){
115                         if(Events[EventServerChange]==null || Disabled==true){
116                                 ViewState.SetItemDirty("value",false);
117                         }
118                 }
119                 
120                 protected override void AddParsedSubObject(object obj){
121                         //FIXME: not sure about this function
122                         if (obj is LiteralControl || obj is DataBoundLiteralControl){
123                                 AddParsedSubObject(obj);
124                                 return;
125                         }
126                         //FormatResourceString accessible constraint is "assembly"
127                         throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type","HtmlTextArea",obj.GetType.Name));
128                 }
129                 
130         } // class HtmlTextArea
131 } // namespace System.Web.UI.HtmlControls
132