| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- //
- // System.Web.UI.WebControls.DataControlField.cs
- //
- // Authors:
- // Sanjay Gupta ([email protected])
- // Lluis Sanchez Gual ([email protected])
- //
- // (C) 2004 Novell, Inc. (http://www.novell.com)
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- #if NET_2_0
- using System.Collections;
- using System.Collections.Specialized;
- using System.Web.UI;
- using System.ComponentModel;
- using System.Security.Permissions;
- namespace System.Web.UI.WebControls {
- [DefaultPropertyAttribute ("HeaderText")]
- [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
- [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public abstract class DataControlField : IStateManager, IDataSourceViewSchemaAccessor
- {
- bool tracking = false;
- StateBag viewState;
- Control control;
- Style controlStyle;
- TableItemStyle footerStyle;
- TableItemStyle headerStyle;
- TableItemStyle itemStyle;
- bool sortingEnabled;
-
- protected DataControlField()
- {
- viewState = new StateBag ();
- }
-
- internal void SetDirty ()
- {
- viewState.SetDirty (true);
- }
-
- protected StateBag ViewState {
- get { return viewState; }
- }
- public virtual void ExtractValuesFromCell (IOrderedDictionary dictionary,
- DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
- {
- }
- public virtual bool Initialize (bool sortingEnabled, Control control)
- {
- this.sortingEnabled = sortingEnabled;
- this.control = control;
- return true;
- }
- public virtual void InitializeCell (DataControlFieldCell cell,
- DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
- {
- if (cellType == DataControlCellType.Header)
- {
- if (HeaderText.Length > 0 || HeaderImageUrl.Length > 0) {
- if (sortingEnabled && SortExpression.Length > 0)
- cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, DataControlCommands.SortCommandName, SortExpression, true));
- else
- cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, string.Empty, true));
- }
- }
- else if (cellType == DataControlCellType.Footer) {
- cell.Text = FooterText;
- }
- }
-
- protected internal DataControlField CloneField ()
- {
- DataControlField field = CreateField ();
- CopyProperties (field);
- return field;
- }
-
- protected abstract DataControlField CreateField ();
-
- protected virtual void CopyProperties (DataControlField newField)
- {
- newField.AccessibleHeaderText = AccessibleHeaderText;
- newField.ControlStyle.CopyFrom (ControlStyle);
- newField.FooterStyle.CopyFrom (FooterStyle);
- newField.FooterText = FooterText;
- newField.HeaderImageUrl = HeaderImageUrl;
- newField.HeaderStyle.CopyFrom (HeaderStyle);
- newField.HeaderText = HeaderText;
- newField.InsertVisible = InsertVisible;
- newField.ItemStyle.CopyFrom (ItemStyle);
- newField.ShowHeader = ShowHeader;
- newField.SortExpression = SortExpression;
- newField.Visible = Visible;
- }
-
- protected virtual void OnFieldChanged ()
- {
- if (FieldChanged != null)
- FieldChanged (this, EventArgs.Empty);
- }
-
- protected virtual void LoadViewState (object savedState)
- {
- if (savedState == null)
- return;
-
- object [] states = (object []) savedState;
- viewState.LoadViewState (states[0]);
-
- if (states[1] != null)
- ((IStateManager)controlStyle).LoadViewState (states[1]);
- if (states[2] != null)
- ((IStateManager)footerStyle).LoadViewState (states[2]);
- if (states[3] != null)
- ((IStateManager)headerStyle).LoadViewState (states[3]);
- if (states[4] != null)
- ((IStateManager)itemStyle).LoadViewState (states[4]);
- }
- protected virtual object SaveViewState()
- {
- object[] state = new object [5];
- state [0] = viewState.SaveViewState ();
- if (controlStyle != null)
- state [1] = ((IStateManager) controlStyle).SaveViewState ();
- if (footerStyle != null)
- state [2] = ((IStateManager) footerStyle).SaveViewState ();
- if (headerStyle != null)
- state [3] = ((IStateManager) headerStyle).SaveViewState ();
- if (itemStyle != null)
- state [4] = ((IStateManager) itemStyle).SaveViewState ();
-
- if (state [0] == null && state [1] == null && state [2] == null &&
- state [3] == null && state [4] == null)
- return null;
-
- return state;
- }
- protected virtual void TrackViewState()
- {
- if (controlStyle != null) ((IStateManager) controlStyle).TrackViewState ();
- if (footerStyle != null) ((IStateManager) footerStyle).TrackViewState ();
- if (headerStyle != null) ((IStateManager) headerStyle).TrackViewState ();
- if (itemStyle != null) ((IStateManager) itemStyle).TrackViewState ();
- viewState.TrackViewState ();
- tracking = true;
- }
-
- public virtual void ValidateSupportsCallback ()
- {
- throw new NotSupportedException ("Callback not supported");
- }
- void IStateManager.LoadViewState(object savedState)
- {
- LoadViewState(savedState);
- }
- object IStateManager.SaveViewState()
- {
- return SaveViewState();
- }
- void IStateManager.TrackViewState()
- {
- TrackViewState();
- }
-
- internal Exception GetNotSupportedPropException (string propName)
- {
- return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name);
- }
- [MonoTODO ("Render this")]
- [DefaultValueAttribute ("")]
- [LocalizableAttribute (true)]
- [WebCategoryAttribute ("Accessibility")]
- public virtual string AccessibleHeaderText {
- get {
- object val = viewState ["accessibleHeaderText"];
- return val != null ? (string) val : "";
- }
- set {
- viewState ["accessibleHeaderText"] = value;
- OnFieldChanged ();
- }
- }
- protected Control Control {
- get { return control; }
- }
- [WebCategoryAttribute ("Styles")]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValueAttribute (null)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
- public Style ControlStyle {
- get {
- if (controlStyle == null) {
- controlStyle = new Style ();
- if (IsTrackingViewState)
- controlStyle.TrackViewState();
- }
- return controlStyle;
- }
- }
-
- protected bool DesignMode {
- get { return control != null && control.Site != null ? control.Site.DesignMode : false; }
- }
- [DefaultValueAttribute (null)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [WebCategoryAttribute ("Styles")]
- public TableItemStyle FooterStyle {
- get {
- if (footerStyle == null) {
- footerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- footerStyle.TrackViewState();
- }
- return footerStyle;
- }
- }
- [LocalizableAttribute (true)]
- [WebCategoryAttribute ("Appearance")]
- [DefaultValue ("")]
- public virtual string FooterText {
- get {
- object val = viewState ["footerText"];
- return val != null ? (string) val : "";
- }
- set {
- viewState ["footerText"] = value;
- OnFieldChanged ();
- }
- }
- [UrlPropertyAttribute]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- [WebCategoryAttribute ("Appearance")]
- public virtual string HeaderImageUrl {
- get {
- object val = viewState ["headerImageUrl"];
- return val != null ? (string) val : "";
- }
- set {
- viewState ["headerImageUrl"] = value;
- OnFieldChanged ();
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [WebCategoryAttribute ("Styles")]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValueAttribute (null)]
- public TableItemStyle HeaderStyle {
- get {
- if (headerStyle == null) {
- headerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- headerStyle.TrackViewState();
- }
- return headerStyle;
- }
- }
- [DefaultValueAttribute ("")]
- [LocalizableAttribute (true)]
- [WebCategoryAttribute ("Appearance")]
- public virtual string HeaderText {
- get {
- object val = viewState ["headerText"];
- return val != null ? (string) val : "";
- }
- set {
- viewState ["headerText"] = value;
- OnFieldChanged ();
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (true)]
- public virtual bool InsertVisible {
- get {
- object val = viewState ["InsertVisible"];
- return val != null ? (bool) val : true;
- }
- set {
- viewState ["InsertVisible"] = value;
- OnFieldChanged ();
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [WebCategoryAttribute ("Styles")]
- [DefaultValueAttribute (null)]
- public TableItemStyle ItemStyle {
- get {
- if (itemStyle == null) {
- itemStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- itemStyle.TrackViewState();
- }
- return itemStyle;
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (true)]
- public virtual bool ShowHeader {
- get {
- object val = viewState ["showHeader"];
- return val != null ? (bool) val : true;
- }
- set {
- viewState ["showHeader"] = value;
- OnFieldChanged ();
- }
- }
- [DefaultValueAttribute ("")]
- // [TypeConverterAttribute ("System.Web.UI.Design.DataSourceViewSchemaConverter, " + Consts.AssemblySystem_Design)]
- [WebCategoryAttribute ("Behavior")]
- public virtual string SortExpression {
- get {
- object val = viewState ["sortExpression"];
- return val != null ? (string) val : "";
- }
- set {
- viewState ["sortExpression"] = value;
- OnFieldChanged ();
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (true)]
- public bool Visible {
- get {
- object val = viewState ["visible"];
- return val != null ? (bool) val : true;
- }
- set {
- viewState ["visible"] = value;
- OnFieldChanged ();
- }
- }
- protected bool IsTrackingViewState
- {
- get { return tracking; }
- }
- bool IStateManager.IsTrackingViewState
- {
- get { return IsTrackingViewState; }
- }
- object IDataSourceViewSchemaAccessor.DataSourceViewSchema {
- get { return viewState ["dataSourceViewSchema"]; }
- set {
- viewState ["dataSourceViewSchema"] = value;
- }
- }
- internal event EventHandler FieldChanged;
- }
- }
- #endif
|