2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / System.Web.DynamicData / System.Web.DynamicData / DynamicControl.cs
1 //
2 // DynamicControl.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2008 Novell Inc. http://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 using System;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Drawing;
36 using System.Globalization;
37 using System.Security.Permissions;
38 using System.Security.Principal;
39 using System.Web.Caching;
40 using System.Web.UI;
41 using System.Web.UI.WebControls;
42 using System.Web.DynamicData.ModelProviders;
43
44 namespace System.Web.DynamicData
45 {
46         [ToolboxBitmap (typeof(DynamicControl), "DynamicControl.ico")]
47         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
48         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
49         public class DynamicControl : Control, IAttributeAccessor, IFieldTemplateHost, IFieldFormattingOptions
50         {
51                 Dictionary <string, string> attributes;
52                 
53                 public DynamicControl ()
54                 {
55                 }
56
57                 [MonoTODO]
58                 public DynamicControl (DataBoundControlMode mode)
59                 {
60                         throw new NotImplementedException ();
61                 }
62
63                 [MonoTODO]
64                 [Category ("Behavior")]
65                 [DefaultValue (false)]
66                 public bool ApplyFormatInEditMode { get; set; }
67
68                 [Browsable (false)]
69                 [MonoTODO]
70                 public MetaColumn Column { get; set; }
71
72                 [MonoTODO]
73                 [Category ("Behavior")]
74                 [DefaultValue (false)]
75                 public bool ConvertEmptyStringToNull { get; set; }
76
77                 [MonoTODO]
78                 [Category ("Appearance")]
79                 [DefaultValue ("")]
80                 [CssClassProperty]
81                 public virtual string CssClass { get; set; }
82
83                 [MonoTODO]
84                 [Category ("Data")]
85                 [DefaultValue ("")]
86                 public string DataField { get; set; }
87
88                 [MonoTODO]
89                 [Category ("Data")]
90                 [DefaultValue ("")]
91                 public string DataFormatString { get; set; }
92
93                 [MonoTODO]
94                 [Browsable (false)]
95                 public Control FieldTemplate { get; private set; }
96
97                 [MonoTODO]
98                 [Category ("Behavior")]
99                 [DefaultValue (true)]
100                 public bool HtmlEncode { get; set; }
101
102                 [MonoTODO]
103                 IFieldFormattingOptions IFieldTemplateHost.FormattingOptions {
104                         get { throw new NotImplementedException (); }
105                 }
106
107                 [MonoTODO]
108                 public DataBoundControlMode Mode { get; set; }
109
110                 [MonoTODO]
111                 [Category ("Behavior")]
112                 [DefaultValue ("")]
113                 public string NullDisplayText { get; set; }
114
115                 [MonoTODO]
116                 [Browsable (false)]
117                 public virtual MetaTable Table { get; private set; }
118
119                 [MonoTODO]
120                 [Category ("Behavior")]
121                 [DefaultValue ("")]
122                 public virtual string UIHint { get; set; }
123
124                 [MonoTODO]
125                 [Themeable (false)]
126                 [Category ("Behavior")]
127                 [DefaultValue ("")]
128                 public virtual string ValidationGroup { get; set; }
129                 
130                 public string GetAttribute (string key)
131                 {
132                         if (attributes == null)
133                                 return null;
134
135                         string ret;
136                         if (attributes.TryGetValue (key, out ret))
137                                 return ret;
138
139                         return null;
140                 }
141
142                 [MonoTODO]
143                 protected override void OnInit (EventArgs e)
144                 {
145                         base.OnInit (e);
146                 }
147
148                 protected override void Render (HtmlTextWriter writer)
149                 {
150                         base.Render (writer);
151                         // Why override?
152                 }
153
154                 internal void InternalSetAttributes (Dictionary <string, string> attributes)
155                 {
156                         this.attributes = attributes;
157                 }
158                 
159                 public void SetAttribute (string key, string value)
160                 {
161                         if (attributes == null)
162                                 attributes = new Dictionary <string, string> ();
163
164                         if (attributes.ContainsKey (key))
165                                 attributes [key] = value;
166                         else
167                                 attributes.Add (key, value);
168                 }
169         }
170 }