File: ElementPosition.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (535 lines) | stat: -rw-r--r-- 14,495 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
//-------------------------------------------------------------
// <copyright company=Microsoft Corporation>
//   Copyright  Microsoft Corporation. All Rights Reserved.
// </copyright>
//-------------------------------------------------------------
// @owner=alexgor, deliant
//=================================================================
//  File:		ElementPosition.cs
//
//  Namespace:	System.Web.UI.WebControls[Windows.Forms].Charting
//
//	Classes:	ElementPosition
//
//  Purpose:	Class is used to store relative position of the chart
//				elements like Legend, Title and others. It uses
//              relative coordinate system where top left corner is
//              0,0 and bottom right is 100,100.
//          
//              If Auto property is set to true, all position properties 
//              (X,Y,Width and Height) are ignored and they automatically
//              calculated during chart rendering.
//              
//              Note that setting any of the position properties will 
//              automatically set Auto property to false.
//
//	Reviewed:	AG - August 7, 2002
//              AG - Microsoft 5, 2007
//
//===================================================================


#region Used Namespaces

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.Drawing2D;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

#if Microsoft_CONTROL
	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;
#endif


#endregion

#if Microsoft_CONTROL
	namespace System.Windows.Forms.DataVisualization.Charting
#else
namespace System.Web.UI.DataVisualization.Charting

