From 0f2a8ae5226bb12fa6128c515f773c6bf6994fbd Mon Sep 17 00:00:00 2001 From: peterforstmeier Date: Sun, 3 Oct 2010 11:49:18 +0200 Subject: [PATCH] Cleanup Wizard Layouts, ISimpleContainer in BaseSection.cs --- .../ReportLayout/AbstractLayout.cs | 60 ++++++++++--------- .../ReportWizard/ReportLayout/ListLayout.cs | 17 ++++-- .../ReportWizard/ReportLayout/TableLayout.cs | 25 ++++---- .../Project/BaseItems/BaseSection.cs | 2 +- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/AbstractLayout.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/AbstractLayout.cs index aa4e410d22..9a89d5ed5a 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/AbstractLayout.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/AbstractLayout.cs @@ -15,8 +15,6 @@ namespace ICSharpCode.Reports.Addin.ReportWizard public class AbstractLayout { - ISimpleContainer parentItem; - public AbstractLayout(ReportModel reportModel) { if (reportModel == null) { @@ -35,11 +33,7 @@ namespace ICSharpCode.Reports.Addin.ReportWizard this.ReportModel.ReportHeader.Items.Add(textItem); } - public virtual void SetParent (ISimpleContainer parentItem) - { - this.parentItem = parentItem; - } - + public virtual void CreatePageHeader () { } @@ -83,8 +77,8 @@ namespace ICSharpCode.Reports.Addin.ReportWizard item.Location = p; } - - protected static void AdjustContainer (ICSharpCode.Reports.Core.BaseReportItem parent, + + protected static void AdjustContainer (ISimpleContainer parent, ICSharpCode.Reports.Core.BaseReportItem item) { item.Size = new Size (parent.Size.Width - GlobalValues.ControlMargins.Left - GlobalValues.ControlMargins.Right, @@ -92,13 +86,13 @@ namespace ICSharpCode.Reports.Addin.ReportWizard item.Location = new Point(GlobalValues.ControlMargins.Left, GlobalValues.ControlMargins.Top); - item.Parent = parent; + item.Parent = parent as BaseReportItem; } #region HeaderColumns - protected static ICSharpCode.Reports.Core.BaseRowItem CreateRowWithTextColumns(BaseReportItem parent,ReportItemCollection items) + protected static ICSharpCode.Reports.Core.BaseRowItem CreateRowWithTextColumns(ISimpleContainer parent,ReportItemCollection items) { ReportItemCollection colDetail = AbstractLayout.HeaderColumnsFromReportItems(items); @@ -106,11 +100,12 @@ namespace ICSharpCode.Reports.Addin.ReportWizard AdjustContainer(parent,row); int defY = parent.Location.Y + GlobalValues.ControlMargins.Top; - int defX = row.Size.Width / colDetail.Count; + int ctrlWidth = CalculateControlWidth(row,colDetail); int startX = parent.Location.X + GlobalValues.ControlMargins.Left; + foreach (ICSharpCode.Reports.Core.BaseTextItem ir in colDetail) { Point np = new Point(startX,defY); - startX += defX; + startX += ctrlWidth; ir.Location = np; ir.Parent = row; row.Items.Add(ir); @@ -119,6 +114,7 @@ namespace ICSharpCode.Reports.Addin.ReportWizard } + private static ReportItemCollection HeaderColumnsFromReportItems(ReportItemCollection reportItemCollection) { if (reportItemCollection == null) { @@ -138,35 +134,44 @@ namespace ICSharpCode.Reports.Addin.ReportWizard } #endregion - - protected static void AddItemsToSection (ICSharpCode.Reports.Core.BaseSection section,ReportItemCollection items) + /* + protected static ReportItemCollection AddItemsToSection (ICSharpCode.Reports.Core.BaseSection section,ReportItemCollection items) { int defY = section.Location.Y + GlobalValues.ControlMargins.Top; - int defX = section.Size.Width / items.Count; + int ctrlWidth = CalculateControlWidth(section,items); int startX = section.Location.X + GlobalValues.ControlMargins.Left; - + var vv = new ReportItemCollection(); foreach (var ir in items) { Point np = new Point(startX,defY); - startX += defX; + startX += ctrlWidth; ir.Location = np; - section.Items.Add(ir); +// section.Items.Add(ir); + vv.Add(ir); } + return vv; } + */ - - protected void AddItemsToContainer (ICSharpCode.Reports.Core.BaseSection section,ReportItemCollection items) + protected ReportItemCollection AddItemsToContainer (ReportItemCollection items) { - section.Items.Add(this.parentItem as BaseReportItem); int locationY = 10; - int locationX = this.parentItem.Location.X + GlobalValues.ControlMargins.Left; - int minCtrlWidth = this.parentItem.Size.Width / items.Count; + int locationX = this.ParentItem.Location.X + GlobalValues.ControlMargins.Left; + var minCtrlWidth = CalculateControlWidth(ParentItem,items); + var col = new ReportItemCollection(); foreach (var ir in items) { ir.Location = new Point(locationX,locationY); - this.parentItem.Items.Add(ir); + col.Add(ir); locationX += minCtrlWidth; } + return col; + } + + + protected static int CalculateControlWidth(ISimpleContainer row, ReportItemCollection colDetail) + { + return row.Size.Width / colDetail.Count; } @@ -191,12 +196,11 @@ namespace ICSharpCode.Reports.Addin.ReportWizard } #endregion + protected ReportModel ReportModel {get; private set;} - protected ISimpleContainer ParentItem { - get { return parentItem; } - } + protected ISimpleContainer ParentItem {get;set;} } } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/ListLayout.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/ListLayout.cs index 8b20caa3e0..e691758393 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/ListLayout.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/ListLayout.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.Reports.Addin.ReportWizard this.reportItems = reportItemCollection; ICSharpCode.Reports.Core.BaseRowItem row = new ICSharpCode.Reports.Core.BaseRowItem(); AdjustContainer(base.ReportModel.DetailSection,row); - base.SetParent(row); + base.ParentItem = row; } @@ -45,7 +45,9 @@ namespace ICSharpCode.Reports.Addin.ReportWizard throw new ArgumentNullException("section"); } - if (base.ReportModel.ReportSettings.GroupColumnsCollection.Count > 0) { + if (base.ReportModel.ReportSettings.GroupColumnsCollection.Count > 0) + { + var groupheader = base.CreateGroupHeader(new Point (5,10)); base.ReportModel.DetailSection.Items.Add(groupheader); @@ -56,11 +58,16 @@ namespace ICSharpCode.Reports.Addin.ReportWizard } if (base.ParentItem != null) { - base.AddItemsToContainer(base.ReportModel.DetailSection,this.reportItems); + var items = base.AddItemsToContainer(this.reportItems); + ParentItem.Items.AddRange(items); ParentItem.Size = new Size(ParentItem.Size.Width,40); + section.Items.Add(ParentItem as BaseReportItem); } - else{ - AddItemsToSection (base.ReportModel.DetailSection,this.reportItems); + else + { + //var items1 = AddItemsToSection (base.ReportModel.DetailSection,this.reportItems); + //AddItemsToSection (base.ReportModel.DetailSection,this.reportItems); + //section.Items.AddRange(items1); } } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs index e843d8246d..16d4cdde00 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs @@ -23,7 +23,6 @@ namespace ICSharpCode.Reports.Addin.ReportWizard } - public override void CreatePageHeader() { base.CreatePageHeader(); @@ -41,30 +40,30 @@ namespace ICSharpCode.Reports.Addin.ReportWizard ICSharpCode.Reports.Core.BaseTableItem table = new ICSharpCode.Reports.Core.BaseTableItem(); table.Name = "Table1"; - AdjustContainer(base.ReportModel.DetailSection,table); + base.ReportModel.DetailSection.Items.Add(table); + base.ParentItem = table; - ICSharpCode.Reports.Core.BaseRowItem headerRow = CreateRowWithTextColumns(table, - this.reportItems); + ICSharpCode.Reports.Core.BaseRowItem headerRow = CreateRowWithTextColumns(ParentItem, this.reportItems); + Point insertLocation = new Point (margin.Left,headerRow.Location.Y + headerRow.Size.Height + margin.Bottom + margin.Top); if (base.ReportModel.ReportSettings.GroupColumnsCollection.Count > 0) { var groupHeader = base.CreateGroupHeader(insertLocation); - table.Items.Add(groupHeader); + ParentItem.Items.Add(groupHeader); insertLocation = new Point(margin.Left,insertLocation.Y + groupHeader.Size.Height + margin.Bottom + margin.Top); } ICSharpCode.Reports.Core.BaseRowItem detailRow = new ICSharpCode.Reports.Core.BaseRowItem(); - AdjustContainer (table,detailRow); - + AdjustContainer (ParentItem,detailRow); detailRow.Location = insertLocation; - int defX = detailRow.Size.Width / this.reportItems.Count; + int defX = AbstractLayout.CalculateControlWidth(detailRow,reportItems); int startX = detailRow.Location.X + margin.Left; @@ -80,13 +79,13 @@ namespace ICSharpCode.Reports.Addin.ReportWizard insertLocation = new Point(margin.Left,insertLocation.Y + detailRow.Size.Height + margin.Bottom + margin.Top); - table.Items.Add (headerRow); - table.Items.Add (detailRow); + ParentItem.Items.Add (headerRow); + ParentItem.Items.Add (detailRow); - table.Size = CalculateContainerSize(table,margin); + ParentItem.Size = CalculateContainerSize(ParentItem,margin); - section.Size = new Size (section.Size.Width,table.Size.Height + margin.Top + margin.Bottom); - base.ReportModel.DetailSection.Items.Add(table); + section.Size = new Size (section.Size.Width,ParentItem.Size.Height + margin.Top + margin.Bottom); + } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseSection.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseSection.cs index ee3cbeeda9..d8d74d1cdd 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseSection.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseSection.cs @@ -16,7 +16,7 @@ using ICSharpCode.Reports.Core.Interfaces; namespace ICSharpCode.Reports.Core { - public class BaseSection : BaseReportItem { + public class BaseSection : BaseReportItem,ISimpleContainer { private bool pageBreakAfter; private ReportItemCollection items;