1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsPrintSettingsImpl.h"
7 #include "nsReadableUtils.h"
8 #include "nsIPrintSession.h"
10 #define DEFAULT_MARGIN_WIDTH 0.5
12 NS_IMPL_ISUPPORTS(nsPrintSettings
, nsIPrintSettings
)
14 /** ---------------------------------------------------
15 * See documentation in nsPrintSettingsImpl.h
18 nsPrintSettings::nsPrintSettings() :
20 mPrintRange(kRangeAllPages
),
24 mPrintBGColors(false),
25 mPrintBGImages(false),
26 mPrintFrameTypeUsage(kUseInternalDefault
),
27 mPrintFrameType(kFramesAsIs
),
28 mHowToEnableFrameUI(kFrameEnableNone
),
33 mShowPrintProgress(true),
36 mPaperSizeType(kPaperSizeDefined
),
39 mPaperSizeUnit(kPaperSizeInches
),
40 mPrintReversed(false),
42 mOrientation(kPortraitOrientation
),
43 mDownloadFonts(false),
46 mOutputFormat(kOutputFormatNative
),
47 mIsInitedFromPrinter(false),
48 mIsInitedFromPrefs(false),
49 mPersistMarginBoxSettings(true)
52 /* member initializers and constructor code */
53 int32_t marginWidth
= NS_INCHES_TO_INT_TWIPS(DEFAULT_MARGIN_WIDTH
);
54 mMargin
.SizeTo(marginWidth
, marginWidth
, marginWidth
, marginWidth
);
55 mEdge
.SizeTo(0, 0, 0, 0);
56 mUnwriteableMargin
.SizeTo(0,0,0,0);
58 mPrintOptions
= kPrintOddPages
| kPrintEvenPages
;
60 mHeaderStrs
[0].AssignLiteral("&T");
61 mHeaderStrs
[2].AssignLiteral("&U");
63 mFooterStrs
[0].AssignLiteral("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
64 mFooterStrs
[2].AssignLiteral("&D");
68 /** ---------------------------------------------------
69 * See documentation in nsPrintSettingsImpl.h
72 nsPrintSettings::nsPrintSettings(const nsPrintSettings
& aPS
)
77 /** ---------------------------------------------------
78 * See documentation in nsPrintSettingsImpl.h
81 nsPrintSettings::~nsPrintSettings()
85 /* [noscript] attribute nsIPrintSession printSession; */
86 NS_IMETHODIMP
nsPrintSettings::GetPrintSession(nsIPrintSession
**aPrintSession
)
88 NS_ENSURE_ARG_POINTER(aPrintSession
);
89 *aPrintSession
= nullptr;
91 nsCOMPtr
<nsIPrintSession
> session
= do_QueryReferent(mSession
);
93 return NS_ERROR_NOT_INITIALIZED
;
94 *aPrintSession
= session
;
95 NS_ADDREF(*aPrintSession
);
98 NS_IMETHODIMP
nsPrintSettings::SetPrintSession(nsIPrintSession
*aPrintSession
)
100 // Clearing it by passing nullptr is not allowed. That's why we
101 // use a weak ref so that it doesn't have to be cleared.
102 NS_ENSURE_ARG(aPrintSession
);
104 mSession
= do_GetWeakReference(aPrintSession
);
106 // This may happen if the implementation of this object does
107 // not support weak references - programmer error.
108 NS_ERROR("Could not get a weak reference from aPrintSession");
109 return NS_ERROR_FAILURE
;
114 /* attribute long startPageRange; */
115 NS_IMETHODIMP
nsPrintSettings::GetStartPageRange(int32_t *aStartPageRange
)
117 //NS_ENSURE_ARG_POINTER(aStartPageRange);
118 *aStartPageRange
= mStartPageNum
;
121 NS_IMETHODIMP
nsPrintSettings::SetStartPageRange(int32_t aStartPageRange
)
123 mStartPageNum
= aStartPageRange
;
127 /* attribute long endPageRange; */
128 NS_IMETHODIMP
nsPrintSettings::GetEndPageRange(int32_t *aEndPageRange
)
130 //NS_ENSURE_ARG_POINTER(aEndPageRange);
131 *aEndPageRange
= mEndPageNum
;
134 NS_IMETHODIMP
nsPrintSettings::SetEndPageRange(int32_t aEndPageRange
)
136 mEndPageNum
= aEndPageRange
;
140 /* attribute boolean printReversed; */
141 NS_IMETHODIMP
nsPrintSettings::GetPrintReversed(bool *aPrintReversed
)
143 //NS_ENSURE_ARG_POINTER(aPrintReversed);
144 *aPrintReversed
= mPrintReversed
;
147 NS_IMETHODIMP
nsPrintSettings::SetPrintReversed(bool aPrintReversed
)
149 mPrintReversed
= aPrintReversed
;
153 /* attribute boolean printInColor; */
154 NS_IMETHODIMP
nsPrintSettings::GetPrintInColor(bool *aPrintInColor
)
156 //NS_ENSURE_ARG_POINTER(aPrintInColor);
157 *aPrintInColor
= mPrintInColor
;
160 NS_IMETHODIMP
nsPrintSettings::SetPrintInColor(bool aPrintInColor
)
162 mPrintInColor
= aPrintInColor
;
166 /* attribute short orientation; */
167 NS_IMETHODIMP
nsPrintSettings::GetOrientation(int32_t *aOrientation
)
169 NS_ENSURE_ARG_POINTER(aOrientation
);
170 *aOrientation
= mOrientation
;
173 NS_IMETHODIMP
nsPrintSettings::SetOrientation(int32_t aOrientation
)
175 mOrientation
= aOrientation
;
179 /* attribute wstring colorspace; */
180 NS_IMETHODIMP
nsPrintSettings::GetColorspace(char16_t
* *aColorspace
)
182 NS_ENSURE_ARG_POINTER(aColorspace
);
183 if (!mColorspace
.IsEmpty()) {
184 *aColorspace
= ToNewUnicode(mColorspace
);
186 *aColorspace
= nullptr;
190 NS_IMETHODIMP
nsPrintSettings::SetColorspace(const char16_t
* aColorspace
)
193 mColorspace
= aColorspace
;
195 mColorspace
.SetLength(0);
200 /* attribute wstring resolutionname; */
201 NS_IMETHODIMP
nsPrintSettings::GetResolutionName(char16_t
* *aResolutionName
)
203 NS_ENSURE_ARG_POINTER(aResolutionName
);
204 if (!mResolutionName
.IsEmpty()) {
205 *aResolutionName
= ToNewUnicode(mResolutionName
);
207 *aResolutionName
= nullptr;
211 NS_IMETHODIMP
nsPrintSettings::SetResolutionName(const char16_t
* aResolutionName
)
213 if (aResolutionName
) {
214 mResolutionName
= aResolutionName
;
216 mResolutionName
.SetLength(0);
221 /* attribute wstring resolution; */
222 NS_IMETHODIMP
nsPrintSettings::GetResolution(int32_t *aResolution
)
224 NS_ENSURE_ARG_POINTER(aResolution
);
225 *aResolution
= mResolution
;
228 NS_IMETHODIMP
nsPrintSettings::SetResolution(const int32_t aResolution
)
230 mResolution
= aResolution
;
234 /* attribute wstring duplex; */
235 NS_IMETHODIMP
nsPrintSettings::GetDuplex(int32_t *aDuplex
)
237 NS_ENSURE_ARG_POINTER(aDuplex
);
241 NS_IMETHODIMP
nsPrintSettings::SetDuplex(const int32_t aDuplex
)
247 /* attribute boolean downloadFonts; */
248 NS_IMETHODIMP
nsPrintSettings::GetDownloadFonts(bool *aDownloadFonts
)
250 //NS_ENSURE_ARG_POINTER(aDownloadFonts);
251 *aDownloadFonts
= mDownloadFonts
;
254 NS_IMETHODIMP
nsPrintSettings::SetDownloadFonts(bool aDownloadFonts
)
256 mDownloadFonts
= aDownloadFonts
;
260 /* attribute wstring printer; */
261 NS_IMETHODIMP
nsPrintSettings::GetPrinterName(char16_t
* *aPrinter
)
263 NS_ENSURE_ARG_POINTER(aPrinter
);
265 *aPrinter
= ToNewUnicode(mPrinter
);
266 NS_ENSURE_TRUE(*aPrinter
, NS_ERROR_OUT_OF_MEMORY
);
271 NS_IMETHODIMP
nsPrintSettings::SetPrinterName(const char16_t
* aPrinter
)
273 if (!aPrinter
|| !mPrinter
.Equals(aPrinter
)) {
274 mIsInitedFromPrinter
= false;
275 mIsInitedFromPrefs
= false;
278 mPrinter
.Assign(aPrinter
);
282 /* attribute long numCopies; */
283 NS_IMETHODIMP
nsPrintSettings::GetNumCopies(int32_t *aNumCopies
)
285 NS_ENSURE_ARG_POINTER(aNumCopies
);
286 *aNumCopies
= mNumCopies
;
289 NS_IMETHODIMP
nsPrintSettings::SetNumCopies(int32_t aNumCopies
)
291 mNumCopies
= aNumCopies
;
295 /* attribute wstring printCommand; */
296 NS_IMETHODIMP
nsPrintSettings::GetPrintCommand(char16_t
* *aPrintCommand
)
298 //NS_ENSURE_ARG_POINTER(aPrintCommand);
299 *aPrintCommand
= ToNewUnicode(mPrintCommand
);
302 NS_IMETHODIMP
nsPrintSettings::SetPrintCommand(const char16_t
* aPrintCommand
)
305 mPrintCommand
= aPrintCommand
;
307 mPrintCommand
.SetLength(0);
312 /* attribute boolean printToFile; */
313 NS_IMETHODIMP
nsPrintSettings::GetPrintToFile(bool *aPrintToFile
)
315 //NS_ENSURE_ARG_POINTER(aPrintToFile);
316 *aPrintToFile
= mPrintToFile
;
319 NS_IMETHODIMP
nsPrintSettings::SetPrintToFile(bool aPrintToFile
)
321 mPrintToFile
= aPrintToFile
;
325 /* attribute wstring toFileName; */
326 NS_IMETHODIMP
nsPrintSettings::GetToFileName(char16_t
* *aToFileName
)
328 //NS_ENSURE_ARG_POINTER(aToFileName);
329 *aToFileName
= ToNewUnicode(mToFileName
);
332 NS_IMETHODIMP
nsPrintSettings::SetToFileName(const char16_t
* aToFileName
)
335 mToFileName
= aToFileName
;
337 mToFileName
.SetLength(0);
342 /* attribute short outputFormat; */
343 NS_IMETHODIMP
nsPrintSettings::GetOutputFormat(int16_t *aOutputFormat
)
345 NS_ENSURE_ARG_POINTER(aOutputFormat
);
346 *aOutputFormat
= mOutputFormat
;
349 NS_IMETHODIMP
nsPrintSettings::SetOutputFormat(int16_t aOutputFormat
)
351 mOutputFormat
= aOutputFormat
;
355 /* attribute long printPageDelay; */
356 NS_IMETHODIMP
nsPrintSettings::GetPrintPageDelay(int32_t *aPrintPageDelay
)
358 *aPrintPageDelay
= mPrintPageDelay
;
361 NS_IMETHODIMP
nsPrintSettings::SetPrintPageDelay(int32_t aPrintPageDelay
)
363 mPrintPageDelay
= aPrintPageDelay
;
367 /* attribute boolean isInitializedFromPrinter; */
368 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrinter(bool *aIsInitializedFromPrinter
)
370 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter
);
371 *aIsInitializedFromPrinter
= (bool)mIsInitedFromPrinter
;
374 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrinter(bool aIsInitializedFromPrinter
)
376 mIsInitedFromPrinter
= (bool)aIsInitializedFromPrinter
;
380 /* attribute boolean isInitializedFromPrefs; */
381 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrefs(bool *aInitializedFromPrefs
)
383 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs
);
384 *aInitializedFromPrefs
= (bool)mIsInitedFromPrefs
;
387 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrefs(bool aInitializedFromPrefs
)
389 mIsInitedFromPrefs
= (bool)aInitializedFromPrefs
;
393 /* attribute boolean persistMarginBoxSettings; */
394 NS_IMETHODIMP
nsPrintSettings::GetPersistMarginBoxSettings(bool *aPersistMarginBoxSettings
)
396 NS_ENSURE_ARG_POINTER(aPersistMarginBoxSettings
);
397 *aPersistMarginBoxSettings
= mPersistMarginBoxSettings
;
400 NS_IMETHODIMP
nsPrintSettings::SetPersistMarginBoxSettings(bool aPersistMarginBoxSettings
)
402 mPersistMarginBoxSettings
= aPersistMarginBoxSettings
;
406 /* attribute double marginTop; */
407 NS_IMETHODIMP
nsPrintSettings::GetMarginTop(double *aMarginTop
)
409 NS_ENSURE_ARG_POINTER(aMarginTop
);
410 *aMarginTop
= NS_TWIPS_TO_INCHES(mMargin
.top
);
413 NS_IMETHODIMP
nsPrintSettings::SetMarginTop(double aMarginTop
)
415 mMargin
.top
= NS_INCHES_TO_INT_TWIPS(float(aMarginTop
));
419 /* attribute double marginLeft; */
420 NS_IMETHODIMP
nsPrintSettings::GetMarginLeft(double *aMarginLeft
)
422 NS_ENSURE_ARG_POINTER(aMarginLeft
);
423 *aMarginLeft
= NS_TWIPS_TO_INCHES(mMargin
.left
);
426 NS_IMETHODIMP
nsPrintSettings::SetMarginLeft(double aMarginLeft
)
428 mMargin
.left
= NS_INCHES_TO_INT_TWIPS(float(aMarginLeft
));
432 /* attribute double marginBottom; */
433 NS_IMETHODIMP
nsPrintSettings::GetMarginBottom(double *aMarginBottom
)
435 NS_ENSURE_ARG_POINTER(aMarginBottom
);
436 *aMarginBottom
= NS_TWIPS_TO_INCHES(mMargin
.bottom
);
439 NS_IMETHODIMP
nsPrintSettings::SetMarginBottom(double aMarginBottom
)
441 mMargin
.bottom
= NS_INCHES_TO_INT_TWIPS(float(aMarginBottom
));
445 /* attribute double marginRight; */
446 NS_IMETHODIMP
nsPrintSettings::GetMarginRight(double *aMarginRight
)
448 NS_ENSURE_ARG_POINTER(aMarginRight
);
449 *aMarginRight
= NS_TWIPS_TO_INCHES(mMargin
.right
);
452 NS_IMETHODIMP
nsPrintSettings::SetMarginRight(double aMarginRight
)
454 mMargin
.right
= NS_INCHES_TO_INT_TWIPS(float(aMarginRight
));
458 /* attribute double edgeTop; */
459 NS_IMETHODIMP
nsPrintSettings::GetEdgeTop(double *aEdgeTop
)
461 NS_ENSURE_ARG_POINTER(aEdgeTop
);
462 *aEdgeTop
= NS_TWIPS_TO_INCHES(mEdge
.top
);
465 NS_IMETHODIMP
nsPrintSettings::SetEdgeTop(double aEdgeTop
)
467 mEdge
.top
= NS_INCHES_TO_INT_TWIPS(float(aEdgeTop
));
471 /* attribute double edgeLeft; */
472 NS_IMETHODIMP
nsPrintSettings::GetEdgeLeft(double *aEdgeLeft
)
474 NS_ENSURE_ARG_POINTER(aEdgeLeft
);
475 *aEdgeLeft
= NS_TWIPS_TO_INCHES(mEdge
.left
);
478 NS_IMETHODIMP
nsPrintSettings::SetEdgeLeft(double aEdgeLeft
)
480 mEdge
.left
= NS_INCHES_TO_INT_TWIPS(float(aEdgeLeft
));
484 /* attribute double edgeBottom; */
485 NS_IMETHODIMP
nsPrintSettings::GetEdgeBottom(double *aEdgeBottom
)
487 NS_ENSURE_ARG_POINTER(aEdgeBottom
);
488 *aEdgeBottom
= NS_TWIPS_TO_INCHES(mEdge
.bottom
);
491 NS_IMETHODIMP
nsPrintSettings::SetEdgeBottom(double aEdgeBottom
)
493 mEdge
.bottom
= NS_INCHES_TO_INT_TWIPS(float(aEdgeBottom
));
497 /* attribute double edgeRight; */
498 NS_IMETHODIMP
nsPrintSettings::GetEdgeRight(double *aEdgeRight
)
500 NS_ENSURE_ARG_POINTER(aEdgeRight
);
501 *aEdgeRight
= NS_TWIPS_TO_INCHES(mEdge
.right
);
504 NS_IMETHODIMP
nsPrintSettings::SetEdgeRight(double aEdgeRight
)
506 mEdge
.right
= NS_INCHES_TO_INT_TWIPS(float(aEdgeRight
));
510 /* attribute double unwriteableMarginTop; */
511 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginTop(double *aUnwriteableMarginTop
)
513 NS_ENSURE_ARG_POINTER(aUnwriteableMarginTop
);
514 *aUnwriteableMarginTop
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.top
);
517 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginTop(double aUnwriteableMarginTop
)
519 if (aUnwriteableMarginTop
>= 0.0) {
520 mUnwriteableMargin
.top
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginTop
);
525 /* attribute double unwriteableMarginLeft; */
526 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginLeft(double *aUnwriteableMarginLeft
)
528 NS_ENSURE_ARG_POINTER(aUnwriteableMarginLeft
);
529 *aUnwriteableMarginLeft
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.left
);
532 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft
)
534 if (aUnwriteableMarginLeft
>= 0.0) {
535 mUnwriteableMargin
.left
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginLeft
);
540 /* attribute double unwriteableMarginBottom; */
541 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginBottom(double *aUnwriteableMarginBottom
)
543 NS_ENSURE_ARG_POINTER(aUnwriteableMarginBottom
);
544 *aUnwriteableMarginBottom
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.bottom
);
547 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom
)
549 if (aUnwriteableMarginBottom
>= 0.0) {
550 mUnwriteableMargin
.bottom
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginBottom
);
555 /* attribute double unwriteableMarginRight; */
556 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginRight(double *aUnwriteableMarginRight
)
558 NS_ENSURE_ARG_POINTER(aUnwriteableMarginRight
);
559 *aUnwriteableMarginRight
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.right
);
562 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginRight(double aUnwriteableMarginRight
)
564 if (aUnwriteableMarginRight
>= 0.0) {
565 mUnwriteableMargin
.right
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginRight
);
570 /* attribute double scaling; */
571 NS_IMETHODIMP
nsPrintSettings::GetScaling(double *aScaling
)
573 NS_ENSURE_ARG_POINTER(aScaling
);
574 *aScaling
= mScaling
;
578 NS_IMETHODIMP
nsPrintSettings::SetScaling(double aScaling
)
584 /* attribute boolean printBGColors; */
585 NS_IMETHODIMP
nsPrintSettings::GetPrintBGColors(bool *aPrintBGColors
)
587 NS_ENSURE_ARG_POINTER(aPrintBGColors
);
588 *aPrintBGColors
= mPrintBGColors
;
591 NS_IMETHODIMP
nsPrintSettings::SetPrintBGColors(bool aPrintBGColors
)
593 mPrintBGColors
= aPrintBGColors
;
597 /* attribute boolean printBGImages; */
598 NS_IMETHODIMP
nsPrintSettings::GetPrintBGImages(bool *aPrintBGImages
)
600 NS_ENSURE_ARG_POINTER(aPrintBGImages
);
601 *aPrintBGImages
= mPrintBGImages
;
604 NS_IMETHODIMP
nsPrintSettings::SetPrintBGImages(bool aPrintBGImages
)
606 mPrintBGImages
= aPrintBGImages
;
610 /* attribute long printRange; */
611 NS_IMETHODIMP
nsPrintSettings::GetPrintRange(int16_t *aPrintRange
)
613 NS_ENSURE_ARG_POINTER(aPrintRange
);
614 *aPrintRange
= mPrintRange
;
617 NS_IMETHODIMP
nsPrintSettings::SetPrintRange(int16_t aPrintRange
)
619 mPrintRange
= aPrintRange
;
623 /* attribute wstring docTitle; */
624 NS_IMETHODIMP
nsPrintSettings::GetTitle(char16_t
* *aTitle
)
626 NS_ENSURE_ARG_POINTER(aTitle
);
627 if (!mTitle
.IsEmpty()) {
628 *aTitle
= ToNewUnicode(mTitle
);
634 NS_IMETHODIMP
nsPrintSettings::SetTitle(const char16_t
* aTitle
)
644 /* attribute wstring docURL; */
645 NS_IMETHODIMP
nsPrintSettings::GetDocURL(char16_t
* *aDocURL
)
647 NS_ENSURE_ARG_POINTER(aDocURL
);
648 if (!mURL
.IsEmpty()) {
649 *aDocURL
= ToNewUnicode(mURL
);
655 NS_IMETHODIMP
nsPrintSettings::SetDocURL(const char16_t
* aDocURL
)
665 /** ---------------------------------------------------
666 * See documentation in nsPrintSettingsImpl.h
667 * @update 1/12/01 rods
670 nsPrintSettings::GetPrintOptions(int32_t aType
, bool *aTurnOnOff
)
672 NS_ENSURE_ARG_POINTER(aTurnOnOff
);
673 *aTurnOnOff
= mPrintOptions
& aType
? true : false;
676 /** ---------------------------------------------------
677 * See documentation in nsPrintSettingsImpl.h
678 * @update 1/12/01 rods
681 nsPrintSettings::SetPrintOptions(int32_t aType
, bool aTurnOnOff
)
684 mPrintOptions
|= aType
;
686 mPrintOptions
&= ~aType
;
691 /** ---------------------------------------------------
692 * See documentation in nsPrintSettingsImpl.h
693 * @update 1/12/01 rods
696 nsPrintSettings::GetPrintOptionsBits(int32_t *aBits
)
698 NS_ENSURE_ARG_POINTER(aBits
);
699 *aBits
= mPrintOptions
;
703 /* attribute wstring docTitle; */
705 nsPrintSettings::GetMarginStrs(char16_t
* *aTitle
,
706 nsHeaderFooterEnum aType
,
709 NS_ENSURE_ARG_POINTER(aTitle
);
711 if (aType
== eHeader
) {
713 case kJustLeft
: *aTitle
= ToNewUnicode(mHeaderStrs
[0]);break;
714 case kJustCenter
: *aTitle
= ToNewUnicode(mHeaderStrs
[1]);break;
715 case kJustRight
: *aTitle
= ToNewUnicode(mHeaderStrs
[2]);break;
719 case kJustLeft
: *aTitle
= ToNewUnicode(mFooterStrs
[0]);break;
720 case kJustCenter
: *aTitle
= ToNewUnicode(mFooterStrs
[1]);break;
721 case kJustRight
: *aTitle
= ToNewUnicode(mFooterStrs
[2]);break;
728 nsPrintSettings::SetMarginStrs(const char16_t
* aTitle
,
729 nsHeaderFooterEnum aType
,
732 NS_ENSURE_ARG_POINTER(aTitle
);
733 if (aType
== eHeader
) {
735 case kJustLeft
: mHeaderStrs
[0] = aTitle
;break;
736 case kJustCenter
: mHeaderStrs
[1] = aTitle
;break;
737 case kJustRight
: mHeaderStrs
[2] = aTitle
;break;
741 case kJustLeft
: mFooterStrs
[0] = aTitle
;break;
742 case kJustCenter
: mFooterStrs
[1] = aTitle
;break;
743 case kJustRight
: mFooterStrs
[2] = aTitle
;break;
749 /* attribute wstring Header String Left */
750 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrLeft(char16_t
* *aTitle
)
752 return GetMarginStrs(aTitle
, eHeader
, kJustLeft
);
754 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrLeft(const char16_t
* aTitle
)
756 return SetMarginStrs(aTitle
, eHeader
, kJustLeft
);
759 /* attribute wstring Header String Center */
760 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrCenter(char16_t
* *aTitle
)
762 return GetMarginStrs(aTitle
, eHeader
, kJustCenter
);
764 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrCenter(const char16_t
* aTitle
)
766 return SetMarginStrs(aTitle
, eHeader
, kJustCenter
);
769 /* attribute wstring Header String Right */
770 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrRight(char16_t
* *aTitle
)
772 return GetMarginStrs(aTitle
, eHeader
, kJustRight
);
774 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrRight(const char16_t
* aTitle
)
776 return SetMarginStrs(aTitle
, eHeader
, kJustRight
);
780 /* attribute wstring Footer String Left */
781 NS_IMETHODIMP
nsPrintSettings::GetFooterStrLeft(char16_t
* *aTitle
)
783 return GetMarginStrs(aTitle
, eFooter
, kJustLeft
);
785 NS_IMETHODIMP
nsPrintSettings::SetFooterStrLeft(const char16_t
* aTitle
)
787 return SetMarginStrs(aTitle
, eFooter
, kJustLeft
);
790 /* attribute wstring Footer String Center */
791 NS_IMETHODIMP
nsPrintSettings::GetFooterStrCenter(char16_t
* *aTitle
)
793 return GetMarginStrs(aTitle
, eFooter
, kJustCenter
);
795 NS_IMETHODIMP
nsPrintSettings::SetFooterStrCenter(const char16_t
* aTitle
)
797 return SetMarginStrs(aTitle
, eFooter
, kJustCenter
);
800 /* attribute wstring Footer String Right */
801 NS_IMETHODIMP
nsPrintSettings::GetFooterStrRight(char16_t
* *aTitle
)
803 return GetMarginStrs(aTitle
, eFooter
, kJustRight
);
805 NS_IMETHODIMP
nsPrintSettings::SetFooterStrRight(const char16_t
* aTitle
)
807 return SetMarginStrs(aTitle
, eFooter
, kJustRight
);
810 /* attribute short printFrameTypeUsage; */
811 NS_IMETHODIMP
nsPrintSettings::GetPrintFrameTypeUsage(int16_t *aPrintFrameTypeUsage
)
813 NS_ENSURE_ARG_POINTER(aPrintFrameTypeUsage
);
814 *aPrintFrameTypeUsage
= mPrintFrameTypeUsage
;
817 NS_IMETHODIMP
nsPrintSettings::SetPrintFrameTypeUsage(int16_t aPrintFrameTypeUsage
)
819 mPrintFrameTypeUsage
= aPrintFrameTypeUsage
;
823 /* attribute long printFrameType; */
824 NS_IMETHODIMP
nsPrintSettings::GetPrintFrameType(int16_t *aPrintFrameType
)
826 NS_ENSURE_ARG_POINTER(aPrintFrameType
);
827 *aPrintFrameType
= (int32_t)mPrintFrameType
;
830 NS_IMETHODIMP
nsPrintSettings::SetPrintFrameType(int16_t aPrintFrameType
)
832 mPrintFrameType
= aPrintFrameType
;
836 /* attribute boolean printSilent; */
837 NS_IMETHODIMP
nsPrintSettings::GetPrintSilent(bool *aPrintSilent
)
839 NS_ENSURE_ARG_POINTER(aPrintSilent
);
840 *aPrintSilent
= mPrintSilent
;
843 NS_IMETHODIMP
nsPrintSettings::SetPrintSilent(bool aPrintSilent
)
845 mPrintSilent
= aPrintSilent
;
849 /* attribute boolean shrinkToFit; */
850 NS_IMETHODIMP
nsPrintSettings::GetShrinkToFit(bool *aShrinkToFit
)
852 NS_ENSURE_ARG_POINTER(aShrinkToFit
);
853 *aShrinkToFit
= mShrinkToFit
;
856 NS_IMETHODIMP
nsPrintSettings::SetShrinkToFit(bool aShrinkToFit
)
858 mShrinkToFit
= aShrinkToFit
;
862 /* attribute boolean showPrintProgress; */
863 NS_IMETHODIMP
nsPrintSettings::GetShowPrintProgress(bool *aShowPrintProgress
)
865 NS_ENSURE_ARG_POINTER(aShowPrintProgress
);
866 *aShowPrintProgress
= mShowPrintProgress
;
869 NS_IMETHODIMP
nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress
)
871 mShowPrintProgress
= aShowPrintProgress
;
875 /* attribute wstring paperName; */
876 NS_IMETHODIMP
nsPrintSettings::GetPaperName(char16_t
* *aPaperName
)
878 NS_ENSURE_ARG_POINTER(aPaperName
);
879 if (!mPaperName
.IsEmpty()) {
880 *aPaperName
= ToNewUnicode(mPaperName
);
882 *aPaperName
= nullptr;
886 NS_IMETHODIMP
nsPrintSettings::SetPaperName(const char16_t
* aPaperName
)
889 mPaperName
= aPaperName
;
891 mPaperName
.SetLength(0);
896 /* attribute wstring plexName; */
897 NS_IMETHODIMP
nsPrintSettings::GetPlexName(char16_t
* *aPlexName
)
899 NS_ENSURE_ARG_POINTER(aPlexName
);
900 if (!mPlexName
.IsEmpty()) {
901 *aPlexName
= ToNewUnicode(mPlexName
);
903 *aPlexName
= nullptr;
907 NS_IMETHODIMP
nsPrintSettings::SetPlexName(const char16_t
* aPlexName
)
910 mPlexName
= aPlexName
;
912 mPlexName
.SetLength(0);
917 /* attribute boolean howToEnableFrameUI; */
918 NS_IMETHODIMP
nsPrintSettings::GetHowToEnableFrameUI(int16_t *aHowToEnableFrameUI
)
920 NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI
);
921 *aHowToEnableFrameUI
= mHowToEnableFrameUI
;
924 NS_IMETHODIMP
nsPrintSettings::SetHowToEnableFrameUI(int16_t aHowToEnableFrameUI
)
926 mHowToEnableFrameUI
= aHowToEnableFrameUI
;
930 /* attribute long isCancelled; */
931 NS_IMETHODIMP
nsPrintSettings::GetIsCancelled(bool *aIsCancelled
)
933 NS_ENSURE_ARG_POINTER(aIsCancelled
);
934 *aIsCancelled
= mIsCancelled
;
937 NS_IMETHODIMP
nsPrintSettings::SetIsCancelled(bool aIsCancelled
)
939 mIsCancelled
= aIsCancelled
;
943 /* attribute double paperWidth; */
944 NS_IMETHODIMP
nsPrintSettings::GetPaperWidth(double *aPaperWidth
)
946 NS_ENSURE_ARG_POINTER(aPaperWidth
);
947 *aPaperWidth
= mPaperWidth
;
950 NS_IMETHODIMP
nsPrintSettings::SetPaperWidth(double aPaperWidth
)
952 mPaperWidth
= aPaperWidth
;
956 /* attribute double paperHeight; */
957 NS_IMETHODIMP
nsPrintSettings::GetPaperHeight(double *aPaperHeight
)
959 NS_ENSURE_ARG_POINTER(aPaperHeight
);
960 *aPaperHeight
= mPaperHeight
;
963 NS_IMETHODIMP
nsPrintSettings::SetPaperHeight(double aPaperHeight
)
965 mPaperHeight
= aPaperHeight
;
969 /* attribute short PaperSizeUnit; */
970 NS_IMETHODIMP
nsPrintSettings::GetPaperSizeUnit(int16_t *aPaperSizeUnit
)
972 NS_ENSURE_ARG_POINTER(aPaperSizeUnit
);
973 *aPaperSizeUnit
= mPaperSizeUnit
;
976 NS_IMETHODIMP
nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit
)
978 mPaperSizeUnit
= aPaperSizeUnit
;
982 /* attribute short PaperSizeType; */
983 NS_IMETHODIMP
nsPrintSettings::GetPaperSizeType(int16_t *aPaperSizeType
)
985 NS_ENSURE_ARG_POINTER(aPaperSizeType
);
986 *aPaperSizeType
= mPaperSizeType
;
989 NS_IMETHODIMP
nsPrintSettings::SetPaperSizeType(int16_t aPaperSizeType
)
991 mPaperSizeType
= aPaperSizeType
;
995 /* attribute short PaperData; */
996 NS_IMETHODIMP
nsPrintSettings::GetPaperData(int16_t *aPaperData
)
998 NS_ENSURE_ARG_POINTER(aPaperData
);
999 *aPaperData
= mPaperData
;
1002 NS_IMETHODIMP
nsPrintSettings::SetPaperData(int16_t aPaperData
)
1004 mPaperData
= aPaperData
;
1008 /** ---------------------------------------------------
1009 * See documentation in nsPrintOptionsImpl.h
1010 * @update 6/21/00 dwc
1011 * @update 1/12/01 rods
1014 nsPrintSettings::SetMarginInTwips(nsIntMargin
& aMargin
)
1021 nsPrintSettings::SetEdgeInTwips(nsIntMargin
& aEdge
)
1027 // NOTE: Any subclass implementation of this function should make sure
1028 // to check for negative margin values in aUnwriteableMargin (which
1029 // would indicate that we should use the system default unwriteable margin.)
1031 nsPrintSettings::SetUnwriteableMarginInTwips(nsIntMargin
& aUnwriteableMargin
)
1033 if (aUnwriteableMargin
.top
>= 0) {
1034 mUnwriteableMargin
.top
= aUnwriteableMargin
.top
;
1036 if (aUnwriteableMargin
.left
>= 0) {
1037 mUnwriteableMargin
.left
= aUnwriteableMargin
.left
;
1039 if (aUnwriteableMargin
.bottom
>= 0) {
1040 mUnwriteableMargin
.bottom
= aUnwriteableMargin
.bottom
;
1042 if (aUnwriteableMargin
.right
>= 0) {
1043 mUnwriteableMargin
.right
= aUnwriteableMargin
.right
;
1048 /** ---------------------------------------------------
1049 * See documentation in nsPrintOptionsImpl.h
1050 * @update 6/21/00 dwc
1053 nsPrintSettings::GetMarginInTwips(nsIntMargin
& aMargin
)
1060 nsPrintSettings::GetEdgeInTwips(nsIntMargin
& aEdge
)
1067 nsPrintSettings::GetUnwriteableMarginInTwips(nsIntMargin
& aUnwriteableMargin
)
1069 aUnwriteableMargin
= mUnwriteableMargin
;
1073 /** ---------------------------------------------------
1074 * Stub - platform-specific implementations can use this function.
1077 nsPrintSettings::SetupSilentPrinting()
1082 /** ---------------------------------------------------
1083 * See documentation in nsPrintOptionsImpl.h
1086 nsPrintSettings::GetEffectivePageSize(double *aWidth
, double *aHeight
)
1088 if (mPaperSizeUnit
== kPaperSizeInches
) {
1089 *aWidth
= NS_INCHES_TO_TWIPS(float(mPaperWidth
));
1090 *aHeight
= NS_INCHES_TO_TWIPS(float(mPaperHeight
));
1092 *aWidth
= NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth
));
1093 *aHeight
= NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight
));
1095 if (kLandscapeOrientation
== mOrientation
) {
1096 double temp
= *aWidth
;
1104 nsPrintSettings::GetPageRanges(nsTArray
<int32_t> &aPages
)
1111 nsPrintSettings::_Clone(nsIPrintSettings
**_retval
)
1113 nsPrintSettings
* printSettings
= new nsPrintSettings(*this);
1114 return printSettings
->QueryInterface(NS_GET_IID(nsIPrintSettings
), (void**)_retval
); // ref counts
1117 /* nsIPrintSettings clone (); */
1119 nsPrintSettings::Clone(nsIPrintSettings
**_retval
)
1121 NS_ENSURE_ARG_POINTER(_retval
);
1122 return _Clone(_retval
);
1125 /* void assign (in nsIPrintSettings aPS); */
1127 nsPrintSettings::_Assign(nsIPrintSettings
*aPS
)
1129 nsPrintSettings
*ps
= static_cast<nsPrintSettings
*>(aPS
);
1134 /* void assign (in nsIPrintSettings aPS); */
1136 nsPrintSettings::Assign(nsIPrintSettings
*aPS
)
1139 return _Assign(aPS
);
1142 //-------------------------------------------
1143 nsPrintSettings
& nsPrintSettings::operator=(const nsPrintSettings
& rhs
)
1149 mStartPageNum
= rhs
.mStartPageNum
;
1150 mEndPageNum
= rhs
.mEndPageNum
;
1151 mMargin
= rhs
.mMargin
;
1153 mUnwriteableMargin
= rhs
.mUnwriteableMargin
;
1154 mScaling
= rhs
.mScaling
;
1155 mPrintBGColors
= rhs
.mPrintBGColors
;
1156 mPrintBGImages
= rhs
.mPrintBGImages
;
1157 mPrintRange
= rhs
.mPrintRange
;
1158 mTitle
= rhs
.mTitle
;
1160 mHowToEnableFrameUI
= rhs
.mHowToEnableFrameUI
;
1161 mIsCancelled
= rhs
.mIsCancelled
;
1162 mPrintFrameTypeUsage
= rhs
.mPrintFrameTypeUsage
;
1163 mPrintFrameType
= rhs
.mPrintFrameType
;
1164 mPrintSilent
= rhs
.mPrintSilent
;
1165 mShrinkToFit
= rhs
.mShrinkToFit
;
1166 mShowPrintProgress
= rhs
.mShowPrintProgress
;
1167 mPaperName
= rhs
.mPaperName
;
1168 mPlexName
= rhs
.mPlexName
;
1169 mPaperSizeType
= rhs
.mPaperSizeType
;
1170 mPaperData
= rhs
.mPaperData
;
1171 mPaperWidth
= rhs
.mPaperWidth
;
1172 mPaperHeight
= rhs
.mPaperHeight
;
1173 mPaperSizeUnit
= rhs
.mPaperSizeUnit
;
1174 mPrintReversed
= rhs
.mPrintReversed
;
1175 mPrintInColor
= rhs
.mPrintInColor
;
1176 mOrientation
= rhs
.mOrientation
;
1177 mPrintCommand
= rhs
.mPrintCommand
;
1178 mNumCopies
= rhs
.mNumCopies
;
1179 mPrinter
= rhs
.mPrinter
;
1180 mPrintToFile
= rhs
.mPrintToFile
;
1181 mToFileName
= rhs
.mToFileName
;
1182 mOutputFormat
= rhs
.mOutputFormat
;
1183 mPrintPageDelay
= rhs
.mPrintPageDelay
;
1185 for (int32_t i
=0;i
<NUM_HEAD_FOOT
;i
++) {
1186 mHeaderStrs
[i
] = rhs
.mHeaderStrs
[i
];
1187 mFooterStrs
[i
] = rhs
.mFooterStrs
[i
];