123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- //
- // Purpose: Design-time UI editor for Annotations.
- //
- #if DESIGNER
- using System.ComponentModel;
- using System.Drawing.Design;
- using System.Globalization;
- using FastReport.DataVisualization.Charting;
- namespace FastReport.Design.DataVisualization.Charting
- {
- /// <summary>
- /// Designer editor for the Annotation Collection.
- /// </summary>
- internal 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)
- {
- annotation.Name = NextUniqueName(control, itemType);
- }
- return annotation;
- }
- /// <summary>
- /// Finds the unique name for a new annotation being added to the collection
- /// </summary>
- /// <param name="control">Chart control reference.</param>
- /// <param name="type">Type of the annotation added.</param>
- /// <returns>Next unique chart annotation name</returns>
- private static string NextUniqueName(Chart control, Type type)
- {
- // Find unique name
- string result = string.Empty;
- string prefix = type.Name;
- for (int i = 1; i < System.Int32.MaxValue; i++)
- {
- result = prefix + i.ToString(CultureInfo.InvariantCulture);
- // Check whether the name is unique
- if (control.Annotations.IsUniqueName(result))
- {
- break;
- }
- }
- return result;
- }
- #endregion // Methods
- }
- /// <summary>
- /// UI type editor for the annotation anchor point
- /// </summary>
- internal class AnchorPointUITypeEditor : System.Drawing.Design.UITypeEditor
- {
- #region Editor methods and properties
- /// <summary>
- /// Display a drop down 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 : 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 = 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
- TreeNode noPoint = this.Nodes.Add("NotSet");
- // Get chart object
- if (this._annotation != null &&
- _annotation.AnnotationGroup == null &&
- this._annotation.Chart != null)
- {
- Chart chart = this._annotation.Chart;
- // Loop through all series
- foreach (Series series in chart.Series)
- {
- TreeNode seriesNode = this.Nodes.Add(series.Name);
- seriesNode.Tag = series;
- // Indicate that there are no points in series
- if (series.Points.Count == 0)
- {
- seriesNode.Nodes.Add("(empty)");
- }
- // Loop through all points
- int index = 1;
- foreach (DataPoint point in series.Points)
- {
- TreeNode dataPointNode = seriesNode.Nodes.Add("DataPoint" + index.ToString(System.Globalization.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 == "NotSet")
- {
- this._edSvc.CloseDropDown();
- }
- }
- }
- #endregion
- }
- /// <summary>
- /// UI type editor for the annotation axes.
- /// </summary>
- internal class AnnotationAxisUITypeEditor : System.Drawing.Design.UITypeEditor
- {
- #region Editor methods and properties
- /// <summary>
- /// Display a drop down 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 : 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 = 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
- TreeNode noPoint = this.Nodes.Add("NotSet");
- // Get chart object
- if (this._annotation != null &&
- _annotation.AnnotationGroup == null &&
- this._annotation.Chart != null)
- {
- Chart chart = this._annotation.Chart;
- // Loop through all chart areas
- foreach (ChartArea chartArea in chart.ChartAreas)
- {
- 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.AxisName == AxisName.Y || curAxis.AxisName == AxisName.Y2)
- {
- if (_showXAxes)
- {
- continue;
- }
- }
- if (curAxis.AxisName == AxisName.X || curAxis.AxisName == AxisName.X2)
- {
- if (!_showXAxes)
- {
- continue;
- }
- }
- // Create child node
- 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 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 == "NotSet")
- {
- this._edSvc.CloseDropDown();
- }
- }
- }
- #endregion
- }
- }
- #endif
|