~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/StandardPrinter.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Drawing;
 
6
using ICSharpCode.Reports.Core.Exporter;
 
7
using ICSharpCode.Reports.Core.Globals;
 
8
using ICSharpCode.Reports.Core.Interfaces;
 
9
using ICSharpCode.Reports.Expressions.ReportingLanguage;
 
10
 
 
11
namespace ICSharpCode.Reports.Core.BaseClasses.Printing
 
12
{
 
13
        /// <summary>
 
14
        /// Description of StandardPrinter.
 
15
        /// </summary>
 
16
        
 
17
        
 
18
        internal sealed class StandardPrinter
 
19
        {
 
20
                public StandardPrinter()
 
21
                {
 
22
                }
 
23
                
 
24
                
 
25
                public static void AdjustBackColor (ISimpleContainer container)
 
26
                {
 
27
                        foreach (var item in container.Items)
 
28
                        {
 
29
                                item.BackColor = container.BackColor;
 
30
                        }
 
31
                }
 
32
                
 
33
                
 
34
                public static void FillBackground (Graphics  graphics,BaseStyleDecorator decorator)
 
35
                {
 
36
                        if (decorator.BackColor != GlobalValues.DefaultBackColor) {
 
37
                                
 
38
                                RectangleShape backgroundShape = new RectangleShape();
 
39
                                
 
40
                                backgroundShape.FillShape(graphics,
 
41
                                                          new SolidFillPattern(decorator.BackColor),
 
42
                                                          decorator.DisplayRectangle);
 
43
                        }
 
44
                }
 
45
                
 
46
                
 
47
                public static void DrawBorder (Graphics graphics,BaseStyleDecorator decorator)
 
48
                {
 
49
                        if (decorator.DrawBorder)
 
50
                        {
 
51
                                if (decorator.FrameColor == Color.Empty)
 
52
                                {
 
53
                                        decorator.FrameColor = decorator.ForeColor;
 
54
                                }
 
55
                                Border border = new Border(new BaseLine (decorator.FrameColor,System.Drawing.Drawing2D.DashStyle.Solid,1));
 
56
                                border.DrawBorder(graphics,decorator.DisplayRectangle);
 
57
                        }
 
58
                }
 
59
                
 
60
                
 
61
                #region Render/Convert SimpleItem
 
62
                
 
63
                /// <summary>
 
64
                /// Convert a single item, Location is calculated as follows
 
65
                /// </summary>
 
66
                /// <param name="offset"> only Y value is used, gives the offset to Items location.Y </param>
 
67
                /// <param name="item">Item to convert</param>
 
68
                /// <returns></returns>
 
69
                
 
70
                
 
71
                private static void RenderLineItem (BaseReportItem item, Point offset,IExpressionEvaluatorFacade evaluator,ReportPageEventArgs rpea)
 
72
                {
 
73
                        
 
74
                        Point saveLocation = new Point (item.Location.X,item.Location.Y);
 
75
                        
 
76
                        PrintHelper.AdjustChildLocation(item,offset);
 
77
                        
 
78
                        IReportExpression epr = item as IReportExpression;
 
79
                        
 
80
                        string evaluatedValue = String.Empty;
 
81
                        
 
82
                        if (epr != null) {
 
83
                                try {
 
84
                                        if (!String.IsNullOrEmpty(epr.Expression))
 
85
                                        {
 
86
                                                evaluatedValue =  evaluator.Evaluate(epr.Expression);
 
87
                                                
 
88
                                        } else 
 
89
                                        {
 
90
                                                evaluatedValue =  evaluator.Evaluate(epr.Text);
 
91
                                        }
 
92
                                        epr.Text = evaluatedValue;
 
93
                                        
 
94
                                } catch (UnknownFunctionException ufe) {
 
95
                                        
 
96
                                        epr.Text = GlobalValues.UnkownFunctionMessage(ufe.Message);
 
97
                                }
 
98
                                
 
99
                        }
 
100
                        item.Render (rpea);
 
101
                        item.Location = saveLocation;
 
102
                }
 
103
                
 
104
                
 
105
                #endregion
 
106
                
 
107
                
 
108
                #region Render Collection
 
109
                
 
110
                public static Rectangle RenderPlainCollection (BaseReportItem parent,
 
111
                                                               ReportItemCollection items,
 
112
                                                               IExpressionEvaluatorFacade evaluator,
 
113
                                                               Point offset,
 
114
                                                               ReportPageEventArgs rpea)
 
115
                {
 
116
                        
 
117
                        if (items.Count > 0) {
 
118
                                foreach (BaseReportItem child in items) {
 
119
                                        child.Parent = parent;
 
120
                                         StandardPrinter.RenderLineItem (child,offset,evaluator,rpea);
 
121
                                }
 
122
                        }
 
123
                        return new Rectangle(offset,parent.Size);
 
124
                }
 
125
                
 
126
                
 
127
                #endregion
 
128
        
 
129
                
 
130
 
 
131
                public static Rectangle RenderContainer (ISimpleContainer simpleContainer,IExpressionEvaluatorFacade evaluator,Point offset,ReportPageEventArgs rpea)
 
132
                {
 
133
                        
 
134
                        BaseReportItem item = simpleContainer as BaseReportItem;
 
135
                        Rectangle retVal = new Rectangle(offset,item.Size);
 
136
                        Point saveLocation = item.Location;
 
137
                        PrintHelper.AdjustChildLocation(item,offset);
 
138
                        
 
139
                        item.Render(rpea);
 
140
                        
 
141
                        
 
142
                        if (simpleContainer.Items != null)  {
 
143
                                retVal = StandardPrinter.RenderPlainCollection(item,simpleContainer.Items,evaluator,offset,rpea);
 
144
                        }
 
145
                
 
146
                        retVal = new Rectangle (retVal.X,retVal.Y,
 
147
                                        retVal.X + item.Size.Width,
 
148
                                        item.Size.Height + 3 * GlobalValues.GapBetweenContainer);
 
149
                        item.Location = saveLocation;
 
150
                        return retVal;
 
151
                }
 
152
 
 
153
        }
 
154
}