using System;
using System.ComponentModel;
using FastReport.Utils;
namespace FastReport
{
///
/// The layout of the data band columns.
///
public enum ColumnLayout
{
///
/// Print columns across then down.
///
AcrossThenDown,
///
/// Print columns down then across.
///
DownThenAcross
}
///
/// This class holds the band columns settings. It is used in the property.
///
[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
public class BandColumns
{
private int count;
private float width;
private ColumnLayout layout;
private int minRowCount;
private DataBand band;
///
/// Gets or sets the number of columns.
///
///
/// Set this property to 0 or 1 if you don't want to use columns.
///
[DefaultValue(0)]
public int Count
{
get { return count; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException("Count", "Value must be >= 0");
count = value;
}
}
///
/// The column width, in pixels.
///
[DefaultValue(0f)]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float Width
{
get { return width; }
set { width = value; }
}
///
/// Gets or sets the layout of the columns.
///
[DefaultValue(ColumnLayout.AcrossThenDown)]
public ColumnLayout Layout
{
get { return layout; }
set { layout = value; }
}
///
/// Gets or sets the minimum row count that must be printed.
///
///
/// This property is used if the Layout property is set to DownThenAcross. 0 means that
/// FastReport should calculate the optimal number of rows.
///
[DefaultValue(0)]
public int MinRowCount
{
get { return minRowCount; }
set { minRowCount = value; }
}
internal float ActualWidth
{
get
{
ReportPage page = band.Page as ReportPage;
if (Width == 0 && page != null)
return (page.PaperWidth - page.LeftMargin - page.RightMargin) * Units.Millimeters / (Count == 0 ? 1 : Count);
return Width;
}
}
internal FloatCollection Positions
{
get
{
FloatCollection positions = new FloatCollection();
float columnWidth = ActualWidth;
for (int i = 0; i < Count; i++)
{
positions.Add(i * columnWidth);
}
return positions;
}
}
///
/// Assigns values from another source.
///
/// Source to assign from.
public void Assign(BandColumns source)
{
Count = source.Count;
Width = source.Width;
Layout = source.Layout;
MinRowCount = source.MinRowCount;
}
internal void Serialize(FRWriter writer, BandColumns c)
{
if (Count != c.Count)
writer.WriteInt("Columns.Count", Count);
if (Width != c.Width)
writer.WriteFloat("Columns.Width", Width);
if (Layout != c.Layout)
writer.WriteValue("Columns.Layout", Layout);
if (MinRowCount != c.MinRowCount)
writer.WriteInt("Columns.MinRowCount", MinRowCount);
}
///
/// Initializes a new instance of the BandColumns class with default settings.
///
public BandColumns(DataBand band)
{
this.band = band;
}
}
}