mirror of
https://github.com/david-schmidt/gsport.git
synced 2024-09-27 08:54:30 +00:00
Improve handling of Windows printer dialog when printing to a native printer.
-If printing with multipage mode on, user will be prompted with the Windows printer dialog with each print job. If multipage mode is off, user will be prompted every time printer is reset to avoid being prompted for every page. -Improved error handling when user clicks "Cancel" on the print dialog. An error dialog is shown and the Virtual Imagewriter falls back to bitmap output.
This commit is contained in:
parent
4eb6157e11
commit
eeec76ecaf
@ -196,8 +196,8 @@ Imagewriter::Imagewriter(Bit16u dpi, Bit16u paperSize, Bit16u bannerSize, char*
|
|||||||
outputHandle = NULL;
|
outputHandle = NULL;
|
||||||
|
|
||||||
resetPrinter();
|
resetPrinter();
|
||||||
|
//Only initialize native printer here if multipage output is off. That way the user doesn't get prompted every page.
|
||||||
if (strcasecmp(output, "printer") == 0)
|
if (strcasecmp(output, "printer") == 0 && !multipageOutput)
|
||||||
{
|
{
|
||||||
#if defined (WIN32)
|
#if defined (WIN32)
|
||||||
// Show Print dialog to obtain a printer device context
|
// Show Print dialog to obtain a printer device context
|
||||||
@ -222,9 +222,13 @@ Imagewriter::Imagewriter(Bit16u dpi, Bit16u paperSize, Bit16u bannerSize, char*
|
|||||||
pd.lpPrintTemplateName = (LPCSTR) NULL;
|
pd.lpPrintTemplateName = (LPCSTR) NULL;
|
||||||
pd.lpSetupTemplateName = (LPCSTR) NULL;
|
pd.lpSetupTemplateName = (LPCSTR) NULL;
|
||||||
pd.hPrintTemplate = (HANDLE) NULL;
|
pd.hPrintTemplate = (HANDLE) NULL;
|
||||||
pd.hSetupTemplate = (HANDLE) NULL;
|
pd.hSetupTemplate = (HANDLE) NULL;
|
||||||
PrintDlg(&pd);
|
if(!PrintDlg(&pd))
|
||||||
// TODO: what if user presses cancel?
|
{
|
||||||
|
//If user presses cancel, warn them with a dialog and switch output to bitmap files
|
||||||
|
this->output = "bmp";
|
||||||
|
MessageBox(NULL,"You did not select a printer.\nAll printer output will be saved as bitmap files.\nTo select a printer, press F4 and select 'Reset Virtual Imagewriter'",NULL,MB_ICONEXCLAMATION);
|
||||||
|
}
|
||||||
printerDC = pd.hDC;
|
printerDC = pd.hDC;
|
||||||
ShowCursor(0);
|
ShowCursor(0);
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
@ -1635,7 +1639,53 @@ SDL_FreeSurface(image);*/
|
|||||||
if (strcasecmp(output, "printer") == 0)
|
if (strcasecmp(output, "printer") == 0)
|
||||||
{
|
{
|
||||||
#if defined (WIN32)
|
#if defined (WIN32)
|
||||||
|
if (multipageOutput && outputHandle == NULL)
|
||||||
|
{
|
||||||
|
ShowCursor(1);
|
||||||
|
PRINTDLG pd;
|
||||||
|
pd.lStructSize = sizeof(PRINTDLG);
|
||||||
|
pd.hDevMode = (HANDLE) NULL;
|
||||||
|
pd.hDevNames = (HANDLE) NULL;
|
||||||
|
pd.Flags = PD_RETURNDC;
|
||||||
|
pd.hwndOwner = NULL;
|
||||||
|
pd.hDC = (HDC) NULL;
|
||||||
|
pd.nFromPage = 1;
|
||||||
|
pd.nToPage = 1;
|
||||||
|
pd.nMinPage = 0;
|
||||||
|
pd.nMaxPage = 0;
|
||||||
|
pd.nCopies = 1;
|
||||||
|
pd.hInstance = NULL;
|
||||||
|
pd.lCustData = 0L;
|
||||||
|
pd.lpfnPrintHook = (LPPRINTHOOKPROC) NULL;
|
||||||
|
pd.lpfnSetupHook = (LPSETUPHOOKPROC) NULL;
|
||||||
|
pd.lpPrintTemplateName = (LPCSTR) NULL;
|
||||||
|
pd.lpSetupTemplateName = (LPCSTR) NULL;
|
||||||
|
pd.hPrintTemplate = (HANDLE) NULL;
|
||||||
|
pd.hSetupTemplate = (HANDLE) NULL;
|
||||||
|
if(!PrintDlg(&pd))
|
||||||
|
{
|
||||||
|
//If user clicks cancel, show warning dialog and force all output to bitmaps as failsafe.
|
||||||
|
MessageBox(NULL,"You did not select a printer.\nAll output from this print job will be saved as bitmap files.",NULL,MB_ICONEXCLAMATION);
|
||||||
|
findNextName("page", ".bmp", &fname[0]);
|
||||||
|
SDL_SaveBMP(page, fname); //Save first page as bitmap.
|
||||||
|
outputHandle = printerDC;
|
||||||
|
printerDC = NULL;
|
||||||
|
ShowCursor(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Create device context.
|
||||||
|
printerDC = pd.hDC;
|
||||||
|
ShowCursor(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!printerDC) //Fall thru for subsequent pages if printer dialog was cancelled.
|
||||||
|
{
|
||||||
|
findNextName("page", ".bmp", &fname[0]);
|
||||||
|
SDL_SaveBMP(page, fname); //Save remaining pages.
|
||||||
|
return;
|
||||||
|
}
|
||||||
Bit32u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH);
|
Bit32u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH);
|
||||||
Bit32u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT);
|
Bit32u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT);
|
||||||
Bit16u printeroffsetW = GetDeviceCaps(printerDC, PHYSICALOFFSETX); //printer x offset in actual pixels
|
Bit16u printeroffsetW = GetDeviceCaps(printerDC, PHYSICALOFFSETX); //printer x offset in actual pixels
|
||||||
|
Loading…
Reference in New Issue
Block a user