//------------------------------------------------------------- // // Copyright © Microsoft Corporation. All Rights Reserved. // //------------------------------------------------------------- // @owner=alexgor, deliant, victark using System; using System.Text; using System.Globalization; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics.CodeAnalysis; #if Microsoft_CONTROL namespace System.Windows.Forms.DataVisualization.Charting #else namespace System.Web.UI.DataVisualization.Charting #endif { /// /// ChartElement is the most basic element of the chart element hierarchy. /// #if ASPPERM_35 [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] #endif public abstract class ChartElement : IChartElement, IDisposable { #region Member variables private IChartElement _parent = null; private CommonElements _common = null; private object _tag = null; #endregion #region Properties /// /// Gets or sets an object associated with this chart element. /// /// /// An associated with this chart element. /// /// /// This property may be used to store additional data with this chart element. /// [ Browsable(false), DefaultValue(null), DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden), Utilities.SerializationVisibilityAttribute(Utilities.SerializationVisibility.Hidden) ] public object Tag { get { return _tag; } set { _tag = value; } } /// /// Gets or sets the parent chart element or collection. /// /// The parent chart element or collection. internal virtual IChartElement Parent { get { return _parent; } set { _parent = value; } } /// /// Gets a shortcut to Common intance providing access to the various chart related services. /// /// The Common instance. internal CommonElements Common { get { if (_common == null && _parent != null) { _common = _parent.Common; } return _common; } set { _common = value; } } /// /// Gets the chart. /// /// The chart. internal Chart Chart { get { if (Common != null) return Common.Chart; else return null; } } #endregion #region Constructors /// /// Initializes a new instance of the class. /// protected ChartElement() { } /// /// Initializes a new instance of the class. /// /// The parent chart element or collection. internal ChartElement(IChartElement parent) { _parent = parent; } #endregion #region Methods /// /// Invalidates this chart element. /// internal virtual void Invalidate() { if (_parent != null) _parent.Invalidate(); } #endregion #region IChartElement Members IChartElement IChartElement.Parent { get { return _parent; } set { this.Parent = value; } } void IChartElement.Invalidate() { this.Invalidate(); } CommonElements IChartElement.Common { get{ return this.Common; } } #endregion #region IDisposable Members /// /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { } /// /// Performs freeing, releasing, or resetting managed resources. /// [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public void Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } #endregion #region Methods /// /// Returns a that represents the current . /// /// /// A that represents the current . /// /// For internal use. internal virtual string ToStringInternal() { return GetType().Name; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public override string ToString() { return this.ToStringInternal(); } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// /// true if the specified is equal to the current ; otherwise, false. /// /// The parameter is null. /// For internal use. internal virtual bool EqualsInternal(object obj) { return base.Equals(obj); } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// /// true if the specified is equal to the current ; otherwise, false. /// /// The parameter is null. [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public override bool Equals(object obj) { return this.EqualsInternal(obj); } /// /// Serves as a hash function for a particular type. /// /// /// A hash code for the current . /// [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public override int GetHashCode() { return base.GetHashCode(); } #endregion } /// /// ChartNamedElement is a base class for most chart elements. Series, ChartAreas, Legends and other chart elements have a Name and reuse the unique name generation and validation logic provided by the ChartNamedElementCollection. /// #if ASPPERM_35 [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] #endif public abstract class ChartNamedElement : ChartElement { #region Member variables private string _name = String.Empty; #endregion #region Properties /// /// Gets or sets the name of the chart element. /// /// The name. [DefaultValue("")] public virtual string Name { get { return _name; } set { if (_name != value) { if (Parent is INameController) { INameController nameController = Parent as INameController; if (!nameController.IsUniqueName(value)) throw new ArgumentException(SR.ExceptionNameAlreadyExistsInCollection(value, nameController.GetType().Name)); // Fire the name change events in case when the old name is not empty NameReferenceChangedEventArgs args = new NameReferenceChangedEventArgs(this, _name, value); nameController.OnNameReferenceChanging(args); _name = value; nameController.OnNameReferenceChanged(args); } else { _name = value; } Invalidate(); } } } #endregion #region Constructors /// /// Initializes a new instance of the class. /// protected ChartNamedElement() : base() { } /// /// Initializes a new instance of the class. /// /// The name of the new chart element. protected ChartNamedElement(string name) : base() { _name = name; } /// /// Initializes a new instance of the class. /// /// The parent chart element. /// The name of the new chart element. internal ChartNamedElement(IChartElement parent, string name) : base(parent) { _name = name; } #endregion #region Methods /// /// Returns a that represents the current . /// /// /// A that represents the current . /// internal override string ToStringInternal() { string typeName = GetType().Name; return (string.IsNullOrEmpty(_name)) ? typeName : typeName + '-' + _name; } #endregion } /// /// NameReferenceChanged events help chart maintain referencial integrity. /// internal class NameReferenceChangedEventArgs : EventArgs { #region MemberValiables ChartNamedElement _oldElement; string _oldName; string _newName; #endregion #region Properties public ChartNamedElement OldElement { get { return _oldElement; } } public string OldName { get { return _oldName; } } public string NewName { get { return _newName; } } #endregion #region Constructor public NameReferenceChangedEventArgs(ChartNamedElement oldElement, ChartNamedElement newElement) { _oldElement = oldElement; _oldName = oldElement!=null ? oldElement.Name : string.Empty; _newName = newElement!=null ? newElement.Name : string.Empty; } public NameReferenceChangedEventArgs(ChartNamedElement oldElement, string oldName, string newName) { _oldElement = oldElement; _oldName = oldName; _newName = newName; } #endregion } }