This patch does the following:

1) Introduces a new public interface nsIPrintSettingService which emables consumers to create PS objects whithout a nsIWebBrowserPrint interface
2) The implementation is nsPrintOptionsImpl which now impls the private interface nsIPrintOptions and the public iface nsIPrintSettingsService
3) Several methods/attrs have been moved from nsIWebBrowserPrint iface to nsIPrintSettingsService
4) The CIDs for nsIPrintOptions and nsIPrinSettingsService are now the same.
5) There is no longer a CID "@mozilla.org/gfx/printoptions;1"
6) nsIWebBrowserPrint still has the "globalPrintSettings" attr so if you already have an nsIWebBrowserPrint you don't have to create the PS Service to get it.
7) A bug has been filed to rename the imlp of nsPrintOptionsImpl to nsPrintSettingsService.
Bug 144128 r=dcone sr=attinasi
This commit is contained in:
rods%netscape.com 2002-05-14 12:05:00 +00:00
Родитель 0abdd7c9ad
Коммит 0c5c90b638
39 изменённых файлов: 443 добавлений и 479 удалений

Просмотреть файл

@ -123,15 +123,19 @@
// Print Options
#include "nsIPrintSettings.h"
#include "nsIPrintSettingsService.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
#include "nsISimpleEnumerator.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
// PrintOptions is now implemented by PrintSettingsService
const char* kPrintSettingsServiceCID = "@mozilla.org/gfx/printsettings-service;1";
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
// Printing Events
#include "nsIEventQueue.h"
#include "nsIEventQueueService.h"
@ -6427,21 +6431,24 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
// to if we have a PrintOptions first, because we can't do anything
// below without it then inside we check to se if the printSettings
// is null to know if we need to create on.
// if they don't pass in a PrintSettings, then get the Global PS
mPrt->mPrintSettings = aPrintSettings;
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) {
// if they don't pass in a PrintSettings, then make one
if (mPrt->mPrintSettings == nsnull) {
mPrt->mPrintOptions->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!");
if (!mPrt->mPrintSettings) {
GetGlobalPrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions && mPrt->mPrintSettings) {
// Get the default printer name and set it into the PrintSettings
if (NS_FAILED(CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_PRINTPREVIEW, PR_FALSE))) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
rv = CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE);
} else {
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
// Let's print ...
@ -6541,7 +6548,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
if (factory) {
nsCOMPtr<nsIDeviceContextSpec> devspec;
nsCOMPtr<nsIDeviceContext> dx;
nsresult rv = factory->CreateDeviceContextSpec(mWindow, aPrintSettings, *getter_AddRefs(devspec), PR_TRUE);
nsresult rv = factory->CreateDeviceContextSpec(mWindow, mPrt->mPrintSettings, *getter_AddRefs(devspec), PR_TRUE);
if (NS_SUCCEEDED(rv)) {
rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC));
if (NS_SUCCEEDED(rv)) {
@ -6818,23 +6825,24 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
return NS_ERROR_OUT_OF_MEMORY;
}
// if they don't pass in a PrintSettings, then make one
// it will have all the default values
// if they don't pass in a PrintSettings, then get the Global PS
mPrt->mPrintSettings = aPrintSettings;
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) {
// if they don't pass in a PrintSettings, then make one
if (mPrt->mPrintSettings == nsnull) {
mPrt->mPrintOptions->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!");
if (!mPrt->mPrintSettings) {
GetGlobalPrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions && mPrt->mPrintSettings) {
// Get the default printer name and set it into the PrintSettings
if (NS_FAILED(CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE))) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
rv = CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE);
} else {
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
mPrt->mPrintSettings->SetIsCancelled(PR_FALSE);
mPrt->mPrintSettings->GetShrinkToFit(&mPrt->mShrinkToFit);
@ -6972,7 +6980,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
// NS_ERROR_NOT_IMPLEMENTED indicates they want default behavior
// Any other error code means we must bail out
//
rv = printPromptService->ShowPrintDialog(domWin, this, aPrintSettings);
rv = printPromptService->ShowPrintDialog(domWin, this, mPrt->mPrintSettings);
if (rv == NS_ERROR_NOT_IMPLEMENTED) {
// This means the Dialog service was there,
// but they choose not to implement this dialog and
@ -8221,57 +8229,6 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount,
}
/* readonly attribute nsIPrintSettings newPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings)
{
NS_ENSURE_ARG_POINTER(aNewPrintSettings);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = printService->CreatePrintSettings(aNewPrintSettings);
InitPrintSettingsFromPrinter(nsnull, *aNewPrintSettings);
}
return rv;
}
/* readonly attribute wstring defaultPrinterName; */
NS_IMETHODIMP
DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->GetDefaultPrinterName(aDefaultPrinterName);
}
return rv;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP
DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
NS_ENSURE_ARG_POINTER(aPrintSettings);
PRUnichar* printerName = nsnull;
if (!aPrinterName) {
GetDefaultPrinterName(&printerName);
if (!printerName || !*printerName) return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->InitPrintSettingsFromPrinter(aPrinterName?aPrinterName:printerName, aPrintSettings);
}
if (printerName) {
nsMemory::Free(printerName);
}
return NS_OK;
}
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
@ -8279,9 +8236,10 @@ DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSetti
NS_ENSURE_ARG_POINTER(aGlobalPrintSettings);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
//nsCOMPtr<nsIPrintOptions> printSettingsService = do_GetService(kPrintOptionsCID, &rv);
nsCOMPtr<nsIPrintSettingsService> printSettingsService = do_GetService(kPrintSettingsServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = printService->GetGlobalPrintSettings(aGlobalPrintSettings);
rv = printSettingsService->GetGlobalPrintSettings(aGlobalPrintSettings);
}
return rv;
}
@ -8377,30 +8335,6 @@ DocumentViewerImpl::Cancel()
return NS_ERROR_FAILURE;
}
/* void initPrintSettingsFromPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && printService) {
return printService->InitPrintSettingsFromPrefs(aPrintSettings, aUsePrinterNamePrefix, aFlags);
}
return NS_OK;
}
/* void savePrintSettingsToPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && printService) {
return printService->SavePrintSettingsToPrefs(aPrintSettings, aUsePrinterNamePrefix, aFlags);
}
return NS_OK;
}
/** ---------------------------------------------------
* Get the Focused Frame for a documentviewer
*

Просмотреть файл

@ -66,7 +66,6 @@
// for profiles
#include <nsMPFileLocProvider.h>
#include "nsIWebBrowserPrint.h"
#include "nsIPrintOptions.h"
// all of our local includes
#include "EmbedPrivate.h"
@ -81,7 +80,6 @@
#include "PtMozilla.h"
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static const char sWatcherContractID[] = "@mozilla.org/embedcomp/window-watcher;1";

Просмотреть файл

@ -36,7 +36,6 @@
#include "nsIHistoryEntry.h"
#include "nsIWebBrowserPrint.h"
#include "nsIPrintOptions.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"

Просмотреть файл

@ -44,21 +44,6 @@ interface nsIWebBrowserPrint : nsISupports
const short PRINTPREVIEW_HOME = 3;
const short PRINTPREVIEW_END = 4;
/**
* Returns a new, unique PrintSettings object each time.
*
* For example, if each browser was to have its own unique
* PrintSettings, then each browser window would call this to
* create its own unique PrintSettings object.
*
* If each browse window was to use the same PrintSettings object
* then it should use "globalPrintSettings"
*
* Initializes the newPrintSettings from the default printer
*
*/
readonly attribute nsIPrintSettings newPrintSettings;
/**
* Returns a "global" PrintSettings object
* Creates a new the first time, if one doesn't exist.
@ -88,62 +73,6 @@ interface nsIWebBrowserPrint : nsISupports
*/
readonly attribute boolean doingPrintPreview;
/**
* The name of the default printer
*/
readonly attribute wstring defaultPrinterName;
/**
* Initializes certain settings from the native printer into the PrintSettings
* if aPrinterName is null then it uses the default printer name if it can
* These settings include, but are not limited to:
* Page Orientation
* Page Size
* Number of Copies
*/
void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
/**
* Reads PrintSettings values from Prefs,
* the values to be read are indicated by the "flags" arg.
*
* First it reads in the "generic" set of PrintSetings not associated with any printer
* then it uses the PrinterName in the PrinterSettings to read any settings that were saved
* just for that printer.
*
* aPS - PrintSettings to have its settings read
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
* aFlags - indicates which prefs to read, see nsIPrintSettings.idl for the const values.
*
* Items not read:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
* printFrameType, printSilent, shrinkToFit, numCopies
*
*/
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* Writes PrintSettings values to Prefs,
* the values to be written are indicated by the "flags" arg.
*
* If there is no PrinterName in the PrinterSettings
* the values are saved as the "generic" values not associated with any printer.
* If a PrinterName is there, then it saves the items qualified for that Printer
*
* aPS - PrintSettings to have its settings saved
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
* aFlags - indicates which prefs to save, see nsIPrintSettings.idl for the const values.
*
* Items not written:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
* printFrameType, printSilent, shrinkToFit, numCopies
*
*/
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* This returns whether the current document is a frameset document
*/
@ -172,7 +101,8 @@ interface nsIWebBrowserPrint : nsISupports
/**
* Print the specified DOM window
*
* aThePrintOptions - Printer Settings for the print job
* aThePrintOptions - Printer Settings for the print job, if aThePrintSettings is null
* then the global PS will be used.
* nsIWebProgressListener - is updated during the print
* @return void
*/
@ -182,7 +112,8 @@ interface nsIWebBrowserPrint : nsISupports
/**
* Print Preview the specified DOM window
*
* aThePrintOptions - Printer Settings for the print preview
* aThePrintOptions - Printer Settings for the print preview, if aThePrintSettings is null
* then the global PS will be used.
* nsIWebProgressListener - is updated during the printpreview
* @return void
*/

