diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2015-01-20 11:37:59 -0800 |
---|---|---|
committer | Michael Vrhel <michael.vrhel@artifex.com> | 2015-01-20 11:37:59 -0800 |
commit | f24f164f25b66df32d7e584ba9993c1519386aac (patch) | |
tree | a68b42373791f14f8126f48228cac93ef442867b /platform/windows/gsprint/gsprint.cpp | |
parent | 90c560641d9b459a658029eefc4cbb02fdbca0b5 (diff) | |
download | mupdf-f24f164f25b66df32d7e584ba9993c1519386aac.tar.xz |
Rework of gsview printing with addition of new Print control dialog
This adds an additional project (gsprint.vxcproj) which will do the necessary native
calls to bring up the custom print dialog for the output device.
We can then obtain the settings and make the appropriate page
size adjustments in creating our xps content.
Diffstat (limited to 'platform/windows/gsprint/gsprint.cpp')
-rw-r--r-- | platform/windows/gsprint/gsprint.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/platform/windows/gsprint/gsprint.cpp b/platform/windows/gsprint/gsprint.cpp new file mode 100644 index 00000000..813364a8 --- /dev/null +++ b/platform/windows/gsprint/gsprint.cpp @@ -0,0 +1,73 @@ +// gsprint.cpp : Defines the exported functions for the DLL application. +// +#include "gsprint.h" +#include "stdlib.h" + +#define FAIL -1 + +/* Code to handle the special device properties window as well as make sure + * that the values are maintained when we leave */ +SYMBOL_DECLSPEC int __stdcall ShowPropertiesDialog(void *hptr, void *printername, bool show_win) +{ + HWND hWnd = (HWND)hptr; + HANDLE hPrinter = NULL; + LPDEVMODE pDevMode; + DWORD dwNeeded, dwRet; + wchar_t *output = NULL; + + int lenA = lstrlenA((char*)printername); + int lenW = ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, NULL, 0); + if (lenW > 0) + { + output = new wchar_t[lenW + 1]; + if (output == NULL) + return -1; + ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, output, lenW); + output[lenW] = 0; + } + else + return FAIL; + + if (!OpenPrinter(output, &hPrinter, NULL)) + { + free(output); + return FAIL; + } + + /* First get the size needed */ + dwNeeded = DocumentProperties(hWnd, hPrinter, output, NULL, NULL, 0); + pDevMode = (LPDEVMODE)malloc(dwNeeded); + if (pDevMode == NULL) + { + free(output); + ClosePrinter(hPrinter); + return FAIL; + } + + /* Now actually get the DEVMODE data. DM_IN_PROMPT brings up the window. + * DM_OUT_BUFFER ensures that we get the values that have been set */ + DWORD fMode = DM_OUT_BUFFER; + if (show_win) + fMode = fMode | DM_IN_PROMPT; + + dwRet = DocumentProperties(hWnd, hPrinter, output, pDevMode, NULL, fMode); + if (dwRet != IDOK) + { + free(output); + ClosePrinter(hPrinter); + free(pDevMode); + return FAIL; + } + + /* This is the secret to ensure that the DEVMODE settings are saved. Fun + * finding this bit of information in the MS literature */ + PRINTER_INFO_9 new_info; + new_info.pDevMode = pDevMode; + SetPrinter(hPrinter, 9, (LPBYTE)&new_info, 0); + + /* Clean up */ + free(pDevMode); + free(output); + ClosePrinter(hPrinter); + return 0; +} |