зеркало из https://github.com/mozilla/pjs.git
Bug 461283 - Crash [@ fastcopy_I ] - printing broken r=vlad
This commit is contained in:
Родитель
b01fc785a9
Коммит
06611e4c3a
|
@ -194,7 +194,7 @@ CheckForExtendedDialog()
|
|||
//----------------------------------------------------------------------------------
|
||||
// Map an incoming size to a Windows Native enum in the DevMode
|
||||
static void
|
||||
MapPaperSizeToNativeEnum(LPDEVMODE aDevMode,
|
||||
MapPaperSizeToNativeEnum(LPDEVMODEW aDevMode,
|
||||
PRInt16 aType,
|
||||
double aW,
|
||||
double aH)
|
||||
|
@ -249,7 +249,7 @@ MapPaperSizeToNativeEnum(LPDEVMODE aDevMode,
|
|||
// Setup Paper Size & Orientation options into the DevMode
|
||||
//
|
||||
static void
|
||||
SetupDevModeFromSettings(LPDEVMODE aDevMode, nsIPrintSettings* aPrintSettings)
|
||||
SetupDevModeFromSettings(LPDEVMODEW aDevMode, nsIPrintSettings* aPrintSettings)
|
||||
{
|
||||
// Setup paper size
|
||||
if (aPrintSettings) {
|
||||
|
@ -753,28 +753,28 @@ static UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM
|
|||
// This function assumes that aPrintName has already been converted from
|
||||
// unicode
|
||||
//
|
||||
static HGLOBAL CreateGlobalDevModeAndInit(LPCTSTR aPrintName, nsIPrintSettings* aPS)
|
||||
static HGLOBAL CreateGlobalDevModeAndInit(LPCWSTR aPrintName, nsIPrintSettings* aPS)
|
||||
{
|
||||
HGLOBAL hGlobalDevMode = NULL;
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
HANDLE hPrinter = NULL;
|
||||
// const cast kludge for silly Win32 api's
|
||||
LPTSTR printName = const_cast<char*>(aPrintName);
|
||||
BOOL status = ::OpenPrinter(printName, &hPrinter, NULL);
|
||||
LPWSTR printName = const_cast<wchar_t*>(aPrintName);
|
||||
BOOL status = ::OpenPrinterW(printName, &hPrinter, NULL);
|
||||
if (status) {
|
||||
|
||||
LPDEVMODE pNewDevMode;
|
||||
LPDEVMODEW pNewDevMode;
|
||||
DWORD dwNeeded, dwRet;
|
||||
|
||||
// Get the buffer size
|
||||
dwNeeded = ::DocumentProperties(gParentWnd, hPrinter, printName, NULL, NULL, 0);
|
||||
dwNeeded = ::DocumentPropertiesW(gParentWnd, hPrinter, printName, NULL, NULL, 0);
|
||||
if (dwNeeded == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate a buffer of the correct size.
|
||||
pNewDevMode = (LPDEVMODE)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, dwNeeded);
|
||||
pNewDevMode = (LPDEVMODEW)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, dwNeeded);
|
||||
if (!pNewDevMode) return NULL;
|
||||
|
||||
hGlobalDevMode = (HGLOBAL)::GlobalAlloc(GHND, dwNeeded);
|
||||
|
@ -783,7 +783,7 @@ static HGLOBAL CreateGlobalDevModeAndInit(LPCTSTR aPrintName, nsIPrintSettings*
|
|||
return NULL;
|
||||
}
|
||||
|
||||
dwRet = ::DocumentProperties(gParentWnd, hPrinter, printName, pNewDevMode, NULL, DM_OUT_BUFFER);
|
||||
dwRet = ::DocumentPropertiesW(gParentWnd, hPrinter, printName, pNewDevMode, NULL, DM_OUT_BUFFER);
|
||||
|
||||
if (dwRet != IDOK) {
|
||||
::HeapFree(::GetProcessHeap(), 0, pNewDevMode);
|
||||
|
@ -794,14 +794,14 @@ static HGLOBAL CreateGlobalDevModeAndInit(LPCTSTR aPrintName, nsIPrintSettings*
|
|||
|
||||
// Lock memory and copy contents from DEVMODE (current printer)
|
||||
// to Global Memory DEVMODE
|
||||
LPDEVMODE devMode = (DEVMODE *)::GlobalLock(hGlobalDevMode);
|
||||
LPDEVMODEW devMode = (DEVMODEW *)::GlobalLock(hGlobalDevMode);
|
||||
if (devMode) {
|
||||
memcpy(devMode, pNewDevMode, dwNeeded);
|
||||
// Initialize values from the PrintSettings
|
||||
SetupDevModeFromSettings(devMode, aPS);
|
||||
|
||||
// Sets back the changes we made to the DevMode into the Printer Driver
|
||||
dwRet = ::DocumentProperties(gParentWnd, hPrinter, printName, devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER);
|
||||
dwRet = ::DocumentPropertiesW(gParentWnd, hPrinter, printName, devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER);
|
||||
if (dwRet != IDOK) {
|
||||
::GlobalUnlock(hGlobalDevMode);
|
||||
::GlobalFree(hGlobalDevMode);
|
||||
|
@ -882,10 +882,7 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
printerName = GetDefaultPrinterNameFromGlobalPrinters();
|
||||
} else {
|
||||
HANDLE hPrinter = NULL;
|
||||
nsCAutoString printerNameNative;
|
||||
NS_CopyUnicodeToNative(nsDependentString(printerName), printerNameNative);
|
||||
LPTSTR tempPrinterName = const_cast<char*>(printerNameNative.get());
|
||||
if(!::OpenPrinter(tempPrinterName, &hPrinter, NULL)) {
|
||||
if(!::OpenPrinterW(const_cast<wchar_t*>(printerName), &hPrinter, NULL)) {
|
||||
// If the last used printer is not found, we should use default printer.
|
||||
printerName = GetDefaultPrinterNameFromGlobalPrinters();
|
||||
} else {
|
||||
|
@ -897,20 +894,18 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
if (!printerName) return NS_ERROR_FAILURE;
|
||||
|
||||
// Now create a DEVNAMES struct so the the dialog is initialized correctly.
|
||||
nsCAutoString tempPrinterName;
|
||||
rv = NS_CopyUnicodeToNative(nsDependentString(printerName), tempPrinterName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRUint32 len = tempPrinterName.Length();
|
||||
hDevNames = (HGLOBAL)::GlobalAlloc(GHND, len+sizeof(DEVNAMES)+1);
|
||||
PRUint32 len = wcslen(printerName);
|
||||
hDevNames = (HGLOBAL)::GlobalAlloc(GHND, sizeof(wchar_t) * (len + 1) +
|
||||
sizeof(DEVNAMES));
|
||||
DEVNAMES* pDevNames = (DEVNAMES*)::GlobalLock(hDevNames);
|
||||
pDevNames->wDriverOffset = sizeof(DEVNAMES);
|
||||
pDevNames->wDeviceOffset = sizeof(DEVNAMES);
|
||||
pDevNames->wOutputOffset = sizeof(DEVNAMES)+len+1;
|
||||
pDevNames->wDefault = 0;
|
||||
|
||||
char* device = &(((char*)pDevNames)[pDevNames->wDeviceOffset]);
|
||||
strcpy(device, tempPrinterName.get());
|
||||
wchar_t* device = &(((wchar_t*)pDevNames)[pDevNames->wDeviceOffset]);
|
||||
wcscpy(device, printerName);
|
||||
::GlobalUnlock(hDevNames);
|
||||
|
||||
// Create a Moveable Memory Object that holds a new DevMode
|
||||
|
@ -919,11 +914,11 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
// NOTE: We only need to free hGlobalDevMode when the dialog is cancelled
|
||||
// When the user prints, it comes back in the printdlg struct and
|
||||
// is used and cleaned up later
|
||||
hGlobalDevMode = CreateGlobalDevModeAndInit(tempPrinterName.get(), aPrintSettings);
|
||||
hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings);
|
||||
|
||||
// Prepare to Display the Print Dialog
|
||||
PRINTDLG prntdlg;
|
||||
memset(&prntdlg, 0, sizeof(PRINTDLG));
|
||||
PRINTDLGW prntdlg;
|
||||
memset(&prntdlg, 0, sizeof(PRINTDLGW));
|
||||
|
||||
prntdlg.lStructSize = sizeof(prntdlg);
|
||||
prntdlg.hwndOwner = aHWnd;
|
||||
|
@ -969,7 +964,7 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
prntdlg.Flags |= PD_ENABLEPRINTHOOK;
|
||||
}
|
||||
|
||||
BOOL result = ::PrintDlg(&prntdlg);
|
||||
BOOL result = ::PrintDlgW(&prntdlg);
|
||||
|
||||
if (TRUE == result) {
|
||||
// check to make sure we don't have any NULL pointers
|
||||
|
@ -986,8 +981,8 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
char* device = &(((char *)devnames)[devnames->wDeviceOffset]);
|
||||
char* driver = &(((char *)devnames)[devnames->wDriverOffset]);
|
||||
wchar_t* device = &(((wchar_t *)devnames)[devnames->wDeviceOffset]);
|
||||
wchar_t* driver = &(((wchar_t *)devnames)[devnames->wDriverOffset]);
|
||||
|
||||
// Check to see if the "Print To File" control is checked
|
||||
// then take the name from devNames and set it in the PrintSettings
|
||||
|
@ -998,9 +993,9 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
// if the "Print To File" checkbox is checked it MUST be "FILE:"
|
||||
// We assert as an extra safety check.
|
||||
if (prntdlg.Flags & PD_PRINTTOFILE) {
|
||||
char* fileName = &(((char *)devnames)[devnames->wOutputOffset]);
|
||||
NS_ASSERTION(strcmp(fileName, "FILE:") == 0, "FileName must be `FILE:`");
|
||||
aPrintSettings->SetToFileName(NS_ConvertASCIItoUTF16(fileName).get());
|
||||
wchar_t* fileName = &(((wchar_t *)devnames)[devnames->wOutputOffset]);
|
||||
NS_ASSERTION(wcscmp(fileName, L"FILE:") == 0, "FileName must be `FILE:`");
|
||||
aPrintSettings->SetToFileName(fileName);
|
||||
aPrintSettings->SetPrintToFile(PR_TRUE);
|
||||
} else {
|
||||
// clear "print to file" info
|
||||
|
@ -1015,18 +1010,15 @@ ShowNativePrintDialog(HWND aHWnd,
|
|||
}
|
||||
|
||||
// Setup local Data members
|
||||
psWin->SetDeviceName(NS_ConvertUTF8toUTF16(device).get());
|
||||
psWin->SetDriverName(NS_ConvertUTF8toUTF16(driver).get());
|
||||
psWin->SetDeviceName(device);
|
||||
psWin->SetDriverName(driver);
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags);
|
||||
wprintf(L"printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags);
|
||||
#endif
|
||||
// fill the print options with the info from the dialog
|
||||
nsDependentCString printerNameNative(device);
|
||||
nsAutoString printerName;
|
||||
NS_CopyNativeToUnicode(printerNameNative, printerName);
|
||||
|
||||
aPrintSettings->SetPrinterName(printerName.get());
|
||||
aPrintSettings->SetPrinterName(device);
|
||||
|
||||
if (prntdlg.Flags & PD_SELECTION) {
|
||||
aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection);
|
||||
|
@ -1247,10 +1239,8 @@ ShowNativePrintDialogEx(HWND aHWnd,
|
|||
aPrintSettings->GetPrinterName(&printerName);
|
||||
HGLOBAL hGlobalDevMode = NULL;
|
||||
if (printerName) {
|
||||
nsCAutoString tempPrinterName;
|
||||
rv = NS_CopyUnicodeToNative(nsDependentString(printerName), tempPrinterName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
hGlobalDevMode = CreateGlobalDevModeAndInit(tempPrinterName.get(), aPrintSettings);
|
||||
hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings);
|
||||
}
|
||||
|
||||
// Prepare to Display the Print Dialog
|
||||
|
@ -1407,7 +1397,7 @@ ShowNativePrintDialogEx(HWND aHWnd,
|
|||
::GlobalUnlock(prntdlg.hDevNames);
|
||||
|
||||
// Transfer the settings from the native data to the PrintSettings
|
||||
LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode);
|
||||
LPDEVMODEW devMode = (LPDEVMODEW)::GlobalLock(prntdlg.hDevMode);
|
||||
if (devMode == NULL) {
|
||||
::GlobalFree(hGlobalDevMode);
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -83,13 +83,13 @@ NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const PRUnichar * aDeviceName)
|
|||
if (mDeviceName) {
|
||||
nsMemory::Free(mDeviceName);
|
||||
}
|
||||
mDeviceName = aDeviceName?nsCRT::strdup(aDeviceName):nsnull;
|
||||
mDeviceName = aDeviceName?wcsdup(aDeviceName):nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(PRUnichar **aDeviceName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDeviceName);
|
||||
*aDeviceName = mDeviceName?nsCRT::strdup(mDeviceName):nsnull;
|
||||
*aDeviceName = mDeviceName?wcsdup(mDeviceName):nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -99,13 +99,13 @@ NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const PRUnichar * aDriverName)
|
|||
if (mDriverName) {
|
||||
nsMemory::Free(mDriverName);
|
||||
}
|
||||
mDriverName = aDriverName?nsCRT::strdup(aDriverName):nsnull;
|
||||
mDriverName = aDriverName?wcsdup(aDriverName):nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(PRUnichar **aDriverName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDriverName);
|
||||
*aDriverName = mDriverName?nsCRT::strdup(mDriverName):nsnull;
|
||||
*aDriverName = mDriverName?wcsdup(mDriverName):nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -176,8 +176,8 @@ nsPrintSettingsWin& nsPrintSettingsWin::operator=(const nsPrintSettingsWin& rhs)
|
|||
::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
||||
}
|
||||
|
||||
mDeviceName = rhs.mDeviceName?nsCRT::strdup(rhs.mDeviceName):nsnull;
|
||||
mDriverName = rhs.mDriverName?nsCRT::strdup(rhs.mDriverName):nsnull;
|
||||
mDeviceName = rhs.mDeviceName?wcsdup(rhs.mDeviceName):nsnull;
|
||||
mDriverName = rhs.mDriverName?wcsdup(rhs.mDriverName):nsnull;
|
||||
|
||||
if (rhs.mDevMode) {
|
||||
CopyDevMode(rhs.mDevMode, mDevMode);
|
||||
|
|
Загрузка…
Ссылка в новой задаче