diff options
author | Carolyn MacLeod <carolyn> | 2011-04-11 16:28:40 +0000 |
---|---|---|
committer | Carolyn MacLeod <carolyn> | 2011-04-11 16:28:40 +0000 |
commit | 814d9ded9e1af6976010d762f2aadc439b042b0f (patch) | |
tree | 1deedfd8f154ca45917bebdaaded51fa380a7e6d /bundles/org.eclipse.swt/Eclipse SWT Printing | |
parent | ca2ab800288a0cff39f00b82f164bf6ac861ac7a (diff) | |
download | eclipse.platform.swt-814d9ded9e1af6976010d762f2aadc439b042b0f.tar.gz eclipse.platform.swt-814d9ded9e1af6976010d762f2aadc439b042b0f.tar.xz eclipse.platform.swt-814d9ded9e1af6976010d762f2aadc439b042b0f.zip |
Bug 342192 - PrintDialog crashes on xp if no printers are installed
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Printing')
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java | 41 |
1 files changed, 27 insertions, 14 deletions
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 23b5f1ed1a..a1ad1f3995 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 @@ -324,21 +324,34 @@ public PrinterData open() { pd.lStructSize = PRINTDLG.sizeof; pd.hwndOwner = hwndOwner; - boolean success = true; + boolean success = false; 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 { + /* Ensure that the printer name is in the current list of printers. */ + PrinterData printerList[] = Printer.getPrinterList(); + if (printerList.length > 0) { + for (int p = 0; p < printerList.length; p++) { + if (printerList[p].name.equals(printerData.name)) { + success = true; + break; + } + } + } + if (success) { + /* 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; + } + } + if (!success) { /* Initialize PRINTDLG fields, including DEVMODE, for the default printer. */ pd.Flags = OS.PD_RETURNDEFAULT; if (success = OS.PrintDlg(pd)) { |