From d87fde2b513b0fff96cc59e3f5083f24edcbfb42 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 10 Jan 2003 00:53:28 +0000 Subject: [PATCH] Re-enable print preview gui stuff (which was mostly off) on GTK and Xlib ports. Bug 187125, patch by Roland.Mainz@informatik.med.uni-giessen.de (Roland Mainz), r=smontagu, sr=rbs --- content/base/src/nsPrintEngine.cpp | 13 ----- gfx/src/gtk/nsDeviceContextSpecG.cpp | 14 +++++ gfx/src/xlib/nsDeviceContextSpecXlib.cpp | 16 +++++- gfx/src/xlib/nsDeviceContextX.h | 2 + gfx/src/xlib/nsDeviceContextXlib.cpp | 22 ++++++-- gfx/src/xlib/nsDeviceContextXlib.h | 6 ++- gfx/src/xlib/nsGfxFactoryXlib.cpp | 1 - gfx/src/xlib/nsRenderingContextXlib.cpp | 53 ++++++++++++------- gfx/src/xlib/nsRenderingContextXlib.h | 7 +-- gfx/src/xprint/nsDeviceContextXP.cpp | 26 ++++----- gfx/src/xprint/nsDeviceContextXP.h | 4 +- layout/printing/nsPrintEngine.cpp | 13 ----- .../content/printPreviewBindings.xml | 27 ++++++++-- 13 files changed, 130 insertions(+), 74 deletions(-) diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp index 9f6377512b1..39d8afbec3b 100644 --- a/content/base/src/nsPrintEngine.cpp +++ b/content/base/src/nsPrintEngine.cpp @@ -584,19 +584,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, nsCOMPtr docShell(do_QueryInterface(mContainer)); NS_ASSERTION(docShell, "This has to be a docshell"); - - if (mIsDoingPrintPreview) { - PRBool okToPrint = PR_FALSE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.whileInPrintPreview", &okToPrint); - } - if (!okToPrint) { - ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW, PR_FALSE); - return NS_OK; - } - } - mPrt = new nsPrintData(nsPrintData::eIsPrinting); if (!mPrt) { PR_PL(("NS_ERROR_OUT_OF_MEMORY - Creating PrintData")); diff --git a/gfx/src/gtk/nsDeviceContextSpecG.cpp b/gfx/src/gtk/nsDeviceContextSpecG.cpp index da06b285739..c5657788ed8 100644 --- a/gfx/src/gtk/nsDeviceContextSpecG.cpp +++ b/gfx/src/gtk/nsDeviceContextSpecG.cpp @@ -125,6 +125,11 @@ public: /* Does this device allow to set/change number of copies for an document ? */ void SetCanChangeNumCopies( PRBool aCanSetNumCopies ); + + /* Does this device allow multiple devicecontext instances to be used in + * parallel (e.g. print while the device is already in use by print-preview + * or printing while another print job is in progress) ? */ + void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ); private: /* private helper methods */ @@ -204,6 +209,11 @@ void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies ) SetBoolValue("can_change_num_copies", aCanSetNumCopies); } +void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ) +{ + SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances); +} + #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ //--------------- @@ -791,6 +801,10 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich /* Xprint does not allow the client to set a spooler command. * Job spooling is the job of the server side (=Xprt) */ printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE); + + /* Mozilla's Xprint support allows multiple nsIDeviceContext instances + * be used in parallel */ + printerFeatures.SetMultipleConcurrentDeviceContextsSupported(PR_TRUE); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ XpuClosePrinterDisplay(pdpy, pcontext); diff --git a/gfx/src/xlib/nsDeviceContextSpecXlib.cpp b/gfx/src/xlib/nsDeviceContextSpecXlib.cpp index e7edffbd086..6f992ed16e3 100644 --- a/gfx/src/xlib/nsDeviceContextSpecXlib.cpp +++ b/gfx/src/xlib/nsDeviceContextSpecXlib.cpp @@ -125,7 +125,12 @@ public: /* Does this device allow to set/change number of copies for an document ? */ void SetCanChangeNumCopies( PRBool aCanSetNumCopies ); - + + /* Does this device allow multiple devicecontext instances to be used in + * parallel (e.g. print while the device is already in use by print-preview + * or printing while another print job is in progress) ? */ + void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ); + private: /* private helper methods */ void SetBoolValue( const char *tagname, PRBool value ); @@ -204,6 +209,11 @@ void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies ) SetBoolValue("can_change_num_copies", aCanSetNumCopies); } +void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ) +{ + SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances); +} + #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ //--------------- @@ -799,6 +809,10 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic /* Xprint does not allow the client to set a spooler command. * Job spooling is the job of the server side (=Xprt) */ printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE); + + /* Mozilla's Xprint support allows multiple nsIDeviceContext instances + * be used in parallel */ + printerFeatures.SetMultipleConcurrentDeviceContextsSupported(PR_TRUE); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ XpuClosePrinterDisplay(pdpy, pcontext); diff --git a/gfx/src/xlib/nsDeviceContextX.h b/gfx/src/xlib/nsDeviceContextX.h index 9b28b12df1f..e73f3cbbb9b 100644 --- a/gfx/src/xlib/nsDeviceContextX.h +++ b/gfx/src/xlib/nsDeviceContextX.h @@ -44,6 +44,7 @@ #include "xlibrgb.h" class nsFontMetricsXlibContext; +class nsRenderingContextXlibContext; /* common baseclass for |nsDeviceContextXlib| and |nsDeviceContextXp| */ class nsDeviceContextX : public DeviceContextImpl @@ -60,6 +61,7 @@ public: NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) = 0; virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) = 0; + virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) = 0; }; #endif /* !nsDeviceContextX_h__ */ diff --git a/gfx/src/xlib/nsDeviceContextXlib.cpp b/gfx/src/xlib/nsDeviceContextXlib.cpp index 12137219ab1..a94a7885c51 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.cpp +++ b/gfx/src/xlib/nsDeviceContextXlib.cpp @@ -100,7 +100,7 @@ nsDeviceContextXlib::nsDeviceContextXlib() if (!mXlibRgbHandle) abort(); - mFontMetricsContextCounter++; + mContextCounter++; } nsDeviceContextXlib::~nsDeviceContextXlib() @@ -109,17 +109,20 @@ nsDeviceContextXlib::~nsDeviceContextXlib() NS_IF_RELEASE(surf); mSurface = nsnull; - mFontMetricsContextCounter--; + mContextCounter--; - if (mFontMetricsContext && (mFontMetricsContextCounter == 0)) + if (mContextCounter == 0) { + DeleteRenderingContextXlibContext(mRCContext); DeleteFontMetricsXlibContext(mFontMetricsContext); + mRCContext = nsnull; mFontMetricsContext = nsnull; } } -nsFontMetricsXlibContext *nsDeviceContextXlib::mFontMetricsContext = nsnull; -int nsDeviceContextXlib::mFontMetricsContextCounter = 0; +nsFontMetricsXlibContext *nsDeviceContextXlib::mFontMetricsContext = nsnull; +nsRenderingContextXlibContext *nsDeviceContextXlib::mRCContext = nsnull; +int nsDeviceContextXlib::mContextCounter = 0; NS_IMETHODIMP nsDeviceContextXlib::Init(nsNativeWidget aNativeWidget) { @@ -203,6 +206,15 @@ nsDeviceContextXlib::CommonInit(void) if (!mFontMetricsContext) { rv = CreateFontMetricsXlibContext(this, PR_FALSE, &mFontMetricsContext); + if (NS_FAILED(rv)) + return rv; + } + + if (!mRCContext) + { + rv = CreateRenderingContextXlibContext(this, &mRCContext); + if (NS_FAILED(rv)) + return rv; } return rv; diff --git a/gfx/src/xlib/nsDeviceContextXlib.h b/gfx/src/xlib/nsDeviceContextXlib.h index 226e917366a..1875d9a9abf 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.h +++ b/gfx/src/xlib/nsDeviceContextXlib.h @@ -89,6 +89,7 @@ public: XlibRgbHandle *GetXlibRgbHandle() { return mXlibRgbHandle; } NS_IMETHOD GetDepth( PRUint32 &depth ) { depth = (PRUint32)mDepth; return NS_OK; } virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) { aContext = mFontMetricsContext; }; + virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) { aContext = mRCContext; }; protected: virtual ~nsDeviceContextXlib(); @@ -103,8 +104,9 @@ private: Screen * mScreen; Visual * mVisual; int mDepth; - static nsFontMetricsXlibContext *mFontMetricsContext; - static int mFontMetricsContextCounter; + static nsFontMetricsXlibContext *mFontMetricsContext; + static nsRenderingContextXlibContext *mRCContext; + static int mContextCounter; float mWidthFloat; float mHeightFloat; diff --git a/gfx/src/xlib/nsGfxFactoryXlib.cpp b/gfx/src/xlib/nsGfxFactoryXlib.cpp index b0260fabac0..a24c895908b 100644 --- a/gfx/src/xlib/nsGfxFactoryXlib.cpp +++ b/gfx/src/xlib/nsGfxFactoryXlib.cpp @@ -201,7 +201,6 @@ static const nsModuleComponentInfo components[] = PR_STATIC_CALLBACK(void) nsGfxXlibModuleDtor(nsIModule *self) { - nsRenderingContextXlib::Shutdown(); } NS_IMPL_NSGETMODULE_WITH_DTOR(nsGfxXlibModule, components, nsGfxXlibModuleDtor) diff --git a/gfx/src/xlib/nsRenderingContextXlib.cpp b/gfx/src/xlib/nsRenderingContextXlib.cpp index 4fdabbd3b9e..625d64ee0b5 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -74,7 +74,34 @@ static void Widen8To16AndDraw(Drawable drawable, int text_length); -nsGCCacheXlib *nsRenderingContextXlib::gcCache = nsnull; +class nsRenderingContextXlibContext +{ +public: + nsGCCacheXlib mGcCache; +}; + +nsresult CreateRenderingContextXlibContext(nsIDeviceContext *aDevice, nsRenderingContextXlibContext **aContext) +{ + nsRenderingContextXlibContext *rcctx; + + *aContext = nsnull; + + rcctx = new nsRenderingContextXlibContext(); + if (!rcctx) + return NS_ERROR_OUT_OF_MEMORY; + + /* No |Init()|-function to call (yet) */ + *aContext = rcctx; + + return NS_OK; +} + +void DeleteRenderingContextXlibContext(nsRenderingContextXlibContext *aContext) +{ + if (aContext) { + delete aContext; + } +} class GraphicsState { @@ -142,16 +169,6 @@ nsRenderingContextXlib::~nsRenderingContextXlib() mGC->Release(); } -/*static*/ nsresult -nsRenderingContextXlib::Shutdown() -{ - if (gcCache) { - delete gcCache; - gcCache = nsnull; - } - return NS_OK; -} - NS_IMETHODIMP nsRenderingContextXlib::Init(nsIDeviceContext* aContext, nsIWidget *aWindow) { @@ -604,15 +621,13 @@ void nsRenderingContextXlib::UpdateGC() if (mClipRegion) { mClipRegion->GetNativeRegion((void*&)rgn); } - - if (!gcCache) { - gcCache = new nsGCCacheXlib(); - if (!gcCache) - return; - } - mGC = gcCache->GetGC(mDisplay, drawable, - valuesMask, &values, rgn); + nsRenderingContextXlibContext *rcContext; + nsIDeviceContext *dc = mContext; + NS_STATIC_CAST(nsDeviceContextX *, dc)->GetRCContext(rcContext); + + mGC = rcContext->mGcCache.GetGC(mDisplay, drawable, + valuesMask, &values, rgn); } NS_IMETHODIMP diff --git a/gfx/src/xlib/nsRenderingContextXlib.h b/gfx/src/xlib/nsRenderingContextXlib.h index 8ed8fe5ad1e..4f0c7f625f0 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.h +++ b/gfx/src/xlib/nsRenderingContextXlib.h @@ -66,7 +66,6 @@ class nsRenderingContextXlib : public nsRenderingContextImpl public: nsRenderingContextXlib(); virtual ~nsRenderingContextXlib(); - static nsresult Shutdown(); // release statics NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -272,8 +271,10 @@ protected: w = 32766 - x; } } - - static nsGCCacheXlib *gcCache; }; +/* Prototypes */ +nsresult CreateRenderingContextXlibContext(nsIDeviceContext *aDevice, nsRenderingContextXlibContext **aContext); +void DeleteRenderingContextXlibContext(nsRenderingContextXlibContext *aContext); + #endif /* !nsRenderingContextXlib_h___ */ diff --git a/gfx/src/xprint/nsDeviceContextXP.cpp b/gfx/src/xprint/nsDeviceContextXP.cpp index af8366c04ea..5f121103056 100644 --- a/gfx/src/xprint/nsDeviceContextXP.cpp +++ b/gfx/src/xprint/nsDeviceContextXP.cpp @@ -62,7 +62,8 @@ nsDeviceContextXp :: nsDeviceContextXp() mPrintContext(nsnull), mSpec(nsnull), mParentDeviceContext(nsnull), - mFontMetricsContext(nsnull) + mFontMetricsContext(nsnull), + mRCContext(nsnull) { } @@ -144,15 +145,18 @@ nsDeviceContextXp::InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext, mParentDeviceContext = aParentContext; /* be sure we've cleaned-up old rubbish - new values will re-populate nsFontMetricsXlib soon... */ - if (mFontMetricsContext) - { - DeleteFontMetricsXlibContext(mFontMetricsContext); - mFontMetricsContext = nsnull; - } + DeleteRenderingContextXlibContext(mRCContext); + DeleteFontMetricsXlibContext(mFontMetricsContext); + mRCContext = nsnull; + mFontMetricsContext = nsnull; rv = CreateFontMetricsXlibContext(this, PR_TRUE, &mFontMetricsContext); if (NS_FAILED(rv)) return rv; + + rv = CreateRenderingContextXlibContext(this, &mRCContext); + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -310,12 +314,10 @@ void nsDeviceContextXp::DestroyXPContext() * properties (build-in fonts for example ) than the printer * previously used. */ FlushFontCache(); - nsRenderingContextXlib::Shutdown(); - if (mFontMetricsContext) - { - DeleteFontMetricsXlibContext(mFontMetricsContext); - mFontMetricsContext = nsnull; - } + DeleteRenderingContextXlibContext(mRCContext); + DeleteFontMetricsXlibContext(mFontMetricsContext); + mRCContext = nsnull; + mFontMetricsContext = nsnull; mPrintContext = nsnull; // nsCOMPtr will call |delete mPrintContext;| } diff --git a/gfx/src/xprint/nsDeviceContextXP.h b/gfx/src/xprint/nsDeviceContextXP.h index 163fa30ea9c..afca5c6207c 100644 --- a/gfx/src/xprint/nsDeviceContextXP.h +++ b/gfx/src/xprint/nsDeviceContextXP.h @@ -103,7 +103,8 @@ public: NS_IMETHOD CreateFontCache(); virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) { aContext = mFontMetricsContext; }; - + virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) { aContext = mRCContext; }; + protected: virtual ~nsDeviceContextXp(); void DestroyXPContext(); @@ -112,6 +113,7 @@ protected: nsCOMPtr mSpec; nsCOMPtr mParentDeviceContext; nsFontMetricsXlibContext *mFontMetricsContext; + nsRenderingContextXlibContext *mRCContext; }; #endif /* !nsDeviceContextXp_h___ */ diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 9f6377512b1..39d8afbec3b 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -584,19 +584,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, nsCOMPtr docShell(do_QueryInterface(mContainer)); NS_ASSERTION(docShell, "This has to be a docshell"); - - if (mIsDoingPrintPreview) { - PRBool okToPrint = PR_FALSE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.whileInPrintPreview", &okToPrint); - } - if (!okToPrint) { - ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW, PR_FALSE); - return NS_OK; - } - } - mPrt = new nsPrintData(nsPrintData::eIsPrinting); if (!mPrt) { PR_PL(("NS_ERROR_OUT_OF_MEMORY - Creating PrintData")); diff --git a/xpfe/communicator/resources/content/printPreviewBindings.xml b/xpfe/communicator/resources/content/printPreviewBindings.xml index adeb1db6615..ce02a056a0c 100644 --- a/xpfe/communicator/resources/content/printPreviewBindings.xml +++ b/xpfe/communicator/resources/content/printPreviewBindings.xml @@ -170,15 +170,35 @@ } catch(e) {} - // XXX TEMPORARY - // XXX Until bug 119491 ("Cleanup global vars in PostScript and Xprint - // modules") is fixed we will hide the ``Print...'' button + // Hide the ``Print...'' button when the underlying gfx code does not + // support multiple devicecontext to be used concurrently + // (e.g. printing and printpreview at the same time; required as + // legacy support for unices.'s PostScript module (Xprint + // on unices.does not have problems with that)) // XXX the scaling widgets, and the orientation widgets on unices. var canPrint = true; try { var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); canPrint = prefs.getBoolPref("print.whileInPrintPreview"); + if (!canPrint) + { + // Ask the printerfeatures database if this printer device + // supports multiple device instances which can be used + // concurrently + var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + + print.currentPrintSettings.printerName + + ".can_use_multiple_devicecontexts_concurrently"); + + // We can print from print preview when we can use multiple + // devicecontext instances in parallel (regardless what + // "print.whileInPrintPreview" may say here...) + if (smdci) + { + canPrint = true; + } + } + } catch(e) {} if (!canPrint) @@ -197,7 +217,6 @@ document.getAnonymousNodes(this)[i].setAttribute("hidden", "true"); } } - // XXX TEMPORARY ]]>