Turn on pluggable dialogs (second part of checkin, first part Bug 135441)

Bug 115136 r=dcone sr=attinasi


git-svn-id: svn://10.0.0.236/trunk@189178 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com 2006-02-07 01:13:53 +00:00
parent 1d8fd16487
commit 2a2cd19bb5
12 changed files with 475 additions and 1629 deletions

View File

@ -64,24 +64,17 @@ public:
* means getting information about a printer. A previously
* returned device context spec can be passed in and used as
* a starting point for getting a new spec (or simply returning
* the old spec again). Additionally, if it is desirable to
* get the device context spec without user intervention, any
* dialog boxes can be supressed by passing in PR_TRUE for the
* aQuiet parameter.
* the old spec again).
* @param aWidget.. this is a widget a dialog can be hosted in
* @param aNewSpec out parameter for device context spec returned. the
* aOldSpec may be returned if the object is recyclable.
* @param aQuiet if PR_TRUE, prevent the need for user intervention
* in obtaining device context spec. if nsnull is passed in for
* the aOldSpec, this will typically result in getting a device
* context spec for the default output device (i.e. default
* printer).
* @param aIsPrintPreview if PR_TRUE, creating Spec for PrintPreview
* @return error status
*/
NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet) = 0;
PRBool aIsPrintPreview) = 0;
};
#endif

View File

@ -107,15 +107,6 @@ interface nsIPrintOptions : nsISupports
*/
void displayJobProperties (in wstring aPrinter, in nsIPrintSettings aPrintSettings, out boolean aDisplayed);
// Attributes
attribute boolean isCancelled;
attribute wstring title;
attribute wstring docURL;
attribute boolean printToFile;
attribute wstring toFileName;
// no script methods
[noscript] void SetFontNamePointSize(in nsNativeStringRef aName, in PRInt32 aPointSize);

View File

@ -77,14 +77,14 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: Init(void)
NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
PRBool aIsPrintPreview)
{
nsresult rv;
static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
nsCOMPtr<nsIDeviceContextSpec> devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = ((nsDeviceContextSpecGTK *)devSpec.get())->Init(aPrintSettings, aQuiet);
rv = ((nsDeviceContextSpecGTK *)devSpec.get())->Init(aPrintSettings);
if (NS_SUCCEEDED(rv))
{
aNewSpec = devSpec;

View File

@ -53,7 +53,7 @@ public:
NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet);
PRBool aIsPrintPreview);
protected:
virtual ~nsDeviceContextSpecFactoryGTK();

View File