Просмотреть файл

@ -66,7 +66,6 @@
// PSM2 includes
#include "nsISecureBrowserUI.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_CID(kChildCID, NS_CHILD_CID);
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);

Просмотреть файл

@ -170,7 +170,6 @@ Handle itemH;
if (((TPPrDlg)aDialog)->fDone)
{
//nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");
// cleanup and set the print options to what we want
if (gPrintSettings)
{

Просмотреть файл

@ -55,7 +55,7 @@
#include "nsIPrintOptions.h"
#include "nsIServiceManager.h"
#include "nsGfxCIID.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";

Просмотреть файл

@ -76,7 +76,6 @@ WIN_LIBS= \
#include "nsUnitConversion.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
#include "nsRect.h"

Просмотреть файл

@ -104,7 +104,6 @@
#include "nsIServiceManager.h"
// Printer Includes
#include "nsIPrintOptions.h"
#include "nsIWebBrowserPrint.h"
// qa additions

Просмотреть файл

@ -4,6 +4,7 @@
#include "stdafx.h"
#include "mfcembed.h"
#include "PrintSetupDialog.h"
#include "nsIPrintSettings.h"
#ifdef _DEBUG
#define new DEBUG_NEW

Просмотреть файл

@ -127,7 +127,6 @@
#include "nsIWebBrowserFocus.h"
// Printer Includes
#include "nsIPrintOptions.h"
#include "nsIWebBrowserPrint.h"
#include "nsIDOMWindow.h"

Просмотреть файл

@ -9,3 +9,4 @@ nsIScreen.idl
nsIScreenManager.idl
nsIPrintOptions.idl
nsIPrintSettings.idl
nsIPrintSettingsService.idl

Просмотреть файл

@ -38,6 +38,7 @@ XPIDLSRCS = \
nsIScreenManager.idl \
nsIPrintOptions.idl \
nsIPrintSettings.idl \
nsIPrintSettingsService.idl \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_GFX_TOOLKIT)))

