Ver Fonte

Merged InABox.Report.Common in to InABox.Core
Improved Text Alignments and Wrapping in Digital Forms

Frank van den Bos há 2 anos atrás
pai
commit
324e2cb503

+ 38 - 14
InABox.Core/DigitalForms/Layouts/Controls/DFLayoutLabel/DFLayoutTextStyle.cs

@@ -12,7 +12,7 @@ namespace InABox.Core
         Single,
         Double
     }
-
+    
     public interface IDFLayoutTextControl
     {
         T GetStyleProperty<T>(string property, T defaultValue);
@@ -52,6 +52,21 @@ namespace InABox.Core
         [ColorEditor]
         public string Background { get; set; }
 
+        [EditorSequence(6)]
+        [Caption("Horz Alignment", IncludePath = false)]
+        [EnumLookupEditor(typeof(DFLayoutAlignment))]
+        public DFLayoutAlignment HorizontalTextAlignment { get; set; }
+        
+        [EditorSequence(7)]
+        [Caption("Vertical Alignment", IncludePath = false)]
+        [EnumLookupEditor(typeof(DFLayoutAlignment))]
+        public DFLayoutAlignment VerticalTextAlignment { get; set; }
+        
+        [EditorSequence(8)]
+        [Caption("Allow Wrap?", IncludePath = false)]
+        [CheckBoxEditor]
+        public bool TextWrapping { get; set; }
+        
         [JsonIgnore]
         [NullEditor]
         public Color ForegroundColour { get => GetForegroundColour(); set => SetForegroundColour(value); }
@@ -59,7 +74,7 @@ namespace InABox.Core
         [JsonIgnore]
         [NullEditor]
         public Color BackgroundColour { get => GetBackgroundColour(); set => SetBackgroundColour(value); }
-
+        
         protected override void Init()
         {
             base.Init();
@@ -69,25 +84,34 @@ namespace InABox.Core
             Foreground = "";
             Background = "";
             FontSize = 0;
+            TextWrapping = true;
+            HorizontalTextAlignment = DFLayoutAlignment.Start;
+            VerticalTextAlignment = DFLayoutAlignment.Middle;
         }
 
         public void LoadProperties(IDFLayoutTextControl control)
         {
-            IsItalic = control.GetStyleProperty("IsItalic", false);
-            IsBold = control.GetStyleProperty("IsBold", false);
-            Underline = control.GetStyleProperty("Underline", UnderlineType.None);
-            Foreground = control.GetStyleProperty("Foreground", "");
-            Background = control.GetStyleProperty("Background", "");
-            FontSize = control.GetStyleProperty("FontSize", 0.0);
+            IsItalic = control.GetStyleProperty(nameof(IsItalic), false);
+            IsBold = control.GetStyleProperty(nameof(IsBold), false);
+            Underline = control.GetStyleProperty(nameof(Underline), UnderlineType.None);
+            Foreground = control.GetStyleProperty(nameof(Foreground), "");
+            Background = control.GetStyleProperty(nameof(Background), "");
+            FontSize = control.GetStyleProperty(nameof(FontSize), 0.0);
+            TextWrapping = control.GetStyleProperty(nameof(TextWrapping), true);
+            HorizontalTextAlignment = control.GetStyleProperty(nameof(HorizontalTextAlignment), DFLayoutAlignment.Start);
+            VerticalTextAlignment = control.GetStyleProperty(nameof(VerticalTextAlignment), DFLayoutAlignment.Middle);
         }
         public void SaveProperties(IDFLayoutTextControl control)
         {
-            control.SetStyleProperty("IsItalic", IsItalic);
-            control.SetStyleProperty("IsBold", IsBold);
-            control.SetStyleProperty("Underline", Underline);
-            control.SetStyleProperty("Foreground", Foreground);
-            control.SetStyleProperty("Background", Background);
-            control.SetStyleProperty("FontSize", FontSize);
+            control.SetStyleProperty(nameof(IsItalic), IsItalic);
+            control.SetStyleProperty(nameof(IsBold), IsBold);
+            control.SetStyleProperty(nameof(Underline), Underline);
+            control.SetStyleProperty(nameof(Foreground), Foreground);
+            control.SetStyleProperty(nameof(Background), Background);
+            control.SetStyleProperty(nameof(FontSize), FontSize);
+            control.SetStyleProperty(nameof(TextWrapping), TextWrapping);
+            control.SetStyleProperty(nameof(HorizontalTextAlignment), HorizontalTextAlignment);
+            control.SetStyleProperty(nameof(VerticalTextAlignment), VerticalTextAlignment);
         }
 
         public Color GetForegroundColour() => ColourFromString(Foreground);

+ 12 - 6
InABox.Core/DigitalForms/Layouts/Fields/DFLayoutStringField/DFLayoutStringFieldProperties.cs

@@ -1,15 +1,21 @@
 namespace InABox.Core
 {
+    
     public class DFLayoutStringFieldProperties : DFLayoutFieldProperties<string>
     {
+        [EditorSequence(3)]
+        [CheckBoxEditor(Caption = "Allow Wrap?")]
+        public bool TextWrapping { get; set; }
+        
+        [EditorSequence(4)]
         [CheckBoxEditor(Caption = "Popup Editor?")]
         public bool PopupEditor { get; set; }
-
+        
         protected override void Init()
         {
             base.Init();
-
             PopupEditor = false;
+            TextWrapping = false;
         }
 
         public override object? ParseValue(object? value)
@@ -25,15 +31,15 @@
         protected override void LoadProperties()
         {
             base.LoadProperties();
-
-            PopupEditor = GetProperty("PopupEditor", false);
+            PopupEditor = GetProperty(nameof(PopupEditor), false);
+            TextWrapping = GetProperty(nameof(TextWrapping), false);
         }
 
         protected override void SaveProperties()
         {
             base.SaveProperties();
-
-            SetProperty("PopupEditor", PopupEditor);
+            SetProperty(nameof(PopupEditor), PopupEditor);
+            SetProperty(nameof(TextWrapping), TextWrapping);
         }
     }
 }

+ 2 - 2
inabox.reports.common/ReportPrinters.cs → InABox.Core/Reports/ReportPrinters.cs

@@ -1,10 +1,10 @@
 using System.Collections.Generic;
 
-namespace InABox.Reports.Common
+namespace InABox.Core.Reports
 {
     public static class ReportPrinters
     {
-        private static readonly List<string> _printers = new();
+        private static readonly List<string> _printers = new List<string>();
 
         public static string[] All => _printers.ToArray();
 

+ 1 - 1
inabox.reports.common/ReportTemplate.cs → InABox.Core/Reports/ReportTemplate.cs

@@ -1,7 +1,7 @@
 using System;
 using InABox.Core;
 
-namespace InABox.Reports.Common
+namespace InABox.Core.Reports
 {
     [UserTracking(false)]
     public class ReportTemplate : Entity, IPersistent, IRemotable, ILicense<CoreLicense>

+ 0 - 1
InABox.Database/InABox.Database.csproj

@@ -16,7 +16,6 @@
         <ProjectReference Include="..\InABox.Configuration\InABox.Configuration.csproj" />
         <ProjectReference Include="..\InABox.Core\InABox.Core.csproj" />
         <ProjectReference Include="..\inabox.logging.shared\InABox.Logging.Shared.csproj" />
-        <ProjectReference Include="..\InABox.Reports.Common\InABox.Reports.Common.csproj" />
         <ProjectReference Include="..\InABox.Scripting\InABox.Scripting.csproj" />
     </ItemGroup>
 

+ 1 - 1
InABox.Database/Stores/DigitalFormStore.cs

@@ -1,5 +1,5 @@
 using InABox.Core;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 
 namespace InABox.Database
 {

+ 0 - 1
InABox.Reports/InABox.Reports.csproj

@@ -39,7 +39,6 @@
 
     <ItemGroup>
         <ProjectReference Include="..\InABox.Core\InABox.Core.csproj" />
-        <ProjectReference Include="..\InABox.DynamicGrid\InABox.DynamicGrid.csproj" />
         <ProjectReference Include="..\InABox.Reports.Common\InABox.Reports.Common.csproj" />
         <ProjectReference Include="..\InABox.Scripting\InABox.Scripting.csproj" />
         <ProjectReference Include="..\inabox.wpf\InABox.Wpf.csproj" />

+ 2 - 2
inabox.reports.common/InABox.Reports.Common.csproj

@@ -9,11 +9,11 @@
             <PrivateAssets>all</PrivateAssets>
             <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
         </PackageReference>
-        <PackageReference Include="PropertyChanged.Fody" Version="3.4.1"/>
+        <PackageReference Include="PropertyChanged.Fody" Version="3.4.1" />
     </ItemGroup>
 
     <ItemGroup>
-        <ProjectReference Include="..\..\InABox\InABox.Core\InABox.Core.csproj"/>
+        <ProjectReference Include="..\..\InABox\InABox.Core\InABox.Core.csproj" />
     </ItemGroup>
 
 </Project>

+ 16 - 0
inabox.scripting/Spreadsheet/ISheet.cs

@@ -6,6 +6,7 @@ using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using InABox.Core;
 
 namespace InABox.Scripting
 {
@@ -52,6 +53,14 @@ namespace InABox.Scripting
         public Color Colour { get; }
     }
 
+    public enum CellAlignment
+    {
+        Start,
+        Middle,
+        End,
+        Justify
+    }
+
     public interface ICellStyle
     {
         public ISpreadsheet Spreadsheet { get; }
@@ -63,6 +72,13 @@ namespace InABox.Scripting
         public Color Background { get; }
 
         public Color Foreground { get; }
+        
+        public CellAlignment VerticalAlignment { get; }
+        
+        public CellAlignment HorizontalAlignment { get; }
+        
+        public bool WrapText { get; }
+        
     }
 
     public interface ISheet

+ 18 - 0
inabox.scripting/Spreadsheet/NPOISpreadsheet.cs

@@ -516,6 +516,24 @@ namespace InABox.Scripting
 
         public IFont Font => new Font(_style.GetFont(Spreadsheet.Workbook), Spreadsheet);
 
+        public CellAlignment VerticalAlignment => _style.VerticalAlignment switch
+        {
+            NPOI.SS.UserModel.VerticalAlignment.Top => CellAlignment.Start,
+            NPOI.SS.UserModel.VerticalAlignment.Bottom => CellAlignment.End,
+            NPOI.SS.UserModel.VerticalAlignment.Justify => CellAlignment.Justify,
+            _ => CellAlignment.Middle
+        };
+
+        public CellAlignment HorizontalAlignment => _style.Alignment switch
+        {
+            NPOI.SS.UserModel.HorizontalAlignment.Center => CellAlignment.Middle,
+            NPOI.SS.UserModel.HorizontalAlignment.Right => CellAlignment.End,
+            NPOI.SS.UserModel.HorizontalAlignment.Justify => CellAlignment.Justify,
+            _ => CellAlignment.Start
+        };
+
+        public bool WrapText => _style.WrapText;
+        
         public CellStyle(NCellStyle style, Spreadsheet spreadsheet)
         {
             _style = style;

+ 16 - 1
inabox.wpf/DigitalForms/Designer/Controls/DFLabelControl.cs

@@ -25,9 +25,24 @@ namespace InABox.DynamicGrid
             var textBlock = new TextBlock
             {
                 Text = Control.Caption,
+                TextWrapping = TextWrapping.WrapWithOverflow,
                 FontWeight = style.IsBold ? FontWeights.Bold : FontWeights.Normal,
                 FontStyle = style.IsItalic ? FontStyles.Italic : FontStyles.Normal,
-                VerticalAlignment = VerticalAlignment.Center,
+                VerticalAlignment = Control.Style.VerticalTextAlignment switch
+                {
+                    DFLayoutAlignment.Start => VerticalAlignment.Top,
+                    DFLayoutAlignment.End => VerticalAlignment.Bottom,
+                    DFLayoutAlignment.Stretch => VerticalAlignment.Stretch,
+                    _ => VerticalAlignment.Center
+                },
+                HorizontalAlignment = HorizontalAlignment.Stretch,
+                TextAlignment = Control.Style.HorizontalTextAlignment switch
+                {
+                    DFLayoutAlignment.Middle => TextAlignment.Center,
+                    DFLayoutAlignment.End => TextAlignment.Right,
+                    DFLayoutAlignment.Stretch => TextAlignment.Justify,
+                    _ => TextAlignment.Left
+                },
                 Margin = new Thickness(5)
             };
 

+ 3 - 2
inabox.wpf/DigitalForms/Designer/Controls/Fields/DFStringControl.cs

@@ -50,8 +50,9 @@ namespace InABox.DynamicGrid
             {
                 TextBox = new TextBox();
                 TextBox.Text = Field.Properties.Default;
-                TextBox.HorizontalContentAlignment = HorizontalAlignment.Left;
-                TextBox.VerticalContentAlignment = VerticalAlignment.Center;
+                TextBox.TextWrapping = Field.Properties.TextWrapping ? TextWrapping.Wrap : TextWrapping.NoWrap;
+                TextBox.VerticalContentAlignment = VerticalAlignment.Top;
+                TextBox.TextAlignment = TextAlignment.Left;
                 TextBox.TextChanged += (sender, e) => ChangeField();
                 element = TextBox;
             }

+ 0 - 3
inabox.wpf/DigitalForms/DigitalFormGrid.cs

@@ -6,9 +6,6 @@ using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 using InABox.Clients;
 using InABox.Core;
-using InABox.DynamicGrid;
-using InABox.Reports;
-using InABox.Reports.Common;
 using InABox.WPF;
 using Microsoft.Win32;
 

+ 2 - 2
inabox.wpf/DigitalForms/DigitalFormReportGrid.cs

@@ -2,7 +2,7 @@
 using FastReport.Data;
 using InABox.Clients;
 using InABox.Core;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using InABox.Wpf.Reports;
 using InABox.WPF;
 using Syncfusion.DocIO.DLS;
@@ -176,7 +176,7 @@ namespace InABox.DynamicGrid
 
             foreach(var element in dfLayout.Elements)
             {
-
+                
             }
 
             return report;

+ 25 - 13
inabox.wpf/DigitalForms/DynamicFormLayoutGrid.cs

@@ -164,15 +164,9 @@ namespace InABox.DynamicGrid
             }
 
             for (int row = firstRow; row <= lastRow; ++row)
-            {
-                float height = sheet.GetRowHeight(row);
-                float defaultheight = sheet.GetDefaultRowHeight(); 
-                float multiplier = defaultheight == 0 ? 1.0F : height/defaultheight;
-                var final = Math.Round(multiplier * 10,0) * 5;
-                layout.RowHeights.Add($"{final}");
-            }
-            
-            foreach(var cell in cells)
+                layout.RowHeights.Add("Auto");
+
+                foreach(var cell in cells)
             {
                 var style = cell.InnerCell.GetStyle();
 
@@ -211,14 +205,13 @@ namespace InABox.DynamicGrid
                     var field = (Activator.CreateInstance(fieldType) as DFLayoutField)!;
                     field.Name = variableName.Value;
                     
-                    
                     if (variableProps.Success)
                     {
                         if (field is DFLayoutOptionField option)
                             option.Properties.Options = variableProps.Value;
-                        
+                        if (field is DFLayoutStringField text)
+                            text.Properties.TextWrapping = style.WrapText;
                         // need to populate other variable types here
-                        
                     }
                     
                     
@@ -265,7 +258,26 @@ namespace InABox.DynamicGrid
                     _ => UnderlineType.None
                 },
                 BackgroundColour = style.Background,
-                ForegroundColour = style.Font.Colour
+                ForegroundColour = style.Font.Colour,
+
+                HorizontalTextAlignment = style.HorizontalAlignment switch
+                {
+                     CellAlignment.Middle => DFLayoutAlignment.Middle,
+                     CellAlignment.End => DFLayoutAlignment.End,
+                     CellAlignment.Justify => DFLayoutAlignment.Stretch,
+                     _ => DFLayoutAlignment.Start
+                },
+                
+                VerticalTextAlignment = style.VerticalAlignment switch
+                {
+                    CellAlignment.Start => DFLayoutAlignment.Start,
+                    CellAlignment.End => DFLayoutAlignment.End,
+                    CellAlignment.Justify => DFLayoutAlignment.Stretch,
+                    _ => DFLayoutAlignment.Middle
+                },
+                
+                TextWrapping = style.WrapText
+
             };
             return result;
         }

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicGridUtils.cs

@@ -10,7 +10,7 @@ using System.Windows.Controls;
 using InABox.Clients;
 using InABox.Core;
 using InABox.Wpf;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using Syncfusion.Data.Extensions;
 
 namespace InABox.DynamicGrid

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicOneToManyGrid.cs

@@ -11,7 +11,7 @@ using System.Windows.Media.Imaging;
 using InABox.Clients;
 using InABox.Configuration;
 using InABox.Core;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using InABox.WPF;
 
 namespace InABox.DynamicGrid

+ 0 - 1
inabox.wpf/InABox.Wpf.csproj

@@ -119,7 +119,6 @@
         <ProjectReference Include="..\InABox.Configuration\InABox.Configuration.csproj" />
         <ProjectReference Include="..\InABox.Core\InABox.Core.csproj" />
         <ProjectReference Include="..\InABox.Dxf\InABox.Dxf.csproj" />
-        <ProjectReference Include="..\InABox.Reports.Common\InABox.Reports.Common.csproj" />
         <ProjectReference Include="..\InABox.Scripting\InABox.Scripting.csproj" />
     </ItemGroup>
 

+ 1 - 1
inabox.wpf/Reports/PreviewWindow.xaml.cs

@@ -20,7 +20,7 @@ using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
 using System;
 using InABox.Wpf;
 using TextBox = System.Windows.Controls.TextBox;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using ICSharpCode.AvalonEdit.Highlighting;
 using System.Drawing;
 using System.Collections.Generic;

+ 1 - 1
inabox.wpf/Reports/ReportGrid.cs

@@ -6,7 +6,7 @@ using System.Windows.Media.Imaging;
 using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using InABox.WPF;
 using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
 using SaveFileDialog = Microsoft.Win32.SaveFileDialog;

+ 1 - 6
inabox.wpf/Reports/ReportUtils.cs

@@ -12,18 +12,13 @@ using System.Windows;
 using System.Windows.Controls;
 using FastReport;
 using FastReport.Data;
-using FastReport.Design;
-using FastReport.Design.StandardDesigner;
 using FastReport.Export.Pdf;
 using FastReport.Utils;
 using InABox.Clients;
 using InABox.Core;
-using InABox.Reports.Common;
+using InABox.Core.Reports;
 using InABox.Scripting;
 using InABox.Wpf.Reports.CustomObjects;
-using InABox.WPF;
-using Microsoft.CodeAnalysis.Scripting;
-using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
 using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 using XmlDocument = System.Xml.XmlDocument;