384 lines
10 KiB
C#
384 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.Design;
|
|
using System.Drawing;
|
|
using System.Reflection;
|
|
using System.Resources;
|
|
using System.Windows.Forms;
|
|
using DevComponents.Charts.Design.Properties;
|
|
using DevComponents.DotNetBar.Charts;
|
|
|
|
namespace DevComponents.Charts.Design
|
|
{
|
|
public class BaseCollectionEditor : CollectionEditor
|
|
{
|
|
#region Static variables
|
|
|
|
static Size _lastSize = Size.Empty;
|
|
static Point _lastLoc = Point.Empty;
|
|
|
|
#endregion
|
|
|
|
#region Private variables
|
|
|
|
private ListBox _ListBox;
|
|
private object _ChartItem;
|
|
private object _LastChartItem;
|
|
private PropertyGrid _PropertyGrid;
|
|
|
|
private Button _AddButton;
|
|
private Button _RemButton;
|
|
private Button _CopyButton;
|
|
private ToolTip _ToolTip;
|
|
|
|
private List<object> _RemovedItems;
|
|
|
|
private bool _EditCancelled;
|
|
private bool _ComponentChanged;
|
|
|
|
#endregion
|
|
|
|
private ChartControlDesigner _ControlDesigner;
|
|
|
|
public BaseCollectionEditor(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
#region Protected properties
|
|
|
|
protected Button AddButton
|
|
{
|
|
get { return (_AddButton); }
|
|
}
|
|
|
|
protected object ChartItem
|
|
{
|
|
get { return (_ChartItem); }
|
|
set { _ChartItem = value; }
|
|
}
|
|
|
|
protected bool ComponentChanged
|
|
{
|
|
get { return (_ComponentChanged); }
|
|
}
|
|
|
|
protected bool EditCancelled
|
|
{
|
|
get { return (_EditCancelled); }
|
|
}
|
|
|
|
protected ListBox ListBox
|
|
{
|
|
get { return (_ListBox); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private properties
|
|
|
|
#region RemovedItems
|
|
|
|
private List<object> RemovedItems
|
|
{
|
|
get
|
|
{
|
|
if (_RemovedItems == null)
|
|
_RemovedItems = new List<object>();
|
|
|
|
return (_RemovedItems);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region CreateCollectionForm
|
|
|
|
protected override CollectionForm CreateCollectionForm()
|
|
{
|
|
_EditCancelled = false;
|
|
|
|
CollectionForm collectionForm = base.CreateCollectionForm();
|
|
|
|
_ChartItem = null;
|
|
|
|
if (collectionForm.Controls[0] is TableLayoutPanel)
|
|
{
|
|
TableLayoutPanel tlpf = collectionForm.Controls["overArchingTableLayoutPanel"] as TableLayoutPanel;
|
|
|
|
if (tlpf != null)
|
|
{
|
|
TableLayoutPanel tlp2 = tlpf.Controls["addRemoveTableLayoutPanel"] as TableLayoutPanel;
|
|
|
|
if (tlp2 != null)
|
|
{
|
|
_RemButton = tlp2.Controls["removeButton"] as Button;
|
|
|
|
if (_RemButton != null)
|
|
_RemButton.Click += CollectionEditor_RemoveClick;
|
|
|
|
_AddButton = tlp2.Controls["addButton"] as Button;
|
|
|
|
if (_AddButton != null)
|
|
{
|
|
_AddButton.Click += CollectionEditor_AddClick;
|
|
|
|
AddCopyButton(collectionForm);
|
|
}
|
|
}
|
|
|
|
_ListBox = tlpf.Controls["listbox"] as ListBox;
|
|
|
|
if (_ListBox != null)
|
|
_ListBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
|
|
|
|
_PropertyGrid = tlpf.Controls["propertyBrowser"] as PropertyGrid;
|
|
|
|
if (_PropertyGrid != null)
|
|
_PropertyGrid.HelpVisible = true;
|
|
}
|
|
}
|
|
|
|
collectionForm.Load += CollectionFormLoad;
|
|
collectionForm.Resize += CollectionFormResize;
|
|
collectionForm.LocationChanged += CollectionFormLocationChanged;
|
|
|
|
return (collectionForm);
|
|
}
|
|
|
|
#region CollectionFormLoad
|
|
|
|
void CollectionFormLoad(object sender, EventArgs e)
|
|
{
|
|
CollectionForm form = sender as CollectionForm;
|
|
|
|
if (form != null)
|
|
{
|
|
if (_lastSize != Size.Empty)
|
|
form.Size = _lastSize;
|
|
|
|
if (_lastLoc != Point.Empty)
|
|
form.Location = _lastLoc;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CollectionFormResize
|
|
|
|
void CollectionFormResize(object sender, EventArgs e)
|
|
{
|
|
CollectionForm form = sender as CollectionForm;
|
|
|
|
if (form != null && form.Visible == true)
|
|
_lastSize = form.Size;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CollectionFormLocationChanged
|
|
|
|
void CollectionFormLocationChanged(object sender, EventArgs e)
|
|
{
|
|
CollectionForm form = sender as CollectionForm;
|
|
|
|
if (form != null && form.Visible == true)
|
|
_lastLoc = form.Location;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region AddCopyButton
|
|
|
|
private void AddCopyButton(CollectionForm collectionForm)
|
|
{
|
|
_CopyButton = new Button();
|
|
|
|
_CopyButton.Size = new Size(24, 24);
|
|
_CopyButton.Enabled = false;
|
|
_CopyButton.Click += CopyButton_Click;
|
|
|
|
ResourceManager rm = Resources.ResourceManager;
|
|
_CopyButton.Image = (Image)rm.GetObject("Copy");
|
|
|
|
collectionForm.Controls.Add(_CopyButton);
|
|
|
|
_CopyButton.Location = new Point(204, 85);
|
|
_CopyButton.BringToFront();
|
|
|
|
_ToolTip = new ToolTip();
|
|
_ToolTip.SetToolTip(_CopyButton, "Clone the selected item");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CopyButton_Click
|
|
|
|
protected virtual void CopyButton_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ListBox_SelectedIndexChanged
|
|
|
|
void ListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (_ListBox.SelectedItem != null)
|
|
{
|
|
PropertyInfo p = _ListBox.SelectedItem.GetType().GetProperty("Value");
|
|
|
|
_LastChartItem = _ChartItem;
|
|
_ChartItem = p.GetValue(_ListBox.SelectedItem, null);
|
|
|
|
_CopyButton.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
_CopyButton.Enabled = false;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CollectionEditor_AddClick
|
|
|
|
protected virtual void CollectionEditor_AddClick(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CollectionEditor_RemoveClick
|
|
|
|
protected virtual void CollectionEditor_RemoveClick(object sender, EventArgs e)
|
|
{
|
|
if (_LastChartItem != null)
|
|
{
|
|
RemovedItems.Add(_LastChartItem);
|
|
|
|
if (_LastChartItem is ChartVisualElement)
|
|
((ChartVisualElement)_LastChartItem).Visible = false;
|
|
|
|
else if (_LastChartItem is SeriesPoint)
|
|
((SeriesPoint)_LastChartItem).Visible = false;
|
|
|
|
_LastChartItem = null;
|
|
}
|
|
else if (_ChartItem != null)
|
|
{
|
|
RemovedItems.Add(_ChartItem);
|
|
|
|
if (_ChartItem is ChartVisualElement)
|
|
((ChartVisualElement)_ChartItem).Visible = false;
|
|
|
|
else if (_LastChartItem is SeriesPoint)
|
|
((SeriesPoint)_LastChartItem).Visible = false;
|
|
|
|
_ChartItem = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CancelChanges
|
|
|
|
protected override void CancelChanges()
|
|
{
|
|
_EditCancelled = true;
|
|
|
|
if (_RemovedItems != null)
|
|
{
|
|
foreach (object item in _RemovedItems)
|
|
{
|
|
if (item is ChartVisualElement)
|
|
((ChartVisualElement)item).Visible = true;
|
|
|
|
else if (item is SeriesPoint)
|
|
((SeriesPoint)item).Visible = true;
|
|
}
|
|
}
|
|
|
|
ChartVisualElement cve = _ChartItem as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
cve.InvalidateLayout();
|
|
|
|
base.CancelChanges();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BeforeEditValue
|
|
|
|
protected IComponentChangeService BeforeEditValue(ITypeDescriptorContext context)
|
|
{
|
|
ChartVisualElement cve = context.Instance as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
{
|
|
ISite site = cve.ChartControl.Site;
|
|
IComponentChangeService cs = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
|
|
|
|
if (cs != null)
|
|
cs.ComponentChanged += cs_ComponentChanged;
|
|
|
|
return (cs);
|
|
}
|
|
|
|
return (null);
|
|
}
|
|
|
|
void cs_ComponentChanged(object sender, ComponentChangedEventArgs e)
|
|
{
|
|
_ComponentChanged = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AfterEditValue
|
|
|
|
protected void AfterEditValue(ITypeDescriptorContext context, IComponentChangeService cs)
|
|
{
|
|
if (cs != null)
|
|
cs.ComponentChanged -= cs_ComponentChanged;
|
|
|
|
if (_ComponentChanged == true)
|
|
{
|
|
ChartContainer chCont = ((ChartVisualElement)context.Instance).ParentChartContainer;
|
|
|
|
if (chCont != null)
|
|
{
|
|
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(chCont);
|
|
PropertyDescriptor pd = pdc["Name"];
|
|
|
|
cs.OnComponentChanged(chCont, pd, null, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetDesigner
|
|
|
|
internal ChartControlDesigner GetDesigner(IComponent component)
|
|
{
|
|
if (_ControlDesigner == null)
|
|
{
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
|
|
_ControlDesigner = dh.GetDesigner(component) as ChartControlDesigner;
|
|
}
|
|
|
|
return (_ControlDesigner);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|