123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- // 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 support classes for Legend.
- //
- #if DESIGNER
- using System.ComponentModel;
- using FastReport.DataVisualization.Charting;
- namespace FastReport.Design.DataVisualization.Charting
- {
- /// <summary>
- /// Designer editor for the custom legend items collection.
- /// </summary>
- internal class LegendItemCollectionEditor : ChartCollectionEditor
- {
- #region Editor methods
- /// <summary>
- /// Object constructor.
- /// </summary>
- public LegendItemCollectionEditor() : base(typeof(LegendItemsCollection))
- {
- }
- /// <summary>
- /// Edit object's value.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="provider">Service provider.</param>
- /// <param name="value">Calue.</param>
- /// <returns>Object.</returns>
- public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
- {
- return base.EditValue(context, provider, value);
- }
- #endregion
- }
- /// <summary>
- /// Designer editor for the legend collection.
- /// </summary>
- internal class LegendCollectionEditor : ChartCollectionEditor
- {
- #region Editor methods
- /// <summary>
- /// Object constructor.
- /// </summary>
- public LegendCollectionEditor() : base(typeof(LegendCollection))
- {
- }
- /// <summary>
- /// Create series instance in the editor
- /// </summary>
- /// <param name="itemType">Item type.</param>
- /// <returns>Newly created item.</returns>
- protected override object CreateInstance(Type itemType)
- {
- if (Context != null && Context.Instance != null)
- {
- Chart control = (Chart)Context.Instance;
- // Create legend with unique name
- int countLegend = control.Legends.Count + 1;
- string legendName = "Legend" + countLegend.ToString(System.Globalization.CultureInfo.InvariantCulture);
- // Check if this name already in use
- bool legendFound = true;
- while(legendFound)
- {
- legendFound = false;
- foreach(Legend legend in control.Legends)
- {
- if(legend.Name == legendName)
- {
- legendFound = true;
- }
- }
- if(legendFound)
- {
- ++countLegend;
- legendName = "Legend" + countLegend.ToString(System.Globalization.CultureInfo.InvariantCulture);
- }
- }
- // Create new legend
- Legend newLegend = new Legend(legendName);
- return newLegend;
- }
- return base.CreateInstance(itemType);
- }
- #endregion
- }
- /// <summary>
- /// Designer editor for the legend column collection.
- /// </summary>
- internal class LegendCellColumnCollectionEditor : ChartCollectionEditor
- {
- #region Editor methods
- /// <summary>
- /// Object constructor.
- /// </summary>
- public LegendCellColumnCollectionEditor() : base(typeof(LegendCellColumnCollection))
- {
- }
- /// <summary>
- /// Create series instance in the editor
- /// </summary>
- /// <param name="itemType">Item type.</param>
- /// <returns>Newly created item.</returns>
- protected override object CreateInstance(Type itemType)
- {
- if (Context != null && Context.Instance != null)
- {
- Legend legend = Context.Instance as Legend;
- if(legend != null)
- {
- int itemCount = legend.CellColumns.Count + 1;
- string itemName = "Column" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
- // Check if this name already in use
- bool itemFound = true;
- while (itemFound)
- {
- itemFound = false;
- foreach (LegendCellColumn column in legend.CellColumns)
- {
- if (column.Name == itemName)
- {
- itemFound = true;
- }
- }
- if (itemFound)
- {
- ++itemCount;
- itemName = "Column" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
- }
- }
- // Create new legend column
- LegendCellColumn legendColumn = new LegendCellColumn();
- legendColumn.Name = itemName;
- return legendColumn;
- }
- }
- return base.CreateInstance(itemType);
- }
- #endregion
- }
- /// <summary>
- /// Designer editor for the legend cell collection.
- /// </summary>
- internal class LegendCellCollectionEditor : ChartCollectionEditor
- {
- #region Editor methods
- /// <summary>
- /// Object constructor.
- /// </summary>
- public LegendCellCollectionEditor() : base(typeof(LegendCellCollection))
- {
- }
- /// <summary>
- /// Create series instance in the editor
- /// </summary>
- /// <param name="itemType">Item type.</param>
- /// <returns>Newly created item.</returns>
- protected override object CreateInstance(Type itemType)
- {
- if (Context != null && Context.Instance != null)
- {
- LegendItem legendItem = Context.Instance as LegendItem;
- if(legendItem != null)
- {
- int itemCount = legendItem.Cells.Count + 1;
- string itemName = "Cell" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
- // Check if this name already in use
- bool itemFound = true;
- while (itemFound)
- {
- itemFound = false;
- foreach (LegendCell cell in legendItem.Cells)
- {
- if (cell.Name == itemName)
- {
- itemFound = true;
- }
- }
- if (itemFound)
- {
- ++itemCount;
- itemName = "Cell" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
- }
- }
- // Create new legend cell
- LegendCell legendCell = new LegendCell();
- legendCell.Name = itemName;
- return legendCell;
- }
- }
- return base.CreateInstance(itemType);
- }
- #endregion
- }
- }
- #endif
|