2006-02-16 21:32:25 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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
|
1999-06-28 23:39:35 +00:00
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
2006-02-16 21:32:25 +00:00
|
|
|
* 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.
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla OS/2 libraries.
|
|
|
|
*
|
2006-02-16 21:32:25 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* John Fairhurst, <john_fairhurst@iname.com>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
2006-02-16 21:32:25 +00:00
|
|
|
* Contributor(s):
|
2006-02-16 21:31:33 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2006-02-16 21:32:30 +00:00
|
|
|
* Peter Weilbacher <mozilla@weilbacher.org>
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
2006-02-16 21:32:25 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2006-02-16 21:32:08 +00:00
|
|
|
#include <stdlib.h>
|
2006-02-16 21:31:54 +00:00
|
|
|
#include "nsDeviceContextSpecOS2.h"
|
|
|
|
|
|
|
|
#include "nsReadableUtils.h"
|
2006-02-16 21:31:56 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2006-02-16 21:32:30 +00:00
|
|
|
#include "nsIPref.h"
|
2006-02-16 21:31:54 +00:00
|
|
|
#include "prenv.h" /* for PR_GetEnv */
|
|
|
|
|
2006-02-16 21:32:30 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2006-02-16 21:31:54 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2006-02-16 21:32:01 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2006-02-16 21:32:30 +00:00
|
|
|
#include "nsStringFwd.h"
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:32:18 +00:00
|
|
|
#include "nsOS2Uni.h"
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
PRINTDLG nsDeviceContextSpecOS2::PrnDlg;
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecOS2
|
|
|
|
// The PrinterEnumerator creates the printer info
|
|
|
|
// but the nsDeviceContextSpecOS2 cleans it up
|
|
|
|
// If it gets created (via the Page Setup Dialog) but the user never prints anything
|
|
|
|
// then it will never be delete, so this class takes care of that.
|
|
|
|
class GlobalPrinters {
|
|
|
|
public:
|
|
|
|
static GlobalPrinters* GetInstance() { return &mGlobalPrinters; }
|
|
|
|
~GlobalPrinters() { FreeGlobalPrinters(); }
|
|
|
|
|
|
|
|
void FreeGlobalPrinters();
|
|
|
|
nsresult InitializeGlobalPrinters();
|
|
|
|
|
|
|
|
PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; }
|
|
|
|
PRInt32 GetNumPrinters() { return mGlobalNumPrinters; }
|
|
|
|
nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); }
|
2006-02-16 21:32:00 +00:00
|
|
|
void GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName);
|
2006-02-16 21:31:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GlobalPrinters() {}
|
|
|
|
|
|
|
|
static GlobalPrinters mGlobalPrinters;
|
|
|
|
static nsStringArray* mGlobalPrinterList;
|
2006-02-16 21:32:29 +00:00
|
|
|
static ULONG mGlobalNumPrinters;
|
2006-02-16 21:31:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
//---------------
|
|
|
|
// static members
|
|
|
|
GlobalPrinters GlobalPrinters::mGlobalPrinters;
|
|
|
|
nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull;
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG GlobalPrinters::mGlobalNumPrinters = 0;
|
2006-02-16 21:31:57 +00:00
|
|
|
//---------------
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
/** -------------------------------------------------------
|
|
|
|
* Construct the nsDeviceContextSpecOS2
|
|
|
|
* @update dc 12/02/98
|
|
|
|
*/
|
|
|
|
nsDeviceContextSpecOS2 :: nsDeviceContextSpecOS2()
|
|
|
|
{
|
|
|
|
mQueue = nsnull;
|
1999-06-28 23:39:35 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
/** -------------------------------------------------------
|
|
|
|
* Destroy the nsDeviceContextSpecOS2
|
|
|
|
* @update dc 2/15/98
|
|
|
|
*/
|
|
|
|
nsDeviceContextSpecOS2 :: ~nsDeviceContextSpecOS2()
|
1999-06-28 23:39:35 +00:00
|
|
|
{
|
|
|
|
if( mQueue)
|
|
|
|
PrnClosePrinter( mQueue);
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
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
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
void SetupDevModeFromSettings(ULONG printer, nsIPrintSettings* aPrintSettings)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
|
|
|
if (aPrintSettings) {
|
2006-02-16 21:32:03 +00:00
|
|
|
int bufferSize = 3 * sizeof(DJP_ITEM);
|
|
|
|
PBYTE pDJP_Buffer = new BYTE[bufferSize];
|
|
|
|
memset(pDJP_Buffer, 0, bufferSize);
|
|
|
|
PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer;
|
|
|
|
|
2006-02-16 21:32:02 +00:00
|
|
|
HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer);
|
2006-02-16 21:32:03 +00:00
|
|
|
char* driver = nsDeviceContextSpecOS2::PrnDlg.GetDriverType(printer);
|
2006-02-16 21:32:02 +00:00
|
|
|
|
|
|
|
// Setup Orientation
|
|
|
|
PRInt32 orientation;
|
|
|
|
aPrintSettings->GetOrientation(&orientation);
|
2006-02-16 21:32:03 +00:00
|
|
|
if (!strcmp(driver, "LASERJET"))
|
|
|
|
pDJP->lType = DJP_ALL;
|
|
|
|
else
|
|
|
|
pDJP->lType = DJP_CURRENT;
|
2006-02-16 21:32:02 +00:00
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = DJP_SJ_ORIENTATION;
|
|
|
|
pDJP->ulValue = orientation == nsIPrintSettings::kPortraitOrientation?DJP_ORI_PORTRAIT:DJP_ORI_LANDSCAPE;
|
2006-02-16 21:32:03 +00:00
|
|
|
pDJP++;
|
2006-02-16 21:32:02 +00:00
|
|
|
|
|
|
|
// Setup Number of Copies
|
|
|
|
PRInt32 copies;
|
|
|
|
aPrintSettings->GetNumCopies(&copies);
|
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->lType = DJP_CURRENT;
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = DJP_SJ_COPIES;
|
|
|
|
pDJP->ulValue = copies;
|
2006-02-16 21:32:03 +00:00
|
|
|
pDJP++;
|
|
|
|
|
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->lType = DJP_NONE;
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = 0;
|
|
|
|
pDJP->ulValue = 0;
|
|
|
|
|
2006-02-16 21:32:28 +00:00
|
|
|
LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer);
|
2006-02-16 21:32:29 +00:00
|
|
|
GreEscape (hdc, DEVESC_SETJOBPROPERTIES, bufferSize, pDJP_Buffer,
|
|
|
|
&driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer)));
|
2006-02-16 21:32:02 +00:00
|
|
|
|
2006-02-16 21:32:03 +00:00
|
|
|
delete [] pDJP_Buffer;
|
2006-02-16 21:32:02 +00:00
|
|
|
DevCloseDC(hdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
nsresult nsDeviceContextSpecOS2::SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, ULONG printer)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
|
|
|
if (aPrintSettings == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-02-16 21:32:03 +00:00
|
|
|
int bufferSize = 3 * sizeof(DJP_ITEM);
|
|
|
|
PBYTE pDJP_Buffer = new BYTE[bufferSize];
|
|
|
|
memset(pDJP_Buffer, 0, bufferSize);
|
|
|
|
PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer;
|
|
|
|
|
2006-02-16 21:32:02 +00:00
|
|
|
HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer);
|
|
|
|
|
|
|
|
//Get Number of Copies from Job Properties
|
|
|
|
pDJP->lType = DJP_CURRENT;
|
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = DJP_SJ_COPIES;
|
|
|
|
pDJP->ulValue = 1;
|
2006-02-16 21:32:03 +00:00
|
|
|
pDJP++;
|
2006-02-16 21:32:02 +00:00
|
|
|
|
|
|
|
//Get Orientation from Job Properties
|
2006-02-16 21:32:09 +00:00
|
|
|
pDJP->lType = DJP_CURRENT;
|
2006-02-16 21:32:02 +00:00
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = DJP_SJ_ORIENTATION;
|
|
|
|
pDJP->ulValue = 1;
|
2006-02-16 21:32:03 +00:00
|
|
|
pDJP++;
|
|
|
|
|
|
|
|
pDJP->lType = DJP_NONE;
|
|
|
|
pDJP->cb = sizeof(DJP_ITEM);
|
|
|
|
pDJP->ulNumReturned = 1;
|
|
|
|
pDJP->ulProperty = 0;
|
|
|
|
pDJP->ulValue = 0;
|
|
|
|
|
2006-02-16 21:32:28 +00:00
|
|
|
LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer);
|
|
|
|
LONG rc = GreEscape(hdc, DEVESC_QUERYJOBPROPERTIES, bufferSize, pDJP_Buffer,
|
|
|
|
&driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer)));
|
2006-02-16 21:32:03 +00:00
|
|
|
|
|
|
|
pDJP = (PDJP_ITEM) pDJP_Buffer;
|
|
|
|
if ((rc == DEV_OK) || (rc == DEV_WARNING)) {
|
|
|
|
while (pDJP->lType != DJP_NONE) {
|
|
|
|
if ((pDJP->ulProperty == DJP_SJ_ORIENTATION) && (pDJP->lType > 0)){
|
|
|
|
if ((pDJP->ulValue == DJP_ORI_PORTRAIT) || (pDJP->ulValue == DJP_ORI_REV_PORTRAIT))
|
|
|
|
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
|
|
|
|
else
|
2006-02-16 21:32:02 +00:00
|
|
|
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
|
2006-02-16 21:32:03 +00:00
|
|
|
}
|
|
|
|
if ((pDJP->ulProperty == DJP_SJ_COPIES) && (pDJP->lType > 0)){
|
|
|
|
aPrintSettings->SetNumCopies(PRInt32(pDJP->ulValue));
|
|
|
|
}
|
|
|
|
pDJP = DJP_NEXT_STRUCTP(pDJP);
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-16 21:32:03 +00:00
|
|
|
|
|
|
|
delete [] pDJP_Buffer;
|
2006-02-16 21:32:02 +00:00
|
|
|
DevCloseDC(hdc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecOS2 :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
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)
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
/** -------------------------------------------------------
|
|
|
|
* 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
|
2006-02-16 21:32:06 +00:00
|
|
|
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aPrintPreview )
|
2006-02-16 21:31:54 +00:00
|
|
|
* - Xlib-toolkit:
|
|
|
|
* file: mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp
|
2006-02-16 21:32:06 +00:00
|
|
|
* function: NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aPrintPreview )
|
2006-02-16 21:31:54 +00:00
|
|
|
* - Qt-toolkit:
|
|
|
|
* file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
|
2006-02-16 21:32:06 +00:00
|
|
|
* function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aPrintPreview )
|
2006-02-16 21:31:54 +00:00
|
|
|
*
|
|
|
|
* ** Please update the other toolkits when changing this function.
|
|
|
|
*/
|
2006-02-16 21:32:09 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecOS2::Init(nsIPrintSettings* aPS, PRBool aIsPrintPreview)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2006-02-16 21:31:56 +00:00
|
|
|
mPrintSettings = aPS;
|
|
|
|
NS_ASSERTION(aPS, "Must have a PrintSettings!");
|
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:32:06 +00:00
|
|
|
if (aPS) {
|
|
|
|
PRBool tofile = PR_FALSE;
|
|
|
|
PRInt32 copies = 1;
|
|
|
|
PRUnichar *printer = nsnull;
|
|
|
|
PRUnichar *printfile = nsnull;
|
|
|
|
|
|
|
|
mPrintSettings->GetPrinterName(&printer);
|
|
|
|
mPrintSettings->GetToFileName(&printfile);
|
|
|
|
mPrintSettings->GetPrintToFile(&tofile);
|
|
|
|
mPrintSettings->GetNumCopies(&copies);
|
|
|
|
|
|
|
|
if ((copies == 0) || (copies > 999)) {
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
2006-02-16 21:31:56 +00:00
|
|
|
|
2006-02-16 21:32:06 +00:00
|
|
|
if (printfile != nsnull) {
|
|
|
|
// ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446)
|
|
|
|
strcpy(mPrData.path, NS_ConvertUCS2toUTF8(printfile).get());
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
2006-02-16 21:32:06 +00:00
|
|
|
if (printer != nsnull)
|
|
|
|
strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get());
|
2006-02-16 21:32:09 +00:00
|
|
|
|
|
|
|
if (aIsPrintPreview)
|
|
|
|
mPrData.destination = printPreview;
|
|
|
|
else if (tofile)
|
|
|
|
mPrData.destination = printToFile;
|
|
|
|
else
|
|
|
|
mPrData.destination = printToPrinter;
|
2006-02-16 21:32:06 +00:00
|
|
|
mPrData.copies = copies;
|
|
|
|
|
|
|
|
rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
const nsAFlatString& printerUCS2 = NS_ConvertUTF8toUCS2(mPrData.printer);
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
2006-02-16 21:32:06 +00:00
|
|
|
if (numPrinters) {
|
2006-02-16 21:32:29 +00:00
|
|
|
for(ULONG i = 0; (i < numPrinters) && !mQueue; i++) {
|
2006-02-16 21:32:06 +00:00
|
|
|
if ((GlobalPrinters::GetInstance()->GetStringAt(i)->Equals(printerUCS2, nsCaseInsensitiveStringComparator()))) {
|
|
|
|
SetupDevModeFromSettings(i, aPS);
|
|
|
|
mQueue = PrnDlg.SetPrinterQueue(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (printfile != nsnull)
|
|
|
|
nsMemory::Free(printfile);
|
|
|
|
|
|
|
|
if (printer != nsnull)
|
|
|
|
nsMemory::Free(printer);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:31:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-16 21:32:09 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetDestination( int &aDestination )
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
2006-02-16 21:32:09 +00:00
|
|
|
aDestination = mPrData.destination;
|
2006-02-16 21:31:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:56 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecOS2 :: GetPrinterName ( char **aPrinter )
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:39:35 +00:00
|
|
|
nsresult nsDeviceContextSpecOS2::GetPRTQUEUE( PRTQUEUE *&p)
|
|
|
|
{
|
|
|
|
p = mQueue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
// Printer Enumerator
|
|
|
|
nsPrinterEnumeratorOS2::nsPrinterEnumeratorOS2()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorOS2, nsIPrinterEnumerator)
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorOS2::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
|
|
|
|
{
|
2006-02-16 21:31:56 +00:00
|
|
|
NS_ENSURE_ARG(aCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
if (aCount)
|
|
|
|
*aCount = 0;
|
|
|
|
else
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aResult)
|
|
|
|
*aResult = nsnull;
|
|
|
|
else
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-02-16 21:32:21 +00:00
|
|
|
|
|
|
|
nsDeviceContextSpecOS2::PrnDlg.RefreshPrintQueue();
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
|
|
|
|
if (!array && numPrinters > 0) {
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:31:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-02-16 21:31:57 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG count = 0;
|
2006-02-16 21:31:57 +00:00
|
|
|
while( count < numPrinters )
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
2006-02-16 21:31:57 +00:00
|
|
|
PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
if (!str) {
|
2006-02-16 21:32:29 +00:00
|
|
|
for (ULONG i = 0 ; i < count ; i++)
|
2006-02-16 21:31:54 +00:00
|
|
|
nsMemory::Free(array[i]);
|
|
|
|
|
|
|
|
nsMemory::Free(array);
|
2006-02-16 21:31:57 +00:00
|
|
|
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:31:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
array[count++] = str;
|
|
|
|
|
|
|
|
}
|
|
|
|
*aCount = count;
|
|
|
|
*aResult = array;
|
2006-02-16 21:31:57 +00:00
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:00 +00:00
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorOS2::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
|
|
|
|
GlobalPrinters::GetInstance()->GetDefaultPrinterName(*aDefaultPrinterName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
|
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorOS2::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
|
|
|
|
{
|
2006-02-16 21:32:02 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrinterName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
|
|
|
|
|
|
|
if (!*aPrinterName)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (NS_FAILED(GlobalPrinters::GetInstance()->InitializeGlobalPrinters()))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
|
|
|
for(ULONG i = 0; i < numPrinters; i++) {
|
2006-02-16 21:32:02 +00:00
|
|
|
if ((GlobalPrinters::GetInstance()->GetStringAt(i)->Equals(aPrinterName, nsCaseInsensitiveStringComparator())))
|
|
|
|
nsDeviceContextSpecOS2::SetPrintSettingsFromDevMode(aPrintSettings, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free them, we won't need them for a while
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:32:16 +00:00
|
|
|
aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE);
|
2006-02-16 21:32:02 +00:00
|
|
|
return NS_OK;
|
2006-02-16 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:56 +00:00
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorOS2::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
2006-02-16 21:31:57 +00:00
|
|
|
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
ULONG numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
|
|
|
for(ULONG i = 0; i < numPrinters; i++) {
|
2006-02-16 21:32:01 +00:00
|
|
|
if ((GlobalPrinters::GetInstance()->GetStringAt(i)->Equals(aPrinter, nsCaseInsensitiveStringComparator()))) {
|
2006-02-16 21:32:02 +00:00
|
|
|
SetupDevModeFromSettings(i, aPrintSettings);
|
|
|
|
if ( nsDeviceContextSpecOS2::PrnDlg.ShowProperties(i) ) {
|
|
|
|
nsDeviceContextSpecOS2::SetPrintSettingsFromDevMode(aPrintSettings, i);
|
2006-02-16 21:31:57 +00:00
|
|
|
return NS_OK;
|
2006-02-16 21:32:02 +00:00
|
|
|
} else {
|
2006-02-16 21:31:57 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
2006-02-16 21:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GlobalPrinters::InitializeGlobalPrinters ()
|
|
|
|
{
|
|
|
|
if (PrintersAreAllocated())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mGlobalNumPrinters = 0;
|
|
|
|
mGlobalNumPrinters = nsDeviceContextSpecOS2::PrnDlg.GetNumPrinters();
|
|
|
|
if (!mGlobalNumPrinters)
|
|
|
|
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
|
|
|
|
|
|
|
|
mGlobalPrinterList = new nsStringArray();
|
|
|
|
if (!mGlobalPrinterList)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2006-02-16 21:32:30 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
|
|
|
BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature
|
|
|
|
|
|
|
|
for (ULONG i = 0; i < mGlobalNumPrinters; i++) {
|
2006-02-16 21:32:09 +00:00
|
|
|
nsXPIDLCString printer;
|
|
|
|
nsDeviceContextSpecOS2::PrnDlg.GetPrinter(i, getter_Copies(printer));
|
2006-02-16 21:32:26 +00:00
|
|
|
|
|
|
|
nsAutoChar16Buffer printerName;
|
|
|
|
PRInt32 printerNameLength;
|
2006-02-16 21:32:30 +00:00
|
|
|
rv = MultiByteToWideChar(0, printer, strlen(printer),
|
|
|
|
printerName, printerNameLength);
|
2006-02-16 21:32:31 +00:00
|
|
|
mGlobalPrinterList->AppendString(nsDependentString(printerName.get()));
|
|
|
|
|
2006-02-16 21:32:30 +00:00
|
|
|
// store printer description in prefs for the print dialog
|
|
|
|
if (!prefFailed) {
|
|
|
|
nsCAutoString printerDescription;
|
|
|
|
printerDescription = nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(i)->szDeviceName);
|
|
|
|
printerDescription += " (";
|
|
|
|
printerDescription += nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetDriverType(i));
|
|
|
|
printerDescription += ")";
|
|
|
|
pPrefs->SetCharPref(nsPrintfCString(256,
|
|
|
|
"print.printer_%s.printer_description",
|
|
|
|
printer.get()).get(),
|
|
|
|
printerDescription.get());
|
|
|
|
}
|
2006-02-16 21:31:57 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:00 +00:00
|
|
|
void GlobalPrinters::GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName)
|
|
|
|
{
|
|
|
|
aDefaultPrinterName = nsnull;
|
|
|
|
|
2006-02-16 21:32:22 +00:00
|
|
|
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2006-02-16 21:32:11 +00:00
|
|
|
if (GetNumPrinters() == 0)
|
|
|
|
return;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
// the default printer is always index 0
|
2006-02-16 21:32:09 +00:00
|
|
|
nsXPIDLCString printer;
|
2006-02-16 21:32:31 +00:00
|
|
|
nsDeviceContextSpecOS2::PrnDlg.GetPrinter(0, getter_Copies(printer));
|
2006-02-16 21:32:00 +00:00
|
|
|
|
2006-02-16 21:32:26 +00:00
|
|
|
nsAutoChar16Buffer printerName;
|
|
|
|
PRInt32 printerNameLength;
|
|
|
|
MultiByteToWideChar(0, printer, strlen(printer), printerName,
|
|
|
|
printerNameLength);
|
|
|
|
aDefaultPrinterName = ToNewUnicode(nsDependentString(printerName.get()));
|
2006-02-16 21:32:22 +00:00
|
|
|
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-16 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:31:57 +00:00
|
|
|
void GlobalPrinters::FreeGlobalPrinters()
|
|
|
|
{
|
|
|
|
delete mGlobalPrinterList;
|
|
|
|
mGlobalPrinterList = nsnull;
|
|
|
|
mGlobalNumPrinters = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-16 21:31:54 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// OS/2 Printing - was in libprint.cpp
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
static HMODULE hmodRes;
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
void PRTQUEUE::InitWithPQI3(const PRQINFO3* pInfo)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
PRINTDLG::PRINTDLG()
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
mQueueCount = 0;
|
|
|
|
|
|
|
|
ULONG TotalQueues = 0;
|
|
|
|
ULONG MemNeeded = 0;
|
|
|
|
SPLERR rc;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
rc = ::SplEnumQueue(NULL, 3, NULL, 0, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
|
2006-02-16 21:31:54 +00:00
|
|
|
PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded);
|
2006-02-16 21:32:31 +00:00
|
|
|
rc = ::SplEnumQueue(NULL, 3, pPQI3Buf, MemNeeded, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
if (mQueueCount > MAX_PRINT_QUEUES)
|
|
|
|
mQueueCount = MAX_PRINT_QUEUES;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
ULONG defaultQueue = 0;
|
|
|
|
for (ULONG cnt = 0; cnt < mQueueCount; cnt++) {
|
|
|
|
if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
|
|
|
|
defaultQueue = cnt;
|
|
|
|
mPQBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
// 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);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
PRINTDLG::~PRINTDLG()
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
2006-02-16 21:32:31 +00:00
|
|
|
for (ULONG index = 0; index < mQueueCount; index++)
|
|
|
|
delete mPQBuf[index];
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:27 +00:00
|
|
|
void PRINTDLG::RefreshPrintQueue()
|
2006-02-16 21:32:21 +00:00
|
|
|
{
|
|
|
|
ULONG newQueueCount = 0;
|
|
|
|
ULONG TotalQueues = 0;
|
|
|
|
ULONG MemNeeded = 0;
|
|
|
|
SPLERR rc;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
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);
|
2006-02-16 21:32:21 +00:00
|
|
|
|
|
|
|
if (newQueueCount > MAX_PRINT_QUEUES)
|
|
|
|
newQueueCount = MAX_PRINT_QUEUES;
|
|
|
|
|
|
|
|
PRTQUEUE* tmpBuf[MAX_PRINT_QUEUES];
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
ULONG defaultQueue = 0;
|
|
|
|
for (ULONG cnt = 0; cnt < newQueueCount; cnt++) {
|
|
|
|
if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
|
|
|
|
defaultQueue = cnt;
|
2006-02-16 21:32:21 +00:00
|
|
|
|
|
|
|
BOOL found = FALSE;
|
2006-02-16 21:32:31 +00:00
|
|
|
for (ULONG index = 0; index < mQueueCount && !found; index++) {
|
2006-02-16 21:32:21 +00:00
|
|
|
//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
|
2006-02-16 21:32:31 +00:00
|
|
|
if (mPQBuf[index] != 0) {
|
|
|
|
if ((strcmp(pPQI3Buf[cnt].pszPrinters, mPQBuf[index]->PrinterName()) == 0) &&
|
|
|
|
(strcmp(pPQI3Buf[cnt].pszDriverName, mPQBuf[index]->PQI3().pszDriverName) == 0)) {
|
2006-02-16 21:32:21 +00:00
|
|
|
found = TRUE;
|
2006-02-16 21:32:31 +00:00
|
|
|
tmpBuf[cnt] = mPQBuf[index];
|
|
|
|
mPQBuf[index] = 0;
|
2006-02-16 21:32:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
2006-02-16 21:32:31 +00:00
|
|
|
tmpBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
|
2006-02-16 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
for (ULONG index = 0; index < newQueueCount; index++) {
|
|
|
|
if (mPQBuf[index] != 0)
|
|
|
|
delete(mPQBuf[index]);
|
|
|
|
mPQBuf[index] = tmpBuf[index];
|
2006-02-16 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mQueueCount > newQueueCount)
|
2006-02-16 21:32:31 +00:00
|
|
|
for (ULONG index = newQueueCount; index < mQueueCount; index++)
|
|
|
|
if (mPQBuf[index] != 0)
|
|
|
|
delete(mPQBuf[index]);
|
2006-02-16 21:32:21 +00:00
|
|
|
|
|
|
|
mQueueCount = newQueueCount;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
free(pPQI3Buf);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
ULONG PRINTDLG::GetNumPrinters()
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
return mQueueCount;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
void PRINTDLG::GetPrinter(ULONG printerNdx, char** printerName)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
2006-02-16 21:32:31 +00:00
|
|
|
if (printerNdx >= mQueueCount)
|
2006-02-16 21:32:20 +00:00
|
|
|
return;
|
2006-02-16 21:32:09 +00:00
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
nsCAutoString pName(mPQBuf[printerNdx]->QueueName());
|
2006-02-16 21:32:09 +00:00
|
|
|
|
2006-02-16 21:32:07 +00:00
|
|
|
pName.ReplaceChar('\r', ' ');
|
|
|
|
pName.StripChars("\n");
|
2006-02-16 21:32:09 +00:00
|
|
|
*printerName = ToNewCString(pName);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
PRTQUEUE* PRINTDLG::SetPrinterQueue(ULONG printerNdx)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
PRTQUEUE *pPQ = NULL;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
if (printerNdx >= mQueueCount)
|
2006-02-16 21:31:54 +00:00
|
|
|
return NULL;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
pPQ = mPQBuf[printerNdx];
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
return new PRTQUEUE(*pPQ);
|
2006-02-16 21:31:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
LONG PRINTDLG::GetPrintDriverSize(ULONG printerNdx)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
2006-02-16 21:32:31 +00:00
|
|
|
return mPQBuf[printerNdx]->PQI3().pDriverData->cb;
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
PDRIVDATA PRINTDLG::GetPrintDriver(ULONG printerNdx)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
2006-02-16 21:32:31 +00:00
|
|
|
if (printerNdx >= mQueueCount)
|
2006-02-16 21:32:02 +00:00
|
|
|
return NULL;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
return mPQBuf[printerNdx]->PQI3().pDriverData;
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
HDC PRINTDLG::GetDCHandle(ULONG printerNdx)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
|
|
|
HDC hdc = 0;
|
|
|
|
DEVOPENSTRUC dop;
|
|
|
|
|
|
|
|
dop.pszLogAddress = 0;
|
2006-02-16 21:32:31 +00:00
|
|
|
dop.pszDriverName = (char *)mPQBuf[printerNdx]->DriverName();
|
|
|
|
dop.pdriv = mPQBuf[printerNdx]->PQI3().pDriverData;
|
2006-02-16 21:32:02 +00:00
|
|
|
dop.pszDataType = 0;
|
|
|
|
dop.pszComment = 0;
|
|
|
|
dop.pszQueueProcName = 0;
|
|
|
|
dop.pszQueueProcParams = 0;
|
|
|
|
dop.pszSpoolerParams = 0;
|
|
|
|
dop.pszNetworkParams = 0;
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
hdc = ::DevOpenDC(0, OD_INFO, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
|
2006-02-16 21:32:02 +00:00
|
|
|
return hdc;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
char* PRINTDLG::GetDriverType(ULONG printerNdx)
|
2006-02-16 21:32:02 +00:00
|
|
|
{
|
2006-02-16 21:32:31 +00:00
|
|
|
return (char *)mPQBuf[printerNdx]->DriverName ();
|
2006-02-16 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
BOOL PRINTDLG::ShowProperties(ULONG printerNdx)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
2006-02-16 21:32:29 +00:00
|
|
|
LONG devrc = FALSE;
|
2006-02-16 21:31:54 +00:00
|
|
|
PDRIVDATA pOldDrivData;
|
|
|
|
PDRIVDATA pNewDrivData = NULL;
|
|
|
|
LONG buflen;
|
|
|
|
|
|
|
|
/* check size of buffer required for job properties */
|
|
|
|
buflen = DevPostDeviceModes( 0 /*hab*/,
|
|
|
|
NULL,
|
2006-02-16 21:32:31 +00:00
|
|
|
mPQBuf[printerNdx]->DriverName (),
|
|
|
|
mPQBuf[printerNdx]->DeviceName (),
|
|
|
|
mPQBuf[printerNdx]->PrinterName (),
|
2006-02-16 21:31:54 +00:00
|
|
|
DPDM_POSTJOBPROP);
|
|
|
|
|
|
|
|
/* return error to caller */
|
|
|
|
if (buflen <= 0)
|
|
|
|
return(buflen);
|
|
|
|
|
|
|
|
/* allocate some memory for larger job properties and */
|
|
|
|
/* return error to caller */
|
|
|
|
|
2006-02-16 21:32:31 +00:00
|
|
|
if (buflen != mPQBuf[printerNdx]->PQI3().pDriverData->cb)
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
if (DosAllocMem((PPVOID)&pNewDrivData,buflen,fALLOC))
|
2006-02-16 21:32:20 +00:00
|
|
|
return(FALSE); // DPDM_ERROR
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
/* copy over old data so driver can use old job */
|
|
|
|
/* properties as base for job properties dialog */
|
2006-02-16 21:32:31 +00:00
|
|
|
pOldDrivData = mPQBuf[printerNdx]->PQI3().pDriverData;
|
|
|
|
mPQBuf[printerNdx]->PQI3().pDriverData = pNewDrivData;
|
2006-02-16 21:31:54 +00:00
|
|
|
memcpy( (PSZ)pNewDrivData, (PSZ)pOldDrivData, pOldDrivData->cb );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* display job properties dialog and get updated */
|
|
|
|
/* job properties from driver */
|
|
|
|
|
|
|
|
devrc = DevPostDeviceModes( 0 /*hab*/,
|
2006-02-16 21:32:31 +00:00
|
|
|
mPQBuf[printerNdx]->PQI3().pDriverData,
|
|
|
|
mPQBuf[printerNdx]->DriverName (),
|
|
|
|
mPQBuf[printerNdx]->DeviceName (),
|
|
|
|
mPQBuf[printerNdx]->PrinterName (),
|
2006-02-16 21:31:54 +00:00
|
|
|
DPDM_POSTJOBPROP);
|
|
|
|
rc = (devrc != DPDM_ERROR);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Job management */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2006-02-16 21:32:09 +00:00
|
|
|
HDC PrnOpenDC( PRTQUEUE *pInfo, PSZ pszApplicationName, int copies, int destination, char *file )
|
2006-02-16 21:31:54 +00:00
|
|
|
{
|
|
|
|
HDC hdc = 0;
|
|
|
|
PSZ pszLogAddress;
|
|
|
|
PSZ pszDataType;
|
|
|
|
LONG dcType;
|
|
|
|
DEVOPENSTRUC dop;
|
|
|
|
|
2006-02-16 21:31:55 +00:00
|
|
|
if (!pInfo || !pszApplicationName)
|
|
|
|
return hdc;
|
|
|
|
|
2006-02-16 21:32:09 +00:00
|
|
|
if ( destination ) {
|
2006-02-16 21:31:54 +00:00
|
|
|
pszLogAddress = pInfo->PQI3 ().pszName;
|
|
|
|
pszDataType = "PM_Q_STD";
|
2006-02-16 21:32:09 +00:00
|
|
|
if ( destination == 2 )
|
|
|
|
dcType = OD_METAFILE;
|
|
|
|
else
|
|
|
|
dcType = OD_QUEUED;
|
2006-02-16 21:31:54 +00:00
|
|
|
} else {
|
2006-02-16 21:32:17 +00:00
|
|
|
if (file && *file)
|
2006-02-16 21:31:54 +00:00
|
|
|
pszLogAddress = (PSZ) file;
|
|
|
|
else
|
|
|
|
pszLogAddress = "FILE";
|
|
|
|
pszDataType = "PM_Q_RAW";
|
|
|
|
dcType = OD_DIRECT;
|
|
|
|
}
|
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
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 = 0;
|
|
|
|
dop.pszSpoolerParams = 0;
|
|
|
|
dop.pszNetworkParams = 0;
|
2006-02-16 21:31:54 +00:00
|
|
|
|
2006-02-16 21:32:29 +00:00
|
|
|
hdc = ::DevOpenDC( 0, dcType, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
|
2006-02-16 21:31:54 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2006-02-16 21:32:29 +00:00
|
|
|
if (hdc == 0)
|
|
|
|
{
|
|
|
|
ULONG ErrorCode = ERRORIDERROR (::WinGetLastError (0));
|
|
|
|
printf ("!ERROR! - Can't open DC for printer %04lX\a\n", ErrorCode);
|
|
|
|
}
|
2006-02-16 21:31:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return hdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|