From c607d641dc174fa4d4f9d38bd3e1f530f1cce56b Mon Sep 17 00:00:00 2001
From: Daniel Brunner <0xFEEDC0DE64@gmail.com>
Date: Sat, 4 Feb 2017 13:48:16 +0100
Subject: [PATCH] Imported existing sources
---
.gitattributes | 63 +
BrushForm.Designer.cs | 195 +++
BrushForm.cs | 147 ++
BrushForm.resx | 120 ++
BrushPen.DesignTime.cs | 240 +++
BrushPenData.cs | 212 +++
LICENSE | 674 ++++++++
ListViewPrinter.cs | 2250 +++++++++++++++++++++++++
ListViewPrinter2005.csproj | 73 +
ListViewPrinter2008.csproj | 131 ++
ListViewPrinter2010.csproj | 127 ++
ListViewPrinter2010.ncrunchproject | 27 +
ListViewPrinter2012.csproj | 127 ++
ListViewPrinter2012.ncrunchproject | 22 +
ListViewPrinter2012.v2.ncrunchproject | 22 +
Properties/AssemblyInfo.cs | 35 +
README.md | 2 +
lvp-keyfile.snk | Bin 0 -> 596 bytes
18 files changed, 4467 insertions(+)
create mode 100644 .gitattributes
create mode 100644 BrushForm.Designer.cs
create mode 100644 BrushForm.cs
create mode 100644 BrushForm.resx
create mode 100644 BrushPen.DesignTime.cs
create mode 100644 BrushPenData.cs
create mode 100644 LICENSE
create mode 100644 ListViewPrinter.cs
create mode 100644 ListViewPrinter2005.csproj
create mode 100644 ListViewPrinter2008.csproj
create mode 100644 ListViewPrinter2010.csproj
create mode 100644 ListViewPrinter2010.ncrunchproject
create mode 100644 ListViewPrinter2012.csproj
create mode 100644 ListViewPrinter2012.ncrunchproject
create mode 100644 ListViewPrinter2012.v2.ncrunchproject
create mode 100644 Properties/AssemblyInfo.cs
create mode 100644 lvp-keyfile.snk
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/BrushForm.Designer.cs b/BrushForm.Designer.cs
new file mode 100644
index 0000000..5f38167
--- /dev/null
+++ b/BrushForm.Designer.cs
@@ -0,0 +1,195 @@
+namespace BrightIdeasSoftware
+{
+ partial class BrushForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null)) {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.rbNone = new System.Windows.Forms.RadioButton();
+ this.rbHatch = new System.Windows.Forms.RadioButton();
+ this.rbGradient = new System.Windows.Forms.RadioButton();
+ this.rbSolid = new System.Windows.Forms.RadioButton();
+ this.groupBox2 = new System.Windows.Forms.GroupBox();
+ this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
+ this.groupBox3 = new System.Windows.Forms.GroupBox();
+ this.examplePanel = new System.Windows.Forms.Panel();
+ this.groupBox1.SuspendLayout();
+ this.groupBox2.SuspendLayout();
+ this.groupBox3.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // groupBox1
+ //
+ this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.groupBox1.Controls.Add(this.rbNone);
+ this.groupBox1.Controls.Add(this.rbHatch);
+ this.groupBox1.Controls.Add(this.rbGradient);
+ this.groupBox1.Controls.Add(this.rbSolid);
+ this.groupBox1.Location = new System.Drawing.Point(12, 12);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(318, 52);
+ this.groupBox1.TabIndex = 0;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "Style";
+ //
+ // rbNone
+ //
+ this.rbNone.AutoSize = true;
+ this.rbNone.Location = new System.Drawing.Point(261, 20);
+ this.rbNone.Name = "rbNone";
+ this.rbNone.Size = new System.Drawing.Size(51, 17);
+ this.rbNone.TabIndex = 4;
+ this.rbNone.TabStop = true;
+ this.rbNone.Text = "&None";
+ this.rbNone.UseVisualStyleBackColor = true;
+ this.rbNone.CheckedChanged += new System.EventHandler(this.rbCheckedChanged);
+ //
+ // rbHatch
+ //
+ this.rbHatch.AutoSize = true;
+ this.rbHatch.Location = new System.Drawing.Point(173, 19);
+ this.rbHatch.Name = "rbHatch";
+ this.rbHatch.Size = new System.Drawing.Size(54, 17);
+ this.rbHatch.TabIndex = 2;
+ this.rbHatch.TabStop = true;
+ this.rbHatch.Text = "&Hatch";
+ this.rbHatch.UseVisualStyleBackColor = true;
+ this.rbHatch.CheckedChanged += new System.EventHandler(this.rbCheckedChanged);
+ //
+ // rbGradient
+ //
+ this.rbGradient.AutoSize = true;
+ this.rbGradient.Location = new System.Drawing.Point(75, 20);
+ this.rbGradient.Name = "rbGradient";
+ this.rbGradient.Size = new System.Drawing.Size(65, 17);
+ this.rbGradient.TabIndex = 1;
+ this.rbGradient.TabStop = true;
+ this.rbGradient.Text = "&Gradient";
+ this.rbGradient.UseVisualStyleBackColor = true;
+ this.rbGradient.CheckedChanged += new System.EventHandler(this.rbCheckedChanged);
+ //
+ // rbSolid
+ //
+ this.rbSolid.AutoSize = true;
+ this.rbSolid.Location = new System.Drawing.Point(7, 20);
+ this.rbSolid.Name = "rbSolid";
+ this.rbSolid.Size = new System.Drawing.Size(48, 17);
+ this.rbSolid.TabIndex = 0;
+ this.rbSolid.TabStop = true;
+ this.rbSolid.Text = "&Solid";
+ this.rbSolid.UseVisualStyleBackColor = true;
+ this.rbSolid.CheckedChanged += new System.EventHandler(this.rbCheckedChanged);
+ //
+ // groupBox2
+ //
+ this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.groupBox2.Controls.Add(this.propertyGrid1);
+ this.groupBox2.Location = new System.Drawing.Point(12, 71);
+ this.groupBox2.Name = "groupBox2";
+ this.groupBox2.Size = new System.Drawing.Size(318, 237);
+ this.groupBox2.TabIndex = 1;
+ this.groupBox2.TabStop = false;
+ this.groupBox2.Text = "Properties";
+ //
+ // propertyGrid1
+ //
+ this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.propertyGrid1.CommandsVisibleIfAvailable = false;
+ this.propertyGrid1.HelpVisible = false;
+ this.propertyGrid1.Location = new System.Drawing.Point(7, 20);
+ this.propertyGrid1.Name = "propertyGrid1";
+ this.propertyGrid1.PropertySort = System.Windows.Forms.PropertySort.Alphabetical;
+ this.propertyGrid1.Size = new System.Drawing.Size(305, 211);
+ this.propertyGrid1.TabIndex = 0;
+ this.propertyGrid1.ToolbarVisible = false;
+ this.propertyGrid1.SelectedObjectsChanged += new System.EventHandler(this.propertyGrid1_SelectedObjectsChanged);
+ this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged);
+ //
+ // groupBox3
+ //
+ this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.groupBox3.Controls.Add(this.examplePanel);
+ this.groupBox3.Location = new System.Drawing.Point(12, 315);
+ this.groupBox3.Name = "groupBox3";
+ this.groupBox3.Size = new System.Drawing.Size(318, 76);
+ this.groupBox3.TabIndex = 2;
+ this.groupBox3.TabStop = false;
+ this.groupBox3.Text = "Example";
+ //
+ // examplePanel
+ //
+ this.examplePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.examplePanel.Location = new System.Drawing.Point(7, 20);
+ this.examplePanel.Name = "examplePanel";
+ this.examplePanel.Size = new System.Drawing.Size(305, 50);
+ this.examplePanel.TabIndex = 0;
+ this.examplePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.examplePanel_Paint);
+ //
+ // BrushForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(342, 403);
+ this.ControlBox = false;
+ this.Controls.Add(this.groupBox3);
+ this.Controls.Add(this.groupBox2);
+ this.Controls.Add(this.groupBox1);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.Name = "BrushForm";
+ this.ShowIcon = false;
+ this.ShowInTaskbar = false;
+ this.Text = "BrushForm";
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ this.groupBox2.ResumeLayout(false);
+ this.groupBox3.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.GroupBox groupBox1;
+ private System.Windows.Forms.GroupBox groupBox2;
+ private System.Windows.Forms.GroupBox groupBox3;
+ private System.Windows.Forms.Panel examplePanel;
+ protected System.Windows.Forms.RadioButton rbHatch;
+ protected System.Windows.Forms.RadioButton rbGradient;
+ protected System.Windows.Forms.RadioButton rbSolid;
+ protected System.Windows.Forms.RadioButton rbNone;
+ protected System.Windows.Forms.PropertyGrid propertyGrid1;
+ }
+}
\ No newline at end of file
diff --git a/BrushForm.cs b/BrushForm.cs
new file mode 100644
index 0000000..374d48f
--- /dev/null
+++ b/BrushForm.cs
@@ -0,0 +1,147 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Text;
+using System.Windows.Forms;
+
+//TODO: Allow alpha
+
+namespace BrightIdeasSoftware
+{
+ internal partial class BrushForm : Form
+ {
+ public BrushForm()
+ {
+ InitializeComponent();
+ this.TopLevel = false;
+ }
+
+ public IBrushData GetBrushData()
+ {
+ return this.propertyGrid1.SelectedObject as IBrushData;
+ }
+
+ public Brush GetBrush()
+ {
+ IBrushData bd = this.GetBrushData();
+ if (bd == null)
+ return null;
+ else
+ return bd.GetBrush();
+ }
+
+ public void SetBrush(IBrushData value)
+ {
+ this.rbSolid.Tag = (value is SolidBrushData) ? value : new SolidBrushData();
+ this.rbHatch.Tag = (value is HatchBrushData) ? value : new HatchBrushData();
+ this.rbGradient.Tag = (value is LinearGradientBrushData) ? value : new LinearGradientBrushData();
+ this.TurnOnRadioButton(value);
+ }
+
+ protected void TurnOnRadioButton(IBrushData value)
+ {
+ RadioButton turnedOn = this.rbNone;
+ if (value != null) {
+ if (value.GetType() == typeof(SolidBrushData))
+ turnedOn = this.rbSolid;
+ else if (value.GetType() == typeof(LinearGradientBrushData))
+ turnedOn = this.rbGradient;
+ else if (value.GetType() == typeof(HatchBrushData))
+ turnedOn = this.rbHatch;
+ }
+
+ turnedOn.Checked = true;
+ }
+
+ protected void examplePanel_Paint(object sender, PaintEventArgs e)
+ {
+ using (BufferedGraphics buffered = BufferedGraphicsManager.Current.Allocate(e.Graphics, e.ClipRectangle)) {
+ Graphics g = buffered.Graphics;
+ g.Clear(((Panel)sender).BackColor);
+ this.HandlePaintEvent(g, e.ClipRectangle);
+ buffered.Render();
+ }
+ }
+
+ virtual protected void HandlePaintEvent(Graphics g, Rectangle r)
+ {
+ using (Brush b = this.GetBrush()) {
+ StringFormat fmt = new StringFormat();
+ fmt.Alignment = StringAlignment.Center;
+ fmt.LineAlignment = StringAlignment.Center;
+ if (b == null) {
+ g.DrawString("No brush", new Font("Tahoma", 14), Brushes.DarkGray, r, fmt);
+ } else {
+ g.DrawString("Through a mirror darkly", new Font("Tahoma", 14), Brushes.Black, r, fmt);
+ g.FillRectangle(BlockFormat.PrepareBrushForDrawing(b, r), r);
+ }
+ }
+ }
+
+ private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
+ {
+ this.examplePanel.Invalidate();
+ }
+
+ private void propertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
+ {
+ this.examplePanel.Invalidate();
+ }
+
+ private void rbCheckedChanged(object sender, EventArgs e)
+ {
+ this.propertyGrid1.SelectedObject = ((RadioButton)sender).Tag;
+ }
+ }
+
+ internal class PenForm : BrushForm
+ {
+ public PenData GetPenData()
+ {
+ return this.propertyGrid1.SelectedObject as PenData;
+ }
+
+ public Pen GetPen()
+ {
+ PenData data = this.GetPenData();
+ if (data == null)
+ return null;
+ else
+ return data.GetPen();
+ }
+
+ public void SetPenData(PenData value)
+ {
+ IBrushData bd = (value == null) ? null : value.Brush;
+ this.rbSolid.Tag = (bd is SolidBrushData) ? value : new PenData(new SolidBrushData());
+ this.rbGradient.Tag = (bd is LinearGradientBrushData) ? value : new PenData(new LinearGradientBrushData());
+ this.rbHatch.Tag = (bd is HatchBrushData) ? value : new PenData(new HatchBrushData());
+ this.TurnOnRadioButton(bd);
+ }
+
+ protected override void HandlePaintEvent(Graphics g, Rectangle r)
+ {
+ using (Pen p = this.GetPen()) {
+ g.SmoothingMode = ObjectListView.SmoothingMode;
+ StringFormat fmt = new StringFormat();
+ fmt.Alignment = StringAlignment.Center;
+ fmt.LineAlignment = StringAlignment.Center;
+ if (p == null) {
+ g.DrawString("No pen", new Font("Tahoma", 14), Brushes.DarkGray, r, fmt);
+ } else {
+ g.DrawString("Through a mirror darkly", new Font("Tahoma", 14), Brushes.Black, r, fmt);
+ int inset = (int)Math.Max(1.0, p.Width);
+ r.Inflate(-inset, -inset);
+ Point[] pts = new Point[4];
+ pts[0] = r.Location;
+ pts[1] = new Point(r.X + r.Width / 2, r.Bottom);
+ pts[2] = new Point(r.X + r.Width / 2, r.Top);
+ pts[3] = new Point(r.Right, r.Bottom);
+ g.DrawLines(BlockFormat.PreparePenForDrawing(p, r), pts);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/BrushForm.resx b/BrushForm.resx
new file mode 100644
index 0000000..19dc0dd
--- /dev/null
+++ b/BrushForm.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BrushPen.DesignTime.cs b/BrushPen.DesignTime.cs
new file mode 100644
index 0000000..cfa0d25
--- /dev/null
+++ b/BrushPen.DesignTime.cs
@@ -0,0 +1,240 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms.Design;
+using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Design;
+using System.ComponentModel.Design.Serialization;
+
+namespace BrightIdeasSoftware
+{
+ ///
+ /// Editor for use within the IDE when changing BrushFactory values
+ ///
+ internal class BrushDataEditor : UITypeEditor
+ {
+ public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
+ {
+ return UITypeEditorEditStyle.DropDown;
+ }
+
+ ///
+ /// The user has asked to edit a value. Do it.
+ ///
+ public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
+ {
+ // For future reference. When we are running within the IDE, IDesignerHost will be non-null, e.g.
+ //IDesignerHost host = provider.GetService(typeof(IDesignerHost)) as IDesignerHost;
+
+ // We need editor service otherwise we can't do anything
+ IWindowsFormsEditorService wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
+ if (wfes == null)
+ return value;
+
+ BrushForm form = new BrushForm();
+ form.SetBrush(value as IBrushData);
+ wfes.DropDownControl(form);
+ return form.GetBrushData();
+ }
+
+ ///
+ /// Can we paint a representation of our value?
+ ///
+ public override bool GetPaintValueSupported(ITypeDescriptorContext context)
+ {
+ return true;
+ }
+
+ ///
+ /// Draw a representation of our value
+ ///
+ public override void PaintValue(PaintValueEventArgs e)
+ {
+ IBrushData bd = e.Value as IBrushData;
+ if (bd == null)
+ base.PaintValue(e);
+ else
+ e.Graphics.FillRectangle(BlockFormat.PrepareBrushForDrawing(bd.GetBrush(), e.Bounds), e.Bounds);
+ }
+ }
+
+ ///
+ /// Editor for use within the IDE when changing BrushFactory values
+ ///
+ internal class PenDataEditor : UITypeEditor
+ {
+ public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
+ {
+ return UITypeEditorEditStyle.DropDown;
+ }
+
+ ///
+ /// The user has asked to edit a value. Do it.
+ ///
+ public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
+ {
+ // For future reference. When we are running within the IDE, IDesignerHost will be non-null, e.g.
+ //IDesignerHost host = provider.GetService(typeof(IDesignerHost)) as IDesignerHost;
+
+ // We need editor service otherwise we can't do anything
+ IWindowsFormsEditorService wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
+ if (wfes == null)
+ return value;
+
+ PenForm form = new PenForm();
+ form.SetPenData(value as PenData);
+ wfes.DropDownControl(form);
+ return form.GetPenData();
+ }
+
+ ///
+ /// Can we paint a representation of our value?
+ ///
+ public override bool GetPaintValueSupported(ITypeDescriptorContext context)
+ {
+ return true;
+ }
+
+ ///
+ /// Draw a representation of our value
+ ///
+ public override void PaintValue(PaintValueEventArgs e)
+ {
+ PenData p = e.Value as PenData;
+ if (p == null)
+ base.PaintValue(e);
+ else {
+ e.Graphics.SetClip(e.Bounds);
+ e.Graphics.DrawLine(p.GetPen(), e.Bounds.Left, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom);
+ e.Graphics.ResetClip();
+ }
+ }
+ }
+
+ ///
+ /// Instances of this class handle converting BrushFactories to and from various other forms.
+ /// This class can convert BrushFactories to and from string representations, and can convert
+ /// to InstanceDescriptor (which are used to convert an object into source code).
+ ///
+ internal class BrushDataConverter : ExpandableObjectConverter
+ {
+ ///
+ /// Indicate that we can convert to a string or to an InstanceDescriptor (these
+ /// are used to serial an object to code).
+ ///
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
+ {
+ if (destinationType == typeof(string))
+ return true;
+
+ return base.CanConvertTo(context, destinationType);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
+ {
+ IBrushData b = value as IBrushData;
+ if (destinationType == typeof(string)) {
+ if (b == null)
+ return "(none)";
+ else {
+ return b.GetType().Name;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ if (sourceType == typeof(string))
+ return true;
+
+ return base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ if (value != null && value.GetType() == typeof(string)) {
+ String s = value as String;
+ if (s.Length == 0)
+ return null;
+ switch (s[0]) {
+ case 'S':
+ return new SolidBrushData();
+ case 'G':
+ return new LinearGradientBrushData();
+ case 'H':
+ return new HatchBrushData();
+ default:
+ return null;
+ }
+ }
+ return base.ConvertFrom(context, culture, value);
+ }
+ }
+
+ ///
+ /// Instances of this class handle converting BrushFactories to and from various other forms.
+ /// This class can convert BrushFactories to and from string representations, and can convert
+ /// to InstanceDescriptor (which are used to convert an object into source code).
+ ///
+ internal class PenDataConverter : ExpandableObjectConverter
+ {
+ ///
+ /// Indicate that we can convert to a string or to an InstanceDescriptor (these
+ /// are used to serial an object to code).
+ ///
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
+ {
+ if (destinationType == typeof(string))
+ return true;
+
+ return base.CanConvertTo(context, destinationType);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
+ {
+ if (destinationType == typeof(string)) {
+ PenData p = value as PenData;
+ if (p == null || p.Brush == null)
+ return "(none)";
+ else {
+ string name = p.Brush.GetType().Name;
+ return name.Substring(0, name.Length - "BrushData".Length) + "Pen";
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ if (sourceType == typeof(string))
+ return true;
+
+ return base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ if (value != null && value.GetType() == typeof(string)) {
+ String s = value as String;
+ if (s.Length == 0)
+ return null;
+ switch (s[0]) {
+ case 'S':
+ return new PenData(new SolidBrushData());
+ case 'G':
+ return new PenData(new LinearGradientBrushData());
+ case 'H':
+ return new PenData(new HatchBrushData());
+ default:
+ return null;
+ }
+ }
+ return base.ConvertFrom(context, culture, value);
+ }
+ }
+}
diff --git a/BrushPenData.cs b/BrushPenData.cs
new file mode 100644
index 0000000..1184861
--- /dev/null
+++ b/BrushPenData.cs
@@ -0,0 +1,212 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Design;
+
+namespace BrightIdeasSoftware
+{
+ ///
+ /// PenData represents the data required to create a pen.
+ ///
+ /// Pens cannot be edited directly within the IDE (is this VCS EE only?)
+ /// These objects allow pen characters to be edited within the IDE and then real
+ /// Pen objects created.
+ [Editor(typeof(PenDataEditor), typeof(UITypeEditor)),
+ TypeConverter(typeof(PenDataConverter))]
+ public class PenData
+ {
+ public PenData() : this(new SolidBrushData())
+ {
+ }
+
+ public PenData(IBrushData brush)
+ {
+ this.Brush = brush;
+ }
+
+ public Pen GetPen()
+ {
+ Pen p = new Pen(this.Brush.GetBrush(), this.Width);
+ p.SetLineCap(this.StartCap, this.EndCap, this.DashCap);
+ p.DashStyle = this.DashStyle;
+ p.LineJoin = this.LineJoin;
+ return p;
+ }
+
+ [TypeConverter(typeof(ExpandableObjectConverter))]
+ public IBrushData Brush
+ {
+ get { return brushData; }
+ set { brushData = value; }
+ }
+ private IBrushData brushData;
+
+ [DefaultValue(typeof(DashCap), "Round")]
+ public DashCap DashCap
+ {
+ get { return dashCap; }
+ set { dashCap = value; }
+ }
+ private DashCap dashCap = DashCap.Round;
+
+ [DefaultValue(typeof(DashStyle), "Solid")]
+ public DashStyle DashStyle
+ {
+ get { return dashStyle; }
+ set { dashStyle = value; }
+ }
+ private DashStyle dashStyle = DashStyle.Solid;
+
+ [DefaultValue(typeof(LineCap), "NoAnchor")]
+ public LineCap EndCap
+ {
+ get { return endCap; }
+ set { endCap = value; }
+ }
+ private LineCap endCap = LineCap.NoAnchor;
+
+ [DefaultValue(typeof(LineJoin), "Round")]
+ public LineJoin LineJoin
+ {
+ get { return lineJoin; }
+ set { lineJoin = value; }
+ }
+ private LineJoin lineJoin = LineJoin.Round;
+
+ [DefaultValue(typeof(LineCap), "NoAnchor")]
+ public LineCap StartCap
+ {
+ get { return startCap; }
+ set { startCap = value; }
+ }
+ private LineCap startCap = LineCap.NoAnchor;
+
+ [DefaultValue(1.0f)]
+ public float Width
+ {
+ get { return width; }
+ set { width = value; }
+ }
+ private float width = 1.0f;
+ }
+
+ [Editor(typeof(BrushDataEditor), typeof(UITypeEditor)),
+ TypeConverter(typeof(BrushDataConverter))]
+ public interface IBrushData
+ {
+ Brush GetBrush();
+ }
+
+ public class SolidBrushData : IBrushData
+ {
+ public Brush GetBrush()
+ {
+ if (this.Alpha < 255)
+ return new SolidBrush(Color.FromArgb(this.Alpha, this.Color));
+ else
+ return new SolidBrush(this.Color);
+ }
+
+ [DefaultValue(typeof(Color), "")]
+ public Color Color
+ {
+ get { return color; }
+ set { color = value; }
+ }
+ private Color color = Color.Empty;
+
+ [DefaultValue(255)]
+ public int Alpha
+ {
+ get { return alpha; }
+ set { alpha = value; }
+ }
+ private int alpha = 255;
+ }
+
+ public class LinearGradientBrushData : IBrushData
+ {
+ public Brush GetBrush()
+ {
+ return new LinearGradientBrush(new Rectangle(0, 0, 100, 100), this.FromColor, this.ToColor, this.GradientMode);
+ }
+
+ public Color FromColor
+ {
+ get { return fromColor; }
+ set { fromColor = value; }
+ }
+ private Color fromColor = Color.Aqua;
+
+ public Color ToColor
+ {
+ get { return toColor; }
+ set { toColor = value; }
+ }
+ private Color toColor = Color.Pink;
+
+ public LinearGradientMode GradientMode
+ {
+ get { return gradientMode; }
+ set { gradientMode = value; }
+ }
+ private LinearGradientMode gradientMode = LinearGradientMode.Horizontal;
+ }
+
+ public class HatchBrushData : IBrushData
+ {
+ public Brush GetBrush()
+ {
+ return new HatchBrush(this.HatchStyle, this.ForegroundColor, this.BackgroundColor);
+ }
+
+ public Color BackgroundColor
+ {
+ get { return backgroundColor; }
+ set { backgroundColor = value; }
+ }
+ private Color backgroundColor = Color.AliceBlue;
+
+ public Color ForegroundColor
+ {
+ get { return foregroundColor; }
+ set { foregroundColor = value; }
+ }
+ private Color foregroundColor = Color.Aqua;
+
+ public HatchStyle HatchStyle
+ {
+ get { return hatchStyle; }
+ set { hatchStyle = value; }
+ }
+ private HatchStyle hatchStyle = HatchStyle.Cross;
+ }
+
+ public class TextureBrushData : IBrushData
+ {
+ public Brush GetBrush()
+ {
+ if (this.Image == null)
+ return null;
+ else
+ return new TextureBrush(this.Image, this.WrapMode);
+ }
+
+ public Image Image
+ {
+ get { return image; }
+ set { image = value; }
+ }
+ private Image image;
+
+ public WrapMode WrapMode
+ {
+ get { return wrapMode; }
+ set { wrapMode = value; }
+ }
+ private WrapMode wrapMode = WrapMode.Tile;
+ }
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9cecc1d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {one line to give the program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ {project} Copyright (C) {year} {fullname}
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/ListViewPrinter.cs b/ListViewPrinter.cs
new file mode 100644
index 0000000..744f2be
--- /dev/null
+++ b/ListViewPrinter.cs
@@ -0,0 +1,2250 @@
+/*
+ * ListViewPrinterBase - A helper class to easily print an ListView
+ *
+ * User: Phillip Piper (phillip_piper@bigfoot.com)
+ * Date: 2007-11-01 11:15 AM
+ *
+ * Change log:
+ * 2009-02-24 JPP - Correctly use new renderer scheme :)
+ * 2009-01-26 JPP - Use new renderer scheme
+ * - Removed ugly hack about BarRenderer when printing.
+ * 2009-01-19 JPP - Use IsPrinting property on BaseRenderer
+ * v2.0.1
+ * 2008-12-16 JPP - Hide all obsolete properties from the code generator
+ * v2.0
+ * The interaction with the IDE was completely rewritten in this version.
+ * Old code should still work, but the IDE will not recognise the old configurations.
+ *
+ * 2008-11-23 JPP - Put back some obsolete methods to make transition easier.
+ * 2008-11-15 JPP - Use BrushData and PenData objects to ease IDE interactions.
+ * - [BREAK] Removed obsolete methods.
+ * - Changed license to GPL v3, to be consistent with ObjectListView.
+ * v1.2
+ * 2008-04-13 JPP - Made the instance variables 'groupHeaderFormat' and 'listHeaderFormat'
+ * private, like they always should have been. Use their corresponding
+ * properties instead.
+ * 2008-01-16 JPP - Made all classes public so they can be accessed from a DLL
+ * - Corrected initial value bugs
+ * 2007-11-29 JPP - Made list cells able to wrap, rather than always ellipsing.
+ * - Handle ListViewItems having less sub items than there are columns.
+ * 2007-11-21 JPP - Cell images are no longer erased by a non-transparent cell backgrounds.
+ * v1.1
+ * 2007-11-10 JPP - Made to work with virtual lists (if using ObjectListView)
+ * - Make the list view header be able to show on each page
+ * 2007-11-06 JPP - Changed to use Pens internally in BlockFormat
+ * - Fixed bug where group + following row would overprint footer
+ * v1.0
+ * 2007-11-05 JPP - Vastly improved integration with IDE
+ * - Added support for page ranges, and printing images
+ * 2007-11-03 JPP Added support for groups
+ * 2007-10-31 JPP Initial version
+ *
+ * To Do:
+ *
+ * Copyright (C) 2006-2008 Phillip Piper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * If you wish to use this code in a closed source application, please contact phillip_piper@bigfoot.com.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Printing;
+using System.Windows.Forms;
+
+namespace BrightIdeasSoftware
+{
+ ///
+ /// A ListViewPrinterBase prints or print previews an ListView.
+ ///
+ ///
+ /// The format of the page header/footer, list header and list rows can all be customised.
+ /// This class works best with ObjectListView class, but still works fine with normal ListViews.
+ /// If you don't have ObjectListView class in your project, you must define WITHOUT_OBJECTLISTVIEW as one
+ /// of the conditional compilation symbols on your projects properties.
+ ///
+ public class ListViewPrinterBase : PrintDocument
+ {
+ #region Constructors
+
+ ///
+ /// Make a new ListViewPrinterBase
+ ///
+ public ListViewPrinterBase()
+ {
+ // Give the report a reasonable set of default values
+ this.HeaderFormat = BlockFormat.Header();
+ this.ListHeaderFormat = BlockFormat.ListHeader();
+ this.CellFormat = BlockFormat.DefaultCell();
+ this.GroupHeaderFormat = BlockFormat.GroupHeader();
+ this.FooterFormat = BlockFormat.Footer();
+ }
+
+ ///
+ /// Make a new ListViewPrinterBase that will print the given ListView
+ ///
+ public ListViewPrinterBase(ListView lv)
+ : this()
+ {
+ this.ListView = lv;
+ }
+
+ #endregion
+
+ #region Control Properties
+
+ ///
+ /// This is the ListView that will be printed
+ ///
+ [Category("Behaviour"),
+ Description("Which listview will be printed by this printer?"),
+ DefaultValue(null)]
+ public ListView ListView
+ {
+ get { return listView; }
+ set { listView = value; }
+ }
+ private ListView listView;
+
+ ///
+ /// Should this report use text only?
+ ///
+ [Category("Behaviour"),
+ Description("Should this report use text only? If this is false, images on the primary column will be included."),
+ DefaultValue(false)]
+ public bool IsTextOnly
+ {
+ get { return isTextOnly; }
+ set { isTextOnly = value; }
+ }
+ private bool isTextOnly = false;
+
+ ///
+ /// Should this report be shrunk to fit into the width of a page?
+ ///
+ [Category("Behaviour"),
+ Description("Should this report be shrunk to fit into the width of a page?"),
+ DefaultValue(true)]
+ public bool IsShrinkToFit
+ {
+ get { return isShrinkToFit; }
+ set { isShrinkToFit = value; }
+ }
+ private bool isShrinkToFit = true;
+
+ ///
+ /// Should this report only include the selected rows in the listview?
+ ///
+ [Category("Behaviour"),
+ Description("Should this report only include the selected rows in the listview?"),
+ DefaultValue(false)]
+ public bool IsPrintSelectionOnly
+ {
+ get { return isPrintSelectionOnly; }
+ set { isPrintSelectionOnly = value; }
+ }
+ private bool isPrintSelectionOnly = false;
+
+ ///
+ /// Should this report use the column order as the user sees them? With this enabled,
+ /// the report will match the order of column as the user has arranged them.
+ ///
+ [Category("Behaviour"),
+ Description("Should this report use the column order as the user sees them? With this enabled, the report will match the order of column as the user has arranged them."),
+ DefaultValue(true)]
+ public bool UseColumnDisplayOrder
+ {
+ get { return useColumnDisplayOrder; }
+ set { useColumnDisplayOrder = value; }
+ }
+ private bool useColumnDisplayOrder = true;
+
+ ///
+ /// Should column headings always be centered, even if on the control itself, they are
+ /// aligned to the left or right?
+ ///
+ [Category("Behaviour"),
+ Description("Should column headings always be centered or should they follow the alignment on the control itself?"),
+ DefaultValue(true)]
+ public bool AlwaysCenterListHeader
+ {
+ get { return slwaysCenterListHeader; }
+ set { slwaysCenterListHeader = value; }
+ }
+ private bool slwaysCenterListHeader = true;
+
+ ///
+ /// Should listview headings be printed at the top of each page, or just at the top of the list?
+ ///
+ [Category("Behaviour"),
+ Description("Should listview headings be printed at the top of each page, or just at the top of the list?"),
+ DefaultValue(true)]
+ public bool IsListHeaderOnEachPage
+ {
+ get { return isListHeaderOnEachPage; }
+ set { isListHeaderOnEachPage = value; }
+ }
+ private bool isListHeaderOnEachPage = true;
+
+ ///
+ /// Return the index of the first page of the report that should be printed
+ ///
+ [Category("Behaviour"),
+ Description("Return the first page of the report that should be printed"),
+ DefaultValue(0)]
+ public int FirstPage
+ {
+ get { return firstPage; }
+ set { firstPage = value; }
+ }
+ private int firstPage = 0;
+
+ ///
+ /// Return the index of the last page of the report that should be printed
+ ///
+ [Category("Behaviour"),
+ Description("Return the last page of the report that should be printed"),
+ DefaultValue(9999)]
+ public int LastPage
+ {
+ get { return lastPage; }
+ set { lastPage = value; }
+ }
+ private int lastPage = 9999;
+
+ ///
+ /// Return the number of the page that is currently being printed.
+ ///
+ [Browsable(false)]
+ public int PageNumber
+ {
+ get {
+ return this.pageNumber;
+ }
+ }
+
+ ///
+ /// Is this report showing groups?
+ ///
+ /// Groups can't be shown when we are printing selected rows only.
+ [Browsable(false)]
+ public bool IsShowingGroups
+ {
+ get {
+ return (this.ListView != null && this.ListView.ShowGroups && !this.IsPrintSelectionOnly && this.ListView.Groups.Count > 0);
+ }
+ }
+
+ #endregion
+
+ #region Formatting Properties
+
+ ///
+ /// How should the page header be formatted? null means no page header will be printed
+ ///
+ [Category("Appearance - Formatting"),
+ Description("How will the page header be formatted? "),
+ DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ public BlockFormat HeaderFormat
+ {
+ get { return headerFormat; }
+ set { headerFormat = value; }
+ }
+ private BlockFormat headerFormat;
+
+ ///
+ /// How should the list header be formatted? null means no list header will be printed
+ ///
+ [Category("Appearance - Formatting"),
+ Description("How will the header of the list be formatted? "),
+ DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ public BlockFormat ListHeaderFormat
+ {
+ get { return listHeaderFormat; }
+ set { listHeaderFormat = value; }
+ }
+ private BlockFormat listHeaderFormat;
+
+ ///
+ /// How should the grouping header be formatted? null means revert to reasonable default
+ ///
+ [Category("Appearance - Formatting"),
+ Description("How will the group headers be formatted?"),
+ DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ public BlockFormat GroupHeaderFormat
+ {
+ get {
+ // The group header format cannot be null
+ if (groupHeaderFormat == null)
+ groupHeaderFormat = BlockFormat.GroupHeader();
+
+ return groupHeaderFormat;
+ }
+ set { groupHeaderFormat = value; }
+ }
+ private BlockFormat groupHeaderFormat;
+
+ ///
+ /// How should the list cells be formatted? null means revert to default
+ ///
+ [Category("Appearance - Formatting"),
+ Description("How will the list cells be formatted? "),
+ DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ public BlockFormat CellFormat
+ {
+ get {
+ // The cell format cannot be null
+ if (cellFormat == null)
+ cellFormat = BlockFormat.DefaultCell();
+
+ return cellFormat;
+ }
+ set {
+ cellFormat = value;
+ }
+ }
+ private BlockFormat cellFormat;
+
+ ///
+ /// How should the page footer be formatted? null means no footer will be printed
+ ///
+ [Category("Appearance - Formatting"),
+ Description("How will the page footer be formatted?"),
+ DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ public BlockFormat FooterFormat
+ {
+ get { return footerFormat; }
+ set { footerFormat = value; }
+ }
+ private BlockFormat footerFormat;
+
+ ///
+ /// What font will be used to draw the text of the list?
+ ///
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public Font ListFont
+ {
+ get { return this.CellFormat.Font; }
+ set { this.CellFormat.Font = value; }
+ }
+
+ ///
+ /// What pen will be used to draw the cells within the list?
+ /// If this is null, no grid will be drawn
+ ///
+ /// This is just a conviencence wrapper around CellFormat.SetBorderPen
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public Pen ListGridPen
+ {
+ get { return this.CellFormat.GetBorderPen(Sides.Top); }
+ set { this.CellFormat.SetBorderPen(Sides.All, value); }
+ }
+
+ ///
+ /// What string will be written at the top of each page of the report?
+ ///
+ /// The header can be divided into three parts: left aligned,
+ /// centered, and right aligned. If the given string contains Tab characters,
+ /// everything before the first tab will be left aligned, everything between
+ /// the first and second tabs will be centered and everything after the second
+ /// tab will be right aligned.
+ /// Within each part, the following substitutions are possible:
+ ///
+ /// - {0} - The page number
+ /// - {1} - The current date/time
+ ///
+ ///
+ [Category("Appearance"),
+ Description("The string that will be written at the top of each page. Use '\\t' characters to separate left, centre, and right parts of the header."),
+ DefaultValue(null)]
+ public String Header
+ {
+ get { return header; }
+ set {
+ header = value;
+ if (!String.IsNullOrEmpty(header))
+ header = header.Replace("\\t", "\t");
+ }
+ }
+ private String header;
+
+ ///
+ /// What string will be written at the bottom of each page of the report?
+ ///
+ /// The footer, like the header, can have three parts, and behaves
+ /// in the same way as described as Header.
+ [Category("Appearance"),
+ Description("The string that will be written at the bottom of each page. Use '\\t' characters to separate left, centre, and right parts of the footer."),
+ DefaultValue(null)]
+ public String Footer
+ {
+ get { return footer; }
+ set {
+ footer = value;
+ if (!String.IsNullOrEmpty(footer))
+ footer = footer.Replace("\\t", "\t");
+ }
+ }
+ private String footer;
+
+ //-----------------------------------------------------------------------
+ // Watermark
+
+ ///
+ /// The watermark will be printed translucently over the report itself
+ ///
+ [Category("Appearance - Watermark"),
+ Description("The watermark will be printed translucently over the report itself?"),
+ DefaultValue(null)]
+ public String Watermark
+ {
+ get { return watermark; }
+ set { watermark = value; }
+ }
+ private String watermark;
+
+ ///
+ /// What font should be used to print the watermark
+ ///
+ [Category("Appearance - Watermark"),
+ Description("What font should be used to print the watermark?"),
+ DefaultValue(null)]
+ public Font WatermarkFont
+ {
+ get { return watermarkFont; }
+ set { watermarkFont = value; }
+ }
+ private Font watermarkFont;
+
+ ///
+ /// Return the watermark font or a reasonable default
+ ///
+ [Browsable(false)]
+ public Font WatermarkFontOrDefault
+ {
+ get {
+ if (this.WatermarkFont == null)
+ return new Font("Tahoma", 72);
+ else
+ return this.WatermarkFont;
+ }
+ }
+
+ ///
+ /// What color should be used for the watermark?
+ ///
+ [Category("Appearance - Watermark"),
+ Description("What foregroundColor should be used for the watermark?"),
+ DefaultValue(typeof(Color), "")]
+ public Color WatermarkColor
+ {
+ get { return watermarkColor; }
+ set { watermarkColor = value; }
+ }
+ private Color watermarkColor = Color.Empty;
+
+ ///
+ /// Return the color of the watermark or a reasonable default
+ ///
+ [Browsable(false)]
+ public Color WatermarkColorOrDefault
+ {
+ get {
+ if (this.WatermarkColor == Color.Empty)
+ return Color.Gray;
+ else
+ return this.WatermarkColor;
+ }
+ }
+
+ ///
+ /// How transparent should the watermark be? <= 0 is transparent, >= 100 is completely opaque.
+ ///
+ [Category("Appearance - Watermark"),
+ Description("How transparent should the watermark be? 0 is transparent, 100 is completely opaque."),
+ DefaultValue(50)]
+ public int WatermarkTransparency
+ {
+ get { return watermarkTransparency; }
+ set { watermarkTransparency = Math.Max(0, Math.Min(value, 100)); }
+ }
+ private int watermarkTransparency = 50;
+
+ #endregion
+
+ #region Accessing
+
+ ///
+ /// Return the number of rows that this printer is going to print
+ ///
+ /// The listview that is being printed
+ /// The number of rows that will be displayed
+ protected int GetRowCount(ListView lv)
+ {
+ if (this.IsPrintSelectionOnly)
+ return lv.SelectedIndices.Count;
+ else
+ if (lv.VirtualMode)
+ return lv.VirtualListSize;
+ else
+ return lv.Items.Count;
+ }
+
+ ///
+ /// Return the n'th row that will be printed
+ ///
+ /// The listview that is being printed
+ /// The index of the row to be printed
+ /// A ListViewItem
+ protected ListViewItem GetRow(ListView lv, int n)
+ {
+ if (this.IsPrintSelectionOnly)
+ if (lv.VirtualMode)
+ return this.GetVirtualItem(lv, lv.SelectedIndices[n]);
+ else
+ return lv.SelectedItems[n];
+
+ if (!this.IsShowingGroups)
+ if (lv.VirtualMode)
+ return this.GetVirtualItem(lv, n);
+ else
+ return lv.Items[n];
+
+ // If we are showing groups, things are more complicated. The n'th
+ // row of the report doesn't directly correspond to existing list.
+ // The best we can do is figure out which group the n'th item belongs to
+ // and then figure out which item it is within the groups items.
+ int i;
+ for (i = this.groupStartPositions.Count - 1; i >= 0; i--)
+ if (n >= this.groupStartPositions[i])
+ break;
+ int indexInList = n - this.groupStartPositions[i];
+ return lv.Groups[i].Items[indexInList];
+ }
+
+ ///
+ /// Get the nth item from the given listview, which is in virtual mode.
+ ///
+ /// The ListView in virtual mode
+ /// index of item to get
+ /// the item
+ virtual protected ListViewItem GetVirtualItem(ListView lv, int n)
+ {
+ throw new ApplicationException("Virtual list items cannot be retrieved. Use an ObjectListView instead.");
+ }
+
+ ///
+ /// Return the i'th subitem of the given row, in the order
+ /// that coumns are presented in the report
+ ///
+ /// The row from which a subitem is to be fetched
+ /// The index of the subitem in display order
+ /// A SubItem
+ protected ListViewItem.ListViewSubItem GetSubItem(ListViewItem lvi, int i)
+ {
+ if (i < lvi.SubItems.Count)
+ return lvi.SubItems[this.GetColumn(i).Index];
+ else
+ return new ListViewItem.ListViewSubItem();
+ }
+
+ ///
+ /// Return the number of columns to be printed in the report
+ ///
+ /// An int
+ protected int GetColumnCount()
+ {
+ return this.sortedColumns.Count;
+ }
+
+ ///
+ /// Return the n'th ColumnHeader (ordered as they should be displayed in the report)
+ ///
+ /// Which column
+ /// A ColumnHeader
+ protected ColumnHeader GetColumn(int i)
+ {
+ return this.sortedColumns[i];
+ }
+
+ ///
+ /// Return the index of group that starts at the given position.
+ /// Return -1 if no group starts at that position
+ ///
+ /// The row position in the list
+ /// The group index
+ protected int GetGroupAtPosition(int n)
+ {
+ return this.groupStartPositions.IndexOf(n);
+ }
+
+ #endregion
+
+ #region Commands
+
+ ///
+ /// Show a Page Setup dialog to customize the printing of this document
+ ///
+ public void PageSetup()
+ {
+ PageSetupDialog dlg = new PageSetupDialog();
+ dlg.Document = this;
+ dlg.EnableMetric = true;
+ dlg.ShowDialog();
+ }
+
+ ///
+ /// Show a Print Preview of this document
+ ///
+ public void PrintPreview()
+ {
+ PrintPreviewDialog dlg = new PrintPreviewDialog();
+ dlg.UseAntiAlias = true;
+ dlg.Document = this;
+ dlg.ShowDialog();
+ }
+
+ ///
+ /// Print this document after showing a confirmation dialog
+ ///
+ public void PrintWithDialog()
+ {
+ PrintDialog dlg = new PrintDialog();
+ dlg.Document = this;
+ dlg.AllowSelection = this.ListView.SelectedIndices.Count > 0;
+ dlg.AllowSomePages = true;
+
+ // Show the standard print dialog box, that lets the user select a printer
+ // and change the settings for that printer.
+ if (dlg.ShowDialog() == DialogResult.OK) {
+ this.IsPrintSelectionOnly = (dlg.PrinterSettings.PrintRange == PrintRange.Selection);
+ if (dlg.PrinterSettings.PrintRange == PrintRange.SomePages) {
+ this.FirstPage = dlg.PrinterSettings.FromPage;
+ this.LastPage = dlg.PrinterSettings.ToPage;
+ } else {
+ this.FirstPage = 1;
+ this.LastPage = 999999;
+ }
+ this.Print();
+ }
+ }
+
+ #endregion
+
+ #region Event handlers
+
+ ///
+ /// A print job is about to be printed
+ ///
+ ///
+ override protected void OnBeginPrint(PrintEventArgs e)
+ {
+ base.OnBeginPrint(e);
+
+ // Initialize our state information
+ this.rowIndex = -1;
+ this.indexLeftColumn = -1;
+ this.indexRightColumn = -1;
+ this.pageNumber = 0;
+
+ // Initialize our caches
+ this.sortedColumns = new SortedList();
+ this.groupStartPositions = new List();
+
+ this.PreparePrint();
+ }
+
+ ///
+ /// Print a given page
+ ///
+ ///
+ override protected void OnPrintPage(PrintPageEventArgs e)
+ {
+ if (this.ListView == null || this.ListView.View != View.Details)
+ return;
+
+ base.OnPrintPage(e);
+
+ this.pageNumber++;
+
+ // Ignore all pages before the first requested page
+ // Have to allow for weird cases where the last page is before the first page
+ // and where we run out of things to print before reaching the first requested page.
+ int pageToStop = Math.Min(this.FirstPage, this.LastPage + 1);
+ if (this.pageNumber < pageToStop) {
+ e.HasMorePages = true;
+ while (this.pageNumber < pageToStop && e.HasMorePages) {
+ e.HasMorePages = this.PrintOnePage(e);
+ this.pageNumber++;
+ }
+
+ // Remove anything drawn
+ e.Graphics.Clear(Color.White);
+
+ // If we ran out of pages before reaching the first page, simply return
+ if (!e.HasMorePages)
+ return;
+ }
+
+ // If we haven't reached the end of the requested pages, print one.
+ if (this.pageNumber <= this.LastPage) {
+ e.HasMorePages = this.PrintOnePage(e);
+ e.HasMorePages = e.HasMorePages && (this.pageNumber < this.LastPage);
+ } else
+ e.HasMorePages = false;
+ }
+
+ #endregion
+
+ #region List printing
+
+ ///
+ /// Prepare some precalculated fields used when printing
+ ///
+ protected void PreparePrint()
+ {
+ if (this.ListView == null)
+ return;
+
+ // Build sortedColumn so it holds the column in the order they should be printed
+ foreach (ColumnHeader column in this.ListView.Columns) {
+ if (this.UseColumnDisplayOrder)
+ this.sortedColumns.Add(column.DisplayIndex, column);
+ else
+ this.sortedColumns.Add(column.Index, column);
+ }
+
+ // If the listview is grouped, build an array to holds the start
+ // position of each group. The way to understand this array is that
+ // the index of the first member of group n is found at groupStartPositions[n].
+ int itemCount = 0;
+ foreach (ListViewGroup lvg in this.ListView.Groups) {
+ this.groupStartPositions.Add(itemCount);
+ itemCount += lvg.Items.Count;
+ }
+ }
+
+ ///
+ /// Do the actual work of printing on page
+ ///
+ ///
+ protected bool PrintOnePage(PrintPageEventArgs e)
+ {
+ this.CalculateBounds(e);
+ this.CalculatePrintParameters(this.ListView);
+ this.PrintHeaderFooter(e.Graphics);
+ this.ApplyScaling(e.Graphics);
+ bool continuePrinting = this.PrintList(e.Graphics, this.ListView);
+ this.PrintWatermark(e.Graphics);
+ return continuePrinting;
+ }
+
+ ///
+ /// Figure out the page bounds and the boundaries for the list
+ ///
+ ///
+ protected void CalculateBounds(PrintPageEventArgs e)
+ {
+ // Printing to a real printer doesn't take the printers hard margins into account
+ if (this.PrintController.IsPreview)
+ this.pageBounds = (RectangleF)e.MarginBounds;
+ else
+ this.pageBounds = new RectangleF(e.MarginBounds.X - e.PageSettings.HardMarginX,
+ e.MarginBounds.Y - e.PageSettings.HardMarginY, e.MarginBounds.Width, e.MarginBounds.Height);
+
+ this.listBounds = this.pageBounds;
+ }
+
+ ///
+ /// Figure out the boundaries for various aspects of the report
+ ///
+ /// The listview to be printed
+ protected void CalculatePrintParameters(ListView lv)
+ {
+ // If we are in the middle of printing a listview, don't change the parameters
+ if (this.rowIndex >= 0 && this.rowIndex < this.GetRowCount(lv))
+ return;
+
+ this.rowIndex = 0;
+
+ // If we are shrinking the report to fit on the page...
+ if (this.IsShrinkToFit) {
+
+ // ...we print all the columns, but we need to figure how much to shrink
+ // them so that they will fit onto the page
+ this.indexLeftColumn = 0;
+ this.indexRightColumn = this.GetColumnCount() - 1;
+
+ int totalWidth = 0;
+ for (int i = 0; i < this.GetColumnCount(); i++) {
+ totalWidth += this.GetColumn(i).Width;
+ }
+ this.scaleFactor = Math.Min(this.listBounds.Width / totalWidth, 1.0f);
+ } else {
+ // ...otherwise, we print unscaled but have to figure out which columns
+ // will fit on the current page
+ this.scaleFactor = 1.0f;
+ this.indexLeftColumn = ++this.indexRightColumn;
+
+ // Iterate the columns until we find a column that won't fit on the page
+ int width = 0;
+ for (int i = this.indexLeftColumn; i < this.GetColumnCount() && (width += this.GetColumn(i).Width) < this.listBounds.Width; i++)
+ this.indexRightColumn = i;
+ }
+ }
+
+ ///
+ /// Apply any scaling that is required to the report
+ ///
+ ///
+ protected void ApplyScaling(Graphics g)
+ {
+ if (this.scaleFactor >= 1.0f)
+ return;
+
+ g.ScaleTransform(this.scaleFactor, this.scaleFactor);
+
+ float inverse = 1.0f / this.scaleFactor;
+ this.listBounds = new RectangleF(this.listBounds.X * inverse, this.listBounds.Y * inverse, this.listBounds.Width * inverse, this.listBounds.Height * inverse);
+ }
+
+ ///
+ /// Print our watermark on the given Graphic
+ ///
+ ///
+ protected void PrintWatermark(Graphics g)
+ {
+ if (String.IsNullOrEmpty(this.Watermark))
+ return;
+
+ StringFormat strFormat = new StringFormat();
+ strFormat.LineAlignment = StringAlignment.Center;
+ strFormat.Alignment = StringAlignment.Center;
+
+ // THINK: Do we want this to be a property?
+ int watermarkRotation = -30;
+
+ // Setup a rotation transform on the Graphic so we can write the watermark at an angle
+ g.ResetTransform();
+ Matrix m = new Matrix();
+ m.RotateAt(watermarkRotation, new PointF(this.pageBounds.X + this.pageBounds.Width / 2, this.pageBounds.Y + this.pageBounds.Height / 2));
+ g.Transform = m;
+
+ // Calculate the semi-transparent pen required to print the watermark
+ int alpha = (int)(255.0f * (float)this.WatermarkTransparency / 100.0f);
+ Brush brush = new SolidBrush(Color.FromArgb(alpha, this.WatermarkColorOrDefault));
+
+ // Finally draw the watermark
+ g.DrawString(this.Watermark, this.WatermarkFontOrDefault, brush, this.pageBounds, strFormat);
+ g.ResetTransform();
+ }
+
+ ///
+ /// Do the work of printing the list into 'listBounds'
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ /// Return true if there are still more pages in the report
+ protected bool PrintList(Graphics g, ListView lv)
+ {
+ this.currentOrigin = this.listBounds.Location;
+
+ if (this.rowIndex == 0 || this.IsListHeaderOnEachPage)
+ this.PrintListHeader(g, lv);
+
+ this.PrintRows(g, lv);
+
+ // We continue to print pages when we have more rows or more columns remaining
+ return (this.rowIndex < this.GetRowCount(lv) || this.indexRightColumn + 1 < this.GetColumnCount());
+ }
+
+ ///
+ /// Print the header of the listview
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ protected void PrintListHeader(Graphics g, ListView lv)
+ {
+ // If there is no format for the header, we don't draw it
+ BlockFormat fmt = this.ListHeaderFormat;
+ if (fmt == null)
+ return;
+
+ // Calculate the height of the list header
+ float height = 0;
+ for (int i = 0; i < this.GetColumnCount(); i++) {
+ ColumnHeader col = this.GetColumn(i);
+ height = Math.Max(height, fmt.CalculateHeight(g, col.Text, col.Width));
+ }
+
+ // Draw the header one cell at a time
+ RectangleF cell = new RectangleF(this.currentOrigin.X, this.currentOrigin.Y, 0, height);
+ for (int i = this.indexLeftColumn; i <= this.indexRightColumn; i++) {
+ ColumnHeader col = this.GetColumn(i);
+ cell.Width = col.Width;
+ fmt.Draw(g, cell, col.Text, (this.AlwaysCenterListHeader ? HorizontalAlignment.Center : col.TextAlign));
+ cell.Offset(cell.Width, 0);
+ }
+
+ this.currentOrigin.Y += cell.Height;
+ }
+
+ ///
+ /// Print the rows of the listview
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ protected void PrintRows(Graphics g, ListView lv)
+ {
+ while (this.rowIndex < this.GetRowCount(lv)) {
+
+ // Will this row fit before the end of page?
+ float rowHeight = this.CalculateRowHeight(g, lv, this.rowIndex);
+ if (this.currentOrigin.Y + rowHeight > this.listBounds.Bottom)
+ break;
+
+ // If we are printing group and there is a group begining at the current position,
+ // print it so long as the group header and at least one following row will fit on the page
+ if (this.IsShowingGroups) {
+ int groupIndex = this.GetGroupAtPosition(this.rowIndex);
+ if (groupIndex != -1) {
+ float groupHeaderHeight = this.GroupHeaderFormat.CalculateHeight(g);
+ if (this.currentOrigin.Y + groupHeaderHeight + rowHeight < this.listBounds.Bottom) {
+ this.PrintGroupHeader(g, lv, groupIndex);
+ } else {
+ this.currentOrigin.Y = this.listBounds.Bottom;
+ break;
+ }
+ }
+ }
+ this.PrintRow(g, lv, this.rowIndex, rowHeight);
+ this.rowIndex++;
+ }
+ }
+
+ ///
+ /// Calculate how high the given row of the report should be.
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ /// The index of the row whose height is to be calculated
+ /// The height of one row in pixels
+ virtual protected float CalculateRowHeight(Graphics g, ListView lv, int n)
+ {
+ // If we're including graphics in the report, we need to allow for the height of a small image
+ if (!this.IsTextOnly && lv.SmallImageList != null)
+ this.CellFormat.MinimumTextHeight = lv.SmallImageList.ImageSize.Height;
+
+ // If the cell lines can't wrap, calculate the generic height of the row
+ if (!this.CellFormat.CanWrap)
+ return this.CellFormat.CalculateHeight(g);
+
+ // If the cell lines can wrap, calculate the height of the tallest cell
+ float height = 0f;
+ ListViewItem lvi = this.GetRow(lv, n);
+ for (int i = 0; i < this.GetColumnCount(); i++) {
+ ColumnHeader column = this.GetColumn(i);
+ int colWidth = column.Width;
+ if (!this.IsTextOnly && column.Index == 0 && lv.SmallImageList != null && lvi.ImageIndex != -1)
+ colWidth -= lv.SmallImageList.ImageSize.Width;
+
+ // If we are using an specialized renderer in an ObjectListView, it could do anything
+ // with the Text value (e.g. it could be a BLOB that is presented as an Image).
+ // So we ignore it, and hope that the height of the row can be calculated from
+ // the other cells in the row.
+ OLVColumn olvc = column as OLVColumn;
+ if (olvc == null || !(olvc.Renderer is BaseRenderer))
+ height = Math.Max(height, this.CellFormat.CalculateHeight(g, this.GetSubItem(lvi, i).Text, colWidth));
+ }
+ return height;
+ }
+
+ ///
+ /// Print a group header
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ /// The index of the group header to be printed
+ protected void PrintGroupHeader(Graphics g, ListView lv, int groupIndex)
+ {
+ ListViewGroup lvg = lv.Groups[groupIndex];
+ BlockFormat fmt = this.GroupHeaderFormat;
+ float height = fmt.CalculateHeight(g);
+ RectangleF r = new RectangleF(this.currentOrigin.X, this.currentOrigin.Y, this.listBounds.Width, height);
+ fmt.Draw(g, r, lvg.Header, lvg.HeaderAlignment);
+ this.currentOrigin.Y += height;
+ }
+
+ ///
+ /// Print one row of the listview
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected void PrintRow(Graphics g, ListView lv, int row, float rowHeight)
+ {
+ ListViewItem lvi = this.GetRow(lv, row);
+
+ // Print the row cell by cell. We only print the cells that are in the range
+ // of columns that are chosen for this page
+ RectangleF cell = new RectangleF(this.currentOrigin, new SizeF(0, rowHeight));
+ for (int i = this.indexLeftColumn; i <= this.indexRightColumn; i++) {
+ ColumnHeader col = this.GetColumn(i);
+ cell.Width = col.Width;
+ this.PrintCell(g, lv, lvi, row, i, cell);
+ cell.Offset(cell.Width, 0);
+ }
+ this.currentOrigin.Y += rowHeight;
+ }
+
+ ///
+ /// Print one cell of the listview
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ virtual protected void PrintCell(Graphics g, ListView lv, ListViewItem lvi, int row, int column, RectangleF cell)
+ {
+ BlockFormat fmt = this.CellFormat;
+ ColumnHeader ch = this.GetColumn(column);
+
+ // Are we going to print an icon in this cell? We print an image if it
+ // isn't a text only report AND it is a primary column AND the cell has an image and a image list.
+ if (!this.IsTextOnly && ch.Index == 0 && lvi.ImageIndex != -1 && lv.SmallImageList != null) {
+ // Trick the block format into indenting the text so it doesn't write the text into where the image is going to be drawn
+ const int gapBetweenImageAndText = 3;
+ float textInsetCorrection = lv.SmallImageList.ImageSize.Width + gapBetweenImageAndText;
+ fmt.SetTextInset(Sides.Left, fmt.GetTextInset(Sides.Left) + textInsetCorrection);
+ fmt.Draw(g, cell, this.GetSubItem(lvi, column).Text, ch.TextAlign);
+ fmt.SetTextInset(Sides.Left, fmt.GetTextInset(Sides.Left) - textInsetCorrection);
+
+ // Now draw the image into the area reserved for it
+ RectangleF r = fmt.CalculatePaddedTextBox(cell);
+ if (lv.SmallImageList.ImageSize.Height < r.Height)
+ r.Y += (r.Height - lv.SmallImageList.ImageSize.Height) / 2;
+ g.DrawImage(lv.SmallImageList.Images[lvi.ImageIndex], r.Location);
+ } else {
+ // No image to draw. SImply draw the text
+ fmt.Draw(g, cell, this.GetSubItem(lvi, column).Text, ch.TextAlign);
+ }
+ }
+
+ ///
+ /// Print the page header and page footer
+ ///
+ ///
+ protected void PrintHeaderFooter(Graphics g)
+ {
+ if (!String.IsNullOrEmpty(this.Header))
+ PrintPageHeader(g);
+
+ if (!String.IsNullOrEmpty(this.Footer))
+ PrintPageFooter(g);
+ }
+
+ ///
+ /// Print the page header
+ ///
+ ///
+ protected void PrintPageHeader(Graphics g)
+ {
+ BlockFormat fmt = this.HeaderFormat;
+ if (fmt == null)
+ return;
+
+ float height = fmt.CalculateHeight(g);
+ RectangleF headerRect = new RectangleF(this.listBounds.X, this.listBounds.Y, this.listBounds.Width, height);
+ fmt.Draw(g, headerRect, this.SplitAndFormat(this.Header));
+
+ // Move down the top of the area available for the list
+ this.listBounds.Y += height;
+ this.listBounds.Height -= height;
+ }
+
+ ///
+ /// Print the page footer
+ ///
+ ///
+ protected void PrintPageFooter(Graphics g)
+ {
+ BlockFormat fmt = this.FooterFormat;
+ if (fmt == null)
+ return;
+
+ float height = fmt.CalculateHeight(g);
+ RectangleF r = new RectangleF(this.listBounds.X, this.listBounds.Bottom - height, this.listBounds.Width, height);
+ fmt.Draw(g, r, this.SplitAndFormat(this.Footer));
+
+ // Decrease the area available for the list
+ this.listBounds.Height -= height;
+ }
+
+ ///
+ /// Split the given string into at most three parts, using Tab as the divider.
+ /// Perform any substitutions required
+ ///
+ ///
+ ///
+ private String[] SplitAndFormat(String text)
+ {
+ String s = String.Format(text, this.pageNumber, DateTime.Now);
+ return s.Split(new Char[] { '\x09' }, 3);
+ }
+
+ #endregion
+
+ #region Compatibility
+
+ ///
+ /// What color will all the borders be drawn in?
+ ///
+ /// This is just a conviencence wrapper around ListGridPen
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use ListGridPen instead")]
+ public Color ListGridColor
+ {
+ get
+ {
+ Pen p = this.ListGridPen;
+ if (p == null)
+ return Color.Empty;
+ else
+ return p.Color;
+ }
+ set
+ {
+ this.ListGridPen = new Pen(new SolidBrush(value), 0.5f);
+ }
+ }
+
+ #endregion
+
+ #region Private variables
+
+ // These are our state variables.
+ private int rowIndex;
+ private int indexLeftColumn;
+ private int indexRightColumn;
+ private int pageNumber;
+
+ // Cached values
+ private SortedList sortedColumns;
+ private List groupStartPositions;
+
+ // Per-page variables
+ private RectangleF pageBounds;
+ private RectangleF listBounds;
+ private PointF currentOrigin;
+ private float scaleFactor;
+
+ #endregion
+ }
+
+ ///
+ /// This ListViewPrinterBase handles only normal ListViews, while this class knows about the specifics of ObjectListViews
+ ///
+ public class ListViewPrinter : ListViewPrinterBase
+ {
+ ///
+ /// Make a ListViewPrinter
+ ///
+ public ListViewPrinter()
+ {
+ }
+
+#if !WITHOUT_OBJECTLISTVIEW
+ ///
+ /// Get the nth item from the given listview, which is in virtual mode.
+ ///
+ /// The ListView in virtual mode
+ /// index of item to get
+ /// the item
+ override protected ListViewItem GetVirtualItem(ListView lv, int n)
+ {
+ return ((VirtualObjectListView)lv).MakeListViewItem(n);
+ }
+
+ ///
+ /// Calculate how high each row of the report should be.
+ ///
+ /// The graphic used for drawing
+ /// The listview to be printed
+ ///
+ /// The height of one row in pixels
+ override protected float CalculateRowHeight(Graphics g, ListView lv, int n)
+ {
+ float height = base.CalculateRowHeight(g, lv, n);
+ if (lv is ObjectListView)
+ height = Math.Max(height, ((ObjectListView)lv).RowHeightEffective);
+ return height;
+ }
+
+ ///
+ /// If the given BlockFormat doesn't specify a background, take it from the SubItem or the ListItem.
+ ///
+ protected bool ApplyCellSpecificBackground(BlockFormat fmt, ListViewItem lvi, ListViewItem.ListViewSubItem lvsi)
+ {
+ if (fmt.BackgroundBrush != null)
+ return false;
+
+ if (lvi.UseItemStyleForSubItems)
+ fmt.BackgroundBrush = new SolidBrush(lvi.BackColor);
+ else
+ fmt.BackgroundBrush = new SolidBrush(lvsi.BackColor);
+
+ return true;
+ }
+
+ ///
+ /// Print one cell of the ListView
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected override void PrintCell(Graphics g, ListView lv, ListViewItem lvi, int row, int column, RectangleF cell)
+ {
+ if (this.IsTextOnly || !(lv is ObjectListView)) {
+ base.PrintCell(g, lv, lvi, row, column, cell);
+ return;
+ }
+
+ OLVColumn olvc = (OLVColumn)this.GetColumn(column);
+ BaseRenderer renderer = olvc.Renderer as BaseRenderer;
+ if (renderer == null)
+ renderer = ((ObjectListView)lv).DefaultRenderer as BaseRenderer;
+
+ // We couldn't find a renderer we could use. Just use the default rendering
+ if (renderer == null) {
+ base.PrintCell(g, lv, lvi, row, column, cell);
+ return;
+ }
+
+ renderer.IsPrinting = true;
+ renderer.Aspect = null;
+ renderer.Column = olvc;
+ renderer.IsItemSelected = false;
+ renderer.Font = this.CellFormat.Font;
+ renderer.TextBrush = this.CellFormat.TextBrush;
+ renderer.ListItem = (OLVListItem)lvi;
+ renderer.ListView = (ObjectListView)lv;
+ renderer.RowObject = ((OLVListItem)lvi).RowObject;
+ renderer.SubItem = (OLVListSubItem)this.GetSubItem(lvi, column);
+ renderer.CanWrap = this.CellFormat.CanWrap;
+
+ // Use the cell block format to draw the background and border of the cell
+ bool bkChanged = this.ApplyCellSpecificBackground(this.CellFormat, renderer.ListItem, renderer.SubItem);
+ this.CellFormat.Draw(g, cell, "", "", "");
+ if (bkChanged)
+ this.CellFormat.BackgroundBrush = null;
+
+ // The renderer draws into the text area of the block. Unfortunately, the renderer uses Rectangle's
+ // rather than RectangleF's, so we have to convert, trying to prevent rounding errors
+ RectangleF r = this.CellFormat.CalculatePaddedTextBox(cell);
+ Rectangle r2 = new Rectangle((int)r.X + 1, (int)r.Y + 1, (int)r.Width - 1, (int)r.Height - 1);
+ renderer.Render(g, r2);
+
+ renderer.IsPrinting = false;
+ }
+#endif
+ }
+
+ ///
+ /// Specify which sides of a block will be operated on
+ ///
+ public enum Sides
+ {
+ ///
+ /// Left
+ ///
+ Left = 0,
+
+ ///
+ /// Top
+ ///
+ Top = 1,
+
+ ///
+ /// Right
+ ///
+ Right = 2,
+
+ ///
+ /// Bottom
+ ///
+ Bottom = 3,
+
+ ///
+ /// All
+ ///
+ All = 4
+ }
+
+ ///
+ /// A BlockFormat controls the formatting and style of a single part (block) of a
+ /// ListViewPrinter output.
+ ///
+ public class BlockFormat : System.ComponentModel.Component
+ {
+ #region Public properties
+
+ ///
+ /// In what font should the text of the block be drawn? If this is null, the font from the listview will be used
+ ///
+ [Category("Appearance"),
+ Description("What font should this block be drawn in?"),
+ DefaultValue(null)]
+ public Font Font
+ {
+ get { return font; }
+ set { font = value; }
+ }
+ private Font font;
+
+ ///
+ /// Return the font that should be used for the text of this block or a reasonable default
+ ///
+ [Browsable(false)]
+ public Font FontOrDefault
+ {
+ get {
+ if (this.Font == null)
+ return new Font("Ms Sans Serif", 12);
+ else
+ return this.Font;
+ }
+ }
+
+ ///
+ /// What brush will be used to draw the text?
+ ///
+ ///
+ /// If this format is used for cells and this is null AND an ObjectListView is being printed,
+ /// then the text color from the listview will be used.
+ /// This is useful when you have setup specific colors on a RowFormatter delegate, for example.
+ ///
+ ///
+ public Brush TextBrush;
+
+ ///
+ /// This object is used by the IDE to set the text brush.
+ ///
+ [Category("Appearance"),
+ DisplayName("TextBrush"),
+ DefaultValue(null)]
+ public IBrushData TextBrushData
+ {
+ get {
+ return textBrushData;
+ }
+ set {
+ textBrushData = value;
+ if (value != null)
+ this.TextBrush = value.GetBrush();
+ }
+ }
+ private IBrushData textBrushData;
+
+ ///
+ /// Return the brush that will be used to draw the text or a reasonable default
+ ///
+ [Browsable(false)]
+ public Brush TextBrushOrDefault
+ {
+ get {
+ if (this.TextBrush == null)
+ return Brushes.Black;
+ else
+ return this.TextBrush;
+ }
+ }
+
+ ///
+ /// What brush will be used to paint the background?
+ ///
+ [Browsable(false)]
+ public Brush BackgroundBrush;
+
+ ///
+ /// This object is used by the IDE to set the background brush.
+ ///
+ [Category("Appearance"),
+ DisplayName("BackgroundBrush"),
+ DefaultValue(null)]
+ public IBrushData BackgroundBrushData
+ {
+ get {
+ return backgroundBrushData;
+ }
+ set {
+ backgroundBrushData = value;
+ if (value != null)
+ this.BackgroundBrush = value.GetBrush();
+ }
+ }
+ private IBrushData backgroundBrushData;
+
+ ///
+ /// When laying out our header can the text be wrapped?
+ ///
+ [Category("Appearance"),
+ Description("When laying out our header can the text be wrapped?"),
+ DefaultValue(false)]
+ public bool CanWrap
+ {
+ get { return canWrap; }
+ set { canWrap = value; }
+ }
+ private bool canWrap = false;
+
+ ///
+ /// If this is set, at least this much vertical space will be reserved for the text,
+ /// even if the text is smaller.
+ ///
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public float MinimumTextHeight
+ {
+ get { return minimumTextHeight; }
+ set { minimumTextHeight = value; }
+ }
+ private float minimumTextHeight = 0;
+
+ //----------------------------------------------------------------------------------
+ // All of these attributes are solely to make them appear in the IDE
+ // When programming by hand, use Get/SetBorderPen()
+ // rather than these methods.
+
+ ///
+ /// Set the TopBorder
+ ///
+ [Category("Appearance"),
+ DisplayName("Border - Top"),
+ DefaultValue(null)]
+ public PenData TopBorderPenData
+ {
+ get { return topBorderPenData; }
+ set {
+ topBorderPenData = value;
+ if (value != null)
+ this.SetBorderPen(Sides.Top, value.GetPen());
+ }
+ }
+ private PenData topBorderPenData;
+
+ ///
+ /// Set the LeftBorder
+ ///
+ [Category("Appearance"),
+ DisplayName("Border - Left"),
+ DefaultValue(null)]
+ public PenData LeftBorderPenData
+ {
+ get { return leftBorderPenData; }
+ set {
+ leftBorderPenData = value;
+ if (value != null)
+ this.SetBorderPen(Sides.Left, value.GetPen());
+ }
+ }
+ private PenData leftBorderPenData;
+
+ ///
+ /// Set the BottomBorder
+ ///
+ [Category("Appearance"),
+ DisplayName("Border - Bottom"),
+ DefaultValue(null)]
+ public PenData BottomBorderPenData
+ {
+ get { return bottomBorderPenData; }
+ set {
+ bottomBorderPenData = value;
+ if (value != null)
+ this.SetBorderPen(Sides.Bottom, value.GetPen());
+ }
+ }
+ private PenData bottomBorderPenData;
+
+ ///
+ /// Set the RightBorder
+ ///
+ [Category("Appearance"),
+ DisplayName("Border - Right"),
+ DefaultValue(null)]
+ public PenData RightBorderPenData
+ {
+ get { return rightBorderPenData; }
+ set {
+ rightBorderPenData = value;
+ if (value != null)
+ this.SetBorderPen(Sides.Right, value.GetPen());
+ }
+ }
+ private PenData rightBorderPenData;
+
+ ///
+ /// Set the RightBorder
+ ///
+ [Category("Appearance"),
+ DisplayName("Border - All"),
+ DefaultValue(null)]
+ public PenData AllBorderPenData
+ {
+ get {
+ if (leftBorderPenData == topBorderPenData &&
+ leftBorderPenData == rightBorderPenData &&
+ leftBorderPenData == bottomBorderPenData)
+ return leftBorderPenData;
+ else
+ return null;
+ }
+ set {
+ this.LeftBorderPenData = value;
+ this.TopBorderPenData = value;
+ this.RightBorderPenData = value;
+ this.BottomBorderPenData = value;
+ }
+ }
+
+ #endregion
+
+ #region Compatibilty
+
+ ///
+ /// What color will be used to draw the background?
+ /// This is a convience method used by the IDE.
+ ///
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use BackgroundBrush instead")]
+ public Color BackgroundColor
+ {
+ get
+ {
+ if (this.BackgroundBrush == null || !(this.BackgroundBrush is SolidBrush))
+ return Color.Empty;
+ else
+ return ((SolidBrush)this.BackgroundBrush).Color;
+ }
+ set
+ {
+ this.BackgroundBrush = new SolidBrush(value);
+ }
+ }
+
+ ///
+ /// What color will be used to draw the text?
+ /// This is a convience method. Programmers should call TextBrush directly.
+ ///
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public Color TextColor
+ {
+ get
+ {
+ if (this.TextBrush == null || !(this.TextBrush is SolidBrush))
+ return Color.Empty;
+ else
+ return ((SolidBrush)this.TextBrush).Color;
+ }
+ set
+ {
+ if (value.IsEmpty)
+ this.TextBrush = null;
+ else
+ this.TextBrush = new SolidBrush(value);
+ }
+ }
+
+ //----------------------------------------------------------------------------------
+ // All of these attributes are solely to make them appear in the IDE
+ // When programming by hand, use Get/SetBorderPen() rather than these methods.
+
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public float TopBorderWidth
+ {
+ get { return this.GetBorderWidth(Sides.Top); }
+ set { this.SetBorder(Sides.Top, value, this.GetBorderBrush(Sides.Top)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public float LeftBorderWidth
+ {
+ get { return this.GetBorderWidth(Sides.Left); }
+ set { this.SetBorder(Sides.Left, value, this.GetBorderBrush(Sides.Left)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public float BottomBorderWidth
+ {
+ get { return this.GetBorderWidth(Sides.Bottom); }
+ set { this.SetBorder(Sides.Bottom, value, this.GetBorderBrush(Sides.Bottom)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public float RightBorderWidth
+ {
+ get { return this.GetBorderWidth(Sides.Right); }
+ set { this.SetBorder(Sides.Right, value, this.GetBorderBrush(Sides.Right)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public Color TopBorderColor
+ {
+ get { return this.GetSolidBorderColor(Sides.Top); }
+ set { this.SetBorder(Sides.Top, this.GetBorderWidth(Sides.Top), new SolidBrush(value)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public Color LeftBorderColor
+ {
+ get { return this.GetSolidBorderColor(Sides.Left); }
+ set { this.SetBorder(Sides.Left, this.GetBorderWidth(Sides.Left), new SolidBrush(value)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public Color BottomBorderColor
+ {
+ get { return this.GetSolidBorderColor(Sides.Bottom); }
+ set { this.SetBorder(Sides.Bottom, this.GetBorderWidth(Sides.Bottom), new SolidBrush(value)); }
+ }
+ [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Obsolete("Use Get/SetBorderPen() instead")]
+ public Color RightBorderColor
+ {
+ get { return this.GetSolidBorderColor(Sides.Right); }
+ set { this.SetBorder(Sides.Right, this.GetBorderWidth(Sides.Right), new SolidBrush(value)); }
+ }
+
+ private Color GetSolidBorderColor(Sides side)
+ {
+ Brush b = this.GetBorderBrush(side);
+ if (b != null && b is SolidBrush)
+ return ((SolidBrush)b).Color;
+ else
+ return Color.Empty;
+ }
+
+ #endregion
+
+ #region Accessing
+
+ ///
+ /// Get the padding for a particular side. 0 means no padding on that side.
+ /// Padding appears before the border does.
+ ///
+ /// Which side
+ /// The width of the padding
+ public float GetPadding(Sides side)
+ {
+ if (this.Padding.ContainsKey(side))
+ return this.Padding[side];
+ else
+ return 0.0f;
+ }
+
+ ///
+ /// Set the padding for a particular side. 0 means no padding on that side.
+ ///
+ /// Which side
+ /// How much padding
+ public void SetPadding(Sides side, float value)
+ {
+ if (side == Sides.All) {
+ this.Padding[Sides.Left] = value;
+ this.Padding[Sides.Top] = value;
+ this.Padding[Sides.Right] = value;
+ this.Padding[Sides.Bottom] = value;
+ } else
+ this.Padding[side] = value;
+ }
+
+ ///
+ /// Get the width of the border on a particular side. 0 means no border on that side.
+ ///
+ /// Which side
+ /// The width of the border
+ public Brush GetBorderBrush(Sides side)
+ {
+ Pen p = this.GetBorderPen(side);
+ if (p == null)
+ return null;
+ else
+ return p.Brush;
+ }
+
+ ///
+ /// Get the pen of the border on a particular side.
+ ///
+ /// Which side
+ /// The pen of the border
+ public Pen GetBorderPen(Sides side)
+ {
+ if (this.BorderPen.ContainsKey(side))
+ return this.BorderPen[side];
+ else
+ return null;
+ }
+
+ ///
+ /// Get the width of the border on a particular side. 0 means no border on that side.
+ ///
+ /// Which side
+ /// The width of the border
+ public float GetBorderWidth(Sides side)
+ {
+ Pen p = this.GetBorderPen(side);
+ if (p == null)
+ return 0;
+ else
+ return p.Width;
+ }
+
+ ///
+ /// Change the brush and width of the border on a particular side. 0 means no border on that side.
+ ///
+ /// Which side
+ /// How wide should it be?
+ /// What brush should be used to paint it
+ public void SetBorder(Sides side, float width, Brush brush)
+ {
+ this.SetBorderPen(side, new Pen(brush, width));
+ }
+
+ ///
+ /// Change the pen of the border on a particular side.
+ ///
+ /// Which side
+ /// What pen should be used to draw it
+ public void SetBorderPen(Sides side, Pen p)
+ {
+ if (side == Sides.All) {
+ this.areSideBorderEqual = true;
+ this.BorderPen[Sides.Left] = p;
+ this.BorderPen[Sides.Top] = p;
+ this.BorderPen[Sides.Right] = p;
+ this.BorderPen[Sides.Bottom] = p;
+ } else {
+ this.areSideBorderEqual = false;
+ this.BorderPen[side] = p;
+ }
+ }
+ private bool areSideBorderEqual = false;
+
+ ///
+ /// Get the distance that the text should be inset from the border on a given side
+ ///
+ /// Which side
+ /// Distance of text inset
+ public float GetTextInset(Sides side)
+ {
+ return GetKeyOrDefault(this.TextInset, side, 0f);
+ }
+
+ ///
+ /// Set the distance that the text should be inset from the border on a given side
+ ///
+ /// Which side
+ /// Distance of text inset
+ public void SetTextInset(Sides side, float value)
+ {
+ if (side == Sides.All) {
+ this.TextInset[Sides.Left] = value;
+ this.TextInset[Sides.Top] = value;
+ this.TextInset[Sides.Right] = value;
+ this.TextInset[Sides.Bottom] = value;
+ } else
+ this.TextInset[side] = value;
+ }
+
+ // I hate the fact that Dictionary doesn't have a method like this!
+ private ValueT GetKeyOrDefault(Dictionary map, KeyT key, ValueT defaultValue)
+ {
+ if (map.ContainsKey(key))
+ return map[key];
+ else
+ return defaultValue;
+ }
+
+ private Dictionary BorderPen = new Dictionary();
+ private Dictionary BorderPenData = new Dictionary();
+ private Dictionary TextInset = new Dictionary();
+ private Dictionary Padding = new Dictionary();
+
+ #endregion
+
+ #region Calculating
+
+ ///
+ /// Calculate how height this block will be when its printed on one line
+ ///
+ /// The Graphic to use for renderering
+ ///
+ public float CalculateHeight(Graphics g)
+ {
+ return this.CalculateHeight(g, "Wy", 9999999);
+ }
+
+ ///
+ /// Calculate how height this block will be when it prints the given string
+ /// to a maximum of the given width
+ ///
+ /// The Graphic to use for renderering
+ /// The string to be considered
+ /// The max width for the rendering
+ /// The height that will be used
+ public float CalculateHeight(Graphics g, String s, int width)
+ {
+ width -= (int)(this.GetTextInset(Sides.Left) + this.GetTextInset(Sides.Right) + 0.5f);
+ StringFormat fmt = new StringFormat();
+ fmt.Trimming = StringTrimming.EllipsisCharacter;
+ if (!this.CanWrap)
+ fmt.FormatFlags = StringFormatFlags.NoWrap;
+ float height = g.MeasureString(s, this.FontOrDefault, width, fmt).Height;
+ height = Math.Max(height, this.MinimumTextHeight);
+ height += this.GetPadding(Sides.Top);
+ height += this.GetPadding(Sides.Bottom);
+ height += this.GetBorderWidth(Sides.Top);
+ height += this.GetBorderWidth(Sides.Bottom);
+ height += this.GetTextInset(Sides.Top);
+ height += this.GetTextInset(Sides.Bottom);
+ return height;
+ }
+
+ private RectangleF ApplyInsets(RectangleF cell, float left, float top, float right, float bottom)
+ {
+ return new RectangleF(cell.X + left,
+ cell.Y + top,
+ cell.Width - (left + right),
+ cell.Height - (top + bottom));
+ }
+
+ ///
+ /// Given a bounding box return the box after applying the padding factors
+ ///
+ ///
+ ///
+ public RectangleF CalculatePaddedBox(RectangleF cell)
+ {
+ return this.ApplyInsets(cell,
+ this.GetPadding(Sides.Left),
+ this.GetPadding(Sides.Top),
+ this.GetPadding(Sides.Right),
+ this.GetPadding(Sides.Bottom));
+ }
+
+ ///
+ /// Given an already padded box, return the box into which the text will be drawn.
+ ///
+ ///
+ ///
+ public RectangleF CalculateBorderedBox(RectangleF cell)
+ {
+ return this.ApplyInsets(cell,
+ this.GetBorderWidth(Sides.Left),
+ this.GetBorderWidth(Sides.Top),
+ this.GetBorderWidth(Sides.Right),
+ this.GetBorderWidth(Sides.Bottom));
+ }
+
+ ///
+ /// Given an already padded and bordered box, return the box into which the text will be drawn.
+ ///
+ ///
+ ///
+ public RectangleF CalculateTextBox(RectangleF cell)
+ {
+ return this.ApplyInsets(cell,
+ this.GetTextInset(Sides.Left),
+ this.GetTextInset(Sides.Top),
+ this.GetTextInset(Sides.Right),
+ this.GetTextInset(Sides.Bottom));
+ }
+
+ ///
+ /// Apply paddeding and text insets to the given rectangle
+ ///
+ ///
+ ///
+ public RectangleF CalculatePaddedTextBox(RectangleF cell)
+ {
+ return this.CalculateTextBox(this.CalculateBorderedBox(this.CalculatePaddedBox(cell)));
+ }
+
+ #endregion
+
+ #region Rendering
+
+ ///
+ /// Draw the given string aligned within the given cell
+ ///
+ /// Graphics to draw on
+ /// Cell into which the text is to be drawn
+ /// The string to be drawn
+ /// How should the string be aligned
+ public void Draw(Graphics g, RectangleF r, String s, HorizontalAlignment align)
+ {
+ switch (align) {
+ case HorizontalAlignment.Center:
+ this.Draw(g, r, null, s, null);
+ break;
+ case HorizontalAlignment.Left:
+ this.Draw(g, r, s, null, null);
+ break;
+ case HorizontalAlignment.Right:
+ this.Draw(g, r, null, null, s);
+ break;
+ default:
+ break;
+ }
+ }
+
+ ///
+ /// Draw the array of strings so that the first string is left aligned,
+ /// the second is centered and the third is right aligned. All strings
+ /// are optional. Extra strings are ignored.
+ ///
+ /// Graphics to draw on
+ /// Cell into which the text is to be drawn
+ /// Array of strings
+ public void Draw(Graphics g, RectangleF r, String[] strings)
+ {
+ String left = null, centre = null, right = null;
+
+ if (strings.Length >= 1)
+ left = strings[0];
+ if (strings.Length >= 2)
+ centre = strings[1];
+ if (strings.Length >= 3)
+ right = strings[2];
+
+ this.Draw(g, r, left, centre, right);
+ }
+
+ ///
+ /// Draw this block
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void Draw(Graphics g, RectangleF r, String left, String centre, String right)
+ {
+ RectangleF paddedRect = this.CalculatePaddedBox(r);
+ RectangleF paddedBorderedRect = this.CalculateBorderedBox(paddedRect);
+ this.DrawBackground(g, paddedBorderedRect);
+ this.DrawText(g, paddedBorderedRect, left, centre, right);
+ this.DrawBorder(g, paddedRect);
+ }
+
+ private void DrawBackground(Graphics g, RectangleF r)
+ {
+ if (this.BackgroundBrush != null) {
+ // Enlarge the background area by half the border widths on each side
+ RectangleF r2 = this.ApplyInsets(r,
+ this.GetBorderWidth(Sides.Left) / -2,
+ this.GetBorderWidth(Sides.Top) / -2,
+ this.GetBorderWidth(Sides.Right) / -2,
+ this.GetBorderWidth(Sides.Bottom) / -2);
+ g.FillRectangle(PrepareBrushForDrawing(this.BackgroundBrush, r2), r2);
+ }
+ }
+
+ private void DrawBorder(Graphics g, RectangleF r)
+ {
+ if (this.areSideBorderEqual && this.GetBorderPen(Sides.Top) != null) {
+ Pen p = this.GetBorderPen(Sides.Top);
+ this.DrawOneBorder(g, Sides.Top, r.X, r.Y, r.Width, r.Height, true);
+ } else {
+ this.DrawOneBorder(g, Sides.Top, r.X, r.Y, r.Right, r.Y, false);
+ this.DrawOneBorder(g, Sides.Bottom, r.X, r.Bottom, r.Right, r.Bottom, false);
+ this.DrawOneBorder(g, Sides.Left, r.X, r.Y, r.X, r.Bottom, false);
+ this.DrawOneBorder(g, Sides.Right, r.Right, r.Y, r.Right, r.Bottom, false);
+ }
+ }
+
+ static public Brush PrepareBrushForDrawing(Brush value, RectangleF r)
+ {
+ LinearGradientBrush lgb = value as LinearGradientBrush;
+ if (lgb == null)
+ return value;
+
+ // We really just want to change the bounds of the gradient, but there is no way to do that
+ // so we have to make a new brush and copy across the information we can
+
+ //lgb.Rectangle.X = r.X;
+ //lgb.Rectangle.Y = r.Y;
+ //lgb.Rectangle.Width = r.Width;
+ //lgb.Rectangle.Height = r.Height;
+
+ LinearGradientBrush lgb2 = new LinearGradientBrush(r, lgb.LinearColors[0], lgb.LinearColors[1], 0.0);
+ lgb2.Blend = lgb.Blend;
+ //lgb2.InterpolationColors = lgb.InterpolationColors;
+ lgb2.WrapMode = lgb.WrapMode;
+ lgb2.Transform = lgb.Transform;
+ return lgb2;
+ }
+
+ static public Pen PreparePenForDrawing(Pen value, RectangleF r)
+ {
+ if (r.Height == 0)
+ r.Height = value.Width;
+ if (r.Width == 0)
+ r.Width = value.Width;
+ value.Brush = BlockFormat.PrepareBrushForDrawing(value.Brush, r);
+ return value;
+ }
+
+ static public Brush PrepareBrushForDrawing(Brush value, Rectangle r)
+ {
+ LinearGradientBrush lgb = value as LinearGradientBrush;
+ if (lgb == null)
+ return value;
+
+ // We really just want to change the bounds of the gradient, but there is no way to do that
+ // so we have to make a new brush and copy across the information we can
+
+ //lgb.Rectangle.X = r.X;
+ //lgb.Rectangle.Y = r.Y;
+ //lgb.Rectangle.Width = r.Width;
+ //lgb.Rectangle.Height = r.Height;
+
+ LinearGradientBrush lgb2 = new LinearGradientBrush(r, lgb.LinearColors[0], lgb.LinearColors[1], 0.0);
+ lgb2.Blend = lgb.Blend;
+ //lgb2.InterpolationColors = lgb.InterpolationColors;
+ lgb2.WrapMode = lgb.WrapMode;
+ lgb2.Transform = lgb.Transform;
+ return lgb2;
+ }
+
+ static public Pen PreparePenForDrawing(Pen value, Rectangle r)
+ {
+ value.Brush = BlockFormat.PrepareBrushForDrawing(value.Brush, r);
+ return value;
+ }
+
+ private void DrawOneBorder(Graphics g, Sides side, float x1, float y1, float x2, float y2, bool isRectangle)
+ {
+ Pen p = this.GetBorderPen(side);
+
+ if (p == null)
+ return;
+
+ PreparePenForDrawing(p, new RectangleF(x1, y1, x2-x1, y2-y1));
+
+ if (isRectangle)
+ g.DrawRectangle(p, x1, y1, x2, y2);
+ else
+ g.DrawLine(p, x1, y1, x2, y2);
+ }
+
+ private void DrawText(Graphics g, RectangleF r, string left, string centre, string right)
+ {
+ RectangleF textRect = this.CalculateTextBox(r);
+ Font font = this.FontOrDefault;
+ Brush textBrush = this.TextBrushOrDefault;
+
+ StringFormat fmt = new StringFormat();
+ if (!this.CanWrap)
+ fmt.FormatFlags = StringFormatFlags.NoWrap;
+ fmt.LineAlignment = StringAlignment.Center;
+ fmt.Trimming = StringTrimming.EllipsisCharacter;
+
+ if (!String.IsNullOrEmpty(left)) {
+ fmt.Alignment = StringAlignment.Near;
+ g.DrawString(left, font, textBrush, textRect, fmt);
+ }
+
+ if (!String.IsNullOrEmpty(centre)) {
+ fmt.Alignment = StringAlignment.Center;
+ g.DrawString(centre, font, textBrush, textRect, fmt);
+ }
+
+ if (!String.IsNullOrEmpty(right)) {
+ fmt.Alignment = StringAlignment.Far;
+ g.DrawString(right, font, textBrush, textRect, fmt);
+ }
+ //g.DrawRectangle(new Pen(Color.Red, 0.5f), textRect.X, textRect.Y, textRect.Width, textRect.Height);
+ //g.FillRectangle(Brushes.Red, r);
+ }
+
+ #endregion
+
+ #region Standard formatting styles
+
+ ///
+ /// Return the default style for cells
+ ///
+ static public BlockFormat DefaultCell()
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = new Font("MS Sans Serif", 9);
+ //fmt.TextBrush = Brushes.Black;
+ fmt.SetBorderPen(Sides.All, new Pen(Color.Blue, 0.5f));
+ fmt.SetTextInset(Sides.All, 2);
+ fmt.CanWrap = true;
+
+ return fmt;
+ }
+
+ ///
+ /// Return a minimal set of formatting values.
+ ///
+ static public BlockFormat Minimal()
+ {
+ return BlockFormat.Minimal(new Font("Times New Roman", 12));
+ }
+
+ ///
+ /// Return a minimal set of formatting values.
+ ///
+ static public BlockFormat Minimal(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.Black;
+ fmt.SetBorderPen(Sides.All, new Pen(Color.Gray, 0.5f));
+ fmt.SetTextInset(Sides.All, 3.0f);
+
+ return fmt;
+ }
+
+ ///
+ /// Return a set of formatting values that draws boxes
+ ///
+ static public BlockFormat Box()
+ {
+ return BlockFormat.Box(new Font("Verdana", 24));
+ }
+
+ ///
+ /// Return a set of formatting values that draws boxes
+ ///
+ static public BlockFormat Box(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.Black;
+ fmt.SetBorderPen(Sides.All, new Pen(Color.Black, 0.5f));
+ fmt.BackgroundBrush = Brushes.LightBlue;
+ fmt.SetTextInset(Sides.All, 3.0f);
+
+ return fmt;
+ }
+
+ ///
+ /// Return a format that will nicely print headers.
+ ///
+ static public BlockFormat Header()
+ {
+ return BlockFormat.Header(new Font("Verdana", 24));
+ }
+
+ ///
+ /// Return a format that will nicely print headers.
+ ///
+ static public BlockFormat Header(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.WhiteSmoke;
+ fmt.BackgroundBrush = new LinearGradientBrush(new Point(1, 1), new Point(2, 2), Color.DarkBlue, Color.WhiteSmoke);
+ fmt.SetTextInset(Sides.All, 3.0f);
+ fmt.SetPadding(Sides.Bottom, 10);
+
+ return fmt;
+ }
+
+ ///
+ /// Return a format that will nicely print report footers.
+ ///
+ static public BlockFormat Footer()
+ {
+ return BlockFormat.Footer(new Font("Verdana", 10, FontStyle.Italic));
+ }
+
+ ///
+ /// Return a format that will nicely print report footers.
+ ///
+ static public BlockFormat Footer(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.Black;
+ fmt.SetPadding(Sides.Top, 10);
+ fmt.SetBorderPen(Sides.Top, new Pen(Color.Gray, 0.5f));
+ fmt.SetTextInset(Sides.All, 3.0f);
+
+ return fmt;
+ }
+
+ ///
+ /// Return a format that will nicely print list headers.
+ ///
+ static public BlockFormat ListHeader()
+ {
+ return BlockFormat.ListHeader(new Font("Verdana", 12));
+ }
+
+ ///
+ /// Return a format that will nicely print list headers.
+ ///
+ static public BlockFormat ListHeader(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.Black;
+ fmt.BackgroundBrush = Brushes.LightGray;
+ fmt.SetBorderPen(Sides.All, new Pen(Color.DarkGray, 1.5f));
+ fmt.SetTextInset(Sides.All, 1.0f);
+
+ fmt.CanWrap = true;
+
+ return fmt;
+ }
+
+ ///
+ /// Return a format that will nicely print group headers.
+ ///
+ static public BlockFormat GroupHeader()
+ {
+ return BlockFormat.GroupHeader(new Font("Verdana", 10, FontStyle.Bold));
+ }
+
+ ///
+ /// Return a format that will nicely print group headers.
+ ///
+ static public BlockFormat GroupHeader(Font f)
+ {
+ BlockFormat fmt = new BlockFormat();
+
+ fmt.Font = f;
+ fmt.TextBrush = Brushes.Black;
+ fmt.SetPadding(Sides.Top, f.Height / 2);
+ fmt.SetPadding(Sides.Bottom, f.Height / 2);
+ fmt.SetBorder(Sides.Bottom, 3f, new LinearGradientBrush(new Point(1, 1), new Point(2, 2), Color.DarkBlue, Color.White));
+ fmt.SetTextInset(Sides.All, 1.0f);
+
+ return fmt;
+ }
+
+ #endregion
+ }
+}
diff --git a/ListViewPrinter2005.csproj b/ListViewPrinter2005.csproj
new file mode 100644
index 0000000..602abef
--- /dev/null
+++ b/ListViewPrinter2005.csproj
@@ -0,0 +1,73 @@
+
+
+ Debug
+ AnyCPU
+ 8.0.50727
+ 2.0
+ {E73A10BD-2B5A-4BAC-897F-3A58CFC07631}
+ Library
+ Properties
+ BrightIdeasSoftware
+ ListViewPrinter
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ BrushForm.cs
+
+
+
+
+
+ Component
+
+
+
+
+
+ BrushForm.cs
+ Designer
+
+
+
+
+ {18FEDA0C-D147-4286-B39A-01204808106A}
+ ObjectListView
+
+
+
+
+
\ No newline at end of file
diff --git a/ListViewPrinter2008.csproj b/ListViewPrinter2008.csproj
new file mode 100644
index 0000000..646d913
--- /dev/null
+++ b/ListViewPrinter2008.csproj
@@ -0,0 +1,131 @@
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {E73A10BD-2B5A-4BAC-897F-3A58CFC07631}
+ Library
+ Properties
+ BrightIdeasSoftware
+ ListViewPrinter
+
+
+
+
+ 2.0
+ v3.5
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
+ true
+ lvp-keyfile.snk
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ BrushForm.cs
+
+
+
+
+
+ Component
+
+
+
+
+
+ BrushForm.cs
+ Designer
+
+
+
+
+ {18FEDA0C-D147-4286-B39A-01204808106A}
+ ObjectListView2008
+
+
+
+
+ False
+ .NET Framework Client Profile
+ false
+
+
+ False
+ .NET Framework 2.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.5
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ListViewPrinter2010.csproj b/ListViewPrinter2010.csproj
new file mode 100644
index 0000000..6dc6919
--- /dev/null
+++ b/ListViewPrinter2010.csproj
@@ -0,0 +1,127 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {E73A10BD-2B5A-4BAC-897F-3A58CFC07631}
+ Library
+ Properties
+ BrightIdeasSoftware
+ ListViewPrinter
+
+
+
+
+ 3.5
+ v4.0
+ false
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ BrushForm.cs
+
+
+
+
+
+ Component
+
+
+
+
+
+ BrushForm.cs
+ Designer
+
+
+
+
+ {18FEDA0C-D147-4286-B39A-01204808106A}
+ ObjectListView2010
+
+
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 2.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.5
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/ListViewPrinter2010.ncrunchproject b/ListViewPrinter2010.ncrunchproject
new file mode 100644
index 0000000..b4ca671
--- /dev/null
+++ b/ListViewPrinter2010.ncrunchproject
@@ -0,0 +1,27 @@
+
+ false
+ false
+ false
+ true
+ false
+ false
+ false
+ false
+ true
+ true
+ false
+ true
+ true
+ 60000
+
+
+
+ AutoDetect
+ STA
+ x86
+
+
+ .*
+
+
+
\ No newline at end of file
diff --git a/ListViewPrinter2012.csproj b/ListViewPrinter2012.csproj
new file mode 100644
index 0000000..73a85d8
--- /dev/null
+++ b/ListViewPrinter2012.csproj
@@ -0,0 +1,127 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {E73A10BD-2B5A-4BAC-897F-3A58CFC07631}
+ Library
+ Properties
+ BrightIdeasSoftware
+ ListViewPrinter
+
+
+
+
+ 3.5
+ v4.0
+ false
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ BrushForm.cs
+
+
+
+
+
+ Component
+
+
+
+
+
+ BrushForm.cs
+ Designer
+
+
+
+
+ {18FEDA0C-D147-4286-B39A-01204808106A}
+ ObjectListView2012
+
+
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 2.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.0 %28x86%29
+ false
+
+
+ False
+ .NET Framework 3.5
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/ListViewPrinter2012.ncrunchproject b/ListViewPrinter2012.ncrunchproject
new file mode 100644
index 0000000..896f219
--- /dev/null
+++ b/ListViewPrinter2012.ncrunchproject
@@ -0,0 +1,22 @@
+
+ false
+ false
+ false
+ true
+ false
+ false
+ false
+ false
+ true
+ true
+ false
+ true
+ true
+ 60000
+
+
+
+ AutoDetect
+ STA
+ x86
+
\ No newline at end of file
diff --git a/ListViewPrinter2012.v2.ncrunchproject b/ListViewPrinter2012.v2.ncrunchproject
new file mode 100644
index 0000000..896f219
--- /dev/null
+++ b/ListViewPrinter2012.v2.ncrunchproject
@@ -0,0 +1,22 @@
+
+ false
+ false
+ false
+ true
+ false
+ false
+ false
+ false
+ true
+ true
+ false
+ true
+ true
+ 60000
+
+
+
+ AutoDetect
+ STA
+ x86
+
\ No newline at end of file
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..bfc4958
--- /dev/null
+++ b/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ListViewPrinter")]
+[assembly: AssemblyDescription("A class to take a ListView or ObjectListView and make it into a beatiful report")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Bright Ideas Software")]
+[assembly: AssemblyProduct("ListViewPrinter")]
+[assembly: AssemblyCopyright("Copyright © 2008-2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("213c7c43-b654-47cb-b817-fc602282c9df")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("2.5.0.*")]
+[assembly: AssemblyFileVersion("2.5.0.0")]
diff --git a/README.md b/README.md
index 21f39c6..82abf2f 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,4 @@
# ListViewPrinter
A mirror of the ListViewPrinter library
+
+Original can be found [on the homepage](https://www.codeproject.com/kb/list/objectlistview.aspx).
diff --git a/lvp-keyfile.snk b/lvp-keyfile.snk
new file mode 100644
index 0000000000000000000000000000000000000000..0473a7a2e96106665554973cb275fd938698d27a
GIT binary patch
literal 596
zcmZQ)VqjoUVPFUfb~IvOVPIfnU}R|4Zd&&*}EY~cOUDg>DYd+=Z6byY9+7Wl-aA4FfO{Iqhd*7d$THh<{xTKo*
zX5bzRHBAdHWAPW8M1FjJ^L&ovQJIfVmoe>@71Cl8JaOyzy-TZS);;v9f2K7d`C^fJ
z!nGd;Wh|X1`t<)ZrD-~rJW@XU*md@@FA|-X&cxREFE@Om&SiFd6=QfIgT2^;Z%amab?OH!!WSwXvYPS%#K-mJgqQ@?|$i#}tW7pITx75@EfQWr0G
L{cl>5Y1Re+Mj{{D
literal 0
HcmV?d00001