Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit f5d1100

Browse files
Rectangle can be used as Container for Items
1 parent b805eb4 commit f5d1100

3 files changed

Lines changed: 47 additions & 120 deletions

File tree

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportRectangle.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,16 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20-
using System.Collections.Generic;
2120
using System.Drawing.Drawing2D;
22-
using ICSharpCode.Reporting.Arrange;
23-
using ICSharpCode.Reporting.Exporter.Visitors;
24-
using ICSharpCode.Reporting.Interfaces.Export;
2521

2622
namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
2723
{
2824
/// <summary>
2925
/// Description of ExportRectangle.
3026
/// </summary>
31-
public class ExportRectangle:ExportContainer,IExportGraphics,IAcceptor
27+
public class ExportRectangle:ExportContainer,IExportGraphics
3228
{
33-
public ExportRectangle() {
34-
ExportedItems = new List<IExportColumn>();
35-
}
36-
37-
public void Accept(IVisitor visitor)
38-
{
39-
visitor.Visit(this);
40-
}
4129

42-
public List<IExportColumn> ExportedItems {get;private set;}
43-
44-
45-
// public override IMeasurementStrategy MeasurementStrategy()
46-
// {
47-
// throw new NotImplementedException();
48-
// }
49-
5030
public int Thickness {get;set;}
5131

5232
public DashStyle DashStyle {get;set;}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -53,76 +53,12 @@ public static FixedPage CreateFixedPage(ExportPage exportPage) {
5353
public static Canvas CreateContainer(ExportContainer container) {
5454
var canvas = CreateCanvas(container);
5555
var size = container.DesiredSize.ToWpf();
56+
CanvasHelper.SetPosition(canvas,new Point(container.Location.X,container.Location.Y));
5657
canvas.Measure(size);
5758
canvas.Arrange(new Rect(new Point(),size ));
5859
canvas.UpdateLayout();
5960
return canvas;
6061
}
61-
62-
/*
63-
public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
64-
65-
var textBlock = new TextBlock();
66-
67-
textBlock.Foreground = ConvertBrush(exportText.ForeColor);
68-
69-
if (setBackcolor) {
70-
textBlock.Background = ConvertBrush(exportText.BackColor);
71-
}
72-
73-
SetFont(textBlock,exportText);
74-
75-
textBlock.TextWrapping = TextWrapping.Wrap;
76-
77-
CheckForNewLine (textBlock,exportText);
78-
SetContentAlignment(textBlock,exportText);
79-
MeasureTextBlock (textBlock,exportText);
80-
return textBlock;
81-
}
82-
*/
83-
84-
/*
85-
static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
86-
string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
87-
for (int i = 0; i < inlines.Length; i++) {
88-
if (inlines[i].Length > 0) {
89-
textBlock.Inlines.Add(new Run(inlines[i]));
90-
textBlock.Inlines.Add(new LineBreak());
91-
}
92-
}
93-
var li = textBlock.Inlines.LastInline;
94-
textBlock.Inlines.Remove(li);
95-
}
96-
97-
98-
static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
99-
{
100-
var wpfSize = MeasureTextInWpf(exportText);
101-
textBlock.Width = wpfSize.Width;
102-
textBlock.Height = wpfSize.Height;
103-
}
104-
105-
*/
106-
107-
/*
108-
static Size MeasureTextInWpf(ExportText exportText){
109-
110-
if (exportText.CanGrow) {
111-
var formattedText = NewMethod(exportText);
112-
113-
formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
114-
115-
formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));
116-
117-
var size = new Size {
118-
Width = formattedText.WidthIncludingTrailingWhitespace,
119-
Height = formattedText.Height + 6};
120-
return size;
121-
}
122-
return new Size(exportText.Size.Width,exportText.Size.Height);
123-
}
124-
125-
*/
12662

12763

12864
public static FormattedText CreateFormattedText(ExportText exportText)

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20-
using System.Collections.Generic;
2120
using System.Windows;
2221
using System.Windows.Controls;
2322
using System.Windows.Documents;
2423
using System.Windows.Media;
2524

25+
using ICSharpCode.Reporting.BaseClasses;
2626
using ICSharpCode.Reporting.Exporter.Visitors;
2727
using ICSharpCode.Reporting.Interfaces.Export;
2828
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
2929
using ICSharpCode.Reporting.WpfReportViewer.Visitor.Graphics;
30+
using System.Windows.Shapes;
3031

3132
namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
3233
{
@@ -54,45 +55,49 @@ public override void Visit(ExportPage page){
5455
public override void Visit(ExportContainer exportContainer){
5556

5657
sectionCanvas = FixedDocumentCreator.CreateContainer(exportContainer);
57-
sectionCanvas.Name = exportContainer.Name;
58-
CanvasHelper.SetPosition(sectionCanvas,new Point(exportContainer.Location.X,exportContainer.Location.Y));
59-
PerformList(sectionCanvas,exportContainer.ExportedItems);
58+
sectionCanvas = RenderSectionContainer(exportContainer);
6059
}
60+
6161

62-
63-
void PerformList(Canvas myCanvas, List<IExportColumn> exportedItems)
64-
{
65-
foreach (var element in exportedItems) {
66-
var container = element as ExportContainer;
67-
if (container != null) {
68-
var containerCanvas = FixedDocumentCreator.CreateContainer(container);
69-
CanvasHelper.SetPosition(containerCanvas,new Point(container.Location.X,container.Location.Y));
70-
if (container is ExportRectangle) {
71-
DrawRectangleAsContainer(container);
72-
containerCanvas.Children.Add(UIElement);
73-
myCanvas.Children.Add(containerCanvas);
74-
} else {
75-
// var containerCanvas = FixedDocumentCreator.CreateContainer(container);
76-
// CanvasHelper.SetPosition(containerCanvas,new Point(container.Location.X,container.Location.Y));
77-
myCanvas.Children.Add(containerCanvas);
78-
PerformList(containerCanvas,container.ExportedItems);
62+
Canvas RenderSectionContainer (ExportContainer container) {
63+
var canvas = FixedDocumentCreator.CreateContainer(container);
64+
foreach (var element in container.ExportedItems) {
65+
if (IsContainer(element)) {
66+
if (element is ExportRectangle) {
67+
var graphContainer = RenderGraphicsContainer((IExportContainer)element);
68+
canvas.Children.Add(graphContainer);
7969
}
8070
} else {
8171
var acceptor = element as IAcceptor;
8272
acceptor.Accept(this);
83-
myCanvas.Children.Add(UIElement);
73+
canvas.Children.Add(UIElement);
8474
}
8575
}
76+
canvas.Background = FixedDocumentCreator.ConvertBrush(container.BackColor);
77+
return canvas;
8678
}
87-
88-
void DrawRectangleAsContainer(ExportContainer container)
79+
80+
81+
bool IsContainer (IExportColumn column) {
82+
return (column is ExportContainer)|| (column is ExportRectangle);
83+
}
84+
85+
86+
Canvas RenderGraphicsContainer(IExportContainer container)
8987
{
88+
9089
var rect = container as ExportRectangle;
90+
var graphCanvas = FixedDocumentCreator.CreateContainer(rect);
91+
CanvasHelper.SetPosition(graphCanvas, container.Location.ToWpf());
92+
graphCanvas.Background = FixedDocumentCreator.ConvertBrush(container.BackColor);
9193
if (rect != null) {
9294
Visit(rect);
95+
graphCanvas.Children.Add(UIElement);
9396
}
97+
return graphCanvas;
9498
}
9599

100+
96101
public override void Visit(ExportText exportColumn){
97102

98103
var ft = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
@@ -128,19 +133,25 @@ public override void Visit(ExportLine exportGraphics)
128133

129134
public override void Visit(ExportRectangle exportRectangle)
130135
{
131-
var pen = FixedDocumentCreator.CreateWpfPen(exportRectangle);
132-
133-
var visual = new DrawingVisual();
134-
using (var dc = visual.RenderOpen()){
135-
dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportRectangle.BackColor),
136-
pen,
137-
new Rect(exportRectangle.Location.X,exportRectangle.Location.Y,
138-
exportRectangle.Size.Width,exportRectangle.Size.Height));
136+
var border = new Border();
137+
border.BorderThickness = new Thickness(exportRectangle.Thickness);
138+
border.BorderBrush = FixedDocumentCreator.ConvertBrush(exportRectangle.ForeColor);
139+
border.Background = FixedDocumentCreator.ConvertBrush(exportRectangle.BackColor);
140+
border.Width = exportRectangle.Size.Width;
141+
border.Height = exportRectangle.Size.Height;
142+
CanvasHelper.SetPosition(border, new Point(0,0));
143+
var sp = new StackPanel();
144+
sp.Orientation = Orientation.Horizontal;
145+
foreach (var element in exportRectangle.ExportedItems) {
146+
var acceptor = element as IAcceptor;
147+
acceptor.Accept(this);
148+
sp.Children.Add(UIElement);
139149
}
140-
var dragingElement = new DrawingElement(visual);
141-
UIElement = dragingElement;
150+
border.Child = sp;
151+
UIElement = border;
142152
}
143153

154+
144155
public override void Visit(ExportCircle exportCircle)
145156
{
146157
var pen = FixedDocumentCreator.CreateWpfPen(exportCircle);

0 commit comments

Comments
 (0)