summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod <carolyn>2011-02-01 22:11:49 +0000
committerCarolyn MacLeod <carolyn>2011-02-01 22:11:49 +0000
commitdf61f40633a365af9813cad5cd26654bf724165c (patch)
treea1b91c93965036703923cbb9c26a8371341463ef
parent3aa6e5684bd78cc24966d6287af63ae36f7fadb9 (diff)
downloadeclipse.platform.swt-df61f40633a365af9813cad5cd26654bf724165c.tar.gz
eclipse.platform.swt-df61f40633a365af9813cad5cd26654bf724165c.tar.xz
eclipse.platform.swt-df61f40633a365af9813cad5cd26654bf724165c.zip
Bug 275624 - PrintDialog.setPrinterData does not work as expected
Bug 272331 - Setting fileName in PrinterData for PrintDialog does nothing
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java78
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java6
3 files changed, 61 insertions, 24 deletions
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 4322396e15..1d6c08c097 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
@@ -731,6 +731,7 @@ public class OS extends C {
public static final int GM_ADVANCED = 2;
public static final int GMDI_USEDISABLED = 0x1;
public static final int GMEM_FIXED = 0x0;
+ public static final int GMEM_MOVEABLE = 0x2;
public static final int GMEM_ZEROINIT = 0x40;
public static final int GN_CONTEXTMENU = 1000;
public static final int GPTR = 0x40;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
index 218d35addc..23b5f1ed1a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
@@ -292,9 +292,9 @@ public PrinterData open() {
int /*long*/ hwndParent = parent.handle;
/*
- * Feature in Windows. There is no API to set the orientation of a
- * file dialog. It is always inherited from the parent. The fix is
- * to create a hidden parent and set the orientation in the hidden
+ * Feature in Windows. There is no API to set the BIDI orientation
+ * of a print dialog. It is always inherited from the parent. The fix
+ * is to create a hidden parent and set the orientation in the hidden
* parent for the dialog to inherit.
*/
boolean enabled = false;
@@ -324,31 +324,69 @@ public PrinterData open() {
pd.lStructSize = PRINTDLG.sizeof;
pd.hwndOwner = hwndOwner;
- /* Initialize PRINTDLG fields, including DEVMODE. */
- pd.Flags = OS.PD_RETURNDEFAULT;
- if (OS.PrintDlg(pd)) {
- if (pd.hDevNames != 0) {
- OS.GlobalFree(pd.hDevNames);
- pd.hDevNames = 0;
+ boolean success = true;
+ if (printerData.name != null) {
+ /* Initialize PRINTDLG DEVNAMES for the specified printer. */
+ TCHAR buffer = new TCHAR(0, printerData.name, true);
+ int size = buffer.length() * TCHAR.sizeof;
+ short[] offsets = new short[4]; // DEVNAMES (4 offsets)
+ int offsetsSize = offsets.length * 2; // 2 bytes each
+ offsets[1] = (short) offsets.length; // offset 1 points to wDeviceOffset
+ int /*long*/ hMem = OS.GlobalAlloc(OS.GMEM_MOVEABLE | OS.GMEM_ZEROINIT, offsetsSize + size);
+ int /*long*/ ptr = OS.GlobalLock(hMem);
+ OS.MoveMemory(ptr, offsets, offsetsSize);
+ OS.MoveMemory(ptr + offsetsSize, buffer, size);
+ OS.GlobalUnlock(hMem);
+ pd.hDevNames = hMem;
+ } else {
+ /* Initialize PRINTDLG fields, including DEVMODE, for the default printer. */
+ pd.Flags = OS.PD_RETURNDEFAULT;
+ if (success = OS.PrintDlg(pd)) {
+ if (pd.hDevNames != 0) {
+ OS.GlobalFree(pd.hDevNames);
+ pd.hDevNames = 0;
+ }
}
+ }
+ if (success) {
/*
* If user setup info from a previous print dialog was specified,
* then restore the previous DEVMODE struct.
*/
byte devmodeData [] = printerData.otherData;
if (devmodeData != null && devmodeData.length != 0) {
- int /*long*/ lpInitData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, devmodeData.length);
- OS.MoveMemory(lpInitData, devmodeData, devmodeData.length);
+ int /*long*/ hMem = OS.GlobalAlloc(OS.GMEM_MOVEABLE | OS.GMEM_ZEROINIT, devmodeData.length);
+ int /*long*/ ptr = OS.GlobalLock(hMem);
+ OS.MoveMemory(ptr, devmodeData, devmodeData.length);
+ OS.GlobalUnlock(hMem);
if (pd.hDevMode != 0) OS.GlobalFree(pd.hDevMode);
- pd.hDevMode = lpInitData;
+ pd.hDevMode = hMem;
}
/* Initialize the DEVMODE struct's fields from the printerData. */
int /*long*/ hMem = pd.hDevMode;
+ if (hMem == 0) {
+ hMem = OS.GlobalAlloc(OS.GMEM_MOVEABLE | OS.GMEM_ZEROINIT, DEVMODE.sizeof);
+ pd.hDevMode = hMem;
+ }
int /*long*/ ptr = OS.GlobalLock(hMem);
DEVMODE devmode = OS.IsUnicode ? (DEVMODE)new DEVMODEW () : new DEVMODEA ();
OS.MoveMemory(devmode, ptr, OS.IsUnicode ? OS.DEVMODEW_sizeof() : OS.DEVMODEA_sizeof());
+ if (printerData.name != null) {
+ /* Copy PRINTDLG DEVNAMES into DEVMODE dmDeviceName (truncate if necessary). */
+ int max = Math.min(printerData.name.length(), OS.CCHDEVICENAME - 1);
+ if (OS.IsUnicode) {
+ for (int i = 0; i < max; i++) {
+ ((DEVMODEW) devmode).dmDeviceName[i] = printerData.name.charAt(i);
+ }
+ } else {
+ byte[] bytes = printerData.name.getBytes();
+ for (int i = 0; i < max; i++) {
+ ((DEVMODEA) devmode).dmDeviceName[i] = bytes[i];
+ }
+ }
+ }
devmode.dmFields |= OS.DM_ORIENTATION;
devmode.dmOrientation = printerData.orientation == PrinterData.PORTRAIT ? OS.DMORIENT_PORTRAIT : OS.DMORIENT_LANDSCAPE;
if (printerData.copyCount != 1) {
@@ -396,7 +434,7 @@ public PrinterData open() {
String key = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$
Object oldValue = display.getData(key);
display.setData(key, new Boolean(true));
- boolean success = OS.PrintDlg(pd);
+ success = OS.PrintDlg(pd);
display.setData(key, oldValue);
if ((getStyle() & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
for (int i=0; i<shells.length; i++) {
@@ -433,15 +471,7 @@ public PrinterData open() {
i++;
}
String device = buffer.toString(deviceOffset, i);
-
- int outputOffset = offsets[2];
- i = 0;
- while (outputOffset + i < size) {
- if (buffer.tcharAt(outputOffset + i) == 0) break;
- i++;
- }
- String output = buffer.toString(outputOffset, i);
-
+
/* Create PrinterData object and set fields from PRINTDLG */
data = new PrinterData(driver, device);
if ((pd.Flags & OS.PD_PAGENUMS) != 0) {
@@ -452,7 +482,7 @@ public PrinterData open() {
data.scope = PrinterData.SELECTION;
}
data.printToFile = (pd.Flags & OS.PD_PRINTTOFILE) != 0;
- if (data.printToFile) data.fileName = output;
+ if (data.printToFile) data.fileName = printerData.fileName;
data.copyCount = pd.nCopies;
data.collate = (pd.Flags & OS.PD_COLLATE) != 0;
@@ -462,6 +492,8 @@ public PrinterData open() {
ptr = OS.GlobalLock(hMem);
data.otherData = new byte[size];
OS.MoveMemory(data.otherData, ptr, size);
+
+ /* Set PrinterData fields from DEVMODE */
devmode = OS.IsUnicode ? (DEVMODE)new DEVMODEW () : new DEVMODEA ();
OS.MoveMemory(devmode, ptr, OS.IsUnicode ? OS.DEVMODEW_sizeof() : OS.DEVMODEA_sizeof());
if ((devmode.dmFields & OS.DM_ORIENTATION) != 0) {
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 9cbc5485e6..dd71dd0a11 100755
--- 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
@@ -353,7 +353,11 @@ public boolean startJob(String jobName) {
di.lpszDocName = lpszDocName;
}
int /*long*/ lpszOutput = 0;
- if (data.printToFile && data.fileName != null) {
+ if (data.printToFile) {
+ if (data.fileName == null) {
+ /* Prompt the user for a file name. */
+ data.fileName = "FILE:"; //$NON-NLS-1$
+ }
/* Use the character encoding for the default locale */
TCHAR buffer = new TCHAR(0, data.fileName, true);
int byteCount = buffer.length() * TCHAR.sizeof;