@ -51,16 +51,9 @@
#include "nsIPref.h"
#include "prenv.h" /* for PR_GetEnv */
#include "nsIDOMWindowInternal.h"
#include "nsIServiceManager.h"
#include "nsIDialogParamBlock.h"
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsReadableUtils.h"
#include "nsISupportsArray.h"
#include "nsPrintfCString.h"
#include "nsReadableUtils.h"
#include "nsIServiceManager.h"
#ifdef USE_XPRINT
#include "xprintutil.h"
@ -254,66 +247,6 @@ NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
#error "This should not happen"
#endif
/** -------------------------------------------------------
*/
static nsresult DisplayXPDialog(nsIPrintSettings* aPS,
const char* aChromeURL,
PRBool& aClickedOK)
{
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::DisplayXPDialog()\n"));
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<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array) return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintSettings> ps = aPS;
nsCOMPtr<nsISupports> psSupports(do_QueryInterface(ps));
NS_ASSERTION(psSupports, "PrintSettings must be a supports");
array->AppendElement(psSupports);
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
if (ioParamBlock) {
ioParamBlock->SetInt(0, 0);
nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(ioParamBlock));
NS_ASSERTION(blkSupps, "IOBlk must be a supports");
array->AppendElement(blkSupps);
nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
NS_ASSERTION(array, "array must be a supports");
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> 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
* @update dc 2/15/98
@ -323,115 +256,94 @@ static nsresult DisplayXPDialog(nsIPrintSettings* aPS,
* toolkits including:
* - GTK+-toolkit:
* file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init()
* - GTK-toolkit:
* file: mozilla/gfx/src/xlib/nsDeviceContextSpecGTK.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init()
* - Qt-toolkit:
* file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
* function: NS_IMETHODIMP nsDeviceContextSpecQT::Init()
*
* ** Please update the other toolkits when changing this function.
*/
NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS, PRBool aQuiet)
NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS)
{
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p. qQuiet=%d)\n", aPS, (int)aQuiet));
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p)\n", aPS));
nsresult rv = NS_ERROR_FAILURE;
mPrintSettings = aPS;
// if there is a current selection then enable the "Selection" radio button
if (mPrintSettings) {
PRBool isOn;
mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
}
}
PRBool canPrint = PR_FALSE;
rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
if (NS_FAILED(rv)) {
return rv;
}
if (!aQuiet) {
rv = DisplayXPDialog(mPrintSettings,
"chrome://global/content/printdialog.xul", canPrint);
} else {
rv = NS_OK;
canPrint = PR_TRUE;
}
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
if (NS_SUCCEEDED(rv) && canPrint) {
if (aPS) {
PRBool reversed = PR_FALSE;
PRBool color = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintSettings::kRangeAllPages;
PRInt32 orientation = NS_PORTRAIT;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRInt32 copies = 1;
PRUnichar *printer = nsnull;
PRUnichar *papername = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
if (aPS) {
PRBool reversed = PR_FALSE;
PRBool color = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintSettings::kRangeAllPages;
PRInt32 orientation = NS_PORTRAIT;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRInt32 copies = 1;
PRUnichar *printer = nsnull;
PRUnichar *papername = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
aPS->GetPrinterName(&printer);
aPS->GetPrintReversed(&reversed);
aPS->GetPrintInColor(&color);
aPS->GetPaperName(&papername);
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);
aPS->GetPrinterName(&printer);
aPS->GetPrintReversed(&reversed);
aPS->GetPrintInColor(&color);
aPS->GetPaperName(&papername);
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 (printfile)
strcpy(mPath, NS_ConvertUCS2toUTF8(printfile).get());
if (command)
strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get());
if (printer)
strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get());
if (papername)
strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get());
if (printfile)
strcpy(mPath, NS_ConvertUCS2toUTF8(printfile).get());
if (command)
strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get());
if (printer)
strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get());
if (papername)
strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get());
DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
DO_PR_DEBUG_LOG(("printRange %d\n", printRange));
DO_PR_DEBUG_LOG(("fromPage %d\n", fromPage));
DO_PR_DEBUG_LOG(("toPage %d\n", toPage));
DO_PR_DEBUG_LOG(("tofile %d\n", tofile));
DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>"));
DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>"));
DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>"));
DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"<NULL>"));
DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
DO_PR_DEBUG_LOG(("printRange %d\n", printRange));
DO_PR_DEBUG_LOG(("fromPage %d\n", fromPage));
DO_PR_DEBUG_LOG(("toPage %d\n", toPage));
DO_PR_DEBUG_LOG(("tofile %d\n", tofile));
DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>"));
DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>"));
DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>"));
DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"<NULL>"));
mTop = dtop;
mBottom = dbottom;
mLeft = dleft;
mRight = dright;
mFpf = !reversed;
mGrayscale = !color;
mOrientation = orientation;
mToPrinter = !tofile;
mCopies = copies;
}
mTop = dtop;
mBottom = dbottom;
mLeft = dleft;
mRight = dright;
mFpf = !reversed;
mGrayscale = !color;
mOrientation = orientation;
mToPrinter = !tofile;
mCopies = copies;
}
return rv;
@ -993,19 +905,7 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
{
/* 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
* the "default set" here.
* However, this requires changes on all platforms and is another big chunk
* of patches ... ;-(
*/
PRBool pressedOK;
return DisplayXPDialog(aPrintSettings,
"chrome://global/content/printjoboptions.xul",
pressedOK);
return NS_OK;
}
//----------------------------------------------------------------------

View File

@ -74,7 +74,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIPrintSettings* aPS, PRBool aQuiet);
NS_IMETHOD Init(nsIPrintSettings* aPS);
NS_IMETHOD ClosePrintManager();
NS_IMETHOD GetToPrinter(PRBool &aToPrinter);

View File

@ -66,7 +66,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: Init(void)
NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
PRBool aIsPrintPreview)
{
NS_ENSURE_ARG_POINTER(aWidget);
@ -77,7 +77,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget
if (nsnull != devspec){
nsDeviceContextSpecWin* specWin = NS_STATIC_CAST(nsDeviceContextSpecWin*, devspec);
rv = specWin->Init(aWidget, aPrintSettings, aQuiet);
rv = specWin->Init(aWidget, aPrintSettings, aIsPrintPreview);
if (NS_SUCCEEDED(rv)) {
aNewSpec = devspec;
} else {

View File

@ -55,7 +55,7 @@ public:
NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet);
PRBool aIsPrintPreview);
protected:
~nsDeviceContextSpecFactoryWin();

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, PRBool aQuiet);
NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, PRBool aIsPrintPreview);
void GetDriverName(char *&aDriverName) const { aDriverName = mDriverName; }
void GetDeviceName(char *&aDeviceName) const { aDeviceName = mDeviceName; }
@ -70,12 +70,6 @@ public:
LPDEVMODE aDevMode);
protected:
nsresult ShowXPPrintDialog(PRBool aQuiet);
nsresult ShowNativePrintDialog(nsIWidget* aWidget, PRBool aQuiet);
#ifdef MOZ_REQUIRE_CURRENT_SDK
nsresult ShowNativePrintDialogEx(nsIWidget* aWidget, PRBool aQuiet);
#endif
void SetDeviceName(char* aDeviceName);
void SetDriverName(char* aDriverName);
@ -93,9 +87,6 @@ protected:
PRBool mIsDEVMODEGlobalHandle;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
// For PrintDlgEx
FARPROC mUseExtendedPrintDlg;
};