Просмотреть файл

@ -33,6 +33,7 @@ XPIDLSRCS = \
.\nsIScreenManager.idl \
.\nsIPrintOptions.idl \
.\nsIPrintSettings.idl \
.\nsIPrintSettingsService.idl \
.\nsIPrintSettingsWin.idl \
$(NULL)

Просмотреть файл

@ -73,30 +73,6 @@ interface nsIPrintOptions : nsISupports
*/
nsIPrintSettings CreatePrintSettings();
/**
* Creates a new PrintSettnigs Object if it doesn't exist
* otherwise it always hand back the same one.
* This is THE global PrintSettings
*/
readonly attribute nsIPrintSettings globalPrintSettings;
/**
* Initialize the values in the PrintSettings from Prefs
* aPS - PrintSettings to have its settings read
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
*/
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* Save all the PrintSettings to Prefs.
* This is on a printer by printer basis
* Or saved generically if the printer name is null or empty
*
* aPS - PrintSettings to have its settings saved
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
*/
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* available Printers
*/

Просмотреть файл

@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 2; 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) 2001
* 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 ***** */
/* Interface to the Service for gwetting the Global PrintSettings object
or a unique PrintSettings object
*/
#include "nsISupports.idl"
interface nsIPrintSettings;
[scriptable, uuid(841387C8-72E6-484b-9296-BF6EEA80D58A)]
interface nsIPrintSettingsService : nsISupports
{
/**
* Returns a "global" PrintSettings object
* Creates a new the first time, if one doesn't exist.
*
* Then returns the same object each time after that.
*
* Initializes the globalPrintSettings from the default printer
*/
readonly attribute nsIPrintSettings globalPrintSettings;
/**
* Returns a new, unique PrintSettings object each time.
*
* For example, if each browser was to have its own unique
* PrintSettings, then each browser window would call this to
* create its own unique PrintSettings object.
*
* If each browse window was to use the same PrintSettings object
* then it should use "globalPrintSettings"
*
* Initializes the newPrintSettings from the default printer
*
*/
readonly attribute nsIPrintSettings newPrintSettings;
/**
* The name of the default printer
*/
readonly attribute wstring defaultPrinterName;
/**
* Initializes certain settings from the native printer into the PrintSettings
* if aPrinterName is null then it uses the default printer name if it can
* These settings include, but are not limited to:
* Page Orientation
* Page Size
* Number of Copies
*/
void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
/**
* Reads PrintSettings values from Prefs,
* the values to be read are indicated by the "flags" arg.
*
* First it reads in the "generic" set of PrintSetings not associated with any printer
* then it uses the PrinterName in the PrinterSettings to read any settings that were saved
* just for that printer.
*
* aPS - PrintSettings to have its settings read
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
* aFlags - indicates which prefs to read, see nsIPrintSettings.idl for the const values.
*
* Items not read:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
* printFrameType, printSilent, shrinkToFit, numCopies
*
*/
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* Writes PrintSettings values to Prefs,
* the values to be written are indicated by the "flags" arg.
*
* If there is no PrinterName in the PrinterSettings
* the values are saved as the "generic" values not associated with any printer.
* If a PrinterName is there, then it saves the items qualified for that Printer
*
* aPS - PrintSettings to have its settings saved
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
* aFlags - indicates which prefs to save, see nsIPrintSettings.idl for the const values.
*
* Items not written:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
* printFrameType, printSilent, shrinkToFit, numCopies
*
*/
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
};
%{C++
// {841387C8-72E6-484b-9296-BF6EEA80D58A}
#define NS_PRINTSETTINGSSERVICE_IID \
{0x841387c8, 0x72e6, 0x484b, { 0x92, 0x96, 0xbf, 0x6e, 0xea, 0x80, 0xd5, 0x8a}}
%}

