16 changed files with 651 additions and 55 deletions
@ -0,0 +1,183 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.03.2014 |
||||||
|
* Time: 20:30 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Drawing; |
||||||
|
using ICSharpCode.Reporting.BaseClasses; |
||||||
|
using ICSharpCode.Reporting.Globals; |
||||||
|
using ICSharpCode.Reporting.Addin.Designer; |
||||||
|
using ICSharpCode.Reporting.Addin.TypeProvider; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.DesignableItems |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of BaseTextItem.
|
||||||
|
/// </summary>
|
||||||
|
[Designer(typeof(TextItemDesigner))] |
||||||
|
public class BaseTextItem:AbstractItem |
||||||
|
{ |
||||||
|
|
||||||
|
string formatString; |
||||||
|
StringFormat stringFormat; |
||||||
|
StringTrimming stringTrimming; |
||||||
|
ContentAlignment contentAlignment; |
||||||
|
|
||||||
|
|
||||||
|
public BaseTextItem():base() |
||||||
|
{ |
||||||
|
DefaultSize = GlobalValues.PreferedSize; |
||||||
|
Size = GlobalValues.PreferedSize; |
||||||
|
BackColor = Color.White; |
||||||
|
contentAlignment = ContentAlignment.TopLeft; |
||||||
|
TypeDescriptor.AddProvider(new TextItemTypeProvider(), typeof(BaseTextItem)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[EditorBrowsableAttribute()] |
||||||
|
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPaint(e); |
||||||
|
this.Draw(e.Graphics); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override void Draw(Graphics graphics) |
||||||
|
{ |
||||||
|
if (graphics == null) { |
||||||
|
throw new ArgumentNullException("graphics"); |
||||||
|
} |
||||||
|
using (var backgroundBrush = new SolidBrush(this.BackColor)){ |
||||||
|
graphics.FillRectangle(backgroundBrush, base.DrawingRectangle); |
||||||
|
} |
||||||
|
|
||||||
|
var designTrimmimg = StringTrimming.EllipsisCharacter; |
||||||
|
|
||||||
|
if (stringTrimming != StringTrimming.None) { |
||||||
|
designTrimmimg = stringTrimming; |
||||||
|
} |
||||||
|
|
||||||
|
stringFormat = TextDrawer.BuildStringFormat(designTrimmimg, contentAlignment); |
||||||
|
using (var textBrush = new SolidBrush(ForeColor)) { |
||||||
|
TextDrawer.DrawString(graphics, Text, Font, textBrush, ClientRectangle, stringFormat); |
||||||
|
} |
||||||
|
|
||||||
|
// if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes) {
|
||||||
|
// stringFormat.FormatFlags = stringFormat.FormatFlags | StringFormatFlags.DirectionRightToLeft;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
DrawControl(graphics, base.DrawingRectangle); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// [EditorAttribute(typeof(DefaultTextEditor),
|
||||||
|
// typeof(System.Drawing.Design.UITypeEditor) )]
|
||||||
|
public override string Text { |
||||||
|
get { return base.Text; } |
||||||
|
set { base.Text = value; |
||||||
|
this.Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
#region Format and alignment
|
||||||
|
|
||||||
|
// [Browsable(true),
|
||||||
|
// Category("Appearance"),
|
||||||
|
// Description("String to format Number's Date's etc")]
|
||||||
|
// [DefaultValue("entry1")]
|
||||||
|
// [TypeConverter(typeof(FormatStringConverter))]
|
||||||
|
|
||||||
|
public string FormatString { |
||||||
|
get { return formatString; } |
||||||
|
set { |
||||||
|
formatString = value; |
||||||
|
Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Browsable(false)] |
||||||
|
public StringFormat StringFormat { |
||||||
|
get { return stringFormat; } |
||||||
|
set { |
||||||
|
stringFormat = value; |
||||||
|
Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Category("Appearance")] |
||||||
|
public StringTrimming StringTrimming { |
||||||
|
get { return stringTrimming; } |
||||||
|
set { |
||||||
|
stringTrimming = value; |
||||||
|
Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// [Category("Appearance")]
|
||||||
|
// [EditorAttribute(typeof(ContentAlignmentEditor),
|
||||||
|
// typeof(UITypeEditor) )]
|
||||||
|
public ContentAlignment ContentAlignment { |
||||||
|
get { return contentAlignment; } |
||||||
|
set { |
||||||
|
contentAlignment = value; |
||||||
|
Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region RighToLeft
|
||||||
|
|
||||||
|
[Category("Appearance")] |
||||||
|
public System.Windows.Forms.RightToLeft RTL |
||||||
|
{ |
||||||
|
get { return base.RightToLeft; } |
||||||
|
set { base.RightToLeft = value; } |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DataType
|
||||||
|
|
||||||
|
// [Browsable(true),
|
||||||
|
// Category("Databinding"),
|
||||||
|
// Description("Datatype of the underlying Column")]
|
||||||
|
// [DefaultValue("System.String")]
|
||||||
|
// [TypeConverter(typeof(DataTypeStringConverter))]
|
||||||
|
|
||||||
|
public string DataType {get;set;} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Expression
|
||||||
|
|
||||||
|
// [Browsable(true),
|
||||||
|
// Category("Expression"),
|
||||||
|
// Description("Enter a valid Expression")]
|
||||||
|
// [EditorAttribute(typeof(DefaultTextEditor),
|
||||||
|
// typeof(System.Drawing.Design.UITypeEditor) )]
|
||||||
|
public string Expression {get;set;} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region CanGrow/CanShrink
|
||||||
|
|
||||||
|
public bool CanGrow {get;set;} |
||||||
|
|
||||||
|
public bool CanShrink {get;set;} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,134 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.03.2014 |
||||||
|
* Time: 20:24 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
using ICSharpCode.Reporting.Items; |
||||||
|
using ICSharpCode.Reporting.Addin.TypeProvider; |
||||||
|
|
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of TextItemDesigner.
|
||||||
|
/// </summary>
|
||||||
|
public class TextItemDesigner:ControlDesigner |
||||||
|
{ |
||||||
|
|
||||||
|
ISelectionService selectionService; |
||||||
|
IComponentChangeService componentChangeService; |
||||||
|
BaseTextItem ctrl; |
||||||
|
|
||||||
|
public override void Initialize(IComponent component) |
||||||
|
{ |
||||||
|
base.Initialize(component); |
||||||
|
GetService(); |
||||||
|
ctrl = (BaseTextItem) component; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void PostFilterProperties(System.Collections.IDictionary properties) |
||||||
|
{ |
||||||
|
TypeProviderHelper.RemoveProperties(properties); |
||||||
|
base.PostFilterProperties(properties); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void GetService () |
||||||
|
{ |
||||||
|
selectionService = GetService(typeof(ISelectionService)) as ISelectionService; |
||||||
|
if (selectionService != null) |
||||||
|
{ |
||||||
|
selectionService.SelectionChanged += OnSelectionChanged; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); |
||||||
|
if (componentChangeService != null) { |
||||||
|
componentChangeService.ComponentRename += new ComponentRenameEventHandler(OnComponentRename); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void OnSelectionChanged(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
Control.Invalidate( ); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void OnComponentRename(object sender,ComponentRenameEventArgs e) { |
||||||
|
if (e.Component == this.Component) { |
||||||
|
Control.Name = e.NewName; |
||||||
|
Control.Invalidate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region SmartTag
|
||||||
|
|
||||||
|
// public override DesignerActionListCollection ActionLists {
|
||||||
|
// get {
|
||||||
|
// var actions = new DesignerActionListCollection ();
|
||||||
|
// actions.Add (new TextBasedDesignerActionList(this.Component));
|
||||||
|
// return actions;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ContextMenu
|
||||||
|
/* |
||||||
|
public override DesignerVerbCollection Verbs { |
||||||
|
get { |
||||||
|
var verbs = new DesignerVerbCollection(); |
||||||
|
var v1 = new DesignerVerb ("TextEditor",OnRunTextEditor); |
||||||
|
verbs.Add (v1); |
||||||
|
return verbs; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void OnRunTextEditor (object sender,EventArgs e) |
||||||
|
{ |
||||||
|
IStringBasedEditorDialog ed = new TextEditorDialog (ctrl.Text,ctrl.Name); |
||||||
|
if (ed.ShowDialog() == DialogResult.OK) { |
||||||
|
ctrl.Text = ed.TextValue; |
||||||
|
this.SetProperty ("Name",ed.TextValue); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void SetProperty (string prop, object value) |
||||||
|
{ |
||||||
|
PropertyDescriptor p = TypeDescriptor.GetProperties(Control)[prop]; |
||||||
|
if (p == null) { |
||||||
|
throw new ArgumentException (this.ctrl.Text); |
||||||
|
} else { |
||||||
|
p.SetValue (Control,value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
*/ |
||||||
|
#endregion
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing) |
||||||
|
{ |
||||||
|
if (this.selectionService != null) { |
||||||
|
selectionService.SelectionChanged -= OnSelectionChanged; |
||||||
|
} |
||||||
|
|
||||||
|
if (componentChangeService != null) { |
||||||
|
componentChangeService.ComponentRename -= OnComponentRename; |
||||||
|
} |
||||||
|
base.Dispose(disposing); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.03.2014 |
||||||
|
* Time: 20:38 |
||||||
|
* |
||||||
|
* 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 TextItemTypeProvider.
|
||||||
|
/// </summary>
|
||||||
|
class TextItemTypeProvider : TypeDescriptionProvider |
||||||
|
{ |
||||||
|
public TextItemTypeProvider() : base(TypeDescriptor.GetProvider(typeof(AbstractItem))) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) |
||||||
|
{ |
||||||
|
ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); |
||||||
|
return new TextItemTypeDescriptor(td, instance); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
class TextItemTypeDescriptor : CustomTypeDescriptor |
||||||
|
{ |
||||||
|
BaseTextItem instance; |
||||||
|
|
||||||
|
public TextItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) |
||||||
|
: base(parent) |
||||||
|
{ |
||||||
|
instance = instance as BaseTextItem; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override PropertyDescriptorCollection GetProperties() |
||||||
|
{ |
||||||
|
return GetProperties(null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) |
||||||
|
{ |
||||||
|
var props = base.GetProperties(attributes); |
||||||
|
var allProperties = new List<PropertyDescriptor>(); |
||||||
|
|
||||||
|
TypeProviderHelper.AddDefaultProperties(allProperties,props); |
||||||
|
|
||||||
|
TypeProviderHelper.AddTextBasedProperties(allProperties,props); |
||||||
|
|
||||||
|
var prop = props.Find("Text", true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
prop = props.Find("DrawBorder",true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
prop = props.Find("FrameColor",true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
prop = props.Find("ForeColor",true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
prop = props.Find("Visible",true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
prop = props.Find("Expression",true); |
||||||
|
allProperties.Add(prop); |
||||||
|
|
||||||
|
return new PropertyDescriptorCollection(allProperties.ToArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,143 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.03.2014 |
||||||
|
* Time: 20:35 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
using System.Drawing.Text; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.BaseClasses |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of TextDrawer.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TextDrawer |
||||||
|
{ |
||||||
|
|
||||||
|
private TextDrawer() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static void DrawString(Graphics graphics,string text, |
||||||
|
Font font,Brush brush, |
||||||
|
RectangleF rectangle, |
||||||
|
StringFormat format) |
||||||
|
{ |
||||||
|
if (graphics == null) { |
||||||
|
throw new ArgumentNullException("graphics"); |
||||||
|
} |
||||||
|
|
||||||
|
graphics.DrawString(text, |
||||||
|
font, |
||||||
|
brush, |
||||||
|
rectangle, |
||||||
|
format); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static void DrawString (Graphics graphics,string text) |
||||||
|
|
||||||
|
{ |
||||||
|
if (graphics == null) { |
||||||
|
throw new ArgumentNullException("graphics"); |
||||||
|
} |
||||||
|
// if (decorator == null) {
|
||||||
|
// throw new ArgumentNullException("decorator");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// StringFormat stringFormat = BuildStringFormat(decorator.StringTrimming,decorator.ContentAlignment);
|
||||||
|
//
|
||||||
|
// if (decorator.RightToLeft ==System.Windows.Forms.RightToLeft.Yes) {
|
||||||
|
// stringFormat.FormatFlags = stringFormat.FormatFlags | StringFormatFlags.DirectionRightToLeft;
|
||||||
|
// }
|
||||||
|
|
||||||
|
var formattedString = text; |
||||||
|
// if (! String.IsNullOrEmpty(decorator.FormatString)) {
|
||||||
|
// formattedString = StandardFormatter.FormatOutput(text,decorator.FormatString,decorator.DataType,String.Empty);
|
||||||
|
// }
|
||||||
|
|
||||||
|
graphics.TextRenderingHint = TextRenderingHint.AntiAlias; |
||||||
|
|
||||||
|
// graphics.DrawString (formattedString,decorator.Font,
|
||||||
|
// new SolidBrush(decorator.ForeColor),
|
||||||
|
// new Rectangle(decorator.Location.X,
|
||||||
|
// decorator.Location.Y,
|
||||||
|
// decorator.Size.Width,
|
||||||
|
// decorator.Size.Height),
|
||||||
|
// stringFormat);
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static StringFormat BuildStringFormat(StringTrimming stringTrimming,ContentAlignment alignment) |
||||||
|
{ |
||||||
|
StringFormat format = StringFormat.GenericTypographic; |
||||||
|
format.Trimming = stringTrimming; |
||||||
|
format.FormatFlags = StringFormatFlags.LineLimit; |
||||||
|
|
||||||
|
if (alignment <= ContentAlignment.MiddleCenter){ |
||||||
|
switch (alignment){ |
||||||
|
case ContentAlignment.TopLeft:{ |
||||||
|
format.Alignment = StringAlignment.Near; |
||||||
|
format.LineAlignment = StringAlignment.Near; |
||||||
|
return format; |
||||||
|
} |
||||||
|
case ContentAlignment.TopCenter:{ |
||||||
|
format.Alignment = StringAlignment.Center; |
||||||
|
format.LineAlignment = StringAlignment.Near; |
||||||
|
return format; |
||||||
|
} |
||||||
|
case (ContentAlignment.TopCenter | ContentAlignment.TopLeft):{ |
||||||
|
return format; |
||||||
|
} |
||||||
|
case ContentAlignment.TopRight:{ |
||||||
|
format.Alignment = StringAlignment.Far; |
||||||
|
format.LineAlignment = StringAlignment.Near; |
||||||
|
return format; |
||||||
|
} |
||||||
|
case ContentAlignment.MiddleLeft:{ |
||||||
|
format.Alignment = StringAlignment.Near; |
||||||
|
format.LineAlignment = StringAlignment.Center; |
||||||
|
return format; |
||||||
|
} |
||||||
|
case ContentAlignment.MiddleCenter:{ |
||||||
|
format.Alignment = StringAlignment.Center; |
||||||
|
format.LineAlignment = StringAlignment.Center; |
||||||
|
return format; |
||||||
|
} |
||||||
|
} |
||||||
|
return format; |
||||||
|
} |
||||||
|
if (alignment <= ContentAlignment.BottomLeft){ |
||||||
|
if (alignment == ContentAlignment.MiddleRight){ |
||||||
|
format.Alignment = StringAlignment.Far; |
||||||
|
format.LineAlignment = StringAlignment.Center; |
||||||
|
return format; |
||||||
|
} |
||||||
|
if (alignment != ContentAlignment.BottomLeft){ |
||||||
|
return format; |
||||||
|
} |
||||||
|
} |
||||||
|
else{ |
||||||
|
if (alignment != ContentAlignment.BottomCenter){ |
||||||
|
if (alignment == ContentAlignment.BottomRight) |
||||||
|
{ |
||||||
|
format.Alignment = StringAlignment.Far; |
||||||
|
format.LineAlignment = StringAlignment.Far; |
||||||
|
} |
||||||
|
return format; |
||||||
|
} |
||||||
|
format.Alignment = StringAlignment.Center; |
||||||
|
format.LineAlignment = StringAlignment.Far; |
||||||
|
return format; |
||||||
|
} |
||||||
|
format.Alignment = StringAlignment.Near; |
||||||
|
format.LineAlignment = StringAlignment.Far; |
||||||
|
return format; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue