b=84947 New print dialog for Unix and OS/2

r=cls/rods/mkaply/pchen sr=roc+moz
Checking in for Roland.Mainz@informatik.med.uni-giessen.de
This commit is contained in:
kaie%netscape.com 2001-11-22 10:00:44 +00:00
parent 807c799353
commit 3e80341582
48 changed files with 2454 additions and 597 deletions

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Don Cone <dcone@netscape.com>
* Jessica Blanco <jblanco@us.ibm.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -45,6 +46,8 @@
#include "nsFont.h"
%}
interface nsISimpleEnumerator;
/**
* Native types
*/
@ -171,6 +174,8 @@ interface nsIPrintOptions : nsISupports
attribute long paperSize; /* see page size consts */
attribute long orientation; /* see orientation consts */
attribute wstring printCommand;
attribute long numCopies;
attribute wstring printer;
attribute boolean printToFile;
attribute wstring toFileName;
@ -188,6 +193,15 @@ interface nsIPrintOptions : nsISupports
/* Purposely made this an "in" arg */
[noscript] void GetDefaultFont(in nsNativeFontRef aMargin);
/**
* available Printers
*/
nsISimpleEnumerator availablePrinters ();
/**
* display Printer Job Properties dialog
*/
void displayJobProperties (in wstring aPrinter, out boolean aDisplayed);
/**
* Native data constants
@ -195,5 +209,23 @@ interface nsIPrintOptions : nsISupports
const short kNativeDataPrintRecord = 0;
[noscript] voidPtr GetNativeData(in short aDataType);
};
[scriptable, uuid(a6cf9128-15b3-11d2-932e-00805f8add32)]
interface nsIPrinterEnumerator : nsISupports
{
/**
* Return an array of the names of all installed printers.
*
* @param aCount returns number of printers returned
* @param aResult returns array of names
* @return void
*/
void enumeratePrinters(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult);
/* takes printer selected and will display job properties dlg for that printer
* returns true if dialog displays
*/
void displayPropertiesDlg(in wstring aPrinter);
};

View File

@ -103,5 +103,8 @@
{ 0x30a3b080, 0x4867, 0x11d4, \
{ 0xa8, 0x56, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } }
#define NS_PRINTER_ENUMERATOR_CID \
{ 0xa6cf9129, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
#endif

View File

@ -72,6 +72,13 @@ ifneq (gtk,$(MOZ_GFX_TOOLKIT))
INACTIVE_COMPONENT = 1
endif
ifdef MOZ_ENABLE_XPRINT
XPU_LCSRCS = xprintutil.c
CSRCS += $(XPU_LCSRCS)
endif
GARBAGE += $(XPU_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS)
@ -105,7 +112,9 @@ endif
endif
ifdef MOZ_ENABLE_XPRINT
DEFINES += -DUSE_XPRINT
DEFINES += -DUSE_XPRINT -DUSE_MOZILLA_TYPES
INCLUDES += -I$(srcdir)/../xprint
EXTRA_DSO_LDOPTS += $(MOZ_XPRINT_LDFLAGS)
endif
LOCAL_INCLUDES = \
@ -113,3 +122,6 @@ LOCAL_INCLUDES = \
-I$(srcdir)/.. \
$(NULL)
export:: $(addprefix $(srcdir)/../xprint/,$(XPU_LCSRCS))
$(INSTALL) $^ .

View File

@ -42,6 +42,7 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
#include "nsReadableUtils.h"
#include "nsGfxCIID.h"
#include "nsIPref.h"
@ -54,8 +55,15 @@
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
#ifdef USE_XPRINT
#include "xprintutil.h"
#endif /* USE_XPRINT */
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
nsStringArray* nsDeviceContextSpecGTK::globalPrinterList = nsnull;
int nsDeviceContextSpecGTK::globalNumPrinters = 0;
/** -------------------------------------------------------
* Construct the nsDeviceContextSpecGTK
* @update dc 12/02/98
@ -79,10 +87,6 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
static NS_DEFINE_IID(kIDeviceContextSpecXPIID, NS_IDEVICE_CONTEXT_SPEC_XP_IID);
#endif
#if 0
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK, nsIDeviceContextSpec)
#endif
NS_IMETHODIMP nsDeviceContextSpecGTK :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
@ -131,6 +135,84 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: QueryInterface(REFNSIID aIID, void** aIn
NS_IMPL_ADDREF(nsDeviceContextSpecGTK)
NS_IMPL_RELEASE(nsDeviceContextSpecGTK)
int nsDeviceContextSpecGTK::InitializeGlobalPrinters ()
{
globalNumPrinters = 0;
globalPrinterList = new nsStringArray();
if (!globalPrinterList)
return NS_ERROR_OUT_OF_MEMORY;
#ifdef USE_XPRINT
XPPrinterList plist = XpuGetPrinterList(nsnull, &globalNumPrinters);
if (plist && (globalNumPrinters > 0))
{
int i;
for( i = 0 ; i < globalNumPrinters ; i++ )
{
globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name)));
}
XpuFreePrinterList(plist);
}
#endif /* USE_XPRINT */
/* add an entry for the default printer (see nsPostScriptObj.cpp) */
globalPrinterList->AppendString(
nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default")));
globalNumPrinters++;
/* get the list of printers */
char *printerList = nsnull;
/* the env var MOZILLA_PRINTER_LIST can "override" the prefs */
printerList = PR_GetEnv("MOZILLA_PRINTER_LIST");
if (!printerList) {
nsresult rv;
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->CopyCharPref("print.printer_list", &printerList);
}
}
if (printerList) {
char *tok_lasts;
char *name;
/* PL_strtok_r() will modify the string - copy it! */
printerList = strdup(printerList);
if (!printerList)
return NS_ERROR_OUT_OF_MEMORY;
for( name = PL_strtok_r(printerList, " ", &tok_lasts) ;
name != nsnull ;
name = PL_strtok_r(nsnull, " ", &tok_lasts) )
{
globalPrinterList->AppendString(
nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) +
nsString(NS_ConvertASCIItoUCS2(name)));
globalNumPrinters++;
}
free(printerList);
}
if (globalNumPrinters == 0)
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
return NS_OK;
}
void nsDeviceContextSpecGTK::FreeGlobalPrinters()
{
delete globalPrinterList;
globalPrinterList = nsnull;
globalNumPrinters = 0;
}
/** -------------------------------------------------------
* Initialize the nsDeviceContextSpecGTK
* @update dc 2/15/98
@ -162,7 +244,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
PRBool isOn;
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
}
}
@ -178,13 +260,21 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRInt32 copies = 1;
PRUnichar *printer = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
if (PR_FALSE == aQuiet ) {
if( !globalPrinterList )
if (InitializeGlobalPrinters())
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
if( globalNumPrinters && !globalPrinterList->Count() )
return NS_ERROR_OUT_OF_MEMORY;
if (!aQuiet ) {
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
@ -198,13 +288,9 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindowInternal> parent;
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
if (active) {
active->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(parent));
}
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul",
@ -226,9 +312,12 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
else {
canPrint = PR_TRUE;
}
FreeGlobalPrinters();
if (canPrint) {
if (printService) {
printService->GetPrinter(&printer);
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
@ -239,6 +328,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
printService->GetPrintToFile(&tofile);
printService->GetStartPageRange(&fromPage);
printService->GetEndPageRange(&toPage);
printService->GetNumCopies(&copies);
printService->GetMarginTop(&dtop);
printService->GetMarginLeft(&dleft);
printService->GetMarginBottom(&dbottom);
@ -249,6 +339,8 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get());
strcpy(mPrData.path, NS_ConvertUCS2toUTF8(printfile).get());
}
if (printer != nsnull)
strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get());
#ifdef DEBUG_rods
printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright);
printf("printRange %d\n", printRange);
@ -261,7 +353,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
// as I need to make the default be "print" instead of "lpr" for OpenVMS.
strcpy(mPrData.command, "print");
#else
strcpy(mPrData.command, "lpr");
strcpy(mPrData.command, "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}");
#endif /* VMS */
}
@ -274,6 +366,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
mPrData.size = paper_size;
mPrData.orientation = orientation;
mPrData.toPrinter = !tofile;
mPrData.copies = copies;
// PWD, HOME, or fail
@ -287,6 +380,16 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
else
return NS_ERROR_FAILURE;
}
#ifdef NOT_IMPLEMENTED_YET
if (globalNumPrinters) {
for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) {
if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1)))
mQueue = PrnDlg.SetPrinterQueue(i);
}
}
#endif /* NOT_IMPLEMENTED_YET */
if (command != nsnull) {
nsMemory::Free(command);
}
@ -300,12 +403,24 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
return rv;
}
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetToPrinter( PRBool &aToPrinter )
NS_IMETHODIMP nsDeviceContextSpecGTK::GetToPrinter(PRBool &aToPrinter)
{
aToPrinter = mPrData.toPrinter;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinter ( char **aPrinter )
{
*aPrinter = &mPrData.printer[0];
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK::GetCopies ( int &aCopies )
{
aCopies = mPrData.copies;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetFirstPageFirst ( PRBool &aFpf )
{
aFpf = mPrData.fpf;
@ -404,26 +519,107 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetUserCancelled( PRBool &aCancel )
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrintMethod(PrintMethod &aMethod)
{
nsresult rv;
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
PRInt32 method = (PRInt32)pmAuto;
(void) pPrefs->GetIntPref("print.print_method", &method);
aMethod = (PrintMethod)method;
if (aMethod == pmAuto)
aMethod = NS_DEFAULT_PRINT_METHOD;
} else {
aMethod = NS_DEFAULT_PRINT_METHOD;
}
/* printer names for the PostScript module alwas start with
* the NS_POSTSCRIPT_DRIVER_NAME string */
if (strncmp(mPrData.printer, NS_POSTSCRIPT_DRIVER_NAME,
NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0)
aMethod = pmXprint;
else
aMethod = pmPostScript;
return NS_OK;
}
/** -------------------------------------------------------
* Closes the printmanager if it is open.
* @update dc 2/15/98
*/
NS_IMETHODIMP nsDeviceContextSpecGTK :: ClosePrintManager()
NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager()
{
return NS_OK;
}
// Printer Enumerator
nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
{
NS_INIT_REFCNT();
}
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator)
NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
{
if (aCount)
*aCount = 0;
else
return NS_ERROR_NULL_POINTER;
if (aResult)
*aResult = nsnull;
else
return NS_ERROR_NULL_POINTER;
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecGTK::globalNumPrinters * sizeof(PRUnichar*));
if (!array && nsDeviceContextSpecGTK::globalNumPrinters)
return NS_ERROR_OUT_OF_MEMORY;
int count = 0;
while( count < nsDeviceContextSpecGTK::globalNumPrinters )
{
PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecGTK::globalPrinterList->StringAt(count));
if (!str) {
for (int i = count - 1; i >= 0; i--)
nsMemory::Free(array[i]);
nsMemory::Free(array);
return NS_ERROR_OUT_OF_MEMORY;
}
array[count++] = str;
}
*aCount = count;
*aResult = array;
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter)
{
nsresult rv = NS_ERROR_FAILURE;
/* fixme: We simply ignore the |aPrinter| argument here
* We should get the supported printer attributes from the printer and
* populate the print job options dialog with these data instead of using
* the "default set" here.
* However, this requires changes on all platforms and is another big chunk
* of patches ... ;-(
*/
nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv));
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
if (ioParamBlock)
paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
if (paramBlockWrapper) {
paramBlockWrapper->SetData(ioParamBlock);
paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock));
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions.xul",
"_blank", "chrome,modal", paramBlockWrapper,
getter_AddRefs(newWindow));
}
}
return rv;
}

View File

@ -41,7 +41,8 @@
#define nsDeviceContextSpecG_h___
#include "nsIDeviceContextSpec.h"
#include "nsDeviceContextSpecG.h"
#include "nsIPrintOptions.h"
#include "nsVoidArray.h"
#include "nsIDeviceContextSpecPS.h"
#ifdef USE_XPRINT
#include "nsIDeviceContextSpecXPrint.h"
@ -50,17 +51,11 @@
typedef enum
{
pmAuto = 0, /* default */
pmInvalid = 0,
pmXprint,
pmPostScript
} PrintMethod;
/* make Xprint the default print system if user/admin has set the XPSERVERLIST"
* env var. See Xprt config README (/usr/openwin/server/etc/XpConfig/README)
* for details.
*/
#define NS_DEFAULT_PRINT_METHOD ((PR_GetEnv("XPSERVERLIST")!=nsnull)?(pmXprint):(pmPostScript))
class nsDeviceContextSpecGTK : public nsIDeviceContextSpec ,
public nsIDeviceContextSpecPS
#ifdef USE_XPRINT
@ -100,6 +95,10 @@ public:
NS_IMETHOD GetToPrinter( PRBool &aToPrinter );
NS_IMETHOD GetPrinter ( char **aPrinter );
NS_IMETHOD GetCopies ( int &aCopies );
NS_IMETHOD GetFirstPageFirst ( PRBool &aFpf );
NS_IMETHOD GetGrayscale( PRBool &aGrayscale );
@ -125,17 +124,33 @@ public:
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod );
protected:
/**
* Destuct a nsDeviceContextSpecMac, this will release the printrecord
* @update dc 2/16/98
*/
virtual ~nsDeviceContextSpecGTK();
static nsStringArray *globalPrinterList;
static int globalNumPrinters;
int InitializeGlobalPrinters();
void FreeGlobalPrinters();
protected:
UnixPrData mPrData;
};
#endif
//-------------------------------------------------------------------------
// Printer Enumerator
//-------------------------------------------------------------------------
class nsPrinterEnumeratorGTK : public nsIPrinterEnumerator
{
public:
nsPrinterEnumeratorGTK();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTERENUMERATOR
protected:
};
#endif /* !nsDeviceContextSpecG_h___ */

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Christopher Blizzzard <blizzard@mozilla.org>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -73,6 +74,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
// our custom constructors
@ -182,7 +184,12 @@ static nsModuleComponentInfo components[] =
NS_SCREENMANAGER_CID,
// "@mozilla.org/gfx/screenmanager/gtk;1",
"@mozilla.org/gfx/screenmanager;1",
nsScreenManagerGtkConstructor }
nsScreenManagerGtkConstructor },
{ "Gtk Printer Enumerator",
NS_PRINTER_ENUMERATOR_CID,
// "@mozilla.org/gfx/printer_enumerator/gtk;1",
"@mozilla.org/gfx/printerenumerator;1",
nsPrinterEnumeratorGTKConstructor }
};
PR_STATIC_CALLBACK(void)

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -75,6 +76,8 @@ typedef struct unixprdata {
int orientation; /* Orientation e.g. Portrait */
char command[ PATH_MAX ]; /* Print command e.g., lpr */
char path[ PATH_MAX ]; /* If toPrinter = PR_FALSE, dest file */
char printer[256]; /* Printer name */
int copies; /* number of copies */
PRBool cancel; /* If PR_TRUE, user cancelled */
float left; /* left margin */
float right; /* right margin */
@ -86,4 +89,5 @@ void UnixPrDialog(UnixPrData *prData);
PR_END_EXTERN_C
#endif /* nsPrintdGTK_h___ */
#endif /* !nsPrintdGTK_h___ */

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jessica Blanco <jblanco@us.ibm.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -45,6 +46,12 @@
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsISimpleEnumerator.h"
#include "nsISupportsPrimitives.h"
#include "nsGfxCIID.h"
static NS_DEFINE_IID(kCPrinterEnumerator, NS_PRINTER_ENUMERATOR_CID);
NS_IMPL_ISUPPORTS1(nsPrintOptions, nsIPrintOptions)
// Pref Constants
@ -69,6 +76,7 @@ const char kPrintColor[] = "print.print_color";
const char kPrintPaperSize[] = "print.print_paper_size";
const char kPrintOrientation[]= "print.print_orientation";
const char kPrintCommand[] = "print.print_command";
const char kPrinter[] = "print.print_printer";
const char kPrintFile[] = "print.print_file";
const char kPrintToFile[] = "print.print_tofile";
const char kPrintPageDelay[] = "print.print_pagedelay";
@ -95,6 +103,7 @@ nsPrintOptions::nsPrintOptions() :
mPrintRange(kRangeAllPages),
mStartPageNum(1),
mEndPageNum(1),
mNumCopies(1),
mPrintFrameType(kFramesAsIs),
mHowToEnableFrameUI(kFrameEnableNone),
mIsCancelled(PR_FALSE),
@ -141,6 +150,88 @@ nsPrintOptions::~nsPrintOptions()
}
}
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)
{
NS_INIT_REFCNT();
}
nsPrinterListEnumerator::~nsPrinterListEnumerator()
{
if (mPrinters) {
PRUint32 i;
for (i = 0; i < mCount; i++ ) {
nsMemory::Free(mPrinters[i]);
}
nsMemory::Free(mPrinters);
}
}
NS_IMPL_ISUPPORTS1(nsPrinterListEnumerator, nsISimpleEnumerator)
NS_IMETHODIMP nsPrinterListEnumerator::Init( )
{
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> printerEnumerator;
printerEnumerator = do_CreateInstance(kCPrinterEnumerator, &rv);
if (NS_FAILED(rv))
return rv;
rv = printerEnumerator->EnumeratePrinters(&mCount, &mPrinters);
return rv;
}
NS_IMETHODIMP nsPrinterListEnumerator::HasMoreElements(PRBool *result)
{
*result = (mIndex < mCount);
return NS_OK;
}
NS_IMETHODIMP nsPrinterListEnumerator::GetNext(nsISupports **aPrinter)
{
NS_ENSURE_ARG_POINTER(aPrinter);
*aPrinter = nsnull;
if (mIndex >= mCount) {
return NS_ERROR_UNEXPECTED;
}
PRUnichar *printerName = mPrinters[mIndex++];
nsCOMPtr<nsISupportsWString> printerNameWrapper;
nsresult rv;
rv = nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID, nsnull,
NS_GET_IID(nsISupportsWString), getter_AddRefs(printerNameWrapper));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(printerNameWrapper, NS_ERROR_OUT_OF_MEMORY);
printerNameWrapper->SetData(NS_CONST_CAST(PRUnichar*, printerName));
*aPrinter = NS_STATIC_CAST(nsISupports*, printerNameWrapper);
NS_ADDREF(*aPrinter);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
@ -283,6 +374,7 @@ nsPrintOptions::ReadPrefs()
prefs->GetIntPref(kPrintPaperSize, &mPaperSize);
prefs->GetIntPref(kPrintOrientation, &mOrientation);
ReadPrefString(prefs, kPrintCommand, mPrintCommand);
ReadPrefString(prefs, kPrinter, mPrinter);
prefs->GetBoolPref(kPrintFile, &mPrintToFile);
ReadPrefString(prefs, kPrintToFile, mToFileName);
prefs->GetIntPref(kPrintPageDelay, &mPrintPageDelay);
@ -322,6 +414,7 @@ nsPrintOptions::WritePrefs()
prefs->SetIntPref(kPrintPaperSize, mPaperSize);
prefs->SetIntPref(kPrintOrientation, mOrientation);
WritePrefString(prefs, kPrintCommand, mPrintCommand);
WritePrefString(prefs, kPrinter, mPrinter);
prefs->SetBoolPref(kPrintFile, mPrintToFile);
WritePrefString(prefs, kPrintToFile, mToFileName);
prefs->SetIntPref(kPrintPageDelay, mPrintPageDelay);
@ -396,6 +489,19 @@ NS_IMETHODIMP nsPrintOptions::SetPaperSize(PRInt32 aPaperSize)
return NS_OK;
}
/* attribute wstring printCommand; */
NS_IMETHODIMP nsPrintOptions::GetPrintCommand(PRUnichar * *aPrintCommand)
{
//NS_ENSURE_ARG_POINTER(aPrintCommand);
*aPrintCommand = ToNewUnicode(mPrintCommand);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintCommand(const PRUnichar * aPrintCommand)
{
mPrintCommand = aPrintCommand;
return NS_OK;
}
/* attribute short orientation; */
NS_IMETHODIMP nsPrintOptions::GetOrientation(PRInt32 *aOrientation)
{
@ -409,19 +515,68 @@ NS_IMETHODIMP nsPrintOptions::SetOrientation(PRInt32 aOrientation)
return NS_OK;
}
/* attribute wstring printCommand; */
NS_IMETHODIMP nsPrintOptions::GetPrintCommand(PRUnichar * *aPrintCommand)
/* attribute wstring printer; */
NS_IMETHODIMP nsPrintOptions::GetPrinter(PRUnichar * *aPrinter)
{
//NS_ENSURE_ARG_POINTER(aPrintCommand);
*aPrintCommand = ToNewUnicode(mPrintCommand);
//NS_ENSURE_ARG_POINTER(aPrinter);
*aPrinter = ToNewUnicode(mPrinter);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrinter(const PRUnichar * aPrinter)
{
mPrinter = aPrinter;
return NS_OK;
}
/* attribute long numCopies; */
NS_IMETHODIMP nsPrintOptions::GetNumCopies(PRInt32 *aNumCopies)
{
//NS_ENSURE_ARG_POINTER(aNumCopies);
*aNumCopies = mNumCopies;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintCommand(const PRUnichar * aPrintCommand)
NS_IMETHODIMP nsPrintOptions::SetNumCopies(PRInt32 aNumCopies)
{
mPrintCommand = aPrintCommand;
mNumCopies = aNumCopies;
return NS_OK;
}
/* create and return a new |nsPrinterListEnumerator| */
NS_IMETHODIMP nsPrintOptions::AvailablePrinters( nsISimpleEnumerator **aPrinterEnumerator)
{
NS_ENSURE_ARG_POINTER(aPrinterEnumerator);
nsCOMPtr<nsPrinterListEnumerator> printerListEnum = new nsPrinterListEnumerator();
NS_ENSURE_TRUE(printerListEnum.get(), NS_ERROR_OUT_OF_MEMORY);
nsresult rv = printerListEnum->Init();
NS_ENSURE_SUCCESS(rv, rv);
*aPrinterEnumerator = NS_STATIC_CAST(nsISimpleEnumerator*, printerListEnum);
NS_ADDREF(*aPrinterEnumerator);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::DisplayJobProperties( const PRUnichar *aPrinter, PRBool *aDisplayed)
{
NS_ENSURE_ARG(aPrinter);
*aDisplayed = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIPrinterEnumerator> propDlg;
propDlg = do_CreateInstance(kCPrinterEnumerator, &rv);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(propDlg->DisplayPropertiesDlg((PRUnichar*)aPrinter)))
return rv;
*aDisplayed = PR_TRUE;
return NS_OK;
}
/* attribute boolean printToFile; */
NS_IMETHODIMP nsPrintOptions::GetPrintToFile(PRBool *aPrintToFile)
{

View File

@ -18,13 +18,13 @@
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jessica Blanco <jblanco@us.ibm.com>
*/
#ifndef nsPrintOptionsImpl_h__
#define nsPrintOptionsImpl_h__
#include "nsIPrintOptions.h"
class nsIPref;
class nsIPrintSettings;
@ -85,6 +85,8 @@ protected:
PRInt32 mPaperSize; // see page size consts
PRInt32 mOrientation; // see orientation consts
nsString mPrintCommand;
PRInt32 mNumCopies;
nsString mPrinter;
PRBool mPrintToFile;
nsString mToFileName;

View File

@ -35,21 +35,23 @@ MODULE_NAME = nsGfxOS2Module
REQUIRES = xpcom \
string \
widget \
view \
util \
dom \
pref \
uconv \
windowwatcher \
locale \
$(NULL)
DIRS = res
CPPSRCS = \
libprint.cpp \
nsDeviceContextSpecOS2.cpp \
nsDeviceContextOS2.cpp \
nsDrawingSurfaceOS2.cpp \
nsRenderingContextOS2.cpp \
nsFontMetricsOS2.cpp \
nsImageOS2.cpp \
nsRegionOS2.cpp \
nsDeviceContextSpecOS2.cpp \
nsDeviceContextSpecFactoryO.cpp \
nsScreenOS2.cpp \
nsScreenManagerOS2.cpp \
@ -58,8 +60,6 @@ CPPSRCS = \
nsGfxDefs.cpp \
$(NULL)
RES_FILE = $(srcdir)/libprint.res
EXPORTS = \
nsIRenderingContextOS2.h \
$(NULL)

View File

@ -73,12 +73,6 @@ nsDeviceContextOS2 :: nsDeviceContextOS2()
mPrintState = nsPrintState_ePreBeginDoc;
#endif
#ifdef XP_OS2 // OS2TODO - GET RID OF THIS!
// Init module if necessary
if( !gGfxModuleData.hpsScreen)
gGfxModuleData.Init();
#endif
// The first time in we initialize gIsWarp4 flag
if (NOT_SETUP == gIsWarp4) {
unsigned long ulValues[2];
@ -823,13 +817,21 @@ NS_IMETHODIMP nsDeviceContextOS2 :: GetDeviceContextFor(nsIDeviceContextSpec *aD
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
((nsDeviceContextOS2 *)aContext)->mSpec = aDevice;
NS_ADDREF(aDevice);
int numCopies = 0;
int toPrinter = 0;
char *file = nsnull;
((nsDeviceContextSpecOS2 *)aDevice)->GetPRTQUEUE(pq);
((nsDeviceContextSpecOS2 *)aDevice)->GetCopies(numCopies);
((nsDeviceContextSpecOS2 *)aDevice)->GetToPrinter(toPrinter);
if (!toPrinter)
((nsDeviceContextSpecOS2 *)aDevice)->GetPath(&file);
HDC dc = PrnOpenDC(pq, "Mozilla");
HDC dc = PrnOpenDC(pq, "Mozilla", numCopies, toPrinter, file);
if (!dc) {
PMERROR("DevOpenDC");

View File

@ -43,7 +43,7 @@
#include "nsDeviceContext.h"
#include "nsIScreenManager.h"
#include "libprint.h"
#include "nsDeviceContextSpecOS2.h"
class nsIScreen;

View File

@ -40,9 +40,6 @@
#include "nsDeviceContextSpecFactoryO.h"
#include "nsDeviceContextSpecOS2.h"
#define INCL_DEV
#include <os2.h>
#include "libprint.h"
#include "nsGfxCIID.h"
nsDeviceContextSpecFactoryOS2 :: nsDeviceContextSpecFactoryOS2()
@ -54,10 +51,7 @@ nsDeviceContextSpecFactoryOS2 :: ~nsDeviceContextSpecFactoryOS2()
{
}
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryOS2, nsIDeviceContextSpecFactory)
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryOS2, nsIDeviceContextSpecFactory);
NS_IMETHODIMP nsDeviceContextSpecFactoryOS2 :: Init(void)
{
@ -70,30 +64,16 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryOS2 :: CreateDeviceContextSpec(nsIWidget
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
{
nsresult rv = NS_ERROR_FAILURE;
PRINTDLG PrnDlg;
nsresult rv;
static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
nsCOMPtr<nsIDeviceContextSpec> devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv);
PRTQUEUE* pq = PrnDlg.SelectPrinter (HWND_DESKTOP, aQuiet ? TRUE : FALSE);
if( pq)
{
nsIDeviceContextSpec *devspec = nsnull;
nsComponentManager::CreateInstance(kDeviceContextSpecCID, nsnull, kIDeviceContextSpecIID, (void **)&devspec);
if (nsnull != devspec)
{
//XXX need to QI rather than cast... MMP
if (NS_OK == ((nsDeviceContextSpecOS2 *)devspec)->Init(pq))
{
aNewSpec = devspec;
rv = NS_OK;
}
}
} else {
// Cancel was pressed
rv = NS_ERROR_ABORT;
}
return rv;
if (NS_SUCCEEDED(rv)) {
rv = ((nsDeviceContextSpecOS2 *)devSpec.get())->Init(aQuiet);
if (NS_SUCCEEDED(rv)) {
aNewSpec = devSpec;
NS_ADDREF(aNewSpec);
}
}
return rv;
}

View File

@ -20,33 +20,724 @@
*
*/
#include "nsGfxDefs.h"
#include "libprint.h"
#include "nsDeviceContextSpecOS2.h"
nsDeviceContextSpecOS2::nsDeviceContextSpecOS2()
{
NS_INIT_REFCNT();
mQueue = nsnull;
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsGfxDefs.h"
#include "nsReadableUtils.h"
#include "nsIPref.h"
#include "prenv.h" /* for PR_GetEnv */
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsIDialogParamBlock.h"
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
nsStringArray* nsDeviceContextSpecOS2::globalPrinterList = nsnull;
int nsDeviceContextSpecOS2::globalNumPrinters = 0;
PRINTDLG nsDeviceContextSpecOS2::PrnDlg;
/** -------------------------------------------------------
* Construct the nsDeviceContextSpecOS2
* @update dc 12/02/98
*/
nsDeviceContextSpecOS2 :: nsDeviceContextSpecOS2()
{
NS_INIT_REFCNT();
mQueue = nsnull;
}
nsDeviceContextSpecOS2::~nsDeviceContextSpecOS2()
/** -------------------------------------------------------
* Destroy the nsDeviceContextSpecOS2
* @update dc 2/15/98
*/
nsDeviceContextSpecOS2 :: ~nsDeviceContextSpecOS2()
{
if( mQueue)
PrnClosePrinter( mQueue);
}
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecOS2, nsIDeviceContextSpec)
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
#ifdef USE_XPRINT
static NS_DEFINE_IID(kIDeviceContextSpecXPIID, NS_IDEVICE_CONTEXT_SPEC_XP_IID);
#endif
nsresult nsDeviceContextSpecOS2::Init( PRTQUEUE *pq)
NS_IMETHODIMP nsDeviceContextSpecOS2 :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
mQueue = pq;
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIDeviceContextSpecIID))
{
nsIDeviceContextSpec* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
#ifdef USE_XPRINT
if (aIID.Equals(kIDeviceContextSpecXPIID))
{
nsIDeviceContextSpecXp *tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
#endif /* USE_XPRINT */
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
{
nsIDeviceContextSpec* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDeviceContextSpecOS2)
NS_IMPL_RELEASE(nsDeviceContextSpecOS2)
int nsDeviceContextSpecOS2::InitializeGlobalPrinters ()
{
globalNumPrinters = PrnDlg.GetNumPrinters();
if (!globalNumPrinters)
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
globalPrinterList = new nsStringArray();
if (!globalPrinterList)
return NS_ERROR_OUT_OF_MEMORY;
int defaultPrinter = PrnDlg.GetDefaultPrinter();
for (int i = 0; i < globalNumPrinters; i++) {
char *printer = PrnDlg.GetPrinter(i);
if ( defaultPrinter == i )
globalPrinterList->InsertStringAt(nsString(NS_ConvertASCIItoUCS2(printer)), 0);
else
globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(printer)));
}
return NS_OK;
}
void nsDeviceContextSpecOS2::FreeGlobalPrinters ()
{
delete globalPrinterList;
globalPrinterList = nsnull;
globalNumPrinters = 0;
}
/** -------------------------------------------------------
* Initialize the nsDeviceContextSpecOS2
* @update dc 2/15/98
* @update syd 3/2/99
*
* gisburn: Please note that this function exists as 1:1 copy in other
* toolkits including:
* - GTK+-toolkit:
* file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
* - Xlib-toolkit:
* file: mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
* - Qt-toolkit:
* file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
*
* ** Please update the other toolkits when changing this function.
*/
NS_IMETHODIMP nsDeviceContextSpecOS2::Init(PRBool aQuiet)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv));
NS_ASSERTION(nsnull != printService, "No print service.");
// if there is a current selection then enable the "Selection" radio button
if (NS_SUCCEEDED(rv) && printService) {
PRBool isOn;
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
}
}
char *path;
PRBool canPrint = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintOptions::kRangeAllPages;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRInt32 copies = 1;
PRUnichar *printer = nsnull;
PRUnichar *printfile = nsnull;
if( !globalPrinterList )
if (InitializeGlobalPrinters())
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
if( globalNumPrinters && !globalPrinterList->Count() )
return NS_ERROR_OUT_OF_MEMORY;
if ( !aQuiet ) {
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
if (ioParamBlock)
paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
if (paramBlockWrapper) {
paramBlockWrapper->SetData(ioParamBlock);
paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock));
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul",
"_blank", "chrome,modal", paramBlockWrapper,
getter_AddRefs(newWindow));
}
}
if (NS_SUCCEEDED(rv)) {
PRInt32 buttonPressed = 0;
ioParamBlock->GetInt(0, &buttonPressed);
if (buttonPressed == 0)
canPrint = PR_TRUE;
else
{
FreeGlobalPrinters();
return NS_ERROR_ABORT;
}
}
} else {
canPrint = PR_TRUE;
}
if (canPrint) {
if (printService) {
printService->GetPrinter(&printer);
printService->GetPrintRange(&printRange);
printService->GetToFileName(&printfile);
printService->GetPrintToFile(&tofile);
printService->GetStartPageRange(&fromPage);
printService->GetEndPageRange(&toPage);
printService->GetNumCopies(&copies);
if ((copies == 0) || (copies > 999)) {
FreeGlobalPrinters();
return NS_ERROR_FAILURE;
}
if (printfile != nsnull) {
// ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446)
strcpy(mPrData.path, NS_ConvertUCS2toUTF8(printfile).get());
}
if (printer != nsnull)
strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get());
}
mPrData.toPrinter = !tofile;
mPrData.copies = copies;
if (globalNumPrinters) {
for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) {
if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1)))
mQueue = PrnDlg.SetPrinterQueue(i);
}
}
if (printfile != nsnull)
nsMemory::Free(printfile);
if (printer != nsnull)
nsMemory::Free(printer);
FreeGlobalPrinters();
return NS_OK;
}
FreeGlobalPrinters();
return rv;
}
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetToPrinter( PRBool &aToPrinter )
{
aToPrinter = mPrData.toPrinter;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetPrinter ( char **aPrinter )
{
*aPrinter = &mPrData.printer[0];
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetCopies ( int &aCopies )
{
aCopies = mPrData.copies;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetPath ( char **aPath )
{
*aPath = &mPrData.path[0];
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetUserCancelled( PRBool &aCancel )
{
aCancel = mPrData.cancel;
return NS_OK;
}
/** -------------------------------------------------------
* Closes the printmanager if it is open.
* @update dc 2/15/98
*/
NS_IMETHODIMP nsDeviceContextSpecOS2 :: ClosePrintManager()
{
return NS_OK;
}
nsresult nsDeviceContextSpecOS2::GetPRTQUEUE( PRTQUEUE *&p)
{
p = mQueue;
return NS_OK;
}
// Printer Enumerator
nsPrinterEnumeratorOS2::nsPrinterEnumeratorOS2()
{
NS_INIT_REFCNT();
}
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorOS2, nsIPrinterEnumerator)
NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
{
if (aCount)
*aCount = 0;
else
return NS_ERROR_NULL_POINTER;
if (aResult)
*aResult = nsnull;
else
return NS_ERROR_NULL_POINTER;
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecOS2::globalNumPrinters * sizeof(PRUnichar*));
if (!array && nsDeviceContextSpecOS2::globalNumPrinters)
return NS_ERROR_OUT_OF_MEMORY;
int count = 0;
while( count < nsDeviceContextSpecOS2::globalNumPrinters )
{
PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecOS2::globalPrinterList->StringAt(count));
if (!str) {
for (int i = count - 1; i >= 0; i--)
nsMemory::Free(array[i]);
nsMemory::Free(array);
return NS_ERROR_OUT_OF_MEMORY;
}
array[count++] = str;
}
*aCount = count;
*aResult = array;
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorOS2::DisplayPropertiesDlg(const PRUnichar *aPrinter)
{
for(int i = 0; i < nsDeviceContextSpecOS2::globalNumPrinters; i++) {
if (!(nsDeviceContextSpecOS2::globalPrinterList->StringAt(i)->CompareWithConversion(aPrinter, TRUE, -1))) {
if ( nsDeviceContextSpecOS2::PrnDlg.ShowProperties(i) )
return NS_OK;
else
return NS_ERROR_FAILURE;
}
}
return NS_ERROR_FAILURE;
}
//---------------------------------------------------------------------------
// OS/2 Printing - was in libprint.cpp
//---------------------------------------------------------------------------
static HMODULE hmodRes;
static BOOL prnEscape (HDC hdc, long lEscape);
#define SHIFT_PTR(ptr,offset) ( *((LONG*)&ptr) += offset )
class PRTQUEUE
{
public:
PRTQUEUE (const PRQINFO3* pPQI3) { InitWithPQI3 (pPQI3); }
PRTQUEUE (const PRTQUEUE& PQInfo);
~PRTQUEUE (void) { free (mpPQI3); }
PRQINFO3& PQI3 () const { return *mpPQI3; }
const char* DriverName () const { return mDriverName; }
const char* DeviceName () const { return mDeviceName; }
const char* PrinterName() const { return mPrinterName; }
const char* QueueName () const { return mpPQI3->pszComment; }
private:
PRTQUEUE& operator = (const PRTQUEUE& z); // prevent copying
void InitWithPQI3 (const PRQINFO3* pInfo);
PRQINFO3* mpPQI3;
unsigned mPQI3BufSize;
char mDriverName [DRIV_NAME_SIZE + 1]; // Driver name
char mDeviceName [DRIV_DEVICENAME_SIZE + 1]; // Device name
char mPrinterName [PRINTERNAME_SIZE + 1]; // Printer name
};
PRTQUEUE::PRTQUEUE (const PRTQUEUE& PQInfo)
{
mPQI3BufSize = PQInfo.mPQI3BufSize;
mpPQI3 = (PRQINFO3*)malloc (mPQI3BufSize);
memcpy (mpPQI3, PQInfo.mpPQI3, mPQI3BufSize); // Copy entire buffer
long Diff = (long)mpPQI3 - (long)PQInfo.mpPQI3; // Calculate the difference between addresses
SHIFT_PTR (mpPQI3->pszName, Diff); // Modify internal pointers accordingly
SHIFT_PTR (mpPQI3->pszSepFile, Diff);
SHIFT_PTR (mpPQI3->pszPrProc, Diff);
SHIFT_PTR (mpPQI3->pszParms, Diff);
SHIFT_PTR (mpPQI3->pszComment, Diff);
SHIFT_PTR (mpPQI3->pszPrinters, Diff);
SHIFT_PTR (mpPQI3->pszDriverName, Diff);
SHIFT_PTR (mpPQI3->pDriverData, Diff);
strcpy (mDriverName, PQInfo.mDriverName);
strcpy (mDeviceName, PQInfo.mDeviceName);
strcpy (mPrinterName, PQInfo.mPrinterName);
}
void PRTQUEUE::InitWithPQI3 (const PRQINFO3* pInfo)
{
// Make local copy of PPRQINFO3 object
ULONG SizeNeeded;
::SplQueryQueue (NULL, pInfo->pszName, 3, NULL, 0, &SizeNeeded);
mpPQI3 = (PRQINFO3*)malloc (SizeNeeded);
::SplQueryQueue (NULL, pInfo->pszName, 3, mpPQI3, SizeNeeded, &SizeNeeded);
mPQI3BufSize = SizeNeeded;
PCHAR sep = strchr (pInfo->pszDriverName, '.');
if (sep)
{
*sep = '\0';
strcpy (mDriverName, pInfo->pszDriverName);
strcpy (mDeviceName, sep + 1);
*sep = '.';
} else
{
strcpy (mDriverName, pInfo->pszDriverName);
mDeviceName [0] = '\0';
}
sep = strchr (pInfo->pszPrinters, ',');
if (sep)
{
*sep = '\0';
strcpy (mPrinterName, pInfo->pszPrinters);
*sep = '.';
} else
{
strcpy (mPrinterName, pInfo->pszPrinters);
}
}
//===========================================================================
PRINTDLG::PRINTDLG ()
{
mQueueCount = 0;
mDefaultQueue = 0;
ULONG TotalQueues = 0;
ULONG MemNeeded = 0;
SPLERR rc;
rc = ::SplEnumQueue (NULL, 3, NULL, 0, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded);
rc = ::SplEnumQueue (NULL, 3, pPQI3Buf, MemNeeded, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
if (mQueueCount > MAX_PRINT_QUEUES)
mQueueCount = MAX_PRINT_QUEUES;
for (ULONG cnt = 0 ; cnt < mQueueCount ; cnt++)
{
if (pPQI3Buf [cnt].fsType & PRQ3_TYPE_APPDEFAULT)
mDefaultQueue = cnt;
mPQBuf [cnt] = new PRTQUEUE (&pPQI3Buf [cnt]);
}
free (pPQI3Buf);
}
PRINTDLG::~PRINTDLG ()
{
for (int cnt = 0 ; cnt < mQueueCount ; cnt++)
delete mPQBuf [cnt];
}
int PRINTDLG::GetIndex (int numPrinter)
{
int index;
if (numPrinter == 0)
index = mDefaultQueue;
else if (numPrinter > mDefaultQueue)
index = numPrinter;
else
index = numPrinter - 1;
return index;
}
int PRINTDLG::GetNumPrinters ()
{
return mQueueCount;
}
int PRINTDLG::GetDefaultPrinter ()
{
return mDefaultQueue;
}
char* PRINTDLG::GetPrinter (int numPrinter)
{
const char* pq = NULL;
if (numPrinter > mQueueCount)
return NULL;
pq = mPQBuf [numPrinter]->PQI3().pszDriverName;
return (char *)pq;
}
PRTQUEUE* PRINTDLG::SetPrinterQueue (int numPrinter)
{
PRTQUEUE *pPQ = NULL;
if (numPrinter > mQueueCount)
return NULL;
pPQ = mPQBuf [GetIndex(numPrinter)];
return new PRTQUEUE (*pPQ);
}
BOOL PRINTDLG::ShowProperties (int index)
{
BOOL rc = FALSE;
ULONG devrc = FALSE;
PDRIVDATA pOldDrivData;
PDRIVDATA pNewDrivData = NULL;
LONG buflen;
int Ind = GetIndex(index);
/* check size of buffer required for job properties */
buflen = DevPostDeviceModes( 0 /*hab*/,
NULL,
mPQBuf[Ind]->DriverName (),
mPQBuf[Ind]->DeviceName (),
mPQBuf[Ind]->PrinterName (),
DPDM_POSTJOBPROP);
/* return error to caller */
if (buflen <= 0)
return(buflen);
/* allocate some memory for larger job properties and */
/* return error to caller */
if (buflen != mPQBuf[Ind]->PQI3().pDriverData->cb)
{
if (DosAllocMem((PPVOID)&pNewDrivData,buflen,fALLOC))
return(DPDM_ERROR);
/* copy over old data so driver can use old job */
/* properties as base for job properties dialog */
pOldDrivData = mPQBuf[Ind]->PQI3().pDriverData;
mPQBuf[Ind]->PQI3().pDriverData = pNewDrivData;
memcpy( (PSZ)pNewDrivData, (PSZ)pOldDrivData, pOldDrivData->cb );
}
/* display job properties dialog and get updated */
/* job properties from driver */
devrc = DevPostDeviceModes( 0 /*hab*/,
mPQBuf[Ind]->PQI3().pDriverData,
mPQBuf[Ind]->DriverName (),
mPQBuf[Ind]->DeviceName (),
mPQBuf[Ind]->PrinterName (),
DPDM_POSTJOBPROP);
rc = (devrc != DPDM_ERROR);
return rc;
}
/****************************************************************************/
/* Job management */
/****************************************************************************/
HDC PrnOpenDC( PRTQUEUE *pInfo, PSZ pszApplicationName, int copies, int toPrinter, char *file )
{
HDC hdc = 0;
PSZ pszLogAddress;
PSZ pszDataType;
LONG dcType;
DEVOPENSTRUC dop;
char pszQueueProcParams[CCHMAXPATH] = "COP=";
char numCopies[12];
itoa (copies, numCopies, 10);
strcat (pszQueueProcParams, numCopies);
if ( toPrinter ) {
pszLogAddress = pInfo->PQI3 ().pszName;
pszDataType = "PM_Q_STD";
dcType = OD_QUEUED;
} else {
if (file && strlen(file) != 0)
pszLogAddress = (PSZ) file;
else
pszLogAddress = "FILE";
pszDataType = "PM_Q_RAW";
dcType = OD_DIRECT;
}
dop.pszLogAddress = pszLogAddress;
dop.pszDriverName = (char*)pInfo->DriverName ();
dop.pdriv = pInfo->PQI3 ().pDriverData;
dop.pszDataType = pszDataType;
dop.pszComment = pszApplicationName;
dop.pszQueueProcName = pInfo->PQI3 ().pszPrProc;
dop.pszQueueProcParams = pszQueueProcParams;
dop.pszSpoolerParams = 0;
dop.pszNetworkParams = 0;
hdc = ::DevOpenDC( 0, dcType, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
if (hdc == 0)
{
ULONG ErrorCode = ERRORIDERROR (::WinGetLastError (0));
#ifdef DEBUG
printf ("!ERROR! - Can't open DC for printer %04X\a\n", ErrorCode);
#endif
}
return hdc;
}
BOOL prnEscape( HDC hdc, long lEscape)
{
BOOL rc = FALSE;
if( hdc)
{
long lDummy = 0;
long lResult = ::DevEscape( hdc, lEscape, 0, NULL, &lDummy, NULL);
rc = (lResult == DEV_OK);
}
return rc;
}
/* find the selected form */
BOOL PrnQueryHardcopyCaps( HDC hdc, PHCINFO pHCInfo)
{
BOOL rc = FALSE;
if( hdc && pHCInfo)
{
PHCINFO pBuffer;
long lAvail, i;
/* query how many forms are available */
lAvail = ::DevQueryHardcopyCaps( hdc, 0, 0, NULL);
pBuffer = (PHCINFO) malloc( lAvail * sizeof(HCINFO));
::DevQueryHardcopyCaps( hdc, 0, lAvail, pBuffer);
for( i = 0; i < lAvail; i++)
if( pBuffer[ i].flAttributes & HCAPS_CURRENT)
{
memcpy( pHCInfo, pBuffer + i, sizeof(HCINFO));
rc = TRUE;
break;
}
free( pBuffer);
}
return rc;
}
/****************************************************************************/
/* Library-level data and functions -Printing */
/****************************************************************************/
BOOL PrnInitialize( HMODULE hmodResources)
{
hmodRes = hmodResources;
return TRUE;
}
BOOL PrnTerminate()
{
/* nop for now, may do something eventually */
return TRUE;
}
BOOL PrnClosePrinter( PRTQUEUE *pPrintQueue)
{
BOOL rc = FALSE;
if (pPrintQueue)
{
delete pPrintQueue;
rc = TRUE;
}
return rc;
}

View File

@ -37,28 +37,148 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef _nsDeviceContextSpecOS2_h
#define _nsDeviceContextSpecOS2_h
#ifndef nsDeviceContextSpecOS2_h___
#define nsDeviceContextSpecOS2_h___
#include "nsGfxDefs.h"
#define INCL_PM
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_SPLDOSPRINT
#include "nsIDeviceContextSpec.h"
#include "libprint.h"
#include "nsIPrintOptions.h"
#include "nsVoidArray.h"
#ifdef USE_XPRINT
#include "nsIDeviceContextSpecXPrint.h"
#endif /* USE_XPRINT */
#include "nsPrintdOS2.h"
#include <os2.h>
//---------------------------------------------------------------------------
// OS/2 Printing - was in libprint
//---------------------------------------------------------------------------
// Library init and term; job properties per queue are cached during run.
BOOL PrnInitialize (HMODULE hmodResources);
BOOL PrnTerminate (void);
// opaque type to describe a print queue (printer)
class PRTQUEUE;
#define MAX_PRINT_QUEUES (128)
class PRINTDLG
{
public:
PRINTDLG ();
~PRINTDLG ();
int GetNumPrinters ();
int GetDefaultPrinter ();
char* GetPrinter (int numPrinter);
PRTQUEUE* SetPrinterQueue (int numPrinter);
BOOL ShowProperties(int index);
PRTQUEUE* SelectPrinter (HWND hwndOwner, BOOL bQuiet);
private:
ULONG mQueueCount;
ULONG mDefaultQueue;
PRTQUEUE* mPQBuf [MAX_PRINT_QUEUES];
int GetIndex( int numPrinter);
};
// Release app. resources associated with a printer
BOOL PrnClosePrinter( PRTQUEUE *pPrintQueue);
// Get a DC for the selected printer. Must supply the application name.
HDC PrnOpenDC( PRTQUEUE *pPrintQueue, PSZ pszApplicationName, int copies, int toPrinter, char *file);
// Get the hardcopy caps for the selected form
BOOL PrnQueryHardcopyCaps( HDC hdc, PHCINFO pHCInfo);
// Abort the current job started with PrnStartJob().
BOOL PrnAbortJob( HDC hdc);
//---------------------------------------------------------------------
// nsDeviceContextSpecOS2
//---------------------------------------------------------------------
class nsDeviceContextSpecOS2 : public nsIDeviceContextSpec
#ifdef USE_XPRINT
, public nsIDeviceContextSpecXp
#endif
{
public:
/**
* Construct a nsDeviceContextSpecMac, which is an object which contains and manages a mac printrecord
* @update dc 12/02/98
*/
nsDeviceContextSpecOS2();
NS_DECL_ISUPPORTS
NS_IMETHOD Init(PRTQUEUE *pq);
/**
* Initialize the nsDeviceContextSpecMac for use. This will allocate a printrecord for use
* @update dc 2/16/98
* @param aQuiet if PR_TRUE, prevent the need for user intervention
* in obtaining device context spec. if nsnull is passed in for
* the aOldSpec, this will typically result in getting a device
* context spec for the default output device (i.e. default
* printer).
* @return error status
*/
NS_IMETHOD Init(PRBool aQuiet);
NS_IMETHOD ClosePrintManager();
NS_IMETHOD GetToPrinter( PRBool &aToPrinter );
NS_IMETHOD GetPrinter ( char **aPrinter );
NS_IMETHOD GetCopies ( int &aCopies );
NS_IMETHOD GetPath ( char **aPath );
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
NS_IMETHOD GetPRTQUEUE(PRTQUEUE *&p);
static nsStringArray *globalPrinterList;
static int globalNumPrinters;
static PRINTDLG PrnDlg;
int InitializeGlobalPrinters();
void FreeGlobalPrinters();
protected:
/**
* Destuct a nsDeviceContextSpecMac, this will release the printrecord
* @update dc 2/16/98
*/
virtual ~nsDeviceContextSpecOS2();
protected:
OS2PrData mPrData;
PRTQUEUE *mQueue;
};
//-------------------------------------------------------------------------
// Printer Enumerator
//-------------------------------------------------------------------------
class nsPrinterEnumeratorOS2 : public nsIPrinterEnumerator
{
public:
nsPrinterEnumeratorOS2();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTERENUMERATOR
protected:
};
#endif

View File

@ -35,7 +35,7 @@
#define DPRINTF printf
#endif
#include "libprint.h"
#include "nsDeviceContextSpecOS2.h"
#include <stdlib.h>
@ -161,53 +161,6 @@ void PMERROR( const char *api)
DPRINTF ( "%s failed, error = 0x%X\n", api, usError);
}
nsGfxModuleData::nsGfxModuleData() : hModResources(0), hpsScreen(0)
{
}
void nsGfxModuleData::Init()
{
char buffer[CCHMAXPATH];
APIRET rc;
rc = DosLoadModule( buffer, CCHMAXPATH, "GFXRES", &hModResources);
if( rc)
{
DPRINTF ( "Gfx failed to load self. rc = %d, cause = %s\n", (int)rc, buffer);
// rats. Can't load ourselves. Oh well. Try to be harmless...
hModResources = 0;
}
PrnInitialize( hModResources);
// get screen bit-depth
hpsScreen = ::WinGetScreenPS (HWND_DESKTOP);
}
nsGfxModuleData::~nsGfxModuleData()
{
/* Free any converters that were created */
if (gUconvInfoList) {
nsUconvInfo* UconvInfoList = gUconvInfoList;
nsUconvInfo* tUconvInfoList;
do {
if (UconvInfoList->mConverter)
::UniFreeUconvObject(UconvInfoList->mConverter);
tUconvInfoList = UconvInfoList;
UconvInfoList = UconvInfoList->pNext;
free(tUconvInfoList);
} while (UconvInfoList);
} /* endif */
PrnTerminate();
if( hModResources)
DosFreeModule( hModResources);
::WinReleasePS( hpsScreen);
}
nsGfxModuleData gGfxModuleData;
int WideCharToMultiByte( int CodePage, const PRUnichar *pText, ULONG ulLength, char* szBuffer, ULONG ulSize )
{
UconvObject* pConverter = 0;

View File

@ -81,18 +81,6 @@ struct nsUconvInfo
static nsUconvInfo* gUconvInfoList = NULL;
// Module data
struct nsGfxModuleData
{
HMODULE hModResources;
HPS hpsScreen;
nsGfxModuleData();
~nsGfxModuleData();
void Init();
};
int WideCharToMultiByte( int CodePage, const PRUnichar *pText, ULONG ulLength, char* szBuffer, ULONG ulSize );
int MultiByteToWideChar( int CodePage, const char*pText, ULONG ulLength, PRUnichar *szBuffer, ULONG ulSize );
BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL);
@ -101,8 +89,6 @@ BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
BOOL IsDBCS();
extern nsGfxModuleData gGfxModuleData;
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif

View File

@ -69,6 +69,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorOS2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerOS2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsOS2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorOS2)
// our custom constructors
@ -178,7 +179,12 @@ static nsModuleComponentInfo components[] =
NS_SCREENMANAGER_CID,
// "@mozilla.org/gfx/screenmanager/gtk;1",
"@mozilla.org/gfx/screenmanager;1",
nsScreenManagerOS2Constructor }
nsScreenManagerOS2Constructor },
{ "OS/2 Printer Enumerator",
NS_PRINTER_ENUMERATOR_CID,
// "@mozilla.org/gfx/printer_enumerator/gtk;1",
"@mozilla.org/gfx/printerenumerator;1",
nsPrinterEnumeratorOS2Constructor }
};
PR_STATIC_CALLBACK(void)

53
gfx/src/os2/nsPrintdOS2.h Normal file
View File

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* Original Code: Syd Logan (syd@netscape.com) 3/12/99 */
#ifndef nsPrintdOS2_h___
#define nsPrintdOS2_h___
#include <limits.h>
PR_BEGIN_EXTERN_C
/* stolen from nsPostScriptObj.h. needs to be put somewhere else that
both ps and gtk can see easily */
#ifndef PATH_MAX
#ifdef _POSIX_PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX
#else
#define PATH_MAX 256
#endif
#endif
typedef struct OS2prdata {
PRBool toPrinter; /* If PR_TRUE, print to printer */
int copies; /* number of copies to print 0 < n < 999 */
char printer[ PATH_MAX ]; /* Printer selected - name*/
char path[ PATH_MAX ]; /* If toPrinter = PR_FALSE, dest file */
PRBool cancel; /* If PR_TRUE, user cancelled */
} OS2PrData;
PR_END_EXTERN_C
#endif /* nsPrintdOS2_h___ */

View File

@ -19,7 +19,8 @@
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -41,6 +42,11 @@
#include "nsISupports.h"
/* dummy printer name for the gfx/src/ps driver */
#define NS_POSTSCRIPT_DRIVER_NAME "PostScript/"
/* strlen(NS_POSTSCRIPT_DRIVER_NAME)*/
#define NS_POSTSCRIPT_DRIVER_NAME_LEN (11)
#define NS_IDEVICE_CONTEXT_SPEC_PS_IID { 0xa4ef8910, 0xdd65, 0x11d2, { 0xa8, 0x32, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } }
class nsIDeviceContextSpecPS : public nsISupports
@ -119,6 +125,14 @@ public:
**/
NS_IMETHOD GetCommand ( char **aCommand ) = 0;
/*
* Printer name e.g., myprinter
* @update
* @param aPrinter --
* @return
**/
NS_IMETHOD GetPrinter ( char **aPrinter ) = 0;
/*
* Get width and height based on user page size choice, e.g., 8.5 x 11.0
* @update

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
* described herein are Copyright (c) International Business Machines Corporation, 2000.
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
@ -46,6 +48,7 @@
#include "nsIPersistentProperties2.h"
#include "nsCRT.h"
#include "prenv.h"
#ifdef VMS
#include <stdlib.h>
@ -232,6 +235,9 @@ nsPostScriptObj::~nsPostScriptObj()
delete gLangGroups;
gLangGroups = nsnull;
}
#ifdef DEBUG
puts("nsPostScriptObj::~nsPostScriptObj(): printing done.");
#endif /* DEBUG */
}
/** ---------------------------------------------------
@ -271,7 +277,39 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec, PRUnichar * aTitle )
aSpec->GetSize( printSize );
mPrintSetup->paper_size = printSize;
aSpec->GetToPrinter( isAPrinter );
if ( isAPrinter == PR_TRUE ) {
if (isAPrinter) {
/* Define the destination printer (queue).
* We assume that the print command is set to
* "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}"
* - which means that if the ${MOZ_PRINTER_NAME} env var is not empty
* the "-P" option of lpr will be set to the printer name.
*/
char *envvar;
/* get printer name */
aSpec->GetPrinter(&buf);
/* do not set the ${MOZ_PRINTER_NAME} env var if we want the default
* printer */
if (buf)
{
/* strip the leading NS_POSTSCRIPT_DRIVER_NAME string */
buf = buf + NS_POSTSCRIPT_DRIVER_NAME_LEN;
if (!strcmp(buf, "default"))
buf = "";
}
else
buf = "";
envvar = (char *)malloc(strlen(buf) + /*strlen("MOZ_PRINTER_NAME=")+1*/18);
if (!envvar)
return NS_ERROR_OUT_OF_MEMORY;
sprintf(envvar, "MOZ_PRINTER_NAME=%s", buf);
#ifdef DEBUG
printf("setting printer name via '%s'\n", envvar);
#endif /* DEBUG */
PR_SetEnv(envvar);
free(envvar);
#ifndef VMS
aSpec->GetCommand( &buf );
#if defined(XP_OS2_VACPP) || defined(XP_PC)

View File

@ -81,6 +81,13 @@ ifneq (xlib,$(MOZ_GFX_TOOLKIT))
INACTIVE_COMPONENT = 1
endif
ifdef MOZ_ENABLE_XPRINT
XPU_LCSRCS = xprintutil.c
CSRCS += $(XPU_LCSRCS)
endif
GARBAGE += $(XPU_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb $(MOZ_XLIB_LDFLAGS)
@ -105,7 +112,7 @@ DEFINES += -D_BSD_SOURCE
endif
ifdef MOZ_ENABLE_XPRINT
DEFINES += -DUSE_XPRINT
DEFINES += -DUSE_XPRINT -DUSE_MOZILLA_TYPES
INCLUDES += -I$(srcdir)/../xprint
EXTRA_DSO_LDOPTS += $(MOZ_XPRINT_LDFLAGS)
endif
@ -115,3 +122,5 @@ INCLUDES += \
-I$(srcdir)/.. \
$(NULL)
export:: $(addprefix $(srcdir)/../xprint/,$(XPU_LCSRCS))
$(INSTALL) $^ .

View File

@ -42,6 +42,7 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
#include "nsReadableUtils.h"
#include "nsGfxCIID.h"
#include "nsIPref.h"
@ -53,8 +54,15 @@
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#ifdef USE_XPRINT
#include "xprintutil.h"
#endif /* USE_XPRINT */
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
nsStringArray* nsDeviceContextSpecXlib::globalPrinterList = nsnull;
int nsDeviceContextSpecXlib::globalNumPrinters = 0;
nsDeviceContextSpecXlib::nsDeviceContextSpecXlib()
{
NS_INIT_REFCNT();
@ -118,6 +126,83 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::QueryInterface(REFNSIID aIID, void **aIns
NS_IMPL_ADDREF(nsDeviceContextSpecXlib)
NS_IMPL_RELEASE(nsDeviceContextSpecXlib)
int nsDeviceContextSpecXlib::InitializeGlobalPrinters ()
{
globalNumPrinters = 0;
globalPrinterList = new nsStringArray();
if (!globalPrinterList)
return NS_ERROR_OUT_OF_MEMORY;
#ifdef USE_XPRINT
XPPrinterList plist = XpuGetPrinterList(nsnull, &globalNumPrinters);
if (plist && (globalNumPrinters > 0))
{
int i;
for( i = 0 ; i < globalNumPrinters ; i++ )
{
globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name)));
}
XpuFreePrinterList(plist);
}
#endif /* USE_XPRINT */
/* add an entry for the default printer (see nsPostScriptObj.cpp) */
globalPrinterList->AppendString(
nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default")));
globalNumPrinters++;
/* get the list of printers */
char *printerList = nsnull;
/* the env var MOZILLA_PRINTER_LIST can "override" the prefs */
printerList = PR_GetEnv("MOZILLA_PRINTER_LIST");
if (!printerList) {
nsresult rv;
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->CopyCharPref("print.printer_list", &printerList);
}
}
if (printerList) {
char *tok_lasts;
char *name;
/* PL_strtok_r() will modify the string - copy it! */
printerList = strdup(printerList);
if (!printerList)
return NS_ERROR_OUT_OF_MEMORY;
for( name = PL_strtok_r(printerList, " ", &tok_lasts) ;
name != nsnull ;
name = PL_strtok_r(nsnull, " ", &tok_lasts) )
{
globalPrinterList->AppendString(
nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) +
nsString(NS_ConvertASCIItoUCS2(name)));
globalNumPrinters++;
}
free(printerList);
}
if (globalNumPrinters == 0)
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
return NS_OK;
}
void nsDeviceContextSpecXlib::FreeGlobalPrinters()
{
delete globalPrinterList;
globalPrinterList = nsnull;
globalNumPrinters = 0;
}
/** -------------------------------------------------------
* Initialize the nsDeviceContextSpecGTK
* @update dc 2/15/98
@ -149,7 +234,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
PRBool isOn;
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
if (NS_SUCCEEDED(rv)) {
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
}
}
@ -165,13 +250,21 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRInt32 copies = 1;
PRUnichar *printer = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
if (PR_FALSE == aQuiet ) {
if( !globalPrinterList )
if (InitializeGlobalPrinters())
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
if( globalNumPrinters && !globalPrinterList->Count() )
return NS_ERROR_OUT_OF_MEMORY;
if (!aQuiet ) {
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
@ -185,13 +278,9 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindowInternal> parent;
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
if (active) {
active->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(parent));
}
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul",
@ -213,9 +302,12 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
else {
canPrint = PR_TRUE;
}
FreeGlobalPrinters();
if (canPrint) {
if (printService) {
printService->GetPrinter(&printer);
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
@ -226,6 +318,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
printService->GetPrintToFile(&tofile);
printService->GetStartPageRange(&fromPage);
printService->GetEndPageRange(&toPage);
printService->GetNumCopies(&copies);
printService->GetMarginTop(&dtop);
printService->GetMarginLeft(&dleft);
printService->GetMarginBottom(&dbottom);
@ -236,6 +329,8 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get());
strcpy(mPrData.path, NS_ConvertUCS2toUTF8(printfile).get());
}
if (printer != nsnull)
strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get());
#ifdef DEBUG_rods
printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright);
printf("printRange %d\n", printRange);
@ -248,7 +343,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
// as I need to make the default be "print" instead of "lpr" for OpenVMS.
strcpy(mPrData.command, "print");
#else
strcpy(mPrData.command, "lpr");
strcpy(mPrData.command, "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}");
#endif /* VMS */
}
@ -261,6 +356,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
mPrData.size = paper_size;
mPrData.orientation = orientation;
mPrData.toPrinter = !tofile;
mPrData.copies = copies;
// PWD, HOME, or fail
@ -274,6 +370,16 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
else
return NS_ERROR_FAILURE;
}
#ifdef NOT_IMPLEMENTED_YET
if (globalNumPrinters) {
for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) {
if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1)))
mQueue = PrnDlg.SetPrinterQueue(i);
}
}
#endif /* NOT_IMPLEMENTED_YET */
if (command != nsnull) {
nsMemory::Free(command);
}
@ -293,6 +399,18 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::GetToPrinter(PRBool &aToPrinter)
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinter ( char **aPrinter )
{
*aPrinter = &mPrData.printer[0];
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetCopies ( int &aCopies )
{
aCopies = mPrData.copies;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetFirstPageFirst(PRBool &aFpf)
{
aFpf = mPrData.fpf;
@ -392,17 +510,14 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::GetUserCancelled(PRBool &aCancel)
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrintMethod(PrintMethod &aMethod)
{
nsresult rv;
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
PRInt32 method = (PRInt32)pmAuto;
(void) pPrefs->GetIntPref("print.print_method", &method);
aMethod = (PrintMethod)method;
if (aMethod == pmAuto)
aMethod = NS_DEFAULT_PRINT_METHOD;
} else {
aMethod = NS_DEFAULT_PRINT_METHOD;
}
/* printer names for the PostScript module alwas start with
* the NS_POSTSCRIPT_DRIVER_NAME string */
if (strncmp(mPrData.printer, NS_POSTSCRIPT_DRIVER_NAME,
NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0)
aMethod = pmXprint;
else
aMethod = pmPostScript;
return NS_OK;
}
@ -410,3 +525,92 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::ClosePrintManager()
{
return NS_OK;
}
// Printer Enumerator
nsPrinterEnumeratorXlib::nsPrinterEnumeratorXlib()
{
NS_INIT_REFCNT();
}
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorXlib, nsIPrinterEnumerator)
NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
{
if (aCount)
*aCount = 0;
else
return NS_ERROR_NULL_POINTER;
if (aResult)
*aResult = nsnull;
else
return NS_ERROR_NULL_POINTER;
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecXlib::globalNumPrinters * sizeof(PRUnichar*));
if (!array && nsDeviceContextSpecXlib::globalNumPrinters)
return NS_ERROR_OUT_OF_MEMORY;
int count = 0;
while( count < nsDeviceContextSpecXlib::globalNumPrinters )
{
PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecXlib::globalPrinterList->StringAt(count));
if (!str) {
for (int i = count - 1; i >= 0; i--)
nsMemory::Free(array[i]);
nsMemory::Free(array);
return NS_ERROR_OUT_OF_MEMORY;
}
array[count++] = str;
}
*aCount = count;
*aResult = array;
return NS_OK;
}
NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPrinter)
{
nsresult rv = NS_ERROR_FAILURE;
/* fixme: We simply ignore the |aPrinter| argument here
* We should get the supported printer attributes from the printer and
* populate the print job options dialog with these data instead of using
* the "default set" here.
* However, this requires changes on all platforms and is another big chunk
* of patches ... ;-(
*/
nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv));
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
if (ioParamBlock)
paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
if (paramBlockWrapper) {
paramBlockWrapper->SetData(ioParamBlock);
paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock));
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions.xul",
"_blank", "chrome,modal", paramBlockWrapper,
getter_AddRefs(newWindow));
}
}
return rv;
}

