From 66d51ebb5b1088eaf2f9de36578dd8768b24182c Mon Sep 17 00:00:00 2001 From: "mkaply%us.ibm.com" Date: Thu, 16 Feb 2006 21:32:21 +0000 Subject: [PATCH] #211984 r=mkaply, sr=blizzard (platform specific), a=mkaply OS/2 only - refresh printer list before dialog comes up --- widget/src/os2/nsDeviceContextSpecOS2.cpp | 57 +++++++++++++++++++++++ widget/src/os2/nsDeviceContextSpecOS2.h | 1 + 2 files changed, 58 insertions(+) diff --git a/widget/src/os2/nsDeviceContextSpecOS2.cpp b/widget/src/os2/nsDeviceContextSpecOS2.cpp index deaa899b1ab..5e2aed9fa99 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.cpp +++ b/widget/src/os2/nsDeviceContextSpecOS2.cpp @@ -398,6 +398,8 @@ NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnic *aResult = nsnull; else return NS_ERROR_NULL_POINTER; + + nsDeviceContextSpecOS2::PrnDlg.RefreshPrintQueue(); nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); if (NS_FAILED(rv)) { @@ -674,6 +676,61 @@ PRINTDLG::~PRINTDLG () delete mPQBuf [cnt]; } +PRINTDLG::RefreshPrintQueue () +{ + ULONG newQueueCount = 0; + ULONG TotalQueues = 0; + ULONG MemNeeded = 0; + mDefaultQueue = 0; + SPLERR rc; + + rc = ::SplEnumQueue (NULL, 3, NULL, 0, &newQueueCount, &TotalQueues, &MemNeeded, NULL); + PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded); + rc = ::SplEnumQueue (NULL, 3, pPQI3Buf, MemNeeded, &newQueueCount, &TotalQueues, &MemNeeded, NULL); + + if (newQueueCount > MAX_PRINT_QUEUES) + newQueueCount = MAX_PRINT_QUEUES; + + PRTQUEUE* tmpBuf[MAX_PRINT_QUEUES]; + + for (ULONG cnt = 0 ; cnt < newQueueCount ; cnt++) + { + if (pPQI3Buf [cnt].fsType & PRQ3_TYPE_APPDEFAULT) + mDefaultQueue = cnt; + + BOOL found = FALSE; + for (ULONG j = 0 ; j < mQueueCount && !found; j++) + { + //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 (mPQBuf[j] != 0) { + if ((strcmp(pPQI3Buf[cnt].pszPrinters, mPQBuf[j]->PrinterName()) == 0) && + (strcmp(pPQI3Buf[cnt].pszDriverName, mPQBuf[j]->PQI3().pszDriverName) == 0)) { + found = TRUE; + tmpBuf[cnt] = mPQBuf[j]; + mPQBuf[j] = 0; + } + } + } + if (!found) + tmpBuf[cnt] = new PRTQUEUE (&pPQI3Buf[cnt]); + } + + for (int i=0; i < newQueueCount; i++) { + if (mPQBuf[i] != 0) + delete(mPQBuf[i]); + mPQBuf[i] = tmpBuf[i]; + } + + if (mQueueCount > newQueueCount) + for (int i = newQueueCount; i < mQueueCount; i++) + if (mPQBuf[i] != 0) + delete(mPQBuf[i]); + + mQueueCount = newQueueCount; + free (pPQI3Buf); +} + int PRINTDLG::GetIndex (int numPrinter) { int index; diff --git a/widget/src/os2/nsDeviceContextSpecOS2.h b/widget/src/os2/nsDeviceContextSpecOS2.h index c1802c5143d..587f408865a 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.h +++ b/widget/src/os2/nsDeviceContextSpecOS2.h @@ -79,6 +79,7 @@ class PRINTDLG public: PRINTDLG (); ~PRINTDLG (); + RefreshPrintQueue(); int GetNumPrinters (); int GetDefaultPrinter (); void GetPrinter (int numPrinter, char** printerName);