mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-10 12:40:10 +00:00
Fixed bug that prevented GTK from storing printer driver preferences in the print dialogue on Windows. Also saving devmode->dmDeviceName so the dialogue remembers which printer your selected last, and doesn't try to feed to saved preferences to the wrong printer.
This commit is contained in:
parent
426a0be531
commit
446659e80f
@ -678,6 +678,7 @@ devmode_to_settings (GtkPrintSettings *settings,
|
||||
HANDLE hDevMode)
|
||||
{
|
||||
LPDEVMODEW devmode;
|
||||
char *devmode_name;
|
||||
|
||||
devmode = GlobalLock (hDevMode);
|
||||
|
||||
@ -692,6 +693,10 @@ devmode_to_settings (GtkPrintSettings *settings,
|
||||
extra);
|
||||
g_free (extra);
|
||||
}
|
||||
|
||||
devmode_name = g_utf16_to_utf8 (devmode->dmDeviceName, -1, NULL, NULL, NULL);
|
||||
gtk_print_settings_set (settings, "win32-devmode-name", devmode_name);
|
||||
g_free (devmode_name);
|
||||
|
||||
if (devmode->dmFields & DM_ORIENTATION)
|
||||
gtk_print_settings_set_orientation (settings,
|
||||
@ -936,9 +941,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;
|
||||
@ -946,31 +952,54 @@ 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
|
||||
{
|
||||
const char *saved_printer_name;
|
||||
gunichar2 *device_name;
|
||||
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);
|
||||
|
||||
memset (devmode->dmDeviceName, 0, CCHDEVICENAME * sizeof (wchar_t));
|
||||
saved_printer_name = gtk_print_settings_get (settings, "win32-devmode-name");
|
||||
if (saved_printer_name)
|
||||
{
|
||||
device_name = g_utf8_to_utf16 (saved_printer_name, -1, NULL, NULL, NULL);
|
||||
if (device_name)
|
||||
wcsncpy (devmode->dmDeviceName, device_name, MIN (CCHDEVICENAME - 1, wcslen (device_name)));
|
||||
g_free (device_name);
|
||||
}
|
||||
|
||||
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))
|
||||
@ -1224,12 +1253,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->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 {
|
||||
@ -1551,7 +1593,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);
|
||||
@ -2049,7 +2091,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