View File

@ -41,7 +41,8 @@
#define nsDeviceContextSpecXlib_h___
#include "nsIDeviceContextSpec.h"
#include "nsDeviceContextSpecXlib.h"
#include "nsIPrintOptions.h"
#include "nsVoidArray.h"
#include "nsIDeviceContextSpecPS.h"
#ifdef USE_XPRINT
#include "nsIDeviceContextSpecXPrint.h"
@ -50,17 +51,11 @@
typedef enum
{
pmAuto = 0, /* default */
pmInvalid = 0,
pmXprint,
pmPostScript
} PrintMethod;
/* make Xprint the default print system if user/admin has set the XPSERVERLIST"
* env var. See Xprt config README (/usr/openwin/server/etc/XpConfig/README)
* for details.
*/
#define NS_DEFAULT_PRINT_METHOD ((PR_GetEnv("XPSERVERLIST")!=nsnull)?(pmXprint):(pmPostScript))
class nsDeviceContextSpecXlib : public nsIDeviceContextSpec,
public nsIDeviceContextSpecPS
#ifdef USE_XPRINT
@ -76,6 +71,8 @@ public:
NS_IMETHOD ClosePrintManager();
NS_IMETHOD GetToPrinter(PRBool &aToPrinter);
NS_IMETHOD GetPrinter ( char **aPrinter );
NS_IMETHOD GetCopies ( int &aCopies );
NS_IMETHOD GetFirstPageFirst(PRBool &aFpf);
NS_IMETHOD GetGrayscale(PRBool &aGrayscale);
NS_IMETHOD GetSize(int &aSize);
@ -90,9 +87,28 @@ public:
NS_IMETHOD GetUserCancelled(PRBool &aCancel);
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
virtual ~nsDeviceContextSpecXlib();
static nsStringArray *globalPrinterList;
static int globalNumPrinters;
int InitializeGlobalPrinters();
void FreeGlobalPrinters();
protected:
UnixPrData mPrData;
};
//-------------------------------------------------------------------------
// Printer Enumerator
//-------------------------------------------------------------------------
class nsPrinterEnumeratorXlib : public nsIPrinterEnumerator
{
public:
nsPrinterEnumeratorXlib();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTERENUMERATOR
#endif
protected:
};
#endif /* !nsDeviceContextSpecXlib_h___ */

View File

