2006-02-07 04:13:47 +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/. */
|
2006-02-07 04:13:47 +03:00
|
|
|
#include "nsPrintSettingsWin.h"
|
2016-06-30 12:01:10 +03:00
|
|
|
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2006-02-07 04:13:47 +03:00
|
|
|
#include "nsCRT.h"
|
|
|
|
|
2016-06-30 12:01:10 +03:00
|
|
|
// Using paper sizes from wingdi.h and the units given there, plus a little
|
|
|
|
// extra research for the ones it doesn't give. Looks like the list hasn't
|
|
|
|
// changed since Windows 2000, so should be fairly stable now.
|
|
|
|
const short kPaperSizeUnits[] = {
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // Not Used default to mm as
|
|
|
|
// DEVMODE uses tenths of mm, just
|
|
|
|
// in case
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTERSMALL
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_TABLOID
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LEDGER
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LEGAL
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_STATEMENT
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_EXECUTIVE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A3
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A4SMALL
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A5
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B5
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_FOLIO
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_QUARTO
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_10X14
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_11X17
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_NOTE
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_9
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_10
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_11
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_12
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_14
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_CSHEET
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_DSHEET
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ESHEET
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_DL
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_C5
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_C3
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_C4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_C6
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_C65
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_B4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_B5
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_B6
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_ITALY
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_MONARCH
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_ENV_PERSONAL
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_FANFOLD_US
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_FANFOLD_STD_GERMAN
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_FANFOLD_LGL_GERMAN
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ISO_B4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JAPANESE_POSTCARD
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_9X11
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_10X11
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_15X11
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_ENV_INVITE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_RESERVED_48
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_RESERVED_49
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LEGAL_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_TABLOID_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_A4_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A4_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER_EXTRA_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A_PLUS
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B_PLUS
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER_PLUS
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A4_PLUS
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A5_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B5_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A3_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A5_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B5_EXTRA
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A2
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A3_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A3_EXTRA_TRANSVERSE
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_DBL_JAPANESE_POSTCARD
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A6
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_KAKU2
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_KAKU3
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_CHOU3
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_CHOU4
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_LETTER_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A3_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A4_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A5_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B4_JIS_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B5_JIS_ROTATED
|
|
|
|
nsIPrintSettings::
|
|
|
|
kPaperSizeMillimeters, // DMPAPER_JAPANESE_POSTCARD_ROTATED
|
|
|
|
nsIPrintSettings::
|
|
|
|
kPaperSizeMillimeters, // DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_A6_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_KAKU2_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_KAKU3_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_CHOU3_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_CHOU4_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B6_JIS
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_B6_JIS_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeInches, // DMPAPER_12X11
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_YOU4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_JENV_YOU4_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P16K
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P32K
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P32KBIG
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_1
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_2
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_3
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_4
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_5
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_6
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_7
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_8
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_9
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_10
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P16K_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P32K_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_P32KBIG_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_1_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_2_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_3_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_4_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_5_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_6_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_7_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_8_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_9_ROTATED
|
|
|
|
nsIPrintSettings::kPaperSizeMillimeters, // DMPAPER_PENV_10_ROTATED
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsWin, nsPrintSettings,
|
|
|
|
nsIPrintSettingsWin)
|
2006-02-07 04:13:47 +03:00
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
|
|
|
nsPrintSettingsWin::nsPrintSettingsWin()
|
|
|
|
: nsPrintSettings(),
|
2012-07-30 18:20:58 +04:00
|
|
|
mDeviceName(nullptr),
|
|
|
|
mDriverName(nullptr),
|
|
|
|
mDevMode(nullptr) {}
|
2006-02-07 04:13:47 +03:00
|
|
|
|
2006-02-07 04:13:52 +03:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
2017-10-09 02:08:09 +03:00
|
|
|
nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS)
|
|
|
|
: mDevMode(nullptr) {
|
2006-02-07 04:14:05 +03:00
|
|
|
*this = aPS;
|
2006-02-07 04:13:52 +03:00
|
|
|
}
|
|
|
|
|
2006-02-07 04:13:47 +03:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
|
|
|
nsPrintSettingsWin::~nsPrintSettingsWin() {
|
2006-02-07 04:14:13 +03:00
|
|
|
if (mDevMode) ::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
2006-02-07 04:13:47 +03:00
|
|
|
}
|
|
|
|
|
2017-10-09 02:08:09 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const nsAString& aDeviceName) {
|
|
|
|
mDeviceName = aDeviceName;
|
2006-02-07 04:13:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-10-09 02:08:09 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(nsAString& aDeviceName) {
|
|
|
|
aDeviceName = mDeviceName;
|
2006-02-07 04:13:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-09 02:08:09 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const nsAString& aDriverName) {
|
|
|
|
mDriverName = aDriverName;
|
2006-02-07 04:13:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-10-09 02:08:09 +03:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(nsAString& aDriverName) {
|
|
|
|
aDriverName = mDriverName;
|
2006-02-07 04:13:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 04:54:26 +04:00
|
|
|
void nsPrintSettingsWin::CopyDevMode(DEVMODEW* aInDevMode,
|
|
|
|
DEVMODEW*& aOutDevMode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
aOutDevMode = nullptr;
|
2006-02-07 04:14:13 +03:00
|
|
|
size_t size = aInDevMode->dmSize + aInDevMode->dmDriverExtra;
|
2008-10-22 04:54:26 +04:00
|
|
|
aOutDevMode =
|
|
|
|
(LPDEVMODEW)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
2006-02-07 04:14:13 +03:00
|
|
|
if (aOutDevMode) {
|
|
|
|
memcpy(aOutDevMode, aInDevMode, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 04:54:26 +04:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDevMode(DEVMODEW** aDevMode) {
|
2006-02-07 04:13:47 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aDevMode);
|
|
|
|
|
|
|
|
if (mDevMode) {
|
2006-02-07 04:14:13 +03:00
|
|
|
CopyDevMode(mDevMode, *aDevMode);
|
2006-02-07 04:13:47 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDevMode = nullptr;
|
2006-02-07 04:13:47 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-02-07 04:14:05 +03:00
|
|
|
|
2008-10-22 04:54:26 +04:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODEW* aDevMode) {
|
2006-02-07 04:13:47 +03:00
|
|
|
if (mDevMode) {
|
2006-02-07 04:14:13 +03:00
|
|
|
::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
2013-10-08 22:48:20 +04:00
|
|
|
mDevMode = nullptr;
|
2006-02-07 04:13:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aDevMode) {
|
2006-02-07 04:14:13 +03:00
|
|
|
CopyDevMode(aDevMode, mDevMode);
|
2006-02-07 04:13:47 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-02-07 04:13:52 +03:00
|
|
|
|
2016-01-22 19:05:19 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsWin::GetPrintableWidthInInches(double* aPrintableWidthInInches) {
|
|
|
|
MOZ_ASSERT(aPrintableWidthInInches);
|
|
|
|
*aPrintableWidthInInches = mPrintableWidthInInches;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsWin::SetPrintableWidthInInches(double aPrintableWidthInInches) {
|
|
|
|
mPrintableWidthInInches = aPrintableWidthInInches;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsWin::GetPrintableHeightInInches(
|
|
|
|
double* aPrintableHeightInInches) {
|
|
|
|
MOZ_ASSERT(aPrintableHeightInInches);
|
|
|
|
*aPrintableHeightInInches = mPrintableHeightInInches;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsWin::SetPrintableHeightInInches(
|
|
|
|
double aPrintableHeightInInches) {
|
|
|
|
mPrintableHeightInInches = aPrintableHeightInInches;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsWin::GetEffectivePageSize(double* aWidth, double* aHeight) {
|
|
|
|
// If printable page size not set, fall back to nsPrintSettings.
|
|
|
|
if (mPrintableWidthInInches == 0l || mPrintableHeightInInches == 0l) {
|
|
|
|
return nsPrintSettings::GetEffectivePageSize(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOrientation == kPortraitOrientation) {
|
|
|
|
*aWidth = NS_INCHES_TO_TWIPS(mPrintableWidthInInches);
|
|
|
|
*aHeight = NS_INCHES_TO_TWIPS(mPrintableHeightInInches);
|
|
|
|
} else {
|
|
|
|
*aHeight = NS_INCHES_TO_TWIPS(mPrintableWidthInInches);
|
|
|
|
*aWidth = NS_INCHES_TO_TWIPS(mPrintableHeightInInches);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-29 03:13:10 +03:00
|
|
|
void nsPrintSettingsWin::InitUnwriteableMargin(HDC aHdc) {
|
|
|
|
int32_t pixelsPerInchY = GetDeviceCaps(aHdc, LOGPIXELSY);
|
|
|
|
int32_t pixelsPerInchX = GetDeviceCaps(aHdc, LOGPIXELSX);
|
|
|
|
|
|
|
|
int32_t marginLeft = GetDeviceCaps(aHdc, PHYSICALOFFSETX);
|
|
|
|
int32_t marginTop = GetDeviceCaps(aHdc, PHYSICALOFFSETY);
|
|
|
|
|
|
|
|
double marginLeftInch = double(marginLeft) / pixelsPerInchX;
|
|
|
|
double marginTopInch = double(marginTop) / pixelsPerInchY;
|
|
|
|
|
|
|
|
int32_t printableAreaWidth = GetDeviceCaps(aHdc, HORZRES);
|
|
|
|
int32_t printableAreaHeight = GetDeviceCaps(aHdc, VERTRES);
|
|
|
|
|
|
|
|
double printableAreaWidthInch = double(printableAreaWidth) / pixelsPerInchX;
|
|
|
|
double printableAreaHeightInch = double(printableAreaHeight) / pixelsPerInchY;
|
|
|
|
|
|
|
|
int32_t physicalWidth = GetDeviceCaps(aHdc, PHYSICALWIDTH);
|
|
|
|
int32_t physicalHeight = GetDeviceCaps(aHdc, PHYSICALHEIGHT);
|
|
|
|
|
|
|
|
double physicalWidthInch = double(physicalWidth) / pixelsPerInchX;
|
|
|
|
double physicalHeightInch = double(physicalHeight) / pixelsPerInchY;
|
|
|
|
|
|
|
|
double marginBottomInch =
|
|
|
|
physicalHeightInch - printableAreaHeightInch - marginTopInch;
|
|
|
|
double marginRightInch =
|
|
|
|
physicalWidthInch - printableAreaWidthInch - marginLeftInch;
|
|
|
|
|
|
|
|
mUnwriteableMargin.SizeTo(NS_INCHES_TO_INT_TWIPS(marginTopInch),
|
|
|
|
NS_INCHES_TO_INT_TWIPS(marginRightInch),
|
|
|
|
NS_INCHES_TO_INT_TWIPS(marginBottomInch),
|
|
|
|
NS_INCHES_TO_INT_TWIPS(marginLeftInch));
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:40:07 +03:00
|
|
|
void nsPrintSettingsWin::CopyFromNative(HDC aHdc, DEVMODEW* aDevMode) {
|
2016-01-22 19:05:19 +03:00
|
|
|
MOZ_ASSERT(aHdc);
|
2016-01-12 20:40:07 +03:00
|
|
|
MOZ_ASSERT(aDevMode);
|
|
|
|
|
|
|
|
mIsInitedFromPrinter = true;
|
|
|
|
if (aDevMode->dmFields & DM_ORIENTATION) {
|
|
|
|
mOrientation = int32_t(aDevMode->dmOrientation == DMORIENT_PORTRAIT
|
|
|
|
? kPortraitOrientation
|
|
|
|
: kLandscapeOrientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDevMode->dmFields & DM_COPIES) {
|
|
|
|
mNumCopies = aDevMode->dmCopies;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we do the scaling, grab their value and reset back to 100.
|
|
|
|
if (aDevMode->dmFields & DM_SCALE) {
|
|
|
|
double scale = double(aDevMode->dmScale) / 100.0f;
|
|
|
|
if (mScaling == 1.0 || scale != 1.0) {
|
|
|
|
mScaling = scale;
|
|
|
|
}
|
|
|
|
aDevMode->dmScale = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDevMode->dmFields & DM_PAPERSIZE) {
|
|
|
|
mPaperData = aDevMode->dmPaperSize;
|
2016-06-30 12:01:10 +03:00
|
|
|
// If not a paper size we know about, the unit will be the last one saved.
|
|
|
|
if (mPaperData > 0 &&
|
|
|
|
mPaperData < int32_t(mozilla::ArrayLength(kPaperSizeUnits))) {
|
|
|
|
mPaperSizeUnit = kPaperSizeUnits[mPaperData];
|
|
|
|
}
|
2016-01-12 20:40:07 +03:00
|
|
|
} else {
|
|
|
|
mPaperData = -1;
|
|
|
|
}
|
|
|
|
|
2018-03-29 03:13:10 +03:00
|
|
|
InitUnwriteableMargin(aHdc);
|
|
|
|
|
2016-06-30 12:01:10 +03:00
|
|
|
// The length and width in DEVMODE are always in tenths of a millimeter.
|
|
|
|
double sizeUnitToTenthsOfAmm =
|
|
|
|
10L * (mPaperSizeUnit == kPaperSizeInches ? MM_PER_INCH_FLOAT : 1L);
|
2016-01-12 20:40:07 +03:00
|
|
|
if (aDevMode->dmFields & DM_PAPERLENGTH) {
|
2016-06-30 12:01:10 +03:00
|
|
|
mPaperHeight = aDevMode->dmPaperLength / sizeUnitToTenthsOfAmm;
|
2016-01-12 20:40:07 +03:00
|
|
|
} else {
|
|
|
|
mPaperHeight = -1l;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDevMode->dmFields & DM_PAPERWIDTH) {
|
2016-06-30 12:01:10 +03:00
|
|
|
mPaperWidth = aDevMode->dmPaperWidth / sizeUnitToTenthsOfAmm;
|
2016-01-12 20:40:07 +03:00
|
|
|
} else {
|
|
|
|
mPaperWidth = -1l;
|
|
|
|
}
|
2016-01-22 19:05:19 +03:00
|
|
|
|
2016-05-10 17:17:56 +03:00
|
|
|
// Note: we only scale the printing using the LOGPIXELSY, so we use that
|
|
|
|
// when calculating the surface width as well as the height.
|
2018-03-29 03:13:10 +03:00
|
|
|
int32_t printableWidthInDots = GetDeviceCaps(aHdc, PHYSICALWIDTH);
|
|
|
|
int32_t printableHeightInDots = GetDeviceCaps(aHdc, PHYSICALHEIGHT);
|
2016-01-22 19:05:19 +03:00
|
|
|
int32_t heightDPI = GetDeviceCaps(aHdc, LOGPIXELSY);
|
|
|
|
|
|
|
|
// Keep these values in portrait format, so we can reflect our own changes
|
|
|
|
// to mOrientation.
|
|
|
|
if (mOrientation == kPortraitOrientation) {
|
2016-05-10 17:17:56 +03:00
|
|
|
mPrintableWidthInInches = double(printableWidthInDots) / heightDPI;
|
2016-01-22 19:05:19 +03:00
|
|
|
mPrintableHeightInInches = double(printableHeightInDots) / heightDPI;
|
|
|
|
} else {
|
2016-05-10 17:17:56 +03:00
|
|
|
mPrintableHeightInInches = double(printableWidthInDots) / heightDPI;
|
2016-01-22 19:05:19 +03:00
|
|
|
mPrintableWidthInInches = double(printableHeightInDots) / heightDPI;
|
|
|
|
}
|
|
|
|
|
2016-05-10 17:17:56 +03:00
|
|
|
// Using Y to match existing code for print scaling calculations.
|
2016-01-22 19:05:19 +03:00
|
|
|
mResolution = heightDPI;
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:40:07 +03:00
|
|
|
void nsPrintSettingsWin::CopyToNative(DEVMODEW* aDevMode) {
|
|
|
|
MOZ_ASSERT(aDevMode);
|
|
|
|
|
|
|
|
if (mPaperData >= 0) {
|
|
|
|
aDevMode->dmPaperSize = mPaperData;
|
|
|
|
aDevMode->dmFields |= DM_PAPERSIZE;
|
|
|
|
} else {
|
|
|
|
aDevMode->dmPaperSize = 0;
|
|
|
|
aDevMode->dmFields &= ~DM_PAPERSIZE;
|
|
|
|
}
|
|
|
|
|
2016-06-30 12:01:10 +03:00
|
|
|
// The length and width in DEVMODE are always in tenths of a millimeter.
|
|
|
|
double sizeUnitToTenthsOfAmm =
|
|
|
|
10L * (mPaperSizeUnit == kPaperSizeInches ? MM_PER_INCH_FLOAT : 1L);
|
2016-01-12 20:40:07 +03:00
|
|
|
|
2016-05-11 12:18:10 +03:00
|
|
|
// Note: small page sizes can be required here for sticker, label and slide
|
|
|
|
// printers etc. see bug 1271900.
|
2016-06-30 12:01:10 +03:00
|
|
|
if (mPaperHeight > 0) {
|
|
|
|
aDevMode->dmPaperLength = mPaperHeight * sizeUnitToTenthsOfAmm;
|
2016-01-12 20:40:07 +03:00
|
|
|
aDevMode->dmFields |= DM_PAPERLENGTH;
|
|
|
|
} else {
|
|
|
|
aDevMode->dmPaperLength = 0;
|
|
|
|
aDevMode->dmFields &= ~DM_PAPERLENGTH;
|
|
|
|
}
|
|
|
|
|
2016-06-30 12:01:10 +03:00
|
|
|
if (mPaperWidth > 0) {
|
|
|
|
aDevMode->dmPaperWidth = mPaperWidth * sizeUnitToTenthsOfAmm;
|
2016-01-12 20:40:07 +03:00
|
|
|
aDevMode->dmFields |= DM_PAPERWIDTH;
|
|
|
|
} else {
|
|
|
|
aDevMode->dmPaperWidth = 0;
|
|
|
|
aDevMode->dmFields &= ~DM_PAPERWIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup Orientation
|
|
|
|
aDevMode->dmOrientation = mOrientation == kPortraitOrientation
|
|
|
|
? DMORIENT_PORTRAIT
|
|
|
|
: DMORIENT_LANDSCAPE;
|
|
|
|
aDevMode->dmFields |= DM_ORIENTATION;
|
|
|
|
|
|
|
|
// Setup Number of Copies
|
|
|
|
aDevMode->dmCopies = mNumCopies;
|
|
|
|
aDevMode->dmFields |= DM_COPIES;
|
|
|
|
}
|
|
|
|
|
2006-02-07 04:14:05 +03:00
|
|
|
//-------------------------------------------
|
|
|
|
nsresult nsPrintSettingsWin::_Clone(nsIPrintSettings** _retval) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPrintSettingsWin> printSettings = new nsPrintSettingsWin(*this);
|
2015-03-12 16:43:50 +03:00
|
|
|
printSettings.forget(_retval);
|
|
|
|
return NS_OK;
|
2006-02-07 04:13:52 +03:00
|
|
|
}
|
2006-02-07 04:14:05 +03:00
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
nsPrintSettingsWin& nsPrintSettingsWin::operator=(
|
|
|
|
const nsPrintSettingsWin& rhs) {
|
|
|
|
if (this == &rhs) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
((nsPrintSettings&)*this) = rhs;
|
|
|
|
|
|
|
|
// Use free because we used the native malloc to create the memory
|
|
|
|
if (mDevMode) {
|
2006-02-07 04:14:13 +03:00
|
|
|
::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
2006-02-07 04:14:05 +03:00
|
|
|
}
|
|
|
|
|
2017-10-09 02:08:09 +03:00
|
|
|
mDeviceName = rhs.mDeviceName;
|
|
|
|
mDriverName = rhs.mDriverName;
|
2006-02-07 04:14:05 +03:00
|
|
|
|
|
|
|
if (rhs.mDevMode) {
|
2006-02-07 04:14:13 +03:00
|
|
|
CopyDevMode(rhs.mDevMode, mDevMode);
|
2006-02-07 04:14:05 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mDevMode = nullptr;
|
2006-02-07 04:14:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
nsresult nsPrintSettingsWin::_Assign(nsIPrintSettings* aPS) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsPrintSettingsWin* psWin = static_cast<nsPrintSettingsWin*>(aPS);
|
2006-02-07 04:14:05 +03:00
|
|
|
*this = *psWin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Testing of assign and clone
|
|
|
|
// This define turns on the testing module below
|
|
|
|
// so at start up it writes and reads the prefs.
|
|
|
|
#ifdef DEBUG_rodsX
|
2017-12-19 13:42:15 +03:00
|
|
|
# include "nsIPrintSettingsService.h"
|
2006-02-07 04:14:05 +03:00
|
|
|
# include "nsIServiceManager.h"
|
|
|
|
class Tester {
|
|
|
|
public:
|
|
|
|
Tester();
|
|
|
|
};
|
|
|
|
Tester::Tester() {
|
|
|
|
nsCOMPtr<nsIPrintSettings> ps;
|
|
|
|
nsresult rv;
|
2017-12-19 13:42:15 +03:00
|
|
|
nsCOMPtr<nsIPrintSettingsService> printService =
|
|
|
|
do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
|
2006-02-07 04:14:05 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = printService->CreatePrintSettings(getter_AddRefs(ps));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps) {
|
2011-10-02 06:16:19 +04:00
|
|
|
ps->SetPrintOptions(nsIPrintSettings::kPrintOddPages, true);
|
|
|
|
ps->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, false);
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetMarginTop(1.0);
|
|
|
|
ps->SetMarginLeft(1.0);
|
|
|
|
ps->SetMarginBottom(1.0);
|
|
|
|
ps->SetMarginRight(1.0);
|
|
|
|
ps->SetScaling(0.5);
|
2011-10-02 06:16:19 +04:00
|
|
|
ps->SetPrintBGColors(true);
|
|
|
|
ps->SetPrintBGImages(true);
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetPrintRange(15);
|
2006-02-07 04:15:21 +03:00
|
|
|
ps->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get());
|
|
|
|
ps->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get());
|
|
|
|
ps->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get());
|
|
|
|
ps->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get());
|
|
|
|
ps->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get());
|
|
|
|
ps->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get());
|
|
|
|
ps->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get());
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetPaperData(1);
|
|
|
|
ps->SetPaperWidth(100.0);
|
|
|
|
ps->SetPaperHeight(50.0);
|
|
|
|
ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
|
2011-10-02 06:16:19 +04:00
|
|
|
ps->SetPrintReversed(true);
|
|
|
|
ps->SetPrintInColor(true);
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
|
2006-02-07 04:15:21 +03:00
|
|
|
ps->SetPrintCommand(NS_ConvertUTF8toUTF16("Command").get());
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetNumCopies(2);
|
2006-02-07 04:15:21 +03:00
|
|
|
ps->SetPrinterName(NS_ConvertUTF8toUTF16("Printer Name").get());
|
2011-10-02 06:16:19 +04:00
|
|
|
ps->SetPrintToFile(true);
|
2006-02-07 04:15:21 +03:00
|
|
|
ps->SetToFileName(NS_ConvertUTF8toUTF16("File Name").get());
|
2006-02-07 04:14:05 +03:00
|
|
|
ps->SetPrintPageDelay(1000);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrintSettings> ps2;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = printService->CreatePrintSettings(getter_AddRefs(ps2));
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2->Assign(ps);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrintSettings> psClone;
|
|
|
|
ps2->Clone(getter_AddRefs(psClone));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Tester gTester;
|
2016-05-10 17:17:56 +03:00
|
|
|
#endif
|