зеркало из https://github.com/mozilla/gecko-dev.git
Bug 154883 - Use session printing APIs on Mac OSX. r=pinkerton/sr=sfraser/a=asa
This commit is contained in:
Родитель
d56281d5e3
Коммит
e096b2864f
|
@ -39,7 +39,6 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#define PM_USE_SESSION_APIS 0
|
|
||||||
#include "nsDeviceContextSpecX.h"
|
#include "nsDeviceContextSpecX.h"
|
||||||
|
|
||||||
#include "prmem.h"
|
#include "prmem.h"
|
||||||
|
@ -54,7 +53,7 @@
|
||||||
* @update dc 12/02/98
|
* @update dc 12/02/98
|
||||||
*/
|
*/
|
||||||
nsDeviceContextSpecX::nsDeviceContextSpecX()
|
nsDeviceContextSpecX::nsDeviceContextSpecX()
|
||||||
: mPrintingContext(0)
|
: mPrintSession(0)
|
||||||
, mPageFormat(kPMNoPageFormat)
|
, mPageFormat(kPMNoPageFormat)
|
||||||
, mPrintSettings(kPMNoPrintSettings)
|
, mPrintSettings(kPMNoPrintSettings)
|
||||||
, mSavedPort(0)
|
, mSavedPort(0)
|
||||||
|
@ -81,19 +80,14 @@ NS_IMPL_ISUPPORTS2(nsDeviceContextSpecX, nsIDeviceContextSpec, nsIPrintingContex
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIPrintSettings* aPS, PRBool aIsPrintPreview)
|
NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIPrintSettings* aPS, PRBool aIsPrintPreview)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
OSStatus status;
|
|
||||||
|
|
||||||
if (!aIsPrintPreview) {
|
|
||||||
status = ::PMBegin();
|
|
||||||
if (status != noErr)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
mBeganPrinting = PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPrintSettingsX> printSettingsX(do_QueryInterface(aPS));
|
nsCOMPtr<nsIPrintSettingsX> printSettingsX(do_QueryInterface(aPS));
|
||||||
if (!printSettingsX)
|
if (!printSettingsX)
|
||||||
return NS_ERROR_NO_INTERFACE;
|
return NS_ERROR_NO_INTERFACE;
|
||||||
|
|
||||||
|
rv = printSettingsX->GetNativePrintSession(&mPrintSession);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
rv = printSettingsX->GetPMPageFormat(&mPageFormat);
|
rv = printSettingsX->GetPMPageFormat(&mPageFormat);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -116,15 +110,6 @@ NS_IMETHODIMP nsDeviceContextSpecX::PrintManagerOpen(PRBool* aIsOpen)
|
||||||
*/
|
*/
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::ClosePrintManager()
|
NS_IMETHODIMP nsDeviceContextSpecX::ClosePrintManager()
|
||||||
{
|
{
|
||||||
if (mPrintSettings != kPMNoPrintSettings)
|
|
||||||
::PMDisposePrintSettings(mPrintSettings);
|
|
||||||
|
|
||||||
if (mPageFormat != kPMNoPageFormat)
|
|
||||||
::PMDisposePageFormat(mPageFormat);
|
|
||||||
|
|
||||||
if (mBeganPrinting)
|
|
||||||
::PMEnd();
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +123,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(PRInt32 aStartPage,
|
||||||
status = ::PMSetLastPage(mPrintSettings, aEndPage, false);
|
status = ::PMSetLastPage(mPrintSettings, aEndPage, false);
|
||||||
NS_ASSERTION(status == noErr, "PMSetLastPage failed");
|
NS_ASSERTION(status == noErr, "PMSetLastPage failed");
|
||||||
|
|
||||||
status = ::PMBeginDocument(mPrintSettings, mPageFormat, &mPrintingContext);
|
status = ::PMSessionBeginDocument(mPrintSession, mPrintSettings, mPageFormat);
|
||||||
if (status != noErr) return NS_ERROR_ABORT;
|
if (status != noErr) return NS_ERROR_ABORT;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -146,8 +131,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(PRInt32 aStartPage,
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::EndDocument()
|
NS_IMETHODIMP nsDeviceContextSpecX::EndDocument()
|
||||||
{
|
{
|
||||||
::PMEndDocument(mPrintingContext);
|
::PMSessionEndDocument(mPrintSession);
|
||||||
mPrintingContext = 0;
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,38 +142,45 @@ NS_IMETHODIMP nsDeviceContextSpecX::AbortDocument()
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::BeginPage()
|
NS_IMETHODIMP nsDeviceContextSpecX::BeginPage()
|
||||||
{
|
{
|
||||||
// see http://devworld.apple.com/techpubs/carbon/graphics/CarbonPrintingManager/Carbon_Printing_Manager/Functions/PMSessionBeginPage.html
|
OSStatus status = ::PMSessionBeginPage(mPrintSession, mPageFormat, NULL);
|
||||||
OSStatus status = ::PMBeginPage(mPrintingContext, NULL);
|
|
||||||
if (status != noErr) return NS_ERROR_ABORT;
|
if (status != noErr) return NS_ERROR_ABORT;
|
||||||
|
|
||||||
::GetPort(&mSavedPort);
|
::GetPort(&mSavedPort);
|
||||||
GrafPtr printingPort;
|
void *graphicsContext;
|
||||||
status = ::PMGetGrafPtr(mPrintingContext, &printingPort);
|
status = ::PMSessionGetGraphicsContext(mPrintSession, kPMGraphicsContextQuickdraw, &graphicsContext);
|
||||||
if (status != noErr) return NS_ERROR_ABORT;
|
if (status != noErr)
|
||||||
::SetPort(printingPort);
|
return NS_ERROR_ABORT;
|
||||||
|
::SetPort((CGrafPtr)graphicsContext);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::EndPage()
|
NS_IMETHODIMP nsDeviceContextSpecX::EndPage()
|
||||||
{
|
{
|
||||||
OSStatus status = ::PMEndPage(mPrintingContext);
|
OSStatus status = ::PMSessionEndPage(mPrintSession);
|
||||||
if (mSavedPort)
|
if (mSavedPort)
|
||||||
{
|
{
|
||||||
::SetPort(mSavedPort);
|
::SetPort(mSavedPort);
|
||||||
mSavedPort = 0;
|
mSavedPort = 0;
|
||||||
}
|
}
|
||||||
if (status != noErr) return NS_ERROR_ABORT;
|
if (status != noErr)
|
||||||
|
return NS_ERROR_ABORT;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::GetPrinterResolution(double* aResolution)
|
NS_IMETHODIMP nsDeviceContextSpecX::GetPrinterResolution(double* aResolution)
|
||||||
{
|
{
|
||||||
PMResolution defaultResolution;
|
PMPrinter printer;
|
||||||
OSStatus status = ::PMGetPrinterResolution(kPMDefaultResolution, &defaultResolution);
|
OSStatus status = ::PMSessionGetCurrentPrinter(mPrintSession, &printer);
|
||||||
if (status == noErr)
|
if (status != noErr)
|
||||||
*aResolution = defaultResolution.hRes;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
return (status == noErr ? NS_OK : NS_ERROR_FAILURE);
|
PMResolution defaultResolution;
|
||||||
|
status = ::PMPrinterGetPrinterResolution(printer, kPMDefaultResolution, &defaultResolution);
|
||||||
|
if (status != noErr)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
*aResolution = defaultResolution.hRes;
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceContextSpecX::GetPageRect(double* aTop, double* aLeft, double* aBottom, double* aRight)
|
NS_IMETHODIMP nsDeviceContextSpecX::GetPageRect(double* aTop, double* aLeft, double* aBottom, double* aRight)
|
||||||
|
|
|
@ -103,7 +103,7 @@ protected:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
PMPrintContext mPrintingContext; // printing context (non-session APIs)
|
PMPrintSession mPrintSession; // printing context.
|
||||||
PMPageFormat mPageFormat; // page format.
|
PMPageFormat mPageFormat; // page format.
|
||||||
PMPrintSettings mPrintSettings; // print settings.
|
PMPrintSettings mPrintSettings; // print settings.
|
||||||
CGrafPtr mSavedPort; // saved graphics port.
|
CGrafPtr mSavedPort; // saved graphics port.
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#define PM_USE_SESSION_APIS 0
|
|
||||||
#include <PMApplication.h>
|
#include <PMApplication.h>
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#include "nsPrintSettingsX.h"
|
#include "nsPrintSettingsX.h"
|
||||||
|
#include "nsIPrintSessionX.h"
|
||||||
|
|
||||||
#include "nsIPrefService.h"
|
#include "nsIPrefService.h"
|
||||||
#include "nsIPrefBranch.h"
|
#include "nsIPrefBranch.h"
|
||||||
|
@ -80,9 +81,13 @@ nsPrintSettingsX::nsPrintSettingsX(const nsPrintSettingsX& src) :
|
||||||
nsPrintSettingsX::~nsPrintSettingsX()
|
nsPrintSettingsX::~nsPrintSettingsX()
|
||||||
{
|
{
|
||||||
if (mPageFormat != kPMNoPageFormat) {
|
if (mPageFormat != kPMNoPageFormat) {
|
||||||
::PMDisposePageFormat(mPageFormat);
|
::PMRelease(mPageFormat);
|
||||||
mPageFormat = kPMNoPageFormat;
|
mPageFormat = kPMNoPageFormat;
|
||||||
}
|
}
|
||||||
|
if (mPrintSettings != kPMNoPrintSettings) {
|
||||||
|
::PMRelease(mPrintSettings);
|
||||||
|
mPrintSettings = kPMNoPrintSettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -98,34 +103,34 @@ nsPrintSettingsX& nsPrintSettingsX::operator=(const nsPrintSettingsX& rhs)
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
|
|
||||||
if (mPageFormat != kPMNoPageFormat) {
|
if (mPageFormat != kPMNoPageFormat) {
|
||||||
::PMDisposePageFormat(mPageFormat);
|
::PMRelease(mPageFormat);
|
||||||
mPageFormat = kPMNoPageFormat;
|
mPageFormat = kPMNoPageFormat;
|
||||||
}
|
}
|
||||||
if (rhs.mPageFormat != kPMNoPageFormat) {
|
if (rhs.mPageFormat != kPMNoPageFormat) {
|
||||||
PMPageFormat pageFormat;
|
PMPageFormat pageFormat;
|
||||||
status = ::PMNewPageFormat(&pageFormat);
|
status = ::PMCreatePageFormat(&pageFormat);
|
||||||
if (status == noErr) {
|
if (status == noErr) {
|
||||||
status = ::PMCopyPageFormat(rhs.mPageFormat, pageFormat);
|
status = ::PMCopyPageFormat(rhs.mPageFormat, pageFormat);
|
||||||
if (status == noErr)
|
if (status == noErr)
|
||||||
mPageFormat = pageFormat;
|
mPageFormat = pageFormat;
|
||||||
else
|
else
|
||||||
::PMDisposePageFormat(pageFormat);
|
::PMRelease(pageFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPrintSettings != kPMNoPrintSettings) {
|
if (mPrintSettings != kPMNoPrintSettings) {
|
||||||
::PMDisposePrintSettings(mPrintSettings);
|
::PMRelease(mPrintSettings);
|
||||||
mPrintSettings = kPMNoPrintSettings;
|
mPrintSettings = kPMNoPrintSettings;
|
||||||
}
|
}
|
||||||
if (rhs.mPrintSettings != kPMNoPrintSettings) {
|
if (rhs.mPrintSettings != kPMNoPrintSettings) {
|
||||||
PMPrintSettings printSettings;
|
PMPrintSettings printSettings;
|
||||||
status = ::PMNewPrintSettings(&printSettings);
|
status = ::PMCreatePrintSettings(&printSettings);
|
||||||
if (status == noErr) {
|
if (status == noErr) {
|
||||||
status = ::PMCopyPrintSettings(rhs.mPrintSettings, printSettings);
|
status = ::PMCopyPrintSettings(rhs.mPrintSettings, printSettings);
|
||||||
if (status == noErr)
|
if (status == noErr)
|
||||||
mPrintSettings = printSettings;
|
mPrintSettings = printSettings;
|
||||||
else
|
else
|
||||||
::PMDisposePrintSettings(printSettings);
|
::PMRelease(printSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,24 +143,40 @@ nsresult nsPrintSettingsX::Init()
|
||||||
{
|
{
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
|
|
||||||
status = ::PMNewPageFormat(&mPageFormat);
|
PMPrintSession printSession = NULL;
|
||||||
if (status != noErr)
|
status = ::PMCreateSession(&printSession);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
status = ::PMNewPrintSettings(&mPrintSettings);
|
|
||||||
if (status != noErr)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
status = ::PMBegin();
|
|
||||||
NS_ASSERTION(status == noErr, "Error from PMBegin()");
|
|
||||||
if (status == noErr) {
|
if (status == noErr) {
|
||||||
status = ::PMDefaultPageFormat(mPageFormat);
|
// First, create a default page format
|
||||||
NS_ASSERTION(status == noErr, "Error from PMDefaultPageFormat()");
|
status = CreateDefaultPageFormat(printSession, mPageFormat);
|
||||||
status = ::PMDefaultPrintSettings(mPrintSettings);
|
|
||||||
NS_ASSERTION(status == noErr, "Error from PMDefaultPrintSettings()");
|
|
||||||
|
|
||||||
::PMEnd();
|
// Then, if no error, create the default print settings
|
||||||
|
if (status == noErr) {
|
||||||
|
status = CreateDefaultPrintSettings(printSession, mPrintSettings);
|
||||||
|
}
|
||||||
|
OSStatus tempStatus = ::PMRelease(printSession);
|
||||||
|
if (status == noErr)
|
||||||
|
status = tempStatus;
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ---------------------------------------------------
|
||||||
|
*/
|
||||||
|
NS_IMETHODIMP nsPrintSettingsX::GetNativePrintSession(PMPrintSession *aNativePrintSession)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aNativePrintSession);
|
||||||
|
*aNativePrintSession = nsnull;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPrintSession> printSession;
|
||||||
|
GetPrintSession(getter_AddRefs(printSession));
|
||||||
|
if (!printSession)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
nsCOMPtr<nsIPrintSessionX> printSessionX(do_QueryInterface(printSession));
|
||||||
|
if (!printSession)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
return printSessionX->GetNativeSession(aNativePrintSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -166,18 +187,10 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPageFormat(PMPageFormat *aPMPageFormat)
|
||||||
*aPMPageFormat = kPMNoPageFormat;
|
*aPMPageFormat = kPMNoPageFormat;
|
||||||
NS_ENSURE_STATE(mPageFormat != kPMNoPageFormat);
|
NS_ENSURE_STATE(mPageFormat != kPMNoPageFormat);
|
||||||
|
|
||||||
PMPageFormat pageFormat;
|
*aPMPageFormat = mPageFormat;
|
||||||
OSStatus status = ::PMNewPageFormat(&pageFormat);
|
OSStatus status = noErr;
|
||||||
if (status != noErr) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
status = ::PMCopyPageFormat(mPageFormat, pageFormat);
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
if (status != noErr) {
|
|
||||||
::PMDisposePageFormat(pageFormat);
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
*aPMPageFormat = pageFormat;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -185,13 +198,14 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPageFormat(PMPageFormat *aPMPageFormat)
|
||||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPMPageFormat)
|
NS_IMETHODIMP nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPMPageFormat)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG(aPMPageFormat);
|
NS_ENSURE_ARG(aPMPageFormat);
|
||||||
NS_ENSURE_STATE(mPageFormat != kPMNoPageFormat);
|
|
||||||
|
|
||||||
OSErr status = ::PMCopyPageFormat(aPMPageFormat, mPageFormat);
|
OSStatus status = ::PMRetain(aPMPageFormat);
|
||||||
if (status != noErr)
|
if (status == noErr) {
|
||||||
return NS_ERROR_FAILURE;
|
if (mPageFormat)
|
||||||
|
status = ::PMRelease(mPageFormat);
|
||||||
return NS_OK;
|
mPageFormat = aPMPageFormat;
|
||||||
|
}
|
||||||
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -202,18 +216,10 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPrintSettings(PMPrintSettings *aPMPrintSett
|
||||||
*aPMPrintSettings = kPMNoPrintSettings;
|
*aPMPrintSettings = kPMNoPrintSettings;
|
||||||
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
||||||
|
|
||||||
PMPrintSettings printSettings;
|
*aPMPrintSettings = mPrintSettings;
|
||||||
OSStatus status = ::PMNewPrintSettings(&printSettings);
|
OSStatus status = noErr;
|
||||||
if (status != noErr) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
status = ::PMCopyPrintSettings(mPrintSettings, printSettings);
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
if (status != noErr) {
|
|
||||||
::PMDisposePrintSettings(printSettings);
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
*aPMPrintSettings = printSettings;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -221,13 +227,14 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPrintSettings(PMPrintSettings *aPMPrintSett
|
||||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPrintSettings(PMPrintSettings aPMPrintSettings)
|
NS_IMETHODIMP nsPrintSettingsX::SetPMPrintSettings(PMPrintSettings aPMPrintSettings)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG(aPMPrintSettings);
|
NS_ENSURE_ARG(aPMPrintSettings);
|
||||||
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
|
||||||
|
|
||||||
OSErr status = ::PMCopyPrintSettings(aPMPrintSettings, mPrintSettings);
|
OSStatus status = ::PMRetain(aPMPrintSettings);
|
||||||
if (status != noErr)
|
if (status == noErr) {
|
||||||
return NS_ERROR_FAILURE;
|
if (mPrintSettings)
|
||||||
|
status = ::PMRelease(mPageFormat);
|
||||||
return NS_OK;
|
mPrintSettings = aPMPrintSettings;
|
||||||
|
}
|
||||||
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ---------------------------------------------------
|
/** ---------------------------------------------------
|
||||||
|
@ -265,16 +272,15 @@ NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
PMPageFormat newPageFormat = kPMNoPageFormat;
|
PMPageFormat newPageFormat = kPMNoPageFormat;
|
||||||
|
|
||||||
status = ::PMNewPageFormat(&newPageFormat);
|
status = ::PMCreatePageFormat(&newPageFormat);
|
||||||
if (status != noErr)
|
if (status == noErr) {
|
||||||
return NS_ERROR_FAILURE;
|
status = ::PMUnflattenPageFormat(decodedDataHandle, &newPageFormat);
|
||||||
status = ::PMUnflattenPageFormat(decodedDataHandle, &newPageFormat);
|
if (status == noErr) {
|
||||||
if (status != noErr)
|
if (mPageFormat)
|
||||||
return NS_ERROR_FAILURE;
|
status = ::PMRelease(mPageFormat);
|
||||||
|
mPageFormat = newPageFormat; // PMCreatePageFormat returned it with a refcnt of 1
|
||||||
status = ::PMCopyPageFormat(newPageFormat, mPageFormat);
|
}
|
||||||
::PMDisposePageFormat(newPageFormat);
|
}
|
||||||
|
|
||||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,3 +341,40 @@ NS_IMETHODIMP nsPrintSettingsX::_Assign(nsIPrintSettings *aPS)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------
|
||||||
|
OSStatus nsPrintSettingsX::CreateDefaultPageFormat(PMPrintSession aSession, PMPageFormat& outFormat)
|
||||||
|
{
|
||||||
|
OSStatus status;
|
||||||
|
PMPageFormat pageFormat;
|
||||||
|
|
||||||
|
outFormat = kPMNoPageFormat;
|
||||||
|
status = ::PMCreatePageFormat(&pageFormat);
|
||||||
|
if (status == noErr && pageFormat != kPMNoPageFormat) {
|
||||||
|
status = ::PMSessionDefaultPageFormat(aSession, pageFormat);
|
||||||
|
if (status == noErr) {
|
||||||
|
outFormat = pageFormat;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------
|
||||||
|
|
||||||
|
OSStatus nsPrintSettingsX::CreateDefaultPrintSettings(PMPrintSession aSession, PMPrintSettings& outSettings)
|
||||||
|
{
|
||||||
|
OSStatus status;
|
||||||
|
PMPrintSettings printSettings;
|
||||||
|
|
||||||
|
outSettings = kPMNoPrintSettings;
|
||||||
|
status = ::PMCreatePrintSettings(&printSettings);
|
||||||
|
if (status == noErr && printSettings != kPMNoPrintSettings) {
|
||||||
|
status = ::PMSessionDefaultPrintSettings(aSession, printSettings);
|
||||||
|
if (status == noErr) {
|
||||||
|
outSettings = printSettings;
|
||||||
|
return noErr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,10 @@ protected:
|
||||||
nsresult _Clone(nsIPrintSettings **_retval);
|
nsresult _Clone(nsIPrintSettings **_retval);
|
||||||
nsresult _Assign(nsIPrintSettings *aPS);
|
nsresult _Assign(nsIPrintSettings *aPS);
|
||||||
|
|
||||||
|
// The out param has a ref count of 1 on return so caller needs to PMRelase() when done.
|
||||||
|
OSStatus CreateDefaultPageFormat(PMPrintSession aSession, PMPageFormat& outFormat);
|
||||||
|
OSStatus CreateDefaultPrintSettings(PMPrintSession aSession, PMPrintSettings& outSettings);
|
||||||
|
|
||||||
PMPageFormat mPageFormat;
|
PMPageFormat mPageFormat;
|
||||||
PMPrintSettings mPrintSettings;
|
PMPrintSettings mPrintSettings;
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче