1 //-------------------------------------------------------------
2 // <copyright company=’Microsoft Corporation’>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: ElementPosition.cs
10 // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting
12 // Classes: ElementPosition
14 // Purpose: Class is used to store relative position of the chart
15 // elements like Legend, Title and others. It uses
16 // relative coordinate system where top left corner is
17 // 0,0 and bottom right is 100,100.
19 // If Auto property is set to true, all position properties
20 // (X,Y,Width and Height) are ignored and they automatically
21 // calculated during chart rendering.
23 // Note that setting any of the position properties will
24 // automatically set Auto property to false.
26 // Reviewed: AG - August 7, 2002
27 // AG - Microsoft 5, 2007
29 //===================================================================
32 #region Used Namespaces
35 using System
.Collections
;
36 using System
.Collections
.Specialized
;
37 using System
.ComponentModel
;
38 using System
.ComponentModel
.Design
;
41 using System
.Drawing
.Design
;
42 using System
.Drawing
.Drawing2D
;
43 using System
.Diagnostics
.CodeAnalysis
;
44 using System
.Globalization
;
47 using System
.Windows
.Forms
.DataVisualization
.Charting
;
48 using System
.Windows
.Forms
.DataVisualization
.Charting
.Data
;
49 using System
.Windows
.Forms
.DataVisualization
.Charting
.ChartTypes
;
50 using System
.Windows
.Forms
.DataVisualization
.Charting
.Utilities
;
51 using System
.Windows
.Forms
.DataVisualization
.Charting
.Borders3D
;
55 using System
.Web
.UI
.DataVisualization
.Charting
;
56 using System
.Web
.UI
.DataVisualization
.Charting
.Data
;
63 namespace System
.Windows
.Forms
.DataVisualization
.Charting
65 namespace System
.Web
.UI
.DataVisualization
.Charting
70 /// ElementPosition is the base class for many chart visual
71 /// elements like Legend, Title and ChartArea. It provides
72 /// the position of the chart element in relative coordinates,
73 /// from (0,0) to (100,100).
76 SRDescription("DescriptionAttributeElementPosition_ElementPosition"),
77 DefaultProperty("Data"),
80 [AspNetHostingPermission(System
.Security
.Permissions
.SecurityAction
.InheritanceDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
81 [AspNetHostingPermission(System
.Security
.Permissions
.SecurityAction
.LinkDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
83 public class ElementPosition
: ChartElement
87 // Private data members, which store properties values
90 private float _width
= 0;
91 private float _height
= 0;
92 internal bool _auto
= true;
94 // Indicates the auto position of all areas must be reset
95 internal bool resetAreaAutoPosition
= false;
102 /// ElementPosition default constructor
104 public ElementPosition()
109 /// ElementPosition default constructor
111 internal ElementPosition(IChartElement parent
)
118 /// ElementPosition constructor.
120 /// <param name="x">X position.</param>
121 /// <param name="y">Y position.</param>
122 /// <param name="width">Width.</param>
123 /// <param name="height">Height.</param>
124 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
125 Justification
= "X and Y are cartesian coordinates and well understood")]
126 public ElementPosition(float x
, float y
, float width
, float height
)
132 this._height
= height
;
140 /// Asks the user at design-time if he wants to change the Auto position
141 /// of all areas at the same time.
143 /// <param name="autoValue">Value to be set for the Auto property.</param>
144 private void ResetAllAreasAutoPosition(bool autoValue
)
146 if(resetAreaAutoPosition
)
148 // Proceed only if at design time
149 if(Chart
!= null && Chart
.IsDesignMode() && !Chart
.serializing
&& Chart
.Site
!= null)
151 // Check if there is more than one area and Auto position set to the same value
152 if(Chart
.ChartAreas
.Count
> 1)
154 bool firstAutoValue
= Chart
.ChartAreas
[0].Position
.Auto
;
155 bool sameAutoValue
= true;
156 foreach(ChartArea area
in Chart
.ChartAreas
)
158 if(area
.Position
.Auto
!= firstAutoValue
)
160 sameAutoValue
= false;
165 // Proceed only all Auto values are the same
168 string message
= SR
.MessageChangingChartAreaPositionProperty
;
171 message
+= SR
.MessageChangingChartAreaPositionConfirmAutomatic
;
175 message
+= SR
.MessageChangingChartAreaPositionConfirmCustom
;
179 IDesignerMessageBoxDialog confirm
= Chart
.Site
.GetService(typeof(IDesignerMessageBoxDialog
)) as IDesignerMessageBoxDialog
;
180 if (confirm
!= null && confirm
.ShowQuestion(message
))
182 foreach (ChartArea area
in Chart
.ChartAreas
)
186 this.SetPositionNoAuto(0f
, 0f
, 0f
, 0f
);
188 area
.Position
._auto
= autoValue
;
199 /// Convert element position into RectangleF
201 /// <returns>RectangleF structure.</returns>
202 public RectangleF
ToRectangleF()
204 return new RectangleF(_x
, _y
, _width
, _height
);
208 /// Initializes ElementPosition from RectangleF
210 /// <param name="rect">RectangleF structure.</param>
211 public void FromRectangleF(RectangleF rect
)
214 throw new ArgumentNullException("rect");
218 this._width
= rect
.Width
;
219 this._height
= rect
.Height
;
224 /// Gets the size of the ElementPosition object.
226 /// <returns>The size of the ElementPosition object.</returns>
228 [Utilities
.SerializationVisibility(Utilities
.SerializationVisibility
.Hidden
)]
231 get { return new SizeF(this._width, this._height); }
235 /// Gets the bottom position in relative coordinates.
237 /// <returns>Bottom position.</returns>
239 [Utilities
.SerializationVisibility(Utilities
.SerializationVisibility
.Hidden
)]
242 get { return this._y + this._height; }
246 /// Gets the right position in relative coordinates.
248 /// <returns>Right position.</returns>
250 [Utilities
.SerializationVisibility(Utilities
.SerializationVisibility
.Hidden
)]
253 get{ return this._x + this._width; }
257 /// Determines whether the specified Object is equal to the current Object.
259 /// <param name="obj">The Object to compare with the current Object.</param>
260 /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
261 internal override bool EqualsInternal(object obj
)
263 ElementPosition pos
= obj
as ElementPosition
;
266 if(this._auto
== true && this._auto
== pos
._auto
)
270 else if(this._x
== pos
._x
&& this._y
== pos
._y
&&
271 this._width
== pos
._width
&& this._height
== pos
._height
)
281 /// Returns a string that represents the element position data.
283 /// <returns>Element position data as a string.</returns>
284 internal override string ToStringInternal()
286 string posString
= Constants
.AutoValue
;
290 this._x
.ToString(System
.Globalization
.CultureInfo
.CurrentCulture
)+", "+
291 this._y
.ToString(System
.Globalization
.CultureInfo
.CurrentCulture
)+", "+
292 this._width
.ToString(System
.Globalization
.CultureInfo
.CurrentCulture
)+", "+
293 this._height
.ToString(System
.Globalization
.CultureInfo
.CurrentCulture
);
299 /// Set the element position without modifying the "Auto" property
301 /// <param name="x">X position.</param>
302 /// <param name="y">Y position.</param>
303 /// <param name="width">Width.</param>
304 /// <param name="height">Height.</param>
305 internal void SetPositionNoAuto(float x
, float y
, float width
, float height
)
307 bool oldValue
= this._auto
;
311 this._height
= height
;
312 this._auto
= oldValue
;
317 #region Element Position properties
320 /// X position of element.
323 SRCategory("CategoryAttributeMisc"),
326 SRDescription("DescriptionAttributeElementPosition_X"),
327 NotifyParentPropertyAttribute(true),
328 RefreshPropertiesAttribute(RefreshProperties
.All
),
329 #if !Microsoft_CONTROL
330 PersistenceMode(PersistenceMode
.Attribute
)
333 [System
.Diagnostics
.CodeAnalysis
.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId
= "X")]
342 if(value < 0.0 || value > 100.0)
344 throw(new ArgumentOutOfRangeException("value", SR
.ExceptionElementPositionArgumentOutOfRange
));
350 if( (_x
+ Width
) > 100)
360 /// Y position of element.
363 SRCategory("CategoryAttributeMisc"),
366 SRDescription("DescriptionAttributeElementPosition_Y"),
367 NotifyParentPropertyAttribute(true),
368 RefreshPropertiesAttribute(RefreshProperties
.All
),
369 #if !Microsoft_CONTROL
370 PersistenceMode(PersistenceMode
.Attribute
)
373 [System
.Diagnostics
.CodeAnalysis
.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId
= "Y")]
382 if(value < 0.0 || value > 100.0)
384 throw(new ArgumentOutOfRangeException("value", SR
.ExceptionElementPositionArgumentOutOfRange
));
390 if( (_y
+ Height
) > 100)
400 /// Width of element.
403 SRCategory("CategoryAttributeMisc"),
406 SRDescription("DescriptionAttributeElementPosition_Width"),
407 NotifyParentPropertyAttribute(true),
408 RefreshPropertiesAttribute(RefreshProperties
.All
),
409 #if !Microsoft_CONTROL
410 PersistenceMode(PersistenceMode
.Attribute
)
421 if(value < 0.0 || value > 100.0)
423 throw(new ArgumentOutOfRangeException("value", SR
.ExceptionElementPositionArgumentOutOfRange
));
429 if( (_x
+ Width
) > 100)
439 /// Height of element.
442 SRCategory("CategoryAttributeMisc"),
445 SRDescription("DescriptionAttributeElementPosition_Height"),
446 NotifyParentPropertyAttribute(true),
447 RefreshPropertiesAttribute(RefreshProperties
.All
),
448 #if !Microsoft_CONTROL
449 PersistenceMode(PersistenceMode
.Attribute
)
460 if(value < 0.0 || value > 100.0)
462 throw(new ArgumentOutOfRangeException("value", SR
.ExceptionElementPositionArgumentOutOfRange
));
468 if( (_y
+ Height
) > 100)
479 /// Gets or sets a flag which indicates whether positioning is on.
482 SRCategory("CategoryAttributeMisc"),
485 SRDescription("DescriptionAttributeElementPosition_Auto"),
486 NotifyParentPropertyAttribute(true),
487 RefreshPropertiesAttribute(RefreshProperties
.All
),
488 #if !Microsoft_CONTROL
489 PersistenceMode(PersistenceMode
.Attribute
)
502 ResetAllAreasAutoPosition(value);
522 /// Used for invoking windows forms MesageBox dialog.
524 internal interface IDesignerMessageBoxDialog
527 /// Shows Yes/No MessageBox.
529 /// <param name="message">The message.</param>
531 /// true if user confirms with Yes
533 bool ShowQuestion(string message
);