223 lines
9.5 KiB
C#
223 lines
9.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.ComponentModel.Design;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
|
|
namespace DevComponents.DotNetBar.Layout.Design
|
|
{
|
|
public class LayoutGroupDesigner : LayoutItemBaseDesigner
|
|
{
|
|
#region Constructor
|
|
|
|
#endregion
|
|
|
|
#region Implementation
|
|
|
|
public override System.Collections.ICollection AssociatedComponents
|
|
{
|
|
get
|
|
{
|
|
LayoutGroup group = (LayoutGroup)this.Component;
|
|
|
|
if (group.Items.Count>0)
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
foreach (LayoutItemBase child in group.Items)
|
|
{
|
|
if (child.Site != null)
|
|
list.Add(child);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
return base.AssociatedComponents;
|
|
}
|
|
}
|
|
|
|
public override DesignerVerbCollection Verbs
|
|
{
|
|
get
|
|
{
|
|
DesignerVerb[] verbs;
|
|
verbs = new DesignerVerb[]
|
|
{
|
|
new DesignerVerb("Add Spacer", new EventHandler(AddSpacerItem)),
|
|
new DesignerVerb("Add Group", new EventHandler(AddGroupItem)),
|
|
new DesignerVerb("Apply Panel Style", new EventHandler(PanelStyle)),
|
|
new DesignerVerb("Apply Group Panel Style", new EventHandler(GroupPanelStyle)),
|
|
new DesignerVerb("Remove Panel Style", new EventHandler(RemovePanelStyle))
|
|
};
|
|
return new DesignerVerbCollection(verbs);
|
|
}
|
|
}
|
|
private void AddSpacerItem(object sender, EventArgs e)
|
|
{
|
|
AddSpacerItem();
|
|
}
|
|
|
|
private void AddSpacerItem()
|
|
{
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
LayoutGroup lc = this.Component as LayoutGroup;
|
|
if (lc == null || dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction("Creating Spacer Item");
|
|
try
|
|
{
|
|
IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
|
|
if (cc != null)
|
|
{
|
|
cc.OnComponentChanging(this.Component, null);
|
|
cc.OnComponentChanging(lc, TypeDescriptor.GetProperties(lc)["Items"]);
|
|
}
|
|
|
|
LayoutSpacerItem item = null;
|
|
item = dh.CreateComponent(typeof(LayoutSpacerItem)) as LayoutSpacerItem;
|
|
item.Width = 32;
|
|
item.Height = 32;
|
|
lc.Items.Add(item);
|
|
lc.InvalidateLayout();
|
|
if (cc != null)
|
|
{
|
|
cc.OnComponentChanged(lc, TypeDescriptor.GetProperties(lc)["Items"], null, null);
|
|
cc.OnComponentChanged(this.Component, null, null, null);
|
|
}
|
|
|
|
SelectComponent(item, SelectionTypes.Replace);
|
|
}
|
|
catch
|
|
{
|
|
dt.Cancel();
|
|
}
|
|
finally
|
|
{
|
|
if (!dt.Canceled) dt.Commit();
|
|
}
|
|
}
|
|
|
|
private void AddGroupItem(object sender, EventArgs e)
|
|
{
|
|
AddGroupItem();
|
|
}
|
|
|
|
private void AddGroupItem()
|
|
{
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
LayoutGroup lc = this.Component as LayoutGroup;
|
|
if (lc == null || dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction("Creating Group Item");
|
|
try
|
|
{
|
|
IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
|
|
if (cc != null)
|
|
{
|
|
cc.OnComponentChanging(this.Component, null);
|
|
cc.OnComponentChanging(lc, TypeDescriptor.GetProperties(lc)["Items"]);
|
|
}
|
|
|
|
LayoutGroup item = null;
|
|
item = dh.CreateComponent(typeof(LayoutGroup)) as LayoutGroup;
|
|
item.Width = 200;
|
|
item.Height = 100;
|
|
item.TextPosition = eLayoutPosition.Top;
|
|
item.MinSize = new Size(120, 32);
|
|
lc.Items.Add(item);
|
|
lc.InvalidateLayout();
|
|
if (cc != null)
|
|
{
|
|
cc.OnComponentChanged(lc, TypeDescriptor.GetProperties(lc)["Items"], null, null);
|
|
cc.OnComponentChanged(this.Component, null, null, null);
|
|
}
|
|
|
|
SelectComponent(item, SelectionTypes.Replace);
|
|
}
|
|
catch
|
|
{
|
|
dt.Cancel();
|
|
}
|
|
finally
|
|
{
|
|
if (!dt.Canceled) dt.Commit();
|
|
}
|
|
}
|
|
|
|
private void PanelStyle(object sender, EventArgs e)
|
|
{
|
|
LayoutGroup group = (LayoutGroup)this.Component;
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
if (group == null || dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction("Apply Panel Style");
|
|
|
|
TypeDescriptor.GetProperties(group)["Appearance"].SetValue(group, eGroupAppearance.Panel); // group.Appearance = eGroupAppearance.Panel;
|
|
TypeDescriptor.GetProperties(group)["CaptionHeight"].SetValue(group, 22); // group.CaptionHeight = 22;
|
|
TypeDescriptor.GetProperties(group)["TextLineAlignment"].SetValue(group, DevComponents.DotNetBar.Layout.eTextLineAlignment.Middle); // group.TextLineAlignment = DevComponents.DotNetBar.Layout.eTextLineAlignment.Middle;
|
|
TypeDescriptor.GetProperties(group)["TextPosition"].SetValue(group, DevComponents.DotNetBar.Layout.eLayoutPosition.Top); // group.TextPosition = DevComponents.DotNetBar.Layout.eLayoutPosition.Top;
|
|
TypeDescriptor.GetProperties(group)["TextAlignment"].SetValue(group, eTextAlignment.Default); // group.TextAlignment = eTextAlignment.Default;
|
|
if (string.IsNullOrEmpty(group.Text))
|
|
TypeDescriptor.GetProperties(group)["Text"].SetValue(group, "Caption"); // group.Text = "Caption";
|
|
|
|
dt.Commit();
|
|
|
|
}
|
|
|
|
private void GroupPanelStyle(object sender, EventArgs e)
|
|
{
|
|
LayoutGroup group = (LayoutGroup)this.Component;
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
if (group == null || dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction("Apply Group Panel Style");
|
|
|
|
TypeDescriptor.GetProperties(group)["Appearance"].SetValue(group, eGroupAppearance.GroupPanel); // group.Appearance = eGroupAppearance.GroupPanel;
|
|
TypeDescriptor.GetProperties(group)["CaptionHeight"].SetValue(group, 18); // group.CaptionHeight = 18;
|
|
TypeDescriptor.GetProperties(group)["TextLineAlignment"].SetValue(group, DevComponents.DotNetBar.Layout.eTextLineAlignment.Middle); // group.TextLineAlignment = DevComponents.DotNetBar.Layout.eTextLineAlignment.Middle;
|
|
TypeDescriptor.GetProperties(group)["TextPosition"].SetValue(group, DevComponents.DotNetBar.Layout.eLayoutPosition.Top); // group.TextPosition = DevComponents.DotNetBar.Layout.eLayoutPosition.Top;
|
|
TypeDescriptor.GetProperties(group)["TextAlignment"].SetValue(group, eTextAlignment.Center); // group.TextAlignment = eTextAlignment.Center;
|
|
if (string.IsNullOrEmpty(group.Text))
|
|
TypeDescriptor.GetProperties(group)["Text"].SetValue(group, "Caption"); // group.Text = "Caption";
|
|
|
|
dt.Commit();
|
|
}
|
|
|
|
private void RemovePanelStyle(object sender, EventArgs e)
|
|
{
|
|
LayoutGroup group = (LayoutGroup)this.Component;
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
if (group == null || dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction("Remove Panel Style");
|
|
|
|
TypeDescriptor.GetProperties(group)["Appearance"].SetValue(group, eGroupAppearance.None); // group.Appearance = eGroupAppearance.None;
|
|
TypeDescriptor.GetProperties(group)["TextLineAlignment"].SetValue(group, DevComponents.DotNetBar.Layout.eTextLineAlignment.Default); // group.TextLineAlignment = DevComponents.DotNetBar.Layout.eTextLineAlignment.Default;
|
|
TypeDescriptor.GetProperties(group)["CaptionHeight"].SetValue(group, 0); // group.CaptionHeight = 0;
|
|
TypeDescriptor.GetProperties(group)["TextPosition"].SetValue(group, DevComponents.DotNetBar.Layout.eLayoutPosition.Default); // group.TextPosition = DevComponents.DotNetBar.Layout.eLayoutPosition.Default;
|
|
TypeDescriptor.GetProperties(group)["TextAlignment"].SetValue(group, eTextAlignment.Default); // group.TextAlignment = eTextAlignment.Default;
|
|
TypeDescriptor.GetProperties(group)["Text"].SetValue(group, ""); // group.Text = "Caption";
|
|
dt.Commit();
|
|
|
|
}
|
|
|
|
protected virtual void SelectComponent(IComponent comp, SelectionTypes selectionType)
|
|
{
|
|
ISelectionService selection = (ISelectionService)this.GetService(typeof(ISelectionService));
|
|
if (selection != null && comp != null)
|
|
{
|
|
ArrayList arr = new ArrayList(1);
|
|
arr.Add(comp);
|
|
selection.SetSelectedComponents(arr, selectionType);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|