Просмотреть файл

@ -762,6 +762,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIPrintSettingsService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIFontList.idl</PATH>
@ -822,6 +829,11 @@
<PATH>nsIPrintOptions.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIPrintSettingsService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIFontList.idl</PATH>
@ -1553,6 +1565,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIPrintSettingsService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIFontList.idl</PATH>
@ -1613,6 +1632,11 @@
<PATH>nsIPrintOptions.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIPrintSettingsService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIFontList.idl</PATH>
@ -1667,6 +1691,12 @@
<PATH>nsIPrintOptions.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIPrintSettingsService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

Просмотреть файл

@ -95,9 +95,13 @@
{ 0xc401eb80, 0xf9ea, 0x11d3, \
{ 0xbb, 0x6f, 0xe7, 0x32, 0xb7, 0x3e, 0xbe, 0x7c } }
#define NS_PRINTOPTIONS_CID \
{ 0x30a3b080, 0x4867, 0x11d4, \
{ 0xa8, 0x56, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } }
#define NS_PRINTSETTINGSSERVICE_CID \
{ 0x841387c8, 0x72e6, 0x484b, \
{ 0x92, 0x96, 0xbf, 0x6e, 0xea, 0x80, 0xd5, 0x8a } }
// NOTE: This now has the same CID as NS_PRINTSETTINGSSERVICE_CID
// will go away when Bug 144114 is fixed
#define NS_PRINTOPTIONS_CID NS_PRINTSETTINGSSERVICE_CID
#define NS_PRINTER_ENUMERATOR_CID \
{ 0xa6cf9129, 0x15b3, 0x11d2, \

Просмотреть файл

@ -180,9 +180,9 @@ static const nsModuleComponentInfo components[] =
// "@mozilla.org/gfx/printer_enumerator/beos;1",
"@mozilla.org/gfx/printerenumerator;1",
nsPrinterEnumeratorBeOSConstructor },
{ "BeOS Printer Options",
NS_PRINTOPTIONS_CID,
"@mozilla.org/gfx/printoptions;1",
{ "BeOS PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsBeOSConstructor }
};

Просмотреть файл

@ -171,10 +171,10 @@ static const nsModuleComponentInfo components[] =
// "@mozilla.org/gfx/device_context_spec_factory/gtk;1",
"@mozilla.org/gfx/devicecontextspecfactory;1",
nsDeviceContextSpecFactoryGTKConstructor },
{ "Print Options",
NS_PRINTOPTIONS_CID,
// "@mozilla.org/gfx/printoptions;1",
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
// "@mozilla.org/gfx/printsettings-service;1",
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsGTKConstructor },
{ "GTK Font Enumerator",
NS_FONT_ENUMERATOR_CID,

Просмотреть файл

@ -149,14 +149,14 @@ static const nsModuleComponentInfo components[] =
"@mozilla.org/gfx/devicecontextspecfactory;1",
nsDeviceContextSpecFactoryMacConstructor },
#if TARGET_CARBON
{ "nsPrintOptions",
NS_PRINTOPTIONS_CID,
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsXConstructor },
#else
{ "Print Options",
NS_PRINTOPTIONS_CID,
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsMacConstructor },
#endif
{ "nsFontEnumerator",

Просмотреть файл

@ -62,7 +62,7 @@
static NS_DEFINE_IID(kCPrinterEnumerator, NS_PRINTER_ENUMERATOR_CID);
NS_IMPL_ISUPPORTS1(nsPrintOptions, nsIPrintOptions)
NS_IMPL_ISUPPORTS2(nsPrintOptions, nsIPrintOptions, nsIPrintSettingsService)
// Pref Constants
const char kMarginTop[] = "print_margin_top";
@ -332,57 +332,6 @@ const char* nsPrintOptions::GetPrefName(const char * aPrefName,
}
/** ---------------------------------------------------
* Helper function - Returns either the name or sets the length to zero
*/
static void GetAdjustedPrinterName(nsIPrintSettings* aPS, PRBool aUsePNP, nsString& aPrinterName)
{
aPrinterName.SetLength(0);
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
PRUnichar* prtName = nsnull;
if (aUsePNP && NS_SUCCEEDED(aPS->GetPrinterName(&prtName))) {
if (prtName && !*prtName) {
nsMemory::Free(prtName);
prtName = nsnull;
}
}
if (prtName) {
aPrinterName = prtName;
PRUnichar uc = '_';
const char* replaceStr = " \n\r";
for (PRInt32 i=0;i<(PRInt32)strlen(replaceStr);i++) {
PRUnichar uChar = replaceStr[i];
aPrinterName.ReplaceChar(uChar, uc);
}
}
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS, PRBool aUsePNP, PRUint32 aFlags)
{
nsString prtName;
// read any non printer specific prefs
// with empty printer name
nsresult rv = ReadPrefs(aPS, prtName, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
GetAdjustedPrinterName(aPS, aUsePNP, prtName);
if (prtName.Length()) {
// Now read any printer specific prefs
return ReadPrefs(aPS, prtName, aFlags);
}
return NS_OK;
}
//----------------------------------------------------------------------
// Testing of read/write prefs
// This define controls debug output
@ -627,24 +576,6 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUi
return NS_ERROR_FAILURE;
}
/* void SavePrintSettingsToPrefs (in nsIPrintSettings aPS); */
/** ---------------------------------------------------
* This will asve into prefs most all the PrintSettings either generically (not specified printer)
* or to a specific printer.
*/
nsresult
nsPrintOptions::SavePrintSettingsToPrefs(nsIPrintSettings *aPS, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsString prtName;
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
GetAdjustedPrinterName(aPS, aUsePrinterNamePrefix, prtName);
// Now write any printer specific prefs
return WritePrefs(aPS, prtName, aFlags);
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
@ -924,6 +855,11 @@ NS_IMETHODIMP nsPrintOptions::CreatePrintSettings(nsIPrintSettings **_retval)
return rv;
}
//-----------------------------------------------------
//-----------------------------------------------------
//-- nsIPrintSettingsService
//-----------------------------------------------------
//-----------------------------------------------------
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP nsPrintOptions::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
{
@ -957,6 +893,121 @@ NS_IMETHODIMP nsPrintOptions::GetGlobalPrintSettings(nsIPrintSettings * *aGlobal
return NS_OK;
}
/* readonly attribute nsIPrintSettings newPrintSettings; */
NS_IMETHODIMP
nsPrintOptions::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings)
{
NS_ENSURE_ARG_POINTER(aNewPrintSettings);
nsresult rv = CreatePrintSettings(aNewPrintSettings);
NS_ENSURE_SUCCESS(rv, rv);
rv = InitPrintSettingsFromPrinter(nsnull, *aNewPrintSettings);
return rv;
}
//-----------------------------------------------------------------------
NS_IMETHODIMP
nsPrintOptions::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
rv = prtEnum->GetDefaultPrinterName(aDefaultPrinterName);
}
return rv;
}
//-----------------------------------------------------------------------
NS_IMETHODIMP
nsPrintOptions::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
NS_ENSURE_ARG_POINTER(aPrintSettings);
PRUnichar* printerName = nsnull;
if (!aPrinterName) {
GetDefaultPrinterName(&printerName);
if (!printerName || !*printerName) return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
rv = prtEnum->InitPrintSettingsFromPrinter(aPrinterName?aPrinterName:printerName, aPrintSettings);
}
if (printerName) {
nsMemory::Free(printerName);
}
return rv;
}
/** ---------------------------------------------------
* Helper function - Returns either the name or sets the length to zero
*/
static void GetAdjustedPrinterName(nsIPrintSettings* aPS, PRBool aUsePNP, nsString& aPrinterName)
{
aPrinterName.SetLength(0);
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
PRUnichar* prtName = nsnull;
if (aUsePNP && NS_SUCCEEDED(aPS->GetPrinterName(&prtName))) {
if (prtName && !*prtName) {
nsMemory::Free(prtName);
prtName = nsnull;
}
}
if (prtName) {
aPrinterName = prtName;
PRUnichar uc = '_';
const char* replaceStr = " \n\r";
for (PRInt32 i=0;i<(PRInt32)strlen(replaceStr);i++) {
PRUnichar uChar = replaceStr[i];
aPrinterName.ReplaceChar(uChar, uc);
}
}
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS, PRBool aUsePNP, PRUint32 aFlags)
{
nsString prtName;
// read any non printer specific prefs
// with empty printer name
nsresult rv = ReadPrefs(aPS, prtName, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
GetAdjustedPrinterName(aPS, aUsePNP, prtName);
if (prtName.Length()) {
// Now read any printer specific prefs
return ReadPrefs(aPS, prtName, aFlags);
}
return NS_OK;
}
/** ---------------------------------------------------
* This will asve into prefs most all the PrintSettings either generically (not specified printer)
* or to a specific printer.
*/
nsresult
nsPrintOptions::SavePrintSettingsToPrefs(nsIPrintSettings *aPS, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsString prtName;
// Get the Printer Name from the PtinerSettings
// to use as a prefix for Pref Names
GetAdjustedPrinterName(aPS, aUsePrinterNamePrefix, prtName);
// Now write any printer specific prefs
return WritePrefs(aPS, prtName, aFlags);
}
//-----------------------------------------------------
//-- Protected Methods
@ -1121,7 +1172,7 @@ public:
};
Tester::Tester()
{
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
nsCOMPtr<nsIPrintSettings> ps;
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);

