diff --git a/mozilla/content/base/public/MANIFEST_IDL b/mozilla/content/base/public/MANIFEST_IDL index ffed46f129b..8492affc8f9 100644 --- a/mozilla/content/base/public/MANIFEST_IDL +++ b/mozilla/content/base/public/MANIFEST_IDL @@ -10,3 +10,6 @@ nsISelectionListener.idl nsISelectionPrivate.idl nsIScriptLoader.idl nsIScriptLoaderObserver.idl +nsIPrintProgress.idl +nsIPrintStatusFeedback.idl +nsIPrintProgressParams.idl diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 5ee3fcdeb10..781da6156bc 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -119,11 +119,14 @@ #include "nsIFocusController.h" // Print Options +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms +#include "nsISimpleEnumerator.h" +#include "nsISupportsPrimitives.h" +static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // Printing Events #include "nsIEventQueue.h" @@ -140,6 +143,11 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsIEventProcessor.h" #include "imgIContainer.h" // image animation mode constants +// Print Progress +#include "nsPrintProgress.h" +#include "nsPrintProgressParams.h" + + // Print error dialog #include "nsIPrompt.h" #include "nsIWindowWatcher.h" @@ -354,15 +362,25 @@ public: // Listener Helper Methods void OnEndPrinting(nsresult aResult); void OnStartPrinting(); + static void DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, + PRInt32 aMaxProgress, + PRBool aDoStartStop = PR_FALSE, + PRInt32 aFlag = 0); nsCOMPtr mPrintDC; nsIView *mPrintView; - FILE *mFilePointer; // a file where information can go to when printing + FILE *mDebugFilePtr; // a file where information can go to when printing PrintObject * mPrintObject; PrintObject * mSelectedPO; - nsCOMPtr mPrintListener; // An observer for printing... + nsVoidArray mPrintProgressListeners; + nsCOMPtr mPrintProgressListener; + nsCOMPtr mPrintProgress; + nsCOMPtr mPrintProgressParams; + PRBool mShowProgressDialog; + nsCOMPtr mCurrentFocusWin; // cache a pointer to the currently focused window nsVoidArray* mPrintDocList; @@ -378,6 +396,8 @@ public: PRInt32 mNumPrintablePages; PRInt32 mNumPagesPrinted; + nsCOMPtr mPrintSettings; + #ifdef DEBUG_PRINTING FILE * mDebugFD; #endif @@ -436,7 +456,7 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // Printing Methods - PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintOptions* aPrintOptions,PrintObject* aPOect); + PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintSettings* aPrintSettings,PrintObject* aPOect); PRBool DonePrintingPages(PrintObject* aPO); // helper method @@ -493,6 +513,12 @@ private: void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages); void DoProgressForAsIsFrames(); void DoProgressForSeparateFrames(); + void DoPrintProgress(PRBool aIsForPrinting); + void SetDocAndURLIntoProgress(nsIWebShell* aWebShell, nsIPrintProgressParams* aParams); + nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, + PRUint32 aErrorCode, + PRBool aIsPrinting); // get the currently infocus frame for the document viewer nsIDOMWindowInternal * FindFocusedDOMWindowInternal(); @@ -531,14 +557,14 @@ private: // Timer Methods nsresult StartPagePrintTimer(nsIPresContext * aPresContext, - nsIPrintOptions* aPrintOptions, - PrintObject* aPOect, + nsIPrintSettings* aPrintSettings, + PrintObject* aPO, PRUint32 aDelay); void PrepareToStartLoad(void); // Misc - void ShowPrintErrorDialog(nsresult printerror); + void ShowPrintErrorDialog(nsresult printerror, PRBool aIsPrinting = PR_TRUE); protected: // IMPORTANT: The ownership implicit in the following member @@ -585,6 +611,10 @@ protected: PrintData* mPrtPreview; #endif +#ifdef NS_DEBUG + FILE* mDebugFile; +#endif + // static memeber variables static PRBool mIsCreatingPrintPreview; static PRBool mIsDoingPrinting; @@ -610,7 +640,7 @@ public: NS_DECL_ISUPPORTS nsPagePrintTimer() - : mDocViewer(nsnull), mPresContext(nsnull), mPrintOptions(nsnull), mDelay(0) + : mDocViewer(nsnull), mPresContext(nsnull), mPrintSettings(nsnull), mDelay(0) { NS_INIT_ISUPPORTS(); } @@ -648,7 +678,7 @@ public: // Check to see if we are done // donePrinting will be true if it completed successfully or // if the printing was cancelled - PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintOptions, mPrintObj); + PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintSettings, mPrintObj); if (donePrinting) { // now clean up print or print the next webshell if (mDocViewer->DonePrintingPages(mPrintObj)) { @@ -669,7 +699,7 @@ public: void Init(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay) { @@ -678,18 +708,18 @@ public: NS_ADDREF(mDocViewer); mPresContext = aPresContext; - mPrintOptions = aPrintOptions; + mPrintSettings = aPrintSettings; mPrintObj = aPO; mDelay = aDelay; } nsresult Start(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay) { - Init(aDocViewerImpl, aPresContext, aPrintOptions, aPO, aDelay); + Init(aDocViewerImpl, aPresContext, aPrintSettings, aPO, aDelay); return StartTimer(); } @@ -703,12 +733,12 @@ public: } private: - DocumentViewerImpl* mDocViewer; - nsIPresContext* mPresContext; - nsIPrintOptions* mPrintOptions; - nsCOMPtr mTimer; - PRUint32 mDelay; - PrintObject * mPrintObj; + DocumentViewerImpl* mDocViewer; + nsIPresContext* mPresContext; + nsCOMPtr mPrintSettings; + nsCOMPtr mTimer; + PRUint32 mDelay; + PrintObject * mPrintObj; }; NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback) @@ -735,10 +765,10 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult) //-- PrintData Class Impl //--------------------------------------------------- PrintData::PrintData() : - mPrintView(nsnull), mFilePointer(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), - mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), + mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), + mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), - mPrintFrameType(nsIPrintOptions::kFramesAsIs), mOnStartSent(PR_FALSE), + mPrintFrameType(nsIPrintSettings::kFramesAsIs), mOnStartSent(PR_FALSE), mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0) { #ifdef DEBUG_PRINTING @@ -762,35 +792,58 @@ PrintData::~PrintData() delete mPrintObject; - mPrintDocList->Clear(); - delete mPrintDocList; + if (mPrintDocList != nsnull) { + mPrintDocList->Clear(); + delete mPrintDocList; + } #ifdef DEBUG_PRINTING fclose(mDebugFD); #endif DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; + + for (PRInt32 i=0;iOnStartPrinting(); - } + if (!mOnStartSent) { + DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT); mOnStartSent = PR_TRUE; } } void PrintData::OnEndPrinting(nsresult aResult) { - if (mPrintListener) { - if (!mOnStartSent) { - mPrintListener->OnStartPrinting(); + // Make sure OnStartPrinting was called + OnStartPrinting(); + + DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT); + if (mPrintProgress && mShowProgressDialog) { + mPrintProgress->CloseProgressDialog(PR_TRUE); + } +} + +void +PrintData::DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, + PRInt32 aMaxProgress, + PRBool aDoStartStop, + PRInt32 aFlag) +{ + for (PRInt32 i=0;iOnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); + if (aDoStartStop) { + wpl->OnStateChange(nsnull, nsnull, aFlag, 0); } - mPrintListener->OnEndPrinting(aResult); - // clear the lister so the destructor doesn't send the - mPrintListener = nsnull; } } @@ -875,6 +928,10 @@ void DocumentViewerImpl::PrepareToStartLoad() { mIsDoingPrintPreview = PR_FALSE; mPrtPreview = nsnull; #endif + +#ifdef NS_DEBUG + mDebugFile = nsnull; +#endif } DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) @@ -2306,27 +2363,34 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) //------------------------------------------------------- PRBool -DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - PrintObject* aPO) +DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, + nsIPrintSettings* aPrintSettings, + PrintObject* aPO) { NS_ASSERTION(aPresContext, "Pointer is null!"); - NS_ASSERTION(aPrintOptions, "Pointer is null!"); + NS_ASSERTION(aPrintSettings, "Pointer is null!"); NS_ASSERTION(aPO, "Pointer is null!"); PRINT_DEBUG_MSG1("-----------------------------------\n"); PRINT_DEBUG_MSG3("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesStr[aPO->mFrameType]); - nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { + if (aPrintSettings != nsnull) { PRBool isCancelled; - printService->GetIsCancelled(&isCancelled); + aPrintSettings->GetIsCancelled(&isCancelled); // DO NOT allow the print job to be cancelled if it is Print FrameAsIs // because it is only printing one page. - if (isCancelled && mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs) { - printService->SetIsCancelled(PR_FALSE); + if (isCancelled && mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs) { + aPrintSettings->SetIsCancelled(PR_FALSE); + return PR_TRUE; + } + } + if (mPrt->mPrintProgress) { + PRBool isCancelled; + mPrt->mPrintProgress->GetProcessCanceledByUser(&isCancelled); + // DO NOT allow the print job to be cancelled if it is Print FrameAsIs + // because it is only printing one page. + if (isCancelled && mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs) { + aPrintSettings->SetIsCancelled(PR_FALSE); return PR_TRUE; } } @@ -2370,19 +2434,12 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // NOTE: mPrt->mPrintFrameType gets set to "kFramesAsIs" when a // plain document contains IFrames, so we need to override that case here - if (mPrt->mPrintListener) { - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { - DoProgressForSeparateFrames(); + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + DoProgressForSeparateFrames(); - } else if (mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs || - mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { - // Make sure the Listener gets a "zero" progress at the beginning - // so it can initialize it's state - if (curPage == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, endPage); - } - mPrt->mPrintListener->OnProgressPrinting(curPage, endPage); - } + } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || + mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, curPage+1, endPage); } // Set Clip when Printing "AsIs" or @@ -2390,11 +2447,11 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, PRBool setClip = PR_FALSE; switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: setClip = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO->mPrintAsIs) { if (aPO->mFrameType == eIFrame) { setClip = aPO != mPrt->mSelectedPO; @@ -2402,7 +2459,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: if (aPO->mPrintAsIs) { if (aPO->mFrameType == eIFrame) { setClip = PR_TRUE; @@ -2420,7 +2477,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // if a print job was cancelled externally, an EndPage or BeginPage may // fail and the failure is passed back here. // Returning PR_TRUE means we are done printing. - if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext, aPrintOptions))) { + if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext))) { return PR_TRUE; } @@ -2454,7 +2511,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // XXX this is because PrintAsIs for FrameSets reflows to two pages // not sure why, but this needs to be fixed. - if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { return PR_TRUE; } } @@ -2801,7 +2858,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, if (aDoingSetClip) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mClipRect.height); clipRect = aPO->mClipRect; - } else if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + } else if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.height); clipRect = aPO->mClipRect; doClip = PR_TRUE; @@ -2814,7 +2871,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, clipRect = aPO->mClipRect; } else { - if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if (aPO->mParent && aPO->mParent == mPrt->mSelectedPO) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.height); clipRect = aPO->mClipRect; @@ -2887,20 +2944,19 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) PRBool containerIsSet = PR_FALSE; nsresult rv; if (mIsCreatingPrintPreview) { - aPO->mPresContext = do_CreateInstance(kPrintPreviewContextCID,&rv); + nsCOMPtr printPreviewCon(do_CreateInstance(kPrintPreviewContextCID, &rv)); if (NS_FAILED(rv)) { return rv; } + aPO->mPresContext = do_QueryInterface(printPreviewCon); + printPreviewCon->SetPrintSettings(mPrt->mPrintSettings); } else { nsCOMPtr printcon(do_CreateInstance(kPrintContextCID, &rv)); if (NS_FAILED(rv)) { return rv; - } else { - aPO->mPresContext = do_QueryInterface(printcon); - if (NS_FAILED(rv)) { - return rv; - } } + aPO->mPresContext = do_QueryInterface(printcon); + printcon->SetPrintSettings(mPrt->mPrintSettings); } // init it with the DC @@ -2946,15 +3002,13 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) // This means you can never print any selection that is longer than one page // put it keeps it from page breaking in the middle of your print of the selection // (see also nsSimplePageSequence.cpp) - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->GetPrintRange(&printRangeType); + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + if (mPrt->mPrintSettings != nsnull) { + mPrt->mPrintSettings->GetPrintRange(&printRangeType); } - if (printRangeType == nsIPrintOptions::kRangeSelection && IsThereARangeSelection(domWinIntl)) { + if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSelection(domWinIntl)) { height = 0x0FFFFFFF; } nsRect tbounds = nsRect(0, 0, width, height); @@ -3033,9 +3087,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) aPO->mPresShell->BeginObservingDocument(); nsMargin margin(0,0,0,0); - if (printService) { - printService->GetMarginInTwips(margin); - } + mPrt->mPrintSettings->GetMarginInTwips(margin); // initialize it with the default/generic case nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); @@ -3047,7 +3099,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) const PRInt32 kFivePagesHigh = 5; // now, change the value for special cases - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { if (aPO->mFrameType == eFrame) { adjRect.SetRect(0, 0, width, height); } else if (aPO->mFrameType == eIFrame) { @@ -3055,7 +3107,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); } - } else if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + } else if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if (aPO->mFrameType == eFrame) { adjRect.SetRect(0, 0, width, height); } else if (aPO->mFrameType == eIFrame) { @@ -3090,7 +3142,6 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) } } } - #ifdef DEBUG_rods { @@ -3222,21 +3273,18 @@ DocumentViewerImpl::EnablePOsForPrinting() // this is where we decided which POs get printed. mPrt->mSelectedPO = nsnull; - nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_FAILED(rv)) { - return rv; + if (mPrt->mPrintSettings == nsnull) { + return NS_ERROR_FAILURE; } - mPrt->mPrintFrameType = nsIPrintOptions::kNoFrames; - printService->GetPrintFrameType(&mPrt->mPrintFrameType); + mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; + mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - printService->GetPrintRange(&printRangeType); + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->GetPrintRange(&printRangeType); PRINT_DEBUG_MSG1("\n********* DocumentViewerImpl::EnablePOsForPrinting *********\n"); PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); @@ -3248,9 +3296,9 @@ DocumentViewerImpl::EnablePOsForPrinting() // ***** This is the ultimate override ***** // if we are printing the selection (either an IFrame or selection range) // then set the mPrintFrameType as if it were the selected frame - if (printRangeType == nsIPrintOptions::kRangeSelection) { - mPrt->mPrintFrameType = nsIPrintOptions::kSelectedFrame; - printHowEnable = nsIPrintOptions::kFrameEnableNone; + if (printRangeType == nsIPrintSettings::kRangeSelection) { + mPrt->mPrintFrameType = nsIPrintSettings::kSelectedFrame; + printHowEnable = nsIPrintSettings::kFrameEnableNone; } // This tells us that the "Frame" UI has turned off, @@ -3258,11 +3306,11 @@ DocumentViewerImpl::EnablePOsForPrinting() // // This means there are not FrameSets, // but the document could contain an IFrame - if (printHowEnable == nsIPrintOptions::kFrameEnableNone) { + if (printHowEnable == nsIPrintSettings::kFrameEnableNone) { // Print all the pages or a sub range of pages - if (printRangeType == nsIPrintOptions::kRangeAllPages || - printRangeType == nsIPrintOptions::kRangeSpecifiedPageRange) { + if (printRangeType == nsIPrintSettings::kRangeAllPages || + printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); // Set the children so they are PrinAsIs @@ -3275,7 +3323,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // ***** Another override ***** - mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; + mPrt->mPrintFrameType = nsIPrintSettings::kFramesAsIs; } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3285,7 +3333,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // This means we are either printed a selected IFrame or // we are printing the current selection - if (printRangeType == nsIPrintOptions::kRangeSelection) { + if (printRangeType == nsIPrintSettings::kRangeSelection) { // If the currentFocusDOMWin can'r be null if something is selected if (mPrt->mCurrentFocusWin) { @@ -3308,8 +3356,8 @@ DocumentViewerImpl::EnablePOsForPrinting() // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { - printRangeType = nsIPrintOptions::kRangeAllPages; - printService->SetPrintRange(printRangeType); + printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->SetPrintRange(printRangeType); } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3322,6 +3370,7 @@ DocumentViewerImpl::EnablePOsForPrinting() NS_ASSERTION(po, "PrintObject can't be null!"); nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (IsThereARangeSelection(domWin)) { + mPrt->mCurrentFocusWin = domWin; SetPrintPO(po, PR_TRUE); break; } @@ -3332,7 +3381,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // check to see if there is a selection when a FrameSet is present - if (printRangeType == nsIPrintOptions::kRangeSelection) { + if (printRangeType == nsIPrintSettings::kRangeSelection) { // If the currentFocusDOMWin can'r be null if something is selected if (mPrt->mCurrentFocusWin) { // Find the selected IFrame @@ -3354,8 +3403,8 @@ DocumentViewerImpl::EnablePOsForPrinting() // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { - printRangeType = nsIPrintOptions::kRangeAllPages; - printService->SetPrintRange(printRangeType); + printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->SetPrintRange(printRangeType); } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3366,7 +3415,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // If we are printing "AsIs" then sets all the POs to be printed as is - if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { SetPrintAsIs(mPrt->mPrintObject); SetPrintPO(mPrt->mPrintObject, PR_TRUE); return NS_OK; @@ -3375,7 +3424,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // If we are printing the selected Frame then // find that PO for that selected DOMWin and set it all of its // children to be printed - if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if ((mPrt->mIsParentAFrameSet && mPrt->mCurrentFocusWin) || mPrt->mIsIFrameSelected) { PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCurrentFocusWin); @@ -3398,7 +3447,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // If we are print each subdoc separately, // then don't print any of the FraneSet Docs - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); PRInt32 cnt = mPrt->mPrintDocList->Count(); for (PRInt32 i=0;imFilePointer ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); + rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); PRINT_DEBUG_MSG1("****************** Begin Document ************************\n"); if (docTitleStr != nsnull) { @@ -3539,14 +3588,16 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nsCOMPtr webContainer(do_QueryInterface(mContainer)); NS_ASSERTION(webShell, "The WebShell can't be NULL!"); + if (mPrt->mPrintProgressParams) { + SetDocAndURLIntoProgress(aPO->mWebShell, mPrt->mPrintProgressParams); + } + if (webShell != nsnull) { - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - printService->GetPrintRange(&printRangeType); + if (mPrt->mPrintSettings != nsnull) { + mPrt->mPrintSettings->GetPrintRange(&printRangeType); } // Ask the page sequence frame to print all the pages @@ -3566,18 +3617,18 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (aPO->mFrameType == eFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO->mKids.Count() > 0) { skipPageEjectOnly = PR_TRUE; } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: if (aPO->mKids.Count() > 0) { skipPageEjectOnly = PR_TRUE; } @@ -3586,13 +3637,13 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } else if (aPO->mFrameType == eIFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; skipSetTitle = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO != mPrt->mSelectedPO) { skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; @@ -3603,7 +3654,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; doAddInParentsOffset = aPO->mParent != nsnull && aPO->mParent->mFrameType == eIFrame; @@ -3637,7 +3688,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nscoord y = 0; PrintObject * po = aPO; while (po != nsnull) { - //if (mPrt->mPrintFrameType != nsIPrintOptions::kSelectedFrame || po != aPO->mParent) { + //if (mPrt->mPrintFrameType != nsIPrintSettings::kSelectedFrame || po != aPO->mParent) { PRBool isParent = po == aPO->mParent; if (!isParent || (isParent && doAddInParentsOffset)) { x += po->mRect.x; @@ -3653,16 +3704,19 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)); - if (nsnull != mPrt->mFilePointer) { + // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging + if (nsnull != mPrt->mDebugFilePtr) { +#ifdef NS_DEBUG // output the regression test nsIFrameDebug* fdbg; nsIFrame* root; poPresShell->GetRootFrame(&root); if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - fdbg->DumpRegressionData(poPresContext, mPrt->mFilePointer, 0, PR_TRUE); + fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRUE); } - fclose(mPrt->mFilePointer); + fclose(mPrt->mDebugFilePtr); +#endif } else { nsIFrame* rootFrame; poPresShell->GetRootFrame(&rootFrame); @@ -3678,7 +3732,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } #endif - if (printService) { + if (mPrt->mPrintSettings) { if (!skipSetTitle) { PRUnichar * docTitleStr; PRUnichar * docURLStr; @@ -3689,17 +3743,17 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } if (docTitleStr) { - printService->SetTitle(docTitleStr); + mPrt->mPrintSettings->SetTitle(docTitleStr); nsMemory::Free(docTitleStr); } if (docURLStr) { - printService->SetDocURL(docURLStr); + mPrt->mPrintSettings->SetDocURL(docURLStr); nsMemory::Free(docURLStr); } } - if (nsIPrintOptions::kRangeSelection == printRangeType) { + if (nsIPrintSettings::kRangeSelection == printRangeType) { poPresContext->SetIsRenderingOnlySelection(PR_TRUE); // temporarily creating rendering context // which is needed to dinf the selection frames @@ -3724,10 +3778,10 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a &startFrame, startPageNum, startRect, &endFrame, endPageNum, endRect); if (NS_SUCCEEDED(rv)) { - printService->SetStartPageRange(startPageNum); - printService->SetEndPageRange(endPageNum); + mPrt->mPrintSettings->SetStartPageRange(startPageNum); + mPrt->mPrintSettings->SetEndPageRange(endPageNum); nsMargin margin(0,0,0,0); - printService->GetMarginInTwips(margin); + mPrt->mPrintSettings->GetMarginInTwips(margin); if (startPageNum == endPageNum) { nsIFrame * seqFrame; @@ -3773,22 +3827,22 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a rootFrame->SetRect(poPresContext, r); mPageSeqFrame = pageSequence; - mPageSeqFrame->StartPrint(poPresContext, printService); + mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings); if (!aDoSyncPrinting) { // Get the delay time in between the printing of each page // this gives the user more time to press cancel PRInt32 printPageDelay = 500; - printService->GetPrintPageDelay(&printPageDelay); + mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); // Schedule Page to Print PRINT_DEBUG_MSG3("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]); - StartPagePrintTimer(poPresContext, printService, aPO, printPageDelay); + StartPagePrintTimer(poPresContext, mPrt->mPrintSettings, aPO, printPageDelay); } else { DoProgressForAsIsFrames(); // Print the page synchronously PRINT_DEBUG_MSG3("Async Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]); - aDonePrinting = PrintPage(poPresContext, printService, aPO); + aDonePrinting = PrintPage(poPresContext, mPrt->mPrintSettings, aPO); } } } else { @@ -3844,18 +3898,12 @@ DocumentViewerImpl::CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNu void DocumentViewerImpl::DoProgressForAsIsFrames() { - if (mPrt->mPrintListener) { - // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe eDoc - // this is done to make the printing of embedded IFrames easier - // NOTE: we don't want to advance the progress in that case, it is down elsewhere - if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs && mPrt->mPrintObject->mFrameType != eDoc) { - mPrt->mNumDocsPrinted++; - // notify the listener of printed docs - if (mPrt->mNumDocsPrinted == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintableDocs); - } - mPrt->mPrintListener->OnProgressPrinting(mPrt->mNumDocsPrinted, mPrt->mNumPrintableDocs); - } + // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe eDoc + // this is done to make the printing of embedded IFrames easier + // NOTE: we don't want to advance the progress in that case, it is down elsewhere + if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs && mPrt->mPrintObject->mFrameType != eDoc) { + mPrt->mNumDocsPrinted++; + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, mPrt->mNumDocsPrinted, mPrt->mNumPrintableDocs); } } @@ -3863,15 +3911,10 @@ DocumentViewerImpl::DoProgressForAsIsFrames() void DocumentViewerImpl::DoProgressForSeparateFrames() { - if (mPrt->mPrintListener) { - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { - mPrt->mNumPagesPrinted++; - // notify the listener of printed docs - if (mPrt->mNumPagesPrinted == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintablePages); - } - mPrt->mPrintListener->OnProgressPrinting(mPrt->mNumPagesPrinted, mPrt->mNumPrintablePages); - } + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + mPrt->mNumPagesPrinted++; + // notify the listener of printed docs + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, mPrt->mNumPagesPrinted+1, mPrt->mNumPrintablePages); } } @@ -4697,6 +4740,63 @@ DocumentViewerImpl::ReturnToGalleyPresentation() #endif // NS_PRINT_PREVIEW +//----------------------------------------------------------------- +// This method checks to see if there is at least one printer defined +// and if so, it sets the first printer in the list as the default name +// in the PrintSettings which is then used for Printer Preview +nsresult +DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, + PRUint32 aErrorCode, + PRBool aIsPrinting) +{ + NS_ENSURE_ARG_POINTER(aPrintOptions); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + PRUint32 numPrinters = 0; + + nsCOMPtr simpEnum; + aPrintOptions->AvailablePrinters(getter_AddRefs(simpEnum)); + if (simpEnum) { + numPrinters = 0; + do { + PRBool hasMore; + simpEnum->HasMoreElements(&hasMore); + if (!hasMore) break; + + nsCOMPtr supps; + simpEnum->GetNext(getter_AddRefs(supps)); + if (numPrinters == 0) { + nsCOMPtr wStr = do_QueryInterface(supps); + if (wStr) { + PRUnichar* defPrinterName; + wStr->ToString(&defPrinterName); + aPrintSettings->SetPrinterName(defPrinterName); + nsMemory::Free(defPrinterName); + } + } + numPrinters++; + } while (true); + + if (numPrinters == 0) { + // this means there were no printers + ShowPrintErrorDialog(aErrorCode, aIsPrinting); + } else { + rv = NS_OK; + } + } else { + // this means there were no printers + // XXX the ifdefs are temporary until they correctly implement Available Printers +#if defined(XP_MAC) || defined(XP_OS2) + rv = NS_OK; +#else + ShowPrintErrorDialog(aErrorCode, aIsPrinting); +#endif + } + return rv; +} + /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 11/01/01 rods @@ -4705,7 +4805,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() * PrintPreview: See the design spec that is attached to Bug 107562 */ NS_IMETHODIMP -DocumentViewerImpl::PrintPreview() +DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { nsresult rv = NS_OK; @@ -4716,26 +4816,37 @@ DocumentViewerImpl::PrintPreview() // another is still in here (the printing dialog is a good example). // the only time we can print more than one job at a time is the regression tests if (mIsDoingPrintPreview) { -#if 0 - // Let the user know we are not ready to print. - rv = NS_ERROR_NOT_AVAILABLE; - ShowPrintErrorDialog(rv); - return rv; -#else ReturnToGalleyPresentation(); return NS_OK; -#endif } - - // Let's print ... - mIsCreatingPrintPreview = PR_TRUE; - mIsDoingPrintPreview = PR_TRUE; mPrt = new PrintData(); if (mPrt == nsnull) { mIsCreatingPrintPreview = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } + + mPrt->mPrintSettings = aPrintSettings; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + // if they don't pass in a PrintSettings, then make one + if (mPrt->mPrintSettings == nsnull) { + printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings)); + } + NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!"); + + // Get the default printer name and set it into the PrintSettings + if (NS_FAILED(CheckForPrinters(printService, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_PRINTPREVIEW, PR_FALSE))) { + delete mPrt; + mPrt = nsnull; + return NS_ERROR_FAILURE; + } + } + + // Let's print ... + mIsCreatingPrintPreview = PR_TRUE; + mIsDoingPrintPreview = PR_TRUE; + mIsDoingPrintPreview = PR_TRUE; // Very important! Turn Off scripting @@ -4791,28 +4902,26 @@ DocumentViewerImpl::PrintPreview() // Setup print options for UI rv = NS_ERROR_FAILURE; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { + if (mPrt->mPrintSettings != nsnull) { if (mPrt->mIsParentAFrameSet) { if (mPrt->mCurrentFocusWin) { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); } } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); } // Now determine how to set up the Frame print UI - printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); + mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); } #ifdef DEBUG_PRINTING - if (printService) { - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + if (mPrt->mPrintSettings) { + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &val); + mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n"); PRINT_DEBUG_MSG2("IsParentAFrameSet: %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet)); @@ -4835,14 +4944,14 @@ DocumentViewerImpl::PrintPreview() if (factory) { nsIDeviceContextSpec *devspec = nsnull; nsCOMPtr dx; - factory->CreateDeviceContextSpec(mWindow, devspec, doSilent); + factory->CreateDeviceContextSpec(mWindow, aPrintSettings, devspec, doSilent); if (nsnull != devspec) { nsresult rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); if (NS_SUCCEEDED(rv)) { mDeviceContext->SetAltDevice(ppDC); - if (printService) { + if (mPrt->mPrintSettings != nsnull) { double scaling; - printService->GetScaling(&scaling); + mPrt->mPrintSettings->GetScaling(&scaling); if (scaling < 1.0) { mDeviceContext->SetCanonicalPixelScale(float(scaling)); } @@ -4853,13 +4962,11 @@ DocumentViewerImpl::PrintPreview() } } - if (printService && doSilent) { - //printService->SetPrintRange(nsIPrintOptions::kFramesAsIs); - printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs); + if (doSilent) { + mPrt->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); } - mPrt->mPrintDC = mDeviceContext; // XXX why? - mPrt->mFilePointer = nsnull; + mPrt->mPrintDC = mDeviceContext; // XXX why? if (mDeviceContext) { mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_TRUE); @@ -4905,12 +5012,87 @@ DocumentViewerImpl::PrintPreview() return NS_OK; } + +void +DocumentViewerImpl::SetDocAndURLIntoProgress(nsIWebShell* aWebShell, + nsIPrintProgressParams* aParams) +{ + NS_ASSERTION(aWebShell, "Must have vaild nsIWebShell"); + NS_ASSERTION(aParams, "Must have vaild nsIPrintProgressParams"); + if (aWebShell == nsnull || aParams == nsnull) { + return; + } + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + GetWebShellTitleAndURL(aWebShell, &docTitleStr, &docURLStr); + mPrt->mPrintProgressParams->SetDocTitle((const PRUnichar*) docTitleStr); + mPrt->mPrintProgressParams->SetDocURL((const PRUnichar*) docURLStr); + if (docTitleStr != nsnull) nsMemory::Free(docTitleStr); + if (docURLStr != nsnull) nsMemory::Free(docURLStr); +} + +void +DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) +{ + nsPrintProgress* prtProgress = new nsPrintProgress(); + nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrt->mPrintProgress)); + if (NS_FAILED(rv)) return; + + + rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mPrt->mPrintProgressListener)); + if (NS_FAILED(rv)) return; + // add to listener list + mPrt->mPrintProgressListeners.AppendElement((void*)mPrt->mPrintProgressListener); + nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, mPrt->mPrintProgressListener.get()); + NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!"); + NS_ADDREF(wpl); + + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + if (prefs) { + prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog); + if (mPrt->mShowProgressDialog) { + nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams(); + nsCOMPtr params; + rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)getter_AddRefs(mPrt->mPrintProgressParams)); + if (NS_SUCCEEDED(rv) && mPrt->mPrintProgressParams) { + SetDocAndURLIntoProgress(mPrt->mPrintObject->mWebShell, mPrt->mPrintProgressParams); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + + nsCOMPtr parent(do_QueryInterface(active)); + mPrt->mPrintProgress->OpenProgressDialog(parent, "chrome://global/content/printProgress.xul", mPrt->mPrintProgressParams); + } + } + } + } +} + +#ifdef NS_DEBUG /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 01/24/00 dwc */ NS_IMETHODIMP -DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) +DocumentViewerImpl::Print(PRBool aSilent, + FILE * aDebugFile, + nsIPrintSettings* aPrintSettings) +{ + mDebugFile = aDebugFile; + return Print(aSilent, aPrintSettings, nsnull); +} +#endif + +/** --------------------------------------------------- + * See documentation above in the nsIContentViewerfile class definition + * @update 01/24/00 dwc + */ +NS_IMETHODIMP +DocumentViewerImpl::Print(PRBool aSilent, + nsIPrintSettings* aPrintSettings, + nsIWebProgressListener* aWebProgressListener) { #ifdef DEBUG_PRINTING // need for capturing result on each doc and sub-doc that is printed @@ -4931,19 +5113,39 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi return rv; } - // Let's print ... - mIsDoingPrinting = PR_TRUE; - mPrt = new PrintData(); if (mPrt == nsnull) { - mIsDoingPrinting = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } - if (aPrintListener) { - mPrt->mPrintListener = aPrintListener; - } + // if they don't pass in a PrintSettings, then make one + // it will have all the default values + mPrt->mPrintSettings = aPrintSettings; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + // if they don't pass in a PrintSettings, then make one + if (mPrt->mPrintSettings == nsnull) { + printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings)); + } + NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!"); + // Get the default printer name and set it into the PrintSettings + if (NS_FAILED(CheckForPrinters(printService, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE))) { + delete mPrt; + mPrt = nsnull; + return NS_ERROR_FAILURE; + } + } + mPrt->mPrintSettings->SetPrintSilent(aSilent); + + // Let's print ... + mIsDoingPrinting = PR_TRUE; + + if (aWebProgressListener != nsnull) { + mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener); + NS_ADDREF(aWebProgressListener); + } + // Get the currently focused window and cache it // because the Print Dialog will "steal" focus and later when you try // to get the currently focused windows it will be NULL @@ -4957,6 +5159,8 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrt->mPrintDocList = new nsVoidArray(); if (mPrt->mPrintDocList == nsnull) { mIsDoingPrinting = PR_FALSE; + delete mPrt; + mPrt = nsnull; return NS_ERROR_FAILURE; } } else { @@ -4990,30 +5194,26 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi DUMP_DOC_LIST("\nAfter Mapping------------------------------------------"); - // Setup print options for UI rv = NS_ERROR_FAILURE; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - if (mPrt->mIsParentAFrameSet) { - if (mPrt->mCurrentFocusWin) { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll); - } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach); - } + // Setup print options for UI + if (mPrt->mIsParentAFrameSet) { + if (mPrt->mCurrentFocusWin) { + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); } - // Now determine how to set up the Frame print UI - printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); + } else { + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); } + // Now determine how to set up the Frame print UI + mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); #ifdef DEBUG_PRINTING - if (printService) { - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + if (mPrt->mPrintSettings) { + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &val); + mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n"); PRINT_DEBUG_MSG2("IsParentAFrameSet: %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet)); @@ -5038,19 +5238,22 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi nsIDeviceContextSpec *devspec = nsnull; nsCOMPtr dx; mPrt->mPrintDC = nsnull; // XXX why? - mPrt->mFilePointer = aFile; - rv = factory->CreateDeviceContextSpec(mWindow, devspec, aSilent); +#ifdef NS_DEBUG + mPrt->mDebugFilePtr = mDebugFile; +#endif + + PRBool printSilently; + mPrt->mPrintSettings->GetPrintSilent(&printSilently); + rv = factory->CreateDeviceContextSpec(mWindow, mPrt->mPrintSettings, devspec, printSilently); if (NS_SUCCEEDED(rv)) { rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); if (NS_SUCCEEDED(rv)) rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); - if (printService) { - double scaling; - printService->GetScaling(&scaling); - if (scaling < 1.0) { - dx->SetCanonicalPixelScale(float(scaling)); - } + double scaling; + mPrt->mPrintSettings->GetScaling(&scaling); + if (scaling <= 1.0) { + dx->SetCanonicalPixelScale(float(scaling)); } if (NS_SUCCEEDED(rv)) { @@ -5062,9 +5265,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi PRInt32 i1,i2; printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrt->mPrintPS, mPrt->mPrintPC,mPrt->mPrintDC,mPrt->mPrintVM,mPrt->mPrintView); - + // DEVICE CONTEXT INFORMATION from PresContext printf("DeviceContext of Presentation Context(%x)\n",dx); dx->GetDevUnitsToTwips(a1); @@ -5106,13 +5307,74 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi #endif /* DEBUG_dcone */ - // if there is a frameset and we are printing silently then - // the default must be reset kFramesAsIs - if (printService && mPrt->mIsParentAFrameSet && aSilent) { - mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; - printService->SetPrintFrameType(mPrt->mPrintFrameType); + // Always check and set the print settings first and then fall back + // onto the PrintService if there isn't a PrintSettings + // + // Posiible Usage values: + // nsIPrintSettings::kUseInternalDefault + // nsIPrintSettings::kUseSettingWhenPossible + // + // NOTE: The consts are the same for PrintSettings and PrintSettings + PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; + mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); + + // Ok, see if we are going to use our value and override the default + if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { + // Get the Print Options/Settings PrintFrameType to see what is preferred + PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); + + // Don't let anybody do something stupid like try to set it to + // kNoFrames when we are printing a FrameSet + if (printFrameType == nsIPrintSettings::kNoFrames) { + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } else { + // First find out from the PrinService what options are available + // to us for Printing FrameSets + PRInt16 howToEnableFrameUI; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + switch (howToEnableFrameUI) { + case nsIPrintSettings::kFrameEnableAll: + mPrt->mPrintFrameType = printFrameType; + break; + + case nsIPrintSettings::kFrameEnableAsIsAndEach: + if (printFrameType != nsIPrintSettings::kSelectedFrame) { + mPrt->mPrintFrameType = printFrameType; + } else { // revert back to a good value + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + } + break; + } // switch + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } + } } + if (printService) { + // check to see if we are printing to a file + PRBool isPrintToFile = PR_FALSE; + mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); + if (isPrintToFile) { + // On some platforms The BeginDocument needs to know the name of the file + // and it uses the PrintService to get it, so we need to set it into the PrintService here + PRUnichar* fileName; + mPrt->mPrintSettings->GetToFileName(&fileName); + if (fileName != nsnull) { + printService->SetPrintToFile(PR_TRUE); + printService->SetToFileName(fileName); + nsMemory::Free(fileName); + } + } else { + printService->SetPrintToFile(PR_FALSE); + printService->SetToFileName(nsnull); + } + } + + DoPrintProgress(PR_TRUE); + // Print listener setup... if (mPrt != nsnull) { mPrt->OnStartPrinting(); @@ -5123,7 +5385,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi // notified that images must be loaded as a result of the // InitialReflow... // - if(!mIsPrinting || (aFile != 0)){ + if(!mIsPrinting || (mPrt->mDebugFilePtr != nsnull)) { rv = DocumentReadyForPrinting(); #ifdef DEBUG_dcone printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); @@ -5166,7 +5428,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi void -DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) +DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { nsresult rv; @@ -5186,12 +5448,12 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) *title = nsnull; nsAutoString stringName; - switch(printerror) + switch(aPrintError) { #define NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(nserr) case nserr: stringName = NS_LITERAL_STRING(#nserr); break; NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_CMD_FAILURE) - NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE) + NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_ACCESS_DENIED) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE) @@ -5200,6 +5462,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_FILE_IO_ERROR) + NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_PRINTPREVIEW) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_UNEXPECTED) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_OUT_OF_MEMORY) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_NOT_IMPLEMENTED) @@ -5209,9 +5472,14 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_FAILURE) #undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG } - + myStringBundle->GetStringFromName(stringName.get(), &msg); - myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), &title); + if (aIsPrinting) { + myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), &title); + } else { + myStringBundle->GetStringFromName(NS_LITERAL_STRING("printpreview_error_dialog_title").get(), &title); + } + if (!msg) return; @@ -6199,7 +6467,7 @@ DocumentViewerImpl::ProcessEvent(nsGUIEvent *aEvent, PRBool aIsInContentArea, ns /*=============== Timer Related Code ======================*/ nsresult DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPOect, PRUint32 aDelay) { @@ -6214,6 +6482,6 @@ DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, ++mDestroyRefCount; } - return mPagePrintTimer->Start(this, aPresContext, aPrintOptions, aPOect, aDelay); + return mPagePrintTimer->Start(this, aPresContext, aPrintSettings, aPOect, aDelay); } diff --git a/mozilla/dom/public/idl/base/nsIDOMWindowInternal.idl b/mozilla/dom/public/idl/base/nsIDOMWindowInternal.idl index 774f9d8907b..cdcdad0ab15 100644 --- a/mozilla/dom/public/idl/base/nsIDOMWindowInternal.idl +++ b/mozilla/dom/public/idl/base/nsIDOMWindowInternal.idl @@ -44,6 +44,7 @@ interface nsISidebar; interface nsIPrompt; interface nsIControllers; interface nsIDOMLocation; +interface nsIPrintSettings; [scriptable, uuid(9c911860-7dd9-11d4-9a83-000064657374)] @@ -130,8 +131,8 @@ interface nsIDOMWindowInternal : nsIDOMWindow void home(); void stop(); - void print(); - void printPreview(); + void print(in nsIPrintSettings aPrintSettings); + void printPreview(in nsIPrintSettings aPrintSettings); void moveTo(in long xPos, in long yPos); void moveBy(in long xDif, in long yDif); diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index e8cd994407a..c7a4df0e1c3 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -123,6 +123,7 @@ #include "nsISupportsPrimitives.h" #include "nsDOMClassInfo.h" #include "nsIJSNativeInitializer.h" +#include "nsIPrintSettings.h" #include "nsWindowRoot.h" @@ -1960,7 +1961,8 @@ NS_IMETHODIMP GlobalWindowImpl::Stop() return webNav->Stop(nsIWebNavigation::STOP_ALL); } -nsresult GlobalWindowImpl::DoPrint(PRBool aDoPreview) +nsresult GlobalWindowImpl::DoPrint(nsIPrintSettings* aPrintSettings, + PRBool aDoPreview) { if (mDocShell) { nsCOMPtr viewer; @@ -1969,9 +1971,9 @@ nsresult GlobalWindowImpl::DoPrint(PRBool aDoPreview) nsCOMPtr viewerFile(do_QueryInterface(viewer)); if (viewerFile) { if (aDoPreview) { - return viewerFile->PrintPreview(); + return viewerFile->PrintPreview(aPrintSettings); } else { - return viewerFile->Print(PR_FALSE, nsnull); + return viewerFile->Print(PR_FALSE, aPrintSettings, nsnull); } } } @@ -1979,14 +1981,14 @@ nsresult GlobalWindowImpl::DoPrint(PRBool aDoPreview) return NS_OK; } -NS_IMETHODIMP GlobalWindowImpl::Print() +NS_IMETHODIMP GlobalWindowImpl::Print(nsIPrintSettings* aPrintSettings) { - return DoPrint(PR_FALSE); + return DoPrint(aPrintSettings, PR_FALSE); } -NS_IMETHODIMP GlobalWindowImpl::PrintPreview() +NS_IMETHODIMP GlobalWindowImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { - return DoPrint(PR_TRUE); + return DoPrint(aPrintSettings, PR_TRUE); } NS_IMETHODIMP GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos) diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index f2878a95bcc..ff22d8a4d74 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -237,7 +237,7 @@ protected: nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height); nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top); - nsresult DoPrint(PRBool aDoPreview); + nsresult DoPrint(nsIPrintSettings* aPrintSettings, PRBool aDoPreview); // Helper for window.find() nsresult FindInternal(nsAReadableString& aStr, PRBool caseSensitive, diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 9e3a5e84bd6..ff5931b1705 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1803,7 +1803,7 @@ nsEditorShell::Print() { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - NS_ENSURE_SUCCESS(viewerFile->Print(PR_FALSE,nsnull), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull), NS_ERROR_FAILURE); } } return NS_OK; diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp index 2e6987b5381..105dd6989ef 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -56,7 +56,6 @@ #include "nsIWebBrowserPersist.h" #include "nsIClipboardCommands.h" #include "nsIProfile.h" -#include "nsIPrintListener.h" #include "nsIPrintOptions.h" #include "nsIWebBrowserPrint.h" #include "nsIWidget.h" @@ -96,12 +95,12 @@ static const TCHAR *c_szUninitialized = _T("Method called while control is unini #define RETURN_E_UNEXPECTED() \ RETURN_ERROR(c_szUninitialized, E_UNEXPECTED); -class PrintListener : public nsIPrintListener +class PrintListener : public nsIWebProgressListener { PRBool mComplete; public: NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTLISTENER + NS_DECL_NSIWEBPROGRESSLISTENER PrintListener(); virtual ~PrintListener(); @@ -1451,8 +1450,8 @@ HRESULT CMozillaBrowser::PrintDocument(BOOL promptUser) if (window) { PrintListener *listener = new PrintListener; - nsCOMPtr printListener = do_QueryInterface(listener); - browserAsPrint->Print(window, nsnull, printListener); + nsCOMPtr printListener = do_QueryInterface(listener); + browserAsPrint->Print(window, nsnull, nsnull); listener->WaitForComplete(); } @@ -3252,7 +3251,7 @@ HRESULT _stdcall CMozillaBrowser::EditCommandHandler(CMozillaBrowser *pThis, con // PrintListener implementation -NS_IMPL_ISUPPORTS1(PrintListener, nsIPrintListener) +NS_IMPL_ISUPPORTS1(PrintListener, nsIWebProgressListener) PrintListener::PrintListener() : mComplete(PR_FALSE) { @@ -3300,21 +3299,35 @@ void PrintListener::WaitForComplete() ::CloseHandle(hFakeEvent); } -/* void OnStartPrinting (); */ -NS_IMETHODIMP PrintListener::OnStartPrinting() -{ - return NS_OK; -} - -/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ -NS_IMETHODIMP PrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) -{ - return NS_OK; -} - -/* void OnEndPrinting (in PRUint32 aStatus); */ -NS_IMETHODIMP PrintListener::OnEndPrinting(PRUint32 aStatus) +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +NS_IMETHODIMP PrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus) { + if (aStatus == nsIWebProgressListener::STATE_STOP) { mComplete = PR_TRUE; - return NS_OK; + } + return NS_OK; +} + +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ +NS_IMETHODIMP PrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP PrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP PrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP PrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/embedding/browser/photon/src/EmbedPrintListener.cpp b/mozilla/embedding/browser/photon/src/EmbedPrintListener.cpp index 17a6ca57a3d..8cef35d113d 100644 --- a/mozilla/embedding/browser/photon/src/EmbedPrintListener.cpp +++ b/mozilla/embedding/browser/photon/src/EmbedPrintListener.cpp @@ -40,7 +40,7 @@ EmbedPrintListener::~EmbedPrintListener() { } -NS_IMPL_ISUPPORTS1(EmbedPrintListener, nsIPrintListener) +NS_IMPL_ISUPPORTS1(EmbedPrintListener, nsIWebProgressListener) nsresult EmbedPrintListener::Init(EmbedPrivate *aOwner) @@ -72,26 +72,39 @@ EmbedPrintListener::InvokePrintCallback(int status, unsigned int cur, unsigned i PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo); } -/* void OnStartPrinting (); */ -NS_IMETHODIMP -EmbedPrintListener::OnStartPrinting() +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +NS_IMETHODIMP EmbedPrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus) { - InvokePrintCallback(Pt_MOZ_PRINT_START, 0, 0); - return NS_OK; + if (aStatus == nsIWebProgressListener::STATE_START) { + InvokePrintCallback(Pt_MOZ_PRINT_START, 0, 0); + + } else if (aStatus == nsIWebProgressListener::STATE_STOP) { + InvokePrintCallback(Pt_MOZ_PRINT_COMPLETE, 0, 0); + } + return NS_OK; } -/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ -NS_IMETHODIMP -EmbedPrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ +NS_IMETHODIMP EmbedPrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { - InvokePrintCallback(Pt_MOZ_PRINT_PROGRESS, aProgress, aProgressMax); - return NS_OK; + InvokePrintCallback(Pt_MOZ_PRINT_PROGRESS, aCurTotalProgress, aMaxTotalProgress); + return NS_OK; } -/* void OnEndPrinting (in PRUint32 aStatus); */ -NS_IMETHODIMP -EmbedPrintListener::OnEndPrinting(PRUint32 aStatus) +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP EmbedPrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) { - InvokePrintCallback(Pt_MOZ_PRINT_COMPLETE, 0, 0); - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP EmbedPrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP EmbedPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/embedding/browser/photon/src/EmbedPrintListener.h b/mozilla/embedding/browser/photon/src/EmbedPrintListener.h index aa105cb166d..d3ecfa1439d 100644 --- a/mozilla/embedding/browser/photon/src/EmbedPrintListener.h +++ b/mozilla/embedding/browser/photon/src/EmbedPrintListener.h @@ -23,11 +23,11 @@ #ifndef __EmbedPrintListener_h #define __EmbedPrintListener_h -#include +#include class EmbedPrivate; -class EmbedPrintListener : public nsIPrintListener +class EmbedPrintListener : public nsIWebProgressListener { public: @@ -40,7 +40,7 @@ class EmbedPrintListener : public nsIPrintListener NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTLISTENER + NS_DECL_NSIWEBPROGRESSLISTENER private: diff --git a/mozilla/embedding/browser/photon/src/EmbedPrivate.cpp b/mozilla/embedding/browser/photon/src/EmbedPrivate.cpp index bf7cb48e529..46648efa23d 100644 --- a/mozilla/embedding/browser/photon/src/EmbedPrivate.cpp +++ b/mozilla/embedding/browser/photon/src/EmbedPrivate.cpp @@ -156,7 +156,7 @@ EmbedPrivate::Init(PtWidget_t *aOwningWidget) // and initialize it. It is assumed that this print listener // will be destroyed when we go out of scope. mPrint = new EmbedPrintListener(); - mPrintGuard = NS_STATIC_CAST(nsIPrintListener *, mPrint); + mPrintGuard = NS_STATIC_CAST(nsIWebProgressListener *, mPrint); mPrint->Init(this); m_PrintSettings = (nsIPrintSettings*)new nsPrintSettings(); diff --git a/mozilla/embedding/browser/photon/src/PtMozilla.cpp b/mozilla/embedding/browser/photon/src/PtMozilla.cpp index cf52fda7baf..5228ddfed2a 100644 --- a/mozilla/embedding/browser/photon/src/PtMozilla.cpp +++ b/mozilla/embedding/browser/photon/src/PtMozilla.cpp @@ -25,7 +25,6 @@ #include "nsCWebBrowser.h" #include "nsFileSpec.h" #include "nsILocalFile.h" -#include "nsIContentViewerFile.h" #include "nsISelectionController.h" #include "nsEmbedAPI.h" diff --git a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl index eb2bebec5d1..5c061ae29c1 100644 --- a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl +++ b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl @@ -24,8 +24,7 @@ interface nsIDOMWindow; interface nsIPrintSettings; -interface nsIPrintListener; - +interface nsIWebProgressListener; /** * The nsIWebBrowserPrint @@ -33,6 +32,22 @@ interface nsIPrintListener; [scriptable, uuid(9A7CA4B0-FBBA-11d4-A869-00105A183419)] interface nsIWebBrowserPrint : nsISupports { + /** + * Returns a PrintSettings object + * Creates a new the first time, if one doesn't exist. + * then returns the same object each time after that + * unless a different object was set into it. + */ + attribute nsIPrintSettings printSettings; + + /** + * This returns the current settings that was last used for printing + * or page setup. For peinring, the print engine always sets the PrintSettings + * from whoever is printing into the global settings + * for page setup it is the responsibilitity of those implementing page setup + * to set their setting into the global settings + */ + attribute nsIPrintSettings globalPrintSettings; /** * Print the specified DOM window @@ -40,9 +55,9 @@ interface nsIWebBrowserPrint : nsISupports * aDOMWindow - The DOM window to print * aThePrintOptions - Printer Settings for the print job */ - void Print(in nsIDOMWindow aDOMWindow, - in nsIPrintSettings aThePrintSettings, - in nsIPrintListener aPrintListsner); + void print(in nsIDOMWindow aDOMWindow, + in nsIPrintSettings aThePrintSettings, + in nsIWebProgressListener aWPListener); /** * Print Preview the specified DOM window @@ -50,10 +65,9 @@ interface nsIWebBrowserPrint : nsISupports * aDOMWindow - The DOM window to print preview * aThePrintOptions - Printer Settings for the print preview */ - void PrintPreview(in nsIDOMWindow aDOMWindow, + void printPreview(in nsIDOMWindow aDOMWindow, in nsIPrintSettings aThePrintSettings); - void Cancel(); - + void cancel(); }; diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index 9e1b2fa7564..28afbb1014d 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -62,6 +62,7 @@ // Printing Includes #include "nsIContentViewer.h" #include "nsIContentViewerFile.h" + // Print Options #include "nsIPrintOptions.h" #include "nsGfxCIID.h" @@ -1757,19 +1758,27 @@ NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) /* helper function */ nsresult nsWebBrowser::DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, nsIPrintSettings *aThePrintSettings, - nsIPrintListener *aPrintListener, + nsIWebProgressListener *aProgressListener, PRBool aDoPrinting) { - nsresult rv = NS_OK; - PRBool silent = PR_FALSE; - if( aThePrintSettings != nsnull) { - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->SetPrintSettings(aThePrintSettings); + // this is if we want to have the ability to switch between having + // each window have their own PrintSettings, or having them all share it. +#ifdef ENABLE_GLOBAL_PRINTSETTINGS + PRBool useGlobalPrintSettings = PR_FALSE; + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + if (pref) { + pref->GetBoolPref(&useGlobalPrintSettings); + if (useGlobalPrintSettings && aThePrintSettings != nsnull) { + printService->GetPrintSettingsValues("print.use_global_printsettings", aThePrintSettings); + } } - aThePrintSettings->GetPrintSilent(&silent); } +#endif + nsresult rv = NS_ERROR_FAILURE; // XXX this next line may need to be changed // it is unclear what the correct way is to get the document. nsCOMPtr thisDOMWin; @@ -1781,13 +1790,20 @@ nsresult nsWebBrowser::DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, nsCOMPtr contentViewerFile(do_QueryInterface(contentViewer)); if (contentViewerFile) { if (aDoPrinting) { - rv = contentViewerFile->Print(silent, nsnull, aPrintListener); + rv = contentViewerFile->Print(PR_FALSE, aThePrintSettings, aProgressListener); } else { - rv = contentViewerFile->PrintPreview(); + rv = contentViewerFile->PrintPreview(aThePrintSettings); } } } } + +#ifdef ENABLE_GLOBAL_PRINTSETTINGS + if (useGlobalPrintSettings && aThePrintSettings != nsnull && printService) { + printService->SetPrintSettingsValues(aThePrintSettings); + } +#endif + return rv; } @@ -1798,9 +1814,9 @@ nsresult nsWebBrowser::DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, /* void Print (in nsIDOMWindow aDOMWindow, in nsIPrintSettings aThePrintSettings); */ NS_IMETHODIMP nsWebBrowser::Print(nsIDOMWindow *aDOMWindow, nsIPrintSettings *aThePrintSettings, - nsIPrintListener *aPrintListener) + nsIWebProgressListener * aProgressListener) { - return DoPrintOrPrintPreview(aDOMWindow, aThePrintSettings, aPrintListener, PR_TRUE); + return DoPrintOrPrintPreview(aDOMWindow, aThePrintSettings, aProgressListener, PR_TRUE); } /* void PrintPreview (in nsIPrintSettings aThePrintSettings); */ @@ -1821,3 +1837,61 @@ NS_IMETHODIMP nsWebBrowser::Cancel(void) } return NS_OK; } + +/* attribute nsIPrintSettings printSettings; */ +/** + * Creates a PrintSettings Object to be used for Printing + */ +NS_IMETHODIMP nsWebBrowser::GetPrintSettings(nsIPrintSettings * *aPrintSettings) +{ + nsresult rv = NS_OK; + if (!mPrintSettings) { + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + printService->CreatePrintSettings(getter_AddRefs(mPrintSettings)); + } + } + *aPrintSettings = mPrintSettings; + NS_IF_ADDREF(*aPrintSettings); + return rv; +} + +NS_IMETHODIMP nsWebBrowser::SetPrintSettings(nsIPrintSettings * aPrintSettings) +{ + mPrintSettings = aPrintSettings; + return NS_OK; +} + + +/* attribute nsIPrintSettings globalPrintSettings; */ +/** + * gets/set the PS into the the PrintOptions + */ +NS_IMETHODIMP nsWebBrowser::GetGlobalPrintSettings(nsIPrintSettings * *aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + NS_ENSURE_ARG_POINTER(*aPrintSettings); + + nsresult rv = NS_OK; + if (aPrintSettings != nsnull && *aPrintSettings != nsnull) { + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + printService->GetPrintSettingsValues(aPrintSettings); + } + } + *aPrintSettings = mPrintSettings; + NS_IF_ADDREF(*aPrintSettings); + return rv; +} + +NS_IMETHODIMP nsWebBrowser::SetGlobalPrintSettings(nsIPrintSettings * aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + nsresult rv = NS_OK; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + printService->SetPrintSettingsValues(aPrintSettings); + } + return NS_OK; +} + diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h index 9704d4879d4..0acf81a21d0 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h @@ -49,6 +49,7 @@ #include "nsIWebBrowserFocus.h" #include "nsIWebBrowserPrint.h" #include "nsIWindowWatcher.h" +#include "nsIPrintSettings.h" #include "nsVoidArray.h" #include "nsWeakPtr.h" @@ -126,7 +127,7 @@ protected: // helper function for Printing and Print Preview nsresult DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, nsIPrintSettings *aThePrintSettings, - nsIPrintListener *aPrintListener, + nsIWebProgressListener* aPrgressListener, PRBool aDoPrinting); static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent); @@ -149,6 +150,8 @@ protected: nsCOMPtr mWebProgress; nsCOMPtr mSecurityUI; + nsCOMPtr mPrintSettings; + // cached background color nscolor mBackgroundColor; diff --git a/mozilla/embedding/components/windowwatcher/src/nsPromptService.h b/mozilla/embedding/components/windowwatcher/src/nsPromptService.h index caa0c5701ac..ed9876632a9 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsPromptService.h +++ b/mozilla/embedding/components/windowwatcher/src/nsPromptService.h @@ -52,6 +52,7 @@ class nsIDOMWindow; class nsIDialogParamBlock; +class nsIPrintSettings; class nsPromptService: public nsIPromptService, public nsPIPromptService { @@ -70,7 +71,6 @@ public: private: nsresult GetLocaleString(const char *aKey, PRUnichar **aResult); - nsCOMPtr mWatcher; }; diff --git a/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp b/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp index 89d82042036..36bc1f765f8 100644 --- a/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp +++ b/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp @@ -7,6 +7,7 @@ #include "BrowserView.h" #include "nsIWebBrowser.h" #include "nsIWebBrowserPrint.h" +#include "nsIWebProgressListener.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -17,14 +18,15 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog -class CDlgPrintListener : public nsIPrintListener +class CDlgPrintListener : public nsIWebProgressListener { // Construction public: CDlgPrintListener(CPrintProgressDialog* aDlg); NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTLISTENER + NS_DECL_NSIWEBPROGRESSLISTENER + void ClearDlg() { m_PrintDlg = NULL; } // weak reference @@ -37,8 +39,8 @@ NS_IMPL_ADDREF(CDlgPrintListener) NS_IMPL_RELEASE(CDlgPrintListener) NS_INTERFACE_MAP_BEGIN(CDlgPrintListener) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintListener) - NS_INTERFACE_MAP_ENTRY(nsIPrintListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebProgressListener) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_END @@ -49,34 +51,50 @@ CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog* aDlg) : //NS_ADDREF_THIS(); } -/* void OnStartPrinting (); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP -CDlgPrintListener::OnStartPrinting() +CDlgPrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus) { if (m_PrintDlg) { - return m_PrintDlg->OnStartPrinting(); + if (aStatus == nsIWebProgressListener::STATE_START) { + return m_PrintDlg->OnStartPrinting(); + + } else if (aStatus == nsIWebProgressListener::STATE_STOP) { + return m_PrintDlg->OnEndPrinting(aStatus); + } } return NS_OK; } -/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ NS_IMETHODIMP -CDlgPrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +CDlgPrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { if (m_PrintDlg) { - return m_PrintDlg->OnProgressPrinting(aProgress, aProgressMax); + return m_PrintDlg->OnProgressPrinting(aCurSelfProgress, aMaxSelfProgress); } return NS_OK; } -/* void OnEndPrinting (in PRUint32 aStatus); */ +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ NS_IMETHODIMP -CDlgPrintListener::OnEndPrinting(PRUint32 aStatus) +CDlgPrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) { - if (m_PrintDlg) { - return m_PrintDlg->OnEndPrinting(aStatus); - } - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP +CDlgPrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP +CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; } ///////////////////////////////////////////////////////////////////////////// @@ -178,7 +196,7 @@ int CPrintProgressDialog::DoModal( ) m_PrintListener = new CDlgPrintListener(this); // constructor addrefs if (m_PrintListener) { // doModal will be set to false if the print job was cancelled - doModal = NS_SUCCEEDED(print->Print(m_DOMWin, nsnull, m_PrintListener)) == PR_TRUE; + doModal = NS_SUCCEEDED(print->Print(m_DOMWin, nsnull, nsnull)) == PR_TRUE; } } @@ -190,46 +208,6 @@ int CPrintProgressDialog::DoModal( ) } -/* void OnStartPrinting (); */ -NS_IMETHODIMP -CPrintProgressDialog::OnStartPrinting() -{ - return NS_OK; -} - -/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ -NS_IMETHODIMP -CPrintProgressDialog::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) -{ - // Initialize the progress meter we we get the "zero" progress - // which also tells us the max progress - if (aProgress == 0) { - CWnd *pWnd = GetDlgItem(IDC_PPD_DOC_TXT); - if(pWnd) - pWnd->SetWindowText(m_URL); - - m_wndProgress.SetRange(0, aProgressMax); - m_wndProgress.SetPos(0); - } - m_wndProgress.SetPos(aProgress); - RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); - - return NS_OK; -} - -/* void OnEndPrinting (in PRUint32 aStatus); */ -NS_IMETHODIMP -CPrintProgressDialog::OnEndPrinting(PRUint32 aStatus) -{ - // Here we need to know whether we have gone "modal" - // because we could get notified here if the user cancels - // before we ever get a chance to go into the modal loop - if (m_InModalMode) { - EndDialog(1); - } - return NS_OK; -} - void CPrintProgressDialog::OnCancel() { nsCOMPtr print(do_GetInterface(m_WebBrowser)); diff --git a/mozilla/embedding/qa/testembed/PrintProgressDialog.h b/mozilla/embedding/qa/testembed/PrintProgressDialog.h index e5f081d03d8..129ca952587 100644 --- a/mozilla/embedding/qa/testembed/PrintProgressDialog.h +++ b/mozilla/embedding/qa/testembed/PrintProgressDialog.h @@ -7,10 +7,8 @@ // PrintProgressDialog.h : header file // -#include "nsIPrintListener.h" class nsIWebBrowser; class nsIDOMWindow; -class nsIPrintListener; ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog @@ -28,10 +26,6 @@ public: // Helper void SetURI(const char* aTitle); - // same as nsIPrintListener - NS_IMETHOD OnStartPrinting(void); - NS_IMETHOD OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); - NS_IMETHOD OnEndPrinting(PRUint32 aStatus); // Dialog Data //{{AFX_DATA(CPrintProgressDialog) @@ -53,7 +47,7 @@ protected: CString m_URL; nsIWebBrowser* m_WebBrowser; nsIDOMWindow* m_DOMWin; - nsCOMPtr m_PrintListener; + nsCOMPtr m_PrintListener; BOOL m_InModalMode; // Generated message map functions diff --git a/mozilla/embedding/tests/mfcembed/BrowserView.cpp b/mozilla/embedding/tests/mfcembed/BrowserView.cpp index 9a5a71f4298..06a981a424e 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserView.cpp +++ b/mozilla/embedding/tests/mfcembed/BrowserView.cpp @@ -70,7 +70,6 @@ // Print Includes #include "PrintProgressDialog.h" -#include "nsPrintSettingsImpl.h" #include "PrintSetupDialog.h" // Mozilla Includes @@ -155,7 +154,6 @@ CBrowserView::CBrowserView() m_SecurityState = SECURITY_STATE_INSECURE; - m_PrintSettings = (nsIPrintSettings*)new nsPrintSettings(); } CBrowserView::~CBrowserView() @@ -269,6 +267,11 @@ HRESULT CBrowserView::CreateBrowser() // Finally, show the web browser window mBaseWindow->SetVisibility(PR_TRUE); + nsCOMPtr print(do_GetInterface(mWebBrowser)); + if (print) { + print->GetPrintSettings(getter_AddRefs(m_PrintSettings)); + } + return S_OK; } @@ -980,6 +983,16 @@ LRESULT CBrowserView::OnFindMsg(WPARAM wParam, LPARAM lParam) void CBrowserView::OnFilePrint() { + nsresult rv; + nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) + { + prefs->SetBoolPref("print.use_native_print_dialog", PR_TRUE); + prefs->SetBoolPref("print.show_print_progress", PR_FALSE); + } + else + NS_ASSERTION(PR_FALSE, "Could not get preferences service"); + nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); if(domWindow) { @@ -1027,6 +1040,13 @@ static float GetFloatFromStr(const char* aStr, float aMaxVal = 1.0) } } +static PRUnichar* GetUnicodeFromCString(const CString& aStr) +{ + nsString str; + str.AssignWithConversion(LPCSTR(aStr)); + return ToNewUnicode(str); +} + void CBrowserView::OnFilePrintSetup() { CPrintSetupDialog dlg(m_PrintSettings); @@ -1039,6 +1059,40 @@ void CBrowserView::OnFilePrintSetup() m_PrintSettings->SetScaling(double(dlg.m_Scaling) / 100.0); m_PrintSettings->SetPrintBGColors(dlg.m_PrintBGColors); m_PrintSettings->SetPrintBGColors(dlg.m_PrintBGImages); + + short type; + double width; + double height; + dlg.GetPaperSizeInfo(type, width, height); + m_PrintSettings->SetPaperSizeType(type); + m_PrintSettings->SetPaperWidth(width); + m_PrintSettings->SetPaperHeight(height); + + PRUnichar* uStr; + uStr = GetUnicodeFromCString(dlg.m_HeaderLeft); + m_PrintSettings->SetHeaderStrLeft(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + + uStr = GetUnicodeFromCString(dlg.m_HeaderMiddle); + m_PrintSettings->SetHeaderStrCenter(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + + uStr = GetUnicodeFromCString(dlg.m_HeaderRight); + m_PrintSettings->SetHeaderStrRight(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + + uStr = GetUnicodeFromCString(dlg.m_FooterLeft); + m_PrintSettings->SetFooterStrLeft(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + + uStr = GetUnicodeFromCString(dlg.m_FooterMiddle); + m_PrintSettings->SetFooterStrCenter(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + + uStr = GetUnicodeFromCString(dlg.m_FooterRight); + m_PrintSettings->SetFooterStrRight(uStr); + if (uStr != nsnull) nsMemory::Free(uStr); + } } diff --git a/mozilla/embedding/tests/mfcembed/BrowserView.h b/mozilla/embedding/tests/mfcembed/BrowserView.h index e8cd91a1ef5..01eac69dfcc 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserView.h +++ b/mozilla/embedding/tests/mfcembed/BrowserView.h @@ -49,6 +49,7 @@ #endif #include "IBrowserFrameGlue.h" +#include "nsIPrintSettings.h" ///////////////////////////////////////////////////////////////////////////// // CBrowserView window @@ -57,7 +58,6 @@ class CBrowserFrame; class CBrowserImpl; class CFindDialog; class CPrintProgressDialog; -class nsIPrintSettings; class CBrowserView : public CWnd { @@ -146,7 +146,7 @@ public: // Generated message map functions protected: - nsIPrintSettings* m_PrintSettings; + nsCOMPtr m_PrintSettings; //{{AFX_MSG(CBrowserView) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); diff --git a/mozilla/embedding/tests/mfcembed/MfcEmbed.rc b/mozilla/embedding/tests/mfcembed/MfcEmbed.rc index 829d4fabd84..112c460c324 100644 --- a/mozilla/embedding/tests/mfcembed/MfcEmbed.rc +++ b/mozilla/embedding/tests/mfcembed/MfcEmbed.rc @@ -351,30 +351,58 @@ BEGIN EDITTEXT IDC_EDIT_HOMEPAGE,53,95,211,14,ES_AUTOHSCROLL END -IDD_PRINTSETUP_DIALOG DIALOG DISCARDABLE 0, 0, 205, 141 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_PRINTSETUP_DIALOG DIALOG DISCARDABLE 0, 0, 328, 183 +STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Page Setup" FONT 8, "MS Sans Serif" BEGIN - DEFPUSHBUTTON "OK",IDOK,7,120,50,14 - PUSHBUTTON "Cancel",IDCANCEL,108,120,50,14 - GROUPBOX "Margins",IDC_STATIC,7,8,147,44 - LTEXT "Left:",IDC_STATIC,89,22,15,8 - EDITTEXT IDC_LEFT_MARGIN_TXT,105,18,40,14,ES_AUTOHSCROLL - LTEXT "Top:",IDC_STATIC,22,22,16,8 - EDITTEXT IDC_TOP_MARGIN_TXT,39,19,40,14,ES_AUTOHSCROLL - LTEXT "Right:",IDC_STATIC,85,38,20,8 - EDITTEXT IDC_BOTTOM_MARGIN_TXT,39,35,40,14,ES_AUTOHSCROLL - LTEXT "Bottom:",IDC_STATIC,13,37,25,8 - EDITTEXT IDC_RIGHT_MARGIN_TXT,106,35,40,14,ES_AUTOHSCROLL - CONTROL "Print Background C&olors",IDC_PRT_BGCOLORS,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,93,92,10 + COMBOBOX IDC_PAPER_SIZE_CBX,26,16,81,67,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + EDITTEXT IDC_UD_PAPER_WDTH,33,33,40,14,ES_AUTOHSCROLL | + WS_DISABLED + EDITTEXT IDC_UD_PAPER_HGT,106,33,40,14,ES_AUTOHSCROLL | + WS_DISABLED + CONTROL "Inches",IDC_INCHES_RD,"Button",BS_AUTORADIOBUTTON | + WS_DISABLED | WS_GROUP,13,52,37,10 + CONTROL "Millimeters",IDC_MILLI_RD,"Button",BS_AUTORADIOBUTTON | + WS_DISABLED,53,52,48,10 CONTROL "Slider1",IDC_SCALE,"msctls_trackbar32",TBS_AUTOTICKS | - TBS_BOTH | WS_TABSTOP,9,65,100,19 - EDITTEXT IDC_SCALE_TXT,110,71,19,14,ES_AUTOHSCROLL - GROUPBOX "Scaling",IDC_STATIC,7,54,148,34 + TBS_BOTH | WS_TABSTOP,9,81,100,19 + EDITTEXT IDC_SCALE_TXT,110,86,19,14,ES_AUTOHSCROLL + CONTROL "Print Background C&olors",IDC_PRT_BGCOLORS,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,8,107,92,10 CONTROL "Print Background &Images",IDC_PRT_BGIMAGES,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,106,95,10 + BS_AUTOCHECKBOX | WS_TABSTOP,8,118,95,10 + EDITTEXT IDC_TOP_MARGIN_TXT,39,140,40,14,ES_AUTOHSCROLL + EDITTEXT IDC_LEFT_MARGIN_TXT,112,140,40,14,ES_AUTOHSCROLL + EDITTEXT IDC_BOTTOM_MARGIN_TXT,185,140,40,14,ES_AUTOHSCROLL + EDITTEXT IDC_RIGHT_MARGIN_TXT,258,140,40,14,ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,7,162,50,14 + PUSHBUTTON "Cancel",IDCANCEL,271,162,50,14 + GROUPBOX "Margins",IDC_STATIC,7,132,302,26 + LTEXT "Left:",IDC_STATIC,95,142,15,8 + LTEXT "Top:",IDC_STATIC,22,142,16,8 + LTEXT "Right:",IDC_STATIC,236,143,20,8 + LTEXT "Bottom:",IDC_STATIC,158,142,25,8 + GROUPBOX "Scaling",IDC_STATIC,7,70,148,34 + LTEXT "Size:",IDC_STATIC,10,17,16,8 + GROUPBOX "Paper Size",IDC_STATIC,7,7,147,57 + LTEXT "Width:",IDC_UD_WIDTH_LBL,10,36,22,8,WS_DISABLED + LTEXT "Height:",IDC_UD_HEIGHT_LBL,81,36,24,8,WS_DISABLED + GROUPBOX "Header",IDC_STATIC,161,7,147,60 + LTEXT "Left:",IDC_STATIC,172,19,15,8 + EDITTEXT IDC_HDR_LEFT_TXT,187,17,117,14,ES_AUTOHSCROLL + LTEXT "Middle:",IDC_STATIC,163,36,24,8 + EDITTEXT IDC_HDR_MID_TXT,187,33,117,14,ES_AUTOHSCROLL + LTEXT "Right:",IDC_STATIC,167,51,20,8 + EDITTEXT IDC_HDR_RIGHT_TXT,187,49,117,14,ES_AUTOHSCROLL + GROUPBOX "Footer",IDC_STATIC,161,69,147,60 + LTEXT "Left:",IDC_STATIC,172,81,15,8 + EDITTEXT IDC_FTR_LEFT_TXT,187,79,117,14,ES_AUTOHSCROLL + LTEXT "Middle:",IDC_STATIC,163,97,24,8 + EDITTEXT IDC_FTR_MID_TXT,187,95,117,14,ES_AUTOHSCROLL + LTEXT "Right:",IDC_STATIC,167,113,20,8 + EDITTEXT IDC_FTR_RIGHT_TXT,187,111,117,14,ES_AUTOHSCROLL END @@ -472,9 +500,9 @@ BEGIN IDD_PRINTSETUP_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 198 + RIGHTMARGIN, 321 TOPMARGIN, 7 - BOTTOMMARGIN, 134 + BOTTOMMARGIN, 176 END END #endif // APSTUDIO_INVOKED diff --git a/mozilla/embedding/tests/mfcembed/PrintProgressDialog.cpp b/mozilla/embedding/tests/mfcembed/PrintProgressDialog.cpp index 16061eed074..5c830be0fc3 100644 --- a/mozilla/embedding/tests/mfcembed/PrintProgressDialog.cpp +++ b/mozilla/embedding/tests/mfcembed/PrintProgressDialog.cpp @@ -17,14 +17,14 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog -class CDlgPrintListener : public nsIPrintListener +class CDlgPrintListener : public nsIWebProgressListener { // Construction public: CDlgPrintListener(CPrintProgressDialog* aDlg); NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTLISTENER + NS_DECL_NSIWEBPROGRESSLISTENER void ClearDlg() { m_PrintDlg = NULL; } // weak reference @@ -37,8 +37,8 @@ NS_IMPL_ADDREF(CDlgPrintListener) NS_IMPL_RELEASE(CDlgPrintListener) NS_INTERFACE_MAP_BEGIN(CDlgPrintListener) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintListener) - NS_INTERFACE_MAP_ENTRY(nsIPrintListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebProgressListener) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_END @@ -49,36 +49,53 @@ CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog* aDlg) : //NS_ADDREF_THIS(); } -/* void OnStartPrinting (); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP -CDlgPrintListener::OnStartPrinting() +CDlgPrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus) { if (m_PrintDlg) { - return m_PrintDlg->OnStartPrinting(); + if (aStateFlags == (nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT)) { + return m_PrintDlg->OnStartPrinting(); + + } else if (aStateFlags == (nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT)) { + return m_PrintDlg->OnEndPrinting(aStatus); + } } return NS_OK; } -/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ NS_IMETHODIMP -CDlgPrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +CDlgPrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { if (m_PrintDlg) { - return m_PrintDlg->OnProgressPrinting(aProgress, aProgressMax); + return m_PrintDlg->OnProgressPrinting(aCurSelfProgress, aMaxSelfProgress); } return NS_OK; } -/* void OnEndPrinting (in PRUint32 aStatus); */ +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ NS_IMETHODIMP -CDlgPrintListener::OnEndPrinting(PRUint32 aStatus) +CDlgPrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) { - if (m_PrintDlg) { - return m_PrintDlg->OnEndPrinting(aStatus); - } - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP +CDlgPrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP +CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog @@ -180,7 +197,8 @@ int CPrintProgressDialog::DoModal( ) m_PrintListener = new CDlgPrintListener(this); // constructor addrefs if (m_PrintListener) { // doModal will be set to false if the print job was cancelled - doModal = NS_SUCCEEDED(print->Print(m_DOMWin, m_PrintSettings, m_PrintListener)) == PR_TRUE; + nsIWebProgressListener * wpl = NS_STATIC_CAST(nsIWebProgressListener*, m_PrintListener); + doModal = NS_SUCCEEDED(print->Print(m_DOMWin, m_PrintSettings, wpl)) == PR_TRUE; } } @@ -203,6 +221,8 @@ CPrintProgressDialog::OnStartPrinting() NS_IMETHODIMP CPrintProgressDialog::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) { + if (m_wndProgress.m_hWnd == NULL) return NS_OK; + // Initialize the progress meter we we get the "zero" progress // which also tells us the max progress if (aProgress == 0) { diff --git a/mozilla/embedding/tests/mfcembed/PrintProgressDialog.h b/mozilla/embedding/tests/mfcembed/PrintProgressDialog.h index 8671a3a1f0f..52e4ed409e4 100644 --- a/mozilla/embedding/tests/mfcembed/PrintProgressDialog.h +++ b/mozilla/embedding/tests/mfcembed/PrintProgressDialog.h @@ -7,10 +7,9 @@ // PrintProgressDialog.h : header file // -#include "nsIPrintListener.h" +#include "nsIWebProgressListener.h" class nsIWebBrowser; class nsIDOMWindow; -class nsIPrintListener; ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog @@ -29,7 +28,6 @@ public: // Helper void SetURI(const char* aTitle); - // same as nsIPrintListener NS_IMETHOD OnStartPrinting(void); NS_IMETHOD OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); NS_IMETHOD OnEndPrinting(PRUint32 aStatus); @@ -54,7 +52,7 @@ protected: CString m_URL; nsIWebBrowser* m_WebBrowser; nsIDOMWindow* m_DOMWin; - nsCOMPtr m_PrintListener; + nsCOMPtr m_PrintListener; nsIPrintSettings* m_PrintSettings; BOOL m_InModalMode; diff --git a/mozilla/embedding/tests/mfcembed/PrintSetupDialog.cpp b/mozilla/embedding/tests/mfcembed/PrintSetupDialog.cpp index 3a05325d1de..4deb399124c 100644 --- a/mozilla/embedding/tests/mfcembed/PrintSetupDialog.cpp +++ b/mozilla/embedding/tests/mfcembed/PrintSetupDialog.cpp @@ -11,7 +11,22 @@ static char THIS_FILE[] = __FILE__; #endif -#include "nsPrintSettingsImpl.h" +typedef struct { + char* mDesc; + short mUnit; + double mWidth; + double mHeight; + BOOL mIsUserDefined; +} PaperSizes; + +static const PaperSizes gPaperSize[] = { + {"Letter (8.5 x 11.0)", nsIPrintSettings::kPaperSizeInches, 8.5, 11.0, FALSE}, + {"Legal (8.5 x 14.0)", nsIPrintSettings::kPaperSizeInches, 8.5, 14.0, FALSE}, + {"A4 (210 x 297mm)", nsIPrintSettings::kPaperSizeMillimeters, 210.0, 297.0, FALSE}, + {"User Defined", nsIPrintSettings::kPaperSizeInches, 8.5, 11.0, TRUE} +}; +static const int gNumPaperSizes = 4; + ///////////////////////////////////////////////////////////////////////////// // CPrintSetupDialog dialog @@ -19,7 +34,8 @@ static char THIS_FILE[] = __FILE__; CPrintSetupDialog::CPrintSetupDialog(nsIPrintSettings* aPrintSettings, CWnd* pParent /*=NULL*/) : CDialog(CPrintSetupDialog::IDD, pParent), - m_PrintSettings(aPrintSettings) + m_PrintSettings(aPrintSettings), + m_PaperSizeInx(0) { //{{AFX_DATA_INIT(CPrintSetupDialog) m_BottomMargin = _T(""); @@ -29,6 +45,16 @@ CPrintSetupDialog::CPrintSetupDialog(nsIPrintSettings* aPrintSettings, CWnd* pPa m_Scaling = 0; m_PrintBGImages = FALSE; m_PrintBGColors = FALSE; + m_PaperSize = _T(""); + m_PaperHeight = 0.0; + m_PaperWidth = 0.0; + m_IsInches = -1; + m_FooterLeft = _T(""); + m_FooterMiddle = _T(""); + m_FooterRight = _T(""); + m_HeaderLeft = _T(""); + m_HeaderMiddle = _T(""); + m_HeaderRight = _T(""); //}}AFX_DATA_INIT SetPrintSettings(m_PrintSettings); @@ -47,6 +73,16 @@ void CPrintSetupDialog::DoDataExchange(CDataExchange* pDX) DDX_Slider(pDX, IDC_SCALE, m_Scaling); DDX_Check(pDX, IDC_PRT_BGIMAGES, m_PrintBGImages); DDX_Check(pDX, IDC_PRT_BGCOLORS, m_PrintBGColors); + DDX_CBString(pDX, IDC_PAPER_SIZE_CBX, m_PaperSize); + DDX_Text(pDX, IDC_UD_PAPER_HGT, m_PaperHeight); + DDX_Text(pDX, IDC_UD_PAPER_WDTH, m_PaperWidth); + DDX_Radio(pDX, IDC_INCHES_RD, m_IsInches); + DDX_Text(pDX, IDC_FTR_LEFT_TXT, m_FooterLeft); + DDX_Text(pDX, IDC_FTR_MID_TXT, m_FooterMiddle); + DDX_Text(pDX, IDC_FTR_RIGHT_TXT, m_FooterRight); + DDX_Text(pDX, IDC_HDR_LEFT_TXT, m_HeaderLeft); + DDX_Text(pDX, IDC_HDR_MID_TXT, m_HeaderMiddle); + DDX_Text(pDX, IDC_HDR_RIGHT_TXT, m_HeaderRight); //}}AFX_DATA_MAP } @@ -55,6 +91,7 @@ BEGIN_MESSAGE_MAP(CPrintSetupDialog, CDialog) //{{AFX_MSG_MAP(CPrintSetupDialog) ON_NOTIFY(NM_CUSTOMDRAW, IDC_SCALE, OnCustomdrawScale) ON_EN_KILLFOCUS(IDC_SCALE_TXT, OnKillfocusScaleTxt) + ON_CBN_SELCHANGE(IDC_PAPER_SIZE_CBX, OnSelchangePaperSizeCbx) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -62,13 +99,12 @@ END_MESSAGE_MAP() // CPrintSetupDialog message handlers void CPrintSetupDialog::SetPrintSettings(nsIPrintSettings* aPrintSettings) { - if (m_PrintSettings != NULL) { - m_PrintSettings = aPrintSettings; + if (aPrintSettings != NULL) { double top, left, right, bottom; - m_PrintSettings->GetMarginTop(&top); - m_PrintSettings->GetMarginLeft(&left); - m_PrintSettings->GetMarginRight(&right); - m_PrintSettings->GetMarginBottom(&bottom); + aPrintSettings->GetMarginTop(&top); + aPrintSettings->GetMarginLeft(&left); + aPrintSettings->GetMarginRight(&right); + aPrintSettings->GetMarginBottom(&bottom); char buf[16]; sprintf(buf, "%5.2f", top); @@ -81,15 +117,40 @@ void CPrintSetupDialog::SetPrintSettings(nsIPrintSettings* aPrintSettings) m_BottomMargin = buf; double scaling; - m_PrintSettings->GetScaling(&scaling); + aPrintSettings->GetScaling(&scaling); m_Scaling = int(scaling * 100.0); PRBool boolVal; - m_PrintSettings->GetPrintBGColors(&boolVal); + aPrintSettings->GetPrintBGColors(&boolVal); m_PrintBGColors = boolVal == PR_TRUE; - m_PrintSettings->GetPrintBGImages(&boolVal); + aPrintSettings->GetPrintBGImages(&boolVal); m_PrintBGImages = boolVal == PR_TRUE; + PRUnichar* uStr; + aPrintSettings->GetHeaderStrLeft(&uStr); + m_HeaderLeft = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + + aPrintSettings->GetHeaderStrCenter(&uStr); + m_HeaderMiddle = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + + aPrintSettings->GetHeaderStrRight(&uStr); + m_HeaderRight = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + + aPrintSettings->GetFooterStrLeft(&uStr); + m_FooterLeft = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + + aPrintSettings->GetFooterStrCenter(&uStr); + m_FooterMiddle = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + + aPrintSettings->GetFooterStrRight(&uStr); + m_FooterRight = uStr; + if (uStr != nsnull) nsMemory::Free(uStr); + } } @@ -98,6 +159,51 @@ void CPrintSetupDialog::OnOK() CDialog::OnOK(); } +// Search for Sizes in Pape Size Data +int CPrintSetupDialog::GetPaperSizeIndexFromData(short aUnit, double aW, double aH) +{ + for (int i=0;iSetTicFreq(10); } + CComboBox* cbx = (CComboBox*)GetDlgItem(IDC_PAPER_SIZE_CBX); + if (cbx != NULL) { + // First Initialize the Combobox + for (int i=0;iAddString(gPaperSize[i].mDesc); + } + short unit; + double paperWidth = 0.0; + double paperHeight = 0.0; + m_PrintSettings->GetPaperSizeType(&unit); + m_PrintSettings->GetPaperWidth(&paperWidth); + m_PrintSettings->GetPaperHeight(&paperHeight); + + m_PaperSizeInx = GetPaperSizeIndexFromData(unit, paperWidth, paperHeight); + if (m_PaperSizeInx == -1) { // couldn't find a match + m_PaperSizeInx = 0; + unit = gPaperSize[m_PaperSizeInx].mUnit; + paperWidth = gPaperSize[m_PaperSizeInx].mWidth; + paperHeight = gPaperSize[m_PaperSizeInx].mHeight; + } + + cbx->SetCurSel(m_PaperSizeInx); + + EnableUserDefineControls(gPaperSize[m_PaperSizeInx].mIsUserDefined); + + if (gPaperSize[m_PaperSizeInx].mIsUserDefined) { + CString wStr; + CString hStr; + if (unit == nsIPrintSettings::kPaperSizeInches) { + wStr.Format("%6.2f", paperWidth); + hStr.Format("%6.2f", paperHeight); + CheckRadioButton(IDC_INCHES_RD, IDC_MILLI_RD, IDC_INCHES_RD); + } else { + wStr.Format("%d", int(paperWidth)); + hStr.Format("%d", int(paperHeight)); + CheckRadioButton(IDC_INCHES_RD, IDC_MILLI_RD, IDC_MILLI_RD); + } + CWnd* widthTxt = GetDlgItem(IDC_UD_PAPER_WDTH); + CWnd* heightTxt = GetDlgItem(IDC_UD_PAPER_HGT); + widthTxt->SetWindowText(wStr); + heightTxt->SetWindowText(hStr); + } else { + CheckRadioButton(IDC_INCHES_RD, IDC_MILLI_RD, IDC_INCHES_RD); + } + } + return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } @@ -150,3 +302,32 @@ void CPrintSetupDialog::OnKillfocusScaleTxt() scale->SetPos(GetIntFromStr(str)); } } + + +void CPrintSetupDialog::EnableUserDefineControls(BOOL aEnable) +{ + CWnd* cntrl = GetDlgItem(IDC_UD_WIDTH_LBL); + cntrl->EnableWindow(aEnable); + cntrl = GetDlgItem(IDC_UD_HEIGHT_LBL); + cntrl->EnableWindow(aEnable); + cntrl = GetDlgItem(IDC_UD_PAPER_WDTH); + cntrl->EnableWindow(aEnable); + cntrl = GetDlgItem(IDC_UD_PAPER_HGT); + cntrl->EnableWindow(aEnable); + cntrl = GetDlgItem(IDC_INCHES_RD); + cntrl->EnableWindow(aEnable); + cntrl = GetDlgItem(IDC_MILLI_RD); + cntrl->EnableWindow(aEnable); +} + +void CPrintSetupDialog::OnSelchangePaperSizeCbx() +{ + CComboBox* cbx = (CComboBox*)GetDlgItem(IDC_PAPER_SIZE_CBX); + if (cbx) { + CString text; + cbx->GetWindowText(text); + m_PaperSizeInx = GetPaperSizeIndex(text); + EnableUserDefineControls(gPaperSize[m_PaperSizeInx].mIsUserDefined); + } + +} diff --git a/mozilla/embedding/tests/mfcembed/PrintSetupDialog.h b/mozilla/embedding/tests/mfcembed/PrintSetupDialog.h index c989ff57e1f..5440ec94042 100644 --- a/mozilla/embedding/tests/mfcembed/PrintSetupDialog.h +++ b/mozilla/embedding/tests/mfcembed/PrintSetupDialog.h @@ -17,6 +17,7 @@ class CPrintSetupDialog : public CDialog public: CPrintSetupDialog(nsIPrintSettings* aPrintSettings, CWnd* pParent = NULL); // standard constructor void SetPrintSettings(nsIPrintSettings* aPrintSettings); + void GetPaperSizeInfo(short& aType, double& aWidth, double& aHeight); // Dialog Data //{{AFX_DATA(CPrintSetupDialog) @@ -28,8 +29,19 @@ public: int m_Scaling; BOOL m_PrintBGImages; BOOL m_PrintBGColors; + CString m_PaperSize; + double m_PaperHeight; + double m_PaperWidth; + int m_IsInches; + CString m_FooterLeft; + CString m_FooterMiddle; + CString m_FooterRight; + CString m_HeaderLeft; + CString m_HeaderMiddle; + CString m_HeaderRight; //}}AFX_DATA + int m_PaperSizeInx; // Overrides // ClassWizard generated virtual function overrides @@ -42,12 +54,17 @@ public: protected: nsIPrintSettings* m_PrintSettings; + void EnableUserDefineControls(BOOL aEnable); + int GetPaperSizeIndexFromData(short aType, double aW, double aH); + int GetPaperSizeIndex(const CString& aStr); + // Generated message map functions //{{AFX_MSG(CPrintSetupDialog) virtual void OnOK(); virtual BOOL OnInitDialog(); afx_msg void OnCustomdrawScale(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnKillfocusScaleTxt(); + afx_msg void OnSelchangePaperSizeCbx(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/mozilla/embedding/tests/mfcembed/makefile.win b/mozilla/embedding/tests/mfcembed/makefile.win index 778582644f5..c3dc5b80bbf 100644 --- a/mozilla/embedding/tests/mfcembed/makefile.win +++ b/mozilla/embedding/tests/mfcembed/makefile.win @@ -68,7 +68,6 @@ OBJS = \ .\$(OBJDIR)\MostRecentUrls.obj \ .\$(OBJDIR)\PrintProgressDialog.obj \ .\$(OBJDIR)\Preferences.obj \ - .\$(OBJDIR)\nsPrintSettingsImpl.obj \ .\$(OBJDIR)\PrintSetupDialog.obj \ .\$(OBJDIR)\StdAfx.obj \ $(NULL) diff --git a/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.cpp b/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.cpp deleted file mode 100644 index 0c92a944d89..00000000000 --- a/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsPrintSettingsImpl.h" -#include "nsCoord.h" -#include "nsUnitConversion.h" -#include "nsReadableUtils.h" - -// For Prefs -#include "nsIPref.h" -#include "nsIServiceManager.h" - -NS_IMPL_ISUPPORTS1(nsPrintSettings, nsIPrintSettings) - -/** --------------------------------------------------- - * See documentation in nsPrintSettingsImpl.h - * @update 6/21/00 dwc - */ -nsPrintSettings::nsPrintSettings() : - mPrintRange(kRangeAllPages), - mStartPageNum(1), - mEndPageNum(1), - mScaling(1.0), - mPrintBGColors(PR_FALSE), - mPrintBGImages(PR_FALSE), - mPrintOptions(0L), - mPrintReversed(PR_FALSE), - mPrintInColor(PR_TRUE), - mPaperSize(kLetterPaperSize), - mOrientation(kPortraitOrientation), - mPrintToFile(PR_FALSE), - mPrintFrameType(kFramesAsIs), - mPrintPageDelay(500), - mPrintSilent(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); - - /* member initializers and constructor code */ - nscoord halfInch = NS_INCHES_TO_TWIPS(0.5); - mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch); - - mPrintOptions = kOptPrintOddPages | kOptPrintEvenPages; - - mHeaderStrs[0].Assign(NS_LITERAL_STRING("&T")); - mHeaderStrs[2].Assign(NS_LITERAL_STRING("&U")); - - mFooterStrs[0].Assign(NS_LITERAL_STRING("&PT")); // Use &P (Page Num Only) or &PT (Page Num of Page Total) - mFooterStrs[2].Assign(NS_LITERAL_STRING("&D")); - -} - -/** --------------------------------------------------- - * See documentation in nsPrintSettingsImpl.h - * @update 6/21/00 dwc - */ -nsPrintSettings::~nsPrintSettings() -{ -} - - -/* attribute long startPageRange; */ -NS_IMETHODIMP nsPrintSettings::GetStartPageRange(PRInt32 *aStartPageRange) -{ - //NS_ENSURE_ARG_POINTER(aStartPageRange); - *aStartPageRange = mStartPageNum; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange) -{ - mStartPageNum = aStartPageRange; - return NS_OK; -} - -/* attribute long endPageRange; */ -NS_IMETHODIMP nsPrintSettings::GetEndPageRange(PRInt32 *aEndPageRange) -{ - //NS_ENSURE_ARG_POINTER(aEndPageRange); - *aEndPageRange = mEndPageNum; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange) -{ - mEndPageNum = aEndPageRange; - return NS_OK; -} - -/* attribute boolean printReversed; */ -NS_IMETHODIMP nsPrintSettings::GetPrintReversed(PRBool *aPrintReversed) -{ - //NS_ENSURE_ARG_POINTER(aPrintReversed); - *aPrintReversed = mPrintReversed; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintReversed(PRBool aPrintReversed) -{ - mPrintReversed = aPrintReversed; - return NS_OK; -} - -/* attribute boolean printInColor; */ -NS_IMETHODIMP nsPrintSettings::GetPrintInColor(PRBool *aPrintInColor) -{ - //NS_ENSURE_ARG_POINTER(aPrintInColor); - *aPrintInColor = mPrintInColor; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintInColor(PRBool aPrintInColor) -{ - mPrintInColor = aPrintInColor; - return NS_OK; -} - -/* attribute short paperSize; */ -NS_IMETHODIMP nsPrintSettings::GetPaperSize(PRInt32 *aPaperSize) -{ - //NS_ENSURE_ARG_POINTER(aPaperSize); - *aPaperSize = mPaperSize; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPaperSize(PRInt32 aPaperSize) -{ - mPaperSize = aPaperSize; - return NS_OK; -} - -/* attribute short orientation; */ -NS_IMETHODIMP nsPrintSettings::GetOrientation(PRInt32 *aOrientation) -{ - //NS_ENSURE_ARG_POINTER(aOrientation); - *aOrientation = mOrientation; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetOrientation(PRInt32 aOrientation) -{ - mOrientation = aOrientation; - return NS_OK; -} - -/* attribute wstring printCommand; */ -NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand) -{ - //NS_ENSURE_ARG_POINTER(aPrintCommand); - *aPrintCommand = ToNewUnicode(mPrintCommand); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand) -{ - mPrintCommand = aPrintCommand; - return NS_OK; -} - -/* attribute boolean printToFile; */ -NS_IMETHODIMP nsPrintSettings::GetPrintToFile(PRBool *aPrintToFile) -{ - //NS_ENSURE_ARG_POINTER(aPrintToFile); - *aPrintToFile = mPrintToFile; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintToFile(PRBool aPrintToFile) -{ - mPrintToFile = aPrintToFile; - return NS_OK; -} - -/* attribute wstring toFileName; */ -NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName) -{ - //NS_ENSURE_ARG_POINTER(aToFileName); - *aToFileName = ToNewUnicode(mToFileName); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName) -{ - mToFileName = aToFileName; - return NS_OK; -} - -/* attribute long printPageDelay; */ -NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay) -{ - *aPrintPageDelay = mPrintPageDelay; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay) -{ - mPrintPageDelay = aPrintPageDelay; - return NS_OK; -} - -/* attribute double marginTop; */ -NS_IMETHODIMP nsPrintSettings::GetMarginTop(double *aMarginTop) -{ - NS_ENSURE_ARG_POINTER(aMarginTop); - *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop) -{ - mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop)); - return NS_OK; -} - -/* attribute double marginLeft; */ -NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double *aMarginLeft) -{ - NS_ENSURE_ARG_POINTER(aMarginLeft); - *aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft) -{ - mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft)); - return NS_OK; -} - -/* attribute double marginBottom; */ -NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double *aMarginBottom) -{ - NS_ENSURE_ARG_POINTER(aMarginBottom); - *aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom) -{ - mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom)); - return NS_OK; -} - -/* attribute double marginRight; */ -NS_IMETHODIMP nsPrintSettings::GetMarginRight(double *aMarginRight) -{ - NS_ENSURE_ARG_POINTER(aMarginRight); - *aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight) -{ - mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight)); - return NS_OK; -} - -/* attribute double scaling; */ -NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling) -{ - NS_ENSURE_ARG_POINTER(aScaling); - *aScaling = mScaling; - return NS_OK; -} - -NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling) -{ - mScaling = aScaling; - return NS_OK; -} - -/* attribute boolean printBGColors; */ -NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(PRBool *aPrintBGColors) -{ - NS_ENSURE_ARG_POINTER(aPrintBGColors); - *aPrintBGColors = mPrintBGColors; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors) -{ - mPrintBGColors = aPrintBGColors; - return NS_OK; -} - -/* attribute boolean printBGImages; */ -NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(PRBool *aPrintBGImages) -{ - NS_ENSURE_ARG_POINTER(aPrintBGImages); - *aPrintBGImages = mPrintBGImages; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages) -{ - mPrintBGImages = aPrintBGImages; - return NS_OK; -} - -/* attribute long printRange; */ -NS_IMETHODIMP nsPrintSettings::GetPrintRange(PRInt16 *aPrintRange) -{ - NS_ENSURE_ARG_POINTER(aPrintRange); - *aPrintRange = mPrintRange; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange) -{ - mPrintRange = aPrintRange; - return NS_OK; -} - -/* attribute wstring docTitle; */ -NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle) -{ - NS_ENSURE_ARG_POINTER(aTitle); - *aTitle = ToNewUnicode(mTitle); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle) -{ - NS_ENSURE_ARG_POINTER(aTitle); - mTitle = aTitle; - return NS_OK; -} - -/* attribute wstring docURL; */ -NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL) -{ - NS_ENSURE_ARG_POINTER(aDocURL); - *aDocURL = ToNewUnicode(mURL); - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL) -{ - NS_ENSURE_ARG_POINTER(aDocURL); - mURL = aDocURL; - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation in nsPrintOptionsImpl.h - * @update 1/12/01 rods - */ -NS_IMETHODIMP -nsPrintSettings::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff) -{ - NS_ENSURE_ARG_POINTER(aTurnOnOff); - *aTurnOnOff = mPrintOptions & aType; - return NS_OK; -} -/** --------------------------------------------------- - * See documentation in nsPrintOptionsImpl.h - * @update 1/12/01 rods - */ -NS_IMETHODIMP -nsPrintSettings::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff) -{ - if (aTurnOnOff) { - mPrintOptions |= aType; - } else { - mPrintOptions &= ~aType; - } - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation in nsPrintOptionsImpl.h - * @update 1/12/01 rods - */ -NS_IMETHODIMP -nsPrintSettings::GetPrintOptionsBits(PRInt32 *aBits) -{ - NS_ENSURE_ARG_POINTER(aBits); - *aBits = mPrintOptions; - return NS_OK; -} - -/* attribute wstring docTitle; */ -nsresult -nsPrintSettings::GetMarginStrs(PRUnichar * *aTitle, - nsHeaderFooterEnum aType, - PRInt16 aJust) -{ - NS_ENSURE_ARG_POINTER(aTitle); - *aTitle = nsnull; - if (aType == eHeader) { - switch (aJust) { - case kJustLeft: *aTitle = ToNewUnicode(mHeaderStrs[0]);break; - case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break; - case kJustRight: *aTitle = ToNewUnicode(mHeaderStrs[2]);break; - } //switch - } else { - switch (aJust) { - case kJustLeft: *aTitle = ToNewUnicode(mFooterStrs[0]);break; - case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break; - case kJustRight: *aTitle = ToNewUnicode(mFooterStrs[2]);break; - } //switch - } - return NS_OK; -} - -nsresult -nsPrintSettings::SetMarginStrs(const PRUnichar * aTitle, - nsHeaderFooterEnum aType, - PRInt16 aJust) -{ - NS_ENSURE_ARG_POINTER(aTitle); - if (aType == eHeader) { - switch (aJust) { - case kJustLeft: mHeaderStrs[0] = aTitle;break; - case kJustCenter: mHeaderStrs[1] = aTitle;break; - case kJustRight: mHeaderStrs[2] = aTitle;break; - } //switch - } else { - switch (aJust) { - case kJustLeft: mFooterStrs[0] = aTitle;break; - case kJustCenter: mFooterStrs[1] = aTitle;break; - case kJustRight: mFooterStrs[2] = aTitle;break; - } //switch - } - return NS_OK; -} - -/* attribute wstring Header String Left */ -NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eHeader, kJustLeft); -} -NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eHeader, kJustLeft); -} - -/* attribute wstring Header String Center */ -NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eHeader, kJustCenter); -} -NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eHeader, kJustCenter); -} - -/* attribute wstring Header String Right */ -NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eHeader, kJustRight); -} -NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eHeader, kJustRight); -} - - -/* attribute wstring Footer String Left */ -NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eFooter, kJustLeft); -} -NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eFooter, kJustLeft); -} - -/* attribute wstring Footer String Center */ -NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eFooter, kJustCenter); -} -NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eFooter, kJustCenter); -} - -/* attribute wstring Footer String Right */ -NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(PRUnichar * *aTitle) -{ - return GetMarginStrs(aTitle, eFooter, kJustRight); -} -NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const PRUnichar * aTitle) -{ - return SetMarginStrs(aTitle, eFooter, kJustRight); -} - -/* attribute long printFrame; */ -NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(PRInt16 *aPrintFrameType) -{ - NS_ENSURE_ARG_POINTER(aPrintFrameType); - *aPrintFrameType = (PRInt32)mPrintFrameType; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType) -{ - mPrintFrameType = aPrintFrameType; - return NS_OK; -} - -/* attribute long isCancelled; */ -NS_IMETHODIMP nsPrintSettings::GetPrintSilent(PRBool *aPrintSilent) -{ - NS_ENSURE_ARG_POINTER(aPrintSilent); - *aPrintSilent = mPrintSilent; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintSilent(PRBool aPrintSilent) -{ - mPrintSilent = aPrintSilent; - return NS_OK; -} - diff --git a/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.h b/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.h deleted file mode 100644 index db077c67400..00000000000 --- a/mozilla/embedding/tests/mfcembed/nsPrintSettingsImpl.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is the Mozilla browser. - * - * The Initial Developer of the Original Code is Netscape - * Communications, Inc. Portions created by Netscape are - * Copyright (C) 1999, Mozilla. All Rights Reserved. - * - * Contributor(s): - * Travis Bogard - */ - -#ifndef nsPrintSettingsImpl_h__ -#define nsPrintSettingsImpl_h__ - -#include "nsIPrintSettings.h" -#include "nsMargin.h" -#include "nsString.h" - -//***************************************************************************** -//*** nsPrintSettings -//***************************************************************************** -class nsPrintSettings : public nsIPrintSettings -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTSETTINGS - - nsPrintSettings(); - virtual ~nsPrintSettings(); - -protected: - typedef enum { - eHeader, - eFooter - } nsHeaderFooterEnum; - - nsresult GetMarginStrs(PRUnichar * *aTitle, nsHeaderFooterEnum aType, PRInt16 aJust); - nsresult SetMarginStrs(const PRUnichar * aTitle, nsHeaderFooterEnum aType, PRInt16 aJust); - - // Members - nsMargin mMargin; - PRInt32 mPrintOptions; - - // scriptable data members - PRInt16 mPrintRange; - PRInt32 mStartPageNum; // only used for ePrintRange_SpecifiedRange - PRInt32 mEndPageNum; - double mScaling; - PRBool mPrintBGColors; // print background colors - PRBool mPrintBGImages; // print background images - - PRInt16 mPrintFrameType; - PRBool mPrintSilent; - PRInt32 mPrintPageDelay; - - nsString mTitle; - nsString mURL; - nsString mPageNumberFormat; - nsString mHeaderStrs[3]; - nsString mFooterStrs[3]; - - PRBool mPrintReversed; - PRBool mPrintInColor; // a false means grayscale - PRInt32 mPaperSize; // see page size consts - PRInt32 mOrientation; // see orientation consts - nsString mPrintCommand; - PRBool mPrintToFile; - nsString mToFileName; - -}; - - - -#endif /* nsPrintSettings_h__ */ diff --git a/mozilla/embedding/tests/mfcembed/resource.h b/mozilla/embedding/tests/mfcembed/resource.h index d39ff3097aa..52161558470 100644 --- a/mozilla/embedding/tests/mfcembed/resource.h +++ b/mozilla/embedding/tests/mfcembed/resource.h @@ -55,10 +55,23 @@ #define IDC_SCALE 1028 #define IDC_SCALE_TXT 1030 #define IDC_PRT_BGIMAGES 1031 +#define IDC_PAPER_SIZE_CBX 1032 +#define IDC_UD_PAPER_HGT 1033 +#define IDC_UD_PAPER_WDTH 1034 +#define IDC_UD_WIDTH_LBL 1035 +#define IDC_UD_HEIGHT_LBL 1036 +#define IDC_INCHES_RD 1037 +#define IDC_MILLI_RD 1038 +#define IDC_HDR_LEFT_TXT 1039 #define IDC_MATCH_WHOLE_WORD 1040 +#define IDC_HDR_MID_TXT 1040 #define IDC_MATCH_CASE 1041 +#define IDC_HDR_RIGHT_TXT 1041 #define IDC_WRAP_AROUND 1042 +#define IDC_FTR_LEFT_TXT 1042 #define IDC_SEARCH_BACKWARDS 1043 +#define IDC_FTR_MID_TXT 1043 +#define IDC_FTR_RIGHT_TXT 1044 #define IDC_FIND_EDIT 1152 #define IDC_RADIO_BLANK_PAGE 1153 #define IDC_RADIO_HOME_PAGE 1154 @@ -87,9 +100,9 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 153 +#define _APS_NEXT_RESOURCE_VALUE 154 #define _APS_NEXT_COMMAND_VALUE 32791 -#define _APS_NEXT_CONTROL_VALUE 1032 +#define _APS_NEXT_CONTROL_VALUE 1042 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/mozilla/embedding/tests/winEmbed/makefile.win b/mozilla/embedding/tests/winEmbed/makefile.win index 2caca671766..f250b496a54 100644 --- a/mozilla/embedding/tests/winEmbed/makefile.win +++ b/mozilla/embedding/tests/winEmbed/makefile.win @@ -39,6 +39,7 @@ REQUIRES = xpcom \ uriloader \ shistory \ webbrowserpersist \ + gfx \ $(NULL) PROGRAM = .\$(OBJDIR)\$(MODULE).exe diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.cpp b/mozilla/embedding/tests/winEmbed/winEmbed.cpp index cfa2a96e663..c52446ee204 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.cpp +++ b/mozilla/embedding/tests/winEmbed/winEmbed.cpp @@ -688,7 +688,7 @@ BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (NS_SUCCEEDED(res)) { nsCOMPtr spContentViewerFile = do_QueryInterface(pContentViewer); - spContentViewerFile->Print(PR_TRUE, nsnull); + spContentViewerFile->Print(PR_TRUE, nsnull, (nsIWebProgressListener*)nsnull); } } break; diff --git a/mozilla/gfx/idl/nsIPrintOptions.idl b/mozilla/gfx/idl/nsIPrintOptions.idl index 89b9292c268..a4f3412df81 100644 --- a/mozilla/gfx/idl/nsIPrintOptions.idl +++ b/mozilla/gfx/idl/nsIPrintOptions.idl @@ -42,7 +42,6 @@ #include "nsIPrintSettings.idl" %{ C++ -#include "nsMargin.h" #include "nsFont.h" %} @@ -51,7 +50,6 @@ interface nsISimpleEnumerator; /** * Native types */ - [ref] native nsNativeMarginRef(nsMargin); [ref] native nsNativeFontRef(nsFont); [ref] native nsNativeStringRef(nsString); @@ -81,7 +79,7 @@ interface nsIPrintOptions : nsISupports const long kJustRight = 2; /** - * Page Size Constants + * Page Size Constants (NOTE: These have been deprecated!); */ const short kLetterPaperSize = 0; const short kLegalPaperSize = 1; @@ -89,6 +87,24 @@ interface nsIPrintOptions : nsISupports const short kA4PaperSize = 3; const short kA3PaperSize = 4; + /** + * FrameSet Default Type Constants + */ + const short kUseInternalDefault = 0; + const short kUseSettingWhenPossible = 1; + + /** + * Page Size Type Constants + */ + const short kPaperSizeNativeData = 0; + const short kPaperSizeDefined = 1; + + /** + * Page Size Unit Constants + */ + const short kPaperSizeInches = 0; + const short kPaperSizeMillimeters = 1; + /** * Orientation Constants */ @@ -103,6 +119,9 @@ interface nsIPrintOptions : nsISupports const short kSelectedFrame = 2; const short kEachFrameSep = 3; + /** + * How to Enable Frame Set Printing Constants + */ const short kFrameEnableNone = 0; const short kFrameEnableAll = 1; const short kFrameEnableAsIsAndEach = 2; @@ -137,6 +156,17 @@ interface nsIPrintOptions : nsISupports */ void WritePrefs(); + /** + * Creates a new PrintSettnigs Object + * and initializes it from prefs + */ + nsIPrintSettings CreatePrintSettings(); + + /** + * Initialize the values in the PrintSettings from Prefs + */ + void InitPrintSettingsFromPrefs(in nsIPrintSettings aPO); + /** * Data Members */ @@ -166,20 +196,29 @@ interface nsIPrintOptions : nsISupports attribute wstring footerStrRight; attribute short howToEnableFrameUI; - attribute short printFrameType; attribute boolean isCancelled; - attribute boolean PrintSilent; /* print without putting up the dialog */ + attribute short printFrameTypeUsage; /* indicates whether to use the interal value or not*/ + attribute short printFrameType; + attribute boolean printSilent; /* print without putting up the dialog */ - attribute nsIPrintSettings printSettings; + attribute nsIPrintSettings printSettingsValues; /* used copy the values to/from the settings obj*/ + attribute nsIPrintSettings printSettings; /* used to set and get the current object */ /* Additional XP Related */ + attribute short paperSizeType; /* use native data or is defined here */ + attribute short paperData; /* native data value */ + attribute double paperWidth; /* width of the paper in inches or mm */ + attribute double paperHeight; /* height of the paper in inches or mm */ + attribute short paperSizeUnit; /* paper is in inches or mm */ + + attribute long paperSize; /* This has been deprecated */ + attribute boolean printReversed; attribute boolean printInColor; /* a false means grayscale */ - attribute long paperSize; /* see page size consts */ attribute long orientation; /* see orientation consts */ attribute wstring printCommand; attribute long numCopies; - attribute wstring printer; + attribute wstring printerName; attribute boolean printToFile; attribute wstring toFileName; @@ -197,15 +236,25 @@ interface nsIPrintOptions : nsISupports /* Purposely made this an "in" arg */ [noscript] void GetDefaultFont(in nsNativeFontRef aMargin); + [noscript] void GetPageSizeInTwips(out long aWidth, out long aHeight); + /** * available Printers */ nsISimpleEnumerator availablePrinters (); + + /** + * Indicates whether the list of printers contains the extended + * information. i.e. That there are "pairs" of values returned. Where the second + * value is either "FILE", "PRINTER", "BOTH" + * + */ + readonly attribute boolean isExtended; /** * display Printer Job Properties dialog */ - void displayJobProperties (in wstring aPrinter, out boolean aDisplayed); + void displayJobProperties (in wstring aPrinter, in nsIPrintSettings aPrintSettings, out boolean aDisplayed); /** * Native data constants @@ -219,7 +268,7 @@ interface nsIPrintOptions : nsISupports interface nsIPrinterEnumerator : nsISupports { /** - * Return an array of the names of all installed printers. + * Returns an array of the names of all installed printers. * * @param aCount returns number of printers returned * @param aResult returns array of names @@ -227,9 +276,29 @@ interface nsIPrinterEnumerator : nsISupports */ void enumeratePrinters(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult); + /** + * Returns an array of "pairs" of strings + * The first string in the pair is the printer name + * the second string in the pair is can be "FILE", "PRINTER", or "BOTH" + * which indicates whether the printer driver associated with this printer + * ALWAYS "spools" to a file or to a printer. + * + * If this type of information is not available, it should return zero items + * + * Note: On some platforms any given driveris able to spool to either + * + * @param aCount returns number of printers AND info strings returned + * i.e If there are 5 printers define the + * "count" returned will be 10 + * @param aResult returns array of names + * @return void + */ + void enumeratePrintersExtended(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult); + /* takes printer selected and will display job properties dlg for that printer * returns true if dialog displays */ - void displayPropertiesDlg(in wstring aPrinter); + void displayPropertiesDlg(in wstring aPrinter, in nsIPrintSettings aPrintSettings); + }; diff --git a/mozilla/gfx/idl/nsIPrintSettings.idl b/mozilla/gfx/idl/nsIPrintSettings.idl index c9924355999..e78e9159a2f 100644 --- a/mozilla/gfx/idl/nsIPrintSettings.idl +++ b/mozilla/gfx/idl/nsIPrintSettings.idl @@ -39,6 +39,17 @@ #include "nsISupports.idl" + +%{ C++ +#include "nsMargin.h" +#include "nsFont.h" +%} + +/** + * Native types + */ + [ref] native nsNativeMarginRef(nsMargin); + /** * Simplified graphics interface for JS rendering. * @@ -46,14 +57,13 @@ */ [scriptable, uuid(83427530-F790-11d4-A869-00105A183419)] - - interface nsIPrintSettings : nsISupports { + /* Print Option Flags for Bit Field*/ - const long kOptPrintOddPages = 0x00000001; - const long kOptPrintEvenPages = 0x00000002; - const long kPrintOptionsEnableSelectionRB = 0x00000004; + const long kPrintOddPages = 0x00000001; + const long kPrintEvenPages = 0x00000002; + const long kEnableSelectionRB = 0x00000004; /* Print Range Enums */ const long kRangeAllPages = 0; @@ -67,13 +77,22 @@ interface nsIPrintSettings : nsISupports const long kJustRight = 2; /** - * Page Size Constants + * FrameSet Default Type Constants */ - const short kLetterPaperSize = 0; - const short kLegalPaperSize = 1; - const short kExecutivePaperSize = 2; - const short kA4PaperSize = 3; - const short kA3PaperSize = 4; + const short kUseInternalDefault = 0; + const short kUseSettingWhenPossible = 1; + + /** + * Page Size Type Constants + */ + const short kPaperSizeNativeData = 0; + const short kPaperSizeDefined = 1; + + /** + * Page Size Unit Constants + */ + const short kPaperSizeInches = 0; + const short kPaperSizeMillimeters = 1; /** * Orientation Constants @@ -89,6 +108,13 @@ interface nsIPrintSettings : nsISupports const short kSelectedFrame = 2; const short kEachFrameSep = 3; + /** + * How to Enable Frame Set Printing Constants + */ + const short kFrameEnableNone = 0; + const short kFrameEnableAll = 1; + const short kFrameEnableAsIsAndEach = 2; + /** * Set PrintOptions */ @@ -104,6 +130,11 @@ interface nsIPrintSettings : nsISupports */ PRInt32 GetPrintOptionsBits(); + /** + * Returns W/H in Twips from Paper Size H/W + */ + void GetPageSizeInTwips(out long aWidth, out long aHeight); + /** * Data Members */ @@ -132,18 +163,34 @@ interface nsIPrintSettings : nsISupports attribute wstring footerStrCenter; attribute wstring footerStrRight; + attribute short howToEnableFrameUI; /* indicates how to enable the frameset UI */ + attribute boolean isCancelled; /* indicates whether the print job has been cancelled */ + attribute short printFrameTypeUsage; /* indicates whether to use the interal value or not */ attribute short printFrameType; - attribute boolean PrintSilent; /* print without putting up the dialog */ + attribute boolean printSilent; /* print without putting up the dialog */ /* Additional XP Related */ + attribute short paperSizeType; /* use native data or is defined here */ + attribute short paperData; /* native data value */ + attribute double paperWidth; /* width of the paper in inches or mm */ + attribute double paperHeight; /* height of the paper in inches or mm */ + attribute short paperSizeUnit; /* paper is in inches or mm */ + attribute boolean printReversed; attribute boolean printInColor; /* a false means grayscale */ attribute long paperSize; /* see page size consts */ attribute long orientation; /* see orientation consts */ attribute wstring printCommand; + attribute long numCopies; + attribute wstring printerName; attribute boolean printToFile; attribute wstring toFileName; attribute long printPageDelay; /* in milliseconds */ + /* C++ Helper Functions */ + [noscript] void SetMarginInTwips(in nsNativeMarginRef aMargin); + /* Purposely made this an "in" arg */ + [noscript] void GetMarginInTwips(in nsNativeMarginRef aMargin); + }; diff --git a/mozilla/gfx/public/nsIDeviceContext.h b/mozilla/gfx/public/nsIDeviceContext.h index 0601229db1a..9ef13f71d87 100644 --- a/mozilla/gfx/public/nsIDeviceContext.h +++ b/mozilla/gfx/public/nsIDeviceContext.h @@ -67,7 +67,7 @@ typedef void * nsNativeDeviceContext; #define NS_ERROR_GFX_PRINTER_CMD_FAILURE \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+2) /* no printer available (e.g. cannot find _any_ printer) */ -#define NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE \ +#define NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+3) /* _specified_ (by name) printer not found */ #define NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND \ @@ -93,6 +93,9 @@ typedef void * nsNativeDeviceContext; /* print-to-file: I/O error while printing to file */ #define NS_ERROR_GFX_PRINTER_FILE_IO_ERROR \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+12) +/* 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) /** * Conts need for Print Preview diff --git a/mozilla/gfx/public/nsIDeviceContextSpecFactory.h b/mozilla/gfx/public/nsIDeviceContextSpecFactory.h index a9907097185..30b914745de 100644 --- a/mozilla/gfx/public/nsIDeviceContextSpecFactory.h +++ b/mozilla/gfx/public/nsIDeviceContextSpecFactory.h @@ -43,6 +43,7 @@ class nsIDeviceContextSpec; class nsIWidget; +class nsIPrintSettings; #define NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID \ { 0xf6669570, 0x7b3d, 0x11d2, \ @@ -78,6 +79,7 @@ public: * @return error status */ NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) = 0; }; diff --git a/mozilla/gfx/public/nsIPrintingContext.h b/mozilla/gfx/public/nsIPrintingContext.h index 2028501d059..7620a50c372 100644 --- a/mozilla/gfx/public/nsIPrintingContext.h +++ b/mozilla/gfx/public/nsIPrintingContext.h @@ -42,6 +42,8 @@ #include "nsISupports.h" +class nsIPrintSettings; + // 3d5917da-1dd2-11b2-bc7b-aa83823362e0 #define NS_IPRINTING_CONTEXT_IID \ { 0x3d5917da, 0x1dd2, 0x11b2, \ @@ -59,7 +61,7 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet) = 0; + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet) = 0; /** * This will tell if the printmanager is currently open diff --git a/mozilla/gfx/src/Makefile.in b/mozilla/gfx/src/Makefile.in index 75fa9d2b9b8..adebfd2a0c5 100644 --- a/mozilla/gfx/src/Makefile.in +++ b/mozilla/gfx/src/Makefile.in @@ -91,6 +91,7 @@ CPPSRCS = \ nsScriptableRegion.cpp \ nsGraphicsImpl.cpp \ nsPrintOptionsImpl.cpp \ + nsPrintSettingsImpl.cpp \ $(NULL) ifeq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT))) diff --git a/mozilla/gfx/src/beos/nsDeviceContextSpecB.cpp b/mozilla/gfx/src/beos/nsDeviceContextSpecB.cpp index d50f3083dfc..a158fed6a9e 100644 --- a/mozilla/gfx/src/beos/nsDeviceContextSpecB.cpp +++ b/mozilla/gfx/src/beos/nsDeviceContextSpecB.cpp @@ -39,9 +39,6 @@ #include "nsDeviceContextSpecB.h" -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" - #include "nsIPref.h" #include "prenv.h" /* for PR_GetEnv */ @@ -52,17 +49,46 @@ #include "nsIWindowWatcher.h" #include "nsIDOMWindowInternal.h" -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" #include "nsReadableUtils.h" +#include "nsISupportsArray.h" //#include "prmem.h" //#include "plstr.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +//---------------------------------------------------------------------------------- +// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecG +// The PrinterEnumerator creates the printer info +// but the nsDeviceContextSpecG cleans it up +// If it gets created (via the Page Setup Dialog) but the user never prints anything +// then it will never be delete, so this class takes care of that. +class GlobalPrinters { +public: + static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } + ~GlobalPrinters() { FreeGlobalPrinters(); } -nsStringArray* nsDeviceContextSpecBeOS::globalPrinterList = nsnull; -int nsDeviceContextSpecBeOS::globalNumPrinters = 0; + void FreeGlobalPrinters(); + nsresult InitializeGlobalPrinters(); + + PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; } + PRInt32 GetNumPrinters() { return mGlobalNumPrinters; } + nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } + +protected: + GlobalPrinters() {} + + static GlobalPrinters mGlobalPrinters; + static nsStringArray* mGlobalPrinterList; + static int mGlobalNumPrinters; + +}; +//--------------- +// static members +GlobalPrinters GlobalPrinters::mGlobalPrinters; +nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull; +int GlobalPrinters::mGlobalNumPrinters = 0; +//--------------- +nsStringArray* nsDeviceContextSpecBeOS::mGlobalPrinterList = nsnull; +int nsDeviceContextSpecBeOS::mGlobalNumPrinters = 0; /** ------------------------------------------------------- * Construct the nsDeviceContextSpecBeOS @@ -127,83 +153,80 @@ NS_IMPL_ADDREF(nsDeviceContextSpecBeOS) NS_IMPL_RELEASE(nsDeviceContextSpecBeOS) -int nsDeviceContextSpecBeOS::InitializeGlobalPrinters () +/** ------------------------------------------------------- + */ +static nsresult DisplayXPDialog(nsIPrintSettings* aPS, + const char* aChromeURL, + PRBool& aClickedOK) { - globalNumPrinters = 0; - globalPrinterList = new nsStringArray(); - if (!globalPrinterList) - return NS_ERROR_OUT_OF_MEMORY; - - /* add an entry for the default printer (see nsPostScriptObj.cpp) */ - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); - globalNumPrinters++; + NS_ASSERTION(aPS, "Must have a print settings!"); - /* get the list of printers */ - char *printerList = nsnull; - - /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ - printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); - - if (!printerList) { - nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - (void) pPrefs->CopyCharPref("print.printer_list", &printerList); - } - } + aClickedOK = PR_FALSE; + nsresult rv = NS_ERROR_FAILURE; - if (printerList) { - char *tok_lasts; - char *name; - - /* PL_strtok_r() will modify the string - copy it! */ - printerList = strdup(printerList); - if (!printerList) - return NS_ERROR_OUT_OF_MEMORY; - - for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; - name != nsnull ; - name = PL_strtok_r(nsnull, " ", &tok_lasts) ) - { - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + - nsString(NS_ConvertASCIItoUCS2(name))); - globalNumPrinters++; + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; + + nsCOMPtr ps = aPS; + nsCOMPtr psSupports(do_QueryInterface(ps)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); + + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + nsCOMPtr parent = do_QueryInterface(active); + + nsCOMPtr newWindow; + rv = wwatch->OpenWindow(parent, aChromeURL, + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); } - - free(printerList); } - - if (globalNumPrinters == 0) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - return NS_OK; + if (NS_SUCCEEDED(rv)) { + PRInt32 buttonPressed = 0; + ioParamBlock->GetInt(0, &buttonPressed); + if (buttonPressed == 1) { + aClickedOK = PR_TRUE; + } else { + rv = NS_ERROR_ABORT; + } + } else { + rv = NS_ERROR_ABORT; + } + return rv; } -void nsDeviceContextSpecBeOS::FreeGlobalPrinters() -{ - delete globalPrinterList; - globalPrinterList = nsnull; - globalNumPrinters = 0; -} /** ------------------------------------------------------- * Initialize the nsDeviceContextSpecBeOS * @update dc 2/15/98 * @update syd 3/2/99 */ -NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(nsIPrintSettings* aPS, PRBool aQuiet) { nsresult rv = NS_ERROR_FAILURE; - - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); - NS_ASSERTION(nsnull != printService, "No print service."); + NS_ASSERTION(nsnull != aPS, "No print settings."); // if there is a current selection then enable the "Selection" radio button - if (NS_SUCCEEDED(rv) && printService) { + if (aPS != nsnull) { PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); + aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); @@ -215,7 +238,7 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(PRBool aQuiet) PRBool reversed = PR_FALSE; PRBool color = PR_FALSE; PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintOptions::kRangeAllPages; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 paper_size = NS_LETTER_SIZE; PRInt32 orientation = NS_PORTRAIT; PRInt32 fromPage = 1; @@ -229,71 +252,39 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(PRBool aQuiet) double dtop = 0.5; double dbottom = 0.5; - if( !globalPrinterList ) - if (InitializeGlobalPrinters()) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - if( globalNumPrinters && !globalPrinterList->Count() ) - return NS_ERROR_OUT_OF_MEMORY; + rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } if (!aQuiet ) { - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - if (NS_SUCCEEDED(rv)) { - PRInt32 buttonPressed = 0; - ioParamBlock->GetInt(0, &buttonPressed); - if (buttonPressed == 0) { - canPrint = PR_TRUE; - } - else { - rv = NS_ERROR_ABORT; - } - } + rv = DisplayXPDialog(aPS, + "chrome://global/content/printdialog.xul", canPrint); } else { canPrint = PR_TRUE; } - FreeGlobalPrinters(); + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); if (canPrint) { - if (printService) { - printService->GetPrinter(&printer); - printService->GetPrintReversed(&reversed); - printService->GetPrintInColor(&color); - printService->GetPaperSize(&paper_size); - printService->GetOrientation(&orientation); - printService->GetPrintCommand(&command); - printService->GetPrintRange(&printRange); - printService->GetToFileName(&printfile); - printService->GetPrintToFile(&tofile); - printService->GetStartPageRange(&fromPage); - printService->GetEndPageRange(&toPage); - printService->GetNumCopies(&copies); - printService->GetMarginTop(&dtop); - printService->GetMarginLeft(&dleft); - printService->GetMarginBottom(&dbottom); - printService->GetMarginRight(&dright); + if (aPS != nsnull) { + aPS->GetPrinterName(&printer); + aPS->GetPrintReversed(&reversed); + aPS->GetPrintInColor(&color); + aPS->GetPaperSize(&paper_size); + aPS->GetOrientation(&orientation); + aPS->GetPrintCommand(&command); + aPS->GetPrintRange(&printRange); + aPS->GetToFileName(&printfile); + aPS->GetPrintToFile(&tofile); + aPS->GetStartPageRange(&fromPage); + aPS->GetEndPageRange(&toPage); + aPS->GetNumCopies(&copies); + aPS->GetMarginTop(&dtop); + aPS->GetMarginLeft(&dleft); + aPS->GetMarginBottom(&dbottom); + aPS->GetMarginRight(&dright); if (command != nsnull && printfile != nsnull) { // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446) @@ -343,9 +334,9 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(PRBool aQuiet) } #ifdef NOT_IMPLEMENTED_YET - if (globalNumPrinters) { - for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) { - if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) + if (mGlobalNumPrinters) { + for(int i = 0; (i < mGlobalNumPrinters) && !mQueue; i++) { + if (!(mGlobalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) mQueue = PrnDlg.SetPrinterQueue(i); } } @@ -370,7 +361,7 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS :: GetToPrinter( PRBool &aToPrinter ) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecBeOS::GetPrinter ( char **aPrinter ) +NS_IMETHODIMP nsDeviceContextSpecBeOS::GetPrinterName ( char **aPrinter ) { *aPrinter = &mPrData.printer[0]; return NS_OK; @@ -499,8 +490,20 @@ nsPrinterEnumeratorBeOS::nsPrinterEnumeratorBeOS() NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorBeOS, nsIPrinterEnumerator) +NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrintersExtended(PRUint32* aCount, PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + *aCount = 0; + *aResult = nsnull; + return NS_OK; +} + NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) { + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + if (aCount) *aCount = 0; else @@ -511,21 +514,32 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUni else return NS_ERROR_NULL_POINTER; + nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } - PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecBeOS::globalNumPrinters * sizeof(PRUnichar*)); - if (!array && nsDeviceContextSpecBeOS::globalNumPrinters) + PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); + + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*)); + if (!array && numPrinters > 0) { + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; + } int count = 0; - while( count < nsDeviceContextSpecBeOS::globalNumPrinters ) + while( count < numPrinters ) { - PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecBeOS::globalPrinterList->StringAt(count)); + + PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count)); if (!str) { for (int i = count - 1; i >= 0; i--) nsMemory::Free(array[i]); nsMemory::Free(array); + + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; } array[count++] = str; @@ -533,14 +547,13 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUni } *aCount = count; *aResult = array; + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_OK; } -NS_IMETHODIMP nsPrinterEnumeratorBeOS::DisplayPropertiesDlg(const PRUnichar *aPrinter) +NS_IMETHODIMP nsPrinterEnumeratorBeOS::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) { - nsresult rv = NS_ERROR_FAILURE; - /* fixme: We simply ignore the |aPrinter| argument here * We should get the supported printer attributes from the printer and * populate the print job options dialog with these data instead of using @@ -549,32 +562,80 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::DisplayPropertiesDlg(const PRUnichar *aPr * of patches ... ;-( */ - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); + PRBool pressedOK; + return DisplayXPDialog(aPrintSettings, + "chrome://global/content/printjoboptions.xul", + pressedOK); - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - - return rv; } +//---------------------------------------------------------------------- +nsresult GlobalPrinters::InitializeGlobalPrinters () +{ + if (PrintersAreAllocated()) { + return NS_OK; + } + + mGlobalNumPrinters = 0; + mGlobalPrinterList = new nsStringArray(); + if (!mGlobalPrinterList) + return NS_ERROR_OUT_OF_MEMORY; + + /* add an entry for the default printer (see nsPostScriptObj.cpp) */ + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); + mGlobalNumPrinters++; + + /* get the list of printers */ + char *printerList = nsnull; + + /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ + printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); + + if (!printerList) { + nsresult rv; + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->CopyCharPref("print.printer_list", &printerList); + } + } + + if (printerList) { + char *tok_lasts; + char *name; + + /* PL_strtok_r() will modify the string - copy it! */ + printerList = strdup(printerList); + if (!printerList) + return NS_ERROR_OUT_OF_MEMORY; + + for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; + name != nsnull ; + name = PL_strtok_r(nsnull, " ", &tok_lasts) ) + { + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + + nsString(NS_ConvertASCIItoUCS2(name))); + mGlobalNumPrinters++; + } + + free(printerList); + } + + if (mGlobalNumPrinters == 0) + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; + + return NS_OK; +} + +//---------------------------------------------------------------------- +void GlobalPrinters::FreeGlobalPrinters() +{ + delete mGlobalPrinterList; + mGlobalPrinterList = nsnull; + mGlobalNumPrinters = 0; +} + + + + diff --git a/mozilla/gfx/src/beos/nsDeviceContextSpecB.h b/mozilla/gfx/src/beos/nsDeviceContextSpecB.h index 71fda32a088..885d6dd6852 100644 --- a/mozilla/gfx/src/beos/nsDeviceContextSpecB.h +++ b/mozilla/gfx/src/beos/nsDeviceContextSpecB.h @@ -42,9 +42,10 @@ #include "nsIDeviceContextSpec.h" #include "nsDeviceContextSpecB.h" -#include "nsIPrintOptions.h" #include "nsVoidArray.h" #include "nsIDeviceContextSpecPS.h" +#include "nsIPrintSettings.h" +#include "nsIPrintOptions.h" #include "nsPrintdBeOS.h" @@ -70,7 +71,7 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); /** @@ -82,7 +83,7 @@ public: NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); - NS_IMETHOD GetPrinter ( char **aPrinter ); + NS_IMETHOD GetPrinterName ( char **aPrinter ); NS_IMETHOD GetCopies ( int &aCopies ); diff --git a/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.cpp b/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.cpp index 8cee0047bfb..57d518e9eed 100644 --- a/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.cpp +++ b/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.cpp @@ -78,6 +78,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryBeOS :: Init(void) * @update dc 2/16/98 */ NS_IMETHODIMP nsDeviceContextSpecFactoryBeOS :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { @@ -86,7 +87,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryBeOS :: CreateDeviceContextSpec(nsIWidge nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); if (NS_SUCCEEDED(rv)) { - rv = ((nsDeviceContextSpecBeOS *)devSpec.get())->Init(aQuiet); + rv = ((nsDeviceContextSpecBeOS *)devSpec.get())->Init(aPrintSettings, aQuiet); if (NS_SUCCEEDED(rv)) { aNewSpec = devSpec; diff --git a/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.h b/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.h index 3e9c67b981d..1ee077f3558 100644 --- a/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.h +++ b/mozilla/gfx/src/beos/nsDeviceContextSpecFactoryB.h @@ -51,6 +51,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.cpp b/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.cpp index 15a4a0e0a2c..cd368a99018 100644 --- a/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.cpp +++ b/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.cpp @@ -75,6 +75,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: Init(void) * @update dc 2/16/98 */ NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { @@ -83,14 +84,13 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: CreateDeviceContextSpec(nsIWidget nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); if (NS_SUCCEEDED(rv)) { - rv = ((nsDeviceContextSpecGTK *)devSpec.get())->Init(aQuiet); + rv = ((nsDeviceContextSpecGTK *)devSpec.get())->Init(aPrintSettings, aQuiet); if (NS_SUCCEEDED(rv)) { aNewSpec = devSpec; NS_ADDREF(aNewSpec); } } - return rv; } diff --git a/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.h b/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.h index 3c48e9816ea..63262db4b78 100644 --- a/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.h +++ b/mozilla/gfx/src/gtk/nsDeviceContextSpecFactoryG.h @@ -51,6 +51,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp b/mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp index 776acfb0a2d..06725a391ff 100644 --- a/mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp +++ b/mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp @@ -39,11 +39,7 @@ #include "nsDeviceContextSpecG.h" -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" -#include "nsIPrintOptions.h" #include "nsReadableUtils.h" -#include "nsGfxCIID.h" #include "nsIPref.h" #include "prenv.h" /* for PR_GetEnv */ @@ -54,15 +50,44 @@ #include "nsISupportsPrimitives.h" #include "nsIWindowWatcher.h" #include "nsIDOMWindowInternal.h" +#include "nsISupportsArray.h" #ifdef USE_XPRINT #include "xprintutil.h" #endif /* USE_XPRINT */ -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +//---------------------------------------------------------------------------------- +// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecG +// The PrinterEnumerator creates the printer info +// but the nsDeviceContextSpecG cleans it up +// If it gets created (via the Page Setup Dialog) but the user never prints anything +// then it will never be delete, so this class takes care of that. +class GlobalPrinters { +public: + static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } + ~GlobalPrinters() { FreeGlobalPrinters(); } -nsStringArray* nsDeviceContextSpecGTK::globalPrinterList = nsnull; -int nsDeviceContextSpecGTK::globalNumPrinters = 0; + void FreeGlobalPrinters(); + nsresult InitializeGlobalPrinters(); + + PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; } + PRInt32 GetNumPrinters() { return mGlobalNumPrinters; } + nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } + +protected: + GlobalPrinters() {} + + static GlobalPrinters mGlobalPrinters; + static nsStringArray* mGlobalPrinterList; + static int mGlobalNumPrinters; + +}; +//--------------- +// static members +GlobalPrinters GlobalPrinters::mGlobalPrinters; +nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull; +int GlobalPrinters::mGlobalNumPrinters = 0; +//--------------- /** ------------------------------------------------------- * Construct the nsDeviceContextSpecGTK @@ -136,81 +161,63 @@ NS_IMPL_ADDREF(nsDeviceContextSpecGTK) NS_IMPL_RELEASE(nsDeviceContextSpecGTK) -int nsDeviceContextSpecGTK::InitializeGlobalPrinters () +static nsresult DisplayXPDialog(nsIPrintSettings* aPS, + const char* aChromeURL, + PRBool& aClickedOK) { - globalNumPrinters = 0; - globalPrinterList = new nsStringArray(); - if (!globalPrinterList) - return NS_ERROR_OUT_OF_MEMORY; - -#ifdef USE_XPRINT - XPPrinterList plist = XpuGetPrinterList(nsnull, &globalNumPrinters); - - if (plist && (globalNumPrinters > 0)) - { - int i; - for( i = 0 ; i < globalNumPrinters ; i++ ) - { - globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); - } - - XpuFreePrinterList(plist); - } -#endif /* USE_XPRINT */ + NS_ASSERTION(aPS, "Must have a print settings!"); - /* add an entry for the default printer (see nsPostScriptObj.cpp) */ - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); - globalNumPrinters++; + aClickedOK = PR_FALSE; + nsresult rv = NS_ERROR_FAILURE; - /* get the list of printers */ - char *printerList = nsnull; - - /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ - printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); - - if (!printerList) { - nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - (void) pPrefs->CopyCharPref("print.printer_list", &printerList); - } - } + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; - if (printerList) { - char *tok_lasts; - char *name; - - /* PL_strtok_r() will modify the string - copy it! */ - printerList = strdup(printerList); - if (!printerList) - return NS_ERROR_OUT_OF_MEMORY; - - for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; - name != nsnull ; - name = PL_strtok_r(nsnull, " ", &tok_lasts) ) - { - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + - nsString(NS_ConvertASCIItoUCS2(name))); - globalNumPrinters++; + nsCOMPtr ps = aPS; + nsCOMPtr psSupports(do_QueryInterface(ps)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); + + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + nsCOMPtr parent = do_QueryInterface(active); + + nsCOMPtr newWindow; + rv = wwatch->OpenWindow(parent, aChromeURL, + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); } - - free(printerList); } - - if (globalNumPrinters == 0) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - return NS_OK; + if (NS_SUCCEEDED(rv)) { + PRInt32 buttonPressed = 0; + ioParamBlock->GetInt(0, &buttonPressed); + if (buttonPressed == 1) { + aClickedOK = PR_TRUE; + } else { + rv = NS_ERROR_ABORT; + } + } else { + rv = NS_ERROR_ABORT; + } + return rv; } -void nsDeviceContextSpecGTK::FreeGlobalPrinters() -{ - delete globalPrinterList; - globalPrinterList = nsnull; - globalNumPrinters = 0; -} /** ------------------------------------------------------- @@ -232,17 +239,16 @@ void nsDeviceContextSpecGTK::FreeGlobalPrinters() * * ** Please update the other toolkits when changing this function. */ -NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings* aPS, PRBool aQuiet) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); - NS_ASSERTION(nsnull != printService, "No print service."); - + mPrintSettings = aPS; + // if there is a current selection then enable the "Selection" radio button - if (NS_SUCCEEDED(rv) && printService) { + if (mPrintSettings) { PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); + mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); @@ -254,7 +260,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) PRBool reversed = PR_FALSE; PRBool color = PR_FALSE; PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintOptions::kRangeAllPages; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 paper_size = NS_LETTER_SIZE; PRInt32 orientation = NS_PORTRAIT; PRInt32 fromPage = 1; @@ -268,71 +274,39 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) double dtop = 0.5; double dbottom = 0.5; - if( !globalPrinterList ) - if (InitializeGlobalPrinters()) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - if( globalNumPrinters && !globalPrinterList->Count() ) - return NS_ERROR_OUT_OF_MEMORY; + rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } if (!aQuiet ) { - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - if (NS_SUCCEEDED(rv)) { - PRInt32 buttonPressed = 0; - ioParamBlock->GetInt(0, &buttonPressed); - if (buttonPressed == 0) { - canPrint = PR_TRUE; - } - else { - rv = NS_ERROR_ABORT; - } - } + rv = DisplayXPDialog(mPrintSettings, + "chrome://global/content/printdialog.xul", canPrint); } else { canPrint = PR_TRUE; } - FreeGlobalPrinters(); + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); if (canPrint) { - if (printService) { - printService->GetPrinter(&printer); - printService->GetPrintReversed(&reversed); - printService->GetPrintInColor(&color); - printService->GetPaperSize(&paper_size); - printService->GetOrientation(&orientation); - printService->GetPrintCommand(&command); - printService->GetPrintRange(&printRange); - printService->GetToFileName(&printfile); - printService->GetPrintToFile(&tofile); - printService->GetStartPageRange(&fromPage); - printService->GetEndPageRange(&toPage); - printService->GetNumCopies(&copies); - printService->GetMarginTop(&dtop); - printService->GetMarginLeft(&dleft); - printService->GetMarginBottom(&dbottom); - printService->GetMarginRight(&dright); + if (aPS != nsnull) { + aPS->GetPrinterName(&printer); + aPS->GetPrintReversed(&reversed); + aPS->GetPrintInColor(&color); + aPS->GetPaperSize(&paper_size); + aPS->GetOrientation(&orientation); + aPS->GetPrintCommand(&command); + aPS->GetPrintRange(&printRange); + aPS->GetToFileName(&printfile); + aPS->GetPrintToFile(&tofile); + aPS->GetStartPageRange(&fromPage); + aPS->GetEndPageRange(&toPage); + aPS->GetNumCopies(&copies); + aPS->GetMarginTop(&dtop); + aPS->GetMarginLeft(&dleft); + aPS->GetMarginBottom(&dbottom); + aPS->GetMarginRight(&dright); if (command != nsnull && printfile != nsnull) { // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446) @@ -342,10 +316,18 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) if (printer != nsnull) strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get()); #ifdef DEBUG_rods - printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright); + printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", + dtop, dleft, dbottom, dright); printf("printRange %d\n", printRange); printf("fromPage %d\n", fromPage); printf("toPage %d\n", toPage); + printf("tofile %d\n", tofile); + printf("printfile %s\n", + printfile? NS_ConvertUCS2toUTF8(printfile).get():"NULL"); + printf("command %s\n", + command? NS_ConvertUCS2toUTF8(command).get():"NULL"); + printf("printer %s\n", + printer? NS_ConvertUCS2toUTF8(printer).get():"NULL"); #endif /* DEBUG_rods */ } else { #ifdef VMS @@ -382,9 +364,9 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) } #ifdef NOT_IMPLEMENTED_YET - if (globalNumPrinters) { - for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) { - if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) + if (mGlobalNumPrinters) { + for(int i = 0; (i < mGlobalNumPrinters) && !mQueue; i++) { + if (!(mGlobalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) mQueue = PrnDlg.SetPrinterQueue(i); } } @@ -396,7 +378,6 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) if (printfile != nsnull) { nsMemory::Free(printfile); } - return NS_OK; } @@ -409,7 +390,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetToPrinter(PRBool &aToPrinter) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinter ( char **aPrinter ) +NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinterName ( char **aPrinter ) { *aPrinter = &mPrData.printer[0]; return NS_OK; @@ -535,7 +516,6 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager() return NS_OK; } - // Printer Enumerator nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK() { @@ -544,8 +524,20 @@ nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK() NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator) +NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrintersExtended(PRUint32* aCount, PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + *aCount = 0; + *aResult = nsnull; + return NS_OK; +} + NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) { + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + if (aCount) *aCount = 0; else @@ -556,21 +548,32 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnic else return NS_ERROR_NULL_POINTER; + nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } - PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecGTK::globalNumPrinters * sizeof(PRUnichar*)); - if (!array && nsDeviceContextSpecGTK::globalNumPrinters) + PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); + + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*)); + if (!array && numPrinters > 0) { + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; + } int count = 0; - while( count < nsDeviceContextSpecGTK::globalNumPrinters ) + while( count < numPrinters ) { - PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecGTK::globalPrinterList->StringAt(count)); + + PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count)); if (!str) { for (int i = count - 1; i >= 0; i--) nsMemory::Free(array[i]); nsMemory::Free(array); + + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; } array[count++] = str; @@ -578,14 +581,13 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnic } *aCount = count; *aResult = array; + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_OK; } -NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter) +NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings* aPrintSettings) { - nsresult rv = NS_ERROR_FAILURE; - /* fixme: We simply ignore the |aPrinter| argument here * We should get the supported printer attributes from the printer and * populate the print job options dialog with these data instead of using @@ -594,32 +596,94 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPri * of patches ... ;-( */ - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); + PRBool pressedOK; + return DisplayXPDialog(aPrintSettings, + "chrome://global/content/printjoboptions.xul", + pressedOK); - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - - return rv; } +//---------------------------------------------------------------------- +nsresult GlobalPrinters::InitializeGlobalPrinters () +{ + if (PrintersAreAllocated()) { + return NS_OK; + } + + mGlobalNumPrinters = 0; + mGlobalPrinterList = new nsStringArray(); + if (!mGlobalPrinterList) + return NS_ERROR_OUT_OF_MEMORY; + +#ifdef USE_XPRINT + XPPrinterList plist = XpuGetPrinterList(nsnull, &mGlobalNumPrinters); + + if (plist && (mGlobalNumPrinters > 0)) + { + int i; + for( i = 0 ; i < mGlobalNumPrinters ; i++ ) + { + mGlobalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); + } + + XpuFreePrinterList(plist); + } +#endif /* USE_XPRINT */ + + /* add an entry for the default printer (see nsPostScriptObj.cpp) */ + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); + mGlobalNumPrinters++; + + /* get the list of printers */ + char *printerList = nsnull; + + /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ + printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); + + if (!printerList) { + nsresult rv; + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->CopyCharPref("print.printer_list", &printerList); + } + } + + if (printerList) { + char *tok_lasts; + char *name; + + /* PL_strtok_r() will modify the string - copy it! */ + printerList = strdup(printerList); + if (!printerList) + return NS_ERROR_OUT_OF_MEMORY; + + for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; + name != nsnull ; + name = PL_strtok_r(nsnull, " ", &tok_lasts) ) + { + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + + nsString(NS_ConvertASCIItoUCS2(name))); + mGlobalNumPrinters++; + } + + free(printerList); + } + + if (mGlobalNumPrinters == 0) + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; + + return NS_OK; +} + +//---------------------------------------------------------------------- +void GlobalPrinters::FreeGlobalPrinters() +{ + delete mGlobalPrinterList; + mGlobalPrinterList = nsnull; + mGlobalNumPrinters = 0; +} + + + diff --git a/mozilla/gfx/src/gtk/nsDeviceContextSpecG.h b/mozilla/gfx/src/gtk/nsDeviceContextSpecG.h index 0df9cd93037..c8826f2be03 100644 --- a/mozilla/gfx/src/gtk/nsDeviceContextSpecG.h +++ b/mozilla/gfx/src/gtk/nsDeviceContextSpecG.h @@ -44,6 +44,7 @@ #include "nsIPrintOptions.h" #include "nsVoidArray.h" #include "nsIDeviceContextSpecPS.h" +#include "nsIPrintSettings.h" #ifdef USE_XPRINT #include "nsIDeviceContextSpecXPrint.h" #endif /* USE_XPRINT */ @@ -81,7 +82,7 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); /** @@ -95,7 +96,7 @@ public: NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); - NS_IMETHOD GetPrinter ( char **aPrinter ); + NS_IMETHOD GetPrinterName ( char **aPrinter ); NS_IMETHOD GetCopies ( int &aCopies ); @@ -131,11 +132,8 @@ public: */ virtual ~nsDeviceContextSpecGTK(); - static nsStringArray *globalPrinterList; - static int globalNumPrinters; - int InitializeGlobalPrinters(); - void FreeGlobalPrinters(); protected: + nsCOMPtr mPrintSettings; UnixPrData mPrData; }; diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.cpp b/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.cpp index 8a2eb18eaec..cfdd14e4fdd 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.cpp @@ -41,6 +41,7 @@ #include "nsIPrintingContext.h" #include "nsGfxCIID.h" #include "plstr.h" +#include "nsDeviceContextSpecMac.h" /** ------------------------------------------------------- * Constructor @@ -75,21 +76,23 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryMac :: Init(void) * @update dc 12/02/98 */ NS_IMETHODIMP nsDeviceContextSpecFactoryMac :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { + nsresult rv; static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID); - nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr printingContext = do_QueryInterface(devSpec, &rv); - if (NS_SUCCEEDED(rv)) { - rv = printingContext->Init(aQuiet); - if (NS_SUCCEEDED(rv)) { - aNewSpec = devSpec; - NS_ADDREF(aNewSpec); - } - } - } - return rv; + nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID,&rv); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr printingContext = do_QueryInterface(devSpec,&rv); + if (NS_SUCCEEDED(rv)) { + rv = printingContext->Init(aPrintSettings,aQuiet); + if (NS_SUCCEEDED(rv)) { + aNewSpec = devSpec; + NS_ADDREF(aNewSpec); + } + } + } + return rv; } diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.h b/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.h index a28fd951754..dc4049c723a 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.h +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecFactoryM.h @@ -51,6 +51,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecMac.cpp b/mozilla/gfx/src/mac/nsDeviceContextSpecMac.cpp index 7ab847ecdfe..f83b89ad8ab 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecMac.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecMac.cpp @@ -73,6 +73,7 @@ static long prFirstItem; // our first item in the e static PItemUPP prPItemProc; // store the old item handler here static PRBool gPrintSelection; static UserItemUPP gDrawListUPP = nsnull; +static nsIPrintSettings *gPrintSettings; typedef struct dialog_item_struct { @@ -179,38 +180,38 @@ Handle itemH; if (((TPPrDlg)aDialog)->fDone) { - nsCOMPtr printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1"); + //nsCOMPtr printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1"); // cleanup and set the print options to what we want - if (printOptionsService) + if (gPrintSettings) { // print selection ::GetDialogItem(aDialog, firstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox); value = ::GetControlValue((ControlHandle)itemH); if (1==value){ - printOptionsService->SetPrintRange(nsIPrintOptions::kRangeSelection); + gPrintSettings->SetPrintRange(nsIPrintOptions::kRangeSelection); } else { - printOptionsService->SetPrintRange(nsIPrintOptions::kRangeAllPages); + gPrintSettings->SetPrintRange(nsIPrintOptions::kRangeAllPages); } // print frames as is ::GetDialogItem(aDialog, firstItem+ePrintFrameAsIsCheckboxID-1, &itemType, &itemH, &itemBox); value = ::GetControlValue((ControlHandle)itemH); if (1==value){ - printOptionsService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs); + gPrintSettings->SetPrintFrameType(nsIPrintOptions::kFramesAsIs); } // selected frame ::GetDialogItem(aDialog, firstItem+ePrintSelectedFrameCheckboxID-1, &itemType, &itemH, &itemBox); value = ::GetControlValue((ControlHandle)itemH); if (1==value){ - printOptionsService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame); + gPrintSettings->SetPrintFrameType(nsIPrintOptions::kSelectedFrame); } // print all frames ::GetDialogItem(aDialog, firstItem+ePrintAllFramesCheckboxID-1, &itemType, &itemH, &itemBox); value = ::GetControlValue((ControlHandle)itemH); if (1==value){ - printOptionsService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep); + gPrintSettings->SetPrintFrameType(nsIPrintOptions::kEachFrameSep); } } } @@ -263,11 +264,11 @@ static pascal TPPrDlg MyJobDlgInit(THPrint aHPrint) prFirstItem = AppendToDialog(gPrtJobDialog, DITL_ADDITIONS); - nsCOMPtr printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1"); + //nsCOMPtr printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1"); - if (printOptionsService) { - printOptionsService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); - printOptionsService->GetHowToEnableFrameUI(&howToEnableFrameUI); + if (gPrintSettings) { + gPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + gPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); } ::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox); @@ -324,8 +325,10 @@ static pascal TPPrDlg MyJobDlgInit(THPrint aHPrint) * Initialize the nsDeviceContextSpecMac * @update dc 05/04/2001 */ -NS_IMETHODIMP nsDeviceContextSpecMac::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecMac::Init(nsIPrintSettings* aPS, PRBool aQuiet) { + mPrintSettings = aPS; + #if !TARGET_CARBON if (aQuiet) diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecMac.h b/mozilla/gfx/src/mac/nsDeviceContextSpecMac.h index c263c3e3106..11ca9760c97 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecMac.h +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecMac.h @@ -42,6 +42,7 @@ #include "nsIDeviceContextSpec.h" #include "nsIPrintingContext.h" #include "nsDeviceContextMac.h" +#include "nsIPrintSettings.h" #include class nsDeviceContextSpecMac : public nsIDeviceContextSpec, public nsIPrintingContext { @@ -64,8 +65,9 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); + /** * This will tell if the printmanager is currently open * @update dc 12/03/98 @@ -100,8 +102,11 @@ protected: virtual ~nsDeviceContextSpecMac(); protected: - THPrint mPrtRec; // the print record - PRBool mPrintManagerOpen; // tells if the print manager is open + THPrint mPrtRec; // the print record + PRBool mPrintManagerOpen; // tells if the print manager is open + nsIPrintSettings *mPrintSettings; + + #if !TARGET_CARBON // pinkerton - obsolete APIs. Doesn't exist in carbon TPrPort* mPrinterPort; diff --git a/mozilla/gfx/src/makefile.win b/mozilla/gfx/src/makefile.win index 09ae4306f6e..c0674c9e7b0 100644 --- a/mozilla/gfx/src/makefile.win +++ b/mozilla/gfx/src/makefile.win @@ -56,6 +56,7 @@ CPP_OBJS=.\$(OBJDIR)\nsColor.obj \ .\$(OBJDIR)\nsRenderingContextImpl.obj \ .\$(OBJDIR)\nsScriptableRegion.obj \ .\$(OBJDIR)\nsPrintOptionsImpl.obj \ + .\$(OBJDIR)\nsPrintSettingsImpl.obj \ $(NULL) diff --git a/mozilla/gfx/src/nsPrintOptionsImpl.cpp b/mozilla/gfx/src/nsPrintOptionsImpl.cpp index cd12819989c..daa95cf00bf 100644 --- a/mozilla/gfx/src/nsPrintOptionsImpl.cpp +++ b/mozilla/gfx/src/nsPrintOptionsImpl.cpp @@ -41,6 +41,7 @@ #include "nsCoord.h" #include "nsUnitConversion.h" #include "nsReadableUtils.h" +#include "nsPrintSettingsImpl.h" // For Prefs #include "nsIPref.h" @@ -71,9 +72,15 @@ const char kPrintFooterStr2[] = "print.print_footercenter"; const char kPrintFooterStr3[] = "print.print_footerright"; // Additional Prefs +const char kPrintPaperSize[] = "print.print_paper_size"; // this has been deprecated + const char kPrintReversed[] = "print.print_reversed"; const char kPrintColor[] = "print.print_color"; -const char kPrintPaperSize[] = "print.print_paper_size"; +const char kPrintPaperSizeType[] = "print.print_paper_size_type"; +const char kPrintPaperData[] = "print.print_paper_data"; +const char kPrintPaperSizeUnit[] = "print.print_paper_size_unit"; +const char kPrintPaperWidth[] = "print.print_paper_width"; +const char kPrintPaperHeight[]= "print.print_paper_height"; const char kPrintOrientation[]= "print.print_orientation"; const char kPrintCommand[] = "print.print_command"; const char kPrinter[] = "print.print_printer"; @@ -105,16 +112,24 @@ nsPrintOptions::nsPrintOptions() : mEndPageNum(1), mScaling(1.0), mNumCopies(1), + mPrintFrameTypeUsage(kUseInternalDefault), mPrintFrameType(kFramesAsIs), mHowToEnableFrameUI(kFrameEnableNone), mIsCancelled(PR_FALSE), mPrintSilent(PR_FALSE), mPrintPageDelay(500), + mPrintSettingsObj(nsnull), + mPaperSizeType(kPaperSizeDefined), + mPaperData(0), + mPaperWidth(8.5), + mPaperHeight(11.0), + mPaperSizeUnit(kPaperSizeInches), + mPaperSize(kLetterPaperSize), /* this has been deprecated */ mPrintReversed(PR_FALSE), mPrintInColor(PR_TRUE), - mPaperSize(kLetterPaperSize), mOrientation(kPortraitOrientation), - mPrintToFile(PR_FALSE) + mPrintToFile(PR_FALSE), + mIsExtendedInfo(PR_FALSE) { NS_INIT_ISUPPORTS(); @@ -152,6 +167,9 @@ nsPrintOptions::~nsPrintOptions() } +//************************************************************** +//** PageList Enumerator +//************************************************************** class nsPrinterListEnumerator : public nsISimpleEnumerator { @@ -165,7 +183,7 @@ nsPrinterListEnumerator : public nsISimpleEnumerator //nsISimpleEnumerator interface NS_DECL_NSISIMPLEENUMERATOR - NS_IMETHOD Init(); + NS_IMETHOD Init(PRBool& aIsExtendedInfo); protected: PRUnichar **mPrinters; @@ -192,7 +210,7 @@ nsPrinterListEnumerator::~nsPrinterListEnumerator() NS_IMPL_ISUPPORTS1(nsPrinterListEnumerator, nsISimpleEnumerator) -NS_IMETHODIMP nsPrinterListEnumerator::Init( ) +NS_IMETHODIMP nsPrinterListEnumerator::Init(PRBool& aIsExtended) { nsresult rv; nsCOMPtr printerEnumerator; @@ -201,7 +219,16 @@ NS_IMETHODIMP nsPrinterListEnumerator::Init( ) if (NS_FAILED(rv)) return rv; - rv = printerEnumerator->EnumeratePrinters(&mCount, &mPrinters); + // First check to see if we can get the extended printer informations + // if not then get the regular + + rv = printerEnumerator->EnumeratePrintersExtended(&mCount, &mPrinters); + if (NS_SUCCEEDED(rv) && mCount > 0) { + aIsExtended = PR_TRUE; + } else { + aIsExtended = PR_FALSE; + rv = printerEnumerator->EnumeratePrinters(&mCount, &mPrinters); + } return rv; } @@ -295,6 +322,23 @@ nsPrintOptions::GetMarginInTwips(nsMargin& aMargin) return NS_OK; } +/** --------------------------------------------------- + * See documentation in nsPrintOptionsImpl.h + * @update 6/21/00 dwc + */ +NS_IMETHODIMP +nsPrintOptions::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) +{ + if (mPaperSizeUnit == kPaperSizeInches) { + *aWidth = NS_INCHES_TO_TWIPS(float(mPaperWidth)); + *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight)); + } else { + *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth)); + *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight)); + } + return NS_OK; +} + /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h * @update 6/21/00 dwc @@ -344,7 +388,6 @@ nsPrintOptions::GetPrintOptionsBits(PRInt32 *aBits) return NS_OK; } - /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h * @update 1/12/01 rods @@ -370,9 +413,23 @@ nsPrintOptions::ReadPrefs() ReadPrefString(prefs, kPrintFooterStr3, mFooterStrs[2]); // Read Additional XP Prefs + prefs->GetIntPref(kPrintPaperSize, &mPaperSize); // this has been deprecated + prefs->GetBoolPref(kPrintReversed, &mPrintReversed); prefs->GetBoolPref(kPrintColor, &mPrintInColor); - prefs->GetIntPref(kPrintPaperSize, &mPaperSize); + + PRInt32 iVal = kPaperSizeInches; + prefs->GetIntPref(kPrintPaperSizeUnit, &iVal); + mPaperSizeUnit = PRInt16(iVal); + iVal = kPaperSizeDefined; + prefs->GetIntPref(kPrintPaperSizeType, &iVal); + mPaperSizeType = PRInt16(iVal); + iVal = 0; + prefs->GetIntPref(kPrintPaperData, &iVal); + mPaperData = PRInt16(iVal); + ReadPrefDouble(prefs, kPrintPaperWidth, mPaperWidth); + ReadPrefDouble(prefs, kPrintPaperHeight, mPaperHeight); + prefs->GetIntPref(kPrintOrientation, &mOrientation); ReadPrefString(prefs, kPrintCommand, mPrintCommand); ReadPrefString(prefs, kPrinter, mPrinter); @@ -385,6 +442,110 @@ nsPrintOptions::ReadPrefs() return NS_ERROR_FAILURE; } +/** --------------------------------------------------- + * See documentation in nsPrintOptionsImpl.h + * @update 1/12/01 rods + */ +NS_IMETHODIMP +nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS) +{ + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + if (prefs) { + nsMargin margin; + ReadInchesToTwipsPref(prefs, kMarginTop, margin.top); + ReadInchesToTwipsPref(prefs, kMarginLeft, margin.left); + ReadInchesToTwipsPref(prefs, kMarginBottom, margin.bottom); + ReadInchesToTwipsPref(prefs, kMarginRight, margin.right); + aPS->SetMarginInTwips(margin); + + PRBool b; + prefs->GetBoolPref(kPrintEvenPages, &b); + aPS->SetPrintOptions(kOptPrintEvenPages, b); + + prefs->GetBoolPref(kPrintOddPages, &b); + aPS->SetPrintOptions(kOptPrintOddPages, b); + + nsString str; + str.SetLength(0); + ReadPrefString(prefs, kPrintHeaderStr1, str); + aPS->SetHeaderStrLeft(str.get()); + str.SetLength(0); + ReadPrefString(prefs, kPrintHeaderStr2, str); + aPS->SetHeaderStrCenter(str.get()); + str.SetLength(0); + ReadPrefString(prefs, kPrintHeaderStr3, str); + aPS->SetHeaderStrRight(str.get()); + + str.SetLength(0); + ReadPrefString(prefs, kPrintFooterStr1, str); + aPS->SetFooterStrRight(str.get()); + str.SetLength(0); + ReadPrefString(prefs, kPrintFooterStr2, str); + aPS->SetFooterStrCenter(str.get()); + str.SetLength(0); + ReadPrefString(prefs, kPrintFooterStr3, str); + aPS->SetFooterStrRight(str.get()); + + // Read Additional XP Prefs + PRInt32 iVal = kLetterPaperSize; + prefs->GetIntPref(kPrintPaperSize, &iVal); // this has been deprecated + aPS->SetPaperSize(iVal); + + b = PR_FALSE; + prefs->GetBoolPref(kPrintReversed, &b); + aPS->SetPrintReversed(b); + + b = PR_TRUE; + prefs->GetBoolPref(kPrintColor, &b); + aPS->SetPrintInColor(b); + + iVal = kPaperSizeInches; + prefs->GetIntPref(kPrintPaperSizeUnit, &iVal); + aPS->SetPaperSizeUnit(iVal); + + iVal = kPaperSizeDefined; + prefs->GetIntPref(kPrintPaperSizeType, &iVal); + aPS->SetPaperSizeType(iVal); + + iVal = 0; + prefs->GetIntPref(kPrintPaperData, &iVal); + aPS->SetPaperData(iVal); + + double d = 8.5; + ReadPrefDouble(prefs, kPrintPaperWidth, d); + aPS->SetPaperWidth(d); + + d = 11.0; + ReadPrefDouble(prefs, kPrintPaperHeight, d); + aPS->SetPaperHeight(d); + + iVal = kPortraitOrientation; + prefs->GetIntPref(kPrintOrientation, &mOrientation); + aPS->SetOrientation(iVal); + + str.SetLength(0); + ReadPrefString(prefs, kPrintCommand, str); + aPS->SetPrintCommand(str.get()); + + str.SetLength(0); + ReadPrefString(prefs, kPrinter, mPrinter); + aPS->SetPrinterName(str.get()); + + b = PR_FALSE; + prefs->GetBoolPref(kPrintFile, &b); + aPS->SetPrintToFile(b); + + ReadPrefString(prefs, kPrintToFile, mToFileName); + + iVal = 500; + prefs->GetIntPref(kPrintPageDelay, &iVal); + aPS->SetPrintPageDelay(iVal); + + return NS_OK; + } + return NS_ERROR_FAILURE; +} + /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h * @update 1/12/01 rods @@ -410,9 +571,15 @@ nsPrintOptions::WritePrefs() WritePrefString(prefs, kPrintFooterStr3, mFooterStrs[2]); // Write Additional XP Prefs + prefs->SetIntPref(kPrintPaperSize, mPaperSize); // this has been deprecated + prefs->SetBoolPref(kPrintReversed, mPrintReversed); prefs->SetBoolPref(kPrintColor, mPrintInColor); - prefs->SetIntPref(kPrintPaperSize, mPaperSize); + prefs->SetIntPref(kPrintPaperSizeUnit, PRInt32(mPaperSizeUnit)); + prefs->SetIntPref(kPrintPaperSizeType, PRInt32(mPaperSizeType)); + prefs->SetIntPref(kPrintPaperData, PRInt32(mPaperData)); + WritePrefDouble(prefs, kPrintPaperWidth, mPaperWidth); + WritePrefDouble(prefs, kPrintPaperHeight, mPaperHeight); prefs->SetIntPref(kPrintOrientation, mOrientation); WritePrefString(prefs, kPrintCommand, mPrintCommand); WritePrefString(prefs, kPrinter, mPrinter); @@ -477,19 +644,6 @@ NS_IMETHODIMP nsPrintOptions::SetPrintInColor(PRBool aPrintInColor) return NS_OK; } -/* attribute short paperSize; */ -NS_IMETHODIMP nsPrintOptions::GetPaperSize(PRInt32 *aPaperSize) -{ - //NS_ENSURE_ARG_POINTER(aPaperSize); - *aPaperSize = mPaperSize; - return NS_OK; -} -NS_IMETHODIMP nsPrintOptions::SetPaperSize(PRInt32 aPaperSize) -{ - mPaperSize = aPaperSize; - return NS_OK; -} - /* attribute wstring printCommand; */ NS_IMETHODIMP nsPrintOptions::GetPrintCommand(PRUnichar * *aPrintCommand) { @@ -517,13 +671,13 @@ NS_IMETHODIMP nsPrintOptions::SetOrientation(PRInt32 aOrientation) } /* attribute wstring printer; */ -NS_IMETHODIMP nsPrintOptions::GetPrinter(PRUnichar * *aPrinter) +NS_IMETHODIMP nsPrintOptions::GetPrinterName(PRUnichar * *aPrinter) { //NS_ENSURE_ARG_POINTER(aPrinter); *aPrinter = ToNewUnicode(mPrinter); return NS_OK; } -NS_IMETHODIMP nsPrintOptions::SetPrinter(const PRUnichar * aPrinter) +NS_IMETHODIMP nsPrintOptions::SetPrinterName(const PRUnichar * aPrinter) { mPrinter = aPrinter; return NS_OK; @@ -543,22 +697,33 @@ NS_IMETHODIMP nsPrintOptions::SetNumCopies(PRInt32 aNumCopies) } /* create and return a new |nsPrinterListEnumerator| */ -NS_IMETHODIMP nsPrintOptions::AvailablePrinters( nsISimpleEnumerator **aPrinterEnumerator) +NS_IMETHODIMP nsPrintOptions::AvailablePrinters(nsISimpleEnumerator **aPrinterEnumerator) { NS_ENSURE_ARG_POINTER(aPrinterEnumerator); + *aPrinterEnumerator = nsnull; + nsCOMPtr printerListEnum = new nsPrinterListEnumerator(); NS_ENSURE_TRUE(printerListEnum.get(), NS_ERROR_OUT_OF_MEMORY); - nsresult rv = printerListEnum->Init(); - NS_ENSURE_SUCCESS(rv, rv); - - *aPrinterEnumerator = NS_STATIC_CAST(nsISimpleEnumerator*, printerListEnum); - NS_ADDREF(*aPrinterEnumerator); + // if Init fails NS_OK is return (script needs NS_OK) but the enumerator will be null + nsresult rv = printerListEnum->Init(mIsExtendedInfo); + if (NS_SUCCEEDED(rv)) { + *aPrinterEnumerator = NS_STATIC_CAST(nsISimpleEnumerator*, printerListEnum); + NS_ADDREF(*aPrinterEnumerator); + } return NS_OK; - } -NS_IMETHODIMP nsPrintOptions::DisplayJobProperties( const PRUnichar *aPrinter, PRBool *aDisplayed) +/* readonly attribute boolean isExtended; */ +NS_IMETHODIMP nsPrintOptions::GetIsExtended(PRBool *aIsExtended) +{ + NS_ENSURE_ARG(aIsExtended); + *aIsExtended = mIsExtendedInfo; + return NS_OK; +} + + +NS_IMETHODIMP nsPrintOptions::DisplayJobProperties( const PRUnichar *aPrinter, nsIPrintSettings* aPrintSettings, PRBool *aDisplayed) { NS_ENSURE_ARG(aPrinter); *aDisplayed = PR_FALSE; @@ -570,7 +735,7 @@ NS_IMETHODIMP nsPrintOptions::DisplayJobProperties( const PRUnichar *aPrinter, P if (NS_FAILED(rv)) return rv; - if (NS_FAILED(propDlg->DisplayPropertiesDlg((PRUnichar*)aPrinter))) + if (NS_FAILED(propDlg->DisplayPropertiesDlg((PRUnichar*)aPrinter, aPrintSettings))) return rv; *aDisplayed = PR_TRUE; @@ -874,7 +1039,7 @@ NS_IMETHODIMP nsPrintOptions::SetHowToEnableFrameUI(PRInt16 aHowToEnableFrameUI) NS_IMETHODIMP nsPrintOptions::GetPrintFrameType(PRInt16 *aPrintFrameType) { NS_ENSURE_ARG_POINTER(aPrintFrameType); - *aPrintFrameType = (PRInt32)mPrintFrameType; + *aPrintFrameType = mPrintFrameType; return NS_OK; } NS_IMETHODIMP nsPrintOptions::SetPrintFrameType(PRInt16 aPrintFrameType) @@ -883,6 +1048,19 @@ NS_IMETHODIMP nsPrintOptions::SetPrintFrameType(PRInt16 aPrintFrameType) return NS_OK; } +/* attribute short printFrameTypeUsage; */ +NS_IMETHODIMP nsPrintOptions::GetPrintFrameTypeUsage(PRInt16 *aPrintFrameTypeUsage) +{ + NS_ENSURE_ARG_POINTER(aPrintFrameTypeUsage); + *aPrintFrameTypeUsage = mPrintFrameTypeUsage; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPrintFrameTypeUsage(PRInt16 aPrintFrameTypeUsage) +{ + mPrintFrameTypeUsage = aPrintFrameTypeUsage; + return NS_OK; +} + /* attribute long isCancelled; */ NS_IMETHODIMP nsPrintOptions::GetIsCancelled(PRBool *aIsCancelled) { @@ -923,95 +1101,299 @@ NS_IMETHODIMP nsPrintOptions::GetNativeData(PRInt16 aDataType, void * *_retval) NS_IMETHODIMP nsPrintOptions::GetPrintSettings(nsIPrintSettings * *aPrintSettings) { NS_ENSURE_ARG_POINTER(aPrintSettings); - *aPrintSettings = nsnull; - - /* This may need to be implemented in the future */ - return NS_ERROR_NOT_IMPLEMENTED; + *aPrintSettings = mPrintSettingsObj; + return NS_OK; } NS_IMETHODIMP nsPrintOptions::SetPrintSettings(nsIPrintSettings * aPrintSettings) { - NS_ENSURE_ARG_POINTER(aPrintSettings); + mPrintSettingsObj = aPrintSettings; + return NS_OK; +} - aPrintSettings->GetStartPageRange(&mStartPageNum); - aPrintSettings->GetEndPageRange(&mEndPageNum); +/* attribute nsIPrintSettings printSettingsValues; */ +NS_IMETHODIMP nsPrintOptions::GetPrintSettingsValues(nsIPrintSettings * *aPrintSettingsValues) +{ + NS_ENSURE_ARG_POINTER(aPrintSettingsValues); + nsIPrintSettings* printSettingsValues = *aPrintSettingsValues; + if (printSettingsValues == nsnull) { + if (NS_SUCCEEDED(CreatePrintSettings(&printSettingsValues))) { + *aPrintSettingsValues = printSettingsValues; + } else { + return NS_ERROR_FAILURE; + } + } + + printSettingsValues->SetStartPageRange(mStartPageNum); + printSettingsValues->SetEndPageRange(mEndPageNum); double dblVal; - aPrintSettings->GetMarginTop(&dblVal); - SetMarginTop(dblVal); + GetMarginTop(&dblVal); + printSettingsValues->SetMarginTop(dblVal); - aPrintSettings->GetMarginLeft(&dblVal); - SetMarginLeft(dblVal); + GetMarginLeft(&dblVal); + printSettingsValues->SetMarginLeft(dblVal); - aPrintSettings->GetMarginBottom(&dblVal); - SetMarginBottom(dblVal); + GetMarginBottom(&dblVal); + printSettingsValues->SetMarginBottom(dblVal); - aPrintSettings->GetMarginRight(&dblVal); - SetMarginRight(dblVal); + GetMarginRight(&dblVal); + printSettingsValues->SetMarginRight(dblVal); - aPrintSettings->GetScaling(&mScaling); - aPrintSettings->GetPrintBGColors(&mPrintBGColors); - aPrintSettings->GetPrintBGImages(&mPrintBGImages); + printSettingsValues->SetScaling(mScaling); + printSettingsValues->SetPrintBGColors(mPrintBGColors); + printSettingsValues->SetPrintBGImages(mPrintBGImages); - aPrintSettings->GetPrintRange(&mPrintRange); + printSettingsValues->SetPrintRange(mPrintRange); PRUnichar* uniChar; - aPrintSettings->GetTitle(&uniChar); + GetTitle(&uniChar); + printSettingsValues->SetTitle(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetDocURL(&uniChar); + printSettingsValues->SetDocURL(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetHeaderStrLeft(&uniChar); + printSettingsValues->SetHeaderStrLeft(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetHeaderStrCenter(&uniChar); + printSettingsValues->SetHeaderStrCenter(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetHeaderStrRight(&uniChar); + printSettingsValues->SetHeaderStrRight(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetFooterStrLeft(&uniChar); + printSettingsValues->SetFooterStrLeft(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetFooterStrCenter(&uniChar); + printSettingsValues->SetFooterStrCenter(uniChar); + + GetFooterStrRight(&uniChar); + printSettingsValues->SetFooterStrRight(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + printSettingsValues->SetPrintFrameTypeUsage(mPrintFrameTypeUsage); + printSettingsValues->SetPrintFrameType(mPrintFrameType); + printSettingsValues->SetPrintSilent(mPrintSilent); + printSettingsValues->SetPrintReversed(mPrintReversed); + printSettingsValues->SetPrintInColor(mPrintInColor); + printSettingsValues->SetPaperSizeUnit(mPaperSizeUnit); + printSettingsValues->SetPaperHeight(mPaperHeight); + printSettingsValues->SetPaperWidth(mPaperWidth); + printSettingsValues->SetOrientation(mOrientation); + printSettingsValues->SetNumCopies(mNumCopies); + + GetPrinterName(&uniChar); + printSettingsValues->SetPrinterName(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + GetPrintCommand(&uniChar); + printSettingsValues->SetPrintCommand(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + printSettingsValues->SetPrintToFile(mPrintToFile); + + GetToFileName(&uniChar); + printSettingsValues->SetToFileName(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + printSettingsValues->SetPrintPageDelay(mPrintPageDelay); + + return NS_OK; +} + +NS_IMETHODIMP nsPrintOptions::SetPrintSettingsValues(nsIPrintSettings * aPrintSettingsValues) +{ + + NS_ENSURE_ARG_POINTER(aPrintSettingsValues); + + aPrintSettingsValues->GetStartPageRange(&mStartPageNum); + aPrintSettingsValues->GetEndPageRange(&mEndPageNum); + + double dblVal; + aPrintSettingsValues->GetMarginTop(&dblVal); + SetMarginTop(dblVal); + + aPrintSettingsValues->GetMarginLeft(&dblVal); + SetMarginLeft(dblVal); + + aPrintSettingsValues->GetMarginBottom(&dblVal); + SetMarginBottom(dblVal); + + aPrintSettingsValues->GetMarginRight(&dblVal); + SetMarginRight(dblVal); + + aPrintSettingsValues->GetScaling(&mScaling); + aPrintSettingsValues->GetPrintBGColors(&mPrintBGColors); + aPrintSettingsValues->GetPrintBGImages(&mPrintBGImages); + + aPrintSettingsValues->GetPrintRange(&mPrintRange); + + PRUnichar* uniChar; + aPrintSettingsValues->GetTitle(&uniChar); SetTitle(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetDocURL(&uniChar); + aPrintSettingsValues->GetDocURL(&uniChar); SetDocURL(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetHeaderStrLeft(&uniChar); + aPrintSettingsValues->GetHeaderStrLeft(&uniChar); SetHeaderStrLeft(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetHeaderStrCenter(&uniChar); + aPrintSettingsValues->GetHeaderStrCenter(&uniChar); SetHeaderStrCenter(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetHeaderStrRight(&uniChar); + aPrintSettingsValues->GetHeaderStrRight(&uniChar); SetHeaderStrRight(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetFooterStrLeft(&uniChar); + aPrintSettingsValues->GetFooterStrLeft(&uniChar); SetFooterStrLeft(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetFooterStrCenter(&uniChar); + aPrintSettingsValues->GetFooterStrCenter(&uniChar); SetFooterStrCenter(uniChar); - aPrintSettings->GetFooterStrRight(&uniChar); + aPrintSettingsValues->GetFooterStrRight(&uniChar); SetFooterStrRight(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetPrintFrameType(&mPrintFrameType); - aPrintSettings->GetPrintSilent(&mPrintSilent); - aPrintSettings->GetPrintReversed(&mPrintReversed); - aPrintSettings->GetPrintInColor(&mPrintInColor); - aPrintSettings->GetPaperSize(&mPaperSize); - aPrintSettings->GetOrientation(&mOrientation); + aPrintSettingsValues->GetPrintFrameTypeUsage(&mPrintFrameTypeUsage); + aPrintSettingsValues->GetPrintFrameType(&mPrintFrameType); + aPrintSettingsValues->GetPrintSilent(&mPrintSilent); + aPrintSettingsValues->GetPrintReversed(&mPrintReversed); + aPrintSettingsValues->GetPrintInColor(&mPrintInColor); + aPrintSettingsValues->GetPaperSizeUnit(&mPaperSizeUnit); + aPrintSettingsValues->GetPaperHeight(&mPaperHeight); + aPrintSettingsValues->GetPaperWidth(&mPaperWidth); + aPrintSettingsValues->GetOrientation(&mOrientation); + aPrintSettingsValues->GetNumCopies(&mNumCopies); - aPrintSettings->GetPrintCommand(&uniChar); + aPrintSettingsValues->GetPrinterName(&uniChar); + SetPrinterName(uniChar); + if (uniChar != nsnull) nsMemory::Free(uniChar); + + aPrintSettingsValues->GetPrintCommand(&uniChar); SetPrintCommand(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetPrintToFile(&mPrintToFile); + aPrintSettingsValues->GetPrintToFile(&mPrintToFile); - aPrintSettings->GetToFileName(&uniChar); + aPrintSettingsValues->GetToFileName(&uniChar); SetToFileName(uniChar); if (uniChar != nsnull) nsMemory::Free(uniChar); - aPrintSettings->GetPrintPageDelay(&mPrintPageDelay); + aPrintSettingsValues->GetPrintPageDelay(&mPrintPageDelay); SetPrintPageDelay(mPrintPageDelay); return NS_OK; } +/* attribute double paperWidth; */ +NS_IMETHODIMP nsPrintOptions::GetPaperWidth(double *aPaperWidth) +{ + NS_ENSURE_ARG_POINTER(aPaperWidth); + *aPaperWidth = mPaperWidth; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPaperWidth(double aPaperWidth) +{ + mPaperWidth = aPaperWidth; + return NS_OK; +} + +/* attribute double paperHeight; */ +NS_IMETHODIMP nsPrintOptions::GetPaperHeight(double *aPaperHeight) +{ + NS_ENSURE_ARG_POINTER(aPaperHeight); + *aPaperHeight = mPaperHeight; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPaperHeight(double aPaperHeight) +{ + mPaperHeight = aPaperHeight; + return NS_OK; +} + +/* attribute short PaperSizeUnit; */ +NS_IMETHODIMP nsPrintOptions::GetPaperSizeUnit(PRInt16 *aPaperSizeUnit) +{ + NS_ENSURE_ARG_POINTER(aPaperSizeUnit); + *aPaperSizeUnit = mPaperSizeUnit; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPaperSizeUnit(PRInt16 aPaperSizeUnit) +{ + mPaperSizeUnit = aPaperSizeUnit; + return NS_OK; +} + +/* attribute short PaperSizeType; */ +NS_IMETHODIMP nsPrintOptions::GetPaperSizeType(PRInt16 *aPaperSizeType) +{ + NS_ENSURE_ARG_POINTER(aPaperSizeType); + *aPaperSizeType = mPaperSizeType; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPaperSizeType(PRInt16 aPaperSizeType) +{ + mPaperSizeType = aPaperSizeType; + return NS_OK; +} + +/* attribute short PaperData; */ +NS_IMETHODIMP nsPrintOptions::GetPaperData(PRInt16 *aPaperData) +{ + NS_ENSURE_ARG_POINTER(aPaperData); + *aPaperData = mPaperData; + return NS_OK; +} +NS_IMETHODIMP nsPrintOptions::SetPaperData(PRInt16 aPaperData) +{ + mPaperData = aPaperData; + return NS_OK; +} + +/* This has been deprecated */ +NS_IMETHODIMP nsPrintOptions::GetPaperSize(PRInt32 *aPaperSize) +{ + *aPaperSize = mPaperSize; + return NS_OK; +} +/* This has been deprecated */ +NS_IMETHODIMP nsPrintOptions::SetPaperSize(PRInt32 aPaperSize) +{ + mPaperSize = aPaperSize; + return NS_OK; +} + +/* nsIPrintSettings CreatePrintSettings (); */ +NS_IMETHODIMP nsPrintOptions::CreatePrintSettings(nsIPrintSettings **_retval) +{ + nsresult rv = NS_OK; + nsPrintSettings* printSettings = new nsPrintSettings(); // does not initially ref count + NS_ASSERTION(printSettings, "Can't be NULL!"); + + rv = printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + InitPrintSettingsFromPrefs(*_retval); // ignore return value + + return rv; +} + + //----------------------------------------------------- //-- Protected Methods //----------------------------------------------------- @@ -1043,6 +1425,31 @@ nsresult nsPrintOptions::WritePrefString(nsIPref * aPref, return rv; } +nsresult nsPrintOptions::ReadPrefDouble(nsIPref * aPref, + const char * aPrefId, + double& aVal) +{ + char * str = nsnull; + nsresult rv = aPref->CopyCharPref(aPrefId, &str); + if (NS_SUCCEEDED(rv) && str) { + sscanf(str, "%6.2", &aVal); + nsMemory::Free(str); + } + return rv; +} + +nsresult nsPrintOptions::WritePrefDouble(nsIPref * aPref, + const char * aPrefId, + double aVal) +{ + NS_ENSURE_ARG_POINTER(aPref); + NS_ENSURE_ARG_POINTER(aPrefId); + + char str[64]; + sprintf(str, "%6.2f", aVal); + return aPref->SetCharPref(aPrefId, str); +} + void nsPrintOptions::ReadBitFieldPref(nsIPref * aPref, const char * aPrefId, PRInt32 anOption) diff --git a/mozilla/gfx/src/nsPrintOptionsImpl.h b/mozilla/gfx/src/nsPrintOptionsImpl.h index a3f9201253d..17a1ecfca0c 100644 --- a/mozilla/gfx/src/nsPrintOptionsImpl.h +++ b/mozilla/gfx/src/nsPrintOptionsImpl.h @@ -50,6 +50,8 @@ protected: nsresult ReadPrefString(nsIPref * aPref, const char * aPrefId, nsString& aString); nsresult WritePrefString(nsIPref * aPref, const char * aPrefId, nsString& aString); + nsresult ReadPrefDouble(nsIPref * aPref, const char * aPrefId, double& aVal); + nsresult WritePrefDouble(nsIPref * aPref, const char * aPrefId, double aVal); typedef enum { eHeader, @@ -71,6 +73,7 @@ protected: PRBool mPrintBGColors; // print background colors PRBool mPrintBGImages; // print background images + PRInt16 mPrintFrameTypeUsage; PRInt16 mPrintFrameType; PRBool mHowToEnableFrameUI; PRBool mIsCancelled; @@ -83,9 +86,17 @@ protected: nsString mHeaderStrs[3]; nsString mFooterStrs[3]; + nsIPrintSettings* mPrintSettingsObj; //weak ref, hold address only + + PRInt16 mPaperData; + PRInt16 mPaperSizeType; + double mPaperWidth; + double mPaperHeight; + PRInt16 mPaperSizeUnit; + + PRInt32 mPaperSize; // this has been deprecated PRBool mPrintReversed; PRBool mPrintInColor; // a false means grayscale - PRInt32 mPaperSize; // see page size consts PRInt32 mOrientation; // see orientation consts nsString mPrintCommand; PRInt32 mNumCopies; @@ -93,6 +104,8 @@ protected: PRBool mPrintToFile; nsString mToFileName; + PRBool mIsExtendedInfo; + static nsFont* sDefaultFont; }; diff --git a/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.cpp b/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.cpp index f0688492c35..db814f455c3 100644 --- a/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.cpp +++ b/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.cpp @@ -61,6 +61,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryOS2 :: Init(void) //XXX this method needs to do what the API says... NS_IMETHODIMP nsDeviceContextSpecFactoryOS2 :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { @@ -69,7 +70,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryOS2 :: CreateDeviceContextSpec(nsIWidget nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); if (NS_SUCCEEDED(rv)) { - rv = ((nsDeviceContextSpecOS2 *)devSpec.get())->Init(aQuiet); + rv = ((nsDeviceContextSpecOS2 *)devSpec.get())->Init(aPrintSettings, aQuiet); if (NS_SUCCEEDED(rv)) { aNewSpec = devSpec; NS_ADDREF(aNewSpec); diff --git a/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.h b/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.h index 151bd6c95b0..6362f83d3d4 100644 --- a/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.h +++ b/mozilla/gfx/src/os2/nsDeviceContextSpecFactoryO.h @@ -52,6 +52,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.cpp b/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.cpp index 2dfd778e0b9..495d39610fb 100644 --- a/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.cpp +++ b/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.cpp @@ -22,12 +22,8 @@ #include "nsDeviceContextSpecOS2.h" -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" -#include "nsGfxDefs.h" #include "nsReadableUtils.h" +#include "nsISupportsArray.h" #include "nsIPref.h" #include "prenv.h" /* for PR_GetEnv */ @@ -39,10 +35,9 @@ #include "nsIWindowWatcher.h" #include "nsIDOMWindowInternal.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); - nsStringArray* nsDeviceContextSpecOS2::globalPrinterList = nsnull; int nsDeviceContextSpecOS2::globalNumPrinters = 0; + PRINTDLG nsDeviceContextSpecOS2::PrnDlg; /** ------------------------------------------------------- @@ -114,7 +109,7 @@ int nsDeviceContextSpecOS2::InitializeGlobalPrinters () { globalNumPrinters = PrnDlg.GetNumPrinters(); if (!globalNumPrinters) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; globalPrinterList = new nsStringArray(); if (!globalPrinterList) @@ -161,17 +156,17 @@ void nsDeviceContextSpecOS2::FreeGlobalPrinters () * * ** Please update the other toolkits when changing this function. */ -NS_IMETHODIMP nsDeviceContextSpecOS2::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecOS2::Init(nsIPrintSettings* aPS, PRBool aQuiet) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); - NS_ASSERTION(nsnull != printService, "No print service."); - + mPrintSettings = aPS; + NS_ASSERTION(aPS, "Must have a PrintSettings!"); + // if there is a current selection then enable the "Selection" radio button - if (NS_SUCCEEDED(rv) && printService) { + if (aPS != nsnull) { PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); + aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); @@ -181,7 +176,7 @@ NS_IMETHODIMP nsDeviceContextSpecOS2::Init(PRBool aQuiet) char *path; PRBool canPrint = PR_FALSE; PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintOptions::kRangeAllPages; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 fromPage = 1; PRInt32 toPage = 1; PRInt32 copies = 1; @@ -190,39 +185,50 @@ NS_IMETHODIMP nsDeviceContextSpecOS2::Init(PRBool aQuiet) if( !globalPrinterList ) if (InitializeGlobalPrinters()) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; if( globalNumPrinters && !globalPrinterList->Count() ) return NS_ERROR_OUT_OF_MEMORY; if ( !aQuiet ) { rv = NS_ERROR_FAILURE; + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; + + nsCOMPtr ps = aPS; + nsCOMPtr psSupports(do_QueryInterface(ps)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); + wwatch->GetActiveWindow(getter_AddRefs(active)); nsCOMPtr parent = do_QueryInterface(active); nsCOMPtr newWindow; rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); } } + if (NS_SUCCEEDED(rv)) { PRInt32 buttonPressed = 0; ioParamBlock->GetInt(0, &buttonPressed); - if (buttonPressed == 0) + if (buttonPressed == 1) canPrint = PR_TRUE; else { @@ -235,14 +241,14 @@ NS_IMETHODIMP nsDeviceContextSpecOS2::Init(PRBool aQuiet) } if (canPrint) { - if (printService) { - printService->GetPrinter(&printer); - printService->GetPrintRange(&printRange); - printService->GetToFileName(&printfile); - printService->GetPrintToFile(&tofile); - printService->GetStartPageRange(&fromPage); - printService->GetEndPageRange(&toPage); - printService->GetNumCopies(&copies); + if (mPrintSettings) { + mPrintSettings->GetPrinterName(&printer); + mPrintSettings->GetPrintRange(&printRange); + mPrintSettings->GetToFileName(&printfile); + mPrintSettings->GetPrintToFile(&tofile); + mPrintSettings->GetStartPageRange(&fromPage); + mPrintSettings->GetEndPageRange(&toPage); + mPrintSettings->GetNumCopies(&copies); if ((copies == 0) || (copies > 999)) { FreeGlobalPrinters(); @@ -288,7 +294,7 @@ NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetToPrinter( PRBool &aToPrinter ) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetPrinter ( char **aPrinter ) +NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetPrinterName ( char **aPrinter ) { *aPrinter = &mPrData.printer[0]; return NS_OK; @@ -335,8 +341,20 @@ nsPrinterEnumeratorOS2::nsPrinterEnumeratorOS2() NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorOS2, nsIPrinterEnumerator) +NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrintersExtended(PRUint32* aCount, PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + *aCount = 0; + *aResult = nsnull; + return NS_OK; +} + NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) { + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + if (aCount) *aCount = 0; else @@ -373,7 +391,7 @@ NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnic return NS_OK; } -NS_IMETHODIMP nsPrinterEnumeratorOS2::DisplayPropertiesDlg(const PRUnichar *aPrinter) +NS_IMETHODIMP nsPrinterEnumeratorOS2::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) { for(int i = 0; i < nsDeviceContextSpecOS2::globalNumPrinters; i++) { if (!(nsDeviceContextSpecOS2::globalPrinterList->StringAt(i)->CompareWithConversion(aPrinter, TRUE, -1))) { diff --git a/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.h b/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.h index f71f2fd430d..64358d6dd7b 100644 --- a/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.h +++ b/mozilla/gfx/src/os2/nsDeviceContextSpecOS2.h @@ -47,6 +47,7 @@ #include "nsIDeviceContextSpec.h" #include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsVoidArray.h" #ifdef USE_XPRINT #include "nsIDeviceContextSpecXPrint.h" @@ -131,13 +132,13 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); NS_IMETHOD ClosePrintManager(); NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); - NS_IMETHOD GetPrinter ( char **aPrinter ); + NS_IMETHOD GetPrinterName ( char **aPrinter ); NS_IMETHOD GetCopies ( int &aCopies ); @@ -147,23 +148,23 @@ public: NS_IMETHOD GetPRTQUEUE(PRTQUEUE *&p); +/** + * Destuct a nsDeviceContextSpecMac, this will release the printrecord + * @update dc 2/16/98 + */ + virtual ~nsDeviceContextSpecOS2(); + static nsStringArray *globalPrinterList; static int globalNumPrinters; static PRINTDLG PrnDlg; int InitializeGlobalPrinters(); void FreeGlobalPrinters(); -protected: -/** - * Destuct a nsDeviceContextSpecMac, this will release the printrecord - * @update dc 2/16/98 - */ - virtual ~nsDeviceContextSpecOS2(); - protected: OS2PrData mPrData; PRTQUEUE *mQueue; + nsCOMPtr mPrintSettings; }; //------------------------------------------------------------------------- diff --git a/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.cpp b/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.cpp index 51377275213..38ab9f124e4 100644 --- a/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.cpp +++ b/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.cpp @@ -70,6 +70,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryPh :: Init(void) //XXX this method needs to do what the API says... NS_IMETHODIMP nsDeviceContextSpecFactoryPh :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { diff --git a/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.h b/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.h index e0f55ac8f3c..a9da1380633 100644 --- a/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.h +++ b/mozilla/gfx/src/photon/nsDeviceContextSpecFactoryP.h @@ -51,6 +51,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec( nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/ps/nsIDeviceContextSpecPS.h b/mozilla/gfx/src/ps/nsIDeviceContextSpecPS.h index b8d0a9e68ef..1eb07f17ac4 100644 --- a/mozilla/gfx/src/ps/nsIDeviceContextSpecPS.h +++ b/mozilla/gfx/src/ps/nsIDeviceContextSpecPS.h @@ -131,7 +131,7 @@ public: * @param aPrinter -- * @return **/ - NS_IMETHOD GetPrinter ( char **aPrinter ) = 0; + NS_IMETHOD GetPrinterName ( char **aPrinter ) = 0; /* * Get width and height based on user page size choice, e.g., 8.5 x 11.0 diff --git a/mozilla/gfx/src/ps/nsPostScriptObj.cpp b/mozilla/gfx/src/ps/nsPostScriptObj.cpp index 3301057aaf7..4a194d33634 100644 --- a/mozilla/gfx/src/ps/nsPostScriptObj.cpp +++ b/mozilla/gfx/src/ps/nsPostScriptObj.cpp @@ -286,7 +286,7 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec, PRUnichar * aTitle ) */ char *envvar; /* get printer name */ - aSpec->GetPrinter(&buf); + aSpec->GetPrinterName(&buf); /* do not set the ${MOZ_PRINTER_NAME} env var if we want the default * printer */ diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp index 860ab9522bc..9c65bab240b 100644 --- a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp @@ -97,6 +97,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryQT::Init(void) */ NS_IMETHODIMP nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { @@ -108,7 +109,7 @@ nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget, (void **)&devSpec); if (nsnull != devSpec) { - if (NS_OK == ((nsDeviceContextSpecQT*)devSpec)->Init(aQuiet)) { + if (NS_OK == ((nsDeviceContextSpecQT*)devSpec)->Init(aPrintSettings, aQuiet)) { aNewSpec = devSpec; rv = NS_OK; } diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.h b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.h index dd9cb33f60f..0baa22ec995 100644 --- a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.h +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQT.h @@ -52,6 +52,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp b/mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp index 4f4db6313f3..c51fcdde522 100644 --- a/mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp @@ -40,21 +40,17 @@ #include "nsDeviceContextSpecQT.h" #include "nsRenderingContextQT.h" -#include "nsCOMPtr.h" -#include "nsReadableUtils.h" -#include "nsIServiceManager.h" -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" - #include "nsIPref.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsIDOMWindowInternal.h" +#include "nsIServiceManager.h" #include "nsIDialogParamBlock.h" #include "nsISupportsPrimitives.h" #include "nsIWindowWatcher.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +#include "nsReadableUtils.h" +#include "nsISupportsArray.h" #include @@ -134,15 +130,15 @@ NS_IMETHODIMP nsDeviceContextSpecQT::QueryInterface(REFNSIID aIID, * @update dc 2/15/98 * @update syd 3/2/99 */ -NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecQT::Init(nsIPrintSettings* aPS, PRBool aQuiet) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); - + NS_ASSERTION(aPS, "Must have a PrintSettings!"); + // if there is a current selection then enable the "Selection" radio button - if (NS_SUCCEEDED(rv) && printService) { + if (aPS) { PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, + aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv) && pPrefs) { @@ -153,7 +149,7 @@ NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet) PRBool reversed = PR_FALSE; PRBool color = PR_FALSE; PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintOptions::kRangeAllPages; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 paper_size = NS_LETTER_SIZE; PRInt32 orientation = NS_PORTRAIT; PRInt32 fromPage = 1; @@ -166,52 +162,59 @@ NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet) double dbottom = 0.5; rv = NS_ERROR_FAILURE; + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; + + nsCOMPtr ps = aPS; + nsCOMPtr psSupports(do_QueryInterface(ps)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); if (wwatch) { - - nsCOMPtr parent; nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - if (active) { - active->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(parent)); - } + wwatch->GetActiveWindow(getter_AddRefs(active)); + nsCOMPtr parent = do_QueryInterface(active); nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); + rv = wwatch->OpenWindow(parent, aChromeURL, + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); } } if (NS_SUCCEEDED(rv)) { PRInt32 buttonPressed = 0; ioParamBlock->GetInt(0, &buttonPressed); - if (buttonPressed == 0) { - if (printService) { - printService->GetPrintReversed(&reversed); - printService->GetPrintInColor(&color); - printService->GetPaperSize(&paper_size); - printService->GetOrientation(&orientation); - printService->GetPrintCommand(&command); - printService->GetPrintRange(&printRange); - printService->GetToFileName(&printfile); - printService->GetPrintToFile(&tofile); - printService->GetStartPageRange(&fromPage); - printService->GetEndPageRange(&toPage); - printService->GetMarginTop(&dtop); - printService->GetMarginLeft(&dleft); - printService->GetMarginBottom(&dbottom); - printService->GetMarginRight(&dright); + if (buttonPressed == 1) { + if (aPS) { + aPS->GetPrintReversed(&reversed); + aPS->GetPrintInColor(&color); + aPS->GetPaperSize(&paper_size); + aPS->GetOrientation(&orientation); + aPS->GetPrintCommand(&command); + aPS->GetPrintRange(&printRange); + aPS->GetToFileName(&printfile); + aPS->GetPrintToFile(&tofile); + aPS->GetStartPageRange(&fromPage); + aPS->GetEndPageRange(&toPage); + aPS->GetMarginTop(&dtop); + aPS->GetMarginLeft(&dleft); + aPS->GetMarginBottom(&dbottom); + aPS->GetMarginRight(&dright); if (command != nsnull && printfile != nsnull) { // convert Unicode strings to cstrings @@ -275,7 +278,7 @@ NS_IMETHODIMP nsDeviceContextSpecQT::GetToPrinter(PRBool &aToPrinter) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecQT::GetPrinter (char **aPrinter) +NS_IMETHODIMP nsDeviceContextSpecQT::GetPrinterName (char **aPrinter) { *aPrinter = &mPrData.printer[0]; return NS_OK; diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecQT.h b/mozilla/gfx/src/qt/nsDeviceContextSpecQT.h index 6c7e52ee212..4b5cee6c089 100644 --- a/mozilla/gfx/src/qt/nsDeviceContextSpecQT.h +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecQT.h @@ -43,6 +43,7 @@ #include "nsIDeviceContextSpec.h" #include "nsDeviceContextSpecQT.h" #include "nsIDeviceContextSpecPS.h" +#include "nsIPrintSettings.h" #include "../gtk/nsPrintdGTK.h" @@ -68,7 +69,7 @@ public: * printer). * @return error status */ - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); /** @@ -80,7 +81,7 @@ public: NS_IMETHOD GetToPrinter(PRBool &aToPrinter); - NS_IMETHOD GetPrinter ( char **aPrinter ); + NS_IMETHOD GetPrinterName ( char **aPrinter ); NS_IMETHOD GetFirstPageFirst(PRBool &aFpf); diff --git a/mozilla/gfx/src/windows/makefile.win b/mozilla/gfx/src/windows/makefile.win index a93aeec6fea..89e03ecf53c 100644 --- a/mozilla/gfx/src/windows/makefile.win +++ b/mozilla/gfx/src/windows/makefile.win @@ -35,6 +35,8 @@ REQUIRES = xpcom \ unicharutil \ locale \ necko \ + dom \ + windowwatcher \ content \ layout \ $(NULL) @@ -96,6 +98,7 @@ WIN_LIBS= \ !if defined(NGLAYOUT_DDRAW) ole32.lib \ !endif + winspool.lib \ comdlg32.lib LLFLAGS = $(LLFLAGS) diff --git a/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.cpp b/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.cpp index 77ad68a9bb8..55e22626a06 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.cpp @@ -38,67 +38,7 @@ #include "nsDeviceContextSpecFactoryW.h" #include "nsDeviceContextSpecWin.h" -#include -#include #include "nsGfxCIID.h" -#include "plstr.h" -#include "nsIServiceManager.h" -#include "nsIStringBundle.h" - -#include "nsIPrintOptions.h" - -// For Localization -#include "nsIStringBundle.h" -#include "nsDeviceContext.h" -#include "nsDeviceContextWin.h" - -// This is for extending the dialog -#include - -static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); - -//---------------------------------------------------------------------------------- -// Return localized bundle for resource strings -static nsresult -GetLocalizedBundle(const char * aPropFileName, nsIStringBundle** aStrBundle) -{ - NS_ENSURE_ARG_POINTER(aPropFileName); - NS_ENSURE_ARG_POINTER(aStrBundle); - - nsresult rv; - nsCOMPtr bundle; - - - // Create bundle - nsCOMPtr stringService = - do_GetService(kStringBundleServiceCID, &rv); - if (NS_SUCCEEDED(rv) && stringService) { - rv = stringService->CreateBundle(aPropFileName, aStrBundle); - } - - return rv; -} - -//-------------------------------------------------------- -// Return localized string -static nsresult -GetLocalizedString(nsIStringBundle* aStrBundle, const char* aKey, nsString& oVal) -{ - NS_ENSURE_ARG_POINTER(aStrBundle); - NS_ENSURE_ARG_POINTER(aKey); - - // Determine default label from string bundle - nsXPIDLString valUni; - nsAutoString key; - key.AssignWithConversion(aKey); - nsresult rv = aStrBundle->GetStringFromName(key.get(), getter_Copies(valUni)); - if (NS_SUCCEEDED(rv) && valUni) { - oVal.Assign(valUni); - } else { - oVal.Truncate(); - } - return rv; -} nsDeviceContextSpecFactoryWin :: nsDeviceContextSpecFactoryWin() { @@ -121,560 +61,28 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: Init(void) return NS_OK; } -//---------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------- -// Identifies whcih new radio btn was lciked on -static UINT gFrameSelectedRadioBtn = NULL; - -// Indicates whether the native print dialog was successfully extended -static PRPackedBool gDialogWasExtended = PR_FALSE; - -#define PRINTDLG_PROPERTIES "chrome://communicator/locale/gfx/printdialog.properties" -#define TEMPLATE_NAME "PRINTDLGNEW" - -//-------------------------------------------------------- -// Set a multi-byte string in the control -static void SetTextOnWnd(HWND aControl, const nsString& aStr) -{ - char* pStr = nsDeviceContextWin::GetACPString(aStr); - if (pStr) { - ::SetWindowText(aControl, pStr); - delete [] pStr; - } -} - -//-------------------------------------------------------- -// Will get the control and localized string by "key" -static void SetText(HWND aParent, - UINT aId, - nsIStringBundle* aStrBundle, - const char* aKey) -{ - HWND wnd = GetDlgItem (aParent, aId); - if (!wnd) { - return; - } - nsAutoString str; - nsresult rv = GetLocalizedString(aStrBundle, aKey, str); - if (NS_SUCCEEDED(rv)) { - SetTextOnWnd(wnd, str); - } -} - -//-------------------------------------------------------- -static void SetRadio(HWND aParent, - UINT aId, - PRBool aIsSet, - PRBool isEnabled = PR_TRUE) -{ - HWND wnd = ::GetDlgItem (aParent, aId); - if (!wnd) { - return; - } - if (!isEnabled) { - ::EnableWindow(wnd, FALSE); - return; - } - ::EnableWindow(wnd, TRUE); - ::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0); -} - -//-------------------------------------------------------- -static void SetRadioOfGroup(HWND aDlg, int aRadId) -{ - int radioIds[] = {rad4, rad5, rad6}; - int numRads = 3; - - for (int i=0;ilCustData; - - HINSTANCE hInst = (HINSTANCE)::GetWindowLong(hdlg, GWL_HINSTANCE); - if (hInst == NULL) return 0L; - - // Start by getting the local rects of several of the controls - // so we can calculate where the new controls are - HWND wnd = ::GetDlgItem(hdlg, grp1); - if (wnd == NULL) return 0L; - RECT dlgRect; - GetLocalRect(wnd, dlgRect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad1); // this is the top control "All" - if (wnd == NULL) return 0L; - RECT rad1Rect; - GetLocalRect(wnd, rad1Rect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad2); // this is the bottom control "Selection" - if (wnd == NULL) return 0L; - RECT rad2Rect; - GetLocalRect(wnd, rad2Rect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad3); // this is the middle control "Pages" - if (wnd == NULL) return 0L; - RECT rad3Rect; - GetLocalRect(wnd, rad3Rect, hdlg); - - HWND okWnd = ::GetDlgItem(hdlg, IDOK); - if (okWnd == NULL) return 0L; - RECT okRect; - GetLocalRect(okWnd, okRect, hdlg); - - wnd = ::GetDlgItem(hdlg, grp4); // this is the "Print range" groupbox - if (wnd == NULL) return 0L; - RECT prtRect; - GetLocalRect(wnd, prtRect, hdlg); - - - // calculate various different "gaps" for layout purposes - - int rbGap = rad3Rect.top - rad1Rect.bottom; // gap between radiobtns - int grpBotGap = dlgRect.bottom - rad2Rect.bottom; // gap from bottom rb to bottom of grpbox - int grpGap = dlgRect.top - prtRect.bottom ; // gap between group boxes - int top = dlgRect.bottom + grpGap; - int radHgt = rad1Rect.bottom - rad1Rect.top + 1; // top of new group box - int y = top+(rad1Rect.top-dlgRect.top); // starting pos of first radio - int rbWidth = dlgRect.right - rad1Rect.left - 5; // measure from rb left to the edge of the groupbox - // (5 is arbitrary) - nsRect rect; - - // Create and position the radio buttons - // - // If any one control cannot be created then - // hide the others and bail out - // - rect.SetRect(rad1Rect.left, y, rbWidth,radHgt); - HWND rad4Wnd = CreateRadioBtn(hInst, hdlg, rad4, NS_LITERAL_STRING("As &laid out on the screen"), rect); - if (rad4Wnd == NULL) return 0L; - y += radHgt + rbGap; - - rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); - HWND rad5Wnd = CreateRadioBtn(hInst, hdlg, rad5, NS_LITERAL_STRING("The selected &frame"), rect); - if (rad5Wnd == NULL) { - Show(rad4Wnd, FALSE); // hide - return 0L; - } - y += radHgt + rbGap; - - rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); - HWND rad6Wnd = CreateRadioBtn(hInst, hdlg, rad6, NS_LITERAL_STRING("&Each frame separately"), rect); - if (rad6Wnd == NULL) { - Show(rad4Wnd, FALSE); // hide - Show(rad5Wnd, FALSE); // hide - return 0L; - } - y += radHgt + grpBotGap; - - // Create and position the group box - rect.SetRect (dlgRect.left, top, dlgRect.right-dlgRect.left+1, y-top+1); - HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, NS_LITERAL_STRING("Print Frame"), rect); - if (grpBoxWnd == NULL) { - Show(rad4Wnd, FALSE); // hide - Show(rad5Wnd, FALSE); // hide - Show(rad6Wnd, FALSE); // hide - return 0L; - } - - // Here we figure out the old height of the dlg - // then figure it's gap from the old grpbx to the bottom - // then size the dlg - RECT pr, cr; - ::GetWindowRect(hdlg, &pr); - ::GetClientRect(hdlg, &cr); - - int dlgHgt = (cr.bottom - cr.top) + 1; - int bottomGap = dlgHgt - okRect.bottom; - pr.bottom += (dlgRect.bottom-dlgRect.top) + grpGap + 1 - (dlgHgt-dlgRect.bottom) + bottomGap; - - ::SetWindowPos(hdlg, NULL, pr.left, pr.top, pr.right-pr.left+1, pr.bottom-pr.top+1, - SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER); - - // figure out the new height of the dialog - ::GetClientRect(hdlg, &cr); - dlgHgt = (cr.bottom - cr.top) + 1; - - // Reposition the OK and Cancel btns - int okHgt = okRect.bottom - okRect.top + 1; - ::SetWindowPos(okWnd, NULL, okRect.left, dlgHgt-bottomGap-okHgt, 0, 0, - SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); - - HWND cancelWnd = ::GetDlgItem(hdlg, IDCANCEL); - if (cancelWnd == NULL) return 0L; - - RECT cancelRect; - GetLocalRect(cancelWnd, cancelRect, hdlg); - int cancelHgt = cancelRect.bottom - cancelRect.top + 1; - ::SetWindowPos(cancelWnd, NULL, cancelRect.left, dlgHgt-bottomGap-cancelHgt, 0, 0, - SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); - - // Localize the new controls in the print dialog - nsCOMPtr strBundle; - if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { - PRInt32 i = 0; - while (gAllPropKeys[i].mKeyStr != NULL) { - SetText(hdlg, gAllPropKeys[i].mKeyId, strBundle, gAllPropKeys[i].mKeyStr); - i++; - } - } - - // Set up radio buttons - if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAll) { - SetRadio(hdlg, rad4, PR_FALSE); - SetRadio(hdlg, rad5, PR_TRUE); - SetRadio(hdlg, rad6, PR_FALSE); - // set default so user doesn't have to actually press on it - gFrameSelectedRadioBtn = rad5; - - } else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) { - SetRadio(hdlg, rad4, PR_FALSE); - SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); - SetRadio(hdlg, rad6, PR_TRUE); - // set default so user doesn't have to actually press on it - gFrameSelectedRadioBtn = rad6; - - - } else { // nsIPrintOptions::kFrameEnableNone - // we are using this function to disabe the group box - SetRadio(hdlg, grp3, PR_FALSE, PR_FALSE); - // now disable radiobuttons - SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); - SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); - SetRadio(hdlg, rad6, PR_FALSE, PR_FALSE); - } - - // Looks like we were able to extend the dialog - gDialogWasExtended = PR_TRUE; - } - return 0L; -} - - //XXX this method needs to do what the API says... NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { NS_ENSURE_ARG_POINTER(aWidget); - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); + nsresult rv = NS_ERROR_FAILURE; + nsIDeviceContextSpec* devspec = nsnull; - gDialogWasExtended = PR_FALSE; + nsComponentManager::CreateInstance(kDeviceContextSpecCID, nsnull, kIDeviceContextSpecIID, (void **)&devspec); - PRINTDLG prntdlg; - memset(&prntdlg, 0, sizeof(PRINTDLG)); - - prntdlg.lStructSize = sizeof(prntdlg); - prntdlg.hwndOwner = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW); - prntdlg.hDevMode = NULL; - prntdlg.hDevNames = NULL; - prntdlg.hDC = NULL; - prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE | PD_USEDEVMODECOPIESANDCOLLATE; - - // if there is a current selection then enable the "Selection" radio button - PRInt16 howToEnableFrameUI = nsIPrintOptions::kFrameEnableNone; - if (printService) { - PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); - if (!isOn) { - prntdlg.Flags |= PD_NOSELECTION; + if (nsnull != devspec){ + nsDeviceContextSpecWin* specWin = NS_STATIC_CAST(nsDeviceContextSpecWin*, devspec); + rv = specWin->Init(aWidget, aPrintSettings, aQuiet); + if (NS_SUCCEEDED(rv)) { + aNewSpec = devspec; + } else { + NS_RELEASE(devspec); } - printService->GetHowToEnableFrameUI(&howToEnableFrameUI); - } - - // Determine whether we have a completely native dialog - // or whether we cshould extend it - // true - do only the native - // false - extend the dialog - PRPackedBool doExtend = PR_FALSE; - nsCOMPtr strBundle; - if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { - nsAutoString doExtendStr; - if (NS_SUCCEEDED(GetLocalizedString(strBundle, "extend", doExtendStr))) { - doExtend = doExtendStr.EqualsIgnoreCase("true"); - } - } - - prntdlg.nFromPage = 0xFFFF; - prntdlg.nToPage = 0xFFFF; - prntdlg.nMinPage = 1; - prntdlg.nMaxPage = 0xFFFF; - prntdlg.nCopies = 1; - prntdlg.lpfnSetupHook = NULL; - prntdlg.lpSetupTemplateName = NULL; - prntdlg.hPrintTemplate = NULL; - prntdlg.hSetupTemplate = NULL; - - prntdlg.hInstance = NULL; - prntdlg.lpPrintTemplateName = NULL; - - if (!doExtend || aQuiet) { - prntdlg.lCustData = NULL; - prntdlg.lpfnPrintHook = NULL; - } else { - // Set up print dialog "hook" procedure for extending the dialog - prntdlg.lCustData = (DWORD)howToEnableFrameUI; - prntdlg.lpfnPrintHook = PrintHookProc; - prntdlg.Flags |= PD_ENABLEPRINTHOOK; - } - - if(PR_TRUE == aQuiet){ - prntdlg.Flags = PD_ALLPAGES | PD_RETURNDEFAULT | PD_RETURNIC | PD_USEDEVMODECOPIESANDCOLLATE; - } - - rv = NS_ERROR_FAILURE; // reset - - BOOL result = ::PrintDlg(&prntdlg); - - if (TRUE == result){ - DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames); - if ( NULL != devnames ) { - - char device[200], driver[200]; - - //print something... - - PL_strcpy(device, &(((char *)devnames)[devnames->wDeviceOffset])); - PL_strcpy(driver, &(((char *)devnames)[devnames->wDriverOffset])); - - #if defined(DEBUG_rods) || defined(DEBUG_dcone) - printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags); - #endif - - // fill the print options with the info from the dialog - if (printService) { - - if (prntdlg.Flags & PD_SELECTION) { - printService->SetPrintRange(nsIPrintOptions::kRangeSelection); - - } else if (prntdlg.Flags & PD_PAGENUMS) { - printService->SetPrintRange(nsIPrintOptions::kRangeSpecifiedPageRange); - printService->SetStartPageRange(prntdlg.nFromPage); - printService->SetEndPageRange( prntdlg.nToPage); - - } else { // (prntdlg.Flags & PD_ALLPAGES) - printService->SetPrintRange(nsIPrintOptions::kRangeAllPages); - } - - if (howToEnableFrameUI != nsIPrintOptions::kFrameEnableNone) { - // make sure the dialog got extended - if (gDialogWasExtended) { - // check to see about the frame radio buttons - switch (gFrameSelectedRadioBtn) { - case rad4: - printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs); - break; - case rad5: - printService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame); - break; - case rad6: - printService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep); - break; - } // switch - } else { - // if it didn't get extended then have it default to printing - // each frame separately - printService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep); - } - } else { - printService->SetPrintFrameType(nsIPrintOptions::kNoFrames); - } - } - - - #if defined(DEBUG_rods) || defined(DEBUG_dcone) - PRBool printSelection = prntdlg.Flags & PD_SELECTION; - PRBool printAllPages = prntdlg.Flags & PD_ALLPAGES; - PRBool printNumPages = prntdlg.Flags & PD_PAGENUMS; - PRInt32 fromPageNum = 0; - PRInt32 toPageNum = 0; - - if (printNumPages) { - fromPageNum = prntdlg.nFromPage; - toPageNum = prntdlg.nToPage; - } - if (printSelection) { - printf("Printing the selection\n"); - - } else if (printAllPages) { - printf("Printing all the pages\n"); - - } else { - printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum); - } - #endif - - - nsIDeviceContextSpec *devspec = nsnull; - - nsComponentManager::CreateInstance(kDeviceContextSpecCID, nsnull, kIDeviceContextSpecIID, (void **)&devspec); - - if (nsnull != devspec){ - //XXX need to QI rather than cast... MMP - if (NS_OK == ((nsDeviceContextSpecWin *)devspec)->Init(driver, device, prntdlg.hDevMode)){ - aNewSpec = devspec; - rv = NS_OK; - } - } - - //don't free the DEVMODE because the device context spec now owns it... - ::GlobalUnlock(prntdlg.hDevNames); - ::GlobalFree(prntdlg.hDevNames); - } - } else { - // print dialog aborted - rv = NS_ERROR_ABORT; } return rv; diff --git a/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.h b/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.h index 4c94a024059..99e9352121e 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.h +++ b/mozilla/gfx/src/windows/nsDeviceContextSpecFactoryW.h @@ -42,6 +42,8 @@ #include "nsIDeviceContextSpecFactory.h" #include "nsIDeviceContextSpec.h" +class nsIPrintSettings; + class nsDeviceContextSpecFactoryWin : public nsIDeviceContextSpecFactory { public: @@ -51,6 +53,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/windows/nsDeviceContextSpecWin.cpp b/mozilla/gfx/src/windows/nsDeviceContextSpecWin.cpp index 95c4f3fe483..f6e6d3187bc 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextSpecWin.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextSpecWin.cpp @@ -39,72 +39,1495 @@ #include "nsDeviceContextSpecWin.h" #include "prmem.h" #include "plstr.h" +#include +#include +#include "nsIDOMWindow.h" +#include "nsIServiceManager.h" +#include "nsIDialogParamBlock.h" +#include "nsISupportsPrimitives.h" +#include "nsIWindowWatcher.h" +#include "nsIDOMWindowInternal.h" +#include "nsVoidArray.h" +#include "nsSupportsArray.h" + +#include "nsString.h" +#include "nsIServiceManager.h" +#include "nsReadableUtils.h" +#include "nsGfxCIID.h" +static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +#include "nsIPromptService.h" + +#include "nsIPref.h" +#include "prenv.h" /* for PR_GetEnv */ + +#include +#include + +// For Localization +#include "nsIStringBundle.h" +#include "nsDeviceContext.h" +#include "nsDeviceContextWin.h" + +// This is for extending the dialog +#include + +static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + +//----------------------------------------------- +// Global Data +//----------------------------------------------- +// Identifies which new radio btn was cliked on +static UINT gFrameSelectedRadioBtn = NULL; + +// Indicates whether the native print dialog was successfully extended +static PRPackedBool gDialogWasExtended = PR_FALSE; + +#define PRINTDLG_PROPERTIES "chrome://communicator/locale/gfx/printdialog.properties" +#define TEMPLATE_NAME "PRINTDLGNEW" + +static HWND gParentWnd = NULL; + +//---------------------------------------------------------------------------------- +// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecWin +// The PrinterEnumerator creates the printer info +// but the nsDeviceContextSpecWin cleans it up +// If it gets created (via the Page Setup Dialog) but the user never prints anything +// then it will never be delete, so this class takes care of that. +class GlobalPrinters { +public: + static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } + ~GlobalPrinters() { FreeGlobalPrinters(); } + + void FreeGlobalPrinters(); + + PRBool PrintersAreAllocated() { return mPrinters != nsnull && mPrinterInfoArray != nsnull; } + + LPPRINTER_INFO_2 FindPrinterByName(const PRUnichar* aPrinterName); + LPPRINTER_INFO_2 GetPrinterByIndex(PRInt32 aInx) { return mPrinters?(LPPRINTER_INFO_2)mPrinters->ElementAt(aInx):nsnull; } + + nsresult EnumeratePrinterList(); + void GetDefaultPrinterName(char*& aDefaultPrinterName); + PRInt32 GetNumPrinters() { return mPrinters?mPrinters->Count():0; } + +protected: + GlobalPrinters() {} + nsresult EnumerateNativePrinters(DWORD aWhichPrinters, char* aDefPrinter); + void ReallocatePrinters(); + + static GlobalPrinters mGlobalPrinters; + static nsVoidArray* mPrinters; + static nsVoidArray* mPrinterInfoArray; +}; +//--------------- +// static members +GlobalPrinters GlobalPrinters::mGlobalPrinters; +nsVoidArray* GlobalPrinters::mPrinters = nsnull; +nsVoidArray* GlobalPrinters::mPrinterInfoArray = nsnull; + + +//****************************************************** +// Define native paper sizes +//****************************************************** +typedef struct { + short mPaperSize; // native enum + double mWidth; + double mHeight; + PRBool mIsInches; +} NativePaperSizes; + +// There are around 40 default print sizes defined by Windows +const NativePaperSizes kPaperSizes[] = { + {DMPAPER_LETTER, 8.5, 11.0, PR_TRUE}, + {DMPAPER_LEGAL, 8.5, 14.0, PR_TRUE}, + {DMPAPER_A4, 210.0, 297.0, PR_FALSE}, + {DMPAPER_TABLOID, 11.0, 17.0, PR_TRUE}, + {DMPAPER_LEDGER, 17.0, 11.0, PR_TRUE}, + {DMPAPER_STATEMENT, 5.5, 8.5, PR_TRUE}, + {DMPAPER_EXECUTIVE, 7.25, 10.5, PR_TRUE}, + {DMPAPER_A3, 297.0, 420.0, PR_FALSE}, + {DMPAPER_A5, 148.0, 210.0, PR_FALSE}, + {DMPAPER_CSHEET, 17.0, 22.0, PR_TRUE}, + {DMPAPER_DSHEET, 22.0, 34.0, PR_TRUE}, + {DMPAPER_ESHEET, 34.0, 44.0, PR_TRUE}, + {DMPAPER_LETTERSMALL, 8.5, 11.0, PR_TRUE}, + {DMPAPER_A4SMALL, 210.0, 297.0, PR_FALSE}, + {DMPAPER_B4, 250.0, 354.0, PR_FALSE}, + {DMPAPER_B5, 182.0, 257.0, PR_FALSE}, + {DMPAPER_FOLIO, 8.5, 13.0, PR_TRUE}, + {DMPAPER_QUARTO, 215.0, 275.0, PR_FALSE}, + {DMPAPER_10X14, 10.0, 14.0, PR_TRUE}, + {DMPAPER_11X17, 11.0, 17.0, PR_TRUE}, + {DMPAPER_NOTE, 8.5, 11.0, PR_TRUE}, + {DMPAPER_ENV_9, 3.875, 8.875, PR_TRUE}, + {DMPAPER_ENV_10, 40.125, 9.5, PR_TRUE}, + {DMPAPER_ENV_11, 4.5, 10.375, PR_TRUE}, + {DMPAPER_ENV_12, 4.75, 11.0, PR_TRUE}, + {DMPAPER_ENV_14, 5.0, 11.5, PR_TRUE}, + {DMPAPER_ENV_DL, 110.0, 220.0, PR_FALSE}, + {DMPAPER_ENV_C5, 162.0, 229.0, PR_FALSE}, + {DMPAPER_ENV_C3, 324.0, 458.0, PR_FALSE}, + {DMPAPER_ENV_C4, 229.0, 324.0, PR_FALSE}, + {DMPAPER_ENV_C6, 114.0, 162.0, PR_FALSE}, + {DMPAPER_ENV_C65, 114.0, 229.0, PR_FALSE}, + {DMPAPER_ENV_B4, 250.0, 353.0, PR_FALSE}, + {DMPAPER_ENV_B5, 176.0, 250.0, PR_FALSE}, + {DMPAPER_ENV_B6, 176.0, 125.0, PR_FALSE}, + {DMPAPER_ENV_ITALY, 110.0, 230.0, PR_FALSE}, + {DMPAPER_ENV_MONARCH, 3.875, 7.5, PR_TRUE}, + {DMPAPER_ENV_PERSONAL, 3.625, 6.5, PR_TRUE}, + {DMPAPER_FANFOLD_US, 14.875, 11.0, PR_TRUE}, + {DMPAPER_FANFOLD_STD_GERMAN, 8.5, 12.0, PR_TRUE}, + {DMPAPER_FANFOLD_LGL_GERMAN, 8.5, 13.0, PR_TRUE}, +}; +const PRInt32 kNumPaperSizes = 41; + +//---------------------------------------------------------------------------------- nsDeviceContextSpecWin :: nsDeviceContextSpecWin() { NS_INIT_REFCNT(); - mDriverName = nsnull; - mDeviceName = nsnull; - mDEVMODE = NULL; + mDriverName = nsnull; + mDeviceName = nsnull; + mDevMode = NULL; + mGlobalDevMode = NULL; + mIsDEVMODEGlobalHandle = PR_FALSE; } + +//---------------------------------------------------------------------------------- +NS_IMPL_ISUPPORTS1(nsDeviceContextSpecWin, nsIDeviceContextSpec) + nsDeviceContextSpecWin :: ~nsDeviceContextSpecWin() { - if (nsnull != mDriverName) - { - PR_Free(mDriverName); - mDriverName = nsnull; + SetDeviceName(nsnull); + SetDriverName(nsnull); + SetDevMode(NULL); + SetGlobalDevMode(NULL); + + // Free them, we won't need them for a while + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); +} + + +//---------------------------------------------------------------------------------- +// Map an incoming size to a Windows Native enum in the DevMode +static void +MapPaperSizeToNativeEnum(LPDEVMODE aDevMode, + PRInt16 aType, + double aW, + double aH) +{ + +#ifdef DEBUG_rods + BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION; + BOOL doingPaperSize = aDevMode->dmFields & DM_PAPERSIZE; + BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH; + BOOL doingPaperWidth = aDevMode->dmFields & DM_PAPERWIDTH; +#endif + + PRBool foundEnum = PR_FALSE; + for (PRInt32 i=0;idmPaperSize = kPaperSizes[i].mPaperSize; + aDevMode->dmFields &= ~DM_PAPERLENGTH; + aDevMode->dmFields &= ~DM_PAPERWIDTH; + aDevMode->dmFields |= DM_PAPERSIZE; + return; + } } - if (nsnull != mDeviceName) - { - PR_Free(mDeviceName); - mDeviceName = nsnull; + short width = 0; + short height = 0; + if (aType == nsIPrintSettings::kPaperSizeInches) { + width = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10); + height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10); + + } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) { + width = short(aW / 10.0); + height = short(aH / 10.0); + } else { + return; // don't set anything } - if (NULL != mDEVMODE) - { - ::GlobalFree(mDEVMODE); - mDEVMODE = NULL; + // width and height is in + aDevMode->dmPaperSize = 0; + aDevMode->dmPaperWidth = width; + aDevMode->dmPaperLength = height; + + aDevMode->dmFields |= DM_PAPERSIZE; + aDevMode->dmFields |= DM_PAPERLENGTH; + aDevMode->dmFields |= DM_PAPERWIDTH; +} + +//---------------------------------------------------------------------------------- +// Setup Paper Size & Orientation options into the DevMode +// +static void +SetupDevModeFromSettings(LPDEVMODE aDevMode, nsIPrintSettings* aPrintSettings) +{ + // Setup paper size + if (aPrintSettings) { + PRInt16 type; + aPrintSettings->GetPaperSizeType(&type); + if (type == nsIPrintSettings::kPaperSizeNativeData) { + PRInt16 paperEnum; + aPrintSettings->GetPaperData(&paperEnum); + aDevMode->dmPaperSize = paperEnum; + aDevMode->dmFields &= ~DM_PAPERLENGTH; + aDevMode->dmFields &= ~DM_PAPERWIDTH; + aDevMode->dmFields |= DM_PAPERSIZE; + } else { + PRInt16 unit; + double width, height; + aPrintSettings->GetPaperSizeUnit(&unit); + aPrintSettings->GetPaperWidth(&width); + aPrintSettings->GetPaperHeight(&height); + MapPaperSizeToNativeEnum(aDevMode, unit, width, height); + } + + // Setup Orientation + PRInt32 orientation; + aPrintSettings->GetOrientation(&orientation); + aDevMode->dmOrientation = orientation == nsIPrintSettings::kPortraitOrientation?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE; + aDevMode->dmFields |= DM_ORIENTATION; + + // Setup Number of Copies + PRInt32 copies; + aPrintSettings->GetNumCopies(&copies); + aDevMode->dmCopies = copies; + aDevMode->dmFields |= DM_COPIES; + } + +} + +//---------------------------------------------------------------------------------- +// Helper Function - Free and reallocate the string +static nsresult SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, LPDEVMODE aDevMode) +{ + if (aPrintSettings == nsnull) { + return NS_ERROR_FAILURE; + } + BOOL doingNumCopies = aDevMode->dmFields & DM_COPIES; + BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION; + BOOL doingPaperSize = aDevMode->dmFields & DM_PAPERSIZE; + BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH; + BOOL doingPaperWidth = aDevMode->dmFields & DM_PAPERWIDTH; + + if (doingOrientation) { + PRInt32 orientation = aDevMode->dmOrientation == DMORIENT_PORTRAIT? + nsIPrintSettings::kPortraitOrientation:nsIPrintSettings::kLandscapeOrientation; + aPrintSettings->SetOrientation(orientation); + } + + // Setup Number of Copies + if (doingNumCopies) { + aPrintSettings->SetNumCopies(PRInt32(aDevMode->dmCopies)); + } + + if (doingPaperSize) { + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeNativeData); + aPrintSettings->SetPaperData(aDevMode->dmPaperSize); + + } else if (doingPaperLength && doingPaperWidth) { + PRBool found = PR_FALSE; + for (PRInt32 i=0;idmPaperSize) { + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); + aPrintSettings->SetPaperWidth(kPaperSizes[i].mWidth); + aPrintSettings->SetPaperHeight(kPaperSizes[i].mHeight); + aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeInches); + found = PR_TRUE; + break; + } + } + if (!found) { + return NS_ERROR_FAILURE; + } + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +//---------------------------------------------------------------------------------- +NS_IMETHODIMP nsDeviceContextSpecWin :: Init(nsIWidget* aWidget, + nsIPrintSettings* aPrintSettings, + PRBool aQuiet) +{ + mPrintSettings = aPrintSettings; + + gParentWnd = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW); + + PRBool doNativeDialog = PR_FALSE; + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + pPrefs->GetBoolPref("print.use_native_print_dialog", &doNativeDialog); + } + + if (doNativeDialog || aQuiet) { + rv = ShowNativePrintDialog(aWidget, aQuiet); + } else { + rv = ShowXPPrintDialog(aQuiet); + } + + return rv; +} + +//---------------------------------------------------------- +// Helper Function - Free and reallocate the string +static void CleanAndCopyString(char*& aStr, char* aNewStr) +{ + if (aStr != nsnull) { + if (aNewStr != nsnull && strlen(aStr) > strlen(aNewStr)) { // reuse it if we can + PL_strcpy(aStr, aNewStr); + return; + } else { + PR_Free(aStr); + aStr = nsnull; + } + } + + if (nsnull != aNewStr) { + aStr = (char *)PR_Malloc(PL_strlen(aNewStr) + 1); + PL_strcpy(aStr, aNewStr); } } -NS_IMPL_ISUPPORTS1(nsDeviceContextSpecWin, nsIDeviceContextSpec) - -NS_IMETHODIMP nsDeviceContextSpecWin :: Init(char *aDriverName, char *aDeviceName, HGLOBAL aDEVMODE) +//---------------------------------------------------------------------------------- +void nsDeviceContextSpecWin :: SetDeviceName(char* aDeviceName) { - if (nsnull != aDriverName) - { - mDriverName = (char *)PR_Malloc(PL_strlen(aDriverName) + 1); - PL_strcpy(mDriverName, aDriverName); + CleanAndCopyString(mDeviceName, aDeviceName); +} + +//---------------------------------------------------------------------------------- +void nsDeviceContextSpecWin :: SetDriverName(char* aDriverName) +{ + CleanAndCopyString(mDriverName, aDriverName); +} + +//---------------------------------------------------------------------------------- +void nsDeviceContextSpecWin :: SetGlobalDevMode(HGLOBAL aHGlobal) +{ + if (mGlobalDevMode) { + ::GlobalFree(mGlobalDevMode); + mGlobalDevMode = NULL; + } + mGlobalDevMode = aHGlobal; + mIsDEVMODEGlobalHandle = PR_TRUE; +} + +//---------------------------------------------------------------------------------- +void nsDeviceContextSpecWin :: SetDevMode(LPDEVMODE aDevMode) +{ + mDevMode = aDevMode; + mIsDEVMODEGlobalHandle = PR_FALSE; +} + +//---------------------------------------------------------------------------------- +// Return localized bundle for resource strings +static nsresult +GetLocalizedBundle(const char * aPropFileName, nsIStringBundle** aStrBundle) +{ + NS_ENSURE_ARG_POINTER(aPropFileName); + NS_ENSURE_ARG_POINTER(aStrBundle); + + nsresult rv; + nsCOMPtr bundle; + + + // Create bundle + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv) && stringService) { + rv = stringService->CreateBundle(aPropFileName, aStrBundle); + } + + return rv; +} + +//-------------------------------------------------------- +// Return localized string +static nsresult +GetLocalizedString(nsIStringBundle* aStrBundle, const char* aKey, nsString& oVal) +{ + NS_ENSURE_ARG_POINTER(aStrBundle); + NS_ENSURE_ARG_POINTER(aKey); + + // Determine default label from string bundle + nsXPIDLString valUni; + nsAutoString key; + key.AssignWithConversion(aKey); + nsresult rv = aStrBundle->GetStringFromName(key.get(), getter_Copies(valUni)); + if (NS_SUCCEEDED(rv) && valUni) { + oVal.Assign(valUni); + } else { + oVal.Truncate(); + } + return rv; +} + +//-------------------------------------------------------- +// Set a multi-byte string in the control +static void SetTextOnWnd(HWND aControl, const nsString& aStr) +{ + char* pStr = nsDeviceContextWin::GetACPString(aStr); + if (pStr) { + ::SetWindowText(aControl, pStr); + delete [] pStr; + } +} + +//-------------------------------------------------------- +// Will get the control and localized string by "key" +static void SetText(HWND aParent, + UINT aId, + nsIStringBundle* aStrBundle, + const char* aKey) +{ + HWND wnd = GetDlgItem (aParent, aId); + if (!wnd) { + return; + } + nsAutoString str; + nsresult rv = GetLocalizedString(aStrBundle, aKey, str); + if (NS_SUCCEEDED(rv)) { + SetTextOnWnd(wnd, str); + } +} + +//-------------------------------------------------------- +static void SetRadio(HWND aParent, + UINT aId, + PRBool aIsSet, + PRBool isEnabled = PR_TRUE) +{ + HWND wnd = ::GetDlgItem (aParent, aId); + if (!wnd) { + return; + } + if (!isEnabled) { + ::EnableWindow(wnd, FALSE); + return; + } + ::EnableWindow(wnd, TRUE); + ::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0); +} + +//-------------------------------------------------------- +static void SetRadioOfGroup(HWND aDlg, int aRadId) +{ + int radioIds[] = {rad4, rad5, rad6}; + int numRads = 3; + + for (int i=0;ilCustData; + + HINSTANCE hInst = (HINSTANCE)::GetWindowLong(hdlg, GWL_HINSTANCE); + if (hInst == NULL) return 0L; + + // Start by getting the local rects of several of the controls + // so we can calculate where the new controls are + HWND wnd = ::GetDlgItem(hdlg, grp1); + if (wnd == NULL) return 0L; + RECT dlgRect; + GetLocalRect(wnd, dlgRect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad1); // this is the top control "All" + if (wnd == NULL) return 0L; + RECT rad1Rect; + GetLocalRect(wnd, rad1Rect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad2); // this is the bottom control "Selection" + if (wnd == NULL) return 0L; + RECT rad2Rect; + GetLocalRect(wnd, rad2Rect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad3); // this is the middle control "Pages" + if (wnd == NULL) return 0L; + RECT rad3Rect; + GetLocalRect(wnd, rad3Rect, hdlg); + + HWND okWnd = ::GetDlgItem(hdlg, IDOK); + if (okWnd == NULL) return 0L; + RECT okRect; + GetLocalRect(okWnd, okRect, hdlg); + + wnd = ::GetDlgItem(hdlg, grp4); // this is the "Print range" groupbox + if (wnd == NULL) return 0L; + RECT prtRect; + GetLocalRect(wnd, prtRect, hdlg); + + + // calculate various different "gaps" for layout purposes + + int rbGap = rad3Rect.top - rad1Rect.bottom; // gap between radiobtns + int grpBotGap = dlgRect.bottom - rad2Rect.bottom; // gap from bottom rb to bottom of grpbox + int grpGap = dlgRect.top - prtRect.bottom ; // gap between group boxes + int top = dlgRect.bottom + grpGap; + int radHgt = rad1Rect.bottom - rad1Rect.top + 1; // top of new group box + int y = top+(rad1Rect.top-dlgRect.top); // starting pos of first radio + int rbWidth = dlgRect.right - rad1Rect.left - 5; // measure from rb left to the edge of the groupbox + // (5 is arbitrary) + nsRect rect; + + // Create and position the radio buttons + // + // If any one control cannot be created then + // hide the others and bail out + // + rect.SetRect(rad1Rect.left, y, rbWidth,radHgt); + HWND rad4Wnd = CreateRadioBtn(hInst, hdlg, rad4, NS_LITERAL_STRING("As &laid out on the screen"), rect); + if (rad4Wnd == NULL) return 0L; + y += radHgt + rbGap; + + rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); + HWND rad5Wnd = CreateRadioBtn(hInst, hdlg, rad5, NS_LITERAL_STRING("The selected &frame"), rect); + if (rad5Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + return 0L; + } + y += radHgt + rbGap; + + rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); + HWND rad6Wnd = CreateRadioBtn(hInst, hdlg, rad6, NS_LITERAL_STRING("&Each frame separately"), rect); + if (rad6Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + return 0L; + } + y += radHgt + grpBotGap; + + // Create and position the group box + rect.SetRect (dlgRect.left, top, dlgRect.right-dlgRect.left+1, y-top+1); + HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, NS_LITERAL_STRING("Print Frame"), rect); + if (grpBoxWnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + Show(rad6Wnd, FALSE); // hide + return 0L; + } + + // Here we figure out the old height of the dlg + // then figure it's gap from the old grpbx to the bottom + // then size the dlg + RECT pr, cr; + ::GetWindowRect(hdlg, &pr); + ::GetClientRect(hdlg, &cr); + + int dlgHgt = (cr.bottom - cr.top) + 1; + int bottomGap = dlgHgt - okRect.bottom; + pr.bottom += (dlgRect.bottom-dlgRect.top) + grpGap + 1 - (dlgHgt-dlgRect.bottom) + bottomGap; + + ::SetWindowPos(hdlg, NULL, pr.left, pr.top, pr.right-pr.left+1, pr.bottom-pr.top+1, + SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER); + + // figure out the new height of the dialog + ::GetClientRect(hdlg, &cr); + dlgHgt = (cr.bottom - cr.top) + 1; + + // Reposition the OK and Cancel btns + int okHgt = okRect.bottom - okRect.top + 1; + ::SetWindowPos(okWnd, NULL, okRect.left, dlgHgt-bottomGap-okHgt, 0, 0, + SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); + + HWND cancelWnd = ::GetDlgItem(hdlg, IDCANCEL); + if (cancelWnd == NULL) return 0L; + + RECT cancelRect; + GetLocalRect(cancelWnd, cancelRect, hdlg); + int cancelHgt = cancelRect.bottom - cancelRect.top + 1; + ::SetWindowPos(cancelWnd, NULL, cancelRect.left, dlgHgt-bottomGap-cancelHgt, 0, 0, + SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); + + // Localize the new controls in the print dialog + nsCOMPtr strBundle; + if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { + PRInt32 i = 0; + while (gAllPropKeys[i].mKeyStr != NULL) { + SetText(hdlg, gAllPropKeys[i].mKeyId, strBundle, gAllPropKeys[i].mKeyStr); + i++; + } + } + + // Set up radio buttons + if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) { + SetRadio(hdlg, rad4, PR_FALSE); + SetRadio(hdlg, rad5, PR_TRUE); + SetRadio(hdlg, rad6, PR_FALSE); + // set default so user doesn't have to actually press on it + gFrameSelectedRadioBtn = rad5; + + } else if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) { + SetRadio(hdlg, rad4, PR_FALSE); + SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad6, PR_TRUE); + // set default so user doesn't have to actually press on it + gFrameSelectedRadioBtn = rad6; + + + } else { // nsIPrintSettings::kFrameEnableNone + // we are using this function to disabe the group box + SetRadio(hdlg, grp3, PR_FALSE, PR_FALSE); + // now disable radiobuttons + SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad6, PR_FALSE, PR_FALSE); + } + + // Looks like we were able to extend the dialog + gDialogWasExtended = PR_TRUE; + } + return 0L; +} + +//------------------------------------------------------------------ +// Displays the native Print Dialog +nsresult +nsDeviceContextSpecWin :: ShowNativePrintDialog(nsIWidget *aWidget, PRBool aQuiet) +{ + NS_ENSURE_ARG_POINTER(aWidget); + + nsresult rv = NS_ERROR_FAILURE; + gDialogWasExtended = PR_FALSE; + + PRINTDLG prntdlg; + memset(&prntdlg, 0, sizeof(PRINTDLG)); + + prntdlg.lStructSize = sizeof(prntdlg); + prntdlg.hwndOwner = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW); + prntdlg.hDevMode = NULL; + prntdlg.hDevNames = NULL; + prntdlg.hDC = NULL; + prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE | PD_USEDEVMODECOPIESANDCOLLATE; + + // if there is a current selection then enable the "Selection" radio button + PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone; + if (mPrintSettings != nsnull) { + PRBool isOn; + mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + if (!isOn) { + prntdlg.Flags |= PD_NOSELECTION; + } + mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); } - if (nsnull != aDeviceName) - { - mDeviceName = (char *)PR_Malloc(PL_strlen(aDeviceName) + 1); - PL_strcpy(mDeviceName, aDeviceName); + // Determine whether we have a completely native dialog + // or whether we cshould extend it + // true - do only the native + // false - extend the dialog + PRPackedBool doExtend = PR_FALSE; + nsCOMPtr strBundle; + if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { + nsAutoString doExtendStr; + if (NS_SUCCEEDED(GetLocalizedString(strBundle, "extend", doExtendStr))) { + doExtend = doExtendStr.EqualsIgnoreCase("true"); + } } - mDEVMODE = aDEVMODE; + prntdlg.nFromPage = 0xFFFF; + prntdlg.nToPage = 0xFFFF; + prntdlg.nMinPage = 1; + prntdlg.nMaxPage = 0xFFFF; + prntdlg.nCopies = 1; + prntdlg.lpfnSetupHook = NULL; + prntdlg.lpSetupTemplateName = NULL; + prntdlg.hPrintTemplate = NULL; + prntdlg.hSetupTemplate = NULL; + + prntdlg.hInstance = NULL; + prntdlg.lpPrintTemplateName = NULL; + + if (!doExtend || aQuiet) { + prntdlg.lCustData = NULL; + prntdlg.lpfnPrintHook = NULL; + } else { + // Set up print dialog "hook" procedure for extending the dialog + prntdlg.lCustData = (DWORD)howToEnableFrameUI; + prntdlg.lpfnPrintHook = PrintHookProc; + prntdlg.Flags |= PD_ENABLEPRINTHOOK; + } + + if (PR_TRUE == aQuiet){ + prntdlg.Flags = PD_ALLPAGES | PD_RETURNDEFAULT | PD_RETURNIC | PD_USEDEVMODECOPIESANDCOLLATE; + } + + BOOL result = ::PrintDlg(&prntdlg); + + if (TRUE == result) { + if (mPrintSettings && prntdlg.hDevMode != NULL) { + LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode); + SetPrintSettingsFromDevMode(mPrintSettings, devMode); + ::GlobalUnlock(prntdlg.hDevMode); + } + DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames); + if ( NULL != devnames ) { + + char* device = &(((char *)devnames)[devnames->wDeviceOffset]); + char* driver = &(((char *)devnames)[devnames->wDriverOffset]); + + // Setup local Data members + SetDeviceName(device); + SetDriverName(driver); + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags); +#endif + ::GlobalUnlock(prntdlg.hDevNames); + + // fill the print options with the info from the dialog + if (mPrintSettings != nsnull) { + + if (prntdlg.Flags & PD_SELECTION) { + mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection); + + } else if (prntdlg.Flags & PD_PAGENUMS) { + mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange); + mPrintSettings->SetStartPageRange(prntdlg.nFromPage); + mPrintSettings->SetEndPageRange( prntdlg.nToPage); + + } else { // (prntdlg.Flags & PD_ALLPAGES) + mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); + } + + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + // make sure the dialog got extended + if (gDialogWasExtended) { + // check to see about the frame radio buttons + switch (gFrameSelectedRadioBtn) { + case rad4: + mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); + break; + case rad5: + mPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame); + break; + case rad6: + mPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + break; + } // switch + } else { + // if it didn't get extended then have it default to printing + // each frame separately + mPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + } + } else { + mPrintSettings->SetPrintFrameType(nsIPrintSettings::kNoFrames); + } + } + + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + PRBool printSelection = prntdlg.Flags & PD_SELECTION; + PRBool printAllPages = prntdlg.Flags & PD_ALLPAGES; + PRBool printNumPages = prntdlg.Flags & PD_PAGENUMS; + PRInt32 fromPageNum = 0; + PRInt32 toPageNum = 0; + + if (printNumPages) { + fromPageNum = prntdlg.nFromPage; + toPageNum = prntdlg.nToPage; + } + if (printSelection) { + printf("Printing the selection\n"); + + } else if (printAllPages) { + printf("Printing all the pages\n"); + + } else { + printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum); + } +#endif + + SetGlobalDevMode(prntdlg.hDevMode); + + // Set into DevMode Paper Size and Orientation here + // remove comment if you want to override the values from + // the native setup with those specified in the Page Setup + // mainly Paper Size, Orientation + // SetupPaperInfoFromSettings(); + + } + } else { + return NS_ERROR_ABORT; + } return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecWin :: GetDriverName(char *&aDriverName) const + +//---------------------------------------------------------------------------------- +// Setup the object's data member with the selected printer's data +void +nsDeviceContextSpecWin :: GetDataFromPrinter(PRUnichar * aName) { - aDriverName = mDriverName; + if (!GlobalPrinters::GetInstance()->PrintersAreAllocated()) { + return; + } + + LPPRINTER_INFO_2 prtInfo = GlobalPrinters::GetInstance()->FindPrinterByName(aName); + if (prtInfo == nsnull) { + return; + } + + SetDevMode(prtInfo->pDevMode); + + SetDeviceName(prtInfo->pPrinterName); + + // The driver should be NULL for Win95/Win98 + OSVERSIONINFO os; + os.dwOSVersionInfoSize = sizeof(os); + ::GetVersionEx(&os); + if (VER_PLATFORM_WIN32_NT == os.dwPlatformId) { + SetDriverName("WINSPOOL"); + } else { + SetDriverName(NULL); + } +} + +//---------------------------------------------------------------------------------- +// Setup Paper Size options into the DevMode +// +// When using a data member it may be a HGLOCAL or LPDEVMODE +// if it is a HGLOBAL then we need to "lock" it to get the LPDEVMODE +// and unlock it when we are done. +void +nsDeviceContextSpecWin :: SetupPaperInfoFromSettings() +{ + LPDEVMODE devMode; + + if (mDevMode == NULL && mGlobalDevMode == NULL) { + return; + } + if (mGlobalDevMode != nsnull) { + devMode = (DEVMODE *)::GlobalLock(mGlobalDevMode); + } else { + devMode = mDevMode; + } + + SetupDevModeFromSettings(devMode, mPrintSettings); + + if (mGlobalDevMode != nsnull) ::GlobalUnlock(mGlobalDevMode); +} + +//---------------------------------------------------------------------------------- +nsresult +nsDeviceContextSpecWin :: ShowXPPrintDialog(PRBool aQuiet) +{ + nsresult rv = NS_ERROR_FAILURE; + + NS_ASSERTION(mPrintSettings, "Can't have a null PrintSettings!"); + + // if there is a current selection then enable the "Selection" radio button + PRBool isOn; + mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); + } + + PRBool canPrint = PR_FALSE; + if (!aQuiet ) { + rv = NS_ERROR_FAILURE; + + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; + + nsCOMPtr psSupports(do_QueryInterface(mPrintSettings)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); + + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + nsCOMPtr parent = do_QueryInterface(active); + + nsCOMPtr newWindow; + rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); + } + } + + if (NS_SUCCEEDED(rv)) { + PRInt32 buttonPressed = 0; + ioParamBlock->GetInt(0, &buttonPressed); + if (buttonPressed == 1) { + canPrint = PR_TRUE; + } else { + rv = NS_ERROR_ABORT; + } + } + } else { + canPrint = PR_TRUE; + } + + if (canPrint) { + if (mPrintSettings != nsnull) { + PRUnichar *printerName = nsnull; + mPrintSettings->GetPrinterName(&printerName); + + if (printerName != nsnull) { + // Gets DEVMODE, Device and Driver Names + GetDataFromPrinter(printerName); + + // Set into DevMode Paper Size and Orientation here + SetupPaperInfoFromSettings(); + + nsMemory::Free(printerName); + } else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + return NS_OK; + } + + // Free them, we won't need them for a while + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + + return rv; +} + +//*********************************************************** +// Printer Enumerator +//*********************************************************** +nsPrinterEnumeratorWin::nsPrinterEnumeratorWin() +{ + NS_INIT_REFCNT(); +} + +nsPrinterEnumeratorWin::~nsPrinterEnumeratorWin() +{ + // Do not free printers here + // GlobalPrinters::GetInstance()->FreeGlobalPrinters(); +} + +NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorWin, nsIPrinterEnumerator) + + +static void CleanupArray(PRUnichar**& aArray, PRInt32& aCount) +{ + for (PRInt32 i = aCount - 1; i >= 0; i--) { + nsMemory::Free(aArray[i]); + } + nsMemory::Free(aArray); + aArray = NULL; + aCount = 0; +} + +//---------------------------------------------------------------------------------- +// Enumerate all the Printers from the global array and pass their +// names back (usually to script) +nsresult +nsPrinterEnumeratorWin::DoEnumeratePrinters(PRBool aDoExtended, + PRUint32* aCount, + PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + + if (NS_FAILED(GlobalPrinters::GetInstance()->EnumeratePrinterList())) { + return NS_ERROR_FAILURE; + } + + if (aCount) + *aCount = 0; + else + return NS_ERROR_NULL_POINTER; + + if (aResult) + *aResult = nsnull; + else + return NS_ERROR_NULL_POINTER; + + PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); + PRInt32 numItems = aDoExtended?numPrinters*2:numPrinters; + + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numItems * sizeof(PRUnichar*)); + if (!array) + return NS_ERROR_OUT_OF_MEMORY; + + PRInt32 count = 0; + PRInt32 printerInx = 0; + while( count < numItems ) { + LPPRINTER_INFO_2 prtInfo = (LPPRINTER_INFO_2)GlobalPrinters::GetInstance()->GetPrinterByIndex(printerInx); + nsString newName; + newName.AssignWithConversion(prtInfo->pPrinterName); + PRUnichar *str = ToNewUnicode(newName); + if (!str) { + CleanupArray(array, count); + return NS_ERROR_OUT_OF_MEMORY; + } + array[count++] = str; + + if (aDoExtended) { + nsAutoString info; + if (!PL_strcmp(prtInfo->pPortName, "FILE:")) { + info.Assign(NS_LITERAL_STRING("FILE")); + } else { + info.Assign(NS_LITERAL_STRING("BOTH")); + } + PRUnichar* infoStr = ToNewUnicode(info); + if (!infoStr) { + CleanupArray(array, count); + return NS_ERROR_OUT_OF_MEMORY; + } + array[count++] = infoStr; + } + + printerInx++; + } + *aCount = count; + *aResult = array; + + return NS_OK; + +} + +NS_IMETHODIMP nsPrinterEnumeratorWin::EnumeratePrintersExtended(PRUint32* aCount, PRUnichar*** aResult) +{ + return DoEnumeratePrinters(PR_TRUE, aCount, aResult); +} + +//---------------------------------------------------------------------------------- +// Enumerate all the Printers from the global array and pass their +// names back (usually to script) +NS_IMETHODIMP +nsPrinterEnumeratorWin::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) +{ + return DoEnumeratePrinters(PR_FALSE, aCount, aResult); +} + +//---------------------------------------------------------------------------------- +// Display the AdvancedDocumentProperties for the selected Printer +NS_IMETHODIMP nsPrinterEnumeratorWin::DisplayPropertiesDlg(const PRUnichar *aPrinterName, nsIPrintSettings* aPrintSettings) +{ + LPPRINTER_INFO_2 prtInfo = GlobalPrinters::GetInstance()->FindPrinterByName(aPrinterName); + if (prtInfo == nsnull) { + return NS_ERROR_FAILURE; + } + + nsresult rv = NS_ERROR_FAILURE; + + LPDEVMODE lpDevMode = prtInfo->pDevMode; + + // Convert Printer Name from Unicode to char* + const char* nameCStr = NS_ConvertUCS2toUTF8(aPrinterName).get(); + + if (nameCStr != nsnull) { + HANDLE hPrinter = NULL; + + PRINTER_DEFAULTS printerDefs; + printerDefs.pDatatype = NULL; + printerDefs.pDevMode = lpDevMode; + printerDefs.DesiredAccess = PRINTER_ACCESS_USE; + + BOOL status = ::OpenPrinter((char*)nameCStr, &hPrinter, &printerDefs); + if (status) { + // For some unknown reason calling AdvancedDocumentProperties with the output arg + // set to NULL doesn't return the number of bytes needed like the MS documentation says + // it should. So I am calling DocumentProperties to get the number of bytes for the new DevMode + // but calling it with a NULL output arg also causes problems + // So I am creating a 1K buffer and using that and then if the returned size is larger + // reallocate the buffer with the new size. + const int kBufferSize = 1024; + LPDEVMODE newDevMode = (LPDEVMODE)malloc(kBufferSize); + nsCRT::memset(newDevMode, 0, 1024); + newDevMode->dmSize = sizeof(DEVMODE); + + // get the bytes need for the new DevMode +#if 0 // leave this ifdef'ed for now + LONG bytesNeeded = DocumentProperties(NULL, hPrinter, nameCStr, newDevMode, lpDevMode, 0); + if (bytesNeeded > kBufferSize) { + free(newDevMode); + newDevMode = (LPDEVMODE)malloc(bytesNeeded); + } +#endif + if (newDevMode != nsnull) { + SetupDevModeFromSettings(lpDevMode, aPrintSettings); + + // Display the Dialog and get the new DevMode +#if 0 // need more to do more work to see why AdvancedDocumentProperties fails + // when cancel is pressed + LONG stat = ::AdvancedDocumentProperties(gParentWnd, hPrinter, prtInfo->pDriverName, newDevMode, lpDevMode); +#else + LONG stat = ::DocumentProperties(gParentWnd, hPrinter, prtInfo->pPrinterName, newDevMode, lpDevMode, DM_IN_BUFFER|DM_IN_PROMPT|DM_OUT_BUFFER); +#endif + if (stat == IDOK) { + LONG size = sizeof(*lpDevMode); + memcpy((void*)lpDevMode, (void*)newDevMode, size); + // Now set the print options from the native Page Setup + SetPrintSettingsFromDevMode(aPrintSettings, lpDevMode); + } + ::ClosePrinter(hPrinter); + free(newDevMode); + rv = NS_OK; + } else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + } else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + + return rv; +} + + +//---------------------------------------------------------------------------------- +//-- Global Printers +//---------------------------------------------------------------------------------- + +//---------------------------------------------------------------------------------- +// mPrinterInfoArray holds the arrays of LPPRINTER_INFO_2 returned +// by the native Enumeration call +void +GlobalPrinters::ReallocatePrinters() +{ + if (PrintersAreAllocated()) { + FreeGlobalPrinters(); + } + mPrinters = new nsVoidArray(); + NS_ASSERTION(mPrinters, "Printers Array is NULL!"); + + mPrinterInfoArray = new nsVoidArray(); + NS_ASSERTION(mPrinterInfoArray, "Printers Info Array is NULL!"); +} + +//---------------------------------------------------------------------------------- +void +GlobalPrinters::FreeGlobalPrinters() +{ + if (mPrinterInfoArray != nsnull) { + for (int i=0;iCount();i++) { + LPPRINTER_INFO_2 printerInfo = (LPPRINTER_INFO_2)mPrinterInfoArray->ElementAt(i); + if (printerInfo) { + ::HeapFree(GetProcessHeap(), 0, printerInfo); + } + } + delete mPrinterInfoArray; + mPrinterInfoArray = nsnull; + } + if (mPrinters != nsnull) { + delete mPrinters; + mPrinters = nsnull; + } +} + +//---------------------------------------------------------------------------------- +// Find a Printer in the Printer Array by Name +LPPRINTER_INFO_2 +GlobalPrinters::FindPrinterByName(const PRUnichar* aPrinterName) +{ + NS_ASSERTION(mPrinters, "mPrinters cannot be NULL!"); + + if (mPrinters != nsnull) { + for (PRInt32 i=0;iCount();i++) { + LPPRINTER_INFO_2 prtInfo = (LPPRINTER_INFO_2)mPrinters->ElementAt(i); + nsString name; + name = aPrinterName; + if (name.EqualsWithConversion(prtInfo->pPrinterName)) { + return prtInfo; + } + } + } + return nsnull; +} + +//---------------------------------------------------------------------------------- +nsresult +GlobalPrinters::EnumerateNativePrinters(DWORD aWhichPrinters, char* aDefPrinter) +{ +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + OSVERSIONINFO os; + os.dwOSVersionInfoSize = sizeof(os); + ::GetVersionEx(&os); +#endif + + DWORD dwSizeNeeded; + DWORD dwNumItems; + + // Get buffer size + BOOL status = ::EnumPrinters ( aWhichPrinters, NULL, 2, NULL, 0, &dwSizeNeeded, &dwNumItems ); + if (dwSizeNeeded == 0) { + return NS_OK; + } + + // allocate memory for LPPRINTER_INFO_2 array + LPPRINTER_INFO_2 printerInfo = (LPPRINTER_INFO_2)HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, dwSizeNeeded); + if (printerInfo == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // return an array of LPPRINTER_INFO_2 pointers + if (::EnumPrinters (aWhichPrinters, NULL, 2, (LPBYTE)printerInfo, dwSizeNeeded, &dwSizeNeeded, &dwNumItems) == 0 ) { + return NS_ERROR_OUT_OF_MEMORY; + } + + if ((mPrinters == nsnull || mPrinterInfoArray == nsnull) && dwNumItems > 0) { + return NS_ERROR_OUT_OF_MEMORY; + } + + for (DWORD i=0;iCount()-1; + for (PRInt32 inx=lastInx;inx>=0;inx--) { + if (inx == lastInx) { + mPrinters->AppendElement(mPrinters->ElementAt(inx)); + } else { + mPrinters->ReplaceElementAt(mPrinters->ElementAt(inx), inx-1); + } + } + mPrinters->ReplaceElementAt((void*)&printerInfo[i], 0); + } else { + mPrinters->AppendElement((void*)&printerInfo[i]); + } + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + printf("-------- %d ---------\n", i); + printf("Printer Name: %s\n" , printerInfo[i].pPrinterName); + printf("Share Name: %s\n" , printerInfo[i].Attributes & PRINTER_ATTRIBUTE_SHARED?printerInfo[i].pShareName:""); + printf("Ports: %s\n" , printerInfo[i].pPortName); + printf("Driver Name: %s\n" , printerInfo[i].pDriverName); + printf("Comment: %s\n" , printerInfo[i].pComment); + printf("Location: %s\n" , printerInfo[i].pLocation); + if (VER_PLATFORM_WIN32_NT != os.dwPlatformId) { + printf("Default Printer: %s\n", printerInfo[i].Attributes & PRINTER_ATTRIBUTE_DEFAULT?"YES":"NO"); + } +#endif + } + + // hang onto the pointer until we are done + mPrinterInfoArray->AppendElement((void*)printerInfo); + return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecWin :: GetDeviceName(char *&aDeviceName) const +//------------------------------------------------------------------ +// At this time, it is the only way I can figure out +// how to get the default printer name is silently invoking the +// native print dialog +void +GlobalPrinters::GetDefaultPrinterName(char*& aDefaultPrinterName) { - aDeviceName = mDeviceName; + aDefaultPrinterName = nsnull; + + PRINTDLG prntdlg; + memset(&prntdlg, 0, sizeof(PRINTDLG)); + + prntdlg.lStructSize = sizeof(prntdlg); + prntdlg.Flags = PD_RETURNDEFAULT | PD_RETURNIC; + + BOOL result = ::PrintDlg(&prntdlg); + + if (TRUE == result) { + DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames); + if ( NULL != devnames ) { + char* device = &(((char *)devnames)[devnames->wDeviceOffset]); + aDefaultPrinterName = new char[strlen(device)+1]; + PL_strcpy(aDefaultPrinterName, device); + ::GlobalUnlock(prntdlg.hDevNames); + } + } +} + +//---------------------------------------------------------------------------------- +// This goes and gets the list of of avilable printers and puts +// the default printer at the beginning of the list +nsresult +GlobalPrinters::EnumeratePrinterList() +{ + // reallocate and get a new list each time it is asked for + // this deletes the list and re-allocates them + ReallocatePrinters(); + + // get the name of the default printer + char* defPrinterName; + GetDefaultPrinterName(defPrinterName); + + // any of these could only fail with an OUT_MEMORY_ERROR + // PRINTER_ENUM_LOCAL should get the network printers on Win95 + nsresult rv = EnumerateNativePrinters(PRINTER_ENUM_LOCAL, defPrinterName); + if (NS_SUCCEEDED(rv)) { + // Gets all networked printer the user has connected to + rv = EnumerateNativePrinters(PRINTER_ENUM_CONNECTIONS, defPrinterName); + } + + if (defPrinterName) delete[] defPrinterName; + + // make sure we at least tried to get the printers + if (!PrintersAreAllocated()) { + return NS_ERROR_FAILURE; + } + return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecWin :: GetDEVMODE(HGLOBAL &aDEVMODE) const -{ - aDEVMODE = mDEVMODE; - return NS_OK; -} diff --git a/mozilla/gfx/src/windows/nsDeviceContextSpecWin.h b/mozilla/gfx/src/windows/nsDeviceContextSpecWin.h index f2138bf99e0..afdc13e978c 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextSpecWin.h +++ b/mozilla/gfx/src/windows/nsDeviceContextSpecWin.h @@ -40,6 +40,8 @@ #define nsDeviceContextSpecWin_h___ #include "nsIDeviceContextSpec.h" +#include "nsIPrintOptions.h" // For nsIPrinterEnumerator +#include "nsIPrintSettings.h" #include class nsDeviceContextSpecWin : public nsIDeviceContextSpec @@ -49,17 +51,52 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD Init(char *aDriverName, char *aDeviceName, HGLOBAL aDEVMODE); - NS_IMETHOD GetDriverName(char *&aDriverName) const; - NS_IMETHOD GetDeviceName(char *&aDeviceName) const; - NS_IMETHOD GetDEVMODE(HGLOBAL &aDevMode) const; + NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, PRBool aQuiet); + + void GetDriverName(char *&aDriverName) const { aDriverName = mDriverName; } + void GetDeviceName(char *&aDeviceName) const { aDeviceName = mDeviceName; } + void GetGlobalDevMode(HGLOBAL &aHGlobal) const { aHGlobal = mGlobalDevMode; } + void GetDevMode(LPDEVMODE &aDevMode) const { aDevMode = mDevMode; } + PRBool IsDEVMODEGlobalHandle() const { return mIsDEVMODEGlobalHandle; } protected: + nsresult ShowXPPrintDialog(PRBool aQuiet); + nsresult ShowNativePrintDialog(nsIWidget* aWidget, PRBool aQuiet); + + void SetDeviceName(char* aDeviceName); + void SetDriverName(char* aDriverName); + void SetGlobalDevMode(HGLOBAL aHGlobal); + void SetDevMode(LPDEVMODE aDevMode); + + void GetDataFromPrinter(PRUnichar * aName); + void SetupPaperInfoFromSettings(); + virtual ~nsDeviceContextSpecWin(); - char *mDriverName; - char *mDeviceName; - HGLOBAL mDEVMODE; + char* mDriverName; + char* mDeviceName; + HGLOBAL mGlobalDevMode; + LPDEVMODE mDevMode; + PRBool mIsDEVMODEGlobalHandle; + + nsCOMPtr mPrintSettings; +}; + + +//------------------------------------------------------------------------- +// Printer Enumerator +//------------------------------------------------------------------------- +class nsPrinterEnumeratorWin : public nsIPrinterEnumerator +{ +public: + nsPrinterEnumeratorWin(); + ~nsPrinterEnumeratorWin(); + NS_DECL_ISUPPORTS + NS_DECL_NSIPRINTERENUMERATOR + +private: + // helper + nsresult DoEnumeratePrinters(PRBool aDoExtended, PRUint32* aCount, PRUnichar*** aResult); }; #endif diff --git a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp index a66645e7f2b..4d410540b22 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp @@ -935,36 +935,39 @@ BOOL CALLBACK abortproc( HDC hdc, int iError ) NS_IMETHODIMP nsDeviceContextWin :: GetDeviceContextFor(nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext) { - char *devicename; - char *drivername; - HGLOBAL hdevmode; - DEVMODE *devmode; - - //XXX this API should take an CID, use the repository and - //then QI for the real object rather than casting... MMP - - aContext = new nsDeviceContextWin(); - if(nsnull != aContext){ - NS_ADDREF(aContext); + nsDeviceContextWin* devConWin = new nsDeviceContextWin(); //ref count 0 + if (devConWin != nsnull) { + // this will ref count it + nsresult rv = devConWin->QueryInterface(NS_GET_IID(nsIDeviceContext), (void**)&aContext); + NS_ASSERTION(NS_SUCCEEDED(rv), "This has to support nsIDeviceContext"); } else { return NS_ERROR_OUT_OF_MEMORY; } - ((nsDeviceContextWin *)aContext)->mSpec = aDevice; + devConWin->mSpec = aDevice; NS_ADDREF(aDevice); - ((nsDeviceContextSpecWin *)aDevice)->GetDeviceName(devicename); - ((nsDeviceContextSpecWin *)aDevice)->GetDriverName(drivername); - ((nsDeviceContextSpecWin *)aDevice)->GetDEVMODE(hdevmode); + char* devicename; + char* drivername; - devmode = (DEVMODE *)::GlobalLock(hdevmode); - HDC dc = ::CreateDC(drivername, devicename, NULL, devmode); + nsDeviceContextSpecWin* devSpecWin = NS_STATIC_CAST(nsDeviceContextSpecWin*, aDevice); + devSpecWin->GetDeviceName(devicename); // sets pointer do not free + devSpecWin->GetDriverName(drivername); // sets pointer do not free -// ::SetAbortProc(dc, (ABORTPROC)abortproc); + HDC dc = NULL; + if (devSpecWin->IsDEVMODEGlobalHandle()) { + HGLOBAL hGlobal; + devSpecWin->GetGlobalDevMode(hGlobal); + LPDEVMODE devmode = (DEVMODE *)::GlobalLock(hGlobal); + dc = ::CreateDC(drivername, devicename, NULL, devmode); + ::GlobalUnlock(hGlobal); + } else { + LPDEVMODE devmode; + devSpecWin->GetDevMode(devmode); + dc = ::CreateDC(drivername, devicename, NULL, devmode); + } - ::GlobalUnlock(hdevmode); - - return ((nsDeviceContextWin *)aContext)->Init(dc, this); + return devConWin->Init(dc, this); // take ownership of the DC } NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle) @@ -978,13 +981,33 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle) titleStr = aTitle; char *title = GetACPString(titleStr); + char* docName = nsnull; + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (printService) { + PRBool printToFile = PR_FALSE; + printService->GetPrintToFile(&printToFile); + if (printToFile) { + PRUnichar* uStr; + printService->GetToFileName(&uStr); + if (uStr != nsnull) { + nsAutoString str(uStr); + if (str.Length() > 0) { + docName = ToNewCString(str); + } + nsMemory::Free(uStr); + } + } + } docinfo.cbSize = sizeof(docinfo); docinfo.lpszDocName = title != nsnull?title:"Mozilla Document"; -#ifdef DEBUG_rods + +#ifdef DEBUG_rodsX docinfo.lpszOutput = "p.ps"; #else - docinfo.lpszOutput = NULL; + docinfo.lpszOutput = docName; #endif + docinfo.lpszDatatype = NULL; docinfo.fwType = 0; @@ -993,9 +1016,8 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle) else rv = NS_ERROR_FAILURE; - if (title != nsnull) { - delete [] title; - } + if (title != nsnull) delete [] title; + if (docName != nsnull) nsMemory::Free(docName); } return rv; diff --git a/mozilla/gfx/src/windows/nsGfxFactoryWin.cpp b/mozilla/gfx/src/windows/nsGfxFactoryWin.cpp index 351ca961f82..0c45c6ac024 100644 --- a/mozilla/gfx/src/windows/nsGfxFactoryWin.cpp +++ b/mozilla/gfx/src/windows/nsGfxFactoryWin.cpp @@ -69,6 +69,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsWin) NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorWin) NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList) NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin) NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeWin) PRBool @@ -213,7 +214,11 @@ static nsModuleComponentInfo components[] = NS_SCREENMANAGER_CID, "@mozilla.org/gfx/screenmanager;1", nsScreenManagerWinConstructor }, - + { "Win Printer Enumerator", + NS_PRINTER_ENUMERATOR_CID, + // "@mozilla.org/gfx/printer_enumerator/win;1", + "@mozilla.org/gfx/printerenumerator;1", + nsPrinterEnumeratorWinConstructor }, { "Native Theme Renderer", NS_THEMERENDERER_CID, "@mozilla.org/chrome/chrome-native-theme;1", diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.cpp b/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.cpp index 0c3bace23aa..0108332c461 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.cpp +++ b/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.cpp @@ -60,6 +60,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryXlib::Init(void) } NS_IMETHODIMP nsDeviceContextSpecFactoryXlib::CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet) { @@ -68,7 +69,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryXlib::CreateDeviceContextSpec(nsIWidget nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); if (NS_SUCCEEDED(rv)) { - rv = ((nsDeviceContextSpecXlib *)devSpec.get())->Init(aQuiet); + rv = ((nsDeviceContextSpecXlib *)devSpec.get())->Init(aPrintSettings, aQuiet); if (NS_SUCCEEDED(rv)) { aNewSpec = devSpec; diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.h b/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.h index 2def61a596f..7441831e940 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.h +++ b/mozilla/gfx/src/xlib/nsDeviceContextSpecFactoryX.h @@ -52,6 +52,7 @@ public: NS_IMETHOD Init(void); NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, nsIDeviceContextSpec *&aNewSpec, PRBool aQuiet); diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp index d01effa1606..4e9de0eb2d0 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp +++ b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp @@ -39,12 +39,6 @@ #include "nsDeviceContextSpecXlib.h" -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" -#include "nsIPrintOptions.h" -#include "nsReadableUtils.h" -#include "nsGfxCIID.h" - #include "nsIPref.h" #include "prenv.h" /* for PR_GetEnv */ @@ -54,14 +48,45 @@ #include "nsISupportsPrimitives.h" #include "nsIWindowWatcher.h" +#include "nsReadableUtils.h" +#include "nsISupportsArray.h" + #ifdef USE_XPRINT #include "xprintutil.h" #endif /* USE_XPRINT */ -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +//---------------------------------------------------------------------------------- +// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecXLib +// The PrinterEnumerator creates the printer info +// but the nsDeviceContextSpecXLib cleans it up +// If it gets created (via the Page Setup Dialog) but the user never prints anything +// then it will never be delete, so this class takes care of that. +class GlobalPrinters { +public: + static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } + ~GlobalPrinters() { FreeGlobalPrinters(); } -nsStringArray* nsDeviceContextSpecXlib::globalPrinterList = nsnull; -int nsDeviceContextSpecXlib::globalNumPrinters = 0; + void FreeGlobalPrinters(); + nsresult InitializeGlobalPrinters(); + + PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; } + PRInt32 GetNumPrinters() { return mGlobalNumPrinters; } + nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } + +protected: + GlobalPrinters() {} + + static GlobalPrinters mGlobalPrinters; + static nsStringArray* mGlobalPrinterList; + static int mGlobalNumPrinters; + +}; +//--------------- +// static members +GlobalPrinters GlobalPrinters::mGlobalPrinters; +nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull; +int GlobalPrinters::mGlobalNumPrinters = 0; +//--------------- nsDeviceContextSpecXlib::nsDeviceContextSpecXlib() { @@ -128,80 +153,66 @@ NS_IMPL_RELEASE(nsDeviceContextSpecXlib) int nsDeviceContextSpecXlib::InitializeGlobalPrinters () { - globalNumPrinters = 0; - globalPrinterList = new nsStringArray(); - if (!globalPrinterList) - return NS_ERROR_OUT_OF_MEMORY; - -#ifdef USE_XPRINT - XPPrinterList plist = XpuGetPrinterList(nsnull, &globalNumPrinters); - - if (plist && (globalNumPrinters > 0)) - { - int i; - for( i = 0 ; i < globalNumPrinters ; i++ ) - { - globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); - } - - XpuFreePrinterList(plist); - } -#endif /* USE_XPRINT */ - - /* add an entry for the default printer (see nsPostScriptObj.cpp) */ - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); - globalNumPrinters++; - - /* get the list of printers */ - char *printerList = nsnull; - - /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ - printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); - - if (!printerList) { - nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - (void) pPrefs->CopyCharPref("print.printer_list", &printerList); - } - } - - if (printerList) { - char *tok_lasts; - char *name; - - /* PL_strtok_r() will modify the string - copy it! */ - printerList = strdup(printerList); - if (!printerList) - return NS_ERROR_OUT_OF_MEMORY; - - for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; - name != nsnull ; - name = PL_strtok_r(nsnull, " ", &tok_lasts) ) - { - globalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + - nsString(NS_ConvertASCIItoUCS2(name))); - globalNumPrinters++; - } - - free(printerList); - } - - if (globalNumPrinters == 0) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - - return NS_OK; } -void nsDeviceContextSpecXlib::FreeGlobalPrinters() +/** ------------------------------------------------------- + */ +static nsresult DisplayXPDialog(nsIPrintSettings* aPS, + const char* aChromeURL, + PRBool& aClickedOK) { - delete globalPrinterList; - globalPrinterList = nsnull; - globalNumPrinters = 0; -} + NS_ASSERTION(aPS, "Must have a print settings!"); + aClickedOK = PR_FALSE; + nsresult rv = NS_ERROR_FAILURE; + + // create a nsISupportsArray of the parameters + // being passed to the window + nsCOMPtr array; + NS_NewISupportsArray(getter_AddRefs(array)); + if (!array) return NS_ERROR_FAILURE; + + nsCOMPtr ps = aPS; + nsCOMPtr psSupports(do_QueryInterface(ps)); + NS_ASSERTION(psSupports, "PrintSettings must be a supports"); + array->AppendElement(psSupports); + + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); + if (ioParamBlock) { + ioParamBlock->SetInt(0, 0); + nsCOMPtr blkSupps(do_QueryInterface(ioParamBlock)); + NS_ASSERTION(blkSupps, "IOBlk must be a supports"); + + array->AppendElement(blkSupps); + nsCOMPtr arguments(do_QueryInterface(array)); + NS_ASSERTION(array, "array must be a supports"); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + nsCOMPtr parent = do_QueryInterface(active); + + nsCOMPtr newWindow; + rv = wwatch->OpenWindow(parent, aChromeURL, + "_blank", "chrome,modal,centerscreen", array, + getter_AddRefs(newWindow)); + } + } + + if (NS_SUCCEEDED(rv)) { + PRInt32 buttonPressed = 0; + ioParamBlock->GetInt(0, &buttonPressed); + if (buttonPressed == 1) { + aClickedOK = PR_TRUE; + } else { + rv = NS_ERROR_ABORT; + } + } else { + rv = NS_ERROR_ABORT; + } + return rv; +} /** ------------------------------------------------------- * Initialize the nsDeviceContextSpecGTK @@ -222,17 +233,16 @@ void nsDeviceContextSpecXlib::FreeGlobalPrinters() * * ** Please update the other toolkits when changing this function. */ -NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet) +NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings* aPS, PRBool aQuiet) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); - NS_ASSERTION(nsnull != printService, "No print service."); + NS_ASSERTION(nsnull != aPS, "No print settings."); // if there is a current selection then enable the "Selection" radio button - if (NS_SUCCEEDED(rv) && printService) { + if (aPS != nsnull) { PRBool isOn; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn); + aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); @@ -244,7 +254,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet) PRBool reversed = PR_FALSE; PRBool color = PR_FALSE; PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintOptions::kRangeAllPages; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 paper_size = NS_LETTER_SIZE; PRInt32 orientation = NS_PORTRAIT; PRInt32 fromPage = 1; @@ -258,71 +268,39 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet) double dtop = 0.5; double dbottom = 0.5; - if( !globalPrinterList ) - if (InitializeGlobalPrinters()) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; - if( globalNumPrinters && !globalPrinterList->Count() ) - return NS_ERROR_OUT_OF_MEMORY; + rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } if (!aQuiet ) { - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - if (NS_SUCCEEDED(rv)) { - PRInt32 buttonPressed = 0; - ioParamBlock->GetInt(0, &buttonPressed); - if (buttonPressed == 0) { - canPrint = PR_TRUE; - } - else { - rv = NS_ERROR_ABORT; - } - } + rv = DisplayXPDialog(aPS, + "chrome://global/content/printdialog.xul", canPrint); } else { canPrint = PR_TRUE; } - FreeGlobalPrinters(); + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); if (canPrint) { - if (printService) { - printService->GetPrinter(&printer); - printService->GetPrintReversed(&reversed); - printService->GetPrintInColor(&color); - printService->GetPaperSize(&paper_size); - printService->GetOrientation(&orientation); - printService->GetPrintCommand(&command); - printService->GetPrintRange(&printRange); - printService->GetToFileName(&printfile); - printService->GetPrintToFile(&tofile); - printService->GetStartPageRange(&fromPage); - printService->GetEndPageRange(&toPage); - printService->GetNumCopies(&copies); - printService->GetMarginTop(&dtop); - printService->GetMarginLeft(&dleft); - printService->GetMarginBottom(&dbottom); - printService->GetMarginRight(&dright); + if (aPS != nsnull) { + aPS->GetPrinterName(&printer); + aPS->GetPrintReversed(&reversed); + aPS->GetPrintInColor(&color); + aPS->GetPaperSize(&paper_size); + aPS->GetOrientation(&orientation); + aPS->GetPrintCommand(&command); + aPS->GetPrintRange(&printRange); + aPS->GetToFileName(&printfile); + aPS->GetPrintToFile(&tofile); + aPS->GetStartPageRange(&fromPage); + aPS->GetEndPageRange(&toPage); + aPS->GetNumCopies(&copies); + aPS->GetMarginTop(&dtop); + aPS->GetMarginLeft(&dleft); + aPS->GetMarginBottom(&dbottom); + aPS->GetMarginRight(&dright); if (command != nsnull && printfile != nsnull) { // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446) @@ -374,7 +352,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet) #ifdef NOT_IMPLEMENTED_YET if (globalNumPrinters) { for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) { - if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) + if (!(mGlobalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1))) mQueue = PrnDlg.SetPrinterQueue(i); } } @@ -399,7 +377,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::GetToPrinter(PRBool &aToPrinter) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinter ( char **aPrinter ) +NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinterName ( char **aPrinter ) { *aPrinter = &mPrData.printer[0]; return NS_OK; @@ -535,8 +513,20 @@ nsPrinterEnumeratorXlib::nsPrinterEnumeratorXlib() NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorXlib, nsIPrinterEnumerator) +NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrintersExtended(PRUint32* aCount, PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + *aCount = 0; + *aResult = nsnull; + return NS_OK; +} + NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) { + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + if (aCount) *aCount = 0; else @@ -547,21 +537,32 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUni else return NS_ERROR_NULL_POINTER; + nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } - PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecXlib::globalNumPrinters * sizeof(PRUnichar*)); - if (!array && nsDeviceContextSpecXlib::globalNumPrinters) + PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); + + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*)); + if (!array && numPrinters > 0) { + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; + } int count = 0; - while( count < nsDeviceContextSpecXlib::globalNumPrinters ) + while( count < numPrinters ) { - PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecXlib::globalPrinterList->StringAt(count)); + + PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count)); if (!str) { for (int i = count - 1; i >= 0; i--) nsMemory::Free(array[i]); nsMemory::Free(array); + + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_ERROR_OUT_OF_MEMORY; } array[count++] = str; @@ -569,14 +570,13 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUni } *aCount = count; *aResult = array; + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); return NS_OK; } -NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPrinter) +NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) { - nsresult rv = NS_ERROR_FAILURE; - /* fixme: We simply ignore the |aPrinter| argument here * We should get the supported printer attributes from the printer and * populate the print job options dialog with these data instead of using @@ -585,32 +585,94 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPr * of patches ... ;-( */ - nsCOMPtr printService(do_GetService(kPrintOptionsCID, &rv)); + PRBool pressedOK; + return DisplayXPDialog(aPrintSettings, + "chrome://global/content/printjoboptions.xul", + pressedOK); - rv = NS_ERROR_FAILURE; - nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); - - nsCOMPtr paramBlockWrapper; - if (ioParamBlock) - paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID); - - if (paramBlockWrapper) { - paramBlockWrapper->SetData(ioParamBlock); - paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (wwatch) { - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - nsCOMPtr parent = do_QueryInterface(active); - - nsCOMPtr newWindow; - rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions.xul", - "_blank", "chrome,modal", paramBlockWrapper, - getter_AddRefs(newWindow)); - } - } - - return rv; } +//---------------------------------------------------------------------- +nsresult GlobalPrinters::InitializeGlobalPrinters () +{ + if (PrintersAreAllocated()) { + return NS_OK; + } + + mGlobalNumPrinters = 0; + mGlobalPrinterList = new nsStringArray(); + if (!mGlobalPrinterList) + return NS_ERROR_OUT_OF_MEMORY; + +#ifdef USE_XPRINT + XPPrinterList plist = XpuGetPrinterList(nsnull, &mGlobalNumPrinters); + + if (plist && (mGlobalNumPrinters > 0)) + { + int i; + for( i = 0 ; i < mGlobalNumPrinters ; i++ ) + { + mGlobalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); + } + + XpuFreePrinterList(plist); + } +#endif /* USE_XPRINT */ + + /* add an entry for the default printer (see nsPostScriptObj.cpp) */ + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); + mGlobalNumPrinters++; + + /* get the list of printers */ + char *printerList = nsnull; + + /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */ + printerList = PR_GetEnv("MOZILLA_PRINTER_LIST"); + + if (!printerList) { + nsresult rv; + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->CopyCharPref("print.printer_list", &printerList); + } + } + + if (printerList) { + char *tok_lasts; + char *name; + + /* PL_strtok_r() will modify the string - copy it! */ + printerList = strdup(printerList); + if (!printerList) + return NS_ERROR_OUT_OF_MEMORY; + + for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; + name != nsnull ; + name = PL_strtok_r(nsnull, " ", &tok_lasts) ) + { + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + + nsString(NS_ConvertASCIItoUCS2(name))); + mGlobalNumPrinters++; + } + + free(printerList); + } + + if (mGlobalNumPrinters == 0) + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; + + return NS_OK; +} + +//---------------------------------------------------------------------- +void GlobalPrinters::FreeGlobalPrinters() +{ + delete mGlobalPrinterList; + mGlobalPrinterList = nsnull; + mGlobalNumPrinters = 0; +} + + + diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h index 3e2c2c5cee0..38583af659f 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h +++ b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h @@ -41,7 +41,8 @@ #define nsDeviceContextSpecXlib_h___ #include "nsIDeviceContextSpec.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" +#include "nsIPrintOptions.h" #include "nsVoidArray.h" #include "nsIDeviceContextSpecPS.h" #ifdef USE_XPRINT @@ -67,11 +68,11 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD Init(PRBool aQuiet); + NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet); NS_IMETHOD ClosePrintManager(); NS_IMETHOD GetToPrinter(PRBool &aToPrinter); - NS_IMETHOD GetPrinter ( char **aPrinter ); + NS_IMETHOD GetPrinterName ( char **aPrinter ); NS_IMETHOD GetCopies ( int &aCopies ); NS_IMETHOD GetFirstPageFirst(PRBool &aFpf); NS_IMETHOD GetGrayscale(PRBool &aGrayscale); @@ -88,10 +89,6 @@ public: NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); virtual ~nsDeviceContextSpecXlib(); - static nsStringArray *globalPrinterList; - static int globalNumPrinters; - int InitializeGlobalPrinters(); - void FreeGlobalPrinters(); protected: UnixPrData mPrData; }; diff --git a/mozilla/gfx/src/xprint/nsIDeviceContextSpecXPrint.h b/mozilla/gfx/src/xprint/nsIDeviceContextSpecXPrint.h index d2acf9e5a22..a82d2112b54 100644 --- a/mozilla/gfx/src/xprint/nsIDeviceContextSpecXPrint.h +++ b/mozilla/gfx/src/xprint/nsIDeviceContextSpecXPrint.h @@ -120,7 +120,7 @@ public: * @param aPrinter -- * @return **/ - NS_IMETHOD GetPrinter ( char **aPrinter ) = 0; + NS_IMETHOD GetPrinterName ( char **aPrinter ) = 0; /* * Get width and height based on user page size choice, e.g., 8.5 x 11.0 diff --git a/mozilla/gfx/src/xprint/nsXPrintContext.cpp b/mozilla/gfx/src/xprint/nsXPrintContext.cpp index 08fcabb50c7..6fa3352bd94 100644 --- a/mozilla/gfx/src/xprint/nsXPrintContext.cpp +++ b/mozilla/gfx/src/xprint/nsXPrintContext.cpp @@ -95,6 +95,7 @@ nsXPrintContext::nsXPrintContext() mScreen = (Screen *)nsnull; mVisual = (Visual *)nsnull; mDrawable = (Drawable)None; + mGC = nsnull; mDepth = 0; mIsGrayscale = PR_FALSE; /* default is color output */ mIsAPrinter = PR_TRUE; /* default destination is printer */ @@ -111,8 +112,7 @@ nsXPrintContext::~nsXPrintContext() { PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::~nsXPrintContext()\n")); - // end the document - if( mPDisplay != nsnull ) + if (mPDisplay) { if (mGC) { @@ -120,15 +120,20 @@ nsXPrintContext::~nsXPrintContext() mGC = nsnull; } - XPU_TRACE(XpDestroyContext(mPDisplay, mPContext)); - - // Cleanup things allocated along the way - xxlib_rgb_destroy_handle(mXlibRgbHandle); - mXlibRgbHandle = nsnull; + if (mPContext != None) + { + XPU_TRACE(XpDestroyContext(mPDisplay, mPContext)); + mPContext = None; + } + if (mXlibRgbHandle) + { + xxlib_rgb_destroy_handle(mXlibRgbHandle); + mXlibRgbHandle = nsnull; + } + XPU_TRACE(XCloseDisplay(mPDisplay)); - mPContext = nsnull; mPDisplay = nsnull; } @@ -266,7 +271,7 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec) /* get destination printer (we need this when printing to file as * the printer DDX in Xprt generates the data...) */ - aSpec->GetPrinter(&buf); + aSpec->GetPrinterName(&buf); /* Are we "printing" to a file instead to the print queue ? */ if (!mIsAPrinter) diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 5ee3fcdeb10..781da6156bc 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -119,11 +119,14 @@ #include "nsIFocusController.h" // Print Options +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms +#include "nsISimpleEnumerator.h" +#include "nsISupportsPrimitives.h" +static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // Printing Events #include "nsIEventQueue.h" @@ -140,6 +143,11 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsIEventProcessor.h" #include "imgIContainer.h" // image animation mode constants +// Print Progress +#include "nsPrintProgress.h" +#include "nsPrintProgressParams.h" + + // Print error dialog #include "nsIPrompt.h" #include "nsIWindowWatcher.h" @@ -354,15 +362,25 @@ public: // Listener Helper Methods void OnEndPrinting(nsresult aResult); void OnStartPrinting(); + static void DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, + PRInt32 aMaxProgress, + PRBool aDoStartStop = PR_FALSE, + PRInt32 aFlag = 0); nsCOMPtr mPrintDC; nsIView *mPrintView; - FILE *mFilePointer; // a file where information can go to when printing + FILE *mDebugFilePtr; // a file where information can go to when printing PrintObject * mPrintObject; PrintObject * mSelectedPO; - nsCOMPtr mPrintListener; // An observer for printing... + nsVoidArray mPrintProgressListeners; + nsCOMPtr mPrintProgressListener; + nsCOMPtr mPrintProgress; + nsCOMPtr mPrintProgressParams; + PRBool mShowProgressDialog; + nsCOMPtr mCurrentFocusWin; // cache a pointer to the currently focused window nsVoidArray* mPrintDocList; @@ -378,6 +396,8 @@ public: PRInt32 mNumPrintablePages; PRInt32 mNumPagesPrinted; + nsCOMPtr mPrintSettings; + #ifdef DEBUG_PRINTING FILE * mDebugFD; #endif @@ -436,7 +456,7 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // Printing Methods - PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintOptions* aPrintOptions,PrintObject* aPOect); + PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintSettings* aPrintSettings,PrintObject* aPOect); PRBool DonePrintingPages(PrintObject* aPO); // helper method @@ -493,6 +513,12 @@ private: void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages); void DoProgressForAsIsFrames(); void DoProgressForSeparateFrames(); + void DoPrintProgress(PRBool aIsForPrinting); + void SetDocAndURLIntoProgress(nsIWebShell* aWebShell, nsIPrintProgressParams* aParams); + nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, + PRUint32 aErrorCode, + PRBool aIsPrinting); // get the currently infocus frame for the document viewer nsIDOMWindowInternal * FindFocusedDOMWindowInternal(); @@ -531,14 +557,14 @@ private: // Timer Methods nsresult StartPagePrintTimer(nsIPresContext * aPresContext, - nsIPrintOptions* aPrintOptions, - PrintObject* aPOect, + nsIPrintSettings* aPrintSettings, + PrintObject* aPO, PRUint32 aDelay); void PrepareToStartLoad(void); // Misc - void ShowPrintErrorDialog(nsresult printerror); + void ShowPrintErrorDialog(nsresult printerror, PRBool aIsPrinting = PR_TRUE); protected: // IMPORTANT: The ownership implicit in the following member @@ -585,6 +611,10 @@ protected: PrintData* mPrtPreview; #endif +#ifdef NS_DEBUG + FILE* mDebugFile; +#endif + // static memeber variables static PRBool mIsCreatingPrintPreview; static PRBool mIsDoingPrinting; @@ -610,7 +640,7 @@ public: NS_DECL_ISUPPORTS nsPagePrintTimer() - : mDocViewer(nsnull), mPresContext(nsnull), mPrintOptions(nsnull), mDelay(0) + : mDocViewer(nsnull), mPresContext(nsnull), mPrintSettings(nsnull), mDelay(0) { NS_INIT_ISUPPORTS(); } @@ -648,7 +678,7 @@ public: // Check to see if we are done // donePrinting will be true if it completed successfully or // if the printing was cancelled - PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintOptions, mPrintObj); + PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintSettings, mPrintObj); if (donePrinting) { // now clean up print or print the next webshell if (mDocViewer->DonePrintingPages(mPrintObj)) { @@ -669,7 +699,7 @@ public: void Init(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay) { @@ -678,18 +708,18 @@ public: NS_ADDREF(mDocViewer); mPresContext = aPresContext; - mPrintOptions = aPrintOptions; + mPrintSettings = aPrintSettings; mPrintObj = aPO; mDelay = aDelay; } nsresult Start(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay) { - Init(aDocViewerImpl, aPresContext, aPrintOptions, aPO, aDelay); + Init(aDocViewerImpl, aPresContext, aPrintSettings, aPO, aDelay); return StartTimer(); } @@ -703,12 +733,12 @@ public: } private: - DocumentViewerImpl* mDocViewer; - nsIPresContext* mPresContext; - nsIPrintOptions* mPrintOptions; - nsCOMPtr mTimer; - PRUint32 mDelay; - PrintObject * mPrintObj; + DocumentViewerImpl* mDocViewer; + nsIPresContext* mPresContext; + nsCOMPtr mPrintSettings; + nsCOMPtr mTimer; + PRUint32 mDelay; + PrintObject * mPrintObj; }; NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback) @@ -735,10 +765,10 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult) //-- PrintData Class Impl //--------------------------------------------------- PrintData::PrintData() : - mPrintView(nsnull), mFilePointer(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), - mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), + mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), + mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), - mPrintFrameType(nsIPrintOptions::kFramesAsIs), mOnStartSent(PR_FALSE), + mPrintFrameType(nsIPrintSettings::kFramesAsIs), mOnStartSent(PR_FALSE), mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0) { #ifdef DEBUG_PRINTING @@ -762,35 +792,58 @@ PrintData::~PrintData() delete mPrintObject; - mPrintDocList->Clear(); - delete mPrintDocList; + if (mPrintDocList != nsnull) { + mPrintDocList->Clear(); + delete mPrintDocList; + } #ifdef DEBUG_PRINTING fclose(mDebugFD); #endif DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; + + for (PRInt32 i=0;iOnStartPrinting(); - } + if (!mOnStartSent) { + DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT); mOnStartSent = PR_TRUE; } } void PrintData::OnEndPrinting(nsresult aResult) { - if (mPrintListener) { - if (!mOnStartSent) { - mPrintListener->OnStartPrinting(); + // Make sure OnStartPrinting was called + OnStartPrinting(); + + DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT); + if (mPrintProgress && mShowProgressDialog) { + mPrintProgress->CloseProgressDialog(PR_TRUE); + } +} + +void +PrintData::DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, + PRInt32 aMaxProgress, + PRBool aDoStartStop, + PRInt32 aFlag) +{ + for (PRInt32 i=0;iOnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); + if (aDoStartStop) { + wpl->OnStateChange(nsnull, nsnull, aFlag, 0); } - mPrintListener->OnEndPrinting(aResult); - // clear the lister so the destructor doesn't send the - mPrintListener = nsnull; } } @@ -875,6 +928,10 @@ void DocumentViewerImpl::PrepareToStartLoad() { mIsDoingPrintPreview = PR_FALSE; mPrtPreview = nsnull; #endif + +#ifdef NS_DEBUG + mDebugFile = nsnull; +#endif } DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) @@ -2306,27 +2363,34 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) //------------------------------------------------------- PRBool -DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - PrintObject* aPO) +DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, + nsIPrintSettings* aPrintSettings, + PrintObject* aPO) { NS_ASSERTION(aPresContext, "Pointer is null!"); - NS_ASSERTION(aPrintOptions, "Pointer is null!"); + NS_ASSERTION(aPrintSettings, "Pointer is null!"); NS_ASSERTION(aPO, "Pointer is null!"); PRINT_DEBUG_MSG1("-----------------------------------\n"); PRINT_DEBUG_MSG3("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesStr[aPO->mFrameType]); - nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { + if (aPrintSettings != nsnull) { PRBool isCancelled; - printService->GetIsCancelled(&isCancelled); + aPrintSettings->GetIsCancelled(&isCancelled); // DO NOT allow the print job to be cancelled if it is Print FrameAsIs // because it is only printing one page. - if (isCancelled && mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs) { - printService->SetIsCancelled(PR_FALSE); + if (isCancelled && mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs) { + aPrintSettings->SetIsCancelled(PR_FALSE); + return PR_TRUE; + } + } + if (mPrt->mPrintProgress) { + PRBool isCancelled; + mPrt->mPrintProgress->GetProcessCanceledByUser(&isCancelled); + // DO NOT allow the print job to be cancelled if it is Print FrameAsIs + // because it is only printing one page. + if (isCancelled && mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs) { + aPrintSettings->SetIsCancelled(PR_FALSE); return PR_TRUE; } } @@ -2370,19 +2434,12 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // NOTE: mPrt->mPrintFrameType gets set to "kFramesAsIs" when a // plain document contains IFrames, so we need to override that case here - if (mPrt->mPrintListener) { - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { - DoProgressForSeparateFrames(); + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + DoProgressForSeparateFrames(); - } else if (mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs || - mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { - // Make sure the Listener gets a "zero" progress at the beginning - // so it can initialize it's state - if (curPage == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, endPage); - } - mPrt->mPrintListener->OnProgressPrinting(curPage, endPage); - } + } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || + mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, curPage+1, endPage); } // Set Clip when Printing "AsIs" or @@ -2390,11 +2447,11 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, PRBool setClip = PR_FALSE; switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: setClip = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO->mPrintAsIs) { if (aPO->mFrameType == eIFrame) { setClip = aPO != mPrt->mSelectedPO; @@ -2402,7 +2459,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: if (aPO->mPrintAsIs) { if (aPO->mFrameType == eIFrame) { setClip = PR_TRUE; @@ -2420,7 +2477,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // if a print job was cancelled externally, an EndPage or BeginPage may // fail and the failure is passed back here. // Returning PR_TRUE means we are done printing. - if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext, aPrintOptions))) { + if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext))) { return PR_TRUE; } @@ -2454,7 +2511,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // XXX this is because PrintAsIs for FrameSets reflows to two pages // not sure why, but this needs to be fixed. - if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { return PR_TRUE; } } @@ -2801,7 +2858,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, if (aDoingSetClip) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mClipRect.height); clipRect = aPO->mClipRect; - } else if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + } else if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.height); clipRect = aPO->mClipRect; doClip = PR_TRUE; @@ -2814,7 +2871,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, clipRect = aPO->mClipRect; } else { - if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if (aPO->mParent && aPO->mParent == mPrt->mSelectedPO) { aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.height); clipRect = aPO->mClipRect; @@ -2887,20 +2944,19 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) PRBool containerIsSet = PR_FALSE; nsresult rv; if (mIsCreatingPrintPreview) { - aPO->mPresContext = do_CreateInstance(kPrintPreviewContextCID,&rv); + nsCOMPtr printPreviewCon(do_CreateInstance(kPrintPreviewContextCID, &rv)); if (NS_FAILED(rv)) { return rv; } + aPO->mPresContext = do_QueryInterface(printPreviewCon); + printPreviewCon->SetPrintSettings(mPrt->mPrintSettings); } else { nsCOMPtr printcon(do_CreateInstance(kPrintContextCID, &rv)); if (NS_FAILED(rv)) { return rv; - } else { - aPO->mPresContext = do_QueryInterface(printcon); - if (NS_FAILED(rv)) { - return rv; - } } + aPO->mPresContext = do_QueryInterface(printcon); + printcon->SetPrintSettings(mPrt->mPrintSettings); } // init it with the DC @@ -2946,15 +3002,13 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) // This means you can never print any selection that is longer than one page // put it keeps it from page breaking in the middle of your print of the selection // (see also nsSimplePageSequence.cpp) - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->GetPrintRange(&printRangeType); + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + if (mPrt->mPrintSettings != nsnull) { + mPrt->mPrintSettings->GetPrintRange(&printRangeType); } - if (printRangeType == nsIPrintOptions::kRangeSelection && IsThereARangeSelection(domWinIntl)) { + if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSelection(domWinIntl)) { height = 0x0FFFFFFF; } nsRect tbounds = nsRect(0, 0, width, height); @@ -3033,9 +3087,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) aPO->mPresShell->BeginObservingDocument(); nsMargin margin(0,0,0,0); - if (printService) { - printService->GetMarginInTwips(margin); - } + mPrt->mPrintSettings->GetMarginInTwips(margin); // initialize it with the default/generic case nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); @@ -3047,7 +3099,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) const PRInt32 kFivePagesHigh = 5; // now, change the value for special cases - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { if (aPO->mFrameType == eFrame) { adjRect.SetRect(0, 0, width, height); } else if (aPO->mFrameType == eIFrame) { @@ -3055,7 +3107,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); } - } else if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + } else if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if (aPO->mFrameType == eFrame) { adjRect.SetRect(0, 0, width, height); } else if (aPO->mFrameType == eIFrame) { @@ -3090,7 +3142,6 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO) } } } - #ifdef DEBUG_rods { @@ -3222,21 +3273,18 @@ DocumentViewerImpl::EnablePOsForPrinting() // this is where we decided which POs get printed. mPrt->mSelectedPO = nsnull; - nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_FAILED(rv)) { - return rv; + if (mPrt->mPrintSettings == nsnull) { + return NS_ERROR_FAILURE; } - mPrt->mPrintFrameType = nsIPrintOptions::kNoFrames; - printService->GetPrintFrameType(&mPrt->mPrintFrameType); + mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; + mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - printService->GetPrintRange(&printRangeType); + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->GetPrintRange(&printRangeType); PRINT_DEBUG_MSG1("\n********* DocumentViewerImpl::EnablePOsForPrinting *********\n"); PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); @@ -3248,9 +3296,9 @@ DocumentViewerImpl::EnablePOsForPrinting() // ***** This is the ultimate override ***** // if we are printing the selection (either an IFrame or selection range) // then set the mPrintFrameType as if it were the selected frame - if (printRangeType == nsIPrintOptions::kRangeSelection) { - mPrt->mPrintFrameType = nsIPrintOptions::kSelectedFrame; - printHowEnable = nsIPrintOptions::kFrameEnableNone; + if (printRangeType == nsIPrintSettings::kRangeSelection) { + mPrt->mPrintFrameType = nsIPrintSettings::kSelectedFrame; + printHowEnable = nsIPrintSettings::kFrameEnableNone; } // This tells us that the "Frame" UI has turned off, @@ -3258,11 +3306,11 @@ DocumentViewerImpl::EnablePOsForPrinting() // // This means there are not FrameSets, // but the document could contain an IFrame - if (printHowEnable == nsIPrintOptions::kFrameEnableNone) { + if (printHowEnable == nsIPrintSettings::kFrameEnableNone) { // Print all the pages or a sub range of pages - if (printRangeType == nsIPrintOptions::kRangeAllPages || - printRangeType == nsIPrintOptions::kRangeSpecifiedPageRange) { + if (printRangeType == nsIPrintSettings::kRangeAllPages || + printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); // Set the children so they are PrinAsIs @@ -3275,7 +3323,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // ***** Another override ***** - mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; + mPrt->mPrintFrameType = nsIPrintSettings::kFramesAsIs; } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3285,7 +3333,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // This means we are either printed a selected IFrame or // we are printing the current selection - if (printRangeType == nsIPrintOptions::kRangeSelection) { + if (printRangeType == nsIPrintSettings::kRangeSelection) { // If the currentFocusDOMWin can'r be null if something is selected if (mPrt->mCurrentFocusWin) { @@ -3308,8 +3356,8 @@ DocumentViewerImpl::EnablePOsForPrinting() // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { - printRangeType = nsIPrintOptions::kRangeAllPages; - printService->SetPrintRange(printRangeType); + printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->SetPrintRange(printRangeType); } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3322,6 +3370,7 @@ DocumentViewerImpl::EnablePOsForPrinting() NS_ASSERTION(po, "PrintObject can't be null!"); nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (IsThereARangeSelection(domWin)) { + mPrt->mCurrentFocusWin = domWin; SetPrintPO(po, PR_TRUE); break; } @@ -3332,7 +3381,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // check to see if there is a selection when a FrameSet is present - if (printRangeType == nsIPrintOptions::kRangeSelection) { + if (printRangeType == nsIPrintSettings::kRangeSelection) { // If the currentFocusDOMWin can'r be null if something is selected if (mPrt->mCurrentFocusWin) { // Find the selected IFrame @@ -3354,8 +3403,8 @@ DocumentViewerImpl::EnablePOsForPrinting() // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { - printRangeType = nsIPrintOptions::kRangeAllPages; - printService->SetPrintRange(printRangeType); + printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->SetPrintRange(printRangeType); } PRINT_DEBUG_MSG2("PrintFrameType: %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]); @@ -3366,7 +3415,7 @@ DocumentViewerImpl::EnablePOsForPrinting() } // If we are printing "AsIs" then sets all the POs to be printed as is - if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { SetPrintAsIs(mPrt->mPrintObject); SetPrintPO(mPrt->mPrintObject, PR_TRUE); return NS_OK; @@ -3375,7 +3424,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // If we are printing the selected Frame then // find that PO for that selected DOMWin and set it all of its // children to be printed - if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { if ((mPrt->mIsParentAFrameSet && mPrt->mCurrentFocusWin) || mPrt->mIsIFrameSelected) { PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCurrentFocusWin); @@ -3398,7 +3447,7 @@ DocumentViewerImpl::EnablePOsForPrinting() // If we are print each subdoc separately, // then don't print any of the FraneSet Docs - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); PRInt32 cnt = mPrt->mPrintDocList->Count(); for (PRInt32 i=0;imFilePointer ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); + rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); PRINT_DEBUG_MSG1("****************** Begin Document ************************\n"); if (docTitleStr != nsnull) { @@ -3539,14 +3588,16 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nsCOMPtr webContainer(do_QueryInterface(mContainer)); NS_ASSERTION(webShell, "The WebShell can't be NULL!"); + if (mPrt->mPrintProgressParams) { + SetDocAndURLIntoProgress(aPO->mWebShell, mPrt->mPrintProgressParams); + } + if (webShell != nsnull) { - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - printService->GetPrintRange(&printRangeType); + if (mPrt->mPrintSettings != nsnull) { + mPrt->mPrintSettings->GetPrintRange(&printRangeType); } // Ask the page sequence frame to print all the pages @@ -3566,18 +3617,18 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (aPO->mFrameType == eFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO->mKids.Count() > 0) { skipPageEjectOnly = PR_TRUE; } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: if (aPO->mKids.Count() > 0) { skipPageEjectOnly = PR_TRUE; } @@ -3586,13 +3637,13 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } else if (aPO->mFrameType == eIFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintOptions::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; skipSetTitle = PR_TRUE; break; - case nsIPrintOptions::kSelectedFrame: + case nsIPrintSettings::kSelectedFrame: if (aPO != mPrt->mSelectedPO) { skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; @@ -3603,7 +3654,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } break; - case nsIPrintOptions::kEachFrameSep: + case nsIPrintSettings::kEachFrameSep: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; doAddInParentsOffset = aPO->mParent != nsnull && aPO->mParent->mFrameType == eIFrame; @@ -3637,7 +3688,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a nscoord y = 0; PrintObject * po = aPO; while (po != nsnull) { - //if (mPrt->mPrintFrameType != nsIPrintOptions::kSelectedFrame || po != aPO->mParent) { + //if (mPrt->mPrintFrameType != nsIPrintSettings::kSelectedFrame || po != aPO->mParent) { PRBool isParent = po == aPO->mParent; if (!isParent || (isParent && doAddInParentsOffset)) { x += po->mRect.x; @@ -3653,16 +3704,19 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)); - if (nsnull != mPrt->mFilePointer) { + // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging + if (nsnull != mPrt->mDebugFilePtr) { +#ifdef NS_DEBUG // output the regression test nsIFrameDebug* fdbg; nsIFrame* root; poPresShell->GetRootFrame(&root); if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - fdbg->DumpRegressionData(poPresContext, mPrt->mFilePointer, 0, PR_TRUE); + fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRUE); } - fclose(mPrt->mFilePointer); + fclose(mPrt->mDebugFilePtr); +#endif } else { nsIFrame* rootFrame; poPresShell->GetRootFrame(&rootFrame); @@ -3678,7 +3732,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } #endif - if (printService) { + if (mPrt->mPrintSettings) { if (!skipSetTitle) { PRUnichar * docTitleStr; PRUnichar * docURLStr; @@ -3689,17 +3743,17 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } if (docTitleStr) { - printService->SetTitle(docTitleStr); + mPrt->mPrintSettings->SetTitle(docTitleStr); nsMemory::Free(docTitleStr); } if (docURLStr) { - printService->SetDocURL(docURLStr); + mPrt->mPrintSettings->SetDocURL(docURLStr); nsMemory::Free(docURLStr); } } - if (nsIPrintOptions::kRangeSelection == printRangeType) { + if (nsIPrintSettings::kRangeSelection == printRangeType) { poPresContext->SetIsRenderingOnlySelection(PR_TRUE); // temporarily creating rendering context // which is needed to dinf the selection frames @@ -3724,10 +3778,10 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a &startFrame, startPageNum, startRect, &endFrame, endPageNum, endRect); if (NS_SUCCEEDED(rv)) { - printService->SetStartPageRange(startPageNum); - printService->SetEndPageRange(endPageNum); + mPrt->mPrintSettings->SetStartPageRange(startPageNum); + mPrt->mPrintSettings->SetEndPageRange(endPageNum); nsMargin margin(0,0,0,0); - printService->GetMarginInTwips(margin); + mPrt->mPrintSettings->GetMarginInTwips(margin); if (startPageNum == endPageNum) { nsIFrame * seqFrame; @@ -3773,22 +3827,22 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a rootFrame->SetRect(poPresContext, r); mPageSeqFrame = pageSequence; - mPageSeqFrame->StartPrint(poPresContext, printService); + mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings); if (!aDoSyncPrinting) { // Get the delay time in between the printing of each page // this gives the user more time to press cancel PRInt32 printPageDelay = 500; - printService->GetPrintPageDelay(&printPageDelay); + mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); // Schedule Page to Print PRINT_DEBUG_MSG3("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]); - StartPagePrintTimer(poPresContext, printService, aPO, printPageDelay); + StartPagePrintTimer(poPresContext, mPrt->mPrintSettings, aPO, printPageDelay); } else { DoProgressForAsIsFrames(); // Print the page synchronously PRINT_DEBUG_MSG3("Async Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]); - aDonePrinting = PrintPage(poPresContext, printService, aPO); + aDonePrinting = PrintPage(poPresContext, mPrt->mPrintSettings, aPO); } } } else { @@ -3844,18 +3898,12 @@ DocumentViewerImpl::CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNu void DocumentViewerImpl::DoProgressForAsIsFrames() { - if (mPrt->mPrintListener) { - // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe eDoc - // this is done to make the printing of embedded IFrames easier - // NOTE: we don't want to advance the progress in that case, it is down elsewhere - if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs && mPrt->mPrintObject->mFrameType != eDoc) { - mPrt->mNumDocsPrinted++; - // notify the listener of printed docs - if (mPrt->mNumDocsPrinted == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintableDocs); - } - mPrt->mPrintListener->OnProgressPrinting(mPrt->mNumDocsPrinted, mPrt->mNumPrintableDocs); - } + // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe eDoc + // this is done to make the printing of embedded IFrames easier + // NOTE: we don't want to advance the progress in that case, it is down elsewhere + if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs && mPrt->mPrintObject->mFrameType != eDoc) { + mPrt->mNumDocsPrinted++; + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, mPrt->mNumDocsPrinted, mPrt->mNumPrintableDocs); } } @@ -3863,15 +3911,10 @@ DocumentViewerImpl::DoProgressForAsIsFrames() void DocumentViewerImpl::DoProgressForSeparateFrames() { - if (mPrt->mPrintListener) { - if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) { - mPrt->mNumPagesPrinted++; - // notify the listener of printed docs - if (mPrt->mNumPagesPrinted == 1) { - mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintablePages); - } - mPrt->mPrintListener->OnProgressPrinting(mPrt->mNumPagesPrinted, mPrt->mNumPrintablePages); - } + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + mPrt->mNumPagesPrinted++; + // notify the listener of printed docs + PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, mPrt->mNumPagesPrinted+1, mPrt->mNumPrintablePages); } } @@ -4697,6 +4740,63 @@ DocumentViewerImpl::ReturnToGalleyPresentation() #endif // NS_PRINT_PREVIEW +//----------------------------------------------------------------- +// This method checks to see if there is at least one printer defined +// and if so, it sets the first printer in the list as the default name +// in the PrintSettings which is then used for Printer Preview +nsresult +DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, + PRUint32 aErrorCode, + PRBool aIsPrinting) +{ + NS_ENSURE_ARG_POINTER(aPrintOptions); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + PRUint32 numPrinters = 0; + + nsCOMPtr simpEnum; + aPrintOptions->AvailablePrinters(getter_AddRefs(simpEnum)); + if (simpEnum) { + numPrinters = 0; + do { + PRBool hasMore; + simpEnum->HasMoreElements(&hasMore); + if (!hasMore) break; + + nsCOMPtr supps; + simpEnum->GetNext(getter_AddRefs(supps)); + if (numPrinters == 0) { + nsCOMPtr wStr = do_QueryInterface(supps); + if (wStr) { + PRUnichar* defPrinterName; + wStr->ToString(&defPrinterName); + aPrintSettings->SetPrinterName(defPrinterName); + nsMemory::Free(defPrinterName); + } + } + numPrinters++; + } while (true); + + if (numPrinters == 0) { + // this means there were no printers + ShowPrintErrorDialog(aErrorCode, aIsPrinting); + } else { + rv = NS_OK; + } + } else { + // this means there were no printers + // XXX the ifdefs are temporary until they correctly implement Available Printers +#if defined(XP_MAC) || defined(XP_OS2) + rv = NS_OK; +#else + ShowPrintErrorDialog(aErrorCode, aIsPrinting); +#endif + } + return rv; +} + /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 11/01/01 rods @@ -4705,7 +4805,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() * PrintPreview: See the design spec that is attached to Bug 107562 */ NS_IMETHODIMP -DocumentViewerImpl::PrintPreview() +DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { nsresult rv = NS_OK; @@ -4716,26 +4816,37 @@ DocumentViewerImpl::PrintPreview() // another is still in here (the printing dialog is a good example). // the only time we can print more than one job at a time is the regression tests if (mIsDoingPrintPreview) { -#if 0 - // Let the user know we are not ready to print. - rv = NS_ERROR_NOT_AVAILABLE; - ShowPrintErrorDialog(rv); - return rv; -#else ReturnToGalleyPresentation(); return NS_OK; -#endif } - - // Let's print ... - mIsCreatingPrintPreview = PR_TRUE; - mIsDoingPrintPreview = PR_TRUE; mPrt = new PrintData(); if (mPrt == nsnull) { mIsCreatingPrintPreview = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } + + mPrt->mPrintSettings = aPrintSettings; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + // if they don't pass in a PrintSettings, then make one + if (mPrt->mPrintSettings == nsnull) { + printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings)); + } + NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!"); + + // Get the default printer name and set it into the PrintSettings + if (NS_FAILED(CheckForPrinters(printService, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_PRINTPREVIEW, PR_FALSE))) { + delete mPrt; + mPrt = nsnull; + return NS_ERROR_FAILURE; + } + } + + // Let's print ... + mIsCreatingPrintPreview = PR_TRUE; + mIsDoingPrintPreview = PR_TRUE; + mIsDoingPrintPreview = PR_TRUE; // Very important! Turn Off scripting @@ -4791,28 +4902,26 @@ DocumentViewerImpl::PrintPreview() // Setup print options for UI rv = NS_ERROR_FAILURE; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { + if (mPrt->mPrintSettings != nsnull) { if (mPrt->mIsParentAFrameSet) { if (mPrt->mCurrentFocusWin) { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); } } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); } // Now determine how to set up the Frame print UI - printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); + mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); } #ifdef DEBUG_PRINTING - if (printService) { - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + if (mPrt->mPrintSettings) { + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &val); + mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n"); PRINT_DEBUG_MSG2("IsParentAFrameSet: %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet)); @@ -4835,14 +4944,14 @@ DocumentViewerImpl::PrintPreview() if (factory) { nsIDeviceContextSpec *devspec = nsnull; nsCOMPtr dx; - factory->CreateDeviceContextSpec(mWindow, devspec, doSilent); + factory->CreateDeviceContextSpec(mWindow, aPrintSettings, devspec, doSilent); if (nsnull != devspec) { nsresult rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); if (NS_SUCCEEDED(rv)) { mDeviceContext->SetAltDevice(ppDC); - if (printService) { + if (mPrt->mPrintSettings != nsnull) { double scaling; - printService->GetScaling(&scaling); + mPrt->mPrintSettings->GetScaling(&scaling); if (scaling < 1.0) { mDeviceContext->SetCanonicalPixelScale(float(scaling)); } @@ -4853,13 +4962,11 @@ DocumentViewerImpl::PrintPreview() } } - if (printService && doSilent) { - //printService->SetPrintRange(nsIPrintOptions::kFramesAsIs); - printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs); + if (doSilent) { + mPrt->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); } - mPrt->mPrintDC = mDeviceContext; // XXX why? - mPrt->mFilePointer = nsnull; + mPrt->mPrintDC = mDeviceContext; // XXX why? if (mDeviceContext) { mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_TRUE); @@ -4905,12 +5012,87 @@ DocumentViewerImpl::PrintPreview() return NS_OK; } + +void +DocumentViewerImpl::SetDocAndURLIntoProgress(nsIWebShell* aWebShell, + nsIPrintProgressParams* aParams) +{ + NS_ASSERTION(aWebShell, "Must have vaild nsIWebShell"); + NS_ASSERTION(aParams, "Must have vaild nsIPrintProgressParams"); + if (aWebShell == nsnull || aParams == nsnull) { + return; + } + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + GetWebShellTitleAndURL(aWebShell, &docTitleStr, &docURLStr); + mPrt->mPrintProgressParams->SetDocTitle((const PRUnichar*) docTitleStr); + mPrt->mPrintProgressParams->SetDocURL((const PRUnichar*) docURLStr); + if (docTitleStr != nsnull) nsMemory::Free(docTitleStr); + if (docURLStr != nsnull) nsMemory::Free(docURLStr); +} + +void +DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) +{ + nsPrintProgress* prtProgress = new nsPrintProgress(); + nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrt->mPrintProgress)); + if (NS_FAILED(rv)) return; + + + rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mPrt->mPrintProgressListener)); + if (NS_FAILED(rv)) return; + // add to listener list + mPrt->mPrintProgressListeners.AppendElement((void*)mPrt->mPrintProgressListener); + nsIWebProgressListener* wpl = NS_STATIC_CAST(nsIWebProgressListener*, mPrt->mPrintProgressListener.get()); + NS_ASSERTION(wpl, "nsIWebProgressListener is NULL!"); + NS_ADDREF(wpl); + + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + if (prefs) { + prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog); + if (mPrt->mShowProgressDialog) { + nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams(); + nsCOMPtr params; + rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)getter_AddRefs(mPrt->mPrintProgressParams)); + if (NS_SUCCEEDED(rv) && mPrt->mPrintProgressParams) { + SetDocAndURLIntoProgress(mPrt->mPrintObject->mWebShell, mPrt->mPrintProgressParams); + + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + nsCOMPtr active; + wwatch->GetActiveWindow(getter_AddRefs(active)); + + nsCOMPtr parent(do_QueryInterface(active)); + mPrt->mPrintProgress->OpenProgressDialog(parent, "chrome://global/content/printProgress.xul", mPrt->mPrintProgressParams); + } + } + } + } +} + +#ifdef NS_DEBUG /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 01/24/00 dwc */ NS_IMETHODIMP -DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) +DocumentViewerImpl::Print(PRBool aSilent, + FILE * aDebugFile, + nsIPrintSettings* aPrintSettings) +{ + mDebugFile = aDebugFile; + return Print(aSilent, aPrintSettings, nsnull); +} +#endif + +/** --------------------------------------------------- + * See documentation above in the nsIContentViewerfile class definition + * @update 01/24/00 dwc + */ +NS_IMETHODIMP +DocumentViewerImpl::Print(PRBool aSilent, + nsIPrintSettings* aPrintSettings, + nsIWebProgressListener* aWebProgressListener) { #ifdef DEBUG_PRINTING // need for capturing result on each doc and sub-doc that is printed @@ -4931,19 +5113,39 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi return rv; } - // Let's print ... - mIsDoingPrinting = PR_TRUE; - mPrt = new PrintData(); if (mPrt == nsnull) { - mIsDoingPrinting = PR_FALSE; return NS_ERROR_OUT_OF_MEMORY; } - if (aPrintListener) { - mPrt->mPrintListener = aPrintListener; - } + // if they don't pass in a PrintSettings, then make one + // it will have all the default values + mPrt->mPrintSettings = aPrintSettings; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + // if they don't pass in a PrintSettings, then make one + if (mPrt->mPrintSettings == nsnull) { + printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings)); + } + NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!"); + // Get the default printer name and set it into the PrintSettings + if (NS_FAILED(CheckForPrinters(printService, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE))) { + delete mPrt; + mPrt = nsnull; + return NS_ERROR_FAILURE; + } + } + mPrt->mPrintSettings->SetPrintSilent(aSilent); + + // Let's print ... + mIsDoingPrinting = PR_TRUE; + + if (aWebProgressListener != nsnull) { + mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener); + NS_ADDREF(aWebProgressListener); + } + // Get the currently focused window and cache it // because the Print Dialog will "steal" focus and later when you try // to get the currently focused windows it will be NULL @@ -4957,6 +5159,8 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrt->mPrintDocList = new nsVoidArray(); if (mPrt->mPrintDocList == nsnull) { mIsDoingPrinting = PR_FALSE; + delete mPrt; + mPrt = nsnull; return NS_ERROR_FAILURE; } } else { @@ -4990,30 +5194,26 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi DUMP_DOC_LIST("\nAfter Mapping------------------------------------------"); - // Setup print options for UI rv = NS_ERROR_FAILURE; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - if (mPrt->mIsParentAFrameSet) { - if (mPrt->mCurrentFocusWin) { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll); - } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach); - } + // Setup print options for UI + if (mPrt->mIsParentAFrameSet) { + if (mPrt->mCurrentFocusWin) { + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone); + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); } - // Now determine how to set up the Frame print UI - printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); + } else { + mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); } + // Now determine how to set up the Frame print UI + mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected); #ifdef DEBUG_PRINTING - if (printService) { - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - printService->GetHowToEnableFrameUI(&printHowEnable); + if (mPrt->mPrintSettings) { + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; - printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &val); + mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n"); PRINT_DEBUG_MSG2("IsParentAFrameSet: %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet)); @@ -5038,19 +5238,22 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi nsIDeviceContextSpec *devspec = nsnull; nsCOMPtr dx; mPrt->mPrintDC = nsnull; // XXX why? - mPrt->mFilePointer = aFile; - rv = factory->CreateDeviceContextSpec(mWindow, devspec, aSilent); +#ifdef NS_DEBUG + mPrt->mDebugFilePtr = mDebugFile; +#endif + + PRBool printSilently; + mPrt->mPrintSettings->GetPrintSilent(&printSilently); + rv = factory->CreateDeviceContextSpec(mWindow, mPrt->mPrintSettings, devspec, printSilently); if (NS_SUCCEEDED(rv)) { rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); if (NS_SUCCEEDED(rv)) rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); - if (printService) { - double scaling; - printService->GetScaling(&scaling); - if (scaling < 1.0) { - dx->SetCanonicalPixelScale(float(scaling)); - } + double scaling; + mPrt->mPrintSettings->GetScaling(&scaling); + if (scaling <= 1.0) { + dx->SetCanonicalPixelScale(float(scaling)); } if (NS_SUCCEEDED(rv)) { @@ -5062,9 +5265,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi PRInt32 i1,i2; printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrt->mPrintPS, mPrt->mPrintPC,mPrt->mPrintDC,mPrt->mPrintVM,mPrt->mPrintView); - + // DEVICE CONTEXT INFORMATION from PresContext printf("DeviceContext of Presentation Context(%x)\n",dx); dx->GetDevUnitsToTwips(a1); @@ -5106,13 +5307,74 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi #endif /* DEBUG_dcone */ - // if there is a frameset and we are printing silently then - // the default must be reset kFramesAsIs - if (printService && mPrt->mIsParentAFrameSet && aSilent) { - mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; - printService->SetPrintFrameType(mPrt->mPrintFrameType); + // Always check and set the print settings first and then fall back + // onto the PrintService if there isn't a PrintSettings + // + // Posiible Usage values: + // nsIPrintSettings::kUseInternalDefault + // nsIPrintSettings::kUseSettingWhenPossible + // + // NOTE: The consts are the same for PrintSettings and PrintSettings + PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; + mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); + + // Ok, see if we are going to use our value and override the default + if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { + // Get the Print Options/Settings PrintFrameType to see what is preferred + PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); + + // Don't let anybody do something stupid like try to set it to + // kNoFrames when we are printing a FrameSet + if (printFrameType == nsIPrintSettings::kNoFrames) { + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } else { + // First find out from the PrinService what options are available + // to us for Printing FrameSets + PRInt16 howToEnableFrameUI; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + switch (howToEnableFrameUI) { + case nsIPrintSettings::kFrameEnableAll: + mPrt->mPrintFrameType = printFrameType; + break; + + case nsIPrintSettings::kFrameEnableAsIsAndEach: + if (printFrameType != nsIPrintSettings::kSelectedFrame) { + mPrt->mPrintFrameType = printFrameType; + } else { // revert back to a good value + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + } + break; + } // switch + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } + } } + if (printService) { + // check to see if we are printing to a file + PRBool isPrintToFile = PR_FALSE; + mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); + if (isPrintToFile) { + // On some platforms The BeginDocument needs to know the name of the file + // and it uses the PrintService to get it, so we need to set it into the PrintService here + PRUnichar* fileName; + mPrt->mPrintSettings->GetToFileName(&fileName); + if (fileName != nsnull) { + printService->SetPrintToFile(PR_TRUE); + printService->SetToFileName(fileName); + nsMemory::Free(fileName); + } + } else { + printService->SetPrintToFile(PR_FALSE); + printService->SetToFileName(nsnull); + } + } + + DoPrintProgress(PR_TRUE); + // Print listener setup... if (mPrt != nsnull) { mPrt->OnStartPrinting(); @@ -5123,7 +5385,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi // notified that images must be loaded as a result of the // InitialReflow... // - if(!mIsPrinting || (aFile != 0)){ + if(!mIsPrinting || (mPrt->mDebugFilePtr != nsnull)) { rv = DocumentReadyForPrinting(); #ifdef DEBUG_dcone printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); @@ -5166,7 +5428,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi void -DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) +DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { nsresult rv; @@ -5186,12 +5448,12 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) *title = nsnull; nsAutoString stringName; - switch(printerror) + switch(aPrintError) { #define NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(nserr) case nserr: stringName = NS_LITERAL_STRING(#nserr); break; NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_CMD_FAILURE) - NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE) + NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_ACCESS_DENIED) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE) @@ -5200,6 +5462,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_FILE_IO_ERROR) + NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_GFX_PRINTER_PRINTPREVIEW) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_UNEXPECTED) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_OUT_OF_MEMORY) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_NOT_IMPLEMENTED) @@ -5209,9 +5472,14 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult printerror) NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_FAILURE) #undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG } - + myStringBundle->GetStringFromName(stringName.get(), &msg); - myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), &title); + if (aIsPrinting) { + myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), &title); + } else { + myStringBundle->GetStringFromName(NS_LITERAL_STRING("printpreview_error_dialog_title").get(), &title); + } + if (!msg) return; @@ -6199,7 +6467,7 @@ DocumentViewerImpl::ProcessEvent(nsGUIEvent *aEvent, PRBool aIsInContentArea, ns /*=============== Timer Related Code ======================*/ nsresult DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, - nsIPrintOptions* aPrintOptions, + nsIPrintSettings* aPrintSettings, PrintObject* aPOect, PRUint32 aDelay) { @@ -6214,6 +6482,6 @@ DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, ++mDestroyRefCount; } - return mPagePrintTimer->Start(this, aPresContext, aPrintOptions, aPOect, aDelay); + return mPagePrintTimer->Start(this, aPresContext, aPrintSettings, aPOect, aDelay); } diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index 292fefb5b37..77ec88c82dd 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -554,13 +554,6 @@ public: extern NS_EXPORT nsresult NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// the screen. -extern NS_EXPORT nsresult - NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); - - - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index d9da755b886..07cdbd4d172 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -178,6 +178,7 @@ static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID); static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); +static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); // supporting bugs 31816, 20760, 22963 // define USE_OVERRIDE to put prefs in as an override stylesheet @@ -7003,7 +7004,10 @@ PresShell::VerifyIncrementalReflow() PRBool isPaginated = PR_FALSE; mPresContext->IsPaginated(&isPaginated); if (isPaginated) { - rv = NS_NewPrintPreviewContext(&cx); + nsCOMPtr ppx = do_CreateInstance(kPrintPreviewContextCID, &rv); + if (NS_SUCCEEDED(rv)) { + ppx->QueryInterface(NS_GET_IID(nsIPresContext),(void**)&cx); + } } else { rv = NS_NewGalleyContext(&cx); diff --git a/mozilla/layout/base/public/MANIFEST_IDL b/mozilla/layout/base/public/MANIFEST_IDL index c6add81971c..97a97db226c 100644 --- a/mozilla/layout/base/public/MANIFEST_IDL +++ b/mozilla/layout/base/public/MANIFEST_IDL @@ -3,4 +3,3 @@ # nsIChromeEventHandler.idl -nsIPrintListener.idl diff --git a/mozilla/layout/base/public/Makefile.in b/mozilla/layout/base/public/Makefile.in index 4eb9eb19464..823d5815f91 100644 --- a/mozilla/layout/base/public/Makefile.in +++ b/mozilla/layout/base/public/Makefile.in @@ -78,7 +78,6 @@ endif XPIDLSRCS = \ nsIChromeEventHandler.idl \ - nsIPrintListener.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/layout/base/public/makefile.win b/mozilla/layout/base/public/makefile.win index 9fad95f9c2c..bae73789e72 100644 --- a/mozilla/layout/base/public/makefile.win +++ b/mozilla/layout/base/public/makefile.win @@ -71,7 +71,6 @@ EXPORTS = \ XPIDLSRCS= \ .\nsIChromeEventHandler.idl \ - .\nsIPrintListener.idl \ $(NULL) diff --git a/mozilla/layout/base/public/nsIPageSequenceFrame.h b/mozilla/layout/base/public/nsIPageSequenceFrame.h index cc2ed83db61..6bce36a3ac0 100644 --- a/mozilla/layout/base/public/nsIPageSequenceFrame.h +++ b/mozilla/layout/base/public/nsIPageSequenceFrame.h @@ -41,7 +41,7 @@ #include "nsRect.h" class nsIPresContext; -class nsIPrintOptions; +class nsIPrintSettings; // IID for the nsIPageSequenceFrame interface // a6cf90d2-15b3-11d2-932e-00805f8add32 @@ -130,14 +130,9 @@ public: * NS_ERROR_FAILURE if there is an error * @see nsIPrintStatusCallback#OnProgress() */ - NS_IMETHOD Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback) = 0; - NS_IMETHOD StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) = 0; - NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) = 0; + nsIPrintSettings* aPrintOptions) = 0; + NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext) = 0; NS_IMETHOD GetCurrentPageNum(PRInt32* aPageNum) = 0; NS_IMETHOD GetNumPages(PRInt32* aNumPages) = 0; NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0; diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index 292fefb5b37..77ec88c82dd 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -554,13 +554,6 @@ public: extern NS_EXPORT nsresult NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// the screen. -extern NS_EXPORT nsresult - NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); - - - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/mozilla/layout/base/public/nsIPrintContext.h b/mozilla/layout/base/public/nsIPrintContext.h index f90e4cd9703..570199ef29f 100644 --- a/mozilla/layout/base/public/nsIPrintContext.h +++ b/mozilla/layout/base/public/nsIPrintContext.h @@ -31,6 +31,7 @@ #include "nsISupports.h" #include "nscore.h" +class nsIPrintSettings; #define NS_IPRINTCONTEXT_IID \ { 0xa05e0e40, 0xe1bf, 0x11d4, \ @@ -41,9 +42,11 @@ class nsIPrintContext : public nsISupports { public: -NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTCONTEXT_IID) - + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTCONTEXT_IID) + // Set and Get nsIPrintSettings + NS_IMETHOD SetPrintSettings(nsIPrintSettings* aPS) = 0; + NS_IMETHOD GetPrintSettings(nsIPrintSettings** aPS) = 0; }; diff --git a/mozilla/layout/base/public/nsIPrintListener.idl b/mozilla/layout/base/public/nsIPrintListener.idl deleted file mode 100644 index 5c2c2282a22..00000000000 --- a/mozilla/layout/base/public/nsIPrintListener.idl +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -[scriptable, uuid(DB8D9F25-F183-11d3-8F9F-00A024A7D144)] - -/* Use this for any object that wants to listen to print requests */ - -interface nsIPrintListener : nsISupports -{ - void OnStartPrinting(); - void OnProgressPrinting(in PRUint32 aProgress, in PRUint32 aProgressMax); - void OnEndPrinting(in PRUint32 aStatus); -}; diff --git a/mozilla/layout/base/public/nsIPrintPreviewContext.h b/mozilla/layout/base/public/nsIPrintPreviewContext.h index 4f1d18b8095..1718a0e8e6e 100644 --- a/mozilla/layout/base/public/nsIPrintPreviewContext.h +++ b/mozilla/layout/base/public/nsIPrintPreviewContext.h @@ -27,6 +27,7 @@ #include "nsISupports.h" #include "nscore.h" +class nsIPrintSettings; #define NS_IPRINTPREVIEWCONTEXT_IID \ { 0xdfd92dd, 0x19ff, 0x4e62, \ @@ -37,9 +38,11 @@ class nsIPrintPreviewContext : public nsISupports { public: -NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTPREVIEWCONTEXT_IID) - + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTPREVIEWCONTEXT_IID) + // Set and Get nsIPrintSettings + NS_IMETHOD SetPrintSettings(nsIPrintSettings* aPS) = 0; + NS_IMETHOD GetPrintSettings(nsIPrintSettings** aPS) = 0; }; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index 292fefb5b37..77ec88c82dd 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -554,13 +554,6 @@ public: extern NS_EXPORT nsresult NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// the screen. -extern NS_EXPORT nsresult - NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); - - - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/mozilla/layout/base/src/nsPrintContext.cpp b/mozilla/layout/base/src/nsPrintContext.cpp index 880fb721687..86d74010526 100644 --- a/mozilla/layout/base/src/nsPrintContext.cpp +++ b/mozilla/layout/base/src/nsPrintContext.cpp @@ -42,6 +42,7 @@ #include "nsIWidget.h" #include "nsGfxCIID.h" #include "nsLayoutAtoms.h" +#include "nsIPrintSettings.h" class PrintContext : public nsPresContext , nsIPrintContext{ @@ -64,8 +65,12 @@ public: NS_IMETHOD GetPaginatedScrolling(PRBool* aResult); NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect); NS_IMETHOD SetPageDim(nsRect* aRect); + NS_IMETHOD SetPrintSettings(nsIPrintSettings* aPS); + NS_IMETHOD GetPrintSettings(nsIPrintSettings** aPS); + protected: nsRect mPageDim; + nsCOMPtr mPrintSettings; }; PrintContext::PrintContext() : @@ -151,6 +156,25 @@ PrintContext::SetPageDim(nsRect* aPageDim) return NS_OK; } +NS_IMETHODIMP +PrintContext::SetPrintSettings(nsIPrintSettings * aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + mPrintSettings = aPrintSettings; + return NS_OK; +} + +NS_IMETHODIMP +PrintContext::GetPrintSettings(nsIPrintSettings * *aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + + *aPrintSettings = mPrintSettings; + NS_IF_ADDREF(*aPrintSettings); + + return NS_OK; +} + NS_EXPORT nsresult NS_NewPrintContext(nsIPrintContext** aInstancePtrResult) diff --git a/mozilla/layout/base/src/nsPrintPreviewContext.cpp b/mozilla/layout/base/src/nsPrintPreviewContext.cpp index 1ab88a80d5c..6b319ac865d 100644 --- a/mozilla/layout/base/src/nsPrintPreviewContext.cpp +++ b/mozilla/layout/base/src/nsPrintPreviewContext.cpp @@ -43,14 +43,9 @@ #include "nsGfxCIID.h" #include "nsLayoutAtoms.h" #include "prlog.h" +#include "nsIPrintSettings.h" -// Print Options -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" -#include "nsIServiceManager.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); - -class PrintPreviewContext : public nsPresContext { +class PrintPreviewContext : public nsPresContext, nsIPrintPreviewContext { public: PrintPreviewContext(); ~PrintPreviewContext(); @@ -66,10 +61,13 @@ public: NS_IMETHOD GetPaginatedScrolling(PRBool* aResult); NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect); NS_IMETHOD SetPageDim(nsRect* aRect); + NS_IMETHOD SetPrintSettings(nsIPrintSettings* aPS); + NS_IMETHOD GetPrintSettings(nsIPrintSettings** aPS); protected: nsRect mPageDim; PRBool mCanPaginatedScroll; + nsCOMPtr mPrintSettings; }; PrintPreviewContext::PrintPreviewContext() : @@ -147,8 +145,27 @@ PrintPreviewContext::SetPageDim(nsRect* aPageDim) return NS_OK; } +NS_IMETHODIMP +PrintPreviewContext::SetPrintSettings(nsIPrintSettings * aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + mPrintSettings = aPrintSettings; + return NS_OK; +} + +NS_IMETHODIMP +PrintPreviewContext::GetPrintSettings(nsIPrintSettings * *aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aPrintSettings); + + *aPrintSettings = mPrintSettings; + NS_IF_ADDREF(*aPrintSettings); + + return NS_OK; +} + NS_EXPORT nsresult -NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult) +NS_NewPrintPreviewContext(nsIPrintPreviewContext** aInstancePtrResult) { if (aInstancePtrResult == nsnull) { return NS_ERROR_NULL_POINTER; @@ -160,5 +177,5 @@ NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult) return NS_ERROR_OUT_OF_MEMORY; } - return it->QueryInterface(NS_GET_IID(nsIPresContext), (void **) aInstancePtrResult); + return it->QueryInterface(NS_GET_IID(nsIPrintPreviewContext), (void **) aInstancePtrResult); } diff --git a/mozilla/layout/build/dlldeps.cpp b/mozilla/layout/build/dlldeps.cpp index 7a4ddf3bf32..39637c89b40 100644 --- a/mozilla/layout/build/dlldeps.cpp +++ b/mozilla/layout/build/dlldeps.cpp @@ -42,6 +42,7 @@ #include "nsIPresShell.h" #include "nsIPrintContext.h" #include "nsIPresContext.h" +#include "nsIPrintPreviewContext.h" #include "nsIStyleSet.h" #include "nsIDocument.h" #include "nsHTMLParts.h" @@ -52,9 +53,10 @@ void XXXNeverCalled() nsIPresShell* ps; NS_NewPresShell(&ps); nsIPresContext* cx; - nsIPrintContext *px; NS_NewGalleyContext(&cx); - NS_NewPrintPreviewContext(&cx); + nsIPrintPreviewContext *ppx; + NS_NewPrintPreviewContext(&ppx); + nsIPrintContext *px; NS_NewPrintContext(&px); nsIFrame* f; NS_NewTextFrame(ps, &f); diff --git a/mozilla/layout/build/nsLayoutCID.h b/mozilla/layout/build/nsLayoutCID.h index 7bdbb068747..95e602c2e20 100644 --- a/mozilla/layout/build/nsLayoutCID.h +++ b/mozilla/layout/build/nsLayoutCID.h @@ -126,6 +126,10 @@ #define NS_PRINTCONTEXT_CID \ { 0xa1fde85f, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } } +// {A1FDE85F-E802-11d4-9885-00C04FA0CF4B} +#define NS_PRINTPREVIEWCONTEXT_CID \ +{ 0xdfd92dd, 0x19ff, 0x4e62, { 0x83, 0x16, 0x8e, 0x44, 0x3, 0x1a, 0x19, 0x62 } } + // {95F46161-D177-11d2-BF86-00105A1B0627} #define NS_HTML_CSS_STYLESHEET_CID \ { 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index a3a3f892f34..366e1e8c17b 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -50,6 +50,7 @@ #include "nsIPresShell.h" #include "nsIPresState.h" #include "nsIPrintContext.h" +#include "nsIPrintPreviewContext.h" #include "nsTextTransformer.h" #include "nsXBLAtoms.h" // to addref/release table @@ -209,7 +210,6 @@ MAKE_CTOR(CreateNewFrameUtil, nsIFrameUtil, NS_NewFrameUtil) MAKE_CTOR(CreateNewLayoutDebugger, nsILayoutDebugger, NS_NewLayoutDebugger) #endif -MAKE_CTOR(CreateNewPrintPreviewContext, nsIPresContext, NS_NewPrintPreviewContext) MAKE_CTOR(CreateNewCSSFrameConstructor, nsICSSFrameConstructor, NS_CreateCSSFrameConstructor) MAKE_CTOR(CreateNewFrameTraversal, nsIFrameTraversal, NS_CreateFrameTraversal) MAKE_CTOR(CreateNewLayoutHistoryState, nsILayoutHistoryState, NS_NewLayoutHistoryState) @@ -217,6 +217,7 @@ MAKE_CTOR(CreateNewPresShell, nsIPresShell, NS_NewPresShell) MAKE_CTOR(CreateNewPresState, nsIPresState, NS_NewPresState) MAKE_CTOR(CreateNewGalleyContext, nsIPresContext, NS_NewGalleyContext) MAKE_CTOR(CreateNewPrintContext, nsIPrintContext, NS_NewPrintContext) +MAKE_CTOR(CreateNewPrintPreviewContext, nsIPrintPreviewContext, NS_NewPrintPreviewContext) MAKE_CTOR(CreateNewBoxObject, nsIBoxObject, NS_NewBoxObject) MAKE_CTOR(CreateNewTreeBoxObject, nsIBoxObject, NS_NewTreeBoxObject) MAKE_CTOR(CreateNewMenuBoxObject, nsIBoxObject, NS_NewMenuBoxObject) @@ -282,6 +283,11 @@ static nsModuleComponentInfo gComponents[] = { NS_PRINTCONTEXT_CID, nsnull, CreateNewPrintContext }, + + { "Print Preview context", + NS_PRINTPREVIEWCONTEXT_CID, + nsnull, + CreateNewPrintPreviewContext }, // XXX end ick { "XUL Box Object", diff --git a/mozilla/layout/generic/nsIPageSequenceFrame.h b/mozilla/layout/generic/nsIPageSequenceFrame.h index cc2ed83db61..6bce36a3ac0 100644 --- a/mozilla/layout/generic/nsIPageSequenceFrame.h +++ b/mozilla/layout/generic/nsIPageSequenceFrame.h @@ -41,7 +41,7 @@ #include "nsRect.h" class nsIPresContext; -class nsIPrintOptions; +class nsIPrintSettings; // IID for the nsIPageSequenceFrame interface // a6cf90d2-15b3-11d2-932e-00805f8add32 @@ -130,14 +130,9 @@ public: * NS_ERROR_FAILURE if there is an error * @see nsIPrintStatusCallback#OnProgress() */ - NS_IMETHOD Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback) = 0; - NS_IMETHOD StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) = 0; - NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) = 0; + nsIPrintSettings* aPrintOptions) = 0; + NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext) = 0; NS_IMETHOD GetCurrentPageNum(PRInt32* aPageNum) = 0; NS_IMETHOD GetNumPages(PRInt32* aNumPages) = 0; NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0; diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 75b78221149..02a365afcf8 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -94,11 +94,10 @@ #include "nsIContentViewer.h" #include "nsIDocShell.h" #include "npapi.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsGfxCIID.h" #include "nsHTMLUtils.h" #include "nsUnicharUtils.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // headers for plugin scriptability #include "nsIScriptGlobalObject.h" @@ -1659,9 +1658,9 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, window.type = windowless ? nsPluginWindowType_Drawable : nsPluginWindowType_Window; // get a few things - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - NS_ENSURE_TRUE(printService, NS_ERROR_FAILURE); - printService->GetMarginInTwips(margin); + nsCOMPtr printSettings; + thePrinterContext->GetPrintSettings(getter_AddRefs(printSettings)); + printSettings->GetMarginInTwips(margin); aPresContext->GetTwipsToPixels(&t2p); GetOffsetFromView(aPresContext, origin, &parentWithView); @@ -1700,7 +1699,9 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, #elif defined (XP_UNIX) // UNIX does things completely differently PRUnichar *printfile = nsnull; - printService->GetToFileName(&printfile); + if (printSettings) { + printSettings->GetToFileName(&printfile); + } if (!printfile) return NS_OK; // XXX what to do on UNIX when we don't have a PS file???? diff --git a/mozilla/layout/generic/nsPageFrame.cpp b/mozilla/layout/generic/nsPageFrame.cpp index 000e3391601..fa1c091a15a 100644 --- a/mozilla/layout/generic/nsPageFrame.cpp +++ b/mozilla/layout/generic/nsPageFrame.cpp @@ -48,6 +48,7 @@ #include "nsIDeviceContext.h" #include "nsReadableUtils.h" #include "nsIPrintPreviewContext.h" +#include "nsIPrintContext.h" #include "nsIView.h" // view flags for clipping #include "nsCSSRendering.h" @@ -63,7 +64,7 @@ #include "nsIFontMetrics.h" // Print Options -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); @@ -124,20 +125,23 @@ nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext, // (Also skip it if we are doing PrintPreview) nsCOMPtr ppContext = do_QueryInterface(aPresContext); if (!ppContext) { - nsresult rv; - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - printService->GetPrintRange(&printRangeType); - // make sure we are printing the selection - if (printRangeType == nsIPrintOptions::kRangeSelection) { - nsIView* view; - aChildList->GetView(aPresContext, &view); - if (view == nsnull) { - nsCOMPtr styleContext; - aChildList->GetStyleContext(getter_AddRefs(styleContext)); - nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList, - styleContext, nsnull, PR_TRUE); + nsCOMPtr prtContext = do_QueryInterface(aPresContext); + if (prtContext) { + nsCOMPtr printSettings; + prtContext->GetPrintSettings(getter_AddRefs(printSettings)); + if (printSettings) { + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + printSettings->GetPrintRange(&printRangeType); + // make sure we are printing the selection + if (printRangeType == nsIPrintSettings::kRangeSelection) { + nsIView* view; + aChildList->GetView(aPresContext, &view); + if (view == nsnull) { + nsCOMPtr styleContext; + aChildList->GetStyleContext(getter_AddRefs(styleContext)); + nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList, + styleContext, nsnull, PR_TRUE); + } } } } @@ -375,7 +379,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) if (kTitle != nsnull) { if (aStr.Find(kTitle) > -1) { PRUnichar * uTitle; - mPD->mPrintOptions->GetTitle(&uTitle); // creates memory + mPD->mPrintSettings->GetTitle(&uTitle); // creates memory SubstValueForCode(aNewStr, kTitle, uTitle); nsMemory::Free(uTitle); nsMemory::Free(kTitle); @@ -388,7 +392,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) if (kDocURL != nsnull) { if (aStr.Find(kDocURL) > -1) { PRUnichar * uDocURL; - mPD->mPrintOptions->GetDocURL(&uDocURL); // creates memory + mPD->mPrintSettings->GetDocURL(&uDocURL); // creates memory SubstValueForCode(aNewStr, kDocURL, uDocURL); nsMemory::Free(uDocURL); nsMemory::Free(kDocURL); @@ -410,15 +414,15 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext, nscoord x = aRect.x; switch (aJust) { - case nsIPrintOptions::kJustLeft: + case nsIPrintSettings::kJustLeft: x += mPD->mExtraMargin.left + mPD->mHeadFooterGap; break; - case nsIPrintOptions::kJustCenter: + case nsIPrintSettings::kJustCenter: x += (aRect.width - width) / 2; break; - case nsIPrintOptions::kJustRight: + case nsIPrintSettings::kJustRight: x += aRect.width - width - mPD->mExtraMargin.right - mPD->mHeadFooterGap; break; } // switch @@ -459,13 +463,13 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext, nscoord strSpace = aRect.width / numStrs; if (!aStr1.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustLeft, aStr1, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustLeft, aStr1, aRect, aAscent, aHeight, strSpace); } if (!aStr2.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustCenter, aStr2, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustCenter, aStr2, aRect, aAscent, aHeight, strSpace); } if (!aStr3.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustRight, aStr3, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustRight, aStr3, aRect, aAscent, aHeight, strSpace); } } @@ -536,16 +540,15 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext, aRenderingContext.PopState(clipEmpty); #ifdef DEBUG_PRINTING PRINT_DEBUG_MSG2("Page: %p", this); - char * s = ToNewCString(str); + const char * s = NS_ConvertUCS2toUTF8(str).get(); if (s) { PRINT_DEBUG_MSG2(" [%s]", s); - nsMemory::Free(s); } char justStr[64]; switch (aJust) { - case nsIPrintOptions::kJustLeft:strcpy(justStr, "Left");break; - case nsIPrintOptions::kJustCenter:strcpy(justStr, "Center");break; - case nsIPrintOptions::kJustRight:strcpy(justStr, "Right");break; + case nsIPrintSettings::kJustLeft:strcpy(justStr, "Left");break; + case nsIPrintSettings::kJustCenter:strcpy(justStr, "Center");break; + case nsIPrintSettings::kJustRight:strcpy(justStr, "Right");break; } // switch PRINT_DEBUG_MSG2(" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer"); PRINT_DEBUG_MSG2(" JST: %s ", justStr); @@ -629,8 +632,17 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, #endif if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) { + // For PrintPreview the + if (!mPD->mPrintSettings) { + nsCOMPtr ppContext = do_QueryInterface(aPresContext); + if (ppContext) { + ppContext->GetPrintSettings(getter_AddRefs(mPD->mPrintSettings)); + } + } + NS_ASSERTION(mPD->mPrintSettings, "Must have a good PrintSettings here!"); + // get the current margin - mPD->mPrintOptions->GetMarginInTwips(mMargin); + mPD->mPrintSettings->GetMarginInTwips(mMargin); rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height); @@ -670,20 +682,20 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, // print document headers and footers PRUnichar * headers[3]; - mPD->mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory - mPD->mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory - mPD->mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory - DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustLeft, + mPD->mPrintSettings->GetHeaderStrLeft(&headers[0]); // creates memory + mPD->mPrintSettings->GetHeaderStrCenter(&headers[1]); // creates memory + mPD->mPrintSettings->GetHeaderStrRight(&headers[2]); // creates memory + DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintSettings::kJustLeft, nsAutoString(headers[0]), nsAutoString(headers[1]), nsAutoString(headers[2]), rect, ascent, visibleHeight); PRInt32 i; for (i=0;i<3;i++) nsMemory::Free(headers[i]); PRUnichar * footers[3]; - mPD->mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory - mPD->mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory - mPD->mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory - DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintOptions::kJustRight, + mPD->mPrintSettings->GetFooterStrLeft(&footers[0]); // creates memory + mPD->mPrintSettings->GetFooterStrCenter(&footers[1]); // creates memory + mPD->mPrintSettings->GetFooterStrRight(&footers[2]); // creates memory + DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintSettings::kJustRight, nsAutoString(footers[0]), nsAutoString(footers[1]), nsAutoString(footers[2]), rect, ascent, visibleHeight); for (i=0;i<3;i++) nsMemory::Free(footers[i]); diff --git a/mozilla/layout/generic/nsPageFrame.h b/mozilla/layout/generic/nsPageFrame.h index 2d7d0841ce2..08828a8d7e7 100644 --- a/mozilla/layout/generic/nsPageFrame.h +++ b/mozilla/layout/generic/nsPageFrame.h @@ -38,7 +38,7 @@ #define nsPageFrame_h___ #include "nsContainerFrame.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" class nsSharedPageData; @@ -129,7 +129,7 @@ protected: void ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr); - nsCOMPtr mPrintOptions; + nsCOMPtr mPrintOptions; PRInt32 mPageNum; PRInt32 mTotNumPages; nsMargin mMargin; diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index 9ff6dbc412d..732624a2685 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -47,7 +47,7 @@ #include "nsIPresShell.h" #include "nsIStyleSet.h" #include "nsIFontMetrics.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsPageFrame.h" #include "nsIPrintPreviewContext.h" #include "nsStyleConsts.h" @@ -74,6 +74,7 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID); #define PRINTING_PROPERTIES "chrome://communicator/locale/printing.properties" // Print Options +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" @@ -161,13 +162,8 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() : // XXX this code and the object data member "mIsPrintingSelection" is only needed // for the hack for printing selection where we make the page the max size nsresult rv; - mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); + mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPageData->mPrintOptions) { - PRInt16 printType; - mPageData->mPrintOptions->GetPrintRange(&printType); - mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType; - mPageData->mPrintOptions->GetMarginInTwips(mMargin); - // now get the default font form the print options mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont); } @@ -504,15 +500,6 @@ SendStatusNotification(nsIPrintStatusCallback* aStatusCallback, return ret; } -NS_IMETHODIMP -nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback) -{ - NS_ASSERTION(0, "No longer being used."); - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsSimplePageSequenceFrame::SetOffsets(nscoord aStartOffset, nscoord aEndOffset) { @@ -568,15 +555,12 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char // Doing this here so we only have to go get these formats once nsAutoString pageNumberFormat; // Now go get the Localized Page Formating String - nsAutoString propName; - propName.AssignWithConversion(aPropName); - PRUnichar* uPropName = ToNewUnicode(propName); + const PRUnichar* uPropName = NS_ConvertUTF8toUCS2(aPropName).get(); if (uPropName != nsnull) { nsresult rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, uPropName, pageNumberFormat); if (NS_FAILED(rv)) { // back stop formatting pageNumberFormat.AssignWithConversion(aDefPropVal); } - nsMemory::Free(uPropName); } // Sets the format into a static data memeber which will own the memory and free it PRUnichar* uStr = ToNewUnicode(pageNumberFormat); @@ -602,20 +586,27 @@ static nsIRegion* CreateRegion() NS_IMETHODIMP nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) + nsIPrintSettings* aPrintSettings) { NS_ENSURE_ARG_POINTER(aPresContext); - NS_ENSURE_ARG_POINTER(aPrintOptions); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + if (!mPageData->mPrintSettings) { + mPageData->mPrintSettings = aPrintSettings; + } PRInt16 printType; - aPrintOptions->GetPrintRange(&printType); + aPrintSettings->GetPrintRange(&printType); mPrintRangeType = printType; - aPrintOptions->GetStartPageRange(&mFromPageNum); - aPrintOptions->GetEndPageRange(&mToPageNum); - aPrintOptions->GetMarginInTwips(mMargin); + mIsPrintingSelection = nsIPrintSettings::kRangeSelection == printType; + aPrintSettings->GetMarginInTwips(mMargin); - mDoingPageRange = nsIPrintOptions::kRangeSpecifiedPageRange == mPrintRangeType || - nsIPrintOptions::kRangeSelection == mPrintRangeType; + aPrintSettings->GetStartPageRange(&mFromPageNum); + aPrintSettings->GetEndPageRange(&mToPageNum); + aPrintSettings->GetMarginInTwips(mMargin); + + mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType || + nsIPrintSettings::kRangeSelection == mPrintRangeType; // If printing a range of pages make sure at least the starting page // number is valid @@ -669,11 +660,11 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, pageNum++; } } - //printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType); + //printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintSettings::kRangeSelection == mPrintRangeType); #endif // Determine if we are rendering only the selection - aPresContext->SetIsRenderingOnlySelection(nsIPrintOptions::kRangeSelection == mPrintRangeType); + aPresContext->SetIsRenderingOnlySelection(nsIPrintSettings::kRangeSelection == mPrintRangeType); if (mDoingPageRange) { @@ -723,7 +714,7 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } // adjust total number of pages - if (nsIPrintOptions::kRangeSelection == mPrintRangeType) { + if (nsIPrintSettings::kRangeSelection == mPrintRangeType) { totalPages = mToPageNum - mFromPageNum + 1; } else { totalPages = pageNum - 1; @@ -754,7 +745,7 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, pointSize = 10; } } - aPrintOptions->SetFontNamePointSize(fontName, pointSize); + mPageData->mPrintOptions->SetFontNamePointSize(fontName, pointSize); // Doing this here so we only have to go get these formats once SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE); @@ -769,11 +760,9 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } NS_IMETHODIMP -nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) +nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext) { NS_ENSURE_ARG_POINTER(aPresContext); - NS_ENSURE_ARG_POINTER(aPrintOptions); // Print each specified page // pageNum keeps track of the current page and what pages are printing @@ -791,8 +780,8 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, } PRBool printEvenPages, printOddPages; - aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintEvenPages, &printEvenPages); - aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintOddPages, &printOddPages); + mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintEvenPages, &printEvenPages); + mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages); // Begin printing of the document nsCOMPtr dc; @@ -865,6 +854,7 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, nsIFrame* conFrame; childFrame->FirstChild(aPresContext, nsnull, &conFrame); conFrame->GetView(aPresContext, &containerView); + NS_ASSERTION(containerView != nsnull, "Container view can't be null!"); containerView->GetBounds(containerRect); containerRect.y -= mYSelOffset; containerRect.height = height-mYSelOffset; @@ -934,8 +924,8 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, } if (!mSkipPageEnd) { - if (nsIPrintOptions::kRangeSelection != mPrintRangeType || - (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) { + if (nsIPrintSettings::kRangeSelection != mPrintRangeType || + (nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) { mPrintedPageNum++; } @@ -965,8 +955,8 @@ nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext) } } - if (nsIPrintOptions::kRangeSelection != mPrintRangeType || - (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) { + if (nsIPrintSettings::kRangeSelection != mPrintRangeType || + (nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) { mPrintedPageNum++; } diff --git a/mozilla/layout/generic/nsSimplePageSequence.h b/mozilla/layout/generic/nsSimplePageSequence.h index a927415e086..4a9e2090513 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.h +++ b/mozilla/layout/generic/nsSimplePageSequence.h @@ -39,6 +39,7 @@ #include "nsIPageSequenceFrame.h" #include "nsContainerFrame.h" +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" //----------------------------------------------- @@ -65,6 +66,7 @@ public: nsStyleBackground* mBackground; //weak reference... + nsCOMPtr mPrintSettings; nsCOMPtr mPrintOptions; }; @@ -89,18 +91,14 @@ public: nsFramePaintLayer aWhichLayer); // nsIPageSequenceFrame - NS_IMETHOD Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback); NS_IMETHOD SetOffsets(nscoord aStartOffset, nscoord aEndOffset); NS_IMETHOD SetPageNo(PRInt32 aPageNo) { return NS_OK;} NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; } // Async Printing NS_IMETHOD StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions); - NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions); + nsIPrintSettings* aPrintSettings); + NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext); NS_IMETHOD GetCurrentPageNum(PRInt32* aPageNum); NS_IMETHOD GetNumPages(PRInt32* aNumPages); NS_IMETHOD IsDoingPrintRange(PRBool* aDoing); diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 75b78221149..02a365afcf8 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -94,11 +94,10 @@ #include "nsIContentViewer.h" #include "nsIDocShell.h" #include "npapi.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsGfxCIID.h" #include "nsHTMLUtils.h" #include "nsUnicharUtils.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // headers for plugin scriptability #include "nsIScriptGlobalObject.h" @@ -1659,9 +1658,9 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, window.type = windowless ? nsPluginWindowType_Drawable : nsPluginWindowType_Window; // get a few things - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - NS_ENSURE_TRUE(printService, NS_ERROR_FAILURE); - printService->GetMarginInTwips(margin); + nsCOMPtr printSettings; + thePrinterContext->GetPrintSettings(getter_AddRefs(printSettings)); + printSettings->GetMarginInTwips(margin); aPresContext->GetTwipsToPixels(&t2p); GetOffsetFromView(aPresContext, origin, &parentWithView); @@ -1700,7 +1699,9 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, #elif defined (XP_UNIX) // UNIX does things completely differently PRUnichar *printfile = nsnull; - printService->GetToFileName(&printfile); + if (printSettings) { + printSettings->GetToFileName(&printfile); + } if (!printfile) return NS_OK; // XXX what to do on UNIX when we don't have a PS file???? diff --git a/mozilla/layout/html/base/src/nsPageFrame.cpp b/mozilla/layout/html/base/src/nsPageFrame.cpp index 000e3391601..fa1c091a15a 100644 --- a/mozilla/layout/html/base/src/nsPageFrame.cpp +++ b/mozilla/layout/html/base/src/nsPageFrame.cpp @@ -48,6 +48,7 @@ #include "nsIDeviceContext.h" #include "nsReadableUtils.h" #include "nsIPrintPreviewContext.h" +#include "nsIPrintContext.h" #include "nsIView.h" // view flags for clipping #include "nsCSSRendering.h" @@ -63,7 +64,7 @@ #include "nsIFontMetrics.h" // Print Options -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); @@ -124,20 +125,23 @@ nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext, // (Also skip it if we are doing PrintPreview) nsCOMPtr ppContext = do_QueryInterface(aPresContext); if (!ppContext) { - nsresult rv; - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - printService->GetPrintRange(&printRangeType); - // make sure we are printing the selection - if (printRangeType == nsIPrintOptions::kRangeSelection) { - nsIView* view; - aChildList->GetView(aPresContext, &view); - if (view == nsnull) { - nsCOMPtr styleContext; - aChildList->GetStyleContext(getter_AddRefs(styleContext)); - nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList, - styleContext, nsnull, PR_TRUE); + nsCOMPtr prtContext = do_QueryInterface(aPresContext); + if (prtContext) { + nsCOMPtr printSettings; + prtContext->GetPrintSettings(getter_AddRefs(printSettings)); + if (printSettings) { + PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; + printSettings->GetPrintRange(&printRangeType); + // make sure we are printing the selection + if (printRangeType == nsIPrintSettings::kRangeSelection) { + nsIView* view; + aChildList->GetView(aPresContext, &view); + if (view == nsnull) { + nsCOMPtr styleContext; + aChildList->GetStyleContext(getter_AddRefs(styleContext)); + nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList, + styleContext, nsnull, PR_TRUE); + } } } } @@ -375,7 +379,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) if (kTitle != nsnull) { if (aStr.Find(kTitle) > -1) { PRUnichar * uTitle; - mPD->mPrintOptions->GetTitle(&uTitle); // creates memory + mPD->mPrintSettings->GetTitle(&uTitle); // creates memory SubstValueForCode(aNewStr, kTitle, uTitle); nsMemory::Free(uTitle); nsMemory::Free(kTitle); @@ -388,7 +392,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) if (kDocURL != nsnull) { if (aStr.Find(kDocURL) > -1) { PRUnichar * uDocURL; - mPD->mPrintOptions->GetDocURL(&uDocURL); // creates memory + mPD->mPrintSettings->GetDocURL(&uDocURL); // creates memory SubstValueForCode(aNewStr, kDocURL, uDocURL); nsMemory::Free(uDocURL); nsMemory::Free(kDocURL); @@ -410,15 +414,15 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext, nscoord x = aRect.x; switch (aJust) { - case nsIPrintOptions::kJustLeft: + case nsIPrintSettings::kJustLeft: x += mPD->mExtraMargin.left + mPD->mHeadFooterGap; break; - case nsIPrintOptions::kJustCenter: + case nsIPrintSettings::kJustCenter: x += (aRect.width - width) / 2; break; - case nsIPrintOptions::kJustRight: + case nsIPrintSettings::kJustRight: x += aRect.width - width - mPD->mExtraMargin.right - mPD->mHeadFooterGap; break; } // switch @@ -459,13 +463,13 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext, nscoord strSpace = aRect.width / numStrs; if (!aStr1.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustLeft, aStr1, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustLeft, aStr1, aRect, aAscent, aHeight, strSpace); } if (!aStr2.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustCenter, aStr2, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustCenter, aStr2, aRect, aAscent, aHeight, strSpace); } if (!aStr3.IsEmpty()) { - DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintOptions::kJustRight, aStr3, aRect, aAscent, aHeight, strSpace); + DrawHeaderFooter(aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustRight, aStr3, aRect, aAscent, aHeight, strSpace); } } @@ -536,16 +540,15 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext, aRenderingContext.PopState(clipEmpty); #ifdef DEBUG_PRINTING PRINT_DEBUG_MSG2("Page: %p", this); - char * s = ToNewCString(str); + const char * s = NS_ConvertUCS2toUTF8(str).get(); if (s) { PRINT_DEBUG_MSG2(" [%s]", s); - nsMemory::Free(s); } char justStr[64]; switch (aJust) { - case nsIPrintOptions::kJustLeft:strcpy(justStr, "Left");break; - case nsIPrintOptions::kJustCenter:strcpy(justStr, "Center");break; - case nsIPrintOptions::kJustRight:strcpy(justStr, "Right");break; + case nsIPrintSettings::kJustLeft:strcpy(justStr, "Left");break; + case nsIPrintSettings::kJustCenter:strcpy(justStr, "Center");break; + case nsIPrintSettings::kJustRight:strcpy(justStr, "Right");break; } // switch PRINT_DEBUG_MSG2(" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer"); PRINT_DEBUG_MSG2(" JST: %s ", justStr); @@ -629,8 +632,17 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, #endif if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) { + // For PrintPreview the + if (!mPD->mPrintSettings) { + nsCOMPtr ppContext = do_QueryInterface(aPresContext); + if (ppContext) { + ppContext->GetPrintSettings(getter_AddRefs(mPD->mPrintSettings)); + } + } + NS_ASSERTION(mPD->mPrintSettings, "Must have a good PrintSettings here!"); + // get the current margin - mPD->mPrintOptions->GetMarginInTwips(mMargin); + mPD->mPrintSettings->GetMarginInTwips(mMargin); rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height); @@ -670,20 +682,20 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, // print document headers and footers PRUnichar * headers[3]; - mPD->mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory - mPD->mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory - mPD->mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory - DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustLeft, + mPD->mPrintSettings->GetHeaderStrLeft(&headers[0]); // creates memory + mPD->mPrintSettings->GetHeaderStrCenter(&headers[1]); // creates memory + mPD->mPrintSettings->GetHeaderStrRight(&headers[2]); // creates memory + DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintSettings::kJustLeft, nsAutoString(headers[0]), nsAutoString(headers[1]), nsAutoString(headers[2]), rect, ascent, visibleHeight); PRInt32 i; for (i=0;i<3;i++) nsMemory::Free(headers[i]); PRUnichar * footers[3]; - mPD->mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory - mPD->mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory - mPD->mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory - DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintOptions::kJustRight, + mPD->mPrintSettings->GetFooterStrLeft(&footers[0]); // creates memory + mPD->mPrintSettings->GetFooterStrCenter(&footers[1]); // creates memory + mPD->mPrintSettings->GetFooterStrRight(&footers[2]); // creates memory + DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintSettings::kJustRight, nsAutoString(footers[0]), nsAutoString(footers[1]), nsAutoString(footers[2]), rect, ascent, visibleHeight); for (i=0;i<3;i++) nsMemory::Free(footers[i]); diff --git a/mozilla/layout/html/base/src/nsPageFrame.h b/mozilla/layout/html/base/src/nsPageFrame.h index 2d7d0841ce2..08828a8d7e7 100644 --- a/mozilla/layout/html/base/src/nsPageFrame.h +++ b/mozilla/layout/html/base/src/nsPageFrame.h @@ -38,7 +38,7 @@ #define nsPageFrame_h___ #include "nsContainerFrame.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" class nsSharedPageData; @@ -129,7 +129,7 @@ protected: void ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr); - nsCOMPtr mPrintOptions; + nsCOMPtr mPrintOptions; PRInt32 mPageNum; PRInt32 mTotNumPages; nsMargin mMargin; diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index d9da755b886..07cdbd4d172 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -178,6 +178,7 @@ static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID); static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); +static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); // supporting bugs 31816, 20760, 22963 // define USE_OVERRIDE to put prefs in as an override stylesheet @@ -7003,7 +7004,10 @@ PresShell::VerifyIncrementalReflow() PRBool isPaginated = PR_FALSE; mPresContext->IsPaginated(&isPaginated); if (isPaginated) { - rv = NS_NewPrintPreviewContext(&cx); + nsCOMPtr ppx = do_CreateInstance(kPrintPreviewContextCID, &rv); + if (NS_SUCCEEDED(rv)) { + ppx->QueryInterface(NS_GET_IID(nsIPresContext),(void**)&cx); + } } else { rv = NS_NewGalleyContext(&cx); diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp index 9ff6dbc412d..732624a2685 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -47,7 +47,7 @@ #include "nsIPresShell.h" #include "nsIStyleSet.h" #include "nsIFontMetrics.h" -#include "nsIPrintOptions.h" +#include "nsIPrintSettings.h" #include "nsPageFrame.h" #include "nsIPrintPreviewContext.h" #include "nsStyleConsts.h" @@ -74,6 +74,7 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID); #define PRINTING_PROPERTIES "chrome://communicator/locale/printing.properties" // Print Options +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" #include "nsGfxCIID.h" #include "nsIServiceManager.h" @@ -161,13 +162,8 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() : // XXX this code and the object data member "mIsPrintingSelection" is only needed // for the hack for printing selection where we make the page the max size nsresult rv; - mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); + mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPageData->mPrintOptions) { - PRInt16 printType; - mPageData->mPrintOptions->GetPrintRange(&printType); - mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType; - mPageData->mPrintOptions->GetMarginInTwips(mMargin); - // now get the default font form the print options mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont); } @@ -504,15 +500,6 @@ SendStatusNotification(nsIPrintStatusCallback* aStatusCallback, return ret; } -NS_IMETHODIMP -nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback) -{ - NS_ASSERTION(0, "No longer being used."); - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsSimplePageSequenceFrame::SetOffsets(nscoord aStartOffset, nscoord aEndOffset) { @@ -568,15 +555,12 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char // Doing this here so we only have to go get these formats once nsAutoString pageNumberFormat; // Now go get the Localized Page Formating String - nsAutoString propName; - propName.AssignWithConversion(aPropName); - PRUnichar* uPropName = ToNewUnicode(propName); + const PRUnichar* uPropName = NS_ConvertUTF8toUCS2(aPropName).get(); if (uPropName != nsnull) { nsresult rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, uPropName, pageNumberFormat); if (NS_FAILED(rv)) { // back stop formatting pageNumberFormat.AssignWithConversion(aDefPropVal); } - nsMemory::Free(uPropName); } // Sets the format into a static data memeber which will own the memory and free it PRUnichar* uStr = ToNewUnicode(pageNumberFormat); @@ -602,20 +586,27 @@ static nsIRegion* CreateRegion() NS_IMETHODIMP nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) + nsIPrintSettings* aPrintSettings) { NS_ENSURE_ARG_POINTER(aPresContext); - NS_ENSURE_ARG_POINTER(aPrintOptions); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + if (!mPageData->mPrintSettings) { + mPageData->mPrintSettings = aPrintSettings; + } PRInt16 printType; - aPrintOptions->GetPrintRange(&printType); + aPrintSettings->GetPrintRange(&printType); mPrintRangeType = printType; - aPrintOptions->GetStartPageRange(&mFromPageNum); - aPrintOptions->GetEndPageRange(&mToPageNum); - aPrintOptions->GetMarginInTwips(mMargin); + mIsPrintingSelection = nsIPrintSettings::kRangeSelection == printType; + aPrintSettings->GetMarginInTwips(mMargin); - mDoingPageRange = nsIPrintOptions::kRangeSpecifiedPageRange == mPrintRangeType || - nsIPrintOptions::kRangeSelection == mPrintRangeType; + aPrintSettings->GetStartPageRange(&mFromPageNum); + aPrintSettings->GetEndPageRange(&mToPageNum); + aPrintSettings->GetMarginInTwips(mMargin); + + mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType || + nsIPrintSettings::kRangeSelection == mPrintRangeType; // If printing a range of pages make sure at least the starting page // number is valid @@ -669,11 +660,11 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, pageNum++; } } - //printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType); + //printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintSettings::kRangeSelection == mPrintRangeType); #endif // Determine if we are rendering only the selection - aPresContext->SetIsRenderingOnlySelection(nsIPrintOptions::kRangeSelection == mPrintRangeType); + aPresContext->SetIsRenderingOnlySelection(nsIPrintSettings::kRangeSelection == mPrintRangeType); if (mDoingPageRange) { @@ -723,7 +714,7 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } // adjust total number of pages - if (nsIPrintOptions::kRangeSelection == mPrintRangeType) { + if (nsIPrintSettings::kRangeSelection == mPrintRangeType) { totalPages = mToPageNum - mFromPageNum + 1; } else { totalPages = pageNum - 1; @@ -754,7 +745,7 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, pointSize = 10; } } - aPrintOptions->SetFontNamePointSize(fontName, pointSize); + mPageData->mPrintOptions->SetFontNamePointSize(fontName, pointSize); // Doing this here so we only have to go get these formats once SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE); @@ -769,11 +760,9 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } NS_IMETHODIMP -nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions) +nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext) { NS_ENSURE_ARG_POINTER(aPresContext); - NS_ENSURE_ARG_POINTER(aPrintOptions); // Print each specified page // pageNum keeps track of the current page and what pages are printing @@ -791,8 +780,8 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, } PRBool printEvenPages, printOddPages; - aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintEvenPages, &printEvenPages); - aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintOddPages, &printOddPages); + mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintEvenPages, &printEvenPages); + mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages); // Begin printing of the document nsCOMPtr dc; @@ -865,6 +854,7 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, nsIFrame* conFrame; childFrame->FirstChild(aPresContext, nsnull, &conFrame); conFrame->GetView(aPresContext, &containerView); + NS_ASSERTION(containerView != nsnull, "Container view can't be null!"); containerView->GetBounds(containerRect); containerRect.y -= mYSelOffset; containerRect.height = height-mYSelOffset; @@ -934,8 +924,8 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext, } if (!mSkipPageEnd) { - if (nsIPrintOptions::kRangeSelection != mPrintRangeType || - (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) { + if (nsIPrintSettings::kRangeSelection != mPrintRangeType || + (nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) { mPrintedPageNum++; } @@ -965,8 +955,8 @@ nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext) } } - if (nsIPrintOptions::kRangeSelection != mPrintRangeType || - (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) { + if (nsIPrintSettings::kRangeSelection != mPrintRangeType || + (nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) { mPrintedPageNum++; } diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.h b/mozilla/layout/html/base/src/nsSimplePageSequence.h index a927415e086..4a9e2090513 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.h +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.h @@ -39,6 +39,7 @@ #include "nsIPageSequenceFrame.h" #include "nsContainerFrame.h" +#include "nsIPrintSettings.h" #include "nsIPrintOptions.h" //----------------------------------------------- @@ -65,6 +66,7 @@ public: nsStyleBackground* mBackground; //weak reference... + nsCOMPtr mPrintSettings; nsCOMPtr mPrintOptions; }; @@ -89,18 +91,14 @@ public: nsFramePaintLayer aWhichLayer); // nsIPageSequenceFrame - NS_IMETHOD Print(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions, - nsIPrintStatusCallback* aStatusCallback); NS_IMETHOD SetOffsets(nscoord aStartOffset, nscoord aEndOffset); NS_IMETHOD SetPageNo(PRInt32 aPageNo) { return NS_OK;} NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; } // Async Printing NS_IMETHOD StartPrint(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions); - NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext, - nsIPrintOptions* aPrintOptions); + nsIPrintSettings* aPrintSettings); + NS_IMETHOD PrintNextPage(nsIPresContext* aPresContext); NS_IMETHOD GetCurrentPageNum(PRInt32* aPageNum); NS_IMETHOD GetNumPages(PRInt32* aNumPages); NS_IMETHOD IsDoingPrintRange(PRBool* aDoing); diff --git a/mozilla/layout/html/base/src/printing.properties b/mozilla/layout/html/base/src/printing.properties index 95b158a3707..1b0bb56db5e 100644 --- a/mozilla/layout/html/base/src/printing.properties +++ b/mozilla/layout/html/base/src/printing.properties @@ -43,11 +43,15 @@ fontname=serif # The size of the font to be used to print the headers and footers fontsize=10 +noPrintFilename.title=Filename is missing +noPrintFilename.alert=You have selected "Print To: File", and the filename is empty! + # Print error codes -print_error_dialog_title=Printer error +print_error_dialog_title=Printer Error +printpreview_error_dialog_title=Print Preview Error NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND=There was a problem printing. The printer doesn't support a printing command. NS_ERROR_GFX_PRINTER_CMD_FAILURE=There was a problem printing. An instruction that was sent to the printer failed. -NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE=There was a problem printing. No printer could be found. +NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE=There was a problem printing. No printer could be found. NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND=There was a problem printing. The printer could not be found. NS_ERROR_GFX_PRINTER_ACCESS_DENIED=There was a problem printing. Access to the printer was denied. NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE=There was a problem printing. Tried to set an invalid printer attribute. @@ -56,6 +60,7 @@ NS_ERROR_GFX_PRINTER_OUT_OF_PAPER=There was a problem printing. The printer is o NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR=There was a problem printing. Printer I/O error. NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE=There was a problem printing. The output file could not be opened. NS_ERROR_GFX_PRINTER_FILE_IO_ERROR=There was an error writing the printing output file. +NS_ERROR_GFX_PRINTER_PRINTPREVIEW=There must be at least one printer available to show Print Preview. NS_ERROR_UNEXPECTED=There was an unexpected problem when printing. NS_ERROR_OUT_OF_MEMORY=There was a problem printing. There is not enough free memory to print. NS_ERROR_NOT_IMPLEMENTED=Some printing functionality is not implemented yet. @@ -64,6 +69,6 @@ NS_ERROR_ABORT=The print job was aborted, or canceled. NS_ERROR_FAILURE=Printing failed for some reason. # No printers available -noprinter=(no printers available) +noprinter=No printers available. # EOF. diff --git a/mozilla/layout/macbuild/layoutIDL.xml b/mozilla/layout/macbuild/layoutIDL.xml index eabcaad0509..de1f6b8a8c3 100644 --- a/mozilla/layout/macbuild/layoutIDL.xml +++ b/mozilla/layout/macbuild/layoutIDL.xml @@ -810,13 +810,6 @@ Text - - Name - nsIPrintListener.idl - MacOS - Text - - Name nsIOutlinerBoxObject.idl @@ -911,11 +904,6 @@ nsIScrollBoxObject.idl MacOS - - Name - nsIPrintListener.idl - MacOS - Name nsIOutlinerBoxObject.idl @@ -1705,13 +1693,6 @@ Text - - Name - nsIPrintListener.idl - MacOS - Text - - Name nsIOutlinerBoxObject.idl @@ -1806,11 +1787,6 @@ nsIScrollBoxObject.idl MacOS - - Name - nsIPrintListener.idl - MacOS - Name nsIOutlinerBoxObject.idl @@ -1899,12 +1875,6 @@ nsIMenuBoxObject.idl MacOS - - headers - Name - nsIPrintListener.idl - MacOS - headers Name diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp index 94a03972d95..1df65478bff 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -262,7 +262,7 @@ NS_IMETHODIMP nsAddressBook::PrintCard() { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - rv = viewerFile->Print(PR_FALSE,nsnull); + rv = viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); } } diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp index 06d2b583c32..589f290dc2f 100644 --- a/mozilla/mailnews/base/src/nsMessenger.cpp +++ b/mozilla/mailnews/base/src/nsMessenger.cpp @@ -1438,7 +1438,7 @@ NS_IMETHODIMP nsMessenger::DoPrint() { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - rv = viewerFile->Print(PR_FALSE,nsnull); + rv = viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); } #ifdef DEBUG_MESSENGER else { diff --git a/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp b/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp index 08e52df9900..f8342182574 100644 --- a/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp @@ -42,6 +42,7 @@ #include "nsIMsgMailSession.h" #include "nsMsgPrintEngine.h" #include "nsMsgBaseCID.h" +#include "nsIDocumentLoader.h" // Interfaces Needed #include "nsIBaseWindow.h" @@ -68,11 +69,10 @@ nsMsgPrintEngine::~nsMsgPrintEngine() } // Implement AddRef and Release -NS_IMPL_ISUPPORTS4(nsMsgPrintEngine, +NS_IMPL_ISUPPORTS3(nsMsgPrintEngine, nsIMsgPrintEngine, nsIWebProgressListener, - nsISupportsWeakReference, - nsIPrintListener); + nsISupportsWeakReference); // nsIWebProgressListener implementation NS_IMETHODIMP @@ -93,62 +93,71 @@ nsMsgPrintEngine::OnStateChange(nsIWebProgress* aWebProgress, } if (progressStateFlags & nsIWebProgressListener::STATE_STOP) { - // Now, fire off the print operation! - rv = NS_ERROR_FAILURE; + // if aWebProgress is a documentloader than the notification from + // loading the documents. If it is NULL (or not a DocLoader) then it + // it coming from Printing + nsCOMPtr docLoader(do_QueryInterface(aWebProgress)); + if (docLoader) { + // Now, fire off the print operation! + rv = NS_ERROR_FAILURE; - // Tell the user the message is loaded... - PRUnichar *msg = GetString(NS_LITERAL_STRING("MessageLoaded").get()); - SetStatusMessage( msg ); - if (msg) nsCRT::free(msg); + // Tell the user the message is loaded... + PRUnichar *msg = GetString(NS_LITERAL_STRING("MessageLoaded").get()); + SetStatusMessage( msg ); + if (msg) nsCRT::free(msg); - NS_ASSERTION(mDocShell,"can't print, there is no docshell"); - if ( (!mDocShell) || (!aRequest) ) - { - return StartNextPrintOperation(); - } - nsCOMPtr aChannel = do_QueryInterface(aRequest); - if (!aChannel) return NS_ERROR_FAILURE; - - // Make sure this isn't just "about:blank" finishing.... - nsCOMPtr originalURI = nsnull; - if (NS_SUCCEEDED(aChannel->GetOriginalURI(getter_AddRefs(originalURI))) && originalURI) - { - nsXPIDLCString spec; - - if (NS_SUCCEEDED(originalURI->GetSpec(getter_Copies(spec))) && spec) - { - if (!nsCRT::strcasecmp(spec, "about:blank")) - { - return StartNextPrintOperation(); - } - } - } - - mDocShell->GetContentViewer(getter_AddRefs(mContentViewer)); - if (mContentViewer) - { - mViewerFile = do_QueryInterface(mContentViewer); - if (mViewerFile) + NS_ASSERTION(mDocShell,"can't print, there is no docshell"); + if ( (!mDocShell) || (!aRequest) ) { - if (mCurrentlyPrintingURI == 0) - rv = mViewerFile->Print(PR_FALSE, nsnull, (nsIPrintListener *)this); - else - rv = mViewerFile->Print(PR_TRUE, nsnull, (nsIPrintListener *)this); + return StartNextPrintOperation(); + } + nsCOMPtr aChannel = do_QueryInterface(aRequest); + if (!aChannel) return NS_ERROR_FAILURE; - if (NS_FAILED(rv)) - { - mViewerFile = nsnull; - mContentViewer = nsnull; - OnEndPrinting(rv); - } - else - { - // Tell the user we started printing... - msg = GetString(NS_LITERAL_STRING("PrintingMessage").get()); - SetStatusMessage( msg ); - if (msg) nsCRT::free(msg); + // Make sure this isn't just "about:blank" finishing.... + nsCOMPtr originalURI = nsnull; + if (NS_SUCCEEDED(aChannel->GetOriginalURI(getter_AddRefs(originalURI))) && originalURI) + { + nsXPIDLCString spec; + + if (NS_SUCCEEDED(originalURI->GetSpec(getter_Copies(spec))) && spec) + { + if (!nsCRT::strcasecmp(spec, "about:blank")) + { + return StartNextPrintOperation(); + } } } + + mDocShell->GetContentViewer(getter_AddRefs(mContentViewer)); + if (mContentViewer) + { + mViewerFile = do_QueryInterface(mContentViewer); + if (mViewerFile) + { + if (mCurrentlyPrintingURI == 0) + rv = mViewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener *)this); + else + rv = mViewerFile->Print(PR_TRUE, nsnull, (nsIWebProgressListener *)this); + + if (NS_FAILED(rv)) + { + mViewerFile = nsnull; + mContentViewer = nsnull; + StartNextPrintOperation(); + } + else + { + // Tell the user we started printing... + msg = GetString(NS_LITERAL_STRING("PrintingMessage").get()); + SetStatusMessage( msg ); + if (msg) nsCRT::free(msg); + } + } + } + } else { + StartNextPrintOperation(); + rv = NS_OK; } } } @@ -364,25 +373,6 @@ nsMsgPrintEngine::SetupObserver() } } -NS_IMETHODIMP -nsMsgPrintEngine::OnStartPrinting(void) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsMsgPrintEngine::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsMsgPrintEngine::OnEndPrinting(PRUint32 aStatus) -{ - StartNextPrintOperation(); - return NS_OK; -} - nsresult nsMsgPrintEngine::SetStatusMessage(PRUnichar *aMsgString) { diff --git a/mozilla/mailnews/base/src/nsMsgPrintEngine.h b/mozilla/mailnews/base/src/nsMsgPrintEngine.h index aa17616bab2..7f6afb535be 100644 --- a/mozilla/mailnews/base/src/nsMsgPrintEngine.h +++ b/mozilla/mailnews/base/src/nsMsgPrintEngine.h @@ -32,7 +32,7 @@ #include "nsIMsgPrintEngine.h" #include "nsIScriptGlobalObject.h" #include "nsIStreamListener.h" -#include "nsIPrintListener.h" +#include "nsIWebProgressListener.h" #include "nsIMsgStatusFeedback.h" #include "nsIStringBundle.h" #include "nsIContentViewerFile.h" @@ -41,8 +41,7 @@ class nsMsgPrintEngine : public nsIMsgPrintEngine, public nsIWebProgressListener, - public nsSupportsWeakReference, - public nsIPrintListener { + public nsSupportsWeakReference { public: nsMsgPrintEngine(); @@ -57,9 +56,6 @@ public: // For nsIWebProgressListener NS_DECL_NSIWEBPROGRESSLISTENER - // For nIPrintListener - NS_DECL_NSIPRINTLISTENER - protected: NS_IMETHOD FireThatLoadOperation(nsString *uri); diff --git a/mozilla/modules/libpref/src/init/all.js b/mozilla/modules/libpref/src/init/all.js index 3ad8bbf6f40..d9f4833b4a7 100644 --- a/mozilla/modules/libpref/src/init/all.js +++ b/mozilla/modules/libpref/src/init/all.js @@ -213,6 +213,14 @@ pref("print.print_headerright", "&U"); pref("print.print_footerleft", "&PT"); pref("print.print_footercenter", ""); pref("print.print_footerright", "&D"); +pref("print.show_print_progress", true); + +// When this is set to false it means each window has its PrintSettings +// and a change in one browser window does not efect the others +pref("print.use_global_printsettings", false); + +// This indeicates whether it should use the native dialog or the XP Dialog50 +pref("print.use_native_print_dialog", false); // Default Capability Preferences: Security-Critical! // Editing these may create a security risk - be sure you know what you're doing diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 476375e069b..efbccd8ca7f 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -69,6 +69,8 @@ #include "nsITimer.h" #include "nsITimerCallback.h" +class nsIPrintSettings; + // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); @@ -795,8 +797,20 @@ PluginViewerImpl::GetSaveable(PRBool *aSaveable) return NS_ERROR_NOT_IMPLEMENTED; } +#ifdef NS_DEBUG NS_IMETHODIMP -PluginViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) +PluginViewerImpl::Print(PRBool aSilent, + FILE * aDebugFile, + nsIPrintSettings* aPrintSettings) +{ + return NS_ERROR_FAILURE; +} +#endif + +NS_IMETHODIMP +PluginViewerImpl::Print(PRBool aSilent, + nsIPrintSettings* aPrintSettings, + nsIWebProgressListener* aWebProgressListener) { nsPluginPrint npprint; npprint.mode = nsPluginMode_Full; @@ -814,7 +828,7 @@ PluginViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintList } NS_IMETHODIMP -PluginViewerImpl::PrintPreview() +PluginViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { return NS_OK; // XXX: hey, plug in guys! implement me! } diff --git a/mozilla/webshell/public/nsIContentViewerFile.h b/mozilla/webshell/public/nsIContentViewerFile.h index 2645988fd3f..09068700ea9 100644 --- a/mozilla/webshell/public/nsIContentViewerFile.h +++ b/mozilla/webshell/public/nsIContentViewerFile.h @@ -9,9 +9,10 @@ #include "nsrootidl.h" #include "nsIWebShell.h" #include "nsIDOMWindow.h" -#include "nsIPrintListener.h" class nsIDeviceContext; +class nsIPrintSettings; +class nsIWebProgressListener; /* starting interface: nsIContentViewerFile */ @@ -31,18 +32,35 @@ class nsIContentViewerFile : public nsISupports { /* readonly attribute boolean saveable; */ NS_IMETHOD GetSaveable(PRBool *aSaveable) = 0; - /* void Print (); - - */ /** * Print the current document - * @param aSilent -- if true, the print settings dialog will be suppressed - * @param aFileName -- a file pointer to output regression tests or print to a file + * @param aSilent -- if true, the print settings dialog will be suppressed + * @param aPrintSettings -- PrintSettings used during print + * @param aProgressListener -- Listens to the progress of printing * @return error status */ - NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener = nsnull) = 0; + NS_IMETHOD Print(PRBool aSilent, + nsIPrintSettings* aPrintSettings, + nsIWebProgressListener * aProgressListener) = 0; +#ifdef NS_DEBUG + /** + * Print the current document + * @param aSilent -- if true, the print settings dialog will be suppressed + * @param aDebugFile -- Regression testing debug file + * @param aPrintSettings -- PrintSettings used during print + * @return error status + */ + NS_IMETHOD Print(PRBool aSilent, + FILE * aDebugFile, + nsIPrintSettings* aPrintSettings = nsnull) = 0; +#endif - NS_IMETHOD PrintPreview() = 0; + /** + * PrintPreview the current document + * @param aPrintSettings -- PrintSettings used during print + * @return error status + */ + NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings) = 0; /* [noscript] void PrintContent (in nsIWebShell parent, in nsIDeviceContext DContext, in nsIDOMWindow aDOMWin, PRBool aIsSubDoc); */ NS_IMETHOD PrintContent(nsIWebShell * aParent, @@ -54,23 +72,25 @@ class nsIContentViewerFile : public nsISupports { NS_IMETHOD GetPrintable(PRBool *aPrintable) = 0; }; +#ifdef NS_DEBUG /* Use this macro when declaring classes that implement this interface. */ #define NS_DECL_NSICONTENTVIEWERFILE \ NS_IMETHOD Save(void); \ NS_IMETHOD GetSaveable(PRBool *aSaveable); \ - NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener); \ - NS_IMETHOD PrintPreview(); \ + NS_IMETHOD Print(PRBool aSilent, nsIPrintSettings* aPrintSettings, nsIWebProgressListener * aProgressListener); \ + NS_IMETHOD Print(PRBool aSilent, FILE * aDebugFile, nsIPrintSettings* aPrintSettings); \ + NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings); \ NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext, nsIDOMWindow * aDOMWin, PRBool aIsSubDoc); \ NS_IMETHOD GetPrintable(PRBool *aPrintable); - -/* Use this macro to declare functions that forward the behavior of this interface to another object. */ -#define NS_FORWARD_NSICONTENTVIEWERFILE(_to) \ - NS_IMETHOD Save(void) { return _to ## Save(); } \ - NS_IMETHOD GetSaveable(PRBool *aSaveable) { return _to ## GetSaveable(aSaveable); } \ - NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) { return _to ## Print(); } \ - NS_IMETHOD PrintPreview() { return _to ## Print(); } \ - NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext, nsIDOMWindow * aDOMWin, PRBool aIsSubDoc) { return _to ## PrintContent(parent, DContext, aDOMWin, aIsSubDoc); } \ - NS_IMETHOD GetPrintable(PRBool *aPrintable) { return _to ## GetPrintable(aPrintable); } - +#else +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSICONTENTVIEWERFILE \ + NS_IMETHOD Save(void); \ + NS_IMETHOD GetSaveable(PRBool *aSaveable); \ + NS_IMETHOD Print(PRBool aSilent, nsIPrintSettings* aPrintSettings, nsIWebProgressListener * aProgressListener); \ + NS_IMETHOD PrintPreview(nsIPrintSettings* aPrintSettings); \ + NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext, nsIDOMWindow * aDOMWin, PRBool aIsSubDoc); \ + NS_IMETHOD GetPrintable(PRBool *aPrintable); +#endif #endif /* __gen_nsIContentViewerFile_h__ */ diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index 9e1721a5eef..58e54dfb610 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -898,10 +898,6 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) DoPrint(); break; - case VIEWER_PRINT_SETUP: - DoPrintSetup(); - break; - case VIEWER_TABLE_INSPECTOR: DoTableInspector(); break; @@ -2195,7 +2191,7 @@ nsBrowserWindow::ShowPrintPreview(PRInt32 aID) { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - viewerFile->PrintPreview(); + viewerFile->PrintPreview(nsnull); } } } @@ -2210,67 +2206,11 @@ void nsBrowserWindow::DoPrint(void) { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - viewerFile->Print(PR_FALSE,0); + viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); } } } -//--------------------------------------------------------------- -void nsBrowserWindow::DoPrintSetup() -{ - if (mXPDialog) { - NS_RELEASE(mXPDialog); - //mXPDialog->SetVisible(PR_TRUE); - //return; - } - - nsString printHTML(NS_LITERAL_STRING("resource:/res/samples/printsetup.html")); - nsRect rect(0, 0, 375, 510); - nsString title(NS_LITERAL_STRING("Print Setup")); - - nsXPBaseWindow * dialog = nsnull; - nsresult rv = nsComponentManager::CreateInstance(kXPBaseWindowCID, nsnull, - kIXPBaseWindowIID, - (void**) &dialog); - if (rv == NS_OK) { - dialog->Init(eXPBaseWindowType_dialog, mAppShell, printHTML, - title, rect, PRUint32(~0), PR_FALSE); - dialog->SetVisible(PR_TRUE); - if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**)&mXPDialog)) { - } - } - - mPrintSetupInfo.mPortrait = PR_TRUE; - mPrintSetupInfo.mBevelLines = PR_TRUE; - mPrintSetupInfo.mBlackText = PR_FALSE; - mPrintSetupInfo.mBlackLines = PR_FALSE; - mPrintSetupInfo.mLastPageFirst = PR_FALSE; - mPrintSetupInfo.mPrintBackgrounds = PR_FALSE; - mPrintSetupInfo.mTopMargin = 0.50; - mPrintSetupInfo.mBottomMargin = 0.50; - mPrintSetupInfo.mLeftMargin = 0.50; - mPrintSetupInfo.mRightMargin = 0.50; - - mPrintSetupInfo.mDocTitle = PR_TRUE; - mPrintSetupInfo.mDocLocation = PR_TRUE; - - mPrintSetupInfo.mHeaderText.Assign(NS_LITERAL_STRING("Header Text")); - mPrintSetupInfo.mFooterText.Assign(NS_LITERAL_STRING("Footer Text")); - - mPrintSetupInfo.mPageNum = PR_TRUE; - mPrintSetupInfo.mPageTotal = PR_TRUE; - mPrintSetupInfo.mDatePrinted = PR_TRUE; - - - nsPrintSetupDialog * printSetupDialog = new nsPrintSetupDialog(this); - if (nsnull != printSetupDialog) { - dialog->AddWindowListener(printSetupDialog); - } - printSetupDialog->SetSetupInfo(mPrintSetupInfo); - //NS_IF_RELEASE(dialog); - -} - //--------------------------------------------------------------- nsIDOMDocument* nsBrowserWindow::GetDOMDocument(nsIDocShell *aDocShell) { diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.h b/mozilla/webshell/tests/viewer/nsBrowserWindow.h index 65535f0bc16..7c5b0207ba3 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.h +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.h @@ -173,7 +173,6 @@ public: void ShowPrintPreview(PRInt32 aID); void DoPrint(void); - void DoPrintSetup(void); void DoTableInspector(void); void DoImageInspector(void); diff --git a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp index 1439535b6a7..17758d7986c 100644 --- a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp +++ b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp @@ -245,15 +245,15 @@ nsWebCrawler::DumpRegressionData() switch (mPrinterTestType) { case 1: // dump print data to a file for regression testing - viewerFile->Print(PR_TRUE,fp); + viewerFile->Print(PR_TRUE, fp); break; case 2: // visual printing tests, all go to the printer, no printer dialog - viewerFile->Print(PR_TRUE,0); + viewerFile->Print(PR_TRUE, nsnull); break; case 3: // visual printing tests, all go to the printer, with a printer dialog - viewerFile->Print(PR_FALSE,0); + viewerFile->Print(PR_FALSE, nsnull); break; default: break; diff --git a/mozilla/webshell/tests/viewer/unix/gtk/nsGtkMenu.cpp b/mozilla/webshell/tests/viewer/unix/gtk/nsGtkMenu.cpp index 5ef90a57d0d..51a8261954b 100644 --- a/mozilla/webshell/tests/viewer/unix/gtk/nsGtkMenu.cpp +++ b/mozilla/webshell/tests/viewer/unix/gtk/nsGtkMenu.cpp @@ -87,7 +87,6 @@ GtkItemFactoryEntry menu_items[] = { "/File/sep1", nsnull, nsnull, 0, "" }, { "/File/Print Preview", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_ONE_COLUMN, nsnull }, { "/File/Print", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_PRINT, nsnull }, - { "/File/Print Setup", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_PRINT_SETUP, nsnull }, { "/File/sep2", nsnull, nsnull, 0, "" }, { "/File/_Exit", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_EXIT, nsnull }, diff --git a/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp index 0ae85c44eb4..1448d28cdac 100644 --- a/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp +++ b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp @@ -150,7 +150,6 @@ void CreateViewerMenus(QWidget *aParent, void * data, PRInt32 * aMenuBarHeight) InsertMenuItem(file, nsnull, nsnull, 0); InsertMenuItem(file, "Print Preview", eventHandler, VIEWER_ONE_COLUMN); InsertMenuItem(file, "Print", eventHandler, VIEWER_PRINT); - InsertMenuItem(file, "Print Setup", eventHandler, VIEWER_PRINT_SETUP); InsertMenuItem(file, nsnull, nsnull, 0); InsertMenuItem(file, "&Exit", eventHandler, VIEWER_EXIT); diff --git a/mozilla/webshell/tests/viewer/viewer.rc b/mozilla/webshell/tests/viewer/viewer.rc index 52246d6462b..bed35f0b90d 100644 --- a/mozilla/webshell/tests/viewer/viewer.rc +++ b/mozilla/webshell/tests/viewer/viewer.rc @@ -76,7 +76,6 @@ VIEWER MENU DISCARDABLE MENUITEM SEPARATOR MENUITEM "Print &Preview", VIEWER_ONE_COLUMN MENUITEM "Print", VIEWER_PRINT - MENUITEM "Print Setup", VIEWER_PRINT_SETUP MENUITEM SEPARATOR MENUITEM "&Exit", VIEWER_EXIT } diff --git a/mozilla/webshell/tests/viewer/vieweros2.rc b/mozilla/webshell/tests/viewer/vieweros2.rc index 27e1b05fc44..49446c9eeb2 100644 --- a/mozilla/webshell/tests/viewer/vieweros2.rc +++ b/mozilla/webshell/tests/viewer/vieweros2.rc @@ -76,7 +76,6 @@ MENU IDM_VIEWERBAR MENUITEM SEPARATOR MENUITEM "Print ~Preview", VIEWER_ONE_COLUMN MENUITEM "~Print", VIEWER_PRINT - MENUITEM "Print Setup", VIEWER_PRINT_SETUP MENUITEM SEPARATOR MENUITEM "E~xit", VIEWER_EXIT } diff --git a/mozilla/xpfe/browser/resources/content/browser.js b/mozilla/xpfe/browser/resources/content/browser.js index 32b145ea66e..221ab844638 100644 --- a/mozilla/xpfe/browser/resources/content/browser.js +++ b/mozilla/xpfe/browser/resources/content/browser.js @@ -38,6 +38,8 @@ * ***** END LICENSE BLOCK ***** */ const nsIWebNavigation = Components.interfaces.nsIWebNavigation; +var gPrintSettings = null; +var gUseGlobalPrintSettings = false; function getWebNavigation() { @@ -72,9 +74,15 @@ function BrowserReloadWithFlags(reloadFlags) function BrowserPrintPreview() { - // using _content.print() until printing becomes scriptable on docShell + var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] + .getService(Components.interfaces.nsIPrintOptions); + if (gPrintSettings == null) { + gPrintSettings = printOptionsService.CreatePrintSettings(); + } + // using _content.printPreview() until printing becomes scriptable on docShell try { - _content.printPreview(); + _content.printPreview(gPrintSettings, false); + } catch (e) { // Pressing cancel is expressed as an NS_ERROR_FAILURE return value, // causing an exception to be thrown which we catch here. @@ -83,18 +91,74 @@ function BrowserPrintPreview() } } + function BrowserPrintSetup() { - goPageSetup(); // from utilityOverlay.js + + try { + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + if (pref) { + gUseGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings", false); + } + + var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] + .getService(Components.interfaces.nsIPrintOptions); + + // create our own local copy of the print settings + if (gPrintSettings == null) { + gPrintSettings = printOptionsService.CreatePrintSettings(); + } + + // if we are using the global settings then get them + // before calling page setup + if (gUseGlobalPrintSettings) { + gPrintSettings = printOptionsService.printSettingsValues; + } + + goPageSetup(gPrintSettings); // from utilityOverlay.js + + // now set our setting into the global settings + // after the changes were made + if (gUseGlobalPrintSettings) { + printOptionsService.printSettingsValues = gPrintSettings; + } + } catch (e) { + alert("BrowserPrintSetup "+e); + } } function BrowserPrint() { - // using _content.print() until printing becomes scriptable on docShell try { - _content.print(); + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + if (pref) { + gUseGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings"); + } + var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] + .getService(Components.interfaces.nsIPrintOptions); + if (gPrintSettings == null) { + gPrintSettings = printOptionsService.CreatePrintSettings(); + } + + // if we are using the global settings then get them + // before calling print + if (gUseGlobalPrintSettings) { + gPrintSettings = printOptionsService.printSettingsValues; + } + + // using _content.print() until printing becomes scriptable on docShell + _content.print(gPrintSettings, false); + + // now set our setting into the global settings + // after the changes were made + if (gUseGlobalPrintSettings) { + printOptionsService.printSettingsValues = gPrintSettings; + } + } catch (e) { - // Pressing cancel is expressed as an NS_ERROR_FAILURE return value, + // Pressing cancel is expressed as an NS_ERROR_ABORT return value, // causing an exception to be thrown which we catch here. // Unfortunately this will also consume helpful failures, so add a // dump(e); // if you need to debug diff --git a/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul b/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul index ab52152b73a..df8615ffa1d 100644 --- a/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul +++ b/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul @@ -111,7 +111,7 @@ - + @@ -192,7 +192,7 @@ - + diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index 98463282647..6f333f9cd12 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -128,7 +128,6 @@ // Stuff to implement file download dialog. #include "nsIDocumentObserver.h" #include "nsIContent.h" -#include "nsIContentViewerFile.h" #include "nsINameSpaceManager.h" #include "nsFileStream.h" #include "nsIProxyObjectManager.h" diff --git a/mozilla/xpfe/communicator/jar.mn b/mozilla/xpfe/communicator/jar.mn index cd765d0bd80..ae853e1161b 100644 --- a/mozilla/xpfe/communicator/jar.mn +++ b/mozilla/xpfe/communicator/jar.mn @@ -25,6 +25,8 @@ comm.jar: content/communicator/askViewZoom.xul (resources/content/askViewZoom.xul) content/communicator/askViewZoom.js (resources/content/askViewZoom.js) content/communicator/findUtils.js (resources/content/findUtils.js) + content/communicator/printPageSetup.js (resources/content/printPageSetup.js) + content/communicator/printPageSetup.xul (resources/content/printPageSetup.xul) en-US.jar: locale/en-US/communicator/contents.rdf (resources/locale/en-US/contents.rdf) @@ -40,6 +42,8 @@ en-US.jar: locale/en-US/communicator/askViewZoom.dtd (resources/locale/en-US/askViewZoom.dtd) locale/en-US/communicator/viewZoomOverlay.dtd (resources/locale/en-US/viewZoomOverlay.dtd) locale/en-US/communicator/viewZoomOverlay.properties (resources/locale/en-US/viewZoomOverlay.properties) + locale/en-US/communicator/printPageSetup.dtd (resources/locale/en-US/printPageSetup.dtd) + locale/en-US/communicator/printPageSetup.properties (resources/locale/en-US/printPageSetup.properties) US.jar: locale/US/communicator-region/contents.rdf (resources/locale/en-US/contents-region.rdf) diff --git a/mozilla/xpfe/communicator/resources/content/printPageSetup.js b/mozilla/xpfe/communicator/resources/content/printPageSetup.js index f472fb72e3d..0d4eac237fe 100644 --- a/mozilla/xpfe/communicator/resources/content/printPageSetup.js +++ b/mozilla/xpfe/communicator/resources/content/printPageSetup.js @@ -38,69 +38,58 @@ * * ***** END LICENSE BLOCK ***** */ -var dialog; -var printSettings = null; -var stringBundle = null; -var paperArray; +var gDialog; +var gPrintSettings = null; +var gStringBundle = null; +var gPaperArray; var gPrintSettingsInterface = Components.interfaces.nsIPrintSettings; -var doDebug = false; +var gDoDebug = false; //--------------------------------------------------- function initDialog() { - dialog = new Object; + gDialog = new Object; - dialog.paperList = document.getElementById("paperList"); - dialog.paperGroup = document.getElementById("paperGroup"); + gDialog.paperList = document.getElementById("paperList"); + gDialog.paperGroup = document.getElementById("paperGroup"); - dialog.orientation = document.getElementById("orientation"); - dialog.printBGColors = document.getElementById("printBGColors"); - dialog.printBGImages = document.getElementById("printBGImages"); + gDialog.orientation = document.getElementById("orientation"); + gDialog.printBGColors = document.getElementById("printBGColors"); + gDialog.printBGImages = document.getElementById("printBGImages"); - dialog.topInput = document.getElementById("topInput"); - dialog.bottomInput = document.getElementById("bottomInput"); - dialog.leftInput = document.getElementById("leftInput"); - dialog.rightInput = document.getElementById("rightInput"); + gDialog.topInput = document.getElementById("topInput"); + gDialog.bottomInput = document.getElementById("bottomInput"); + gDialog.leftInput = document.getElementById("leftInput"); + gDialog.rightInput = document.getElementById("rightInput"); - dialog.hLeftInput = document.getElementById("hLeftInput"); - dialog.hCenterInput = document.getElementById("hCenterInput"); - dialog.hRightInput = document.getElementById("hRightInput"); + gDialog.hLeftInput = document.getElementById("hLeftInput"); + gDialog.hCenterInput = document.getElementById("hCenterInput"); + gDialog.hRightInput = document.getElementById("hRightInput"); - dialog.fLeftInput = document.getElementById("fLeftInput"); - dialog.fCenterInput = document.getElementById("fCenterInput"); - dialog.fRightInput = document.getElementById("fRightInput"); + gDialog.fLeftInput = document.getElementById("fLeftInput"); + gDialog.fCenterInput = document.getElementById("fCenterInput"); + gDialog.fRightInput = document.getElementById("fRightInput"); - dialog.scalingInput = document.getElementById("scalingInput"); + gDialog.scalingInput = document.getElementById("scalingInput"); + + gDialog.enabled = false; - dialog.enabled = false; } //--------------------------------------------------- -function checkValid(elementID) +function checkDouble(element) { - var editField = document.getElementById( elementID ); - if ( !editField ) - return; - var stringIn = editField.value; - if (stringIn && stringIn.length > 0) - { - stringIn = stringIn.replace(/[^\.|^0-9]/g,""); - if (!stringIn) stringIn = ""; - editField.value = stringIn; + var value = element.value; + if (value && value.length > 0) { + value = value.replace(/[^\.|^0-9]/g,""); + if (!value) value = ""; + element.value = value; } } //--------------------------------------------------- -function stripTrailingWhitespace(element) -{ - var stringIn = element.value; - stringIn = stringIn.replace(/\s+$/,""); - element.value = stringIn; -} - -//--------------------------------------------------- -function getDoubleStr( val, dec ) +function getDoubleStr(val, dec) { var str = val.toString(); var inx = str.indexOf("."); @@ -108,7 +97,7 @@ function getDoubleStr( val, dec ) } //--------------------------------------------------- -function listElement( aListElement ) +function listElement(aListElement) { this.listElement = aListElement; } @@ -119,24 +108,24 @@ listElement.prototype = function () { // remove the menupopup node child of the menulist. - this.listElement.removeChild( this.listElement.firstChild ); + this.listElement.removeChild(this.listElement.firstChild); }, appendPaperNames: - function ( aDataObject ) + function (aDataObject) { - var popupNode = document.createElement( "menupopup" ); + var popupNode = document.createElement("menupopup"); for (var i=0;i -1) { selectElement.listElement.selectedIndex = selectedInx; } - //dialog.paperList = selectElement; + //gDialog.paperList = selectElement; } //--------------------------------------------------- @@ -191,20 +183,20 @@ function loadDialog() var print_margin_bottom = 0.5; var print_margin_right = 0.5; - if (printSettings) { - print_paper_type = printSettings.paperSizeType; - print_paper_unit = printSettings.paperSizeUnit; - print_paper_width = printSettings.paperWidth; - print_paper_height = printSettings.paperHeight; - print_orientation = printSettings.orientation; + if (gPrintSettings) { + print_paper_type = gPrintSettings.paperSizeType; + print_paper_unit = gPrintSettings.paperSizeUnit; + print_paper_width = gPrintSettings.paperWidth; + print_paper_height = gPrintSettings.paperHeight; + print_orientation = gPrintSettings.orientation; - print_margin_top = printSettings.marginTop; - print_margin_left = printSettings.marginLeft; - print_margin_right = printSettings.marginRight; - print_margin_bottom = printSettings.marginBottom; + print_margin_top = gPrintSettings.marginTop; + print_margin_left = gPrintSettings.marginLeft; + print_margin_right = gPrintSettings.marginRight; + print_margin_bottom = gPrintSettings.marginBottom; } - if (doDebug) { + if (gDoDebug) { dump("paperSizeType "+print_paper_unit+"\n"); dump("paperWidth "+print_paper_width+"\n"); dump("paperHeight "+print_paper_height+"\n"); @@ -219,39 +211,39 @@ function loadDialog() createPaperArray(); var selectedInx = 0; - for (var i=0;i 100.0) { scaling = 100.0; } scaling /= 100.0; - printSettings.scaling = scaling; + gPrintSettings.scaling = scaling; - if (doDebug) { + if (gDoDebug) { dump("******* Page Setup Accepting ******\n"); + dump("paperSize "+gPrintSettings.paperSize+" (deprecated)\n"); dump("paperSizeType "+print_paper_type+" (should be 1)\n"); dump("paperSizeUnit "+print_paper_unit+"\n"); dump("paperWidth "+print_paper_width+"\n"); dump("paperHeight "+print_paper_height+"\n"); - dump("print_margin_top "+dialog.topInput.value+"\n"); - dump("print_margin_left "+dialog.leftInput.value+"\n"); - dump("print_margin_right "+dialog.bottomInput.value+"\n"); - dump("print_margin_bottom "+dialog.rightInput.value+"\n"); + dump("print_margin_top "+gDialog.topInput.value+"\n"); + dump("print_margin_left "+gDialog.leftInput.value+"\n"); + dump("print_margin_right "+gDialog.bottomInput.value+"\n"); + dump("print_margin_bottom "+gDialog.rightInput.value+"\n"); } - - } else { - dump("************ printSettings: "+printSettings+"\n"); } return true; } -//--------------------------------------------------- -function onCancel() -{ - return true; -} - diff --git a/mozilla/xpfe/communicator/resources/content/printPageSetup.xul b/mozilla/xpfe/communicator/resources/content/printPageSetup.xul index 75cdc6b9408..7a172ffbdc8 100644 --- a/mozilla/xpfe/communicator/resources/content/printPageSetup.xul +++ b/mozilla/xpfe/communicator/resources/content/printPageSetup.xul @@ -24,6 +24,7 @@ Contributor(s): Dan Rosen Roland Mainz Asko Tontti + Rod Spears --> @@ -48,21 +49,25 @@ Contributor(s): - + + + + + + + + + + + + + + @@ -84,19 +89,19 @@ Contributor(s): @@ -121,16 +126,22 @@ Contributor(s): - - - @@ -154,16 +165,22 @@ Contributor(s): - - - @@ -185,9 +202,13 @@ Contributor(s): - diff --git a/mozilla/xpfe/communicator/resources/content/utilityOverlay.js b/mozilla/xpfe/communicator/resources/content/utilityOverlay.js index 6ab59dc3908..58c4bf7f802 100644 --- a/mozilla/xpfe/communicator/resources/content/utilityOverlay.js +++ b/mozilla/xpfe/communicator/resources/content/utilityOverlay.js @@ -119,15 +119,14 @@ function getBrowserURL() { return "chrome://navigator/content/navigator.xul"; } -function goPageSetup() +function goPageSetup(printSettings) { + if (printSettings == null) { + alert("PrintSettings arg is null!"); + } // This code brings up the native page setup dialog (for platforms that // implement nsIPrintOptions.ShowNativeDialog()). - var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] - .getService(Components.interfaces.nsIPrintOptions); - printOptionsService.ReadPrefs(); - printOptionsService.ShowNativeDialog(); - printOptionsService.WritePrefs(); + window.openDialog("chrome://communicator/content/printPageSetup.xul","PageSetup", "chrome,modal,centerscreen", printSettings); } function goPreferences(containerID, paneURL, itemID) diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-debug.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-debug.xul index fcc7f23cb79..e1dae461133 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-debug.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-debug.xul @@ -30,7 +30,7 @@