Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Web.DataVisualization / Common / Annotation / PolygonAnnotation.cs
1 //-------------------------------------------------------------
2 // <copyright company=\92Microsoft Corporation\92>
3 //   Copyright © Microsoft Corporation. All Rights Reserved.
4 // </copyright>
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 //  File:               RectangleAnnotation.cs
9 //
10 //  Namespace:  System.Web.UI.WebControls[Windows.Forms].Charting
11 //
12 //      Classes:        PolylineAnnotation, PolygonAnnotation
13 //
14 //  Purpose:    Polyline and polygon annotation classes.
15 //
16 //      Reviewed:       
17 //
18 //===================================================================
19
20 #region Used namespace
21 using System;
22 using System.Collections;
23 using System.Collections.Specialized;
24 using System.ComponentModel;
25 using System.ComponentModel.Design;
26 using System.Data;
27 using System.Drawing;
28 using System.Drawing.Design;
29 using System.Drawing.Text;
30 using System.Drawing.Drawing2D;
31 using System.Diagnostics.CodeAnalysis;
32 #if Microsoft_CONTROL
33 using System.Windows.Forms;
34 using System.Globalization;
35 using System.Reflection;
36 using System.ComponentModel.Design.Serialization;
37 using System.Windows.Forms.DataVisualization.Charting;
38 using System.Windows.Forms.DataVisualization.Charting.Data;
39 using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
40 using System.Windows.Forms.DataVisualization.Charting.Utilities;
41 using System.Windows.Forms.DataVisualization.Charting.Borders3D;
42 using System.Collections.ObjectModel;
43
44 #else
45 using System.Web;
46 using System.Web.UI;
47 using System.Web.UI.DataVisualization.Charting;
48 using System.Web.UI.DataVisualization.Charting.Data;
49 using System.Web.UI.DataVisualization.Charting.Utilities;
50 using System.Web.UI.DataVisualization.Charting.Borders3D;
51 using System.Collections.ObjectModel;
52 #endif
53
54 #endregion
55
56 #if Microsoft_CONTROL
57 namespace System.Windows.Forms.DataVisualization.Charting
58
59 #else
60 namespace System.Web.UI.DataVisualization.Charting
61
62 #endif
63 {
64         /// <summary>
65         /// <b>PolylineAnnotation</b> is a class that represents a polyline annotation.
66         /// </summary>
67         [
68                 SRDescription("DescriptionAttributePolylineAnnotation_PolylineAnnotation"),
69         ]
70     [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline")]
71 #if ASPPERM_35
72         [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
73     [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
74 #endif
75     public class PolylineAnnotation : Annotation
76         {
77                 #region Fields
78
79                 // Path with polygon points.
80         private    GraphicsPath    _defaultGraphicsPath = new GraphicsPath();
81         private    GraphicsPath    _graphicsPath;
82
83                 // Indicates that path was changed
84                 internal        bool                    pathChanged = false;
85
86                 // Collection of path points exposed at design-time
87                 private AnnotationPathPointCollection _pathPoints;
88
89                 // Indicate that filled polygon must be drawn
90                 internal bool                           isPolygon = false;
91
92                 // Indicates that annotation will be placed using free-draw style
93                 internal bool                           isFreeDrawPlacement = false;
94
95                 // Line start/end caps
96                 private         LineAnchorCapStyle              _startCap = LineAnchorCapStyle.None;
97                 private         LineAnchorCapStyle              _endCap = LineAnchorCapStyle.None;
98
99                 #endregion
100
101                 #region Construction and Initialization
102
103                 /// <summary>
104                 /// Default public constructor.
105                 /// </summary>
106                 public PolylineAnnotation() 
107             : base()
108                 {
109             _pathPoints = new AnnotationPathPointCollection(this);
110              
111             _graphicsPath = _defaultGraphicsPath;
112                 }
113
114                 #endregion
115
116                 #region Properties
117
118                 #region Polyline Visual Attributes
119
120                 /// <summary>
121                 /// Gets or sets a cap style used at the start of an annotation line.
122                 /// <seealso cref="EndCap"/>
123                 /// </summary>
124                 /// <value>
125         /// A <see cref="LineAnchorCapStyle"/> value used for a cap style used at the start of an annotation line.
126                 /// </value>
127                 [
128                 SRCategory("CategoryAttributeAppearance"),
129                 DefaultValue(LineAnchorCapStyle.None),
130                 SRDescription("DescriptionAttributeStartCap3"),
131                 ]
132                 virtual public LineAnchorCapStyle StartCap
133                 {
134                         get
135                         {
136                                 return _startCap;
137                         }
138                         set
139                         {
140                                 _startCap = value;
141                                 Invalidate();
142                         }
143                 }
144
145                 /// <summary>
146         /// Gets or sets a cap style used at the end of an annotation line.
147                 /// <seealso cref="StartCap"/>
148                 /// </summary>
149                 /// <value>
150         /// A <see cref="LineAnchorCapStyle"/> value used for a cap style used at the end of an annotation line.
151                 /// </value>
152                 [
153                 SRCategory("CategoryAttributeAppearance"),
154                 DefaultValue(LineAnchorCapStyle.None),
155                 SRDescription("DescriptionAttributeStartCap3"),
156                 ]
157                 virtual public LineAnchorCapStyle EndCap
158                 {
159                         get
160                         {
161                                 return _endCap;
162                         }
163                         set
164                         {
165                                 _endCap = value;
166                                 Invalidate();
167                         }
168                 }
169
170                 #endregion
171
172                 #region Non Applicable Annotation Appearance Attributes (set as Non-Browsable)
173
174                 /// <summary>
175                 /// Not applicable to this annotation type.
176                 /// </summary>
177                 /// <value>
178                 /// A <see cref="ContentAlignment"/> value.
179                 /// </value>
180                 [
181                 SRCategory("CategoryAttributeAppearance"),
182                 Browsable(false),
183                 DefaultValue(typeof(ContentAlignment), "MiddleCenter"),
184                 ]
185                 override public ContentAlignment Alignment
186                 {
187                         get
188                         {
189                                 return base.Alignment;
190                         }
191                         set
192                         {
193                                 base.Alignment = value;
194                         }
195                 }
196
197         /// <summary>
198         /// Gets or sets an annotation's text style.
199         /// <seealso cref="Font"/>
200         ///     <seealso cref="ForeColor"/>
201         /// </summary>
202         /// <value>
203         /// A <see cref="TextStyle"/> value used to draw an annotation's text.
204         /// </value>
205         [Browsable(false)]
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         public override TextStyle TextStyle
208         {
209             get
210             {
211                 return base.TextStyle;
212             }
213             set
214             {
215                 base.TextStyle = value;
216             }
217         }
218
219                 /// <summary>
220                 /// Not applicable to this annotation type.
221                 /// <seealso cref="Font"/>
222                 /// </summary>
223                 /// <value>
224                 /// A <see cref="Color"/> value.
225                 /// </value>
226                 [
227                 SRCategory("CategoryAttributeAppearance"),
228                 Browsable(false),
229                 DefaultValue(typeof(Color), "Black"),
230         SRDescription("DescriptionAttributeForeColor"),
231         TypeConverter(typeof(ColorConverter)),
232         Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base)
233                 ]
234                 override public Color ForeColor
235                 {
236                         get
237                         {
238                                 return base.ForeColor;
239                         }
240                         set
241                         {
242                                 base.ForeColor = value;
243                         }
244                 }
245
246                 /// <summary>
247                 /// Not applicable to this annotation type.
248                 /// <seealso cref="ForeColor"/>
249                 /// </summary>
250                 /// <value>
251                 /// A <see cref="Font"/> object.
252                 /// </value>
253                 [
254                 SRCategory("CategoryAttributeAppearance"),
255                 Browsable(false),
256                 DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"),
257                 ]
258                 override public Font Font
259                 {
260                         get
261                         {
262                                 return base.Font;
263                         }
264                         set
265                         {
266                                 base.Font = value;
267                         }
268                 }
269
270         /// <summary>
271         /// Not applicable to this annotation type.
272         /// </summary>
273                 [
274                 SRCategory("CategoryAttributeAppearance"),
275                 Browsable(false),
276                 DefaultValue(typeof(Color), ""),
277                 NotifyParentPropertyAttribute(true),
278         TypeConverter(typeof(ColorConverter)),
279         Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base)
280                 ]
281                 override public Color BackColor
282                 {
283                         get
284                         {
285                                 return base.BackColor;
286                         }
287                         set
288                         {
289                                 base.BackColor = value;
290                         }
291                 }
292
293         /// <summary>
294         /// Not applicable to this annotation type.
295         /// </summary>
296                 [
297                 SRCategory("CategoryAttributeAppearance"),
298                 Browsable(false),
299                 DefaultValue(ChartHatchStyle.None),
300                 NotifyParentPropertyAttribute(true),
301                 Editor(Editors.HatchStyleEditor.Editor, Editors.HatchStyleEditor.Base)
302                 ]
303                 override public ChartHatchStyle BackHatchStyle
304                 {
305                         get
306                         {
307                                 return base.BackHatchStyle;
308                         }
309                         set
310                         {
311                                 base.BackHatchStyle = value;
312                         }
313                 }
314
315         /// <summary>
316         /// Not applicable to this annotation type.
317         /// </summary>
318                 [
319                 SRCategory("CategoryAttributeAppearance"),
320                 Browsable(false),
321                 DefaultValue(GradientStyle.None),
322                 NotifyParentPropertyAttribute(true),
323                 Editor(Editors.GradientEditor.Editor, Editors.GradientEditor.Base)
324                 ]               
325                 override public GradientStyle BackGradientStyle
326                 {
327                         get
328                         {
329                                 return base.BackGradientStyle;
330                         }
331                         set
332                         {
333                                 base.BackGradientStyle = value;
334                         }
335                 }
336
337         /// <summary>
338         /// Not applicable to this annotation type.
339         /// </summary>
340                 [
341                 SRCategory("CategoryAttributeAppearance"),
342                 Browsable(false),
343                 DefaultValue(typeof(Color), ""),
344                 NotifyParentPropertyAttribute(true),
345         TypeConverter(typeof(ColorConverter)),
346         Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base)
347                 ] 
348                 override public Color BackSecondaryColor
349                 {
350                         get
351                         {
352                                 return base.BackSecondaryColor;
353                         }
354                         set
355                         {
356                                 base.BackSecondaryColor = value;
357                         }
358                 }
359
360                 #endregion
361
362                 #region Other
363
364         /// <summary>
365         /// Gets or sets an annotation's type name.
366         /// </summary>
367         /// <remarks>
368         /// This property is used to get the name of each annotation type 
369         /// (e.g. Line, Rectangle, Ellipse). 
370         /// <para>
371         /// This property is for internal use and is hidden at design and run time.
372         /// </para>
373         /// </remarks>
374                 [
375                 SRCategory("CategoryAttributeMisc"),
376                 Bindable(true),
377                 Browsable(false),
378                 EditorBrowsableAttribute(EditorBrowsableState.Never),
379                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
380                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
381                 SRDescription("DescriptionAttributeAnnotationType"),
382                 ]
383                 public override string AnnotationType
384                 {
385                         get
386                         {
387                                 return "Polyline";
388                         }
389                 }
390
391                 /// <summary>
392                 /// Gets or sets an annotation selection points style.
393                 /// </summary>
394                 /// <value>
395                 /// A <see cref="SelectionPointsStyle"/> value that represents the annotation 
396                 /// selection style.
397                 /// </value>
398                 /// <remarks>
399         /// This property is for internal use and is hidden at design and run time.
400                 /// </remarks>
401                 [
402                 SRCategory("CategoryAttributeAppearance"),
403                 DefaultValue(SelectionPointsStyle.Rectangle),
404                 ParenthesizePropertyNameAttribute(true),
405                 Browsable(false),
406                 EditorBrowsableAttribute(EditorBrowsableState.Never),
407                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
408                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
409                 SRDescription("DescriptionAttributeSelectionPointsStyle"),
410                 ]
411                 override internal SelectionPointsStyle SelectionPointsStyle
412                 {
413                         get
414                         {
415                                 return SelectionPointsStyle.Rectangle;
416                         }
417                 }
418
419                 /// <summary>
420                 /// Gets or sets a flag that determines whether an annotation should be placed using the free-draw mode.
421                 /// </summary>
422                 /// <value>
423                 /// <b>True</b> if an annotation should be placed using free-draw mode, 
424                 /// <b>false</b> otherwise.  Defaults to <b>false</b>.
425                 /// </value>
426                 /// <remarks>
427                 /// Two different placement modes are supported when the Annotation.BeginPlacement 
428                 /// method is called. Set this property to <b>true</b> to switch from the default 
429                 /// mode to free-draw mode, which allows the caller to free-draw while moving the mouse cursor.
430                 /// </remarks>
431                 [
432                 SRCategory("CategoryAttributeMisc"),
433                 DefaultValue(false),
434                 SRDescription("DescriptionAttributeFreeDrawPlacement"),
435 #if !Microsoft_CONTROL
436                 Browsable(false),
437                 EditorBrowsable(EditorBrowsableState.Never),
438 #endif // !Microsoft_CONTROL
439                 ]
440                 virtual public bool IsFreeDrawPlacement
441                 {
442                         get
443                         {
444                                 return isFreeDrawPlacement;
445                         }
446                         set
447                         {
448                                 isFreeDrawPlacement = value;
449                         }
450                 }
451
452                 /// <summary>
453                 /// Gets or sets the path points of a polyline at run-time.
454                 /// </summary>
455                 /// <value>
456                 /// A <see cref="GraphicsPath"/> object with the polyline shape.
457                 /// </value>
458                 /// <remarks>
459                 /// A polyline must use coordinates relative to an annotation object, where (0,0) is 
460                 /// the top-left coordinates and (100,100) is the bottom-right coordinates of the annotation.  
461                 /// <para>
462                 /// This property is not accessible at design time (at design-time, use the 
463                 /// <see cref="GraphicsPathPoints"/> property instead).
464                 /// </para>
465                 /// </remarks>
466                 [
467                 SRCategory("CategoryAttributePosition"),
468                 DefaultValue(null),
469                 SRDescription("DescriptionAttributePath"),
470                 Browsable(false),
471                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
472                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
473                 ]
474                 virtual public GraphicsPath GraphicsPath
475                 {
476                         get
477                         {
478                                 return _graphicsPath;
479                         }
480                         set
481                         {
482                                 _graphicsPath = value;
483                                 this.pathChanged = true;
484                         }
485                 }
486
487                 /// <summary>
488                 /// Gets or sets the path points of the polyline at design-time.
489                 /// </summary>
490                 /// <value>
491                 /// An <see cref="AnnotationPathPointCollection"/> object with the polyline shape.
492                 /// </value>
493                 /// <remarks>
494                 /// A polyline must use coordinates relative to an annotation object, where (0,0) is 
495                 /// the top-left coordinates and (100,100) is the bottom-right coordinates of the annotation.
496                 /// <para>
497         /// This property is not accessible at runtime (at runtime, use the <see cref="GraphicsPath"/> 
498                 /// property instead).
499                 /// </para>
500                 /// </remarks>
501                 [
502                 SRCategory("CategoryAttributePosition"),
503                 SRDescription("DescriptionAttributePathPoints"),
504                 EditorBrowsableAttribute(EditorBrowsableState.Never),
505                 Editor(Editors.ChartCollectionEditor.Editor, Editors.ChartCollectionEditor.Base),
506                 DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
507 #if !Microsoft_CONTROL
508                 PersistenceMode(PersistenceMode.InnerProperty)
509 #endif
510                 ]
511                 public AnnotationPathPointCollection GraphicsPathPoints
512                 {
513                         get
514                         {
515                                 if(this.pathChanged ||
516                                         _graphicsPath.PointCount != _pathPoints.Count)
517                                 {
518                                         // Recreate collection from graphics path
519                                         _pathPoints.annotation = null;
520                                         _pathPoints.Clear();
521                     if (_graphicsPath.PointCount > 0 )
522                     {
523                         PointF[] points = _graphicsPath.PathPoints;
524                         byte[] types = _graphicsPath.PathTypes;
525                         for (int index = 0; index < points.Length; index++)
526                         {
527                             _pathPoints.Add(new AnnotationPathPoint(points[index].X, points[index].Y, types[index]));
528                         }
529                     }
530                                         _pathPoints.annotation = this;
531                                 }
532                                 return _pathPoints;
533                         }
534                 }
535
536                 #endregion
537
538                 #endregion
539
540                 #region Methods
541
542                 #region Painting
543
544                 /// <summary>
545                 /// Paints an annotation object on the specified graphics.
546                 /// </summary>
547                 /// <param name="graphics">
548                 /// A <see cref="ChartGraphics"/> object, used to paint an annotation object.
549                 /// </param>
550                 /// <param name="chart">
551                 /// Reference to the <see cref="Chart"/> owner control.
552                 /// </param>
553         override internal void Paint(Chart chart, ChartGraphics graphics)
554                 {
555                         // Check for empty path
556                         if(_graphicsPath.PointCount == 0)
557                         {
558                                 return;
559                         }
560
561                         // Get annotation position in relative coordinates
562                         PointF firstPoint = PointF.Empty;
563                         PointF anchorPoint = PointF.Empty;
564                         SizeF size = SizeF.Empty;
565                         GetRelativePosition(out firstPoint, out size, out anchorPoint);
566                         PointF  secondPoint = new PointF(firstPoint.X + size.Width, firstPoint.Y + size.Height);
567
568                         // Create selection rectangle
569                         RectangleF selectionRect = new RectangleF(firstPoint, new SizeF(secondPoint.X - firstPoint.X, secondPoint.Y - firstPoint.Y));
570
571                         // Get position
572                         RectangleF      rectanglePosition = new RectangleF(selectionRect.Location, selectionRect.Size);
573                         if(rectanglePosition.Width < 0)
574                         {
575                                 rectanglePosition.X = rectanglePosition.Right;
576                                 rectanglePosition.Width = -rectanglePosition.Width;
577                         }
578                         if(rectanglePosition.Height < 0)
579                         {
580                                 rectanglePosition.Y = rectanglePosition.Bottom;
581                                 rectanglePosition.Height = -rectanglePosition.Height;
582                         }
583
584                         // Check if position is valid
585                         if( float.IsNaN(rectanglePosition.X) || 
586                                 float.IsNaN(rectanglePosition.Y) || 
587                                 float.IsNaN(rectanglePosition.Right) || 
588                                 float.IsNaN(rectanglePosition.Bottom) )
589                         {
590                                 return;
591                         }
592
593                         // Get annotation absolute position
594                         RectangleF rectanglePositionAbs = graphics.GetAbsoluteRectangle(rectanglePosition);
595
596                         // Calculate scaling
597                         float groupScaleX = rectanglePositionAbs.Width / 100.0f;
598                         float groupScaleY = rectanglePositionAbs.Height / 100.0f;
599                         
600                         // Convert path to pixel coordinates
601                         PointF[] pathPoints = _graphicsPath.PathPoints;
602                         byte[] pathTypes = _graphicsPath.PathTypes;
603                         for(int pointIndex = 0; pointIndex < pathPoints.Length; pointIndex++)
604                         {
605                                 pathPoints[pointIndex].X = rectanglePositionAbs.X + pathPoints[pointIndex].X * groupScaleX;
606                                 pathPoints[pointIndex].Y = rectanglePositionAbs.Y + pathPoints[pointIndex].Y * groupScaleY;
607                         }
608
609             using (GraphicsPath pathAbs = new GraphicsPath(pathPoints, pathTypes))
610             {
611
612                 // Set line caps
613                 bool capChanged = false;
614                 LineCap oldStartCap = LineCap.Flat;
615                 LineCap oldEndCap = LineCap.Flat;
616                 if (!this.isPolygon)
617                 {
618                     if (this._startCap != LineAnchorCapStyle.None ||
619                         this._endCap != LineAnchorCapStyle.None)
620                     {
621                         capChanged = true;
622                         oldStartCap = graphics.Pen.StartCap;
623                         oldEndCap = graphics.Pen.EndCap;
624
625                         // Apply anchor cap settings
626                         if (this._startCap == LineAnchorCapStyle.Arrow)
627                         {
628                             // Adjust arrow size for small line width
629                             if (this.LineWidth < 4)
630                             {
631                                 int adjustment = 3 - this.LineWidth;
632                                 graphics.Pen.StartCap = LineCap.Custom;
633                                 graphics.Pen.CustomStartCap = new AdjustableArrowCap(
634                                     this.LineWidth + adjustment,
635                                     this.LineWidth + adjustment,
636                                     true);
637                             }
638                             else
639                             {
640                                 graphics.Pen.StartCap = LineCap.ArrowAnchor;
641                             }
642                         }
643                         else if (this._startCap == LineAnchorCapStyle.Diamond)
644                         {
645                             graphics.Pen.StartCap = LineCap.DiamondAnchor;
646                         }
647                         else if (this._startCap == LineAnchorCapStyle.Round)
648                         {
649                             graphics.Pen.StartCap = LineCap.RoundAnchor;
650                         }
651                         else if (this._startCap == LineAnchorCapStyle.Square)
652                         {
653                             graphics.Pen.StartCap = LineCap.SquareAnchor;
654                         }
655                         if (this._endCap == LineAnchorCapStyle.Arrow)
656                         {
657                             // Adjust arrow size for small line width
658                             if (this.LineWidth < 4)
659                             {
660                                 int adjustment = 3 - this.LineWidth;
661                                 graphics.Pen.EndCap = LineCap.Custom;
662                                 graphics.Pen.CustomEndCap = new AdjustableArrowCap(
663                                     this.LineWidth + adjustment,
664                                     this.LineWidth + adjustment,
665                                     true);
666                             }
667                             else
668                             {
669                                 graphics.Pen.EndCap = LineCap.ArrowAnchor;
670                             }
671                         }
672                         else if (this._endCap == LineAnchorCapStyle.Diamond)
673                         {
674                             graphics.Pen.EndCap = LineCap.DiamondAnchor;
675                         }
676                         else if (this._endCap == LineAnchorCapStyle.Round)
677                         {
678                             graphics.Pen.EndCap = LineCap.RoundAnchor;
679                         }
680                         else if (this._endCap == LineAnchorCapStyle.Square)
681                         {
682                             graphics.Pen.EndCap = LineCap.SquareAnchor;
683                         }
684                     }
685                 }
686
687                 // Painting mode
688                 if (this.Common.ProcessModePaint)
689                 {
690                     if (this.isPolygon)
691                     {
692                         // Draw polygon
693                         pathAbs.CloseAllFigures();
694                         graphics.DrawPathAbs(
695                             pathAbs,
696                             this.BackColor,
697                             this.BackHatchStyle,
698                             String.Empty,
699                             ChartImageWrapMode.Scaled,
700                             Color.Empty,
701                             ChartImageAlignmentStyle.Center,
702                             this.BackGradientStyle,
703                             this.BackSecondaryColor,
704                             this.LineColor,
705                             this.LineWidth,
706                             this.LineDashStyle,
707                             PenAlignment.Center,
708                             this.ShadowOffset,
709                             this.ShadowColor);
710                     }
711                     else
712                     {
713                         // Draw polyline
714                         graphics.DrawPathAbs(
715                             pathAbs,
716                             Color.Transparent,
717                             ChartHatchStyle.None,
718                             String.Empty,
719                             ChartImageWrapMode.Scaled,
720                             Color.Empty,
721                             ChartImageAlignmentStyle.Center,
722                             GradientStyle.None,
723                             Color.Empty,
724                             this.LineColor,
725                             this.LineWidth,
726                             this.LineDashStyle,
727                             PenAlignment.Center,
728                             this.ShadowOffset,
729                             this.ShadowColor);
730                     }
731                 }
732
733                 if (this.Common.ProcessModeRegions)
734                 {
735                     // Create line graphics path
736                     GraphicsPath selectionPath = null;
737                     GraphicsPath newPath = null;
738
739                     if (this.isPolygon)
740                     {
741                         selectionPath = pathAbs;
742                     }
743                     else
744                     {
745                         newPath = new GraphicsPath();
746                         selectionPath = newPath;
747                         selectionPath.AddPath(pathAbs, false);
748                         using (Pen pen = (Pen)graphics.Pen.Clone())
749                         {
750                             // Increase pen size by 2 pixels
751                             pen.DashStyle = DashStyle.Solid;
752                             pen.Width += 2;
753                             try
754                             {
755                                 selectionPath.Widen(pen);
756                             }
757                             catch (OutOfMemoryException)
758                             {
759                                 // GraphicsPath.Widen incorrectly throws OutOfMemoryException
760                                 // catching here and reacting by not widening
761                             }
762                             catch (ArgumentException)
763                             {
764                             }
765                         }
766                     }
767
768                     // Add hot region
769                     this.Common.HotRegionsList.AddHotRegion(
770                         graphics,
771                         selectionPath,
772                         false,
773                         ReplaceKeywords(this.ToolTip),
774 #if Microsoft_CONTROL
775                                         String.Empty,
776                                         String.Empty,
777                                         String.Empty,
778 #else // Microsoft_CONTROL
779  ReplaceKeywords(this.Url),
780                                                 ReplaceKeywords(this.MapAreaAttributes),
781                         ReplaceKeywords(this.PostBackValue),
782 #endif // Microsoft_CONTROL
783  this,
784                         ChartElementType.Annotation);
785
786                     //Clean up
787                     if (newPath != null)
788                         newPath.Dispose();
789                 }
790
791                 // Restore line caps
792                 if (capChanged)
793                 {
794                     graphics.Pen.StartCap = oldStartCap;
795                     graphics.Pen.EndCap = oldEndCap;
796                 }
797
798                 // Paint selection handles
799                 PaintSelectionHandles(graphics, rectanglePosition, pathAbs);
800             }
801                 }
802
803                 #endregion // Painting
804
805                 #region Position Changing
806 #if Microsoft_CONTROL
807                 /// <summary>
808                 /// Changes annotation position, so it exactly matches the bounary of the 
809                 /// polyline path.
810                 /// </summary>
811                 private void ResizeToPathBoundary()
812                 {
813                         if(_graphicsPath.PointCount > 0)
814                         {
815                                 // Get current annotation position in relative coordinates
816                                 PointF firstPoint = PointF.Empty;
817                                 PointF anchorPoint = PointF.Empty;
818                                 SizeF size = SizeF.Empty;
819                                 GetRelativePosition(out firstPoint, out size, out anchorPoint);
820
821                                 // Get path boundary and convert it to relative coordinates
822                                 RectangleF pathBoundary = _graphicsPath.GetBounds();
823                                 pathBoundary.X *= size.Width / 100f;
824                                 pathBoundary.Y *= size.Height / 100f;
825                                 pathBoundary.X += firstPoint.X;
826                                 pathBoundary.Y += firstPoint.Y;
827                                 pathBoundary.Width *= size.Width / 100f;
828                                 pathBoundary.Height *= size.Height / 100f;
829
830                                 // Scale all current points
831                                 using( Matrix matrix = new Matrix() )
832                                 {
833                                         matrix.Scale(size.Width/pathBoundary.Width, size.Height/pathBoundary.Height);
834                                         matrix.Translate(-pathBoundary.X, -pathBoundary.Y);
835                                         _graphicsPath.Transform(matrix);
836                                 }
837
838                                 // Set new position for annotation
839                                 this.SetPositionRelative(pathBoundary, anchorPoint);
840                         }
841                 }
842 #endif //Microsoft_CONTROL
843         /// <summary>
844         /// Adjust annotation location and\or size as a result of user action.
845         /// </summary>
846         /// <param name="movingDistance">Distance to resize/move the annotation.</param>
847         /// <param name="resizeMode">Resizing mode.</param>
848         /// <param name="pixelCoord">Distance is in pixels, otherwise relative.</param>
849         /// <param name="userInput">Indicates if position changing was a result of the user input.</param>
850                 override internal void AdjustLocationSize(SizeF movingDistance, ResizingMode resizeMode, bool pixelCoord, bool userInput)
851                 {
852                         // Call base class when not resizing the path points
853                         if(resizeMode != ResizingMode.MovingPathPoints)
854                         {
855                                 base.AdjustLocationSize(movingDistance, resizeMode, pixelCoord, userInput);
856                                 return;
857                         }
858
859                         // Get annotation position in relative coordinates
860                         PointF firstPoint = PointF.Empty;
861                         PointF anchorPoint = PointF.Empty;
862                         SizeF size = SizeF.Empty;
863                         GetRelativePosition(out firstPoint, out size, out anchorPoint);
864
865                         // Remember path before moving operation
866                         if(userInput == true && startMovePathRel == null)
867                         {
868 #if Microsoft_CONTROL
869                                 this.startMovePathRel = (GraphicsPath)_graphicsPath.Clone();
870                                 this.startMovePositionRel = new RectangleF(firstPoint, size);
871                                 this.startMoveAnchorLocationRel = new PointF(anchorPoint.X, anchorPoint.Y);
872
873 #endif // Microsoft_CONTROL
874                         }
875
876                         // Convert moving distance to coordinates relative to the anotation
877                         if(pixelCoord)
878                         {
879                                 movingDistance = this.GetGraphics().GetRelativeSize(movingDistance);
880                         }
881                         movingDistance.Width /= startMovePositionRel.Width / 100.0f;
882                         movingDistance.Height /= startMovePositionRel.Height / 100.0f;
883
884                         // Get path points and adjust position of one of them
885                         if(_graphicsPath.PointCount > 0)
886                         {
887                                 GraphicsPath pathToMove = (userInput) ? startMovePathRel : _graphicsPath;
888                                 PointF[] pathPoints = pathToMove.PathPoints;
889                                 byte[] pathTypes = pathToMove.PathTypes;
890
891                                 for(int pointIndex = 0; pointIndex < pathPoints.Length; pointIndex++)
892                                 {
893                                         // Adjust position
894                                         if( currentPathPointIndex == pointIndex ||
895                                                 currentPathPointIndex < 0 ||
896                                                 currentPathPointIndex >= pathPoints.Length )
897                                         {
898                                                 pathPoints[pointIndex].X -= movingDistance.Width;
899                                                 pathPoints[pointIndex].Y -= movingDistance.Height;
900                                         }
901                                 }
902
903 #if Microsoft_CONTROL
904
905                                 // Adjust annotation position to the boundary of the path
906                                 if(userInput && this.AllowResizing)
907                                 {
908                                         // Get path bounds in relative coordinates
909                     _defaultGraphicsPath.Dispose();
910                     _defaultGraphicsPath = new GraphicsPath(pathPoints, pathTypes);
911                                         _graphicsPath = _defaultGraphicsPath;
912
913                     RectangleF pathBounds = _graphicsPath.GetBounds();
914                                         pathBounds.X *= startMovePositionRel.Width / 100f;
915                                         pathBounds.Y *= startMovePositionRel.Height / 100f;
916                                         pathBounds.X += startMovePositionRel.X;
917                                         pathBounds.Y += startMovePositionRel.Y;
918                                         pathBounds.Width *= startMovePositionRel.Width / 100f;
919                                         pathBounds.Height *= startMovePositionRel.Height / 100f;
920
921                                         // Set new annotation position
922                                         this.SetPositionRelative(pathBounds, anchorPoint);
923
924                                         // Adjust path point position
925                                         for(int pointIndex = 0; pointIndex < pathPoints.Length; pointIndex++)
926                                         {
927         
928                                                 pathPoints[pointIndex].X = startMovePositionRel.X + pathPoints[pointIndex].X * (startMovePositionRel.Width / 100f);
929                                                 pathPoints[pointIndex].Y = startMovePositionRel.Y + pathPoints[pointIndex].Y * (startMovePositionRel.Height / 100f);
930
931                                                 pathPoints[pointIndex].X = (pathPoints[pointIndex].X - pathBounds.X) / (pathBounds.Width / 100f);
932                                                 pathPoints[pointIndex].Y = (pathPoints[pointIndex].Y - pathBounds.Y) / (pathBounds.Height / 100f);
933                                         }
934                                 }
935
936 #endif // Microsoft_CONTROL
937
938 #if Microsoft_CONTROL
939                                 // Position changed
940                                 this.positionChanged = true;
941 #endif // Microsoft_CONTROL
942                         
943                                 // Recreate path with new points
944                 _defaultGraphicsPath.Dispose();
945                 _defaultGraphicsPath = new GraphicsPath(pathPoints, pathTypes);
946                 _graphicsPath = _defaultGraphicsPath;
947                                 this.pathChanged = true;
948
949                                 // Invalidate annotation
950                                 this.Invalidate();
951                         }
952                 }
953
954                 #endregion // Position Changing
955
956                 #region Placement Methods
957
958 #if Microsoft_CONTROL
959
960                 /// <summary>
961                 /// Ends user placement of an annotation.
962                 /// </summary>
963                 /// <remarks>
964                 /// Ends an annotation placement operation previously started by a 
965                 /// <see cref="Annotation.BeginPlacement"/> method call.
966                 /// <para>
967                 /// Calling this method is not required, since placement will automatically
968                 /// end when an end user enters all required points. However, it is useful when an annotation 
969                 /// placement operation needs to be aborted for some reason.
970                 /// </para>
971                 /// </remarks>
972                 override public void EndPlacement()
973                 {
974                         // Call base method
975                         base.EndPlacement();
976
977                         // Position was changed
978                         if(this.Chart != null)
979                         {
980                                 this.Chart.OnAnnotationPositionChanged(this);
981                         }
982
983                         // Reset last placement position
984                         this.lastPlacementPosition = PointF.Empty;
985
986                         // Resize annotation to the boundary of the polygon
987                         ResizeToPathBoundary();
988
989                         // Position changed
990                         this.positionChanged = true;
991                 }
992
993                 /// <summary>
994                 /// Handles mouse down event during annotation placement.
995                 /// </summary>
996                 /// <param name="point">Mouse cursor position in pixels.</param>
997                 /// <param name="buttons">Mouse button down.</param>
998                 internal override void PlacementMouseDown(PointF point, MouseButtons buttons)
999                 {
1000                         // Call base class method if path editing is not allowed 
1001                         if(!this.AllowPathEditing)
1002                         {
1003                                 base.PlacementMouseDown(point, buttons);
1004                                 return;
1005                         }
1006
1007                         if(buttons == MouseButtons.Right)
1008                         {
1009                                 // Stop pacement
1010                                 this.EndPlacement();
1011                         }
1012                         if(buttons == MouseButtons.Left &&
1013                                 IsValidPlacementPosition(point.X, point.Y))
1014                         {
1015                                 // Convert coordinate to relative
1016                                 PointF newPoint = this.GetGraphics().GetRelativePoint(point);
1017
1018                                 if(this.lastPlacementPosition.IsEmpty)
1019                                 {
1020                                         // Set annotation coordinates to full chart
1021                                         this.X = 0f;
1022                                         this.Y = 0f;
1023                                         this.Width = 100f;
1024                                         this.Height = 100f;
1025
1026                                         // Remeber position where mouse was clicked
1027                                         this.lastPlacementPosition = newPoint;
1028                                 }
1029                                 else
1030                                 {
1031                                         if(this.lastPlacementPosition.X == newPoint.X && 
1032                                                 this.lastPlacementPosition.Y == newPoint.Y)
1033                                         {
1034                                                 // Stop pacement
1035                                                 this.EndPlacement();
1036                                         }
1037                                 }
1038
1039                                 // Add a line from prev. position to current into the path
1040                                 using( GraphicsPath tmpPath = new GraphicsPath() )
1041                                 {
1042                                         PointF firstPoint = this.lastPlacementPosition;
1043                                         if(_graphicsPath.PointCount > 1)
1044                                         {
1045                                                 firstPoint = _graphicsPath.GetLastPoint();
1046                                         }
1047                                         tmpPath.AddLine(firstPoint, newPoint);
1048                                         _graphicsPath.AddPath(tmpPath, true);
1049                                 }
1050
1051                                 // Remember last position
1052                                 this.lastPlacementPosition = newPoint;
1053
1054                                 // Invalidate and update the chart
1055                                 if(Chart != null)
1056                                 {
1057                                         Invalidate();
1058                                         Chart.UpdateAnnotations();
1059                                 }
1060                         }
1061                 }
1062
1063                 /// <summary>
1064                 /// Handles mouse up event during annotation placement.
1065                 /// </summary>
1066                 /// <param name="point">Mouse cursor position in pixels.</param>
1067                 /// <param name="buttons">Mouse button Up.</param>
1068                 /// <returns>Return true when placing finished.</returns>
1069                 internal override bool PlacementMouseUp(PointF point, MouseButtons buttons)
1070                 {
1071                         // Call base class method if path editing is not allowed 
1072                         if(!this.AllowPathEditing)
1073                         {
1074                                 return base.PlacementMouseUp(point, buttons);
1075                         }
1076
1077                         if(buttons == MouseButtons.Left &&
1078                                 isFreeDrawPlacement)
1079                         {
1080                                 // Stop pacement
1081                                 this.EndPlacement();
1082
1083                         }
1084
1085                         return false;
1086                 }
1087
1088                 /// <summary>
1089                 /// Handles mouse move event during annotation placement.
1090                 /// </summary>
1091                 /// <param name="point">Mouse cursor position in pixels.</param>
1092                 internal override void PlacementMouseMove(PointF point)
1093                 {
1094                         // Call base class method if path editing is not allowed 
1095                         if(!this.AllowPathEditing)
1096                         {
1097                                 base.PlacementMouseMove(point);
1098                                 return;
1099                         }
1100
1101                         // Check if annotation was moved
1102                         if( this.GetGraphics() != null &&
1103                                 _graphicsPath.PointCount > 0 &&
1104                                 !this.lastPlacementPosition.IsEmpty)
1105                         {
1106                                 // Convert coordinate to relative
1107                                 PointF newPoint = this.GetGraphics().GetRelativePoint(point);
1108                                 if(this.isFreeDrawPlacement)
1109                                 {
1110                                         // Add new point
1111                                         using( GraphicsPath tmpPath = new GraphicsPath() )
1112                                         {
1113                                                 PointF firstPoint = this.lastPlacementPosition;
1114                                                 if(_graphicsPath.PointCount > 1)
1115                                                 {
1116                                                         firstPoint = _graphicsPath.GetLastPoint();
1117                                                 }
1118                                                 tmpPath.AddLine(firstPoint, newPoint);
1119                                                 _graphicsPath.AddPath(tmpPath, true);
1120                                         }
1121                                 }
1122                                 else
1123                                 {
1124                                         // Adjust last point position
1125                                         PointF[] pathPoints = _graphicsPath.PathPoints;
1126                                         byte[] pathTypes = _graphicsPath.PathTypes;
1127                                         pathPoints[pathPoints.Length - 1] = newPoint;
1128
1129                     _defaultGraphicsPath.Dispose();
1130                     _defaultGraphicsPath = new GraphicsPath(pathPoints, pathTypes);
1131                     _graphicsPath = _defaultGraphicsPath;
1132
1133                                 }
1134
1135                                 // Position changed
1136                                 this.positionChanged = true;
1137
1138                                 // Invalidate and update the chart
1139                                 if(this.Chart != null)
1140                                 {
1141                                         Invalidate();
1142                                         this.Chart.UpdateAnnotations();
1143                                 }
1144                         }
1145                 }
1146
1147 #endif // Microsoft_CONTROL
1148
1149         #endregion // Placement Methods
1150
1151         #endregion
1152
1153         #region IDisposable override 
1154         /// <summary>
1155         /// Releases unmanaged and - optionally - managed resources
1156         /// </summary>
1157         /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
1158         protected override void Dispose(bool disposing)
1159         {
1160             if (disposing)
1161             {
1162                 if (_defaultGraphicsPath != null)
1163                 {
1164                     _defaultGraphicsPath.Dispose();
1165                     _defaultGraphicsPath = null;
1166                 }
1167                 if (_pathPoints != null)
1168                 {
1169                     _pathPoints.Dispose();
1170                     _pathPoints = null;
1171                 }
1172
1173             }
1174             base.Dispose(disposing);
1175         }
1176         #endregion
1177
1178     }
1179
1180         /// <summary>
1181         /// <b>PolygonAnnotation</b> is a class that represents a polygon annotation.
1182         /// </summary>
1183         [
1184                 SRDescription("DescriptionAttributePolygonAnnotation_PolygonAnnotation"),
1185         ]
1186 #if ASPPERM_35
1187         [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1188     [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1189 #endif
1190     public class PolygonAnnotation : PolylineAnnotation
1191         {
1192                 #region Construction and Initialization
1193
1194                 /// <summary>
1195                 /// Default public constructor.
1196                 /// </summary>
1197                 public PolygonAnnotation() 
1198             : base()
1199                 {
1200                         this.isPolygon = true;
1201                 }
1202
1203                 #endregion
1204
1205                 #region Properties
1206
1207                 #region Non Applicable Annotation Appearance Attributes (set as Non-Browsable)
1208
1209                 /// <summary>
1210                 /// Not applicable to this annotation type.
1211                 /// <seealso cref="EndCap"/>
1212                 /// </summary>
1213                 /// <value>
1214                 /// A <see cref="LineAnchorCapStyle"/> value.
1215                 /// </value>
1216                 [
1217                 SRCategory("CategoryAttributeAppearance"),
1218                 Browsable(false),
1219                 DefaultValue(LineAnchorCapStyle.None),
1220                 ]
1221                 override public LineAnchorCapStyle StartCap
1222                 {
1223                         get
1224                         {
1225                                 return base.StartCap;
1226                         }
1227                         set
1228                         {
1229                                 base.StartCap = value;
1230                         }
1231                 }
1232
1233                 /// <summary>
1234                 /// Not applicable to this annotation type.
1235                 /// <seealso cref="StartCap"/>
1236                 /// </summary>
1237                 /// <value>
1238                 /// A <see cref="LineAnchorCapStyle"/> value.
1239                 /// </value>
1240                 [
1241                 SRCategory("CategoryAttributeAppearance"),
1242                 Browsable(false),
1243                 DefaultValue(LineAnchorCapStyle.None),
1244                 ]
1245                 override public LineAnchorCapStyle EndCap
1246                 {
1247                         get
1248                         {
1249                                 return base.EndCap;
1250                         }
1251                         set
1252                         {
1253                                 base.EndCap = value;
1254                         }
1255                 }
1256
1257                 #endregion
1258
1259                 #region Applicable Annotation Appearance Attributes (set as Browsable)
1260
1261         /// <summary>
1262         /// Gets or sets the background color of an annotation.
1263         /// <seealso cref="BackSecondaryColor"/>
1264         /// <seealso cref="BackHatchStyle"/>
1265         /// <seealso cref="BackGradientStyle"/>
1266         /// </summary>
1267         /// <value>
1268         /// A <see cref="Color"/> value used for the background of an annotation.
1269         /// </value>
1270                 [
1271                 SRCategory("CategoryAttributeAppearance"),
1272                 Browsable(true),
1273                 DefaultValue(typeof(Color), ""),
1274         SRDescription("DescriptionAttributeBackColor"),
1275                 NotifyParentPropertyAttribute(true),
1276         TypeConverter(typeof(ColorConverter)),
1277         Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base)
1278                 ]
1279                 override public Color BackColor
1280                 {
1281                         get
1282                         {
1283                                 return base.BackColor;
1284                         }
1285                         set
1286                         {
1287                                 base.BackColor = value;
1288                         }
1289                 }
1290
1291         /// <summary>
1292         /// Gets or sets the background hatch style of an annotation.
1293         /// <seealso cref="BackSecondaryColor"/>
1294         /// <seealso cref="BackColor"/>
1295         /// <seealso cref="BackGradientStyle"/>
1296         /// </summary>
1297         /// <value>
1298         /// A <see cref="ChartHatchStyle"/> value used for the background of an annotation.
1299         /// </value>
1300         /// <remarks>
1301         /// Two colors are used to draw the hatching, <see cref="BackColor"/> and <see cref="BackSecondaryColor"/>.
1302         /// </remarks>
1303                 [
1304                 SRCategory("CategoryAttributeAppearance"),
1305                 Browsable(true),
1306                 DefaultValue(ChartHatchStyle.None),
1307                 NotifyParentPropertyAttribute(true),
1308                 SRDescription("DescriptionAttributeBackHatchStyle"),
1309                 Editor(Editors.HatchStyleEditor.Editor, Editors.HatchStyleEditor.Base)
1310                 ]
1311                 override public ChartHatchStyle BackHatchStyle
1312                 {
1313                         get
1314                         {
1315                                 return base.BackHatchStyle;
1316                         }
1317                         set
1318                         {
1319                                 base.BackHatchStyle = value;
1320                         }
1321                 }
1322
1323         /// <summary>
1324         /// Gets or sets the background gradient style of an annotation.
1325         /// <seealso cref="BackSecondaryColor"/>
1326         /// <seealso cref="BackColor"/>
1327         /// <seealso cref="BackHatchStyle"/>
1328         /// </summary>
1329         /// <value>
1330         /// A <see cref="GradientStyle"/> value used for the background of an annotation.
1331         /// </value>
1332         /// <remarks>
1333         /// Two colors are used to draw the gradient, <see cref="BackColor"/> and <see cref="BackSecondaryColor"/>.
1334         /// </remarks>
1335                 [
1336                 SRCategory("CategoryAttributeAppearance"),
1337                 Browsable(true),
1338                 DefaultValue(GradientStyle.None),
1339                 NotifyParentPropertyAttribute(true),
1340                 SRDescription("DescriptionAttributeBackGradientStyle"),
1341                 Editor(Editors.GradientEditor.Editor, Editors.GradientEditor.Base)
1342                 ]               
1343                 override public GradientStyle BackGradientStyle
1344                 {
1345                         get
1346                         {
1347                                 return base.BackGradientStyle;
1348                         }
1349                         set
1350                         {
1351                                 base.BackGradientStyle = value;
1352                         }
1353                 }
1354
1355         /// <summary>
1356         /// Gets or sets the secondary background color of an annotation.
1357         /// <seealso cref="BackColor"/>
1358         /// <seealso cref="BackHatchStyle"/>
1359         /// <seealso cref="BackGradientStyle"/>
1360         /// </summary>
1361         /// <value>
1362         /// A <see cref="Color"/> value used for the secondary color of an annotation background with 
1363         /// hatching or gradient fill.
1364         /// </value>
1365         /// <remarks>
1366         /// This color is used with <see cref="BackColor"/> when <see cref="BackHatchStyle"/> or
1367         /// <see cref="BackGradientStyle"/> are used.
1368         /// </remarks>
1369                 [
1370                 SRCategory("CategoryAttributeAppearance"),
1371                 Browsable(true),
1372                 DefaultValue(typeof(Color), ""),
1373                 NotifyParentPropertyAttribute(true),
1374         SRDescription("DescriptionAttributeBackSecondaryColor"),
1375         TypeConverter(typeof(ColorConverter)),
1376         Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base)
1377                 ] 
1378                 override public Color BackSecondaryColor
1379                 {
1380                         get
1381                         {
1382                                 return base.BackSecondaryColor;
1383                         }
1384                         set
1385                         {
1386                                 base.BackSecondaryColor = value;
1387                         }
1388                 }
1389
1390                 #endregion
1391
1392                 #region Other
1393
1394         /// <summary>
1395         /// Gets or sets an annotation's type name.
1396         /// </summary>
1397         /// <remarks>
1398         /// This property is used to get the name of each annotation type 
1399         /// (e.g. Line, Rectangle, Ellipse). 
1400         /// <para>
1401         /// This property is for internal use and is hidden at design and run time.
1402         /// </para>
1403         /// </remarks>
1404                 [
1405                 SRCategory("CategoryAttributeMisc"),
1406                 Bindable(true),
1407                 Browsable(false),
1408                 EditorBrowsableAttribute(EditorBrowsableState.Never),
1409                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
1410                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
1411                 SRDescription("DescriptionAttributeAnnotationType"),
1412                 ]
1413                 public override string AnnotationType
1414                 {
1415                         get
1416                         {
1417                                 return "Polygon";
1418                         }
1419                 }
1420
1421                 /// <summary>
1422                 /// Gets or sets an annotation's selection points style.
1423                 /// </summary>
1424                 /// <value>
1425                 /// A <see cref="SelectionPointsStyle"/> value that represents an annotation's 
1426                 /// selection style.
1427                 /// </value>
1428                 /// <remarks>
1429         /// This property is for internal use and is hidden at design and run time.
1430                 /// </remarks>
1431                 [
1432                 SRCategory("CategoryAttributeAppearance"),
1433                 DefaultValue(SelectionPointsStyle.Rectangle),
1434                 ParenthesizePropertyNameAttribute(true),
1435                 Browsable(false),
1436                 EditorBrowsableAttribute(EditorBrowsableState.Never),
1437                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
1438                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
1439                 SRDescription("DescriptionAttributeSelectionPointsStyle"),
1440                 ]
1441                 override internal SelectionPointsStyle SelectionPointsStyle
1442                 {
1443                         get
1444                         {
1445                                 return SelectionPointsStyle.Rectangle;
1446                         }
1447                 }
1448
1449                 #endregion
1450
1451                 #endregion
1452         }
1453
1454     /// <summary><b>AnnotationPathPointCollection</b> is a collection of polyline 
1455     /// annotation path points, and is only available via the <b>GraphicsPathPoints</b> 
1456     /// property at design-time.
1457     /// <seealso cref="PolylineAnnotation.GraphicsPathPoints"/></summary>
1458     /// <remarks>
1459     /// This collection is used at design-time only, and uses serialization to expose the 
1460     /// shape of the polyline and polygon via their GraphicsPathPoints collection property.
1461     /// At run-time, use Path property to set the path of a polyline or polygon
1462     /// </remarks>
1463         [
1464                 SRDescription("DescriptionAttributeAnnotationPathPointCollection_AnnotationPathPointCollection"),
1465         ]
1466 #if ASPPERM_35
1467         [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1468     [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1469 #endif
1470     public class AnnotationPathPointCollection : ChartElementCollection<AnnotationPathPoint>
1471         {
1472                 #region Fields
1473
1474                 internal                PolylineAnnotation      annotation = null;
1475         private         GraphicsPath        _graphicsPath = null;
1476
1477                 #endregion // Fields
1478
1479                 #region Constructors
1480
1481                 /// <summary>
1482                 /// Default public constructor.
1483                 /// </summary>
1484         public AnnotationPathPointCollection(PolylineAnnotation annotation)
1485             : base(annotation)
1486                 {
1487             this.annotation = annotation;
1488                 }
1489
1490                 #endregion // Constructors
1491
1492                 #region Methods
1493
1494         /// <summary>
1495         /// Forces the invalidation of the chart element
1496         /// </summary>
1497         public override void Invalidate()
1498         {
1499             if (this.annotation != null)
1500             {
1501                 //Dispose previously instantiated graphics path
1502                 if (this._graphicsPath != null)
1503                 {
1504                     this._graphicsPath.Dispose();
1505                     this._graphicsPath = null;
1506                 }
1507
1508                 // Recreate polyline annotation path
1509                 if (this.Count > 0)
1510                 {
1511                     PointF[] points = new PointF[this.Count];
1512                     byte[] types = new byte[this.Count];
1513                     for (int index = 0; index < this.Count; index++)
1514                     {
1515                         points[index] = new PointF(this[index].X, this[index].Y);
1516                         types[index] = this[index].PointType;
1517                     }
1518                     this._graphicsPath = new GraphicsPath(points, types);
1519                 }
1520                 else
1521                 {
1522                     this._graphicsPath = new GraphicsPath();
1523                 }
1524
1525                 // Invalidate annotation
1526                 this.annotation.GraphicsPath = this._graphicsPath;
1527                 this.annotation.Invalidate();
1528             }
1529             base.Invalidate();
1530         }
1531
1532                 #endregion // Methods
1533
1534         #region IDisposable Members
1535         /// <summary>
1536         /// Releases unmanaged and - optionally - managed resources
1537         /// </summary>
1538         /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
1539         protected override void Dispose(bool disposing)
1540         {
1541             if (disposing)
1542             {   
1543                 // Free up managed resources
1544                 if (this._graphicsPath != null)
1545                 {
1546                     this._graphicsPath.Dispose();
1547                     this._graphicsPath = null;
1548                 }
1549             }
1550             base.Dispose(disposing);
1551         }
1552
1553         #endregion
1554     }
1555
1556         /// <summary>
1557         /// The <b>AnnotationPathPoint</b> class represents a path point of a polyline or polygon, 
1558         /// and is stored in their <b>GraphicsPathPoints</b> property, which is only available at design-time.
1559         /// </summary>
1560         /// <remarks>
1561         /// At run-time, use <b>Path</b> property to set the path of a polyline or polygon.
1562         /// </remarks>
1563         [
1564                 SRDescription("DescriptionAttributeAnnotationPathPoint_AnnotationPathPoint"),
1565         ]
1566 #if ASPPERM_35
1567         [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1568     [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
1569 #endif
1570     public class AnnotationPathPoint: ChartElement
1571         {
1572                 #region Fields
1573
1574                 // Point X value
1575                 private float           _x = 0f;
1576
1577                 // Point Y value
1578                 private float           _y = 0f;
1579
1580                 // Point type
1581                 private byte            _pointType = 1;
1582
1583                 #endregion // Fields
1584
1585                 #region Constructors
1586
1587                 /// <summary>
1588                 /// Default public constructor.
1589                 /// </summary>
1590                 public AnnotationPathPoint()
1591                 {
1592                 }
1593
1594                 /// <summary>
1595                 /// Constructor that takes X and Y parameters.
1596                 /// </summary>
1597                 /// <param name="x">Point's X value.</param>
1598                 /// <param name="y">Point's Y value.</param>
1599         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
1600             Justification="X and Y are cartesian coordinates and well understood")]
1601         public AnnotationPathPoint(float x, float y)
1602                 {
1603                         this._x = x;
1604                         this._y = y;
1605                 }
1606
1607                 /// <summary>
1608                 /// Constructor that takes X, Y and point type parameters.
1609                 /// </summary>
1610                 /// <param name="x">Point's X value.</param>
1611                 /// <param name="y">Point's Y value.</param>
1612                 /// <param name="type">Point type.</param>
1613         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
1614             Justification = "X and Y are cartesian coordinates and well understood")]
1615         public AnnotationPathPoint(float x, float y, byte type)
1616                 {
1617                         this._x = x;
1618                         this._y = y;
1619                         this._pointType = type;
1620                 }
1621
1622                 #endregion // Constructors
1623
1624                 #region Properties
1625
1626                 /// <summary>
1627                 /// Gets or sets an annotation path point's X coordinate.
1628                 /// </summary>
1629                 /// <value>
1630                 /// A float value for the point's X coordinate.
1631                 /// </value>
1632                 [
1633                 SRCategory("CategoryAttributePosition"),
1634                 DefaultValue(0f),
1635                 Browsable(true),
1636                 SRDescription("DescriptionAttributeAnnotationPathPoint_X"),
1637 #if !Microsoft_CONTROL
1638                 PersistenceMode(PersistenceMode.Attribute),
1639 #endif
1640                 ]
1641         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "X")]
1642         public float X
1643                 {
1644                         get
1645                         {
1646                                 return _x;
1647                         }
1648                         set
1649                         {
1650                                 _x = value;
1651                         }
1652                 }
1653
1654                 /// <summary>
1655                 /// Gets or sets an annotation path point's Y coordinate.
1656                 /// </summary>
1657                 /// <value>
1658                 /// A float value for the point's Y coordinate.
1659                 /// </value>
1660                 [
1661                 SRCategory("CategoryAttributePosition"),
1662                 DefaultValue(0f),
1663                 Browsable(true),
1664                 SRDescription("DescriptionAttributeAnnotationPathPoint_Y"),
1665 #if !Microsoft_CONTROL
1666                 PersistenceMode(PersistenceMode.Attribute),
1667 #endif
1668                 ]
1669         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Y")]
1670         public float Y
1671                 {
1672                         get
1673                         {
1674                                 return _y;
1675                         }
1676                         set
1677                         {
1678                                 _y = value;
1679                         }
1680                 }
1681
1682                 /// <summary>
1683                 /// Gets or sets an annotation path point's type.
1684                 /// </summary>
1685                 /// <value>
1686                 /// A byte value.
1687                 /// </value>
1688                 /// <remarks>
1689                 /// See the <see cref="PathPointType"/> enumeration for more details.
1690                 /// </remarks>
1691                 [
1692                 SRCategory("CategoryAttributePosition"),
1693                 DefaultValue(typeof(byte), "1"),
1694                 Browsable(false),
1695                 EditorBrowsableAttribute(EditorBrowsableState.Never),
1696                 SRDescription("DescriptionAttributeAnnotationPathPoint_Name"),
1697 #if !Microsoft_CONTROL
1698                 PersistenceMode(PersistenceMode.Attribute),
1699 #endif
1700                 ]
1701                 public byte PointType
1702                 {
1703                         get
1704                         {
1705                                 return _pointType;
1706                         }
1707                         set
1708                         {
1709                                 _pointType = value;
1710                         }
1711                 }
1712
1713                 /// <summary>
1714                 /// Gets or sets an annotation path point's name.
1715                 /// </summary>
1716                 /// <para>
1717         /// This property is for internal use and is hidden at design and run time.
1718                 /// </para>
1719                 [
1720                 SRCategory("CategoryAttributeMisc"),
1721                 DefaultValue("PathPoint"),
1722                 Browsable(false),
1723                 EditorBrowsableAttribute(EditorBrowsableState.Never),
1724                 SRDescription("DescriptionAttributeAnnotationPathPoint_Name"),
1725                 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
1726                 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
1727                 ]
1728                 public string Name
1729                 {
1730                         get
1731                         {
1732                                 return "PathPoint";
1733                         }
1734                 }
1735
1736                 #endregion // Properties
1737
1738     }
1739 }