#endif
{
	/// <summary>
    /// ElementPosition is the base class for many chart visual 
    /// elements like Legend, Title and ChartArea. It provides 
    /// the position of the chart element in relative coordinates, 
    /// from (0,0) to (100,100).
	/// </summary>
	[
		SRDescription("DescriptionAttributeElementPosition_ElementPosition"),
		DefaultProperty("Data"),
	]
#if ASPPERM_35
	[AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
#endif
    public class ElementPosition : ChartElement
	{
		#region Fields

		// Private data members, which store properties values
		private		float	_x = 0;
		private		float	_y = 0;
		private		float	_width = 0;
		private		float	_height = 0;
		internal	bool	_auto = true;

		// Indicates the auto position of all areas must be reset
		internal	bool			resetAreaAutoPosition = false;

		#endregion

		#region Constructors

		/// <summary>
		/// ElementPosition default constructor
		/// </summary>
		public ElementPosition()
		{
		}

        /// <summary>
        /// ElementPosition default constructor
        /// </summary>
        internal ElementPosition(IChartElement parent) 
            : base(parent)
        {
        }


		/// <summary>
        /// ElementPosition constructor.
		/// </summary>
		/// <param name="x">X position.</param>
		/// <param name="y">Y position.</param>
		/// <param name="width">Width.</param>
		/// <param name="height">Height.</param>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
            Justification = "X and Y are cartesian coordinates and well understood")]       
		public ElementPosition(float x, float y, float width, float height)
		{
			this._auto = false;
			this._x = x;
			this._y = y;
			this._width = width;
			this._height = height;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Asks the user at design-time if he wants to change the Auto position
		/// of all areas at the same time.
		/// </summary>
		/// <param name="autoValue">Value to be set for the Auto property.</param>
		private void ResetAllAreasAutoPosition(bool autoValue)
		{
			if(resetAreaAutoPosition)
			{
				// Proceed only if at design time
				if(Chart != null && Chart.IsDesignMode() && !Chart.serializing && Chart.Site != null)
				{
					// Check if there is more than one area and Auto position set to the same value
					if(Chart.ChartAreas.Count > 1)
					{
						bool	firstAutoValue = Chart.ChartAreas[0].Position.Auto;
						bool	sameAutoValue = true;
						foreach(ChartArea area in Chart.ChartAreas)
						{
							if(area.Position.Auto != firstAutoValue)
							{
								sameAutoValue = false;
								break;
							}
						}

						// Proceed only all Auto values are the same
						if(sameAutoValue)
						{
                            string message = SR.MessageChangingChartAreaPositionProperty;
                            if (autoValue)
                            {
                                message += SR.MessageChangingChartAreaPositionConfirmAutomatic;
                            }
                            else
                            {
                                message += SR.MessageChangingChartAreaPositionConfirmCustom;
                            }

                            
                            IDesignerMessageBoxDialog confirm = Chart.Site.GetService(typeof(IDesignerMessageBoxDialog)) as IDesignerMessageBoxDialog;
                            if (confirm != null && confirm.ShowQuestion(message))
                            {
                                foreach (ChartArea area in Chart.ChartAreas)
                                {
                                    if (autoValue)
                                    {
                                        this.SetPositionNoAuto(0f, 0f, 0f, 0f);
                                    }
                                    area.Position._auto = autoValue;
                                }

                            }
						}
					}
				}
			}
		}

		/// <summary>
		/// Convert element position into RectangleF
		/// </summary>
		/// <returns>RectangleF structure.</returns>
		public RectangleF ToRectangleF()
		{
			return new RectangleF(_x, _y, _width, _height);
		}

		/// <summary>
        /// Initializes ElementPosition from RectangleF
		/// </summary>
        /// <param name="rect">RectangleF structure.</param>
		public void FromRectangleF(RectangleF rect)
		{
            if (rect == null)
                throw new ArgumentNullException("rect");

			this._x = rect.X;
			this._y = rect.Y;
			this._width = rect.Width;
			this._height = rect.Height;
			this._auto = false;
		}

		/// <summary>
        /// Gets the size of the ElementPosition object.
		/// </summary>
        /// <returns>The size of the ElementPosition object.</returns>
		[Browsable(false)]
        [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
        public SizeF Size
		{
            get { return new SizeF(this._width, this._height); }
		}

		/// <summary>
		/// Gets the bottom position in relative coordinates.
		/// </summary>
		/// <returns>Bottom position.</returns>
        [Browsable(false)]
        [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
        public float Bottom
		{
            get { return this._y + this._height; }
		}

		/// <summary>
		/// Gets the right position in relative coordinates.
		/// </summary>
		/// <returns>Right position.</returns>
        [Browsable(false)]
        [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
        public float Right
		{
			get{ return this._x + this._width; }
		}

        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
		internal override bool EqualsInternal(object obj)
		{
            ElementPosition pos = obj as ElementPosition;
			if(pos != null)
			{
				if(this._auto == true && this._auto == pos._auto)
				{
					return true;
				}
				else if(this._x == pos._x && this._y == pos._y &&
						this._width == pos._width && this._height == pos._height)
				{
					return true;
				}

			}
            return false;
		}

		/// <summary>
		/// Returns a string that represents the element position data.
		/// </summary>
		/// <returns>Element position data as a string.</returns>
		internal override string ToStringInternal()
		{
            string posString = Constants.AutoValue;
			if(!this._auto)
			{
				posString = 
					this._x.ToString(System.Globalization.CultureInfo.CurrentCulture)+", "+
					this._y.ToString(System.Globalization.CultureInfo.CurrentCulture)+", "+
					this._width.ToString(System.Globalization.CultureInfo.CurrentCulture)+", "+
					this._height.ToString(System.Globalization.CultureInfo.CurrentCulture);
			}
			return posString;
		}

		/// <summary>
		/// Set the element position without modifying the "Auto" property
		/// </summary>
		/// <param name="x">X position.</param>
		/// <param name="y">Y position.</param>
		/// <param name="width">Width.</param>
		/// <param name="height">Height.</param>
		internal void SetPositionNoAuto(float x, float y, float width, float height)
		{
			bool oldValue = this._auto;
			this._x = x;
			this._y = y;
			this._width = width;
			this._height = height;
			this._auto = oldValue;
		}

		#endregion

		#region Element Position properties

		/// <summary>
		/// X position of element.
		/// </summary>
		[
		SRCategory("CategoryAttributeMisc"),
		Bindable(true),
		DefaultValue(0.0F),
		SRDescription("DescriptionAttributeElementPosition_X"),
		NotifyParentPropertyAttribute(true),
		RefreshPropertiesAttribute(RefreshProperties.All),
		#if !Microsoft_CONTROL
		PersistenceMode(PersistenceMode.Attribute)
		#endif
		]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "X")]
		public float X
		{
			get
			{
				return _x;
			}
			set
			{
				if(value < 0.0 || value > 100.0)
				{
					throw(new ArgumentOutOfRangeException("value", SR.ExceptionElementPositionArgumentOutOfRange));
				}
				_x = value;
				Auto = false;

				// Adjust width
				if( (_x + Width) > 100)
				{
					Width = 100 - _x;
				}

				this.Invalidate();
			}
		}

		/// <summary>
		/// Y position of element.
		/// </summary>
		[
		SRCategory("CategoryAttributeMisc"),
		Bindable(true),
		DefaultValue(0.0F),
		SRDescription("DescriptionAttributeElementPosition_Y"),
		NotifyParentPropertyAttribute(true),
		RefreshPropertiesAttribute(RefreshProperties.All),
		#if !Microsoft_CONTROL
		PersistenceMode(PersistenceMode.Attribute)
		#endif
		]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Y")]
		public float Y
		{
			get
			{
				return _y;
			}
			set
			{
				if(value < 0.0 || value > 100.0)
				{
					throw(new ArgumentOutOfRangeException("value", SR.ExceptionElementPositionArgumentOutOfRange));
				}
				_y = value;
				Auto = false;

				// Adjust heigth
				if( (_y + Height) > 100)
				{
					Height = 100 - _y;
				}

				this.Invalidate();
			}
		}

		/// <summary>
		/// Width of element.
		/// </summary>
		[
		SRCategory("CategoryAttributeMisc"),
		Bindable(true),
		DefaultValue(0.0F),
		SRDescription("DescriptionAttributeElementPosition_Width"),
		NotifyParentPropertyAttribute(true),
		RefreshPropertiesAttribute(RefreshProperties.All),
		#if !Microsoft_CONTROL
		PersistenceMode(PersistenceMode.Attribute)
		#endif
		]
		public float Width
		{
			get
			{
				return _width;
			}
			set
			{
				if(value < 0.0 || value > 100.0)
				{
					throw(new ArgumentOutOfRangeException("value", SR.ExceptionElementPositionArgumentOutOfRange));
				}
				_width = value;
				Auto = false;

				// Adjust x
				if( (_x + Width) > 100)
				{
					_x = 100 - Width;
				}

				this.Invalidate();
			}
		}

		/// <summary>
		/// Height of element.
		/// </summary>
		[
		SRCategory("CategoryAttributeMisc"),
		Bindable(true),
		DefaultValue(0.0F),
		SRDescription("DescriptionAttributeElementPosition_Height"),
		NotifyParentPropertyAttribute(true),
		RefreshPropertiesAttribute(RefreshProperties.All),
		#if !Microsoft_CONTROL
		PersistenceMode(PersistenceMode.Attribute)
		#endif
		]
		public float Height
		{
			get
			{
				return _height;
			}
			set
			{
				if(value < 0.0 || value > 100.0)
				{
					throw(new ArgumentOutOfRangeException("value", SR.ExceptionElementPositionArgumentOutOfRange));
				}
				_height = value;
				Auto = false;

				// Adjust y
				if( (_y + Height) > 100)
				{
					_y = 100 - Height;

				}

				this.Invalidate();
			}
		}

        /// <summary>
        /// Gets or sets a flag which indicates whether positioning is on.
        /// </summary>
		[
		SRCategory("CategoryAttributeMisc"),
		Bindable(true),
		DefaultValue(true),
		SRDescription("DescriptionAttributeElementPosition_Auto"),
		NotifyParentPropertyAttribute(true),
		RefreshPropertiesAttribute(RefreshProperties.All),
		#if !Microsoft_CONTROL
		PersistenceMode(PersistenceMode.Attribute)
		#endif
		]
		public bool Auto
		{
			get
			{
				return _auto;
			}
			set
			{
				if(value != _auto)
				{
					ResetAllAreasAutoPosition(value);

					if(value)
					{
						this._x = 0;
						this._y = 0;
						this._width = 0;
						this._height = 0;
					}
					_auto = value;

					this.Invalidate();
				}
			}
		}

		#endregion
	}

    /// <summary>
    /// Used for invoking windows forms MesageBox dialog.
    /// </summary>
    internal interface IDesignerMessageBoxDialog
    {
        /// <summary>
        /// Shows Yes/No MessageBox.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>
        /// true if user confirms with Yes
        /// </returns>
        bool ShowQuestion(string message);
    }
}