@ -72,6 +72,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorXlib)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerXlib)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsXlib)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorXlib)
// our custom constructors
@ -177,7 +178,12 @@ static nsModuleComponentInfo components[] =
NS_SCREENMANAGER_CID,
// "@mozilla.org/gfx/screenmanager/xlib;1",
"@mozilla.org/gfx/screenmanager;1",
nsScreenManagerXlibConstructor }
nsScreenManagerXlibConstructor },
{ "Xlib Printer Enumerator",
NS_PRINTER_ENUMERATOR_CID,
// "@mozilla.org/gfx/printer_enumerator/xlib;1",
"@mozilla.org/gfx/printerenumerator;1",
nsPrinterEnumeratorXlibConstructor }
};
PR_STATIC_CALLBACK(void)

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Vino Fernando Crescini <vino@igelaus.com.au>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -71,6 +72,8 @@ typedef struct unixprdata {
int orientation; /* Orientation e.g. Portrait */
char command[PATH_MAX]; /* Print command e.g., lpr */
char path[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */
char printer[256]; /* Printer name */
int copies; /* number of copies */
PRBool cancel; /* If PR_TRUE, user cancelled */
float left; /* left margin */
float right; /* right margin */
@ -82,5 +85,5 @@ void UnixPrDialog(UnixPrData *prData);
PR_END_EXTERN_C
#endif /* nsPrintdXlib_h___ */
#endif /* !nsPrintdXlib_h___ */

View File

@ -115,12 +115,12 @@ public:
NS_IMETHOD GetRightMargin ( float &aValue ) = 0;
/*
* Print command e.g., lpr
* Printer name e.g., myprinter or myprinter@myxprt:5
* @update
* @param aCommand --
* @param aPrinter --
* @return
**/
NS_IMETHOD GetCommand ( char **aCommand ) = 0;
NS_IMETHOD GetPrinter ( char **aPrinter ) = 0;
/*
* Get width and height based on user page size choice, e.g., 8.5 x 11.0

View File

@ -266,7 +266,7 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
/* get destination printer (we need this when printing to file as
* the printer DDX in Xprt generates the data...)
*/
aSpec->GetCommand(&buf);
aSpec->GetPrinter(&buf);
/* Are we "printing" to a file instead to the print queue ? */
if (!mIsAPrinter)
@ -288,7 +288,7 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
* shared memory transport is used XCloseDisplay() tries to free() the
* shared memory segment - causing heap corruption and/or SEGV.
*/
putenv((char *)"XSUNTRANSPORT=xxx");
PR_SetEnv("XSUNTRANSPORT=xxx");
/* get printer, either by "name" (foobar) or "name@display" (foobar@gaja:5)
* ToDo: report error to user (dialog)

View File

@ -40,6 +40,10 @@
#include <limits.h>
#include <errno.h>
#ifdef XPU_USE_NSPR
#define strtok_r(s1, s2, x) PL_strtok_r((s1), (s2), (x))
#endif /* USE_MOZILLA_TYPES */
/* conformace only; X11 API does (currrently) not make use of |const|.
* If Xlib API gets fixed these macros can be turned into empty
* placeholders... (|#define MAKE_STRING_WRITABLE(x)|) :-)
@ -75,10 +79,15 @@ int XpuCheckExtension( Display *pdpy )
const char *XpuGetXpServerList( void )
{
const char *s;
/* BUG/TODO: XpServerList resource needs to be sourced first, then append
* contents of XPSERVERLIST, then remove duplicates...
*/
return(getenv("XPSERVERLIST"));
s = getenv("XPSERVERLIST");
if( s == NULL )
s = "";
return(s);
}

View File

@ -62,5 +62,8 @@ NS_ERROR_NOT_IMPLEMENTED=Some printing functionality is not implemented yet.
NS_ERROR_NOT_AVAILABLE=Not available
NS_ERROR_ABORT=The print job was aborted, or canceled.
NS_ERROR_FAILURE=Printing failed for some reason.
# No printers available
noprinter=(no printers available)
# EOF.

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* 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
@ -99,11 +100,9 @@ pref("applications.tn3270", "xterm -e tn3270 %h");
pref("applications.rlogin", "xterm -e rlogin %h");
pref("applications.rlogin_with_user", "xterm -e rlogin %h -l %u");
pref("applications.tmp_dir", "/tmp");
// Choose print module. Default is "auto" which selects Xprint module
// if the XPSERVERLIST env var is set
pref("print.print_method", 0); // 0=auto, 1=Xprint, 2=PostScript, 3=reserved
// On Solaris/IRIX, this should be "lp"
pref("print.print_command", "lpr");
pref("print.print_command", "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}");
pref("print.printer_list", ""); // list of printers, seperated by spaces
pref("print.print_reversed", false);
pref("print.print_color", true);
pref("print.print_landscape", false);

View File

@ -1301,13 +1301,13 @@ nsIRangeUtil_IID = { /* a6cf9127-15b3-11d2-932e-00805f8add32 */
0x11d2,
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}
};
INTERFACENAME = { /* a6cf9128-15b3-11d2-932e-00805f8add32 */
nsIPrinterEnumerator = { /* a6cf9128-15b3-11d2-932e-00805f8add32 */
0xa6cf9128,
0x15b3,
0x11d2,
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}
};
INTERFACENAME = { /* a6cf9129-15b3-11d2-932e-00805f8add32 */
nsPrinterEnumerator_CID = { /* a6cf9129-15b3-11d2-932e-00805f8add32 */
0xa6cf9129,
0x15b3,
0x11d2,

View File

@ -41,6 +41,8 @@ toolkit.jar:
content/global/nsJSComponentManager.js (resources/content/nsJSComponentManager.js)
content/global/nsUserSettings.js (resources/content/nsUserSettings.js)
content/global/xul.css (resources/content/xul.css)
content/global/printdialog.xul (resources/content/printdialog.xul)
content/global/printdialog.js (resources/content/printdialog.js)
content/global/build.dtd (build.dtd)
content/global/bindings/browser.xml (resources/content/bindings/browser.xml)
content/global/bindings/button.xml (resources/content/bindings/button.xml)
@ -96,6 +98,7 @@ en-US.jar:
locale/en-US/global/plugins.properties (resources/locale/en-US/plugins.properties)
locale/en-US/global/nsOutlinerSorting.properties (resources/locale/en-US/nsOutlinerSorting.properties)
locale/en-US/global/dialog.properties (resources/locale/en-US/dialog.properties)
locale/en-US/global/printdialog.dtd (resources/locale/en-US/printdialog.dtd)
US.jar:
locale/US/global-region/contents.rdf (resources/locale/en-US/contents-region.rdf)

View File

@ -41,4 +41,5 @@ nsUserSettings.js
toolbarBindings.xml
stringbundleBindings.xml
plugins.html
printdialog.xul
printdialog.js

View File

@ -1,4 +1,4 @@
toolkit.jar:
content/global/platformGlobalOverlay.xul
content/global/platformDialogOverlay.xul
content/global/platformXUL.css
content/global/platformXUL.css

View File

@ -0,0 +1,415 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Masaki Katakai <katakai@japan.sun.com>
* Jessica Blanco <jblanco@us.ibm.com>
* Asko Tontti <atontti@cc.hut.fi>
*/
var dialog;
var printService = null;
var default_file = "mozilla.ps";
var gPrintOptInterface = Components.interfaces.nsIPrintOptions;
var doDebug = false;
//---------------------------------------------------
function initDialog()
{
dialog = new Object;
dialog.propertiesButton = document.getElementById("properties");
dialog.destGroup = document.getElementById("destGroup");
dialog.fileRadio = document.getElementById("fileRadio");
dialog.printerRadio = document.getElementById("printerRadio");
dialog.printrangeGroup = document.getElementById("printrangeGroup");
dialog.allpagesRadio = document.getElementById("allpagesRadio");
dialog.rangeRadio = document.getElementById("rangeRadio");
dialog.selectionRadio = document.getElementById("selectionRadio");
dialog.frompageInput = document.getElementById("frompageInput");
dialog.frompageLabel = document.getElementById("frompageLabel");
dialog.topageInput = document.getElementById("topageInput");
dialog.topageLabel = document.getElementById("topageLabel");
dialog.numCopiesInput = document.getElementById("numCopiesInput");
dialog.printframeGroup = document.getElementById("printframeGroup");
dialog.aslaidoutRadio = document.getElementById("aslaidoutRadio");
dialog.selectedframeRadio = document.getElementById("selectedframeRadio");
dialog.eachframesepRadio = document.getElementById("eachframesepRadio");
dialog.printframeGroupLabel = document.getElementById("printframeGroupLabel");
dialog.fileInput = document.getElementById("fileInput");
dialog.fileLabel = document.getElementById("fileLabel");
dialog.printerLabel = document.getElementById("printerLabel");
dialog.chooseButton = document.getElementById("chooseFile");
dialog.printerList = document.getElementById("printerList");
dialog.printButton = document.documentElement.getButton("accept");
// <data> elements
dialog.printName = document.getElementById("printButton");
dialog.fpDialog = document.getElementById("fpDialog");
dialog.enabled = false;
}
//---------------------------------------------------
function checkInteger(elementID)
{
var integerField = document.getElementById( elementID );
if ( !integerField )
return;
var value = integerField.value;
if (value && value.length > 0) {
value = value.replace(/[^0-9]/g,"");
if (!value) value = "";
integerField.value = value;
}
if (!value || value < 1 || value > 999)
dialog.printButton.setAttribute("disabled","true" );
else
dialog.printButton.removeAttribute("disabled");
}
//---------------------------------------------------
function stripTrailingWhitespace(element)
{
var stringIn = element.value;
stringIn = stringIn.replace(/\s+$/,"");
element.value = stringIn;
}
//---------------------------------------------------
function doPrintToFile( value )
{
if (value ) {
dialog.fileLabel.removeAttribute("disabled");
dialog.fileInput.removeAttribute("disabled");
dialog.chooseButton.removeAttribute("disabled");
} else {
dialog.fileLabel.setAttribute("disabled","true");
dialog.fileInput.setAttribute("disabled","true");
dialog.chooseButton.setAttribute("disabled","true");
}
}
//---------------------------------------------------
function listElement( aListElement )
{
this.listElement = aListElement;
}
listElement.prototype =
{
clearList:
function ()
{
// remove the menupopup node child of the menulist.
this.listElement.removeChild( this.listElement.firstChild );
},
appendPrinterNames:
function ( aDataObject )
{
var popupNode = document.createElement( "menupopup" );
var strDefaultPrinterName = "";
var printerName;
while (aDataObject.hasMoreElements()) {
printerName = aDataObject.getNext();
printerName = printerName.QueryInterface(Components.interfaces.nsISupportsWString);
var printerNameStr = printerName.toString();
if (strDefaultPrinterName == "")
strDefaultPrinterName = printerNameStr;
var itemNode = document.createElement( "menuitem" );
itemNode.setAttribute( "value", printerNameStr );
itemNode.setAttribute( "label", printerNameStr );
popupNode.appendChild( itemNode );
}
if (strDefaultPrinterName != "") {
this.listElement.removeAttribute( "disabled" );
} else {
var stringBundle = srGetStrBundle("chrome://communicator/locale/printing.properties");
this.listElement.setAttribute( "value", strDefaultPrinterName );
this.listElement.setAttribute( "label", stringBundle.GetStringFromName("noprinter") );
this.listElement.setAttribute( "disabled", "true" );
dialog.destGroup.setAttribute("disabled","true");
dialog.printerRadio.setAttribute("disabled","true");
dialog.printerLabel.setAttribute("disabled","true");
dialog.propertiesButton.setAttribute("disabled","true");
dialog.fileRadio.setAttribute("disabled","true");
doPrintToFile(false);
dialog.printButton.setAttribute("disabled","true");
}
this.listElement.appendChild( popupNode );
return strDefaultPrinterName;
}
};
//---------------------------------------------------
function getPrinters( )
{
var printerEnumerator = printService.availablePrinters();
var selectElement = new listElement(dialog.printerList);
selectElement.clearList();
var strDefaultPrinterName = selectElement.appendPrinterNames(printerEnumerator);
selectElement.listElement.value = strDefaultPrinterName;
}
//---------------------------------------------------
function displayPropertiesDialog( )
{
var displayed = new Object;
displayed.value = false;
printService.displayJobProperties(dialog.printerList.value, displayed);
if (doDebug) {
if (displayed)
dump("\nproperties dlg came up. displayed = "+displayed.value+"\n");
else
dump("\nproperties dlg didn't come up. displayed = "+displayed.value+"\n");
}
}
//---------------------------------------------------
function doPrintRange( inx )
{
if ( inx == 1 ) {
dialog.frompageInput.removeAttribute("disabled");
dialog.frompageLabel.removeAttribute("disabled");
dialog.topageInput.removeAttribute("disabled");
dialog.topageLabel.removeAttribute("disabled");
} else {
dialog.frompageInput.setAttribute("disabled","true" );
dialog.frompageLabel.setAttribute("disabled","true" );
dialog.topageInput.setAttribute("disabled","true" );
dialog.topageLabel.setAttribute("disabled","true" );
}
}
//---------------------------------------------------
function getDoubleStr( val, dec )
{
var str = val.toString();
inx = str.indexOf(".");
return str.substring(0, inx+dec+1);
}
//---------------------------------------------------
function loadDialog()
{
var print_tofile = false;
var print_copies = 1;
var print_file = default_file;
var print_selection_radio_enabled = false;
var print_frametype = gPrintOptInterface.kSelectedFrame;
var print_howToEnableUI = gPrintOptInterface.kFrameEnableNone;
try {
printService = Components.classes["@mozilla.org/gfx/printoptions;1"];
if (printService) {
printService = printService.getService();
if (printService) {
printService = printService.QueryInterface(Components.interfaces.nsIPrintOptions);
}
}
} catch(e) {}
if (printService) {
print_copies = printService.numCopies;
print_file = printService.toFileName;
print_tofile = printService.printToFile;
print_frametype = printService.printFrameType;
print_howToEnableUI = printService.howToEnableFrameUI;
print_selection_radio_enabled = printService.GetPrintOptions(gPrintOptInterface.kPrintOptionsEnableSelectionRB);
}
if (doDebug) {
dump("toFileName "+print_file+"\n");
dump("printToFile "+print_tofile+"\n");
dump("printToFile "+print_tofile+"\n");
dump("print_frame "+print_frametype+"\n");
dump("print_howToEnableUI "+print_howToEnableUI+"\n");
dump("selection_radio_enabled "+print_selection_radio_enabled+"\n");
}
if (print_file == "") {
print_file = default_file;
}
if (print_tofile) {
dialog.destGroup.selectedItem = dialog.fileRadio;
doPrintToFile( true );
} else {
dialog.destGroup.selectedItem = dialog.printerRadio;
doPrintToFile( false );
}
dialog.printrangeGroup.selectedItem = dialog.allpagesRadio;
if ( print_selection_radio_enabled) {
dialog.selectionRadio.removeAttribute("disabled");
} else {
dialog.selectionRadio.setAttribute("disabled","true" );
}
doPrintRange(dialog.rangeRadio.selected);
dialog.frompageInput.value = 1;
dialog.topageInput.value = 1;
dialog.numCopiesInput.value = 1;
dialog.fileInput.value = print_file;
getPrinters();
if (doDebug) {
dump("print_howToEnableUI: "+print_howToEnableUI+"\n");
}
// print frame
if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAll) {
dialog.aslaidoutRadio.removeAttribute("disabled");
dialog.selectedframeRadio.removeAttribute("disabled");
dialog.eachframesepRadio.removeAttribute("disabled");
dialog.printframeGroupLabel.removeAttribute("disabled");
// initialize radio group
dialog.printframeGroup.selectedItem = dialog.selectedframeRadio;
} else if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAsIsAndEach) {
dialog.aslaidoutRadio.removeAttribute("disabled"); //enable
dialog.selectedframeRadio.setAttribute("disabled","true" ); // disable
dialog.eachframesepRadio.removeAttribute("disabled"); // enable
dialog.printframeGroupLabel.removeAttribute("disabled"); // enable
// initialize
dialog.printframeGroup.selectedItem = dialog.eachframesepRadio;
} else {
dialog.aslaidoutRadio.setAttribute("disabled","true" );
dialog.selectedframeRadio.setAttribute("disabled","true" );
dialog.eachframesepRadio.setAttribute("disabled","true" );
dialog.printframeGroupLabel.setAttribute("disabled","true" );
}
dialog.printButton.label = dialog.printName.getAttribute("label");
}
var param;
//---------------------------------------------------
function onLoad()
{
// Init dialog.
initDialog();
param = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
if( !param ) {
return;
}
param.SetInt(0, 1 );
loadDialog();
}
//---------------------------------------------------
function onAccept()
{
if (printService) {
var print_howToEnableUI = gPrintOptInterface.kFrameEnableNone;
printService.printToFile = dialog.fileRadio.selected;
print_howToEnableUI = printService.howToEnableFrameUI;
// save these out so they can be picked up by the device spec
printService.toFileName = dialog.fileInput.value;
printService.printer = dialog.printerList.value;
if (dialog.allpagesRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeAllPages;
} else if (dialog.rangeRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeSpecifiedPageRange;
} else if (dialog.selectionRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeSelection;
}
printService.startPageRange = dialog.frompageInput.value;
printService.endPageRange = dialog.topageInput.value;
printService.numCopies = dialog.numCopiesInput.value;
var frametype = gPrintOptInterface.kNoFrames;
if (print_howToEnableUI != gPrintOptInterface.kFrameEnableNone) {
if (dialog.aslaidoutRadio.selected) {
frametype = gPrintOptInterface.kFramesAsIs;
} else if (dialog.selectedframeRadio.selected) {
frametype = gPrintOptInterface.kSelectedFrame;
} else if (dialog.eachframesepRadio.selected) {
frametype = gPrintOptInterface.kEachFrameSep;
} else {
frametype = gPrintOptInterface.kSelectedFrame;
}
}
printService.printFrameType = frametype;
} else {
dump("************ printService: "+printService+"\n");
}
if (param) {
param.SetInt(0, 0 );
}
return true;
}
//---------------------------------------------------
function onCancel()
{
if (param) {
param.SetInt(0, 1 );
}
return true;
}
//---------------------------------------------------
const nsIFilePicker = Components.interfaces.nsIFilePicker;
function onChooseFile()
{
if (dialog.fileRadio.selected == false) {
return;
}
try {
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, dialog.fpDialog.getAttribute("label"), nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterAll);
fp.show();
if (fp.file && fp.file.path.length > 0) {
dialog.fileInput.value = fp.file.path;
}
} catch(ex) {
dump(ex);
}
}

