2007-01-12 00:54:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-01-12 00:54:29 +03:00
|
|
|
|
|
|
|
#include "nsPrintSettingsX.h"
|
2008-02-21 02:47:05 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-01-12 00:54:29 +03:00
|
|
|
|
|
|
|
#include "plbase64.h"
|
2009-10-09 09:20:37 +04:00
|
|
|
#include "plstr.h"
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
#include "nsCocoaUtils.h"
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2011-05-27 12:15:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
#define MAC_OS_X_PAGE_SETUP_PREFNAME "print.macosx.pagesetup-2"
|
2016-11-10 04:37:40 +03:00
|
|
|
#define COCOA_PAPER_UNITS_PER_INCH 72.0
|
2009-10-09 09:14:31 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsX, nsPrintSettings, nsPrintSettingsX)
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
nsPrintSettingsX::nsPrintSettingsX()
|
2017-10-31 13:25:04 +03:00
|
|
|
: mAdjustedPaperWidth{0.0}
|
|
|
|
, mAdjustedPaperHeight{0.0}
|
2007-01-12 00:54:29 +03:00
|
|
|
{
|
2009-10-09 09:20:37 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
mPrintInfo = [[NSPrintInfo sharedPrintInfo] copy];
|
2016-11-10 04:37:40 +03:00
|
|
|
mWidthScale = COCOA_PAPER_UNITS_PER_INCH;
|
|
|
|
mHeightScale = COCOA_PAPER_UNITS_PER_INCH;
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
nsPrintSettingsX::nsPrintSettingsX(const nsPrintSettingsX& src)
|
2007-01-12 00:54:29 +03:00
|
|
|
{
|
|
|
|
*this = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintSettingsX::~nsPrintSettingsX()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
[mPrintInfo release];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintSettingsX& nsPrintSettingsX::operator=(const nsPrintSettingsX& rhs)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-01-12 00:54:29 +03:00
|
|
|
if (this == &rhs) {
|
|
|
|
return *this;
|
|
|
|
}
|
2017-10-31 13:25:04 +03:00
|
|
|
|
2007-01-12 00:54:29 +03:00
|
|
|
nsPrintSettings::operator=(rhs);
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
[mPrintInfo release];
|
|
|
|
mPrintInfo = [rhs.mPrintInfo copy];
|
2007-01-12 00:54:29 +03:00
|
|
|
|
|
|
|
return *this;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(*this);
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPrintSettingsX::Init()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
InitUnwriteableMargin();
|
2016-11-18 02:29:08 +03:00
|
|
|
InitAdjustedPaperSize();
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
// Should be called whenever the page format changes.
|
2008-03-19 23:51:42 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsX::InitUnwriteableMargin()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
PMPaper paper;
|
|
|
|
PMPaperMargins paperMargin;
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPageFormat pageFormat = GetPMPageFormat();
|
|
|
|
::PMGetPageFormatPaper(pageFormat, &paper);
|
2008-03-19 23:51:42 +03:00
|
|
|
::PMPaperGetMargins(paper, &paperMargin);
|
2010-08-13 13:59:16 +04:00
|
|
|
mUnwriteableMargin.top = NS_POINTS_TO_INT_TWIPS(paperMargin.top);
|
|
|
|
mUnwriteableMargin.left = NS_POINTS_TO_INT_TWIPS(paperMargin.left);
|
|
|
|
mUnwriteableMargin.bottom = NS_POINTS_TO_INT_TWIPS(paperMargin.bottom);
|
|
|
|
mUnwriteableMargin.right = NS_POINTS_TO_INT_TWIPS(paperMargin.right);
|
2008-03-19 23:51:42 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
2017-10-31 13:25:04 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2008-03-19 23:51:42 +03:00
|
|
|
}
|
|
|
|
|
2016-11-18 02:29:08 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsX::InitAdjustedPaperSize()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
PMPageFormat pageFormat = GetPMPageFormat();
|
|
|
|
|
|
|
|
PMRect paperRect;
|
|
|
|
::PMGetAdjustedPaperRect(pageFormat, &paperRect);
|
|
|
|
|
|
|
|
mAdjustedPaperWidth = paperRect.right - paperRect.left;
|
|
|
|
mAdjustedPaperHeight = paperRect.bottom - paperRect.top;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
void
|
|
|
|
nsPrintSettingsX::SetCocoaPrintInfo(NSPrintInfo* aPrintInfo)
|
2007-01-12 00:54:29 +03:00
|
|
|
{
|
2015-05-06 21:10:21 +03:00
|
|
|
if (mPrintInfo != aPrintInfo) {
|
|
|
|
[mPrintInfo release];
|
|
|
|
mPrintInfo = [aPrintInfo retain];
|
|
|
|
}
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString encodedData;
|
2011-05-27 12:15:20 +04:00
|
|
|
nsresult rv =
|
2017-07-31 03:52:51 +03:00
|
|
|
Preferences::GetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
|
2011-05-27 12:15:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-01-12 00:54:29 +03:00
|
|
|
return rv;
|
2011-05-27 12:15:20 +04:00
|
|
|
}
|
2007-01-12 00:54:29 +03:00
|
|
|
|
|
|
|
// decode the base64
|
2012-07-30 18:20:58 +04:00
|
|
|
char* decodedData = PL_Base64Decode(encodedData.get(), encodedData.Length(), nullptr);
|
2013-05-08 07:40:12 +04:00
|
|
|
NSData* data = [NSData dataWithBytes:decodedData length:strlen(decodedData)];
|
2009-10-09 09:20:37 +04:00
|
|
|
if (!data)
|
2007-01-12 00:54:29 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPageFormat newPageFormat;
|
|
|
|
OSStatus status = ::PMPageFormatCreateWithDataRepresentation((CFDataRef)data, &newPageFormat);
|
|
|
|
if (status == noErr) {
|
|
|
|
SetPMPageFormat(newPageFormat);
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
2009-10-09 09:20:37 +04:00
|
|
|
InitUnwriteableMargin();
|
2007-01-12 00:54:29 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPageFormat pageFormat = GetPMPageFormat();
|
|
|
|
if (pageFormat == kPMNoPageFormat)
|
2007-01-12 00:54:29 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2009-10-09 09:20:37 +04:00
|
|
|
|
|
|
|
NSData* data = nil;
|
2018-08-22 05:07:28 +03:00
|
|
|
OSStatus err = ::PMPageFormatCreateDataRepresentation(pageFormat, (CFDataRef*)&data, kPMDataFormatXMLDefault);
|
2007-01-12 00:54:29 +03:00
|
|
|
if (err != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString encodedData;
|
2012-07-30 18:20:58 +04:00
|
|
|
encodedData.Adopt(PL_Base64Encode((char*)[data bytes], [data length], nullptr));
|
2007-01-12 00:54:29 +03:00
|
|
|
if (!encodedData.get())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2011-05-27 12:15:20 +04:00
|
|
|
return Preferences::SetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPrintSettingsX::_Clone(nsIPrintSettings **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2017-10-31 13:25:04 +03:00
|
|
|
|
2007-01-12 00:54:29 +03:00
|
|
|
nsPrintSettingsX *newSettings = new nsPrintSettingsX(*this);
|
|
|
|
if (!newSettings)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*_retval = newSettings;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsX::_Assign(nsIPrintSettings *aPS)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsPrintSettingsX *printSettingsX = static_cast<nsPrintSettingsX*>(aPS);
|
2007-01-12 00:54:29 +03:00
|
|
|
if (!printSettingsX)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
*this = *printSettingsX;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPrintSettings
|
|
|
|
nsPrintSettingsX::GetPMPrintSettings()
|
2007-01-12 00:54:29 +03:00
|
|
|
{
|
2010-02-23 23:04:05 +03:00
|
|
|
return static_cast<PMPrintSettings>([mPrintInfo PMPrintSettings]);
|
2007-01-12 00:54:29 +03:00
|
|
|
}
|
2008-09-25 06:26:58 +04:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPrintSession
|
|
|
|
nsPrintSettingsX::GetPMPrintSession()
|
2007-01-12 00:54:29 +03:00
|
|
|
{
|
2010-02-23 23:04:05 +03:00
|
|
|
return static_cast<PMPrintSession>([mPrintInfo PMPrintSession]);
|
2008-02-21 02:47:05 +03:00
|
|
|
}
|
2009-01-29 11:46:23 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
PMPageFormat
|
|
|
|
nsPrintSettingsX::GetPMPageFormat()
|
2009-01-29 11:46:23 +03:00
|
|
|
{
|
2010-02-23 23:04:05 +03:00
|
|
|
return static_cast<PMPageFormat>([mPrintInfo PMPageFormat]);
|
2009-10-09 09:20:37 +04:00
|
|
|
}
|
2009-01-29 11:46:23 +03:00
|
|
|
|
2009-10-09 09:20:37 +04:00
|
|
|
void
|
|
|
|
nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPageFormat)
|
|
|
|
{
|
|
|
|
PMPageFormat oldPageFormat = GetPMPageFormat();
|
|
|
|
::PMCopyPageFormat(aPageFormat, oldPageFormat);
|
2010-02-23 23:04:05 +03:00
|
|
|
[mPrintInfo updateFromPMPageFormat];
|
2009-01-29 11:46:23 +03:00
|
|
|
}
|
2009-10-09 09:20:37 +04:00
|
|
|
|
2016-11-10 04:37:40 +03:00
|
|
|
void
|
|
|
|
nsPrintSettingsX::SetInchesScale(float aWidthScale, float aHeightScale)
|
|
|
|
{
|
2016-11-18 02:29:08 +03:00
|
|
|
if (aWidthScale > 0 && aHeightScale > 0) {
|
|
|
|
mWidthScale = aWidthScale;
|
|
|
|
mHeightScale = aHeightScale;
|
|
|
|
}
|
2016-11-10 04:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrintSettingsX::GetInchesScale(float *aWidthScale, float *aHeightScale)
|
|
|
|
{
|
|
|
|
*aWidthScale = mWidthScale;
|
|
|
|
*aHeightScale = mHeightScale;
|
|
|
|
}
|
2016-11-18 02:29:08 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsX::SetPaperWidth(double aPaperWidth)
|
|
|
|
{
|
|
|
|
mPaperWidth = aPaperWidth;
|
|
|
|
mAdjustedPaperWidth = aPaperWidth * mWidthScale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsX::SetPaperHeight(double aPaperHeight)
|
|
|
|
{
|
|
|
|
mPaperHeight = aPaperHeight;
|
|
|
|
mAdjustedPaperHeight = aPaperHeight * mHeightScale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::GetEffectivePageSize(double *aWidth, double *aHeight)
|
|
|
|
{
|
2017-05-25 16:11:08 +03:00
|
|
|
*aWidth = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale);
|
|
|
|
*aHeight = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrintSettingsX::GetFilePageSize(double *aWidth, double *aHeight)
|
|
|
|
{
|
|
|
|
double height, width;
|
2017-02-06 05:02:50 +03:00
|
|
|
if (kPaperSizeInches == GetCocoaUnit(mPaperSizeUnit)) {
|
2017-05-25 16:11:08 +03:00
|
|
|
width = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale);
|
|
|
|
height = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale);
|
2017-02-06 05:02:50 +03:00
|
|
|
} else {
|
2017-05-25 16:11:08 +03:00
|
|
|
width = NS_MILLIMETERS_TO_TWIPS(mAdjustedPaperWidth / mWidthScale);
|
|
|
|
height = NS_MILLIMETERS_TO_TWIPS(mAdjustedPaperHeight / mHeightScale);
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
2017-05-25 16:11:08 +03:00
|
|
|
width /= TWIPS_PER_POINT_FLOAT;
|
|
|
|
height /= TWIPS_PER_POINT_FLOAT;
|
|
|
|
|
|
|
|
*aWidth = width;
|
|
|
|
*aHeight = height;
|
2016-11-18 02:29:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintSettingsX::SetAdjustedPaperSize(double aWidth, double aHeight)
|
|
|
|
{
|
|
|
|
mAdjustedPaperWidth = aWidth;
|
|
|
|
mAdjustedPaperHeight = aHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintSettingsX::GetAdjustedPaperSize(double *aWidth, double *aHeight)
|
|
|
|
{
|
|
|
|
*aWidth = mAdjustedPaperWidth;
|
|
|
|
*aHeight = mAdjustedPaperHeight;
|
|
|
|
}
|
2017-02-06 05:02:50 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetScaling(double aScaling)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2017-10-30 21:14:08 +03:00
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
[printInfoDict setObject: [NSNumber numberWithFloat: aScaling]
|
|
|
|
forKey: NSPrintScalingFactor];
|
|
|
|
} else {
|
|
|
|
nsPrintSettings::SetScaling(aScaling);
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2017-06-15 01:06:18 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::GetScaling(double *aScaling)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2017-10-30 21:14:08 +03:00
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSDictionary* printInfoDict = [mPrintInfo dictionary];
|
2017-06-15 01:06:18 +03:00
|
|
|
|
2017-10-30 21:14:08 +03:00
|
|
|
*aScaling =
|
|
|
|
[[printInfoDict objectForKey: NSPrintScalingFactor] doubleValue];
|
2017-06-15 01:06:18 +03:00
|
|
|
|
2017-10-30 21:14:08 +03:00
|
|
|
// Limit scaling precision to whole number percent values
|
|
|
|
*aScaling = round(*aScaling * 100.0) / 100.0;
|
|
|
|
} else {
|
|
|
|
nsPrintSettings::GetScaling(aScaling);
|
|
|
|
}
|
2017-06-15 01:06:18 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2017-02-06 05:02:50 +03:00
|
|
|
NS_IMETHODIMP
|
2017-10-09 02:08:09 +03:00
|
|
|
nsPrintSettingsX::SetToFileName(const nsAString& aToFileName)
|
2017-02-06 05:02:50 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2017-09-10 11:49:30 +03:00
|
|
|
if (XRE_IsContentProcess() &&
|
|
|
|
Preferences::GetBool("print.print_via_parent")) {
|
|
|
|
// On content sandbox, NSPrintJobSavingURL will returns error since
|
|
|
|
// sandbox disallows file access.
|
|
|
|
return nsPrintSettings::SetToFileName(aToFileName);
|
|
|
|
}
|
|
|
|
|
2017-02-06 05:02:50 +03:00
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
|
2017-10-09 02:08:09 +03:00
|
|
|
if (!aToFileName.IsEmpty()) {
|
2017-09-10 11:49:30 +03:00
|
|
|
NSURL* jobSavingURL =
|
2017-10-09 02:08:09 +03:00
|
|
|
[NSURL fileURLWithPath: nsCocoaUtils::ToNSString(aToFileName)];
|
2017-09-10 11:49:30 +03:00
|
|
|
if (jobSavingURL) {
|
|
|
|
[printInfoDict setObject: NSPrintSaveJob forKey: NSPrintJobDisposition];
|
|
|
|
[printInfoDict setObject: jobSavingURL forKey: NSPrintJobSavingURL];
|
|
|
|
}
|
|
|
|
mToFileName = aToFileName;
|
|
|
|
} else {
|
|
|
|
mToFileName.Truncate();
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::GetOrientation(int32_t *aOrientation)
|
|
|
|
{
|
2017-10-30 21:14:08 +03:00
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
if ([mPrintInfo orientation] == NS_PAPER_ORIENTATION_PORTRAIT) {
|
|
|
|
*aOrientation = nsIPrintSettings::kPortraitOrientation;
|
|
|
|
} else {
|
|
|
|
*aOrientation = nsIPrintSettings::kLandscapeOrientation;
|
|
|
|
}
|
2017-02-06 05:02:50 +03:00
|
|
|
} else {
|
2017-10-30 21:14:08 +03:00
|
|
|
nsPrintSettings::GetOrientation(aOrientation);
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetOrientation(int32_t aOrientation)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2017-10-30 21:14:08 +03:00
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
if (aOrientation == nsIPrintSettings::kPortraitOrientation) {
|
|
|
|
[printInfoDict setObject: [NSNumber numberWithInt: NS_PAPER_ORIENTATION_PORTRAIT]
|
|
|
|
forKey: NSPrintOrientation];
|
|
|
|
} else {
|
|
|
|
[printInfoDict setObject: [NSNumber numberWithInt: NS_PAPER_ORIENTATION_LANDSCAPE]
|
|
|
|
forKey: NSPrintOrientation];
|
|
|
|
}
|
2017-02-06 05:02:50 +03:00
|
|
|
} else {
|
2017-10-30 21:14:08 +03:00
|
|
|
nsPrintSettings::SetOrientation(aOrientation);
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop);
|
2017-10-30 21:14:08 +03:00
|
|
|
|
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
[printInfoDict setObject :
|
|
|
|
[NSNumber numberWithDouble: aUnwriteableMarginTop]
|
|
|
|
forKey : NSPrintTopMargin];
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft);
|
2017-10-30 21:14:08 +03:00
|
|
|
|
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
[printInfoDict setObject : [NSNumber numberWithDouble: aUnwriteableMarginLeft]
|
|
|
|
forKey : NSPrintLeftMargin];
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom);
|
2017-10-30 21:14:08 +03:00
|
|
|
|
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
[printInfoDict setObject : [NSNumber numberWithDouble: aUnwriteableMarginBottom]
|
|
|
|
forKey : NSPrintBottomMargin];
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsX::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight);
|
2017-10-30 21:14:08 +03:00
|
|
|
|
|
|
|
// Only use NSPrintInfo data in the parent process. The
|
|
|
|
// child process' instance is not needed or used.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
[printInfoDict setObject : [NSNumber numberWithDouble: aUnwriteableMarginRight]
|
|
|
|
forKey : NSPrintRightMargin];
|
2017-02-06 05:02:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nsPrintSettingsX::GetCocoaUnit(int16_t aGeckoUnit)
|
|
|
|
{
|
|
|
|
if (aGeckoUnit == kPaperSizeMillimeters)
|
|
|
|
return kPaperSizeMillimeters;
|
|
|
|
else
|
|
|
|
return kPaperSizeInches;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPrintSettingsX::SetCocoaPaperSize(double aWidth, double aHeight)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
NSSize paperSize;
|
|
|
|
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
|
|
|
|
if ([mPrintInfo orientation] == NS_PAPER_ORIENTATION_PORTRAIT) {
|
|
|
|
// switch widths and heights
|
|
|
|
paperSize = NSMakeSize(aWidth, aHeight);
|
|
|
|
[printInfoDict setObject: [NSValue valueWithSize: paperSize]
|
|
|
|
forKey: NSPrintPaperSize];
|
|
|
|
} else {
|
|
|
|
paperSize = NSMakeSize(aHeight, aWidth);
|
|
|
|
[printInfoDict setObject: [NSValue valueWithSize: paperSize]
|
|
|
|
forKey: NSPrintPaperSize];
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|