Просмотреть файл

@ -25,17 +25,19 @@
#define nsPrintOptionsImpl_h__
#include "nsIPrintOptions.h"
#include "nsIPrintSettingsService.h"
class nsIPref;
class nsIPrintSettings;
//class nsIPrintSettings;
//*****************************************************************************
//*** nsPrintOptions
//*****************************************************************************
class NS_GFX nsPrintOptions : public nsIPrintOptions
class NS_GFX nsPrintOptions : public nsIPrintOptions, public nsIPrintSettingsService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTOPTIONS
NS_DECL_NSIPRINTSETTINGSSERVICE
nsPrintOptions();
virtual ~nsPrintOptions();

Просмотреть файл

@ -160,10 +160,10 @@ static const nsModuleComponentInfo components[] =
// "@mozilla.org/gfx/device_context_spec_factory/gtk;1",
"@mozilla.org/gfx/devicecontextspecfactory;1",
nsDeviceContextSpecFactoryOS2Constructor },
{ "Print Options",
NS_PRINTOPTIONS_CID,
// "@mozilla.org/gfx/printoptions;1",
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
// "@mozilla.org/gfx/printsettings-service;1",
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsOS2Constructor },
{ "OS2 Font Enumerator",
NS_FONT_ENUMERATOR_CID,

Просмотреть файл

@ -58,7 +58,6 @@ nsDeviceContextSpecFactoryPh :: ~nsDeviceContextSpecFactoryPh()
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryPh, nsIDeviceContextSpecFactory)