View File

@ -0,0 +1,119 @@
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
<!--
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 Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Masaki Katakai <katakai@japan.sun.com>
Dan Rosen <dr@netscape.com>
Jessica Blanco <jblanco@us.ibm.com>
Asko Tontti <atontti@cc.hut.fi>
-->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://global/locale/printdialog.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad();"
ondialogaccept="return onAccept();"
title="&printDialog.title;"
persist="screenX screenY"
screenX="24" screenY="24">
<script type="application/x-javascript" src="chrome://global/content/printdialog.js"/>
<script type="application/x-javascript" src="chrome://global/content/strres.js"/>
<groupbox>
<caption label="&printer.label;"/>
<hbox align="center">
<label value="&printTo.label;"/>
<radiogroup id="destGroup" orient="horizontal">
<radio id="printerRadio" label="&printerRadio.label;" onclick="doPrintToFile( false );"/>
<radio id="fileRadio" label="&fileRadio.label;" onclick="doPrintToFile( true );"/>
</radiogroup>
</hbox>
<grid>
<columns>
<column/>
<column flex="1"/>
<column/>
</columns>
<rows>
<row align="center">
<label id="printerLabel" value="&printerInput.label;"/>
<menulist id="printerList" flex ="1">
<menupopup/>
</menulist>
<button id="properties" label="&propertiesButton.label;" oncommand="displayPropertiesDialog();"/>
</row>
<row align="center">
<label id="fileLabel" control="fileInput" value="&fileInput.label;"/>
<textbox id="fileInput" flex="1" onblur="stripTrailingWhitespace(this)"/>
<button id="chooseFile" label="&chooseButton.label;" oncommand="onChooseFile()"/>
</row>
</rows>
</grid>
</groupbox>
<hbox>
<groupbox flex="1">
<caption label="&printrangeGroup.label;"/>
<radiogroup id="printrangeGroup">
<radio id="allpagesRadio" label="&allpagesRadio.label;" onclick="doPrintRange(0)"/>
<hbox align="center">
<radio id="rangeRadio" label="&rangeRadio.label;" onclick="doPrintRange(1)"/>
<label id="frompageLabel" control="frompageInput" value="&frompageInput.label;" />
<textbox id="frompageInput" style="width:5em;" onkeyup="checkInteger(this.id)"/>
<label id="topageLabel" control="topageInput" value="&topageInput.label;" />
<textbox id="topageInput" style="width:5em;" onkeyup="checkInteger(this.id)"/>
</hbox>
<radio id="selectionRadio" label="&selectionRadio.label;" onclick = "doPrintRange(2)"/>
</radiogroup>
</groupbox>
<groupbox flex="1">
<caption label="&copies.label;"/>
<hbox align="center">
<label control="numCopiesInput" value="&numCopies.label;"/>
<textbox id="numCopiesInput" style="width:5em;" onkeyup="checkInteger(this.id)"/>
</hbox>
</groupbox>
</hbox>
<groupbox flex="1">
<caption label="&printframeGroup.label;" id="printframeGroupLabel"/>
<radiogroup id="printframeGroup">
<radio id="aslaidoutRadio" label="&aslaidoutRadio.label;" />
<radio id="selectedframeRadio" label="&selectedframeRadio.label;" />
<radio id="eachframesepRadio" label="&eachframesepRadio.label;" />
</radiogroup>
</groupbox>
<!-- used to store titles and labels -->
<data style="display:none;" id="printButton" label="&printButton.label;"/>
<data style="display:none;" id="fpDialog" label="&fpDialog.title;"/>
</dialog>

View File

@ -16,7 +16,8 @@
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Contributor(s):
# Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
#
DEPTH = ../../../../..
@ -33,8 +34,8 @@ CHROME_CONTENT = \
platformGlobalOverlay.xul \
platformDialogOverlay.xul \
platformHTMLBindings.xml \
printdialog.xul \
printdialog.js \
printjoboptions.js \
printjoboptions.xul \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -1,6 +1,6 @@
toolkit.jar:
content/global/platformGlobalOverlay.xul
content/global/platformDialogOverlay.xul
content/global/printdialog.js
content/global/printdialog.xul
content/global/platformXUL.css
content/global/platformXUL.css
content/global/printjoboptions.js
content/global/printjoboptions.xul

View File

@ -1,143 +0,0 @@
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
<!--
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 Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s): Masaki Katakai <katakai@japan.sun.com>
Dan Rosen <dr@netscape.com>
-->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://global-platform/locale/printdialog.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad();"
ondialogaccept="return onAccept();"
title="&printDialog.title;"
persist="screenX screenY"
screenX="24" screenY="24">
<script type="application/x-javascript" src="chrome://global/content/printdialog.js"/>
<grid>
<columns><column/><column flex="1"/></columns>
<rows>
<row>
<label value="&printTo.label;" flex ="1"/>
<radiogroup id="destGroup" orient="horizontal">
<radio id = "printerRadio" label = "&printerRadio.label;"
oncommand = "doPrintToFile( false );"/>
<radio id = "fileRadio" label = "&fileRadio.label;"
oncommand = "doPrintToFile( true );"/>
</radiogroup>
</row>
<row>
<label id="cmdLabel" value="&cmdInput.label;" flex ="1"/>
<textbox id="cmdInput" flex ="1"/>
</row>
<row align="baseline">
<label id="fileLabel" value="&fileInput.label;"/>
<hbox>
<textbox id="fileInput" flex ="1" onblur="stripTrailingWhitespace(this)"/>
<button id="chooseFile" label = "&chooseButton.label;" oncommand = "onChooseFile()"/>
</hbox>
</row>
<row>
<label value="&reverseGroup.label;" flex ="1"/>
<radiogroup id="reverseGroup" orient="horizontal">
<radio id = "firstRadio" label = "&firstRadio.label;" />
<radio id = "lastRadio" label = "&lastRadio.label;" />
</radiogroup>
</row>
<row>
<label value="&colorGroup.label;" flex ="1"/>
<radiogroup id="colorGroup" orient="horizontal">
<radio id = "grayRadio" label = "&grayRadio.label;" />
<radio id = "colorRadio" label = "&colorRadio.label;"/>
</radiogroup>
</row>
<row>
<label value="&paperGroup.label;" flex ="1"/>
<radiogroup id="paperGroup" >
<radio id = "letterRadio" label = "&letterRadio.label;"/>
<radio id = "legalRadio" label = "&legalRadio.label;"/>
<radio id = "exectiveRadio" label = "&exectiveRadio.label;"/>
<radio id = "a4Radio" label = "&a4Radio.label;" />
<radio id = "a3Radio" label = "&a3Radio.label;" />
</radiogroup>
</row>
<row>
<label value="&orientationGroup.label;" flex ="1"/>
<radiogroup id="orientationGroup" orient="horizontal">
<radio id = "portraitRadio" label = "&portraitRadio.label;" />
<radio id = "landscapeRadio" label = "&landscapeRadio.label;"/>
</radiogroup>
</row>
<row>
<label value="&printrangeGroup.label;" flex ="1"/>
<radiogroup id="printrangeGroup">
<radio id = "allpagesRadio" label = "&allpagesRadio.label;" oncommand = "doPrintRange(0);"/>
<hbox align="center">
<radio id = "rangeRadio" label = "&rangeRadio.label;" oncommand = "doPrintRange(1);"/>
<label id = "frompageLabel" control = "frompageInput" value = "&frompageInput.label;" />
<textbox id = "frompageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
<label id = "topageLabel" control = "topageInput" value = "&topageInput.label;" />
<textbox id = "topageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<radio group = "printrangeGroup" id = "selectionRadio" label = "&selectionRadio.label;" onclick = "doPrintRange(2);"/>
</radiogroup>
</row>
<row>
<label value="&printframeGroup.label;" id="printframeGroupLabel" flex ="1"/>
<radiogroup id="printframeGroup">
<radio id = "aslaidoutRadio" label = "&aslaidoutRadio.label;" />
<radio id = "selectedframeRadio" label = "&selectedframeRadio.label;" />
<radio id = "eachframesepRadio" label = "&eachframesepRadio.label;" />
</radiogroup>
</row>
<row>
<label value="&marginInput.label;" flex ="1"/>
<hbox>
<hbox align="center">
<label id = "topLabel" control = "topInput" value = "&topInput.label;" />
<textbox id = "topInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id = "bottomLabel" control = "bottomInput" value = "&bottomInput.label;" />
<textbox id = "bottomInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id = "leftLabel" control = "leftInput" value = "&leftInput.label;" />
<textbox id = "leftInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id = "rightLabel" control = "rightInput" value = "&rightInput.label;" />
<textbox id = "rightInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
</hbox>
</row>
</rows>
</grid>
<!-- used to store the print -->
<data style="display:none;" id="printButton" label="&printButton.label;"/>
<!-- used to store the print -->
<data style="display:none;" id="fpDialog" label="&fpDialog.title;"/>
</dialog>

View File

