From 37b493159f34dc4ec8d2d531d42d64bd4cb9f1ef Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Thu, 16 Feb 2006 21:31:56 +0000 Subject: [PATCH] Switch public interfaces from nsIPrintOptions to nsIPrintSettings Enabling XP Print Dialog for Windows Enabling XP Print Progress Dialog Enabling XP Page Setup Dialog Fixing nsPrintPreviewContext to use nsIPrintPreviewContext Bug 113917 r=dcone sr=attinasi --- .../src/os2/nsDeviceContextSpecFactoryO.cpp | 3 +- widget/src/os2/nsDeviceContextSpecFactoryO.h | 1 + widget/src/os2/nsDeviceContextSpecOS2.cpp | 94 +++++++++++-------- widget/src/os2/nsDeviceContextSpecOS2.h | 19 ++-- 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/widget/src/os2/nsDeviceContextSpecFactoryO.cpp b/widget/src/os2/nsDeviceContextSpecFactoryO.cpp index f0688492c35..db814f455c3 100644 --- a/widget/src/os2/nsDeviceContextSpecFactoryO.cpp +++ b/widget/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/widget/src/os2/nsDeviceContextSpecFactoryO.h b/widget/src/os2/nsDeviceContextSpecFactoryO.h index 151bd6c95b0..6362f83d3d4 100644 --- a/widget/src/os2/nsDeviceContextSpecFactoryO.h +++ b/widget/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/widget/src/os2/nsDeviceContextSpecOS2.cpp b/widget/src/os2/nsDeviceContextSpecOS2.cpp index 2dfd778e0b9..495d39610fb 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.cpp +++ b/widget/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/widget/src/os2/nsDeviceContextSpecOS2.h b/widget/src/os2/nsDeviceContextSpecOS2.h index f71f2fd430d..64358d6dd7b 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.h +++ b/widget/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; }; //-------------------------------------------------------------------------