2006-04-11 Lluis Sanchez <lluis@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CheckBoxField.cs
1 //
2 // System.Web.UI.WebControls.CheckBoxField.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         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         public class CheckBoxField : BoundField
43         {
44             [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
45             [BrowsableAttribute (false)]\r
46             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
47                 public override bool ConvertEmptyStringToNull {
48                         get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
49                         set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
50                 }
51                 
52             [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
53             [BrowsableAttribute (false)]\r
54             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
55                 public override string DataFormatString {
56                         get { throw GetNotSupportedPropException ("DataFormatString"); } 
57                         set { throw GetNotSupportedPropException ("DataFormatString"); } 
58                 }
59                 
60             [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
61             [BrowsableAttribute (false)]\r
62             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
63                 public override bool HtmlEncode {
64                         get { throw GetNotSupportedPropException ("HtmlEncode"); } 
65                         set { throw GetNotSupportedPropException ("HtmlEncode"); } 
66                 }
67                 
68             [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
69             [BrowsableAttribute (false)]\r
70             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
71                 public override string NullDisplayText {
72                         get { throw GetNotSupportedPropException ("NullDisplayText"); } 
73                         set { throw GetNotSupportedPropException ("NullDisplayText"); } 
74                 }
75                 
76                 protected override bool SupportsHtmlEncode {
77                         get { return false; }
78                 }
79                 
80                 [LocalizableAttribute (true)]
81                 [DefaultValueAttribute ("")]
82                 [WebSysDescription ("")]
83                 [WebCategoryAttribute ("Appearance")]
84                 public virtual string Text {
85                         get { return ViewState.GetString ("Text", ""); }
86                         set {
87                                 ViewState ["Text"] = value;
88                                 OnFieldChanged ();
89                         }
90                 }
91                 
92                 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
93                 {
94                         bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
95                         CheckBox box = new CheckBox ();
96                         box.Enabled = editable && !ReadOnly;
97                         cell.Controls.Add (box);
98                 }
99                 
100                 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
101                         DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
102                 {
103                         CheckBox box = (CheckBox) cell.Controls [0];
104                         dictionary [DataField] = box.Checked;
105                 }
106                 
107                 protected override void OnDataBindField (object sender, EventArgs e)
108                 {
109                         DataControlFieldCell cell = (DataControlFieldCell) sender;
110                         CheckBox box = (CheckBox) cell.Controls [0];
111                         object val = GetValue (cell.BindingContainer);
112                         if (val != null) {
113                                 box.Checked = (bool)val;
114                                 if (!box.Visible)
115                                         box.Visible = true;
116                         }
117                         else
118                                 box.Visible = false;
119                 }
120                 
121                 protected override object GetDesignTimeValue ()
122                 {
123                         return true;
124                 }
125                 
126                 protected override DataControlField CreateField ()
127                 {
128                         return new CheckBoxField ();
129                 }
130                 
131                 protected override void CopyProperties (DataControlField newField)
132                 {
133                         CheckBoxField field = (CheckBoxField) newField;
134                         field.DataField = DataField;
135                         field.ReadOnly = ReadOnly;
136                         field.Text = Text;
137                 }
138         }
139 }
140 #endif