123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- //-------------------------------------------------------------
- // <copyright company=’Microsoft Corporation’>
- // Copyright © Microsoft Corporation. All Rights Reserved.
- // </copyright>
- //-------------------------------------------------------------
- // @owner=alexgor, deliant
- //=================================================================
- // File: AnnotationDesign.cs
- //
- // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting
- //
- // Classes: AnnotationCollectionEditor, AnchorPointUITypeEditor,
- // AnchorPointNameTreeView, AnchorPointValueConverter,
- // AnnotationAxisUITypeEditor, AnnotationAxisNameTreeView,
- // AnnotationAxisValueConverter
- //
- // Purpose: Annotation design-time support classes.
- //
- // Reviewed:
- //
- //===================================================================
- #region Used namespace
- using System;
- using System.Globalization;
- using System.Collections;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Drawing.Text;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using FastReport.Design;
- using FastReport.DataVisualization.Charting;
- using FastReport.DataVisualization.Charting.Data;
- using FastReport.DataVisualization.Charting.ChartTypes;
- using FastReport.DataVisualization.Charting.Utilities;
- using FastReport.DataVisualization.Charting.Borders3D;
- //using FastReport.DataVisualization.Charting.Design;
- #if VS_DESIGN_TIME
- using System.Web.UI.Design;
- using System.Web.UI.WebControls.Charting.Design;
- using System.Web.UI.WebControls.Charting.Data;
- using System.Web.UI.WebControls.Charting.Utilities;
- #endif
- #endregion
- #if WINFORMS_CONTROL
- namespace System.Windows.Forms.Charting.Design
- #else
- namespace System.Web.UI.WebControls.Charting.Design
- #endif
- {
- #if !SMART_CLIENT
- #if VS_DESIGN_TIME
- /// <summary>
- /// Designer editor for the Animation Collection collection.
- /// </summary>
- [
- SRDescription("DescriptionAttributeAnnotationCollectionEditor_AnnotationCollectionEditor")
- ]
- public class AnnotationCollectionEditor : ChartCollectionEditor
- {
- #region Methods
- /// <summary>
- /// Object constructor.
- /// </summary>
- public AnnotationCollectionEditor() : base(typeof(AnnotationCollection))
- {
- }
- /// <summary>
- /// Gets the data types that this collection editor can contain.
- /// </summary>
- /// <returns>An array of data types that this collection can contain.</returns>
- protected override Type[] CreateNewItemTypes()
- {
- return new Type[] {
- typeof(LineAnnotation),
- typeof(VerticalLineAnnotation),
- typeof(HorizontalLineAnnotation),
- typeof(TextAnnotation),
- typeof(RectangleAnnotation),
- typeof(EllipseAnnotation),
- typeof(ArrowAnnotation),
- typeof(Border3DAnnotation),
- typeof(CalloutAnnotation),
- typeof(PolylineAnnotation),
- typeof(PolygonAnnotation),
- typeof(ImageAnnotation),
- typeof(AnnotationGroup)
- };
- }
- /// <summary>
- /// Create annotation instance in the editor
- /// </summary>
- /// <param name="itemType">Item type.</param>
- /// <returns>Newly created item.</returns>
- protected override object CreateInstance(Type itemType)
- {
- Chart control = (Chart)GetChartReference(Context.Instance);
- // Call base class
- Annotation annotation = base.CreateInstance(itemType) as Annotation;
- // Generate unique name
- if(control != null)
- {
- control.Annotations.AssignUniqueName(annotation);
- }
- return annotation;
- }
- #endregion // Methods
- }
- /// <summary>
- /// UI type editor for the annotation anchor point
- /// </summary>
- public class AnchorPointUITypeEditor : System.Drawing.Design.UITypeEditor
- {
- #region Editor methods and properties
- /// <summary>
- /// Display a dropdown list with check boxes.
- /// </summary>
- /// <param name="context">Editing context.</param>
- /// <param name="provider">Provider.</param>
- /// <param name="value">Value to edit.</param>
- /// <returns>Result</returns>
- public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
- {
- if (context != null && context.Instance != null && provider != null)
- {
- IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
- if (edSvc != null &&
- context.Instance is Annotation)
- {
- // Create control for editing
- AnchorPointNameTreeView control = new AnchorPointNameTreeView(
- edSvc,
- (Annotation)context.Instance,
- value as DataPoint);
- // Show drop down control
- edSvc.DropDownControl(control);
- // Get new enumeration value
- value = control.GetNewValue();
- // Dispose control
- control.Dispose();
- }
- }
- return value;
- }
- /// <summary>
- /// Gets editing style.
- /// </summary>
- /// <param name="context">Editing context.</param>
- /// <returns>Editor style.</returns>
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- if (context != null && context.Instance != null)
- {
- return UITypeEditorEditStyle.DropDown;
- }
- return base.GetEditStyle(context);
- }
-
- #endregion
- }
- /// <summary>
- /// Anchor data points name tree view, which is used for the UI type editing.
- /// </summary>
- internal class AnchorPointNameTreeView : System.Windows.Forms.TreeView
- {
- #region Control fields
- // Annotation object to edit
- private Annotation annotation = null;
- private DataPoint dataPoint = null;
- IWindowsFormsEditorService edSvc = null;
- #endregion
- #region Control constructor
- /// <summary>
- /// Public constructor.
- /// </summary>
- /// <param name="edSvc">Editor service.</param>
- /// <param name="annotation">Annotation to edit.</param>
- /// <param name="dataPoint">Annotation anchor data point to edit.</param>
- public AnchorPointNameTreeView(
- IWindowsFormsEditorService edSvc,
- Annotation annotation,
- DataPoint dataPoint)
- {
- // Set editable value
- this.annotation = annotation;
- this.dataPoint = dataPoint;
- this.edSvc = edSvc;
- // Set control border style
- this.BorderStyle = System.Windows.Forms.BorderStyle.None;
- // Fill tree with data point names
- this.FillTree();
- }
- #endregion
- #region Control methods
- /// <summary>
- /// Fills data points name tree.
- /// </summary>
- private void FillTree()
- {
- bool nodeSelected = false;
- this.BeginUpdate();
- // Add "None" option
- System.Windows.Forms.TreeNode noPoint = this.Nodes.Add(Constants.NotSetValue);
- // Get chart object
- if(this.annotation != null &&
- annotation.GetAnnotationGroup() == null &&
- this.annotation.Chart != null)
- {
- Chart chart = this.annotation.Chart;
- // Loop through all series
- foreach(Series series in chart.Series)
- {
- System.Windows.Forms.TreeNode seriesNode = this.Nodes.Add(series.Name);
- seriesNode.Tag = series;
- // Indicate that there are no points in series
- if(series.Points.Count == 0)
- {
- System.Windows.Forms.TreeNode noPointNode = seriesNode.Nodes.Add("(empty)");
- }
- // Loop through all points
- int index = 1;
- foreach(DataPoint point in series.Points)
- {
- System.Windows.Forms.TreeNode dataPointNode = seriesNode.Nodes.Add("DataPoint" + index.ToString(CultureInfo.InvariantCulture));
- dataPointNode.Tag = point;
- ++index;
- // Check if this node should be selected
- if(point == dataPoint)
- {
- seriesNode.Expand();
- this.SelectedNode = dataPointNode;
- nodeSelected = true;
- }
- }
- }
- }
- // Select default node
- if(!nodeSelected)
- {
- this.SelectedNode = noPoint;
- }
- this.EndUpdate();
- }
- /// <summary>
- /// Gets new data point.
- /// </summary>
- /// <returns>New enum value.</returns>
- public DataPoint GetNewValue()
- {
- if(this.SelectedNode != null &&
- this.SelectedNode.Tag != null &&
- this.SelectedNode.Tag is DataPoint)
- {
- return (DataPoint)this.SelectedNode.Tag;
- }
- return null;
- }
- /// <summary>
- /// Mouse double clicked.
- /// </summary>
- protected override void OnDoubleClick(EventArgs e)
- {
- base.OnDoubleClick(e);
- if(this.edSvc != null)
- {
- if(GetNewValue() != null)
- {
- this.edSvc.CloseDropDown();
- }
- else if(this.SelectedNode != null &&
- this.SelectedNode.Text == Constants.NotSetValue)
- {
- this.edSvc.CloseDropDown();
- }
- }
- }
- #endregion
- }
- /// <summary>
- /// UI type editor for the annotation axes.
- /// </summary>
- public class AnnotationAxisUITypeEditor : System.Drawing.Design.UITypeEditor
- {
- #region Editor methods and properties
- /// <summary>
- /// Display a dropdown list with check boxes.
- /// </summary>
- /// <param name="context">Editing context.</param>
- /// <param name="provider">Provider.</param>
- /// <param name="value">Value to edit.</param>
- /// <returns>Result</returns>
- public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
- {
- if (context != null && context.Instance != null && provider != null)
- {
- IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
- if (edSvc != null &&
- context.Instance is Annotation)
- {
- // Check if we dealing with X or Y axis
- bool showXAxes = true;
- if(context.PropertyDescriptor != null &&
- context.PropertyDescriptor.Name == "AxisY")
- {
- showXAxes = false;
- }
- // Create control for editing
- AnnotationAxisNameTreeView control = new AnnotationAxisNameTreeView(
- edSvc,
- (Annotation)context.Instance,
- value as Axis,
- showXAxes);
- // Show drop down control
- edSvc.DropDownControl(control);
- // Get new enumeration value
- value = control.GetNewValue();
- // Dispose control
- control.Dispose();
- }
- }
- return value;
- }
- /// <summary>
- /// Gets editing style.
- /// </summary>
- /// <param name="context">Editing context.</param>
- /// <returns>Editor style.</returns>
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- if (context != null && context.Instance != null)
- {
- return UITypeEditorEditStyle.DropDown;
- }
- return base.GetEditStyle(context);
- }
-
- #endregion
- }
- /// <summary>
- /// Annotation axes names tree view, which is used for the UI type editing.
- /// </summary>
- internal class AnnotationAxisNameTreeView : System.Windows.Forms.TreeView
- {
- #region Control fields
- // Annotation object to edit
- private Annotation annotation = null;
- private Axis axis = null;
- IWindowsFormsEditorService edSvc = null;
- private bool showXAxes = true;
- #endregion
- #region Control constructor
- /// <summary>
- /// Public constructor.
- /// </summary>
- /// <param name="edSvc">Editor service.</param>
- /// <param name="annotation">Annotation to edit.</param>
- /// <param name="axis">Axis object.</param>
- /// <param name="showXAxes">Indicates if X or Y axis should be shown.</param>
- public AnnotationAxisNameTreeView(
- IWindowsFormsEditorService edSvc,
- Annotation annotation,
- Axis axis,
- bool showXAxes)
- {
- // Set editable value
- this.annotation = annotation;
- this.axis = axis;
- this.edSvc = edSvc;
- this.showXAxes = showXAxes;
- // Set control border style
- this.BorderStyle = System.Windows.Forms.BorderStyle.None;
- // Fill tree with data point names
- this.FillTree();
- }
- #endregion
- #region Control methods
- /// <summary>
- /// Fills data points name tree.
- /// </summary>
- private void FillTree()
- {
- bool nodeSelected = false;
- this.BeginUpdate();
- // Add "None" option
- System.Windows.Forms.TreeNode noPoint = this.Nodes.Add(Constants.NotSetValue);
- // Get chart object
- if(this.annotation != null &&
- annotation.GetAnnotationGroup() == null &&
- this.annotation.Chart != null)
- {
- Chart chart = this.annotation.Chart;
- // Loop through all chart areas
- foreach(ChartArea chartArea in chart.ChartAreas)
- {
- System.Windows.Forms.TreeNode areaNode = this.Nodes.Add(chartArea.Name);
- areaNode.Tag = chartArea;
- // Loop through all axes
- foreach(Axis curAxis in chartArea.Axes)
- {
- // Hide X or Y axes
- if(curAxis.Type == AxisName.Y || curAxis.Type == AxisName.Y2)
- {
- if(showXAxes)
- {
- continue;
- }
- }
- if(curAxis.Type == AxisName.X || curAxis.Type == AxisName.X2)
- {
- if(!showXAxes)
- {
- continue;
- }
- }
- // Create child node
- System.Windows.Forms.TreeNode axisNode = areaNode.Nodes.Add(curAxis.Name);
- axisNode.Tag = curAxis;
- // Check if this node should be selected
- if(axis == curAxis)
- {
- areaNode.Expand();
- this.SelectedNode = axisNode;
- nodeSelected = true;
- }
- }
- }
- }
- // Select default node
- if(!nodeSelected)
- {
- this.SelectedNode = noPoint;
- }
- this.EndUpdate();
- }
- /// <summary>
- /// Gets a new data point.
- /// </summary>
- /// <returns>New enum value.</returns>
- public Axis GetNewValue()
- {
- if(this.SelectedNode != null &&
- this.SelectedNode.Tag != null &&
- this.SelectedNode.Tag is Axis)
- {
- return (Axis)this.SelectedNode.Tag;
- }
- return null;
- }
- /// <summary>
- /// Mouse double clicked.
- /// </summary>
- protected override void OnDoubleClick(EventArgs e)
- {
- base.OnDoubleClick(e);
- if(this.edSvc != null)
- {
- if(GetNewValue() != null)
- {
- this.edSvc.CloseDropDown();
- }
- else if(this.SelectedNode != null &&
- this.SelectedNode.Text == Constants.NotSetValue)
- {
- this.edSvc.CloseDropDown();
- }
- }
- }
- #endregion
- }
- #endif // VS_DESIGN_TIME
- #endif // !SMART_CLIENT
- /// <summary>
- /// Converts anchor data point to string name.
- /// </summary>
- public class AnchorPointValueConverter : TypeConverter
- {
- #region Converter methods
- /// <summary>
- /// Converts anchor data point to string name.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Value to convert.</param>
- /// <param name="destinationType">Conversion destination type.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string))
- {
- if(value == null)
- {
- return Constants.NotSetValue;
- }
- else if(value is DataPoint)
- {
- DataPoint dataPoint = (DataPoint)value;
- if(dataPoint.series != null)
- {
- int pointIndex = dataPoint.series.Points.IndexOf(dataPoint) + 1;
- return dataPoint.series.Name + " - " + SR.DescriptionTypePoint + pointIndex.ToString(CultureInfo.InvariantCulture);
- }
- }
- }
- // Call base class
- return base.ConvertTo(context, culture, value, destinationType);
- }
- #endregion
- }
- /// <summary>
- /// Converts anchor data point to string name.
- /// </summary>
- public class AnnotationAxisValueConverter : TypeConverter
- {
- #region Converter methods
- /// <summary>
- /// Converts anchor data point to string name.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Value to convert.</param>
- /// <param name="destinationType">Conversion destination type.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string))
- {
- if(value == null)
- {
- return Constants.NotSetValue;
- }
- else if(value is Axis)
- {
- Axis axis = (Axis)value;
- if(axis.ChartArea != null)
- {
- return axis.ChartArea.Name + " - " + axis.Name;
- }
- }
- }
- // Call base class
- return base.ConvertTo(context, culture, value, destinationType);
- }
- #endregion
- }
- }
|