Bug 185707 [Qt] Get printing working in Qt toolkit

patch by Roland.Mainz@informatik.med.uni-giessen.de r=timeless sr=blizzard (ports)
This commit is contained in:
timeless%mozdev.org 2003-01-06 01:34:47 +00:00
Родитель 96e8f4751b
Коммит 1da4e7cfb2
5 изменённых файлов: 1111 добавлений и 457 удалений

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

@ -22,6 +22,7 @@
* Contributor(s):
* John C. Griggs <johng@corel.com>
* Esben Mose Hansen <esben@despammed.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -51,11 +52,16 @@
#include "nsFont.h"
#include "nsGfxCIID.h"
#include "nsRenderingContextQT.h"
#include "nsDeviceContextSpecQT.h"
#ifdef USE_POSTSCRIPT
#include "nsGfxPSCID.h"
#include "nsIDeviceContextPS.h"
#endif
#endif /* USE_POSTSCRIPT */
#ifdef USE_XPRINT
#include "nsGfxXPrintCID.h"
#include "nsIDeviceContextXPrint.h"
#endif /* USE_XPRINT */
#include <qpaintdevicemetrics.h>
#include <qscrollbar.h>
@ -384,37 +390,69 @@ NS_IMETHODIMP nsDeviceContextQT::GetClientRect(nsRect &aRect)
return GetRect(aRect);
}
NS_IMETHODIMP
nsDeviceContextQT::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
NS_IMETHODIMP nsDeviceContextQT::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
dmsg(ENTER, "GetDeviceContextFor");
nsresult rv;
PrintMethod method;
nsDeviceContextSpecQT *spec = NS_STATIC_CAST(nsDeviceContextSpecQT *, aDevice);
rv = spec->GetPrintMethod(method);
if (NS_FAILED(rv))
return rv;
#ifdef USE_XPRINT
if (method == pmXprint) { // XPRINT
static NS_DEFINE_CID(kCDeviceContextXp, NS_DEVICECONTEXTXP_CID);
nsCOMPtr<nsIDeviceContextXp> dcxp(do_CreateInstance(kCDeviceContextXp, &rv));
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create Xp Device context.");
if (NS_FAILED(rv))
return rv;
rv = dcxp->SetSpec(aDevice);
if (NS_FAILED(rv))
return rv;
rv = dcxp->InitDeviceContextXP((nsIDeviceContext*)aContext,
(nsIDeviceContext*)this);
if (NS_FAILED(rv))
return rv;
rv = dcxp->QueryInterface(NS_GET_IID(nsIDeviceContext),
(void **)&aContext);
return rv;
}
else
#endif /* USE_XPRINT */
#ifdef USE_POSTSCRIPT
if (method == pmPostScript) { // PostScript
// default/PS
static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
// Create a Postscript device context
nsIDeviceContextPS *dcps;
nsCOMPtr<nsIDeviceContextPS> dcps(do_CreateInstance(kCDeviceContextPS, &rv));
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context.");
if (NS_FAILED(rv))
return rv;
rv = nsComponentManager::CreateInstance(kCDeviceContextPS,nsnull,
NS_GET_IID(nsIDeviceContextPS),
(void**)&dcps);
NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't create PS Device context");
rv = dcps->SetSpec(aDevice);
if (NS_FAILED(rv))
return rv;
dcps->SetSpec(aDevice);
dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
rv = dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
(nsIDeviceContext*)this);
if (NS_FAILED(rv))
return rv;
rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
(void **)&aContext);
NS_RELEASE(dcps);
#else
//XXX add xprint support
rv = NS_ERROR_NOT_IMPLEMENTED;
#endif
dmsg(EXIT, "GetDeviceContextFor");
return rv;
}
#endif /* USE_POSTSCRIPT */
NS_WARNING("no print module created.");
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP nsDeviceContextQT::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
{

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -16,11 +16,11 @@
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -39,84 +39,43 @@
#include "nsDeviceContextSpecFactoryQT.h"
#include "nsDeviceContextSpecQT.h"
#include "nsRenderingContextQT.h"
#include "nsGfxCIID.h"
#include "plstr.h"
#include <qapplication.h>
#include "qtlog.h"
#ifdef DEBUG
PRUint32 gDCSpecFactoryCount = 0;
PRUint32 gDCSpecFactoryID = 0;
#endif
/** -------------------------------------------------------
* Constructor
* @update dc 2/16/98
*/
nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT()
{
#ifdef DEBUG
gDCSpecFactoryCount++;
mID = gDCSpecFactoryID++;
PR_LOG(gQTLogModule, QT_BASIC,
("nsDeviceContextSpecFactoryQT CTOR (%p) ID: %d, Count: %d\n",
this, mID, gDCSpecFactoryCount));
#endif
NS_INIT_ISUPPORTS();
}
/** -------------------------------------------------------
* Destructor
* @update dc 2/16/98
*/
nsDeviceContextSpecFactoryQT::~nsDeviceContextSpecFactoryQT()
{
#ifdef DEBUG
gDCSpecFactoryCount--;
PR_LOG(gQTLogModule, QT_BASIC,
("nsDeviceContextSpecFactoryQT DTOR (%p) ID: %d, Count: %d\n",
this, mID, gDCSpecFactoryCount));
#endif
}
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryQT, nsIDeviceContextSpecFactory)
/** -------------------------------------------------------
* Initialize the device context spec factory
* @update dc 2/16/98
*/
nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT()
{
NS_INIT_ISUPPORTS();
}
nsDeviceContextSpecFactoryQT::~nsDeviceContextSpecFactoryQT()
{
}
NS_IMETHODIMP nsDeviceContextSpecFactoryQT::Init(void)
{
return NS_OK;
}
/** -------------------------------------------------------
* Get a device context specification
* @update dc 2/16/98
*/
NS_IMETHODIMP
nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget,
NS_IMETHODIMP nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
nsIDeviceContextSpec *&aNewSpec,
PRBool aIsPrintPreview)
{
nsresult rv = NS_ERROR_FAILURE;
nsIDeviceContextSpec *devSpec = nsnull;
nsComponentManager::CreateInstance(kDeviceContextSpecCID,nsnull,
kIDeviceContextSpecIID,
(void **)&devSpec);
if (nsnull != devSpec) {
if (NS_OK == ((nsDeviceContextSpecQT*)devSpec)->Init(aPrintSettings)) {
nsresult rv;
static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
nsCOMPtr<nsIDeviceContextSpec> devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = ((nsDeviceContextSpecQT *)devSpec.get())->Init(aPrintSettings);
if (NS_SUCCEEDED(rv))
{
aNewSpec = devSpec;
rv = NS_OK;
NS_ADDREF(aNewSpec);
}
}
return rv;
}

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -16,11 +16,11 @@
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -45,6 +45,7 @@
class nsDeviceContextSpecFactoryQT : public nsIDeviceContextSpecFactory
{
public:
nsDeviceContextSpecFactoryQT();
@ -58,10 +59,6 @@ public:
protected:
virtual ~nsDeviceContextSpecFactoryQT();
#ifdef DEBUG
private:
PRUint32 mID;
#endif
};
#endif
#endif /* !nsDeviceContextSpecFactoryQT_h___ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -40,95 +40,91 @@
#ifndef nsDeviceContextSpecQT_h___
#define nsDeviceContextSpecQT_h___
#include "nsCOMPtr.h"
#include "nsIDeviceContextSpec.h"
#include "nsDeviceContextSpecQT.h"
#include "nsIPrintSettings.h"
#include "nsIPrintOptions.h"
#include "nsVoidArray.h"
#include <limits.h>
#ifdef USE_POSTSCRIPT
#include "nsIDeviceContextSpecPS.h"
#endif
#include "nsIPrintSettings.h"
#include "nsCOMPtr.h"
//XXX WHAT IN THE WORLD VV ??
#include "../gtk/nsPrintdGTK.h"
#endif /* USE_POSTSCRIPT */
#ifdef USE_XPRINT
#include "nsIDeviceContextSpecXPrint.h"
#endif /* USE_XPRINT */
class nsDeviceContextSpecQT
: public nsIDeviceContextSpec
#define NS_PORTRAIT 0
#define NS_LANDSCAPE 1
typedef enum
{
pmInvalid = 0,
pmXprint,
pmPostScript
} PrintMethod;
class nsDeviceContextSpecQT : public nsIDeviceContextSpec
#ifdef USE_POSTSCRIPT
, public nsIDeviceContextSpecPS
#endif
#endif /* USE_POSTSCRIPT */
#ifdef USE_XPRINT
, public nsIDeviceContextSpecXp
#endif /* USE_XPRINT */
{
public:
/**
* Construct a nsDeviceContextSpecQT, which is an object which contains and manages a printrecord
* @update dc 12/02/98
*/
nsDeviceContextSpecQT();
NS_DECL_ISUPPORTS
/**
* Initialize the nsDeviceContextSpecQT for use. This will allocate a printrecord for use
* @update dc 2/16/98
* @return error status
*/
NS_IMETHOD Init(nsIPrintSettings* aPS);
/**
* Closes the printmanager if it is open.
* @update dc 2/13/98
* @return error status
*/
NS_IMETHOD ClosePrintManager();
NS_IMETHOD GetToPrinter(PRBool &aToPrinter);
NS_IMETHOD GetPrinterName ( const char **aPrinter );
NS_IMETHOD GetFirstPageFirst(PRBool &aFpf);
NS_IMETHOD GetGrayscale(PRBool &aGrayscale);
NS_IMETHOD GetSize(int &aSize);
NS_IMETHOD GetTopMargin(float &value);
NS_IMETHOD GetBottomMargin(float &value);
NS_IMETHOD GetLeftMargin(float &value);
NS_IMETHOD GetCopies ( int &aCopies );
NS_IMETHOD GetFirstPageFirst(PRBool &aFpf);
NS_IMETHOD GetGrayscale(PRBool &aGrayscale);
NS_IMETHOD GetTopMargin(float &value);
NS_IMETHOD GetBottomMargin(float &value);
NS_IMETHOD GetLeftMargin(float &value);
NS_IMETHOD GetRightMargin(float &value);
NS_IMETHOD GetCommand(const char **aCommand);
NS_IMETHOD GetPath (const char **aPath);
NS_IMETHOD GetPageDimensions(float &aWidth, float &aHeight);
NS_IMETHOD GetLandscape (PRBool &aLandscape);
NS_IMETHOD GetUserCancelled(PRBool &aCancel);
NS_IMETHOD GetPaperName( const char **aPaperName );
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod);
NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight);
protected:
/**
* Destuct a nsDeviceContextSpecQT, this will release the printrecord
* @update dc 2/16/98
*/
NS_IMETHOD GetPaperName(const char **aPaperName);
virtual ~nsDeviceContextSpecQT();
protected:
UnixPrData mPrData;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
#ifdef DEBUG
private:
PRUint32 mID;
#endif
PRBool mToPrinter; /* If PR_TRUE, print to printer */
PRBool mFpf; /* If PR_TRUE, first page first */
PRBool mGrayscale; /* If PR_TRUE, print grayscale */
int mOrientation; /* Orientation e.g. Portrait */
char mCommand[PATH_MAX]; /* Print command e.g., lpr */
char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */
char mPrinter[256]; /* Printer name */
char mPaperName[256]; /* Printer name */
int mCopies; /* number of copies */
PRBool mCancel; /* If PR_TRUE, user cancelled */
float mLeft; /* left margin */
float mRight; /* right margin */
float mTop; /* top margin */
float mBottom; /* bottom margin */
};
#endif
//-------------------------------------------------------------------------
// Printer Enumerator
//-------------------------------------------------------------------------
class nsPrinterEnumeratorQT : public nsIPrinterEnumerator
{
public:
nsPrinterEnumeratorQT();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTERENUMERATOR
};
#endif /* !nsDeviceContextSpecQT_h___ */