From 4aff6cd832cab7ac768b48ca0974700e4e9a0bc7 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 10 Sep 2002 01:57:09 +0000 Subject: [PATCH] Make sure the Print Data is cleaned up when exiting PP Bug 164384 r=pete sr=kin a=asa git-svn-id: svn://10.0.0.236/trunk@129137 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 19 +++++++++++++++++-- mozilla/content/base/src/nsPrintEngine.cpp | 13 +++++++++---- mozilla/content/base/src/nsPrintEngine.h | 3 ++- mozilla/layout/base/nsDocumentViewer.cpp | 19 +++++++++++++++++-- mozilla/layout/printing/nsPrintEngine.cpp | 13 +++++++++---- mozilla/layout/printing/nsPrintEngine.h | 3 ++- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 07911c9f144..291475c4f0c 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -3770,13 +3770,28 @@ DocumentViewerImpl::InstallNewPresentation() } //------------------------------------------------------------ +// This called ONLY when printing has completed and the DV +// is being notified that it should get rid of the PrintEngine. +// +// BUT, if we are in Print Preview then we want to ignore the +// notification (we do not get rid of the PrintEngine) +// +// One small caveat: +// This IS called from two places in this module for cleaning +// up when an error occurred during the start up printing +// and print preview +// void DocumentViewerImpl::OnDonePrinting() { #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) if (mPrintEngine) { - mPrintEngine->Destroy(); - NS_RELEASE(mPrintEngine); + if (GetIsPrintPreview()) { + mPrintEngine->DestroyPrintingData(); + } else { + mPrintEngine->Destroy(); + NS_RELEASE(mPrintEngine); + } } #endif // NS_PRINTING && NS_PRINT_PREVIEW } diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index 6d6b9ca1cb7..79efdb74da6 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -316,6 +316,15 @@ void nsPrintEngine::Destroy() } +//------------------------------------------------------- +void nsPrintEngine::DestroyPrintingData() +{ + if (mPrt) { + delete mPrt; + mPrt = nsnull; + } +} + //--------------------------------------------------------------------------------- //-- Section: Methods needed by the DocViewer //--------------------------------------------------------------------------------- @@ -2237,10 +2246,6 @@ nsresult nsPrintEngine::CleanupOnFailure(nsresult aResult, PRBool aIsPrinting) NS_RELEASE(mPagePrintTimer); } - //if (mPrt) { - // delete mPrt; - // mPrt = nsnull; - //} SetIsPrinting(PR_FALSE); /* cleanup done, let's fire-up an error dialog to notify the user diff --git a/mozilla/content/base/src/nsPrintEngine.h b/mozilla/content/base/src/nsPrintEngine.h index afc3095ba30..91a2cfb0639 100644 --- a/mozilla/content/base/src/nsPrintEngine.h +++ b/mozilla/content/base/src/nsPrintEngine.h @@ -107,9 +107,10 @@ public: nsPrintEngine(); - ~nsPrintEngine(); // non-virtual + virtual ~nsPrintEngine(); void Destroy(); + void DestroyPrintingData(); nsresult Initialize(nsIDocumentViewer* aDocViewer, nsIDocumentViewerPrint* aDocViewerPrint, diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 07911c9f144..291475c4f0c 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -3770,13 +3770,28 @@ DocumentViewerImpl::InstallNewPresentation() } //------------------------------------------------------------ +// This called ONLY when printing has completed and the DV +// is being notified that it should get rid of the PrintEngine. +// +// BUT, if we are in Print Preview then we want to ignore the +// notification (we do not get rid of the PrintEngine) +// +// One small caveat: +// This IS called from two places in this module for cleaning +// up when an error occurred during the start up printing +// and print preview +// void DocumentViewerImpl::OnDonePrinting() { #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) if (mPrintEngine) { - mPrintEngine->Destroy(); - NS_RELEASE(mPrintEngine); + if (GetIsPrintPreview()) { + mPrintEngine->DestroyPrintingData(); + } else { + mPrintEngine->Destroy(); + NS_RELEASE(mPrintEngine); + } } #endif // NS_PRINTING && NS_PRINT_PREVIEW } diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 6d6b9ca1cb7..79efdb74da6 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -316,6 +316,15 @@ void nsPrintEngine::Destroy() } +//------------------------------------------------------- +void nsPrintEngine::DestroyPrintingData() +{ + if (mPrt) { + delete mPrt; + mPrt = nsnull; + } +} + //--------------------------------------------------------------------------------- //-- Section: Methods needed by the DocViewer //--------------------------------------------------------------------------------- @@ -2237,10 +2246,6 @@ nsresult nsPrintEngine::CleanupOnFailure(nsresult aResult, PRBool aIsPrinting) NS_RELEASE(mPagePrintTimer); } - //if (mPrt) { - // delete mPrt; - // mPrt = nsnull; - //} SetIsPrinting(PR_FALSE); /* cleanup done, let's fire-up an error dialog to notify the user diff --git a/mozilla/layout/printing/nsPrintEngine.h b/mozilla/layout/printing/nsPrintEngine.h index afc3095ba30..91a2cfb0639 100644 --- a/mozilla/layout/printing/nsPrintEngine.h +++ b/mozilla/layout/printing/nsPrintEngine.h @@ -107,9 +107,10 @@ public: nsPrintEngine(); - ~nsPrintEngine(); // non-virtual + virtual ~nsPrintEngine(); void Destroy(); + void DestroyPrintingData(); nsresult Initialize(nsIDocumentViewer* aDocViewer, nsIDocumentViewerPrint* aDocViewerPrint,