From d069af6f44186b15c3552a8ef21cf828a23e947c Mon Sep 17 00:00:00 2001 From: "dcone%netscape.com" Date: Fri, 15 Jun 2001 14:03:12 +0000 Subject: [PATCH] Fixed printing so it could not have more than one job at a time. bug=84537 r=rods sr=attinasi a=blizzard git-svn-id: svn://10.0.0.236/trunk@97215 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 46 ++++++++++++++++++- mozilla/layout/base/nsDocumentViewer.cpp | 46 ++++++++++++++++++- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 0279ab7ea5b..485367d1a58 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -128,18 +128,24 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" +#include "nsISound.h" + #include "nsITransformMediator.h" #ifdef IBMBIDI #include "nsIUBidiUtils.h" #endif +static NS_DEFINE_IID(kSoundCID,NS_SOUND_CID); + static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); +PRBool gCurrentlyPrinting = PR_FALSE; + #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -167,6 +173,7 @@ const char * gFrameHowToEnableStr[] = {"kFrameEnableNone", "kFrameEnableAll", "k const char * gPrintRangeStr[] = {"kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection", "kRangeFocusFrame"}; + #define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); #define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); #define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); @@ -578,6 +585,7 @@ public: if (mTimer) { mTimer->Cancel(); } + gCurrentlyPrinting = PR_FALSE; } @@ -616,6 +624,7 @@ public: nsresult result = StartTimer(); if (NS_FAILED(result)) { donePrinting = PR_TRUE; // had a failure.. we are finished.. + gCurrentlyPrinting = PR_FALSE; } } } @@ -2088,6 +2097,7 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) DoProgressForAsIsFrames(); DoProgressForSeparateFrames(); + gCurrentlyPrinting = PR_FALSE; delete mPrt; mPrt = nsnull; @@ -3428,6 +3438,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (startPageNum == endPageNum) { nsIFrame * seqFrame; if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } nsRect rect(0,0,0,0); @@ -3444,6 +3455,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nsIFrame * seqFrame; if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } @@ -3480,6 +3492,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } } else { // not sure what to do here! + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } } @@ -4231,8 +4244,29 @@ DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) NS_IMETHODIMP DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) { +nsresult rv; + + // if we are printing another URL, then exit + // the reason we check here is because this method can be called while + // another is still in here (the printing dialog is a good example). + if(gCurrentlyPrinting) { + // Beep at the user, let them know we are not ready to print. + nsCOMPtr soundInterface; + rv = nsComponentManager::CreateInstance(kSoundCID, + nsnull, NS_GET_IID(nsISound), + getter_AddRefs(soundInterface)); + if (NS_SUCCEEDED(rv) && (soundInterface != nsnull)){ + soundInterface->Beep(); + } + return NS_ERROR_FAILURE; + } else { + gCurrentlyPrinting = PR_TRUE; + } + + mPrt = new PrintData(); if (mPrt == nsnull) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } @@ -4252,6 +4286,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi if (mPrt->mPrintDocList == nsnull) { mPrt->mPrintDocList = new nsVoidArray(); if (mPrt->mPrintDocList == nsnull) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } } else { @@ -4286,7 +4321,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi DUMP_DOC_LIST("\nAfter Mapping------------------------------------------"); // Setup print options for UI - nsresult rv = NS_ERROR_FAILURE; + rv = NS_ERROR_FAILURE; NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && printService) { if (mPrt->mIsParentAFrameSet) { @@ -4349,10 +4384,12 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi // load the document and do the initial reflow on the entire document nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } else { rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrt->mPrintPC); if (NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } } @@ -4375,27 +4412,32 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi rv = nsComponentManager::CreateInstance(kPresShellCID, nsnull, NS_GET_IID(nsIPresShell),(void**)&mPrt->mPrintPS); if(NS_FAILED(rv)){ + gCurrentlyPrinting = PR_FALSE; return rv; } rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager),(void**)&mPrt->mPrintVM); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } rv = mPrt->mPrintVM->Init(mPrt->mPrintDC); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView),(void**)&mPrt->mPrintView); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } nsRect tbounds = nsRect(0,0,width,height); rv = mPrt->mPrintView->Init(mPrt->mPrintVM,tbounds,nsnull); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } @@ -4491,7 +4533,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrt->OnEndPrinting(NS_ERROR_FAILURE); delete mPrt; mPrt = nsnull; - + gCurrentlyPrinting = PR_FALSE; rv = NS_ERROR_FAILURE; } diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 0279ab7ea5b..485367d1a58 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -128,18 +128,24 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" +#include "nsISound.h" + #include "nsITransformMediator.h" #ifdef IBMBIDI #include "nsIUBidiUtils.h" #endif +static NS_DEFINE_IID(kSoundCID,NS_SOUND_CID); + static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); +PRBool gCurrentlyPrinting = PR_FALSE; + #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -167,6 +173,7 @@ const char * gFrameHowToEnableStr[] = {"kFrameEnableNone", "kFrameEnableAll", "k const char * gPrintRangeStr[] = {"kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection", "kRangeFocusFrame"}; + #define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); #define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); #define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); @@ -578,6 +585,7 @@ public: if (mTimer) { mTimer->Cancel(); } + gCurrentlyPrinting = PR_FALSE; } @@ -616,6 +624,7 @@ public: nsresult result = StartTimer(); if (NS_FAILED(result)) { donePrinting = PR_TRUE; // had a failure.. we are finished.. + gCurrentlyPrinting = PR_FALSE; } } } @@ -2088,6 +2097,7 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) DoProgressForAsIsFrames(); DoProgressForSeparateFrames(); + gCurrentlyPrinting = PR_FALSE; delete mPrt; mPrt = nsnull; @@ -3428,6 +3438,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (startPageNum == endPageNum) { nsIFrame * seqFrame; if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } nsRect rect(0,0,0,0); @@ -3444,6 +3455,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nsIFrame * seqFrame; if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } @@ -3480,6 +3492,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } } else { // not sure what to do here! + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } } @@ -4231,8 +4244,29 @@ DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) NS_IMETHODIMP DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) { +nsresult rv; + + // if we are printing another URL, then exit + // the reason we check here is because this method can be called while + // another is still in here (the printing dialog is a good example). + if(gCurrentlyPrinting) { + // Beep at the user, let them know we are not ready to print. + nsCOMPtr soundInterface; + rv = nsComponentManager::CreateInstance(kSoundCID, + nsnull, NS_GET_IID(nsISound), + getter_AddRefs(soundInterface)); + if (NS_SUCCEEDED(rv) && (soundInterface != nsnull)){ + soundInterface->Beep(); + } + return NS_ERROR_FAILURE; + } else { + gCurrentlyPrinting = PR_TRUE; + } + + mPrt = new PrintData(); if (mPrt == nsnull) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } @@ -4252,6 +4286,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi if (mPrt->mPrintDocList == nsnull) { mPrt->mPrintDocList = new nsVoidArray(); if (mPrt->mPrintDocList == nsnull) { + gCurrentlyPrinting = PR_FALSE; return NS_ERROR_FAILURE; } } else { @@ -4286,7 +4321,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi DUMP_DOC_LIST("\nAfter Mapping------------------------------------------"); // Setup print options for UI - nsresult rv = NS_ERROR_FAILURE; + rv = NS_ERROR_FAILURE; NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && printService) { if (mPrt->mIsParentAFrameSet) { @@ -4349,10 +4384,12 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi // load the document and do the initial reflow on the entire document nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } else { rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrt->mPrintPC); if (NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } } @@ -4375,27 +4412,32 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi rv = nsComponentManager::CreateInstance(kPresShellCID, nsnull, NS_GET_IID(nsIPresShell),(void**)&mPrt->mPrintPS); if(NS_FAILED(rv)){ + gCurrentlyPrinting = PR_FALSE; return rv; } rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager),(void**)&mPrt->mPrintVM); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } rv = mPrt->mPrintVM->Init(mPrt->mPrintDC); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView),(void**)&mPrt->mPrintView); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } nsRect tbounds = nsRect(0,0,width,height); rv = mPrt->mPrintView->Init(mPrt->mPrintVM,tbounds,nsnull); if(NS_FAILED(rv)) { + gCurrentlyPrinting = PR_FALSE; return rv; } @@ -4491,7 +4533,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrt->OnEndPrinting(NS_ERROR_FAILURE); delete mPrt; mPrt = nsnull; - + gCurrentlyPrinting = PR_FALSE; rv = NS_ERROR_FAILURE; }