1) On windows and OS/2 it implements IDL attr of "defaultPrinterName" (like Bug 118152)

2) Stubs this out on al other platforms
3) On Windows implmenets new method "InitPrintSettingsFromPrinter" which sets certain key values from the native devmode into the print settings
4) Stubs this out on all other platforms
5) It also cleans up the nsDeviceContextSpecWin interface a little bit:
   It now has a single GetDevMode method that must be paired with a UnlockDevMode  method.
6) It moved GetDataFromPrinter into the public interface
7) Created a simple helper function for getting the default printer name.
Bug 123554 r=dcone sr=attinasi
This commit is contained in:
rods%netscape.com 2002-02-13 13:58:41 +00:00
parent 0fc154332c
commit 106d57603e
14 changed files with 294 additions and 55 deletions

View File

@ -72,7 +72,6 @@
#include "nsViewsCID.h"
#include "nsWidgetsCID.h"
#include "nsGfxCIID.h"
#include "nsIDeviceContext.h"
#include "nsIDeviceContextSpec.h"
#include "nsIDeviceContextSpecFactory.h"
@ -127,6 +126,7 @@
#include "nsISimpleEnumerator.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
// Printing Events
#include "nsIEventQueue.h"
@ -6871,6 +6871,35 @@ DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *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(aPrinterName);
NS_ENSURE_ARG_POINTER(aPrintSettings);
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->InitPrintSettingsFromPrinter(aPrinterName, aPrintSettings);
}
return NS_OK;
}
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)

View File