@ -19,8 +19,10 @@
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Masaki Katakai <katakai@japan.sun.com>
* Asko Tontti <atontti@cc.hut.fi>
* Contributor(s):
* Masaki Katakai <katakai@japan.sun.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
* Asko Tontti <atontti@cc.hut.fi>
*
* 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
@ -40,7 +42,6 @@ var dialog;
var printService = null;
var default_command = "lpr";
var default_file = "mozilla.ps";
var gPrintOptInterface = Components.interfaces.nsIPrintOptions;
var doDebug = false;
@ -49,20 +50,8 @@ function initDialog()
{
dialog = new Object;
dialog.findKey = document.getElementById("dialog.findKey");
dialog.caseSensitive = document.getElementById("dialog.caseSensitive");
dialog.wrap = document.getElementById("dialog.wrap");
dialog.searchBackwards = document.getElementById("dialog.searchBackwards");
dialog.find = document.documentElement.getButton("accept");
dialog.cancel = document.getElementById("cancel");
dialog.fileLabel = document.getElementById("fileLabel");
dialog.cmdLabel = document.getElementById("cmdLabel");
dialog.destGroup = document.getElementById("destGroup");
dialog.fileRadio = document.getElementById("fileRadio");
dialog.printerRadio = document.getElementById("printerRadio");
dialog.reverseGroup = document.getElementById("reverseGroup");
dialog.firstRadio = document.getElementById("firstRadio");
dialog.lastRadio = document.getElementById("lastRadio");
@ -82,31 +71,12 @@ function initDialog()
dialog.portraitRadio = document.getElementById("portraitRadio");
dialog.landscapeRadio = document.getElementById("landscapeRadio");
dialog.printrangeGroup = document.getElementById("printrangeGroup");
dialog.allpagesRadio = document.getElementById("allpagesRadio");
dialog.rangeRadio = document.getElementById("rangeRadio");
dialog.selectionRadio = document.getElementById("selectionRadio");
dialog.frompageInput = document.getElementById("frompageInput");
dialog.frompageLabel = document.getElementById("frompageLabel");
dialog.topageInput = document.getElementById("topageInput");
dialog.topageLabel = document.getElementById("topageLabel");
dialog.printframeGroup = document.getElementById("printframeGroup");
dialog.aslaidoutRadio = document.getElementById("aslaidoutRadio");
dialog.selectedframeRadio = document.getElementById("selectedframeRadio");
dialog.eachframesepRadio = document.getElementById("eachframesepRadio");
dialog.printframeGroupLabel = document.getElementById("printframeGroupLabel");
dialog.topInput = document.getElementById("topInput");
dialog.bottomInput = document.getElementById("bottomInput");
dialog.leftInput = document.getElementById("leftInput");
dialog.rightInput = document.getElementById("rightInput");
dialog.cmdInput = document.getElementById("cmdInput");
dialog.fileInput = document.getElementById("fileInput");
dialog.chooseButton = document.getElementById("chooseFile");
dialog.print = document.documentElement.getButton("accept");
dialog.enabled = false;
}
@ -134,40 +104,6 @@ function stripTrailingWhitespace(element)
element.value = stringIn;
}
//---------------------------------------------------
function doPrintToFile( value )
{
if (value ) {
dialog.fileLabel.removeAttribute("disabled");
dialog.cmdLabel.setAttribute("disabled","true" );
dialog.fileInput.removeAttribute("disabled");
dialog.chooseButton.removeAttribute("disabled");
dialog.cmdInput.setAttribute("disabled","true" );
} else {
dialog.cmdLabel.removeAttribute("disabled");
dialog.fileLabel.setAttribute("disabled","true" );
dialog.fileInput.setAttribute("disabled","true" );
dialog.chooseButton.setAttribute("disabled","true" );
dialog.cmdInput.removeAttribute("disabled");
}
}
//---------------------------------------------------
function doPrintRange( inx )
{
if ( inx == 1 ) {
dialog.frompageInput.removeAttribute("disabled");
dialog.frompageLabel.removeAttribute("disabled");
dialog.topageInput.removeAttribute("disabled");
dialog.topageLabel.removeAttribute("disabled");
} else {
dialog.frompageInput.setAttribute("disabled","true" );
dialog.frompageLabel.setAttribute("disabled","true" );
dialog.topageInput.setAttribute("disabled","true" );
dialog.topageLabel.setAttribute("disabled","true" );
}
}
//---------------------------------------------------
function getDoubleStr( val, dec )
{
@ -179,7 +115,6 @@ function getDoubleStr( val, dec )
//---------------------------------------------------
function loadDialog()
{
var print_tofile = false;
var print_reversed = false;
var print_color = true;
var print_paper_size = 0;
@ -189,10 +124,6 @@ function loadDialog()
var print_margin_bottom = 0.5;
var print_margin_right = 0.5;
var print_command = default_command;
var print_file = default_file;
var print_selection_radio_enabled = false;
var print_frametype = gPrintOptInterface.kSelectedFrame;
var print_howToEnableUI = gPrintOptInterface.kFrameEnableNone;
try {
printService = Components.classes["@mozilla.org/gfx/printoptions;1"];
@ -216,11 +147,6 @@ function loadDialog()
print_margin_bottom = printService.marginBottom;
print_command = printService.printCommand;
print_file = printService.toFileName;
print_tofile = printService.printToFile;
print_frametype = printService.printFrameType;
print_howToEnableUI = printService.howToEnableFrameUI;
print_selection_radio_enabled = printService.GetPrintOptions(gPrintOptInterface.kPrintOptionsEnableSelectionRB);
}
if (doDebug) {
@ -229,13 +155,6 @@ function loadDialog()
dump("paperSize "+print_paper_size+"\n");
dump("orientation "+print_orientation+"\n");
dump("printCommand "+print_command+"\n");
dump("toFileName "+print_file+"\n");
dump("printToFile "+print_tofile+"\n");
dump("printToFile "+print_tofile+"\n");
dump("print_frame "+print_frametype+"\n");
dump("print_howToEnableUI "+print_howToEnableUI+"\n");
dump("selection_radio_enabled "+print_selection_radio_enabled+"\n");
dump("print_margin_top "+print_margin_top+"\n");
dump("print_margin_left "+print_margin_left+"\n");
@ -243,22 +162,10 @@ function loadDialog()
dump("print_margin_bottom "+print_margin_bottom+"\n");
}
if (print_file == "") {
print_file = default_file;
}
if (print_command == "") {
print_command = default_command;
}
if ( print_tofile) {
dialog.destGroup.selectedItem = dialog.fileRadio;
doPrintToFile( true );
} else {
dialog.destGroup.selectedItem = dialog.printerRadio;
doPrintToFile( false );
}
if ( print_color) {
dialog.colorGroup.selectedItem = dialog.colorRadio;
} else {
@ -280,7 +187,7 @@ function loadDialog()
} else if ( print_paper_size == gPrintOptInterface.kA4PaperSize ) {
dialog.paperGroup.selectedItem = dialog.a4Radio;
} else if ( print_paper_size == gPrintOptInterface.kA3PaperSize ) {
dialog.paperGroup.selectedItem = dialog.a3Radio;
dialog.paperGroup.selectedItem = dialog.a3Radio;
}
if ( print_orientation == gPrintOptInterface.kPortraitOrientation ) {
@ -289,58 +196,12 @@ function loadDialog()
dialog.orientationGroup.selectedItem = dialog.landscapeRadio;
}
dialog.printrangeGroup.selectedItem = dialog.allpagesRadio;
if ( print_selection_radio_enabled) {
dialog.selectionRadio.removeAttribute("disabled");
} else {
dialog.selectionRadio.setAttribute("disabled","true" );
}
doPrintRange(dialog.rangeRadio.selected);
dialog.frompageInput.value = 1;
dialog.topageInput.value = 1;
dialog.topInput.value = getDoubleStr(print_margin_top, 1);
dialog.bottomInput.value = getDoubleStr(print_margin_bottom, 1);
dialog.leftInput.value = getDoubleStr(print_margin_left, 1);
dialog.rightInput.value = getDoubleStr(print_margin_right, 1);
dialog.cmdInput.value = print_command;
dialog.fileInput.value = print_file;
dialog.print.label = document.getElementById("printButton").getAttribute("label");
if (doDebug) {
dump("print_howToEnableUI: "+print_howToEnableUI+"\n");
}
// print frame
if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAll) {
dialog.aslaidoutRadio.removeAttribute("disabled");
dialog.selectedframeRadio.removeAttribute("disabled");
dialog.eachframesepRadio.removeAttribute("disabled");
dialog.printframeGroupLabel.removeAttribute("disabled");
// initialize radio group
dialog.printframeGroup.selectedItem = dialog.selectedframeRadio;
} else if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAsIsAndEach) {
dialog.aslaidoutRadio.removeAttribute("disabled"); //enable
dialog.selectedframeRadio.setAttribute("disabled","true" ); // disable
dialog.eachframesepRadio.removeAttribute("disabled"); // enable
dialog.printframeGroupLabel.removeAttribute("disabled"); // enable
// initialize
dialog.printframeGroup.selectedItem = dialog.eachframesepRadio;
} else {
dialog.aslaidoutRadio.setAttribute("disabled","true" );
dialog.selectedframeRadio.setAttribute("disabled","true" );
dialog.eachframesepRadio.setAttribute("disabled","true" );
dialog.printframeGroupLabel.setAttribute("disabled","true" );
}
}
var param;
@ -367,12 +228,8 @@ function onAccept()
var print_paper_size = 0;
if (printService) {
var print_howToEnableUI = gPrintOptInterface.kFrameEnableNone;
printService.printToFile = dialog.fileRadio.selected;
printService.printReversed = dialog.lastRadio.selected;
printService.printInColor = dialog.colorRadio.selected;
print_howToEnableUI = printService.howToEnableFrameUI;
if (dialog.letterRadio.selected) {
print_paper_size = gPrintOptInterface.kLetterPaperSize;
@ -402,31 +259,7 @@ function onAccept()
printService.marginRight = dialog.rightInput.value;
printService.printCommand = dialog.cmdInput.value;
printService.toFileName = dialog.fileInput.value;
if (dialog.allpagesRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeAllPages;
} else if (dialog.rangeRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeSpecifiedPageRange;
} else if (dialog.selectionRadio.selected) {
printService.printRange = gPrintOptInterface.kRangeSelection;
}
printService.startPageRange = dialog.frompageInput.value;
printService.endPageRange = dialog.topageInput.value;
var frametype = gPrintOptInterface.kNoFrames;
if (print_howToEnableUI != gPrintOptInterface.kFrameEnableNone) {
if (dialog.aslaidoutRadio.selected) {
frametype = gPrintOptInterface.kFramesAsIs;
} else if (dialog.selectedframeRadio.selected) {
frametype = gPrintOptInterface.kSelectedFrame;
} else if (dialog.eachframesepRadio.selected) {
frametype = gPrintOptInterface.kEachFrameSep;
} else {
frametype = gPrintOptInterface.kSelectedFrame;
}
}
printService.printFrameType = frametype;
} else {
dump("************ printService: "+printService+"\n");
}
@ -447,22 +280,3 @@ function onCancel()
return true;
}
//---------------------------------------------------
const nsIFilePicker = Components.interfaces.nsIFilePicker;
function onChooseFile()
{
if (dialog.fileRadio.selected == false) {
return;
}
try {
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, document.getElementById("fpDialog").getAttribute("label"), nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterAll);
fp.show();
if (fp.file && fp.file.path.length > 0) {
dialog.fileInput.value = fp.file.path;
}
} catch(ex) {
dump(ex);
}
}

View File

@ -0,0 +1,115 @@
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
<!--
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 Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Masaki Katakai <katakai@japan.sun.com>
Dan Rosen <dr@netscape.com>
Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
Asko Tontti <atontti@cc.hut.fi>
-->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://global-platform/locale/printjoboptions.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad();"
ondialogaccept="return onAccept();"
title="&printJobOptions.title;"
persist="screenX screenY"
screenX="24" screenY="24">
<script type="application/x-javascript" src="chrome://global/content/printjoboptions.js"/>
<grid>
<columns>
<column/>
<column flex="1"/>
</columns>
<rows>
<row>
<label id="cmdLabel" value="&cmdInput.label;"/>
<textbox id="cmdInput" flex ="1"/>
</row>
<row>
<label value="&reverseGroup.label;"/>
<radiogroup id="reverseGroup" orient="horizontal">
<radio id="firstRadio" label="&firstRadio.label;"/>
<radio id="lastRadio" label="&lastRadio.label;"/>
</radiogroup>
</row>
<row>
<label value="&colorGroup.label;"/>
<radiogroup id="colorGroup" orient="horizontal">
<radio id="grayRadio" label="&grayRadio.label;"/>
<radio id="colorRadio" label="&colorRadio.label;"/>
</radiogroup>
</row>
<row>
<label value="&paperGroup.label;"/>
<radiogroup id="paperGroup">
<radio id="letterRadio" label="&letterRadio.label;"/>
<radio id="legalRadio" label="&legalRadio.label;"/>
<radio id="exectiveRadio" label="&exectiveRadio.label;"/>
<radio id="a4Radio" label="&a4Radio.label;"/>
<radio id="a3Radio" label="&a3Radio.label;"/>
</radiogroup>
</row>
<row>
<label value="&orientationGroup.label;"/>
<radiogroup id="orientationGroup" orient="horizontal">
<radio id="portraitRadio" label="&portraitRadio.label;"/>
<radio id="landscapeRadio" label="&landscapeRadio.label;"/>
</radiogroup>
</row>
<row>
<label value="&marginInput.label;"/>
<hbox>
<hbox align="center">
<label id="topLabel" control="topInput" value="&topInput.label;"/>
<textbox id="topInput" style="width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id="bottomLabel" control="bottomInput" value="&bottomInput.label;"/>
<textbox id="bottomInput" style="width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id="leftLabel" control="leftInput" value="&leftInput.label;"/>
<textbox id="leftInput" style="width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
<hbox align="center">
<label id="rightLabel" control="rightInput" value="&rightInput.label;"/>
<textbox id="rightInput" style="width:5em;" onkeyup="checkValid(this.id)"/>
</hbox>
</hbox>
</row>
</rows>
</grid>
</dialog>

View File

@ -16,3 +16,4 @@ languageNames.properties
regionNames.properties
commonDialogs.properties
plugins.properties
printdialog.dtd

View File

@ -50,6 +50,7 @@ CHROME_L10N = \
regionNames.properties \
commonDialogs.properties \
plugins.properties \
printdialog.dtd \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,32 @@
<!-- extracted from printdialog.xul -->
<!ENTITY printButton.label "Print">
<!ENTITY printDialog.title "Print">
<!ENTITY fpDialog.title "Save File">
<!ENTITY printTo.label "Print To:">
<!ENTITY printerRadio.label "Printer">
<!ENTITY fileRadio.label "File">
<!ENTITY propertiesButton.label "Properties...">
<!ENTITY printer.label "Printer">
<!ENTITY printerInput.label "Printer:">
<!ENTITY fileInput.label "File:">
<!ENTITY chooseButton.label "Choose File...">
<!ENTITY printrangeGroup.label "Print Range">
<!ENTITY allpagesRadio.label "All Pages">
<!ENTITY rangeRadio.label "Pages">
<!ENTITY frompageInput.label "from">
<!ENTITY topageInput.label "to">
<!ENTITY selectionRadio.label "Selection">
<!ENTITY copies.label "Copies">
<!ENTITY numCopies.label "Number of copies:">
<!ENTITY printframeGroup.label "Print Frames">
<!ENTITY aslaidoutRadio.label "As laid out on the screen">
<!ENTITY selectedframeRadio.label "The selected frame">
<!ENTITY eachframesepRadio.label "Each frame separately">

View File

@ -16,7 +16,8 @@
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Contributor(s):
# Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
#
DEPTH = ../../../../../..
@ -32,7 +33,7 @@ CHROME_L10N_DIR=global/locale
CHROME_L10N = \
platformGlobalOverlay.dtd \
platformDialogOverlay.dtd \
printdialog.dtd \
printjoboptions.dtd \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -3,5 +3,5 @@ en-unix.jar:
locale/en-US/global-platform/platformGlobalOverlay.dtd
locale/en-US/global-platform/platformDialogOverlay.dtd
locale/en-US/global-platform/platformKeys.properties
locale/en-US/global-platform/printdialog.dtd
locale/en-US/global-platform/wizard.properties
locale/en-US/global-platform/wizard.properties
locale/en-US/global-platform/printjoboptions.dtd

View File

@ -1,18 +1,8 @@
<!-- extracted from printdialog.xul -->
<!-- extracted from printjoboptions.xul -->
<!ENTITY printButton.label "Print">
<!ENTITY printDialog.title "Print">
<!ENTITY fpDialog.title "Save File">
<!ENTITY printTo.label "Print To:">
<!ENTITY printerRadio.label "Printer">
<!ENTITY fileRadio.label "File">
<!ENTITY printJobOptions.title "Printer Properties">
<!ENTITY cmdInput.label "Print Command:">
<!ENTITY fileInput.label "File:">
<!ENTITY chooseButton.label "Choose File...">
<!ENTITY reverseGroup.label "Print:">
<!ENTITY firstRadio.label "First Page First">
@ -33,20 +23,9 @@
<!ENTITY portraitRadio.label "Portrait">
<!ENTITY landscapeRadio.label "Landscape">
<!ENTITY printrangeGroup.label "Print Range:">
<!ENTITY allpagesRadio.label "All Pages">
<!ENTITY rangeRadio.label "Pages">
<!ENTITY frompageInput.label "from">
<!ENTITY topageInput.label "to">
<!ENTITY selectionRadio.label "Selection">
<!ENTITY printframeGroup.label "Print Frames:">
<!ENTITY aslaidoutRadio.label "As laid out on the screen">
<!ENTITY selectedframeRadio.label "The selected frame">
<!ENTITY eachframesepRadio.label "Each frame separately">
<!ENTITY marginInput.label "Margins(inches):">
<!ENTITY topInput.label "Top:">
<!ENTITY bottomInput.label "Bottom:">
<!ENTITY leftInput.label "Left:">
<!ENTITY rightInput.label "Right:">