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 2006-02-16 21:31:54 +00:00
Родитель 2af09ef786
Коммит 05bbb1b253
4 изменённых файлов: 892 добавлений и 48 удалений

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

@ -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;
}

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

@ -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;
}

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

@ -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

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

@ -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___ */