@ -67,6 +67,21 @@ 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
* These settings include, but are not limited to:
* Page Orientation
* Page Size
* Number of Copies
*/
void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
/**
* Use this to Set and Get the current values of the last print invocation
* of "print" or "printpreview". The print engine always sets the PrintSettings

View File

@ -266,6 +266,23 @@ interface nsIPrintOptions : nsISupports
[scriptable, uuid(a6cf9128-15b3-11d2-932e-00805f8add32)]
interface nsIPrinterEnumerator : nsISupports
{
/**
* The name of the default printer
* This name must be in the list of printer names returned by
* "availablePrinters"
*
*/
readonly attribute wstring defaultPrinterName;
/**
* Initializes certain settings from the native printer into the PrintSettings
* These settings include, but are not limited to:
* Page Orientation
* Page Size
* Number of Copies
*/
void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
/**
* Returns an array of the names of all installed printers.
*

View File

@ -544,6 +544,12 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUni
return NS_OK;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP nsPrinterEnumeratorBeOS::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorBeOS::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
{
/* fixme: We simply ignore the |aPrinter| argument here

View File

@ -482,7 +482,13 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnic
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_OK;
}
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

View File

@ -54,6 +54,7 @@ public:
PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; }
PRInt32 GetNumPrinters() { return mGlobalNumPrinters; }
nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); }
void GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName);
protected:
GlobalPrinters() {}
@ -397,6 +398,19 @@ NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnic
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorOS2::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
GlobalPrinters::GetInstance()->GetDefaultPrinterName(*aDefaultPrinterName);
return NS_OK;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP nsPrinterEnumeratorOS2::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsPrinterEnumeratorOS2::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
{
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
@ -442,6 +456,18 @@ nsresult GlobalPrinters::InitializeGlobalPrinters ()
return NS_OK;
}
void GlobalPrinters::GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName)
{
aDefaultPrinterName = nsnull;
int defaultPrinter = nsDeviceContextSpecOS2::PrnDlg.GetDefaultPrinter();
char *printer = nsDeviceContextSpecOS2::PrnDlg.GetPrinter(defaultPrinter);
nsAutoString defaultName;
defaultName.AppendWithConversion(printer);
aDefaultPrinterName = ToNewUnicode(defaultName);
}
void GlobalPrinters::FreeGlobalPrinters()
{
delete mGlobalPrinterList;

View File

@ -148,6 +148,12 @@ nsPrinterEnumeratorPh::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
return DoEnumeratePrinters(PR_FALSE, aCount, aResult);
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP nsPrinterEnumeratorPh::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_OK;
}
//----------------------------------------------------------------------------------
// Display the AdvancedDocumentProperties for the selected Printer
NS_IMETHODIMP nsPrinterEnumeratorPh::DisplayPropertiesDlg(const PRUnichar *aPrinterName, nsIPrintSettings* aPrintSettings)

View File

@ -200,7 +200,7 @@ const NativePaperSizes kPaperSizes[] = {
const PRInt32 kNumPaperSizes = 41;
//----------------------------------------------------------------------------------
nsDeviceContextSpecWin :: nsDeviceContextSpecWin() :
nsDeviceContextSpecWin::nsDeviceContextSpecWin() :
mUseExtendedPrintDlg(NULL)
{
NS_INIT_REFCNT();
@ -223,7 +223,7 @@ nsDeviceContextSpecWin :: nsDeviceContextSpecWin() :
//----------------------------------------------------------------------------------
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecWin, nsIDeviceContextSpec)
nsDeviceContextSpecWin :: ~nsDeviceContextSpecWin()
nsDeviceContextSpecWin::~nsDeviceContextSpecWin()
{
SetDeviceName(nsnull);
SetDriverName(nsnull);
@ -328,7 +328,9 @@ SetupDevModeFromSettings(LPDEVMODE aDevMode, nsIPrintSettings* aPrintSettings)
//----------------------------------------------------------------------------------
// Helper Function - Free and reallocate the string
static nsresult SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, LPDEVMODE aDevMode)
nsresult
nsDeviceContextSpecWin::SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings,
LPDEVMODE aDevMode)
{
if (aPrintSettings == nsnull) {
return NS_ERROR_FAILURE;
@ -376,9 +378,9 @@ static nsresult SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, LP
}
//----------------------------------------------------------------------------------
NS_IMETHODIMP nsDeviceContextSpecWin :: Init(nsIWidget* aWidget,
nsIPrintSettings* aPrintSettings,
PRBool aQuiet)
NS_IMETHODIMP nsDeviceContextSpecWin::Init(nsIWidget* aWidget,
nsIPrintSettings* aPrintSettings,
PRBool aQuiet)
{
mPrintSettings = aPrintSettings;
@ -429,19 +431,19 @@ static void CleanAndCopyString(char*& aStr, char* aNewStr)
}
//----------------------------------------------------------------------------------
void nsDeviceContextSpecWin :: SetDeviceName(char* aDeviceName)
void nsDeviceContextSpecWin::SetDeviceName(char* aDeviceName)
{
CleanAndCopyString(mDeviceName, aDeviceName);
}
//----------------------------------------------------------------------------------
void nsDeviceContextSpecWin :: SetDriverName(char* aDriverName)
void nsDeviceContextSpecWin::SetDriverName(char* aDriverName)
{
CleanAndCopyString(mDriverName, aDriverName);
}
//----------------------------------------------------------------------------------
void nsDeviceContextSpecWin :: SetGlobalDevMode(HGLOBAL aHGlobal)
void nsDeviceContextSpecWin::SetGlobalDevMode(HGLOBAL aHGlobal)
{
if (mGlobalDevMode) {
::GlobalFree(mGlobalDevMode);
@ -452,7 +454,7 @@ void nsDeviceContextSpecWin :: SetGlobalDevMode(HGLOBAL aHGlobal)
}
//----------------------------------------------------------------------------------
void nsDeviceContextSpecWin :: SetDevMode(LPDEVMODE aDevMode)
void nsDeviceContextSpecWin::SetDevMode(LPDEVMODE aDevMode)
{
if (mDevMode) free(mDevMode);
@ -939,11 +941,44 @@ static HGLOBAL CreateGlobalDevModeAndInit(LPTSTR aPrintName, nsIPrintSettings* a
return hGlobalDevMode;
}
//------------------------------------------------------------------
// helper
static PRUnichar * GetDefaultPrinterNameFromGlobalPrinters()
{
PRUnichar * printerName;
LPTSTR lpPrtName;
GlobalPrinters::GetInstance()->GetDefaultPrinterName(lpPrtName);
nsString str;
#ifdef UNICODE
str.AppendWithConversion((PRUnichar *)lpPrtName);
#else
str.AssignWithConversion((char*)lpPrtName);
#endif
printerName = ToNewUnicode(str);
free(lpPrtName);
return printerName;
}
//------------------------------------------------------------------
void
nsDeviceContextSpecWin::GetDevMode(LPDEVMODE &aDevMode)
{
if (mIsDEVMODEGlobalHandle) {
if (mGlobalDevMode) {
aDevMode = (DEVMODE *)::GlobalLock(mGlobalDevMode);
} else {
aDevMode = NULL;
}
} else {
aDevMode = mDevMode;
}
}
//------------------------------------------------------------------
// Displays the native Print Dialog
nsresult
nsDeviceContextSpecWin :: ShowNativePrintDialog(nsIWidget *aWidget, PRBool aQuiet)
nsDeviceContextSpecWin::ShowNativePrintDialog(nsIWidget *aWidget, PRBool aQuiet)
{
NS_ENSURE_ARG_POINTER(aWidget);
nsresult rv = NS_ERROR_FAILURE;
@ -958,16 +993,7 @@ nsDeviceContextSpecWin :: ShowNativePrintDialog(nsIWidget *aWidget, PRBool aQuie
// If there is no name then use the default printer
if (!printerName || (printerName && !*printerName)) {
LPTSTR lpPrtName;
GlobalPrinters::GetInstance()->GetDefaultPrinterName(lpPrtName);
nsString str;
#ifdef UNICODE
str.AppendWithConversion((PRUnichar *)lpPrtName);
#else
str.AssignWithConversion((char*)lpPrtName);
#endif
printerName = ToNewUnicode(str);
free(lpPrtName);
printerName = GetDefaultPrinterNameFromGlobalPrinters();
}
NS_ASSERTION(printerName, "We have to have a printer name");
@ -1286,7 +1312,7 @@ static HPROPSHEETPAGE ExtendPrintDialog(HWND aHWnd, char* aTitle)
//------------------------------------------------------------------
// Displays the native Print Dialog
nsresult
nsDeviceContextSpecWin :: ShowNativePrintDialogEx(nsIWidget *aWidget, PRBool aQuiet)
nsDeviceContextSpecWin::ShowNativePrintDialogEx(nsIWidget *aWidget, PRBool aQuiet)
{
NS_ENSURE_ARG_POINTER(aWidget);
@ -1497,7 +1523,7 @@ nsDeviceContextSpecWin :: ShowNativePrintDialogEx(nsIWidget *aWidget, PRBool aQu
//----------------------------------------------------------------------------------
// Setup the object's data member with the selected printer's data
nsresult
nsDeviceContextSpecWin :: GetDataFromPrinter(PRUnichar * aName, nsIPrintSettings* aPS)
nsDeviceContextSpecWin::GetDataFromPrinter(const PRUnichar * aName, nsIPrintSettings* aPS)
{
nsresult rv = NS_ERROR_FAILURE;
@ -1560,27 +1586,21 @@ nsDeviceContextSpecWin :: GetDataFromPrinter(PRUnichar * aName, nsIPrintSettings
// 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()
nsDeviceContextSpecWin::SetupPaperInfoFromSettings()
{
LPDEVMODE devMode;
if (mDevMode == NULL && mGlobalDevMode == NULL) {
return;
GetDevMode(devMode);
NS_ASSERTION(devMode, "DevMode can't be NULL here");
if (devMode) {
SetupDevModeFromSettings(devMode, mPrintSettings);
}
if (mGlobalDevMode != nsnull) {
devMode = (DEVMODE *)::GlobalLock(mGlobalDevMode);
} else {
devMode = mDevMode;
}
SetupDevModeFromSettings(devMode, mPrintSettings);
if (mGlobalDevMode != nsnull) ::GlobalUnlock(mGlobalDevMode);
UnlockDevMode();
}
//----------------------------------------------------------------------------------
nsresult
nsDeviceContextSpecWin :: ShowXPPrintDialog(PRBool aQuiet)
nsDeviceContextSpecWin::ShowXPPrintDialog(PRBool aQuiet)
{
nsresult rv = NS_ERROR_FAILURE;
@ -1694,6 +1714,53 @@ static void CleanupArray(PRUnichar**& aArray, PRInt32& aCount)
aCount = 0;
}
//----------------------------------------------------------------------------------
// Return the Default Printer name
/* readonly attribute wstring defaultPrinterName; */
NS_IMETHODIMP
nsPrinterEnumeratorWin::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
{
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
*aDefaultPrinterName = GetDefaultPrinterNameFromGlobalPrinters(); // helper
return NS_OK;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP
nsPrinterEnumeratorWin::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
NS_ENSURE_ARG_POINTER(aPrinterName);
NS_ENSURE_ARG_POINTER(aPrintSettings);
if (!*aPrinterName) {
return NS_OK;
}
nsCOMPtr<nsDeviceContextSpecWin> devSpecWin = new nsDeviceContextSpecWin();
if (!devSpecWin) return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(GlobalPrinters::GetInstance()->EnumeratePrinterList())) {
return NS_ERROR_FAILURE;
}
devSpecWin->GetDataFromPrinter(aPrinterName);
LPDEVMODE devmode;
devSpecWin->GetDevMode(devmode);
NS_ASSERTION(devmode, "DevMode can't be NULL here");
if (devmode) {
nsDeviceContextSpecWin::SetPrintSettingsFromDevMode(aPrintSettings, devmode);
}
devSpecWin->UnlockDevMode();
// Free them, we won't need them for a while
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
return NS_OK;
}
//----------------------------------------------------------------------------------
// Enumerate all the Printers from the global array and pass their
// names back (usually to script)
@ -1796,7 +1863,7 @@ NS_IMETHODIMP nsPrinterEnumeratorWin::DisplayPropertiesDlg(const PRUnichar *aPri
#endif
if (stat == IDOK) {
// Now set the print options from the native Page Setup
SetPrintSettingsFromDevMode(aPrintSettings, pDevMode);
nsDeviceContextSpecWin::SetPrintSettingsFromDevMode(aPrintSettings, pDevMode);
}
free(pDevMode);
free(pNewDevMode);

View File

@ -53,11 +53,21 @@ public:
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; }
void GetDriverName(char *&aDriverName) const { aDriverName = mDriverName; }
void GetDeviceName(char *&aDeviceName) const { aDeviceName = mDeviceName; }
// The GetDevMode will return a pointer to a DevMode
// whether it is from the Global memory handle or just the DevMode
// To get the DevMode from the Global memory Handle it must lock it
// So this call must be paired with a call to UnlockGlobalHandle
void GetDevMode(LPDEVMODE &aDevMode);
void UnlockDevMode() { if (mIsDEVMODEGlobalHandle && mGlobalDevMode) ::GlobalUnlock(mGlobalDevMode); }
// helper functions
nsresult GetDataFromPrinter(const PRUnichar * aName, nsIPrintSettings* aPS = nsnull);
static nsresult SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings,
LPDEVMODE aDevMode);
protected:
nsresult ShowXPPrintDialog(PRBool aQuiet);
@ -72,7 +82,6 @@ protected:
void SetGlobalDevMode(HGLOBAL aHGlobal);
void SetDevMode(LPDEVMODE aDevMode);
nsresult GetDataFromPrinter(PRUnichar * aName, nsIPrintSettings* aPS = nsnull);
void SetupPaperInfoFromSettings();
virtual ~nsDeviceContextSpecWin();

