233 lines
5.9 KiB
C#
233 lines
5.9 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.Design;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using DevComponents.DotNetBar.SuperGrid;
|
|
|
|
namespace DevComponents.SuperGrid.Design
|
|
{
|
|
/// <summary>
|
|
/// ColumnGroupHeaderCollectionEditor
|
|
/// </summary>
|
|
public class ColumnGroupHeaderCollectionEditor : CollectionEditor
|
|
{
|
|
#region Static variables
|
|
|
|
static Size _lastSize = Size.Empty;
|
|
static Point _lastLoc = Point.Empty;
|
|
|
|
#endregion
|
|
|
|
public ColumnGroupHeaderCollectionEditor(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
#region CreateCollectionForm
|
|
|
|
protected override CollectionForm CreateCollectionForm()
|
|
{
|
|
CollectionForm collectionForm = base.CreateCollectionForm();
|
|
|
|
if (collectionForm.Controls[0] is TableLayoutPanel)
|
|
{
|
|
TableLayoutPanel tlpf =
|
|
collectionForm.Controls["overArchingTableLayoutPanel"] as TableLayoutPanel;
|
|
|
|
if (tlpf != null)
|
|
{
|
|
PropertyGrid propertyGrid =
|
|
tlpf.Controls["propertyBrowser"] as PropertyGrid;
|
|
|
|
if (propertyGrid != null)
|
|
{
|
|
propertyGrid.HelpVisible = true;
|
|
|
|
propertyGrid.GotFocus += PropertyGridGotFocus;
|
|
propertyGrid.SelectedObjectsChanged += PropertyGridSelectedObjectsChanged;
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
#region PropertyGridGotFocus
|
|
|
|
void PropertyGridGotFocus(object sender, EventArgs e)
|
|
{
|
|
PropertyGrid propertyGrid = sender as PropertyGrid;
|
|
|
|
if (propertyGrid != null)
|
|
UpdateDesignerFocus(propertyGrid);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PropertyGridSelectedObjectsChanged
|
|
|
|
void PropertyGridSelectedObjectsChanged(object sender, EventArgs e)
|
|
{
|
|
PropertyGrid propertyGrid = sender as PropertyGrid;
|
|
|
|
if (propertyGrid != null)
|
|
UpdateDesignerFocus(propertyGrid);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateDesignerFocus
|
|
|
|
private void UpdateDesignerFocus(PropertyGrid propertyGrid)
|
|
{
|
|
GridContainer row = Context.Instance as GridContainer;
|
|
|
|
if (row != null)
|
|
{
|
|
GridElement item = propertyGrid.SelectedObject as GridElement;
|
|
|
|
if (item != null)
|
|
row.SuperGrid.DesignerElement = item;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region CreateCollectionItemType
|
|
|
|
protected override Type CreateCollectionItemType()
|
|
{
|
|
return typeof(ColumnGroupHeader);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateNewItemTypes
|
|
|
|
protected override Type[] CreateNewItemTypes()
|
|
{
|
|
return new Type[]
|
|
{
|
|
typeof(ColumnGroupHeader),
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region EditValue
|
|
|
|
public override object EditValue(
|
|
ITypeDescriptorContext context, IServiceProvider provider, object value)
|
|
{
|
|
object o = base.EditValue(context, provider, value);
|
|
|
|
return (o);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateInstance
|
|
|
|
protected override object CreateInstance(Type itemType)
|
|
{
|
|
ColumnGroupHeader item =
|
|
(ColumnGroupHeader) base.CreateInstance(typeof (ColumnGroupHeader));
|
|
|
|
if (item != null)
|
|
{
|
|
GridColumnHeader gch = Context.Instance as GridColumnHeader;
|
|
|
|
if (gch != null)
|
|
{
|
|
item.Name = GetGroupHeaderName(gch.GroupHeaders);
|
|
}
|
|
else
|
|
{
|
|
ColumnGroupHeader csh = Context.Instance as ColumnGroupHeader;
|
|
|
|
if (csh != null)
|
|
{
|
|
item.Name = GetGroupHeaderName(csh.GroupHeaders);
|
|
|
|
item.StartDisplayIndex = csh.StartDisplayIndex;
|
|
item.EndDisplayIndex = csh.EndDisplayIndex;
|
|
|
|
item.ShowColumnHeaders = csh.ShowColumnHeaders;
|
|
}
|
|
}
|
|
}
|
|
|
|
return (item);
|
|
}
|
|
|
|
#region GetGroupHeaderName
|
|
|
|
private string GetGroupHeaderName(ColumnGroupHeaderCollection csc)
|
|
{
|
|
for (int i = 1; i < 200; i++)
|
|
{
|
|
string s = "GroupHeader" + i;
|
|
|
|
if (csc[s] == null)
|
|
return (s);
|
|
}
|
|
|
|
return ("");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|