View File

@ -112,9 +112,7 @@ nsFont* nsPrintOptions::sDefaultFont = nsnull;
* See documentation in nsPrintOptionsImpl.h
* @update 6/21/00 dwc
*/
nsPrintOptions::nsPrintOptions() :
mIsCancelled(PR_FALSE),
mPrintToFile(PR_FALSE)
nsPrintOptions::nsPrintOptions()
{
NS_INIT_ISUPPORTS();
@ -354,8 +352,11 @@ static void GetAdjustedPrinterName(nsIPrintSettings* aPS, PRBool aUsePNP, nsStri
if (prtName) {
aPrinterName = prtName;
PRUnichar uc = '_';
PRUnichar space = ' ';
aPrinterName.ReplaceChar(space, uc);
const char* replaceStr = " \n\r";
for (PRInt32 i=0;i<(PRInt32)strlen(replaceStr);i++) {
PRUnichar uChar = replaceStr[i];
aPrinterName.ReplaceChar(uChar, uc);
}
}
}
@ -899,79 +900,6 @@ NS_IMETHODIMP nsPrintOptions::DisplayJobProperties( const PRUnichar *aPrinter, n
return NS_OK;
}
/* attribute long isCancelled; */
NS_IMETHODIMP nsPrintOptions::GetIsCancelled(PRBool *aIsCancelled)
{
NS_ENSURE_ARG_POINTER(aIsCancelled);
*aIsCancelled = mIsCancelled;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetIsCancelled(PRBool aIsCancelled)
{
mIsCancelled = aIsCancelled;
return NS_OK;
}
/* attribute boolean printToFile; */
NS_IMETHODIMP nsPrintOptions::GetPrintToFile(PRBool *aPrintToFile)
{
//NS_ENSURE_ARG_POINTER(aPrintToFile);
*aPrintToFile = mPrintToFile;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintToFile(PRBool aPrintToFile)
{
mPrintToFile = aPrintToFile;
return NS_OK;
}
/* attribute wstring toFileName; */
NS_IMETHODIMP nsPrintOptions::GetToFileName(PRUnichar * *aToFileName)
{
//NS_ENSURE_ARG_POINTER(aToFileName);
*aToFileName = ToNewUnicode(mToFileName);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetToFileName(const PRUnichar * aToFileName)
{
mToFileName = aToFileName;
return NS_OK;
}
/* attribute wstring docTitle; */
NS_IMETHODIMP nsPrintOptions::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = ToNewUnicode(mTitle);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetTitle(const PRUnichar * aTitle)
{
if (aTitle) {
mTitle = aTitle;
} else {
mTitle.SetLength(0);
}
return NS_OK;
}
/* attribute wstring docURL; */
NS_IMETHODIMP nsPrintOptions::GetDocURL(PRUnichar * *aDocURL)
{
NS_ENSURE_ARG_POINTER(aDocURL);
*aDocURL = ToNewUnicode(mURL);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetDocURL(const PRUnichar * aDocURL)
{
if (aDocURL) {
mURL = aDocURL;
} else {
mURL.SetLength(0);
}
return NS_OK;
}
/* [noscript] voidPtr GetNativeData (in short aDataType); */
NS_IMETHODIMP nsPrintOptions::GetNativeData(PRInt16 aDataType, void * *_retval)
{

View File

@ -54,18 +54,12 @@ protected:
nsresult ReadPrefDouble(nsIPref * aPref, const char * aPrefId, double& aVal);
nsresult WritePrefDouble(nsIPref * aPref, const char * aPrefId, double aVal);
nsresult ReadPrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
nsresult WritePrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
virtual nsresult ReadPrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
virtual nsresult WritePrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
const char* GetPrefName(const char * aPrefName,
const nsString& aPrinterName);
// Members
PRBool mIsCancelled;
nsString mTitle;
nsString mURL;
PRBool mPrintToFile;
nsString mToFileName;
nsCOMPtr<nsIPrintSettings> mGlobalPrintSettings;
nsCString mPrefName;