~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseSection.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.ComponentModel;
 
6
using System.Drawing;
 
7
using System.Linq;
 
8
using System.Xml.Serialization;
 
9
 
 
10
using ICSharpCode.Reports.Core.Interfaces;
 
11
 
 
12
/// <summary>
 
13
/// This Class is the BaseClass for <see cref="ReportSection"></see>
 
14
/// </summary>
 
15
 
 
16
 
 
17
namespace ICSharpCode.Reports.Core
 
18
{
 
19
        public class BaseSection : BaseReportItem,ISimpleContainer
 
20
        {
 
21
                
 
22
                private ReportItemCollection items;
 
23
                
 
24
                public event EventHandler<SectionEventArgs> SectionPrinting;
 
25
                public event EventHandler<SectionEventArgs> SectionPrinted;
 
26
                
 
27
                
 
28
                #region Constructors
 
29
                
 
30
                public BaseSection(): base()
 
31
                {
 
32
                        base.Name = String.Empty;
 
33
                }
 
34
                
 
35
                public BaseSection (string sectionName) :base()
 
36
                {
 
37
                        base.Name = sectionName;
 
38
                }
 
39
                
 
40
                #endregion
 
41
                
 
42
                #region Rendering
 
43
                
 
44
                public override void Render(ReportPageEventArgs rpea)
 
45
                {
 
46
                        this.NotifyPrinting();
 
47
                        base.Render(rpea);
 
48
                        this.NotifyPrinted();
 
49
                }
 
50
                
 
51
                
 
52
                protected override Rectangle DisplayRectangle {
 
53
                        get { 
 
54
                                        return new Rectangle(Location.X , this.Location.Y ,
 
55
                                                             this.Size.Width,this.Size.Height);
 
56
                        }
 
57
                }
 
58
                
 
59
                
 
60
                private void NotifyPrinting () 
 
61
                {
 
62
                        if (this.SectionPrinting != null) {
 
63
                                SectionEventArgs ea = new SectionEventArgs (this);
 
64
                                SectionPrinting (this,ea);
 
65
                        } 
 
66
                }
 
67
                
 
68
                
 
69
                private void NotifyPrinted () 
 
70
                {
 
71
                        if (this.SectionPrinted != null) {
 
72
                                SectionEventArgs ea = new SectionEventArgs (this);
 
73
                                SectionPrinted (this,ea);
 
74
                        }
 
75
                }
 
76
                
 
77
                #endregion
 
78
                
 
79
                #region FindItem
 
80
                
 
81
                private BaseReportItem FindRec (ReportItemCollection items, string name)
 
82
                {
 
83
                        foreach(BaseReportItem item in items)
 
84
                        {
 
85
                                ISimpleContainer cont = item as ISimpleContainer;
 
86
                                if (cont != null) {
 
87
                                        return FindRec(cont.Items,name);
 
88
                                } else {
 
89
                                        var query = from bt in items where bt.Name == name select bt;
 
90
                                        if (query.Count() >0) {
 
91
                                                return query.FirstOrDefault();
 
92
                                        }
 
93
                                }
 
94
                        }
 
95
                        return null;
 
96
                }
 
97
                
 
98
                
 
99
                
 
100
                public BaseReportItem FindItem (string itemName)
 
101
                {
 
102
                        foreach (BaseReportItem item in items)
 
103
                        {
 
104
                                ISimpleContainer cont = item as ISimpleContainer;
 
105
                                if (cont != null) {
 
106
                                        return FindRec (cont.Items,itemName);
 
107
                                } else {
 
108
                                        return FindRec(this.items,itemName);
 
109
                                }
 
110
                        }
 
111
                        return null;
 
112
                }
 
113
                
 
114
                #endregion
 
115
                
 
116
                #region properties
 
117
                
 
118
                public  int SectionMargin {get;set;}
 
119
        
 
120
//              public virtual int SectionOffset {get;set;}
 
121
                
 
122
                
 
123
                public ReportItemCollection Items
 
124
                {
 
125
                        get {
 
126
                                if (this.items == null) {
 
127
                                        items = new ReportItemCollection();
 
128
                                }
 
129
                                return items;
 
130
                        }
 
131
                }
 
132
                
 
133
        
 
134
                public virtual bool PageBreakAfter {get;set;}
 
135
        
 
136
                #endregion
 
137
 
 
138
                
 
139
                public Size MeasureOverride (Size availableSize)
 
140
                {
 
141
                        Size resultSize = new Size(0,0);
 
142
//                      Console.WriteLine("MeasureOverride");
 
143
                        foreach (var item in Items) {
 
144
//                              Console.WriteLine("{0} - {1}",item.Location,item.Size);
 
145
                                resultSize.Width = Math.Max(resultSize.Width, item.Size.Width);
 
146
                                resultSize.Height = Math.Max(resultSize.Height, item.Size.Height);
 
147
                        }
 
148
 
 
149
//                      resultSize.Width = double.IsPositiveInfinity(availableSize.Width) ?
 
150
//                              resultSize.Width : availableSize.Width;
 
151
//
 
152
//                      resultSize.Height = double.IsPositiveInfinity(availableSize.Height) ?
 
153
//                              resultSize.Height : availableSize.Height;
 
154
                        
 
155
                        resultSize.Width = double.IsPositiveInfinity(availableSize.Width) ?
 
156
                                resultSize.Width : availableSize.Width;
 
157
                        var b = double.IsPositiveInfinity(availableSize.Height);
 
158
                        resultSize.Height = double.IsPositiveInfinity(availableSize.Height) ?
 
159
                                resultSize.Height : availableSize.Height;
 
160
                        
 
161
                        return resultSize;
 
162
                }
 
163
                
 
164
                #region System.IDisposable interface implementation
 
165
                
 
166
                protected override void Dispose(bool disposing)
 
167
                {
 
168
                        try {
 
169
                                if (disposing){
 
170
                                        if (this.items != null) {
 
171
                                                this.items.Clear();
 
172
                                                this.items = null;
 
173
                                        }
 
174
                                }
 
175
                        } finally {
 
176
                                base.Dispose(disposing);
 
177
                        }
 
178
                }
 
179
                
 
180
                #endregion
 
181
        }
 
182
}