Browse Source

BaseClass for designers

reports
Peter Forstmeier 11 years ago
parent
commit
2b141af1be
  1. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj
  2. 159
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseLineItem.cs
  3. 33
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/AbstractDesigner.cs
  4. 241
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/LineDesigner.cs
  5. 39
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/TextItemDesigner.cs
  6. 12
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Toolbox/ToolboxProvider.cs
  7. 86
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj

@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="src\Commands\ViewCommands.cs" />
<Compile Include="src\DesignableItems\AbstractItem.cs" />
<Compile Include="src\DesignableItems\BaseLineItem.cs" />
<Compile Include="src\DesignableItems\BaseSection.cs" />
<Compile Include="src\DesignableItems\BaseTextItem.cs" />
<Compile Include="src\DesignableItems\ReportSettings.cs" />
@ -89,6 +90,8 @@ @@ -89,6 +90,8 @@
<Compile Include="src\DesignerBinding\InternalReportLoader.cs" />
<Compile Include="src\DesignerBinding\ReportDefinitionDeserializer.cs" />
<Compile Include="src\DesignerBinding\ReportDesignerLoader.cs" />
<Compile Include="src\Designer\AbstractDesigner.cs" />
<Compile Include="src\Designer\LineDesigner.cs" />
<Compile Include="src\Designer\ReportRootDesigner.cs" />
<Compile Include="src\Designer\ReportSettingsDesigner.cs" />
<Compile Include="src\Designer\RootReportModel.cs" />
@ -109,6 +112,7 @@ @@ -109,6 +112,7 @@
<Compile Include="src\Toolbox\SideTabItemDesigner.cs" />
<Compile Include="src\Toolbox\ToolboxProvider.cs" />
<Compile Include="src\TypeProvider\AbstractItemTypeProvider.cs" />
<Compile Include="src\TypeProvider\LineItemTypeProvider.cs" />
<Compile Include="src\TypeProvider\SectionItemTypeProvider.cs" />
<Compile Include="src\TypeProvider\TextItemTypeProvider.cs" />
<Compile Include="src\TypeProvider\TypeProviderHelper.cs" />

159
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseLineItem.cs

@ -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();
}
}
}
}

33
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/AbstractDesigner.cs

@ -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;}
}
}

241
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/LineDesigner.cs

@ -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);
}
}
}

39
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/TextItemDesigner.cs

@ -9,8 +9,7 @@ @@ -9,8 +9,7 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
using ICSharpCode.Reporting.Items;
using ICSharpCode.Reporting.Addin.DesignableItems;
using ICSharpCode.Reporting.Addin.TypeProvider;
@ -19,18 +18,17 @@ namespace ICSharpCode.Reporting.Addin.Designer @@ -19,18 +18,17 @@ namespace ICSharpCode.Reporting.Addin.Designer
/// <summary>
/// Description of TextItemDesigner.
/// </summary>
public class TextItemDesigner:ControlDesigner
public class TextItemDesigner:AbstractDesigner
{
ISelectionService selectionService;
IComponentChangeService componentChangeService;
ICSharpCode.Reporting.Addin.DesignableItems.BaseTextItem ctrl;
BaseTextItem ctrl;
public override void Initialize(IComponent component)
{
base.Initialize(component);
GetService();
ctrl = (ICSharpCode.Reporting.Addin.DesignableItems.BaseTextItem) component;
SelectionService.SelectionChanged += OnSelectionChanged;
ComponentChangeService.ComponentRename += OnComponentRename;
ctrl = (BaseTextItem) component;
}
protected override void PostFilterProperties(System.Collections.IDictionary properties)
@ -40,23 +38,6 @@ namespace ICSharpCode.Reporting.Addin.Designer @@ -40,23 +38,6 @@ namespace ICSharpCode.Reporting.Addin.Designer
}
void GetService ()
{
selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
if (selectionService != null)
{
selectionService.SelectionChanged += OnSelectionChanged;
}
componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
if (componentChangeService != null) {
componentChangeService.ComponentRename += OnComponentRename;
}
}
void OnSelectionChanged(object sender, EventArgs e)
{
Control.Invalidate( );
@ -121,12 +102,12 @@ namespace ICSharpCode.Reporting.Addin.Designer @@ -121,12 +102,12 @@ namespace ICSharpCode.Reporting.Addin.Designer
protected override void Dispose(bool disposing)
{
if (selectionService != null) {
selectionService.SelectionChanged -= OnSelectionChanged;
if (SelectionService != null) {
SelectionService.SelectionChanged -= OnSelectionChanged;
}
if (componentChangeService != null) {
componentChangeService.ComponentRename -= OnComponentRename;
if (ComponentChangeService != null) {
ComponentChangeService.ComponentRename -= OnComponentRename;
}
base.Dispose(disposing);
}

12
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Toolbox/ToolboxProvider.cs

@ -13,6 +13,7 @@ using ICSharpCode.Core; @@ -13,6 +13,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Widgets.SideBar;
using ICSharpCode.Reporting.Addin.DesignableItems;
namespace ICSharpCode.Reporting.Addin.Toolbox
{
@ -54,10 +55,19 @@ namespace ICSharpCode.Reporting.Addin.Toolbox @@ -54,10 +55,19 @@ namespace ICSharpCode.Reporting.Addin.Toolbox
sideTab.Items.Add(CreateToolboxPointer(sideTab));
// TextItem
var toolboxItem = new ToolboxItem(typeof(ICSharpCode.Reporting.Addin.DesignableItems.BaseTextItem)) {
var toolboxItem = new ToolboxItem(typeof(BaseTextItem)) {
DisplayName = ResourceService.GetString("SharpReport.Toolbar.TextBox"),
Bitmap = IconService.GetBitmap("Icons.16.16.SharpReport.Textbox")
};
sideTab.Items.Add(new SideTabItemDesigner(toolboxItem));
//Grahics
// Line
toolboxItem = new ToolboxItem(typeof(BaseLineItem)) {
DisplayName = ResourceService.GetString("SharpReport.Toolbar.Line"),
Bitmap = IconService.GetBitmap("Icons.16.16.SharpReport.Line")
};
sideTab.Items.Add(new SideTabItemDesigner(toolboxItem));
/*

86
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs

@ -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…
Cancel
Save