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
This commit is contained in:
rods%netscape.com 2002-01-08 01:15:25 +00:00
parent 5e3c84b859
commit 7f647c74bf
6 changed files with 82 additions and 23 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -451,7 +451,9 @@ nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS)
{
nsCOMPtr<nsIPref> 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);

View File

@ -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)

View File

@ -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;

View File

@ -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<nsIPrintOptions> 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;