forked from AuroraMiddleware/gtk
Fixed bug that prevented GTK from storing printer driver preferences in the print dialogue on Windows.
This commit is contained in:
parent
98dd53c2c3
commit
fc15a409cc
@ -952,9 +952,10 @@ dialog_to_print_settings (GtkPrintOperation *op,
|
||||
|
||||
static HANDLE
|
||||
devmode_from_settings (GtkPrintSettings *settings,
|
||||
GtkPageSetup *page_setup)
|
||||
GtkPageSetup *page_setup,
|
||||
HANDLE hDevModeParam)
|
||||
{
|
||||
HANDLE hDevMode;
|
||||
HANDLE hDevMode = hDevModeParam;
|
||||
LPDEVMODEW devmode;
|
||||
guchar *extras;
|
||||
GtkPaperSize *paper_size;
|
||||
@ -962,31 +963,42 @@ devmode_from_settings (GtkPrintSettings *settings,
|
||||
gsize extras_len;
|
||||
const char *val;
|
||||
|
||||
extras = NULL;
|
||||
extras_len = 0;
|
||||
extras_base64 = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA);
|
||||
if (extras_base64)
|
||||
extras = g_base64_decode (extras_base64, &extras_len);
|
||||
|
||||
hDevMode = GlobalAlloc (GMEM_MOVEABLE,
|
||||
sizeof (DEVMODEW) + extras_len);
|
||||
|
||||
devmode = GlobalLock (hDevMode);
|
||||
|
||||
memset (devmode, 0, sizeof (DEVMODEW));
|
||||
|
||||
devmode->dmSpecVersion = DM_SPECVERSION;
|
||||
devmode->dmSize = sizeof (DEVMODEW);
|
||||
|
||||
devmode->dmDriverExtra = 0;
|
||||
if (extras && extras_len > 0)
|
||||
// If we already provided a valid hDevMode, don't initialize a new one; just lock the one we have
|
||||
if (hDevMode)
|
||||
{
|
||||
devmode->dmDriverExtra = extras_len;
|
||||
memcpy (((char *)devmode) + sizeof (DEVMODEW), extras, extras_len);
|
||||
devmode = GlobalLock (hDevMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
extras = NULL;
|
||||
extras_len = 0;
|
||||
extras_base64 = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA);
|
||||
if (extras_base64)
|
||||
extras = g_base64_decode (extras_base64, &extras_len);
|
||||
|
||||
hDevMode = GlobalAlloc (GMEM_MOVEABLE,
|
||||
sizeof (DEVMODEW) + extras_len);
|
||||
|
||||
devmode = GlobalLock (hDevMode);
|
||||
|
||||
memset (devmode, 0, sizeof (DEVMODEW));
|
||||
|
||||
devmode->dmSpecVersion = DM_SPECVERSION;
|
||||
devmode->dmSize = sizeof (DEVMODEW);
|
||||
|
||||
devmode->dmDriverExtra = 0;
|
||||
if (extras && extras_len > 0)
|
||||
{
|
||||
devmode->dmDriverExtra = extras_len;
|
||||
memcpy (((char *)devmode) + sizeof (DEVMODEW), extras, extras_len);
|
||||
}
|
||||
g_free (extras);
|
||||
|
||||
if (gtk_print_settings_has_key (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION))
|
||||
{
|
||||
devmode->dmDriverVersion = gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION);
|
||||
}
|
||||
}
|
||||
g_free (extras);
|
||||
if (gtk_print_settings_has_key (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION))
|
||||
devmode->dmDriverVersion = gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION);
|
||||
|
||||
if (page_setup ||
|
||||
gtk_print_settings_has_key (settings, GTK_PRINT_SETTINGS_ORIENTATION))
|
||||
@ -1240,12 +1252,25 @@ dialog_from_print_settings (GtkPrintOperation *op,
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a printer saved, restore our settings
|
||||
printer = gtk_print_settings_get_printer (settings);
|
||||
if (printer)
|
||||
{
|
||||
printdlgex->hDevNames = gtk_print_win32_devnames_to_win32_from_printer_name (printer);
|
||||
|
||||
printdlgex->hDevMode = devmode_from_settings (settings,
|
||||
op->priv->default_page_setup);
|
||||
printdlgex->hDevMode = devmode_from_settings (settings,
|
||||
op->priv->default_page_setup, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, use the default settings
|
||||
DWORD FlagsCopy = printdlgex->Flags;
|
||||
printdlgex->Flags |= PD_RETURNDEFAULT;
|
||||
PrintDlgExW (printdlgex);
|
||||
printdlgex->Flags = FlagsCopy;
|
||||
|
||||
devmode_from_settings (settings, op->priv->default_page_setup, printdlgex->hDevMode);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@ -1421,7 +1446,7 @@ pageDlgProc (HWND wnd, UINT message, WPARAM wparam, LPARAM lparam)
|
||||
if (message == WM_SIZE)
|
||||
{
|
||||
gtk_widget_queue_resize (op_win32->embed_widget);
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -1577,7 +1602,7 @@ gtk_print_operation_run_without_dialog (GtkPrintOperation *op,
|
||||
}
|
||||
|
||||
hDevNames = gtk_print_win32_devnames_to_win32_from_printer_name (printer);
|
||||
hDevMode = devmode_from_settings (settings, op->priv->default_page_setup);
|
||||
hDevMode = devmode_from_settings (settings, op->priv->default_page_setup, NULL);
|
||||
|
||||
/* Create a printer DC for the print settings and page setup provided. */
|
||||
pdn = GlobalLock (hDevNames);
|
||||
@ -2075,7 +2100,7 @@ gtk_print_run_page_setup_dialog (GtkWindow *parent,
|
||||
pagesetupdlg->hwndOwner = NULL;
|
||||
|
||||
pagesetupdlg->Flags = PSD_DEFAULTMINMARGINS;
|
||||
pagesetupdlg->hDevMode = devmode_from_settings (settings, page_setup);
|
||||
pagesetupdlg->hDevMode = devmode_from_settings (settings, page_setup, NULL);
|
||||
pagesetupdlg->hDevNames = NULL;
|
||||
printer = gtk_print_settings_get_printer (settings);
|
||||
if (printer)
|
||||
|
Loading…
Reference in New Issue
Block a user