r=Peter Weilbacher, sr=mkaply (OS/2 only), a=mkaply (OS/2 only)
Patch from Rich Walsh - printer select dialog mismatches descriptions
This commit is contained in:
mkaply%us.ibm.com 2006-02-16 21:32:31 +00:00
parent 867389b473
commit 8d70f643a8
2 changed files with 99 additions and 120 deletions

View File

@ -527,7 +527,6 @@ nsresult GlobalPrinters::InitializeGlobalPrinters ()
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature
ULONG defaultPrinter = nsDeviceContextSpecOS2::PrnDlg.GetDefaultPrinter();
for (ULONG i = 0; i < mGlobalNumPrinters; i++) { for (ULONG i = 0; i < mGlobalNumPrinters; i++) {
nsXPIDLCString printer; nsXPIDLCString printer;
nsDeviceContextSpecOS2::PrnDlg.GetPrinter(i, getter_Copies(printer)); nsDeviceContextSpecOS2::PrnDlg.GetPrinter(i, getter_Copies(printer));
@ -536,11 +535,8 @@ nsresult GlobalPrinters::InitializeGlobalPrinters ()
PRInt32 printerNameLength; PRInt32 printerNameLength;
rv = MultiByteToWideChar(0, printer, strlen(printer), rv = MultiByteToWideChar(0, printer, strlen(printer),
printerName, printerNameLength); printerName, printerNameLength);
if (defaultPrinter == i) { mGlobalPrinterList->AppendString(nsDependentString(printerName.get()));
mGlobalPrinterList->InsertStringAt(nsDependentString(printerName.get()), 0);
} else {
mGlobalPrinterList->AppendString(nsDependentString(printerName.get()));
}
// store printer description in prefs for the print dialog // store printer description in prefs for the print dialog
if (!prefFailed) { if (!prefFailed) {
nsCAutoString printerDescription; nsCAutoString printerDescription;
@ -568,9 +564,9 @@ void GlobalPrinters::GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName)
if (GetNumPrinters() == 0) if (GetNumPrinters() == 0)
return; return;
ULONG defaultPrinter = nsDeviceContextSpecOS2::PrnDlg.GetDefaultPrinter(); // the default printer is always index 0
nsXPIDLCString printer; nsXPIDLCString printer;
nsDeviceContextSpecOS2::PrnDlg.GetPrinter(defaultPrinter, getter_Copies(printer)); nsDeviceContextSpecOS2::PrnDlg.GetPrinter(0, getter_Copies(printer));
nsAutoChar16Buffer printerName; nsAutoChar16Buffer printerName;
PRInt32 printerNameLength; PRInt32 printerNameLength;
@ -643,7 +639,7 @@ PRTQUEUE::PRTQUEUE (const PRTQUEUE& PQInfo)
strcpy (mPrinterName, PQInfo.mPrinterName); strcpy (mPrinterName, PQInfo.mPrinterName);
} }
void PRTQUEUE::InitWithPQI3 (const PRQINFO3* pInfo) void PRTQUEUE::InitWithPQI3(const PRQINFO3* pInfo)
{ {
// Make local copy of PPRQINFO3 object // Make local copy of PPRQINFO3 object
ULONG SizeNeeded; ULONG SizeNeeded;
@ -684,37 +680,42 @@ void PRTQUEUE::InitWithPQI3 (const PRQINFO3* pInfo)
//=========================================================================== //===========================================================================
PRINTDLG::PRINTDLG () PRINTDLG::PRINTDLG()
{ {
mQueueCount = 0; mQueueCount = 0;
mDefaultQueue = 0;
ULONG TotalQueues = 0; ULONG TotalQueues = 0;
ULONG MemNeeded = 0; ULONG MemNeeded = 0;
SPLERR rc; SPLERR rc;
rc = ::SplEnumQueue (NULL, 3, NULL, 0, &mQueueCount, &TotalQueues, &MemNeeded, NULL); rc = ::SplEnumQueue(NULL, 3, NULL, 0, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded); PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded);
rc = ::SplEnumQueue (NULL, 3, pPQI3Buf, MemNeeded, &mQueueCount, &TotalQueues, &MemNeeded, NULL); rc = ::SplEnumQueue(NULL, 3, pPQI3Buf, MemNeeded, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
if (mQueueCount > MAX_PRINT_QUEUES) if (mQueueCount > MAX_PRINT_QUEUES)
mQueueCount = MAX_PRINT_QUEUES; mQueueCount = MAX_PRINT_QUEUES;
for (ULONG cnt = 0 ; cnt < mQueueCount ; cnt++) ULONG defaultQueue = 0;
{ for (ULONG cnt = 0; cnt < mQueueCount; cnt++) {
if (pPQI3Buf [cnt].fsType & PRQ3_TYPE_APPDEFAULT) if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
mDefaultQueue = cnt; defaultQueue = cnt;
mPQBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
mPQBuf [cnt] = new PRTQUEUE (&pPQI3Buf [cnt]);
} }
free (pPQI3Buf); // move the entry for the default printer to index 0 (if necessary)
if (defaultQueue > 0) {
PRTQUEUE* temp = mPQBuf[0];
mPQBuf[0] = mPQBuf[defaultQueue];
mPQBuf[defaultQueue] = temp;
}
free(pPQI3Buf);
} }
PRINTDLG::~PRINTDLG () PRINTDLG::~PRINTDLG()
{ {
for (ULONG cnt = 0 ; cnt < mQueueCount ; cnt++) for (ULONG index = 0; index < mQueueCount; index++)
delete mPQBuf [cnt]; delete mPQBuf[index];
} }
void PRINTDLG::RefreshPrintQueue() void PRINTDLG::RefreshPrintQueue()
@ -722,126 +723,112 @@ void PRINTDLG::RefreshPrintQueue()
ULONG newQueueCount = 0; ULONG newQueueCount = 0;
ULONG TotalQueues = 0; ULONG TotalQueues = 0;
ULONG MemNeeded = 0; ULONG MemNeeded = 0;
mDefaultQueue = 0;
SPLERR rc; SPLERR rc;
rc = ::SplEnumQueue (NULL, 3, NULL, 0, &newQueueCount, &TotalQueues, &MemNeeded, NULL); rc = ::SplEnumQueue(NULL, 3, NULL, 0, &newQueueCount, &TotalQueues, &MemNeeded, NULL);
PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded); PRQINFO3* pPQI3Buf = (PRQINFO3*)malloc(MemNeeded);
rc = ::SplEnumQueue (NULL, 3, pPQI3Buf, MemNeeded, &newQueueCount, &TotalQueues, &MemNeeded, NULL); rc = ::SplEnumQueue(NULL, 3, pPQI3Buf, MemNeeded, &newQueueCount, &TotalQueues, &MemNeeded, NULL);
if (newQueueCount > MAX_PRINT_QUEUES) if (newQueueCount > MAX_PRINT_QUEUES)
newQueueCount = MAX_PRINT_QUEUES; newQueueCount = MAX_PRINT_QUEUES;
PRTQUEUE* tmpBuf[MAX_PRINT_QUEUES]; PRTQUEUE* tmpBuf[MAX_PRINT_QUEUES];
for (ULONG cnt = 0 ; cnt < newQueueCount ; cnt++) ULONG defaultQueue = 0;
{ for (ULONG cnt = 0; cnt < newQueueCount; cnt++) {
if (pPQI3Buf [cnt].fsType & PRQ3_TYPE_APPDEFAULT) if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
mDefaultQueue = cnt; defaultQueue = cnt;
BOOL found = FALSE; BOOL found = FALSE;
for (ULONG j = 0 ; j < mQueueCount && !found; j++) for (ULONG index = 0; index < mQueueCount && !found; index++) {
{
//Compare printer from requeried list with what's already in Mozilla's printer list(mPQBuf) //Compare printer from requeried list with what's already in Mozilla's printer list(mPQBuf)
//If printer is already there, use current properties; otherwise create a new printer in list //If printer is already there, use current properties; otherwise create a new printer in list
if (mPQBuf[j] != 0) { if (mPQBuf[index] != 0) {
if ((strcmp(pPQI3Buf[cnt].pszPrinters, mPQBuf[j]->PrinterName()) == 0) && if ((strcmp(pPQI3Buf[cnt].pszPrinters, mPQBuf[index]->PrinterName()) == 0) &&
(strcmp(pPQI3Buf[cnt].pszDriverName, mPQBuf[j]->PQI3().pszDriverName) == 0)) { (strcmp(pPQI3Buf[cnt].pszDriverName, mPQBuf[index]->PQI3().pszDriverName) == 0)) {
found = TRUE; found = TRUE;
tmpBuf[cnt] = mPQBuf[j]; tmpBuf[cnt] = mPQBuf[index];
mPQBuf[j] = 0; mPQBuf[index] = 0;
} }
} }
} }
if (!found) if (!found)
tmpBuf[cnt] = new PRTQUEUE (&pPQI3Buf[cnt]); tmpBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
} }
for (ULONG i=0; i < newQueueCount; i++) { for (ULONG index = 0; index < newQueueCount; index++) {
if (mPQBuf[i] != 0) if (mPQBuf[index] != 0)
delete(mPQBuf[i]); delete(mPQBuf[index]);
mPQBuf[i] = tmpBuf[i]; mPQBuf[index] = tmpBuf[index];
} }
if (mQueueCount > newQueueCount) if (mQueueCount > newQueueCount)
for (ULONG i = newQueueCount; i < mQueueCount; i++) for (ULONG index = newQueueCount; index < mQueueCount; index++)
if (mPQBuf[i] != 0) if (mPQBuf[index] != 0)
delete(mPQBuf[i]); delete(mPQBuf[index]);
mQueueCount = newQueueCount; mQueueCount = newQueueCount;
free (pPQI3Buf);
// move the entry for the default printer to index 0 (if necessary)
if (defaultQueue > 0) {
PRTQUEUE* temp = mPQBuf[0];
mPQBuf[0] = mPQBuf[defaultQueue];
mPQBuf[defaultQueue] = temp;
}
free(pPQI3Buf);
} }
ULONG PRINTDLG::GetIndex (ULONG numPrinter) ULONG PRINTDLG::GetNumPrinters()
{
ULONG index;
if (numPrinter == 0)
index = mDefaultQueue;
else if (numPrinter > mDefaultQueue)
index = numPrinter;
else
index = numPrinter - 1;
return index;
}
ULONG PRINTDLG::GetNumPrinters ()
{ {
return mQueueCount; return mQueueCount;
} }
ULONG PRINTDLG::GetDefaultPrinter () void PRINTDLG::GetPrinter(ULONG printerNdx, char** printerName)
{ {
return mDefaultQueue; if (printerNdx >= mQueueCount)
}
void PRINTDLG::GetPrinter (ULONG numPrinter, char** printerName)
{
if (numPrinter > mQueueCount)
return; return;
nsCAutoString pName(mPQBuf [numPrinter]->QueueName()); nsCAutoString pName(mPQBuf[printerNdx]->QueueName());
pName.ReplaceChar('\r', ' '); pName.ReplaceChar('\r', ' ');
pName.StripChars("\n"); pName.StripChars("\n");
*printerName = ToNewCString(pName); *printerName = ToNewCString(pName);
} }
PRTQUEUE* PRINTDLG::SetPrinterQueue (ULONG numPrinter) PRTQUEUE* PRINTDLG::SetPrinterQueue(ULONG printerNdx)
{ {
PRTQUEUE *pPQ = NULL; PRTQUEUE *pPQ = NULL;
if (numPrinter > mQueueCount) if (printerNdx >= mQueueCount)
return NULL; return NULL;
pPQ = mPQBuf [GetIndex(numPrinter)]; pPQ = mPQBuf[printerNdx];
return new PRTQUEUE (*pPQ); return new PRTQUEUE(*pPQ);
} }
LONG PRINTDLG::GetPrintDriverSize (ULONG printer) LONG PRINTDLG::GetPrintDriverSize(ULONG printerNdx)
{ {
return mPQBuf[GetIndex(printer)]->PQI3().pDriverData->cb; return mPQBuf[printerNdx]->PQI3().pDriverData->cb;
} }
PDRIVDATA PRINTDLG::GetPrintDriver (ULONG printer) PDRIVDATA PRINTDLG::GetPrintDriver(ULONG printerNdx)
{ {
if (printer > mQueueCount) if (printerNdx >= mQueueCount)
return NULL; return NULL;
return mPQBuf[GetIndex(printer)]->PQI3().pDriverData; return mPQBuf[printerNdx]->PQI3().pDriverData;
} }
HDC PRINTDLG::GetDCHandle (ULONG numPrinter) HDC PRINTDLG::GetDCHandle(ULONG printerNdx)
{ {
HDC hdc = 0; HDC hdc = 0;
ULONG index = GetIndex(numPrinter);
DEVOPENSTRUC dop; DEVOPENSTRUC dop;
dop.pszLogAddress = 0; dop.pszLogAddress = 0;
dop.pszDriverName = (char *) mPQBuf[index]->DriverName(); dop.pszDriverName = (char *)mPQBuf[printerNdx]->DriverName();
dop.pdriv = mPQBuf[index]->PQI3 ().pDriverData; dop.pdriv = mPQBuf[printerNdx]->PQI3().pDriverData;
dop.pszDataType = 0; dop.pszDataType = 0;
dop.pszComment = 0; dop.pszComment = 0;
dop.pszQueueProcName = 0; dop.pszQueueProcName = 0;
@ -849,30 +836,29 @@ HDC PRINTDLG::GetDCHandle (ULONG numPrinter)
dop.pszSpoolerParams = 0; dop.pszSpoolerParams = 0;
dop.pszNetworkParams = 0; dop.pszNetworkParams = 0;
hdc = ::DevOpenDC( 0, OD_INFO, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE); hdc = ::DevOpenDC(0, OD_INFO, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
return hdc; return hdc;
} }
char* PRINTDLG::GetDriverType (ULONG printer) char* PRINTDLG::GetDriverType(ULONG printerNdx)
{ {
return (char *)mPQBuf[GetIndex(printer)]->DriverName (); return (char *)mPQBuf[printerNdx]->DriverName ();
} }
BOOL PRINTDLG::ShowProperties (ULONG index) BOOL PRINTDLG::ShowProperties(ULONG printerNdx)
{ {
BOOL rc = FALSE; BOOL rc = FALSE;
LONG devrc = FALSE; LONG devrc = FALSE;
PDRIVDATA pOldDrivData; PDRIVDATA pOldDrivData;
PDRIVDATA pNewDrivData = NULL; PDRIVDATA pNewDrivData = NULL;
LONG buflen; LONG buflen;
ULONG Ind = GetIndex(index);
/* check size of buffer required for job properties */ /* check size of buffer required for job properties */
buflen = DevPostDeviceModes( 0 /*hab*/, buflen = DevPostDeviceModes( 0 /*hab*/,
NULL, NULL,
mPQBuf[Ind]->DriverName (), mPQBuf[printerNdx]->DriverName (),
mPQBuf[Ind]->DeviceName (), mPQBuf[printerNdx]->DeviceName (),
mPQBuf[Ind]->PrinterName (), mPQBuf[printerNdx]->PrinterName (),
DPDM_POSTJOBPROP); DPDM_POSTJOBPROP);
/* return error to caller */ /* return error to caller */
@ -882,15 +868,15 @@ BOOL PRINTDLG::ShowProperties (ULONG index)
/* allocate some memory for larger job properties and */ /* allocate some memory for larger job properties and */
/* return error to caller */ /* return error to caller */
if (buflen != mPQBuf[Ind]->PQI3().pDriverData->cb) if (buflen != mPQBuf[printerNdx]->PQI3().pDriverData->cb)
{ {
if (DosAllocMem((PPVOID)&pNewDrivData,buflen,fALLOC)) if (DosAllocMem((PPVOID)&pNewDrivData,buflen,fALLOC))
return(FALSE); // DPDM_ERROR return(FALSE); // DPDM_ERROR
/* copy over old data so driver can use old job */ /* copy over old data so driver can use old job */
/* properties as base for job properties dialog */ /* properties as base for job properties dialog */
pOldDrivData = mPQBuf[Ind]->PQI3().pDriverData; pOldDrivData = mPQBuf[printerNdx]->PQI3().pDriverData;
mPQBuf[Ind]->PQI3().pDriverData = pNewDrivData; mPQBuf[printerNdx]->PQI3().pDriverData = pNewDrivData;
memcpy( (PSZ)pNewDrivData, (PSZ)pOldDrivData, pOldDrivData->cb ); memcpy( (PSZ)pNewDrivData, (PSZ)pOldDrivData, pOldDrivData->cb );
} }
@ -898,10 +884,10 @@ BOOL PRINTDLG::ShowProperties (ULONG index)
/* job properties from driver */ /* job properties from driver */
devrc = DevPostDeviceModes( 0 /*hab*/, devrc = DevPostDeviceModes( 0 /*hab*/,
mPQBuf[Ind]->PQI3().pDriverData, mPQBuf[printerNdx]->PQI3().pDriverData,
mPQBuf[Ind]->DriverName (), mPQBuf[printerNdx]->DriverName (),
mPQBuf[Ind]->DeviceName (), mPQBuf[printerNdx]->DeviceName (),
mPQBuf[Ind]->PrinterName (), mPQBuf[printerNdx]->PrinterName (),
DPDM_POSTJOBPROP); DPDM_POSTJOBPROP);
rc = (devrc != DPDM_ERROR); rc = (devrc != DPDM_ERROR);
return rc; return rc;

View File

@ -64,8 +64,8 @@
// OS/2 Printing - was in libprint // OS/2 Printing - was in libprint
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Library init and term; job properties per queue are cached during run. // Library init and term; job properties per queue are cached during run.
BOOL PrnInitialize (HMODULE hmodResources); BOOL PrnInitialize(HMODULE hmodResources);
BOOL PrnTerminate (void); BOOL PrnTerminate(void);
// opaque type to describe a print queue (printer) // opaque type to describe a print queue (printer)
class PRTQUEUE; class PRTQUEUE;
@ -74,29 +74,22 @@ class PRTQUEUE;
class PRINTDLG class PRINTDLG
{ {
public: public:
PRINTDLG (); PRINTDLG();
~PRINTDLG (); ~PRINTDLG();
void RefreshPrintQueue(); void RefreshPrintQueue();
ULONG GetNumPrinters (); ULONG GetNumPrinters();
ULONG GetDefaultPrinter (); void GetPrinter(ULONG printerNdx, char** printerName);
void GetPrinter (ULONG numPrinter, char** printerName); PRTQUEUE* SetPrinterQueue(ULONG printerNdx);
PRTQUEUE* SetPrinterQueue (ULONG numPrinter); LONG GetPrintDriverSize(ULONG printerNdx);
HDC GetDCHandle (ULONG numPrinter); PDRIVDATA GetPrintDriver(ULONG printerNdx);
LONG GetPrintDriverSize (ULONG printer); HDC GetDCHandle(ULONG printerNdx);
PDRIVDATA GetPrintDriver (ULONG printer); char* GetDriverType(ULONG printerNdx);
char* GetDriverType (ULONG printer); BOOL ShowProperties(ULONG printerNdx);
BOOL ShowProperties(ULONG index);
PRTQUEUE* SelectPrinter (HWND hwndOwner, BOOL bQuiet);
private: private:
ULONG mQueueCount; ULONG mQueueCount;
ULONG mDefaultQueue; PRTQUEUE* mPQBuf[MAX_PRINT_QUEUES];
PRTQUEUE* mPQBuf [MAX_PRINT_QUEUES];
ULONG GetIndex( ULONG numPrinter);
}; };