View File

@ -960,17 +960,13 @@ NS_IMETHODIMP nsDeviceContextWin :: GetDeviceContextFor(nsIDeviceContextSpec *aD
devSpecWin->GetDriverName(drivername); // sets pointer do not free
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);
LPDEVMODE devmode;
devSpecWin->GetDevMode(devmode);
NS_ASSERTION(devmode, "DevMode can't be NULL here");
if (devmode) {
dc = ::CreateDC(drivername, devicename, NULL, devmode);
}
devSpecWin->UnlockDevMode();
return devConWin->Init(dc, this); // take ownership of the DC
}

View File

@ -482,6 +482,12 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUni
return NS_OK;
}
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
{
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
{
/* fixme: We simply ignore the |aPrinter| argument here

View File

@ -72,7 +72,6 @@
#include "nsViewsCID.h"
#include "nsWidgetsCID.h"
#include "nsGfxCIID.h"
#include "nsIDeviceContext.h"
#include "nsIDeviceContextSpec.h"
#include "nsIDeviceContextSpecFactory.h"
@ -127,6 +126,7 @@
#include "nsISimpleEnumerator.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
// Printing Events
#include "nsIEventQueue.h"
@ -6871,6 +6871,35 @@ DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *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(aPrinterName);
NS_ENSURE_ARG_POINTER(aPrintSettings);
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
if (prtEnum) {
prtEnum->InitPrintSettingsFromPrinter(aPrinterName, aPrintSettings);
}
return NS_OK;
}
/* readonly attribute nsIPrintSettings globalPrintSettings; */
NS_IMETHODIMP
DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)

View File

@ -809,6 +809,19 @@ 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
PluginViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)

View File

@ -74,6 +74,8 @@ function BrowserReloadWithFlags(reloadFlags)
function GetPrintSettings(webBrowserPrint)
{
var prevPS = gPrintSettings;
try {
if (gPrintSettings == null) {
var useGlobalPrintSettings = true;
@ -88,6 +90,18 @@ function GetPrintSettings(webBrowserPrint)
} else {
gPrintSettings = webBrowserPrint.globalPrintSettings;
}
// only do this the first time
if (prevPS == null) {
var defPrinterName = webBrowserPrint.defaultPrinterName;
if (defPrinterName != "") {
if (gPrintSettings.printerName == null || gPrintSettings.printerName == "") {
gPrintSettings.printerName = defPrinterName;
}
webBrowserPrint.initPrintSettingsFromPrinter(gPrintSettings.printerName, gPrintSettings);
}
}
}
} catch (e) {
alert("GetPrintSettings "+e);