This should fix #76928. This fix incorporates ideas from a patch
[mono.git] / mcs / class / System.Drawing / System.Drawing.Printing / PrintingServices.cs
1 //
2 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Author:
24 //
25 //      Jordi Mas i Hernandez, jordimash@gmail.com
26 //
27
28 using System.Runtime.InteropServices;
29 using System.Collections;
30 using System.Drawing.Printing;
31 using System.ComponentModel;
32 using System.Drawing.Imaging;
33
34 namespace System.Drawing.Printing
35 {
36         internal abstract class PrintingServices
37         {
38                 // Properties
39                 internal abstract PrinterSettings.StringCollection InstalledPrinters { get; }
40                 internal abstract string DefaultPrinter { get; }
41                                 
42
43                 // Methods
44                 internal abstract bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file);
45                 internal abstract IntPtr CreateGraphicsContext (PrinterSettings settings);
46                 internal abstract bool StartPage (GraphicsPrinter gr);
47                 internal abstract bool EndPage (GraphicsPrinter gr);
48                 internal abstract bool EndDoc (GraphicsPrinter gr);
49                 
50                 internal abstract void LoadPrinterSettings (string printer, PrinterSettings settings);
51                 internal abstract void LoadPrinterResolutions (string printer, PrinterSettings settings);
52                 internal abstract void LoadPrinterPaperSizes (string printer, PrinterSettings settings);
53                 
54                 internal void LoadDefaultResolutions (PrinterSettings.PrinterResolutionCollection col)
55                 {
56                         col.Add (new PrinterResolution ((int) PrinterResolutionKind.High, -1, PrinterResolutionKind.High));
57                         col.Add (new PrinterResolution ((int) PrinterResolutionKind.Medium, -1, PrinterResolutionKind.Medium));
58                         col.Add (new PrinterResolution ((int) PrinterResolutionKind.Low, -1, PrinterResolutionKind.Low));
59                         col.Add (new PrinterResolution ((int) PrinterResolutionKind.Draft, -1, PrinterResolutionKind.Draft));
60                 }
61         }
62
63         internal class SysPrn
64         {
65                 static PrintingServices service;
66
67                 static SysPrn ()
68                 {
69                         int platform = (int) Environment.OSVersion.Platform;
70                         
71                         if (platform == 4 || platform == 128) {
72                                 service = new  PrintingServicesUnix ();
73                         } else {
74                                 service = new PrintingServicesWin32 ();
75                         }
76                 }
77
78                 static internal PrintingServices Service {
79                         get { return service; }
80                 }
81         }
82         
83         internal class GraphicsPrinter
84         {
85                 private Graphics graphics;
86                 private IntPtr  hDC;
87                  
88                 internal GraphicsPrinter (Graphics gr, IntPtr dc)
89                 {
90                         graphics = gr;
91                         hDC = dc;
92                 }
93                                                 
94                 internal Graphics Graphics { 
95                         get { return graphics; }
96                         set { graphics = value; }
97                 }
98                 internal IntPtr Hdc { get { return hDC; }}
99         }
100 }
101
102