2 // System.Web.UI.WebControls.DataControlField.cs
5 // Sanjay Gupta (gsanjay@novell.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
8 // (C) 2004 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Specialized;
36 using System.ComponentModel;
37 using System.Security.Permissions;
39 namespace System.Web.UI.WebControls {
41 [DefaultPropertyAttribute ("HeaderText")]
42 [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
43 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
45 public abstract class DataControlField : IStateManager, IDataSourceViewSchemaAccessor
47 bool tracking = false;
51 TableItemStyle footerStyle;
52 TableItemStyle headerStyle;
53 TableItemStyle itemStyle;
56 protected DataControlField()
58 viewState = new StateBag ();
61 internal void SetDirty ()
63 viewState.SetDirty (true);
66 protected StateBag ViewState {
67 get { return viewState; }
70 public virtual void ExtractValuesFromCell (IOrderedDictionary dictionary,
71 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
75 public virtual bool Initialize (bool sortingEnabled, Control control)
77 this.sortingEnabled = sortingEnabled;
78 this.control = control;
82 public virtual void InitializeCell (DataControlFieldCell cell,
83 DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
85 if (cellType == DataControlCellType.Header)
87 if (HeaderText.Length > 0 || HeaderImageUrl.Length > 0) {
88 if (sortingEnabled && SortExpression.Length > 0)
89 cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, DataControlCommands.SortCommandName, SortExpression, true));
91 cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, string.Empty, true));
94 else if (cellType == DataControlCellType.Footer) {
95 cell.Text = FooterText;
99 protected internal DataControlField CloneField ()
101 DataControlField field = CreateField ();
102 CopyProperties (field);
106 protected abstract DataControlField CreateField ();
108 protected virtual void CopyProperties (DataControlField newField)
110 newField.AccessibleHeaderText = AccessibleHeaderText;
111 newField.ControlStyle.CopyFrom (ControlStyle);
112 newField.FooterStyle.CopyFrom (FooterStyle);
113 newField.FooterText = FooterText;
114 newField.HeaderImageUrl = HeaderImageUrl;
115 newField.HeaderStyle.CopyFrom (HeaderStyle);
116 newField.HeaderText = HeaderText;
117 newField.InsertVisible = InsertVisible;
118 newField.ItemStyle.CopyFrom (ItemStyle);
119 newField.ShowHeader = ShowHeader;
120 newField.SortExpression = SortExpression;
121 newField.Visible = Visible;
124 protected virtual void OnFieldChanged ()
126 if (FieldChanged != null)
127 FieldChanged (this, EventArgs.Empty);
130 protected virtual void LoadViewState (object savedState)
132 if (savedState == null)
135 object [] states = (object []) savedState;
136 viewState.LoadViewState (states[0]);
138 if (states[1] != null)
139 ((IStateManager)controlStyle).LoadViewState (states[1]);
140 if (states[2] != null)
141 ((IStateManager)footerStyle).LoadViewState (states[2]);
142 if (states[3] != null)
143 ((IStateManager)headerStyle).LoadViewState (states[3]);
144 if (states[4] != null)
145 ((IStateManager)itemStyle).LoadViewState (states[4]);
148 protected virtual object SaveViewState()
150 object[] state = new object [5];
151 state [0] = viewState.SaveViewState ();
152 if (controlStyle != null)
153 state [1] = ((IStateManager) controlStyle).SaveViewState ();
154 if (footerStyle != null)
155 state [2] = ((IStateManager) footerStyle).SaveViewState ();
156 if (headerStyle != null)
157 state [3] = ((IStateManager) headerStyle).SaveViewState ();
158 if (itemStyle != null)
159 state [4] = ((IStateManager) itemStyle).SaveViewState ();
161 if (state [0] == null && state [1] == null && state [2] == null &&
162 state [3] == null && state [4] == null)
168 protected virtual void TrackViewState()
170 if (controlStyle != null) ((IStateManager) controlStyle).TrackViewState ();
171 if (footerStyle != null) ((IStateManager) footerStyle).TrackViewState ();
172 if (headerStyle != null) ((IStateManager) headerStyle).TrackViewState ();
173 if (itemStyle != null) ((IStateManager) itemStyle).TrackViewState ();
174 viewState.TrackViewState ();
178 public virtual void ValidateSupportsCallback ()
180 throw new NotSupportedException ("Callback not supported");
183 void IStateManager.LoadViewState(object savedState)
185 LoadViewState(savedState);
188 object IStateManager.SaveViewState()
190 return SaveViewState();
193 void IStateManager.TrackViewState()
198 internal Exception GetNotSupportedPropException (string propName)
200 return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name);
203 [MonoTODO ("Render this")]
204 [DefaultValueAttribute ("")]
205 [LocalizableAttribute (true)]
206 [WebCategoryAttribute ("Accessibility")]
207 public virtual string AccessibleHeaderText {
209 object val = viewState ["accessibleHeaderText"];
210 return val != null ? (string) val : "";
213 viewState ["accessibleHeaderText"] = value;
218 protected Control Control {
219 get { return control; }
222 [WebCategoryAttribute ("Styles")]
223 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
224 [DefaultValueAttribute (null)]
225 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
226 public Style ControlStyle {
228 if (controlStyle == null) {
229 controlStyle = new Style ();
230 if (IsTrackingViewState)
231 controlStyle.TrackViewState();
237 protected bool DesignMode {
238 get { return control != null && control.Site != null ? control.Site.DesignMode : false; }
241 [DefaultValueAttribute (null)]
242 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
243 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
244 [WebCategoryAttribute ("Styles")]
245 public TableItemStyle FooterStyle {
247 if (footerStyle == null) {
248 footerStyle = new TableItemStyle ();
249 if (IsTrackingViewState)
250 footerStyle.TrackViewState();
256 [LocalizableAttribute (true)]
257 [WebCategoryAttribute ("Appearance")]
259 public virtual string FooterText {
261 object val = viewState ["footerText"];
262 return val != null ? (string) val : "";
265 viewState ["footerText"] = value;
270 [UrlPropertyAttribute]
271 [DefaultValueAttribute ("")]
272 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
273 [WebCategoryAttribute ("Appearance")]
274 public virtual string HeaderImageUrl {
276 object val = viewState ["headerImageUrl"];
277 return val != null ? (string) val : "";
280 viewState ["headerImageUrl"] = value;
285 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
286 [WebCategoryAttribute ("Styles")]
287 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
288 [DefaultValueAttribute (null)]
289 public TableItemStyle HeaderStyle {
291 if (headerStyle == null) {
292 headerStyle = new TableItemStyle ();
293 if (IsTrackingViewState)
294 headerStyle.TrackViewState();
300 [DefaultValueAttribute ("")]
301 [LocalizableAttribute (true)]
302 [WebCategoryAttribute ("Appearance")]
303 public virtual string HeaderText {
305 object val = viewState ["headerText"];
306 return val != null ? (string) val : "";
309 viewState ["headerText"] = value;
314 [WebCategoryAttribute ("Behavior")]
315 [DefaultValueAttribute (true)]
316 public virtual bool InsertVisible {
318 object val = viewState ["InsertVisible"];
319 return val != null ? (bool) val : true;
322 viewState ["InsertVisible"] = value;
327 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
328 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
329 [WebCategoryAttribute ("Styles")]
330 [DefaultValueAttribute (null)]
331 public TableItemStyle ItemStyle {
333 if (itemStyle == null) {
334 itemStyle = new TableItemStyle ();
335 if (IsTrackingViewState)
336 itemStyle.TrackViewState();
342 [WebCategoryAttribute ("Behavior")]
343 [DefaultValueAttribute (true)]
344 public virtual bool ShowHeader {
346 object val = viewState ["showHeader"];
347 return val != null ? (bool) val : true;
350 viewState ["showHeader"] = value;
355 [DefaultValueAttribute ("")]
356 // [TypeConverterAttribute ("System.Web.UI.Design.DataSourceViewSchemaConverter, " + Consts.AssemblySystem_Design)]
357 [WebCategoryAttribute ("Behavior")]
358 public virtual string SortExpression {
360 object val = viewState ["sortExpression"];
361 return val != null ? (string) val : "";
364 viewState ["sortExpression"] = value;
369 [WebCategoryAttribute ("Behavior")]
370 [DefaultValueAttribute (true)]
371 public bool Visible {
373 object val = viewState ["visible"];
374 return val != null ? (bool) val : true;
377 viewState ["visible"] = value;
382 protected bool IsTrackingViewState
384 get { return tracking; }
387 bool IStateManager.IsTrackingViewState
389 get { return IsTrackingViewState; }
392 object IDataSourceViewSchemaAccessor.DataSourceViewSchema {
393 get { return viewState ["dataSourceViewSchema"]; }
395 viewState ["dataSourceViewSchema"] = value;
399 internal event EventHandler FieldChanged;