Convert printer name WideCharToMultiByte

Bug 167128 r=roy sr=blizzard
This commit is contained in:
rods%netscape.com 2002-09-26 11:38:03 +00:00
Родитель d5b52a8c82
Коммит dddd3b5f28
1 изменённых файлов: 18 добавлений и 24 удалений

Просмотреть файл

@ -98,11 +98,7 @@ static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
// For PrintDlgEx
// needed because there are unicode/ansi versions of this routine
// and we need to make sure we get the correct one.
#ifdef UNICODE
#define GetPrintDlgExQuoted "PrintDlgExW"
#else
#define GetPrintDlgExQuoted "PrintDlgExA"
#endif
// Default labels for the radio buttons
static const char* kAsLaidOutOnScreenStr = "As &laid out on the screen";
@ -760,7 +756,12 @@ static UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM
//----------------------------------------------------------------------------------
// Returns a Global Moveable Memory Handle to a DevMode
// from the Printer byt the name of aPrintName
// from the Printer by the name of aPrintName
//
// NOTE:
// This function assumes that aPrintName has already been converted to
// Double Byte chars typically via the GetACPString helper function
//
static HGLOBAL CreateGlobalDevModeAndInit(LPTSTR aPrintName, nsIPrintSettings* aPS)
{
HGLOBAL hGlobalDevMode = NULL;
@ -773,13 +774,6 @@ static HGLOBAL CreateGlobalDevModeAndInit(LPTSTR aPrintName, nsIPrintSettings* a
LPDEVMODE pNewDevMode;
DWORD dwNeeded, dwRet;
nsString prtName;
#ifdef UNICODE
prtName.AppendWithConversion((PRUnichar *)aPrintName);
#else
prtName.AssignWithConversion((char*)aPrintName);
#endif
// Get the buffer size
dwNeeded = ::DocumentProperties(gParentWnd, hPrinter, aPrintName, NULL, NULL, 0);
if (dwNeeded == 0) {
@ -882,15 +876,19 @@ ShowNativePrintDialog(HWND aHWnd,
if (!printerName) return NS_ERROR_FAILURE;
// Now create a DEVNAMES struct so the the dialog is initialized correctly.
PRUint32 len = nsCRT::strlen(printerName);
char* dbStr = GetACPString(nsString(printerName));
NS_ENSURE_TRUE(dbStr, NS_ERROR_FAILURE);
PRUint32 len = nsCRT::strlen(dbStr);
hDevNames = (HGLOBAL)::GlobalAlloc(GHND, len+sizeof(DEVNAMES)+1);
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, (char*)NS_ConvertUCS2toUTF8(printerName).get());
strcpy(device, dbStr);
::GlobalUnlock(hDevNames);
// Create a Moveable Memory Object that holds a new DevMode
@ -899,11 +897,8 @@ 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
#ifdef UNICODE
hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings);
#else
hGlobalDevMode = CreateGlobalDevModeAndInit((char*)NS_ConvertUCS2toUTF8(printerName).get(), aPrintSettings);
#endif
hGlobalDevMode = CreateGlobalDevModeAndInit(dbStr, aPrintSettings);
free(dbStr);
// Prepare to Display the Print Dialog
PRINTDLG prntdlg;
@ -1225,11 +1220,10 @@ ShowNativePrintDialogEx(HWND aHWnd,
aPrintSettings->GetPrinterName(&printerName);
HGLOBAL hGlobalDevMode = NULL;
if (printerName) {
#ifdef UNICODE
hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings);
#else
hGlobalDevMode = CreateGlobalDevModeAndInit((char*)NS_ConvertUCS2toUTF8(printerName).get(), aPrintSettings);
#endif
char* dbStr = GetACPString(nsString(printerName));
NS_ENSURE_TRUE(dbStr, NS_ERROR_FAILURE);
hGlobalDevMode = CreateGlobalDevModeAndInit(dbStr, aPrintSettings);
free(dbStr);
}
// Prepare to Display the Print Dialog