Preliminary support for PrintHandlers and basic PlainTextPrintHandler (needs a lot of work)
This commit is contained in:
parent
b3a460fc12
commit
4c1138198d
@ -20,6 +20,8 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using UniversalWidgetToolkit.Drawing;
|
||||
|
||||
namespace UniversalEditor.Printing
|
||||
{
|
||||
public abstract class PrintHandler : References<PrintHandlerReference>
|
||||
@ -37,10 +39,10 @@ namespace UniversalEditor.Printing
|
||||
return phr;
|
||||
}
|
||||
|
||||
protected abstract void PrintInternal(ObjectModel objectModel);
|
||||
public void Print(ObjectModel objectModel)
|
||||
protected abstract void PrintInternal(ObjectModel objectModel, Graphics g);
|
||||
public void Print(ObjectModel objectModel, Graphics g)
|
||||
{
|
||||
PrintInternal(objectModel);
|
||||
PrintInternal(objectModel, g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,8 @@ namespace UniversalEditor.Printing
|
||||
mvarType = dataFormatType;
|
||||
}
|
||||
|
||||
public ObjectModelReference.ObjectModelReferenceCollection SupportedObjectModels { get; } = new ObjectModelReference.ObjectModelReferenceCollection();
|
||||
|
||||
private Guid mvarID = Guid.Empty;
|
||||
public Guid ID { get { return mvarID; } set { mvarID = value; } }
|
||||
|
||||
|
||||
86
CSharp/Libraries/UniversalEditor.Printing/Reflection.cs
Normal file
86
CSharp/Libraries/UniversalEditor.Printing/Reflection.cs
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Reflection.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UniversalEditor.Printing
|
||||
{
|
||||
public static class Reflection
|
||||
{
|
||||
private static PrintHandlerReference[] _phrs = null;
|
||||
public static PrintHandlerReference[] GetAvailablePrintHandlers()
|
||||
{
|
||||
if (_phrs == null)
|
||||
Initialize();
|
||||
|
||||
return _phrs;
|
||||
}
|
||||
|
||||
public static PrintHandlerReference[] GetAvailablePrintHandlers(ObjectModel om)
|
||||
{
|
||||
List<PrintHandlerReference> list = new List<PrintHandlerReference>();
|
||||
PrintHandlerReference[] phrs = GetAvailablePrintHandlers();
|
||||
foreach (PrintHandlerReference phr in phrs)
|
||||
{
|
||||
if (phr.SupportedObjectModels.Contains(om.GetType()))
|
||||
list.Add(phr);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Assembly[] _asms = null;
|
||||
private static void Initialize()
|
||||
{
|
||||
if (_asms == null)
|
||||
{
|
||||
List<PrintHandlerReference> list = new List<PrintHandlerReference>();
|
||||
_asms = UniversalEditor.Common.Reflection.GetAvailableAssemblies();
|
||||
foreach (Assembly asm in _asms)
|
||||
{
|
||||
Type[] types = null;
|
||||
try
|
||||
{
|
||||
types = asm.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
types = ex.Types;
|
||||
}
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type == null) continue;
|
||||
|
||||
if (type.IsSubclassOf(typeof(PrintHandler)))
|
||||
{
|
||||
PrintHandler ph = (type.Assembly.CreateInstance(type.FullName) as PrintHandler);
|
||||
PrintHandlerReference phr = ph.MakeReference();
|
||||
|
||||
list.Add(phr);
|
||||
}
|
||||
}
|
||||
}
|
||||
_phrs = list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -32,12 +32,21 @@
|
||||
<Compile Include="PrintHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PrintHandlerReference.cs" />
|
||||
<Compile Include="Reflection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UniversalEditor.Core\UniversalEditor.Core.csproj">
|
||||
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
|
||||
<Name>UniversalEditor.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\..\UniversalWidgetToolkit\Libraries\UniversalWidgetToolkit\UniversalWidgetToolkit.csproj">
|
||||
<Project>{29E1C1BB-3EA5-4062-B62F-85EEC703FE07}</Project>
|
||||
<Name>UniversalWidgetToolkit</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
|
||||
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
|
||||
<Name>UniversalEditor.Essential</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -46,7 +46,7 @@ namespace UniversalEditor.Editors.Text.Plain
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private SyntaxTextBox txt = null;
|
||||
private TextBox txt = null;
|
||||
|
||||
private static EditorReference _er = null;
|
||||
public override EditorReference MakeReference ()
|
||||
@ -58,10 +58,17 @@ namespace UniversalEditor.Editors.Text.Plain
|
||||
return _er;
|
||||
}
|
||||
|
||||
private void txt_Changed(object sender, EventArgs e)
|
||||
{
|
||||
PlainTextObjectModel om = (this.ObjectModel as PlainTextObjectModel);
|
||||
om.Text = txt.Text;
|
||||
}
|
||||
|
||||
public PlainTextEditor ()
|
||||
{
|
||||
txt = new SyntaxTextBox();
|
||||
// txt.Multiline = true;
|
||||
txt = new TextBox();
|
||||
txt.Changed += txt_Changed;
|
||||
txt.Multiline = true;
|
||||
|
||||
this.Layout = new BoxLayout(Orientation.Vertical);
|
||||
this.Controls.Add(txt, new BoxLayout.Constraints(true, true));
|
||||
|
||||
@ -630,29 +630,11 @@ namespace UniversalEditor.UserInterface
|
||||
this.Destroy ();
|
||||
}
|
||||
|
||||
private class TestPrintHandler : PrintHandler
|
||||
{
|
||||
private static PrintHandlerReference _phr = null;
|
||||
protected override PrintHandlerReference MakeReferenceInternal()
|
||||
{
|
||||
if (_phr == null)
|
||||
{
|
||||
_phr = base.MakeReferenceInternal();
|
||||
}
|
||||
return _phr;
|
||||
}
|
||||
|
||||
protected override void PrintInternal(ObjectModel objectModel)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDocument()
|
||||
{
|
||||
Editor editor = GetCurrentEditor ();
|
||||
if (editor != null) {
|
||||
PrintHandler ph1 = new TestPrintHandler();
|
||||
PrintHandlerReference[] phrs = { ph1.MakeReference() }; // PrintHandler.GetAvailablePrintHandlers(editor.ObjectModel);
|
||||
PrintHandlerReference[] phrs = UniversalEditor.Printing.Reflection.GetAvailablePrintHandlers(editor.ObjectModel);
|
||||
if (phrs.Length > 0)
|
||||
{
|
||||
PrintDialog dlg = new PrintDialog();
|
||||
@ -661,7 +643,7 @@ namespace UniversalEditor.UserInterface
|
||||
PrintHandler ph = phrs[0].Create();
|
||||
if (ph != null)
|
||||
{
|
||||
PrintJob job = new PrintJob("Test Page", dlg.SelectedPrinter, dlg.Settings);
|
||||
PrintJob job = new PrintJob(editor.Title, dlg.SelectedPrinter, dlg.Settings);
|
||||
job.BeginPrint += Job_BeginPrint;
|
||||
job.DrawPage += Job_DrawPage;
|
||||
job.SetExtraData<PrintHandler>("ph", ph);
|
||||
@ -680,29 +662,7 @@ namespace UniversalEditor.UserInterface
|
||||
PrintHandler ph = job.GetExtraData<PrintHandler>("ph");
|
||||
ObjectModel om = job.GetExtraData<ObjectModel>("om");
|
||||
|
||||
|
||||
e.Graphics.DrawRectangle(new Pen(MBS.Framework.Drawing.Colors.Gray, new Measurement(1.0, MeasurementUnit.Pixel)), new Rectangle(20, 20, 120, 80));
|
||||
e.Graphics.DrawRectangle(new Pen(MBS.Framework.Drawing.Colors.Gray, new Measurement(1.0, MeasurementUnit.Pixel)), new Rectangle(180, 20, 80, 80));
|
||||
|
||||
e.Graphics.FillRectangle(new SolidBrush(MBS.Framework.Drawing.Colors.Gray), new Rectangle(20, 20, 120, 80));
|
||||
e.Graphics.FillRectangle(new SolidBrush(MBS.Framework.Drawing.Colors.Gray), new Rectangle(180, 20, 80, 80));
|
||||
|
||||
|
||||
// if (settings != NULL)
|
||||
// print.Settings = settings; // gtk_print_operation_set_print_settings(print, settings);
|
||||
|
||||
// res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
||||
// GTK_WINDOW(main_window), NULL);
|
||||
|
||||
// if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
|
||||
// {
|
||||
// if (settings != NULL)x
|
||||
// g_object_unref(settings);
|
||||
// settings = g_object_ref(gtk_print_operation_get_print_settings(print));
|
||||
//}
|
||||
|
||||
//g_object_unref(print);
|
||||
// ph.Print(om);
|
||||
ph.Print(om, e.Graphics);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
//
|
||||
// AssemblyInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("UniversalEditor.Plugins.Generic.Printing")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Mike Becker")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
@ -0,0 +1,50 @@
|
||||
//
|
||||
// PlainTextPrintHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using UniversalEditor.ObjectModels.Text.Plain;
|
||||
using UniversalEditor.Printing;
|
||||
using UniversalWidgetToolkit.Drawing;
|
||||
|
||||
namespace UniversalEditor.Plugins.Generic.Printing.Text.Plain
|
||||
{
|
||||
public class PlainTextPrintHandler : PrintHandler
|
||||
{
|
||||
private static PrintHandlerReference _phr = null;
|
||||
protected override PrintHandlerReference MakeReferenceInternal()
|
||||
{
|
||||
if (_phr == null)
|
||||
{
|
||||
_phr = base.MakeReferenceInternal();
|
||||
_phr.SupportedObjectModels.Add(typeof(PlainTextObjectModel));
|
||||
}
|
||||
return _phr;
|
||||
}
|
||||
|
||||
protected override void PrintInternal(ObjectModel objectModel, Graphics g)
|
||||
{
|
||||
PlainTextObjectModel text = (objectModel as PlainTextObjectModel);
|
||||
if (text == null)
|
||||
throw new ObjectModelNotSupportedException();
|
||||
|
||||
g.DrawText(text.Text, Font.FromFamily("Liberation Serif", 12), new Rectangle(64, 64, 1400, 1400), Brushes.Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>UniversalEditor.Plugins.Generic.Printing</RootNamespace>
|
||||
<AssemblyName>UniversalEditor.Plugins.Generic.Printing</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\Output\Debug\Plugins</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\Output\Release\Plugins</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Text\Plain\PlainTextPrintHandler.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Text\" />
|
||||
<Folder Include="Text\Plain\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
|
||||
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
|
||||
<Name>UniversalEditor.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Libraries\UniversalEditor.Printing\UniversalEditor.Printing.csproj">
|
||||
<Project>{868A6888-EDB9-407E-A710-40F297D4EAB8}</Project>
|
||||
<Name>UniversalEditor.Printing</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\..\UniversalWidgetToolkit\Libraries\UniversalWidgetToolkit\UniversalWidgetToolkit.csproj">
|
||||
<Project>{29E1C1BB-3EA5-4062-B62F-85EEC703FE07}</Project>
|
||||
<Name>UniversalWidgetToolkit</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Libraries\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
|
||||
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
|
||||
<Name>UniversalEditor.Essential</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -137,6 +137,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.TestProject
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Printing", "Libraries\UniversalEditor.Printing\UniversalEditor.Printing.csproj", "{868A6888-EDB9-407E-A710-40F297D4EAB8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins.Printing", "Plugins.Printing", "{FB678C6D-29A0-405B-BA86-E1EC12A96AA9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Generic.Printing", "Plugins.Printing\UniversalEditor.Plugins.Generic.Printing\UniversalEditor.Plugins.Generic.Printing.csproj", "{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -397,6 +401,10 @@ Global
|
||||
{868A6888-EDB9-407E-A710-40F297D4EAB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{868A6888-EDB9-407E-A710-40F297D4EAB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{868A6888-EDB9-407E-A710-40F297D4EAB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3231B32-A0E4-4B67-9A09-310B25BBB9B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5}
|
||||
@ -461,6 +469,7 @@ Global
|
||||
{E6C8A539-F219-4BD0-A2F4-E7064ABF6777} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
|
||||
{242A32D8-9A3A-4FE3-902B-AB9C3154723A} = {05D15661-E684-4EC9-8FBD-C014BA433CC5}
|
||||
{868A6888-EDB9-407E-A710-40F297D4EAB8} = {0399182F-AF56-4E86-B229-EAB38C2EE6AF}
|
||||
{A3231B32-A0E4-4B67-9A09-310B25BBB9B6} = {FB678C6D-29A0-405B-BA86-E1EC12A96AA9}
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
Policies = $0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user