diff options
author | Silenio Quarti <silenio_quarti@ca.ibm.com> | 2011-08-17 18:33:08 -0400 |
---|---|---|
committer | Silenio Quarti <silenio_quarti@ca.ibm.com> | 2011-08-17 18:33:08 -0400 |
commit | 0af6a7dcf02fe44885063157294405c3130cd181 (patch) | |
tree | bc143d7ef7447a7e3e66531618ca19902257b5ac | |
parent | 956064920164af846897dbf9e7041081754b9dbf (diff) | |
download | eclipse.platform.swt-0af6a7dcf02fe44885063157294405c3130cd181.tar.gz eclipse.platform.swt-0af6a7dcf02fe44885063157294405c3130cd181.tar.xz eclipse.platform.swt-0af6a7dcf02fe44885063157294405c3130cd181.zip |
Bug 281912 - printing to non-default printer no longer works properly
6 files changed, 184 insertions, 36 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c index 31e8d5c765..997d92013a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c @@ -1023,6 +1023,18 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(CloseHandle) } #endif +#ifndef NO_ClosePrinter +JNIEXPORT jboolean JNICALL OS_NATIVE(ClosePrinter) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, ClosePrinter_FUNC); + rc = (jboolean)ClosePrinter((HANDLE)arg0); + OS_NATIVE_EXIT(env, that, ClosePrinter_FUNC); + return rc; +} +#endif + #ifndef NO_CloseThemeData JNIEXPORT jint JNICALL OS_NATIVE(CloseThemeData) (JNIEnv *env, jclass that, jintLong arg0) @@ -2280,6 +2292,38 @@ fail: } #endif +#ifndef NO_DocumentPropertiesA +JNIEXPORT jint JNICALL OS_NATIVE(DocumentPropertiesA) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jbyteArray arg2, jintLong arg3, jintLong arg4, jint arg5) +{ + jbyte *lparg2=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, DocumentPropertiesA_FUNC); + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)DocumentPropertiesA((HWND)arg0, (HANDLE)arg1, (LPTSTR)lparg2, (PDEVMODE)arg3, (PDEVMODE)arg4, arg5); +fail: + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0); + OS_NATIVE_EXIT(env, that, DocumentPropertiesA_FUNC); + return rc; +} +#endif + +#ifndef NO_DocumentPropertiesW +JNIEXPORT jint JNICALL OS_NATIVE(DocumentPropertiesW) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jcharArray arg2, jintLong arg3, jintLong arg4, jint arg5) +{ + jchar *lparg2=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, DocumentPropertiesW_FUNC); + if (arg2) if ((lparg2 = (*env)->GetCharArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)DocumentPropertiesW((HWND)arg0, (HANDLE)arg1, (LPWSTR)lparg2, (PDEVMODEW)arg3, (PDEVMODEW)arg4, arg5); +fail: + if (arg2 && lparg2) (*env)->ReleaseCharArrayElements(env, arg2, lparg2, 0); + OS_NATIVE_EXIT(env, that, DocumentPropertiesW_FUNC); + return rc; +} +#endif + #ifndef NO_DragDetect JNIEXPORT jboolean JNICALL OS_NATIVE(DragDetect) (JNIEnv *env, jclass that, jintLong arg0, jobject arg1) @@ -12113,6 +12157,44 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(OpenClipboard) } #endif +#ifndef NO_OpenPrinterA +JNIEXPORT jboolean JNICALL OS_NATIVE(OpenPrinterA) + (JNIEnv *env, jclass that, jbyteArray arg0, jintLongArray arg1, jintLong arg2) +{ + jbyte *lparg0=NULL; + jintLong *lparg1=NULL; + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, OpenPrinterA_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg1) if ((lparg1 = (*env)->GetIntLongArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jboolean)OpenPrinterA((LPTSTR)lparg0, (LPHANDLE)lparg1, (LPPRINTER_DEFAULTS)arg2); +fail: + if (arg1 && lparg1) (*env)->ReleaseIntLongArrayElements(env, arg1, lparg1, 0); + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + OS_NATIVE_EXIT(env, that, OpenPrinterA_FUNC); + return rc; +} +#endif + +#ifndef NO_OpenPrinterW +JNIEXPORT jboolean JNICALL OS_NATIVE(OpenPrinterW) + (JNIEnv *env, jclass that, jcharArray arg0, jintLongArray arg1, jintLong arg2) +{ + jchar *lparg0=NULL; + jintLong *lparg1=NULL; + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, OpenPrinterW_FUNC); + if (arg0) if ((lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg1) if ((lparg1 = (*env)->GetIntLongArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jboolean)OpenPrinterW((LPWSTR)lparg0, (LPHANDLE)lparg1, (LPPRINTER_DEFAULTSW)arg2); +fail: + if (arg1 && lparg1) (*env)->ReleaseIntLongArrayElements(env, arg1, lparg1, 0); + if (arg0 && lparg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, 0); + OS_NATIVE_EXIT(env, that, OpenPrinterW_FUNC); + return rc; +} +#endif + #ifndef NO_OpenProcess JNIEXPORT jintLong JNICALL OS_NATIVE(OpenProcess) (JNIEnv *env, jclass that, jint arg0, jboolean arg1, jint arg2) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.h index 1eb06481af..49d530b235 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.h @@ -196,6 +196,7 @@ #define NO_ChooseFontW #define NO_CloseEnhMetaFile #define NO_CloseGestureInfoHandle +#define NO_ClosePrinter #define NO_CloseThemeData #define NO_CloseTouchInputHandle #define NO_CoCreateInstance @@ -225,6 +226,8 @@ #define NO_DeleteEnhMetaFile #define NO_DestroyCursor #define NO_DispatchMessageA +#define NO_DocumentPropertiesA +#define NO_DocumentPropertiesW #define NO_DPtoLP #define NO_DragDetect #define NO_DragFinish @@ -446,6 +449,8 @@ #define NO_NotifyWinEvent #define NO_OleInitialize #define NO_OleUninitialize +#define NO_OpenPrinterA +#define NO_OpenPrinterW #define NO_OpenThemeData #define NO_PathIsExe #define NO_PeekMessageA diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c index 661e1110ca..0accdd13d2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 1059; -int OS_nativeFunctionCallCount[1059]; +int OS_nativeFunctionCount = 1064; +int OS_nativeFunctionCallCount[1064]; char * OS_nativeFunctionNames[] = { "ACCEL_1sizeof", "ACTCTX_1sizeof", @@ -90,6 +90,7 @@ char * OS_nativeFunctionNames[] = { "CloseEnhMetaFile", "CloseGestureInfoHandle", "CloseHandle", + "ClosePrinter", "CloseThemeData", "CloseTouchInputHandle", "CoCreateInstance", @@ -185,6 +186,8 @@ char * OS_nativeFunctionNames[] = { "DestroyWindow", "DispatchMessageA", "DispatchMessageW", + "DocumentPropertiesA", + "DocumentPropertiesW", "DragDetect", "DragFinish", "DragQueryFileA", @@ -1221,6 +1224,8 @@ char * OS_nativeFunctionNames[] = { "OleInitialize", "OleUninitialize", "OpenClipboard", + "OpenPrinterA", + "OpenPrinterW", "OpenProcess", "OpenThemeData", "PAINTSTRUCT_1sizeof", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h index 9bd7930ced..158eee7e48 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h @@ -98,6 +98,7 @@ typedef enum { CloseEnhMetaFile_FUNC, CloseGestureInfoHandle_FUNC, CloseHandle_FUNC, + ClosePrinter_FUNC, CloseThemeData_FUNC, CloseTouchInputHandle_FUNC, CoCreateInstance_FUNC, @@ -193,6 +194,8 @@ typedef enum { DestroyWindow_FUNC, DispatchMessageA_FUNC, DispatchMessageW_FUNC, + DocumentPropertiesA_FUNC, + DocumentPropertiesW_FUNC, DragDetect_FUNC, DragFinish_FUNC, DragQueryFileA_FUNC, @@ -1229,6 +1232,8 @@ typedef enum { OleInitialize_FUNC, OleUninitialize_FUNC, OpenClipboard_FUNC, + OpenPrinterA_FUNC, + OpenPrinterW_FUNC, OpenProcess_FUNC, OpenThemeData_FUNC, PAINTSTRUCT_1sizeof_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java index 464589f9a6..f26ec8294d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java @@ -552,6 +552,7 @@ public class OS extends C { public static final int DM_COPIES = 0x00000100; public static final int DM_DUPLEX = 0x00001000; public static final int DM_ORIENTATION = 0x00000001; + public static final int DM_OUT_BUFFER = 2; public static final short DMORIENT_PORTRAIT = 1; public static final short DMORIENT_LANDSCAPE = 2; public static final short DMDUP_SIMPLEX = 1; @@ -2532,6 +2533,15 @@ public static final int /*long*/ DispatchMessage (MSG lpmsg) { return DispatchMessageA (lpmsg); } +public static final int DocumentProperties (int /*long*/ hWnd, int /*long*/ hPrinter, TCHAR pDeviceName, int /*long*/ pDevModeOutput, int /*long*/ pDevModeInput, int fMode) { + if (IsUnicode) { + char [] pDeviceName1 = pDeviceName == null ? null : pDeviceName.chars; + return DocumentPropertiesW (hWnd, hPrinter, pDeviceName1, pDevModeOutput, pDevModeInput, fMode); + } + byte [] pDeviceName1 = pDeviceName == null ? null : pDeviceName.bytes; + return DocumentPropertiesA (hWnd, hPrinter, pDeviceName1, pDevModeOutput, pDevModeInput, fMode); +} + public static final int DragQueryFile (int /*long*/ hDrop, int iFile, TCHAR lpszFile, int cch) { if (IsUnicode) { char [] lpszFile1 = lpszFile == null ? null : lpszFile.chars; @@ -3092,6 +3102,15 @@ public static final void MoveMemory (TEXTMETRIC Destination, int /*long*/ Source } } +public static final boolean OpenPrinter (TCHAR pPrinterName, int /*long*/ [] phPrinter, int /*long*/ pDefault) { + if (IsUnicode) { + char [] pPrinterName1 = pPrinterName == null ? null : pPrinterName.chars; + return OpenPrinterW (pPrinterName1, phPrinter, pDefault); + } + byte [] pPrinterName1 = pPrinterName == null ? null : pPrinterName.bytes; + return OpenPrinterA (pPrinterName1, phPrinter, pDefault); +} + public static final boolean PeekMessage (MSG lpMsg, int /*long*/ hWnd, int wMsgFilterMin, int wMsgFilterMax, int wRemoveMsg) { if (IsUnicode) return PeekMessageW (lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); return PeekMessageA (lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); @@ -3644,6 +3663,8 @@ public static final native int /*long*/ CloseEnhMetaFile (int /*long*/ hdc); public static final native int /*long*/ CloseGestureInfoHandle (int /*long*/ hGesture); /** @param hObject cast=(HANDLE) */ public static final native boolean CloseHandle (int /*long*/ hObject); +/** @param hPrinter cast=(HANDLE) */ +public static final native boolean ClosePrinter (int /*long*/ hPrinter); /** * @method flags=dynamic * @param hTheme cast=(HTHEME) @@ -3911,6 +3932,22 @@ public static final native boolean DestroyMenu (int /*long*/ hMenu); public static final native boolean DestroyWindow (int /*long*/ hWnd); public static final native int /*long*/ DispatchMessageW (MSG lpmsg); public static final native int /*long*/ DispatchMessageA (MSG lpmsg); +/** + * @param hWnd cast=(HWND) + * @param hPrinter cast=(HANDLE) + * @param pDeviceName cast=(LPWSTR) + * @param pDevModeOutput cast=(PDEVMODEW) + * @param pDevModeInput cast=(PDEVMODEW) + */ +public static final native int DocumentPropertiesW (int /*long*/ hWnd, int /*long*/ hPrinter, char[] pDeviceName, int /*long*/ pDevModeOutput, int /*long*/ pDevModeInput, int fMode); +/** + * @param hWnd cast=(HWND) + * @param hPrinter cast=(HANDLE) + * @param pDeviceName cast=(LPTSTR) + * @param pDevModeOutput cast=(PDEVMODE) + * @param pDevModeInput cast=(PDEVMODE) + */ +public static final native int DocumentPropertiesA (int /*long*/ hWnd, int /*long*/ hPrinter, byte[] pDeviceName, int /*long*/ pDevModeOutput, int /*long*/ pDevModeInput, int fMode); /** @param hdc cast=(HDC) */ public static final native boolean DPtoLP (int /*long*/ hdc, POINT lpPoints, int nCount); /** @@ -4513,6 +4550,18 @@ public static final native int GetPixel (int /*long*/ hdc, int x, int y); /** @param hdc cast=(HDC) */ public static final native int GetPolyFillMode (int /*long*/ hdc); /** + * @param pPrinterName cast=(LPWSTR) + * @param phPrinter cast=(LPHANDLE) + * @param pDefault cast=(LPPRINTER_DEFAULTSW) + */ +public static final native boolean OpenPrinterW (char[] pPrinterName, int /*long*/ [] phPrinter, int /*long*/ pDefault); +/** + * @param pPrinterName cast=(LPTSTR) + * @param phPrinter cast=(LPHANDLE) + * @param pDefault cast=(LPPRINTER_DEFAULTS) + */ +public static final native boolean OpenPrinterA (byte[] pPrinterName, int /*long*/ [] phPrinter, int /*long*/ pDefault); +/** * @param hModule cast=(HMODULE) * @param lpProcName cast=(LPCTSTR) */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java index 9e9c64c2de..7acec23a00 100755..100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java @@ -222,46 +222,48 @@ protected void create(DeviceData deviceData) { lpInitData = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, devmodeData.length); OS.MoveMemory(lpInitData, devmodeData, devmodeData.length); } else { - /* Initialize DEVMODE for the default printer. */ - PRINTDLG pd = new PRINTDLG(); - pd.lStructSize = PRINTDLG.sizeof; - pd.Flags = OS.PD_RETURNDEFAULT; - if (!OS.PrintDlg(pd)) SWT.error(SWT.ERROR_NO_HANDLES); - if (pd.hDevMode != 0) { - int /*long*/ hGlobal = pd.hDevMode; - int /*long*/ ptr = OS.GlobalLock(hGlobal); - int size = OS.GlobalSize(hGlobal); - lpInitData = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size); - OS.MoveMemory(lpInitData, ptr, size); - OS.GlobalUnlock(hGlobal); - OS.GlobalFree(pd.hDevMode); + if (!OS.IsWinCE) { + int /*long*/ [] hPrinter = new int /*long*/ [1]; + OS.OpenPrinter(device, hPrinter, 0); + if (hPrinter[0] != 0) { + int dwNeeded = OS.DocumentProperties(0, hPrinter[0], device, 0, 0, 0); + if (dwNeeded >= 0) { + lpInitData = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, dwNeeded); + int rc = OS.DocumentProperties(0, hPrinter[0], device, lpInitData, 0, OS.DM_OUT_BUFFER); + if (rc != OS.IDOK) { + OS.HeapFree(hHeap, 0, lpInitData); + lpInitData = 0; + } + } + OS.ClosePrinter(hPrinter[0]); + } } - if (pd.hDevNames != 0) OS.GlobalFree(pd.hDevNames); } /* Initialize DEVMODE struct fields from the printerData. */ - DEVMODE devmode = OS.IsUnicode ? (DEVMODE)new DEVMODEW () : new DEVMODEA (); - OS.MoveMemory(devmode, lpInitData, DEVMODE.sizeof); - devmode.dmFields |= OS.DM_ORIENTATION; - devmode.dmOrientation = data.orientation == PrinterData.LANDSCAPE ? OS.DMORIENT_LANDSCAPE : OS.DMORIENT_PORTRAIT; - if (data.copyCount != 1) { - devmode.dmFields |= OS.DM_COPIES; - devmode.dmCopies = (short)data.copyCount; - } - if (data.collate != false) { - devmode.dmFields |= OS.DM_COLLATE; - devmode.dmCollate = OS.DMCOLLATE_TRUE; - } - if (data.duplex != SWT.DEFAULT) { - devmode.dmFields |= OS.DM_DUPLEX; - switch (data.duplex) { - case PrinterData.DUPLEX_SHORT_EDGE: devmode.dmDuplex = OS.DMDUP_HORIZONTAL; break; - case PrinterData.DUPLEX_LONG_EDGE: devmode.dmDuplex = OS.DMDUP_VERTICAL; break; - default: devmode.dmDuplex = OS.DMDUP_SIMPLEX; + if (lpInitData != 0) { + DEVMODE devmode = OS.IsUnicode ? (DEVMODE)new DEVMODEW () : new DEVMODEA (); + OS.MoveMemory(devmode, lpInitData, DEVMODE.sizeof); + devmode.dmFields |= OS.DM_ORIENTATION; + devmode.dmOrientation = data.orientation == PrinterData.LANDSCAPE ? OS.DMORIENT_LANDSCAPE : OS.DMORIENT_PORTRAIT; + if (data.copyCount != 1) { + devmode.dmFields |= OS.DM_COPIES; + devmode.dmCopies = (short)data.copyCount; + } + if (data.collate != false) { + devmode.dmFields |= OS.DM_COLLATE; + devmode.dmCollate = OS.DMCOLLATE_TRUE; } + if (data.duplex != SWT.DEFAULT) { + devmode.dmFields |= OS.DM_DUPLEX; + switch (data.duplex) { + case PrinterData.DUPLEX_SHORT_EDGE: devmode.dmDuplex = OS.DMDUP_HORIZONTAL; break; + case PrinterData.DUPLEX_LONG_EDGE: devmode.dmDuplex = OS.DMDUP_VERTICAL; break; + default: devmode.dmDuplex = OS.DMDUP_SIMPLEX; + } + } + OS.MoveMemory(lpInitData, devmode, DEVMODE.sizeof); } - OS.MoveMemory(lpInitData, devmode, DEVMODE.sizeof); - handle = OS.CreateDC(driver, device, 0, lpInitData); if (lpInitData != 0) OS.HeapFree(hHeap, 0, lpInitData); if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); |