|
|
@@ -43,14 +43,11 @@ namespace System.Drawing.Printing
|
|
|
|
|
|
}
|
|
|
|
|
|
- internal override bool IsPrinterValid(string printer, bool force)
|
|
|
+ internal override bool IsPrinterValid(string printer)
|
|
|
{
|
|
|
if (printer == null | printer == String.Empty)
|
|
|
return false;
|
|
|
|
|
|
- if (!force && this.printer_name != null && String.Intern(this.printer_name).Equals(printer))
|
|
|
- return is_printer_valid;
|
|
|
-
|
|
|
int ret = Win32DocumentProperties (IntPtr.Zero, IntPtr.Zero, printer, IntPtr.Zero, IntPtr.Zero, 0);
|
|
|
is_printer_valid = (ret > 0);
|
|
|
this.printer_name = printer;
|
|
|
@@ -75,6 +72,12 @@ namespace System.Drawing.Printing
|
|
|
ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ORIENTATION, IntPtr.Zero, IntPtr.Zero);
|
|
|
if (ret != -1)
|
|
|
settings.landscape_angle = ret;
|
|
|
+
|
|
|
+ IntPtr dc = IntPtr.Zero;
|
|
|
+ dc = Win32CreateIC (null, printer, null, IntPtr.Zero /* DEVMODE */);
|
|
|
+ ret = Win32GetDeviceCaps (dc, (int)DevCapabilities.TECHNOLOGY);
|
|
|
+ settings.is_plotter = ret == (int)PrinterType.DT_PLOTTER;
|
|
|
+ Win32DeleteDC (dc);
|
|
|
|
|
|
try {
|
|
|
Win32OpenPrinter (printer, out hPrn, IntPtr.Zero);
|
|
|
@@ -88,13 +91,15 @@ namespace System.Drawing.Printing
|
|
|
|
|
|
devmode = (DEVMODE) Marshal.PtrToStructure (ptr_dev, typeof(DEVMODE));
|
|
|
|
|
|
- foreach (PaperSize paper_size in settings.PaperSizes) {
|
|
|
+ LoadPrinterPaperSizes (printer, settings);
|
|
|
+ foreach (PaperSize paper_size in settings.PaperSizes) {
|
|
|
if ((int) paper_size.Kind == devmode.dmPaperSize) {
|
|
|
settings.DefaultPageSettings.PaperSize = paper_size;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ LoadPrinterPaperSources (printer, settings);
|
|
|
foreach (PaperSource paper_source in settings.PaperSources) {
|
|
|
if ((int) paper_source.Kind == devmode.dmDefaultSource) {
|
|
|
settings.DefaultPageSettings.PaperSource = paper_source;
|
|
|
@@ -106,7 +111,7 @@ namespace System.Drawing.Printing
|
|
|
Win32ClosePrinter (hPrn);
|
|
|
|
|
|
if (ptr_dev != IntPtr.Zero)
|
|
|
- Marshal.FreeHGlobal (ptr_dev);
|
|
|
+ Marshal.FreeHGlobal (ptr_dev);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -140,7 +145,7 @@ namespace System.Drawing.Printing
|
|
|
Marshal.FreeHGlobal (buff);
|
|
|
}
|
|
|
|
|
|
- internal override void LoadPrinterPaperSizes (string printer, PrinterSettings settings)
|
|
|
+ void LoadPrinterPaperSizes (string printer, PrinterSettings settings)
|
|
|
{
|
|
|
int items, ret;
|
|
|
IntPtr ptr_names, buff_names = IntPtr.Zero;
|
|
|
@@ -148,7 +153,11 @@ namespace System.Drawing.Printing
|
|
|
IntPtr ptr_sizes_enum, buff_sizes_enum = IntPtr.Zero;
|
|
|
string name;
|
|
|
|
|
|
- settings.PaperSizes.Clear ();
|
|
|
+ if (settings.PaperSizes == null)
|
|
|
+ settings.paper_sizes = new PrinterSettings.PaperSizeCollection (new PaperSize [0]);
|
|
|
+ else
|
|
|
+ settings.PaperSizes.Clear ();
|
|
|
+
|
|
|
items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
|
if (items == -1)
|
|
|
@@ -202,7 +211,7 @@ namespace System.Drawing.Printing
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal override bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file)
|
|
|
+ internal static bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file)
|
|
|
{
|
|
|
DOCINFO di = new DOCINFO ();
|
|
|
int ret;
|
|
|
@@ -218,7 +227,7 @@ namespace System.Drawing.Printing
|
|
|
return (ret > 0) ? true : false;
|
|
|
}
|
|
|
|
|
|
- internal override void LoadPrinterPaperSources (string printer, PrinterSettings settings)
|
|
|
+ void LoadPrinterPaperSources (string printer, PrinterSettings settings)
|
|
|
{
|
|
|
int items, ret;
|
|
|
IntPtr ptr_names, buff_names = IntPtr.Zero;
|
|
|
@@ -226,7 +235,11 @@ namespace System.Drawing.Printing
|
|
|
PaperSourceKind kind;
|
|
|
string name;
|
|
|
|
|
|
- settings.PaperSources.Clear ();
|
|
|
+ if (settings.PaperSources == null)
|
|
|
+ settings.paper_sources = new PrinterSettings.PaperSourceCollection (new PaperSource [0]);
|
|
|
+ else
|
|
|
+ settings.PaperSources.Clear ();
|
|
|
+
|
|
|
items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_BINNAMES, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
|
if (items == -1)
|
|
|
@@ -266,19 +279,19 @@ namespace System.Drawing.Printing
|
|
|
|
|
|
}
|
|
|
|
|
|
- internal override bool StartPage (GraphicsPrinter gr)
|
|
|
+ internal static bool StartPage (GraphicsPrinter gr)
|
|
|
{
|
|
|
int ret = Win32StartPage (gr.Hdc);
|
|
|
return (ret > 0) ? true : false;
|
|
|
}
|
|
|
|
|
|
- internal override bool EndPage (GraphicsPrinter gr)
|
|
|
+ internal static bool EndPage (GraphicsPrinter gr)
|
|
|
{
|
|
|
int ret = Win32EndPage (gr.Hdc);
|
|
|
return (ret > 0) ? true : false;
|
|
|
}
|
|
|
|
|
|
- internal override bool EndDoc (GraphicsPrinter gr)
|
|
|
+ internal static bool EndDoc (GraphicsPrinter gr)
|
|
|
{
|
|
|
int ret = Win32EndDoc (gr.Hdc);
|
|
|
Win32DeleteDC (gr.Hdc);
|
|
|
@@ -286,7 +299,7 @@ namespace System.Drawing.Printing
|
|
|
return (ret > 0) ? true : false;
|
|
|
}
|
|
|
|
|
|
- internal override IntPtr CreateGraphicsContext (PrinterSettings settings, PageSettings default_page_settings)
|
|
|
+ internal static IntPtr CreateGraphicsContext (PrinterSettings settings, PageSettings default_page_settings)
|
|
|
{
|
|
|
IntPtr dc = IntPtr.Zero;
|
|
|
dc = Win32CreateDC (null, settings.PrinterName, null, IntPtr.Zero /* DEVMODE */);
|
|
|
@@ -300,13 +313,13 @@ namespace System.Drawing.Printing
|
|
|
int length = name.Capacity;
|
|
|
|
|
|
if (Win32GetDefaultPrinter (name, ref length) > 0)
|
|
|
- if (this.IsPrinterValid(name.ToString(), false))
|
|
|
+ if (IsPrinterValid(name.ToString()))
|
|
|
return name.ToString ();
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal override PrinterSettings.StringCollection InstalledPrinters {
|
|
|
+ internal static PrinterSettings.StringCollection InstalledPrinters {
|
|
|
get {
|
|
|
PrinterSettings.StringCollection col = new PrinterSettings.StringCollection (new string[] {});
|
|
|
PRINTER_INFO printer_info;
|
|
|
@@ -409,14 +422,14 @@ namespace System.Drawing.Printing
|
|
|
// DllImports
|
|
|
//
|
|
|
|
|
|
- [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="OpenPrinter", SetLastError=true)]
|
|
|
+ [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="OpenPrinter", SetLastError=true)]
|
|
|
static extern int Win32OpenPrinter (string pPrinterName, out IntPtr phPrinter, IntPtr pDefault);
|
|
|
|
|
|
[DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="GetPrinter", SetLastError=true)]
|
|
|
static extern int Win32GetPrinter (IntPtr hPrinter, int level, IntPtr dwBuf, int size, ref int dwNeeded);
|
|
|
|
|
|
[DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="ClosePrinter", SetLastError=true)]
|
|
|
- static extern int Win32ClosePrinter (IntPtr hPrinter);
|
|
|
+ static extern int Win32ClosePrinter (IntPtr hPrinter);
|
|
|
|
|
|
[DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="DeviceCapabilities", SetLastError=true)]
|
|
|
static extern int Win32DeviceCapabilities (string device, string port, DCCapabilities cap, IntPtr outputBuffer, IntPtr deviceMode);
|
|
|
@@ -425,17 +438,21 @@ namespace System.Drawing.Printing
|
|
|
static extern int Win32EnumPrinters (int Flags, string Name, uint Level, IntPtr pPrinterEnum, uint cbBuf,
|
|
|
ref uint pcbNeeded, ref uint pcReturned);
|
|
|
|
|
|
- [DllImport("winspool.drv", EntryPoint="GetDefaultPrinter", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
|
- private static extern int Win32GetDefaultPrinter (StringBuilder buffer, ref int bufferSize);
|
|
|
+ [DllImport("winspool.drv", EntryPoint="GetDefaultPrinter", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
|
+ private static extern int Win32GetDefaultPrinter (StringBuilder buffer, ref int bufferSize);
|
|
|
|
|
|
- [DllImport("winspool.drv", EntryPoint="DocumentProperties", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
|
+ [DllImport("winspool.drv", EntryPoint="DocumentProperties", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
|
private static extern int Win32DocumentProperties (IntPtr hwnd, IntPtr hPrinter, string pDeviceName,
|
|
|
IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);
|
|
|
|
|
|
- [DllImport("gdi32.dll", EntryPoint="CreateDC")]
|
|
|
+ [DllImport("gdi32.dll", EntryPoint="CreateDC")]
|
|
|
static extern IntPtr Win32CreateDC (string lpszDriver, string lpszDevice,
|
|
|
string lpszOutput, IntPtr lpInitData);
|
|
|
|
|
|
+ [DllImport("gdi32.dll", EntryPoint="CreateIC")]
|
|
|
+ static extern IntPtr Win32CreateIC (string lpszDriver, string lpszDevice,
|
|
|
+ string lpszOutput, IntPtr lpInitData);
|
|
|
+
|
|
|
[DllImport("gdi32.dll", CharSet=CharSet.Unicode, EntryPoint="StartDoc")]
|
|
|
static extern int Win32StartDoc (IntPtr hdc, [In] ref DOCINFO lpdi);
|
|
|
|
|
|
@@ -451,9 +468,12 @@ namespace System.Drawing.Printing
|
|
|
[DllImport("gdi32.dll", EntryPoint="DeleteDC")]
|
|
|
public static extern IntPtr Win32DeleteDC (IntPtr hDc);
|
|
|
|
|
|
- //
|
|
|
- // Structs
|
|
|
- //
|
|
|
+ [DllImport("gdi32.dll", EntryPoint="GetDeviceCaps")]
|
|
|
+ public static extern int Win32GetDeviceCaps (IntPtr hDc, int index);
|
|
|
+
|
|
|
+ //
|
|
|
+ // Structs
|
|
|
+ //
|
|
|
[StructLayout (LayoutKind.Sequential)]
|
|
|
internal struct PRINTER_INFO
|
|
|
{
|
|
|
@@ -478,9 +498,9 @@ namespace System.Drawing.Printing
|
|
|
public uint Status;
|
|
|
public uint cJobs;
|
|
|
public uint AveragePPM;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- [StructLayout (LayoutKind.Sequential)]
|
|
|
+ [StructLayout (LayoutKind.Sequential)]
|
|
|
internal struct DOCINFO
|
|
|
{
|
|
|
public int cbSize;
|
|
|
@@ -490,47 +510,47 @@ namespace System.Drawing.Printing
|
|
|
public int fwType;
|
|
|
}
|
|
|
|
|
|
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
|
- internal struct DEVMODE
|
|
|
- {
|
|
|
- [MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
|
|
|
- public string dmDeviceName;
|
|
|
- public short dmSpecVersion;
|
|
|
- public short dmDriverVersion;
|
|
|
- public short dmSize;
|
|
|
- public short dmDriverExtra;
|
|
|
- public int dmFields;
|
|
|
-
|
|
|
- public short dmOrientation;
|
|
|
- public short dmPaperSize;
|
|
|
- public short dmPaperLength;
|
|
|
- public short dmPaperWidth;
|
|
|
-
|
|
|
- public short dmScale;
|
|
|
- public short dmCopies;
|
|
|
- public short dmDefaultSource;
|
|
|
- public short dmPrintQuality;
|
|
|
- public short dmColor;
|
|
|
- public short dmDuplex;
|
|
|
- public short dmYResolution;
|
|
|
- public short dmTTOption;
|
|
|
- public short dmCollate;
|
|
|
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
- public string dmFormName;
|
|
|
- public short dmLogPixels;
|
|
|
- public short dmBitsPerPel;
|
|
|
- public int dmPelsWidth;
|
|
|
- public int dmPelsHeight;
|
|
|
- public int dmDisplayFlags;
|
|
|
- public int dmDisplayFrequency;
|
|
|
- public int dmICMMethod;
|
|
|
- public int dmICMIntent;
|
|
|
- public int dmMediaType;
|
|
|
- public int dmDitherType;
|
|
|
- public int dmReserved1;
|
|
|
- public int dmReserved2;
|
|
|
- public int dmPanningWidth;
|
|
|
- public int dmPanningHeight;
|
|
|
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
|
+ internal struct DEVMODE
|
|
|
+ {
|
|
|
+ [MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
|
|
|
+ public string dmDeviceName;
|
|
|
+ public short dmSpecVersion;
|
|
|
+ public short dmDriverVersion;
|
|
|
+ public short dmSize;
|
|
|
+ public short dmDriverExtra;
|
|
|
+ public int dmFields;
|
|
|
+
|
|
|
+ public short dmOrientation;
|
|
|
+ public short dmPaperSize;
|
|
|
+ public short dmPaperLength;
|
|
|
+ public short dmPaperWidth;
|
|
|
+
|
|
|
+ public short dmScale;
|
|
|
+ public short dmCopies;
|
|
|
+ public short dmDefaultSource;
|
|
|
+ public short dmPrintQuality;
|
|
|
+ public short dmColor;
|
|
|
+ public short dmDuplex;
|
|
|
+ public short dmYResolution;
|
|
|
+ public short dmTTOption;
|
|
|
+ public short dmCollate;
|
|
|
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
+ public string dmFormName;
|
|
|
+ public short dmLogPixels;
|
|
|
+ public short dmBitsPerPel;
|
|
|
+ public int dmPelsWidth;
|
|
|
+ public int dmPelsHeight;
|
|
|
+ public int dmDisplayFlags;
|
|
|
+ public int dmDisplayFrequency;
|
|
|
+ public int dmICMMethod;
|
|
|
+ public int dmICMIntent;
|
|
|
+ public int dmMediaType;
|
|
|
+ public int dmDitherType;
|
|
|
+ public int dmReserved1;
|
|
|
+ public int dmReserved2;
|
|
|
+ public int dmPanningWidth;
|
|
|
+ public int dmPanningHeight;
|
|
|
}
|
|
|
|
|
|
// Enums
|
|
|
@@ -574,33 +594,86 @@ namespace System.Drawing.Printing
|
|
|
[Flags]
|
|
|
internal enum PrinterStatus : uint
|
|
|
{
|
|
|
- PS_PAUSED = 0x00000001,
|
|
|
- PS_ERROR = 0x00000002,
|
|
|
- PS_PENDING_DELETION = 0x00000004,
|
|
|
- PS_PAPER_JAM = 0x00000008,
|
|
|
- PS_PAPER_OUT = 0x00000010,
|
|
|
- PS_MANUAL_FEED = 0x00000020,
|
|
|
- PS_PAPER_PROBLEM = 0x00000040,
|
|
|
- PS_OFFLINE = 0x00000080,
|
|
|
- PS_IO_ACTIVE = 0x00000100,
|
|
|
- PS_BUSY = 0x00000200,
|
|
|
- PS_PRINTING = 0x00000400,
|
|
|
- PS_OUTPUT_BIN_FULL = 0x00000800,
|
|
|
- PS_NOT_AVAILABLE = 0x00001000,
|
|
|
- PS_WAITING = 0x00002000,
|
|
|
- PS_PROCESSING = 0x00004000,
|
|
|
- PS_INITIALIZING = 0x00008000,
|
|
|
- PS_WARMING_UP = 0x00010000,
|
|
|
- PS_TONER_LOW = 0x00020000,
|
|
|
- PS_NO_TONER = 0x00040000,
|
|
|
- PS_PAGE_PUNT = 0x00080000,
|
|
|
- PS_USER_INTERVENTION = 0x00100000,
|
|
|
- PS_OUT_OF_MEMORY = 0x00200000,
|
|
|
- PS_DOOR_OPEN = 0x00400000,
|
|
|
- PS_SERVER_UNKNOWN = 0x00800000,
|
|
|
+ PS_PAUSED = 0x00000001,
|
|
|
+ PS_ERROR = 0x00000002,
|
|
|
+ PS_PENDING_DELETION = 0x00000004,
|
|
|
+ PS_PAPER_JAM = 0x00000008,
|
|
|
+ PS_PAPER_OUT = 0x00000010,
|
|
|
+ PS_MANUAL_FEED = 0x00000020,
|
|
|
+ PS_PAPER_PROBLEM = 0x00000040,
|
|
|
+ PS_OFFLINE = 0x00000080,
|
|
|
+ PS_IO_ACTIVE = 0x00000100,
|
|
|
+ PS_BUSY = 0x00000200,
|
|
|
+ PS_PRINTING = 0x00000400,
|
|
|
+ PS_OUTPUT_BIN_FULL = 0x00000800,
|
|
|
+ PS_NOT_AVAILABLE = 0x00001000,
|
|
|
+ PS_WAITING = 0x00002000,
|
|
|
+ PS_PROCESSING = 0x00004000,
|
|
|
+ PS_INITIALIZING = 0x00008000,
|
|
|
+ PS_WARMING_UP = 0x00010000,
|
|
|
+ PS_TONER_LOW = 0x00020000,
|
|
|
+ PS_NO_TONER = 0x00040000,
|
|
|
+ PS_PAGE_PUNT = 0x00080000,
|
|
|
+ PS_USER_INTERVENTION = 0x00100000,
|
|
|
+ PS_OUT_OF_MEMORY = 0x00200000,
|
|
|
+ PS_DOOR_OPEN = 0x00400000,
|
|
|
+ PS_SERVER_UNKNOWN = 0x00800000,
|
|
|
PS_POWER_SAVE = 0x01000000
|
|
|
}
|
|
|
+
|
|
|
+ // for use in GetDeviceCaps
|
|
|
+ internal enum DevCapabilities
|
|
|
+ {
|
|
|
+ TECHNOLOGY = 2,
|
|
|
+ }
|
|
|
+
|
|
|
+ internal enum PrinterType
|
|
|
+ {
|
|
|
+ DT_PLOTTER = 0, // Vector Plotter
|
|
|
+ DT_RASDIPLAY = 1, // Raster Display
|
|
|
+ DT_RASPRINTER = 2, // Raster printer
|
|
|
+ DT_RASCAMERA = 3, // Raster camera
|
|
|
+ DT_CHARSTREAM = 4, // Character-stream, PLP
|
|
|
+ DT_METAFILE = 5, // Metafile, VDM
|
|
|
+ DT_DISPFILE = 6, // Display-file
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ class GlobalPrintingServicesWin32 : GlobalPrintingServices
|
|
|
+ {
|
|
|
+ internal override PrinterSettings.StringCollection InstalledPrinters {
|
|
|
+ get {
|
|
|
+ return PrintingServicesWin32.InstalledPrinters;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override IntPtr CreateGraphicsContext (PrinterSettings settings, PageSettings default_page_settings)
|
|
|
+ {
|
|
|
+ return PrintingServicesWin32.CreateGraphicsContext (settings, default_page_settings);
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file)
|
|
|
+ {
|
|
|
+ return PrintingServicesWin32.StartDoc (gr, doc_name, output_file);
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override bool EndDoc (GraphicsPrinter gr)
|
|
|
+ {
|
|
|
+ return PrintingServicesWin32.EndDoc (gr);
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override bool StartPage (GraphicsPrinter gr)
|
|
|
+ {
|
|
|
+ return PrintingServicesWin32.StartPage (gr);
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override bool EndPage (GraphicsPrinter gr)
|
|
|
+ {
|
|
|
+ return PrintingServicesWin32.EndPage (gr);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|