FastReport
120 строк · 3.4 Кб
1using FastReport.Utils;
2using System;
3using System.ComponentModel;
4
5namespace FastReport
6{
7/// <summary>
8/// This class contains the page columns settings.
9/// It is used in the <see cref="ReportPage.Columns"/> property.
10/// </summary>
11[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
12public class PageColumns
13{
14private int count;
15private float width;
16private FloatCollection positions;
17private ReportPage page;
18
19/// <summary>
20/// Gets or sets the number of columns.
21/// </summary>
22/// <remarks>
23/// Set this property to 0 or 1 if you don't want to use columns.
24/// </remarks>
25[DefaultValue(1)]
26public int Count
27{
28get { return count; }
29set
30{
31if (value <= 0)
32throw new ArgumentOutOfRangeException("Count", "Value must be greather than 0");
33
34count = value;
35width = (page.PaperWidth - page.LeftMargin - page.RightMargin) / count;
36positions.Clear();
37for (int i = 0; i < count; i++)
38{
39positions.Add(i * Width);
40}
41}
42}
43
44/// <summary>
45/// Gets or sets the column width.
46/// </summary>
47[TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
48public float Width
49{
50get { return width; }
51set { width = value; }
52}
53
54/// <summary>
55/// Gets or sets a list of column starting positions.
56/// </summary>
57/// <remarks>
58/// Each value represents a column starting position measured in the millimeters.
59/// </remarks>
60public FloatCollection Positions
61{
62get { return positions; }
63set
64{
65if (value.Count == count)
66{
67positions = value;
68}
69else
70{
71positions.Clear();
72for (int i = 0; i < count; i++)
73{
74positions.Add(i * Width);
75}
76}
77}
78}
79
80private bool ShouldSerializeWidth()
81{
82return Count > 1;
83}
84
85private bool ShouldSerializePositions()
86{
87return Count > 1;
88}
89
90/// <summary>
91/// Assigns values from another source.
92/// </summary>
93/// <param name="source">Source to assign from.</param>
94public void Assign(PageColumns source)
95{
96Count = source.Count;
97Width = source.Width;
98Positions.Assign(source.Positions);
99}
100
101internal void Serialize(FRWriter writer, PageColumns c)
102{
103if (Count != c.Count)
104writer.WriteInt("Columns.Count", Count);
105if (Count > 1)
106{
107writer.WriteFloat("Columns.Width", Width);
108Positions = Positions; // avoid bug when number of positions is not equal number of columns
109writer.WriteValue("Columns.Positions", Positions);
110}
111}
112
113internal PageColumns(ReportPage page)
114{
115this.page = page;
116positions = new FloatCollection();
117Count = 1;
118}
119}
120}
121