зеркало из https://github.com/mozilla/pjs.git
Bug 377096 - Factor out nsIPrintOptions::AvailablePrinters. r=pavlov, sr=biesi.
This commit is contained in:
Родитель
f81a94510f
Коммит
c693e38ac1
|
@ -55,6 +55,7 @@
|
|||
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
@ -563,20 +564,10 @@ nsPrinterEnumeratorQt::nsPrinterEnumeratorQt()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorQt, nsIPrinterEnumerator)
|
||||
|
||||
NS_IMETHODIMP nsPrinterEnumeratorQt::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
||||
NS_IMETHODIMP nsPrinterEnumeratorQt::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
||||
{
|
||||
NS_ENSURE_ARG(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
if (aCount)
|
||||
*aCount = 0;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aResult)
|
||||
*aResult = nsnull;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
||||
*aPrinterNameList = nsnull;
|
||||
|
||||
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -584,9 +575,8 @@ NS_IMETHODIMP nsPrinterEnumeratorQt::EnumeratePrinters(PRUint32* aCount, PRUnich
|
|||
}
|
||||
|
||||
PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
||||
|
||||
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
|
||||
if (!array && numPrinters > 0) {
|
||||
nsStringArray *printers = new nsStringArray(numPrinters);
|
||||
if (!printers) {
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -594,25 +584,11 @@ NS_IMETHODIMP nsPrinterEnumeratorQt::EnumeratePrinters(PRUint32* aCount, PRUnich
|
|||
int count = 0;
|
||||
while( count < numPrinters )
|
||||
{
|
||||
PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
|
||||
|
||||
if (!str) {
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
nsMemory::Free(array[i]);
|
||||
|
||||
nsMemory::Free(array);
|
||||
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
array[count++] = str;
|
||||
|
||||
printers->AppendString(*GlobalPrinters::GetInstance()->GetStringAt(count++));
|
||||
}
|
||||
*aCount = count;
|
||||
*aResult = array;
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
|
||||
}
|
||||
|
||||
/* readonly attribute wstring defaultPrinterName; */
|
||||
|
|
|
@ -117,7 +117,6 @@ public:
|
|||
float mOrigDCScale;
|
||||
|
||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||
nsCOMPtr<nsIPrintOptions> mPrintOptions;
|
||||
nsPrintPreviewListener* mPPEventListeners;
|
||||
|
||||
PRUnichar* mBrandName; // needed as a substitute name for a document
|
||||
|
|
|
@ -57,13 +57,10 @@
|
|||
#include "nsGfxCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
// PrintOptions is now implemented by PrintSettingsService
|
||||
static const char sPrintSettingsServiceContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
||||
static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
||||
|
||||
// Printing Events
|
||||
#include "nsPrintPreviewListener.h"
|
||||
|
@ -468,9 +465,7 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
mPrt->mPrintOptions = do_GetService(sPrintOptionsContractID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings);
|
||||
rv = CheckForPrinters(mPrt->mPrintSettings);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mPrt->mPrintSettings->SetIsCancelled(PR_FALSE);
|
||||
|
@ -914,48 +909,32 @@ nsPrintEngine::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings
|
|||
// and if so, it sets the first printer in the list as the default name
|
||||
// in the PrintSettings which is then used for Printer Preview
|
||||
nsresult
|
||||
nsPrintEngine::CheckForPrinters(nsIPrintOptions* aPrintOptions,
|
||||
nsIPrintSettings* aPrintSettings)
|
||||
nsPrintEngine::CheckForPrinters(nsIPrintSettings* aPrintSettings)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPrintOptions);
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
// Mac doesn't support retrieving a printer list.
|
||||
return NS_OK;
|
||||
#else
|
||||
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
||||
|
||||
nsresult rv;
|
||||
// See if aPrintSettings already has a printer
|
||||
nsXPIDLString printerName;
|
||||
nsresult rv = aPrintSettings->GetPrinterName(getter_Copies(printerName));
|
||||
if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> simpEnum;
|
||||
rv = aPrintOptions->AvailablePrinters(getter_AddRefs(simpEnum));
|
||||
if (simpEnum) {
|
||||
PRBool fndPrinter = PR_FALSE;
|
||||
simpEnum->HasMoreElements(&fndPrinter);
|
||||
if (fndPrinter) {
|
||||
// For now, it assumes the first item in the list
|
||||
// is the default printer, but only set the
|
||||
// printer name if there isn't one
|
||||
nsCOMPtr<nsISupports> supps;
|
||||
simpEnum->GetNext(getter_AddRefs(supps));
|
||||
PRUnichar* defPrinterName;
|
||||
aPrintSettings->GetPrinterName(&defPrinterName);
|
||||
if (!defPrinterName || !*defPrinterName) {
|
||||
if (defPrinterName) nsMemory::Free(defPrinterName);
|
||||
nsCOMPtr<nsISupportsString> wStr = do_QueryInterface(supps);
|
||||
if (wStr) {
|
||||
wStr->ToString(&defPrinterName);
|
||||
aPrintSettings->SetPrinterName(defPrinterName);
|
||||
nsMemory::Free(defPrinterName);
|
||||
}
|
||||
} else {
|
||||
nsMemory::Free(defPrinterName);
|
||||
}
|
||||
rv = NS_OK;
|
||||
}
|
||||
} else {
|
||||
// this means there were no printers
|
||||
// XXX the ifdefs are temporary until they correctly implement Available Printers
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
rv = NS_OK;
|
||||
#endif
|
||||
// aPrintSettings doesn't have a printer set. Try to fetch the default.
|
||||
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
|
||||
do_GetService(sPrintSettingsServiceContractID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = printSettingsService->GetDefaultPrinterName(getter_Copies(printerName));
|
||||
if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
|
||||
rv = aPrintSettings->SetPrinterName(printerName.get());
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -162,8 +162,7 @@ public:
|
|||
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
|
||||
nsIPrintProgressParams* aParams);
|
||||
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
|
||||
nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions,
|
||||
nsIPrintSettings* aPrintSettings);
|
||||
nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings);
|
||||
void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount);
|
||||
|
||||
PRBool IsThereARangeSelection(nsIDOMWindow * aDOMWin);
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
|
||||
var dialog;
|
||||
var printService = null;
|
||||
var printOptions = null;
|
||||
var gOriginalNumCopies = 1;
|
||||
|
||||
var paramBlock;
|
||||
|
@ -148,49 +147,46 @@ listElement.prototype =
|
|||
appendPrinterNames:
|
||||
function (aDataObject)
|
||||
{
|
||||
var list = document.getElementById("printerList");
|
||||
var strDefaultPrinterName = "";
|
||||
var printerName;
|
||||
|
||||
// build popup menu from printer names
|
||||
while (aDataObject.hasMoreElements()) {
|
||||
printerName = aDataObject.getNext();
|
||||
printerName = printerName.QueryInterface(Components.interfaces.nsISupportsString);
|
||||
var printerNameStr = printerName.toString();
|
||||
if (strDefaultPrinterName == "")
|
||||
strDefaultPrinterName = printerNameStr;
|
||||
|
||||
list.appendItem(printerNameStr, printerNameStr, getPrinterDescription(printerNameStr));
|
||||
}
|
||||
if (strDefaultPrinterName != "") {
|
||||
this.listElement.removeAttribute("disabled");
|
||||
} else {
|
||||
if ((null == aDataObject) || !aDataObject.hasMore()) {
|
||||
// disable dialog
|
||||
var stringBundle = srGetStrBundle("chrome://global/locale/printing.properties");
|
||||
this.listElement.setAttribute("value", strDefaultPrinterName);
|
||||
this.listElement.setAttribute("value", "");
|
||||
this.listElement.setAttribute("label", stringBundle.GetStringFromName("noprinter"));
|
||||
|
||||
// disable dialog
|
||||
this.listElement.setAttribute("disabled", "true");
|
||||
dialog.printerLabel.setAttribute("disabled","true");
|
||||
dialog.propertiesButton.setAttribute("disabled","true");
|
||||
dialog.fileCheck.setAttribute("disabled","true");
|
||||
dialog.printButton.setAttribute("disabled","true");
|
||||
}
|
||||
|
||||
return strDefaultPrinterName;
|
||||
else {
|
||||
// build popup menu from printer names
|
||||
var list = document.getElementById("printerList");
|
||||
do {
|
||||
printerNameStr = aDataObject.getNext();
|
||||
list.appendItem(printerNameStr, printerNameStr, getPrinterDescription(printerNameStr));
|
||||
} while (aDataObject.hasMore());
|
||||
this.listElement.removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
function getPrinters()
|
||||
{
|
||||
var printerEnumerator = printOptions.availablePrinters();
|
||||
|
||||
var selectElement = new listElement(dialog.printerList);
|
||||
selectElement.clearList();
|
||||
var strDefaultPrinterName = selectElement.appendPrinterNames(printerEnumerator);
|
||||
|
||||
selectElement.listElement.value = strDefaultPrinterName;
|
||||
var printerEnumerator;
|
||||
try {
|
||||
printerEnumerator =
|
||||
Components.classes["@mozilla.org/gfx/printerenumerator;1"]
|
||||
.getService(Components.interfaces.nsIPrinterEnumerator)
|
||||
.printerNameList;
|
||||
} catch(e) { printerEnumerator = null; }
|
||||
|
||||
selectElement.appendPrinterNames(printerEnumerator);
|
||||
selectElement.listElement.value = printService.defaultPrinterName;
|
||||
|
||||
// make sure we load the prefs for the initially selected printer
|
||||
setPrinterDefaultsForSelectedPrinter();
|
||||
|
@ -265,12 +261,11 @@ function loadDialog()
|
|||
printService = printService.getService();
|
||||
if (printService) {
|
||||
printService = printService.QueryInterface(Components.interfaces.nsIPrintSettingsService);
|
||||
printOptions = printService.QueryInterface(Components.interfaces.nsIPrintOptions);
|
||||
}
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
// Note: getPrinters sets up the PrintToFile radio buttons and initalises gPrintSettings
|
||||
// Note: getPrinters sets up the PrintToFile control
|
||||
getPrinters();
|
||||
|
||||
if (gPrintSettings) {
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
struct nsFont;
|
||||
%}
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsIStringEnumerator;
|
||||
|
||||
/**
|
||||
* Native types
|
||||
|
@ -58,7 +58,7 @@ interface nsISimpleEnumerator;
|
|||
* John Keiser <jkeiser@netscape.com> and Roland Mainz
|
||||
* <roland.mainz@informatik.med.uni-giessen.de> for futher details.
|
||||
*/
|
||||
[scriptable, uuid(722566e9-5983-42e8-9dae-7178b23933c7)]
|
||||
[scriptable, uuid(92597c2b-109b-40bb-8f93-9b9acfa31de8)]
|
||||
|
||||
interface nsIPrintOptions : nsISupports
|
||||
{
|
||||
|
@ -73,13 +73,6 @@ interface nsIPrintOptions : nsISupports
|
|||
*/
|
||||
nsIPrintSettings CreatePrintSettings();
|
||||
|
||||
/**
|
||||
* available Printers
|
||||
* It returns an enumerator object or throws an exception on error cases
|
||||
* like if internal setup failed and/or no printers are available.
|
||||
*/
|
||||
nsISimpleEnumerator availablePrinters ();
|
||||
|
||||
/**
|
||||
* Get a prefixed integer pref
|
||||
*/
|
||||
|
@ -100,15 +93,15 @@ interface nsIPrintOptions : nsISupports
|
|||
[noscript] voidPtr GetNativeData(in short aDataType);
|
||||
};
|
||||
|
||||
[scriptable, uuid(a6cf9128-15b3-11d2-932e-00805f8add32)]
|
||||
[scriptable, uuid(5e738fff-404c-4c94-9189-e8f2cce93e94)]
|
||||
|
||||
interface nsIPrinterEnumerator : nsISupports
|
||||
{
|
||||
/**
|
||||
* The name of the default printer
|
||||
* This name must be in the list of printer names returned by
|
||||
* "availablePrinters"
|
||||
*
|
||||
* The name of the system default printer. This name should also be
|
||||
* present in printerNameList below. This is not necessarily gecko's
|
||||
* default printer; see nsIPrintSettingsService.defaultPrinterName
|
||||
* for that.
|
||||
*/
|
||||
readonly attribute wstring defaultPrinterName;
|
||||
|
||||
|
@ -122,13 +115,9 @@ interface nsIPrinterEnumerator : nsISupports
|
|||
void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
|
||||
|
||||
/**
|
||||
* Returns an array of the names of all installed printers.
|
||||
*
|
||||
* @param aCount returns number of printers returned
|
||||
* @param aResult returns array of names
|
||||
* @return void
|
||||
* The list of printer names
|
||||
*/
|
||||
void enumeratePrinters(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult);
|
||||
readonly attribute nsIStringEnumerator printerNameList;
|
||||
|
||||
/* takes printer selected and will display job properties dlg for that printer
|
||||
* returns true if dialog displays
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "prenv.h" /* for PR_GetEnv */
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -413,20 +414,10 @@ nsPrinterEnumeratorBeOS::nsPrinterEnumeratorBeOS()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorBeOS, nsIPrinterEnumerator)
|
||||
|
||||
NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
||||
NS_IMETHODIMP nsPrinterEnumeratorBeOS::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
||||
{
|
||||
NS_ENSURE_ARG(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
if (aCount)
|
||||
*aCount = 0;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aResult)
|
||||
*aResult = nsnull;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
||||
*aPrinterNameList = nsnull;
|
||||
|
||||
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -434,9 +425,8 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUni
|
|||
}
|
||||
|
||||
PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
||||
|
||||
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
|
||||
if (!array && numPrinters > 0) {
|
||||
nsStringArray *printers = new nsStringArray(numPrinters);
|
||||
if (!printers) {
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -444,26 +434,11 @@ NS_IMETHODIMP nsPrinterEnumeratorBeOS::EnumeratePrinters(PRUint32* aCount, PRUni
|
|||
int count = 0;
|
||||
while( count < numPrinters )
|
||||
{
|
||||
|
||||
PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
|
||||
|
||||
if (!str) {
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
nsMemory::Free(array[i]);
|
||||
|
||||
nsMemory::Free(array);
|
||||
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
array[count++] = str;
|
||||
|
||||
printers->AppendString(*GlobalPrinters::GetInstance()->GetStringAt(count++));
|
||||
}
|
||||
*aCount = count;
|
||||
*aResult = array;
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
|
||||
}
|
||||
|
||||
/* readonly attribute wstring defaultPrinterName; */
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#ifdef USE_XPRINT
|
||||
|
@ -828,20 +829,10 @@ nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator)
|
||||
|
||||
NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
||||
NS_IMETHODIMP nsPrinterEnumeratorGTK::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
||||
{
|
||||
NS_ENSURE_ARG(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
if (aCount)
|
||||
*aCount = 0;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aResult)
|
||||
*aResult = nsnull;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
||||
*aPrinterNameList = nsnull;
|
||||
|
||||
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -849,9 +840,8 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnic
|
|||
}
|
||||
|
||||
PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
||||
|
||||
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
|
||||
if (!array && numPrinters > 0) {
|
||||
nsStringArray *printers = new nsStringArray(numPrinters);
|
||||
if (!printers) {
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -859,25 +849,11 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnic
|
|||
int count = 0;
|
||||
while( count < numPrinters )
|
||||
{
|
||||
PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
|
||||
|
||||
if (!str) {
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
nsMemory::Free(array[i]);
|
||||
|
||||
nsMemory::Free(array);
|
||||
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
array[count++] = str;
|
||||
|
||||
printers->AppendString(*GlobalPrinters::GetInstance()->GetStringAt(count++));
|
||||
}
|
||||
*aCount = count;
|
||||
*aResult = array;
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
|
||||
}
|
||||
|
||||
/* readonly attribute wstring defaultPrinterName; */
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsStringFwd.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
|
||||
#include "nsOS2Uni.h"
|
||||
|
||||
|
@ -435,20 +436,10 @@ nsPrinterEnumeratorOS2::nsPrinterEnumeratorOS2()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorOS2, nsIPrinterEnumerator)
|
||||
|
||||
NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
||||
NS_IMETHODIMP nsPrinterEnumeratorOS2::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
||||
{
|
||||
NS_ENSURE_ARG(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
if (aCount)
|
||||
*aCount = 0;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aResult)
|
||||
*aResult = nsnull;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
||||
*aPrinterNameList = nsnull;
|
||||
|
||||
nsDeviceContextSpecOS2::PrnDlg.RefreshPrintQueue();
|
||||
|
||||
|
@ -458,9 +449,8 @@ NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnic
|
|||
}
|
||||
|
||||
ULONG numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
||||
|
||||
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
|
||||
if (!array && numPrinters > 0) {
|
||||
nsStringArray *printers = new nsStringArray(numPrinters);
|
||||
if (!printers) {
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -468,25 +458,11 @@ NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnic
|
|||
ULONG count = 0;
|
||||
while( count < numPrinters )
|
||||
{
|
||||
PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
|
||||
|
||||
if (!str) {
|
||||
for (ULONG i = 0 ; i < count ; i++)
|
||||
nsMemory::Free(array[i]);
|
||||
|
||||
nsMemory::Free(array);
|
||||
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
array[count++] = str;
|
||||
|
||||
printers->AppendString(*GlobalPrinters::GetInstance()->GetStringAt(count++));
|
||||
}
|
||||
*aCount = count;
|
||||
*aResult = array;
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPrinterEnumeratorOS2::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#ifdef MOZ_CAIRO_GFX
|
||||
#include "gfxPDFSurface.h"
|
||||
#include "gfxWindowsSurface.h"
|
||||
|
@ -905,18 +906,7 @@ nsPrinterEnumeratorWin::~nsPrinterEnumeratorWin()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorWin, nsIPrinterEnumerator)
|
||||
|
||||
|
||||
static void CleanupArray(PRUnichar**& aArray, PRInt32& aCount)
|
||||
{
|
||||
for (PRInt32 i = aCount - 1; i >= 0; i--) {
|
||||
nsMemory::Free(aArray[i]);
|
||||
}
|
||||
nsMemory::Free(aArray);
|
||||
aArray = NULL;
|
||||
aCount = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
// Return the Default Printer name
|
||||
/* readonly attribute wstring defaultPrinterName; */
|
||||
NS_IMETHODIMP
|
||||
|
@ -967,52 +957,31 @@ nsPrinterEnumeratorWin::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterNa
|
|||
// Enumerate all the Printers from the global array and pass their
|
||||
// names back (usually to script)
|
||||
NS_IMETHODIMP
|
||||
nsPrinterEnumeratorWin::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
||||
nsPrinterEnumeratorWin::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
||||
{
|
||||
NS_ENSURE_ARG(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
||||
*aPrinterNameList = nsnull;
|
||||
|
||||
nsresult rv = GlobalPrinters::GetInstance()->EnumeratePrinterList();
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_PL(("***** nsDeviceContextSpecWin::EnumeratePrinters - Couldn't enumerate printers!\n"));
|
||||
PR_PL(("***** nsDeviceContextSpecWin::GetPrinterNameList - Couldn't enumerate printers!\n"));
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aCount)
|
||||
*aCount = 0;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aResult)
|
||||
*aResult = nsnull;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
||||
PRInt32 numItems = numPrinters;
|
||||
|
||||
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numItems * sizeof(PRUnichar*));
|
||||
if (!array)
|
||||
nsStringArray *printers = new nsStringArray(numPrinters);
|
||||
if (!printers)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRInt32 count = 0;
|
||||
|
||||
PRInt32 printerInx = 0;
|
||||
while( count < numItems ) {
|
||||
while( printerInx < numPrinters ) {
|
||||
LPTSTR name = GlobalPrinters::GetInstance()->GetItemFromList(printerInx++);
|
||||
nsAutoString newName;
|
||||
NS_CopyNativeToUnicode(nsDependentCString(name), newName);
|
||||
PRUnichar *str = ToNewUnicode(newName);
|
||||
if (!str) {
|
||||
CleanupArray(array, count);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
array[count++] = str;
|
||||
printers->AppendString(newName);
|
||||
}
|
||||
*aCount = count;
|
||||
*aResult = array;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
return NS_NewAdoptingStringEnumerator(aPrinterNameList, array);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
@ -118,10 +118,6 @@ public:
|
|||
~nsPrinterEnumeratorWin();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPRINTERENUMERATOR
|
||||
|
||||
private:
|
||||
// helper
|
||||
nsresult DoEnumeratePrinters(PRBool aDoExtended, PRUint32* aCount, PRUnichar*** aResult);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#include "nsIPrefService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIStringEnumerator.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "stdlib.h"
|
||||
|
@ -137,80 +137,6 @@ nsPrintOptions::Init()
|
|||
return prefService->GetBranch("print.", getter_AddRefs(mPrefBranch));
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************
|
||||
//** PageList Enumerator
|
||||
//**************************************************************
|
||||
class
|
||||
nsPrinterListEnumerator : public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
nsPrinterListEnumerator();
|
||||
virtual ~nsPrinterListEnumerator();
|
||||
|
||||
//nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//nsISimpleEnumerator interface
|
||||
NS_DECL_NSISIMPLEENUMERATOR
|
||||
|
||||
NS_IMETHOD Init();
|
||||
|
||||
protected:
|
||||
PRUnichar **mPrinters;
|
||||
PRUint32 mCount;
|
||||
PRUint32 mIndex;
|
||||
};
|
||||
|
||||
nsPrinterListEnumerator::nsPrinterListEnumerator() :
|
||||
mPrinters(nsnull), mCount(0), mIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsPrinterListEnumerator::~nsPrinterListEnumerator()
|
||||
{
|
||||
if (mPrinters)
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mCount, mPrinters);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPrinterListEnumerator, nsISimpleEnumerator)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListEnumerator::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrinterEnumerator> printerEnumerator =
|
||||
do_CreateInstance(kCPrinterEnumerator, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return printerEnumerator->EnumeratePrinters(&mCount, &mPrinters);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListEnumerator::HasMoreElements(PRBool *result)
|
||||
{
|
||||
*result = (mIndex < mCount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListEnumerator::GetNext(nsISupports **aPrinter)
|
||||
{
|
||||
NS_ENSURE_STATE(mIndex < mCount);
|
||||
|
||||
PRUnichar *printerName = mPrinters[mIndex++];
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISupportsString> printerNameWrapper =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
printerNameWrapper->SetData(nsDependentString(printerName));
|
||||
*aPrinter = NS_STATIC_CAST(nsISupports*, printerNameWrapper);
|
||||
NS_ADDREF(*aPrinter);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::ShowPrintSetupDialog(nsIPrintSettings *aPS)
|
||||
{
|
||||
|
@ -862,23 +788,6 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* create and return a new |nsPrinterListEnumerator| */
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::AvailablePrinters(nsISimpleEnumerator **aPrinterEnumerator)
|
||||
{
|
||||
nsRefPtr<nsPrinterListEnumerator> printerListEnum =
|
||||
new nsPrinterListEnumerator();
|
||||
NS_ENSURE_TRUE(printerListEnum, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*aPrinterEnumerator = printerListEnum.get());
|
||||
|
||||
nsresult rv = printerListEnum->Init();
|
||||
if (NS_FAILED(rv))
|
||||
NS_RELEASE(*aPrinterEnumerator);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::DisplayJobProperties(const PRUnichar *aPrinter,
|
||||
nsIPrintSettings* aPrintSettings,
|
||||
|
@ -962,18 +871,18 @@ nsPrintOptions::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
|
|||
ReadPrefString(kPrinterName, lastPrinterName);
|
||||
if (!lastPrinterName.IsEmpty()) {
|
||||
// Verify it's still a valid printer
|
||||
PRUnichar **printers;
|
||||
PRUint32 ctPrinters;
|
||||
rv = prtEnum->EnumeratePrinters(&ctPrinters, &printers);
|
||||
nsCOMPtr<nsIStringEnumerator> printers;
|
||||
rv = prtEnum->GetPrinterNameList(getter_AddRefs(printers));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRBool isValid = PR_FALSE;
|
||||
for (PRInt32 ii = ctPrinters - 1; ii >= 0; --ii) {
|
||||
if (lastPrinterName.Equals(printers[ii])) {
|
||||
PRBool hasMore;
|
||||
while (NS_SUCCEEDED(printers->HasMore(&hasMore)) && hasMore) {
|
||||
nsAutoString printer;
|
||||
if (NS_SUCCEEDED(printers->GetNext(printer)) && lastPrinterName.Equals(printer)) {
|
||||
isValid = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(ctPrinters, printers);
|
||||
if (isValid) {
|
||||
*aDefaultPrinterName = ToNewUnicode(lastPrinterName);
|
||||
return NS_OK;
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
|
||||
var dialog;
|
||||
var printService = null;
|
||||
var printOptions = null;
|
||||
var gOriginalNumCopies = 1;
|
||||
|
||||
var paramBlock;
|
||||
|
@ -148,49 +147,46 @@ listElement.prototype =
|
|||
appendPrinterNames:
|
||||
function (aDataObject)
|
||||
{
|
||||
var list = document.getElementById("printerList");
|
||||
var strDefaultPrinterName = "";
|
||||
var printerName;
|
||||
|
||||
// build popup menu from printer names
|
||||
while (aDataObject.hasMoreElements()) {
|
||||
printerName = aDataObject.getNext();
|
||||
printerName = printerName.QueryInterface(Components.interfaces.nsISupportsString);
|
||||
var printerNameStr = printerName.toString();
|
||||
if (strDefaultPrinterName == "")
|
||||
strDefaultPrinterName = printerNameStr;
|
||||
|
||||
list.appendItem(printerNameStr, printerNameStr, getPrinterDescription(printerNameStr));
|
||||
}
|
||||
if (strDefaultPrinterName != "") {
|
||||
this.listElement.removeAttribute("disabled");
|
||||
} else {
|
||||
if ((null == aDataObject) || !aDataObject.hasMore()) {
|
||||
// disable dialog
|
||||
var stringBundle = srGetStrBundle("chrome://global/locale/printing.properties");
|
||||
this.listElement.setAttribute("value", strDefaultPrinterName);
|
||||
this.listElement.setAttribute("value", "");
|
||||
this.listElement.setAttribute("label", stringBundle.GetStringFromName("noprinter"));
|
||||
|
||||
// disable dialog
|
||||
this.listElement.setAttribute("disabled", "true");
|
||||
dialog.printerLabel.setAttribute("disabled","true");
|
||||
dialog.propertiesButton.setAttribute("disabled","true");
|
||||
dialog.fileCheck.setAttribute("disabled","true");
|
||||
dialog.printButton.setAttribute("disabled","true");
|
||||
}
|
||||
|
||||
return strDefaultPrinterName;
|
||||
else {
|
||||
// build popup menu from printer names
|
||||
var list = document.getElementById("printerList");
|
||||
do {
|
||||
printerNameStr = aDataObject.getNext();
|
||||
list.appendItem(printerNameStr, printerNameStr, getPrinterDescription(printerNameStr));
|
||||
} while (aDataObject.hasMore());
|
||||
this.listElement.removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
function getPrinters()
|
||||
{
|
||||
var printerEnumerator = printOptions.availablePrinters();
|
||||
|
||||
var selectElement = new listElement(dialog.printerList);
|
||||
selectElement.clearList();
|
||||
var strDefaultPrinterName = selectElement.appendPrinterNames(printerEnumerator);
|
||||
|
||||
selectElement.listElement.value = strDefaultPrinterName;
|
||||
var printerEnumerator;
|
||||
try {
|
||||
printerEnumerator =
|
||||
Components.classes["@mozilla.org/gfx/printerenumerator;1"]
|
||||
.getService(Components.interfaces.nsIPrinterEnumerator)
|
||||
.printerNameList;
|
||||
} catch(e) { printerEnumerator = null; }
|
||||
|
||||
selectElement.appendPrinterNames(printerEnumerator);
|
||||
selectElement.listElement.value = printService.defaultPrinterName;
|
||||
|
||||
// make sure we load the prefs for the initially selected printer
|
||||
setPrinterDefaultsForSelectedPrinter();
|
||||
|
@ -265,12 +261,11 @@ function loadDialog()
|
|||
printService = printService.getService();
|
||||
if (printService) {
|
||||
printService = printService.QueryInterface(Components.interfaces.nsIPrintSettingsService);
|
||||
printOptions = printService.QueryInterface(Components.interfaces.nsIPrintOptions);
|
||||
}
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
// Note: getPrinters sets up the PrintToFile radio buttons and initalises gPrintSettings
|
||||
// Note: getPrinters sets up the PrintToFile control
|
||||
getPrinters();
|
||||
|
||||
if (gPrintSettings) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче