From 8270a2d62e35751aaba2f73c10816cf3865c262a Mon Sep 17 00:00:00 2001 From: smallsql Date: Wed, 15 Dec 2010 14:53:33 +0000 Subject: Some fixes on the printing API from Karsten Heinrich --- awt/printing.cs | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 5 deletions(-) (limited to 'awt') diff --git a/awt/printing.cs b/awt/printing.cs index 7d5983ec..1cce4826 100644 --- a/awt/printing.cs +++ b/awt/printing.cs @@ -1,5 +1,6 @@ /* Copyright (C) 2009 Volker Berlin (i-net software) + Copyright (C) 2010 Karsten Heinrich (i-net software) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -115,12 +116,31 @@ namespace ikvm.awt.printing private const int ERROR_INSUFFICIENT_BUFFER = 122; - private const int PRINTER_STATUS_DOOR_OPEN = 0x400000; - private const int PRINTER_STATUS_ERROR = 0x2; - private const int PRINTER_STATUS_NO_TONER = 0x40000; - private const int PRINTER_STATUS_OFFLINE = 0x80; - private const int PRINTER_STATUS_OUT_OF_MEMORY = 0x200000; + private const int PRINTER_STATUS_PAUSED = 0x1; + private const int PRINTER_STATUS_ERROR = 0x2; // MSDN says that this value is not used + private const int PRINTER_STATUS_PENDING_DELETION = 0x4; + private const int PRINTER_STATUS_PAPER_JAM = 0x8; + private const int PRINTER_STATUS_PAPER_OUT = 0x10; + private const int PRINTER_STATUS_MANUAL_FEED = 0x20; + private const int PRINTER_STATUS_PAPER_PROBLEM = 0x40; + private const int PRINTER_STATUS_OFFLINE = 0x80; + private const int PRINTER_STATUS_IO_ACTIVE = 0x100; + private const int PRINTER_STATUS_BUSY = 0x200; + private const int PRINTER_STATUS_PRINTING = 0x400; + private const int PRINTER_STATUS_OUTPUT_BIN_FULL = 0x800; + private const int PRINTER_STATUS_NOT_AVAILABLE = 0x1000; + private const int PRINTER_STATUS_WAITING = 0x2000; + private const int PRINTER_STATUS_PROCESSING = 0x4000; + private const int PRINTER_STATUS_INITIALIZING = 0x8000; + private const int PRINTER_STATUS_WARMING_UP = 0x10000; + private const int PRINTER_STATUS_TONER_LOW = 0x20000; + private const int PRINTER_STATUS_NO_TONER = 0x40000; + private const int PRINTER_STATUS_PAGE_PUNT = 0x80000; private const int PRINTER_STATUS_USER_INTERVENTION = 0x100000; + private const int PRINTER_STATUS_OUT_OF_MEMORY = 0x200000; + private const int PRINTER_STATUS_DOOR_OPEN = 0x400000; + private const int PRINTER_STATUS_SERVER_UNKNOWN = 0x800000; + private const int PRINTER_STATUS_POWER_SAVE = 0x1000000; /// /// Get a printer status @@ -134,6 +154,27 @@ namespace ikvm.awt.printing int status; if (GetPrinterInfo2(printerName, out cJobs, out status)) { + if (category == (java.lang.Class)typeof(javax.print.attribute.standard.PrinterState)) + { + if ((status & + (PRINTER_STATUS_ERROR | PRINTER_STATUS_NO_TONER | PRINTER_STATUS_OUT_OF_MEMORY | + PRINTER_STATUS_OFFLINE | PRINTER_STATUS_USER_INTERVENTION | + PRINTER_STATUS_DOOR_OPEN | PRINTER_STATUS_NOT_AVAILABLE )) > 0) + { + return javax.print.attribute.standard.PrinterState.STOPPED; + } + if( (status & (PRINTER_STATUS_BUSY | PRINTER_STATUS_PRINTING ))> 0 ) + { + return javax.print.attribute.standard.PrinterState.PROCESSING; + } + return null; + // null seems to be the default instead of unknown - UNKOWN ist not used in the reference RT + // javax.print.attribute.standard.PrinterState.UNKNOWN; + } + if (category == (java.lang.Class)typeof(javax.print.attribute.standard.PrinterStateReasons)) + { + return extractResions(status); + } if (category == (java.lang.Class)typeof(javax.print.attribute.standard.QueuedJobCount)) { return new javax.print.attribute.standard.QueuedJobCount(cJobs); @@ -159,6 +200,65 @@ namespace ikvm.awt.printing return null; } + private javax.print.attribute.standard.PrinterStateReasons extractResions(int status) + { + javax.print.attribute.standard.PrinterStateReasons reasons = new javax.print.attribute.standard.PrinterStateReasons(); + if ((status & PRINTER_STATUS_PAUSED) > 0) + { + reasons.put(javax.print.attribute.standard.PrinterStateReason.PAUSED, javax.print.attribute.standard.Severity.REPORT); + } + if ((status & PRINTER_STATUS_ERROR) > 0) + { + reasons.put(javax.print.attribute.standard.PrinterStateReason.OTHER, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_PENDING_DELETION) > 0) { } + if ((status & PRINTER_STATUS_PAPER_JAM) > 0) + { + reasons.put(javax.print.attribute.standard.PrinterStateReason.MEDIA_JAM, javax.print.attribute.standard.Severity.WARNING); + } + if ((status & PRINTER_STATUS_PAPER_OUT) > 0) + { + reasons.put(javax.print.attribute.standard.PrinterStateReason.MEDIA_EMPTY, javax.print.attribute.standard.Severity.WARNING); + } + if ((status & PRINTER_STATUS_MANUAL_FEED) > 0) { } + if ((status & PRINTER_STATUS_PAPER_PROBLEM) > 0) {} + if ((status & PRINTER_STATUS_OFFLINE) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.TIMED_OUT, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_IO_ACTIVE) > 0) { } + if ((status & PRINTER_STATUS_BUSY) > 0) { } + if ((status & PRINTER_STATUS_PRINTING) > 0) { } + if ((status & PRINTER_STATUS_OUTPUT_BIN_FULL) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.OUTPUT_AREA_FULL, javax.print.attribute.standard.Severity.WARNING); + } + if ((status & PRINTER_STATUS_NOT_AVAILABLE) > 0) { } + if ((status & PRINTER_STATUS_WAITING) > 0) { } + if ((status & PRINTER_STATUS_PROCESSING) > 0) { } + if ((status & PRINTER_STATUS_INITIALIZING) > 0) { } + if ((status & PRINTER_STATUS_WARMING_UP) > 0) { } + if ((status & PRINTER_STATUS_TONER_LOW) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.TONER_LOW, javax.print.attribute.standard.Severity.WARNING); + } + if ((status & PRINTER_STATUS_NO_TONER) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.TONER_EMPTY, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_PAGE_PUNT) > 0) { } + if ((status & PRINTER_STATUS_USER_INTERVENTION) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.OTHER, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_OUT_OF_MEMORY) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.OTHER, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_DOOR_OPEN) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.DOOR_OPEN, javax.print.attribute.standard.Severity.ERROR); + } + if ((status & PRINTER_STATUS_SERVER_UNKNOWN) > 0) { } + if ((status & PRINTER_STATUS_POWER_SAVE) > 0) { + reasons.put(javax.print.attribute.standard.PrinterStateReason.PAUSED, javax.print.attribute.standard.Severity.REPORT); + } + return reasons.isEmpty() ? null : reasons; + } + /// /// Get infos from the PRINTER_INFO_2 struc /// @@ -228,4 +328,8 @@ namespace ikvm.awt.printing return ClosePrinter(handle); } } + + class Win32Print + { + } } -- cgit v1.2.3