7 changed files with 544 additions and 30 deletions
@ -0,0 +1,159 @@
@@ -0,0 +1,159 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 23.03.2014 |
||||
* Time: 17:54 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.Drawing.Drawing2D; |
||||
using ICSharpCode.Reporting.Addin.Designer; |
||||
using ICSharpCode.Reporting.Addin.TypeProvider; |
||||
|
||||
namespace ICSharpCode.Reporting.Addin.DesignableItems |
||||
{ |
||||
[Designer(typeof(LineDesigner))] |
||||
public class BaseLineItem:AbstractItem |
||||
{ |
||||
Point fromPoint; |
||||
Point toPoint; |
||||
LineCap startLineCap; |
||||
LineCap endLineCap; |
||||
DashCap dashLineCap; |
||||
DashStyle dashStyle; |
||||
float thickness; |
||||
|
||||
public BaseLineItem() |
||||
{ |
||||
this.thickness = 1; |
||||
this.dashStyle = DashStyle.Solid; |
||||
this.Size = new Size(50,10); |
||||
TypeDescriptor.AddProvider(new LineItemTypeProvider(), typeof(BaseLineItem)); |
||||
this.SetStartEndPoint(); |
||||
} |
||||
|
||||
void SetStartEndPoint () |
||||
{ |
||||
fromPoint = new Point(ClientRectangle.Left + 10,ClientRectangle.Height / 2); |
||||
toPoint = new Point(ClientRectangle.Left + ClientRectangle.Width - 10, |
||||
ClientRectangle.Height/ 2); |
||||
Invalidate(); |
||||
} |
||||
|
||||
|
||||
|
||||
// [System.ComponentModel.EditorBrowsableAttribute()]
|
||||
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) |
||||
{ |
||||
e.Graphics.SmoothingMode = SmoothingMode.HighQuality; |
||||
base.OnPaint(e); |
||||
Draw(e.Graphics); |
||||
} |
||||
|
||||
|
||||
public override void Draw(Graphics graphics) |
||||
{ |
||||
if (graphics == null) { |
||||
throw new ArgumentNullException("graphics"); |
||||
} |
||||
using (Pen p = new Pen(this.ForeColor,this.Thickness)) { |
||||
p.SetLineCap(this.StartLineCap,this.EndLineCap,this.DashLineCap); |
||||
graphics.DrawLine(p,this.fromPoint,this.toPoint); |
||||
} |
||||
} |
||||
|
||||
|
||||
public Point FromPoint { |
||||
get { return fromPoint; } |
||||
set { |
||||
Point x = value; |
||||
if (!this.ClientRectangle.Contains(x)) { |
||||
this.fromPoint = new Point(x.X - this.Location.X, |
||||
x.Y - this.Location.Y); |
||||
} else { |
||||
this.fromPoint = x; |
||||
} |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public Point ToPoint { |
||||
get { return toPoint; } |
||||
set { |
||||
Point x = value; |
||||
if (!ClientRectangle.Contains(x)) { |
||||
this.toPoint = new Point(x.X - this.Location.X, |
||||
x.Y - this.Location.Y); |
||||
} |
||||
else { |
||||
toPoint = x; |
||||
} |
||||
Invalidate(); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
// [Browsable(true),
|
||||
// Category("Appearance"),
|
||||
// Description("LineStyle")]
|
||||
public DashStyle DashStyle { |
||||
get { return dashStyle; } |
||||
set { |
||||
dashStyle = value; |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
|
||||
// [Browsable(true),
|
||||
// Category("Appearance"),
|
||||
// Description("Thickness of Line")]
|
||||
public float Thickness { |
||||
get { return thickness; } |
||||
set { |
||||
thickness = value; |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
// [Browsable(true),
|
||||
// Category("Appearance"),
|
||||
// Description("LineCap at Startposition")]
|
||||
public LineCap StartLineCap { |
||||
get { return startLineCap; } |
||||
set { |
||||
startLineCap = value; |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
// [Browsable(true),
|
||||
// Category("Appearance"),
|
||||
// Description("Linecap at Endposition")]
|
||||
public LineCap EndLineCap { |
||||
get { return endLineCap; } |
||||
set { |
||||
endLineCap = value; |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
// [Browsable(true),
|
||||
// Category("Appearance"),
|
||||
// Description("Dashlinecap")]
|
||||
public DashCap DashLineCap { |
||||
get { return dashLineCap; } |
||||
set { |
||||
dashLineCap = value; |
||||
this.Invalidate(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 23.03.2014 |
||||
* Time: 18:22 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.ComponentModel.Design; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
namespace ICSharpCode.Reporting.Addin.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of AbstractDesigner.
|
||||
/// </summary>
|
||||
public class AbstractDesigner:ControlDesigner |
||||
{ |
||||
|
||||
public override void Initialize(System.ComponentModel.IComponent component) |
||||
{ |
||||
base.Initialize(component); |
||||
SelectionService = GetService(typeof(ISelectionService)) as ISelectionService; |
||||
ComponentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); |
||||
} |
||||
|
||||
|
||||
protected ISelectionService SelectionService {get; private set;} |
||||
|
||||
protected IComponentChangeService ComponentChangeService {get;private set;} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
@@ -0,0 +1,241 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 23.03.2014 |
||||
* Time: 17:56 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.Reporting.Addin.DesignableItems; |
||||
using ICSharpCode.Reporting.Addin.TypeProvider; |
||||
|
||||
namespace ICSharpCode.Reporting.Addin.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of LineDesigner.
|
||||
/// </summary>
|
||||
public class LineDesigner:AbstractDesigner |
||||
{ |
||||
BaseLineItem baseLine; |
||||
bool dragging; |
||||
bool overToPoint; |
||||
bool overFromPoint; |
||||
|
||||
|
||||
public override void Initialize(IComponent component) |
||||
{ |
||||
if (component == null) { |
||||
throw new ArgumentNullException("component"); |
||||
} |
||||
base.Initialize(component); |
||||
baseLine = (BaseLineItem)component; |
||||
|
||||
ComponentChangeService.ComponentChanging += OnComponentChanging; |
||||
ComponentChangeService.ComponentChanged += OnComponentChanged; |
||||
ComponentChangeService.ComponentRename += OnComponentRename; |
||||
SelectionService.SelectionChanged += OnSelectionChanged; |
||||
} |
||||
|
||||
protected override void PostFilterProperties(System.Collections.IDictionary properties) |
||||
{ |
||||
TypeProviderHelper.RemoveProperties(properties); |
||||
base.PostFilterProperties(properties); |
||||
} |
||||
|
||||
|
||||
#region events
|
||||
|
||||
private void OnComponentChanging (object sender,ComponentChangingEventArgs e) |
||||
{ |
||||
// System.Console.WriteLine("changing");
|
||||
// System.Console.WriteLine("{0}",this.baseLine.ClientRectangle);
|
||||
Control.Invalidate( ); |
||||
} |
||||
|
||||
|
||||
void OnComponentChanged(object sender,ComponentChangedEventArgs e) |
||||
{ |
||||
Console.WriteLine("changed"); |
||||
Console.WriteLine("{0}",this.baseLine.ClientRectangle); |
||||
Control.Invalidate( ); |
||||
} |
||||
|
||||
|
||||
void OnComponentRename(object sender,ComponentRenameEventArgs e) { |
||||
if (e.Component == this.Component) { |
||||
Control.Name = e.NewName; |
||||
Control.Invalidate(); |
||||
Control.Invalidate( ); |
||||
} |
||||
} |
||||
|
||||
|
||||
void OnSelectionChanged(object sender, EventArgs e) |
||||
{ |
||||
Control.Invalidate( ); |
||||
} |
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnPaintAdornments(PaintEventArgs pe) |
||||
{ |
||||
var label = Control as BaseLineItem; |
||||
|
||||
if (SelectionService != null) |
||||
{ |
||||
if (SelectionService.GetComponentSelected(label)) |
||||
{ |
||||
// Paint grab handles.
|
||||
var grapRectangle = GetHandle(label.FromPoint); |
||||
ControlPaint.DrawGrabHandle(pe.Graphics, grapRectangle, true, true); |
||||
grapRectangle = GetHandle(label.ToPoint); |
||||
ControlPaint.DrawGrabHandle(pe.Graphics, grapRectangle, true, true); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
static Rectangle GetHandle(Point pt) |
||||
{ |
||||
var handle = new Rectangle(pt, new Size(7, 7)); |
||||
handle.Offset(-3, -3); |
||||
return handle; |
||||
} |
||||
|
||||
|
||||
protected override void OnSetCursor( ) |
||||
{ |
||||
// Get mouse cursor position relative to
|
||||
// the control's coordinate space.
|
||||
|
||||
var label = (BaseLineItem) Control; |
||||
var p = label.PointToClient(Cursor.Position); |
||||
|
||||
// Display a resize cursor if the mouse is
|
||||
// over a grab handle; otherwise show a
|
||||
// normal arrow.
|
||||
if (GetHandle(label.FromPoint).Contains(p) || |
||||
GetHandle(label.ToPoint).Contains(p)) |
||||
{ |
||||
Cursor.Current = Cursors.SizeAll; |
||||
} |
||||
else |
||||
{ |
||||
Cursor.Current = Cursors.Default; |
||||
} |
||||
} |
||||
|
||||
|
||||
#region Drag handling state and methods
|
||||
|
||||
protected override void OnMouseDragBegin(int x, int y) |
||||
{ |
||||
System.Console.WriteLine("DragBegib"); |
||||
Point p = this.baseLine.PointToClient(new Point(x, y)); |
||||
overFromPoint = GetHandle(this.baseLine.FromPoint).Contains(p); |
||||
this.overToPoint = GetHandle(this.baseLine.ToPoint).Contains(p); |
||||
if (overFromPoint || overToPoint ) |
||||
{ |
||||
dragging = true; |
||||
// PropertyDescriptor pd =
|
||||
// TypeDescriptor.GetProperties(this.baseLine)["FromPoint"];
|
||||
// pd.SetValue(this.baseLine, p);
|
||||
// dragDirection = overToPoint;
|
||||
// Point current = dragDirection ?
|
||||
// (label.Origin + label.Direction) :
|
||||
// label.Origin;
|
||||
// dragOffset = current - new Size(p);
|
||||
} |
||||
else |
||||
{ |
||||
dragging = false; |
||||
base.OnMouseDragBegin(x, y); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected override void OnMouseDragMove(int x, int y) |
||||
{ |
||||
if (dragging) |
||||
{ |
||||
Point p = this.baseLine.PointToClient(new Point(x, y)); |
||||
if (this.overToPoint) { |
||||
this.baseLine.ToPoint = p; |
||||
} else { |
||||
this.baseLine.FromPoint = p; |
||||
} |
||||
|
||||
// this.baseLine.Invalidate();
|
||||
// this.dragOffset = p;
|
||||
} |
||||
else |
||||
{ |
||||
base.OnMouseDragMove(x, y); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected override void OnMouseDragEnd(bool cancel) |
||||
{ |
||||
if (dragging) |
||||
{ |
||||
// Update property via PropertyDescriptor to
|
||||
// make sure that VS.NET notices.
|
||||
|
||||
// PropertyDescriptor pd =
|
||||
// TypeDescriptor.GetProperties(this.baseLine)["ToPoint"];
|
||||
// pd.SetValue(this.baseLine, this.dragOffset);
|
||||
/* |
||||
DirectionalLabel label = (DirectionalLabel) Control; |
||||
if (dragDirection) |
||||
{ |
||||
Size d = label.Direction; |
||||
PropertyDescriptor pd = |
||||
TypeDescriptor.GetProperties(label)["Direction"]; |
||||
pd.SetValue(label, d); |
||||
} |
||||
else |
||||
{ |
||||
Point o = label.Origin; |
||||
PropertyDescriptor pd = |
||||
TypeDescriptor.GetProperties(label)["Origin"]; |
||||
pd.SetValue(label, o); |
||||
} |
||||
*/ |
||||
dragging = false; |
||||
this.baseLine.Invalidate(); |
||||
} |
||||
|
||||
// Always call base class.
|
||||
base.OnMouseDragEnd(cancel); |
||||
|
||||
} |
||||
//
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
|
||||
if (ComponentChangeService != null) { |
||||
ComponentChangeService.ComponentChanging -= OnComponentChanging; |
||||
ComponentChangeService.ComponentChanged -= OnComponentChanged; |
||||
ComponentChangeService.ComponentRename -= OnComponentRename; |
||||
} |
||||
if (SelectionService != null) { |
||||
SelectionService.SelectionChanged -= OnSelectionChanged; |
||||
} |
||||
|
||||
base.Dispose(disposing); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 23.03.2014 |
||||
* Time: 18:02 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using ICSharpCode.Reporting.Addin.DesignableItems; |
||||
|
||||
namespace ICSharpCode.Reporting.Addin.TypeProvider |
||||
{ |
||||
/// <summary>
|
||||
/// Description of LineItemTypeProvider.
|
||||
/// </summary>
|
||||
class LineItemTypeProvider : TypeDescriptionProvider |
||||
{ |
||||
public LineItemTypeProvider() : base(TypeDescriptor.GetProvider(typeof(AbstractItem))) |
||||
{ |
||||
} |
||||
|
||||
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) |
||||
{ |
||||
ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); |
||||
return new LineItemTypeDescriptor(td, instance); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
class LineItemTypeDescriptor : CustomTypeDescriptor |
||||
{ |
||||
|
||||
|
||||
public LineItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) |
||||
: base(parent) |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
public override PropertyDescriptorCollection GetProperties() |
||||
{ |
||||
return GetProperties(null); |
||||
} |
||||
|
||||
|
||||
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) |
||||
{ |
||||
PropertyDescriptorCollection props = base.GetProperties(attributes); |
||||
List<PropertyDescriptor> allProperties = new List<PropertyDescriptor>(); |
||||
|
||||
TypeProviderHelper.AddDefaultProperties(allProperties,props); |
||||
|
||||
PropertyDescriptor prop = null; |
||||
prop = props.Find("ForeColor",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("FromPoint",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("ToPoint",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("StartLineCap",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("EndLineCap",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("dashLineCap",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("DashStyle",true); |
||||
allProperties.Add(prop); |
||||
|
||||
prop = props.Find("Thickness",true); |
||||
allProperties.Add(prop); |
||||
|
||||
return new PropertyDescriptorCollection(allProperties.ToArray()); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue