File: PrintManager.cs

package info (click to toggle)
mono-tools 4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,868 kB
  • sloc: cs: 100,909; sh: 3,845; makefile: 2,040; xml: 126
file content (59 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
//
// PrintManager.cs: GtkHTML version dependent printing support.
//
// Authors: Mario Sopena
// 	    Rafael Ferreira <raf@ophion.org>
//	    Mike Kestner <mkestner@novell.com>
//

using System;
using Gtk;
using Gnome;

namespace Monodoc {
	class PrintManager {
	
#if GTKHTML_SHARP_3_14
		public static void Print (string html)
		{
			new Gtk.HTML (html).PrintOperationRun (new PrintOperation (), PrintOperationAction.PrintDialog, null, null, null, null, null);
		}
#else
		// Fallback to the original GNOME Print API.
		public static void Print (string html) 
		{
			string caption = "Monodoc Printing";

			Gnome.PrintJob pj = new Gnome.PrintJob (PrintConfig.Default ());
			PrintDialog dialog = new PrintDialog (pj, caption, 0);

			Gtk.HTML gtk_html = new Gtk.HTML (html);
			gtk_html.PrintSetMaster (pj);
			
			Gnome.PrintContext ctx = pj.Context;
			gtk_html.Print (ctx);

			pj.Close ();

			// hello user
			int response = dialog.Run ();
		
			if (response == (int) PrintButtons.Cancel) {
				dialog.Hide ();
				dialog.Destroy ();
				return;
			} else if (response == (int) PrintButtons.Print) {
				pj.Print ();
			} else if (response == (int) PrintButtons.Preview) {
				new PrintJobPreview (pj, caption).Show ();
			}
		
			ctx.Close ();
			dialog.Hide ();
			dialog.Destroy ();
		}
#endif
	}
}