Просмотреть файл

@ -159,10 +159,10 @@ static const nsModuleComponentInfo components[] =
"@mozilla.org/gfx/devicecontextspecfactory;1",
//"@mozilla.org/gfx/device_context_spec_factory/Ph;1",
nsDeviceContextSpecFactoryPhConstructor },
{ "Print Options",
NS_PRINTOPTIONS_CID,
// "@mozilla.org/gfx/printoptions;1",
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
// "@mozilla.org/gfx/printsettings-service;1",
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsPhConstructor },
{ "Ph Font Enumerator",
NS_FONT_ENUMERATOR_CID,

Просмотреть файл

@ -51,7 +51,6 @@ nsDeviceContextSpecFactoryWin :: ~nsDeviceContextSpecFactoryWin()
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryWin, nsIDeviceContextSpecFactory)

Просмотреть файл

@ -60,7 +60,6 @@
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsGfxCIID.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
// File Picker
#include "nsILocalFile.h"

Просмотреть файл

@ -196,8 +196,8 @@ static const nsModuleComponentInfo components[] =
nsScriptableRegionConstructor },
{ "nsPrintOptionsWin",
NS_PRINTOPTIONS_CID,
"@mozilla.org/gfx/printoptions;1",
NS_PRINTSETTINGSSERVICE_CID,
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsWinConstructor },
{ "nsFontEnumeratorWin",

Просмотреть файл

@ -159,10 +159,10 @@ static const nsModuleComponentInfo components[] =
// "@mozilla.org/gfx/device_context_spec_factory/xlib;1",
"@mozilla.org/gfx/devicecontextspecfactory;1",
nsDeviceContextSpecFactoryXlibConstructor },
{ "Print Options",
NS_PRINTOPTIONS_CID,
// "@mozilla.org/gfx/printoptions;1",
"@mozilla.org/gfx/printoptions;1",
{ "PrintSettings Service",
NS_PRINTSETTINGSSERVICE_CID,
// "@mozilla.org/gfx/printsettings-service;1",
"@mozilla.org/gfx/printsettings-service;1",
nsPrintOptionsXlibConstructor },
{ "Xlib Font Enumerator",
NS_FONT_ENUMERATOR_CID,

Просмотреть файл

@ -123,15 +123,19 @@
// Print Options
#include "nsIPrintSettings.h"
#include "nsIPrintSettingsService.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
#include "nsISimpleEnumerator.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
// PrintOptions is now implemented by PrintSettingsService
const char* kPrintSettingsServiceCID = "@mozilla.org/gfx/printsettings-service;1";
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
// Printing Events
#include "nsIEventQueue.h"
#include "nsIEventQueueService.h"
@ -6427,21 +6431,24 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
// to if we have a PrintOptions first, because we can't do anything
// below without it then inside we check to se if the printSettings
// is null to know if we need to create on.
// if they don't pass in a PrintSettings, then get the Global PS
mPrt->mPrintSettings = aPrintSettings;
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) {
// if they don't pass in a PrintSettings, then make one
if (mPrt->mPrintSettings == nsnull) {
mPrt->mPrintOptions->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!");
if (!mPrt->mPrintSettings) {
GetGlobalPrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions && mPrt->mPrintSettings) {
// Get the default printer name and set it into the PrintSettings
if (NS_FAILED(CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_PRINTPREVIEW, PR_FALSE))) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
rv = CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE);
} else {
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
// Let's print ...
@ -6541,7 +6548,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
if (factory) {
nsCOMPtr<nsIDeviceContextSpec> devspec;
nsCOMPtr<nsIDeviceContext> dx;
nsresult rv = factory->CreateDeviceContextSpec(mWindow, aPrintSettings, *getter_AddRefs(devspec), PR_TRUE);
nsresult rv = factory->CreateDeviceContextSpec(mWindow, mPrt->mPrintSettings, *getter_AddRefs(devspec), PR_TRUE);
if (NS_SUCCEEDED(rv)) {
rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC));
if (NS_SUCCEEDED(rv)) {
@ -6818,23 +6825,24 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
return NS_ERROR_OUT_OF_MEMORY;
}
// if they don't pass in a PrintSettings, then make one
// it will have all the default values
// if they don't pass in a PrintSettings, then get the Global PS
mPrt->mPrintSettings = aPrintSettings;
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) {
// if they don't pass in a PrintSettings, then make one
if (mPrt->mPrintSettings == nsnull) {
mPrt->mPrintOptions->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!");
if (!mPrt->mPrintSettings) {
GetGlobalPrintSettings(getter_AddRefs(mPrt->mPrintSettings));
}
mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions && mPrt->mPrintSettings) {
// Get the default printer name and set it into the PrintSettings
if (NS_FAILED(CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE))) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
rv = CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE);
} else {
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
}
mPrt->mPrintSettings->SetIsCancelled(PR_FALSE);
mPrt->mPrintSettings->GetShrinkToFit(&mPrt->mShrinkToFit);
@ -6972,7 +6980,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
// NS_ERROR_NOT_IMPLEMENTED indicates they want default behavior
// Any other error code means we must bail out
//
rv = printPromptService->ShowPrintDialog(domWin, this, aPrintSettings);
rv = printPromptService->ShowPrintDialog(domWin, this, mPrt->mPrintSettings);
if (rv == NS_ERROR_NOT_IMPLEMENTED) {
// This means the Dialog service was there,
// but they choose not to implement this dialog and
@ -8221,57 +8229,6 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount,
}
/* readonly attribute nsIPrintSettings newPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings)
{
NS_ENSURE_ARG_POINTER(aNewPrintSettings);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = printService->CreatePrintSettings(aNewPrintSettings);
InitPrintSettingsFromPrinter(nsnull, *aNewPrintSettings);
}
return rv;
}
/* readonly attribute wstring defaultPrinterName; */
NS_IMETHODIMP
DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->GetDefaultPrinterName(aDefaultPrinterName);
}
return rv;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP
DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
NS_ENSURE_ARG_POINTER(aPrintSettings);
PRUnichar* printerName = nsnull;
if (!aPrinterName) {
GetDefaultPrinterName(&printerName);
if (!printerName || !*printerName) return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->InitPrintSettingsFromPrinter(aPrinterName?aPrinterName:printerName, aPrintSettings);
}
if (printerName) {
nsMemory::Free(printerName);
}
return NS_OK;
}
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
@ -8279,9 +8236,10 @@ DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSetti
NS_ENSURE_ARG_POINTER(aGlobalPrintSettings);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
//nsCOMPtr<nsIPrintOptions> printSettingsService = do_GetService(kPrintOptionsCID, &rv);
nsCOMPtr<nsIPrintSettingsService> printSettingsService = do_GetService(kPrintSettingsServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = printService->GetGlobalPrintSettings(aGlobalPrintSettings);
rv = printSettingsService->GetGlobalPrintSettings(aGlobalPrintSettings);
}
return rv;
}
@ -8377,30 +8335,6 @@ DocumentViewerImpl::Cancel()
return NS_ERROR_FAILURE;
}
/* void initPrintSettingsFromPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && printService) {
return printService->InitPrintSettingsFromPrefs(aPrintSettings, aUsePrinterNamePrefix, aFlags);
}
return NS_OK;
}
/* void savePrintSettingsToPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv) && printService) {
return printService->SavePrintSettingsToPrefs(aPrintSettings, aUsePrinterNamePrefix, aFlags);
}
return NS_OK;
}
/** ---------------------------------------------------
* Get the Focused Frame for a documentviewer
*

Просмотреть файл

@ -76,7 +76,6 @@
#include "nsIPrintSettings.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
// Widget Creation
#include "nsIWidget.h"

Просмотреть файл

@ -80,7 +80,8 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
//
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);

Просмотреть файл

@ -76,7 +76,6 @@
#include "nsIPrintSettings.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
// Widget Creation
#include "nsIWidget.h"

Просмотреть файл

@ -80,7 +80,8 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
const char* kPrintOptionsCID = "@mozilla.org/gfx/printsettings-service;1";
//
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);

Просмотреть файл

@ -843,30 +843,11 @@ PluginViewerImpl::Print(nsIPrintSettings* aPrintSettings,
}
NS_IMETHODIMP
PluginViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute wstring defaultPrinterName; */
NS_IMETHODIMP
PluginViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP
PluginViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP
NS_IMETHODIMP
PluginViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void printPreview (in nsIPrintSettings aThePrintSettings); */
@ -912,20 +893,6 @@ PluginViewerImpl::Cancel()
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void initPrintSettingsFromPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
PluginViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void savePrintSettingsToPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */
NS_IMETHODIMP
PluginViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void enumerateDocumentNames (out PRUint32 aCount, [array, size_is (aCount), retval] out wstring aResult); */
NS_IMETHODIMP
PluginViewerImpl::EnumerateDocumentNames(PRUint32 *aCount, PRUnichar ***aResult)

