From 741a62007ecc405aefe04939aaa9e8ac5befb8d2 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 8 Jan 2002 01:15:25 +0000 Subject: [PATCH] Improves error codes for printing and fixes selection printing by making sure the margins are initialized when no prefs are there Bugs 86378 & 118637 r=dcone sr=attinasi git-svn-id: svn://10.0.0.236/trunk@111523 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/public/nsIDeviceContext.h | 12 ++++ mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp | 8 +-- mozilla/gfx/src/nsPrintOptionsImpl.cpp | 2 + mozilla/gfx/src/nsPrintSettingsImpl.cpp | 12 +++- mozilla/gfx/src/os2/nsDeviceContextOS2.cpp | 6 +- .../gfx/src/windows/nsDeviceContextWin.cpp | 65 +++++++++++++++---- 6 files changed, 82 insertions(+), 23 deletions(-) diff --git a/mozilla/gfx/public/nsIDeviceContext.h b/mozilla/gfx/public/nsIDeviceContext.h index 9ef13f71d87..43aeb66555f 100644 --- a/mozilla/gfx/public/nsIDeviceContext.h +++ b/mozilla/gfx/public/nsIDeviceContext.h @@ -96,6 +96,18 @@ typedef void * nsNativeDeviceContext; /* print preview: needs at least one printer */ #define NS_ERROR_GFX_PRINTER_PRINTPREVIEW \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+13) +/* print: starting document */ +#define NS_ERROR_GFX_PRINTER_STARTDOC \ + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+14) +/* print: ending document */ +#define NS_ERROR_GFX_PRINTER_ENDDOC \ + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+15) +/* print: starting page */ +#define NS_ERROR_GFX_PRINTER_STARTPAGE \ + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+16) +/* print: ending page */ +#define NS_ERROR_GFX_PRINTER_ENDPAGE \ + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+17) /** * Conts need for Print Preview diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp b/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp index fb063637d79..57ebe43cc9d 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp @@ -157,7 +157,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::ClosePrintManager() NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument() { OSStatus status = ::PMBeginDocument(mPrintSettings, mPageFormat, &mPrintingContext); - if (status != noErr) return NS_ERROR_FAILURE; + if (status != noErr) return NS_ERROR_GFX_PRINTER_STARTDOC; return NS_OK; } @@ -173,12 +173,12 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginPage() { // see http://devworld.apple.com/techpubs/carbon/graphics/CarbonPrintingManager/Carbon_Printing_Manager/Functions/PMSessionBeginPage.html OSStatus status = ::PMBeginPage(mPrintingContext, NULL); - if (status != noErr) return NS_ERROR_FAILURE; + if (status != noErr) return NS_ERROR_GFX_PRINTER_STARTPAGE; ::GetPort(&mSavedPort); GrafPtr printingPort; status = ::PMGetGrafPtr(mPrintingContext, &printingPort); - if (status != noErr) return NS_ERROR_FAILURE; + if (status != noErr) return NS_ERROR_GFX_PRINTER_STARTPAGE; ::SetPort(printingPort); return NS_OK; } @@ -191,7 +191,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::EndPage() ::SetPort(mSavedPort); mSavedPort = 0; } - if (status != noErr) return NS_ERROR_FAILURE; + if (status != noErr) return NS_ERROR_GFX_PRINTER_ENDDOC; return NS_OK; } diff --git a/mozilla/gfx/src/nsPrintOptionsImpl.cpp b/mozilla/gfx/src/nsPrintOptionsImpl.cpp index daa95cf00bf..3b6acdf1a1b 100644 --- a/mozilla/gfx/src/nsPrintOptionsImpl.cpp +++ b/mozilla/gfx/src/nsPrintOptionsImpl.cpp @@ -451,7 +451,9 @@ nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS) { nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); if (prefs) { + nscoord halfInch = NS_INCHES_TO_TWIPS(0.5); nsMargin margin; + margin.SizeTo(halfInch, halfInch, halfInch, halfInch); ReadInchesToTwipsPref(prefs, kMarginTop, margin.top); ReadInchesToTwipsPref(prefs, kMarginLeft, margin.left); ReadInchesToTwipsPref(prefs, kMarginBottom, margin.bottom); diff --git a/mozilla/gfx/src/nsPrintSettingsImpl.cpp b/mozilla/gfx/src/nsPrintSettingsImpl.cpp index a7f47cd569a..278e3b62970 100644 --- a/mozilla/gfx/src/nsPrintSettingsImpl.cpp +++ b/mozilla/gfx/src/nsPrintSettingsImpl.cpp @@ -361,7 +361,11 @@ NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange) NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle) { NS_ENSURE_ARG_POINTER(aTitle); - *aTitle = ToNewUnicode(mTitle); + if (mTitle.Length() > 0) { + *aTitle = ToNewUnicode(mTitle); + } else { + *aTitle = nsnull; + } return NS_OK; } NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle) @@ -375,7 +379,11 @@ NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle) NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL) { NS_ENSURE_ARG_POINTER(aDocURL); - *aDocURL = ToNewUnicode(mURL); + if (mURL.Length() > 0) { + *aDocURL = ToNewUnicode(mURL); + } else { + *aDocURL = nsnull; + } return NS_OK; } NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL) diff --git a/mozilla/gfx/src/os2/nsDeviceContextOS2.cpp b/mozilla/gfx/src/os2/nsDeviceContextOS2.cpp index 036d6561c8d..e40d8a2e7c6 100644 --- a/mozilla/gfx/src/os2/nsDeviceContextOS2.cpp +++ b/mozilla/gfx/src/os2/nsDeviceContextOS2.cpp @@ -917,7 +917,7 @@ nsresult nsDeviceContextOS2::BeginDocument(PRUnichar * aTitle) if (lResult == DEV_OK) rv = NS_OK; else - rv = NS_ERROR_FAILURE; + rv = NS_ERROR_GFX_PRINTER_STARTDOC; if (title != nsnull) { delete [] title; @@ -939,7 +939,7 @@ nsresult nsDeviceContextOS2::EndDocument() if (lResult == DEV_OK) return NS_OK; else - return NS_ERROR_FAILURE; + return NS_ERROR_GFX_PRINTER_ENDDOC; } return NS_OK; @@ -962,7 +962,7 @@ nsresult nsDeviceContextOS2::EndPage() if (lResult == DEV_OK) return NS_OK; else - return NS_ERROR_FAILURE; + return NS_ERROR_GFX_PRINTER_ENDPAGE; } return NS_OK; diff --git a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp index 275739cb07e..36d202b4a87 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp @@ -54,6 +54,7 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // Size of the color cube #define COLOR_CUBE_SIZE 216 +#define DOC_TITLE_LENGTH 64 static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); @@ -974,19 +975,47 @@ NS_IMETHODIMP nsDeviceContextWin :: GetDeviceContextFor(nsIDeviceContextSpec *aD return devConWin->Init(dc, this); // take ownership of the DC } +#if defined(DEBUG_rods) || defined(DEBUG_dcone) +static void DisplayLastError() +{ + LPVOID lpMsgBuf; + DWORD errCode = GetLastError(); + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + + // Display the string. + MessageBox( NULL, (const char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION ); +} +#define DISPLAY_LAST_ERROR DisplayLastError(); +#else +#define DISPLAY_LAST_ERROR +#endif + + NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle) { - nsresult rv = NS_OK; + nsresult rv = NS_ERROR_GFX_PRINTER_STARTDOC; - if (NULL != mDC){ + if (NULL != mDC) { DOCINFO docinfo; nsString titleStr; titleStr = aTitle; + if (titleStr.Length() > DOC_TITLE_LENGTH) { + titleStr.SetLength(DOC_TITLE_LENGTH-3); + titleStr.AppendWithConversion("..."); + } char *title = GetACPString(titleStr); char* docName = nsnull; - nsresult rv = NS_ERROR_FAILURE; nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); if (printService) { PRBool printToFile = PR_FALSE; @@ -1015,10 +1044,12 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle) docinfo.lpszDatatype = NULL; docinfo.fwType = 0; - if (::StartDoc(mDC, &docinfo) > 0) + if (::StartDoc(mDC, &docinfo) > 0) { rv = NS_OK; - else - rv = NS_ERROR_FAILURE; + } else { + DISPLAY_LAST_ERROR + rv = NS_ERROR_GFX_PRINTER_STARTDOC; + } if (title != nsnull) delete [] title; if (docName != nsnull) nsMemory::Free(docName); @@ -1031,10 +1062,12 @@ NS_IMETHODIMP nsDeviceContextWin :: EndDocument(void) { if (NULL != mDC) { - if (::EndDoc(mDC) > 0) + if (::EndDoc(mDC) > 0) { return NS_OK; - else - return NS_ERROR_FAILURE; + } else { + DISPLAY_LAST_ERROR + return NS_ERROR_GFX_PRINTER_ENDDOC; + } } return NS_OK; @@ -1046,8 +1079,10 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginPage(void) { if (::StartPage(mDC) > 0) return NS_OK; - else - return NS_ERROR_FAILURE; + else { + DISPLAY_LAST_ERROR + return NS_ERROR_GFX_PRINTER_STARTPAGE; + } } return NS_OK; @@ -1057,10 +1092,12 @@ NS_IMETHODIMP nsDeviceContextWin :: EndPage(void) { if (NULL != mDC) { - if (::EndPage(mDC) > 0) + if (::EndPage(mDC) > 0) { return NS_OK; - else - return NS_ERROR_FAILURE; + } else { + DISPLAY_LAST_ERROR + return NS_ERROR_GFX_PRINTER_ENDPAGE; + } } return NS_OK;