//------------------------------------------------------------- // // Copyright © Microsoft Corporation. All Rights Reserved. // //------------------------------------------------------------- // @owner=alexgor, deliant //================================================================= // File: GroupAnnotation.cs // // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting // // Classes: AnnotationGroup // // Purpose: Annotation group class. // // Reviewed: // //=================================================================== #region Used namespace using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Drawing; using System.Drawing.Design; using System.Drawing.Text; using System.Drawing.Drawing2D; #if Microsoft_CONTROL using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using System.Windows.Forms.DataVisualization.Charting.Data; using System.Windows.Forms.DataVisualization.Charting.ChartTypes; using System.Windows.Forms.DataVisualization.Charting.Utilities; using System.Windows.Forms.DataVisualization.Charting.Borders3D; #else using System.Web; using System.Web.UI; using System.Web.UI.DataVisualization.Charting; using System.Web.UI.DataVisualization.Charting.Data; using System.Web.UI.DataVisualization.Charting.Utilities; #endif #endregion #if Microsoft_CONTROL namespace System.Windows.Forms.DataVisualization.Charting #else namespace System.Web.UI.DataVisualization.Charting #endif { /// /// AnnotationGroup is a class that represents an annotation group. /// /// /// This class is a collection of annotations, and can be used /// to manipulate annotations relative to each other. /// [ SRDescription("DescriptionAttributeAnnotationGroup_AnnotationGroup"), ] #if ASPPERM_35 [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] #endif public class AnnotationGroup : Annotation { #region Fields // Collection of annotations in the group internal AnnotationCollection annotations = null; #endregion #region Construction and Initialization /// /// Default public constructor. /// public AnnotationGroup() : base() { annotations = new AnnotationCollection(this); annotations.AnnotationGroup = this; } #endregion #region Miscellaneous Properties /// /// Gets or sets the name of the chart area which an annotation is clipped to. /// /// /// A string which represents the name of an existing chart area. /// /// /// If the chart area name is specified, an annotation will only be drawn inside the /// plotting area of the chart area specified. All parts of the annotation /// outside of the plotting area will be clipped. /// /// To disable chart area clipping, set the property to "NotSet" or an empty string. /// /// [ SRCategory("CategoryAttributeMisc"), DefaultValue(Constants.NotSetValue), SRDescription("DescriptionAttributeAnnotationGroup_ClipToChartArea"), TypeConverter(typeof(LegendAreaNameConverter)), Browsable(false), ] override public string ClipToChartArea { get { return base.ClipToChartArea; } set { base.ClipToChartArea = value; foreach(Annotation annotation in this.annotations) { annotation.ClipToChartArea = value; } } } #endregion #region Position Properties /// /// Gets or sets a flag that specifies whether the size of an annotation is always /// defined in relative chart coordinates. /// /// /// /// /// True if an annotation's and are always /// in chart relative coordinates, false otherwise. /// /// /// An annotation's width and height may be set in relative chart or axes coordinates. /// By default, relative chart coordinates are used. /// /// To use axes coordinates for size set the IsSizeAlwaysRelative property to /// false and either anchor the annotation to a data point or set the /// or properties. /// /// [ SRCategory("CategoryAttributePosition"), DefaultValue(true), SRDescription("DescriptionAttributeAnnotationGroup_SizeAlwaysRelative"), ] override public bool IsSizeAlwaysRelative { get { return base.IsSizeAlwaysRelative; } set { base.IsSizeAlwaysRelative = value; } } #endregion #region Visual Properties #if Microsoft_CONTROL /// /// Gets or sets a flag that determines if an annotation is selected. /// /// /// /// True if the annotation is selected, false otherwise. /// #else /// /// Gets or sets a flag that determines if an annotation is selected. /// /// /// True if the annotation is selected, false otherwise. /// #endif // Microsoft_CONTROL [ SRCategory("CategoryAttributeAppearance"), DefaultValue(false), Browsable(false), SRDescription("DescriptionAttributeAnnotationGroup_Selected"), ] override public bool IsSelected { get { return base.IsSelected; } set { base.IsSelected = value; // Clear selection for all annotations in the group foreach(Annotation annotation in this.annotations) { annotation.IsSelected = false; } } } /// /// Gets or sets a flag that specifies whether an annotation is visible. /// /// /// True if the annotation is visible, false otherwise. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(true), SRDescription("DescriptionAttributeAnnotationGroup_Visible"), ParenthesizePropertyNameAttribute(true), ] override public bool Visible { get { return base.Visible; } set { base.Visible = value; } } /// /// Gets or sets an annotation's content alignment. /// /// /// A value that represents the content alignment. /// /// /// This property is used to align text for , , /// and objects, and to align /// a non-scaled image inside an object. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(ContentAlignment), "MiddleCenter"), SRDescription("DescriptionAttributeAlignment"), Browsable(false), ] override public ContentAlignment Alignment { get { return base.Alignment; } set { base.Alignment = value; foreach(Annotation annotation in this.annotations) { annotation.Alignment = value; } } } /// /// Gets or sets an annotation's text style. /// /// /// /// /// A value used to draw an annotation's text. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override TextStyle TextStyle { get { return base.TextStyle; } set { base.TextStyle = value; } } /// /// Gets or sets the text color of an annotation. /// /// /// /// A value used for the text color of an annotation. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), "Black"), SRDescription("DescriptionAttributeForeColor"), TypeConverter(typeof(ColorConverter)), Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base), Browsable(false), ] override public Color ForeColor { get { return base.ForeColor; } set { base.ForeColor = value; foreach(Annotation annotation in this.annotations) { annotation.ForeColor = value; } } } /// /// Gets or sets the font of an annotation's text. /// /// /// /// A object used for an annotation's text. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"), SRDescription("DescriptionAttributeTextFont"), Browsable(false), ] override public Font Font { get { return base.Font; } set { base.Font = value; foreach(Annotation annotation in this.annotations) { annotation.Font = value; } } } /// /// Gets or sets the color of an annotation line. /// /// /// /// /// A value used to draw an annotation line. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), "Black"), SRDescription("DescriptionAttributeLineColor"), TypeConverter(typeof(ColorConverter)), Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base), Browsable(false), ] override public Color LineColor { get { return base.LineColor; } set { base.LineColor = value; foreach(Annotation annotation in this.annotations) { annotation.LineColor = value; } } } /// /// Gets or sets the width of an annotation line. /// /// /// /// /// An integer value defining the width of an annotation line in pixels. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(1), SRDescription("DescriptionAttributeLineWidth"), Browsable(false), ] override public int LineWidth { get { return base.LineWidth; } set { base.LineWidth = value; foreach(Annotation annotation in this.annotations) { annotation.LineWidth = value; } } } /// /// Gets or sets the style of an annotation line. /// /// /// /// /// A value used to draw an annotation line. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(ChartDashStyle.Solid), SRDescription("DescriptionAttributeLineDashStyle"), Browsable(false), ] override public ChartDashStyle LineDashStyle { get { return base.LineDashStyle; } set { base.LineDashStyle = value; foreach(Annotation annotation in this.annotations) { annotation.LineDashStyle = value; } } } /// /// Gets or sets the background color of an annotation. /// /// /// /// /// /// A value used for the background of an annotation. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), ""), SRDescription("DescriptionAttributeBackColor"), NotifyParentPropertyAttribute(true), TypeConverter(typeof(ColorConverter)), Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base), Browsable(false), ] override public Color BackColor { get { return base.BackColor; } set { base.BackColor = value; foreach(Annotation annotation in this.annotations) { annotation.BackColor = value; } } } /// /// Gets or sets the background hatch style of an annotation. /// /// /// /// /// /// A value used for the background of an annotation. /// /// /// Two colors are used to draw the hatching, and . /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(ChartHatchStyle.None), NotifyParentPropertyAttribute(true), SRDescription("DescriptionAttributeBackHatchStyle"), Editor(Editors.HatchStyleEditor.Editor, Editors.HatchStyleEditor.Base), Browsable(false), ] override public ChartHatchStyle BackHatchStyle { get { return base.BackHatchStyle; } set { base.BackHatchStyle = value; foreach(Annotation annotation in this.annotations) { annotation.BackHatchStyle = value; } } } /// /// Gets or sets the background gradient style of an annotation. /// /// /// /// /// /// A value used for the background of an annotation. /// /// /// Two colors are used to draw the gradient, and . /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(GradientStyle.None), NotifyParentPropertyAttribute(true), SRDescription("DescriptionAttributeBackGradientStyle"), Editor(Editors.GradientEditor.Editor, Editors.GradientEditor.Base), Browsable(false), ] override public GradientStyle BackGradientStyle { get { return base.BackGradientStyle; } set { base.BackGradientStyle = value; foreach(Annotation annotation in this.annotations) { annotation.BackGradientStyle = value; } } } /// /// Gets or sets the secondary background color of an annotation. /// /// /// /// /// /// A value used for the secondary color of an annotation background with /// hatching or gradient fill. /// /// /// This color is used with when or /// are used. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), ""), NotifyParentPropertyAttribute(true), SRDescription("DescriptionAttributeBackSecondaryColor"), TypeConverter(typeof(ColorConverter)), Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base), Browsable(false), ] override public Color BackSecondaryColor { get { return base.BackSecondaryColor; } set { base.BackSecondaryColor = value; foreach(Annotation annotation in this.annotations) { annotation.BackSecondaryColor = value; } } } /// /// Gets or sets the color of an annotation's shadow. /// /// /// /// A value used to draw an annotation's shadow. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), "128,0,0,0"), SRDescription("DescriptionAttributeShadowColor"), TypeConverter(typeof(ColorConverter)), Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base), Browsable(false), ] override public Color ShadowColor { get { return base.ShadowColor; } set { base.ShadowColor = value; foreach(Annotation annotation in this.annotations) { annotation.ShadowColor = value; } } } /// /// Gets or sets the offset between an annotation and its shadow. /// /// /// /// An integer value that represents the offset between an annotation and its shadow. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(0), SRDescription("DescriptionAttributeShadowOffset"), Browsable(false), ] override public int ShadowOffset { get { return base.ShadowOffset; } set { base.ShadowOffset = value; foreach(Annotation annotation in this.annotations) { annotation.ShadowOffset = value; } } } #endregion #region Editing Permissions Properties #if Microsoft_CONTROL /// /// Gets or sets a flag that specifies whether an annotation may be selected /// with a mouse by the end user. /// /// /// True if the annotation may be selected, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAllowSelecting"), ] override public bool AllowSelecting { get { return base.AllowSelecting; } set { base.AllowSelecting = value; } } /// /// Gets or sets a flag that specifies whether an annotation may be moved /// with a mouse by the end user. /// /// /// True if the annotation may be moved, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAllowMoving"), ] override public bool AllowMoving { get { return base.AllowMoving; } set { base.AllowMoving = value; } } /// /// Gets or sets a flag that specifies whether an annotation anchor may be moved /// with a mouse by the end user. /// /// /// True if the annotation anchor may be moved, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAnnotationGroup_AllowAnchorMoving"), ] override public bool AllowAnchorMoving { get { return base.AllowAnchorMoving; } set { base.AllowAnchorMoving = value; } } /// /// Gets or sets a flag that specifies whether an annotation may be resized /// with a mouse by the end user. /// /// /// True if the annotation may be resized, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAllowResizing"), ] override public bool AllowResizing { get { return base.AllowResizing; } set { base.AllowResizing = value; } } /// /// Gets or sets a flag that specifies whether an annotation's text may be edited /// when the end user double clicks on the text. /// /// /// True if the annotation text may be edited, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAllowTextEditing"), ] override public bool AllowTextEditing { get { return base.AllowTextEditing; } set { base.AllowTextEditing = value; } } /// /// Gets or sets a flag that specifies whether a polygon annotation's points /// may be moved with a mouse by the end user. /// /// /// True if the polygon annotation's points may be moved, false otherwise. /// [ SRCategory("CategoryAttributeEditing"), DefaultValue(false), SRDescription("DescriptionAttributeAnnotationGroup_AllowPathEditing"), ] override public bool AllowPathEditing { get { return base.AllowPathEditing; } set { base.AllowPathEditing = value; } } #endif // Microsoft_CONTROL #endregion #region Other Properties /// /// Gets the collection of annotations in the group. /// /// /// An object. /// /// /// Note that the coordinates of all annotations in the group are relative to the /// group annotation. /// [ SRCategory("CategoryAttributeAnnotations"), SRDescription("DescriptionAttributeAnnotationGroup_Annotations"), Editor(Editors.AnnotationCollectionEditor.Editor, Editors.AnnotationCollectionEditor.Base), #if Microsoft_CONTROL DesignerSerializationVisibility(DesignerSerializationVisibility.Content), #else // Microsoft_CONTROL PersistenceMode(PersistenceMode.InnerProperty), #endif // Microsoft_CONTROL ] public AnnotationCollection Annotations { get { return annotations; } } /// /// Gets or sets an annotation's type name. /// /// /// This property is used to get the name of each annotation type /// (e.g. Line, Rectangle, Ellipse). /// /// This property is for internal use and is hidden at design and run time. /// /// [ SRCategory("CategoryAttributeMisc"), Bindable(true), Browsable(false), EditorBrowsableAttribute(EditorBrowsableState.Never), DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden), SerializationVisibilityAttribute(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeAnnotationType"), ] public override string AnnotationType { get { return "Group"; } } /// /// Gets or sets annotation selection points style. /// /// /// A value that represents annotation /// selection style. /// /// /// This property is for internal use and is hidden at design and run time. /// [ SRCategory("CategoryAttributeAppearance"), DefaultValue(SelectionPointsStyle.Rectangle), ParenthesizePropertyNameAttribute(true), Browsable(false), EditorBrowsableAttribute(EditorBrowsableState.Never), DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden), SerializationVisibilityAttribute(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeSelectionPointsStyle"), ] override internal SelectionPointsStyle SelectionPointsStyle { get { return SelectionPointsStyle.Rectangle; } } #endregion #region Methods /// /// Paints an annotation object using the specified graphics. /// /// /// A object, used to paint the annotation object. /// /// /// Reference to the control. /// override internal void Paint(Chart chart, ChartGraphics graphics) { // Paint all annotations in the group foreach(Annotation annotation in this.annotations) { annotation.Paint(chart, graphics); } if( (this.Common.ProcessModePaint && this.IsSelected) || this.Common.ProcessModeRegions ) { // Get annotation position in relative coordinates PointF firstPoint = PointF.Empty; PointF anchorPoint = PointF.Empty; SizeF size = SizeF.Empty; GetRelativePosition(out firstPoint, out size, out anchorPoint); PointF secondPoint = new PointF(firstPoint.X + size.Width, firstPoint.Y + size.Height); // Create selection rectangle RectangleF selectionRect = new RectangleF(firstPoint, new SizeF(secondPoint.X - firstPoint.X, secondPoint.Y - firstPoint.Y)); // Check rectangle orientation if(selectionRect.Width < 0) { selectionRect.X = selectionRect.Right; selectionRect.Width = -selectionRect.Width; } if(selectionRect.Height < 0) { selectionRect.Y = selectionRect.Bottom; selectionRect.Height = -selectionRect.Height; } // Check if text position is valid if( selectionRect.IsEmpty || float.IsNaN(selectionRect.X) || float.IsNaN(selectionRect.Y) || float.IsNaN(selectionRect.Right) || float.IsNaN(selectionRect.Bottom) ) { return; } if(this.Common.ProcessModeRegions) { // Add hot region this.Common.HotRegionsList.AddHotRegion( selectionRect, ReplaceKeywords(this.ToolTip), #if Microsoft_CONTROL String.Empty, String.Empty, String.Empty, #else // Microsoft_CONTROL ReplaceKeywords(this.Url), ReplaceKeywords(this.MapAreaAttributes), ReplaceKeywords(this.PostBackValue), #endif // Microsoft_CONTROL this, ChartElementType.Annotation, String.Empty); } // Paint selection handles PaintSelectionHandles(graphics, selectionRect, null); } } #endregion // Methods #region IDisposable override /// /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected override void Dispose(bool disposing) { if (disposing) { //Clean up managed resources if (this.annotations != null) { this.annotations.Dispose(); this.annotations = null; } } base.Dispose(disposing); } #endregion } }