merge from trunk revisions 58933, 58935, 58936
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AutoGeneratedField.cs
1 //
2 // System.Web.UI.WebControls.AutoGeneratedField.cs
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Web.UI;
35 using System.ComponentModel;
36 using System.Security.Permissions;
37
38 namespace System.Web.UI.WebControls {
39
40         [EditorBrowsableAttribute (EditorBrowsableState.Never)]
41         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43         public sealed class AutoGeneratedField : BoundField
44         {
45                 Type dataType;
46                 
47                 internal AutoGeneratedField ()
48                 {
49                 }
50                 
51                 public AutoGeneratedField (string dataField)
52                 {
53                         DataField = dataField;
54                 }
55                 
56                 internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
57                 {
58                         DataField = fieldProperties.DataField;
59                         SortExpression = fieldProperties.DataField;
60                         DataType = fieldProperties.Type;
61                         HeaderText = fieldProperties.Name;
62                         ReadOnly = fieldProperties.IsReadOnly;
63                 }
64                 
65                 [MonoTODO]
66                 public Type DataType {
67                         get { return dataType; }
68                         set { dataType = value; }
69                 }
70                 
71                 public override bool ConvertEmptyStringToNull {
72                         get { return true; }
73                         set { throw new NotSupportedException (); }
74                 }
75
76                 public override string DataFormatString {
77                         get { return string.Empty; }
78                         set { throw new NotSupportedException (); }
79                 }
80
81                 public override bool InsertVisible {
82                         get { return true; }
83                         set { throw new NotSupportedException (); }
84                 }
85                 
86                 [MonoTODO ("Support other data types")]
87                 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
88                         DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
89                 {
90                         if (dataType == typeof(bool)) {
91                                 CheckBox box = (CheckBox) cell.Controls [0];
92                                 dictionary [DataField] = box.Checked;
93                         } else
94                                 base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
95                 }
96                 
97                 
98                 [MonoTODO ("Support other data types")]
99                 public override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
100                 {
101                         bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
102                         
103                         if (dataType == typeof(bool)) {
104                                 CheckBox box = new CheckBox ();
105                                 box.Enabled = editable && !ReadOnly;
106                                 cell.Controls.Add (box);
107                         } else
108                                 base.InitializeDataCell (cell, rowState);
109                 }
110                 
111                 [MonoTODO ("Support other data types")]
112                 protected override void OnDataBindField (object sender, EventArgs e)
113                 {
114                         DataControlFieldCell cell = (DataControlFieldCell) sender;
115                         if (dataType == typeof(bool)) {
116                                 CheckBox box = (CheckBox) cell.Controls [0];
117                                 object val = GetValue (cell.BindingContainer);
118                                 if (val != null) {
119                                         box.Checked = (bool)val;
120                                         if (!box.Visible)
121                                                 box.Visible = true;
122                                 }
123                                 else
124                                         box.Visible = false;
125                         } else
126                                 base.OnDataBindField (sender, e);
127                 }
128                 
129                 public override void ValidateSupportsCallback ()
130                 {
131                 }
132                 
133                 protected override DataControlField CreateField ()
134                 {
135                         return new AutoGeneratedField ();
136                 }
137
138                 protected override void CopyProperties (DataControlField newField)
139                 {
140                         base.CopyProperties (newField);
141                         AutoGeneratedField field = (AutoGeneratedField) newField;
142                         field.DataType = DataType;
143                 }
144
145                 [MonoTODO]
146                 protected override object GetDesignTimeValue()
147                 {
148                         return base.GetDesignTimeValue ();
149                 }
150         }
151 }
152 #endif