-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/printing' into develop
- Loading branch information
Showing
55 changed files
with
2,486 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Source/Eto.Platform.Gtk/Forms/Printing/PrintDialogHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using Eto.Forms; | ||
|
||
namespace Eto.Platform.GtkSharp.Forms.Printing | ||
{ | ||
public class PrintDialogHandler : WidgetHandler<Gtk.PrintUnixDialog, PrintDialog>, IPrintDialog | ||
{ | ||
PrintSettings settings; | ||
|
||
public PrintDialogHandler () | ||
{ | ||
AllowPageRange =true; | ||
} | ||
|
||
public class CustomOptions : Gtk.VBox { | ||
public Gtk.CheckButton SelectionOnly { get; private set; } | ||
|
||
public CustomOptions () | ||
{ | ||
this.Spacing = 10; | ||
SelectionOnly = new Gtk.CheckButton { Label = "Selection Only" }; | ||
this.PackStart (SelectionOnly, false, false, 10); | ||
} | ||
} | ||
|
||
public DialogResult ShowDialog (Window parent) | ||
{ | ||
var parentWindow = parent != null ? (Gtk.Window)parent.ControlObject : null; | ||
Control = new Gtk.PrintUnixDialog(string.Empty, parentWindow); | ||
|
||
if (parent != null) | ||
{ | ||
Control.TransientFor = ((Gtk.Window)parent.ControlObject); | ||
Control.Modal = true; | ||
} | ||
|
||
var caps = Gtk.PrintCapabilities.Preview | ||
| Gtk.PrintCapabilities.Collate | ||
| Gtk.PrintCapabilities.GeneratePdf | ||
| Gtk.PrintCapabilities.Copies | ||
| Gtk.PrintCapabilities.PageSet | ||
| Gtk.PrintCapabilities.GeneratePs | ||
| Gtk.PrintCapabilities.Scale | ||
| Gtk.PrintCapabilities.NumberUp | ||
| Gtk.PrintCapabilities.Reverse; | ||
var printSettingsHandler = (PrintSettingsHandler)this.PrintSettings.Handler; | ||
|
||
Control.PageSetup = this.PrintSettings.ToGtkPageSetup (); | ||
Control.PrintSettings = this.PrintSettings.ToGtkPrintSettings (); | ||
var customOptions = new CustomOptions(); | ||
customOptions.SelectionOnly.Active = printSettingsHandler.SelectionOnly; | ||
|
||
if (AllowSelection) | ||
Control.AddCustomTab (customOptions, new Gtk.Label { Text = "Other Options" }); | ||
|
||
Control.ManualCapabilities = caps; | ||
Control.ShowAll (); | ||
var response = (Gtk.ResponseType)Control.Run (); | ||
Control.Hide (); | ||
|
||
printSettingsHandler.Set(Control.PrintSettings, Control.PageSetup, customOptions.SelectionOnly.Active); | ||
if (response == Gtk.ResponseType.Apply) { | ||
printSettingsHandler.ShowPreview = true; | ||
return DialogResult.Ok; | ||
} | ||
|
||
return response.ToEto (); | ||
} | ||
public PrintSettings PrintSettings { | ||
get { | ||
if (settings == null) settings = new PrintSettings(Widget.Generator); | ||
return settings; | ||
} | ||
set { | ||
settings = value; | ||
} | ||
} | ||
|
||
// not supported in gtk | ||
public bool AllowPageRange { | ||
get; set; | ||
} | ||
|
||
public bool AllowSelection { | ||
get; set; | ||
} | ||
} | ||
} | ||
|
81 changes: 81 additions & 0 deletions
81
Source/Eto.Platform.Gtk/Forms/Printing/PrintDocumentHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using Eto.Forms; | ||
using Eto.Drawing; | ||
using Eto.Platform.GtkSharp.Drawing; | ||
|
||
namespace Eto.Platform.GtkSharp.Forms.Printing | ||
{ | ||
public class PrintDocumentHandler : WidgetHandler<Gtk.PrintOperation, PrintDocument>, IPrintDocument | ||
{ | ||
PrintSettings settings; | ||
|
||
public PrintDocumentHandler () | ||
{ | ||
Control = new Gtk.PrintOperation(); | ||
} | ||
|
||
public void Print () | ||
{ | ||
var settingsHandler = (PrintSettingsHandler)this.PrintSettings.Handler; | ||
Control.PrintSettings = settingsHandler.Control; | ||
if (settingsHandler.ShowPreview) | ||
Control.Run (Gtk.PrintOperationAction.Preview, null); | ||
else | ||
Control.Run (Gtk.PrintOperationAction.Print, null); | ||
} | ||
|
||
public override void AttachEvent (string id) | ||
{ | ||
switch (id) { | ||
case PrintDocument.BeginPrintEvent: | ||
Control.BeginPrint += (o, args) => { | ||
Widget.OnBeginPrint (EventArgs.Empty); | ||
}; | ||
break; | ||
case PrintDocument.EndPrintEvent: | ||
Control.EndPrint += (o, args) => { | ||
Widget.OnEndPrint (EventArgs.Empty); | ||
}; | ||
break; | ||
|
||
case PrintDocument.PrintPageEvent: | ||
Control.DrawPage += (o, args) => { | ||
using (var graphics = new Graphics(Widget.Generator, new GraphicsHandler(args.Context.CairoContext, args.Context.CreatePangoContext ()))) { | ||
var width = args.Context.Width; //.PageSetup.GetPageWidth(Gtk.Unit.Points); | ||
var height = args.Context.Height; //.PageSetup.GetPageHeight(Gtk.Unit.Points); | ||
var e = new PrintPageEventArgs(graphics, new SizeF((float)width, (float)height), args.PageNr); | ||
Widget.OnPrintPage (e); | ||
} | ||
}; | ||
break; | ||
default: | ||
base.AttachEvent (id); | ||
break; | ||
} | ||
} | ||
|
||
public string Name { | ||
get { return Control.JobName; } | ||
set { Control.JobName = value; } | ||
} | ||
|
||
public PrintSettings PrintSettings { | ||
get { | ||
if (settings == null) | ||
settings = Control.PrintSettings.ToEto (Control.DefaultPageSetup, false, Widget.Generator); | ||
return settings; | ||
} | ||
set { | ||
settings = value; | ||
Control.DefaultPageSetup = settings.ToGtkPageSetup (); | ||
Control.PrintSettings = settings.ToGtkPrintSettings (); | ||
} | ||
} | ||
|
||
public int PageCount { | ||
get { return Control.NPages; } | ||
set { Control.NPages = value; } | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.