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));
96 else if (cellType == DataControlCellType.Footer) {
97 string footerText = FooterText;
98 cell.Text = (footerText.Length > 0) ? footerText : " ";
102 protected internal DataControlField CloneField ()
104 DataControlField field = CreateField ();
105 CopyProperties (field);
109 protected abstract DataControlField CreateField ();
111 protected virtual void CopyProperties (DataControlField newField)
113 newField.AccessibleHeaderText = AccessibleHeaderText;
114 newField.ControlStyle.CopyFrom (ControlStyle);
115 newField.FooterStyle.CopyFrom (FooterStyle);
116 newField.FooterText = FooterText;
117 newField.HeaderImageUrl = HeaderImageUrl;
118 newField.HeaderStyle.CopyFrom (HeaderStyle);
119 newField.HeaderText = HeaderText;
120 newField.InsertVisible = InsertVisible;
121 newField.ItemStyle.CopyFrom (ItemStyle);
122 newField.ShowHeader = ShowHeader;
123 newField.SortExpression = SortExpression;
124 newField.Visible = Visible;
127 protected virtual void OnFieldChanged ()
129 if (FieldChanged != null)
130 FieldChanged (this, EventArgs.Empty);
133 protected virtual void LoadViewState (object savedState)
135 if (savedState == null)
138 object [] states = (object []) savedState;
139 viewState.LoadViewState (states[0]);
141 if (states[1] != null)
142 ((IStateManager)controlStyle).LoadViewState (states[1]);
143 if (states[2] != null)
144 ((IStateManager)footerStyle).LoadViewState (states[2]);
145 if (states[3] != null)
146 ((IStateManager)headerStyle).LoadViewState (states[3]);
147 if (states[4] != null)
148 ((IStateManager)itemStyle).LoadViewState (states[4]);
151 protected virtual object SaveViewState()
153 object[] state = new object [5];
154 state [0] = viewState.SaveViewState ();
155 if (controlStyle != null)
156 state [1] = ((IStateManager) controlStyle).SaveViewState ();
157 if (footerStyle != null)
158 state [2] = ((IStateManager) footerStyle).SaveViewState ();
159 if (headerStyle != null)
160 state [3] = ((IStateManager) headerStyle).SaveViewState ();
161 if (itemStyle != null)
162 state [4] = ((IStateManager) itemStyle).SaveViewState ();
164 if (state [0] == null && state [1] == null && state [2] == null &&
165 state [3] == null && state [4] == null)
171 protected virtual void TrackViewState()
173 if (controlStyle != null) ((IStateManager) controlStyle).TrackViewState ();
174 if (footerStyle != null) ((IStateManager) footerStyle).TrackViewState ();
175 if (headerStyle != null) ((IStateManager) headerStyle).TrackViewState ();
176 if (itemStyle != null) ((IStateManager) itemStyle).TrackViewState ();
177 viewState.TrackViewState ();
181 public virtual void ValidateSupportsCallback ()
183 throw new NotSupportedException ("Callback not supported");
186 void IStateManager.LoadViewState(object savedState)
188 LoadViewState(savedState);
191 object IStateManager.SaveViewState()
193 return SaveViewState();
196 void IStateManager.TrackViewState()
201 internal Exception GetNotSupportedPropException (string propName)
203 return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name);
206 [MonoTODO ("Render this")]
207 [DefaultValueAttribute ("")]
208 [LocalizableAttribute (true)]
209 [WebCategoryAttribute ("Accessibility")]
210 public virtual string AccessibleHeaderText {
212 object val = viewState ["accessibleHeaderText"];
213 return val != null ? (string) val : "";
216 viewState ["accessibleHeaderText"] = value;
221 protected Control Control {
222 get { return control; }
225 [WebCategoryAttribute ("Styles")]
226 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
227 [DefaultValueAttribute (null)]
228 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
229 public Style ControlStyle {
231 if (controlStyle == null) {
232 controlStyle = new Style ();
233 if (IsTrackingViewState)
234 controlStyle.TrackViewState();
240 protected bool DesignMode {
241 get { return control != null && control.Site != null ? control.Site.DesignMode : false; }
244 [DefaultValueAttribute (null)]
245 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
246 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
247 [WebCategoryAttribute ("Styles")]
248 public TableItemStyle FooterStyle {
250 if (footerStyle == null) {
251 footerStyle = new TableItemStyle ();
252 if (IsTrackingViewState)
253 footerStyle.TrackViewState();
259 [LocalizableAttribute (true)]
260 [WebCategoryAttribute ("Appearance")]
262 public virtual string FooterText {
264 object val = viewState ["footerText"];
265 return val != null ? (string) val : "";
268 viewState ["footerText"] = value;
273 [UrlPropertyAttribute]
274 [DefaultValueAttribute ("")]
275 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
276 [WebCategoryAttribute ("Appearance")]
277 public virtual string HeaderImageUrl {
279 object val = viewState ["headerImageUrl"];
280 return val != null ? (string) val : "";
283 viewState ["headerImageUrl"] = value;
288 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
289 [WebCategoryAttribute ("Styles")]
290 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
291 [DefaultValueAttribute (null)]
292 public TableItemStyle HeaderStyle {
294 if (headerStyle == null) {
295 headerStyle = new TableItemStyle ();
296 if (IsTrackingViewState)
297 headerStyle.TrackViewState();
303 [DefaultValueAttribute ("")]
304 [LocalizableAttribute (true)]
305 [WebCategoryAttribute ("Appearance")]
306 public virtual string HeaderText {
308 object val = viewState ["headerText"];
309 return val != null ? (string) val : "";
312 viewState ["headerText"] = value;
317 [WebCategoryAttribute ("Behavior")]
318 [DefaultValueAttribute (true)]
319 public virtual bool InsertVisible {
321 object val = viewState ["InsertVisible"];
322 return val != null ? (bool) val : true;
325 viewState ["InsertVisible"] = value;
330 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
331 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
332 [WebCategoryAttribute ("Styles")]
333 [DefaultValueAttribute (null)]
334 public TableItemStyle ItemStyle {
336 if (itemStyle == null) {
337 itemStyle = new TableItemStyle ();
338 if (IsTrackingViewState)
339 itemStyle.TrackViewState();
345 [WebCategoryAttribute ("Behavior")]
346 [DefaultValueAttribute (true)]
347 public virtual bool ShowHeader {
349 object val = viewState ["showHeader"];
350 return val != null ? (bool) val : true;
353 viewState ["showHeader"] = value;
358 [DefaultValueAttribute ("")]
359 // [TypeConverterAttribute ("System.Web.UI.Design.DataSourceViewSchemaConverter, " + Consts.AssemblySystem_Design)]
360 [WebCategoryAttribute ("Behavior")]
361 public virtual string SortExpression {
363 object val = viewState ["sortExpression"];
364 return val != null ? (string) val : "";
367 viewState ["sortExpression"] = value;
372 [WebCategoryAttribute ("Behavior")]
373 [DefaultValueAttribute (true)]
374 public bool Visible {
376 object val = viewState ["visible"];
377 return val != null ? (bool) val : true;
380 viewState ["visible"] = value;
385 protected bool IsTrackingViewState
387 get { return tracking; }
390 bool IStateManager.IsTrackingViewState
392 get { return IsTrackingViewState; }
395 object IDataSourceViewSchemaAccessor.DataSourceViewSchema {
396 get { return viewState ["dataSourceViewSchema"]; }
398 viewState ["dataSourceViewSchema"] = value;
402 internal event EventHandler FieldChanged;