Просмотреть файл

@ -2211,7 +2211,7 @@ void nsBrowserWindow::DoPrint(void)
nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint = do_QueryInterface(viewer);
if (webBrowserPrint) {
if (!mPrintSettings) {
webBrowserPrint->GetNewPrintSettings(getter_AddRefs(mPrintSettings));
webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(mPrintSettings));
}
webBrowserPrint->Print(mPrintSettings, (nsIWebProgressListener*)nsnull);
}

Просмотреть файл

@ -198,7 +198,7 @@ function BrowserExitPrintPreview()
mainWin.setAttribute("onclose", gOldCloseHandler);
}
function GetPrintSettings(webBrowserPrint)
function GetPrintSettings()
{
var prevPS = gPrintSettings;
@ -211,13 +211,15 @@ function GetPrintSettings(webBrowserPrint)
gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
}
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
if (gPrintSettingsAreGlobal) {
gPrintSettings = webBrowserPrint.globalPrintSettings;
gPrintSettings = psService.globalPrintSettings;
if (gSavePrintSettings) {
webBrowserPrint.initPrintSettingsFromPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
psService.initPrintSettingsFromPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
} else {
gPrintSettings = webBrowserPrint.newPrintSettings;
gPrintSettings = psService.newPrintSettings;
}
}
} catch (e) {
@ -249,7 +251,7 @@ function BrowserPrintPreview()
var webBrowserPrint = ifreq.getInterface(
Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings(webBrowserPrint);
gPrintSettings = GetPrintSettings();
webBrowserPrint.printPreview(gPrintSettings, null);
}
@ -274,7 +276,7 @@ function BrowserPrintSetup()
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings(webBrowserPrint);
gPrintSettings = GetPrintSettings();
}
didOK = goPageSetup(window, gPrintSettings); // from utilityOverlay.js
@ -282,7 +284,9 @@ function BrowserPrintSetup()
if (webBrowserPrint) {
if (gPrintSettingsAreGlobal && gSavePrintSettings) {
webBrowserPrint.savePrintSettingsToPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
psService.savePrintSettingsToPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
if (webBrowserPrint.doingPrintPreview) {
webBrowserPrint.printPreview(gPrintSettings, null);
@ -301,7 +305,7 @@ function BrowserPrint()
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings(webBrowserPrint);
gPrintSettings = GetPrintSettings();
webBrowserPrint.print(gPrintSettings, null);
}
} catch (e) {

Просмотреть файл

@ -26,6 +26,7 @@
var dialog;
var printService = null;
var printOptions = null;
var gOriginalNumCopies = 1;
var paramBlock;
@ -176,7 +177,7 @@ listElement.prototype =
//---------------------------------------------------
function getPrinters()
{
var printerEnumerator = printService.availablePrinters();
var printerEnumerator = printOptions.availablePrinters();
var selectElement = new listElement(dialog.printerList);
selectElement.clearList();
@ -198,7 +199,7 @@ function setPrinterDefaultsForSelectedPrinter()
gPrintSettings.printerName = dialog.printerList.value;
// First get any defaults from the printer
gWebBrowserPrint.initPrintSettingsFromPrinter(gPrintSettings.printerName, gPrintSettings);
printService.initPrintSettingsFromPrinter(gPrintSettings.printerName, gPrintSettings);
var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit |
gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight |
@ -206,7 +207,7 @@ function setPrinterDefaultsForSelectedPrinter()
gPrintSetInterface.kInitSavePrintCommand;
// now augment them with any values from last time
gWebBrowserPrint.initPrintSettingsFromPrefs(gPrintSettings, true, flags);
printService.initPrintSettingsFromPrefs(gPrintSettings, true, flags);
}
@ -252,11 +253,12 @@ function loadDialog()
var print_tofile = "";
try {
printService = Components.classes["@mozilla.org/gfx/printoptions;1"];
printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"];
if (printService) {
printService = printService.getService();
if (printService) {
printService = printService.QueryInterface(Components.interfaces.nsIPrintOptions);
printService = printService.QueryInterface(Components.interfaces.nsIPrintSettingsService);
printOptions = printService.QueryInterface(Components.interfaces.nsIPrintOptions);
}
}
} catch(e) {}
@ -435,12 +437,12 @@ function onAccept()
saveToPrefs = prefs.getBoolPref("print.save_print_settings");
}
if (saveToPrefs && gWebBrowserPrint != null) {
if (saveToPrefs && printService != null) {
var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit |
gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight |
gPrintSetInterface.kInitSavePaperName |
gPrintSetInterface.kInitSavePrintCommand;
gWebBrowserPrint.savePrintSettingsToPrefs(gPrintSettings, true, flags);
printService.savePrintSettingsToPrefs(gPrintSettings, true, flags);
}
// set return value to "print"